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 breakpoint_1 (int, int);
135 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
137 static int breakpoint_cond_eval (void *);
139 static void cleanup_executing_breakpoints (void *);
141 static void commands_command (char *, int);
143 static void condition_command (char *, int);
145 static int get_number_trailer (char **, int);
154 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
155 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
157 static enum print_stop_action
print_it_typical (bpstat
);
159 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
161 static int watchpoint_check (void *);
163 static void maintenance_info_breakpoints (char *, int);
165 static int hw_breakpoint_used_count (void);
167 static int hw_watchpoint_used_count (enum bptype
, int *);
169 static void hbreak_command (char *, int);
171 static void thbreak_command (char *, int);
173 static void watch_command_1 (char *, int, int);
175 static void rwatch_command (char *, int);
177 static void awatch_command (char *, int);
179 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
181 static void stop_command (char *arg
, int from_tty
);
183 static void stopin_command (char *arg
, int from_tty
);
185 static void stopat_command (char *arg
, int from_tty
);
187 static char *ep_parse_optional_if_clause (char **arg
);
189 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
190 char *arg
, int tempflag
, int from_tty
);
192 static void tcatch_command (char *arg
, int from_tty
);
194 static void ep_skip_leading_whitespace (char **s
);
196 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
199 static void free_bp_location (struct bp_location
*loc
);
201 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
203 static void update_global_location_list (int);
205 static void update_global_location_list_nothrow (int);
207 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
209 static int is_watchpoint (struct breakpoint
*bpt
);
211 static void insert_breakpoint_locations (void);
213 static int syscall_catchpoint_p (struct breakpoint
*b
);
215 static void tracepoints_info (char *, int);
217 static void delete_trace_command (char *, int);
219 static void enable_trace_command (char *, int);
221 static void disable_trace_command (char *, int);
223 static void trace_pass_command (char *, int);
225 static void skip_prologue_sal (struct symtab_and_line
*sal
);
228 /* Flag indicating that a command has proceeded the inferior past the
229 current breakpoint. */
231 static int breakpoint_proceeded
;
234 bpdisp_text (enum bpdisp disp
)
236 /* NOTE: the following values are a part of MI protocol and represent
237 values of 'disp' field returned when inferior stops at a breakpoint. */
238 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
239 return bpdisps
[(int) disp
];
242 /* Prototypes for exported functions. */
243 /* If FALSE, gdb will not use hardware support for watchpoints, even
244 if such is available. */
245 static int can_use_hw_watchpoints
;
248 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
249 struct cmd_list_element
*c
,
252 fprintf_filtered (file
, _("\
253 Debugger's willingness to use watchpoint hardware is %s.\n"),
257 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
258 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
259 for unrecognized breakpoint locations.
260 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
261 static enum auto_boolean pending_break_support
;
263 show_pending_break_support (struct ui_file
*file
, int from_tty
,
264 struct cmd_list_element
*c
,
267 fprintf_filtered (file
, _("\
268 Debugger's behavior regarding pending breakpoints is %s.\n"),
272 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
273 set with "break" but falling in read-only memory.
274 If 0, gdb will warn about such breakpoints, but won't automatically
275 use hardware breakpoints. */
276 static int automatic_hardware_breakpoints
;
278 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
279 struct cmd_list_element
*c
,
282 fprintf_filtered (file
, _("\
283 Automatic usage of hardware breakpoints is %s.\n"),
287 /* If on, gdb will keep breakpoints inserted even as inferior is
288 stopped, and immediately insert any new breakpoints. If off, gdb
289 will insert breakpoints into inferior only when resuming it, and
290 will remove breakpoints upon stop. If auto, GDB will behave as ON
291 if in non-stop mode, and as OFF if all-stop mode.*/
293 static const char always_inserted_auto
[] = "auto";
294 static const char always_inserted_on
[] = "on";
295 static const char always_inserted_off
[] = "off";
296 static const char *always_inserted_enums
[] = {
297 always_inserted_auto
,
302 static const char *always_inserted_mode
= always_inserted_auto
;
304 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
305 struct cmd_list_element
*c
, const char *value
)
307 if (always_inserted_mode
== always_inserted_auto
)
308 fprintf_filtered (file
, _("\
309 Always inserted breakpoint mode is %s (currently %s).\n"),
311 breakpoints_always_inserted_mode () ? "on" : "off");
313 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
317 breakpoints_always_inserted_mode (void)
319 return (always_inserted_mode
== always_inserted_on
320 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
323 void _initialize_breakpoint (void);
325 /* Are we executing breakpoint commands? */
326 static int executing_breakpoint_commands
;
328 /* Are overlay event breakpoints enabled? */
329 static int overlay_events_enabled
;
331 /* Walk the following statement or block through all breakpoints.
332 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
335 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
337 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
338 for (B = breakpoint_chain; \
339 B ? (TMP=B->next, 1): 0; \
342 /* Similar iterator for the low-level breakpoints. SAFE variant is not
343 provided so update_global_location_list must not be called while executing
344 the block of ALL_BP_LOCATIONS. */
346 #define ALL_BP_LOCATIONS(B,BP_TMP) \
347 for (BP_TMP = bp_location; \
348 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
351 /* Iterator for tracepoints only. */
353 #define ALL_TRACEPOINTS(B) \
354 for (B = breakpoint_chain; B; B = B->next) \
355 if (tracepoint_type (B))
357 /* Chains of all breakpoints defined. */
359 struct breakpoint
*breakpoint_chain
;
361 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
363 static struct bp_location
**bp_location
;
365 /* Number of elements of BP_LOCATION. */
367 static unsigned bp_location_count
;
369 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
370 for the current elements of BP_LOCATION which get a valid result from
371 bp_location_has_shadow. You can use it for roughly limiting the subrange of
372 BP_LOCATION to scan for shadow bytes for an address you need to read. */
374 static CORE_ADDR bp_location_placed_address_before_address_max
;
376 /* Maximum offset plus alignment between
377 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
378 the current elements of BP_LOCATION which get a valid result from
379 bp_location_has_shadow. You can use it for roughly limiting the subrange of
380 BP_LOCATION to scan for shadow bytes for an address you need to read. */
382 static CORE_ADDR bp_location_shadow_len_after_address_max
;
384 /* The locations that no longer correspond to any breakpoint,
385 unlinked from bp_location array, but for which a hit
386 may still be reported by a target. */
387 VEC(bp_location_p
) *moribund_locations
= NULL
;
389 /* Number of last breakpoint made. */
391 static int breakpoint_count
;
393 /* If the last command to create a breakpoint created multiple
394 breakpoints, this holds the start and end breakpoint numbers. */
395 static int multi_start
;
396 static int multi_end
;
397 /* True if the last breakpoint set was part of a group set with a
398 single command, e.g., "rbreak". */
399 static int last_was_multi
;
401 /* Number of last tracepoint made. */
403 static int tracepoint_count
;
405 /* Return whether a breakpoint is an active enabled breakpoint. */
407 breakpoint_enabled (struct breakpoint
*b
)
409 return (b
->enable_state
== bp_enabled
);
412 /* Set breakpoint count to NUM. */
415 set_breakpoint_count (int num
)
417 breakpoint_count
= num
;
419 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
422 /* Called at the start an "rbreak" command to record the first
425 start_rbreak_breakpoints (void)
427 multi_start
= breakpoint_count
+ 1;
430 /* Called at the end of an "rbreak" command to record the last
433 end_rbreak_breakpoints (void)
435 if (breakpoint_count
>= multi_start
)
437 multi_end
= breakpoint_count
;
442 /* Used in run_command to zero the hit count when a new run starts. */
445 clear_breakpoint_hit_counts (void)
447 struct breakpoint
*b
;
453 /* Encapsulate tests for different types of tracepoints. */
456 tracepoint_type (const struct breakpoint
*b
)
458 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
461 /* Allocate a new counted_command_line with reference count of 1.
462 The new structure owns COMMANDS. */
464 static struct counted_command_line
*
465 alloc_counted_command_line (struct command_line
*commands
)
467 struct counted_command_line
*result
468 = xmalloc (sizeof (struct counted_command_line
));
470 result
->commands
= commands
;
474 /* Increment reference count. This does nothing if CMD is NULL. */
477 incref_counted_command_line (struct counted_command_line
*cmd
)
483 /* Decrement reference count. If the reference count reaches 0,
484 destroy the counted_command_line. Sets *CMDP to NULL. This does
485 nothing if *CMDP is NULL. */
488 decref_counted_command_line (struct counted_command_line
**cmdp
)
492 if (--(*cmdp
)->refc
== 0)
494 free_command_lines (&(*cmdp
)->commands
);
501 /* A cleanup function that calls decref_counted_command_line. */
504 do_cleanup_counted_command_line (void *arg
)
506 decref_counted_command_line (arg
);
509 /* Create a cleanup that calls decref_counted_command_line on the
512 static struct cleanup
*
513 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
515 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
518 /* Default address, symtab and line to put a breakpoint at
519 for "break" command with no arg.
520 if default_breakpoint_valid is zero, the other three are
521 not valid, and "break" with no arg is an error.
523 This set by print_stack_frame, which calls set_default_breakpoint. */
525 int default_breakpoint_valid
;
526 CORE_ADDR default_breakpoint_address
;
527 struct symtab
*default_breakpoint_symtab
;
528 int default_breakpoint_line
;
529 struct program_space
*default_breakpoint_pspace
;
532 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
533 Advance *PP after the string and any trailing whitespace.
535 Currently the string can either be a number or "$" followed by the name
536 of a convenience variable. Making it an expression wouldn't work well
537 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
539 If the string is a NULL pointer, that denotes the last breakpoint.
541 TRAILER is a character which can be found after the number; most
542 commonly this is `-'. If you don't want a trailer, use \0. */
544 get_number_trailer (char **pp
, int trailer
)
546 int retval
= 0; /* default */
550 /* Empty line means refer to the last breakpoint. */
551 return breakpoint_count
;
554 /* Make a copy of the name, so we can null-terminate it
555 to pass to lookup_internalvar(). */
560 while (isalnum (*p
) || *p
== '_')
562 varname
= (char *) alloca (p
- start
+ 1);
563 strncpy (varname
, start
, p
- start
);
564 varname
[p
- start
] = '\0';
565 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
569 printf_filtered (_("Convenience variable must have integer value.\n"));
577 while (*p
>= '0' && *p
<= '9')
580 /* There is no number here. (e.g. "cond a == b"). */
582 /* Skip non-numeric token */
583 while (*p
&& !isspace((int) *p
))
585 /* Return zero, which caller must interpret as error. */
591 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
593 /* Trailing junk: return 0 and let caller print error msg. */
594 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
605 /* Like get_number_trailer, but don't allow a trailer. */
607 get_number (char **pp
)
609 return get_number_trailer (pp
, '\0');
612 /* Parse a number or a range.
613 * A number will be of the form handled by get_number.
614 * A range will be of the form <number1> - <number2>, and
615 * will represent all the integers between number1 and number2,
618 * While processing a range, this fuction is called iteratively;
619 * At each call it will return the next value in the range.
621 * At the beginning of parsing a range, the char pointer PP will
622 * be advanced past <number1> and left pointing at the '-' token.
623 * Subsequent calls will not advance the pointer until the range
624 * is completed. The call that completes the range will advance
625 * pointer PP past <number2>.
629 get_number_or_range (char **pp
)
631 static int last_retval
, end_value
;
632 static char *end_ptr
;
633 static int in_range
= 0;
637 /* Default case: pp is pointing either to a solo number,
638 or to the first number of a range. */
639 last_retval
= get_number_trailer (pp
, '-');
644 /* This is the start of a range (<number1> - <number2>).
645 Skip the '-', parse and remember the second number,
646 and also remember the end of the final token. */
650 while (isspace ((int) *end_ptr
))
651 end_ptr
++; /* skip white space */
652 end_value
= get_number (temp
);
653 if (end_value
< last_retval
)
655 error (_("inverted range"));
657 else if (end_value
== last_retval
)
659 /* degenerate range (number1 == number2). Advance the
660 token pointer so that the range will be treated as a
669 error (_("negative value"));
672 /* pp points to the '-' that betokens a range. All
673 number-parsing has already been done. Return the next
674 integer value (one greater than the saved previous value).
675 Do not advance the token pointer 'pp' until the end of range
678 if (++last_retval
== end_value
)
680 /* End of range reached; advance token pointer. */
688 /* Return the breakpoint with the specified number, or NULL
689 if the number does not refer to an existing breakpoint. */
692 get_breakpoint (int num
)
694 struct breakpoint
*b
;
697 if (b
->number
== num
)
704 /* condition N EXP -- set break condition of breakpoint N to EXP. */
707 condition_command (char *arg
, int from_tty
)
709 struct breakpoint
*b
;
714 error_no_arg (_("breakpoint number"));
717 bnum
= get_number (&p
);
719 error (_("Bad breakpoint argument: '%s'"), arg
);
722 if (b
->number
== bnum
)
724 struct bp_location
*loc
= b
->loc
;
725 for (; loc
; loc
= loc
->next
)
730 xfree (b
->cond_string
);
731 b
->cond_string
= NULL
;
738 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
743 /* I don't know if it matters whether this is the string the user
744 typed in or the decompiled expression. */
745 b
->cond_string
= xstrdup (arg
);
746 b
->condition_not_parsed
= 0;
748 if (is_watchpoint (b
))
750 innermost_block
= NULL
;
752 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
754 error (_("Junk at end of expression"));
755 b
->cond_exp_valid_block
= innermost_block
;
759 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
763 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
765 error (_("Junk at end of expression"));
769 breakpoints_changed ();
770 observer_notify_breakpoint_modified (b
->number
);
774 error (_("No breakpoint number %d."), bnum
);
777 /* Check that COMMAND do not contain commands that are suitable
778 only for tracepoints and not suitable for ordinary breakpoints.
779 Throw if any such commands is found.
782 check_no_tracepoint_commands (struct command_line
*commands
)
784 struct command_line
*c
;
785 for (c
= commands
; c
; c
= c
->next
)
789 if (c
->control_type
== while_stepping_control
)
790 error (_("The 'while-stepping' command can only be used for tracepoints"));
792 for (i
= 0; i
< c
->body_count
; ++i
)
793 check_no_tracepoint_commands ((c
->body_list
)[i
]);
795 /* Not that command parsing removes leading whitespace and comment
796 lines and also empty lines. So, we only need to check for
798 if (strstr (c
->line
, "collect ") == c
->line
)
799 error (_("The 'collect' command can only be used for tracepoints"));
801 if (strstr (c
->line
, "teval ") == c
->line
)
802 error (_("The 'teval' command can only be used for tracepoints"));
807 breakpoint_is_tracepoint (const struct breakpoint
*b
)
812 case bp_fast_tracepoint
:
820 /* A helper function that validsates that COMMANDS are valid for a
821 breakpoint. This function will throw an exception if a problem is
825 validate_commands_for_breakpoint (struct breakpoint
*b
,
826 struct command_line
*commands
)
828 if (breakpoint_is_tracepoint (b
))
830 /* We need to verify that each top-level element of commands
831 is valid for tracepoints, that there's at most one while-stepping
832 element, and that while-stepping's body has valid tracing commands
833 excluding nested while-stepping. */
834 struct command_line
*c
;
835 struct command_line
*while_stepping
= 0;
836 for (c
= commands
; c
; c
= c
->next
)
839 if (c
->control_type
== while_stepping_control
)
841 if (b
->type
== bp_fast_tracepoint
)
842 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
845 error (_("The 'while-stepping' command can be used only once"));
852 struct command_line
*c2
;
854 gdb_assert (while_stepping
->body_count
== 1);
855 c2
= while_stepping
->body_list
[0];
856 for (; c2
; c2
= c2
->next
)
859 if (c2
->control_type
== while_stepping_control
)
860 error (_("The 'while-stepping' command cannot be nested"));
866 check_no_tracepoint_commands (commands
);
870 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
871 validate that only allowed commands are included.
875 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
877 validate_commands_for_breakpoint (b
, commands
);
879 decref_counted_command_line (&b
->commands
);
880 b
->commands
= alloc_counted_command_line (commands
);
881 breakpoints_changed ();
882 observer_notify_breakpoint_modified (b
->number
);
886 check_tracepoint_command (char *line
, void *closure
)
888 struct breakpoint
*b
= closure
;
889 validate_actionline (&line
, b
);
892 /* A structure used to pass information through
893 map_breakpoint_numbers. */
897 /* True if the command was typed at a tty. */
899 /* Non-NULL if the body of the commands are being read from this
900 already-parsed command. */
901 struct command_line
*control
;
902 /* The command lines read from the user, or NULL if they have not
904 struct counted_command_line
*cmd
;
907 /* A callback for map_breakpoint_numbers that sets the commands for
911 do_map_commands_command (struct breakpoint
*b
, void *data
)
913 struct commands_info
*info
= data
;
915 if (info
->cmd
== NULL
)
917 struct command_line
*l
;
919 if (info
->control
!= NULL
)
920 l
= copy_command_lines (info
->control
->body_list
[0]);
923 l
= read_command_lines (_("Type commands for all specified breakpoints"),
925 (breakpoint_is_tracepoint (b
)
926 ? check_tracepoint_command
: 0),
929 info
->cmd
= alloc_counted_command_line (l
);
932 /* If a breakpoint was on the list more than once, we don't need to
934 if (b
->commands
!= info
->cmd
)
936 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
937 incref_counted_command_line (info
->cmd
);
938 decref_counted_command_line (&b
->commands
);
939 b
->commands
= info
->cmd
;
940 breakpoints_changed ();
941 observer_notify_breakpoint_modified (b
->number
);
946 commands_command_1 (char *arg
, int from_tty
, struct command_line
*control
)
948 struct cleanup
*cleanups
;
949 struct commands_info info
;
951 info
.from_tty
= from_tty
;
952 info
.control
= control
;
954 /* If we read command lines from the user, then `info' will hold an
955 extra reference to the commands that we must clean up. */
956 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
958 if (arg
== NULL
|| !*arg
)
961 arg
= xstrprintf ("%d-%d", multi_start
, multi_end
);
962 else if (breakpoint_count
> 0)
963 arg
= xstrprintf ("%d", breakpoint_count
);
964 make_cleanup (xfree
, arg
);
967 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
969 if (info
.cmd
== NULL
)
970 error (_("No breakpoints specified."));
972 do_cleanups (cleanups
);
976 commands_command (char *arg
, int from_tty
)
978 commands_command_1 (arg
, from_tty
, NULL
);
981 /* Like commands_command, but instead of reading the commands from
982 input stream, takes them from an already parsed command structure.
984 This is used by cli-script.c to DTRT with breakpoint commands
985 that are part of if and while bodies. */
986 enum command_control_type
987 commands_from_control_command (char *arg
, struct command_line
*cmd
)
989 commands_command_1 (arg
, 0, cmd
);
990 return simple_control
;
993 /* Return non-zero if BL->TARGET_INFO contains valid information. */
996 bp_location_has_shadow (struct bp_location
*bl
)
998 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1002 if (bl
->target_info
.shadow_len
== 0)
1003 /* bp isn't valid, or doesn't shadow memory. */
1008 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1009 by replacing any memory breakpoints with their shadowed contents.
1011 The range of shadowed area by each bp_location is:
1012 b->address - bp_location_placed_address_before_address_max
1013 up to b->address + bp_location_shadow_len_after_address_max
1014 The range we were requested to resolve shadows for is:
1015 memaddr ... memaddr + len
1016 Thus the safe cutoff boundaries for performance optimization are
1017 memaddr + len <= b->address - bp_location_placed_address_before_address_max
1019 b->address + bp_location_shadow_len_after_address_max <= memaddr */
1022 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1024 /* Left boundary, right boundary and median element of our binary search. */
1025 unsigned bc_l
, bc_r
, bc
;
1027 /* Find BC_L which is a leftmost element which may affect BUF content. It is
1028 safe to report lower value but a failure to report higher one. */
1031 bc_r
= bp_location_count
;
1032 while (bc_l
+ 1 < bc_r
)
1034 struct bp_location
*b
;
1036 bc
= (bc_l
+ bc_r
) / 2;
1037 b
= bp_location
[bc
];
1039 /* Check first B->ADDRESS will not overflow due to the added constant.
1040 Then advance the left boundary only if we are sure the BC element can
1041 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
1043 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
1044 we cannot miss a breakpoint with its shadow range tail still reaching
1047 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
1048 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
1054 /* Now do full processing of the found relevant range of elements. */
1056 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1058 struct bp_location
*b
= bp_location
[bc
];
1059 CORE_ADDR bp_addr
= 0;
1063 if (b
->owner
->type
== bp_none
)
1064 warning (_("reading through apparently deleted breakpoint #%d?"),
1067 /* Performance optimization: any futher element can no longer affect BUF
1070 if (b
->address
>= bp_location_placed_address_before_address_max
1071 && memaddr
+ len
<= b
->address
1072 - bp_location_placed_address_before_address_max
)
1075 if (!bp_location_has_shadow (b
))
1077 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1078 current_program_space
->aspace
, 0))
1081 /* Addresses and length of the part of the breakpoint that
1083 bp_addr
= b
->target_info
.placed_address
;
1084 bp_size
= b
->target_info
.shadow_len
;
1086 if (bp_addr
+ bp_size
<= memaddr
)
1087 /* The breakpoint is entirely before the chunk of memory we
1091 if (bp_addr
>= memaddr
+ len
)
1092 /* The breakpoint is entirely after the chunk of memory we are
1096 /* Offset within shadow_contents. */
1097 if (bp_addr
< memaddr
)
1099 /* Only copy the second part of the breakpoint. */
1100 bp_size
-= memaddr
- bp_addr
;
1101 bptoffset
= memaddr
- bp_addr
;
1105 if (bp_addr
+ bp_size
> memaddr
+ len
)
1107 /* Only copy the first part of the breakpoint. */
1108 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1111 memcpy (buf
+ bp_addr
- memaddr
,
1112 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1117 /* A wrapper function for inserting catchpoints. */
1119 insert_catchpoint (struct ui_out
*uo
, void *args
)
1121 struct breakpoint
*b
= (struct breakpoint
*) args
;
1124 gdb_assert (b
->type
== bp_catchpoint
);
1125 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1130 /* Return true if BPT is of any hardware watchpoint kind. */
1133 is_hardware_watchpoint (struct breakpoint
*bpt
)
1135 return (bpt
->type
== bp_hardware_watchpoint
1136 || bpt
->type
== bp_read_watchpoint
1137 || bpt
->type
== bp_access_watchpoint
);
1140 /* Return true if BPT is of any watchpoint kind, hardware or
1144 is_watchpoint (struct breakpoint
*bpt
)
1146 return (is_hardware_watchpoint (bpt
)
1147 || bpt
->type
== bp_watchpoint
);
1150 /* Find the current value of a watchpoint on EXP. Return the value in
1151 *VALP and *RESULTP and the chain of intermediate and final values
1152 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1155 If a memory error occurs while evaluating the expression, *RESULTP will
1156 be set to NULL. *RESULTP may be a lazy value, if the result could
1157 not be read from memory. It is used to determine whether a value
1158 is user-specified (we should watch the whole value) or intermediate
1159 (we should watch only the bit used to locate the final value).
1161 If the final value, or any intermediate value, could not be read
1162 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1163 set to any referenced values. *VALP will never be a lazy value.
1164 This is the value which we store in struct breakpoint.
1166 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1167 value chain. The caller must free the values individually. If
1168 VAL_CHAIN is NULL, all generated values will be left on the value
1172 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1173 struct value
**resultp
, struct value
**val_chain
)
1175 struct value
*mark
, *new_mark
, *result
;
1176 volatile struct gdb_exception ex
;
1184 /* Evaluate the expression. */
1185 mark
= value_mark ();
1188 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1190 result
= evaluate_expression (exp
);
1194 /* Ignore memory errors, we want watchpoints pointing at
1195 inaccessible memory to still be created; otherwise, throw the
1196 error to some higher catcher. */
1202 throw_exception (ex
);
1207 new_mark
= value_mark ();
1208 if (mark
== new_mark
)
1213 /* Make sure it's not lazy, so that after the target stops again we
1214 have a non-lazy previous value to compare with. */
1216 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1221 /* Return the chain of intermediate values. We use this to
1222 decide which addresses to watch. */
1223 *val_chain
= new_mark
;
1224 value_release_to_mark (mark
);
1228 /* Assuming that B is a watchpoint: returns true if the current thread
1229 and its running state are safe to evaluate or update watchpoint B.
1230 Watchpoints on local expressions need to be evaluated in the
1231 context of the thread that was current when the watchpoint was
1232 created, and, that thread needs to be stopped to be able to select
1233 the correct frame context. Watchpoints on global expressions can
1234 be evaluated on any thread, and in any state. It is presently left
1235 to the target allowing memory accesses when threads are
1239 watchpoint_in_thread_scope (struct breakpoint
*b
)
1241 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1242 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1243 && !is_executing (inferior_ptid
)));
1246 /* Assuming that B is a watchpoint:
1247 - Reparse watchpoint expression, if REPARSE is non-zero
1248 - Evaluate expression and store the result in B->val
1249 - Evaluate the condition if there is one, and store the result
1251 - Update the list of values that must be watched in B->loc.
1253 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1254 If this is local watchpoint that is out of scope, delete it.
1256 Even with `set breakpoint always-inserted on' the watchpoints are removed
1257 + inserted on each stop here. Normal breakpoints must never be removed
1258 because they might be missed by a running thread when debugging in non-stop
1259 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1260 processed here) are specific to each LWP since they are stored in each LWP's
1261 hardware debug registers. Therefore, such LWP must be stopped first in
1262 order to be able to modify its hardware watchpoints.
1264 Hardware watchpoints must be reset exactly once after being presented to the
1265 user. It cannot be done sooner, because it would reset the data used to
1266 present the watchpoint hit to the user. And it must not be done later
1267 because it could display the same single watchpoint hit during multiple GDB
1268 stops. Note that the latter is relevant only to the hardware watchpoint
1269 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1270 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1271 memory content has not changed.
1273 The following constraints influence the location where we can reset hardware
1276 * target_stopped_by_watchpoint and target_stopped_data_address are called
1277 several times when GDB stops.
1280 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1281 stop. GDB only presents one hardware watchpoint hit at a time as the
1282 reason for stopping, and all the other hits are presented later, one after
1283 the other, each time the user requests the execution to be resumed.
1284 Execution is not resumed for the threads still having pending hit event
1285 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1286 the inferior on the first stop the thread hit event is kept being reported
1287 from its cached value by linux_nat_stopped_data_address until the real
1288 thread resume happens after the watchpoint gets presented and thus its
1289 LWP_INFO->STATUS gets reset.
1291 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1292 removal from inferior. */
1295 update_watchpoint (struct breakpoint
*b
, int reparse
)
1297 int within_current_scope
;
1298 struct frame_id saved_frame_id
;
1299 struct bp_location
*loc
;
1303 /* If this is a local watchpoint, we only want to check if the
1304 watchpoint frame is in scope if the current thread is the thread
1305 that was used to create the watchpoint. */
1306 if (!watchpoint_in_thread_scope (b
))
1309 /* We don't free locations. They are stored in bp_location array and
1310 update_global_locations will eventually delete them and remove
1311 breakpoints if needed. */
1314 if (b
->disposition
== disp_del_at_next_stop
)
1319 /* Determine if the watchpoint is within scope. */
1320 if (b
->exp_valid_block
== NULL
)
1321 within_current_scope
= 1;
1324 struct frame_info
*fi
;
1326 /* Save the current frame's ID so we can restore it after
1327 evaluating the watchpoint expression on its own frame. */
1328 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1329 took a frame parameter, so that we didn't have to change the
1332 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1334 fi
= frame_find_by_id (b
->watchpoint_frame
);
1335 within_current_scope
= (fi
!= NULL
);
1336 if (within_current_scope
)
1340 if (within_current_scope
&& reparse
)
1349 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1350 /* If the meaning of expression itself changed, the old value is
1351 no longer relevant. We don't want to report a watchpoint hit
1352 to the user when the old value and the new value may actually
1353 be completely different objects. */
1354 value_free (b
->val
);
1358 /* Note that unlike with breakpoints, the watchpoint's condition
1359 expression is stored in the breakpoint object, not in the
1360 locations (re)created below. */
1361 if (b
->cond_string
!= NULL
)
1363 if (b
->cond_exp
!= NULL
)
1365 xfree (b
->cond_exp
);
1370 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1374 /* If we failed to parse the expression, for example because
1375 it refers to a global variable in a not-yet-loaded shared library,
1376 don't try to insert watchpoint. We don't automatically delete
1377 such watchpoint, though, since failure to parse expression
1378 is different from out-of-scope watchpoint. */
1379 if ( !target_has_execution
)
1381 /* Without execution, memory can't change. No use to try and
1382 set watchpoint locations. The watchpoint will be reset when
1383 the target gains execution, through breakpoint_re_set. */
1385 else if (within_current_scope
&& b
->exp
)
1387 struct value
*val_chain
, *v
, *result
, *next
;
1388 struct program_space
*frame_pspace
;
1390 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1392 /* Avoid setting b->val if it's already set. The meaning of
1393 b->val is 'the last value' user saw, and we should update
1394 it only if we reported that last value to user. As it
1395 happens, the code that reports it updates b->val directly. */
1402 /* Change the type of breakpoint between hardware assisted or an
1403 ordinary watchpoint depending on the hardware support and free
1404 hardware slots. REPARSE is set when the inferior is started. */
1405 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1408 int i
, mem_cnt
, other_type_used
;
1410 /* We need to determine how many resources are already used
1411 for all other hardware watchpoints to see if we still have
1412 enough resources to also fit this watchpoint in as well.
1413 To avoid the hw_watchpoint_used_count call below from counting
1414 this watchpoint, make sure that it is marked as a software
1416 b
->type
= bp_watchpoint
;
1417 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1419 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1422 b
->type
= bp_watchpoint
;
1425 int target_resources_ok
= target_can_use_hardware_watchpoint
1426 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1427 if (target_resources_ok
<= 0)
1428 b
->type
= bp_watchpoint
;
1430 b
->type
= bp_hardware_watchpoint
;
1434 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1436 /* Look at each value on the value chain. */
1437 for (v
= val_chain
; v
; v
= next
)
1439 /* If it's a memory location, and GDB actually needed
1440 its contents to evaluate the expression, then we
1441 must watch it. If the first value returned is
1442 still lazy, that means an error occurred reading it;
1443 watch it anyway in case it becomes readable. */
1444 if (VALUE_LVAL (v
) == lval_memory
1445 && (v
== val_chain
|| ! value_lazy (v
)))
1447 struct type
*vtype
= check_typedef (value_type (v
));
1449 /* We only watch structs and arrays if user asked
1450 for it explicitly, never if they just happen to
1451 appear in the middle of some value chain. */
1453 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1454 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1458 struct bp_location
*loc
, **tmp
;
1460 addr
= value_address (v
);
1461 len
= TYPE_LENGTH (value_type (v
));
1463 if (b
->type
== bp_read_watchpoint
)
1465 else if (b
->type
== bp_access_watchpoint
)
1468 loc
= allocate_bp_location (b
);
1469 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1472 loc
->gdbarch
= get_type_arch (value_type (v
));
1474 loc
->pspace
= frame_pspace
;
1475 loc
->address
= addr
;
1477 loc
->watchpoint_type
= type
;
1481 next
= value_next (v
);
1486 /* If a software watchpoint is not watching any memory, then the
1487 above left it without any location set up. But,
1488 bpstat_stop_status requires a location to be able to report
1489 stops, so make sure there's at least a dummy one. */
1490 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1492 b
->loc
= allocate_bp_location (b
);
1493 b
->loc
->pspace
= frame_pspace
;
1494 b
->loc
->address
= -1;
1495 b
->loc
->length
= -1;
1496 b
->loc
->watchpoint_type
= -1;
1499 else if (!within_current_scope
)
1501 printf_filtered (_("\
1502 Watchpoint %d deleted because the program has left the block \n\
1503 in which its expression is valid.\n"),
1505 if (b
->related_breakpoint
)
1507 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1508 b
->related_breakpoint
->related_breakpoint
= NULL
;
1509 b
->related_breakpoint
= NULL
;
1511 b
->disposition
= disp_del_at_next_stop
;
1514 /* Restore the selected frame. */
1516 select_frame (frame_find_by_id (saved_frame_id
));
1520 /* Returns 1 iff breakpoint location should be
1521 inserted in the inferior. */
1523 should_be_inserted (struct bp_location
*bpt
)
1525 if (!breakpoint_enabled (bpt
->owner
))
1528 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1531 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1534 /* This is set for example, when we're attached to the parent of a
1535 vfork, and have detached from the child. The child is running
1536 free, and we expect it to do an exec or exit, at which point the
1537 OS makes the parent schedulable again (and the target reports
1538 that the vfork is done). Until the child is done with the shared
1539 memory region, do not insert breakpoints in the parent, otherwise
1540 the child could still trip on the parent's breakpoints. Since
1541 the parent is blocked anyway, it won't miss any breakpoint. */
1542 if (bpt
->pspace
->breakpoints_not_allowed
)
1545 /* Tracepoints are inserted by the target at a time of its choosing,
1547 if (tracepoint_type (bpt
->owner
))
1553 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1554 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1555 and HW_BREAKPOINT_ERROR are used to report problems.
1557 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1558 method for each breakpoint or catchpoint type. */
1560 insert_bp_location (struct bp_location
*bpt
,
1561 struct ui_file
*tmp_error_stream
,
1562 int *disabled_breaks
,
1563 int *hw_breakpoint_error
)
1567 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1570 /* Initialize the target-specific information. */
1571 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1572 bpt
->target_info
.placed_address
= bpt
->address
;
1573 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1575 if (bpt
->loc_type
== bp_loc_software_breakpoint
1576 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1578 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1580 /* If the explicitly specified breakpoint type
1581 is not hardware breakpoint, check the memory map to see
1582 if the breakpoint address is in read only memory or not.
1583 Two important cases are:
1584 - location type is not hardware breakpoint, memory
1585 is readonly. We change the type of the location to
1586 hardware breakpoint.
1587 - location type is hardware breakpoint, memory is read-write.
1588 This means we've previously made the location hardware one, but
1589 then the memory map changed, so we undo.
1591 When breakpoints are removed, remove_breakpoints will
1592 use location types we've just set here, the only possible
1593 problem is that memory map has changed during running program,
1594 but it's not going to work anyway with current gdb. */
1595 struct mem_region
*mr
1596 = lookup_mem_region (bpt
->target_info
.placed_address
);
1600 if (automatic_hardware_breakpoints
)
1603 enum bp_loc_type new_type
;
1605 if (mr
->attrib
.mode
!= MEM_RW
)
1606 new_type
= bp_loc_hardware_breakpoint
;
1608 new_type
= bp_loc_software_breakpoint
;
1610 if (new_type
!= bpt
->loc_type
)
1612 static int said
= 0;
1613 bpt
->loc_type
= new_type
;
1616 fprintf_filtered (gdb_stdout
, _("\
1617 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1622 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1623 && mr
->attrib
.mode
!= MEM_RW
)
1624 warning (_("cannot set software breakpoint at readonly address %s"),
1625 paddress (bpt
->gdbarch
, bpt
->address
));
1629 /* First check to see if we have to handle an overlay. */
1630 if (overlay_debugging
== ovly_off
1631 || bpt
->section
== NULL
1632 || !(section_is_overlay (bpt
->section
)))
1634 /* No overlay handling: just set the breakpoint. */
1636 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1637 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1640 val
= target_insert_breakpoint (bpt
->gdbarch
,
1645 /* This breakpoint is in an overlay section.
1646 Shall we set a breakpoint at the LMA? */
1647 if (!overlay_events_enabled
)
1649 /* Yes -- overlay event support is not active,
1650 so we must try to set a breakpoint at the LMA.
1651 This will not work for a hardware breakpoint. */
1652 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1653 warning (_("hardware breakpoint %d not supported in overlay!"),
1654 bpt
->owner
->number
);
1657 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1659 /* Set a software (trap) breakpoint at the LMA. */
1660 bpt
->overlay_target_info
= bpt
->target_info
;
1661 bpt
->overlay_target_info
.placed_address
= addr
;
1662 val
= target_insert_breakpoint (bpt
->gdbarch
,
1663 &bpt
->overlay_target_info
);
1665 fprintf_unfiltered (tmp_error_stream
,
1666 "Overlay breakpoint %d failed: in ROM?\n",
1667 bpt
->owner
->number
);
1670 /* Shall we set a breakpoint at the VMA? */
1671 if (section_is_mapped (bpt
->section
))
1673 /* Yes. This overlay section is mapped into memory. */
1674 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1675 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1678 val
= target_insert_breakpoint (bpt
->gdbarch
,
1683 /* No. This breakpoint will not be inserted.
1684 No error, but do not mark the bp as 'inserted'. */
1691 /* Can't set the breakpoint. */
1692 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1694 /* See also: disable_breakpoints_in_shlibs. */
1696 bpt
->shlib_disabled
= 1;
1697 if (!*disabled_breaks
)
1699 fprintf_unfiltered (tmp_error_stream
,
1700 "Cannot insert breakpoint %d.\n",
1701 bpt
->owner
->number
);
1702 fprintf_unfiltered (tmp_error_stream
,
1703 "Temporarily disabling shared library breakpoints:\n");
1705 *disabled_breaks
= 1;
1706 fprintf_unfiltered (tmp_error_stream
,
1707 "breakpoint #%d\n", bpt
->owner
->number
);
1711 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1713 *hw_breakpoint_error
= 1;
1714 fprintf_unfiltered (tmp_error_stream
,
1715 "Cannot insert hardware breakpoint %d.\n",
1716 bpt
->owner
->number
);
1720 fprintf_unfiltered (tmp_error_stream
,
1721 "Cannot insert breakpoint %d.\n",
1722 bpt
->owner
->number
);
1723 fprintf_filtered (tmp_error_stream
,
1724 "Error accessing memory address ");
1725 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1727 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1728 safe_strerror (val
));
1739 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1740 /* NOTE drow/2003-09-08: This state only exists for removing
1741 watchpoints. It's not clear that it's necessary... */
1742 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1744 val
= target_insert_watchpoint (bpt
->address
,
1746 bpt
->watchpoint_type
);
1748 /* If trying to set a read-watchpoint, and it turns out it's not
1749 supported, try emulating one with an access watchpoint. */
1750 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1752 struct bp_location
*loc
, **loc_temp
;
1754 /* But don't try to insert it, if there's already another
1755 hw_access location that would be considered a duplicate
1757 ALL_BP_LOCATIONS (loc
, loc_temp
)
1759 && loc
->watchpoint_type
== hw_access
1760 && watchpoint_locations_match (bpt
, loc
))
1764 bpt
->target_info
= loc
->target_info
;
1765 bpt
->watchpoint_type
= hw_access
;
1772 val
= target_insert_watchpoint (bpt
->address
,
1776 bpt
->watchpoint_type
= hw_access
;
1780 bpt
->inserted
= (val
== 0);
1783 else if (bpt
->owner
->type
== bp_catchpoint
)
1785 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1786 bpt
->owner
, RETURN_MASK_ERROR
);
1787 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1788 bpt
->owner
->number
);
1790 bpt
->owner
->enable_state
= bp_disabled
;
1794 /* We've already printed an error message if there was a problem
1795 inserting this catchpoint, and we've disabled the catchpoint,
1796 so just return success. */
1803 /* This function is called when program space PSPACE is about to be
1804 deleted. It takes care of updating breakpoints to not reference
1808 breakpoint_program_space_exit (struct program_space
*pspace
)
1810 struct breakpoint
*b
, *b_temp
;
1811 struct bp_location
*loc
, **loc_temp
;
1813 /* Remove any breakpoint that was set through this program space. */
1814 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1816 if (b
->pspace
== pspace
)
1817 delete_breakpoint (b
);
1820 /* Breakpoints set through other program spaces could have locations
1821 bound to PSPACE as well. Remove those. */
1822 ALL_BP_LOCATIONS (loc
, loc_temp
)
1824 struct bp_location
*tmp
;
1826 if (loc
->pspace
== pspace
)
1828 if (loc
->owner
->loc
== loc
)
1829 loc
->owner
->loc
= loc
->next
;
1831 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1832 if (tmp
->next
== loc
)
1834 tmp
->next
= loc
->next
;
1840 /* Now update the global location list to permanently delete the
1841 removed locations above. */
1842 update_global_location_list (0);
1845 /* Make sure all breakpoints are inserted in inferior.
1846 Throws exception on any error.
1847 A breakpoint that is already inserted won't be inserted
1848 again, so calling this function twice is safe. */
1850 insert_breakpoints (void)
1852 struct breakpoint
*bpt
;
1854 ALL_BREAKPOINTS (bpt
)
1855 if (is_hardware_watchpoint (bpt
))
1856 update_watchpoint (bpt
, 0 /* don't reparse. */);
1858 update_global_location_list (1);
1860 /* update_global_location_list does not insert breakpoints when
1861 always_inserted_mode is not enabled. Explicitly insert them
1863 if (!breakpoints_always_inserted_mode ())
1864 insert_breakpoint_locations ();
1867 /* insert_breakpoints is used when starting or continuing the program.
1868 remove_breakpoints is used when the program stops.
1869 Both return zero if successful,
1870 or an `errno' value if could not write the inferior. */
1873 insert_breakpoint_locations (void)
1875 struct breakpoint
*bpt
;
1876 struct bp_location
*b
, **bp_tmp
;
1879 int disabled_breaks
= 0;
1880 int hw_breakpoint_error
= 0;
1882 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1883 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1885 /* Explicitly mark the warning -- this will only be printed if
1886 there was an error. */
1887 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1889 save_current_space_and_thread ();
1891 ALL_BP_LOCATIONS (b
, bp_tmp
)
1893 struct thread_info
*tp
;
1894 CORE_ADDR last_addr
;
1896 if (!should_be_inserted (b
) || b
->inserted
)
1899 /* There is no point inserting thread-specific breakpoints if the
1900 thread no longer exists. */
1901 if (b
->owner
->thread
!= -1
1902 && !valid_thread_id (b
->owner
->thread
))
1905 switch_to_program_space_and_thread (b
->pspace
);
1907 /* For targets that support global breakpoints, there's no need
1908 to select an inferior to insert breakpoint to. In fact, even
1909 if we aren't attached to any process yet, we should still
1910 insert breakpoints. */
1911 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1912 && ptid_equal (inferior_ptid
, null_ptid
))
1915 val
= insert_bp_location (b
, tmp_error_stream
,
1917 &hw_breakpoint_error
);
1922 /* If we failed to insert all locations of a watchpoint,
1923 remove them, as half-inserted watchpoint is of limited use. */
1924 ALL_BREAKPOINTS (bpt
)
1926 int some_failed
= 0;
1927 struct bp_location
*loc
;
1929 if (!is_hardware_watchpoint (bpt
))
1932 if (!breakpoint_enabled (bpt
))
1935 if (bpt
->disposition
== disp_del_at_next_stop
)
1938 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1939 if (!loc
->inserted
&& should_be_inserted (loc
))
1946 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1948 remove_breakpoint (loc
, mark_uninserted
);
1950 hw_breakpoint_error
= 1;
1951 fprintf_unfiltered (tmp_error_stream
,
1952 "Could not insert hardware watchpoint %d.\n",
1960 /* If a hardware breakpoint or watchpoint was inserted, add a
1961 message about possibly exhausted resources. */
1962 if (hw_breakpoint_error
)
1964 fprintf_unfiltered (tmp_error_stream
,
1965 "Could not insert hardware breakpoints:\n\
1966 You may have requested too many hardware breakpoints/watchpoints.\n");
1968 target_terminal_ours_for_output ();
1969 error_stream (tmp_error_stream
);
1972 do_cleanups (cleanups
);
1976 remove_breakpoints (void)
1978 struct bp_location
*b
, **bp_tmp
;
1981 ALL_BP_LOCATIONS (b
, bp_tmp
)
1984 val
|= remove_breakpoint (b
, mark_uninserted
);
1989 /* Remove breakpoints of process PID. */
1992 remove_breakpoints_pid (int pid
)
1994 struct bp_location
*b
, **b_tmp
;
1996 struct inferior
*inf
= find_inferior_pid (pid
);
1998 ALL_BP_LOCATIONS (b
, b_tmp
)
2000 if (b
->pspace
!= inf
->pspace
)
2005 val
= remove_breakpoint (b
, mark_uninserted
);
2014 remove_hw_watchpoints (void)
2016 struct bp_location
*b
, **bp_tmp
;
2019 ALL_BP_LOCATIONS (b
, bp_tmp
)
2021 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
2022 val
|= remove_breakpoint (b
, mark_uninserted
);
2028 reattach_breakpoints (int pid
)
2030 struct cleanup
*old_chain
;
2031 struct bp_location
*b
, **bp_tmp
;
2033 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2034 int dummy1
= 0, dummy2
= 0;
2035 struct inferior
*inf
;
2036 struct thread_info
*tp
;
2038 tp
= any_live_thread_of_process (pid
);
2042 inf
= find_inferior_pid (pid
);
2043 old_chain
= save_inferior_ptid ();
2045 inferior_ptid
= tp
->ptid
;
2047 make_cleanup_ui_file_delete (tmp_error_stream
);
2049 ALL_BP_LOCATIONS (b
, bp_tmp
)
2051 if (b
->pspace
!= inf
->pspace
)
2057 val
= insert_bp_location (b
, tmp_error_stream
,
2061 do_cleanups (old_chain
);
2066 do_cleanups (old_chain
);
2070 static int internal_breakpoint_number
= -1;
2072 static struct breakpoint
*
2073 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2074 CORE_ADDR address
, enum bptype type
)
2076 struct symtab_and_line sal
;
2077 struct breakpoint
*b
;
2079 init_sal (&sal
); /* initialize to zeroes */
2082 sal
.section
= find_pc_overlay (sal
.pc
);
2083 sal
.pspace
= current_program_space
;
2085 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2086 b
->number
= internal_breakpoint_number
--;
2087 b
->disposition
= disp_donttouch
;
2093 create_overlay_event_breakpoint (char *func_name
)
2095 struct objfile
*objfile
;
2097 ALL_OBJFILES (objfile
)
2099 struct breakpoint
*b
;
2100 struct minimal_symbol
*m
;
2102 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2106 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2107 SYMBOL_VALUE_ADDRESS (m
),
2109 b
->addr_string
= xstrdup (func_name
);
2111 if (overlay_debugging
== ovly_auto
)
2113 b
->enable_state
= bp_enabled
;
2114 overlay_events_enabled
= 1;
2118 b
->enable_state
= bp_disabled
;
2119 overlay_events_enabled
= 0;
2122 update_global_location_list (1);
2126 create_longjmp_master_breakpoint (char *func_name
)
2128 struct program_space
*pspace
;
2129 struct objfile
*objfile
;
2130 struct cleanup
*old_chain
;
2132 old_chain
= save_current_program_space ();
2134 ALL_PSPACES (pspace
)
2135 ALL_OBJFILES (objfile
)
2137 struct breakpoint
*b
;
2138 struct minimal_symbol
*m
;
2140 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2143 set_current_program_space (pspace
);
2145 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2149 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2150 SYMBOL_VALUE_ADDRESS (m
),
2152 b
->addr_string
= xstrdup (func_name
);
2153 b
->enable_state
= bp_disabled
;
2155 update_global_location_list (1);
2157 do_cleanups (old_chain
);
2160 /* Create a master std::terminate breakpoint. The actual function
2161 looked for is named FUNC_NAME. */
2163 create_std_terminate_master_breakpoint (const char *func_name
)
2165 struct program_space
*pspace
;
2166 struct objfile
*objfile
;
2167 struct cleanup
*old_chain
;
2169 old_chain
= save_current_program_space ();
2171 ALL_PSPACES (pspace
)
2172 ALL_OBJFILES (objfile
)
2174 struct breakpoint
*b
;
2175 struct minimal_symbol
*m
;
2177 set_current_program_space (pspace
);
2179 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2180 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2181 && MSYMBOL_TYPE (m
) != mst_file_text
))
2184 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2185 SYMBOL_VALUE_ADDRESS (m
),
2186 bp_std_terminate_master
);
2187 b
->addr_string
= xstrdup (func_name
);
2188 b
->enable_state
= bp_disabled
;
2190 update_global_location_list (1);
2192 do_cleanups (old_chain
);
2196 update_breakpoints_after_exec (void)
2198 struct breakpoint
*b
;
2199 struct breakpoint
*temp
;
2200 struct bp_location
*bploc
, **bplocp_tmp
;
2202 /* We're about to delete breakpoints from GDB's lists. If the
2203 INSERTED flag is true, GDB will try to lift the breakpoints by
2204 writing the breakpoints' "shadow contents" back into memory. The
2205 "shadow contents" are NOT valid after an exec, so GDB should not
2206 do that. Instead, the target is responsible from marking
2207 breakpoints out as soon as it detects an exec. We don't do that
2208 here instead, because there may be other attempts to delete
2209 breakpoints after detecting an exec and before reaching here. */
2210 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2211 if (bploc
->pspace
== current_program_space
)
2212 gdb_assert (!bploc
->inserted
);
2214 ALL_BREAKPOINTS_SAFE (b
, temp
)
2216 if (b
->pspace
!= current_program_space
)
2219 /* Solib breakpoints must be explicitly reset after an exec(). */
2220 if (b
->type
== bp_shlib_event
)
2222 delete_breakpoint (b
);
2226 /* JIT breakpoints must be explicitly reset after an exec(). */
2227 if (b
->type
== bp_jit_event
)
2229 delete_breakpoint (b
);
2233 /* Thread event breakpoints must be set anew after an exec(),
2234 as must overlay event and longjmp master breakpoints. */
2235 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2236 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
)
2238 delete_breakpoint (b
);
2242 /* Step-resume breakpoints are meaningless after an exec(). */
2243 if (b
->type
== bp_step_resume
)
2245 delete_breakpoint (b
);
2249 /* Longjmp and longjmp-resume breakpoints are also meaningless
2251 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2253 delete_breakpoint (b
);
2257 if (b
->type
== bp_catchpoint
)
2259 /* For now, none of the bp_catchpoint breakpoints need to
2260 do anything at this point. In the future, if some of
2261 the catchpoints need to something, we will need to add
2262 a new method, and call this method from here. */
2266 /* bp_finish is a special case. The only way we ought to be able
2267 to see one of these when an exec() has happened, is if the user
2268 caught a vfork, and then said "finish". Ordinarily a finish just
2269 carries them to the call-site of the current callee, by setting
2270 a temporary bp there and resuming. But in this case, the finish
2271 will carry them entirely through the vfork & exec.
2273 We don't want to allow a bp_finish to remain inserted now. But
2274 we can't safely delete it, 'cause finish_command has a handle to
2275 the bp on a bpstat, and will later want to delete it. There's a
2276 chance (and I've seen it happen) that if we delete the bp_finish
2277 here, that its storage will get reused by the time finish_command
2278 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2279 We really must allow finish_command to delete a bp_finish.
2281 In the absense of a general solution for the "how do we know
2282 it's safe to delete something others may have handles to?"
2283 problem, what we'll do here is just uninsert the bp_finish, and
2284 let finish_command delete it.
2286 (We know the bp_finish is "doomed" in the sense that it's
2287 momentary, and will be deleted as soon as finish_command sees
2288 the inferior stopped. So it doesn't matter that the bp's
2289 address is probably bogus in the new a.out, unlike e.g., the
2290 solib breakpoints.) */
2292 if (b
->type
== bp_finish
)
2297 /* Without a symbolic address, we have little hope of the
2298 pre-exec() address meaning the same thing in the post-exec()
2300 if (b
->addr_string
== NULL
)
2302 delete_breakpoint (b
);
2306 /* FIXME what about longjmp breakpoints? Re-create them here? */
2307 create_overlay_event_breakpoint ("_ovly_debug_event");
2308 create_longjmp_master_breakpoint ("longjmp");
2309 create_longjmp_master_breakpoint ("_longjmp");
2310 create_longjmp_master_breakpoint ("siglongjmp");
2311 create_longjmp_master_breakpoint ("_siglongjmp");
2312 create_std_terminate_master_breakpoint ("std::terminate()");
2316 detach_breakpoints (int pid
)
2318 struct bp_location
*b
, **bp_tmp
;
2320 struct cleanup
*old_chain
= save_inferior_ptid ();
2321 struct inferior
*inf
= current_inferior ();
2323 if (pid
== PIDGET (inferior_ptid
))
2324 error (_("Cannot detach breakpoints of inferior_ptid"));
2326 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2327 inferior_ptid
= pid_to_ptid (pid
);
2328 ALL_BP_LOCATIONS (b
, bp_tmp
)
2330 if (b
->pspace
!= inf
->pspace
)
2334 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2336 do_cleanups (old_chain
);
2340 /* Remove the breakpoint location B from the current address space.
2341 Note that this is used to detach breakpoints from a child fork.
2342 When we get here, the child isn't in the inferior list, and neither
2343 do we have objects to represent its address space --- we should
2344 *not* look at b->pspace->aspace here. */
2347 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2350 struct cleanup
*old_chain
;
2352 if (b
->owner
->enable_state
== bp_permanent
)
2353 /* Permanent breakpoints cannot be inserted or removed. */
2356 /* The type of none suggests that owner is actually deleted.
2357 This should not ever happen. */
2358 gdb_assert (b
->owner
->type
!= bp_none
);
2360 if (b
->loc_type
== bp_loc_software_breakpoint
2361 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2363 /* "Normal" instruction breakpoint: either the standard
2364 trap-instruction bp (bp_breakpoint), or a
2365 bp_hardware_breakpoint. */
2367 /* First check to see if we have to handle an overlay. */
2368 if (overlay_debugging
== ovly_off
2369 || b
->section
== NULL
2370 || !(section_is_overlay (b
->section
)))
2372 /* No overlay handling: just remove the breakpoint. */
2374 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2375 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2377 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2381 /* This breakpoint is in an overlay section.
2382 Did we set a breakpoint at the LMA? */
2383 if (!overlay_events_enabled
)
2385 /* Yes -- overlay event support is not active, so we
2386 should have set a breakpoint at the LMA. Remove it.
2388 /* Ignore any failures: if the LMA is in ROM, we will
2389 have already warned when we failed to insert it. */
2390 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2391 target_remove_hw_breakpoint (b
->gdbarch
,
2392 &b
->overlay_target_info
);
2394 target_remove_breakpoint (b
->gdbarch
,
2395 &b
->overlay_target_info
);
2397 /* Did we set a breakpoint at the VMA?
2398 If so, we will have marked the breakpoint 'inserted'. */
2401 /* Yes -- remove it. Previously we did not bother to
2402 remove the breakpoint if the section had been
2403 unmapped, but let's not rely on that being safe. We
2404 don't know what the overlay manager might do. */
2405 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2406 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2409 /* However, we should remove *software* breakpoints only
2410 if the section is still mapped, or else we overwrite
2411 wrong code with the saved shadow contents. */
2412 else if (section_is_mapped (b
->section
))
2413 val
= target_remove_breakpoint (b
->gdbarch
,
2420 /* No -- not inserted, so no need to remove. No error. */
2425 /* In some cases, we might not be able to remove a breakpoint
2426 in a shared library that has already been removed, but we
2427 have not yet processed the shlib unload event. */
2428 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2433 b
->inserted
= (is
== mark_inserted
);
2435 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2440 b
->inserted
= (is
== mark_inserted
);
2441 val
= target_remove_watchpoint (b
->address
, b
->length
,
2442 b
->watchpoint_type
);
2444 /* Failure to remove any of the hardware watchpoints comes here. */
2445 if ((is
== mark_uninserted
) && (b
->inserted
))
2446 warning (_("Could not remove hardware watchpoint %d."),
2449 else if (b
->owner
->type
== bp_catchpoint
2450 && breakpoint_enabled (b
->owner
)
2453 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2455 val
= b
->owner
->ops
->remove (b
->owner
);
2458 b
->inserted
= (is
== mark_inserted
);
2465 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2468 struct cleanup
*old_chain
;
2470 if (b
->owner
->enable_state
== bp_permanent
)
2471 /* Permanent breakpoints cannot be inserted or removed. */
2474 /* The type of none suggests that owner is actually deleted.
2475 This should not ever happen. */
2476 gdb_assert (b
->owner
->type
!= bp_none
);
2478 old_chain
= save_current_space_and_thread ();
2480 switch_to_program_space_and_thread (b
->pspace
);
2482 ret
= remove_breakpoint_1 (b
, is
);
2484 do_cleanups (old_chain
);
2488 /* Clear the "inserted" flag in all breakpoints. */
2491 mark_breakpoints_out (void)
2493 struct bp_location
*bpt
, **bptp_tmp
;
2495 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2496 if (bpt
->pspace
== current_program_space
)
2500 /* Clear the "inserted" flag in all breakpoints and delete any
2501 breakpoints which should go away between runs of the program.
2503 Plus other such housekeeping that has to be done for breakpoints
2506 Note: this function gets called at the end of a run (by
2507 generic_mourn_inferior) and when a run begins (by
2508 init_wait_for_inferior). */
2513 breakpoint_init_inferior (enum inf_context context
)
2515 struct breakpoint
*b
, *temp
;
2516 struct bp_location
*bpt
, **bptp_tmp
;
2518 struct program_space
*pspace
= current_program_space
;
2520 /* If breakpoint locations are shared across processes, then there's
2522 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2525 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2527 if (bpt
->pspace
== pspace
2528 && bpt
->owner
->enable_state
!= bp_permanent
)
2532 ALL_BREAKPOINTS_SAFE (b
, temp
)
2534 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2541 /* If the call dummy breakpoint is at the entry point it will
2542 cause problems when the inferior is rerun, so we better get
2545 case bp_watchpoint_scope
:
2547 /* Also get rid of scope breakpoints. */
2549 case bp_shlib_event
:
2551 /* Also remove solib event breakpoints. Their addresses may
2552 have changed since the last time we ran the program.
2553 Actually we may now be debugging against different target;
2554 and so the solib backend that installed this breakpoint may
2555 not be used in by the target. E.g.,
2557 (gdb) file prog-linux
2558 (gdb) run # native linux target
2561 (gdb) file prog-win.exe
2562 (gdb) tar rem :9999 # remote Windows gdbserver.
2565 delete_breakpoint (b
);
2569 case bp_hardware_watchpoint
:
2570 case bp_read_watchpoint
:
2571 case bp_access_watchpoint
:
2573 /* Likewise for watchpoints on local expressions. */
2574 if (b
->exp_valid_block
!= NULL
)
2575 delete_breakpoint (b
);
2576 else if (context
== inf_starting
)
2578 /* Reset val field to force reread of starting value
2579 in insert_breakpoints. */
2581 value_free (b
->val
);
2591 /* Get rid of the moribund locations. */
2592 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2593 free_bp_location (bpt
);
2594 VEC_free (bp_location_p
, moribund_locations
);
2597 /* These functions concern about actual breakpoints inserted in the
2598 target --- to e.g. check if we need to do decr_pc adjustment or if
2599 we need to hop over the bkpt --- so we check for address space
2600 match, not program space. */
2602 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2603 exists at PC. It returns ordinary_breakpoint_here if it's an
2604 ordinary breakpoint, or permanent_breakpoint_here if it's a
2605 permanent breakpoint.
2606 - When continuing from a location with an ordinary breakpoint, we
2607 actually single step once before calling insert_breakpoints.
2608 - When continuing from a localion with a permanent breakpoint, we
2609 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2610 the target, to advance the PC past the breakpoint. */
2612 enum breakpoint_here
2613 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2615 struct bp_location
*bpt
, **bptp_tmp
;
2616 int any_breakpoint_here
= 0;
2618 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2620 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2621 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2624 if ((breakpoint_enabled (bpt
->owner
)
2625 || bpt
->owner
->enable_state
== bp_permanent
)
2626 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2629 if (overlay_debugging
2630 && section_is_overlay (bpt
->section
)
2631 && !section_is_mapped (bpt
->section
))
2632 continue; /* unmapped overlay -- can't be a match */
2633 else if (bpt
->owner
->enable_state
== bp_permanent
)
2634 return permanent_breakpoint_here
;
2636 any_breakpoint_here
= 1;
2640 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2643 /* Return true if there's a moribund breakpoint at PC. */
2646 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2648 struct bp_location
*loc
;
2651 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2652 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2659 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2660 inserted using regular breakpoint_chain / bp_location array mechanism.
2661 This does not check for single-step breakpoints, which are
2662 inserted and removed using direct target manipulation. */
2665 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2667 struct bp_location
*bpt
, **bptp_tmp
;
2669 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2671 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2672 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2676 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2679 if (overlay_debugging
2680 && section_is_overlay (bpt
->section
)
2681 && !section_is_mapped (bpt
->section
))
2682 continue; /* unmapped overlay -- can't be a match */
2690 /* Returns non-zero iff there's either regular breakpoint
2691 or a single step breakpoint inserted at PC. */
2694 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2696 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2699 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2705 /* This function returns non-zero iff there is a software breakpoint
2709 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2711 struct bp_location
*bpt
, **bptp_tmp
;
2712 int any_breakpoint_here
= 0;
2714 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2716 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2720 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2723 if (overlay_debugging
2724 && section_is_overlay (bpt
->section
)
2725 && !section_is_mapped (bpt
->section
))
2726 continue; /* unmapped overlay -- can't be a match */
2732 /* Also check for software single-step breakpoints. */
2733 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2740 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2741 CORE_ADDR addr
, ULONGEST len
)
2743 struct breakpoint
*bpt
;
2745 ALL_BREAKPOINTS (bpt
)
2747 struct bp_location
*loc
;
2749 if (bpt
->type
!= bp_hardware_watchpoint
2750 && bpt
->type
!= bp_access_watchpoint
)
2753 if (!breakpoint_enabled (bpt
))
2756 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2757 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2761 /* Check for intersection. */
2762 l
= max (loc
->address
, addr
);
2763 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2771 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2772 PC is valid for process/thread PTID. */
2775 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2778 struct bp_location
*bpt
, **bptp_tmp
;
2779 /* The thread and task IDs associated to PTID, computed lazily. */
2783 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2785 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2786 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2789 if (!breakpoint_enabled (bpt
->owner
)
2790 && bpt
->owner
->enable_state
!= bp_permanent
)
2793 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2797 if (bpt
->owner
->thread
!= -1)
2799 /* This is a thread-specific breakpoint. Check that ptid
2800 matches that thread. If thread hasn't been computed yet,
2801 it is now time to do so. */
2803 thread
= pid_to_thread_id (ptid
);
2804 if (bpt
->owner
->thread
!= thread
)
2808 if (bpt
->owner
->task
!= 0)
2810 /* This is a task-specific breakpoint. Check that ptid
2811 matches that task. If task hasn't been computed yet,
2812 it is now time to do so. */
2814 task
= ada_get_task_number (ptid
);
2815 if (bpt
->owner
->task
!= task
)
2819 if (overlay_debugging
2820 && section_is_overlay (bpt
->section
)
2821 && !section_is_mapped (bpt
->section
))
2822 continue; /* unmapped overlay -- can't be a match */
2831 /* bpstat stuff. External routines' interfaces are documented
2835 ep_is_catchpoint (struct breakpoint
*ep
)
2837 return (ep
->type
== bp_catchpoint
);
2841 bpstat_free (bpstat bs
)
2843 if (bs
->old_val
!= NULL
)
2844 value_free (bs
->old_val
);
2845 decref_counted_command_line (&bs
->commands
);
2849 /* Clear a bpstat so that it says we are not at any breakpoint.
2850 Also free any storage that is part of a bpstat. */
2853 bpstat_clear (bpstat
*bsp
)
2870 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2871 is part of the bpstat is copied as well. */
2874 bpstat_copy (bpstat bs
)
2878 bpstat retval
= NULL
;
2883 for (; bs
!= NULL
; bs
= bs
->next
)
2885 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2886 memcpy (tmp
, bs
, sizeof (*tmp
));
2887 incref_counted_command_line (tmp
->commands
);
2888 if (bs
->old_val
!= NULL
)
2890 tmp
->old_val
= value_copy (bs
->old_val
);
2891 release_value (tmp
->old_val
);
2895 /* This is the first thing in the chain. */
2905 /* Find the bpstat associated with this breakpoint */
2908 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2913 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2915 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2921 /* Find a step_resume breakpoint associated with this bpstat.
2922 (If there are multiple step_resume bp's on the list, this function
2923 will arbitrarily pick one.)
2925 It is an error to use this function if BPSTAT doesn't contain a
2926 step_resume breakpoint.
2928 See wait_for_inferior's use of this function. */
2930 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2934 gdb_assert (bsp
!= NULL
);
2936 current_thread
= pid_to_thread_id (inferior_ptid
);
2938 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2940 if ((bsp
->breakpoint_at
!= NULL
)
2941 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2942 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2943 || bsp
->breakpoint_at
->owner
->thread
== -1))
2944 return bsp
->breakpoint_at
->owner
;
2947 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2951 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2952 at. *BSP upon return is a bpstat which points to the remaining
2953 breakpoints stopped at (but which is not guaranteed to be good for
2954 anything but further calls to bpstat_num).
2955 Return 0 if passed a bpstat which does not indicate any breakpoints.
2956 Return -1 if stopped at a breakpoint that has been deleted since
2958 Return 1 otherwise. */
2961 bpstat_num (bpstat
*bsp
, int *num
)
2963 struct breakpoint
*b
;
2966 return 0; /* No more breakpoint values */
2968 /* We assume we'll never have several bpstats that
2969 correspond to a single breakpoint -- otherwise,
2970 this function might return the same number more
2971 than once and this will look ugly. */
2972 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2973 *bsp
= (*bsp
)->next
;
2975 return -1; /* breakpoint that's been deleted since */
2977 *num
= b
->number
; /* We have its number */
2981 /* Modify BS so that the actions will not be performed. */
2984 bpstat_clear_actions (bpstat bs
)
2986 for (; bs
!= NULL
; bs
= bs
->next
)
2988 decref_counted_command_line (&bs
->commands
);
2989 bs
->commands_left
= NULL
;
2990 if (bs
->old_val
!= NULL
)
2992 value_free (bs
->old_val
);
2998 /* Called when a command is about to proceed the inferior. */
3001 breakpoint_about_to_proceed (void)
3003 if (!ptid_equal (inferior_ptid
, null_ptid
))
3005 struct thread_info
*tp
= inferior_thread ();
3007 /* Allow inferior function calls in breakpoint commands to not
3008 interrupt the command list. When the call finishes
3009 successfully, the inferior will be standing at the same
3010 breakpoint as if nothing happened. */
3015 breakpoint_proceeded
= 1;
3018 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3020 cleanup_executing_breakpoints (void *ignore
)
3022 executing_breakpoint_commands
= 0;
3025 /* Execute all the commands associated with all the breakpoints at this
3026 location. Any of these commands could cause the process to proceed
3027 beyond this point, etc. We look out for such changes by checking
3028 the global "breakpoint_proceeded" after each command.
3030 Returns true if a breakpoint command resumed the inferior. In that
3031 case, it is the caller's responsibility to recall it again with the
3032 bpstat of the current thread. */
3035 bpstat_do_actions_1 (bpstat
*bsp
)
3038 struct cleanup
*old_chain
;
3041 /* Avoid endless recursion if a `source' command is contained
3043 if (executing_breakpoint_commands
)
3046 executing_breakpoint_commands
= 1;
3047 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3049 /* This pointer will iterate over the list of bpstat's. */
3052 breakpoint_proceeded
= 0;
3053 for (; bs
!= NULL
; bs
= bs
->next
)
3055 struct counted_command_line
*ccmd
;
3056 struct command_line
*cmd
;
3057 struct cleanup
*this_cmd_tree_chain
;
3059 /* Take ownership of the BSP's command tree, if it has one.
3061 The command tree could legitimately contain commands like
3062 'step' and 'next', which call clear_proceed_status, which
3063 frees stop_bpstat's command tree. To make sure this doesn't
3064 free the tree we're executing out from under us, we need to
3065 take ownership of the tree ourselves. Since a given bpstat's
3066 commands are only executed once, we don't need to copy it; we
3067 can clear the pointer in the bpstat, and make sure we free
3068 the tree when we're done. */
3069 ccmd
= bs
->commands
;
3070 bs
->commands
= NULL
;
3072 = make_cleanup_decref_counted_command_line (&ccmd
);
3073 cmd
= bs
->commands_left
;
3074 bs
->commands_left
= NULL
;
3078 execute_control_command (cmd
);
3080 if (breakpoint_proceeded
)
3086 /* We can free this command tree now. */
3087 do_cleanups (this_cmd_tree_chain
);
3089 if (breakpoint_proceeded
)
3091 if (target_can_async_p ())
3092 /* If we are in async mode, then the target might be still
3093 running, not stopped at any breakpoint, so nothing for
3094 us to do here -- just return to the event loop. */
3097 /* In sync mode, when execute_control_command returns
3098 we're already standing on the next breakpoint.
3099 Breakpoint commands for that stop were not run, since
3100 execute_command does not run breakpoint commands --
3101 only command_line_handler does, but that one is not
3102 involved in execution of breakpoint commands. So, we
3103 can now execute breakpoint commands. It should be
3104 noted that making execute_command do bpstat actions is
3105 not an option -- in this case we'll have recursive
3106 invocation of bpstat for each breakpoint with a
3107 command, and can easily blow up GDB stack. Instead, we
3108 return true, which will trigger the caller to recall us
3109 with the new stop_bpstat. */
3114 do_cleanups (old_chain
);
3119 bpstat_do_actions (void)
3121 /* Do any commands attached to breakpoint we are stopped at. */
3122 while (!ptid_equal (inferior_ptid
, null_ptid
)
3123 && target_has_execution
3124 && !is_exited (inferior_ptid
)
3125 && !is_executing (inferior_ptid
))
3126 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3127 and only return when it is stopped at the next breakpoint, we
3128 keep doing breakpoint actions until it returns false to
3129 indicate the inferior was not resumed. */
3130 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3134 /* Print out the (old or new) value associated with a watchpoint. */
3137 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3140 fprintf_unfiltered (stream
, _("<unreadable>"));
3143 struct value_print_options opts
;
3144 get_user_print_options (&opts
);
3145 value_print (val
, stream
, &opts
);
3149 /* This is the normal print function for a bpstat. In the future,
3150 much of this logic could (should?) be moved to bpstat_stop_status,
3151 by having it set different print_it values.
3153 Current scheme: When we stop, bpstat_print() is called. It loops
3154 through the bpstat list of things causing this stop, calling the
3155 print_bp_stop_message function on each one. The behavior of the
3156 print_bp_stop_message function depends on the print_it field of
3157 bpstat. If such field so indicates, call this function here.
3159 Return values from this routine (ultimately used by bpstat_print()
3160 and normal_stop() to decide what to do):
3161 PRINT_NOTHING: Means we already printed all we needed to print,
3162 don't print anything else.
3163 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3164 that something to be followed by a location.
3165 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3166 that something to be followed by a location.
3167 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3170 static enum print_stop_action
3171 print_it_typical (bpstat bs
)
3173 struct cleanup
*old_chain
;
3174 struct breakpoint
*b
;
3175 const struct bp_location
*bl
;
3176 struct ui_stream
*stb
;
3178 enum print_stop_action result
;
3180 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3181 which has since been deleted. */
3182 if (bs
->breakpoint_at
== NULL
)
3183 return PRINT_UNKNOWN
;
3184 bl
= bs
->breakpoint_at
;
3187 stb
= ui_out_stream_new (uiout
);
3188 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3193 case bp_hardware_breakpoint
:
3194 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3195 if (bl
->address
!= bl
->requested_address
)
3196 breakpoint_adjustment_warning (bl
->requested_address
,
3199 annotate_breakpoint (b
->number
);
3201 ui_out_text (uiout
, "\nTemporary breakpoint ");
3203 ui_out_text (uiout
, "\nBreakpoint ");
3204 if (ui_out_is_mi_like_p (uiout
))
3206 ui_out_field_string (uiout
, "reason",
3207 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3208 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3210 ui_out_field_int (uiout
, "bkptno", b
->number
);
3211 ui_out_text (uiout
, ", ");
3212 result
= PRINT_SRC_AND_LOC
;
3215 case bp_shlib_event
:
3216 /* Did we stop because the user set the stop_on_solib_events
3217 variable? (If so, we report this as a generic, "Stopped due
3218 to shlib event" message.) */
3219 printf_filtered (_("Stopped due to shared library event\n"));
3220 result
= PRINT_NOTHING
;
3223 case bp_thread_event
:
3224 /* Not sure how we will get here.
3225 GDB should not stop for these breakpoints. */
3226 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3227 result
= PRINT_NOTHING
;
3230 case bp_overlay_event
:
3231 /* By analogy with the thread event, GDB should not stop for these. */
3232 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3233 result
= PRINT_NOTHING
;
3236 case bp_longjmp_master
:
3237 /* These should never be enabled. */
3238 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3239 result
= PRINT_NOTHING
;
3242 case bp_std_terminate_master
:
3243 /* These should never be enabled. */
3244 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3245 result
= PRINT_NOTHING
;
3249 case bp_hardware_watchpoint
:
3250 annotate_watchpoint (b
->number
);
3251 if (ui_out_is_mi_like_p (uiout
))
3254 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3256 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3257 ui_out_text (uiout
, "\nOld value = ");
3258 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3259 ui_out_field_stream (uiout
, "old", stb
);
3260 ui_out_text (uiout
, "\nNew value = ");
3261 watchpoint_value_print (b
->val
, stb
->stream
);
3262 ui_out_field_stream (uiout
, "new", stb
);
3263 ui_out_text (uiout
, "\n");
3264 /* More than one watchpoint may have been triggered. */
3265 result
= PRINT_UNKNOWN
;
3268 case bp_read_watchpoint
:
3269 if (ui_out_is_mi_like_p (uiout
))
3272 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3274 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3275 ui_out_text (uiout
, "\nValue = ");
3276 watchpoint_value_print (b
->val
, stb
->stream
);
3277 ui_out_field_stream (uiout
, "value", stb
);
3278 ui_out_text (uiout
, "\n");
3279 result
= PRINT_UNKNOWN
;
3282 case bp_access_watchpoint
:
3283 if (bs
->old_val
!= NULL
)
3285 annotate_watchpoint (b
->number
);
3286 if (ui_out_is_mi_like_p (uiout
))
3289 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3291 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3292 ui_out_text (uiout
, "\nOld value = ");
3293 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3294 ui_out_field_stream (uiout
, "old", stb
);
3295 ui_out_text (uiout
, "\nNew value = ");
3300 if (ui_out_is_mi_like_p (uiout
))
3303 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3304 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3305 ui_out_text (uiout
, "\nValue = ");
3307 watchpoint_value_print (b
->val
, stb
->stream
);
3308 ui_out_field_stream (uiout
, "new", stb
);
3309 ui_out_text (uiout
, "\n");
3310 result
= PRINT_UNKNOWN
;
3313 /* Fall through, we don't deal with these types of breakpoints
3317 if (ui_out_is_mi_like_p (uiout
))
3320 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3321 result
= PRINT_UNKNOWN
;
3325 if (ui_out_is_mi_like_p (uiout
))
3328 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3329 result
= PRINT_UNKNOWN
;
3334 case bp_longjmp_resume
:
3335 case bp_step_resume
:
3336 case bp_watchpoint_scope
:
3338 case bp_std_terminate
:
3340 case bp_fast_tracepoint
:
3343 result
= PRINT_UNKNOWN
;
3347 do_cleanups (old_chain
);
3351 /* Generic routine for printing messages indicating why we
3352 stopped. The behavior of this function depends on the value
3353 'print_it' in the bpstat structure. Under some circumstances we
3354 may decide not to print anything here and delegate the task to
3357 static enum print_stop_action
3358 print_bp_stop_message (bpstat bs
)
3360 switch (bs
->print_it
)
3363 /* Nothing should be printed for this bpstat entry. */
3364 return PRINT_UNKNOWN
;
3368 /* We still want to print the frame, but we already printed the
3369 relevant messages. */
3370 return PRINT_SRC_AND_LOC
;
3373 case print_it_normal
:
3375 const struct bp_location
*bl
= bs
->breakpoint_at
;
3376 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3378 /* Normal case. Call the breakpoint's print_it method, or
3379 print_it_typical. */
3380 /* FIXME: how breakpoint can ever be NULL here? */
3381 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3382 return b
->ops
->print_it (b
);
3384 return print_it_typical (bs
);
3389 internal_error (__FILE__
, __LINE__
,
3390 _("print_bp_stop_message: unrecognized enum value"));
3395 /* Print a message indicating what happened. This is called from
3396 normal_stop(). The input to this routine is the head of the bpstat
3397 list - a list of the eventpoints that caused this stop. This
3398 routine calls the generic print routine for printing a message
3399 about reasons for stopping. This will print (for example) the
3400 "Breakpoint n," part of the output. The return value of this
3403 PRINT_UNKNOWN: Means we printed nothing
3404 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3405 code to print the location. An example is
3406 "Breakpoint 1, " which should be followed by
3408 PRINT_SRC_ONLY: Means we printed something, but there is no need
3409 to also print the location part of the message.
3410 An example is the catch/throw messages, which
3411 don't require a location appended to the end.
3412 PRINT_NOTHING: We have done some printing and we don't need any
3413 further info to be printed.*/
3415 enum print_stop_action
3416 bpstat_print (bpstat bs
)
3420 /* Maybe another breakpoint in the chain caused us to stop.
3421 (Currently all watchpoints go on the bpstat whether hit or not.
3422 That probably could (should) be changed, provided care is taken
3423 with respect to bpstat_explains_signal). */
3424 for (; bs
; bs
= bs
->next
)
3426 val
= print_bp_stop_message (bs
);
3427 if (val
== PRINT_SRC_ONLY
3428 || val
== PRINT_SRC_AND_LOC
3429 || val
== PRINT_NOTHING
)
3433 /* We reached the end of the chain, or we got a null BS to start
3434 with and nothing was printed. */
3435 return PRINT_UNKNOWN
;
3438 /* Evaluate the expression EXP and return 1 if value is zero.
3439 This is used inside a catch_errors to evaluate the breakpoint condition.
3440 The argument is a "struct expression *" that has been cast to char * to
3441 make it pass through catch_errors. */
3444 breakpoint_cond_eval (void *exp
)
3446 struct value
*mark
= value_mark ();
3447 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3448 value_free_to_mark (mark
);
3452 /* Allocate a new bpstat and chain it to the current one. */
3455 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3459 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3461 bs
->breakpoint_at
= bl
;
3462 /* If the condition is false, etc., don't do the commands. */
3463 bs
->commands
= NULL
;
3464 bs
->commands_left
= NULL
;
3466 bs
->print_it
= print_it_normal
;
3470 /* The target has stopped with waitstatus WS. Check if any hardware
3471 watchpoints have triggered, according to the target. */
3474 watchpoints_triggered (struct target_waitstatus
*ws
)
3476 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3478 struct breakpoint
*b
;
3480 if (!stopped_by_watchpoint
)
3482 /* We were not stopped by a watchpoint. Mark all watchpoints
3483 as not triggered. */
3485 if (b
->type
== bp_hardware_watchpoint
3486 || b
->type
== bp_read_watchpoint
3487 || b
->type
== bp_access_watchpoint
)
3488 b
->watchpoint_triggered
= watch_triggered_no
;
3493 if (!target_stopped_data_address (¤t_target
, &addr
))
3495 /* We were stopped by a watchpoint, but we don't know where.
3496 Mark all watchpoints as unknown. */
3498 if (b
->type
== bp_hardware_watchpoint
3499 || b
->type
== bp_read_watchpoint
3500 || b
->type
== bp_access_watchpoint
)
3501 b
->watchpoint_triggered
= watch_triggered_unknown
;
3503 return stopped_by_watchpoint
;
3506 /* The target could report the data address. Mark watchpoints
3507 affected by this data address as triggered, and all others as not
3511 if (b
->type
== bp_hardware_watchpoint
3512 || b
->type
== bp_read_watchpoint
3513 || b
->type
== bp_access_watchpoint
)
3515 struct bp_location
*loc
;
3518 b
->watchpoint_triggered
= watch_triggered_no
;
3519 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3520 /* Exact match not required. Within range is
3522 if (target_watchpoint_addr_within_range (¤t_target
,
3526 b
->watchpoint_triggered
= watch_triggered_yes
;
3534 /* Possible return values for watchpoint_check (this can't be an enum
3535 because of check_errors). */
3536 /* The watchpoint has been deleted. */
3537 #define WP_DELETED 1
3538 /* The value has changed. */
3539 #define WP_VALUE_CHANGED 2
3540 /* The value has not changed. */
3541 #define WP_VALUE_NOT_CHANGED 3
3542 /* Ignore this watchpoint, no matter if the value changed or not. */
3545 #define BP_TEMPFLAG 1
3546 #define BP_HARDWAREFLAG 2
3548 /* Evaluate watchpoint condition expression and check if its value changed.
3550 P should be a pointer to struct bpstat, but is defined as a void *
3551 in order for this function to be usable with catch_errors. */
3554 watchpoint_check (void *p
)
3556 bpstat bs
= (bpstat
) p
;
3557 struct breakpoint
*b
;
3558 struct frame_info
*fr
;
3559 int within_current_scope
;
3561 b
= bs
->breakpoint_at
->owner
;
3563 /* If this is a local watchpoint, we only want to check if the
3564 watchpoint frame is in scope if the current thread is the thread
3565 that was used to create the watchpoint. */
3566 if (!watchpoint_in_thread_scope (b
))
3569 if (b
->exp_valid_block
== NULL
)
3570 within_current_scope
= 1;
3573 struct frame_info
*frame
= get_current_frame ();
3574 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3575 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3577 /* in_function_epilogue_p() returns a non-zero value if we're still
3578 in the function but the stack frame has already been invalidated.
3579 Since we can't rely on the values of local variables after the
3580 stack has been destroyed, we are treating the watchpoint in that
3581 state as `not changed' without further checking. Don't mark
3582 watchpoints as changed if the current frame is in an epilogue -
3583 even if they are in some other frame, our view of the stack
3584 is likely to be wrong and frame_find_by_id could error out. */
3585 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3588 fr
= frame_find_by_id (b
->watchpoint_frame
);
3589 within_current_scope
= (fr
!= NULL
);
3591 /* If we've gotten confused in the unwinder, we might have
3592 returned a frame that can't describe this variable. */
3593 if (within_current_scope
)
3595 struct symbol
*function
;
3597 function
= get_frame_function (fr
);
3598 if (function
== NULL
3599 || !contained_in (b
->exp_valid_block
,
3600 SYMBOL_BLOCK_VALUE (function
)))
3601 within_current_scope
= 0;
3604 if (within_current_scope
)
3605 /* If we end up stopping, the current frame will get selected
3606 in normal_stop. So this call to select_frame won't affect
3611 if (within_current_scope
)
3613 /* We use value_{,free_to_}mark because it could be a
3614 *long* time before we return to the command level and
3615 call free_all_values. We can't call free_all_values because
3616 we might be in the middle of evaluating a function call. */
3618 struct value
*mark
= value_mark ();
3619 struct value
*new_val
;
3621 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3623 /* We use value_equal_contents instead of value_equal because the latter
3624 coerces an array to a pointer, thus comparing just the address of the
3625 array instead of its contents. This is not what we want. */
3626 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3627 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3629 if (new_val
!= NULL
)
3631 release_value (new_val
);
3632 value_free_to_mark (mark
);
3634 bs
->old_val
= b
->val
;
3637 return WP_VALUE_CHANGED
;
3641 /* Nothing changed. */
3642 value_free_to_mark (mark
);
3643 return WP_VALUE_NOT_CHANGED
;
3648 /* This seems like the only logical thing to do because
3649 if we temporarily ignored the watchpoint, then when
3650 we reenter the block in which it is valid it contains
3651 garbage (in the case of a function, it may have two
3652 garbage values, one before and one after the prologue).
3653 So we can't even detect the first assignment to it and
3654 watch after that (since the garbage may or may not equal
3655 the first value assigned). */
3656 /* We print all the stop information in print_it_typical(), but
3657 in this case, by the time we call print_it_typical() this bp
3658 will be deleted already. So we have no choice but print the
3659 information here. */
3660 if (ui_out_is_mi_like_p (uiout
))
3662 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3663 ui_out_text (uiout
, "\nWatchpoint ");
3664 ui_out_field_int (uiout
, "wpnum", b
->number
);
3665 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3666 which its expression is valid.\n");
3668 if (b
->related_breakpoint
)
3670 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3671 b
->related_breakpoint
->related_breakpoint
= NULL
;
3672 b
->related_breakpoint
= NULL
;
3674 b
->disposition
= disp_del_at_next_stop
;
3680 /* Return true if it looks like target has stopped due to hitting
3681 breakpoint location BL. This function does not check if we
3682 should stop, only if BL explains the stop. */
3684 bpstat_check_location (const struct bp_location
*bl
,
3685 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3687 struct breakpoint
*b
= bl
->owner
;
3689 /* By definition, the inferior does not report stops at
3691 if (tracepoint_type (b
))
3694 if (b
->type
!= bp_watchpoint
3695 && b
->type
!= bp_hardware_watchpoint
3696 && b
->type
!= bp_read_watchpoint
3697 && b
->type
!= bp_access_watchpoint
3698 && b
->type
!= bp_hardware_breakpoint
3699 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3701 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3704 if (overlay_debugging
/* unmapped overlay section */
3705 && section_is_overlay (bl
->section
)
3706 && !section_is_mapped (bl
->section
))
3710 /* Continuable hardware watchpoints are treated as non-existent if the
3711 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3712 some data address). Otherwise gdb won't stop on a break instruction
3713 in the code (not from a breakpoint) when a hardware watchpoint has
3714 been defined. Also skip watchpoints which we know did not trigger
3715 (did not match the data address). */
3717 if ((b
->type
== bp_hardware_watchpoint
3718 || b
->type
== bp_read_watchpoint
3719 || b
->type
== bp_access_watchpoint
)
3720 && b
->watchpoint_triggered
== watch_triggered_no
)
3723 if (b
->type
== bp_hardware_breakpoint
)
3725 if (bl
->address
!= bp_addr
)
3727 if (overlay_debugging
/* unmapped overlay section */
3728 && section_is_overlay (bl
->section
)
3729 && !section_is_mapped (bl
->section
))
3733 if (b
->type
== bp_catchpoint
)
3735 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3736 if (!b
->ops
->breakpoint_hit (b
))
3743 /* If BS refers to a watchpoint, determine if the watched values
3744 has actually changed, and we should stop. If not, set BS->stop
3747 bpstat_check_watchpoint (bpstat bs
)
3749 const struct bp_location
*bl
= bs
->breakpoint_at
;
3750 struct breakpoint
*b
= bl
->owner
;
3752 if (b
->type
== bp_watchpoint
3753 || b
->type
== bp_read_watchpoint
3754 || b
->type
== bp_access_watchpoint
3755 || b
->type
== bp_hardware_watchpoint
)
3759 int must_check_value
= 0;
3761 if (b
->type
== bp_watchpoint
)
3762 /* For a software watchpoint, we must always check the
3764 must_check_value
= 1;
3765 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3766 /* We have a hardware watchpoint (read, write, or access)
3767 and the target earlier reported an address watched by
3769 must_check_value
= 1;
3770 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3771 && b
->type
== bp_hardware_watchpoint
)
3772 /* We were stopped by a hardware watchpoint, but the target could
3773 not report the data address. We must check the watchpoint's
3774 value. Access and read watchpoints are out of luck; without
3775 a data address, we can't figure it out. */
3776 must_check_value
= 1;
3778 if (must_check_value
)
3780 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3782 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3783 int e
= catch_errors (watchpoint_check
, bs
, message
,
3785 do_cleanups (cleanups
);
3789 /* We've already printed what needs to be printed. */
3790 bs
->print_it
= print_it_done
;
3794 bs
->print_it
= print_it_noop
;
3797 case WP_VALUE_CHANGED
:
3798 if (b
->type
== bp_read_watchpoint
)
3800 /* There are two cases to consider here:
3802 1. we're watching the triggered memory for reads.
3803 In that case, trust the target, and always report
3804 the watchpoint hit to the user. Even though
3805 reads don't cause value changes, the value may
3806 have changed since the last time it was read, and
3807 since we're not trapping writes, we will not see
3808 those, and as such we should ignore our notion of
3811 2. we're watching the triggered memory for both
3812 reads and writes. There are two ways this may
3815 2.1. this is a target that can't break on data
3816 reads only, but can break on accesses (reads or
3817 writes), such as e.g., x86. We detect this case
3818 at the time we try to insert read watchpoints.
3820 2.2. otherwise, the target supports read
3821 watchpoints, but, the user set an access or write
3822 watchpoint watching the same memory as this read
3825 If we're watching memory writes as well as reads,
3826 ignore watchpoint hits when we find that the
3827 value hasn't changed, as reads don't cause
3828 changes. This still gives false positives when
3829 the program writes the same value to memory as
3830 what there was already in memory (we will confuse
3831 it for a read), but it's much better than
3834 int other_write_watchpoint
= 0;
3836 if (bl
->watchpoint_type
== hw_read
)
3838 struct breakpoint
*other_b
;
3840 ALL_BREAKPOINTS (other_b
)
3841 if ((other_b
->type
== bp_hardware_watchpoint
3842 || other_b
->type
== bp_access_watchpoint
)
3843 && (other_b
->watchpoint_triggered
3844 == watch_triggered_yes
))
3846 other_write_watchpoint
= 1;
3851 if (other_write_watchpoint
3852 || bl
->watchpoint_type
== hw_access
)
3854 /* We're watching the same memory for writes,
3855 and the value changed since the last time we
3856 updated it, so this trap must be for a write.
3858 bs
->print_it
= print_it_noop
;
3863 case WP_VALUE_NOT_CHANGED
:
3864 if (b
->type
== bp_hardware_watchpoint
3865 || b
->type
== bp_watchpoint
)
3867 /* Don't stop: write watchpoints shouldn't fire if
3868 the value hasn't changed. */
3869 bs
->print_it
= print_it_noop
;
3877 /* Error from catch_errors. */
3878 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3879 if (b
->related_breakpoint
)
3880 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3881 b
->disposition
= disp_del_at_next_stop
;
3882 /* We've already printed what needs to be printed. */
3883 bs
->print_it
= print_it_done
;
3887 else /* must_check_value == 0 */
3889 /* This is a case where some watchpoint(s) triggered, but
3890 not at the address of this watchpoint, or else no
3891 watchpoint triggered after all. So don't print
3892 anything for this watchpoint. */
3893 bs
->print_it
= print_it_noop
;
3900 /* Check conditions (condition proper, frame, thread and ignore count)
3901 of breakpoint referred to by BS. If we should not stop for this
3902 breakpoint, set BS->stop to 0. */
3904 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3906 int thread_id
= pid_to_thread_id (ptid
);
3907 const struct bp_location
*bl
= bs
->breakpoint_at
;
3908 struct breakpoint
*b
= bl
->owner
;
3910 if (frame_id_p (b
->frame_id
)
3911 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3915 int value_is_zero
= 0;
3916 struct expression
*cond
;
3918 /* If this is a scope breakpoint, mark the associated
3919 watchpoint as triggered so that we will handle the
3920 out-of-scope event. We'll get to the watchpoint next
3922 if (b
->type
== bp_watchpoint_scope
)
3923 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3925 if (is_watchpoint (b
))
3930 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3932 int within_current_scope
= 1;
3934 /* We use value_mark and value_free_to_mark because it could
3935 be a long time before we return to the command level and
3936 call free_all_values. We can't call free_all_values
3937 because we might be in the middle of evaluating a
3939 struct value
*mark
= value_mark ();
3941 /* Need to select the frame, with all that implies so that
3942 the conditions will have the right context. Because we
3943 use the frame, we will not see an inlined function's
3944 variables when we arrive at a breakpoint at the start
3945 of the inlined function; the current frame will be the
3947 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3948 select_frame (get_current_frame ());
3951 struct frame_info
*frame
;
3953 /* For local watchpoint expressions, which particular
3954 instance of a local is being watched matters, so we
3955 keep track of the frame to evaluate the expression
3956 in. To evaluate the condition however, it doesn't
3957 really matter which instantiation of the function
3958 where the condition makes sense triggers the
3959 watchpoint. This allows an expression like "watch
3960 global if q > 10" set in `func', catch writes to
3961 global on all threads that call `func', or catch
3962 writes on all recursive calls of `func' by a single
3963 thread. We simply always evaluate the condition in
3964 the innermost frame that's executing where it makes
3965 sense to evaluate the condition. It seems
3967 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3969 select_frame (frame
);
3971 within_current_scope
= 0;
3973 if (within_current_scope
)
3975 = catch_errors (breakpoint_cond_eval
, cond
,
3976 "Error in testing breakpoint condition:\n",
3980 warning (_("Watchpoint condition cannot be tested "
3981 "in the current scope"));
3982 /* If we failed to set the right context for this
3983 watchpoint, unconditionally report it. */
3986 /* FIXME-someday, should give breakpoint # */
3987 value_free_to_mark (mark
);
3990 if (cond
&& value_is_zero
)
3994 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3998 else if (b
->ignore_count
> 0)
4001 annotate_ignore_count_change ();
4003 /* Increase the hit count even though we don't
4011 /* Get a bpstat associated with having just stopped at address
4012 BP_ADDR in thread PTID.
4014 Determine whether we stopped at a breakpoint, etc, or whether we
4015 don't understand this stop. Result is a chain of bpstat's such that:
4017 if we don't understand the stop, the result is a null pointer.
4019 if we understand why we stopped, the result is not null.
4021 Each element of the chain refers to a particular breakpoint or
4022 watchpoint at which we have stopped. (We may have stopped for
4023 several reasons concurrently.)
4025 Each element of the chain has valid next, breakpoint_at,
4026 commands, FIXME??? fields. */
4029 bpstat_stop_status (struct address_space
*aspace
,
4030 CORE_ADDR bp_addr
, ptid_t ptid
)
4032 struct breakpoint
*b
= NULL
;
4033 struct bp_location
*bl
, **blp_tmp
;
4034 struct bp_location
*loc
;
4035 /* Root of the chain of bpstat's */
4036 struct bpstats root_bs
[1];
4037 /* Pointer to the last thing in the chain currently. */
4038 bpstat bs
= root_bs
;
4040 int need_remove_insert
;
4042 /* ALL_BP_LOCATIONS iteration would break across
4043 update_global_location_list possibly executed by
4044 bpstat_check_breakpoint_conditions's inferior call. */
4048 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4051 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4053 /* For hardware watchpoints, we look only at the first location.
4054 The watchpoint_check function will work on entire expression,
4055 not the individual locations. For read watchopints, the
4056 watchpoints_triggered function have checked all locations
4058 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4061 if (bl
->shlib_disabled
)
4064 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4067 /* Come here if it's a watchpoint, or if the break address matches */
4069 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4071 /* Assume we stop. Should we find watchpoint that is not actually
4072 triggered, or if condition of breakpoint is false, we'll reset
4077 bpstat_check_watchpoint (bs
);
4081 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4082 || b
->type
== bp_longjmp_master
4083 || b
->type
== bp_std_terminate_master
)
4084 /* We do not stop for these. */
4087 bpstat_check_breakpoint_conditions (bs
, ptid
);
4093 /* We will stop here */
4094 if (b
->disposition
== disp_disable
)
4096 if (b
->enable_state
!= bp_permanent
)
4097 b
->enable_state
= bp_disabled
;
4098 update_global_location_list (0);
4102 bs
->commands
= b
->commands
;
4103 incref_counted_command_line (bs
->commands
);
4104 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4105 if (bs
->commands_left
4106 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4109 bs
->commands_left
->line
) == 0)))
4111 bs
->commands_left
= bs
->commands_left
->next
;
4116 /* Print nothing for this entry if we dont stop or dont print. */
4117 if (bs
->stop
== 0 || bs
->print
== 0)
4118 bs
->print_it
= print_it_noop
;
4122 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4124 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4127 bs
= bpstat_alloc (loc
, bs
);
4128 /* For hits of moribund locations, we should just proceed. */
4131 bs
->print_it
= print_it_noop
;
4135 bs
->next
= NULL
; /* Terminate the chain */
4137 /* If we aren't stopping, the value of some hardware watchpoint may
4138 not have changed, but the intermediate memory locations we are
4139 watching may have. Don't bother if we're stopping; this will get
4141 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4145 need_remove_insert
= 0;
4147 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4149 && bs
->breakpoint_at
->owner
4150 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4152 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4153 /* Updating watchpoints invalidates bs->breakpoint_at.
4154 Prevent further code from trying to use it. */
4155 bs
->breakpoint_at
= NULL
;
4156 need_remove_insert
= 1;
4159 if (need_remove_insert
)
4160 update_global_location_list (1);
4162 return root_bs
->next
;
4165 /* Tell what to do about this bpstat. */
4167 bpstat_what (bpstat bs
)
4169 /* Classify each bpstat as one of the following. */
4172 /* This bpstat element has no effect on the main_action. */
4175 /* There was a watchpoint, stop but don't print. */
4178 /* There was a watchpoint, stop and print. */
4181 /* There was a breakpoint but we're not stopping. */
4184 /* There was a breakpoint, stop but don't print. */
4187 /* There was a breakpoint, stop and print. */
4190 /* We hit the longjmp breakpoint. */
4193 /* We hit the longjmp_resume breakpoint. */
4196 /* We hit the step_resume breakpoint. */
4199 /* We hit the shared library event breakpoint. */
4202 /* We hit the jit event breakpoint. */
4205 /* This is just used to count how many enums there are. */
4209 /* Here is the table which drives this routine. So that we can
4210 format it pretty, we define some abbreviations for the
4211 enum bpstat_what codes. */
4212 #define kc BPSTAT_WHAT_KEEP_CHECKING
4213 #define ss BPSTAT_WHAT_STOP_SILENT
4214 #define sn BPSTAT_WHAT_STOP_NOISY
4215 #define sgl BPSTAT_WHAT_SINGLE
4216 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4217 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4218 #define sr BPSTAT_WHAT_STEP_RESUME
4219 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4220 #define jit BPSTAT_WHAT_CHECK_JIT
4222 /* "Can't happen." Might want to print an error message.
4223 abort() is not out of the question, but chances are GDB is just
4224 a bit confused, not unusable. */
4225 #define err BPSTAT_WHAT_STOP_NOISY
4227 /* Given an old action and a class, come up with a new action. */
4228 /* One interesting property of this table is that wp_silent is the same
4229 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4230 after stopping, the check for whether to step over a breakpoint
4231 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4232 reference to how we stopped. We retain separate wp_silent and
4233 bp_silent codes in case we want to change that someday.
4235 Another possibly interesting property of this table is that
4236 there's a partial ordering, priority-like, of the actions. Once
4237 you've decided that some action is appropriate, you'll never go
4238 back and decide something of a lower priority is better. The
4241 kc < jit clr sgl shl slr sn sr ss
4242 sgl < jit shl slr sn sr ss
4243 slr < jit err shl sn sr ss
4244 clr < jit err shl sn sr ss
4251 What I think this means is that we don't need a damned table
4252 here. If you just put the rows and columns in the right order,
4253 it'd look awfully regular. We could simply walk the bpstat list
4254 and choose the highest priority action we find, with a little
4255 logic to handle the 'err' cases. */
4257 /* step_resume entries: a step resume breakpoint overrides another
4258 breakpoint of signal handling (see comment in wait_for_inferior
4259 at where we set the step_resume breakpoint). */
4261 static const enum bpstat_what_main_action
4262 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4265 /* kc ss sn sgl slr clr sr shl jit */
4266 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4267 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4268 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4269 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4270 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4271 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4272 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4273 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4274 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4275 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4276 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4290 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4291 struct bpstat_what retval
;
4293 retval
.call_dummy
= STOP_NONE
;
4294 for (; bs
!= NULL
; bs
= bs
->next
)
4296 enum class bs_class
= no_effect
;
4297 if (bs
->breakpoint_at
== NULL
)
4298 /* I suspect this can happen if it was a momentary breakpoint
4299 which has since been deleted. */
4301 if (bs
->breakpoint_at
->owner
== NULL
)
4302 bs_class
= bp_nostop
;
4304 switch (bs
->breakpoint_at
->owner
->type
)
4310 case bp_hardware_breakpoint
:
4316 bs_class
= bp_noisy
;
4318 bs_class
= bp_silent
;
4321 bs_class
= bp_nostop
;
4324 case bp_hardware_watchpoint
:
4325 case bp_read_watchpoint
:
4326 case bp_access_watchpoint
:
4330 bs_class
= wp_noisy
;
4332 bs_class
= wp_silent
;
4335 /* There was a watchpoint, but we're not stopping.
4336 This requires no further action. */
4337 bs_class
= no_effect
;
4340 bs_class
= long_jump
;
4342 case bp_longjmp_resume
:
4343 bs_class
= long_resume
;
4345 case bp_step_resume
:
4348 bs_class
= step_resume
;
4351 /* It is for the wrong frame. */
4352 bs_class
= bp_nostop
;
4354 case bp_watchpoint_scope
:
4355 bs_class
= bp_nostop
;
4357 case bp_shlib_event
:
4358 bs_class
= shlib_event
;
4361 bs_class
= jit_event
;
4363 case bp_thread_event
:
4364 case bp_overlay_event
:
4365 case bp_longjmp_master
:
4366 case bp_std_terminate_master
:
4367 bs_class
= bp_nostop
;
4373 bs_class
= bp_noisy
;
4375 bs_class
= bp_silent
;
4378 /* There was a catchpoint, but we're not stopping.
4379 This requires no further action. */
4380 bs_class
= no_effect
;
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_STACK_DUMMY
;
4388 case bp_std_terminate
:
4389 /* Make sure the action is stop (silent or noisy),
4390 so infrun.c pops the dummy frame. */
4391 bs_class
= bp_silent
;
4392 retval
.call_dummy
= STOP_STD_TERMINATE
;
4395 case bp_fast_tracepoint
:
4396 /* Tracepoint hits should not be reported back to GDB, and
4397 if one got through somehow, it should have been filtered
4399 internal_error (__FILE__
, __LINE__
,
4400 _("bpstat_what: tracepoint encountered"));
4403 current_action
= table
[(int) bs_class
][(int) current_action
];
4405 retval
.main_action
= current_action
;
4409 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4410 without hardware support). This isn't related to a specific bpstat,
4411 just to things like whether watchpoints are set. */
4414 bpstat_should_step (void)
4416 struct breakpoint
*b
;
4418 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4424 bpstat_causes_stop (bpstat bs
)
4426 for (; bs
!= NULL
; bs
= bs
->next
)
4435 /* Print the LOC location out of the list of B->LOC locations. */
4437 static void print_breakpoint_location (struct breakpoint
*b
,
4438 struct bp_location
*loc
,
4440 struct ui_stream
*stb
)
4442 struct cleanup
*old_chain
= save_current_program_space ();
4444 if (loc
!= NULL
&& loc
->shlib_disabled
)
4448 set_current_program_space (loc
->pspace
);
4450 if (b
->source_file
&& loc
)
4453 = find_pc_sect_function (loc
->address
, loc
->section
);
4456 ui_out_text (uiout
, "in ");
4457 ui_out_field_string (uiout
, "func",
4458 SYMBOL_PRINT_NAME (sym
));
4459 ui_out_wrap_hint (uiout
, wrap_indent
);
4460 ui_out_text (uiout
, " at ");
4462 ui_out_field_string (uiout
, "file", b
->source_file
);
4463 ui_out_text (uiout
, ":");
4465 if (ui_out_is_mi_like_p (uiout
))
4467 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4468 char *fullname
= symtab_to_fullname (sal
.symtab
);
4471 ui_out_field_string (uiout
, "fullname", fullname
);
4474 ui_out_field_int (uiout
, "line", b
->line_number
);
4478 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4480 ui_out_field_stream (uiout
, "at", stb
);
4483 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4485 do_cleanups (old_chain
);
4488 /* Print B to gdb_stdout. */
4490 print_one_breakpoint_location (struct breakpoint
*b
,
4491 struct bp_location
*loc
,
4493 struct bp_location
**last_loc
,
4494 int print_address_bits
,
4497 struct command_line
*l
;
4499 struct ep_type_description
4504 static struct ep_type_description bptypes
[] =
4506 {bp_none
, "?deleted?"},
4507 {bp_breakpoint
, "breakpoint"},
4508 {bp_hardware_breakpoint
, "hw breakpoint"},
4509 {bp_until
, "until"},
4510 {bp_finish
, "finish"},
4511 {bp_watchpoint
, "watchpoint"},
4512 {bp_hardware_watchpoint
, "hw watchpoint"},
4513 {bp_read_watchpoint
, "read watchpoint"},
4514 {bp_access_watchpoint
, "acc watchpoint"},
4515 {bp_longjmp
, "longjmp"},
4516 {bp_longjmp_resume
, "longjmp resume"},
4517 {bp_step_resume
, "step resume"},
4518 {bp_watchpoint_scope
, "watchpoint scope"},
4519 {bp_call_dummy
, "call dummy"},
4520 {bp_std_terminate
, "std::terminate"},
4521 {bp_shlib_event
, "shlib events"},
4522 {bp_thread_event
, "thread events"},
4523 {bp_overlay_event
, "overlay events"},
4524 {bp_longjmp_master
, "longjmp master"},
4525 {bp_std_terminate_master
, "std::terminate master"},
4526 {bp_catchpoint
, "catchpoint"},
4527 {bp_tracepoint
, "tracepoint"},
4528 {bp_fast_tracepoint
, "fast tracepoint"},
4529 {bp_jit_event
, "jit events"},
4532 static char bpenables
[] = "nynny";
4533 char wrap_indent
[80];
4534 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4535 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4536 struct cleanup
*bkpt_chain
;
4538 int header_of_multiple
= 0;
4539 int part_of_multiple
= (loc
!= NULL
);
4540 struct value_print_options opts
;
4542 get_user_print_options (&opts
);
4544 gdb_assert (!loc
|| loc_number
!= 0);
4545 /* See comment in print_one_breakpoint concerning
4546 treatment of breakpoints with single disabled
4550 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4551 header_of_multiple
= 1;
4556 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4560 if (part_of_multiple
)
4563 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4564 ui_out_field_string (uiout
, "number", formatted
);
4569 ui_out_field_int (uiout
, "number", b
->number
);
4574 if (part_of_multiple
)
4575 ui_out_field_skip (uiout
, "type");
4578 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4579 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4580 internal_error (__FILE__
, __LINE__
,
4581 _("bptypes table does not describe type #%d."),
4583 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4588 if (part_of_multiple
)
4589 ui_out_field_skip (uiout
, "disp");
4591 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4596 if (part_of_multiple
)
4597 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4599 ui_out_field_fmt (uiout
, "enabled", "%c",
4600 bpenables
[(int) b
->enable_state
]);
4601 ui_out_spaces (uiout
, 2);
4605 strcpy (wrap_indent
, " ");
4606 if (opts
.addressprint
)
4608 if (print_address_bits
<= 32)
4609 strcat (wrap_indent
, " ");
4611 strcat (wrap_indent
, " ");
4614 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4616 /* Although the print_one can possibly print
4617 all locations, calling it here is not likely
4618 to get any nice result. So, make sure there's
4619 just one location. */
4620 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4621 b
->ops
->print_one (b
, last_loc
);
4627 internal_error (__FILE__
, __LINE__
,
4628 _("print_one_breakpoint: bp_none encountered\n"));
4632 case bp_hardware_watchpoint
:
4633 case bp_read_watchpoint
:
4634 case bp_access_watchpoint
:
4635 /* Field 4, the address, is omitted (which makes the columns
4636 not line up too nicely with the headers, but the effect
4637 is relatively readable). */
4638 if (opts
.addressprint
)
4639 ui_out_field_skip (uiout
, "addr");
4641 ui_out_field_string (uiout
, "what", b
->exp_string
);
4645 case bp_hardware_breakpoint
:
4649 case bp_longjmp_resume
:
4650 case bp_step_resume
:
4651 case bp_watchpoint_scope
:
4653 case bp_std_terminate
:
4654 case bp_shlib_event
:
4655 case bp_thread_event
:
4656 case bp_overlay_event
:
4657 case bp_longjmp_master
:
4658 case bp_std_terminate_master
:
4660 case bp_fast_tracepoint
:
4662 if (opts
.addressprint
)
4665 if (header_of_multiple
)
4666 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4667 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4668 ui_out_field_string (uiout
, "addr", "<PENDING>");
4670 ui_out_field_core_addr (uiout
, "addr",
4671 loc
->gdbarch
, loc
->address
);
4674 if (!header_of_multiple
)
4675 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4682 /* For backward compatibility, don't display inferiors unless there
4685 && !header_of_multiple
4687 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4688 && (number_of_program_spaces () > 1
4689 || number_of_inferiors () > 1)
4690 && loc
->owner
->type
!= bp_catchpoint
)))
4692 struct inferior
*inf
;
4695 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4697 if (inf
->pspace
== loc
->pspace
)
4702 ui_out_text (uiout
, " inf ");
4705 ui_out_text (uiout
, ", ");
4706 ui_out_text (uiout
, plongest (inf
->num
));
4711 if (!part_of_multiple
)
4713 if (b
->thread
!= -1)
4715 /* FIXME: This seems to be redundant and lost here; see the
4716 "stop only in" line a little further down. */
4717 ui_out_text (uiout
, " thread ");
4718 ui_out_field_int (uiout
, "thread", b
->thread
);
4720 else if (b
->task
!= 0)
4722 ui_out_text (uiout
, " task ");
4723 ui_out_field_int (uiout
, "task", b
->task
);
4727 ui_out_text (uiout
, "\n");
4729 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4732 ui_out_text (uiout
, "\tstop only in stack frame at ");
4733 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4735 ui_out_field_core_addr (uiout
, "frame",
4736 b
->gdbarch
, b
->frame_id
.stack_addr
);
4737 ui_out_text (uiout
, "\n");
4740 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4742 /* We do not print the condition for Ada exception catchpoints
4743 because the condition is an internal implementation detail
4744 that we do not want to expose to the user. */
4746 if (tracepoint_type (b
))
4747 ui_out_text (uiout
, "\ttrace only if ");
4749 ui_out_text (uiout
, "\tstop only if ");
4750 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4751 ui_out_text (uiout
, "\n");
4754 if (!part_of_multiple
&& b
->thread
!= -1)
4756 /* FIXME should make an annotation for this */
4757 ui_out_text (uiout
, "\tstop only in thread ");
4758 ui_out_field_int (uiout
, "thread", b
->thread
);
4759 ui_out_text (uiout
, "\n");
4762 if (!part_of_multiple
&& b
->hit_count
)
4764 /* FIXME should make an annotation for this */
4765 if (ep_is_catchpoint (b
))
4766 ui_out_text (uiout
, "\tcatchpoint");
4768 ui_out_text (uiout
, "\tbreakpoint");
4769 ui_out_text (uiout
, " already hit ");
4770 ui_out_field_int (uiout
, "times", b
->hit_count
);
4771 if (b
->hit_count
== 1)
4772 ui_out_text (uiout
, " time\n");
4774 ui_out_text (uiout
, " times\n");
4777 /* Output the count also if it is zero, but only if this is
4778 mi. FIXME: Should have a better test for this. */
4779 if (ui_out_is_mi_like_p (uiout
))
4780 if (!part_of_multiple
&& b
->hit_count
== 0)
4781 ui_out_field_int (uiout
, "times", b
->hit_count
);
4783 if (!part_of_multiple
&& b
->ignore_count
)
4786 ui_out_text (uiout
, "\tignore next ");
4787 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4788 ui_out_text (uiout
, " hits\n");
4791 l
= b
->commands
? b
->commands
->commands
: NULL
;
4792 if (!part_of_multiple
&& l
)
4794 struct cleanup
*script_chain
;
4797 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4798 print_command_lines (uiout
, l
, 4);
4799 do_cleanups (script_chain
);
4802 if (!part_of_multiple
&& b
->pass_count
)
4804 annotate_field (10);
4805 ui_out_text (uiout
, "\tpass count ");
4806 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4807 ui_out_text (uiout
, " \n");
4810 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4813 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4814 else if (b
->exp_string
)
4815 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4818 do_cleanups (bkpt_chain
);
4819 do_cleanups (old_chain
);
4823 print_one_breakpoint (struct breakpoint
*b
,
4824 struct bp_location
**last_loc
, int print_address_bits
,
4827 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4828 print_address_bits
, allflag
);
4830 /* If this breakpoint has custom print function,
4831 it's already printed. Otherwise, print individual
4832 locations, if any. */
4833 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4835 /* If breakpoint has a single location that is
4836 disabled, we print it as if it had
4837 several locations, since otherwise it's hard to
4838 represent "breakpoint enabled, location disabled"
4840 Note that while hardware watchpoints have
4841 several locations internally, that's no a property
4844 && !is_hardware_watchpoint (b
)
4845 && (b
->loc
->next
|| !b
->loc
->enabled
)
4846 && !ui_out_is_mi_like_p (uiout
))
4848 struct bp_location
*loc
;
4850 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4851 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4852 print_address_bits
, allflag
);
4858 breakpoint_address_bits (struct breakpoint
*b
)
4860 int print_address_bits
= 0;
4861 struct bp_location
*loc
;
4863 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4867 /* Software watchpoints that aren't watching memory don't have
4868 an address to print. */
4869 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4872 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4873 if (addr_bit
> print_address_bits
)
4874 print_address_bits
= addr_bit
;
4877 return print_address_bits
;
4880 struct captured_breakpoint_query_args
4886 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4888 struct captured_breakpoint_query_args
*args
= data
;
4889 struct breakpoint
*b
;
4890 struct bp_location
*dummy_loc
= NULL
;
4893 if (args
->bnum
== b
->number
)
4895 int print_address_bits
= breakpoint_address_bits (b
);
4896 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4904 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4906 struct captured_breakpoint_query_args args
;
4908 /* For the moment we don't trust print_one_breakpoint() to not throw
4910 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4911 error_message
, RETURN_MASK_ALL
) < 0)
4917 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4918 catchpoints, et.al.). */
4921 user_settable_breakpoint (const struct breakpoint
*b
)
4923 return (b
->type
== bp_breakpoint
4924 || b
->type
== bp_catchpoint
4925 || b
->type
== bp_hardware_breakpoint
4926 || tracepoint_type (b
)
4927 || b
->type
== bp_watchpoint
4928 || b
->type
== bp_read_watchpoint
4929 || b
->type
== bp_access_watchpoint
4930 || b
->type
== bp_hardware_watchpoint
);
4933 /* Print information on user settable breakpoint (watchpoint, etc)
4934 number BNUM. If BNUM is -1 print all user settable breakpoints.
4935 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4938 breakpoint_1 (int bnum
, int allflag
)
4940 struct breakpoint
*b
;
4941 struct bp_location
*last_loc
= NULL
;
4942 int nr_printable_breakpoints
;
4943 struct cleanup
*bkpttbl_chain
;
4944 struct value_print_options opts
;
4945 int print_address_bits
= 0;
4947 get_user_print_options (&opts
);
4949 /* Compute the number of rows in the table, as well as the
4950 size required for address fields. */
4951 nr_printable_breakpoints
= 0;
4954 || bnum
== b
->number
)
4956 if (allflag
|| user_settable_breakpoint (b
))
4958 int addr_bit
= breakpoint_address_bits (b
);
4959 if (addr_bit
> print_address_bits
)
4960 print_address_bits
= addr_bit
;
4962 nr_printable_breakpoints
++;
4966 if (opts
.addressprint
)
4968 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4972 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4975 if (nr_printable_breakpoints
> 0)
4976 annotate_breakpoints_headers ();
4977 if (nr_printable_breakpoints
> 0)
4979 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4980 if (nr_printable_breakpoints
> 0)
4982 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4983 if (nr_printable_breakpoints
> 0)
4985 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4986 if (nr_printable_breakpoints
> 0)
4988 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4989 if (opts
.addressprint
)
4991 if (nr_printable_breakpoints
> 0)
4993 if (print_address_bits
<= 32)
4994 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4996 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4998 if (nr_printable_breakpoints
> 0)
5000 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5001 ui_out_table_body (uiout
);
5002 if (nr_printable_breakpoints
> 0)
5003 annotate_breakpoints_table ();
5009 || bnum
== b
->number
)
5011 /* We only print out user settable breakpoints unless the
5013 if (allflag
|| user_settable_breakpoint (b
))
5014 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5018 do_cleanups (bkpttbl_chain
);
5020 if (nr_printable_breakpoints
== 0)
5023 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5025 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5030 if (last_loc
&& !server_command
)
5031 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5034 /* FIXME? Should this be moved up so that it is only called when
5035 there have been breakpoints? */
5036 annotate_breakpoints_table_end ();
5040 breakpoints_info (char *bnum_exp
, int from_tty
)
5045 bnum
= parse_and_eval_long (bnum_exp
);
5047 breakpoint_1 (bnum
, 0);
5051 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5056 bnum
= parse_and_eval_long (bnum_exp
);
5058 breakpoint_1 (bnum
, 1);
5062 breakpoint_has_pc (struct breakpoint
*b
,
5063 struct program_space
*pspace
,
5064 CORE_ADDR pc
, struct obj_section
*section
)
5066 struct bp_location
*bl
= b
->loc
;
5067 for (; bl
; bl
= bl
->next
)
5069 if (bl
->pspace
== pspace
5070 && bl
->address
== pc
5071 && (!overlay_debugging
|| bl
->section
== section
))
5077 /* Print a message describing any breakpoints set at PC. This
5078 concerns with logical breakpoints, so we match program spaces, not
5082 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5083 struct program_space
*pspace
, CORE_ADDR pc
,
5084 struct obj_section
*section
, int thread
)
5087 struct breakpoint
*b
;
5090 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5094 printf_filtered (_("Note: breakpoint "));
5095 else /* if (others == ???) */
5096 printf_filtered (_("Note: breakpoints "));
5098 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5101 printf_filtered ("%d", b
->number
);
5102 if (b
->thread
== -1 && thread
!= -1)
5103 printf_filtered (" (all threads)");
5104 else if (b
->thread
!= -1)
5105 printf_filtered (" (thread %d)", b
->thread
);
5106 printf_filtered ("%s%s ",
5107 ((b
->enable_state
== bp_disabled
5108 || b
->enable_state
== bp_call_disabled
5109 || b
->enable_state
== bp_startup_disabled
)
5111 : b
->enable_state
== bp_permanent
5115 : ((others
== 1) ? " and" : ""));
5117 printf_filtered (_("also set at pc "));
5118 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5119 printf_filtered (".\n");
5123 /* Set the default place to put a breakpoint
5124 for the `break' command with no arguments. */
5127 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5128 CORE_ADDR addr
, struct symtab
*symtab
,
5131 default_breakpoint_valid
= valid
;
5132 default_breakpoint_pspace
= pspace
;
5133 default_breakpoint_address
= addr
;
5134 default_breakpoint_symtab
= symtab
;
5135 default_breakpoint_line
= line
;
5138 /* Return true iff it is meaningful to use the address member of
5139 BPT. For some breakpoint types, the address member is irrelevant
5140 and it makes no sense to attempt to compare it to other addresses
5141 (or use it for any other purpose either).
5143 More specifically, each of the following breakpoint types will always
5144 have a zero valued address and we don't want to mark breakpoints of any of
5145 these types to be a duplicate of an actual breakpoint at address zero:
5153 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5155 enum bptype type
= bpt
->type
;
5157 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5160 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5161 true if LOC1 and LOC2 represent the same watchpoint location. */
5164 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5166 /* Note that this checks the owner's type, not the location's. In
5167 case the target does not support read watchpoints, but does
5168 support access watchpoints, we'll have bp_read_watchpoint
5169 watchpoints with hw_access locations. Those should be considered
5170 duplicates of hw_read locations. The hw_read locations will
5171 become hw_access locations later. */
5172 return (loc1
->owner
->type
== loc2
->owner
->type
5173 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5174 && loc1
->address
== loc2
->address
5175 && loc1
->length
== loc2
->length
);
5178 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5179 same breakpoint location. In most targets, this can only be true
5180 if ASPACE1 matches ASPACE2. On targets that have global
5181 breakpoints, the address space doesn't really matter. */
5184 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5185 struct address_space
*aspace2
, CORE_ADDR addr2
)
5187 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5188 || aspace1
== aspace2
)
5192 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5193 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5194 represent the same location. */
5197 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5199 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5200 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5202 if (hw_point1
!= hw_point2
)
5205 return watchpoint_locations_match (loc1
, loc2
);
5207 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5208 loc2
->pspace
->aspace
, loc2
->address
);
5212 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5213 int bnum
, int have_bnum
)
5218 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5219 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5221 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5222 bnum
, astr1
, astr2
);
5224 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5227 /* Adjust a breakpoint's address to account for architectural constraints
5228 on breakpoint placement. Return the adjusted address. Note: Very
5229 few targets require this kind of adjustment. For most targets,
5230 this function is simply the identity function. */
5233 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5234 CORE_ADDR bpaddr
, enum bptype bptype
)
5236 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5238 /* Very few targets need any kind of breakpoint adjustment. */
5241 else if (bptype
== bp_watchpoint
5242 || bptype
== bp_hardware_watchpoint
5243 || bptype
== bp_read_watchpoint
5244 || bptype
== bp_access_watchpoint
5245 || bptype
== bp_catchpoint
)
5247 /* Watchpoints and the various bp_catch_* eventpoints should not
5248 have their addresses modified. */
5253 CORE_ADDR adjusted_bpaddr
;
5255 /* Some targets have architectural constraints on the placement
5256 of breakpoint instructions. Obtain the adjusted address. */
5257 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5259 /* An adjusted breakpoint address can significantly alter
5260 a user's expectations. Print a warning if an adjustment
5262 if (adjusted_bpaddr
!= bpaddr
)
5263 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5265 return adjusted_bpaddr
;
5269 /* Allocate a struct bp_location. */
5271 static struct bp_location
*
5272 allocate_bp_location (struct breakpoint
*bpt
)
5274 struct bp_location
*loc
, *loc_p
;
5276 loc
= xmalloc (sizeof (struct bp_location
));
5277 memset (loc
, 0, sizeof (*loc
));
5281 loc
->shlib_disabled
= 0;
5290 case bp_longjmp_resume
:
5291 case bp_step_resume
:
5292 case bp_watchpoint_scope
:
5294 case bp_std_terminate
:
5295 case bp_shlib_event
:
5296 case bp_thread_event
:
5297 case bp_overlay_event
:
5299 case bp_longjmp_master
:
5300 case bp_std_terminate_master
:
5301 loc
->loc_type
= bp_loc_software_breakpoint
;
5303 case bp_hardware_breakpoint
:
5304 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5306 case bp_hardware_watchpoint
:
5307 case bp_read_watchpoint
:
5308 case bp_access_watchpoint
:
5309 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5314 case bp_fast_tracepoint
:
5315 loc
->loc_type
= bp_loc_other
;
5318 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5324 static void free_bp_location (struct bp_location
*loc
)
5329 if (loc
->function_name
)
5330 xfree (loc
->function_name
);
5335 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5336 that has type BPTYPE and has no locations as yet. */
5337 /* This function is used in gdbtk sources and thus can not be made static. */
5339 static struct breakpoint
*
5340 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5343 struct breakpoint
*b
, *b1
;
5345 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5346 memset (b
, 0, sizeof (*b
));
5349 b
->gdbarch
= gdbarch
;
5350 b
->language
= current_language
->la_language
;
5351 b
->input_radix
= input_radix
;
5353 b
->enable_state
= bp_enabled
;
5356 b
->ignore_count
= 0;
5358 b
->frame_id
= null_frame_id
;
5359 b
->forked_inferior_pid
= null_ptid
;
5360 b
->exec_pathname
= NULL
;
5361 b
->syscalls_to_be_caught
= NULL
;
5363 b
->condition_not_parsed
= 0;
5365 /* Add this breakpoint to the end of the chain
5366 so that a list of breakpoints will come out in order
5367 of increasing numbers. */
5369 b1
= breakpoint_chain
;
5371 breakpoint_chain
= b
;
5381 /* Initialize loc->function_name. */
5383 set_breakpoint_location_function (struct bp_location
*loc
)
5385 if (loc
->owner
->type
== bp_breakpoint
5386 || loc
->owner
->type
== bp_hardware_breakpoint
5387 || tracepoint_type (loc
->owner
))
5389 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5391 if (loc
->function_name
)
5392 loc
->function_name
= xstrdup (loc
->function_name
);
5396 /* Attempt to determine architecture of location identified by SAL. */
5397 static struct gdbarch
*
5398 get_sal_arch (struct symtab_and_line sal
)
5401 return get_objfile_arch (sal
.section
->objfile
);
5403 return get_objfile_arch (sal
.symtab
->objfile
);
5408 /* set_raw_breakpoint is a low level routine for allocating and
5409 partially initializing a breakpoint of type BPTYPE. The newly
5410 created breakpoint's address, section, source file name, and line
5411 number are provided by SAL. The newly created and partially
5412 initialized breakpoint is added to the breakpoint chain and
5413 is also returned as the value of this function.
5415 It is expected that the caller will complete the initialization of
5416 the newly created breakpoint struct as well as output any status
5417 information regarding the creation of a new breakpoint. In
5418 particular, set_raw_breakpoint does NOT set the breakpoint
5419 number! Care should be taken to not allow an error to occur
5420 prior to completing the initialization of the breakpoint. If this
5421 should happen, a bogus breakpoint will be left on the chain. */
5424 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5425 struct symtab_and_line sal
, enum bptype bptype
)
5427 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5428 CORE_ADDR adjusted_address
;
5429 struct gdbarch
*loc_gdbarch
;
5431 loc_gdbarch
= get_sal_arch (sal
);
5433 loc_gdbarch
= b
->gdbarch
;
5435 if (bptype
!= bp_catchpoint
)
5436 gdb_assert (sal
.pspace
!= NULL
);
5438 /* Adjust the breakpoint's address prior to allocating a location.
5439 Once we call allocate_bp_location(), that mostly uninitialized
5440 location will be placed on the location chain. Adjustment of the
5441 breakpoint may cause target_read_memory() to be called and we do
5442 not want its scan of the location chain to find a breakpoint and
5443 location that's only been partially initialized. */
5444 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5446 b
->loc
= allocate_bp_location (b
);
5447 b
->loc
->gdbarch
= loc_gdbarch
;
5448 b
->loc
->requested_address
= sal
.pc
;
5449 b
->loc
->address
= adjusted_address
;
5450 b
->loc
->pspace
= sal
.pspace
;
5452 /* Store the program space that was used to set the breakpoint, for
5453 breakpoint resetting. */
5454 b
->pspace
= sal
.pspace
;
5456 if (sal
.symtab
== NULL
)
5457 b
->source_file
= NULL
;
5459 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5460 b
->loc
->section
= sal
.section
;
5461 b
->line_number
= sal
.line
;
5463 set_breakpoint_location_function (b
->loc
);
5465 breakpoints_changed ();
5471 /* Note that the breakpoint object B describes a permanent breakpoint
5472 instruction, hard-wired into the inferior's code. */
5474 make_breakpoint_permanent (struct breakpoint
*b
)
5476 struct bp_location
*bl
;
5477 b
->enable_state
= bp_permanent
;
5479 /* By definition, permanent breakpoints are already present in the code.
5480 Mark all locations as inserted. For now, make_breakpoint_permanent
5481 is called in just one place, so it's hard to say if it's reasonable
5482 to have permanent breakpoint with multiple locations or not,
5483 but it's easy to implmement. */
5484 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5488 /* Call this routine when stepping and nexting to enable a breakpoint
5489 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5490 set_longjmp_resume_breakpoint() to figure out where we are going. */
5493 set_longjmp_breakpoint (int thread
)
5495 struct breakpoint
*b
, *temp
;
5497 /* To avoid having to rescan all objfile symbols at every step,
5498 we maintain a list of continually-inserted but always disabled
5499 longjmp "master" breakpoints. Here, we simply create momentary
5500 clones of those and enable them for the requested thread. */
5501 ALL_BREAKPOINTS_SAFE (b
, temp
)
5502 if (b
->pspace
== current_program_space
5503 && b
->type
== bp_longjmp_master
)
5505 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5506 clone
->type
= bp_longjmp
;
5507 clone
->thread
= thread
;
5511 /* Delete all longjmp breakpoints from THREAD. */
5513 delete_longjmp_breakpoint (int thread
)
5515 struct breakpoint
*b
, *temp
;
5517 ALL_BREAKPOINTS_SAFE (b
, temp
)
5518 if (b
->type
== bp_longjmp
)
5520 if (b
->thread
== thread
)
5521 delete_breakpoint (b
);
5526 enable_overlay_breakpoints (void)
5528 struct breakpoint
*b
;
5531 if (b
->type
== bp_overlay_event
)
5533 b
->enable_state
= bp_enabled
;
5534 update_global_location_list (1);
5535 overlay_events_enabled
= 1;
5540 disable_overlay_breakpoints (void)
5542 struct breakpoint
*b
;
5545 if (b
->type
== bp_overlay_event
)
5547 b
->enable_state
= bp_disabled
;
5548 update_global_location_list (0);
5549 overlay_events_enabled
= 0;
5553 /* Set an active std::terminate breakpoint for each std::terminate
5554 master breakpoint. */
5556 set_std_terminate_breakpoint (void)
5558 struct breakpoint
*b
, *temp
;
5560 ALL_BREAKPOINTS_SAFE (b
, temp
)
5561 if (b
->pspace
== current_program_space
5562 && b
->type
== bp_std_terminate_master
)
5564 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5565 clone
->type
= bp_std_terminate
;
5569 /* Delete all the std::terminate breakpoints. */
5571 delete_std_terminate_breakpoint (void)
5573 struct breakpoint
*b
, *temp
;
5575 ALL_BREAKPOINTS_SAFE (b
, temp
)
5576 if (b
->type
== bp_std_terminate
)
5577 delete_breakpoint (b
);
5581 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5583 struct breakpoint
*b
;
5585 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5587 b
->enable_state
= bp_enabled
;
5588 /* addr_string has to be used or breakpoint_re_set will delete me. */
5590 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5592 update_global_location_list_nothrow (1);
5598 remove_thread_event_breakpoints (void)
5600 struct breakpoint
*b
, *temp
;
5602 ALL_BREAKPOINTS_SAFE (b
, temp
)
5603 if (b
->type
== bp_thread_event
5604 && b
->loc
->pspace
== current_program_space
)
5605 delete_breakpoint (b
);
5608 struct captured_parse_breakpoint_args
5611 struct symtabs_and_lines
*sals_p
;
5612 char ***addr_string_p
;
5616 struct lang_and_radix
5622 /* Create a breakpoint for JIT code registration and unregistration. */
5625 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5627 struct breakpoint
*b
;
5629 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5630 update_global_location_list_nothrow (1);
5635 remove_solib_event_breakpoints (void)
5637 struct breakpoint
*b
, *temp
;
5639 ALL_BREAKPOINTS_SAFE (b
, temp
)
5640 if (b
->type
== bp_shlib_event
5641 && b
->loc
->pspace
== current_program_space
)
5642 delete_breakpoint (b
);
5646 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5648 struct breakpoint
*b
;
5650 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5651 update_global_location_list_nothrow (1);
5655 /* Disable any breakpoints that are on code in shared libraries. Only
5656 apply to enabled breakpoints, disabled ones can just stay disabled. */
5659 disable_breakpoints_in_shlibs (void)
5661 struct bp_location
*loc
, **locp_tmp
;
5663 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5665 struct breakpoint
*b
= loc
->owner
;
5666 /* We apply the check to all breakpoints, including disabled
5667 for those with loc->duplicate set. This is so that when breakpoint
5668 becomes enabled, or the duplicate is removed, gdb will try to insert
5669 all breakpoints. If we don't set shlib_disabled here, we'll try
5670 to insert those breakpoints and fail. */
5671 if (((b
->type
== bp_breakpoint
)
5672 || (b
->type
== bp_jit_event
)
5673 || (b
->type
== bp_hardware_breakpoint
)
5674 || (tracepoint_type (b
)))
5675 && loc
->pspace
== current_program_space
5676 && !loc
->shlib_disabled
5678 && PC_SOLIB (loc
->address
)
5680 && solib_name_from_address (loc
->pspace
, loc
->address
)
5684 loc
->shlib_disabled
= 1;
5689 /* Disable any breakpoints that are in in an unloaded shared library. Only
5690 apply to enabled breakpoints, disabled ones can just stay disabled. */
5693 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5695 struct bp_location
*loc
, **locp_tmp
;
5696 int disabled_shlib_breaks
= 0;
5698 /* SunOS a.out shared libraries are always mapped, so do not
5699 disable breakpoints; they will only be reported as unloaded
5700 through clear_solib when GDB discards its shared library
5701 list. See clear_solib for more information. */
5702 if (exec_bfd
!= NULL
5703 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5706 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5708 struct breakpoint
*b
= loc
->owner
;
5709 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5710 || loc
->loc_type
== bp_loc_software_breakpoint
)
5711 && solib
->pspace
== loc
->pspace
5712 && !loc
->shlib_disabled
5713 && (b
->type
== bp_breakpoint
5714 || b
->type
== bp_jit_event
5715 || b
->type
== bp_hardware_breakpoint
)
5716 && solib_contains_address_p (solib
, loc
->address
))
5718 loc
->shlib_disabled
= 1;
5719 /* At this point, we cannot rely on remove_breakpoint
5720 succeeding so we must mark the breakpoint as not inserted
5721 to prevent future errors occurring in remove_breakpoints. */
5723 if (!disabled_shlib_breaks
)
5725 target_terminal_ours_for_output ();
5726 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5729 disabled_shlib_breaks
= 1;
5734 /* FORK & VFORK catchpoints. */
5736 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5739 insert_catch_fork (struct breakpoint
*b
)
5741 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5744 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5747 remove_catch_fork (struct breakpoint
*b
)
5749 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5752 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5756 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5758 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5761 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5763 static enum print_stop_action
5764 print_it_catch_fork (struct breakpoint
*b
)
5766 annotate_catchpoint (b
->number
);
5767 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5768 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5769 return PRINT_SRC_AND_LOC
;
5772 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5775 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5777 struct value_print_options opts
;
5779 get_user_print_options (&opts
);
5781 /* Field 4, the address, is omitted (which makes the columns
5782 not line up too nicely with the headers, but the effect
5783 is relatively readable). */
5784 if (opts
.addressprint
)
5785 ui_out_field_skip (uiout
, "addr");
5787 ui_out_text (uiout
, "fork");
5788 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5790 ui_out_text (uiout
, ", process ");
5791 ui_out_field_int (uiout
, "what",
5792 ptid_get_pid (b
->forked_inferior_pid
));
5793 ui_out_spaces (uiout
, 1);
5797 /* Implement the "print_mention" breakpoint_ops method for fork
5801 print_mention_catch_fork (struct breakpoint
*b
)
5803 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5806 /* The breakpoint_ops structure to be used in fork catchpoints. */
5808 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5812 breakpoint_hit_catch_fork
,
5813 print_it_catch_fork
,
5814 print_one_catch_fork
,
5815 print_mention_catch_fork
5818 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5821 insert_catch_vfork (struct breakpoint
*b
)
5823 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5826 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5829 remove_catch_vfork (struct breakpoint
*b
)
5831 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5834 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5838 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5840 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5843 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5845 static enum print_stop_action
5846 print_it_catch_vfork (struct breakpoint
*b
)
5848 annotate_catchpoint (b
->number
);
5849 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5850 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5851 return PRINT_SRC_AND_LOC
;
5854 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5857 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5859 struct value_print_options opts
;
5861 get_user_print_options (&opts
);
5862 /* Field 4, the address, is omitted (which makes the columns
5863 not line up too nicely with the headers, but the effect
5864 is relatively readable). */
5865 if (opts
.addressprint
)
5866 ui_out_field_skip (uiout
, "addr");
5868 ui_out_text (uiout
, "vfork");
5869 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5871 ui_out_text (uiout
, ", process ");
5872 ui_out_field_int (uiout
, "what",
5873 ptid_get_pid (b
->forked_inferior_pid
));
5874 ui_out_spaces (uiout
, 1);
5878 /* Implement the "print_mention" breakpoint_ops method for vfork
5882 print_mention_catch_vfork (struct breakpoint
*b
)
5884 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5887 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5889 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5893 breakpoint_hit_catch_vfork
,
5894 print_it_catch_vfork
,
5895 print_one_catch_vfork
,
5896 print_mention_catch_vfork
5899 /* Implement the "insert" breakpoint_ops method for syscall
5903 insert_catch_syscall (struct breakpoint
*b
)
5905 struct inferior
*inf
= current_inferior ();
5907 ++inf
->total_syscalls_count
;
5908 if (!b
->syscalls_to_be_caught
)
5909 ++inf
->any_syscall_count
;
5914 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5918 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5920 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5921 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5923 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5924 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5926 memset ((void *) vec_addr
, 0,
5927 (iter
+ 1 - old_size
) * sizeof (int));
5929 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5930 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5934 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5935 inf
->total_syscalls_count
!= 0,
5936 inf
->any_syscall_count
,
5937 VEC_length (int, inf
->syscalls_counts
),
5938 VEC_address (int, inf
->syscalls_counts
));
5941 /* Implement the "remove" breakpoint_ops method for syscall
5945 remove_catch_syscall (struct breakpoint
*b
)
5947 struct inferior
*inf
= current_inferior ();
5949 --inf
->total_syscalls_count
;
5950 if (!b
->syscalls_to_be_caught
)
5951 --inf
->any_syscall_count
;
5956 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5960 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5961 /* Shouldn't happen. */
5963 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5964 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5968 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5969 inf
->total_syscalls_count
!= 0,
5970 inf
->any_syscall_count
,
5971 VEC_length (int, inf
->syscalls_counts
),
5972 VEC_address (int, inf
->syscalls_counts
));
5975 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5979 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5981 /* We must check if we are catching specific syscalls in this breakpoint.
5982 If we are, then we must guarantee that the called syscall is the same
5983 syscall we are catching. */
5984 int syscall_number
= 0;
5986 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5989 /* Now, checking if the syscall is the same. */
5990 if (b
->syscalls_to_be_caught
)
5994 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5996 if (syscall_number
== iter
)
6006 /* Implement the "print_it" breakpoint_ops method for syscall
6009 static enum print_stop_action
6010 print_it_catch_syscall (struct breakpoint
*b
)
6012 /* These are needed because we want to know in which state a
6013 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6014 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6015 must print "called syscall" or "returned from syscall". */
6017 struct target_waitstatus last
;
6019 struct cleanup
*old_chain
;
6022 get_last_target_status (&ptid
, &last
);
6024 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6026 annotate_catchpoint (b
->number
);
6029 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6031 syscall_id
= xstrprintf ("'%s'", s
.name
);
6033 old_chain
= make_cleanup (xfree
, syscall_id
);
6035 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6036 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6037 b
->number
, syscall_id
);
6038 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6039 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6040 b
->number
, syscall_id
);
6042 do_cleanups (old_chain
);
6044 return PRINT_SRC_AND_LOC
;
6047 /* Implement the "print_one" breakpoint_ops method for syscall
6051 print_one_catch_syscall (struct breakpoint
*b
,
6052 struct bp_location
**last_loc
)
6054 struct value_print_options opts
;
6056 get_user_print_options (&opts
);
6057 /* Field 4, the address, is omitted (which makes the columns
6058 not line up too nicely with the headers, but the effect
6059 is relatively readable). */
6060 if (opts
.addressprint
)
6061 ui_out_field_skip (uiout
, "addr");
6064 if (b
->syscalls_to_be_caught
6065 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6066 ui_out_text (uiout
, "syscalls \"");
6068 ui_out_text (uiout
, "syscall \"");
6070 if (b
->syscalls_to_be_caught
)
6073 char *text
= xstrprintf ("%s", "");
6075 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6080 get_syscall_by_number (iter
, &s
);
6083 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6085 text
= xstrprintf ("%s%d, ", text
, iter
);
6087 /* We have to xfree the last 'text' (now stored at 'x')
6088 because xstrprintf dinamically allocates new space for it
6092 /* Remove the last comma. */
6093 text
[strlen (text
) - 2] = '\0';
6094 ui_out_field_string (uiout
, "what", text
);
6097 ui_out_field_string (uiout
, "what", "<any syscall>");
6098 ui_out_text (uiout
, "\" ");
6101 /* Implement the "print_mention" breakpoint_ops method for syscall
6105 print_mention_catch_syscall (struct breakpoint
*b
)
6107 if (b
->syscalls_to_be_caught
)
6111 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6112 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6114 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6117 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6121 get_syscall_by_number (iter
, &s
);
6124 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6126 printf_filtered (" %d", s
.number
);
6128 printf_filtered (")");
6131 printf_filtered (_("Catchpoint %d (any syscall)"),
6135 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6137 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6139 insert_catch_syscall
,
6140 remove_catch_syscall
,
6141 breakpoint_hit_catch_syscall
,
6142 print_it_catch_syscall
,
6143 print_one_catch_syscall
,
6144 print_mention_catch_syscall
6147 /* Returns non-zero if 'b' is a syscall catchpoint. */
6150 syscall_catchpoint_p (struct breakpoint
*b
)
6152 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6155 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6156 but does NOT mention it nor update the global location list.
6157 This is useful if you need to fill more fields in the
6158 struct breakpoint before calling mention.
6160 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6161 If COND_STRING is not NULL, then store it in the breakpoint.
6162 OPS, if not NULL, is the breakpoint_ops structure associated
6163 to the catchpoint. */
6165 static struct breakpoint
*
6166 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6168 struct breakpoint_ops
*ops
)
6170 struct symtab_and_line sal
;
6171 struct breakpoint
*b
;
6174 sal
.pspace
= current_program_space
;
6176 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6177 set_breakpoint_count (breakpoint_count
+ 1);
6178 b
->number
= breakpoint_count
;
6180 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6182 b
->addr_string
= NULL
;
6183 b
->enable_state
= bp_enabled
;
6184 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6190 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6192 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6193 If COND_STRING is not NULL, then store it in the breakpoint.
6194 OPS, if not NULL, is the breakpoint_ops structure associated
6195 to the catchpoint. */
6197 static struct breakpoint
*
6198 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6199 char *cond_string
, struct breakpoint_ops
*ops
)
6201 struct breakpoint
*b
=
6202 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6205 update_global_location_list (1);
6211 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6212 int tempflag
, char *cond_string
,
6213 struct breakpoint_ops
*ops
)
6215 struct breakpoint
*b
6216 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6218 /* FIXME: We should put this information in a breakpoint private data
6220 b
->forked_inferior_pid
= null_ptid
;
6223 /* Exec catchpoints. */
6226 insert_catch_exec (struct breakpoint
*b
)
6228 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6232 remove_catch_exec (struct breakpoint
*b
)
6234 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6238 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6240 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6243 static enum print_stop_action
6244 print_it_catch_exec (struct breakpoint
*b
)
6246 annotate_catchpoint (b
->number
);
6247 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6249 return PRINT_SRC_AND_LOC
;
6253 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6255 struct value_print_options opts
;
6257 get_user_print_options (&opts
);
6259 /* Field 4, the address, is omitted (which makes the columns
6260 not line up too nicely with the headers, but the effect
6261 is relatively readable). */
6262 if (opts
.addressprint
)
6263 ui_out_field_skip (uiout
, "addr");
6265 ui_out_text (uiout
, "exec");
6266 if (b
->exec_pathname
!= NULL
)
6268 ui_out_text (uiout
, ", program \"");
6269 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6270 ui_out_text (uiout
, "\" ");
6275 print_mention_catch_exec (struct breakpoint
*b
)
6277 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6280 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6284 breakpoint_hit_catch_exec
,
6285 print_it_catch_exec
,
6286 print_one_catch_exec
,
6287 print_mention_catch_exec
6291 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6292 struct breakpoint_ops
*ops
)
6294 struct gdbarch
*gdbarch
= get_current_arch ();
6295 struct breakpoint
*b
=
6296 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6298 b
->syscalls_to_be_caught
= filter
;
6300 /* Now, we have to mention the breakpoint and update the global
6303 update_global_location_list (1);
6307 hw_breakpoint_used_count (void)
6309 struct breakpoint
*b
;
6314 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6322 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6324 struct breakpoint
*b
;
6327 *other_type_used
= 0;
6330 if (breakpoint_enabled (b
))
6332 if (b
->type
== type
)
6334 else if ((b
->type
== bp_hardware_watchpoint
6335 || b
->type
== bp_read_watchpoint
6336 || b
->type
== bp_access_watchpoint
))
6337 *other_type_used
= 1;
6344 disable_watchpoints_before_interactive_call_start (void)
6346 struct breakpoint
*b
;
6350 if (((b
->type
== bp_watchpoint
)
6351 || (b
->type
== bp_hardware_watchpoint
)
6352 || (b
->type
== bp_read_watchpoint
)
6353 || (b
->type
== bp_access_watchpoint
))
6354 && breakpoint_enabled (b
))
6356 b
->enable_state
= bp_call_disabled
;
6357 update_global_location_list (0);
6363 enable_watchpoints_after_interactive_call_stop (void)
6365 struct breakpoint
*b
;
6369 if (((b
->type
== bp_watchpoint
)
6370 || (b
->type
== bp_hardware_watchpoint
)
6371 || (b
->type
== bp_read_watchpoint
)
6372 || (b
->type
== bp_access_watchpoint
))
6373 && (b
->enable_state
== bp_call_disabled
))
6375 b
->enable_state
= bp_enabled
;
6376 update_global_location_list (1);
6382 disable_breakpoints_before_startup (void)
6384 struct breakpoint
*b
;
6389 if (b
->pspace
!= current_program_space
)
6392 if ((b
->type
== bp_breakpoint
6393 || b
->type
== bp_hardware_breakpoint
)
6394 && breakpoint_enabled (b
))
6396 b
->enable_state
= bp_startup_disabled
;
6402 update_global_location_list (0);
6404 current_program_space
->executing_startup
= 1;
6408 enable_breakpoints_after_startup (void)
6410 struct breakpoint
*b
;
6413 current_program_space
->executing_startup
= 0;
6417 if (b
->pspace
!= current_program_space
)
6420 if ((b
->type
== bp_breakpoint
6421 || b
->type
== bp_hardware_breakpoint
)
6422 && b
->enable_state
== bp_startup_disabled
)
6424 b
->enable_state
= bp_enabled
;
6430 breakpoint_re_set ();
6434 /* Set a breakpoint that will evaporate an end of command
6435 at address specified by SAL.
6436 Restrict it to frame FRAME if FRAME is nonzero. */
6439 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6440 struct frame_id frame_id
, enum bptype type
)
6442 struct breakpoint
*b
;
6444 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6446 gdb_assert (!frame_id_inlined_p (frame_id
));
6448 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6449 b
->enable_state
= bp_enabled
;
6450 b
->disposition
= disp_donttouch
;
6451 b
->frame_id
= frame_id
;
6453 /* If we're debugging a multi-threaded program, then we
6454 want momentary breakpoints to be active in only a
6455 single thread of control. */
6456 if (in_thread_list (inferior_ptid
))
6457 b
->thread
= pid_to_thread_id (inferior_ptid
);
6459 update_global_location_list_nothrow (1);
6464 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6468 clone_momentary_breakpoint (struct breakpoint
*orig
)
6470 struct breakpoint
*copy
;
6472 /* If there's nothing to clone, then return nothing. */
6476 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6477 copy
->loc
= allocate_bp_location (copy
);
6478 set_breakpoint_location_function (copy
->loc
);
6480 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6481 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6482 copy
->loc
->address
= orig
->loc
->address
;
6483 copy
->loc
->section
= orig
->loc
->section
;
6484 copy
->loc
->pspace
= orig
->loc
->pspace
;
6486 if (orig
->source_file
== NULL
)
6487 copy
->source_file
= NULL
;
6489 copy
->source_file
= xstrdup (orig
->source_file
);
6491 copy
->line_number
= orig
->line_number
;
6492 copy
->frame_id
= orig
->frame_id
;
6493 copy
->thread
= orig
->thread
;
6494 copy
->pspace
= orig
->pspace
;
6496 copy
->enable_state
= bp_enabled
;
6497 copy
->disposition
= disp_donttouch
;
6498 copy
->number
= internal_breakpoint_number
--;
6500 update_global_location_list_nothrow (0);
6505 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6508 struct symtab_and_line sal
;
6510 sal
= find_pc_line (pc
, 0);
6512 sal
.section
= find_pc_overlay (pc
);
6513 sal
.explicit_pc
= 1;
6515 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6519 /* Tell the user we have just set a breakpoint B. */
6522 mention (struct breakpoint
*b
)
6525 struct cleanup
*ui_out_chain
;
6526 struct value_print_options opts
;
6528 get_user_print_options (&opts
);
6530 /* FIXME: This is misplaced; mention() is called by things (like
6531 hitting a watchpoint) other than breakpoint creation. It should
6532 be possible to clean this up and at the same time replace the
6533 random calls to breakpoint_changed with this hook. */
6534 observer_notify_breakpoint_created (b
->number
);
6536 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6537 b
->ops
->print_mention (b
);
6542 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6545 ui_out_text (uiout
, "Watchpoint ");
6546 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6547 ui_out_field_int (uiout
, "number", b
->number
);
6548 ui_out_text (uiout
, ": ");
6549 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6550 do_cleanups (ui_out_chain
);
6552 case bp_hardware_watchpoint
:
6553 ui_out_text (uiout
, "Hardware watchpoint ");
6554 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6555 ui_out_field_int (uiout
, "number", b
->number
);
6556 ui_out_text (uiout
, ": ");
6557 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6558 do_cleanups (ui_out_chain
);
6560 case bp_read_watchpoint
:
6561 ui_out_text (uiout
, "Hardware read watchpoint ");
6562 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6563 ui_out_field_int (uiout
, "number", b
->number
);
6564 ui_out_text (uiout
, ": ");
6565 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6566 do_cleanups (ui_out_chain
);
6568 case bp_access_watchpoint
:
6569 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6570 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6571 ui_out_field_int (uiout
, "number", b
->number
);
6572 ui_out_text (uiout
, ": ");
6573 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6574 do_cleanups (ui_out_chain
);
6577 if (ui_out_is_mi_like_p (uiout
))
6582 if (b
->disposition
== disp_del
)
6583 printf_filtered (_("Temporary breakpoint"));
6585 printf_filtered (_("Breakpoint"));
6586 printf_filtered (_(" %d"), b
->number
);
6589 case bp_hardware_breakpoint
:
6590 if (ui_out_is_mi_like_p (uiout
))
6595 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6599 if (ui_out_is_mi_like_p (uiout
))
6604 printf_filtered (_("Tracepoint"));
6605 printf_filtered (_(" %d"), b
->number
);
6608 case bp_fast_tracepoint
:
6609 if (ui_out_is_mi_like_p (uiout
))
6614 printf_filtered (_("Fast tracepoint"));
6615 printf_filtered (_(" %d"), b
->number
);
6622 case bp_longjmp_resume
:
6623 case bp_step_resume
:
6625 case bp_std_terminate
:
6626 case bp_watchpoint_scope
:
6627 case bp_shlib_event
:
6628 case bp_thread_event
:
6629 case bp_overlay_event
:
6631 case bp_longjmp_master
:
6632 case bp_std_terminate_master
:
6638 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6642 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6646 if (opts
.addressprint
|| b
->source_file
== NULL
)
6648 printf_filtered (" at ");
6649 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6653 printf_filtered (": file %s, line %d.",
6654 b
->source_file
, b
->line_number
);
6658 struct bp_location
*loc
= b
->loc
;
6660 for (; loc
; loc
= loc
->next
)
6662 printf_filtered (" (%d locations)", n
);
6667 if (ui_out_is_mi_like_p (uiout
))
6669 printf_filtered ("\n");
6673 static struct bp_location
*
6674 add_location_to_breakpoint (struct breakpoint
*b
,
6675 const struct symtab_and_line
*sal
)
6677 struct bp_location
*loc
, **tmp
;
6679 loc
= allocate_bp_location (b
);
6680 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6683 loc
->gdbarch
= get_sal_arch (*sal
);
6685 loc
->gdbarch
= b
->gdbarch
;
6686 loc
->requested_address
= sal
->pc
;
6687 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6688 loc
->requested_address
, b
->type
);
6689 loc
->pspace
= sal
->pspace
;
6690 gdb_assert (loc
->pspace
!= NULL
);
6691 loc
->section
= sal
->section
;
6693 set_breakpoint_location_function (loc
);
6698 /* Return 1 if LOC is pointing to a permanent breakpoint,
6699 return 0 otherwise. */
6702 bp_loc_is_permanent (struct bp_location
*loc
)
6706 const gdb_byte
*brk
;
6707 gdb_byte
*target_mem
;
6708 struct cleanup
*cleanup
;
6711 gdb_assert (loc
!= NULL
);
6713 addr
= loc
->address
;
6714 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6716 /* Software breakpoints unsupported? */
6720 target_mem
= alloca (len
);
6722 /* Enable the automatic memory restoration from breakpoints while
6723 we read the memory. Otherwise we could say about our temporary
6724 breakpoints they are permanent. */
6725 cleanup
= save_current_space_and_thread ();
6727 switch_to_program_space_and_thread (loc
->pspace
);
6728 make_show_memory_breakpoints_cleanup (0);
6730 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6731 && memcmp (target_mem
, brk
, len
) == 0)
6734 do_cleanups (cleanup
);
6741 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6742 as textual description of the location, and COND_STRING
6743 as condition expression. */
6746 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6747 struct symtabs_and_lines sals
, char *addr_string
,
6749 enum bptype type
, enum bpdisp disposition
,
6750 int thread
, int task
, int ignore_count
,
6751 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6753 struct breakpoint
*b
= NULL
;
6756 if (type
== bp_hardware_breakpoint
)
6758 int i
= hw_breakpoint_used_count ();
6759 int target_resources_ok
=
6760 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6762 if (target_resources_ok
== 0)
6763 error (_("No hardware breakpoint support in the target."));
6764 else if (target_resources_ok
< 0)
6765 error (_("Hardware breakpoints used exceeds limit."));
6768 gdb_assert (sals
.nelts
> 0);
6770 for (i
= 0; i
< sals
.nelts
; ++i
)
6772 struct symtab_and_line sal
= sals
.sals
[i
];
6773 struct bp_location
*loc
;
6777 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6779 loc_gdbarch
= gdbarch
;
6781 describe_other_breakpoints (loc_gdbarch
,
6782 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6787 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6788 set_breakpoint_count (breakpoint_count
+ 1);
6789 b
->number
= breakpoint_count
;
6793 b
->cond_string
= cond_string
;
6794 b
->ignore_count
= ignore_count
;
6795 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6796 b
->disposition
= disposition
;
6798 b
->pspace
= sals
.sals
[0].pspace
;
6800 if (enabled
&& b
->pspace
->executing_startup
6801 && (b
->type
== bp_breakpoint
6802 || b
->type
== bp_hardware_breakpoint
))
6803 b
->enable_state
= bp_startup_disabled
;
6809 loc
= add_location_to_breakpoint (b
, &sal
);
6812 if (bp_loc_is_permanent (loc
))
6813 make_breakpoint_permanent (b
);
6817 char *arg
= b
->cond_string
;
6818 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6820 error (_("Garbage %s follows condition"), arg
);
6825 b
->addr_string
= addr_string
;
6827 /* addr_string has to be used or breakpoint_re_set will delete
6830 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6836 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6837 elements to fill the void space. */
6839 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6841 int i
= index_to_remove
+1;
6842 int last_index
= sal
->nelts
-1;
6844 for (;i
<= last_index
; ++i
)
6845 sal
->sals
[i
-1] = sal
->sals
[i
];
6850 /* If appropriate, obtains all sals that correspond to the same file
6851 and line as SAL, in all program spaces. Users debugging with IDEs,
6852 will want to set a breakpoint at foo.c:line, and not really care
6853 about program spaces. This is done only if SAL does not have
6854 explicit PC and has line and file information. If we got just a
6855 single expanded sal, return the original.
6857 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6858 which the name of enclosing function is different from SAL. This
6859 makes sure that if we have breakpoint originally set in template
6860 instantiation, say foo<int>(), we won't expand SAL to locations at
6861 the same line in all existing instantiations of 'foo'. */
6863 static struct symtabs_and_lines
6864 expand_line_sal_maybe (struct symtab_and_line sal
)
6866 struct symtabs_and_lines expanded
;
6867 CORE_ADDR original_pc
= sal
.pc
;
6868 char *original_function
= NULL
;
6871 struct cleanup
*old_chain
;
6873 /* If we have explicit pc, don't expand.
6874 If we have no line number, we can't expand. */
6875 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6878 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6879 expanded
.sals
[0] = sal
;
6885 old_chain
= save_current_space_and_thread ();
6887 switch_to_program_space_and_thread (sal
.pspace
);
6889 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6891 /* Note that expand_line_sal visits *all* program spaces. */
6892 expanded
= expand_line_sal (sal
);
6894 if (expanded
.nelts
== 1)
6896 /* We had one sal, we got one sal. Return that sal, adjusting it
6897 past the function prologue if necessary. */
6898 xfree (expanded
.sals
);
6900 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6901 sal
.pc
= original_pc
;
6902 expanded
.sals
[0] = sal
;
6903 skip_prologue_sal (&expanded
.sals
[0]);
6904 do_cleanups (old_chain
);
6908 if (!sal
.explicit_line
)
6910 CORE_ADDR func_addr
, func_end
;
6911 for (i
= 0; i
< expanded
.nelts
; ++i
)
6913 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6914 char *this_function
;
6916 /* We need to switch threads as well since we're about to
6918 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6920 if (find_pc_partial_function (pc
, &this_function
,
6921 &func_addr
, &func_end
))
6924 && strcmp (this_function
, original_function
) != 0)
6926 remove_sal (&expanded
, i
);
6929 else if (func_addr
== pc
)
6931 /* We're at beginning of a function, and should
6933 struct symbol
*sym
= find_pc_function (pc
);
6935 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
6938 /* Since find_pc_partial_function returned true,
6939 we should really always find the section here. */
6940 struct obj_section
*section
= find_pc_section (pc
);
6943 struct gdbarch
*gdbarch
6944 = get_objfile_arch (section
->objfile
);
6946 = gdbarch_skip_prologue (gdbarch
, pc
);
6955 for (i
= 0; i
< expanded
.nelts
; ++i
)
6957 /* If this SAL corresponds to a breakpoint inserted using a
6958 line number, then skip the function prologue if necessary. */
6959 skip_prologue_sal (&expanded
.sals
[i
]);
6963 do_cleanups (old_chain
);
6965 if (expanded
.nelts
<= 1)
6967 /* This is un ugly workaround. If we get zero
6968 expanded sals then something is really wrong.
6969 Fix that by returnign the original sal. */
6970 xfree (expanded
.sals
);
6972 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6973 sal
.pc
= original_pc
;
6974 expanded
.sals
[0] = sal
;
6981 for (i
= 0; i
< expanded
.nelts
; ++i
)
6982 if (expanded
.sals
[i
].pc
== original_pc
)
6993 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6994 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6995 value. COND_STRING, if not NULL, specified the condition to be
6996 used for all breakpoints. Essentially the only case where
6997 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6998 function. In that case, it's still not possible to specify
6999 separate conditions for different overloaded functions, so
7000 we take just a single condition string.
7002 NOTE: If the function succeeds, the caller is expected to cleanup
7003 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7004 array contents). If the function fails (error() is called), the
7005 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7006 COND and SALS arrays and each of those arrays contents. */
7009 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7010 struct symtabs_and_lines sals
, char **addr_string
,
7012 enum bptype type
, enum bpdisp disposition
,
7013 int thread
, int task
, int ignore_count
,
7014 struct breakpoint_ops
*ops
, int from_tty
,
7018 for (i
= 0; i
< sals
.nelts
; ++i
)
7020 struct symtabs_and_lines expanded
=
7021 expand_line_sal_maybe (sals
.sals
[i
]);
7023 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7024 cond_string
, type
, disposition
,
7025 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7029 /* Parse ARG which is assumed to be a SAL specification possibly
7030 followed by conditionals. On return, SALS contains an array of SAL
7031 addresses found. ADDR_STRING contains a vector of (canonical)
7032 address strings. ARG points to the end of the SAL. */
7035 parse_breakpoint_sals (char **address
,
7036 struct symtabs_and_lines
*sals
,
7037 char ***addr_string
,
7040 char *addr_start
= *address
;
7041 *addr_string
= NULL
;
7042 /* If no arg given, or if first arg is 'if ', use the default
7044 if ((*address
) == NULL
7045 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7047 if (default_breakpoint_valid
)
7049 struct symtab_and_line sal
;
7050 init_sal (&sal
); /* initialize to zeroes */
7051 sals
->sals
= (struct symtab_and_line
*)
7052 xmalloc (sizeof (struct symtab_and_line
));
7053 sal
.pc
= default_breakpoint_address
;
7054 sal
.line
= default_breakpoint_line
;
7055 sal
.symtab
= default_breakpoint_symtab
;
7056 sal
.pspace
= default_breakpoint_pspace
;
7057 sal
.section
= find_pc_overlay (sal
.pc
);
7059 /* "break" without arguments is equivalent to "break *PC" where PC is
7060 the default_breakpoint_address. So make sure to set
7061 sal.explicit_pc to prevent GDB from trying to expand the list of
7062 sals to include all other instances with the same symtab and line.
7064 sal
.explicit_pc
= 1;
7066 sals
->sals
[0] = sal
;
7070 error (_("No default breakpoint address now."));
7074 /* Force almost all breakpoints to be in terms of the
7075 current_source_symtab (which is decode_line_1's default). This
7076 should produce the results we want almost all of the time while
7077 leaving default_breakpoint_* alone.
7078 ObjC: However, don't match an Objective-C method name which
7079 may have a '+' or '-' succeeded by a '[' */
7081 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7083 if (default_breakpoint_valid
7085 || ((strchr ("+-", (*address
)[0]) != NULL
)
7086 && ((*address
)[1] != '['))))
7087 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7088 default_breakpoint_line
, addr_string
,
7091 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7092 addr_string
, not_found_ptr
);
7094 /* For any SAL that didn't have a canonical string, fill one in. */
7095 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7096 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7097 if (addr_start
!= (*address
))
7100 for (i
= 0; i
< sals
->nelts
; i
++)
7102 /* Add the string if not present. */
7103 if ((*addr_string
)[i
] == NULL
)
7104 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7110 /* Convert each SAL into a real PC. Verify that the PC can be
7111 inserted as a breakpoint. If it can't throw an error. */
7114 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7118 for (i
= 0; i
< sals
->nelts
; i
++)
7119 resolve_sal_pc (&sals
->sals
[i
]);
7122 /* Fast tracepoints may have restrictions on valid locations. For
7123 instance, a fast tracepoint using a jump instead of a trap will
7124 likely have to overwrite more bytes than a trap would, and so can
7125 only be placed where the instruction is longer than the jump, or a
7126 multi-instruction sequence does not have a jump into the middle of
7130 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7131 struct symtabs_and_lines
*sals
)
7134 struct symtab_and_line
*sal
;
7136 struct cleanup
*old_chain
;
7138 for (i
= 0; i
< sals
->nelts
; i
++)
7140 sal
= &sals
->sals
[i
];
7142 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7144 old_chain
= make_cleanup (xfree
, msg
);
7147 error (_("May not have a fast tracepoint at 0x%s%s"),
7148 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7150 do_cleanups (old_chain
);
7155 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7157 struct captured_parse_breakpoint_args
*args
= data
;
7159 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7160 args
->not_found_ptr
);
7163 /* Given TOK, a string specification of condition and thread, as
7164 accepted by the 'break' command, extract the condition
7165 string and thread number and set *COND_STRING and *THREAD.
7166 PC identifies the context at which the condition should be parsed.
7167 If no condition is found, *COND_STRING is set to NULL.
7168 If no thread is found, *THREAD is set to -1. */
7170 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7171 char **cond_string
, int *thread
, int *task
)
7173 *cond_string
= NULL
;
7179 char *cond_start
= NULL
;
7180 char *cond_end
= NULL
;
7181 while (*tok
== ' ' || *tok
== '\t')
7186 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7189 toklen
= end_tok
- tok
;
7191 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7193 struct expression
*expr
;
7195 tok
= cond_start
= end_tok
+ 1;
7196 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7199 *cond_string
= savestring (cond_start
,
7200 cond_end
- cond_start
);
7202 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7208 *thread
= strtol (tok
, &tok
, 0);
7210 error (_("Junk after thread keyword."));
7211 if (!valid_thread_id (*thread
))
7212 error (_("Unknown thread %d."), *thread
);
7214 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7220 *task
= strtol (tok
, &tok
, 0);
7222 error (_("Junk after task keyword."));
7223 if (!valid_task_id (*task
))
7224 error (_("Unknown task %d."), *task
);
7227 error (_("Junk at end of arguments."));
7231 /* Set a breakpoint. This function is shared between CLI and MI
7232 functions for setting a breakpoint. This function has two major
7233 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7234 parameter. If non-zero, the function will parse arg, extracting
7235 breakpoint location, address and thread. Otherwise, ARG is just the
7236 location of breakpoint, with condition and thread specified by the
7237 COND_STRING and THREAD parameters. Returns true if any breakpoint
7238 was created; false otherwise. */
7241 create_breakpoint (struct gdbarch
*gdbarch
,
7242 char *arg
, char *cond_string
, int thread
,
7243 int parse_condition_and_thread
,
7244 int tempflag
, int hardwareflag
, int traceflag
,
7246 enum auto_boolean pending_break_support
,
7247 struct breakpoint_ops
*ops
,
7251 struct gdb_exception e
;
7252 struct symtabs_and_lines sals
;
7253 struct symtab_and_line pending_sal
;
7256 char *addr_start
= arg
;
7258 struct cleanup
*old_chain
;
7259 struct cleanup
*bkpt_chain
= NULL
;
7260 struct captured_parse_breakpoint_args parse_args
;
7264 enum bptype type_wanted
;
7266 int first_bp_set
= breakpoint_count
+ 1;
7272 parse_args
.arg_p
= &arg
;
7273 parse_args
.sals_p
= &sals
;
7274 parse_args
.addr_string_p
= &addr_string
;
7275 parse_args
.not_found_ptr
= ¬_found
;
7277 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7278 &parse_args
, RETURN_MASK_ALL
);
7280 /* If caller is interested in rc value from parse, set value. */
7284 throw_exception (e
);
7288 case NOT_FOUND_ERROR
:
7290 /* If pending breakpoint support is turned off, throw
7293 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7294 throw_exception (e
);
7296 exception_print (gdb_stderr
, e
);
7298 /* If pending breakpoint support is auto query and the user
7299 selects no, then simply return the error code. */
7300 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7301 && !nquery ("Make breakpoint pending on future shared library load? "))
7304 /* At this point, either the user was queried about setting
7305 a pending breakpoint and selected yes, or pending
7306 breakpoint behavior is on and thus a pending breakpoint
7307 is defaulted on behalf of the user. */
7308 copy_arg
= xstrdup (addr_start
);
7309 addr_string
= ©_arg
;
7311 sals
.sals
= &pending_sal
;
7316 throw_exception (e
);
7323 /* Create a chain of things that always need to be cleaned up. */
7324 old_chain
= make_cleanup (null_cleanup
, 0);
7328 /* Make sure that all storage allocated to SALS gets freed. */
7329 make_cleanup (xfree
, sals
.sals
);
7331 /* Cleanup the addr_string array but not its contents. */
7332 make_cleanup (xfree
, addr_string
);
7335 /* ----------------------------- SNIP -----------------------------
7336 Anything added to the cleanup chain beyond this point is assumed
7337 to be part of a breakpoint. If the breakpoint create succeeds
7338 then the memory is not reclaimed. */
7339 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7341 /* Mark the contents of the addr_string for cleanup. These go on
7342 the bkpt_chain and only occur if the breakpoint create fails. */
7343 for (i
= 0; i
< sals
.nelts
; i
++)
7345 if (addr_string
[i
] != NULL
)
7346 make_cleanup (xfree
, addr_string
[i
]);
7349 /* Resolve all line numbers to PC's and verify that the addresses
7350 are ok for the target. */
7352 breakpoint_sals_to_pc (&sals
, addr_start
);
7354 type_wanted
= (traceflag
7355 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7356 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7358 /* Fast tracepoints may have additional restrictions on location. */
7359 if (type_wanted
== bp_fast_tracepoint
)
7360 check_fast_tracepoint_sals (gdbarch
, &sals
);
7362 /* Verify that condition can be parsed, before setting any
7363 breakpoints. Allocate a separate condition expression for each
7367 if (parse_condition_and_thread
)
7369 /* Here we only parse 'arg' to separate condition
7370 from thread number, so parsing in context of first
7371 sal is OK. When setting the breakpoint we'll
7372 re-parse it in context of each sal. */
7375 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7378 make_cleanup (xfree
, cond_string
);
7382 /* Create a private copy of condition string. */
7385 cond_string
= xstrdup (cond_string
);
7386 make_cleanup (xfree
, cond_string
);
7389 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7390 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7391 thread
, task
, ignore_count
, ops
, from_tty
,
7396 struct symtab_and_line sal
= {0};
7397 struct breakpoint
*b
;
7399 make_cleanup (xfree
, copy_arg
);
7401 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7402 set_breakpoint_count (breakpoint_count
+ 1);
7403 b
->number
= breakpoint_count
;
7405 b
->addr_string
= addr_string
[0];
7406 b
->cond_string
= NULL
;
7407 b
->ignore_count
= ignore_count
;
7408 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7409 b
->condition_not_parsed
= 1;
7411 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7412 b
->pspace
= current_program_space
;
7414 if (enabled
&& b
->pspace
->executing_startup
7415 && (b
->type
== bp_breakpoint
7416 || b
->type
== bp_hardware_breakpoint
))
7417 b
->enable_state
= bp_startup_disabled
;
7424 warning (_("Multiple breakpoints were set.\n"
7425 "Use the \"delete\" command to delete unwanted breakpoints."));
7426 multi_start
= first_bp_set
;
7427 multi_end
= breakpoint_count
;
7431 /* That's it. Discard the cleanups for data inserted into the
7433 discard_cleanups (bkpt_chain
);
7434 /* But cleanup everything else. */
7435 do_cleanups (old_chain
);
7437 /* error call may happen here - have BKPT_CHAIN already discarded. */
7438 update_global_location_list (1);
7443 /* Set a breakpoint.
7444 ARG is a string describing breakpoint address,
7445 condition, and thread.
7446 FLAG specifies if a breakpoint is hardware on,
7447 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7451 break_command_1 (char *arg
, int flag
, int from_tty
)
7453 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7454 int tempflag
= flag
& BP_TEMPFLAG
;
7456 create_breakpoint (get_current_arch (),
7458 NULL
, 0, 1 /* parse arg */,
7459 tempflag
, hardwareflag
, 0 /* traceflag */,
7460 0 /* Ignore count */,
7461 pending_break_support
,
7462 NULL
/* breakpoint_ops */,
7469 /* Adjust SAL to the first instruction past the function prologue.
7470 The end of the prologue is determined using the line table from
7471 the debugging information. explicit_pc and explicit_line are
7474 If SAL is already past the prologue, then do nothing. */
7477 skip_prologue_sal (struct symtab_and_line
*sal
)
7480 struct symtab_and_line start_sal
;
7481 struct cleanup
*old_chain
;
7483 old_chain
= save_current_space_and_thread ();
7485 sym
= find_pc_function (sal
->pc
);
7488 start_sal
= find_function_start_sal (sym
, 1);
7489 if (sal
->pc
< start_sal
.pc
)
7491 start_sal
.explicit_line
= sal
->explicit_line
;
7492 start_sal
.explicit_pc
= sal
->explicit_pc
;
7497 do_cleanups (old_chain
);
7500 /* Helper function for break_command_1 and disassemble_command. */
7503 resolve_sal_pc (struct symtab_and_line
*sal
)
7507 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7509 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7510 error (_("No line %d in file \"%s\"."),
7511 sal
->line
, sal
->symtab
->filename
);
7514 /* If this SAL corresponds to a breakpoint inserted using
7515 a line number, then skip the function prologue if necessary. */
7516 if (sal
->explicit_line
)
7518 /* Preserve the original line number. */
7519 int saved_line
= sal
->line
;
7520 skip_prologue_sal (sal
);
7521 sal
->line
= saved_line
;
7525 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7527 struct blockvector
*bv
;
7531 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7534 sym
= block_linkage_function (b
);
7537 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7538 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7542 /* It really is worthwhile to have the section, so we'll just
7543 have to look harder. This case can be executed if we have
7544 line numbers but no functions (as can happen in assembly
7547 struct minimal_symbol
*msym
;
7548 struct cleanup
*old_chain
= save_current_space_and_thread ();
7550 switch_to_program_space_and_thread (sal
->pspace
);
7552 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7554 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7556 do_cleanups (old_chain
);
7563 break_command (char *arg
, int from_tty
)
7565 break_command_1 (arg
, 0, from_tty
);
7569 tbreak_command (char *arg
, int from_tty
)
7571 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7575 hbreak_command (char *arg
, int from_tty
)
7577 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7581 thbreak_command (char *arg
, int from_tty
)
7583 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7587 stop_command (char *arg
, int from_tty
)
7589 printf_filtered (_("Specify the type of breakpoint to set.\n\
7590 Usage: stop in <function | address>\n\
7591 stop at <line>\n"));
7595 stopin_command (char *arg
, int from_tty
)
7599 if (arg
== (char *) NULL
)
7601 else if (*arg
!= '*')
7606 /* look for a ':'. If this is a line number specification, then
7607 say it is bad, otherwise, it should be an address or
7608 function/method name */
7609 while (*argptr
&& !hasColon
)
7611 hasColon
= (*argptr
== ':');
7616 badInput
= (*argptr
!= ':'); /* Not a class::method */
7618 badInput
= isdigit (*arg
); /* a simple line number */
7622 printf_filtered (_("Usage: stop in <function | address>\n"));
7624 break_command_1 (arg
, 0, from_tty
);
7628 stopat_command (char *arg
, int from_tty
)
7632 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7639 /* look for a ':'. If there is a '::' then get out, otherwise
7640 it is probably a line number. */
7641 while (*argptr
&& !hasColon
)
7643 hasColon
= (*argptr
== ':');
7648 badInput
= (*argptr
== ':'); /* we have class::method */
7650 badInput
= !isdigit (*arg
); /* not a line number */
7654 printf_filtered (_("Usage: stop at <line>\n"));
7656 break_command_1 (arg
, 0, from_tty
);
7659 /* accessflag: hw_write: watch write,
7660 hw_read: watch read,
7661 hw_access: watch access (read or write) */
7663 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7665 struct gdbarch
*gdbarch
= get_current_arch ();
7666 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7667 struct expression
*exp
;
7668 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7669 struct value
*val
, *mark
;
7670 struct frame_info
*frame
;
7671 char *exp_start
= NULL
;
7672 char *exp_end
= NULL
;
7673 char *tok
, *id_tok_start
, *end_tok
;
7675 char *cond_start
= NULL
;
7676 char *cond_end
= NULL
;
7677 int i
, other_type_used
, target_resources_ok
= 0;
7678 enum bptype bp_type
;
7682 /* Make sure that we actually have parameters to parse. */
7683 if (arg
!= NULL
&& arg
[0] != '\0')
7685 toklen
= strlen (arg
); /* Size of argument list. */
7687 /* Points tok to the end of the argument list. */
7688 tok
= arg
+ toklen
- 1;
7690 /* Go backwards in the parameters list. Skip the last parameter.
7691 If we're expecting a 'thread <thread_num>' parameter, this should
7692 be the thread identifier. */
7693 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7695 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7698 /* Points end_tok to the beginning of the last token. */
7699 id_tok_start
= tok
+ 1;
7701 /* Go backwards in the parameters list. Skip one more parameter.
7702 If we're expecting a 'thread <thread_num>' parameter, we should
7703 reach a "thread" token. */
7704 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7709 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7712 /* Move the pointer forward to skip the whitespace and
7713 calculate the length of the token. */
7715 toklen
= end_tok
- tok
;
7717 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7719 /* At this point we've found a "thread" token, which means
7720 the user is trying to set a watchpoint that triggers
7721 only in a specific thread. */
7724 /* Extract the thread ID from the next token. */
7725 thread
= strtol (id_tok_start
, &endp
, 0);
7727 /* Check if the user provided a valid numeric value for the
7729 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7730 error (_("Invalid thread ID specification %s."), id_tok_start
);
7732 /* Check if the thread actually exists. */
7733 if (!valid_thread_id (thread
))
7734 error (_("Unknown thread %d."), thread
);
7736 /* Truncate the string and get rid of the thread <thread_num>
7737 parameter before the parameter list is parsed by the
7738 evaluate_expression() function. */
7743 /* Parse the rest of the arguments. */
7744 innermost_block
= NULL
;
7746 exp
= parse_exp_1 (&arg
, 0, 0);
7748 /* Remove trailing whitespace from the expression before saving it.
7749 This makes the eventual display of the expression string a bit
7751 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7754 exp_valid_block
= innermost_block
;
7755 mark
= value_mark ();
7756 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7758 release_value (val
);
7761 while (*tok
== ' ' || *tok
== '\t')
7765 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7768 toklen
= end_tok
- tok
;
7769 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7771 struct expression
*cond
;
7773 innermost_block
= NULL
;
7774 tok
= cond_start
= end_tok
+ 1;
7775 cond
= parse_exp_1 (&tok
, 0, 0);
7777 /* The watchpoint expression may not be local, but the condition
7778 may still be. E.g.: `watch global if local > 0'. */
7779 cond_exp_valid_block
= innermost_block
;
7785 error (_("Junk at end of command."));
7787 if (accessflag
== hw_read
)
7788 bp_type
= bp_read_watchpoint
;
7789 else if (accessflag
== hw_access
)
7790 bp_type
= bp_access_watchpoint
;
7792 bp_type
= bp_hardware_watchpoint
;
7794 mem_cnt
= can_use_hardware_watchpoint (val
);
7795 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7796 error (_("Expression cannot be implemented with read/access watchpoint."));
7799 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7800 target_resources_ok
=
7801 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7803 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7804 error (_("Target does not support this type of hardware watchpoint."));
7806 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7807 error (_("Target can only support one kind of HW watchpoint at a time."));
7810 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7811 watchpoint could not be set. */
7812 if (!mem_cnt
|| target_resources_ok
<= 0)
7813 bp_type
= bp_watchpoint
;
7815 frame
= block_innermost_frame (exp_valid_block
);
7817 /* If the expression is "local", then set up a "watchpoint scope"
7818 breakpoint at the point where we've left the scope of the watchpoint
7819 expression. Create the scope breakpoint before the watchpoint, so
7820 that we will encounter it first in bpstat_stop_status. */
7821 if (exp_valid_block
&& frame
)
7823 if (frame_id_p (frame_unwind_caller_id (frame
)))
7826 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7827 frame_unwind_caller_pc (frame
),
7828 bp_watchpoint_scope
);
7830 scope_breakpoint
->enable_state
= bp_enabled
;
7832 /* Automatically delete the breakpoint when it hits. */
7833 scope_breakpoint
->disposition
= disp_del
;
7835 /* Only break in the proper frame (help with recursion). */
7836 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7838 /* Set the address at which we will stop. */
7839 scope_breakpoint
->loc
->gdbarch
7840 = frame_unwind_caller_arch (frame
);
7841 scope_breakpoint
->loc
->requested_address
7842 = frame_unwind_caller_pc (frame
);
7843 scope_breakpoint
->loc
->address
7844 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7845 scope_breakpoint
->loc
->requested_address
,
7846 scope_breakpoint
->type
);
7850 /* Now set up the breakpoint. */
7851 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7852 set_breakpoint_count (breakpoint_count
+ 1);
7853 b
->number
= breakpoint_count
;
7855 b
->disposition
= disp_donttouch
;
7857 b
->exp_valid_block
= exp_valid_block
;
7858 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7859 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7863 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7869 b
->watchpoint_frame
= get_frame_id (frame
);
7870 b
->watchpoint_thread
= inferior_ptid
;
7874 b
->watchpoint_frame
= null_frame_id
;
7875 b
->watchpoint_thread
= null_ptid
;
7878 if (scope_breakpoint
!= NULL
)
7880 /* The scope breakpoint is related to the watchpoint. We will
7881 need to act on them together. */
7882 b
->related_breakpoint
= scope_breakpoint
;
7883 scope_breakpoint
->related_breakpoint
= b
;
7886 value_free_to_mark (mark
);
7888 /* Finally update the new watchpoint. This creates the locations
7889 that should be inserted. */
7890 update_watchpoint (b
, 1);
7893 update_global_location_list (1);
7896 /* Return count of locations need to be watched and can be handled
7897 in hardware. If the watchpoint can not be handled
7898 in hardware return zero. */
7901 can_use_hardware_watchpoint (struct value
*v
)
7903 int found_memory_cnt
= 0;
7904 struct value
*head
= v
;
7906 /* Did the user specifically forbid us to use hardware watchpoints? */
7907 if (!can_use_hw_watchpoints
)
7910 /* Make sure that the value of the expression depends only upon
7911 memory contents, and values computed from them within GDB. If we
7912 find any register references or function calls, we can't use a
7913 hardware watchpoint.
7915 The idea here is that evaluating an expression generates a series
7916 of values, one holding the value of every subexpression. (The
7917 expression a*b+c has five subexpressions: a, b, a*b, c, and
7918 a*b+c.) GDB's values hold almost enough information to establish
7919 the criteria given above --- they identify memory lvalues,
7920 register lvalues, computed values, etcetera. So we can evaluate
7921 the expression, and then scan the chain of values that leaves
7922 behind to decide whether we can detect any possible change to the
7923 expression's final value using only hardware watchpoints.
7925 However, I don't think that the values returned by inferior
7926 function calls are special in any way. So this function may not
7927 notice that an expression involving an inferior function call
7928 can't be watched with hardware watchpoints. FIXME. */
7929 for (; v
; v
= value_next (v
))
7931 if (VALUE_LVAL (v
) == lval_memory
)
7934 /* A lazy memory lvalue is one that GDB never needed to fetch;
7935 we either just used its address (e.g., `a' in `a.b') or
7936 we never needed it at all (e.g., `a' in `a,b'). */
7940 /* Ahh, memory we actually used! Check if we can cover
7941 it with hardware watchpoints. */
7942 struct type
*vtype
= check_typedef (value_type (v
));
7944 /* We only watch structs and arrays if user asked for it
7945 explicitly, never if they just happen to appear in a
7946 middle of some value chain. */
7948 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7949 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7951 CORE_ADDR vaddr
= value_address (v
);
7952 int len
= TYPE_LENGTH (value_type (v
));
7954 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7961 else if (VALUE_LVAL (v
) != not_lval
7962 && deprecated_value_modifiable (v
) == 0)
7963 return 0; /* ??? What does this represent? */
7964 else if (VALUE_LVAL (v
) == lval_register
)
7965 return 0; /* cannot watch a register with a HW watchpoint */
7968 /* The expression itself looks suitable for using a hardware
7969 watchpoint, but give the target machine a chance to reject it. */
7970 return found_memory_cnt
;
7974 watch_command_wrapper (char *arg
, int from_tty
)
7976 watch_command (arg
, from_tty
);
7980 watch_command (char *arg
, int from_tty
)
7982 watch_command_1 (arg
, hw_write
, from_tty
);
7986 rwatch_command_wrapper (char *arg
, int from_tty
)
7988 rwatch_command (arg
, from_tty
);
7992 rwatch_command (char *arg
, int from_tty
)
7994 watch_command_1 (arg
, hw_read
, from_tty
);
7998 awatch_command_wrapper (char *arg
, int from_tty
)
8000 awatch_command (arg
, from_tty
);
8004 awatch_command (char *arg
, int from_tty
)
8006 watch_command_1 (arg
, hw_access
, from_tty
);
8010 /* Helper routines for the until_command routine in infcmd.c. Here
8011 because it uses the mechanisms of breakpoints. */
8013 struct until_break_command_continuation_args
8015 struct breakpoint
*breakpoint
;
8016 struct breakpoint
*breakpoint2
;
8019 /* This function is called by fetch_inferior_event via the
8020 cmd_continuation pointer, to complete the until command. It takes
8021 care of cleaning up the temporary breakpoints set up by the until
8024 until_break_command_continuation (void *arg
)
8026 struct until_break_command_continuation_args
*a
= arg
;
8028 delete_breakpoint (a
->breakpoint
);
8030 delete_breakpoint (a
->breakpoint2
);
8034 until_break_command (char *arg
, int from_tty
, int anywhere
)
8036 struct symtabs_and_lines sals
;
8037 struct symtab_and_line sal
;
8038 struct frame_info
*frame
= get_selected_frame (NULL
);
8039 struct breakpoint
*breakpoint
;
8040 struct breakpoint
*breakpoint2
= NULL
;
8041 struct cleanup
*old_chain
;
8043 clear_proceed_status ();
8045 /* Set a breakpoint where the user wants it and at return from
8048 if (default_breakpoint_valid
)
8049 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8050 default_breakpoint_line
, (char ***) NULL
, NULL
);
8052 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8053 0, (char ***) NULL
, NULL
);
8055 if (sals
.nelts
!= 1)
8056 error (_("Couldn't get information on specified line."));
8059 xfree (sals
.sals
); /* malloc'd, so freed */
8062 error (_("Junk at end of arguments."));
8064 resolve_sal_pc (&sal
);
8067 /* If the user told us to continue until a specified location,
8068 we don't specify a frame at which we need to stop. */
8069 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8070 null_frame_id
, bp_until
);
8072 /* Otherwise, specify the selected frame, because we want to stop only
8073 at the very same frame. */
8074 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8075 get_stack_frame_id (frame
),
8078 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8080 /* Keep within the current frame, or in frames called by the current
8083 if (frame_id_p (frame_unwind_caller_id (frame
)))
8085 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8086 sal
.pc
= frame_unwind_caller_pc (frame
);
8087 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8089 frame_unwind_caller_id (frame
),
8091 make_cleanup_delete_breakpoint (breakpoint2
);
8094 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8096 /* If we are running asynchronously, and proceed call above has actually
8097 managed to start the target, arrange for breakpoints to be
8098 deleted when the target stops. Otherwise, we're already stopped and
8099 delete breakpoints via cleanup chain. */
8101 if (target_can_async_p () && is_running (inferior_ptid
))
8103 struct until_break_command_continuation_args
*args
;
8104 args
= xmalloc (sizeof (*args
));
8106 args
->breakpoint
= breakpoint
;
8107 args
->breakpoint2
= breakpoint2
;
8109 discard_cleanups (old_chain
);
8110 add_continuation (inferior_thread (),
8111 until_break_command_continuation
, args
,
8115 do_cleanups (old_chain
);
8119 ep_skip_leading_whitespace (char **s
)
8121 if ((s
== NULL
) || (*s
== NULL
))
8123 while (isspace (**s
))
8127 /* This function attempts to parse an optional "if <cond>" clause
8128 from the arg string. If one is not found, it returns NULL.
8130 Else, it returns a pointer to the condition string. (It does not
8131 attempt to evaluate the string against a particular block.) And,
8132 it updates arg to point to the first character following the parsed
8133 if clause in the arg string. */
8136 ep_parse_optional_if_clause (char **arg
)
8140 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8143 /* Skip the "if" keyword. */
8146 /* Skip any extra leading whitespace, and record the start of the
8147 condition string. */
8148 ep_skip_leading_whitespace (arg
);
8151 /* Assume that the condition occupies the remainder of the arg string. */
8152 (*arg
) += strlen (cond_string
);
8157 /* Commands to deal with catching events, such as signals, exceptions,
8158 process start/exit, etc. */
8162 catch_fork_temporary
, catch_vfork_temporary
,
8163 catch_fork_permanent
, catch_vfork_permanent
8168 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8170 struct gdbarch
*gdbarch
= get_current_arch ();
8171 char *cond_string
= NULL
;
8172 catch_fork_kind fork_kind
;
8175 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8176 tempflag
= (fork_kind
== catch_fork_temporary
8177 || fork_kind
== catch_vfork_temporary
);
8181 ep_skip_leading_whitespace (&arg
);
8183 /* The allowed syntax is:
8185 catch [v]fork if <cond>
8187 First, check if there's an if clause. */
8188 cond_string
= ep_parse_optional_if_clause (&arg
);
8190 if ((*arg
!= '\0') && !isspace (*arg
))
8191 error (_("Junk at end of arguments."));
8193 /* If this target supports it, create a fork or vfork catchpoint
8194 and enable reporting of such events. */
8197 case catch_fork_temporary
:
8198 case catch_fork_permanent
:
8199 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8200 &catch_fork_breakpoint_ops
);
8202 case catch_vfork_temporary
:
8203 case catch_vfork_permanent
:
8204 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8205 &catch_vfork_breakpoint_ops
);
8208 error (_("unsupported or unknown fork kind; cannot catch it"));
8214 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8216 struct gdbarch
*gdbarch
= get_current_arch ();
8218 char *cond_string
= NULL
;
8220 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8224 ep_skip_leading_whitespace (&arg
);
8226 /* The allowed syntax is:
8228 catch exec if <cond>
8230 First, check if there's an if clause. */
8231 cond_string
= ep_parse_optional_if_clause (&arg
);
8233 if ((*arg
!= '\0') && !isspace (*arg
))
8234 error (_("Junk at end of arguments."));
8236 /* If this target supports it, create an exec catchpoint
8237 and enable reporting of such events. */
8238 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8239 &catch_exec_breakpoint_ops
);
8242 static enum print_stop_action
8243 print_exception_catchpoint (struct breakpoint
*b
)
8245 int bp_temp
, bp_throw
;
8247 annotate_catchpoint (b
->number
);
8249 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8250 if (b
->loc
->address
!= b
->loc
->requested_address
)
8251 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8254 bp_temp
= b
->disposition
== disp_del
;
8256 bp_temp
? "Temporary catchpoint "
8258 if (!ui_out_is_mi_like_p (uiout
))
8259 ui_out_field_int (uiout
, "bkptno", b
->number
);
8261 bp_throw
? " (exception thrown), "
8262 : " (exception caught), ");
8263 if (ui_out_is_mi_like_p (uiout
))
8265 ui_out_field_string (uiout
, "reason",
8266 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8267 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8268 ui_out_field_int (uiout
, "bkptno", b
->number
);
8270 return PRINT_SRC_AND_LOC
;
8274 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8276 struct value_print_options opts
;
8277 get_user_print_options (&opts
);
8278 if (opts
.addressprint
)
8281 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8282 ui_out_field_string (uiout
, "addr", "<PENDING>");
8284 ui_out_field_core_addr (uiout
, "addr",
8285 b
->loc
->gdbarch
, b
->loc
->address
);
8290 if (strstr (b
->addr_string
, "throw") != NULL
)
8291 ui_out_field_string (uiout
, "what", "exception throw");
8293 ui_out_field_string (uiout
, "what", "exception catch");
8297 print_mention_exception_catchpoint (struct breakpoint
*b
)
8302 bp_temp
= b
->disposition
== disp_del
;
8303 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8304 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8305 : _("Catchpoint "));
8306 ui_out_field_int (uiout
, "bkptno", b
->number
);
8307 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8311 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8314 NULL
, /* breakpoint_hit */
8315 print_exception_catchpoint
,
8316 print_one_exception_catchpoint
,
8317 print_mention_exception_catchpoint
8321 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8322 enum exception_event_kind ex_event
, int from_tty
)
8324 char *trigger_func_name
;
8326 if (ex_event
== EX_EVENT_CATCH
)
8327 trigger_func_name
= "__cxa_begin_catch";
8329 trigger_func_name
= "__cxa_throw";
8331 create_breakpoint (get_current_arch (),
8332 trigger_func_name
, cond_string
, -1,
8333 0 /* condition and thread are valid. */,
8336 AUTO_BOOLEAN_TRUE
/* pending */,
8337 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8343 /* Deal with "catch catch" and "catch throw" commands */
8346 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8347 int tempflag
, int from_tty
)
8349 char *cond_string
= NULL
;
8350 struct symtab_and_line
*sal
= NULL
;
8354 ep_skip_leading_whitespace (&arg
);
8356 cond_string
= ep_parse_optional_if_clause (&arg
);
8358 if ((*arg
!= '\0') && !isspace (*arg
))
8359 error (_("Junk at end of arguments."));
8361 if (ex_event
!= EX_EVENT_THROW
8362 && ex_event
!= EX_EVENT_CATCH
)
8363 error (_("Unsupported or unknown exception event; cannot catch it"));
8365 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8368 warning (_("Unsupported with this platform/compiler combination."));
8371 /* Implementation of "catch catch" command. */
8374 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8376 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8377 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8380 /* Implementation of "catch throw" command. */
8383 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8385 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8386 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8389 /* Create a breakpoint struct for Ada exception catchpoints. */
8392 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8393 struct symtab_and_line sal
,
8397 struct expression
*cond
,
8398 struct breakpoint_ops
*ops
,
8402 struct breakpoint
*b
;
8406 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8408 loc_gdbarch
= gdbarch
;
8410 describe_other_breakpoints (loc_gdbarch
,
8411 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8412 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8413 version for exception catchpoints, because two catchpoints
8414 used for different exception names will use the same address.
8415 In this case, a "breakpoint ... also set at..." warning is
8416 unproductive. Besides. the warning phrasing is also a bit
8417 inapropriate, we should use the word catchpoint, and tell
8418 the user what type of catchpoint it is. The above is good
8419 enough for now, though. */
8422 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8423 set_breakpoint_count (breakpoint_count
+ 1);
8425 b
->enable_state
= bp_enabled
;
8426 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8427 b
->number
= breakpoint_count
;
8428 b
->ignore_count
= 0;
8429 b
->loc
->cond
= cond
;
8430 b
->addr_string
= addr_string
;
8431 b
->language
= language_ada
;
8432 b
->cond_string
= cond_string
;
8433 b
->exp_string
= exp_string
;
8438 update_global_location_list (1);
8441 /* Implement the "catch exception" command. */
8444 catch_ada_exception_command (char *arg
, int from_tty
,
8445 struct cmd_list_element
*command
)
8447 struct gdbarch
*gdbarch
= get_current_arch ();
8449 struct symtab_and_line sal
;
8451 char *addr_string
= NULL
;
8452 char *exp_string
= NULL
;
8453 char *cond_string
= NULL
;
8454 struct expression
*cond
= NULL
;
8455 struct breakpoint_ops
*ops
= NULL
;
8457 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8461 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8462 &cond_string
, &cond
, &ops
);
8463 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8464 cond_string
, cond
, ops
, tempflag
,
8468 /* Cleanup function for a syscall filter list. */
8470 clean_up_filters (void *arg
)
8472 VEC(int) *iter
= *(VEC(int) **) arg
;
8473 VEC_free (int, iter
);
8476 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8477 filter list, or NULL if no filtering is required. */
8479 catch_syscall_split_args (char *arg
)
8481 VEC(int) *result
= NULL
;
8482 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8484 while (*arg
!= '\0')
8486 int i
, syscall_number
;
8491 /* Skip whitespace. */
8492 while (isspace (*arg
))
8495 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8496 cur_name
[i
] = arg
[i
];
8500 /* Check if the user provided a syscall name or a number. */
8501 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8502 if (*endptr
== '\0')
8503 get_syscall_by_number (syscall_number
, &s
);
8506 /* We have a name. Let's check if it's valid and convert it
8508 get_syscall_by_name (cur_name
, &s
);
8510 if (s
.number
== UNKNOWN_SYSCALL
)
8511 /* Here we have to issue an error instead of a warning, because
8512 GDB cannot do anything useful if there's no syscall number to
8514 error (_("Unknown syscall name '%s'."), cur_name
);
8517 /* Ok, it's valid. */
8518 VEC_safe_push (int, result
, s
.number
);
8521 discard_cleanups (cleanup
);
8525 /* Implement the "catch syscall" command. */
8528 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8533 struct gdbarch
*gdbarch
= get_current_arch ();
8535 /* Checking if the feature if supported. */
8536 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8537 error (_("The feature 'catch syscall' is not supported on \
8538 this architeture yet."));
8540 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8542 ep_skip_leading_whitespace (&arg
);
8544 /* We need to do this first "dummy" translation in order
8545 to get the syscall XML file loaded or, most important,
8546 to display a warning to the user if there's no XML file
8547 for his/her architecture. */
8548 get_syscall_by_number (0, &s
);
8550 /* The allowed syntax is:
8552 catch syscall <name | number> [<name | number> ... <name | number>]
8554 Let's check if there's a syscall name. */
8557 filter
= catch_syscall_split_args (arg
);
8561 create_syscall_event_catchpoint (tempflag
, filter
,
8562 &catch_syscall_breakpoint_ops
);
8565 /* Implement the "catch assert" command. */
8568 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8570 struct gdbarch
*gdbarch
= get_current_arch ();
8572 struct symtab_and_line sal
;
8573 char *addr_string
= NULL
;
8574 struct breakpoint_ops
*ops
= NULL
;
8576 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8580 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8581 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8582 ops
, tempflag
, from_tty
);
8586 catch_command (char *arg
, int from_tty
)
8588 error (_("Catch requires an event name."));
8593 tcatch_command (char *arg
, int from_tty
)
8595 error (_("Catch requires an event name."));
8598 /* Delete breakpoints by address or line. */
8601 clear_command (char *arg
, int from_tty
)
8603 struct breakpoint
*b
;
8604 VEC(breakpoint_p
) *found
= 0;
8607 struct symtabs_and_lines sals
;
8608 struct symtab_and_line sal
;
8613 sals
= decode_line_spec (arg
, 1);
8618 sals
.sals
= (struct symtab_and_line
*)
8619 xmalloc (sizeof (struct symtab_and_line
));
8620 make_cleanup (xfree
, sals
.sals
);
8621 init_sal (&sal
); /* initialize to zeroes */
8622 sal
.line
= default_breakpoint_line
;
8623 sal
.symtab
= default_breakpoint_symtab
;
8624 sal
.pc
= default_breakpoint_address
;
8625 sal
.pspace
= default_breakpoint_pspace
;
8626 if (sal
.symtab
== 0)
8627 error (_("No source file specified."));
8635 /* We don't call resolve_sal_pc here. That's not
8636 as bad as it seems, because all existing breakpoints
8637 typically have both file/line and pc set. So, if
8638 clear is given file/line, we can match this to existing
8639 breakpoint without obtaining pc at all.
8641 We only support clearing given the address explicitly
8642 present in breakpoint table. Say, we've set breakpoint
8643 at file:line. There were several PC values for that file:line,
8644 due to optimization, all in one block.
8645 We've picked one PC value. If "clear" is issued with another
8646 PC corresponding to the same file:line, the breakpoint won't
8647 be cleared. We probably can still clear the breakpoint, but
8648 since the other PC value is never presented to user, user
8649 can only find it by guessing, and it does not seem important
8652 /* For each line spec given, delete bps which correspond
8653 to it. Do it in two passes, solely to preserve the current
8654 behavior that from_tty is forced true if we delete more than
8658 for (i
= 0; i
< sals
.nelts
; i
++)
8660 /* If exact pc given, clear bpts at that pc.
8661 If line given (pc == 0), clear all bpts on specified line.
8662 If defaulting, clear all bpts on default line
8665 defaulting sal.pc != 0 tests to do
8670 1 0 <can't happen> */
8674 /* Find all matching breakpoints and add them to
8679 /* Are we going to delete b? */
8680 if (b
->type
!= bp_none
8681 && b
->type
!= bp_watchpoint
8682 && b
->type
!= bp_hardware_watchpoint
8683 && b
->type
!= bp_read_watchpoint
8684 && b
->type
!= bp_access_watchpoint
)
8686 struct bp_location
*loc
= b
->loc
;
8687 for (; loc
; loc
= loc
->next
)
8689 int pc_match
= sal
.pc
8690 && (loc
->pspace
== sal
.pspace
)
8691 && (loc
->address
== sal
.pc
)
8692 && (!section_is_overlay (loc
->section
)
8693 || loc
->section
== sal
.section
);
8694 int line_match
= ((default_match
|| (0 == sal
.pc
))
8695 && b
->source_file
!= NULL
8696 && sal
.symtab
!= NULL
8697 && sal
.pspace
== loc
->pspace
8698 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8699 && b
->line_number
== sal
.line
);
8700 if (pc_match
|| line_match
)
8709 VEC_safe_push(breakpoint_p
, found
, b
);
8712 /* Now go thru the 'found' chain and delete them. */
8713 if (VEC_empty(breakpoint_p
, found
))
8716 error (_("No breakpoint at %s."), arg
);
8718 error (_("No breakpoint at this line."));
8721 if (VEC_length(breakpoint_p
, found
) > 1)
8722 from_tty
= 1; /* Always report if deleted more than one */
8725 if (VEC_length(breakpoint_p
, found
) == 1)
8726 printf_unfiltered (_("Deleted breakpoint "));
8728 printf_unfiltered (_("Deleted breakpoints "));
8730 breakpoints_changed ();
8732 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8735 printf_unfiltered ("%d ", b
->number
);
8736 delete_breakpoint (b
);
8739 putchar_unfiltered ('\n');
8742 /* Delete breakpoint in BS if they are `delete' breakpoints and
8743 all breakpoints that are marked for deletion, whether hit or not.
8744 This is called after any breakpoint is hit, or after errors. */
8747 breakpoint_auto_delete (bpstat bs
)
8749 struct breakpoint
*b
, *temp
;
8751 for (; bs
; bs
= bs
->next
)
8752 if (bs
->breakpoint_at
8753 && bs
->breakpoint_at
->owner
8754 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8756 delete_breakpoint (bs
->breakpoint_at
->owner
);
8758 ALL_BREAKPOINTS_SAFE (b
, temp
)
8760 if (b
->disposition
== disp_del_at_next_stop
)
8761 delete_breakpoint (b
);
8765 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8766 Sort elements primarily by their ADDRESS (no matter what does
8767 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8768 first bp_permanent OWNERed elements and terciarily just ensuring the array
8769 is sorted stable way despite qsort being an instable algorithm. */
8772 bp_location_compare (const void *ap
, const void *bp
)
8774 struct bp_location
*a
= *(void **) ap
;
8775 struct bp_location
*b
= *(void **) bp
;
8776 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8777 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8779 if (a
->address
!= b
->address
)
8780 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8782 /* Sort permanent breakpoints first. */
8783 if (a_perm
!= b_perm
)
8784 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8786 /* Make the user-visible order stable across GDB runs. Locations of the same
8787 breakpoint can be sorted in arbitrary order. */
8789 if (a
->owner
->number
!= b
->owner
->number
)
8790 return (a
->owner
->number
> b
->owner
->number
)
8791 - (a
->owner
->number
< b
->owner
->number
);
8793 return (a
> b
) - (a
< b
);
8796 /* Set bp_location_placed_address_before_address_max and
8797 bp_location_shadow_len_after_address_max according to the current content of
8798 the bp_location array. */
8801 bp_location_target_extensions_update (void)
8803 struct bp_location
*bl
, **blp_tmp
;
8805 bp_location_placed_address_before_address_max
= 0;
8806 bp_location_shadow_len_after_address_max
= 0;
8808 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8810 CORE_ADDR start
, end
, addr
;
8812 if (!bp_location_has_shadow (bl
))
8815 start
= bl
->target_info
.placed_address
;
8816 end
= start
+ bl
->target_info
.shadow_len
;
8818 gdb_assert (bl
->address
>= start
);
8819 addr
= bl
->address
- start
;
8820 if (addr
> bp_location_placed_address_before_address_max
)
8821 bp_location_placed_address_before_address_max
= addr
;
8823 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8825 gdb_assert (bl
->address
< end
);
8826 addr
= end
- bl
->address
;
8827 if (addr
> bp_location_shadow_len_after_address_max
)
8828 bp_location_shadow_len_after_address_max
= addr
;
8832 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8833 into the inferior, only remove already-inserted locations that no
8834 longer should be inserted. Functions that delete a breakpoint or
8835 breakpoints should pass false, so that deleting a breakpoint
8836 doesn't have the side effect of inserting the locations of other
8837 breakpoints that are marked not-inserted, but should_be_inserted
8838 returns true on them.
8840 This behaviour is useful is situations close to tear-down -- e.g.,
8841 after an exec, while the target still has execution, but breakpoint
8842 shadows of the previous executable image should *NOT* be restored
8843 to the new image; or before detaching, where the target still has
8844 execution and wants to delete breakpoints from GDB's lists, and all
8845 breakpoints had already been removed from the inferior. */
8848 update_global_location_list (int should_insert
)
8850 struct breakpoint
*b
;
8851 struct bp_location
**locp
, *loc
;
8852 struct cleanup
*cleanups
;
8854 /* Used in the duplicates detection below. When iterating over all
8855 bp_locations, points to the first bp_location of a given address.
8856 Breakpoints and watchpoints of different types are never
8857 duplicates of each other. Keep one pointer for each type of
8858 breakpoint/watchpoint, so we only need to loop over all locations
8860 struct bp_location
*bp_loc_first
; /* breakpoint */
8861 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8862 struct bp_location
*awp_loc_first
; /* access watchpoint */
8863 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8865 /* Saved former bp_location array which we compare against the newly built
8866 bp_location from the current state of ALL_BREAKPOINTS. */
8867 struct bp_location
**old_location
, **old_locp
;
8868 unsigned old_location_count
;
8870 old_location
= bp_location
;
8871 old_location_count
= bp_location_count
;
8873 bp_location_count
= 0;
8874 cleanups
= make_cleanup (xfree
, old_location
);
8877 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8878 bp_location_count
++;
8880 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8883 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8885 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8886 bp_location_compare
);
8888 bp_location_target_extensions_update ();
8890 /* Identify bp_location instances that are no longer present in the new
8891 list, and therefore should be freed. Note that it's not necessary that
8892 those locations should be removed from inferior -- if there's another
8893 location at the same address (previously marked as duplicate),
8894 we don't need to remove/insert the location.
8896 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8897 former bp_location array state respectively. */
8900 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8903 struct bp_location
*old_loc
= *old_locp
;
8904 struct bp_location
**loc2p
;
8906 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8908 int found_object
= 0;
8909 /* Tells if the location should remain inserted in the target. */
8910 int keep_in_target
= 0;
8913 /* Skip LOCP entries which will definitely never be needed. Stop either
8914 at or being the one matching OLD_LOC. */
8915 while (locp
< bp_location
+ bp_location_count
8916 && (*locp
)->address
< old_loc
->address
)
8920 (loc2p
< bp_location
+ bp_location_count
8921 && (*loc2p
)->address
== old_loc
->address
);
8924 if (*loc2p
== old_loc
)
8931 /* If this location is no longer present, and inserted, look if there's
8932 maybe a new location at the same address. If so, mark that one
8933 inserted, and don't remove this one. This is needed so that we
8934 don't have a time window where a breakpoint at certain location is not
8937 if (old_loc
->inserted
)
8939 /* If the location is inserted now, we might have to remove it. */
8941 if (found_object
&& should_be_inserted (old_loc
))
8943 /* The location is still present in the location list, and still
8944 should be inserted. Don't do anything. */
8949 /* The location is either no longer present, or got disabled.
8950 See if there's another location at the same address, in which
8951 case we don't need to remove this one from the target. */
8953 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8956 (loc2p
< bp_location
+ bp_location_count
8957 && (*loc2p
)->address
== old_loc
->address
);
8960 struct bp_location
*loc2
= *loc2p
;
8962 if (breakpoint_locations_match (loc2
, old_loc
))
8964 /* For the sake of should_be_inserted.
8965 Duplicates check below will fix up this later. */
8966 loc2
->duplicate
= 0;
8968 /* Read watchpoint locations are switched to
8969 access watchpoints, if the former are not
8970 supported, but the latter are. */
8971 if (is_hardware_watchpoint (old_loc
->owner
))
8973 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8974 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8977 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8980 loc2
->target_info
= old_loc
->target_info
;
8989 if (!keep_in_target
)
8991 if (remove_breakpoint (old_loc
, mark_uninserted
))
8993 /* This is just about all we can do. We could keep this
8994 location on the global list, and try to remove it next
8995 time, but there's no particular reason why we will
8998 Note that at this point, old_loc->owner is still valid,
8999 as delete_breakpoint frees the breakpoint only
9000 after calling us. */
9001 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9002 old_loc
->owner
->number
);
9010 if (removed
&& non_stop
9011 && breakpoint_address_is_meaningful (old_loc
->owner
)
9012 && !is_hardware_watchpoint (old_loc
->owner
))
9014 /* This location was removed from the target. In
9015 non-stop mode, a race condition is possible where
9016 we've removed a breakpoint, but stop events for that
9017 breakpoint are already queued and will arrive later.
9018 We apply an heuristic to be able to distinguish such
9019 SIGTRAPs from other random SIGTRAPs: we keep this
9020 breakpoint location for a bit, and will retire it
9021 after we see some number of events. The theory here
9022 is that reporting of events should, "on the average",
9023 be fair, so after a while we'll see events from all
9024 threads that have anything of interest, and no longer
9025 need to keep this breakpoint location around. We
9026 don't hold locations forever so to reduce chances of
9027 mistaking a non-breakpoint SIGTRAP for a breakpoint
9030 The heuristic failing can be disastrous on
9031 decr_pc_after_break targets.
9033 On decr_pc_after_break targets, like e.g., x86-linux,
9034 if we fail to recognize a late breakpoint SIGTRAP,
9035 because events_till_retirement has reached 0 too
9036 soon, we'll fail to do the PC adjustment, and report
9037 a random SIGTRAP to the user. When the user resumes
9038 the inferior, it will most likely immediately crash
9039 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9040 corrupted, because of being resumed e.g., in the
9041 middle of a multi-byte instruction, or skipped a
9042 one-byte instruction. This was actually seen happen
9043 on native x86-linux, and should be less rare on
9044 targets that do not support new thread events, like
9045 remote, due to the heuristic depending on
9048 Mistaking a random SIGTRAP for a breakpoint trap
9049 causes similar symptoms (PC adjustment applied when
9050 it shouldn't), but then again, playing with SIGTRAPs
9051 behind the debugger's back is asking for trouble.
9053 Since hardware watchpoint traps are always
9054 distinguishable from other traps, so we don't need to
9055 apply keep hardware watchpoint moribund locations
9056 around. We simply always ignore hardware watchpoint
9057 traps we can no longer explain. */
9059 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9060 old_loc
->owner
= NULL
;
9062 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9065 free_bp_location (old_loc
);
9069 /* Rescan breakpoints at the same address and section, marking the
9070 first one as "first" and any others as "duplicates". This is so
9071 that the bpt instruction is only inserted once. If we have a
9072 permanent breakpoint at the same place as BPT, make that one the
9073 official one, and the rest as duplicates. Permanent breakpoints
9074 are sorted first for the same address.
9076 Do the same for hardware watchpoints, but also considering the
9077 watchpoint's type (regular/access/read) and length. */
9079 bp_loc_first
= NULL
;
9080 wp_loc_first
= NULL
;
9081 awp_loc_first
= NULL
;
9082 rwp_loc_first
= NULL
;
9083 ALL_BP_LOCATIONS (loc
, locp
)
9085 struct breakpoint
*b
= loc
->owner
;
9086 struct bp_location
**loc_first_p
;
9088 if (b
->enable_state
== bp_disabled
9089 || b
->enable_state
== bp_call_disabled
9090 || b
->enable_state
== bp_startup_disabled
9092 || loc
->shlib_disabled
9093 || !breakpoint_address_is_meaningful (b
)
9094 || tracepoint_type (b
))
9097 /* Permanent breakpoint should always be inserted. */
9098 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9099 internal_error (__FILE__
, __LINE__
,
9100 _("allegedly permanent breakpoint is not "
9101 "actually inserted"));
9103 if (b
->type
== bp_hardware_watchpoint
)
9104 loc_first_p
= &wp_loc_first
;
9105 else if (b
->type
== bp_read_watchpoint
)
9106 loc_first_p
= &rwp_loc_first
;
9107 else if (b
->type
== bp_access_watchpoint
)
9108 loc_first_p
= &awp_loc_first
;
9110 loc_first_p
= &bp_loc_first
;
9112 if (*loc_first_p
== NULL
9113 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9114 || !breakpoint_locations_match (loc
, *loc_first_p
))
9123 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9124 && b
->enable_state
!= bp_permanent
)
9125 internal_error (__FILE__
, __LINE__
,
9126 _("another breakpoint was inserted on top of "
9127 "a permanent breakpoint"));
9130 if (breakpoints_always_inserted_mode () && should_insert
9131 && (have_live_inferiors ()
9132 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9133 insert_breakpoint_locations ();
9135 do_cleanups (cleanups
);
9139 breakpoint_retire_moribund (void)
9141 struct bp_location
*loc
;
9144 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9145 if (--(loc
->events_till_retirement
) == 0)
9147 free_bp_location (loc
);
9148 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9154 update_global_location_list_nothrow (int inserting
)
9156 struct gdb_exception e
;
9157 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9158 update_global_location_list (inserting
);
9161 /* Clear BPT from a BPS. */
9163 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9166 for (bs
= bps
; bs
; bs
= bs
->next
)
9167 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9169 bs
->breakpoint_at
= NULL
;
9171 /* bs->commands will be freed later. */
9175 /* Callback for iterate_over_threads. */
9177 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9179 struct breakpoint
*bpt
= data
;
9180 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9184 /* Delete a breakpoint and clean up all traces of it in the data
9188 delete_breakpoint (struct breakpoint
*bpt
)
9190 struct breakpoint
*b
;
9191 struct bp_location
*loc
, *next
;
9193 gdb_assert (bpt
!= NULL
);
9195 /* Has this bp already been deleted? This can happen because multiple
9196 lists can hold pointers to bp's. bpstat lists are especial culprits.
9198 One example of this happening is a watchpoint's scope bp. When the
9199 scope bp triggers, we notice that the watchpoint is out of scope, and
9200 delete it. We also delete its scope bp. But the scope bp is marked
9201 "auto-deleting", and is already on a bpstat. That bpstat is then
9202 checked for auto-deleting bp's, which are deleted.
9204 A real solution to this problem might involve reference counts in bp's,
9205 and/or giving them pointers back to their referencing bpstat's, and
9206 teaching delete_breakpoint to only free a bp's storage when no more
9207 references were extent. A cheaper bandaid was chosen. */
9208 if (bpt
->type
== bp_none
)
9211 /* At least avoid this stale reference until the reference counting of
9212 breakpoints gets resolved. */
9213 if (bpt
->related_breakpoint
!= NULL
)
9215 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9216 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9217 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9218 bpt
->related_breakpoint
= NULL
;
9221 observer_notify_breakpoint_deleted (bpt
->number
);
9223 if (breakpoint_chain
== bpt
)
9224 breakpoint_chain
= bpt
->next
;
9229 b
->next
= bpt
->next
;
9233 decref_counted_command_line (&bpt
->commands
);
9234 xfree (bpt
->cond_string
);
9235 xfree (bpt
->cond_exp
);
9236 xfree (bpt
->addr_string
);
9238 xfree (bpt
->exp_string
);
9239 value_free (bpt
->val
);
9240 xfree (bpt
->source_file
);
9241 xfree (bpt
->exec_pathname
);
9242 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9244 /* Be sure no bpstat's are pointing at it after it's been freed. */
9245 /* FIXME, how can we find all bpstat's?
9246 We just check stop_bpstat for now. Note that we cannot just
9247 remove bpstats pointing at bpt from the stop_bpstat list
9248 entirely, as breakpoint commands are associated with the bpstat;
9249 if we remove it here, then the later call to
9250 bpstat_do_actions (&stop_bpstat);
9251 in event-top.c won't do anything, and temporary breakpoints
9252 with commands won't work. */
9254 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9256 /* Now that breakpoint is removed from breakpoint
9257 list, update the global location list. This
9258 will remove locations that used to belong to
9259 this breakpoint. Do this before freeing
9260 the breakpoint itself, since remove_breakpoint
9261 looks at location's owner. It might be better
9262 design to have location completely self-contained,
9263 but it's not the case now. */
9264 update_global_location_list (0);
9267 /* On the chance that someone will soon try again to delete this same
9268 bp, we mark it as deleted before freeing its storage. */
9269 bpt
->type
= bp_none
;
9275 do_delete_breakpoint_cleanup (void *b
)
9277 delete_breakpoint (b
);
9281 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9283 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9286 /* A callback for map_breakpoint_numbers that calls
9287 delete_breakpoint. */
9290 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9292 delete_breakpoint (b
);
9296 delete_command (char *arg
, int from_tty
)
9298 struct breakpoint
*b
, *temp
;
9304 int breaks_to_delete
= 0;
9306 /* Delete all breakpoints if no argument.
9307 Do not delete internal or call-dummy breakpoints, these
9308 have to be deleted with an explicit breakpoint number argument. */
9311 if (b
->type
!= bp_call_dummy
9312 && b
->type
!= bp_std_terminate
9313 && b
->type
!= bp_shlib_event
9314 && b
->type
!= bp_jit_event
9315 && b
->type
!= bp_thread_event
9316 && b
->type
!= bp_overlay_event
9317 && b
->type
!= bp_longjmp_master
9318 && b
->type
!= bp_std_terminate_master
9321 breaks_to_delete
= 1;
9326 /* Ask user only if there are some breakpoints to delete. */
9328 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9330 ALL_BREAKPOINTS_SAFE (b
, temp
)
9332 if (b
->type
!= bp_call_dummy
9333 && b
->type
!= bp_std_terminate
9334 && b
->type
!= bp_shlib_event
9335 && b
->type
!= bp_thread_event
9336 && b
->type
!= bp_jit_event
9337 && b
->type
!= bp_overlay_event
9338 && b
->type
!= bp_longjmp_master
9339 && b
->type
!= bp_std_terminate_master
9341 delete_breakpoint (b
);
9346 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9350 all_locations_are_pending (struct bp_location
*loc
)
9352 for (; loc
; loc
= loc
->next
)
9353 if (!loc
->shlib_disabled
)
9358 /* Subroutine of update_breakpoint_locations to simplify it.
9359 Return non-zero if multiple fns in list LOC have the same name.
9360 Null names are ignored. */
9363 ambiguous_names_p (struct bp_location
*loc
)
9365 struct bp_location
*l
;
9366 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9367 (int (*) (const void *, const void *)) streq
,
9368 NULL
, xcalloc
, xfree
);
9370 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9373 const char *name
= l
->function_name
;
9375 /* Allow for some names to be NULL, ignore them. */
9379 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9381 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9396 update_breakpoint_locations (struct breakpoint
*b
,
9397 struct symtabs_and_lines sals
)
9401 struct bp_location
*existing_locations
= b
->loc
;
9403 /* If there's no new locations, and all existing locations
9404 are pending, don't do anything. This optimizes
9405 the common case where all locations are in the same
9406 shared library, that was unloaded. We'd like to
9407 retain the location, so that when the library
9408 is loaded again, we don't loose the enabled/disabled
9409 status of the individual locations. */
9410 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9415 for (i
= 0; i
< sals
.nelts
; ++i
)
9417 struct bp_location
*new_loc
=
9418 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9420 /* Reparse conditions, they might contain references to the
9422 if (b
->cond_string
!= NULL
)
9424 struct gdb_exception e
;
9427 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9429 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9434 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9435 b
->number
, e
.message
);
9436 new_loc
->enabled
= 0;
9440 if (b
->source_file
!= NULL
)
9441 xfree (b
->source_file
);
9442 if (sals
.sals
[i
].symtab
== NULL
)
9443 b
->source_file
= NULL
;
9445 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9447 if (b
->line_number
== 0)
9448 b
->line_number
= sals
.sals
[i
].line
;
9451 /* Update locations of permanent breakpoints. */
9452 if (b
->enable_state
== bp_permanent
)
9453 make_breakpoint_permanent (b
);
9455 /* If possible, carry over 'disable' status from existing breakpoints. */
9457 struct bp_location
*e
= existing_locations
;
9458 /* If there are multiple breakpoints with the same function name,
9459 e.g. for inline functions, comparing function names won't work.
9460 Instead compare pc addresses; this is just a heuristic as things
9461 may have moved, but in practice it gives the correct answer
9462 often enough until a better solution is found. */
9463 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9465 for (; e
; e
= e
->next
)
9467 if (!e
->enabled
&& e
->function_name
)
9469 struct bp_location
*l
= b
->loc
;
9470 if (have_ambiguous_names
)
9472 for (; l
; l
= l
->next
)
9473 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9474 l
->pspace
->aspace
, l
->address
))
9482 for (; l
; l
= l
->next
)
9483 if (l
->function_name
9484 && strcmp (e
->function_name
, l
->function_name
) == 0)
9494 update_global_location_list (1);
9498 /* Reset a breakpoint given it's struct breakpoint * BINT.
9499 The value we return ends up being the return value from catch_errors.
9500 Unused in this case. */
9503 breakpoint_re_set_one (void *bint
)
9505 /* get past catch_errs */
9506 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9510 int *not_found_ptr
= ¬_found
;
9511 struct symtabs_and_lines sals
= {0};
9512 struct symtabs_and_lines expanded
= {0};
9514 enum enable_state save_enable
;
9515 struct gdb_exception e
;
9516 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9521 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9525 case bp_hardware_breakpoint
:
9527 case bp_fast_tracepoint
:
9528 /* Do not attempt to re-set breakpoints disabled during startup. */
9529 if (b
->enable_state
== bp_startup_disabled
)
9532 if (b
->addr_string
== NULL
)
9534 /* Anything without a string can't be re-set. */
9535 delete_breakpoint (b
);
9539 set_language (b
->language
);
9540 input_radix
= b
->input_radix
;
9543 save_current_space_and_thread ();
9544 switch_to_program_space_and_thread (b
->pspace
);
9546 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9548 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9553 int not_found_and_ok
= 0;
9554 /* For pending breakpoints, it's expected that parsing
9555 will fail until the right shared library is loaded.
9556 User has already told to create pending breakpoints and
9557 don't need extra messages. If breakpoint is in bp_shlib_disabled
9558 state, then user already saw the message about that breakpoint
9559 being disabled, and don't want to see more errors. */
9561 && (b
->condition_not_parsed
9562 || (b
->loc
&& b
->loc
->shlib_disabled
)
9563 || b
->enable_state
== bp_disabled
))
9564 not_found_and_ok
= 1;
9566 if (!not_found_and_ok
)
9568 /* We surely don't want to warn about the same breakpoint
9569 10 times. One solution, implemented here, is disable
9570 the breakpoint on error. Another solution would be to
9571 have separate 'warning emitted' flag. Since this
9572 happens only when a binary has changed, I don't know
9573 which approach is better. */
9574 b
->enable_state
= bp_disabled
;
9575 throw_exception (e
);
9581 gdb_assert (sals
.nelts
== 1);
9583 resolve_sal_pc (&sals
.sals
[0]);
9584 if (b
->condition_not_parsed
&& s
&& s
[0])
9586 char *cond_string
= 0;
9590 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9591 &cond_string
, &thread
, &task
);
9593 b
->cond_string
= cond_string
;
9596 b
->condition_not_parsed
= 0;
9599 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9602 make_cleanup (xfree
, sals
.sals
);
9603 update_breakpoint_locations (b
, expanded
);
9607 case bp_hardware_watchpoint
:
9608 case bp_read_watchpoint
:
9609 case bp_access_watchpoint
:
9610 /* Watchpoint can be either on expression using entirely global variables,
9611 or it can be on local variables.
9613 Watchpoints of the first kind are never auto-deleted, and even persist
9614 across program restarts. Since they can use variables from shared
9615 libraries, we need to reparse expression as libraries are loaded
9618 Watchpoints on local variables can also change meaning as result
9619 of solib event. For example, if a watchpoint uses both a local and
9620 a global variables in expression, it's a local watchpoint, but
9621 unloading of a shared library will make the expression invalid.
9622 This is not a very common use case, but we still re-evaluate
9623 expression, to avoid surprises to the user.
9625 Note that for local watchpoints, we re-evaluate it only if
9626 watchpoints frame id is still valid. If it's not, it means
9627 the watchpoint is out of scope and will be deleted soon. In fact,
9628 I'm not sure we'll ever be called in this case.
9630 If a local watchpoint's frame id is still valid, then
9631 b->exp_valid_block is likewise valid, and we can safely use it.
9633 Don't do anything about disabled watchpoints, since they will
9634 be reevaluated again when enabled. */
9635 update_watchpoint (b
, 1 /* reparse */);
9637 /* We needn't really do anything to reset these, since the mask
9638 that requests them is unaffected by e.g., new libraries being
9644 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9646 /* Delete overlay event and longjmp master breakpoints; they will be
9647 reset later by breakpoint_re_set. */
9648 case bp_overlay_event
:
9649 case bp_longjmp_master
:
9650 case bp_std_terminate_master
:
9651 delete_breakpoint (b
);
9654 /* This breakpoint is special, it's set up when the inferior
9655 starts and we really don't want to touch it. */
9656 case bp_shlib_event
:
9658 /* Like bp_shlib_event, this breakpoint type is special.
9659 Once it is set up, we do not want to touch it. */
9660 case bp_thread_event
:
9662 /* Keep temporary breakpoints, which can be encountered when we step
9663 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9664 Otherwise these should have been blown away via the cleanup chain
9665 or by breakpoint_init_inferior when we rerun the executable. */
9668 case bp_watchpoint_scope
:
9670 case bp_std_terminate
:
9671 case bp_step_resume
:
9673 case bp_longjmp_resume
:
9678 do_cleanups (cleanups
);
9682 /* Re-set all breakpoints after symbols have been re-loaded. */
9684 breakpoint_re_set (void)
9686 struct breakpoint
*b
, *temp
;
9687 enum language save_language
;
9688 int save_input_radix
;
9689 struct cleanup
*old_chain
;
9691 save_language
= current_language
->la_language
;
9692 save_input_radix
= input_radix
;
9693 old_chain
= save_current_program_space ();
9695 ALL_BREAKPOINTS_SAFE (b
, temp
)
9697 /* Format possible error msg */
9698 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9700 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9701 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9702 do_cleanups (cleanups
);
9704 set_language (save_language
);
9705 input_radix
= save_input_radix
;
9707 jit_breakpoint_re_set ();
9709 do_cleanups (old_chain
);
9711 create_overlay_event_breakpoint ("_ovly_debug_event");
9712 create_longjmp_master_breakpoint ("longjmp");
9713 create_longjmp_master_breakpoint ("_longjmp");
9714 create_longjmp_master_breakpoint ("siglongjmp");
9715 create_longjmp_master_breakpoint ("_siglongjmp");
9716 create_std_terminate_master_breakpoint ("std::terminate()");
9719 /* Reset the thread number of this breakpoint:
9721 - If the breakpoint is for all threads, leave it as-is.
9722 - Else, reset it to the current thread for inferior_ptid. */
9724 breakpoint_re_set_thread (struct breakpoint
*b
)
9726 if (b
->thread
!= -1)
9728 if (in_thread_list (inferior_ptid
))
9729 b
->thread
= pid_to_thread_id (inferior_ptid
);
9731 /* We're being called after following a fork. The new fork is
9732 selected as current, and unless this was a vfork will have a
9733 different program space from the original thread. Reset that
9735 b
->loc
->pspace
= current_program_space
;
9739 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9740 If from_tty is nonzero, it prints a message to that effect,
9741 which ends with a period (no newline). */
9744 set_ignore_count (int bptnum
, int count
, int from_tty
)
9746 struct breakpoint
*b
;
9752 if (b
->number
== bptnum
)
9754 b
->ignore_count
= count
;
9758 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9760 else if (count
== 1)
9761 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9764 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9767 breakpoints_changed ();
9768 observer_notify_breakpoint_modified (b
->number
);
9772 error (_("No breakpoint number %d."), bptnum
);
9776 make_breakpoint_silent (struct breakpoint
*b
)
9778 /* Silence the breakpoint. */
9782 /* Command to set ignore-count of breakpoint N to COUNT. */
9785 ignore_command (char *args
, int from_tty
)
9791 error_no_arg (_("a breakpoint number"));
9793 num
= get_number (&p
);
9795 error (_("bad breakpoint number: '%s'"), args
);
9797 error (_("Second argument (specified ignore-count) is missing."));
9799 set_ignore_count (num
,
9800 longest_to_int (value_as_long (parse_and_eval (p
))),
9803 printf_filtered ("\n");
9806 /* Call FUNCTION on each of the breakpoints
9807 whose numbers are given in ARGS. */
9810 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9817 struct breakpoint
*b
, *tmp
;
9821 error_no_arg (_("one or more breakpoint numbers"));
9828 num
= get_number_or_range (&p1
);
9831 warning (_("bad breakpoint number at or near '%s'"), p
);
9835 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9836 if (b
->number
== num
)
9838 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9841 if (related_breakpoint
)
9842 function (related_breakpoint
, data
);
9846 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9852 static struct bp_location
*
9853 find_location_by_number (char *number
)
9855 char *dot
= strchr (number
, '.');
9859 struct breakpoint
*b
;
9860 struct bp_location
*loc
;
9865 bp_num
= get_number_or_range (&p1
);
9867 error (_("Bad breakpoint number '%s'"), number
);
9870 if (b
->number
== bp_num
)
9875 if (!b
|| b
->number
!= bp_num
)
9876 error (_("Bad breakpoint number '%s'"), number
);
9879 loc_num
= get_number_or_range (&p1
);
9881 error (_("Bad breakpoint location number '%s'"), number
);
9885 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9888 error (_("Bad breakpoint location number '%s'"), dot
+1);
9894 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9895 If from_tty is nonzero, it prints a message to that effect,
9896 which ends with a period (no newline). */
9899 disable_breakpoint (struct breakpoint
*bpt
)
9901 /* Never disable a watchpoint scope breakpoint; we want to
9902 hit them when we leave scope so we can delete both the
9903 watchpoint and its scope breakpoint at that time. */
9904 if (bpt
->type
== bp_watchpoint_scope
)
9907 /* You can't disable permanent breakpoints. */
9908 if (bpt
->enable_state
== bp_permanent
)
9911 bpt
->enable_state
= bp_disabled
;
9913 update_global_location_list (0);
9915 observer_notify_breakpoint_modified (bpt
->number
);
9918 /* A callback for map_breakpoint_numbers that calls
9919 disable_breakpoint. */
9922 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9924 disable_breakpoint (b
);
9928 disable_command (char *args
, int from_tty
)
9930 struct breakpoint
*bpt
;
9932 ALL_BREAKPOINTS (bpt
)
9936 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9941 case bp_fast_tracepoint
:
9943 case bp_hardware_breakpoint
:
9945 case bp_hardware_watchpoint
:
9946 case bp_read_watchpoint
:
9947 case bp_access_watchpoint
:
9948 disable_breakpoint (bpt
);
9952 else if (strchr (args
, '.'))
9954 struct bp_location
*loc
= find_location_by_number (args
);
9957 update_global_location_list (0);
9960 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9964 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9966 int target_resources_ok
, other_type_used
;
9969 if (bpt
->type
== bp_hardware_breakpoint
)
9972 i
= hw_breakpoint_used_count ();
9973 target_resources_ok
=
9974 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9976 if (target_resources_ok
== 0)
9977 error (_("No hardware breakpoint support in the target."));
9978 else if (target_resources_ok
< 0)
9979 error (_("Hardware breakpoints used exceeds limit."));
9982 if (bpt
->type
== bp_watchpoint
9983 || bpt
->type
== bp_hardware_watchpoint
9984 || bpt
->type
== bp_read_watchpoint
9985 || bpt
->type
== bp_access_watchpoint
)
9987 struct gdb_exception e
;
9989 TRY_CATCH (e
, RETURN_MASK_ALL
)
9991 update_watchpoint (bpt
, 1 /* reparse */);
9995 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10001 if (bpt
->enable_state
!= bp_permanent
)
10002 bpt
->enable_state
= bp_enabled
;
10003 bpt
->disposition
= disposition
;
10004 update_global_location_list (1);
10005 breakpoints_changed ();
10007 observer_notify_breakpoint_modified (bpt
->number
);
10012 enable_breakpoint (struct breakpoint
*bpt
)
10014 do_enable_breakpoint (bpt
, bpt
->disposition
);
10017 /* A callback for map_breakpoint_numbers that calls
10018 enable_breakpoint. */
10021 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10023 enable_breakpoint (b
);
10026 /* The enable command enables the specified breakpoints (or all defined
10027 breakpoints) so they once again become (or continue to be) effective
10028 in stopping the inferior. */
10031 enable_command (char *args
, int from_tty
)
10033 struct breakpoint
*bpt
;
10035 ALL_BREAKPOINTS (bpt
)
10039 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10042 case bp_breakpoint
:
10043 case bp_tracepoint
:
10044 case bp_fast_tracepoint
:
10045 case bp_catchpoint
:
10046 case bp_hardware_breakpoint
:
10047 case bp_watchpoint
:
10048 case bp_hardware_watchpoint
:
10049 case bp_read_watchpoint
:
10050 case bp_access_watchpoint
:
10051 enable_breakpoint (bpt
);
10055 else if (strchr (args
, '.'))
10057 struct bp_location
*loc
= find_location_by_number (args
);
10060 update_global_location_list (1);
10063 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10067 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10069 do_enable_breakpoint (bpt
, disp_disable
);
10073 enable_once_command (char *args
, int from_tty
)
10075 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10079 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10081 do_enable_breakpoint (bpt
, disp_del
);
10085 enable_delete_command (char *args
, int from_tty
)
10087 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10091 set_breakpoint_cmd (char *args
, int from_tty
)
10096 show_breakpoint_cmd (char *args
, int from_tty
)
10100 /* Invalidate last known value of any hardware watchpoint if
10101 the memory which that value represents has been written to by
10105 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10106 const bfd_byte
*data
)
10108 struct breakpoint
*bp
;
10110 ALL_BREAKPOINTS (bp
)
10111 if (bp
->enable_state
== bp_enabled
10112 && bp
->type
== bp_hardware_watchpoint
10113 && bp
->val_valid
&& bp
->val
)
10115 struct bp_location
*loc
;
10117 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10118 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10119 && loc
->address
+ loc
->length
> addr
10120 && addr
+ len
> loc
->address
)
10122 value_free (bp
->val
);
10129 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10131 struct symtabs_and_lines
10132 decode_line_spec_1 (char *string
, int funfirstline
)
10134 struct symtabs_and_lines sals
;
10136 error (_("Empty line specification."));
10137 if (default_breakpoint_valid
)
10138 sals
= decode_line_1 (&string
, funfirstline
,
10139 default_breakpoint_symtab
,
10140 default_breakpoint_line
,
10141 (char ***) NULL
, NULL
);
10143 sals
= decode_line_1 (&string
, funfirstline
,
10144 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10146 error (_("Junk at end of line specification: %s"), string
);
10150 /* Create and insert a raw software breakpoint at PC. Return an
10151 identifier, which should be used to remove the breakpoint later.
10152 In general, places which call this should be using something on the
10153 breakpoint chain instead; this function should be eliminated
10157 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10158 struct address_space
*aspace
, CORE_ADDR pc
)
10160 struct bp_target_info
*bp_tgt
;
10162 bp_tgt
= XZALLOC (struct bp_target_info
);
10164 bp_tgt
->placed_address_space
= aspace
;
10165 bp_tgt
->placed_address
= pc
;
10167 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10169 /* Could not insert the breakpoint. */
10177 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10180 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10182 struct bp_target_info
*bp_tgt
= bp
;
10185 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10191 /* One (or perhaps two) breakpoints used for software single stepping. */
10193 static void *single_step_breakpoints
[2];
10194 static struct gdbarch
*single_step_gdbarch
[2];
10196 /* Create and insert a breakpoint for software single step. */
10199 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10200 struct address_space
*aspace
, CORE_ADDR next_pc
)
10204 if (single_step_breakpoints
[0] == NULL
)
10206 bpt_p
= &single_step_breakpoints
[0];
10207 single_step_gdbarch
[0] = gdbarch
;
10211 gdb_assert (single_step_breakpoints
[1] == NULL
);
10212 bpt_p
= &single_step_breakpoints
[1];
10213 single_step_gdbarch
[1] = gdbarch
;
10216 /* NOTE drow/2006-04-11: A future improvement to this function would be
10217 to only create the breakpoints once, and actually put them on the
10218 breakpoint chain. That would let us use set_raw_breakpoint. We could
10219 adjust the addresses each time they were needed. Doing this requires
10220 corresponding changes elsewhere where single step breakpoints are
10221 handled, however. So, for now, we use this. */
10223 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10224 if (*bpt_p
== NULL
)
10225 error (_("Could not insert single-step breakpoint at %s"),
10226 paddress (gdbarch
, next_pc
));
10229 /* Remove and delete any breakpoints used for software single step. */
10232 remove_single_step_breakpoints (void)
10234 gdb_assert (single_step_breakpoints
[0] != NULL
);
10236 /* See insert_single_step_breakpoint for more about this deprecated
10238 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10239 single_step_breakpoints
[0]);
10240 single_step_gdbarch
[0] = NULL
;
10241 single_step_breakpoints
[0] = NULL
;
10243 if (single_step_breakpoints
[1] != NULL
)
10245 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10246 single_step_breakpoints
[1]);
10247 single_step_gdbarch
[1] = NULL
;
10248 single_step_breakpoints
[1] = NULL
;
10252 /* Check whether a software single-step breakpoint is inserted at PC. */
10255 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10259 for (i
= 0; i
< 2; i
++)
10261 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10263 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10264 bp_tgt
->placed_address
,
10272 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10273 non-zero otherwise. */
10275 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10277 if (syscall_catchpoint_p (bp
)
10278 && bp
->enable_state
!= bp_disabled
10279 && bp
->enable_state
!= bp_call_disabled
)
10286 catch_syscall_enabled (void)
10288 struct inferior
*inf
= current_inferior ();
10290 return inf
->total_syscalls_count
!= 0;
10294 catching_syscall_number (int syscall_number
)
10296 struct breakpoint
*bp
;
10298 ALL_BREAKPOINTS (bp
)
10299 if (is_syscall_catchpoint_enabled (bp
))
10301 if (bp
->syscalls_to_be_caught
)
10305 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10307 if (syscall_number
== iter
)
10317 /* Complete syscall names. Used by "catch syscall". */
10319 catch_syscall_completer (struct cmd_list_element
*cmd
,
10320 char *text
, char *word
)
10322 const char **list
= get_syscall_names ();
10323 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10326 /* Tracepoint-specific operations. */
10328 /* Set tracepoint count to NUM. */
10330 set_tracepoint_count (int num
)
10332 tracepoint_count
= num
;
10333 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10337 trace_command (char *arg
, int from_tty
)
10339 if (create_breakpoint (get_current_arch (),
10341 NULL
, 0, 1 /* parse arg */,
10342 0 /* tempflag */, 0 /* hardwareflag */,
10344 0 /* Ignore count */,
10345 pending_break_support
,
10349 set_tracepoint_count (breakpoint_count
);
10353 ftrace_command (char *arg
, int from_tty
)
10355 if (create_breakpoint (get_current_arch (),
10357 NULL
, 0, 1 /* parse arg */,
10358 0 /* tempflag */, 1 /* hardwareflag */,
10360 0 /* Ignore count */,
10361 pending_break_support
,
10365 set_tracepoint_count (breakpoint_count
);
10368 /* Given information about a tracepoint as recorded on a target (which
10369 can be either a live system or a trace file), attempt to create an
10370 equivalent GDB tracepoint. This is not a reliable process, since
10371 the target does not necessarily have all the information used when
10372 the tracepoint was originally defined. */
10374 struct breakpoint
*
10375 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10378 struct breakpoint
*tp
;
10380 /* In the absence of a source location, fall back to raw address. */
10381 sprintf (buf
, "*%s", paddress (get_current_arch(), utp
->addr
));
10383 if (!create_breakpoint (get_current_arch (),
10385 NULL
, 0, 1 /* parse arg */,
10387 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10389 0 /* Ignore count */,
10390 pending_break_support
,
10393 utp
->enabled
/* enabled */))
10396 set_tracepoint_count (breakpoint_count
);
10398 tp
= get_tracepoint (tracepoint_count
);
10399 gdb_assert (tp
!= NULL
);
10403 sprintf (buf
, "%d %d", utp
->pass
, tp
->number
);
10405 trace_pass_command (buf
, 0);
10410 printf_filtered ("Want to restore a condition\n");
10413 if (utp
->numactions
> 0)
10415 printf_filtered ("Want to restore action list\n");
10418 if (utp
->num_step_actions
> 0)
10420 printf_filtered ("Want to restore action list\n");
10426 /* Print information on tracepoint number TPNUM_EXP, or all if
10430 tracepoints_info (char *tpnum_exp
, int from_tty
)
10432 struct breakpoint
*b
;
10433 int tps_to_list
= 0;
10435 /* In the no-arguments case, say "No tracepoints" if none found. */
10436 if (tpnum_exp
== 0)
10438 ALL_TRACEPOINTS (b
)
10440 if (b
->number
>= 0)
10448 ui_out_message (uiout
, 0, "No tracepoints.\n");
10453 /* Otherwise be the same as "info break". */
10454 breakpoints_info (tpnum_exp
, from_tty
);
10457 /* The 'enable trace' command enables tracepoints.
10458 Not supported by all targets. */
10460 enable_trace_command (char *args
, int from_tty
)
10462 enable_command (args
, from_tty
);
10465 /* The 'disable trace' command disables tracepoints.
10466 Not supported by all targets. */
10468 disable_trace_command (char *args
, int from_tty
)
10470 disable_command (args
, from_tty
);
10473 /* Remove a tracepoint (or all if no argument) */
10475 delete_trace_command (char *arg
, int from_tty
)
10477 struct breakpoint
*b
, *temp
;
10483 int breaks_to_delete
= 0;
10485 /* Delete all breakpoints if no argument.
10486 Do not delete internal or call-dummy breakpoints, these
10487 have to be deleted with an explicit breakpoint number argument. */
10488 ALL_TRACEPOINTS (b
)
10490 if (b
->number
>= 0)
10492 breaks_to_delete
= 1;
10497 /* Ask user only if there are some breakpoints to delete. */
10499 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10501 ALL_BREAKPOINTS_SAFE (b
, temp
)
10503 if (tracepoint_type (b
)
10505 delete_breakpoint (b
);
10510 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10513 /* Set passcount for tracepoint.
10515 First command argument is passcount, second is tracepoint number.
10516 If tracepoint number omitted, apply to most recently defined.
10517 Also accepts special argument "all". */
10520 trace_pass_command (char *args
, int from_tty
)
10522 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10523 unsigned int count
;
10526 if (args
== 0 || *args
== 0)
10527 error (_("passcount command requires an argument (count + optional TP num)"));
10529 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10531 while (*args
&& isspace ((int) *args
))
10534 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10536 args
+= 3; /* Skip special argument "all". */
10539 error (_("Junk at end of arguments."));
10542 t1
= get_tracepoint_by_number (&args
, 1, 1);
10548 ALL_TRACEPOINTS (t2
)
10549 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10551 t2
->pass_count
= count
;
10552 observer_notify_tracepoint_modified (t2
->number
);
10554 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10555 t2
->number
, count
);
10557 if (! all
&& *args
)
10558 t1
= get_tracepoint_by_number (&args
, 1, 0);
10564 struct breakpoint
*
10565 get_tracepoint (int num
)
10567 struct breakpoint
*t
;
10569 ALL_TRACEPOINTS (t
)
10570 if (t
->number
== num
)
10576 /* Find the tracepoint with the given target-side number (which may be
10577 different from the tracepoint number after disconnecting and
10580 struct breakpoint
*
10581 get_tracepoint_by_number_on_target (int num
)
10583 struct breakpoint
*t
;
10585 ALL_TRACEPOINTS (t
)
10586 if (t
->number_on_target
== num
)
10592 /* Utility: parse a tracepoint number and look it up in the list.
10593 If MULTI_P is true, there might be a range of tracepoints in ARG.
10594 if OPTIONAL_P is true, then if the argument is missing, the most
10595 recent tracepoint (tracepoint_count) is returned. */
10596 struct breakpoint
*
10597 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10599 extern int tracepoint_count
;
10600 struct breakpoint
*t
;
10602 char *instring
= arg
== NULL
? NULL
: *arg
;
10604 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10607 tpnum
= tracepoint_count
;
10609 error_no_arg (_("tracepoint number"));
10612 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10616 if (instring
&& *instring
)
10617 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10620 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10624 ALL_TRACEPOINTS (t
)
10625 if (t
->number
== tpnum
)
10630 /* FIXME: if we are in the middle of a range we don't want to give
10631 a message. The current interface to get_number_or_range doesn't
10632 allow us to discover this. */
10633 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10637 /* save-tracepoints command */
10639 tracepoint_save_command (char *args
, int from_tty
)
10641 struct breakpoint
*tp
;
10643 struct command_line
*line
;
10646 struct cleanup
*cleanup
;
10647 struct ui_file
*fp
;
10649 if (args
== 0 || *args
== 0)
10650 error (_("Argument required (file name in which to save tracepoints)"));
10652 /* See if we have anything to save. */
10653 ALL_TRACEPOINTS (tp
)
10660 warning (_("save-tracepoints: no tracepoints to save."));
10664 pathname
= tilde_expand (args
);
10665 cleanup
= make_cleanup (xfree
, pathname
);
10666 fp
= gdb_fopen (pathname
, "w");
10668 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10669 args
, safe_strerror (errno
));
10670 make_cleanup_ui_file_delete (fp
);
10672 ALL_TRACEPOINTS (tp
)
10674 if (tp
->addr_string
)
10675 fprintf_unfiltered (fp
, "trace %s\n", tp
->addr_string
);
10678 sprintf_vma (tmp
, tp
->loc
->address
);
10679 fprintf_unfiltered (fp
, "trace *0x%s\n", tmp
);
10682 if (tp
->pass_count
)
10683 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10687 volatile struct gdb_exception ex
;
10689 fprintf_unfiltered (fp
, " actions\n");
10691 ui_out_redirect (uiout
, fp
);
10692 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10694 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10696 ui_out_redirect (uiout
, NULL
);
10699 throw_exception (ex
);
10701 fprintf_unfiltered (fp
, " end\n");
10704 do_cleanups (cleanup
);
10706 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10710 /* Create a vector of all tracepoints. */
10712 VEC(breakpoint_p
) *
10715 VEC(breakpoint_p
) *tp_vec
= 0;
10716 struct breakpoint
*tp
;
10718 ALL_TRACEPOINTS (tp
)
10720 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10727 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10728 It is defined as a macro to prevent duplication.
10729 COMMAND should be a string constant containing the name of the command. */
10730 #define BREAK_ARGS_HELP(command) \
10731 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10732 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10733 If a line number is specified, break at start of code for that line.\n\
10734 If a function is specified, break at start of code for that function.\n\
10735 If an address is specified, break at that exact address.\n\
10736 With no LOCATION, uses current execution address of selected stack frame.\n\
10737 This is useful for breaking on return to a stack frame.\n\
10739 THREADNUM is the number from \"info threads\".\n\
10740 CONDITION is a boolean expression.\n\
10742 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10744 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10746 /* List of subcommands for "catch". */
10747 static struct cmd_list_element
*catch_cmdlist
;
10749 /* List of subcommands for "tcatch". */
10750 static struct cmd_list_element
*tcatch_cmdlist
;
10752 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10753 lists, and pass some additional user data to the command function. */
10755 add_catch_command (char *name
, char *docstring
,
10756 void (*sfunc
) (char *args
, int from_tty
,
10757 struct cmd_list_element
*command
),
10758 char **(*completer
) (struct cmd_list_element
*cmd
,
10759 char *text
, char *word
),
10760 void *user_data_catch
,
10761 void *user_data_tcatch
)
10763 struct cmd_list_element
*command
;
10765 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10767 set_cmd_sfunc (command
, sfunc
);
10768 set_cmd_context (command
, user_data_catch
);
10769 set_cmd_completer (command
, completer
);
10771 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10773 set_cmd_sfunc (command
, sfunc
);
10774 set_cmd_context (command
, user_data_tcatch
);
10775 set_cmd_completer (command
, completer
);
10779 clear_syscall_counts (struct inferior
*inf
)
10781 inf
->total_syscalls_count
= 0;
10782 inf
->any_syscall_count
= 0;
10783 VEC_free (int, inf
->syscalls_counts
);
10787 _initialize_breakpoint (void)
10789 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10790 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10791 struct cmd_list_element
*c
;
10793 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10794 observer_attach_inferior_exit (clear_syscall_counts
);
10795 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10797 breakpoint_chain
= 0;
10798 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10799 before a breakpoint is set. */
10800 breakpoint_count
= 0;
10802 tracepoint_count
= 0;
10804 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10805 Set ignore-count of breakpoint number N to COUNT.\n\
10806 Usage is `ignore N COUNT'."));
10808 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10810 add_com ("commands", class_breakpoint
, commands_command
, _("\
10811 Set commands to be executed when a breakpoint is hit.\n\
10812 Give breakpoint number as argument after \"commands\".\n\
10813 With no argument, the targeted breakpoint is the last one set.\n\
10814 The commands themselves follow starting on the next line.\n\
10815 Type a line containing \"end\" to indicate the end of them.\n\
10816 Give \"silent\" as the first line to make the breakpoint silent;\n\
10817 then no output is printed when it is hit, except what the commands print."));
10819 add_com ("condition", class_breakpoint
, condition_command
, _("\
10820 Specify breakpoint number N to break only if COND is true.\n\
10821 Usage is `condition N COND', where N is an integer and COND is an\n\
10822 expression to be evaluated whenever breakpoint N is reached."));
10824 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10825 Set a temporary breakpoint.\n\
10826 Like \"break\" except the breakpoint is only temporary,\n\
10827 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10828 by using \"enable delete\" on the breakpoint number.\n\
10830 BREAK_ARGS_HELP ("tbreak")));
10831 set_cmd_completer (c
, location_completer
);
10833 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10834 Set a hardware assisted breakpoint.\n\
10835 Like \"break\" except the breakpoint requires hardware support,\n\
10836 some target hardware may not have this support.\n\
10838 BREAK_ARGS_HELP ("hbreak")));
10839 set_cmd_completer (c
, location_completer
);
10841 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10842 Set a temporary hardware assisted breakpoint.\n\
10843 Like \"hbreak\" except the breakpoint is only temporary,\n\
10844 so it will be deleted when hit.\n\
10846 BREAK_ARGS_HELP ("thbreak")));
10847 set_cmd_completer (c
, location_completer
);
10849 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10850 Enable some breakpoints.\n\
10851 Give breakpoint numbers (separated by spaces) as arguments.\n\
10852 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10853 This is used to cancel the effect of the \"disable\" command.\n\
10854 With a subcommand you can enable temporarily."),
10855 &enablelist
, "enable ", 1, &cmdlist
);
10857 add_com ("ab", class_breakpoint
, enable_command
, _("\
10858 Enable some breakpoints.\n\
10859 Give breakpoint numbers (separated by spaces) as arguments.\n\
10860 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10861 This is used to cancel the effect of the \"disable\" command.\n\
10862 With a subcommand you can enable temporarily."));
10864 add_com_alias ("en", "enable", class_breakpoint
, 1);
10866 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10867 Enable some breakpoints.\n\
10868 Give breakpoint numbers (separated by spaces) as arguments.\n\
10869 This is used to cancel the effect of the \"disable\" command.\n\
10870 May be abbreviated to simply \"enable\".\n"),
10871 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10873 add_cmd ("once", no_class
, enable_once_command
, _("\
10874 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10875 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10878 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10879 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10880 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10883 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10884 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10885 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10888 add_cmd ("once", no_class
, enable_once_command
, _("\
10889 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10890 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10893 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10894 Disable some breakpoints.\n\
10895 Arguments are breakpoint numbers with spaces in between.\n\
10896 To disable all breakpoints, give no argument.\n\
10897 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10898 &disablelist
, "disable ", 1, &cmdlist
);
10899 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10900 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10902 add_com ("sb", class_breakpoint
, disable_command
, _("\
10903 Disable some breakpoints.\n\
10904 Arguments are breakpoint numbers with spaces in between.\n\
10905 To disable all breakpoints, give no argument.\n\
10906 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10908 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10909 Disable some breakpoints.\n\
10910 Arguments are breakpoint numbers with spaces in between.\n\
10911 To disable all breakpoints, give no argument.\n\
10912 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10913 This command may be abbreviated \"disable\"."),
10916 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10917 Delete some breakpoints or auto-display expressions.\n\
10918 Arguments are breakpoint numbers with spaces in between.\n\
10919 To delete all breakpoints, give no argument.\n\
10921 Also a prefix command for deletion of other GDB objects.\n\
10922 The \"unset\" command is also an alias for \"delete\"."),
10923 &deletelist
, "delete ", 1, &cmdlist
);
10924 add_com_alias ("d", "delete", class_breakpoint
, 1);
10925 add_com_alias ("del", "delete", class_breakpoint
, 1);
10927 add_com ("db", class_breakpoint
, delete_command
, _("\
10928 Delete some breakpoints.\n\
10929 Arguments are breakpoint numbers with spaces in between.\n\
10930 To delete all breakpoints, give no argument.\n"));
10932 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10933 Delete some breakpoints or auto-display expressions.\n\
10934 Arguments are breakpoint numbers with spaces in between.\n\
10935 To delete all breakpoints, give no argument.\n\
10936 This command may be abbreviated \"delete\"."),
10939 add_com ("clear", class_breakpoint
, clear_command
, _("\
10940 Clear breakpoint at specified line or function.\n\
10941 Argument may be line number, function name, or \"*\" and an address.\n\
10942 If line number is specified, all breakpoints in that line are cleared.\n\
10943 If function is specified, breakpoints at beginning of function are cleared.\n\
10944 If an address is specified, breakpoints at that address are cleared.\n\
10946 With no argument, clears all breakpoints in the line that the selected frame\n\
10947 is executing in.\n\
10949 See also the \"delete\" command which clears breakpoints by number."));
10951 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10952 Set breakpoint at specified line or function.\n"
10953 BREAK_ARGS_HELP ("break")));
10954 set_cmd_completer (c
, location_completer
);
10956 add_com_alias ("b", "break", class_run
, 1);
10957 add_com_alias ("br", "break", class_run
, 1);
10958 add_com_alias ("bre", "break", class_run
, 1);
10959 add_com_alias ("brea", "break", class_run
, 1);
10962 add_com_alias ("ba", "break", class_breakpoint
, 1);
10966 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10967 Break in function/address or break at a line in the current file."),
10968 &stoplist
, "stop ", 1, &cmdlist
);
10969 add_cmd ("in", class_breakpoint
, stopin_command
,
10970 _("Break in function or address."), &stoplist
);
10971 add_cmd ("at", class_breakpoint
, stopat_command
,
10972 _("Break at a line in the current file."), &stoplist
);
10973 add_com ("status", class_info
, breakpoints_info
, _("\
10974 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10975 The \"Type\" column indicates one of:\n\
10976 \tbreakpoint - normal breakpoint\n\
10977 \twatchpoint - watchpoint\n\
10978 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10979 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10980 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10981 address and file/line number respectively.\n\
10983 Convenience variable \"$_\" and default examine address for \"x\"\n\
10984 are set to the address of the last breakpoint listed unless the command\n\
10985 is prefixed with \"server \".\n\n\
10986 Convenience variable \"$bpnum\" contains the number of the last\n\
10987 breakpoint set."));
10990 add_info ("breakpoints", breakpoints_info
, _("\
10991 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10992 The \"Type\" column indicates one of:\n\
10993 \tbreakpoint - normal breakpoint\n\
10994 \twatchpoint - watchpoint\n\
10995 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10996 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10997 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10998 address and file/line number respectively.\n\
11000 Convenience variable \"$_\" and default examine address for \"x\"\n\
11001 are set to the address of the last breakpoint listed unless the command\n\
11002 is prefixed with \"server \".\n\n\
11003 Convenience variable \"$bpnum\" contains the number of the last\n\
11004 breakpoint set."));
11006 add_info_alias ("b", "breakpoints", 1);
11009 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11010 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11011 The \"Type\" column indicates one of:\n\
11012 \tbreakpoint - normal breakpoint\n\
11013 \twatchpoint - watchpoint\n\
11014 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11015 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11016 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11017 address and file/line number respectively.\n\
11019 Convenience variable \"$_\" and default examine address for \"x\"\n\
11020 are set to the address of the last breakpoint listed unless the command\n\
11021 is prefixed with \"server \".\n\n\
11022 Convenience variable \"$bpnum\" contains the number of the last\n\
11023 breakpoint set."));
11025 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11026 Status of all breakpoints, or breakpoint number NUMBER.\n\
11027 The \"Type\" column indicates one of:\n\
11028 \tbreakpoint - normal breakpoint\n\
11029 \twatchpoint - watchpoint\n\
11030 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11031 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11032 \tuntil - internal breakpoint used by the \"until\" command\n\
11033 \tfinish - internal breakpoint used by the \"finish\" command\n\
11034 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11035 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11036 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11037 address and file/line number respectively.\n\
11039 Convenience variable \"$_\" and default examine address for \"x\"\n\
11040 are set to the address of the last breakpoint listed unless the command\n\
11041 is prefixed with \"server \".\n\n\
11042 Convenience variable \"$bpnum\" contains the number of the last\n\
11044 &maintenanceinfolist
);
11046 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11047 Set catchpoints to catch events."),
11048 &catch_cmdlist
, "catch ",
11049 0/*allow-unknown*/, &cmdlist
);
11051 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11052 Set temporary catchpoints to catch events."),
11053 &tcatch_cmdlist
, "tcatch ",
11054 0/*allow-unknown*/, &cmdlist
);
11056 /* Add catch and tcatch sub-commands. */
11057 add_catch_command ("catch", _("\
11058 Catch an exception, when caught.\n\
11059 With an argument, catch only exceptions with the given name."),
11060 catch_catch_command
,
11064 add_catch_command ("throw", _("\
11065 Catch an exception, when thrown.\n\
11066 With an argument, catch only exceptions with the given name."),
11067 catch_throw_command
,
11071 add_catch_command ("fork", _("Catch calls to fork."),
11072 catch_fork_command_1
,
11074 (void *) (uintptr_t) catch_fork_permanent
,
11075 (void *) (uintptr_t) catch_fork_temporary
);
11076 add_catch_command ("vfork", _("Catch calls to vfork."),
11077 catch_fork_command_1
,
11079 (void *) (uintptr_t) catch_vfork_permanent
,
11080 (void *) (uintptr_t) catch_vfork_temporary
);
11081 add_catch_command ("exec", _("Catch calls to exec."),
11082 catch_exec_command_1
,
11086 add_catch_command ("syscall", _("\
11087 Catch system calls by their names and/or numbers.\n\
11088 Arguments say which system calls to catch. If no arguments\n\
11089 are given, every system call will be caught.\n\
11090 Arguments, if given, should be one or more system call names\n\
11091 (if your system supports that), or system call numbers."),
11092 catch_syscall_command_1
,
11093 catch_syscall_completer
,
11096 add_catch_command ("exception", _("\
11097 Catch Ada exceptions, when raised.\n\
11098 With an argument, catch only exceptions with the given name."),
11099 catch_ada_exception_command
,
11103 add_catch_command ("assert", _("\
11104 Catch failed Ada assertions, when raised.\n\
11105 With an argument, catch only exceptions with the given name."),
11106 catch_assert_command
,
11111 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11112 Set a watchpoint for an expression.\n\
11113 A watchpoint stops execution of your program whenever the value of\n\
11114 an expression changes."));
11115 set_cmd_completer (c
, expression_completer
);
11117 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11118 Set a read watchpoint for an expression.\n\
11119 A watchpoint stops execution of your program whenever the value of\n\
11120 an expression is read."));
11121 set_cmd_completer (c
, expression_completer
);
11123 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11124 Set a watchpoint for an expression.\n\
11125 A watchpoint stops execution of your program whenever the value of\n\
11126 an expression is either read or written."));
11127 set_cmd_completer (c
, expression_completer
);
11129 add_info ("watchpoints", breakpoints_info
,
11130 _("Synonym for ``info breakpoints''."));
11133 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11134 respond to changes - contrary to the description. */
11135 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11136 &can_use_hw_watchpoints
, _("\
11137 Set debugger's willingness to use watchpoint hardware."), _("\
11138 Show debugger's willingness to use watchpoint hardware."), _("\
11139 If zero, gdb will not use hardware for new watchpoints, even if\n\
11140 such is available. (However, any hardware watchpoints that were\n\
11141 created before setting this to nonzero, will continue to use watchpoint\n\
11144 show_can_use_hw_watchpoints
,
11145 &setlist
, &showlist
);
11147 can_use_hw_watchpoints
= 1;
11149 /* Tracepoint manipulation commands. */
11151 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11152 Set a tracepoint at specified line or function.\n\
11154 BREAK_ARGS_HELP ("trace") "\n\
11155 Do \"help tracepoints\" for info on other tracepoint commands."));
11156 set_cmd_completer (c
, location_completer
);
11158 add_com_alias ("tp", "trace", class_alias
, 0);
11159 add_com_alias ("tr", "trace", class_alias
, 1);
11160 add_com_alias ("tra", "trace", class_alias
, 1);
11161 add_com_alias ("trac", "trace", class_alias
, 1);
11163 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11164 Set a fast tracepoint at specified line or function.\n\
11166 BREAK_ARGS_HELP ("ftrace") "\n\
11167 Do \"help tracepoints\" for info on other tracepoint commands."));
11168 set_cmd_completer (c
, location_completer
);
11170 add_info ("tracepoints", tracepoints_info
, _("\
11171 Status of tracepoints, or tracepoint number NUMBER.\n\
11172 Convenience variable \"$tpnum\" contains the number of the\n\
11173 last tracepoint set."));
11175 add_info_alias ("tp", "tracepoints", 1);
11177 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11178 Delete specified tracepoints.\n\
11179 Arguments are tracepoint numbers, separated by spaces.\n\
11180 No argument means delete all tracepoints."),
11183 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11184 Disable specified tracepoints.\n\
11185 Arguments are tracepoint numbers, separated by spaces.\n\
11186 No argument means disable all tracepoints."),
11188 deprecate_cmd (c
, "disable");
11190 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11191 Enable specified tracepoints.\n\
11192 Arguments are tracepoint numbers, separated by spaces.\n\
11193 No argument means enable all tracepoints."),
11195 deprecate_cmd (c
, "enable");
11197 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11198 Set the passcount for a tracepoint.\n\
11199 The trace will end when the tracepoint has been passed 'count' times.\n\
11200 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11201 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11203 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11204 Save current tracepoint definitions as a script.\n\
11205 Use the 'source' command in another debug session to restore them."));
11206 set_cmd_completer (c
, filename_completer
);
11208 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11209 Breakpoint specific settings\n\
11210 Configure various breakpoint-specific variables such as\n\
11211 pending breakpoint behavior"),
11212 &breakpoint_set_cmdlist
, "set breakpoint ",
11213 0/*allow-unknown*/, &setlist
);
11214 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11215 Breakpoint specific settings\n\
11216 Configure various breakpoint-specific variables such as\n\
11217 pending breakpoint behavior"),
11218 &breakpoint_show_cmdlist
, "show breakpoint ",
11219 0/*allow-unknown*/, &showlist
);
11221 add_setshow_auto_boolean_cmd ("pending", no_class
,
11222 &pending_break_support
, _("\
11223 Set debugger's behavior regarding pending breakpoints."), _("\
11224 Show debugger's behavior regarding pending breakpoints."), _("\
11225 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11226 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11227 an error. If auto, an unrecognized breakpoint location results in a\n\
11228 user-query to see if a pending breakpoint should be created."),
11230 show_pending_break_support
,
11231 &breakpoint_set_cmdlist
,
11232 &breakpoint_show_cmdlist
);
11234 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11236 add_setshow_boolean_cmd ("auto-hw", no_class
,
11237 &automatic_hardware_breakpoints
, _("\
11238 Set automatic usage of hardware breakpoints."), _("\
11239 Show automatic usage of hardware breakpoints."), _("\
11240 If set, the debugger will automatically use hardware breakpoints for\n\
11241 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11242 a warning will be emitted for such breakpoints."),
11244 show_automatic_hardware_breakpoints
,
11245 &breakpoint_set_cmdlist
,
11246 &breakpoint_show_cmdlist
);
11248 add_setshow_enum_cmd ("always-inserted", class_support
,
11249 always_inserted_enums
, &always_inserted_mode
, _("\
11250 Set mode for inserting breakpoints."), _("\
11251 Show mode for inserting breakpoints."), _("\
11252 When this mode is off, breakpoints are inserted in inferior when it is\n\
11253 resumed, and removed when execution stops. When this mode is on,\n\
11254 breakpoints are inserted immediately and removed only when the user\n\
11255 deletes the breakpoint. When this mode is auto (which is the default),\n\
11256 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11257 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11258 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11259 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11261 &show_always_inserted_mode
,
11262 &breakpoint_set_cmdlist
,
11263 &breakpoint_show_cmdlist
);
11265 automatic_hardware_breakpoints
= 1;
11267 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);