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 if (bs
->old_val
!= NULL
)
2991 value_free (bs
->old_val
);
2997 /* Called when a command is about to proceed the inferior. */
3000 breakpoint_about_to_proceed (void)
3002 if (!ptid_equal (inferior_ptid
, null_ptid
))
3004 struct thread_info
*tp
= inferior_thread ();
3006 /* Allow inferior function calls in breakpoint commands to not
3007 interrupt the command list. When the call finishes
3008 successfully, the inferior will be standing at the same
3009 breakpoint as if nothing happened. */
3014 breakpoint_proceeded
= 1;
3017 /* Stub for cleaning up our state if we error-out of a breakpoint command */
3019 cleanup_executing_breakpoints (void *ignore
)
3021 executing_breakpoint_commands
= 0;
3024 /* Execute all the commands associated with all the breakpoints at this
3025 location. Any of these commands could cause the process to proceed
3026 beyond this point, etc. We look out for such changes by checking
3027 the global "breakpoint_proceeded" after each command.
3029 Returns true if a breakpoint command resumed the inferior. In that
3030 case, it is the caller's responsibility to recall it again with the
3031 bpstat of the current thread. */
3034 bpstat_do_actions_1 (bpstat
*bsp
)
3037 struct cleanup
*old_chain
;
3040 /* Avoid endless recursion if a `source' command is contained
3042 if (executing_breakpoint_commands
)
3045 executing_breakpoint_commands
= 1;
3046 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3048 /* This pointer will iterate over the list of bpstat's. */
3051 breakpoint_proceeded
= 0;
3052 for (; bs
!= NULL
; bs
= bs
->next
)
3054 struct counted_command_line
*ccmd
;
3055 struct command_line
*cmd
;
3056 struct cleanup
*this_cmd_tree_chain
;
3058 /* Take ownership of the BSP's command tree, if it has one.
3060 The command tree could legitimately contain commands like
3061 'step' and 'next', which call clear_proceed_status, which
3062 frees stop_bpstat's command tree. To make sure this doesn't
3063 free the tree we're executing out from under us, we need to
3064 take ownership of the tree ourselves. Since a given bpstat's
3065 commands are only executed once, we don't need to copy it; we
3066 can clear the pointer in the bpstat, and make sure we free
3067 the tree when we're done. */
3068 ccmd
= bs
->commands
;
3069 bs
->commands
= NULL
;
3071 = make_cleanup_decref_counted_command_line (&ccmd
);
3072 cmd
= bs
->commands_left
;
3073 bs
->commands_left
= NULL
;
3077 execute_control_command (cmd
);
3079 if (breakpoint_proceeded
)
3085 /* We can free this command tree now. */
3086 do_cleanups (this_cmd_tree_chain
);
3088 if (breakpoint_proceeded
)
3090 if (target_can_async_p ())
3091 /* If we are in async mode, then the target might be still
3092 running, not stopped at any breakpoint, so nothing for
3093 us to do here -- just return to the event loop. */
3096 /* In sync mode, when execute_control_command returns
3097 we're already standing on the next breakpoint.
3098 Breakpoint commands for that stop were not run, since
3099 execute_command does not run breakpoint commands --
3100 only command_line_handler does, but that one is not
3101 involved in execution of breakpoint commands. So, we
3102 can now execute breakpoint commands. It should be
3103 noted that making execute_command do bpstat actions is
3104 not an option -- in this case we'll have recursive
3105 invocation of bpstat for each breakpoint with a
3106 command, and can easily blow up GDB stack. Instead, we
3107 return true, which will trigger the caller to recall us
3108 with the new stop_bpstat. */
3113 do_cleanups (old_chain
);
3118 bpstat_do_actions (void)
3120 /* Do any commands attached to breakpoint we are stopped at. */
3121 while (!ptid_equal (inferior_ptid
, null_ptid
)
3122 && target_has_execution
3123 && !is_exited (inferior_ptid
)
3124 && !is_executing (inferior_ptid
))
3125 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3126 and only return when it is stopped at the next breakpoint, we
3127 keep doing breakpoint actions until it returns false to
3128 indicate the inferior was not resumed. */
3129 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3133 /* Print out the (old or new) value associated with a watchpoint. */
3136 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3139 fprintf_unfiltered (stream
, _("<unreadable>"));
3142 struct value_print_options opts
;
3143 get_user_print_options (&opts
);
3144 value_print (val
, stream
, &opts
);
3148 /* This is the normal print function for a bpstat. In the future,
3149 much of this logic could (should?) be moved to bpstat_stop_status,
3150 by having it set different print_it values.
3152 Current scheme: When we stop, bpstat_print() is called. It loops
3153 through the bpstat list of things causing this stop, calling the
3154 print_bp_stop_message function on each one. The behavior of the
3155 print_bp_stop_message function depends on the print_it field of
3156 bpstat. If such field so indicates, call this function here.
3158 Return values from this routine (ultimately used by bpstat_print()
3159 and normal_stop() to decide what to do):
3160 PRINT_NOTHING: Means we already printed all we needed to print,
3161 don't print anything else.
3162 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3163 that something to be followed by a location.
3164 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3165 that something to be followed by a location.
3166 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3169 static enum print_stop_action
3170 print_it_typical (bpstat bs
)
3172 struct cleanup
*old_chain
;
3173 struct breakpoint
*b
;
3174 const struct bp_location
*bl
;
3175 struct ui_stream
*stb
;
3177 enum print_stop_action result
;
3179 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3180 which has since been deleted. */
3181 if (bs
->breakpoint_at
== NULL
)
3182 return PRINT_UNKNOWN
;
3183 bl
= bs
->breakpoint_at
;
3186 stb
= ui_out_stream_new (uiout
);
3187 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3192 case bp_hardware_breakpoint
:
3193 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3194 if (bl
->address
!= bl
->requested_address
)
3195 breakpoint_adjustment_warning (bl
->requested_address
,
3198 annotate_breakpoint (b
->number
);
3200 ui_out_text (uiout
, "\nTemporary breakpoint ");
3202 ui_out_text (uiout
, "\nBreakpoint ");
3203 if (ui_out_is_mi_like_p (uiout
))
3205 ui_out_field_string (uiout
, "reason",
3206 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3207 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3209 ui_out_field_int (uiout
, "bkptno", b
->number
);
3210 ui_out_text (uiout
, ", ");
3211 result
= PRINT_SRC_AND_LOC
;
3214 case bp_shlib_event
:
3215 /* Did we stop because the user set the stop_on_solib_events
3216 variable? (If so, we report this as a generic, "Stopped due
3217 to shlib event" message.) */
3218 printf_filtered (_("Stopped due to shared library event\n"));
3219 result
= PRINT_NOTHING
;
3222 case bp_thread_event
:
3223 /* Not sure how we will get here.
3224 GDB should not stop for these breakpoints. */
3225 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3226 result
= PRINT_NOTHING
;
3229 case bp_overlay_event
:
3230 /* By analogy with the thread event, GDB should not stop for these. */
3231 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3232 result
= PRINT_NOTHING
;
3235 case bp_longjmp_master
:
3236 /* These should never be enabled. */
3237 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3238 result
= PRINT_NOTHING
;
3241 case bp_std_terminate_master
:
3242 /* These should never be enabled. */
3243 printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n"));
3244 result
= PRINT_NOTHING
;
3248 case bp_hardware_watchpoint
:
3249 annotate_watchpoint (b
->number
);
3250 if (ui_out_is_mi_like_p (uiout
))
3253 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3255 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3256 ui_out_text (uiout
, "\nOld value = ");
3257 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3258 ui_out_field_stream (uiout
, "old", stb
);
3259 ui_out_text (uiout
, "\nNew value = ");
3260 watchpoint_value_print (b
->val
, stb
->stream
);
3261 ui_out_field_stream (uiout
, "new", stb
);
3262 ui_out_text (uiout
, "\n");
3263 /* More than one watchpoint may have been triggered. */
3264 result
= PRINT_UNKNOWN
;
3267 case bp_read_watchpoint
:
3268 if (ui_out_is_mi_like_p (uiout
))
3271 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3273 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3274 ui_out_text (uiout
, "\nValue = ");
3275 watchpoint_value_print (b
->val
, stb
->stream
);
3276 ui_out_field_stream (uiout
, "value", stb
);
3277 ui_out_text (uiout
, "\n");
3278 result
= PRINT_UNKNOWN
;
3281 case bp_access_watchpoint
:
3282 if (bs
->old_val
!= NULL
)
3284 annotate_watchpoint (b
->number
);
3285 if (ui_out_is_mi_like_p (uiout
))
3288 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3290 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3291 ui_out_text (uiout
, "\nOld value = ");
3292 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3293 ui_out_field_stream (uiout
, "old", stb
);
3294 ui_out_text (uiout
, "\nNew value = ");
3299 if (ui_out_is_mi_like_p (uiout
))
3302 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3303 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3304 ui_out_text (uiout
, "\nValue = ");
3306 watchpoint_value_print (b
->val
, stb
->stream
);
3307 ui_out_field_stream (uiout
, "new", stb
);
3308 ui_out_text (uiout
, "\n");
3309 result
= PRINT_UNKNOWN
;
3312 /* Fall through, we don't deal with these types of breakpoints
3316 if (ui_out_is_mi_like_p (uiout
))
3319 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3320 result
= PRINT_UNKNOWN
;
3324 if (ui_out_is_mi_like_p (uiout
))
3327 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3328 result
= PRINT_UNKNOWN
;
3333 case bp_longjmp_resume
:
3334 case bp_step_resume
:
3335 case bp_watchpoint_scope
:
3337 case bp_std_terminate
:
3339 case bp_fast_tracepoint
:
3342 result
= PRINT_UNKNOWN
;
3346 do_cleanups (old_chain
);
3350 /* Generic routine for printing messages indicating why we
3351 stopped. The behavior of this function depends on the value
3352 'print_it' in the bpstat structure. Under some circumstances we
3353 may decide not to print anything here and delegate the task to
3356 static enum print_stop_action
3357 print_bp_stop_message (bpstat bs
)
3359 switch (bs
->print_it
)
3362 /* Nothing should be printed for this bpstat entry. */
3363 return PRINT_UNKNOWN
;
3367 /* We still want to print the frame, but we already printed the
3368 relevant messages. */
3369 return PRINT_SRC_AND_LOC
;
3372 case print_it_normal
:
3374 const struct bp_location
*bl
= bs
->breakpoint_at
;
3375 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3377 /* Normal case. Call the breakpoint's print_it method, or
3378 print_it_typical. */
3379 /* FIXME: how breakpoint can ever be NULL here? */
3380 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3381 return b
->ops
->print_it (b
);
3383 return print_it_typical (bs
);
3388 internal_error (__FILE__
, __LINE__
,
3389 _("print_bp_stop_message: unrecognized enum value"));
3394 /* Print a message indicating what happened. This is called from
3395 normal_stop(). The input to this routine is the head of the bpstat
3396 list - a list of the eventpoints that caused this stop. This
3397 routine calls the generic print routine for printing a message
3398 about reasons for stopping. This will print (for example) the
3399 "Breakpoint n," part of the output. The return value of this
3402 PRINT_UNKNOWN: Means we printed nothing
3403 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3404 code to print the location. An example is
3405 "Breakpoint 1, " which should be followed by
3407 PRINT_SRC_ONLY: Means we printed something, but there is no need
3408 to also print the location part of the message.
3409 An example is the catch/throw messages, which
3410 don't require a location appended to the end.
3411 PRINT_NOTHING: We have done some printing and we don't need any
3412 further info to be printed.*/
3414 enum print_stop_action
3415 bpstat_print (bpstat bs
)
3419 /* Maybe another breakpoint in the chain caused us to stop.
3420 (Currently all watchpoints go on the bpstat whether hit or not.
3421 That probably could (should) be changed, provided care is taken
3422 with respect to bpstat_explains_signal). */
3423 for (; bs
; bs
= bs
->next
)
3425 val
= print_bp_stop_message (bs
);
3426 if (val
== PRINT_SRC_ONLY
3427 || val
== PRINT_SRC_AND_LOC
3428 || val
== PRINT_NOTHING
)
3432 /* We reached the end of the chain, or we got a null BS to start
3433 with and nothing was printed. */
3434 return PRINT_UNKNOWN
;
3437 /* Evaluate the expression EXP and return 1 if value is zero.
3438 This is used inside a catch_errors to evaluate the breakpoint condition.
3439 The argument is a "struct expression *" that has been cast to char * to
3440 make it pass through catch_errors. */
3443 breakpoint_cond_eval (void *exp
)
3445 struct value
*mark
= value_mark ();
3446 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3447 value_free_to_mark (mark
);
3451 /* Allocate a new bpstat and chain it to the current one. */
3454 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3458 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3460 bs
->breakpoint_at
= bl
;
3461 /* If the condition is false, etc., don't do the commands. */
3462 bs
->commands
= NULL
;
3463 bs
->commands_left
= NULL
;
3465 bs
->print_it
= print_it_normal
;
3469 /* The target has stopped with waitstatus WS. Check if any hardware
3470 watchpoints have triggered, according to the target. */
3473 watchpoints_triggered (struct target_waitstatus
*ws
)
3475 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3477 struct breakpoint
*b
;
3479 if (!stopped_by_watchpoint
)
3481 /* We were not stopped by a watchpoint. Mark all watchpoints
3482 as not triggered. */
3484 if (b
->type
== bp_hardware_watchpoint
3485 || b
->type
== bp_read_watchpoint
3486 || b
->type
== bp_access_watchpoint
)
3487 b
->watchpoint_triggered
= watch_triggered_no
;
3492 if (!target_stopped_data_address (¤t_target
, &addr
))
3494 /* We were stopped by a watchpoint, but we don't know where.
3495 Mark all watchpoints as unknown. */
3497 if (b
->type
== bp_hardware_watchpoint
3498 || b
->type
== bp_read_watchpoint
3499 || b
->type
== bp_access_watchpoint
)
3500 b
->watchpoint_triggered
= watch_triggered_unknown
;
3502 return stopped_by_watchpoint
;
3505 /* The target could report the data address. Mark watchpoints
3506 affected by this data address as triggered, and all others as not
3510 if (b
->type
== bp_hardware_watchpoint
3511 || b
->type
== bp_read_watchpoint
3512 || b
->type
== bp_access_watchpoint
)
3514 struct bp_location
*loc
;
3517 b
->watchpoint_triggered
= watch_triggered_no
;
3518 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3519 /* Exact match not required. Within range is
3521 if (target_watchpoint_addr_within_range (¤t_target
,
3525 b
->watchpoint_triggered
= watch_triggered_yes
;
3533 /* Possible return values for watchpoint_check (this can't be an enum
3534 because of check_errors). */
3535 /* The watchpoint has been deleted. */
3536 #define WP_DELETED 1
3537 /* The value has changed. */
3538 #define WP_VALUE_CHANGED 2
3539 /* The value has not changed. */
3540 #define WP_VALUE_NOT_CHANGED 3
3541 /* Ignore this watchpoint, no matter if the value changed or not. */
3544 #define BP_TEMPFLAG 1
3545 #define BP_HARDWAREFLAG 2
3547 /* Evaluate watchpoint condition expression and check if its value changed.
3549 P should be a pointer to struct bpstat, but is defined as a void *
3550 in order for this function to be usable with catch_errors. */
3553 watchpoint_check (void *p
)
3555 bpstat bs
= (bpstat
) p
;
3556 struct breakpoint
*b
;
3557 struct frame_info
*fr
;
3558 int within_current_scope
;
3560 b
= bs
->breakpoint_at
->owner
;
3562 /* If this is a local watchpoint, we only want to check if the
3563 watchpoint frame is in scope if the current thread is the thread
3564 that was used to create the watchpoint. */
3565 if (!watchpoint_in_thread_scope (b
))
3568 if (b
->exp_valid_block
== NULL
)
3569 within_current_scope
= 1;
3572 struct frame_info
*frame
= get_current_frame ();
3573 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3574 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3576 /* in_function_epilogue_p() returns a non-zero value if we're still
3577 in the function but the stack frame has already been invalidated.
3578 Since we can't rely on the values of local variables after the
3579 stack has been destroyed, we are treating the watchpoint in that
3580 state as `not changed' without further checking. Don't mark
3581 watchpoints as changed if the current frame is in an epilogue -
3582 even if they are in some other frame, our view of the stack
3583 is likely to be wrong and frame_find_by_id could error out. */
3584 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3587 fr
= frame_find_by_id (b
->watchpoint_frame
);
3588 within_current_scope
= (fr
!= NULL
);
3590 /* If we've gotten confused in the unwinder, we might have
3591 returned a frame that can't describe this variable. */
3592 if (within_current_scope
)
3594 struct symbol
*function
;
3596 function
= get_frame_function (fr
);
3597 if (function
== NULL
3598 || !contained_in (b
->exp_valid_block
,
3599 SYMBOL_BLOCK_VALUE (function
)))
3600 within_current_scope
= 0;
3603 if (within_current_scope
)
3604 /* If we end up stopping, the current frame will get selected
3605 in normal_stop. So this call to select_frame won't affect
3610 if (within_current_scope
)
3612 /* We use value_{,free_to_}mark because it could be a
3613 *long* time before we return to the command level and
3614 call free_all_values. We can't call free_all_values because
3615 we might be in the middle of evaluating a function call. */
3617 struct value
*mark
= value_mark ();
3618 struct value
*new_val
;
3620 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3622 /* We use value_equal_contents instead of value_equal because the latter
3623 coerces an array to a pointer, thus comparing just the address of the
3624 array instead of its contents. This is not what we want. */
3625 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3626 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3628 if (new_val
!= NULL
)
3630 release_value (new_val
);
3631 value_free_to_mark (mark
);
3633 bs
->old_val
= b
->val
;
3636 return WP_VALUE_CHANGED
;
3640 /* Nothing changed. */
3641 value_free_to_mark (mark
);
3642 return WP_VALUE_NOT_CHANGED
;
3647 /* This seems like the only logical thing to do because
3648 if we temporarily ignored the watchpoint, then when
3649 we reenter the block in which it is valid it contains
3650 garbage (in the case of a function, it may have two
3651 garbage values, one before and one after the prologue).
3652 So we can't even detect the first assignment to it and
3653 watch after that (since the garbage may or may not equal
3654 the first value assigned). */
3655 /* We print all the stop information in print_it_typical(), but
3656 in this case, by the time we call print_it_typical() this bp
3657 will be deleted already. So we have no choice but print the
3658 information here. */
3659 if (ui_out_is_mi_like_p (uiout
))
3661 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3662 ui_out_text (uiout
, "\nWatchpoint ");
3663 ui_out_field_int (uiout
, "wpnum", b
->number
);
3664 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3665 which its expression is valid.\n");
3667 if (b
->related_breakpoint
)
3669 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3670 b
->related_breakpoint
->related_breakpoint
= NULL
;
3671 b
->related_breakpoint
= NULL
;
3673 b
->disposition
= disp_del_at_next_stop
;
3679 /* Return true if it looks like target has stopped due to hitting
3680 breakpoint location BL. This function does not check if we
3681 should stop, only if BL explains the stop. */
3683 bpstat_check_location (const struct bp_location
*bl
,
3684 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3686 struct breakpoint
*b
= bl
->owner
;
3688 /* By definition, the inferior does not report stops at
3690 if (tracepoint_type (b
))
3693 if (b
->type
!= bp_watchpoint
3694 && b
->type
!= bp_hardware_watchpoint
3695 && b
->type
!= bp_read_watchpoint
3696 && b
->type
!= bp_access_watchpoint
3697 && b
->type
!= bp_hardware_breakpoint
3698 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3700 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3703 if (overlay_debugging
/* unmapped overlay section */
3704 && section_is_overlay (bl
->section
)
3705 && !section_is_mapped (bl
->section
))
3709 /* Continuable hardware watchpoints are treated as non-existent if the
3710 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3711 some data address). Otherwise gdb won't stop on a break instruction
3712 in the code (not from a breakpoint) when a hardware watchpoint has
3713 been defined. Also skip watchpoints which we know did not trigger
3714 (did not match the data address). */
3716 if ((b
->type
== bp_hardware_watchpoint
3717 || b
->type
== bp_read_watchpoint
3718 || b
->type
== bp_access_watchpoint
)
3719 && b
->watchpoint_triggered
== watch_triggered_no
)
3722 if (b
->type
== bp_hardware_breakpoint
)
3724 if (bl
->address
!= bp_addr
)
3726 if (overlay_debugging
/* unmapped overlay section */
3727 && section_is_overlay (bl
->section
)
3728 && !section_is_mapped (bl
->section
))
3732 if (b
->type
== bp_catchpoint
)
3734 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3735 if (!b
->ops
->breakpoint_hit (b
))
3742 /* If BS refers to a watchpoint, determine if the watched values
3743 has actually changed, and we should stop. If not, set BS->stop
3746 bpstat_check_watchpoint (bpstat bs
)
3748 const struct bp_location
*bl
= bs
->breakpoint_at
;
3749 struct breakpoint
*b
= bl
->owner
;
3751 if (b
->type
== bp_watchpoint
3752 || b
->type
== bp_read_watchpoint
3753 || b
->type
== bp_access_watchpoint
3754 || b
->type
== bp_hardware_watchpoint
)
3758 int must_check_value
= 0;
3760 if (b
->type
== bp_watchpoint
)
3761 /* For a software watchpoint, we must always check the
3763 must_check_value
= 1;
3764 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3765 /* We have a hardware watchpoint (read, write, or access)
3766 and the target earlier reported an address watched by
3768 must_check_value
= 1;
3769 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3770 && b
->type
== bp_hardware_watchpoint
)
3771 /* We were stopped by a hardware watchpoint, but the target could
3772 not report the data address. We must check the watchpoint's
3773 value. Access and read watchpoints are out of luck; without
3774 a data address, we can't figure it out. */
3775 must_check_value
= 1;
3777 if (must_check_value
)
3779 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3781 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3782 int e
= catch_errors (watchpoint_check
, bs
, message
,
3784 do_cleanups (cleanups
);
3788 /* We've already printed what needs to be printed. */
3789 bs
->print_it
= print_it_done
;
3793 bs
->print_it
= print_it_noop
;
3796 case WP_VALUE_CHANGED
:
3797 if (b
->type
== bp_read_watchpoint
)
3799 /* There are two cases to consider here:
3801 1. we're watching the triggered memory for reads.
3802 In that case, trust the target, and always report
3803 the watchpoint hit to the user. Even though
3804 reads don't cause value changes, the value may
3805 have changed since the last time it was read, and
3806 since we're not trapping writes, we will not see
3807 those, and as such we should ignore our notion of
3810 2. we're watching the triggered memory for both
3811 reads and writes. There are two ways this may
3814 2.1. this is a target that can't break on data
3815 reads only, but can break on accesses (reads or
3816 writes), such as e.g., x86. We detect this case
3817 at the time we try to insert read watchpoints.
3819 2.2. otherwise, the target supports read
3820 watchpoints, but, the user set an access or write
3821 watchpoint watching the same memory as this read
3824 If we're watching memory writes as well as reads,
3825 ignore watchpoint hits when we find that the
3826 value hasn't changed, as reads don't cause
3827 changes. This still gives false positives when
3828 the program writes the same value to memory as
3829 what there was already in memory (we will confuse
3830 it for a read), but it's much better than
3833 int other_write_watchpoint
= 0;
3835 if (bl
->watchpoint_type
== hw_read
)
3837 struct breakpoint
*other_b
;
3839 ALL_BREAKPOINTS (other_b
)
3840 if ((other_b
->type
== bp_hardware_watchpoint
3841 || other_b
->type
== bp_access_watchpoint
)
3842 && (other_b
->watchpoint_triggered
3843 == watch_triggered_yes
))
3845 other_write_watchpoint
= 1;
3850 if (other_write_watchpoint
3851 || bl
->watchpoint_type
== hw_access
)
3853 /* We're watching the same memory for writes,
3854 and the value changed since the last time we
3855 updated it, so this trap must be for a write.
3857 bs
->print_it
= print_it_noop
;
3862 case WP_VALUE_NOT_CHANGED
:
3863 if (b
->type
== bp_hardware_watchpoint
3864 || b
->type
== bp_watchpoint
)
3866 /* Don't stop: write watchpoints shouldn't fire if
3867 the value hasn't changed. */
3868 bs
->print_it
= print_it_noop
;
3876 /* Error from catch_errors. */
3877 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3878 if (b
->related_breakpoint
)
3879 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3880 b
->disposition
= disp_del_at_next_stop
;
3881 /* We've already printed what needs to be printed. */
3882 bs
->print_it
= print_it_done
;
3886 else /* must_check_value == 0 */
3888 /* This is a case where some watchpoint(s) triggered, but
3889 not at the address of this watchpoint, or else no
3890 watchpoint triggered after all. So don't print
3891 anything for this watchpoint. */
3892 bs
->print_it
= print_it_noop
;
3899 /* Check conditions (condition proper, frame, thread and ignore count)
3900 of breakpoint referred to by BS. If we should not stop for this
3901 breakpoint, set BS->stop to 0. */
3903 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3905 int thread_id
= pid_to_thread_id (ptid
);
3906 const struct bp_location
*bl
= bs
->breakpoint_at
;
3907 struct breakpoint
*b
= bl
->owner
;
3909 if (frame_id_p (b
->frame_id
)
3910 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3914 int value_is_zero
= 0;
3915 struct expression
*cond
;
3917 /* If this is a scope breakpoint, mark the associated
3918 watchpoint as triggered so that we will handle the
3919 out-of-scope event. We'll get to the watchpoint next
3921 if (b
->type
== bp_watchpoint_scope
)
3922 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3924 if (is_watchpoint (b
))
3929 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3931 int within_current_scope
= 1;
3933 /* We use value_mark and value_free_to_mark because it could
3934 be a long time before we return to the command level and
3935 call free_all_values. We can't call free_all_values
3936 because we might be in the middle of evaluating a
3938 struct value
*mark
= value_mark ();
3940 /* Need to select the frame, with all that implies so that
3941 the conditions will have the right context. Because we
3942 use the frame, we will not see an inlined function's
3943 variables when we arrive at a breakpoint at the start
3944 of the inlined function; the current frame will be the
3946 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3947 select_frame (get_current_frame ());
3950 struct frame_info
*frame
;
3952 /* For local watchpoint expressions, which particular
3953 instance of a local is being watched matters, so we
3954 keep track of the frame to evaluate the expression
3955 in. To evaluate the condition however, it doesn't
3956 really matter which instantiation of the function
3957 where the condition makes sense triggers the
3958 watchpoint. This allows an expression like "watch
3959 global if q > 10" set in `func', catch writes to
3960 global on all threads that call `func', or catch
3961 writes on all recursive calls of `func' by a single
3962 thread. We simply always evaluate the condition in
3963 the innermost frame that's executing where it makes
3964 sense to evaluate the condition. It seems
3966 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3968 select_frame (frame
);
3970 within_current_scope
= 0;
3972 if (within_current_scope
)
3974 = catch_errors (breakpoint_cond_eval
, cond
,
3975 "Error in testing breakpoint condition:\n",
3979 warning (_("Watchpoint condition cannot be tested "
3980 "in the current scope"));
3981 /* If we failed to set the right context for this
3982 watchpoint, unconditionally report it. */
3985 /* FIXME-someday, should give breakpoint # */
3986 value_free_to_mark (mark
);
3989 if (cond
&& value_is_zero
)
3993 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3997 else if (b
->ignore_count
> 0)
4000 annotate_ignore_count_change ();
4002 /* Increase the hit count even though we don't
4010 /* Get a bpstat associated with having just stopped at address
4011 BP_ADDR in thread PTID.
4013 Determine whether we stopped at a breakpoint, etc, or whether we
4014 don't understand this stop. Result is a chain of bpstat's such that:
4016 if we don't understand the stop, the result is a null pointer.
4018 if we understand why we stopped, the result is not null.
4020 Each element of the chain refers to a particular breakpoint or
4021 watchpoint at which we have stopped. (We may have stopped for
4022 several reasons concurrently.)
4024 Each element of the chain has valid next, breakpoint_at,
4025 commands, FIXME??? fields. */
4028 bpstat_stop_status (struct address_space
*aspace
,
4029 CORE_ADDR bp_addr
, ptid_t ptid
)
4031 struct breakpoint
*b
= NULL
;
4032 struct bp_location
*bl
, **blp_tmp
;
4033 struct bp_location
*loc
;
4034 /* Root of the chain of bpstat's */
4035 struct bpstats root_bs
[1];
4036 /* Pointer to the last thing in the chain currently. */
4037 bpstat bs
= root_bs
;
4039 int need_remove_insert
;
4041 /* ALL_BP_LOCATIONS iteration would break across
4042 update_global_location_list possibly executed by
4043 bpstat_check_breakpoint_conditions's inferior call. */
4047 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4050 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4052 /* For hardware watchpoints, we look only at the first location.
4053 The watchpoint_check function will work on entire expression,
4054 not the individual locations. For read watchopints, the
4055 watchpoints_triggered function have checked all locations
4057 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4060 if (bl
->shlib_disabled
)
4063 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4066 /* Come here if it's a watchpoint, or if the break address matches */
4068 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4070 /* Assume we stop. Should we find watchpoint that is not actually
4071 triggered, or if condition of breakpoint is false, we'll reset
4076 bpstat_check_watchpoint (bs
);
4080 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4081 || b
->type
== bp_longjmp_master
4082 || b
->type
== bp_std_terminate_master
)
4083 /* We do not stop for these. */
4086 bpstat_check_breakpoint_conditions (bs
, ptid
);
4092 /* We will stop here */
4093 if (b
->disposition
== disp_disable
)
4095 if (b
->enable_state
!= bp_permanent
)
4096 b
->enable_state
= bp_disabled
;
4097 update_global_location_list (0);
4101 bs
->commands
= b
->commands
;
4102 incref_counted_command_line (bs
->commands
);
4103 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4104 if (bs
->commands_left
4105 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4108 bs
->commands_left
->line
) == 0)))
4110 bs
->commands_left
= bs
->commands_left
->next
;
4115 /* Print nothing for this entry if we dont stop or dont print. */
4116 if (bs
->stop
== 0 || bs
->print
== 0)
4117 bs
->print_it
= print_it_noop
;
4121 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4123 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4126 bs
= bpstat_alloc (loc
, bs
);
4127 /* For hits of moribund locations, we should just proceed. */
4130 bs
->print_it
= print_it_noop
;
4134 bs
->next
= NULL
; /* Terminate the chain */
4136 /* If we aren't stopping, the value of some hardware watchpoint may
4137 not have changed, but the intermediate memory locations we are
4138 watching may have. Don't bother if we're stopping; this will get
4140 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4144 need_remove_insert
= 0;
4146 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4148 && bs
->breakpoint_at
->owner
4149 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4151 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4152 /* Updating watchpoints invalidates bs->breakpoint_at.
4153 Prevent further code from trying to use it. */
4154 bs
->breakpoint_at
= NULL
;
4155 need_remove_insert
= 1;
4158 if (need_remove_insert
)
4159 update_global_location_list (1);
4161 return root_bs
->next
;
4164 /* Tell what to do about this bpstat. */
4166 bpstat_what (bpstat bs
)
4168 /* Classify each bpstat as one of the following. */
4171 /* This bpstat element has no effect on the main_action. */
4174 /* There was a watchpoint, stop but don't print. */
4177 /* There was a watchpoint, stop and print. */
4180 /* There was a breakpoint but we're not stopping. */
4183 /* There was a breakpoint, stop but don't print. */
4186 /* There was a breakpoint, stop and print. */
4189 /* We hit the longjmp breakpoint. */
4192 /* We hit the longjmp_resume breakpoint. */
4195 /* We hit the step_resume breakpoint. */
4198 /* We hit the shared library event breakpoint. */
4201 /* We hit the jit event breakpoint. */
4204 /* This is just used to count how many enums there are. */
4208 /* Here is the table which drives this routine. So that we can
4209 format it pretty, we define some abbreviations for the
4210 enum bpstat_what codes. */
4211 #define kc BPSTAT_WHAT_KEEP_CHECKING
4212 #define ss BPSTAT_WHAT_STOP_SILENT
4213 #define sn BPSTAT_WHAT_STOP_NOISY
4214 #define sgl BPSTAT_WHAT_SINGLE
4215 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4216 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4217 #define sr BPSTAT_WHAT_STEP_RESUME
4218 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4219 #define jit BPSTAT_WHAT_CHECK_JIT
4221 /* "Can't happen." Might want to print an error message.
4222 abort() is not out of the question, but chances are GDB is just
4223 a bit confused, not unusable. */
4224 #define err BPSTAT_WHAT_STOP_NOISY
4226 /* Given an old action and a class, come up with a new action. */
4227 /* One interesting property of this table is that wp_silent is the same
4228 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4229 after stopping, the check for whether to step over a breakpoint
4230 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4231 reference to how we stopped. We retain separate wp_silent and
4232 bp_silent codes in case we want to change that someday.
4234 Another possibly interesting property of this table is that
4235 there's a partial ordering, priority-like, of the actions. Once
4236 you've decided that some action is appropriate, you'll never go
4237 back and decide something of a lower priority is better. The
4240 kc < jit clr sgl shl slr sn sr ss
4241 sgl < jit shl slr sn sr ss
4242 slr < jit err shl sn sr ss
4243 clr < jit err shl sn sr ss
4250 What I think this means is that we don't need a damned table
4251 here. If you just put the rows and columns in the right order,
4252 it'd look awfully regular. We could simply walk the bpstat list
4253 and choose the highest priority action we find, with a little
4254 logic to handle the 'err' cases. */
4256 /* step_resume entries: a step resume breakpoint overrides another
4257 breakpoint of signal handling (see comment in wait_for_inferior
4258 at where we set the step_resume breakpoint). */
4260 static const enum bpstat_what_main_action
4261 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4264 /* kc ss sn sgl slr clr sr shl jit */
4265 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4266 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4267 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4268 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4269 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4270 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4271 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4272 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4273 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4274 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4275 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4289 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4290 struct bpstat_what retval
;
4292 retval
.call_dummy
= STOP_NONE
;
4293 for (; bs
!= NULL
; bs
= bs
->next
)
4295 enum class bs_class
= no_effect
;
4296 if (bs
->breakpoint_at
== NULL
)
4297 /* I suspect this can happen if it was a momentary breakpoint
4298 which has since been deleted. */
4300 if (bs
->breakpoint_at
->owner
== NULL
)
4301 bs_class
= bp_nostop
;
4303 switch (bs
->breakpoint_at
->owner
->type
)
4309 case bp_hardware_breakpoint
:
4315 bs_class
= bp_noisy
;
4317 bs_class
= bp_silent
;
4320 bs_class
= bp_nostop
;
4323 case bp_hardware_watchpoint
:
4324 case bp_read_watchpoint
:
4325 case bp_access_watchpoint
:
4329 bs_class
= wp_noisy
;
4331 bs_class
= wp_silent
;
4334 /* There was a watchpoint, but we're not stopping.
4335 This requires no further action. */
4336 bs_class
= no_effect
;
4339 bs_class
= long_jump
;
4341 case bp_longjmp_resume
:
4342 bs_class
= long_resume
;
4344 case bp_step_resume
:
4347 bs_class
= step_resume
;
4350 /* It is for the wrong frame. */
4351 bs_class
= bp_nostop
;
4353 case bp_watchpoint_scope
:
4354 bs_class
= bp_nostop
;
4356 case bp_shlib_event
:
4357 bs_class
= shlib_event
;
4360 bs_class
= jit_event
;
4362 case bp_thread_event
:
4363 case bp_overlay_event
:
4364 case bp_longjmp_master
:
4365 case bp_std_terminate_master
:
4366 bs_class
= bp_nostop
;
4372 bs_class
= bp_noisy
;
4374 bs_class
= bp_silent
;
4377 /* There was a catchpoint, but we're not stopping.
4378 This requires no further action. */
4379 bs_class
= no_effect
;
4382 /* Make sure the action is stop (silent or noisy),
4383 so infrun.c pops the dummy frame. */
4384 bs_class
= bp_silent
;
4385 retval
.call_dummy
= STOP_STACK_DUMMY
;
4387 case bp_std_terminate
:
4388 /* Make sure the action is stop (silent or noisy),
4389 so infrun.c pops the dummy frame. */
4390 bs_class
= bp_silent
;
4391 retval
.call_dummy
= STOP_STD_TERMINATE
;
4394 case bp_fast_tracepoint
:
4395 /* Tracepoint hits should not be reported back to GDB, and
4396 if one got through somehow, it should have been filtered
4398 internal_error (__FILE__
, __LINE__
,
4399 _("bpstat_what: tracepoint encountered"));
4402 current_action
= table
[(int) bs_class
][(int) current_action
];
4404 retval
.main_action
= current_action
;
4408 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4409 without hardware support). This isn't related to a specific bpstat,
4410 just to things like whether watchpoints are set. */
4413 bpstat_should_step (void)
4415 struct breakpoint
*b
;
4417 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4423 bpstat_causes_stop (bpstat bs
)
4425 for (; bs
!= NULL
; bs
= bs
->next
)
4434 /* Print the LOC location out of the list of B->LOC locations. */
4436 static void print_breakpoint_location (struct breakpoint
*b
,
4437 struct bp_location
*loc
,
4439 struct ui_stream
*stb
)
4441 struct cleanup
*old_chain
= save_current_program_space ();
4443 if (loc
!= NULL
&& loc
->shlib_disabled
)
4447 set_current_program_space (loc
->pspace
);
4449 if (b
->source_file
&& loc
)
4452 = find_pc_sect_function (loc
->address
, loc
->section
);
4455 ui_out_text (uiout
, "in ");
4456 ui_out_field_string (uiout
, "func",
4457 SYMBOL_PRINT_NAME (sym
));
4458 ui_out_wrap_hint (uiout
, wrap_indent
);
4459 ui_out_text (uiout
, " at ");
4461 ui_out_field_string (uiout
, "file", b
->source_file
);
4462 ui_out_text (uiout
, ":");
4464 if (ui_out_is_mi_like_p (uiout
))
4466 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4467 char *fullname
= symtab_to_fullname (sal
.symtab
);
4470 ui_out_field_string (uiout
, "fullname", fullname
);
4473 ui_out_field_int (uiout
, "line", b
->line_number
);
4477 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4479 ui_out_field_stream (uiout
, "at", stb
);
4482 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4484 do_cleanups (old_chain
);
4487 /* Print B to gdb_stdout. */
4489 print_one_breakpoint_location (struct breakpoint
*b
,
4490 struct bp_location
*loc
,
4492 struct bp_location
**last_loc
,
4493 int print_address_bits
,
4496 struct command_line
*l
;
4498 struct ep_type_description
4503 static struct ep_type_description bptypes
[] =
4505 {bp_none
, "?deleted?"},
4506 {bp_breakpoint
, "breakpoint"},
4507 {bp_hardware_breakpoint
, "hw breakpoint"},
4508 {bp_until
, "until"},
4509 {bp_finish
, "finish"},
4510 {bp_watchpoint
, "watchpoint"},
4511 {bp_hardware_watchpoint
, "hw watchpoint"},
4512 {bp_read_watchpoint
, "read watchpoint"},
4513 {bp_access_watchpoint
, "acc watchpoint"},
4514 {bp_longjmp
, "longjmp"},
4515 {bp_longjmp_resume
, "longjmp resume"},
4516 {bp_step_resume
, "step resume"},
4517 {bp_watchpoint_scope
, "watchpoint scope"},
4518 {bp_call_dummy
, "call dummy"},
4519 {bp_std_terminate
, "std::terminate"},
4520 {bp_shlib_event
, "shlib events"},
4521 {bp_thread_event
, "thread events"},
4522 {bp_overlay_event
, "overlay events"},
4523 {bp_longjmp_master
, "longjmp master"},
4524 {bp_std_terminate_master
, "std::terminate master"},
4525 {bp_catchpoint
, "catchpoint"},
4526 {bp_tracepoint
, "tracepoint"},
4527 {bp_fast_tracepoint
, "fast tracepoint"},
4528 {bp_jit_event
, "jit events"},
4531 static char bpenables
[] = "nynny";
4532 char wrap_indent
[80];
4533 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4534 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4535 struct cleanup
*bkpt_chain
;
4537 int header_of_multiple
= 0;
4538 int part_of_multiple
= (loc
!= NULL
);
4539 struct value_print_options opts
;
4541 get_user_print_options (&opts
);
4543 gdb_assert (!loc
|| loc_number
!= 0);
4544 /* See comment in print_one_breakpoint concerning
4545 treatment of breakpoints with single disabled
4549 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4550 header_of_multiple
= 1;
4555 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4559 if (part_of_multiple
)
4562 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4563 ui_out_field_string (uiout
, "number", formatted
);
4568 ui_out_field_int (uiout
, "number", b
->number
);
4573 if (part_of_multiple
)
4574 ui_out_field_skip (uiout
, "type");
4577 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4578 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4579 internal_error (__FILE__
, __LINE__
,
4580 _("bptypes table does not describe type #%d."),
4582 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4587 if (part_of_multiple
)
4588 ui_out_field_skip (uiout
, "disp");
4590 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4595 if (part_of_multiple
)
4596 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4598 ui_out_field_fmt (uiout
, "enabled", "%c",
4599 bpenables
[(int) b
->enable_state
]);
4600 ui_out_spaces (uiout
, 2);
4604 strcpy (wrap_indent
, " ");
4605 if (opts
.addressprint
)
4607 if (print_address_bits
<= 32)
4608 strcat (wrap_indent
, " ");
4610 strcat (wrap_indent
, " ");
4613 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4615 /* Although the print_one can possibly print
4616 all locations, calling it here is not likely
4617 to get any nice result. So, make sure there's
4618 just one location. */
4619 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4620 b
->ops
->print_one (b
, last_loc
);
4626 internal_error (__FILE__
, __LINE__
,
4627 _("print_one_breakpoint: bp_none encountered\n"));
4631 case bp_hardware_watchpoint
:
4632 case bp_read_watchpoint
:
4633 case bp_access_watchpoint
:
4634 /* Field 4, the address, is omitted (which makes the columns
4635 not line up too nicely with the headers, but the effect
4636 is relatively readable). */
4637 if (opts
.addressprint
)
4638 ui_out_field_skip (uiout
, "addr");
4640 ui_out_field_string (uiout
, "what", b
->exp_string
);
4644 case bp_hardware_breakpoint
:
4648 case bp_longjmp_resume
:
4649 case bp_step_resume
:
4650 case bp_watchpoint_scope
:
4652 case bp_std_terminate
:
4653 case bp_shlib_event
:
4654 case bp_thread_event
:
4655 case bp_overlay_event
:
4656 case bp_longjmp_master
:
4657 case bp_std_terminate_master
:
4659 case bp_fast_tracepoint
:
4661 if (opts
.addressprint
)
4664 if (header_of_multiple
)
4665 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4666 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4667 ui_out_field_string (uiout
, "addr", "<PENDING>");
4669 ui_out_field_core_addr (uiout
, "addr",
4670 loc
->gdbarch
, loc
->address
);
4673 if (!header_of_multiple
)
4674 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4681 /* For backward compatibility, don't display inferiors unless there
4684 && !header_of_multiple
4686 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4687 && (number_of_program_spaces () > 1
4688 || number_of_inferiors () > 1)
4689 && loc
->owner
->type
!= bp_catchpoint
)))
4691 struct inferior
*inf
;
4694 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4696 if (inf
->pspace
== loc
->pspace
)
4701 ui_out_text (uiout
, " inf ");
4704 ui_out_text (uiout
, ", ");
4705 ui_out_text (uiout
, plongest (inf
->num
));
4710 if (!part_of_multiple
)
4712 if (b
->thread
!= -1)
4714 /* FIXME: This seems to be redundant and lost here; see the
4715 "stop only in" line a little further down. */
4716 ui_out_text (uiout
, " thread ");
4717 ui_out_field_int (uiout
, "thread", b
->thread
);
4719 else if (b
->task
!= 0)
4721 ui_out_text (uiout
, " task ");
4722 ui_out_field_int (uiout
, "task", b
->task
);
4726 ui_out_text (uiout
, "\n");
4728 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4731 ui_out_text (uiout
, "\tstop only in stack frame at ");
4732 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4734 ui_out_field_core_addr (uiout
, "frame",
4735 b
->gdbarch
, b
->frame_id
.stack_addr
);
4736 ui_out_text (uiout
, "\n");
4739 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4741 /* We do not print the condition for Ada exception catchpoints
4742 because the condition is an internal implementation detail
4743 that we do not want to expose to the user. */
4745 if (tracepoint_type (b
))
4746 ui_out_text (uiout
, "\ttrace only if ");
4748 ui_out_text (uiout
, "\tstop only if ");
4749 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4750 ui_out_text (uiout
, "\n");
4753 if (!part_of_multiple
&& b
->thread
!= -1)
4755 /* FIXME should make an annotation for this */
4756 ui_out_text (uiout
, "\tstop only in thread ");
4757 ui_out_field_int (uiout
, "thread", b
->thread
);
4758 ui_out_text (uiout
, "\n");
4761 if (!part_of_multiple
&& b
->hit_count
)
4763 /* FIXME should make an annotation for this */
4764 if (ep_is_catchpoint (b
))
4765 ui_out_text (uiout
, "\tcatchpoint");
4767 ui_out_text (uiout
, "\tbreakpoint");
4768 ui_out_text (uiout
, " already hit ");
4769 ui_out_field_int (uiout
, "times", b
->hit_count
);
4770 if (b
->hit_count
== 1)
4771 ui_out_text (uiout
, " time\n");
4773 ui_out_text (uiout
, " times\n");
4776 /* Output the count also if it is zero, but only if this is
4777 mi. FIXME: Should have a better test for this. */
4778 if (ui_out_is_mi_like_p (uiout
))
4779 if (!part_of_multiple
&& b
->hit_count
== 0)
4780 ui_out_field_int (uiout
, "times", b
->hit_count
);
4782 if (!part_of_multiple
&& b
->ignore_count
)
4785 ui_out_text (uiout
, "\tignore next ");
4786 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4787 ui_out_text (uiout
, " hits\n");
4790 l
= b
->commands
? b
->commands
->commands
: NULL
;
4791 if (!part_of_multiple
&& l
)
4793 struct cleanup
*script_chain
;
4796 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4797 print_command_lines (uiout
, l
, 4);
4798 do_cleanups (script_chain
);
4801 if (!part_of_multiple
&& b
->pass_count
)
4803 annotate_field (10);
4804 ui_out_text (uiout
, "\tpass count ");
4805 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4806 ui_out_text (uiout
, " \n");
4809 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4812 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4813 else if (b
->exp_string
)
4814 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4817 do_cleanups (bkpt_chain
);
4818 do_cleanups (old_chain
);
4822 print_one_breakpoint (struct breakpoint
*b
,
4823 struct bp_location
**last_loc
, int print_address_bits
,
4826 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4827 print_address_bits
, allflag
);
4829 /* If this breakpoint has custom print function,
4830 it's already printed. Otherwise, print individual
4831 locations, if any. */
4832 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4834 /* If breakpoint has a single location that is
4835 disabled, we print it as if it had
4836 several locations, since otherwise it's hard to
4837 represent "breakpoint enabled, location disabled"
4839 Note that while hardware watchpoints have
4840 several locations internally, that's no a property
4843 && !is_hardware_watchpoint (b
)
4844 && (b
->loc
->next
|| !b
->loc
->enabled
)
4845 && !ui_out_is_mi_like_p (uiout
))
4847 struct bp_location
*loc
;
4849 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4850 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4851 print_address_bits
, allflag
);
4857 breakpoint_address_bits (struct breakpoint
*b
)
4859 int print_address_bits
= 0;
4860 struct bp_location
*loc
;
4862 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4866 /* Software watchpoints that aren't watching memory don't have
4867 an address to print. */
4868 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4871 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4872 if (addr_bit
> print_address_bits
)
4873 print_address_bits
= addr_bit
;
4876 return print_address_bits
;
4879 struct captured_breakpoint_query_args
4885 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4887 struct captured_breakpoint_query_args
*args
= data
;
4888 struct breakpoint
*b
;
4889 struct bp_location
*dummy_loc
= NULL
;
4892 if (args
->bnum
== b
->number
)
4894 int print_address_bits
= breakpoint_address_bits (b
);
4895 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4903 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4905 struct captured_breakpoint_query_args args
;
4907 /* For the moment we don't trust print_one_breakpoint() to not throw
4909 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4910 error_message
, RETURN_MASK_ALL
) < 0)
4916 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4917 catchpoints, et.al.). */
4920 user_settable_breakpoint (const struct breakpoint
*b
)
4922 return (b
->type
== bp_breakpoint
4923 || b
->type
== bp_catchpoint
4924 || b
->type
== bp_hardware_breakpoint
4925 || tracepoint_type (b
)
4926 || b
->type
== bp_watchpoint
4927 || b
->type
== bp_read_watchpoint
4928 || b
->type
== bp_access_watchpoint
4929 || b
->type
== bp_hardware_watchpoint
);
4932 /* Print information on user settable breakpoint (watchpoint, etc)
4933 number BNUM. If BNUM is -1 print all user settable breakpoints.
4934 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4937 breakpoint_1 (int bnum
, int allflag
)
4939 struct breakpoint
*b
;
4940 struct bp_location
*last_loc
= NULL
;
4941 int nr_printable_breakpoints
;
4942 struct cleanup
*bkpttbl_chain
;
4943 struct value_print_options opts
;
4944 int print_address_bits
= 0;
4946 get_user_print_options (&opts
);
4948 /* Compute the number of rows in the table, as well as the
4949 size required for address fields. */
4950 nr_printable_breakpoints
= 0;
4953 || bnum
== b
->number
)
4955 if (allflag
|| user_settable_breakpoint (b
))
4957 int addr_bit
= breakpoint_address_bits (b
);
4958 if (addr_bit
> print_address_bits
)
4959 print_address_bits
= addr_bit
;
4961 nr_printable_breakpoints
++;
4965 if (opts
.addressprint
)
4967 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4971 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4974 if (nr_printable_breakpoints
> 0)
4975 annotate_breakpoints_headers ();
4976 if (nr_printable_breakpoints
> 0)
4978 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4979 if (nr_printable_breakpoints
> 0)
4981 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4982 if (nr_printable_breakpoints
> 0)
4984 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4985 if (nr_printable_breakpoints
> 0)
4987 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4988 if (opts
.addressprint
)
4990 if (nr_printable_breakpoints
> 0)
4992 if (print_address_bits
<= 32)
4993 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4995 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4997 if (nr_printable_breakpoints
> 0)
4999 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5000 ui_out_table_body (uiout
);
5001 if (nr_printable_breakpoints
> 0)
5002 annotate_breakpoints_table ();
5008 || bnum
== b
->number
)
5010 /* We only print out user settable breakpoints unless the
5012 if (allflag
|| user_settable_breakpoint (b
))
5013 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5017 do_cleanups (bkpttbl_chain
);
5019 if (nr_printable_breakpoints
== 0)
5022 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5024 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
5029 if (last_loc
&& !server_command
)
5030 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5033 /* FIXME? Should this be moved up so that it is only called when
5034 there have been breakpoints? */
5035 annotate_breakpoints_table_end ();
5039 breakpoints_info (char *bnum_exp
, int from_tty
)
5044 bnum
= parse_and_eval_long (bnum_exp
);
5046 breakpoint_1 (bnum
, 0);
5050 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5055 bnum
= parse_and_eval_long (bnum_exp
);
5057 breakpoint_1 (bnum
, 1);
5061 breakpoint_has_pc (struct breakpoint
*b
,
5062 struct program_space
*pspace
,
5063 CORE_ADDR pc
, struct obj_section
*section
)
5065 struct bp_location
*bl
= b
->loc
;
5066 for (; bl
; bl
= bl
->next
)
5068 if (bl
->pspace
== pspace
5069 && bl
->address
== pc
5070 && (!overlay_debugging
|| bl
->section
== section
))
5076 /* Print a message describing any breakpoints set at PC. This
5077 concerns with logical breakpoints, so we match program spaces, not
5081 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5082 struct program_space
*pspace
, CORE_ADDR pc
,
5083 struct obj_section
*section
, int thread
)
5086 struct breakpoint
*b
;
5089 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5093 printf_filtered (_("Note: breakpoint "));
5094 else /* if (others == ???) */
5095 printf_filtered (_("Note: breakpoints "));
5097 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5100 printf_filtered ("%d", b
->number
);
5101 if (b
->thread
== -1 && thread
!= -1)
5102 printf_filtered (" (all threads)");
5103 else if (b
->thread
!= -1)
5104 printf_filtered (" (thread %d)", b
->thread
);
5105 printf_filtered ("%s%s ",
5106 ((b
->enable_state
== bp_disabled
5107 || b
->enable_state
== bp_call_disabled
5108 || b
->enable_state
== bp_startup_disabled
)
5110 : b
->enable_state
== bp_permanent
5114 : ((others
== 1) ? " and" : ""));
5116 printf_filtered (_("also set at pc "));
5117 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5118 printf_filtered (".\n");
5122 /* Set the default place to put a breakpoint
5123 for the `break' command with no arguments. */
5126 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5127 CORE_ADDR addr
, struct symtab
*symtab
,
5130 default_breakpoint_valid
= valid
;
5131 default_breakpoint_pspace
= pspace
;
5132 default_breakpoint_address
= addr
;
5133 default_breakpoint_symtab
= symtab
;
5134 default_breakpoint_line
= line
;
5137 /* Return true iff it is meaningful to use the address member of
5138 BPT. For some breakpoint types, the address member is irrelevant
5139 and it makes no sense to attempt to compare it to other addresses
5140 (or use it for any other purpose either).
5142 More specifically, each of the following breakpoint types will always
5143 have a zero valued address and we don't want to mark breakpoints of any of
5144 these types to be a duplicate of an actual breakpoint at address zero:
5152 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5154 enum bptype type
= bpt
->type
;
5156 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5159 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5160 true if LOC1 and LOC2 represent the same watchpoint location. */
5163 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5165 /* Note that this checks the owner's type, not the location's. In
5166 case the target does not support read watchpoints, but does
5167 support access watchpoints, we'll have bp_read_watchpoint
5168 watchpoints with hw_access locations. Those should be considered
5169 duplicates of hw_read locations. The hw_read locations will
5170 become hw_access locations later. */
5171 return (loc1
->owner
->type
== loc2
->owner
->type
5172 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5173 && loc1
->address
== loc2
->address
5174 && loc1
->length
== loc2
->length
);
5177 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5178 same breakpoint location. In most targets, this can only be true
5179 if ASPACE1 matches ASPACE2. On targets that have global
5180 breakpoints, the address space doesn't really matter. */
5183 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5184 struct address_space
*aspace2
, CORE_ADDR addr2
)
5186 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5187 || aspace1
== aspace2
)
5191 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5192 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5193 represent the same location. */
5196 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5198 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5199 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5201 if (hw_point1
!= hw_point2
)
5204 return watchpoint_locations_match (loc1
, loc2
);
5206 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5207 loc2
->pspace
->aspace
, loc2
->address
);
5211 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5212 int bnum
, int have_bnum
)
5217 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5218 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5220 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5221 bnum
, astr1
, astr2
);
5223 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5226 /* Adjust a breakpoint's address to account for architectural constraints
5227 on breakpoint placement. Return the adjusted address. Note: Very
5228 few targets require this kind of adjustment. For most targets,
5229 this function is simply the identity function. */
5232 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5233 CORE_ADDR bpaddr
, enum bptype bptype
)
5235 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5237 /* Very few targets need any kind of breakpoint adjustment. */
5240 else if (bptype
== bp_watchpoint
5241 || bptype
== bp_hardware_watchpoint
5242 || bptype
== bp_read_watchpoint
5243 || bptype
== bp_access_watchpoint
5244 || bptype
== bp_catchpoint
)
5246 /* Watchpoints and the various bp_catch_* eventpoints should not
5247 have their addresses modified. */
5252 CORE_ADDR adjusted_bpaddr
;
5254 /* Some targets have architectural constraints on the placement
5255 of breakpoint instructions. Obtain the adjusted address. */
5256 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5258 /* An adjusted breakpoint address can significantly alter
5259 a user's expectations. Print a warning if an adjustment
5261 if (adjusted_bpaddr
!= bpaddr
)
5262 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5264 return adjusted_bpaddr
;
5268 /* Allocate a struct bp_location. */
5270 static struct bp_location
*
5271 allocate_bp_location (struct breakpoint
*bpt
)
5273 struct bp_location
*loc
, *loc_p
;
5275 loc
= xmalloc (sizeof (struct bp_location
));
5276 memset (loc
, 0, sizeof (*loc
));
5280 loc
->shlib_disabled
= 0;
5289 case bp_longjmp_resume
:
5290 case bp_step_resume
:
5291 case bp_watchpoint_scope
:
5293 case bp_std_terminate
:
5294 case bp_shlib_event
:
5295 case bp_thread_event
:
5296 case bp_overlay_event
:
5298 case bp_longjmp_master
:
5299 case bp_std_terminate_master
:
5300 loc
->loc_type
= bp_loc_software_breakpoint
;
5302 case bp_hardware_breakpoint
:
5303 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5305 case bp_hardware_watchpoint
:
5306 case bp_read_watchpoint
:
5307 case bp_access_watchpoint
:
5308 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5313 case bp_fast_tracepoint
:
5314 loc
->loc_type
= bp_loc_other
;
5317 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5323 static void free_bp_location (struct bp_location
*loc
)
5328 if (loc
->function_name
)
5329 xfree (loc
->function_name
);
5334 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5335 that has type BPTYPE and has no locations as yet. */
5336 /* This function is used in gdbtk sources and thus can not be made static. */
5338 static struct breakpoint
*
5339 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5342 struct breakpoint
*b
, *b1
;
5344 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5345 memset (b
, 0, sizeof (*b
));
5348 b
->gdbarch
= gdbarch
;
5349 b
->language
= current_language
->la_language
;
5350 b
->input_radix
= input_radix
;
5352 b
->enable_state
= bp_enabled
;
5355 b
->ignore_count
= 0;
5357 b
->frame_id
= null_frame_id
;
5358 b
->forked_inferior_pid
= null_ptid
;
5359 b
->exec_pathname
= NULL
;
5360 b
->syscalls_to_be_caught
= NULL
;
5362 b
->condition_not_parsed
= 0;
5364 /* Add this breakpoint to the end of the chain
5365 so that a list of breakpoints will come out in order
5366 of increasing numbers. */
5368 b1
= breakpoint_chain
;
5370 breakpoint_chain
= b
;
5380 /* Initialize loc->function_name. */
5382 set_breakpoint_location_function (struct bp_location
*loc
)
5384 if (loc
->owner
->type
== bp_breakpoint
5385 || loc
->owner
->type
== bp_hardware_breakpoint
5386 || tracepoint_type (loc
->owner
))
5388 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5390 if (loc
->function_name
)
5391 loc
->function_name
= xstrdup (loc
->function_name
);
5395 /* Attempt to determine architecture of location identified by SAL. */
5396 static struct gdbarch
*
5397 get_sal_arch (struct symtab_and_line sal
)
5400 return get_objfile_arch (sal
.section
->objfile
);
5402 return get_objfile_arch (sal
.symtab
->objfile
);
5407 /* set_raw_breakpoint is a low level routine for allocating and
5408 partially initializing a breakpoint of type BPTYPE. The newly
5409 created breakpoint's address, section, source file name, and line
5410 number are provided by SAL. The newly created and partially
5411 initialized breakpoint is added to the breakpoint chain and
5412 is also returned as the value of this function.
5414 It is expected that the caller will complete the initialization of
5415 the newly created breakpoint struct as well as output any status
5416 information regarding the creation of a new breakpoint. In
5417 particular, set_raw_breakpoint does NOT set the breakpoint
5418 number! Care should be taken to not allow an error to occur
5419 prior to completing the initialization of the breakpoint. If this
5420 should happen, a bogus breakpoint will be left on the chain. */
5423 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5424 struct symtab_and_line sal
, enum bptype bptype
)
5426 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5427 CORE_ADDR adjusted_address
;
5428 struct gdbarch
*loc_gdbarch
;
5430 loc_gdbarch
= get_sal_arch (sal
);
5432 loc_gdbarch
= b
->gdbarch
;
5434 if (bptype
!= bp_catchpoint
)
5435 gdb_assert (sal
.pspace
!= NULL
);
5437 /* Adjust the breakpoint's address prior to allocating a location.
5438 Once we call allocate_bp_location(), that mostly uninitialized
5439 location will be placed on the location chain. Adjustment of the
5440 breakpoint may cause target_read_memory() to be called and we do
5441 not want its scan of the location chain to find a breakpoint and
5442 location that's only been partially initialized. */
5443 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5445 b
->loc
= allocate_bp_location (b
);
5446 b
->loc
->gdbarch
= loc_gdbarch
;
5447 b
->loc
->requested_address
= sal
.pc
;
5448 b
->loc
->address
= adjusted_address
;
5449 b
->loc
->pspace
= sal
.pspace
;
5451 /* Store the program space that was used to set the breakpoint, for
5452 breakpoint resetting. */
5453 b
->pspace
= sal
.pspace
;
5455 if (sal
.symtab
== NULL
)
5456 b
->source_file
= NULL
;
5458 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5459 b
->loc
->section
= sal
.section
;
5460 b
->line_number
= sal
.line
;
5462 set_breakpoint_location_function (b
->loc
);
5464 breakpoints_changed ();
5470 /* Note that the breakpoint object B describes a permanent breakpoint
5471 instruction, hard-wired into the inferior's code. */
5473 make_breakpoint_permanent (struct breakpoint
*b
)
5475 struct bp_location
*bl
;
5476 b
->enable_state
= bp_permanent
;
5478 /* By definition, permanent breakpoints are already present in the code.
5479 Mark all locations as inserted. For now, make_breakpoint_permanent
5480 is called in just one place, so it's hard to say if it's reasonable
5481 to have permanent breakpoint with multiple locations or not,
5482 but it's easy to implmement. */
5483 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5487 /* Call this routine when stepping and nexting to enable a breakpoint
5488 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5489 set_longjmp_resume_breakpoint() to figure out where we are going. */
5492 set_longjmp_breakpoint (int thread
)
5494 struct breakpoint
*b
, *temp
;
5496 /* To avoid having to rescan all objfile symbols at every step,
5497 we maintain a list of continually-inserted but always disabled
5498 longjmp "master" breakpoints. Here, we simply create momentary
5499 clones of those and enable them for the requested thread. */
5500 ALL_BREAKPOINTS_SAFE (b
, temp
)
5501 if (b
->pspace
== current_program_space
5502 && b
->type
== bp_longjmp_master
)
5504 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5505 clone
->type
= bp_longjmp
;
5506 clone
->thread
= thread
;
5510 /* Delete all longjmp breakpoints from THREAD. */
5512 delete_longjmp_breakpoint (int thread
)
5514 struct breakpoint
*b
, *temp
;
5516 ALL_BREAKPOINTS_SAFE (b
, temp
)
5517 if (b
->type
== bp_longjmp
)
5519 if (b
->thread
== thread
)
5520 delete_breakpoint (b
);
5525 enable_overlay_breakpoints (void)
5527 struct breakpoint
*b
;
5530 if (b
->type
== bp_overlay_event
)
5532 b
->enable_state
= bp_enabled
;
5533 update_global_location_list (1);
5534 overlay_events_enabled
= 1;
5539 disable_overlay_breakpoints (void)
5541 struct breakpoint
*b
;
5544 if (b
->type
== bp_overlay_event
)
5546 b
->enable_state
= bp_disabled
;
5547 update_global_location_list (0);
5548 overlay_events_enabled
= 0;
5552 /* Set an active std::terminate breakpoint for each std::terminate
5553 master breakpoint. */
5555 set_std_terminate_breakpoint (void)
5557 struct breakpoint
*b
, *temp
;
5559 ALL_BREAKPOINTS_SAFE (b
, temp
)
5560 if (b
->pspace
== current_program_space
5561 && b
->type
== bp_std_terminate_master
)
5563 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5564 clone
->type
= bp_std_terminate
;
5568 /* Delete all the std::terminate breakpoints. */
5570 delete_std_terminate_breakpoint (void)
5572 struct breakpoint
*b
, *temp
;
5574 ALL_BREAKPOINTS_SAFE (b
, temp
)
5575 if (b
->type
== bp_std_terminate
)
5576 delete_breakpoint (b
);
5580 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5582 struct breakpoint
*b
;
5584 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5586 b
->enable_state
= bp_enabled
;
5587 /* addr_string has to be used or breakpoint_re_set will delete me. */
5589 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5591 update_global_location_list_nothrow (1);
5597 remove_thread_event_breakpoints (void)
5599 struct breakpoint
*b
, *temp
;
5601 ALL_BREAKPOINTS_SAFE (b
, temp
)
5602 if (b
->type
== bp_thread_event
5603 && b
->loc
->pspace
== current_program_space
)
5604 delete_breakpoint (b
);
5607 struct captured_parse_breakpoint_args
5610 struct symtabs_and_lines
*sals_p
;
5611 char ***addr_string_p
;
5615 struct lang_and_radix
5621 /* Create a breakpoint for JIT code registration and unregistration. */
5624 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5626 struct breakpoint
*b
;
5628 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5629 update_global_location_list_nothrow (1);
5634 remove_solib_event_breakpoints (void)
5636 struct breakpoint
*b
, *temp
;
5638 ALL_BREAKPOINTS_SAFE (b
, temp
)
5639 if (b
->type
== bp_shlib_event
5640 && b
->loc
->pspace
== current_program_space
)
5641 delete_breakpoint (b
);
5645 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5647 struct breakpoint
*b
;
5649 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5650 update_global_location_list_nothrow (1);
5654 /* Disable any breakpoints that are on code in shared libraries. Only
5655 apply to enabled breakpoints, disabled ones can just stay disabled. */
5658 disable_breakpoints_in_shlibs (void)
5660 struct bp_location
*loc
, **locp_tmp
;
5662 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5664 struct breakpoint
*b
= loc
->owner
;
5665 /* We apply the check to all breakpoints, including disabled
5666 for those with loc->duplicate set. This is so that when breakpoint
5667 becomes enabled, or the duplicate is removed, gdb will try to insert
5668 all breakpoints. If we don't set shlib_disabled here, we'll try
5669 to insert those breakpoints and fail. */
5670 if (((b
->type
== bp_breakpoint
)
5671 || (b
->type
== bp_jit_event
)
5672 || (b
->type
== bp_hardware_breakpoint
)
5673 || (tracepoint_type (b
)))
5674 && loc
->pspace
== current_program_space
5675 && !loc
->shlib_disabled
5677 && PC_SOLIB (loc
->address
)
5679 && solib_name_from_address (loc
->pspace
, loc
->address
)
5683 loc
->shlib_disabled
= 1;
5688 /* Disable any breakpoints that are in in an unloaded shared library. Only
5689 apply to enabled breakpoints, disabled ones can just stay disabled. */
5692 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5694 struct bp_location
*loc
, **locp_tmp
;
5695 int disabled_shlib_breaks
= 0;
5697 /* SunOS a.out shared libraries are always mapped, so do not
5698 disable breakpoints; they will only be reported as unloaded
5699 through clear_solib when GDB discards its shared library
5700 list. See clear_solib for more information. */
5701 if (exec_bfd
!= NULL
5702 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5705 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5707 struct breakpoint
*b
= loc
->owner
;
5708 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5709 || loc
->loc_type
== bp_loc_software_breakpoint
)
5710 && solib
->pspace
== loc
->pspace
5711 && !loc
->shlib_disabled
5712 && (b
->type
== bp_breakpoint
5713 || b
->type
== bp_jit_event
5714 || b
->type
== bp_hardware_breakpoint
)
5715 && solib_contains_address_p (solib
, loc
->address
))
5717 loc
->shlib_disabled
= 1;
5718 /* At this point, we cannot rely on remove_breakpoint
5719 succeeding so we must mark the breakpoint as not inserted
5720 to prevent future errors occurring in remove_breakpoints. */
5722 if (!disabled_shlib_breaks
)
5724 target_terminal_ours_for_output ();
5725 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5728 disabled_shlib_breaks
= 1;
5733 /* FORK & VFORK catchpoints. */
5735 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5738 insert_catch_fork (struct breakpoint
*b
)
5740 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5743 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5746 remove_catch_fork (struct breakpoint
*b
)
5748 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5751 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5755 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5757 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5760 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5762 static enum print_stop_action
5763 print_it_catch_fork (struct breakpoint
*b
)
5765 annotate_catchpoint (b
->number
);
5766 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5767 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5768 return PRINT_SRC_AND_LOC
;
5771 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5774 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5776 struct value_print_options opts
;
5778 get_user_print_options (&opts
);
5780 /* Field 4, the address, is omitted (which makes the columns
5781 not line up too nicely with the headers, but the effect
5782 is relatively readable). */
5783 if (opts
.addressprint
)
5784 ui_out_field_skip (uiout
, "addr");
5786 ui_out_text (uiout
, "fork");
5787 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5789 ui_out_text (uiout
, ", process ");
5790 ui_out_field_int (uiout
, "what",
5791 ptid_get_pid (b
->forked_inferior_pid
));
5792 ui_out_spaces (uiout
, 1);
5796 /* Implement the "print_mention" breakpoint_ops method for fork
5800 print_mention_catch_fork (struct breakpoint
*b
)
5802 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5805 /* The breakpoint_ops structure to be used in fork catchpoints. */
5807 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5811 breakpoint_hit_catch_fork
,
5812 print_it_catch_fork
,
5813 print_one_catch_fork
,
5814 print_mention_catch_fork
5817 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5820 insert_catch_vfork (struct breakpoint
*b
)
5822 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5825 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5828 remove_catch_vfork (struct breakpoint
*b
)
5830 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5833 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5837 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5839 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5842 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5844 static enum print_stop_action
5845 print_it_catch_vfork (struct breakpoint
*b
)
5847 annotate_catchpoint (b
->number
);
5848 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5849 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5850 return PRINT_SRC_AND_LOC
;
5853 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5856 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5858 struct value_print_options opts
;
5860 get_user_print_options (&opts
);
5861 /* Field 4, the address, is omitted (which makes the columns
5862 not line up too nicely with the headers, but the effect
5863 is relatively readable). */
5864 if (opts
.addressprint
)
5865 ui_out_field_skip (uiout
, "addr");
5867 ui_out_text (uiout
, "vfork");
5868 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5870 ui_out_text (uiout
, ", process ");
5871 ui_out_field_int (uiout
, "what",
5872 ptid_get_pid (b
->forked_inferior_pid
));
5873 ui_out_spaces (uiout
, 1);
5877 /* Implement the "print_mention" breakpoint_ops method for vfork
5881 print_mention_catch_vfork (struct breakpoint
*b
)
5883 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5886 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5888 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5892 breakpoint_hit_catch_vfork
,
5893 print_it_catch_vfork
,
5894 print_one_catch_vfork
,
5895 print_mention_catch_vfork
5898 /* Implement the "insert" breakpoint_ops method for syscall
5902 insert_catch_syscall (struct breakpoint
*b
)
5904 struct inferior
*inf
= current_inferior ();
5906 ++inf
->total_syscalls_count
;
5907 if (!b
->syscalls_to_be_caught
)
5908 ++inf
->any_syscall_count
;
5913 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5917 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5919 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5920 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5922 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5923 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5925 memset ((void *) vec_addr
, 0,
5926 (iter
+ 1 - old_size
) * sizeof (int));
5928 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5929 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5933 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5934 inf
->total_syscalls_count
!= 0,
5935 inf
->any_syscall_count
,
5936 VEC_length (int, inf
->syscalls_counts
),
5937 VEC_address (int, inf
->syscalls_counts
));
5940 /* Implement the "remove" breakpoint_ops method for syscall
5944 remove_catch_syscall (struct breakpoint
*b
)
5946 struct inferior
*inf
= current_inferior ();
5948 --inf
->total_syscalls_count
;
5949 if (!b
->syscalls_to_be_caught
)
5950 --inf
->any_syscall_count
;
5955 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5959 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5960 /* Shouldn't happen. */
5962 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5963 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5967 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5968 inf
->total_syscalls_count
!= 0,
5969 inf
->any_syscall_count
,
5970 VEC_length (int, inf
->syscalls_counts
),
5971 VEC_address (int, inf
->syscalls_counts
));
5974 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5978 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5980 /* We must check if we are catching specific syscalls in this breakpoint.
5981 If we are, then we must guarantee that the called syscall is the same
5982 syscall we are catching. */
5983 int syscall_number
= 0;
5985 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5988 /* Now, checking if the syscall is the same. */
5989 if (b
->syscalls_to_be_caught
)
5993 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5995 if (syscall_number
== iter
)
6005 /* Implement the "print_it" breakpoint_ops method for syscall
6008 static enum print_stop_action
6009 print_it_catch_syscall (struct breakpoint
*b
)
6011 /* These are needed because we want to know in which state a
6012 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6013 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6014 must print "called syscall" or "returned from syscall". */
6016 struct target_waitstatus last
;
6018 struct cleanup
*old_chain
;
6021 get_last_target_status (&ptid
, &last
);
6023 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6025 annotate_catchpoint (b
->number
);
6028 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6030 syscall_id
= xstrprintf ("'%s'", s
.name
);
6032 old_chain
= make_cleanup (xfree
, syscall_id
);
6034 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6035 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6036 b
->number
, syscall_id
);
6037 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6038 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6039 b
->number
, syscall_id
);
6041 do_cleanups (old_chain
);
6043 return PRINT_SRC_AND_LOC
;
6046 /* Implement the "print_one" breakpoint_ops method for syscall
6050 print_one_catch_syscall (struct breakpoint
*b
,
6051 struct bp_location
**last_loc
)
6053 struct value_print_options opts
;
6055 get_user_print_options (&opts
);
6056 /* Field 4, the address, is omitted (which makes the columns
6057 not line up too nicely with the headers, but the effect
6058 is relatively readable). */
6059 if (opts
.addressprint
)
6060 ui_out_field_skip (uiout
, "addr");
6063 if (b
->syscalls_to_be_caught
6064 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6065 ui_out_text (uiout
, "syscalls \"");
6067 ui_out_text (uiout
, "syscall \"");
6069 if (b
->syscalls_to_be_caught
)
6072 char *text
= xstrprintf ("%s", "");
6074 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6079 get_syscall_by_number (iter
, &s
);
6082 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6084 text
= xstrprintf ("%s%d, ", text
, iter
);
6086 /* We have to xfree the last 'text' (now stored at 'x')
6087 because xstrprintf dinamically allocates new space for it
6091 /* Remove the last comma. */
6092 text
[strlen (text
) - 2] = '\0';
6093 ui_out_field_string (uiout
, "what", text
);
6096 ui_out_field_string (uiout
, "what", "<any syscall>");
6097 ui_out_text (uiout
, "\" ");
6100 /* Implement the "print_mention" breakpoint_ops method for syscall
6104 print_mention_catch_syscall (struct breakpoint
*b
)
6106 if (b
->syscalls_to_be_caught
)
6110 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6111 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6113 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6116 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6120 get_syscall_by_number (iter
, &s
);
6123 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6125 printf_filtered (" %d", s
.number
);
6127 printf_filtered (")");
6130 printf_filtered (_("Catchpoint %d (any syscall)"),
6134 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6136 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6138 insert_catch_syscall
,
6139 remove_catch_syscall
,
6140 breakpoint_hit_catch_syscall
,
6141 print_it_catch_syscall
,
6142 print_one_catch_syscall
,
6143 print_mention_catch_syscall
6146 /* Returns non-zero if 'b' is a syscall catchpoint. */
6149 syscall_catchpoint_p (struct breakpoint
*b
)
6151 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6154 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6155 but does NOT mention it nor update the global location list.
6156 This is useful if you need to fill more fields in the
6157 struct breakpoint before calling mention.
6159 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6160 If COND_STRING is not NULL, then store it in the breakpoint.
6161 OPS, if not NULL, is the breakpoint_ops structure associated
6162 to the catchpoint. */
6164 static struct breakpoint
*
6165 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6167 struct breakpoint_ops
*ops
)
6169 struct symtab_and_line sal
;
6170 struct breakpoint
*b
;
6173 sal
.pspace
= current_program_space
;
6175 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6176 set_breakpoint_count (breakpoint_count
+ 1);
6177 b
->number
= breakpoint_count
;
6179 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6181 b
->addr_string
= NULL
;
6182 b
->enable_state
= bp_enabled
;
6183 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6189 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6191 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6192 If COND_STRING is not NULL, then store it in the breakpoint.
6193 OPS, if not NULL, is the breakpoint_ops structure associated
6194 to the catchpoint. */
6196 static struct breakpoint
*
6197 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6198 char *cond_string
, struct breakpoint_ops
*ops
)
6200 struct breakpoint
*b
=
6201 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6204 update_global_location_list (1);
6210 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6211 int tempflag
, char *cond_string
,
6212 struct breakpoint_ops
*ops
)
6214 struct breakpoint
*b
6215 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6217 /* FIXME: We should put this information in a breakpoint private data
6219 b
->forked_inferior_pid
= null_ptid
;
6222 /* Exec catchpoints. */
6225 insert_catch_exec (struct breakpoint
*b
)
6227 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6231 remove_catch_exec (struct breakpoint
*b
)
6233 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6237 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6239 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6242 static enum print_stop_action
6243 print_it_catch_exec (struct breakpoint
*b
)
6245 annotate_catchpoint (b
->number
);
6246 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6248 return PRINT_SRC_AND_LOC
;
6252 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6254 struct value_print_options opts
;
6256 get_user_print_options (&opts
);
6258 /* Field 4, the address, is omitted (which makes the columns
6259 not line up too nicely with the headers, but the effect
6260 is relatively readable). */
6261 if (opts
.addressprint
)
6262 ui_out_field_skip (uiout
, "addr");
6264 ui_out_text (uiout
, "exec");
6265 if (b
->exec_pathname
!= NULL
)
6267 ui_out_text (uiout
, ", program \"");
6268 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6269 ui_out_text (uiout
, "\" ");
6274 print_mention_catch_exec (struct breakpoint
*b
)
6276 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6279 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6283 breakpoint_hit_catch_exec
,
6284 print_it_catch_exec
,
6285 print_one_catch_exec
,
6286 print_mention_catch_exec
6290 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6291 struct breakpoint_ops
*ops
)
6293 struct gdbarch
*gdbarch
= get_current_arch ();
6294 struct breakpoint
*b
=
6295 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6297 b
->syscalls_to_be_caught
= filter
;
6299 /* Now, we have to mention the breakpoint and update the global
6302 update_global_location_list (1);
6306 hw_breakpoint_used_count (void)
6308 struct breakpoint
*b
;
6313 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6321 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6323 struct breakpoint
*b
;
6326 *other_type_used
= 0;
6329 if (breakpoint_enabled (b
))
6331 if (b
->type
== type
)
6333 else if ((b
->type
== bp_hardware_watchpoint
6334 || b
->type
== bp_read_watchpoint
6335 || b
->type
== bp_access_watchpoint
))
6336 *other_type_used
= 1;
6343 disable_watchpoints_before_interactive_call_start (void)
6345 struct breakpoint
*b
;
6349 if (((b
->type
== bp_watchpoint
)
6350 || (b
->type
== bp_hardware_watchpoint
)
6351 || (b
->type
== bp_read_watchpoint
)
6352 || (b
->type
== bp_access_watchpoint
))
6353 && breakpoint_enabled (b
))
6355 b
->enable_state
= bp_call_disabled
;
6356 update_global_location_list (0);
6362 enable_watchpoints_after_interactive_call_stop (void)
6364 struct breakpoint
*b
;
6368 if (((b
->type
== bp_watchpoint
)
6369 || (b
->type
== bp_hardware_watchpoint
)
6370 || (b
->type
== bp_read_watchpoint
)
6371 || (b
->type
== bp_access_watchpoint
))
6372 && (b
->enable_state
== bp_call_disabled
))
6374 b
->enable_state
= bp_enabled
;
6375 update_global_location_list (1);
6381 disable_breakpoints_before_startup (void)
6383 struct breakpoint
*b
;
6388 if (b
->pspace
!= current_program_space
)
6391 if ((b
->type
== bp_breakpoint
6392 || b
->type
== bp_hardware_breakpoint
)
6393 && breakpoint_enabled (b
))
6395 b
->enable_state
= bp_startup_disabled
;
6401 update_global_location_list (0);
6403 current_program_space
->executing_startup
= 1;
6407 enable_breakpoints_after_startup (void)
6409 struct breakpoint
*b
;
6412 current_program_space
->executing_startup
= 0;
6416 if (b
->pspace
!= current_program_space
)
6419 if ((b
->type
== bp_breakpoint
6420 || b
->type
== bp_hardware_breakpoint
)
6421 && b
->enable_state
== bp_startup_disabled
)
6423 b
->enable_state
= bp_enabled
;
6429 breakpoint_re_set ();
6433 /* Set a breakpoint that will evaporate an end of command
6434 at address specified by SAL.
6435 Restrict it to frame FRAME if FRAME is nonzero. */
6438 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6439 struct frame_id frame_id
, enum bptype type
)
6441 struct breakpoint
*b
;
6443 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6445 gdb_assert (!frame_id_inlined_p (frame_id
));
6447 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6448 b
->enable_state
= bp_enabled
;
6449 b
->disposition
= disp_donttouch
;
6450 b
->frame_id
= frame_id
;
6452 /* If we're debugging a multi-threaded program, then we
6453 want momentary breakpoints to be active in only a
6454 single thread of control. */
6455 if (in_thread_list (inferior_ptid
))
6456 b
->thread
= pid_to_thread_id (inferior_ptid
);
6458 update_global_location_list_nothrow (1);
6463 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6467 clone_momentary_breakpoint (struct breakpoint
*orig
)
6469 struct breakpoint
*copy
;
6471 /* If there's nothing to clone, then return nothing. */
6475 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6476 copy
->loc
= allocate_bp_location (copy
);
6477 set_breakpoint_location_function (copy
->loc
);
6479 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6480 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6481 copy
->loc
->address
= orig
->loc
->address
;
6482 copy
->loc
->section
= orig
->loc
->section
;
6483 copy
->loc
->pspace
= orig
->loc
->pspace
;
6485 if (orig
->source_file
== NULL
)
6486 copy
->source_file
= NULL
;
6488 copy
->source_file
= xstrdup (orig
->source_file
);
6490 copy
->line_number
= orig
->line_number
;
6491 copy
->frame_id
= orig
->frame_id
;
6492 copy
->thread
= orig
->thread
;
6493 copy
->pspace
= orig
->pspace
;
6495 copy
->enable_state
= bp_enabled
;
6496 copy
->disposition
= disp_donttouch
;
6497 copy
->number
= internal_breakpoint_number
--;
6499 update_global_location_list_nothrow (0);
6504 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6507 struct symtab_and_line sal
;
6509 sal
= find_pc_line (pc
, 0);
6511 sal
.section
= find_pc_overlay (pc
);
6512 sal
.explicit_pc
= 1;
6514 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6518 /* Tell the user we have just set a breakpoint B. */
6521 mention (struct breakpoint
*b
)
6524 struct cleanup
*ui_out_chain
;
6525 struct value_print_options opts
;
6527 get_user_print_options (&opts
);
6529 /* FIXME: This is misplaced; mention() is called by things (like
6530 hitting a watchpoint) other than breakpoint creation. It should
6531 be possible to clean this up and at the same time replace the
6532 random calls to breakpoint_changed with this hook. */
6533 observer_notify_breakpoint_created (b
->number
);
6535 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6536 b
->ops
->print_mention (b
);
6541 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6544 ui_out_text (uiout
, "Watchpoint ");
6545 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6546 ui_out_field_int (uiout
, "number", b
->number
);
6547 ui_out_text (uiout
, ": ");
6548 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6549 do_cleanups (ui_out_chain
);
6551 case bp_hardware_watchpoint
:
6552 ui_out_text (uiout
, "Hardware watchpoint ");
6553 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6554 ui_out_field_int (uiout
, "number", b
->number
);
6555 ui_out_text (uiout
, ": ");
6556 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6557 do_cleanups (ui_out_chain
);
6559 case bp_read_watchpoint
:
6560 ui_out_text (uiout
, "Hardware read watchpoint ");
6561 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6562 ui_out_field_int (uiout
, "number", b
->number
);
6563 ui_out_text (uiout
, ": ");
6564 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6565 do_cleanups (ui_out_chain
);
6567 case bp_access_watchpoint
:
6568 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6569 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6570 ui_out_field_int (uiout
, "number", b
->number
);
6571 ui_out_text (uiout
, ": ");
6572 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6573 do_cleanups (ui_out_chain
);
6576 if (ui_out_is_mi_like_p (uiout
))
6581 if (b
->disposition
== disp_del
)
6582 printf_filtered (_("Temporary breakpoint"));
6584 printf_filtered (_("Breakpoint"));
6585 printf_filtered (_(" %d"), b
->number
);
6588 case bp_hardware_breakpoint
:
6589 if (ui_out_is_mi_like_p (uiout
))
6594 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6598 if (ui_out_is_mi_like_p (uiout
))
6603 printf_filtered (_("Tracepoint"));
6604 printf_filtered (_(" %d"), b
->number
);
6607 case bp_fast_tracepoint
:
6608 if (ui_out_is_mi_like_p (uiout
))
6613 printf_filtered (_("Fast tracepoint"));
6614 printf_filtered (_(" %d"), b
->number
);
6621 case bp_longjmp_resume
:
6622 case bp_step_resume
:
6624 case bp_std_terminate
:
6625 case bp_watchpoint_scope
:
6626 case bp_shlib_event
:
6627 case bp_thread_event
:
6628 case bp_overlay_event
:
6630 case bp_longjmp_master
:
6631 case bp_std_terminate_master
:
6637 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6641 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6645 if (opts
.addressprint
|| b
->source_file
== NULL
)
6647 printf_filtered (" at ");
6648 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6652 printf_filtered (": file %s, line %d.",
6653 b
->source_file
, b
->line_number
);
6657 struct bp_location
*loc
= b
->loc
;
6659 for (; loc
; loc
= loc
->next
)
6661 printf_filtered (" (%d locations)", n
);
6666 if (ui_out_is_mi_like_p (uiout
))
6668 printf_filtered ("\n");
6672 static struct bp_location
*
6673 add_location_to_breakpoint (struct breakpoint
*b
,
6674 const struct symtab_and_line
*sal
)
6676 struct bp_location
*loc
, **tmp
;
6678 loc
= allocate_bp_location (b
);
6679 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6682 loc
->gdbarch
= get_sal_arch (*sal
);
6684 loc
->gdbarch
= b
->gdbarch
;
6685 loc
->requested_address
= sal
->pc
;
6686 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6687 loc
->requested_address
, b
->type
);
6688 loc
->pspace
= sal
->pspace
;
6689 gdb_assert (loc
->pspace
!= NULL
);
6690 loc
->section
= sal
->section
;
6692 set_breakpoint_location_function (loc
);
6697 /* Return 1 if LOC is pointing to a permanent breakpoint,
6698 return 0 otherwise. */
6701 bp_loc_is_permanent (struct bp_location
*loc
)
6705 const gdb_byte
*brk
;
6706 gdb_byte
*target_mem
;
6707 struct cleanup
*cleanup
;
6710 gdb_assert (loc
!= NULL
);
6712 addr
= loc
->address
;
6713 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6715 /* Software breakpoints unsupported? */
6719 target_mem
= alloca (len
);
6721 /* Enable the automatic memory restoration from breakpoints while
6722 we read the memory. Otherwise we could say about our temporary
6723 breakpoints they are permanent. */
6724 cleanup
= save_current_space_and_thread ();
6726 switch_to_program_space_and_thread (loc
->pspace
);
6727 make_show_memory_breakpoints_cleanup (0);
6729 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6730 && memcmp (target_mem
, brk
, len
) == 0)
6733 do_cleanups (cleanup
);
6740 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6741 as textual description of the location, and COND_STRING
6742 as condition expression. */
6745 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6746 struct symtabs_and_lines sals
, char *addr_string
,
6748 enum bptype type
, enum bpdisp disposition
,
6749 int thread
, int task
, int ignore_count
,
6750 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6752 struct breakpoint
*b
= NULL
;
6755 if (type
== bp_hardware_breakpoint
)
6757 int i
= hw_breakpoint_used_count ();
6758 int target_resources_ok
=
6759 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6761 if (target_resources_ok
== 0)
6762 error (_("No hardware breakpoint support in the target."));
6763 else if (target_resources_ok
< 0)
6764 error (_("Hardware breakpoints used exceeds limit."));
6767 gdb_assert (sals
.nelts
> 0);
6769 for (i
= 0; i
< sals
.nelts
; ++i
)
6771 struct symtab_and_line sal
= sals
.sals
[i
];
6772 struct bp_location
*loc
;
6776 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6778 loc_gdbarch
= gdbarch
;
6780 describe_other_breakpoints (loc_gdbarch
,
6781 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6786 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6787 set_breakpoint_count (breakpoint_count
+ 1);
6788 b
->number
= breakpoint_count
;
6792 b
->cond_string
= cond_string
;
6793 b
->ignore_count
= ignore_count
;
6794 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6795 b
->disposition
= disposition
;
6797 b
->pspace
= sals
.sals
[0].pspace
;
6799 if (enabled
&& b
->pspace
->executing_startup
6800 && (b
->type
== bp_breakpoint
6801 || b
->type
== bp_hardware_breakpoint
))
6802 b
->enable_state
= bp_startup_disabled
;
6808 loc
= add_location_to_breakpoint (b
, &sal
);
6811 if (bp_loc_is_permanent (loc
))
6812 make_breakpoint_permanent (b
);
6816 char *arg
= b
->cond_string
;
6817 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6819 error (_("Garbage %s follows condition"), arg
);
6824 b
->addr_string
= addr_string
;
6826 /* addr_string has to be used or breakpoint_re_set will delete
6829 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6835 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6836 elements to fill the void space. */
6838 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6840 int i
= index_to_remove
+1;
6841 int last_index
= sal
->nelts
-1;
6843 for (;i
<= last_index
; ++i
)
6844 sal
->sals
[i
-1] = sal
->sals
[i
];
6849 /* If appropriate, obtains all sals that correspond to the same file
6850 and line as SAL, in all program spaces. Users debugging with IDEs,
6851 will want to set a breakpoint at foo.c:line, and not really care
6852 about program spaces. This is done only if SAL does not have
6853 explicit PC and has line and file information. If we got just a
6854 single expanded sal, return the original.
6856 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6857 which the name of enclosing function is different from SAL. This
6858 makes sure that if we have breakpoint originally set in template
6859 instantiation, say foo<int>(), we won't expand SAL to locations at
6860 the same line in all existing instantiations of 'foo'. */
6862 static struct symtabs_and_lines
6863 expand_line_sal_maybe (struct symtab_and_line sal
)
6865 struct symtabs_and_lines expanded
;
6866 CORE_ADDR original_pc
= sal
.pc
;
6867 char *original_function
= NULL
;
6870 struct cleanup
*old_chain
;
6872 /* If we have explicit pc, don't expand.
6873 If we have no line number, we can't expand. */
6874 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6877 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6878 expanded
.sals
[0] = sal
;
6884 old_chain
= save_current_space_and_thread ();
6886 switch_to_program_space_and_thread (sal
.pspace
);
6888 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6890 /* Note that expand_line_sal visits *all* program spaces. */
6891 expanded
= expand_line_sal (sal
);
6893 if (expanded
.nelts
== 1)
6895 /* We had one sal, we got one sal. Return that sal, adjusting it
6896 past the function prologue if necessary. */
6897 xfree (expanded
.sals
);
6899 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6900 sal
.pc
= original_pc
;
6901 expanded
.sals
[0] = sal
;
6902 skip_prologue_sal (&expanded
.sals
[0]);
6903 do_cleanups (old_chain
);
6907 if (!sal
.explicit_line
)
6909 CORE_ADDR func_addr
, func_end
;
6910 for (i
= 0; i
< expanded
.nelts
; ++i
)
6912 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6913 char *this_function
;
6915 /* We need to switch threads as well since we're about to
6917 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6919 if (find_pc_partial_function (pc
, &this_function
,
6920 &func_addr
, &func_end
))
6923 && strcmp (this_function
, original_function
) != 0)
6925 remove_sal (&expanded
, i
);
6928 else if (func_addr
== pc
)
6930 /* We're at beginning of a function, and should
6932 struct symbol
*sym
= find_pc_function (pc
);
6934 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
6937 /* Since find_pc_partial_function returned true,
6938 we should really always find the section here. */
6939 struct obj_section
*section
= find_pc_section (pc
);
6942 struct gdbarch
*gdbarch
6943 = get_objfile_arch (section
->objfile
);
6945 = gdbarch_skip_prologue (gdbarch
, pc
);
6954 for (i
= 0; i
< expanded
.nelts
; ++i
)
6956 /* If this SAL corresponds to a breakpoint inserted using a
6957 line number, then skip the function prologue if necessary. */
6958 skip_prologue_sal (&expanded
.sals
[i
]);
6962 do_cleanups (old_chain
);
6964 if (expanded
.nelts
<= 1)
6966 /* This is un ugly workaround. If we get zero
6967 expanded sals then something is really wrong.
6968 Fix that by returnign the original sal. */
6969 xfree (expanded
.sals
);
6971 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6972 sal
.pc
= original_pc
;
6973 expanded
.sals
[0] = sal
;
6980 for (i
= 0; i
< expanded
.nelts
; ++i
)
6981 if (expanded
.sals
[i
].pc
== original_pc
)
6992 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6993 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6994 value. COND_STRING, if not NULL, specified the condition to be
6995 used for all breakpoints. Essentially the only case where
6996 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6997 function. In that case, it's still not possible to specify
6998 separate conditions for different overloaded functions, so
6999 we take just a single condition string.
7001 NOTE: If the function succeeds, the caller is expected to cleanup
7002 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7003 array contents). If the function fails (error() is called), the
7004 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7005 COND and SALS arrays and each of those arrays contents. */
7008 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7009 struct symtabs_and_lines sals
, char **addr_string
,
7011 enum bptype type
, enum bpdisp disposition
,
7012 int thread
, int task
, int ignore_count
,
7013 struct breakpoint_ops
*ops
, int from_tty
,
7017 for (i
= 0; i
< sals
.nelts
; ++i
)
7019 struct symtabs_and_lines expanded
=
7020 expand_line_sal_maybe (sals
.sals
[i
]);
7022 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7023 cond_string
, type
, disposition
,
7024 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
7028 /* Parse ARG which is assumed to be a SAL specification possibly
7029 followed by conditionals. On return, SALS contains an array of SAL
7030 addresses found. ADDR_STRING contains a vector of (canonical)
7031 address strings. ARG points to the end of the SAL. */
7034 parse_breakpoint_sals (char **address
,
7035 struct symtabs_and_lines
*sals
,
7036 char ***addr_string
,
7039 char *addr_start
= *address
;
7040 *addr_string
= NULL
;
7041 /* If no arg given, or if first arg is 'if ', use the default
7043 if ((*address
) == NULL
7044 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7046 if (default_breakpoint_valid
)
7048 struct symtab_and_line sal
;
7049 init_sal (&sal
); /* initialize to zeroes */
7050 sals
->sals
= (struct symtab_and_line
*)
7051 xmalloc (sizeof (struct symtab_and_line
));
7052 sal
.pc
= default_breakpoint_address
;
7053 sal
.line
= default_breakpoint_line
;
7054 sal
.symtab
= default_breakpoint_symtab
;
7055 sal
.pspace
= default_breakpoint_pspace
;
7056 sal
.section
= find_pc_overlay (sal
.pc
);
7058 /* "break" without arguments is equivalent to "break *PC" where PC is
7059 the default_breakpoint_address. So make sure to set
7060 sal.explicit_pc to prevent GDB from trying to expand the list of
7061 sals to include all other instances with the same symtab and line.
7063 sal
.explicit_pc
= 1;
7065 sals
->sals
[0] = sal
;
7069 error (_("No default breakpoint address now."));
7073 /* Force almost all breakpoints to be in terms of the
7074 current_source_symtab (which is decode_line_1's default). This
7075 should produce the results we want almost all of the time while
7076 leaving default_breakpoint_* alone.
7077 ObjC: However, don't match an Objective-C method name which
7078 may have a '+' or '-' succeeded by a '[' */
7080 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7082 if (default_breakpoint_valid
7084 || ((strchr ("+-", (*address
)[0]) != NULL
)
7085 && ((*address
)[1] != '['))))
7086 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7087 default_breakpoint_line
, addr_string
,
7090 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7091 addr_string
, not_found_ptr
);
7093 /* For any SAL that didn't have a canonical string, fill one in. */
7094 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7095 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7096 if (addr_start
!= (*address
))
7099 for (i
= 0; i
< sals
->nelts
; i
++)
7101 /* Add the string if not present. */
7102 if ((*addr_string
)[i
] == NULL
)
7103 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7109 /* Convert each SAL into a real PC. Verify that the PC can be
7110 inserted as a breakpoint. If it can't throw an error. */
7113 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7117 for (i
= 0; i
< sals
->nelts
; i
++)
7118 resolve_sal_pc (&sals
->sals
[i
]);
7121 /* Fast tracepoints may have restrictions on valid locations. For
7122 instance, a fast tracepoint using a jump instead of a trap will
7123 likely have to overwrite more bytes than a trap would, and so can
7124 only be placed where the instruction is longer than the jump, or a
7125 multi-instruction sequence does not have a jump into the middle of
7129 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7130 struct symtabs_and_lines
*sals
)
7133 struct symtab_and_line
*sal
;
7135 struct cleanup
*old_chain
;
7137 for (i
= 0; i
< sals
->nelts
; i
++)
7139 sal
= &sals
->sals
[i
];
7141 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7143 old_chain
= make_cleanup (xfree
, msg
);
7146 error (_("May not have a fast tracepoint at 0x%s%s"),
7147 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7149 do_cleanups (old_chain
);
7154 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7156 struct captured_parse_breakpoint_args
*args
= data
;
7158 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7159 args
->not_found_ptr
);
7162 /* Given TOK, a string specification of condition and thread, as
7163 accepted by the 'break' command, extract the condition
7164 string and thread number and set *COND_STRING and *THREAD.
7165 PC identifies the context at which the condition should be parsed.
7166 If no condition is found, *COND_STRING is set to NULL.
7167 If no thread is found, *THREAD is set to -1. */
7169 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7170 char **cond_string
, int *thread
, int *task
)
7172 *cond_string
= NULL
;
7178 char *cond_start
= NULL
;
7179 char *cond_end
= NULL
;
7180 while (*tok
== ' ' || *tok
== '\t')
7185 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7188 toklen
= end_tok
- tok
;
7190 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7192 struct expression
*expr
;
7194 tok
= cond_start
= end_tok
+ 1;
7195 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7198 *cond_string
= savestring (cond_start
,
7199 cond_end
- cond_start
);
7201 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7207 *thread
= strtol (tok
, &tok
, 0);
7209 error (_("Junk after thread keyword."));
7210 if (!valid_thread_id (*thread
))
7211 error (_("Unknown thread %d."), *thread
);
7213 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7219 *task
= strtol (tok
, &tok
, 0);
7221 error (_("Junk after task keyword."));
7222 if (!valid_task_id (*task
))
7223 error (_("Unknown task %d."), *task
);
7226 error (_("Junk at end of arguments."));
7230 /* Set a breakpoint. This function is shared between CLI and MI
7231 functions for setting a breakpoint. This function has two major
7232 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7233 parameter. If non-zero, the function will parse arg, extracting
7234 breakpoint location, address and thread. Otherwise, ARG is just the
7235 location of breakpoint, with condition and thread specified by the
7236 COND_STRING and THREAD parameters. Returns true if any breakpoint
7237 was created; false otherwise. */
7240 create_breakpoint (struct gdbarch
*gdbarch
,
7241 char *arg
, char *cond_string
, int thread
,
7242 int parse_condition_and_thread
,
7243 int tempflag
, int hardwareflag
, int traceflag
,
7245 enum auto_boolean pending_break_support
,
7246 struct breakpoint_ops
*ops
,
7250 struct gdb_exception e
;
7251 struct symtabs_and_lines sals
;
7252 struct symtab_and_line pending_sal
;
7255 char *addr_start
= arg
;
7257 struct cleanup
*old_chain
;
7258 struct cleanup
*bkpt_chain
= NULL
;
7259 struct captured_parse_breakpoint_args parse_args
;
7263 enum bptype type_wanted
;
7265 int first_bp_set
= breakpoint_count
+ 1;
7271 parse_args
.arg_p
= &arg
;
7272 parse_args
.sals_p
= &sals
;
7273 parse_args
.addr_string_p
= &addr_string
;
7274 parse_args
.not_found_ptr
= ¬_found
;
7276 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7277 &parse_args
, RETURN_MASK_ALL
);
7279 /* If caller is interested in rc value from parse, set value. */
7283 throw_exception (e
);
7287 case NOT_FOUND_ERROR
:
7289 /* If pending breakpoint support is turned off, throw
7292 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7293 throw_exception (e
);
7295 exception_print (gdb_stderr
, e
);
7297 /* If pending breakpoint support is auto query and the user
7298 selects no, then simply return the error code. */
7299 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7300 && !nquery ("Make breakpoint pending on future shared library load? "))
7303 /* At this point, either the user was queried about setting
7304 a pending breakpoint and selected yes, or pending
7305 breakpoint behavior is on and thus a pending breakpoint
7306 is defaulted on behalf of the user. */
7307 copy_arg
= xstrdup (addr_start
);
7308 addr_string
= ©_arg
;
7310 sals
.sals
= &pending_sal
;
7315 throw_exception (e
);
7322 /* Create a chain of things that always need to be cleaned up. */
7323 old_chain
= make_cleanup (null_cleanup
, 0);
7327 /* Make sure that all storage allocated to SALS gets freed. */
7328 make_cleanup (xfree
, sals
.sals
);
7330 /* Cleanup the addr_string array but not its contents. */
7331 make_cleanup (xfree
, addr_string
);
7334 /* ----------------------------- SNIP -----------------------------
7335 Anything added to the cleanup chain beyond this point is assumed
7336 to be part of a breakpoint. If the breakpoint create succeeds
7337 then the memory is not reclaimed. */
7338 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7340 /* Mark the contents of the addr_string for cleanup. These go on
7341 the bkpt_chain and only occur if the breakpoint create fails. */
7342 for (i
= 0; i
< sals
.nelts
; i
++)
7344 if (addr_string
[i
] != NULL
)
7345 make_cleanup (xfree
, addr_string
[i
]);
7348 /* Resolve all line numbers to PC's and verify that the addresses
7349 are ok for the target. */
7351 breakpoint_sals_to_pc (&sals
, addr_start
);
7353 type_wanted
= (traceflag
7354 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7355 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7357 /* Fast tracepoints may have additional restrictions on location. */
7358 if (type_wanted
== bp_fast_tracepoint
)
7359 check_fast_tracepoint_sals (gdbarch
, &sals
);
7361 /* Verify that condition can be parsed, before setting any
7362 breakpoints. Allocate a separate condition expression for each
7366 if (parse_condition_and_thread
)
7368 /* Here we only parse 'arg' to separate condition
7369 from thread number, so parsing in context of first
7370 sal is OK. When setting the breakpoint we'll
7371 re-parse it in context of each sal. */
7374 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7377 make_cleanup (xfree
, cond_string
);
7381 /* Create a private copy of condition string. */
7384 cond_string
= xstrdup (cond_string
);
7385 make_cleanup (xfree
, cond_string
);
7388 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7389 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7390 thread
, task
, ignore_count
, ops
, from_tty
,
7395 struct symtab_and_line sal
= {0};
7396 struct breakpoint
*b
;
7398 make_cleanup (xfree
, copy_arg
);
7400 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7401 set_breakpoint_count (breakpoint_count
+ 1);
7402 b
->number
= breakpoint_count
;
7404 b
->addr_string
= addr_string
[0];
7405 b
->cond_string
= NULL
;
7406 b
->ignore_count
= ignore_count
;
7407 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7408 b
->condition_not_parsed
= 1;
7410 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7411 b
->pspace
= current_program_space
;
7413 if (enabled
&& b
->pspace
->executing_startup
7414 && (b
->type
== bp_breakpoint
7415 || b
->type
== bp_hardware_breakpoint
))
7416 b
->enable_state
= bp_startup_disabled
;
7423 warning (_("Multiple breakpoints were set.\n"
7424 "Use the \"delete\" command to delete unwanted breakpoints."));
7425 multi_start
= first_bp_set
;
7426 multi_end
= breakpoint_count
;
7430 /* That's it. Discard the cleanups for data inserted into the
7432 discard_cleanups (bkpt_chain
);
7433 /* But cleanup everything else. */
7434 do_cleanups (old_chain
);
7436 /* error call may happen here - have BKPT_CHAIN already discarded. */
7437 update_global_location_list (1);
7442 /* Set a breakpoint.
7443 ARG is a string describing breakpoint address,
7444 condition, and thread.
7445 FLAG specifies if a breakpoint is hardware on,
7446 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7450 break_command_1 (char *arg
, int flag
, int from_tty
)
7452 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7453 int tempflag
= flag
& BP_TEMPFLAG
;
7455 create_breakpoint (get_current_arch (),
7457 NULL
, 0, 1 /* parse arg */,
7458 tempflag
, hardwareflag
, 0 /* traceflag */,
7459 0 /* Ignore count */,
7460 pending_break_support
,
7461 NULL
/* breakpoint_ops */,
7468 /* Adjust SAL to the first instruction past the function prologue.
7469 The end of the prologue is determined using the line table from
7470 the debugging information. explicit_pc and explicit_line are
7473 If SAL is already past the prologue, then do nothing. */
7476 skip_prologue_sal (struct symtab_and_line
*sal
)
7479 struct symtab_and_line start_sal
;
7480 struct cleanup
*old_chain
;
7482 old_chain
= save_current_space_and_thread ();
7484 sym
= find_pc_function (sal
->pc
);
7487 start_sal
= find_function_start_sal (sym
, 1);
7488 if (sal
->pc
< start_sal
.pc
)
7490 start_sal
.explicit_line
= sal
->explicit_line
;
7491 start_sal
.explicit_pc
= sal
->explicit_pc
;
7496 do_cleanups (old_chain
);
7499 /* Helper function for break_command_1 and disassemble_command. */
7502 resolve_sal_pc (struct symtab_and_line
*sal
)
7506 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7508 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7509 error (_("No line %d in file \"%s\"."),
7510 sal
->line
, sal
->symtab
->filename
);
7513 /* If this SAL corresponds to a breakpoint inserted using
7514 a line number, then skip the function prologue if necessary. */
7515 if (sal
->explicit_line
)
7517 /* Preserve the original line number. */
7518 int saved_line
= sal
->line
;
7519 skip_prologue_sal (sal
);
7520 sal
->line
= saved_line
;
7524 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7526 struct blockvector
*bv
;
7530 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7533 sym
= block_linkage_function (b
);
7536 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7537 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7541 /* It really is worthwhile to have the section, so we'll just
7542 have to look harder. This case can be executed if we have
7543 line numbers but no functions (as can happen in assembly
7546 struct minimal_symbol
*msym
;
7547 struct cleanup
*old_chain
= save_current_space_and_thread ();
7549 switch_to_program_space_and_thread (sal
->pspace
);
7551 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7553 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7555 do_cleanups (old_chain
);
7562 break_command (char *arg
, int from_tty
)
7564 break_command_1 (arg
, 0, from_tty
);
7568 tbreak_command (char *arg
, int from_tty
)
7570 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7574 hbreak_command (char *arg
, int from_tty
)
7576 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7580 thbreak_command (char *arg
, int from_tty
)
7582 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7586 stop_command (char *arg
, int from_tty
)
7588 printf_filtered (_("Specify the type of breakpoint to set.\n\
7589 Usage: stop in <function | address>\n\
7590 stop at <line>\n"));
7594 stopin_command (char *arg
, int from_tty
)
7598 if (arg
== (char *) NULL
)
7600 else if (*arg
!= '*')
7605 /* look for a ':'. If this is a line number specification, then
7606 say it is bad, otherwise, it should be an address or
7607 function/method name */
7608 while (*argptr
&& !hasColon
)
7610 hasColon
= (*argptr
== ':');
7615 badInput
= (*argptr
!= ':'); /* Not a class::method */
7617 badInput
= isdigit (*arg
); /* a simple line number */
7621 printf_filtered (_("Usage: stop in <function | address>\n"));
7623 break_command_1 (arg
, 0, from_tty
);
7627 stopat_command (char *arg
, int from_tty
)
7631 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7638 /* look for a ':'. If there is a '::' then get out, otherwise
7639 it is probably a line number. */
7640 while (*argptr
&& !hasColon
)
7642 hasColon
= (*argptr
== ':');
7647 badInput
= (*argptr
== ':'); /* we have class::method */
7649 badInput
= !isdigit (*arg
); /* not a line number */
7653 printf_filtered (_("Usage: stop at <line>\n"));
7655 break_command_1 (arg
, 0, from_tty
);
7658 /* accessflag: hw_write: watch write,
7659 hw_read: watch read,
7660 hw_access: watch access (read or write) */
7662 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7664 struct gdbarch
*gdbarch
= get_current_arch ();
7665 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7666 struct expression
*exp
;
7667 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7668 struct value
*val
, *mark
;
7669 struct frame_info
*frame
;
7670 char *exp_start
= NULL
;
7671 char *exp_end
= NULL
;
7672 char *tok
, *id_tok_start
, *end_tok
;
7674 char *cond_start
= NULL
;
7675 char *cond_end
= NULL
;
7676 int i
, other_type_used
, target_resources_ok
= 0;
7677 enum bptype bp_type
;
7681 /* Make sure that we actually have parameters to parse. */
7682 if (arg
!= NULL
&& arg
[0] != '\0')
7684 toklen
= strlen (arg
); /* Size of argument list. */
7686 /* Points tok to the end of the argument list. */
7687 tok
= arg
+ toklen
- 1;
7689 /* Go backwards in the parameters list. Skip the last parameter.
7690 If we're expecting a 'thread <thread_num>' parameter, this should
7691 be the thread identifier. */
7692 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7694 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7697 /* Points end_tok to the beginning of the last token. */
7698 id_tok_start
= tok
+ 1;
7700 /* Go backwards in the parameters list. Skip one more parameter.
7701 If we're expecting a 'thread <thread_num>' parameter, we should
7702 reach a "thread" token. */
7703 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7708 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7711 /* Move the pointer forward to skip the whitespace and
7712 calculate the length of the token. */
7714 toklen
= end_tok
- tok
;
7716 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7718 /* At this point we've found a "thread" token, which means
7719 the user is trying to set a watchpoint that triggers
7720 only in a specific thread. */
7723 /* Extract the thread ID from the next token. */
7724 thread
= strtol (id_tok_start
, &endp
, 0);
7726 /* Check if the user provided a valid numeric value for the
7728 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7729 error (_("Invalid thread ID specification %s."), id_tok_start
);
7731 /* Check if the thread actually exists. */
7732 if (!valid_thread_id (thread
))
7733 error (_("Unknown thread %d."), thread
);
7735 /* Truncate the string and get rid of the thread <thread_num>
7736 parameter before the parameter list is parsed by the
7737 evaluate_expression() function. */
7742 /* Parse the rest of the arguments. */
7743 innermost_block
= NULL
;
7745 exp
= parse_exp_1 (&arg
, 0, 0);
7747 /* Remove trailing whitespace from the expression before saving it.
7748 This makes the eventual display of the expression string a bit
7750 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7753 exp_valid_block
= innermost_block
;
7754 mark
= value_mark ();
7755 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7757 release_value (val
);
7760 while (*tok
== ' ' || *tok
== '\t')
7764 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7767 toklen
= end_tok
- tok
;
7768 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7770 struct expression
*cond
;
7772 innermost_block
= NULL
;
7773 tok
= cond_start
= end_tok
+ 1;
7774 cond
= parse_exp_1 (&tok
, 0, 0);
7776 /* The watchpoint expression may not be local, but the condition
7777 may still be. E.g.: `watch global if local > 0'. */
7778 cond_exp_valid_block
= innermost_block
;
7784 error (_("Junk at end of command."));
7786 if (accessflag
== hw_read
)
7787 bp_type
= bp_read_watchpoint
;
7788 else if (accessflag
== hw_access
)
7789 bp_type
= bp_access_watchpoint
;
7791 bp_type
= bp_hardware_watchpoint
;
7793 mem_cnt
= can_use_hardware_watchpoint (val
);
7794 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7795 error (_("Expression cannot be implemented with read/access watchpoint."));
7798 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7799 target_resources_ok
=
7800 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7802 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7803 error (_("Target does not support this type of hardware watchpoint."));
7805 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7806 error (_("Target can only support one kind of HW watchpoint at a time."));
7809 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7810 watchpoint could not be set. */
7811 if (!mem_cnt
|| target_resources_ok
<= 0)
7812 bp_type
= bp_watchpoint
;
7814 frame
= block_innermost_frame (exp_valid_block
);
7816 /* If the expression is "local", then set up a "watchpoint scope"
7817 breakpoint at the point where we've left the scope of the watchpoint
7818 expression. Create the scope breakpoint before the watchpoint, so
7819 that we will encounter it first in bpstat_stop_status. */
7820 if (exp_valid_block
&& frame
)
7822 if (frame_id_p (frame_unwind_caller_id (frame
)))
7825 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7826 frame_unwind_caller_pc (frame
),
7827 bp_watchpoint_scope
);
7829 scope_breakpoint
->enable_state
= bp_enabled
;
7831 /* Automatically delete the breakpoint when it hits. */
7832 scope_breakpoint
->disposition
= disp_del
;
7834 /* Only break in the proper frame (help with recursion). */
7835 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7837 /* Set the address at which we will stop. */
7838 scope_breakpoint
->loc
->gdbarch
7839 = frame_unwind_caller_arch (frame
);
7840 scope_breakpoint
->loc
->requested_address
7841 = frame_unwind_caller_pc (frame
);
7842 scope_breakpoint
->loc
->address
7843 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7844 scope_breakpoint
->loc
->requested_address
,
7845 scope_breakpoint
->type
);
7849 /* Now set up the breakpoint. */
7850 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7851 set_breakpoint_count (breakpoint_count
+ 1);
7852 b
->number
= breakpoint_count
;
7854 b
->disposition
= disp_donttouch
;
7856 b
->exp_valid_block
= exp_valid_block
;
7857 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7858 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7862 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7868 b
->watchpoint_frame
= get_frame_id (frame
);
7869 b
->watchpoint_thread
= inferior_ptid
;
7873 b
->watchpoint_frame
= null_frame_id
;
7874 b
->watchpoint_thread
= null_ptid
;
7877 if (scope_breakpoint
!= NULL
)
7879 /* The scope breakpoint is related to the watchpoint. We will
7880 need to act on them together. */
7881 b
->related_breakpoint
= scope_breakpoint
;
7882 scope_breakpoint
->related_breakpoint
= b
;
7885 value_free_to_mark (mark
);
7887 /* Finally update the new watchpoint. This creates the locations
7888 that should be inserted. */
7889 update_watchpoint (b
, 1);
7892 update_global_location_list (1);
7895 /* Return count of locations need to be watched and can be handled
7896 in hardware. If the watchpoint can not be handled
7897 in hardware return zero. */
7900 can_use_hardware_watchpoint (struct value
*v
)
7902 int found_memory_cnt
= 0;
7903 struct value
*head
= v
;
7905 /* Did the user specifically forbid us to use hardware watchpoints? */
7906 if (!can_use_hw_watchpoints
)
7909 /* Make sure that the value of the expression depends only upon
7910 memory contents, and values computed from them within GDB. If we
7911 find any register references or function calls, we can't use a
7912 hardware watchpoint.
7914 The idea here is that evaluating an expression generates a series
7915 of values, one holding the value of every subexpression. (The
7916 expression a*b+c has five subexpressions: a, b, a*b, c, and
7917 a*b+c.) GDB's values hold almost enough information to establish
7918 the criteria given above --- they identify memory lvalues,
7919 register lvalues, computed values, etcetera. So we can evaluate
7920 the expression, and then scan the chain of values that leaves
7921 behind to decide whether we can detect any possible change to the
7922 expression's final value using only hardware watchpoints.
7924 However, I don't think that the values returned by inferior
7925 function calls are special in any way. So this function may not
7926 notice that an expression involving an inferior function call
7927 can't be watched with hardware watchpoints. FIXME. */
7928 for (; v
; v
= value_next (v
))
7930 if (VALUE_LVAL (v
) == lval_memory
)
7933 /* A lazy memory lvalue is one that GDB never needed to fetch;
7934 we either just used its address (e.g., `a' in `a.b') or
7935 we never needed it at all (e.g., `a' in `a,b'). */
7939 /* Ahh, memory we actually used! Check if we can cover
7940 it with hardware watchpoints. */
7941 struct type
*vtype
= check_typedef (value_type (v
));
7943 /* We only watch structs and arrays if user asked for it
7944 explicitly, never if they just happen to appear in a
7945 middle of some value chain. */
7947 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7948 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7950 CORE_ADDR vaddr
= value_address (v
);
7951 int len
= TYPE_LENGTH (value_type (v
));
7953 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7960 else if (VALUE_LVAL (v
) != not_lval
7961 && deprecated_value_modifiable (v
) == 0)
7962 return 0; /* ??? What does this represent? */
7963 else if (VALUE_LVAL (v
) == lval_register
)
7964 return 0; /* cannot watch a register with a HW watchpoint */
7967 /* The expression itself looks suitable for using a hardware
7968 watchpoint, but give the target machine a chance to reject it. */
7969 return found_memory_cnt
;
7973 watch_command_wrapper (char *arg
, int from_tty
)
7975 watch_command (arg
, from_tty
);
7979 watch_command (char *arg
, int from_tty
)
7981 watch_command_1 (arg
, hw_write
, from_tty
);
7985 rwatch_command_wrapper (char *arg
, int from_tty
)
7987 rwatch_command (arg
, from_tty
);
7991 rwatch_command (char *arg
, int from_tty
)
7993 watch_command_1 (arg
, hw_read
, from_tty
);
7997 awatch_command_wrapper (char *arg
, int from_tty
)
7999 awatch_command (arg
, from_tty
);
8003 awatch_command (char *arg
, int from_tty
)
8005 watch_command_1 (arg
, hw_access
, from_tty
);
8009 /* Helper routines for the until_command routine in infcmd.c. Here
8010 because it uses the mechanisms of breakpoints. */
8012 struct until_break_command_continuation_args
8014 struct breakpoint
*breakpoint
;
8015 struct breakpoint
*breakpoint2
;
8018 /* This function is called by fetch_inferior_event via the
8019 cmd_continuation pointer, to complete the until command. It takes
8020 care of cleaning up the temporary breakpoints set up by the until
8023 until_break_command_continuation (void *arg
)
8025 struct until_break_command_continuation_args
*a
= arg
;
8027 delete_breakpoint (a
->breakpoint
);
8029 delete_breakpoint (a
->breakpoint2
);
8033 until_break_command (char *arg
, int from_tty
, int anywhere
)
8035 struct symtabs_and_lines sals
;
8036 struct symtab_and_line sal
;
8037 struct frame_info
*frame
= get_selected_frame (NULL
);
8038 struct breakpoint
*breakpoint
;
8039 struct breakpoint
*breakpoint2
= NULL
;
8040 struct cleanup
*old_chain
;
8042 clear_proceed_status ();
8044 /* Set a breakpoint where the user wants it and at return from
8047 if (default_breakpoint_valid
)
8048 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8049 default_breakpoint_line
, (char ***) NULL
, NULL
);
8051 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8052 0, (char ***) NULL
, NULL
);
8054 if (sals
.nelts
!= 1)
8055 error (_("Couldn't get information on specified line."));
8058 xfree (sals
.sals
); /* malloc'd, so freed */
8061 error (_("Junk at end of arguments."));
8063 resolve_sal_pc (&sal
);
8066 /* If the user told us to continue until a specified location,
8067 we don't specify a frame at which we need to stop. */
8068 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8069 null_frame_id
, bp_until
);
8071 /* Otherwise, specify the selected frame, because we want to stop only
8072 at the very same frame. */
8073 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8074 get_stack_frame_id (frame
),
8077 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8079 /* Keep within the current frame, or in frames called by the current
8082 if (frame_id_p (frame_unwind_caller_id (frame
)))
8084 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8085 sal
.pc
= frame_unwind_caller_pc (frame
);
8086 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8088 frame_unwind_caller_id (frame
),
8090 make_cleanup_delete_breakpoint (breakpoint2
);
8093 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8095 /* If we are running asynchronously, and proceed call above has actually
8096 managed to start the target, arrange for breakpoints to be
8097 deleted when the target stops. Otherwise, we're already stopped and
8098 delete breakpoints via cleanup chain. */
8100 if (target_can_async_p () && is_running (inferior_ptid
))
8102 struct until_break_command_continuation_args
*args
;
8103 args
= xmalloc (sizeof (*args
));
8105 args
->breakpoint
= breakpoint
;
8106 args
->breakpoint2
= breakpoint2
;
8108 discard_cleanups (old_chain
);
8109 add_continuation (inferior_thread (),
8110 until_break_command_continuation
, args
,
8114 do_cleanups (old_chain
);
8118 ep_skip_leading_whitespace (char **s
)
8120 if ((s
== NULL
) || (*s
== NULL
))
8122 while (isspace (**s
))
8126 /* This function attempts to parse an optional "if <cond>" clause
8127 from the arg string. If one is not found, it returns NULL.
8129 Else, it returns a pointer to the condition string. (It does not
8130 attempt to evaluate the string against a particular block.) And,
8131 it updates arg to point to the first character following the parsed
8132 if clause in the arg string. */
8135 ep_parse_optional_if_clause (char **arg
)
8139 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8142 /* Skip the "if" keyword. */
8145 /* Skip any extra leading whitespace, and record the start of the
8146 condition string. */
8147 ep_skip_leading_whitespace (arg
);
8150 /* Assume that the condition occupies the remainder of the arg string. */
8151 (*arg
) += strlen (cond_string
);
8156 /* Commands to deal with catching events, such as signals, exceptions,
8157 process start/exit, etc. */
8161 catch_fork_temporary
, catch_vfork_temporary
,
8162 catch_fork_permanent
, catch_vfork_permanent
8167 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8169 struct gdbarch
*gdbarch
= get_current_arch ();
8170 char *cond_string
= NULL
;
8171 catch_fork_kind fork_kind
;
8174 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8175 tempflag
= (fork_kind
== catch_fork_temporary
8176 || fork_kind
== catch_vfork_temporary
);
8180 ep_skip_leading_whitespace (&arg
);
8182 /* The allowed syntax is:
8184 catch [v]fork if <cond>
8186 First, check if there's an if clause. */
8187 cond_string
= ep_parse_optional_if_clause (&arg
);
8189 if ((*arg
!= '\0') && !isspace (*arg
))
8190 error (_("Junk at end of arguments."));
8192 /* If this target supports it, create a fork or vfork catchpoint
8193 and enable reporting of such events. */
8196 case catch_fork_temporary
:
8197 case catch_fork_permanent
:
8198 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8199 &catch_fork_breakpoint_ops
);
8201 case catch_vfork_temporary
:
8202 case catch_vfork_permanent
:
8203 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8204 &catch_vfork_breakpoint_ops
);
8207 error (_("unsupported or unknown fork kind; cannot catch it"));
8213 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8215 struct gdbarch
*gdbarch
= get_current_arch ();
8217 char *cond_string
= NULL
;
8219 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8223 ep_skip_leading_whitespace (&arg
);
8225 /* The allowed syntax is:
8227 catch exec if <cond>
8229 First, check if there's an if clause. */
8230 cond_string
= ep_parse_optional_if_clause (&arg
);
8232 if ((*arg
!= '\0') && !isspace (*arg
))
8233 error (_("Junk at end of arguments."));
8235 /* If this target supports it, create an exec catchpoint
8236 and enable reporting of such events. */
8237 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8238 &catch_exec_breakpoint_ops
);
8241 static enum print_stop_action
8242 print_exception_catchpoint (struct breakpoint
*b
)
8244 int bp_temp
, bp_throw
;
8246 annotate_catchpoint (b
->number
);
8248 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8249 if (b
->loc
->address
!= b
->loc
->requested_address
)
8250 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8253 bp_temp
= b
->disposition
== disp_del
;
8255 bp_temp
? "Temporary catchpoint "
8257 if (!ui_out_is_mi_like_p (uiout
))
8258 ui_out_field_int (uiout
, "bkptno", b
->number
);
8260 bp_throw
? " (exception thrown), "
8261 : " (exception caught), ");
8262 if (ui_out_is_mi_like_p (uiout
))
8264 ui_out_field_string (uiout
, "reason",
8265 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8266 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8267 ui_out_field_int (uiout
, "bkptno", b
->number
);
8269 return PRINT_SRC_AND_LOC
;
8273 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8275 struct value_print_options opts
;
8276 get_user_print_options (&opts
);
8277 if (opts
.addressprint
)
8280 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8281 ui_out_field_string (uiout
, "addr", "<PENDING>");
8283 ui_out_field_core_addr (uiout
, "addr",
8284 b
->loc
->gdbarch
, b
->loc
->address
);
8289 if (strstr (b
->addr_string
, "throw") != NULL
)
8290 ui_out_field_string (uiout
, "what", "exception throw");
8292 ui_out_field_string (uiout
, "what", "exception catch");
8296 print_mention_exception_catchpoint (struct breakpoint
*b
)
8301 bp_temp
= b
->disposition
== disp_del
;
8302 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8303 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8304 : _("Catchpoint "));
8305 ui_out_field_int (uiout
, "bkptno", b
->number
);
8306 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8310 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8313 NULL
, /* breakpoint_hit */
8314 print_exception_catchpoint
,
8315 print_one_exception_catchpoint
,
8316 print_mention_exception_catchpoint
8320 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8321 enum exception_event_kind ex_event
, int from_tty
)
8323 char *trigger_func_name
;
8325 if (ex_event
== EX_EVENT_CATCH
)
8326 trigger_func_name
= "__cxa_begin_catch";
8328 trigger_func_name
= "__cxa_throw";
8330 create_breakpoint (get_current_arch (),
8331 trigger_func_name
, cond_string
, -1,
8332 0 /* condition and thread are valid. */,
8335 AUTO_BOOLEAN_TRUE
/* pending */,
8336 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8342 /* Deal with "catch catch" and "catch throw" commands */
8345 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8346 int tempflag
, int from_tty
)
8348 char *cond_string
= NULL
;
8349 struct symtab_and_line
*sal
= NULL
;
8353 ep_skip_leading_whitespace (&arg
);
8355 cond_string
= ep_parse_optional_if_clause (&arg
);
8357 if ((*arg
!= '\0') && !isspace (*arg
))
8358 error (_("Junk at end of arguments."));
8360 if (ex_event
!= EX_EVENT_THROW
8361 && ex_event
!= EX_EVENT_CATCH
)
8362 error (_("Unsupported or unknown exception event; cannot catch it"));
8364 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8367 warning (_("Unsupported with this platform/compiler combination."));
8370 /* Implementation of "catch catch" command. */
8373 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8375 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8376 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8379 /* Implementation of "catch throw" command. */
8382 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8384 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8385 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8388 /* Create a breakpoint struct for Ada exception catchpoints. */
8391 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8392 struct symtab_and_line sal
,
8396 struct expression
*cond
,
8397 struct breakpoint_ops
*ops
,
8401 struct breakpoint
*b
;
8405 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8407 loc_gdbarch
= gdbarch
;
8409 describe_other_breakpoints (loc_gdbarch
,
8410 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8411 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8412 version for exception catchpoints, because two catchpoints
8413 used for different exception names will use the same address.
8414 In this case, a "breakpoint ... also set at..." warning is
8415 unproductive. Besides. the warning phrasing is also a bit
8416 inapropriate, we should use the word catchpoint, and tell
8417 the user what type of catchpoint it is. The above is good
8418 enough for now, though. */
8421 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8422 set_breakpoint_count (breakpoint_count
+ 1);
8424 b
->enable_state
= bp_enabled
;
8425 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8426 b
->number
= breakpoint_count
;
8427 b
->ignore_count
= 0;
8428 b
->loc
->cond
= cond
;
8429 b
->addr_string
= addr_string
;
8430 b
->language
= language_ada
;
8431 b
->cond_string
= cond_string
;
8432 b
->exp_string
= exp_string
;
8437 update_global_location_list (1);
8440 /* Implement the "catch exception" command. */
8443 catch_ada_exception_command (char *arg
, int from_tty
,
8444 struct cmd_list_element
*command
)
8446 struct gdbarch
*gdbarch
= get_current_arch ();
8448 struct symtab_and_line sal
;
8450 char *addr_string
= NULL
;
8451 char *exp_string
= NULL
;
8452 char *cond_string
= NULL
;
8453 struct expression
*cond
= NULL
;
8454 struct breakpoint_ops
*ops
= NULL
;
8456 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8460 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8461 &cond_string
, &cond
, &ops
);
8462 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8463 cond_string
, cond
, ops
, tempflag
,
8467 /* Cleanup function for a syscall filter list. */
8469 clean_up_filters (void *arg
)
8471 VEC(int) *iter
= *(VEC(int) **) arg
;
8472 VEC_free (int, iter
);
8475 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8476 filter list, or NULL if no filtering is required. */
8478 catch_syscall_split_args (char *arg
)
8480 VEC(int) *result
= NULL
;
8481 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8483 while (*arg
!= '\0')
8485 int i
, syscall_number
;
8490 /* Skip whitespace. */
8491 while (isspace (*arg
))
8494 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8495 cur_name
[i
] = arg
[i
];
8499 /* Check if the user provided a syscall name or a number. */
8500 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8501 if (*endptr
== '\0')
8502 get_syscall_by_number (syscall_number
, &s
);
8505 /* We have a name. Let's check if it's valid and convert it
8507 get_syscall_by_name (cur_name
, &s
);
8509 if (s
.number
== UNKNOWN_SYSCALL
)
8510 /* Here we have to issue an error instead of a warning, because
8511 GDB cannot do anything useful if there's no syscall number to
8513 error (_("Unknown syscall name '%s'."), cur_name
);
8516 /* Ok, it's valid. */
8517 VEC_safe_push (int, result
, s
.number
);
8520 discard_cleanups (cleanup
);
8524 /* Implement the "catch syscall" command. */
8527 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8532 struct gdbarch
*gdbarch
= get_current_arch ();
8534 /* Checking if the feature if supported. */
8535 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8536 error (_("The feature 'catch syscall' is not supported on \
8537 this architeture yet."));
8539 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8541 ep_skip_leading_whitespace (&arg
);
8543 /* We need to do this first "dummy" translation in order
8544 to get the syscall XML file loaded or, most important,
8545 to display a warning to the user if there's no XML file
8546 for his/her architecture. */
8547 get_syscall_by_number (0, &s
);
8549 /* The allowed syntax is:
8551 catch syscall <name | number> [<name | number> ... <name | number>]
8553 Let's check if there's a syscall name. */
8556 filter
= catch_syscall_split_args (arg
);
8560 create_syscall_event_catchpoint (tempflag
, filter
,
8561 &catch_syscall_breakpoint_ops
);
8564 /* Implement the "catch assert" command. */
8567 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8569 struct gdbarch
*gdbarch
= get_current_arch ();
8571 struct symtab_and_line sal
;
8572 char *addr_string
= NULL
;
8573 struct breakpoint_ops
*ops
= NULL
;
8575 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8579 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8580 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8581 ops
, tempflag
, from_tty
);
8585 catch_command (char *arg
, int from_tty
)
8587 error (_("Catch requires an event name."));
8592 tcatch_command (char *arg
, int from_tty
)
8594 error (_("Catch requires an event name."));
8597 /* Delete breakpoints by address or line. */
8600 clear_command (char *arg
, int from_tty
)
8602 struct breakpoint
*b
;
8603 VEC(breakpoint_p
) *found
= 0;
8606 struct symtabs_and_lines sals
;
8607 struct symtab_and_line sal
;
8612 sals
= decode_line_spec (arg
, 1);
8617 sals
.sals
= (struct symtab_and_line
*)
8618 xmalloc (sizeof (struct symtab_and_line
));
8619 make_cleanup (xfree
, sals
.sals
);
8620 init_sal (&sal
); /* initialize to zeroes */
8621 sal
.line
= default_breakpoint_line
;
8622 sal
.symtab
= default_breakpoint_symtab
;
8623 sal
.pc
= default_breakpoint_address
;
8624 sal
.pspace
= default_breakpoint_pspace
;
8625 if (sal
.symtab
== 0)
8626 error (_("No source file specified."));
8634 /* We don't call resolve_sal_pc here. That's not
8635 as bad as it seems, because all existing breakpoints
8636 typically have both file/line and pc set. So, if
8637 clear is given file/line, we can match this to existing
8638 breakpoint without obtaining pc at all.
8640 We only support clearing given the address explicitly
8641 present in breakpoint table. Say, we've set breakpoint
8642 at file:line. There were several PC values for that file:line,
8643 due to optimization, all in one block.
8644 We've picked one PC value. If "clear" is issued with another
8645 PC corresponding to the same file:line, the breakpoint won't
8646 be cleared. We probably can still clear the breakpoint, but
8647 since the other PC value is never presented to user, user
8648 can only find it by guessing, and it does not seem important
8651 /* For each line spec given, delete bps which correspond
8652 to it. Do it in two passes, solely to preserve the current
8653 behavior that from_tty is forced true if we delete more than
8657 for (i
= 0; i
< sals
.nelts
; i
++)
8659 /* If exact pc given, clear bpts at that pc.
8660 If line given (pc == 0), clear all bpts on specified line.
8661 If defaulting, clear all bpts on default line
8664 defaulting sal.pc != 0 tests to do
8669 1 0 <can't happen> */
8673 /* Find all matching breakpoints and add them to
8678 /* Are we going to delete b? */
8679 if (b
->type
!= bp_none
8680 && b
->type
!= bp_watchpoint
8681 && b
->type
!= bp_hardware_watchpoint
8682 && b
->type
!= bp_read_watchpoint
8683 && b
->type
!= bp_access_watchpoint
)
8685 struct bp_location
*loc
= b
->loc
;
8686 for (; loc
; loc
= loc
->next
)
8688 int pc_match
= sal
.pc
8689 && (loc
->pspace
== sal
.pspace
)
8690 && (loc
->address
== sal
.pc
)
8691 && (!section_is_overlay (loc
->section
)
8692 || loc
->section
== sal
.section
);
8693 int line_match
= ((default_match
|| (0 == sal
.pc
))
8694 && b
->source_file
!= NULL
8695 && sal
.symtab
!= NULL
8696 && sal
.pspace
== loc
->pspace
8697 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8698 && b
->line_number
== sal
.line
);
8699 if (pc_match
|| line_match
)
8708 VEC_safe_push(breakpoint_p
, found
, b
);
8711 /* Now go thru the 'found' chain and delete them. */
8712 if (VEC_empty(breakpoint_p
, found
))
8715 error (_("No breakpoint at %s."), arg
);
8717 error (_("No breakpoint at this line."));
8720 if (VEC_length(breakpoint_p
, found
) > 1)
8721 from_tty
= 1; /* Always report if deleted more than one */
8724 if (VEC_length(breakpoint_p
, found
) == 1)
8725 printf_unfiltered (_("Deleted breakpoint "));
8727 printf_unfiltered (_("Deleted breakpoints "));
8729 breakpoints_changed ();
8731 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8734 printf_unfiltered ("%d ", b
->number
);
8735 delete_breakpoint (b
);
8738 putchar_unfiltered ('\n');
8741 /* Delete breakpoint in BS if they are `delete' breakpoints and
8742 all breakpoints that are marked for deletion, whether hit or not.
8743 This is called after any breakpoint is hit, or after errors. */
8746 breakpoint_auto_delete (bpstat bs
)
8748 struct breakpoint
*b
, *temp
;
8750 for (; bs
; bs
= bs
->next
)
8751 if (bs
->breakpoint_at
8752 && bs
->breakpoint_at
->owner
8753 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8755 delete_breakpoint (bs
->breakpoint_at
->owner
);
8757 ALL_BREAKPOINTS_SAFE (b
, temp
)
8759 if (b
->disposition
== disp_del_at_next_stop
)
8760 delete_breakpoint (b
);
8764 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8765 Sort elements primarily by their ADDRESS (no matter what does
8766 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8767 first bp_permanent OWNERed elements and terciarily just ensuring the array
8768 is sorted stable way despite qsort being an instable algorithm. */
8771 bp_location_compare (const void *ap
, const void *bp
)
8773 struct bp_location
*a
= *(void **) ap
;
8774 struct bp_location
*b
= *(void **) bp
;
8775 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8776 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8778 if (a
->address
!= b
->address
)
8779 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8781 /* Sort permanent breakpoints first. */
8782 if (a_perm
!= b_perm
)
8783 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8785 /* Make the user-visible order stable across GDB runs. Locations of the same
8786 breakpoint can be sorted in arbitrary order. */
8788 if (a
->owner
->number
!= b
->owner
->number
)
8789 return (a
->owner
->number
> b
->owner
->number
)
8790 - (a
->owner
->number
< b
->owner
->number
);
8792 return (a
> b
) - (a
< b
);
8795 /* Set bp_location_placed_address_before_address_max and
8796 bp_location_shadow_len_after_address_max according to the current content of
8797 the bp_location array. */
8800 bp_location_target_extensions_update (void)
8802 struct bp_location
*bl
, **blp_tmp
;
8804 bp_location_placed_address_before_address_max
= 0;
8805 bp_location_shadow_len_after_address_max
= 0;
8807 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8809 CORE_ADDR start
, end
, addr
;
8811 if (!bp_location_has_shadow (bl
))
8814 start
= bl
->target_info
.placed_address
;
8815 end
= start
+ bl
->target_info
.shadow_len
;
8817 gdb_assert (bl
->address
>= start
);
8818 addr
= bl
->address
- start
;
8819 if (addr
> bp_location_placed_address_before_address_max
)
8820 bp_location_placed_address_before_address_max
= addr
;
8822 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8824 gdb_assert (bl
->address
< end
);
8825 addr
= end
- bl
->address
;
8826 if (addr
> bp_location_shadow_len_after_address_max
)
8827 bp_location_shadow_len_after_address_max
= addr
;
8831 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8832 into the inferior, only remove already-inserted locations that no
8833 longer should be inserted. Functions that delete a breakpoint or
8834 breakpoints should pass false, so that deleting a breakpoint
8835 doesn't have the side effect of inserting the locations of other
8836 breakpoints that are marked not-inserted, but should_be_inserted
8837 returns true on them.
8839 This behaviour is useful is situations close to tear-down -- e.g.,
8840 after an exec, while the target still has execution, but breakpoint
8841 shadows of the previous executable image should *NOT* be restored
8842 to the new image; or before detaching, where the target still has
8843 execution and wants to delete breakpoints from GDB's lists, and all
8844 breakpoints had already been removed from the inferior. */
8847 update_global_location_list (int should_insert
)
8849 struct breakpoint
*b
;
8850 struct bp_location
**locp
, *loc
;
8851 struct cleanup
*cleanups
;
8853 /* Used in the duplicates detection below. When iterating over all
8854 bp_locations, points to the first bp_location of a given address.
8855 Breakpoints and watchpoints of different types are never
8856 duplicates of each other. Keep one pointer for each type of
8857 breakpoint/watchpoint, so we only need to loop over all locations
8859 struct bp_location
*bp_loc_first
; /* breakpoint */
8860 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8861 struct bp_location
*awp_loc_first
; /* access watchpoint */
8862 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8864 /* Saved former bp_location array which we compare against the newly built
8865 bp_location from the current state of ALL_BREAKPOINTS. */
8866 struct bp_location
**old_location
, **old_locp
;
8867 unsigned old_location_count
;
8869 old_location
= bp_location
;
8870 old_location_count
= bp_location_count
;
8872 bp_location_count
= 0;
8873 cleanups
= make_cleanup (xfree
, old_location
);
8876 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8877 bp_location_count
++;
8879 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8882 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8884 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8885 bp_location_compare
);
8887 bp_location_target_extensions_update ();
8889 /* Identify bp_location instances that are no longer present in the new
8890 list, and therefore should be freed. Note that it's not necessary that
8891 those locations should be removed from inferior -- if there's another
8892 location at the same address (previously marked as duplicate),
8893 we don't need to remove/insert the location.
8895 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8896 former bp_location array state respectively. */
8899 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8902 struct bp_location
*old_loc
= *old_locp
;
8903 struct bp_location
**loc2p
;
8905 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8907 int found_object
= 0;
8908 /* Tells if the location should remain inserted in the target. */
8909 int keep_in_target
= 0;
8912 /* Skip LOCP entries which will definitely never be needed. Stop either
8913 at or being the one matching OLD_LOC. */
8914 while (locp
< bp_location
+ bp_location_count
8915 && (*locp
)->address
< old_loc
->address
)
8919 (loc2p
< bp_location
+ bp_location_count
8920 && (*loc2p
)->address
== old_loc
->address
);
8923 if (*loc2p
== old_loc
)
8930 /* If this location is no longer present, and inserted, look if there's
8931 maybe a new location at the same address. If so, mark that one
8932 inserted, and don't remove this one. This is needed so that we
8933 don't have a time window where a breakpoint at certain location is not
8936 if (old_loc
->inserted
)
8938 /* If the location is inserted now, we might have to remove it. */
8940 if (found_object
&& should_be_inserted (old_loc
))
8942 /* The location is still present in the location list, and still
8943 should be inserted. Don't do anything. */
8948 /* The location is either no longer present, or got disabled.
8949 See if there's another location at the same address, in which
8950 case we don't need to remove this one from the target. */
8952 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8955 (loc2p
< bp_location
+ bp_location_count
8956 && (*loc2p
)->address
== old_loc
->address
);
8959 struct bp_location
*loc2
= *loc2p
;
8961 if (breakpoint_locations_match (loc2
, old_loc
))
8963 /* For the sake of should_be_inserted.
8964 Duplicates check below will fix up this later. */
8965 loc2
->duplicate
= 0;
8967 /* Read watchpoint locations are switched to
8968 access watchpoints, if the former are not
8969 supported, but the latter are. */
8970 if (is_hardware_watchpoint (old_loc
->owner
))
8972 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8973 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8976 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8979 loc2
->target_info
= old_loc
->target_info
;
8988 if (!keep_in_target
)
8990 if (remove_breakpoint (old_loc
, mark_uninserted
))
8992 /* This is just about all we can do. We could keep this
8993 location on the global list, and try to remove it next
8994 time, but there's no particular reason why we will
8997 Note that at this point, old_loc->owner is still valid,
8998 as delete_breakpoint frees the breakpoint only
8999 after calling us. */
9000 printf_filtered (_("warning: Error removing breakpoint %d\n"),
9001 old_loc
->owner
->number
);
9009 if (removed
&& non_stop
9010 && breakpoint_address_is_meaningful (old_loc
->owner
)
9011 && !is_hardware_watchpoint (old_loc
->owner
))
9013 /* This location was removed from the target. In
9014 non-stop mode, a race condition is possible where
9015 we've removed a breakpoint, but stop events for that
9016 breakpoint are already queued and will arrive later.
9017 We apply an heuristic to be able to distinguish such
9018 SIGTRAPs from other random SIGTRAPs: we keep this
9019 breakpoint location for a bit, and will retire it
9020 after we see some number of events. The theory here
9021 is that reporting of events should, "on the average",
9022 be fair, so after a while we'll see events from all
9023 threads that have anything of interest, and no longer
9024 need to keep this breakpoint location around. We
9025 don't hold locations forever so to reduce chances of
9026 mistaking a non-breakpoint SIGTRAP for a breakpoint
9029 The heuristic failing can be disastrous on
9030 decr_pc_after_break targets.
9032 On decr_pc_after_break targets, like e.g., x86-linux,
9033 if we fail to recognize a late breakpoint SIGTRAP,
9034 because events_till_retirement has reached 0 too
9035 soon, we'll fail to do the PC adjustment, and report
9036 a random SIGTRAP to the user. When the user resumes
9037 the inferior, it will most likely immediately crash
9038 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
9039 corrupted, because of being resumed e.g., in the
9040 middle of a multi-byte instruction, or skipped a
9041 one-byte instruction. This was actually seen happen
9042 on native x86-linux, and should be less rare on
9043 targets that do not support new thread events, like
9044 remote, due to the heuristic depending on
9047 Mistaking a random SIGTRAP for a breakpoint trap
9048 causes similar symptoms (PC adjustment applied when
9049 it shouldn't), but then again, playing with SIGTRAPs
9050 behind the debugger's back is asking for trouble.
9052 Since hardware watchpoint traps are always
9053 distinguishable from other traps, so we don't need to
9054 apply keep hardware watchpoint moribund locations
9055 around. We simply always ignore hardware watchpoint
9056 traps we can no longer explain. */
9058 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9059 old_loc
->owner
= NULL
;
9061 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9064 free_bp_location (old_loc
);
9068 /* Rescan breakpoints at the same address and section, marking the
9069 first one as "first" and any others as "duplicates". This is so
9070 that the bpt instruction is only inserted once. If we have a
9071 permanent breakpoint at the same place as BPT, make that one the
9072 official one, and the rest as duplicates. Permanent breakpoints
9073 are sorted first for the same address.
9075 Do the same for hardware watchpoints, but also considering the
9076 watchpoint's type (regular/access/read) and length. */
9078 bp_loc_first
= NULL
;
9079 wp_loc_first
= NULL
;
9080 awp_loc_first
= NULL
;
9081 rwp_loc_first
= NULL
;
9082 ALL_BP_LOCATIONS (loc
, locp
)
9084 struct breakpoint
*b
= loc
->owner
;
9085 struct bp_location
**loc_first_p
;
9087 if (b
->enable_state
== bp_disabled
9088 || b
->enable_state
== bp_call_disabled
9089 || b
->enable_state
== bp_startup_disabled
9091 || loc
->shlib_disabled
9092 || !breakpoint_address_is_meaningful (b
)
9093 || tracepoint_type (b
))
9096 /* Permanent breakpoint should always be inserted. */
9097 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9098 internal_error (__FILE__
, __LINE__
,
9099 _("allegedly permanent breakpoint is not "
9100 "actually inserted"));
9102 if (b
->type
== bp_hardware_watchpoint
)
9103 loc_first_p
= &wp_loc_first
;
9104 else if (b
->type
== bp_read_watchpoint
)
9105 loc_first_p
= &rwp_loc_first
;
9106 else if (b
->type
== bp_access_watchpoint
)
9107 loc_first_p
= &awp_loc_first
;
9109 loc_first_p
= &bp_loc_first
;
9111 if (*loc_first_p
== NULL
9112 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9113 || !breakpoint_locations_match (loc
, *loc_first_p
))
9122 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9123 && b
->enable_state
!= bp_permanent
)
9124 internal_error (__FILE__
, __LINE__
,
9125 _("another breakpoint was inserted on top of "
9126 "a permanent breakpoint"));
9129 if (breakpoints_always_inserted_mode () && should_insert
9130 && (have_live_inferiors ()
9131 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9132 insert_breakpoint_locations ();
9134 do_cleanups (cleanups
);
9138 breakpoint_retire_moribund (void)
9140 struct bp_location
*loc
;
9143 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9144 if (--(loc
->events_till_retirement
) == 0)
9146 free_bp_location (loc
);
9147 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9153 update_global_location_list_nothrow (int inserting
)
9155 struct gdb_exception e
;
9156 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9157 update_global_location_list (inserting
);
9160 /* Clear BPT from a BPS. */
9162 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9165 for (bs
= bps
; bs
; bs
= bs
->next
)
9166 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9168 bs
->breakpoint_at
= NULL
;
9170 /* bs->commands will be freed later. */
9174 /* Callback for iterate_over_threads. */
9176 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9178 struct breakpoint
*bpt
= data
;
9179 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9183 /* Delete a breakpoint and clean up all traces of it in the data
9187 delete_breakpoint (struct breakpoint
*bpt
)
9189 struct breakpoint
*b
;
9190 struct bp_location
*loc
, *next
;
9192 gdb_assert (bpt
!= NULL
);
9194 /* Has this bp already been deleted? This can happen because multiple
9195 lists can hold pointers to bp's. bpstat lists are especial culprits.
9197 One example of this happening is a watchpoint's scope bp. When the
9198 scope bp triggers, we notice that the watchpoint is out of scope, and
9199 delete it. We also delete its scope bp. But the scope bp is marked
9200 "auto-deleting", and is already on a bpstat. That bpstat is then
9201 checked for auto-deleting bp's, which are deleted.
9203 A real solution to this problem might involve reference counts in bp's,
9204 and/or giving them pointers back to their referencing bpstat's, and
9205 teaching delete_breakpoint to only free a bp's storage when no more
9206 references were extent. A cheaper bandaid was chosen. */
9207 if (bpt
->type
== bp_none
)
9210 /* At least avoid this stale reference until the reference counting of
9211 breakpoints gets resolved. */
9212 if (bpt
->related_breakpoint
!= NULL
)
9214 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9215 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9216 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9217 bpt
->related_breakpoint
= NULL
;
9220 observer_notify_breakpoint_deleted (bpt
->number
);
9222 if (breakpoint_chain
== bpt
)
9223 breakpoint_chain
= bpt
->next
;
9228 b
->next
= bpt
->next
;
9232 decref_counted_command_line (&bpt
->commands
);
9233 xfree (bpt
->cond_string
);
9234 xfree (bpt
->cond_exp
);
9235 xfree (bpt
->addr_string
);
9237 xfree (bpt
->exp_string
);
9238 value_free (bpt
->val
);
9239 xfree (bpt
->source_file
);
9240 xfree (bpt
->exec_pathname
);
9241 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9243 /* Be sure no bpstat's are pointing at it after it's been freed. */
9244 /* FIXME, how can we find all bpstat's?
9245 We just check stop_bpstat for now. Note that we cannot just
9246 remove bpstats pointing at bpt from the stop_bpstat list
9247 entirely, as breakpoint commands are associated with the bpstat;
9248 if we remove it here, then the later call to
9249 bpstat_do_actions (&stop_bpstat);
9250 in event-top.c won't do anything, and temporary breakpoints
9251 with commands won't work. */
9253 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9255 /* Now that breakpoint is removed from breakpoint
9256 list, update the global location list. This
9257 will remove locations that used to belong to
9258 this breakpoint. Do this before freeing
9259 the breakpoint itself, since remove_breakpoint
9260 looks at location's owner. It might be better
9261 design to have location completely self-contained,
9262 but it's not the case now. */
9263 update_global_location_list (0);
9266 /* On the chance that someone will soon try again to delete this same
9267 bp, we mark it as deleted before freeing its storage. */
9268 bpt
->type
= bp_none
;
9274 do_delete_breakpoint_cleanup (void *b
)
9276 delete_breakpoint (b
);
9280 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9282 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9285 /* A callback for map_breakpoint_numbers that calls
9286 delete_breakpoint. */
9289 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9291 delete_breakpoint (b
);
9295 delete_command (char *arg
, int from_tty
)
9297 struct breakpoint
*b
, *temp
;
9303 int breaks_to_delete
= 0;
9305 /* Delete all breakpoints if no argument.
9306 Do not delete internal or call-dummy breakpoints, these
9307 have to be deleted with an explicit breakpoint number argument. */
9310 if (b
->type
!= bp_call_dummy
9311 && b
->type
!= bp_std_terminate
9312 && b
->type
!= bp_shlib_event
9313 && b
->type
!= bp_jit_event
9314 && b
->type
!= bp_thread_event
9315 && b
->type
!= bp_overlay_event
9316 && b
->type
!= bp_longjmp_master
9317 && b
->type
!= bp_std_terminate_master
9320 breaks_to_delete
= 1;
9325 /* Ask user only if there are some breakpoints to delete. */
9327 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9329 ALL_BREAKPOINTS_SAFE (b
, temp
)
9331 if (b
->type
!= bp_call_dummy
9332 && b
->type
!= bp_std_terminate
9333 && b
->type
!= bp_shlib_event
9334 && b
->type
!= bp_thread_event
9335 && b
->type
!= bp_jit_event
9336 && b
->type
!= bp_overlay_event
9337 && b
->type
!= bp_longjmp_master
9338 && b
->type
!= bp_std_terminate_master
9340 delete_breakpoint (b
);
9345 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9349 all_locations_are_pending (struct bp_location
*loc
)
9351 for (; loc
; loc
= loc
->next
)
9352 if (!loc
->shlib_disabled
)
9357 /* Subroutine of update_breakpoint_locations to simplify it.
9358 Return non-zero if multiple fns in list LOC have the same name.
9359 Null names are ignored. */
9362 ambiguous_names_p (struct bp_location
*loc
)
9364 struct bp_location
*l
;
9365 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9366 (int (*) (const void *, const void *)) streq
,
9367 NULL
, xcalloc
, xfree
);
9369 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9372 const char *name
= l
->function_name
;
9374 /* Allow for some names to be NULL, ignore them. */
9378 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9380 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9395 update_breakpoint_locations (struct breakpoint
*b
,
9396 struct symtabs_and_lines sals
)
9400 struct bp_location
*existing_locations
= b
->loc
;
9402 /* If there's no new locations, and all existing locations
9403 are pending, don't do anything. This optimizes
9404 the common case where all locations are in the same
9405 shared library, that was unloaded. We'd like to
9406 retain the location, so that when the library
9407 is loaded again, we don't loose the enabled/disabled
9408 status of the individual locations. */
9409 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9414 for (i
= 0; i
< sals
.nelts
; ++i
)
9416 struct bp_location
*new_loc
=
9417 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9419 /* Reparse conditions, they might contain references to the
9421 if (b
->cond_string
!= NULL
)
9423 struct gdb_exception e
;
9426 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9428 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9433 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9434 b
->number
, e
.message
);
9435 new_loc
->enabled
= 0;
9439 if (b
->source_file
!= NULL
)
9440 xfree (b
->source_file
);
9441 if (sals
.sals
[i
].symtab
== NULL
)
9442 b
->source_file
= NULL
;
9444 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9446 if (b
->line_number
== 0)
9447 b
->line_number
= sals
.sals
[i
].line
;
9450 /* Update locations of permanent breakpoints. */
9451 if (b
->enable_state
== bp_permanent
)
9452 make_breakpoint_permanent (b
);
9454 /* If possible, carry over 'disable' status from existing breakpoints. */
9456 struct bp_location
*e
= existing_locations
;
9457 /* If there are multiple breakpoints with the same function name,
9458 e.g. for inline functions, comparing function names won't work.
9459 Instead compare pc addresses; this is just a heuristic as things
9460 may have moved, but in practice it gives the correct answer
9461 often enough until a better solution is found. */
9462 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9464 for (; e
; e
= e
->next
)
9466 if (!e
->enabled
&& e
->function_name
)
9468 struct bp_location
*l
= b
->loc
;
9469 if (have_ambiguous_names
)
9471 for (; l
; l
= l
->next
)
9472 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9473 l
->pspace
->aspace
, l
->address
))
9481 for (; l
; l
= l
->next
)
9482 if (l
->function_name
9483 && strcmp (e
->function_name
, l
->function_name
) == 0)
9493 update_global_location_list (1);
9497 /* Reset a breakpoint given it's struct breakpoint * BINT.
9498 The value we return ends up being the return value from catch_errors.
9499 Unused in this case. */
9502 breakpoint_re_set_one (void *bint
)
9504 /* get past catch_errs */
9505 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9509 int *not_found_ptr
= ¬_found
;
9510 struct symtabs_and_lines sals
= {0};
9511 struct symtabs_and_lines expanded
= {0};
9513 enum enable_state save_enable
;
9514 struct gdb_exception e
;
9515 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9520 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9524 case bp_hardware_breakpoint
:
9526 case bp_fast_tracepoint
:
9527 /* Do not attempt to re-set breakpoints disabled during startup. */
9528 if (b
->enable_state
== bp_startup_disabled
)
9531 if (b
->addr_string
== NULL
)
9533 /* Anything without a string can't be re-set. */
9534 delete_breakpoint (b
);
9538 set_language (b
->language
);
9539 input_radix
= b
->input_radix
;
9542 save_current_space_and_thread ();
9543 switch_to_program_space_and_thread (b
->pspace
);
9545 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9547 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9552 int not_found_and_ok
= 0;
9553 /* For pending breakpoints, it's expected that parsing
9554 will fail until the right shared library is loaded.
9555 User has already told to create pending breakpoints and
9556 don't need extra messages. If breakpoint is in bp_shlib_disabled
9557 state, then user already saw the message about that breakpoint
9558 being disabled, and don't want to see more errors. */
9560 && (b
->condition_not_parsed
9561 || (b
->loc
&& b
->loc
->shlib_disabled
)
9562 || b
->enable_state
== bp_disabled
))
9563 not_found_and_ok
= 1;
9565 if (!not_found_and_ok
)
9567 /* We surely don't want to warn about the same breakpoint
9568 10 times. One solution, implemented here, is disable
9569 the breakpoint on error. Another solution would be to
9570 have separate 'warning emitted' flag. Since this
9571 happens only when a binary has changed, I don't know
9572 which approach is better. */
9573 b
->enable_state
= bp_disabled
;
9574 throw_exception (e
);
9580 gdb_assert (sals
.nelts
== 1);
9582 resolve_sal_pc (&sals
.sals
[0]);
9583 if (b
->condition_not_parsed
&& s
&& s
[0])
9585 char *cond_string
= 0;
9589 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9590 &cond_string
, &thread
, &task
);
9592 b
->cond_string
= cond_string
;
9595 b
->condition_not_parsed
= 0;
9598 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9601 make_cleanup (xfree
, sals
.sals
);
9602 update_breakpoint_locations (b
, expanded
);
9606 case bp_hardware_watchpoint
:
9607 case bp_read_watchpoint
:
9608 case bp_access_watchpoint
:
9609 /* Watchpoint can be either on expression using entirely global variables,
9610 or it can be on local variables.
9612 Watchpoints of the first kind are never auto-deleted, and even persist
9613 across program restarts. Since they can use variables from shared
9614 libraries, we need to reparse expression as libraries are loaded
9617 Watchpoints on local variables can also change meaning as result
9618 of solib event. For example, if a watchpoint uses both a local and
9619 a global variables in expression, it's a local watchpoint, but
9620 unloading of a shared library will make the expression invalid.
9621 This is not a very common use case, but we still re-evaluate
9622 expression, to avoid surprises to the user.
9624 Note that for local watchpoints, we re-evaluate it only if
9625 watchpoints frame id is still valid. If it's not, it means
9626 the watchpoint is out of scope and will be deleted soon. In fact,
9627 I'm not sure we'll ever be called in this case.
9629 If a local watchpoint's frame id is still valid, then
9630 b->exp_valid_block is likewise valid, and we can safely use it.
9632 Don't do anything about disabled watchpoints, since they will
9633 be reevaluated again when enabled. */
9634 update_watchpoint (b
, 1 /* reparse */);
9636 /* We needn't really do anything to reset these, since the mask
9637 that requests them is unaffected by e.g., new libraries being
9643 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9645 /* Delete overlay event and longjmp master breakpoints; they will be
9646 reset later by breakpoint_re_set. */
9647 case bp_overlay_event
:
9648 case bp_longjmp_master
:
9649 case bp_std_terminate_master
:
9650 delete_breakpoint (b
);
9653 /* This breakpoint is special, it's set up when the inferior
9654 starts and we really don't want to touch it. */
9655 case bp_shlib_event
:
9657 /* Like bp_shlib_event, this breakpoint type is special.
9658 Once it is set up, we do not want to touch it. */
9659 case bp_thread_event
:
9661 /* Keep temporary breakpoints, which can be encountered when we step
9662 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9663 Otherwise these should have been blown away via the cleanup chain
9664 or by breakpoint_init_inferior when we rerun the executable. */
9667 case bp_watchpoint_scope
:
9669 case bp_std_terminate
:
9670 case bp_step_resume
:
9672 case bp_longjmp_resume
:
9677 do_cleanups (cleanups
);
9681 /* Re-set all breakpoints after symbols have been re-loaded. */
9683 breakpoint_re_set (void)
9685 struct breakpoint
*b
, *temp
;
9686 enum language save_language
;
9687 int save_input_radix
;
9688 struct cleanup
*old_chain
;
9690 save_language
= current_language
->la_language
;
9691 save_input_radix
= input_radix
;
9692 old_chain
= save_current_program_space ();
9694 ALL_BREAKPOINTS_SAFE (b
, temp
)
9696 /* Format possible error msg */
9697 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9699 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9700 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9701 do_cleanups (cleanups
);
9703 set_language (save_language
);
9704 input_radix
= save_input_radix
;
9706 jit_breakpoint_re_set ();
9708 do_cleanups (old_chain
);
9710 create_overlay_event_breakpoint ("_ovly_debug_event");
9711 create_longjmp_master_breakpoint ("longjmp");
9712 create_longjmp_master_breakpoint ("_longjmp");
9713 create_longjmp_master_breakpoint ("siglongjmp");
9714 create_longjmp_master_breakpoint ("_siglongjmp");
9715 create_std_terminate_master_breakpoint ("std::terminate()");
9718 /* Reset the thread number of this breakpoint:
9720 - If the breakpoint is for all threads, leave it as-is.
9721 - Else, reset it to the current thread for inferior_ptid. */
9723 breakpoint_re_set_thread (struct breakpoint
*b
)
9725 if (b
->thread
!= -1)
9727 if (in_thread_list (inferior_ptid
))
9728 b
->thread
= pid_to_thread_id (inferior_ptid
);
9730 /* We're being called after following a fork. The new fork is
9731 selected as current, and unless this was a vfork will have a
9732 different program space from the original thread. Reset that
9734 b
->loc
->pspace
= current_program_space
;
9738 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9739 If from_tty is nonzero, it prints a message to that effect,
9740 which ends with a period (no newline). */
9743 set_ignore_count (int bptnum
, int count
, int from_tty
)
9745 struct breakpoint
*b
;
9751 if (b
->number
== bptnum
)
9753 b
->ignore_count
= count
;
9757 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9759 else if (count
== 1)
9760 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9763 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9766 breakpoints_changed ();
9767 observer_notify_breakpoint_modified (b
->number
);
9771 error (_("No breakpoint number %d."), bptnum
);
9775 make_breakpoint_silent (struct breakpoint
*b
)
9777 /* Silence the breakpoint. */
9781 /* Command to set ignore-count of breakpoint N to COUNT. */
9784 ignore_command (char *args
, int from_tty
)
9790 error_no_arg (_("a breakpoint number"));
9792 num
= get_number (&p
);
9794 error (_("bad breakpoint number: '%s'"), args
);
9796 error (_("Second argument (specified ignore-count) is missing."));
9798 set_ignore_count (num
,
9799 longest_to_int (value_as_long (parse_and_eval (p
))),
9802 printf_filtered ("\n");
9805 /* Call FUNCTION on each of the breakpoints
9806 whose numbers are given in ARGS. */
9809 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9816 struct breakpoint
*b
, *tmp
;
9820 error_no_arg (_("one or more breakpoint numbers"));
9827 num
= get_number_or_range (&p1
);
9830 warning (_("bad breakpoint number at or near '%s'"), p
);
9834 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9835 if (b
->number
== num
)
9837 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9840 if (related_breakpoint
)
9841 function (related_breakpoint
, data
);
9845 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9851 static struct bp_location
*
9852 find_location_by_number (char *number
)
9854 char *dot
= strchr (number
, '.');
9858 struct breakpoint
*b
;
9859 struct bp_location
*loc
;
9864 bp_num
= get_number_or_range (&p1
);
9866 error (_("Bad breakpoint number '%s'"), number
);
9869 if (b
->number
== bp_num
)
9874 if (!b
|| b
->number
!= bp_num
)
9875 error (_("Bad breakpoint number '%s'"), number
);
9878 loc_num
= get_number_or_range (&p1
);
9880 error (_("Bad breakpoint location number '%s'"), number
);
9884 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9887 error (_("Bad breakpoint location number '%s'"), dot
+1);
9893 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9894 If from_tty is nonzero, it prints a message to that effect,
9895 which ends with a period (no newline). */
9898 disable_breakpoint (struct breakpoint
*bpt
)
9900 /* Never disable a watchpoint scope breakpoint; we want to
9901 hit them when we leave scope so we can delete both the
9902 watchpoint and its scope breakpoint at that time. */
9903 if (bpt
->type
== bp_watchpoint_scope
)
9906 /* You can't disable permanent breakpoints. */
9907 if (bpt
->enable_state
== bp_permanent
)
9910 bpt
->enable_state
= bp_disabled
;
9912 update_global_location_list (0);
9914 observer_notify_breakpoint_modified (bpt
->number
);
9917 /* A callback for map_breakpoint_numbers that calls
9918 disable_breakpoint. */
9921 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9923 disable_breakpoint (b
);
9927 disable_command (char *args
, int from_tty
)
9929 struct breakpoint
*bpt
;
9931 ALL_BREAKPOINTS (bpt
)
9935 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9940 case bp_fast_tracepoint
:
9942 case bp_hardware_breakpoint
:
9944 case bp_hardware_watchpoint
:
9945 case bp_read_watchpoint
:
9946 case bp_access_watchpoint
:
9947 disable_breakpoint (bpt
);
9951 else if (strchr (args
, '.'))
9953 struct bp_location
*loc
= find_location_by_number (args
);
9956 update_global_location_list (0);
9959 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9963 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9965 int target_resources_ok
, other_type_used
;
9968 if (bpt
->type
== bp_hardware_breakpoint
)
9971 i
= hw_breakpoint_used_count ();
9972 target_resources_ok
=
9973 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9975 if (target_resources_ok
== 0)
9976 error (_("No hardware breakpoint support in the target."));
9977 else if (target_resources_ok
< 0)
9978 error (_("Hardware breakpoints used exceeds limit."));
9981 if (bpt
->type
== bp_watchpoint
9982 || bpt
->type
== bp_hardware_watchpoint
9983 || bpt
->type
== bp_read_watchpoint
9984 || bpt
->type
== bp_access_watchpoint
)
9986 struct gdb_exception e
;
9988 TRY_CATCH (e
, RETURN_MASK_ALL
)
9990 update_watchpoint (bpt
, 1 /* reparse */);
9994 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10000 if (bpt
->enable_state
!= bp_permanent
)
10001 bpt
->enable_state
= bp_enabled
;
10002 bpt
->disposition
= disposition
;
10003 update_global_location_list (1);
10004 breakpoints_changed ();
10006 observer_notify_breakpoint_modified (bpt
->number
);
10011 enable_breakpoint (struct breakpoint
*bpt
)
10013 do_enable_breakpoint (bpt
, bpt
->disposition
);
10016 /* A callback for map_breakpoint_numbers that calls
10017 enable_breakpoint. */
10020 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10022 enable_breakpoint (b
);
10025 /* The enable command enables the specified breakpoints (or all defined
10026 breakpoints) so they once again become (or continue to be) effective
10027 in stopping the inferior. */
10030 enable_command (char *args
, int from_tty
)
10032 struct breakpoint
*bpt
;
10034 ALL_BREAKPOINTS (bpt
)
10038 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
10041 case bp_breakpoint
:
10042 case bp_tracepoint
:
10043 case bp_fast_tracepoint
:
10044 case bp_catchpoint
:
10045 case bp_hardware_breakpoint
:
10046 case bp_watchpoint
:
10047 case bp_hardware_watchpoint
:
10048 case bp_read_watchpoint
:
10049 case bp_access_watchpoint
:
10050 enable_breakpoint (bpt
);
10054 else if (strchr (args
, '.'))
10056 struct bp_location
*loc
= find_location_by_number (args
);
10059 update_global_location_list (1);
10062 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
10066 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10068 do_enable_breakpoint (bpt
, disp_disable
);
10072 enable_once_command (char *args
, int from_tty
)
10074 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
10078 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
10080 do_enable_breakpoint (bpt
, disp_del
);
10084 enable_delete_command (char *args
, int from_tty
)
10086 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
10090 set_breakpoint_cmd (char *args
, int from_tty
)
10095 show_breakpoint_cmd (char *args
, int from_tty
)
10099 /* Invalidate last known value of any hardware watchpoint if
10100 the memory which that value represents has been written to by
10104 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10105 const bfd_byte
*data
)
10107 struct breakpoint
*bp
;
10109 ALL_BREAKPOINTS (bp
)
10110 if (bp
->enable_state
== bp_enabled
10111 && bp
->type
== bp_hardware_watchpoint
10112 && bp
->val_valid
&& bp
->val
)
10114 struct bp_location
*loc
;
10116 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10117 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10118 && loc
->address
+ loc
->length
> addr
10119 && addr
+ len
> loc
->address
)
10121 value_free (bp
->val
);
10128 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10130 struct symtabs_and_lines
10131 decode_line_spec_1 (char *string
, int funfirstline
)
10133 struct symtabs_and_lines sals
;
10135 error (_("Empty line specification."));
10136 if (default_breakpoint_valid
)
10137 sals
= decode_line_1 (&string
, funfirstline
,
10138 default_breakpoint_symtab
,
10139 default_breakpoint_line
,
10140 (char ***) NULL
, NULL
);
10142 sals
= decode_line_1 (&string
, funfirstline
,
10143 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10145 error (_("Junk at end of line specification: %s"), string
);
10149 /* Create and insert a raw software breakpoint at PC. Return an
10150 identifier, which should be used to remove the breakpoint later.
10151 In general, places which call this should be using something on the
10152 breakpoint chain instead; this function should be eliminated
10156 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10157 struct address_space
*aspace
, CORE_ADDR pc
)
10159 struct bp_target_info
*bp_tgt
;
10161 bp_tgt
= XZALLOC (struct bp_target_info
);
10163 bp_tgt
->placed_address_space
= aspace
;
10164 bp_tgt
->placed_address
= pc
;
10166 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10168 /* Could not insert the breakpoint. */
10176 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10179 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10181 struct bp_target_info
*bp_tgt
= bp
;
10184 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10190 /* One (or perhaps two) breakpoints used for software single stepping. */
10192 static void *single_step_breakpoints
[2];
10193 static struct gdbarch
*single_step_gdbarch
[2];
10195 /* Create and insert a breakpoint for software single step. */
10198 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10199 struct address_space
*aspace
, CORE_ADDR next_pc
)
10203 if (single_step_breakpoints
[0] == NULL
)
10205 bpt_p
= &single_step_breakpoints
[0];
10206 single_step_gdbarch
[0] = gdbarch
;
10210 gdb_assert (single_step_breakpoints
[1] == NULL
);
10211 bpt_p
= &single_step_breakpoints
[1];
10212 single_step_gdbarch
[1] = gdbarch
;
10215 /* NOTE drow/2006-04-11: A future improvement to this function would be
10216 to only create the breakpoints once, and actually put them on the
10217 breakpoint chain. That would let us use set_raw_breakpoint. We could
10218 adjust the addresses each time they were needed. Doing this requires
10219 corresponding changes elsewhere where single step breakpoints are
10220 handled, however. So, for now, we use this. */
10222 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10223 if (*bpt_p
== NULL
)
10224 error (_("Could not insert single-step breakpoint at %s"),
10225 paddress (gdbarch
, next_pc
));
10228 /* Remove and delete any breakpoints used for software single step. */
10231 remove_single_step_breakpoints (void)
10233 gdb_assert (single_step_breakpoints
[0] != NULL
);
10235 /* See insert_single_step_breakpoint for more about this deprecated
10237 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10238 single_step_breakpoints
[0]);
10239 single_step_gdbarch
[0] = NULL
;
10240 single_step_breakpoints
[0] = NULL
;
10242 if (single_step_breakpoints
[1] != NULL
)
10244 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10245 single_step_breakpoints
[1]);
10246 single_step_gdbarch
[1] = NULL
;
10247 single_step_breakpoints
[1] = NULL
;
10251 /* Check whether a software single-step breakpoint is inserted at PC. */
10254 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10258 for (i
= 0; i
< 2; i
++)
10260 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10262 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10263 bp_tgt
->placed_address
,
10271 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10272 non-zero otherwise. */
10274 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10276 if (syscall_catchpoint_p (bp
)
10277 && bp
->enable_state
!= bp_disabled
10278 && bp
->enable_state
!= bp_call_disabled
)
10285 catch_syscall_enabled (void)
10287 struct inferior
*inf
= current_inferior ();
10289 return inf
->total_syscalls_count
!= 0;
10293 catching_syscall_number (int syscall_number
)
10295 struct breakpoint
*bp
;
10297 ALL_BREAKPOINTS (bp
)
10298 if (is_syscall_catchpoint_enabled (bp
))
10300 if (bp
->syscalls_to_be_caught
)
10304 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10306 if (syscall_number
== iter
)
10316 /* Complete syscall names. Used by "catch syscall". */
10318 catch_syscall_completer (struct cmd_list_element
*cmd
,
10319 char *text
, char *word
)
10321 const char **list
= get_syscall_names ();
10322 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10325 /* Tracepoint-specific operations. */
10327 /* Set tracepoint count to NUM. */
10329 set_tracepoint_count (int num
)
10331 tracepoint_count
= num
;
10332 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10336 trace_command (char *arg
, int from_tty
)
10338 if (create_breakpoint (get_current_arch (),
10340 NULL
, 0, 1 /* parse arg */,
10341 0 /* tempflag */, 0 /* hardwareflag */,
10343 0 /* Ignore count */,
10344 pending_break_support
,
10348 set_tracepoint_count (breakpoint_count
);
10352 ftrace_command (char *arg
, int from_tty
)
10354 if (create_breakpoint (get_current_arch (),
10356 NULL
, 0, 1 /* parse arg */,
10357 0 /* tempflag */, 1 /* hardwareflag */,
10359 0 /* Ignore count */,
10360 pending_break_support
,
10364 set_tracepoint_count (breakpoint_count
);
10367 /* Given information about a tracepoint as recorded on a target (which
10368 can be either a live system or a trace file), attempt to create an
10369 equivalent GDB tracepoint. This is not a reliable process, since
10370 the target does not necessarily have all the information used when
10371 the tracepoint was originally defined. */
10373 struct breakpoint
*
10374 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10377 struct breakpoint
*tp
;
10379 /* In the absence of a source location, fall back to raw address. */
10380 sprintf (buf
, "*%s", paddress (get_current_arch(), utp
->addr
));
10382 if (!create_breakpoint (get_current_arch (),
10384 NULL
, 0, 1 /* parse arg */,
10386 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10388 0 /* Ignore count */,
10389 pending_break_support
,
10392 utp
->enabled
/* enabled */))
10395 set_tracepoint_count (breakpoint_count
);
10397 tp
= get_tracepoint (tracepoint_count
);
10398 gdb_assert (tp
!= NULL
);
10402 sprintf (buf
, "%d %d", utp
->pass
, tp
->number
);
10404 trace_pass_command (buf
, 0);
10409 printf_filtered ("Want to restore a condition\n");
10412 if (utp
->numactions
> 0)
10414 printf_filtered ("Want to restore action list\n");
10417 if (utp
->num_step_actions
> 0)
10419 printf_filtered ("Want to restore action list\n");
10425 /* Print information on tracepoint number TPNUM_EXP, or all if
10429 tracepoints_info (char *tpnum_exp
, int from_tty
)
10431 struct breakpoint
*b
;
10432 int tps_to_list
= 0;
10434 /* In the no-arguments case, say "No tracepoints" if none found. */
10435 if (tpnum_exp
== 0)
10437 ALL_TRACEPOINTS (b
)
10439 if (b
->number
>= 0)
10447 ui_out_message (uiout
, 0, "No tracepoints.\n");
10452 /* Otherwise be the same as "info break". */
10453 breakpoints_info (tpnum_exp
, from_tty
);
10456 /* The 'enable trace' command enables tracepoints.
10457 Not supported by all targets. */
10459 enable_trace_command (char *args
, int from_tty
)
10461 enable_command (args
, from_tty
);
10464 /* The 'disable trace' command disables tracepoints.
10465 Not supported by all targets. */
10467 disable_trace_command (char *args
, int from_tty
)
10469 disable_command (args
, from_tty
);
10472 /* Remove a tracepoint (or all if no argument) */
10474 delete_trace_command (char *arg
, int from_tty
)
10476 struct breakpoint
*b
, *temp
;
10482 int breaks_to_delete
= 0;
10484 /* Delete all breakpoints if no argument.
10485 Do not delete internal or call-dummy breakpoints, these
10486 have to be deleted with an explicit breakpoint number argument. */
10487 ALL_TRACEPOINTS (b
)
10489 if (b
->number
>= 0)
10491 breaks_to_delete
= 1;
10496 /* Ask user only if there are some breakpoints to delete. */
10498 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10500 ALL_BREAKPOINTS_SAFE (b
, temp
)
10502 if (tracepoint_type (b
)
10504 delete_breakpoint (b
);
10509 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10512 /* Set passcount for tracepoint.
10514 First command argument is passcount, second is tracepoint number.
10515 If tracepoint number omitted, apply to most recently defined.
10516 Also accepts special argument "all". */
10519 trace_pass_command (char *args
, int from_tty
)
10521 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10522 unsigned int count
;
10525 if (args
== 0 || *args
== 0)
10526 error (_("passcount command requires an argument (count + optional TP num)"));
10528 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10530 while (*args
&& isspace ((int) *args
))
10533 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10535 args
+= 3; /* Skip special argument "all". */
10538 error (_("Junk at end of arguments."));
10541 t1
= get_tracepoint_by_number (&args
, 1, 1);
10547 ALL_TRACEPOINTS (t2
)
10548 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10550 t2
->pass_count
= count
;
10551 observer_notify_tracepoint_modified (t2
->number
);
10553 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10554 t2
->number
, count
);
10556 if (! all
&& *args
)
10557 t1
= get_tracepoint_by_number (&args
, 1, 0);
10563 struct breakpoint
*
10564 get_tracepoint (int num
)
10566 struct breakpoint
*t
;
10568 ALL_TRACEPOINTS (t
)
10569 if (t
->number
== num
)
10575 /* Find the tracepoint with the given target-side number (which may be
10576 different from the tracepoint number after disconnecting and
10579 struct breakpoint
*
10580 get_tracepoint_by_number_on_target (int num
)
10582 struct breakpoint
*t
;
10584 ALL_TRACEPOINTS (t
)
10585 if (t
->number_on_target
== num
)
10591 /* Utility: parse a tracepoint number and look it up in the list.
10592 If MULTI_P is true, there might be a range of tracepoints in ARG.
10593 if OPTIONAL_P is true, then if the argument is missing, the most
10594 recent tracepoint (tracepoint_count) is returned. */
10595 struct breakpoint
*
10596 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10598 extern int tracepoint_count
;
10599 struct breakpoint
*t
;
10601 char *instring
= arg
== NULL
? NULL
: *arg
;
10603 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10606 tpnum
= tracepoint_count
;
10608 error_no_arg (_("tracepoint number"));
10611 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10615 if (instring
&& *instring
)
10616 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10619 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10623 ALL_TRACEPOINTS (t
)
10624 if (t
->number
== tpnum
)
10629 /* FIXME: if we are in the middle of a range we don't want to give
10630 a message. The current interface to get_number_or_range doesn't
10631 allow us to discover this. */
10632 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10636 /* save-tracepoints command */
10638 tracepoint_save_command (char *args
, int from_tty
)
10640 struct breakpoint
*tp
;
10642 struct command_line
*line
;
10645 struct cleanup
*cleanup
;
10646 struct ui_file
*fp
;
10648 if (args
== 0 || *args
== 0)
10649 error (_("Argument required (file name in which to save tracepoints)"));
10651 /* See if we have anything to save. */
10652 ALL_TRACEPOINTS (tp
)
10659 warning (_("save-tracepoints: no tracepoints to save."));
10663 pathname
= tilde_expand (args
);
10664 cleanup
= make_cleanup (xfree
, pathname
);
10665 fp
= gdb_fopen (pathname
, "w");
10667 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10668 args
, safe_strerror (errno
));
10669 make_cleanup_ui_file_delete (fp
);
10671 ALL_TRACEPOINTS (tp
)
10673 if (tp
->addr_string
)
10674 fprintf_unfiltered (fp
, "trace %s\n", tp
->addr_string
);
10677 sprintf_vma (tmp
, tp
->loc
->address
);
10678 fprintf_unfiltered (fp
, "trace *0x%s\n", tmp
);
10681 if (tp
->pass_count
)
10682 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10686 volatile struct gdb_exception ex
;
10688 fprintf_unfiltered (fp
, " actions\n");
10690 ui_out_redirect (uiout
, fp
);
10691 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10693 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10695 ui_out_redirect (uiout
, NULL
);
10698 throw_exception (ex
);
10700 fprintf_unfiltered (fp
, " end\n");
10703 do_cleanups (cleanup
);
10705 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10709 /* Create a vector of all tracepoints. */
10711 VEC(breakpoint_p
) *
10714 VEC(breakpoint_p
) *tp_vec
= 0;
10715 struct breakpoint
*tp
;
10717 ALL_TRACEPOINTS (tp
)
10719 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10726 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10727 It is defined as a macro to prevent duplication.
10728 COMMAND should be a string constant containing the name of the command. */
10729 #define BREAK_ARGS_HELP(command) \
10730 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10731 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10732 If a line number is specified, break at start of code for that line.\n\
10733 If a function is specified, break at start of code for that function.\n\
10734 If an address is specified, break at that exact address.\n\
10735 With no LOCATION, uses current execution address of selected stack frame.\n\
10736 This is useful for breaking on return to a stack frame.\n\
10738 THREADNUM is the number from \"info threads\".\n\
10739 CONDITION is a boolean expression.\n\
10741 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10743 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10745 /* List of subcommands for "catch". */
10746 static struct cmd_list_element
*catch_cmdlist
;
10748 /* List of subcommands for "tcatch". */
10749 static struct cmd_list_element
*tcatch_cmdlist
;
10751 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10752 lists, and pass some additional user data to the command function. */
10754 add_catch_command (char *name
, char *docstring
,
10755 void (*sfunc
) (char *args
, int from_tty
,
10756 struct cmd_list_element
*command
),
10757 char **(*completer
) (struct cmd_list_element
*cmd
,
10758 char *text
, char *word
),
10759 void *user_data_catch
,
10760 void *user_data_tcatch
)
10762 struct cmd_list_element
*command
;
10764 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10766 set_cmd_sfunc (command
, sfunc
);
10767 set_cmd_context (command
, user_data_catch
);
10768 set_cmd_completer (command
, completer
);
10770 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10772 set_cmd_sfunc (command
, sfunc
);
10773 set_cmd_context (command
, user_data_tcatch
);
10774 set_cmd_completer (command
, completer
);
10778 clear_syscall_counts (struct inferior
*inf
)
10780 inf
->total_syscalls_count
= 0;
10781 inf
->any_syscall_count
= 0;
10782 VEC_free (int, inf
->syscalls_counts
);
10786 _initialize_breakpoint (void)
10788 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10789 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10790 struct cmd_list_element
*c
;
10792 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10793 observer_attach_inferior_exit (clear_syscall_counts
);
10794 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10796 breakpoint_chain
= 0;
10797 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10798 before a breakpoint is set. */
10799 breakpoint_count
= 0;
10801 tracepoint_count
= 0;
10803 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10804 Set ignore-count of breakpoint number N to COUNT.\n\
10805 Usage is `ignore N COUNT'."));
10807 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10809 add_com ("commands", class_breakpoint
, commands_command
, _("\
10810 Set commands to be executed when a breakpoint is hit.\n\
10811 Give breakpoint number as argument after \"commands\".\n\
10812 With no argument, the targeted breakpoint is the last one set.\n\
10813 The commands themselves follow starting on the next line.\n\
10814 Type a line containing \"end\" to indicate the end of them.\n\
10815 Give \"silent\" as the first line to make the breakpoint silent;\n\
10816 then no output is printed when it is hit, except what the commands print."));
10818 add_com ("condition", class_breakpoint
, condition_command
, _("\
10819 Specify breakpoint number N to break only if COND is true.\n\
10820 Usage is `condition N COND', where N is an integer and COND is an\n\
10821 expression to be evaluated whenever breakpoint N is reached."));
10823 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10824 Set a temporary breakpoint.\n\
10825 Like \"break\" except the breakpoint is only temporary,\n\
10826 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10827 by using \"enable delete\" on the breakpoint number.\n\
10829 BREAK_ARGS_HELP ("tbreak")));
10830 set_cmd_completer (c
, location_completer
);
10832 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10833 Set a hardware assisted breakpoint.\n\
10834 Like \"break\" except the breakpoint requires hardware support,\n\
10835 some target hardware may not have this support.\n\
10837 BREAK_ARGS_HELP ("hbreak")));
10838 set_cmd_completer (c
, location_completer
);
10840 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10841 Set a temporary hardware assisted breakpoint.\n\
10842 Like \"hbreak\" except the breakpoint is only temporary,\n\
10843 so it will be deleted when hit.\n\
10845 BREAK_ARGS_HELP ("thbreak")));
10846 set_cmd_completer (c
, location_completer
);
10848 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10849 Enable some breakpoints.\n\
10850 Give breakpoint numbers (separated by spaces) as arguments.\n\
10851 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10852 This is used to cancel the effect of the \"disable\" command.\n\
10853 With a subcommand you can enable temporarily."),
10854 &enablelist
, "enable ", 1, &cmdlist
);
10856 add_com ("ab", class_breakpoint
, enable_command
, _("\
10857 Enable some breakpoints.\n\
10858 Give breakpoint numbers (separated by spaces) as arguments.\n\
10859 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10860 This is used to cancel the effect of the \"disable\" command.\n\
10861 With a subcommand you can enable temporarily."));
10863 add_com_alias ("en", "enable", class_breakpoint
, 1);
10865 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10866 Enable some breakpoints.\n\
10867 Give breakpoint numbers (separated by spaces) as arguments.\n\
10868 This is used to cancel the effect of the \"disable\" command.\n\
10869 May be abbreviated to simply \"enable\".\n"),
10870 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10872 add_cmd ("once", no_class
, enable_once_command
, _("\
10873 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10874 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10877 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10878 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10879 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10882 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10883 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10884 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10887 add_cmd ("once", no_class
, enable_once_command
, _("\
10888 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10889 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10892 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10893 Disable some breakpoints.\n\
10894 Arguments are breakpoint numbers with spaces in between.\n\
10895 To disable all breakpoints, give no argument.\n\
10896 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10897 &disablelist
, "disable ", 1, &cmdlist
);
10898 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10899 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10901 add_com ("sb", class_breakpoint
, disable_command
, _("\
10902 Disable some breakpoints.\n\
10903 Arguments are breakpoint numbers with spaces in between.\n\
10904 To disable all breakpoints, give no argument.\n\
10905 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10907 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10908 Disable some breakpoints.\n\
10909 Arguments are breakpoint numbers with spaces in between.\n\
10910 To disable all breakpoints, give no argument.\n\
10911 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10912 This command may be abbreviated \"disable\"."),
10915 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10916 Delete some breakpoints or auto-display expressions.\n\
10917 Arguments are breakpoint numbers with spaces in between.\n\
10918 To delete all breakpoints, give no argument.\n\
10920 Also a prefix command for deletion of other GDB objects.\n\
10921 The \"unset\" command is also an alias for \"delete\"."),
10922 &deletelist
, "delete ", 1, &cmdlist
);
10923 add_com_alias ("d", "delete", class_breakpoint
, 1);
10924 add_com_alias ("del", "delete", class_breakpoint
, 1);
10926 add_com ("db", class_breakpoint
, delete_command
, _("\
10927 Delete some breakpoints.\n\
10928 Arguments are breakpoint numbers with spaces in between.\n\
10929 To delete all breakpoints, give no argument.\n"));
10931 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10932 Delete some breakpoints or auto-display expressions.\n\
10933 Arguments are breakpoint numbers with spaces in between.\n\
10934 To delete all breakpoints, give no argument.\n\
10935 This command may be abbreviated \"delete\"."),
10938 add_com ("clear", class_breakpoint
, clear_command
, _("\
10939 Clear breakpoint at specified line or function.\n\
10940 Argument may be line number, function name, or \"*\" and an address.\n\
10941 If line number is specified, all breakpoints in that line are cleared.\n\
10942 If function is specified, breakpoints at beginning of function are cleared.\n\
10943 If an address is specified, breakpoints at that address are cleared.\n\
10945 With no argument, clears all breakpoints in the line that the selected frame\n\
10946 is executing in.\n\
10948 See also the \"delete\" command which clears breakpoints by number."));
10950 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10951 Set breakpoint at specified line or function.\n"
10952 BREAK_ARGS_HELP ("break")));
10953 set_cmd_completer (c
, location_completer
);
10955 add_com_alias ("b", "break", class_run
, 1);
10956 add_com_alias ("br", "break", class_run
, 1);
10957 add_com_alias ("bre", "break", class_run
, 1);
10958 add_com_alias ("brea", "break", class_run
, 1);
10961 add_com_alias ("ba", "break", class_breakpoint
, 1);
10965 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10966 Break in function/address or break at a line in the current file."),
10967 &stoplist
, "stop ", 1, &cmdlist
);
10968 add_cmd ("in", class_breakpoint
, stopin_command
,
10969 _("Break in function or address."), &stoplist
);
10970 add_cmd ("at", class_breakpoint
, stopat_command
,
10971 _("Break at a line in the current file."), &stoplist
);
10972 add_com ("status", class_info
, breakpoints_info
, _("\
10973 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10974 The \"Type\" column indicates one of:\n\
10975 \tbreakpoint - normal breakpoint\n\
10976 \twatchpoint - watchpoint\n\
10977 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10978 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10979 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10980 address and file/line number respectively.\n\
10982 Convenience variable \"$_\" and default examine address for \"x\"\n\
10983 are set to the address of the last breakpoint listed unless the command\n\
10984 is prefixed with \"server \".\n\n\
10985 Convenience variable \"$bpnum\" contains the number of the last\n\
10986 breakpoint set."));
10989 add_info ("breakpoints", breakpoints_info
, _("\
10990 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10991 The \"Type\" column indicates one of:\n\
10992 \tbreakpoint - normal breakpoint\n\
10993 \twatchpoint - watchpoint\n\
10994 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10995 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10996 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10997 address and file/line number respectively.\n\
10999 Convenience variable \"$_\" and default examine address for \"x\"\n\
11000 are set to the address of the last breakpoint listed unless the command\n\
11001 is prefixed with \"server \".\n\n\
11002 Convenience variable \"$bpnum\" contains the number of the last\n\
11003 breakpoint set."));
11005 add_info_alias ("b", "breakpoints", 1);
11008 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
11009 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
11010 The \"Type\" column indicates one of:\n\
11011 \tbreakpoint - normal breakpoint\n\
11012 \twatchpoint - watchpoint\n\
11013 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11014 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11015 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11016 address and file/line number respectively.\n\
11018 Convenience variable \"$_\" and default examine address for \"x\"\n\
11019 are set to the address of the last breakpoint listed unless the command\n\
11020 is prefixed with \"server \".\n\n\
11021 Convenience variable \"$bpnum\" contains the number of the last\n\
11022 breakpoint set."));
11024 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
11025 Status of all breakpoints, or breakpoint number NUMBER.\n\
11026 The \"Type\" column indicates one of:\n\
11027 \tbreakpoint - normal breakpoint\n\
11028 \twatchpoint - watchpoint\n\
11029 \tlongjmp - internal breakpoint used to step through longjmp()\n\
11030 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
11031 \tuntil - internal breakpoint used by the \"until\" command\n\
11032 \tfinish - internal breakpoint used by the \"finish\" command\n\
11033 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
11034 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
11035 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
11036 address and file/line number respectively.\n\
11038 Convenience variable \"$_\" and default examine address for \"x\"\n\
11039 are set to the address of the last breakpoint listed unless the command\n\
11040 is prefixed with \"server \".\n\n\
11041 Convenience variable \"$bpnum\" contains the number of the last\n\
11043 &maintenanceinfolist
);
11045 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
11046 Set catchpoints to catch events."),
11047 &catch_cmdlist
, "catch ",
11048 0/*allow-unknown*/, &cmdlist
);
11050 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
11051 Set temporary catchpoints to catch events."),
11052 &tcatch_cmdlist
, "tcatch ",
11053 0/*allow-unknown*/, &cmdlist
);
11055 /* Add catch and tcatch sub-commands. */
11056 add_catch_command ("catch", _("\
11057 Catch an exception, when caught.\n\
11058 With an argument, catch only exceptions with the given name."),
11059 catch_catch_command
,
11063 add_catch_command ("throw", _("\
11064 Catch an exception, when thrown.\n\
11065 With an argument, catch only exceptions with the given name."),
11066 catch_throw_command
,
11070 add_catch_command ("fork", _("Catch calls to fork."),
11071 catch_fork_command_1
,
11073 (void *) (uintptr_t) catch_fork_permanent
,
11074 (void *) (uintptr_t) catch_fork_temporary
);
11075 add_catch_command ("vfork", _("Catch calls to vfork."),
11076 catch_fork_command_1
,
11078 (void *) (uintptr_t) catch_vfork_permanent
,
11079 (void *) (uintptr_t) catch_vfork_temporary
);
11080 add_catch_command ("exec", _("Catch calls to exec."),
11081 catch_exec_command_1
,
11085 add_catch_command ("syscall", _("\
11086 Catch system calls by their names and/or numbers.\n\
11087 Arguments say which system calls to catch. If no arguments\n\
11088 are given, every system call will be caught.\n\
11089 Arguments, if given, should be one or more system call names\n\
11090 (if your system supports that), or system call numbers."),
11091 catch_syscall_command_1
,
11092 catch_syscall_completer
,
11095 add_catch_command ("exception", _("\
11096 Catch Ada exceptions, when raised.\n\
11097 With an argument, catch only exceptions with the given name."),
11098 catch_ada_exception_command
,
11102 add_catch_command ("assert", _("\
11103 Catch failed Ada assertions, when raised.\n\
11104 With an argument, catch only exceptions with the given name."),
11105 catch_assert_command
,
11110 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11111 Set a watchpoint for an expression.\n\
11112 A watchpoint stops execution of your program whenever the value of\n\
11113 an expression changes."));
11114 set_cmd_completer (c
, expression_completer
);
11116 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11117 Set a read watchpoint for an expression.\n\
11118 A watchpoint stops execution of your program whenever the value of\n\
11119 an expression is read."));
11120 set_cmd_completer (c
, expression_completer
);
11122 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11123 Set a watchpoint for an expression.\n\
11124 A watchpoint stops execution of your program whenever the value of\n\
11125 an expression is either read or written."));
11126 set_cmd_completer (c
, expression_completer
);
11128 add_info ("watchpoints", breakpoints_info
,
11129 _("Synonym for ``info breakpoints''."));
11132 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11133 respond to changes - contrary to the description. */
11134 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11135 &can_use_hw_watchpoints
, _("\
11136 Set debugger's willingness to use watchpoint hardware."), _("\
11137 Show debugger's willingness to use watchpoint hardware."), _("\
11138 If zero, gdb will not use hardware for new watchpoints, even if\n\
11139 such is available. (However, any hardware watchpoints that were\n\
11140 created before setting this to nonzero, will continue to use watchpoint\n\
11143 show_can_use_hw_watchpoints
,
11144 &setlist
, &showlist
);
11146 can_use_hw_watchpoints
= 1;
11148 /* Tracepoint manipulation commands. */
11150 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11151 Set a tracepoint at specified line or function.\n\
11153 BREAK_ARGS_HELP ("trace") "\n\
11154 Do \"help tracepoints\" for info on other tracepoint commands."));
11155 set_cmd_completer (c
, location_completer
);
11157 add_com_alias ("tp", "trace", class_alias
, 0);
11158 add_com_alias ("tr", "trace", class_alias
, 1);
11159 add_com_alias ("tra", "trace", class_alias
, 1);
11160 add_com_alias ("trac", "trace", class_alias
, 1);
11162 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11163 Set a fast tracepoint at specified line or function.\n\
11165 BREAK_ARGS_HELP ("ftrace") "\n\
11166 Do \"help tracepoints\" for info on other tracepoint commands."));
11167 set_cmd_completer (c
, location_completer
);
11169 add_info ("tracepoints", tracepoints_info
, _("\
11170 Status of tracepoints, or tracepoint number NUMBER.\n\
11171 Convenience variable \"$tpnum\" contains the number of the\n\
11172 last tracepoint set."));
11174 add_info_alias ("tp", "tracepoints", 1);
11176 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11177 Delete specified tracepoints.\n\
11178 Arguments are tracepoint numbers, separated by spaces.\n\
11179 No argument means delete all tracepoints."),
11182 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11183 Disable specified tracepoints.\n\
11184 Arguments are tracepoint numbers, separated by spaces.\n\
11185 No argument means disable all tracepoints."),
11187 deprecate_cmd (c
, "disable");
11189 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11190 Enable specified tracepoints.\n\
11191 Arguments are tracepoint numbers, separated by spaces.\n\
11192 No argument means enable all tracepoints."),
11194 deprecate_cmd (c
, "enable");
11196 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11197 Set the passcount for a tracepoint.\n\
11198 The trace will end when the tracepoint has been passed 'count' times.\n\
11199 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11200 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11202 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11203 Save current tracepoint definitions as a script.\n\
11204 Use the 'source' command in another debug session to restore them."));
11205 set_cmd_completer (c
, filename_completer
);
11207 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11208 Breakpoint specific settings\n\
11209 Configure various breakpoint-specific variables such as\n\
11210 pending breakpoint behavior"),
11211 &breakpoint_set_cmdlist
, "set breakpoint ",
11212 0/*allow-unknown*/, &setlist
);
11213 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11214 Breakpoint specific settings\n\
11215 Configure various breakpoint-specific variables such as\n\
11216 pending breakpoint behavior"),
11217 &breakpoint_show_cmdlist
, "show breakpoint ",
11218 0/*allow-unknown*/, &showlist
);
11220 add_setshow_auto_boolean_cmd ("pending", no_class
,
11221 &pending_break_support
, _("\
11222 Set debugger's behavior regarding pending breakpoints."), _("\
11223 Show debugger's behavior regarding pending breakpoints."), _("\
11224 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11225 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11226 an error. If auto, an unrecognized breakpoint location results in a\n\
11227 user-query to see if a pending breakpoint should be created."),
11229 show_pending_break_support
,
11230 &breakpoint_set_cmdlist
,
11231 &breakpoint_show_cmdlist
);
11233 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11235 add_setshow_boolean_cmd ("auto-hw", no_class
,
11236 &automatic_hardware_breakpoints
, _("\
11237 Set automatic usage of hardware breakpoints."), _("\
11238 Show automatic usage of hardware breakpoints."), _("\
11239 If set, the debugger will automatically use hardware breakpoints for\n\
11240 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11241 a warning will be emitted for such breakpoints."),
11243 show_automatic_hardware_breakpoints
,
11244 &breakpoint_set_cmdlist
,
11245 &breakpoint_show_cmdlist
);
11247 add_setshow_enum_cmd ("always-inserted", class_support
,
11248 always_inserted_enums
, &always_inserted_mode
, _("\
11249 Set mode for inserting breakpoints."), _("\
11250 Show mode for inserting breakpoints."), _("\
11251 When this mode is off, breakpoints are inserted in inferior when it is\n\
11252 resumed, and removed when execution stops. When this mode is on,\n\
11253 breakpoints are inserted immediately and removed only when the user\n\
11254 deletes the breakpoint. When this mode is auto (which is the default),\n\
11255 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11256 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11257 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11258 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11260 &show_always_inserted_mode
,
11261 &breakpoint_set_cmdlist
,
11262 &breakpoint_show_cmdlist
);
11264 automatic_hardware_breakpoints
= 1;
11266 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);