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
);
2161 update_breakpoints_after_exec (void)
2163 struct breakpoint
*b
;
2164 struct breakpoint
*temp
;
2165 struct bp_location
*bploc
, **bplocp_tmp
;
2167 /* We're about to delete breakpoints from GDB's lists. If the
2168 INSERTED flag is true, GDB will try to lift the breakpoints by
2169 writing the breakpoints' "shadow contents" back into memory. The
2170 "shadow contents" are NOT valid after an exec, so GDB should not
2171 do that. Instead, the target is responsible from marking
2172 breakpoints out as soon as it detects an exec. We don't do that
2173 here instead, because there may be other attempts to delete
2174 breakpoints after detecting an exec and before reaching here. */
2175 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2176 if (bploc
->pspace
== current_program_space
)
2177 gdb_assert (!bploc
->inserted
);
2179 ALL_BREAKPOINTS_SAFE (b
, temp
)
2181 if (b
->pspace
!= current_program_space
)
2184 /* Solib breakpoints must be explicitly reset after an exec(). */
2185 if (b
->type
== bp_shlib_event
)
2187 delete_breakpoint (b
);
2191 /* JIT breakpoints must be explicitly reset after an exec(). */
2192 if (b
->type
== bp_jit_event
)
2194 delete_breakpoint (b
);
2198 /* Thread event breakpoints must be set anew after an exec(),
2199 as must overlay event and longjmp master breakpoints. */
2200 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2201 || b
->type
== bp_longjmp_master
)
2203 delete_breakpoint (b
);
2207 /* Step-resume breakpoints are meaningless after an exec(). */
2208 if (b
->type
== bp_step_resume
)
2210 delete_breakpoint (b
);
2214 /* Longjmp and longjmp-resume breakpoints are also meaningless
2216 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2218 delete_breakpoint (b
);
2222 if (b
->type
== bp_catchpoint
)
2224 /* For now, none of the bp_catchpoint breakpoints need to
2225 do anything at this point. In the future, if some of
2226 the catchpoints need to something, we will need to add
2227 a new method, and call this method from here. */
2231 /* bp_finish is a special case. The only way we ought to be able
2232 to see one of these when an exec() has happened, is if the user
2233 caught a vfork, and then said "finish". Ordinarily a finish just
2234 carries them to the call-site of the current callee, by setting
2235 a temporary bp there and resuming. But in this case, the finish
2236 will carry them entirely through the vfork & exec.
2238 We don't want to allow a bp_finish to remain inserted now. But
2239 we can't safely delete it, 'cause finish_command has a handle to
2240 the bp on a bpstat, and will later want to delete it. There's a
2241 chance (and I've seen it happen) that if we delete the bp_finish
2242 here, that its storage will get reused by the time finish_command
2243 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2244 We really must allow finish_command to delete a bp_finish.
2246 In the absense of a general solution for the "how do we know
2247 it's safe to delete something others may have handles to?"
2248 problem, what we'll do here is just uninsert the bp_finish, and
2249 let finish_command delete it.
2251 (We know the bp_finish is "doomed" in the sense that it's
2252 momentary, and will be deleted as soon as finish_command sees
2253 the inferior stopped. So it doesn't matter that the bp's
2254 address is probably bogus in the new a.out, unlike e.g., the
2255 solib breakpoints.) */
2257 if (b
->type
== bp_finish
)
2262 /* Without a symbolic address, we have little hope of the
2263 pre-exec() address meaning the same thing in the post-exec()
2265 if (b
->addr_string
== NULL
)
2267 delete_breakpoint (b
);
2271 /* FIXME what about longjmp breakpoints? Re-create them here? */
2272 create_overlay_event_breakpoint ("_ovly_debug_event");
2273 create_longjmp_master_breakpoint ("longjmp");
2274 create_longjmp_master_breakpoint ("_longjmp");
2275 create_longjmp_master_breakpoint ("siglongjmp");
2276 create_longjmp_master_breakpoint ("_siglongjmp");
2280 detach_breakpoints (int pid
)
2282 struct bp_location
*b
, **bp_tmp
;
2284 struct cleanup
*old_chain
= save_inferior_ptid ();
2285 struct inferior
*inf
= current_inferior ();
2287 if (pid
== PIDGET (inferior_ptid
))
2288 error (_("Cannot detach breakpoints of inferior_ptid"));
2290 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2291 inferior_ptid
= pid_to_ptid (pid
);
2292 ALL_BP_LOCATIONS (b
, bp_tmp
)
2294 if (b
->pspace
!= inf
->pspace
)
2298 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2300 do_cleanups (old_chain
);
2304 /* Remove the breakpoint location B from the current address space.
2305 Note that this is used to detach breakpoints from a child fork.
2306 When we get here, the child isn't in the inferior list, and neither
2307 do we have objects to represent its address space --- we should
2308 *not* look at b->pspace->aspace here. */
2311 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2314 struct cleanup
*old_chain
;
2316 if (b
->owner
->enable_state
== bp_permanent
)
2317 /* Permanent breakpoints cannot be inserted or removed. */
2320 /* The type of none suggests that owner is actually deleted.
2321 This should not ever happen. */
2322 gdb_assert (b
->owner
->type
!= bp_none
);
2324 if (b
->loc_type
== bp_loc_software_breakpoint
2325 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2327 /* "Normal" instruction breakpoint: either the standard
2328 trap-instruction bp (bp_breakpoint), or a
2329 bp_hardware_breakpoint. */
2331 /* First check to see if we have to handle an overlay. */
2332 if (overlay_debugging
== ovly_off
2333 || b
->section
== NULL
2334 || !(section_is_overlay (b
->section
)))
2336 /* No overlay handling: just remove the breakpoint. */
2338 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2339 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2341 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2345 /* This breakpoint is in an overlay section.
2346 Did we set a breakpoint at the LMA? */
2347 if (!overlay_events_enabled
)
2349 /* Yes -- overlay event support is not active, so we
2350 should have set a breakpoint at the LMA. Remove it.
2352 /* Ignore any failures: if the LMA is in ROM, we will
2353 have already warned when we failed to insert it. */
2354 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2355 target_remove_hw_breakpoint (b
->gdbarch
,
2356 &b
->overlay_target_info
);
2358 target_remove_breakpoint (b
->gdbarch
,
2359 &b
->overlay_target_info
);
2361 /* Did we set a breakpoint at the VMA?
2362 If so, we will have marked the breakpoint 'inserted'. */
2365 /* Yes -- remove it. Previously we did not bother to
2366 remove the breakpoint if the section had been
2367 unmapped, but let's not rely on that being safe. We
2368 don't know what the overlay manager might do. */
2369 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2370 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2373 /* However, we should remove *software* breakpoints only
2374 if the section is still mapped, or else we overwrite
2375 wrong code with the saved shadow contents. */
2376 else if (section_is_mapped (b
->section
))
2377 val
= target_remove_breakpoint (b
->gdbarch
,
2384 /* No -- not inserted, so no need to remove. No error. */
2389 /* In some cases, we might not be able to remove a breakpoint
2390 in a shared library that has already been removed, but we
2391 have not yet processed the shlib unload event. */
2392 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2397 b
->inserted
= (is
== mark_inserted
);
2399 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2404 b
->inserted
= (is
== mark_inserted
);
2405 val
= target_remove_watchpoint (b
->address
, b
->length
,
2406 b
->watchpoint_type
);
2408 /* Failure to remove any of the hardware watchpoints comes here. */
2409 if ((is
== mark_uninserted
) && (b
->inserted
))
2410 warning (_("Could not remove hardware watchpoint %d."),
2413 else if (b
->owner
->type
== bp_catchpoint
2414 && breakpoint_enabled (b
->owner
)
2417 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2419 val
= b
->owner
->ops
->remove (b
->owner
);
2422 b
->inserted
= (is
== mark_inserted
);
2429 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2432 struct cleanup
*old_chain
;
2434 if (b
->owner
->enable_state
== bp_permanent
)
2435 /* Permanent breakpoints cannot be inserted or removed. */
2438 /* The type of none suggests that owner is actually deleted.
2439 This should not ever happen. */
2440 gdb_assert (b
->owner
->type
!= bp_none
);
2442 old_chain
= save_current_space_and_thread ();
2444 switch_to_program_space_and_thread (b
->pspace
);
2446 ret
= remove_breakpoint_1 (b
, is
);
2448 do_cleanups (old_chain
);
2452 /* Clear the "inserted" flag in all breakpoints. */
2455 mark_breakpoints_out (void)
2457 struct bp_location
*bpt
, **bptp_tmp
;
2459 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2460 if (bpt
->pspace
== current_program_space
)
2464 /* Clear the "inserted" flag in all breakpoints and delete any
2465 breakpoints which should go away between runs of the program.
2467 Plus other such housekeeping that has to be done for breakpoints
2470 Note: this function gets called at the end of a run (by
2471 generic_mourn_inferior) and when a run begins (by
2472 init_wait_for_inferior). */
2477 breakpoint_init_inferior (enum inf_context context
)
2479 struct breakpoint
*b
, *temp
;
2480 struct bp_location
*bpt
, **bptp_tmp
;
2482 struct program_space
*pspace
= current_program_space
;
2484 /* If breakpoint locations are shared across processes, then there's
2486 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2489 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2491 if (bpt
->pspace
== pspace
2492 && bpt
->owner
->enable_state
!= bp_permanent
)
2496 ALL_BREAKPOINTS_SAFE (b
, temp
)
2498 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2505 /* If the call dummy breakpoint is at the entry point it will
2506 cause problems when the inferior is rerun, so we better get
2509 case bp_watchpoint_scope
:
2511 /* Also get rid of scope breakpoints. */
2513 case bp_shlib_event
:
2515 /* Also remove solib event breakpoints. Their addresses may
2516 have changed since the last time we ran the program.
2517 Actually we may now be debugging against different target;
2518 and so the solib backend that installed this breakpoint may
2519 not be used in by the target. E.g.,
2521 (gdb) file prog-linux
2522 (gdb) run # native linux target
2525 (gdb) file prog-win.exe
2526 (gdb) tar rem :9999 # remote Windows gdbserver.
2529 delete_breakpoint (b
);
2533 case bp_hardware_watchpoint
:
2534 case bp_read_watchpoint
:
2535 case bp_access_watchpoint
:
2537 /* Likewise for watchpoints on local expressions. */
2538 if (b
->exp_valid_block
!= NULL
)
2539 delete_breakpoint (b
);
2540 else if (context
== inf_starting
)
2542 /* Reset val field to force reread of starting value
2543 in insert_breakpoints. */
2545 value_free (b
->val
);
2555 /* Get rid of the moribund locations. */
2556 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2557 free_bp_location (bpt
);
2558 VEC_free (bp_location_p
, moribund_locations
);
2561 /* These functions concern about actual breakpoints inserted in the
2562 target --- to e.g. check if we need to do decr_pc adjustment or if
2563 we need to hop over the bkpt --- so we check for address space
2564 match, not program space. */
2566 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2567 exists at PC. It returns ordinary_breakpoint_here if it's an
2568 ordinary breakpoint, or permanent_breakpoint_here if it's a
2569 permanent breakpoint.
2570 - When continuing from a location with an ordinary breakpoint, we
2571 actually single step once before calling insert_breakpoints.
2572 - When continuing from a localion with a permanent breakpoint, we
2573 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2574 the target, to advance the PC past the breakpoint. */
2576 enum breakpoint_here
2577 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2579 struct bp_location
*bpt
, **bptp_tmp
;
2580 int any_breakpoint_here
= 0;
2582 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2584 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2585 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2588 if ((breakpoint_enabled (bpt
->owner
)
2589 || bpt
->owner
->enable_state
== bp_permanent
)
2590 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2593 if (overlay_debugging
2594 && section_is_overlay (bpt
->section
)
2595 && !section_is_mapped (bpt
->section
))
2596 continue; /* unmapped overlay -- can't be a match */
2597 else if (bpt
->owner
->enable_state
== bp_permanent
)
2598 return permanent_breakpoint_here
;
2600 any_breakpoint_here
= 1;
2604 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2607 /* Return true if there's a moribund breakpoint at PC. */
2610 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2612 struct bp_location
*loc
;
2615 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2616 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2623 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2624 inserted using regular breakpoint_chain / bp_location array mechanism.
2625 This does not check for single-step breakpoints, which are
2626 inserted and removed using direct target manipulation. */
2629 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2631 struct bp_location
*bpt
, **bptp_tmp
;
2633 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2635 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2636 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2640 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2643 if (overlay_debugging
2644 && section_is_overlay (bpt
->section
)
2645 && !section_is_mapped (bpt
->section
))
2646 continue; /* unmapped overlay -- can't be a match */
2654 /* Returns non-zero iff there's either regular breakpoint
2655 or a single step breakpoint inserted at PC. */
2658 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2660 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2663 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2669 /* This function returns non-zero iff there is a software breakpoint
2673 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2675 struct bp_location
*bpt
, **bptp_tmp
;
2676 int any_breakpoint_here
= 0;
2678 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2680 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2684 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2687 if (overlay_debugging
2688 && section_is_overlay (bpt
->section
)
2689 && !section_is_mapped (bpt
->section
))
2690 continue; /* unmapped overlay -- can't be a match */
2696 /* Also check for software single-step breakpoints. */
2697 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2704 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2705 CORE_ADDR addr
, ULONGEST len
)
2707 struct breakpoint
*bpt
;
2709 ALL_BREAKPOINTS (bpt
)
2711 struct bp_location
*loc
;
2713 if (bpt
->type
!= bp_hardware_watchpoint
2714 && bpt
->type
!= bp_access_watchpoint
)
2717 if (!breakpoint_enabled (bpt
))
2720 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2721 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2725 /* Check for intersection. */
2726 l
= max (loc
->address
, addr
);
2727 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2735 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2736 PC is valid for process/thread PTID. */
2739 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2742 struct bp_location
*bpt
, **bptp_tmp
;
2743 /* The thread and task IDs associated to PTID, computed lazily. */
2747 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2749 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2750 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2753 if (!breakpoint_enabled (bpt
->owner
)
2754 && bpt
->owner
->enable_state
!= bp_permanent
)
2757 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2761 if (bpt
->owner
->thread
!= -1)
2763 /* This is a thread-specific breakpoint. Check that ptid
2764 matches that thread. If thread hasn't been computed yet,
2765 it is now time to do so. */
2767 thread
= pid_to_thread_id (ptid
);
2768 if (bpt
->owner
->thread
!= thread
)
2772 if (bpt
->owner
->task
!= 0)
2774 /* This is a task-specific breakpoint. Check that ptid
2775 matches that task. If task hasn't been computed yet,
2776 it is now time to do so. */
2778 task
= ada_get_task_number (ptid
);
2779 if (bpt
->owner
->task
!= task
)
2783 if (overlay_debugging
2784 && section_is_overlay (bpt
->section
)
2785 && !section_is_mapped (bpt
->section
))
2786 continue; /* unmapped overlay -- can't be a match */
2795 /* bpstat stuff. External routines' interfaces are documented
2799 ep_is_catchpoint (struct breakpoint
*ep
)
2801 return (ep
->type
== bp_catchpoint
);
2805 bpstat_free (bpstat bs
)
2807 if (bs
->old_val
!= NULL
)
2808 value_free (bs
->old_val
);
2809 decref_counted_command_line (&bs
->commands
);
2813 /* Clear a bpstat so that it says we are not at any breakpoint.
2814 Also free any storage that is part of a bpstat. */
2817 bpstat_clear (bpstat
*bsp
)
2834 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2835 is part of the bpstat is copied as well. */
2838 bpstat_copy (bpstat bs
)
2842 bpstat retval
= NULL
;
2847 for (; bs
!= NULL
; bs
= bs
->next
)
2849 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2850 memcpy (tmp
, bs
, sizeof (*tmp
));
2851 incref_counted_command_line (tmp
->commands
);
2852 if (bs
->old_val
!= NULL
)
2854 tmp
->old_val
= value_copy (bs
->old_val
);
2855 release_value (tmp
->old_val
);
2859 /* This is the first thing in the chain. */
2869 /* Find the bpstat associated with this breakpoint */
2872 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2877 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2879 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2885 /* Find a step_resume breakpoint associated with this bpstat.
2886 (If there are multiple step_resume bp's on the list, this function
2887 will arbitrarily pick one.)
2889 It is an error to use this function if BPSTAT doesn't contain a
2890 step_resume breakpoint.
2892 See wait_for_inferior's use of this function. */
2894 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2898 gdb_assert (bsp
!= NULL
);
2900 current_thread
= pid_to_thread_id (inferior_ptid
);
2902 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2904 if ((bsp
->breakpoint_at
!= NULL
)
2905 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2906 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2907 || bsp
->breakpoint_at
->owner
->thread
== -1))
2908 return bsp
->breakpoint_at
->owner
;
2911 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2915 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2916 at. *BSP upon return is a bpstat which points to the remaining
2917 breakpoints stopped at (but which is not guaranteed to be good for
2918 anything but further calls to bpstat_num).
2919 Return 0 if passed a bpstat which does not indicate any breakpoints.
2920 Return -1 if stopped at a breakpoint that has been deleted since
2922 Return 1 otherwise. */
2925 bpstat_num (bpstat
*bsp
, int *num
)
2927 struct breakpoint
*b
;
2930 return 0; /* No more breakpoint values */
2932 /* We assume we'll never have several bpstats that
2933 correspond to a single breakpoint -- otherwise,
2934 this function might return the same number more
2935 than once and this will look ugly. */
2936 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2937 *bsp
= (*bsp
)->next
;
2939 return -1; /* breakpoint that's been deleted since */
2941 *num
= b
->number
; /* We have its number */
2945 /* Modify BS so that the actions will not be performed. */
2948 bpstat_clear_actions (bpstat bs
)
2950 for (; bs
!= NULL
; bs
= bs
->next
)
2952 decref_counted_command_line (&bs
->commands
);
2953 if (bs
->old_val
!= NULL
)
2955 value_free (bs
->old_val
);
2961 /* Called when a command is about to proceed the inferior. */
2964 breakpoint_about_to_proceed (void)
2966 if (!ptid_equal (inferior_ptid
, null_ptid
))
2968 struct thread_info
*tp
= inferior_thread ();
2970 /* Allow inferior function calls in breakpoint commands to not
2971 interrupt the command list. When the call finishes
2972 successfully, the inferior will be standing at the same
2973 breakpoint as if nothing happened. */
2978 breakpoint_proceeded
= 1;
2981 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2983 cleanup_executing_breakpoints (void *ignore
)
2985 executing_breakpoint_commands
= 0;
2988 /* Execute all the commands associated with all the breakpoints at this
2989 location. Any of these commands could cause the process to proceed
2990 beyond this point, etc. We look out for such changes by checking
2991 the global "breakpoint_proceeded" after each command.
2993 Returns true if a breakpoint command resumed the inferior. In that
2994 case, it is the caller's responsibility to recall it again with the
2995 bpstat of the current thread. */
2998 bpstat_do_actions_1 (bpstat
*bsp
)
3001 struct cleanup
*old_chain
;
3004 /* Avoid endless recursion if a `source' command is contained
3006 if (executing_breakpoint_commands
)
3009 executing_breakpoint_commands
= 1;
3010 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3012 /* This pointer will iterate over the list of bpstat's. */
3015 breakpoint_proceeded
= 0;
3016 for (; bs
!= NULL
; bs
= bs
->next
)
3018 struct counted_command_line
*ccmd
;
3019 struct command_line
*cmd
;
3020 struct cleanup
*this_cmd_tree_chain
;
3022 /* Take ownership of the BSP's command tree, if it has one.
3024 The command tree could legitimately contain commands like
3025 'step' and 'next', which call clear_proceed_status, which
3026 frees stop_bpstat's command tree. To make sure this doesn't
3027 free the tree we're executing out from under us, we need to
3028 take ownership of the tree ourselves. Since a given bpstat's
3029 commands are only executed once, we don't need to copy it; we
3030 can clear the pointer in the bpstat, and make sure we free
3031 the tree when we're done. */
3032 ccmd
= bs
->commands
;
3033 bs
->commands
= NULL
;
3035 = make_cleanup_decref_counted_command_line (&ccmd
);
3036 cmd
= bs
->commands_left
;
3037 bs
->commands_left
= NULL
;
3041 execute_control_command (cmd
);
3043 if (breakpoint_proceeded
)
3049 /* We can free this command tree now. */
3050 do_cleanups (this_cmd_tree_chain
);
3052 if (breakpoint_proceeded
)
3054 if (target_can_async_p ())
3055 /* If we are in async mode, then the target might be still
3056 running, not stopped at any breakpoint, so nothing for
3057 us to do here -- just return to the event loop. */
3060 /* In sync mode, when execute_control_command returns
3061 we're already standing on the next breakpoint.
3062 Breakpoint commands for that stop were not run, since
3063 execute_command does not run breakpoint commands --
3064 only command_line_handler does, but that one is not
3065 involved in execution of breakpoint commands. So, we
3066 can now execute breakpoint commands. It should be
3067 noted that making execute_command do bpstat actions is
3068 not an option -- in this case we'll have recursive
3069 invocation of bpstat for each breakpoint with a
3070 command, and can easily blow up GDB stack. Instead, we
3071 return true, which will trigger the caller to recall us
3072 with the new stop_bpstat. */
3077 do_cleanups (old_chain
);
3082 bpstat_do_actions (void)
3084 /* Do any commands attached to breakpoint we are stopped at. */
3085 while (!ptid_equal (inferior_ptid
, null_ptid
)
3086 && target_has_execution
3087 && !is_exited (inferior_ptid
)
3088 && !is_executing (inferior_ptid
))
3089 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3090 and only return when it is stopped at the next breakpoint, we
3091 keep doing breakpoint actions until it returns false to
3092 indicate the inferior was not resumed. */
3093 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3097 /* Print out the (old or new) value associated with a watchpoint. */
3100 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3103 fprintf_unfiltered (stream
, _("<unreadable>"));
3106 struct value_print_options opts
;
3107 get_user_print_options (&opts
);
3108 value_print (val
, stream
, &opts
);
3112 /* This is the normal print function for a bpstat. In the future,
3113 much of this logic could (should?) be moved to bpstat_stop_status,
3114 by having it set different print_it values.
3116 Current scheme: When we stop, bpstat_print() is called. It loops
3117 through the bpstat list of things causing this stop, calling the
3118 print_bp_stop_message function on each one. The behavior of the
3119 print_bp_stop_message function depends on the print_it field of
3120 bpstat. If such field so indicates, call this function here.
3122 Return values from this routine (ultimately used by bpstat_print()
3123 and normal_stop() to decide what to do):
3124 PRINT_NOTHING: Means we already printed all we needed to print,
3125 don't print anything else.
3126 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3127 that something to be followed by a location.
3128 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3129 that something to be followed by a location.
3130 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3133 static enum print_stop_action
3134 print_it_typical (bpstat bs
)
3136 struct cleanup
*old_chain
;
3137 struct breakpoint
*b
;
3138 const struct bp_location
*bl
;
3139 struct ui_stream
*stb
;
3141 enum print_stop_action result
;
3143 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3144 which has since been deleted. */
3145 if (bs
->breakpoint_at
== NULL
)
3146 return PRINT_UNKNOWN
;
3147 bl
= bs
->breakpoint_at
;
3150 stb
= ui_out_stream_new (uiout
);
3151 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3156 case bp_hardware_breakpoint
:
3157 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3158 if (bl
->address
!= bl
->requested_address
)
3159 breakpoint_adjustment_warning (bl
->requested_address
,
3162 annotate_breakpoint (b
->number
);
3164 ui_out_text (uiout
, "\nTemporary breakpoint ");
3166 ui_out_text (uiout
, "\nBreakpoint ");
3167 if (ui_out_is_mi_like_p (uiout
))
3169 ui_out_field_string (uiout
, "reason",
3170 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3171 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3173 ui_out_field_int (uiout
, "bkptno", b
->number
);
3174 ui_out_text (uiout
, ", ");
3175 result
= PRINT_SRC_AND_LOC
;
3178 case bp_shlib_event
:
3179 /* Did we stop because the user set the stop_on_solib_events
3180 variable? (If so, we report this as a generic, "Stopped due
3181 to shlib event" message.) */
3182 printf_filtered (_("Stopped due to shared library event\n"));
3183 result
= PRINT_NOTHING
;
3186 case bp_thread_event
:
3187 /* Not sure how we will get here.
3188 GDB should not stop for these breakpoints. */
3189 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3190 result
= PRINT_NOTHING
;
3193 case bp_overlay_event
:
3194 /* By analogy with the thread event, GDB should not stop for these. */
3195 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3196 result
= PRINT_NOTHING
;
3199 case bp_longjmp_master
:
3200 /* These should never be enabled. */
3201 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3202 result
= PRINT_NOTHING
;
3206 case bp_hardware_watchpoint
:
3207 annotate_watchpoint (b
->number
);
3208 if (ui_out_is_mi_like_p (uiout
))
3211 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3213 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3214 ui_out_text (uiout
, "\nOld value = ");
3215 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3216 ui_out_field_stream (uiout
, "old", stb
);
3217 ui_out_text (uiout
, "\nNew value = ");
3218 watchpoint_value_print (b
->val
, stb
->stream
);
3219 ui_out_field_stream (uiout
, "new", stb
);
3220 ui_out_text (uiout
, "\n");
3221 /* More than one watchpoint may have been triggered. */
3222 result
= PRINT_UNKNOWN
;
3225 case bp_read_watchpoint
:
3226 if (ui_out_is_mi_like_p (uiout
))
3229 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3231 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3232 ui_out_text (uiout
, "\nValue = ");
3233 watchpoint_value_print (b
->val
, stb
->stream
);
3234 ui_out_field_stream (uiout
, "value", stb
);
3235 ui_out_text (uiout
, "\n");
3236 result
= PRINT_UNKNOWN
;
3239 case bp_access_watchpoint
:
3240 if (bs
->old_val
!= NULL
)
3242 annotate_watchpoint (b
->number
);
3243 if (ui_out_is_mi_like_p (uiout
))
3246 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3248 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3249 ui_out_text (uiout
, "\nOld value = ");
3250 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3251 ui_out_field_stream (uiout
, "old", stb
);
3252 ui_out_text (uiout
, "\nNew value = ");
3257 if (ui_out_is_mi_like_p (uiout
))
3260 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3261 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3262 ui_out_text (uiout
, "\nValue = ");
3264 watchpoint_value_print (b
->val
, stb
->stream
);
3265 ui_out_field_stream (uiout
, "new", stb
);
3266 ui_out_text (uiout
, "\n");
3267 result
= PRINT_UNKNOWN
;
3270 /* Fall through, we don't deal with these types of breakpoints
3274 if (ui_out_is_mi_like_p (uiout
))
3277 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3278 result
= PRINT_UNKNOWN
;
3282 if (ui_out_is_mi_like_p (uiout
))
3285 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3286 result
= PRINT_UNKNOWN
;
3291 case bp_longjmp_resume
:
3292 case bp_step_resume
:
3293 case bp_watchpoint_scope
:
3296 case bp_fast_tracepoint
:
3299 result
= PRINT_UNKNOWN
;
3303 do_cleanups (old_chain
);
3307 /* Generic routine for printing messages indicating why we
3308 stopped. The behavior of this function depends on the value
3309 'print_it' in the bpstat structure. Under some circumstances we
3310 may decide not to print anything here and delegate the task to
3313 static enum print_stop_action
3314 print_bp_stop_message (bpstat bs
)
3316 switch (bs
->print_it
)
3319 /* Nothing should be printed for this bpstat entry. */
3320 return PRINT_UNKNOWN
;
3324 /* We still want to print the frame, but we already printed the
3325 relevant messages. */
3326 return PRINT_SRC_AND_LOC
;
3329 case print_it_normal
:
3331 const struct bp_location
*bl
= bs
->breakpoint_at
;
3332 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3334 /* Normal case. Call the breakpoint's print_it method, or
3335 print_it_typical. */
3336 /* FIXME: how breakpoint can ever be NULL here? */
3337 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3338 return b
->ops
->print_it (b
);
3340 return print_it_typical (bs
);
3345 internal_error (__FILE__
, __LINE__
,
3346 _("print_bp_stop_message: unrecognized enum value"));
3351 /* Print a message indicating what happened. This is called from
3352 normal_stop(). The input to this routine is the head of the bpstat
3353 list - a list of the eventpoints that caused this stop. This
3354 routine calls the generic print routine for printing a message
3355 about reasons for stopping. This will print (for example) the
3356 "Breakpoint n," part of the output. The return value of this
3359 PRINT_UNKNOWN: Means we printed nothing
3360 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3361 code to print the location. An example is
3362 "Breakpoint 1, " which should be followed by
3364 PRINT_SRC_ONLY: Means we printed something, but there is no need
3365 to also print the location part of the message.
3366 An example is the catch/throw messages, which
3367 don't require a location appended to the end.
3368 PRINT_NOTHING: We have done some printing and we don't need any
3369 further info to be printed.*/
3371 enum print_stop_action
3372 bpstat_print (bpstat bs
)
3376 /* Maybe another breakpoint in the chain caused us to stop.
3377 (Currently all watchpoints go on the bpstat whether hit or not.
3378 That probably could (should) be changed, provided care is taken
3379 with respect to bpstat_explains_signal). */
3380 for (; bs
; bs
= bs
->next
)
3382 val
= print_bp_stop_message (bs
);
3383 if (val
== PRINT_SRC_ONLY
3384 || val
== PRINT_SRC_AND_LOC
3385 || val
== PRINT_NOTHING
)
3389 /* We reached the end of the chain, or we got a null BS to start
3390 with and nothing was printed. */
3391 return PRINT_UNKNOWN
;
3394 /* Evaluate the expression EXP and return 1 if value is zero.
3395 This is used inside a catch_errors to evaluate the breakpoint condition.
3396 The argument is a "struct expression *" that has been cast to char * to
3397 make it pass through catch_errors. */
3400 breakpoint_cond_eval (void *exp
)
3402 struct value
*mark
= value_mark ();
3403 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3404 value_free_to_mark (mark
);
3408 /* Allocate a new bpstat and chain it to the current one. */
3411 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3415 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3417 bs
->breakpoint_at
= bl
;
3418 /* If the condition is false, etc., don't do the commands. */
3419 bs
->commands
= NULL
;
3420 bs
->commands_left
= NULL
;
3422 bs
->print_it
= print_it_normal
;
3426 /* The target has stopped with waitstatus WS. Check if any hardware
3427 watchpoints have triggered, according to the target. */
3430 watchpoints_triggered (struct target_waitstatus
*ws
)
3432 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3434 struct breakpoint
*b
;
3436 if (!stopped_by_watchpoint
)
3438 /* We were not stopped by a watchpoint. Mark all watchpoints
3439 as not triggered. */
3441 if (b
->type
== bp_hardware_watchpoint
3442 || b
->type
== bp_read_watchpoint
3443 || b
->type
== bp_access_watchpoint
)
3444 b
->watchpoint_triggered
= watch_triggered_no
;
3449 if (!target_stopped_data_address (¤t_target
, &addr
))
3451 /* We were stopped by a watchpoint, but we don't know where.
3452 Mark all watchpoints as unknown. */
3454 if (b
->type
== bp_hardware_watchpoint
3455 || b
->type
== bp_read_watchpoint
3456 || b
->type
== bp_access_watchpoint
)
3457 b
->watchpoint_triggered
= watch_triggered_unknown
;
3459 return stopped_by_watchpoint
;
3462 /* The target could report the data address. Mark watchpoints
3463 affected by this data address as triggered, and all others as not
3467 if (b
->type
== bp_hardware_watchpoint
3468 || b
->type
== bp_read_watchpoint
3469 || b
->type
== bp_access_watchpoint
)
3471 struct bp_location
*loc
;
3474 b
->watchpoint_triggered
= watch_triggered_no
;
3475 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3476 /* Exact match not required. Within range is
3478 if (target_watchpoint_addr_within_range (¤t_target
,
3482 b
->watchpoint_triggered
= watch_triggered_yes
;
3490 /* Possible return values for watchpoint_check (this can't be an enum
3491 because of check_errors). */
3492 /* The watchpoint has been deleted. */
3493 #define WP_DELETED 1
3494 /* The value has changed. */
3495 #define WP_VALUE_CHANGED 2
3496 /* The value has not changed. */
3497 #define WP_VALUE_NOT_CHANGED 3
3498 /* Ignore this watchpoint, no matter if the value changed or not. */
3501 #define BP_TEMPFLAG 1
3502 #define BP_HARDWAREFLAG 2
3504 /* Evaluate watchpoint condition expression and check if its value changed.
3506 P should be a pointer to struct bpstat, but is defined as a void *
3507 in order for this function to be usable with catch_errors. */
3510 watchpoint_check (void *p
)
3512 bpstat bs
= (bpstat
) p
;
3513 struct breakpoint
*b
;
3514 struct frame_info
*fr
;
3515 int within_current_scope
;
3517 b
= bs
->breakpoint_at
->owner
;
3519 /* If this is a local watchpoint, we only want to check if the
3520 watchpoint frame is in scope if the current thread is the thread
3521 that was used to create the watchpoint. */
3522 if (!watchpoint_in_thread_scope (b
))
3525 if (b
->exp_valid_block
== NULL
)
3526 within_current_scope
= 1;
3529 struct frame_info
*frame
= get_current_frame ();
3530 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3531 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3533 /* in_function_epilogue_p() returns a non-zero value if we're still
3534 in the function but the stack frame has already been invalidated.
3535 Since we can't rely on the values of local variables after the
3536 stack has been destroyed, we are treating the watchpoint in that
3537 state as `not changed' without further checking. Don't mark
3538 watchpoints as changed if the current frame is in an epilogue -
3539 even if they are in some other frame, our view of the stack
3540 is likely to be wrong and frame_find_by_id could error out. */
3541 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3544 fr
= frame_find_by_id (b
->watchpoint_frame
);
3545 within_current_scope
= (fr
!= NULL
);
3547 /* If we've gotten confused in the unwinder, we might have
3548 returned a frame that can't describe this variable. */
3549 if (within_current_scope
)
3551 struct symbol
*function
;
3553 function
= get_frame_function (fr
);
3554 if (function
== NULL
3555 || !contained_in (b
->exp_valid_block
,
3556 SYMBOL_BLOCK_VALUE (function
)))
3557 within_current_scope
= 0;
3560 if (within_current_scope
)
3561 /* If we end up stopping, the current frame will get selected
3562 in normal_stop. So this call to select_frame won't affect
3567 if (within_current_scope
)
3569 /* We use value_{,free_to_}mark because it could be a
3570 *long* time before we return to the command level and
3571 call free_all_values. We can't call free_all_values because
3572 we might be in the middle of evaluating a function call. */
3574 struct value
*mark
= value_mark ();
3575 struct value
*new_val
;
3577 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3579 /* We use value_equal_contents instead of value_equal because the latter
3580 coerces an array to a pointer, thus comparing just the address of the
3581 array instead of its contents. This is not what we want. */
3582 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3583 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3585 if (new_val
!= NULL
)
3587 release_value (new_val
);
3588 value_free_to_mark (mark
);
3590 bs
->old_val
= b
->val
;
3593 return WP_VALUE_CHANGED
;
3597 /* Nothing changed. */
3598 value_free_to_mark (mark
);
3599 return WP_VALUE_NOT_CHANGED
;
3604 /* This seems like the only logical thing to do because
3605 if we temporarily ignored the watchpoint, then when
3606 we reenter the block in which it is valid it contains
3607 garbage (in the case of a function, it may have two
3608 garbage values, one before and one after the prologue).
3609 So we can't even detect the first assignment to it and
3610 watch after that (since the garbage may or may not equal
3611 the first value assigned). */
3612 /* We print all the stop information in print_it_typical(), but
3613 in this case, by the time we call print_it_typical() this bp
3614 will be deleted already. So we have no choice but print the
3615 information here. */
3616 if (ui_out_is_mi_like_p (uiout
))
3618 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3619 ui_out_text (uiout
, "\nWatchpoint ");
3620 ui_out_field_int (uiout
, "wpnum", b
->number
);
3621 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3622 which its expression is valid.\n");
3624 if (b
->related_breakpoint
)
3626 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3627 b
->related_breakpoint
->related_breakpoint
= NULL
;
3628 b
->related_breakpoint
= NULL
;
3630 b
->disposition
= disp_del_at_next_stop
;
3636 /* Return true if it looks like target has stopped due to hitting
3637 breakpoint location BL. This function does not check if we
3638 should stop, only if BL explains the stop. */
3640 bpstat_check_location (const struct bp_location
*bl
,
3641 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3643 struct breakpoint
*b
= bl
->owner
;
3645 /* By definition, the inferior does not report stops at
3647 if (tracepoint_type (b
))
3650 if (b
->type
!= bp_watchpoint
3651 && b
->type
!= bp_hardware_watchpoint
3652 && b
->type
!= bp_read_watchpoint
3653 && b
->type
!= bp_access_watchpoint
3654 && b
->type
!= bp_hardware_breakpoint
3655 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3657 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3660 if (overlay_debugging
/* unmapped overlay section */
3661 && section_is_overlay (bl
->section
)
3662 && !section_is_mapped (bl
->section
))
3666 /* Continuable hardware watchpoints are treated as non-existent if the
3667 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3668 some data address). Otherwise gdb won't stop on a break instruction
3669 in the code (not from a breakpoint) when a hardware watchpoint has
3670 been defined. Also skip watchpoints which we know did not trigger
3671 (did not match the data address). */
3673 if ((b
->type
== bp_hardware_watchpoint
3674 || b
->type
== bp_read_watchpoint
3675 || b
->type
== bp_access_watchpoint
)
3676 && b
->watchpoint_triggered
== watch_triggered_no
)
3679 if (b
->type
== bp_hardware_breakpoint
)
3681 if (bl
->address
!= bp_addr
)
3683 if (overlay_debugging
/* unmapped overlay section */
3684 && section_is_overlay (bl
->section
)
3685 && !section_is_mapped (bl
->section
))
3689 if (b
->type
== bp_catchpoint
)
3691 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3692 if (!b
->ops
->breakpoint_hit (b
))
3699 /* If BS refers to a watchpoint, determine if the watched values
3700 has actually changed, and we should stop. If not, set BS->stop
3703 bpstat_check_watchpoint (bpstat bs
)
3705 const struct bp_location
*bl
= bs
->breakpoint_at
;
3706 struct breakpoint
*b
= bl
->owner
;
3708 if (b
->type
== bp_watchpoint
3709 || b
->type
== bp_read_watchpoint
3710 || b
->type
== bp_access_watchpoint
3711 || b
->type
== bp_hardware_watchpoint
)
3715 int must_check_value
= 0;
3717 if (b
->type
== bp_watchpoint
)
3718 /* For a software watchpoint, we must always check the
3720 must_check_value
= 1;
3721 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3722 /* We have a hardware watchpoint (read, write, or access)
3723 and the target earlier reported an address watched by
3725 must_check_value
= 1;
3726 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3727 && b
->type
== bp_hardware_watchpoint
)
3728 /* We were stopped by a hardware watchpoint, but the target could
3729 not report the data address. We must check the watchpoint's
3730 value. Access and read watchpoints are out of luck; without
3731 a data address, we can't figure it out. */
3732 must_check_value
= 1;
3734 if (must_check_value
)
3736 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3738 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3739 int e
= catch_errors (watchpoint_check
, bs
, message
,
3741 do_cleanups (cleanups
);
3745 /* We've already printed what needs to be printed. */
3746 bs
->print_it
= print_it_done
;
3750 bs
->print_it
= print_it_noop
;
3753 case WP_VALUE_CHANGED
:
3754 if (b
->type
== bp_read_watchpoint
)
3756 /* There are two cases to consider here:
3758 1. we're watching the triggered memory for reads.
3759 In that case, trust the target, and always report
3760 the watchpoint hit to the user. Even though
3761 reads don't cause value changes, the value may
3762 have changed since the last time it was read, and
3763 since we're not trapping writes, we will not see
3764 those, and as such we should ignore our notion of
3767 2. we're watching the triggered memory for both
3768 reads and writes. There are two ways this may
3771 2.1. this is a target that can't break on data
3772 reads only, but can break on accesses (reads or
3773 writes), such as e.g., x86. We detect this case
3774 at the time we try to insert read watchpoints.
3776 2.2. otherwise, the target supports read
3777 watchpoints, but, the user set an access or write
3778 watchpoint watching the same memory as this read
3781 If we're watching memory writes as well as reads,
3782 ignore watchpoint hits when we find that the
3783 value hasn't changed, as reads don't cause
3784 changes. This still gives false positives when
3785 the program writes the same value to memory as
3786 what there was already in memory (we will confuse
3787 it for a read), but it's much better than
3790 int other_write_watchpoint
= 0;
3792 if (bl
->watchpoint_type
== hw_read
)
3794 struct breakpoint
*other_b
;
3796 ALL_BREAKPOINTS (other_b
)
3797 if ((other_b
->type
== bp_hardware_watchpoint
3798 || other_b
->type
== bp_access_watchpoint
)
3799 && (other_b
->watchpoint_triggered
3800 == watch_triggered_yes
))
3802 other_write_watchpoint
= 1;
3807 if (other_write_watchpoint
3808 || bl
->watchpoint_type
== hw_access
)
3810 /* We're watching the same memory for writes,
3811 and the value changed since the last time we
3812 updated it, so this trap must be for a write.
3814 bs
->print_it
= print_it_noop
;
3819 case WP_VALUE_NOT_CHANGED
:
3820 if (b
->type
== bp_hardware_watchpoint
3821 || b
->type
== bp_watchpoint
)
3823 /* Don't stop: write watchpoints shouldn't fire if
3824 the value hasn't changed. */
3825 bs
->print_it
= print_it_noop
;
3833 /* Error from catch_errors. */
3834 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3835 if (b
->related_breakpoint
)
3836 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3837 b
->disposition
= disp_del_at_next_stop
;
3838 /* We've already printed what needs to be printed. */
3839 bs
->print_it
= print_it_done
;
3843 else /* must_check_value == 0 */
3845 /* This is a case where some watchpoint(s) triggered, but
3846 not at the address of this watchpoint, or else no
3847 watchpoint triggered after all. So don't print
3848 anything for this watchpoint. */
3849 bs
->print_it
= print_it_noop
;
3856 /* Check conditions (condition proper, frame, thread and ignore count)
3857 of breakpoint referred to by BS. If we should not stop for this
3858 breakpoint, set BS->stop to 0. */
3860 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3862 int thread_id
= pid_to_thread_id (ptid
);
3863 const struct bp_location
*bl
= bs
->breakpoint_at
;
3864 struct breakpoint
*b
= bl
->owner
;
3866 if (frame_id_p (b
->frame_id
)
3867 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3871 int value_is_zero
= 0;
3872 struct expression
*cond
;
3874 /* If this is a scope breakpoint, mark the associated
3875 watchpoint as triggered so that we will handle the
3876 out-of-scope event. We'll get to the watchpoint next
3878 if (b
->type
== bp_watchpoint_scope
)
3879 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3881 if (is_watchpoint (b
))
3886 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3888 int within_current_scope
= 1;
3890 /* We use value_mark and value_free_to_mark because it could
3891 be a long time before we return to the command level and
3892 call free_all_values. We can't call free_all_values
3893 because we might be in the middle of evaluating a
3895 struct value
*mark
= value_mark ();
3897 /* Need to select the frame, with all that implies so that
3898 the conditions will have the right context. Because we
3899 use the frame, we will not see an inlined function's
3900 variables when we arrive at a breakpoint at the start
3901 of the inlined function; the current frame will be the
3903 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3904 select_frame (get_current_frame ());
3907 struct frame_info
*frame
;
3909 /* For local watchpoint expressions, which particular
3910 instance of a local is being watched matters, so we
3911 keep track of the frame to evaluate the expression
3912 in. To evaluate the condition however, it doesn't
3913 really matter which instantiation of the function
3914 where the condition makes sense triggers the
3915 watchpoint. This allows an expression like "watch
3916 global if q > 10" set in `func', catch writes to
3917 global on all threads that call `func', or catch
3918 writes on all recursive calls of `func' by a single
3919 thread. We simply always evaluate the condition in
3920 the innermost frame that's executing where it makes
3921 sense to evaluate the condition. It seems
3923 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3925 select_frame (frame
);
3927 within_current_scope
= 0;
3929 if (within_current_scope
)
3931 = catch_errors (breakpoint_cond_eval
, cond
,
3932 "Error in testing breakpoint condition:\n",
3936 warning (_("Watchpoint condition cannot be tested "
3937 "in the current scope"));
3938 /* If we failed to set the right context for this
3939 watchpoint, unconditionally report it. */
3942 /* FIXME-someday, should give breakpoint # */
3943 value_free_to_mark (mark
);
3946 if (cond
&& value_is_zero
)
3950 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3954 else if (b
->ignore_count
> 0)
3957 annotate_ignore_count_change ();
3959 /* Increase the hit count even though we don't
3967 /* Get a bpstat associated with having just stopped at address
3968 BP_ADDR in thread PTID.
3970 Determine whether we stopped at a breakpoint, etc, or whether we
3971 don't understand this stop. Result is a chain of bpstat's such that:
3973 if we don't understand the stop, the result is a null pointer.
3975 if we understand why we stopped, the result is not null.
3977 Each element of the chain refers to a particular breakpoint or
3978 watchpoint at which we have stopped. (We may have stopped for
3979 several reasons concurrently.)
3981 Each element of the chain has valid next, breakpoint_at,
3982 commands, FIXME??? fields. */
3985 bpstat_stop_status (struct address_space
*aspace
,
3986 CORE_ADDR bp_addr
, ptid_t ptid
)
3988 struct breakpoint
*b
= NULL
;
3989 struct bp_location
*bl
, **blp_tmp
;
3990 struct bp_location
*loc
;
3991 /* Root of the chain of bpstat's */
3992 struct bpstats root_bs
[1];
3993 /* Pointer to the last thing in the chain currently. */
3994 bpstat bs
= root_bs
;
3996 int need_remove_insert
;
3998 /* ALL_BP_LOCATIONS iteration would break across
3999 update_global_location_list possibly executed by
4000 bpstat_check_breakpoint_conditions's inferior call. */
4004 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4007 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4009 /* For hardware watchpoints, we look only at the first location.
4010 The watchpoint_check function will work on entire expression,
4011 not the individual locations. For read watchopints, the
4012 watchpoints_triggered function have checked all locations
4014 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4017 if (bl
->shlib_disabled
)
4020 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4023 /* Come here if it's a watchpoint, or if the break address matches */
4025 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
4027 /* Assume we stop. Should we find watchpoint that is not actually
4028 triggered, or if condition of breakpoint is false, we'll reset
4033 bpstat_check_watchpoint (bs
);
4037 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4038 || b
->type
== bp_longjmp_master
)
4039 /* We do not stop for these. */
4042 bpstat_check_breakpoint_conditions (bs
, ptid
);
4048 /* We will stop here */
4049 if (b
->disposition
== disp_disable
)
4051 if (b
->enable_state
!= bp_permanent
)
4052 b
->enable_state
= bp_disabled
;
4053 update_global_location_list (0);
4057 bs
->commands
= b
->commands
;
4058 incref_counted_command_line (bs
->commands
);
4059 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4060 if (bs
->commands_left
4061 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4064 bs
->commands_left
->line
) == 0)))
4066 bs
->commands_left
= bs
->commands_left
->next
;
4071 /* Print nothing for this entry if we dont stop or dont print. */
4072 if (bs
->stop
== 0 || bs
->print
== 0)
4073 bs
->print_it
= print_it_noop
;
4077 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4079 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4082 bs
= bpstat_alloc (loc
, bs
);
4083 /* For hits of moribund locations, we should just proceed. */
4086 bs
->print_it
= print_it_noop
;
4090 bs
->next
= NULL
; /* Terminate the chain */
4092 /* If we aren't stopping, the value of some hardware watchpoint may
4093 not have changed, but the intermediate memory locations we are
4094 watching may have. Don't bother if we're stopping; this will get
4096 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4100 need_remove_insert
= 0;
4102 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4104 && bs
->breakpoint_at
->owner
4105 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4107 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4108 /* Updating watchpoints invalidates bs->breakpoint_at.
4109 Prevent further code from trying to use it. */
4110 bs
->breakpoint_at
= NULL
;
4111 need_remove_insert
= 1;
4114 if (need_remove_insert
)
4115 update_global_location_list (1);
4117 return root_bs
->next
;
4120 /* Tell what to do about this bpstat. */
4122 bpstat_what (bpstat bs
)
4124 /* Classify each bpstat as one of the following. */
4127 /* This bpstat element has no effect on the main_action. */
4130 /* There was a watchpoint, stop but don't print. */
4133 /* There was a watchpoint, stop and print. */
4136 /* There was a breakpoint but we're not stopping. */
4139 /* There was a breakpoint, stop but don't print. */
4142 /* There was a breakpoint, stop and print. */
4145 /* We hit the longjmp breakpoint. */
4148 /* We hit the longjmp_resume breakpoint. */
4151 /* We hit the step_resume breakpoint. */
4154 /* We hit the shared library event breakpoint. */
4157 /* We hit the jit event breakpoint. */
4160 /* This is just used to count how many enums there are. */
4164 /* Here is the table which drives this routine. So that we can
4165 format it pretty, we define some abbreviations for the
4166 enum bpstat_what codes. */
4167 #define kc BPSTAT_WHAT_KEEP_CHECKING
4168 #define ss BPSTAT_WHAT_STOP_SILENT
4169 #define sn BPSTAT_WHAT_STOP_NOISY
4170 #define sgl BPSTAT_WHAT_SINGLE
4171 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4172 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4173 #define sr BPSTAT_WHAT_STEP_RESUME
4174 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4175 #define jit BPSTAT_WHAT_CHECK_JIT
4177 /* "Can't happen." Might want to print an error message.
4178 abort() is not out of the question, but chances are GDB is just
4179 a bit confused, not unusable. */
4180 #define err BPSTAT_WHAT_STOP_NOISY
4182 /* Given an old action and a class, come up with a new action. */
4183 /* One interesting property of this table is that wp_silent is the same
4184 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4185 after stopping, the check for whether to step over a breakpoint
4186 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4187 reference to how we stopped. We retain separate wp_silent and
4188 bp_silent codes in case we want to change that someday.
4190 Another possibly interesting property of this table is that
4191 there's a partial ordering, priority-like, of the actions. Once
4192 you've decided that some action is appropriate, you'll never go
4193 back and decide something of a lower priority is better. The
4196 kc < jit clr sgl shl slr sn sr ss
4197 sgl < jit shl slr sn sr ss
4198 slr < jit err shl sn sr ss
4199 clr < jit err shl sn sr ss
4206 What I think this means is that we don't need a damned table
4207 here. If you just put the rows and columns in the right order,
4208 it'd look awfully regular. We could simply walk the bpstat list
4209 and choose the highest priority action we find, with a little
4210 logic to handle the 'err' cases. */
4212 /* step_resume entries: a step resume breakpoint overrides another
4213 breakpoint of signal handling (see comment in wait_for_inferior
4214 at where we set the step_resume breakpoint). */
4216 static const enum bpstat_what_main_action
4217 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4220 /* kc ss sn sgl slr clr sr shl jit */
4221 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4222 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4223 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4224 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4225 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4226 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4227 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4228 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4229 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4230 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4231 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4245 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4246 struct bpstat_what retval
;
4248 retval
.call_dummy
= 0;
4249 for (; bs
!= NULL
; bs
= bs
->next
)
4251 enum class bs_class
= no_effect
;
4252 if (bs
->breakpoint_at
== NULL
)
4253 /* I suspect this can happen if it was a momentary breakpoint
4254 which has since been deleted. */
4256 if (bs
->breakpoint_at
->owner
== NULL
)
4257 bs_class
= bp_nostop
;
4259 switch (bs
->breakpoint_at
->owner
->type
)
4265 case bp_hardware_breakpoint
:
4271 bs_class
= bp_noisy
;
4273 bs_class
= bp_silent
;
4276 bs_class
= bp_nostop
;
4279 case bp_hardware_watchpoint
:
4280 case bp_read_watchpoint
:
4281 case bp_access_watchpoint
:
4285 bs_class
= wp_noisy
;
4287 bs_class
= wp_silent
;
4290 /* There was a watchpoint, but we're not stopping.
4291 This requires no further action. */
4292 bs_class
= no_effect
;
4295 bs_class
= long_jump
;
4297 case bp_longjmp_resume
:
4298 bs_class
= long_resume
;
4300 case bp_step_resume
:
4303 bs_class
= step_resume
;
4306 /* It is for the wrong frame. */
4307 bs_class
= bp_nostop
;
4309 case bp_watchpoint_scope
:
4310 bs_class
= bp_nostop
;
4312 case bp_shlib_event
:
4313 bs_class
= shlib_event
;
4316 bs_class
= jit_event
;
4318 case bp_thread_event
:
4319 case bp_overlay_event
:
4320 case bp_longjmp_master
:
4321 bs_class
= bp_nostop
;
4327 bs_class
= bp_noisy
;
4329 bs_class
= bp_silent
;
4332 /* There was a catchpoint, but we're not stopping.
4333 This requires no further action. */
4334 bs_class
= no_effect
;
4337 /* Make sure the action is stop (silent or noisy),
4338 so infrun.c pops the dummy frame. */
4339 bs_class
= bp_silent
;
4340 retval
.call_dummy
= 1;
4343 case bp_fast_tracepoint
:
4344 /* Tracepoint hits should not be reported back to GDB, and
4345 if one got through somehow, it should have been filtered
4347 internal_error (__FILE__
, __LINE__
,
4348 _("bpstat_what: tracepoint encountered"));
4351 current_action
= table
[(int) bs_class
][(int) current_action
];
4353 retval
.main_action
= current_action
;
4357 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4358 without hardware support). This isn't related to a specific bpstat,
4359 just to things like whether watchpoints are set. */
4362 bpstat_should_step (void)
4364 struct breakpoint
*b
;
4366 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4372 bpstat_causes_stop (bpstat bs
)
4374 for (; bs
!= NULL
; bs
= bs
->next
)
4383 /* Print the LOC location out of the list of B->LOC locations. */
4385 static void print_breakpoint_location (struct breakpoint
*b
,
4386 struct bp_location
*loc
,
4388 struct ui_stream
*stb
)
4390 struct cleanup
*old_chain
= save_current_program_space ();
4392 if (loc
!= NULL
&& loc
->shlib_disabled
)
4396 set_current_program_space (loc
->pspace
);
4398 if (b
->source_file
&& loc
)
4401 = find_pc_sect_function (loc
->address
, loc
->section
);
4404 ui_out_text (uiout
, "in ");
4405 ui_out_field_string (uiout
, "func",
4406 SYMBOL_PRINT_NAME (sym
));
4407 ui_out_wrap_hint (uiout
, wrap_indent
);
4408 ui_out_text (uiout
, " at ");
4410 ui_out_field_string (uiout
, "file", b
->source_file
);
4411 ui_out_text (uiout
, ":");
4413 if (ui_out_is_mi_like_p (uiout
))
4415 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4416 char *fullname
= symtab_to_fullname (sal
.symtab
);
4419 ui_out_field_string (uiout
, "fullname", fullname
);
4422 ui_out_field_int (uiout
, "line", b
->line_number
);
4426 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4428 ui_out_field_stream (uiout
, "at", stb
);
4431 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4433 do_cleanups (old_chain
);
4436 /* Print B to gdb_stdout. */
4438 print_one_breakpoint_location (struct breakpoint
*b
,
4439 struct bp_location
*loc
,
4441 struct bp_location
**last_loc
,
4442 int print_address_bits
,
4445 struct command_line
*l
;
4447 struct ep_type_description
4452 static struct ep_type_description bptypes
[] =
4454 {bp_none
, "?deleted?"},
4455 {bp_breakpoint
, "breakpoint"},
4456 {bp_hardware_breakpoint
, "hw breakpoint"},
4457 {bp_until
, "until"},
4458 {bp_finish
, "finish"},
4459 {bp_watchpoint
, "watchpoint"},
4460 {bp_hardware_watchpoint
, "hw watchpoint"},
4461 {bp_read_watchpoint
, "read watchpoint"},
4462 {bp_access_watchpoint
, "acc watchpoint"},
4463 {bp_longjmp
, "longjmp"},
4464 {bp_longjmp_resume
, "longjmp resume"},
4465 {bp_step_resume
, "step resume"},
4466 {bp_watchpoint_scope
, "watchpoint scope"},
4467 {bp_call_dummy
, "call dummy"},
4468 {bp_shlib_event
, "shlib events"},
4469 {bp_thread_event
, "thread events"},
4470 {bp_overlay_event
, "overlay events"},
4471 {bp_longjmp_master
, "longjmp master"},
4472 {bp_catchpoint
, "catchpoint"},
4473 {bp_tracepoint
, "tracepoint"},
4474 {bp_fast_tracepoint
, "fast tracepoint"},
4475 {bp_jit_event
, "jit events"},
4478 static char bpenables
[] = "nynny";
4479 char wrap_indent
[80];
4480 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4481 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4482 struct cleanup
*bkpt_chain
;
4484 int header_of_multiple
= 0;
4485 int part_of_multiple
= (loc
!= NULL
);
4486 struct value_print_options opts
;
4488 get_user_print_options (&opts
);
4490 gdb_assert (!loc
|| loc_number
!= 0);
4491 /* See comment in print_one_breakpoint concerning
4492 treatment of breakpoints with single disabled
4496 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4497 header_of_multiple
= 1;
4502 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4506 if (part_of_multiple
)
4509 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4510 ui_out_field_string (uiout
, "number", formatted
);
4515 ui_out_field_int (uiout
, "number", b
->number
);
4520 if (part_of_multiple
)
4521 ui_out_field_skip (uiout
, "type");
4524 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4525 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4526 internal_error (__FILE__
, __LINE__
,
4527 _("bptypes table does not describe type #%d."),
4529 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4534 if (part_of_multiple
)
4535 ui_out_field_skip (uiout
, "disp");
4537 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4542 if (part_of_multiple
)
4543 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4545 ui_out_field_fmt (uiout
, "enabled", "%c",
4546 bpenables
[(int) b
->enable_state
]);
4547 ui_out_spaces (uiout
, 2);
4551 strcpy (wrap_indent
, " ");
4552 if (opts
.addressprint
)
4554 if (print_address_bits
<= 32)
4555 strcat (wrap_indent
, " ");
4557 strcat (wrap_indent
, " ");
4560 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4562 /* Although the print_one can possibly print
4563 all locations, calling it here is not likely
4564 to get any nice result. So, make sure there's
4565 just one location. */
4566 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4567 b
->ops
->print_one (b
, last_loc
);
4573 internal_error (__FILE__
, __LINE__
,
4574 _("print_one_breakpoint: bp_none encountered\n"));
4578 case bp_hardware_watchpoint
:
4579 case bp_read_watchpoint
:
4580 case bp_access_watchpoint
:
4581 /* Field 4, the address, is omitted (which makes the columns
4582 not line up too nicely with the headers, but the effect
4583 is relatively readable). */
4584 if (opts
.addressprint
)
4585 ui_out_field_skip (uiout
, "addr");
4587 ui_out_field_string (uiout
, "what", b
->exp_string
);
4591 case bp_hardware_breakpoint
:
4595 case bp_longjmp_resume
:
4596 case bp_step_resume
:
4597 case bp_watchpoint_scope
:
4599 case bp_shlib_event
:
4600 case bp_thread_event
:
4601 case bp_overlay_event
:
4602 case bp_longjmp_master
:
4604 case bp_fast_tracepoint
:
4606 if (opts
.addressprint
)
4609 if (header_of_multiple
)
4610 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4611 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4612 ui_out_field_string (uiout
, "addr", "<PENDING>");
4614 ui_out_field_core_addr (uiout
, "addr",
4615 loc
->gdbarch
, loc
->address
);
4618 if (!header_of_multiple
)
4619 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4626 /* For backward compatibility, don't display inferiors unless there
4629 && !header_of_multiple
4631 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4632 && (number_of_program_spaces () > 1
4633 || number_of_inferiors () > 1)
4634 && loc
->owner
->type
!= bp_catchpoint
)))
4636 struct inferior
*inf
;
4639 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4641 if (inf
->pspace
== loc
->pspace
)
4646 ui_out_text (uiout
, " inf ");
4649 ui_out_text (uiout
, ", ");
4650 ui_out_text (uiout
, plongest (inf
->num
));
4655 if (!part_of_multiple
)
4657 if (b
->thread
!= -1)
4659 /* FIXME: This seems to be redundant and lost here; see the
4660 "stop only in" line a little further down. */
4661 ui_out_text (uiout
, " thread ");
4662 ui_out_field_int (uiout
, "thread", b
->thread
);
4664 else if (b
->task
!= 0)
4666 ui_out_text (uiout
, " task ");
4667 ui_out_field_int (uiout
, "task", b
->task
);
4671 ui_out_text (uiout
, "\n");
4673 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4676 ui_out_text (uiout
, "\tstop only in stack frame at ");
4677 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4679 ui_out_field_core_addr (uiout
, "frame",
4680 b
->gdbarch
, b
->frame_id
.stack_addr
);
4681 ui_out_text (uiout
, "\n");
4684 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4686 /* We do not print the condition for Ada exception catchpoints
4687 because the condition is an internal implementation detail
4688 that we do not want to expose to the user. */
4690 if (tracepoint_type (b
))
4691 ui_out_text (uiout
, "\ttrace only if ");
4693 ui_out_text (uiout
, "\tstop only if ");
4694 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4695 ui_out_text (uiout
, "\n");
4698 if (!part_of_multiple
&& b
->thread
!= -1)
4700 /* FIXME should make an annotation for this */
4701 ui_out_text (uiout
, "\tstop only in thread ");
4702 ui_out_field_int (uiout
, "thread", b
->thread
);
4703 ui_out_text (uiout
, "\n");
4706 if (!part_of_multiple
&& b
->hit_count
)
4708 /* FIXME should make an annotation for this */
4709 if (ep_is_catchpoint (b
))
4710 ui_out_text (uiout
, "\tcatchpoint");
4712 ui_out_text (uiout
, "\tbreakpoint");
4713 ui_out_text (uiout
, " already hit ");
4714 ui_out_field_int (uiout
, "times", b
->hit_count
);
4715 if (b
->hit_count
== 1)
4716 ui_out_text (uiout
, " time\n");
4718 ui_out_text (uiout
, " times\n");
4721 /* Output the count also if it is zero, but only if this is
4722 mi. FIXME: Should have a better test for this. */
4723 if (ui_out_is_mi_like_p (uiout
))
4724 if (!part_of_multiple
&& b
->hit_count
== 0)
4725 ui_out_field_int (uiout
, "times", b
->hit_count
);
4727 if (!part_of_multiple
&& b
->ignore_count
)
4730 ui_out_text (uiout
, "\tignore next ");
4731 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4732 ui_out_text (uiout
, " hits\n");
4735 l
= b
->commands
? b
->commands
->commands
: NULL
;
4736 if (!part_of_multiple
&& l
)
4738 struct cleanup
*script_chain
;
4741 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4742 print_command_lines (uiout
, l
, 4);
4743 do_cleanups (script_chain
);
4746 if (!part_of_multiple
&& b
->pass_count
)
4748 annotate_field (10);
4749 ui_out_text (uiout
, "\tpass count ");
4750 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4751 ui_out_text (uiout
, " \n");
4754 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4757 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4758 else if (b
->exp_string
)
4759 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4762 do_cleanups (bkpt_chain
);
4763 do_cleanups (old_chain
);
4767 print_one_breakpoint (struct breakpoint
*b
,
4768 struct bp_location
**last_loc
, int print_address_bits
,
4771 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4772 print_address_bits
, allflag
);
4774 /* If this breakpoint has custom print function,
4775 it's already printed. Otherwise, print individual
4776 locations, if any. */
4777 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4779 /* If breakpoint has a single location that is
4780 disabled, we print it as if it had
4781 several locations, since otherwise it's hard to
4782 represent "breakpoint enabled, location disabled"
4784 Note that while hardware watchpoints have
4785 several locations internally, that's no a property
4788 && !is_hardware_watchpoint (b
)
4789 && (b
->loc
->next
|| !b
->loc
->enabled
)
4790 && !ui_out_is_mi_like_p (uiout
))
4792 struct bp_location
*loc
;
4794 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4795 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4796 print_address_bits
, allflag
);
4802 breakpoint_address_bits (struct breakpoint
*b
)
4804 int print_address_bits
= 0;
4805 struct bp_location
*loc
;
4807 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4811 /* Software watchpoints that aren't watching memory don't have
4812 an address to print. */
4813 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4816 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4817 if (addr_bit
> print_address_bits
)
4818 print_address_bits
= addr_bit
;
4821 return print_address_bits
;
4824 struct captured_breakpoint_query_args
4830 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4832 struct captured_breakpoint_query_args
*args
= data
;
4833 struct breakpoint
*b
;
4834 struct bp_location
*dummy_loc
= NULL
;
4837 if (args
->bnum
== b
->number
)
4839 int print_address_bits
= breakpoint_address_bits (b
);
4840 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4848 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4850 struct captured_breakpoint_query_args args
;
4852 /* For the moment we don't trust print_one_breakpoint() to not throw
4854 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4855 error_message
, RETURN_MASK_ALL
) < 0)
4861 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4862 catchpoints, et.al.). */
4865 user_settable_breakpoint (const struct breakpoint
*b
)
4867 return (b
->type
== bp_breakpoint
4868 || b
->type
== bp_catchpoint
4869 || b
->type
== bp_hardware_breakpoint
4870 || tracepoint_type (b
)
4871 || b
->type
== bp_watchpoint
4872 || b
->type
== bp_read_watchpoint
4873 || b
->type
== bp_access_watchpoint
4874 || b
->type
== bp_hardware_watchpoint
);
4877 /* Print information on user settable breakpoint (watchpoint, etc)
4878 number BNUM. If BNUM is -1 print all user settable breakpoints.
4879 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4882 breakpoint_1 (int bnum
, int allflag
)
4884 struct breakpoint
*b
;
4885 struct bp_location
*last_loc
= NULL
;
4886 int nr_printable_breakpoints
;
4887 struct cleanup
*bkpttbl_chain
;
4888 struct value_print_options opts
;
4889 int print_address_bits
= 0;
4891 get_user_print_options (&opts
);
4893 /* Compute the number of rows in the table, as well as the
4894 size required for address fields. */
4895 nr_printable_breakpoints
= 0;
4898 || bnum
== b
->number
)
4900 if (allflag
|| user_settable_breakpoint (b
))
4902 int addr_bit
= breakpoint_address_bits (b
);
4903 if (addr_bit
> print_address_bits
)
4904 print_address_bits
= addr_bit
;
4906 nr_printable_breakpoints
++;
4910 if (opts
.addressprint
)
4912 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4916 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4919 if (nr_printable_breakpoints
> 0)
4920 annotate_breakpoints_headers ();
4921 if (nr_printable_breakpoints
> 0)
4923 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4924 if (nr_printable_breakpoints
> 0)
4926 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4927 if (nr_printable_breakpoints
> 0)
4929 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4930 if (nr_printable_breakpoints
> 0)
4932 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4933 if (opts
.addressprint
)
4935 if (nr_printable_breakpoints
> 0)
4937 if (print_address_bits
<= 32)
4938 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4940 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4942 if (nr_printable_breakpoints
> 0)
4944 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4945 ui_out_table_body (uiout
);
4946 if (nr_printable_breakpoints
> 0)
4947 annotate_breakpoints_table ();
4953 || bnum
== b
->number
)
4955 /* We only print out user settable breakpoints unless the
4957 if (allflag
|| user_settable_breakpoint (b
))
4958 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
4962 do_cleanups (bkpttbl_chain
);
4964 if (nr_printable_breakpoints
== 0)
4967 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4969 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4974 if (last_loc
&& !server_command
)
4975 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4978 /* FIXME? Should this be moved up so that it is only called when
4979 there have been breakpoints? */
4980 annotate_breakpoints_table_end ();
4984 breakpoints_info (char *bnum_exp
, int from_tty
)
4989 bnum
= parse_and_eval_long (bnum_exp
);
4991 breakpoint_1 (bnum
, 0);
4995 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5000 bnum
= parse_and_eval_long (bnum_exp
);
5002 breakpoint_1 (bnum
, 1);
5006 breakpoint_has_pc (struct breakpoint
*b
,
5007 struct program_space
*pspace
,
5008 CORE_ADDR pc
, struct obj_section
*section
)
5010 struct bp_location
*bl
= b
->loc
;
5011 for (; bl
; bl
= bl
->next
)
5013 if (bl
->pspace
== pspace
5014 && bl
->address
== pc
5015 && (!overlay_debugging
|| bl
->section
== section
))
5021 /* Print a message describing any breakpoints set at PC. This
5022 concerns with logical breakpoints, so we match program spaces, not
5026 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5027 struct program_space
*pspace
, CORE_ADDR pc
,
5028 struct obj_section
*section
, int thread
)
5031 struct breakpoint
*b
;
5034 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5038 printf_filtered (_("Note: breakpoint "));
5039 else /* if (others == ???) */
5040 printf_filtered (_("Note: breakpoints "));
5042 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5045 printf_filtered ("%d", b
->number
);
5046 if (b
->thread
== -1 && thread
!= -1)
5047 printf_filtered (" (all threads)");
5048 else if (b
->thread
!= -1)
5049 printf_filtered (" (thread %d)", b
->thread
);
5050 printf_filtered ("%s%s ",
5051 ((b
->enable_state
== bp_disabled
5052 || b
->enable_state
== bp_call_disabled
5053 || b
->enable_state
== bp_startup_disabled
)
5055 : b
->enable_state
== bp_permanent
5059 : ((others
== 1) ? " and" : ""));
5061 printf_filtered (_("also set at pc "));
5062 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5063 printf_filtered (".\n");
5067 /* Set the default place to put a breakpoint
5068 for the `break' command with no arguments. */
5071 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5072 CORE_ADDR addr
, struct symtab
*symtab
,
5075 default_breakpoint_valid
= valid
;
5076 default_breakpoint_pspace
= pspace
;
5077 default_breakpoint_address
= addr
;
5078 default_breakpoint_symtab
= symtab
;
5079 default_breakpoint_line
= line
;
5082 /* Return true iff it is meaningful to use the address member of
5083 BPT. For some breakpoint types, the address member is irrelevant
5084 and it makes no sense to attempt to compare it to other addresses
5085 (or use it for any other purpose either).
5087 More specifically, each of the following breakpoint types will always
5088 have a zero valued address and we don't want to mark breakpoints of any of
5089 these types to be a duplicate of an actual breakpoint at address zero:
5097 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5099 enum bptype type
= bpt
->type
;
5101 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5104 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5105 true if LOC1 and LOC2 represent the same watchpoint location. */
5108 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5110 /* Note that this checks the owner's type, not the location's. In
5111 case the target does not support read watchpoints, but does
5112 support access watchpoints, we'll have bp_read_watchpoint
5113 watchpoints with hw_access locations. Those should be considered
5114 duplicates of hw_read locations. The hw_read locations will
5115 become hw_access locations later. */
5116 return (loc1
->owner
->type
== loc2
->owner
->type
5117 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5118 && loc1
->address
== loc2
->address
5119 && loc1
->length
== loc2
->length
);
5122 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5123 same breakpoint location. In most targets, this can only be true
5124 if ASPACE1 matches ASPACE2. On targets that have global
5125 breakpoints, the address space doesn't really matter. */
5128 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5129 struct address_space
*aspace2
, CORE_ADDR addr2
)
5131 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5132 || aspace1
== aspace2
)
5136 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5137 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5138 represent the same location. */
5141 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5143 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5144 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5146 if (hw_point1
!= hw_point2
)
5149 return watchpoint_locations_match (loc1
, loc2
);
5151 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5152 loc2
->pspace
->aspace
, loc2
->address
);
5156 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5157 int bnum
, int have_bnum
)
5162 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5163 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5165 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5166 bnum
, astr1
, astr2
);
5168 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5171 /* Adjust a breakpoint's address to account for architectural constraints
5172 on breakpoint placement. Return the adjusted address. Note: Very
5173 few targets require this kind of adjustment. For most targets,
5174 this function is simply the identity function. */
5177 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5178 CORE_ADDR bpaddr
, enum bptype bptype
)
5180 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5182 /* Very few targets need any kind of breakpoint adjustment. */
5185 else if (bptype
== bp_watchpoint
5186 || bptype
== bp_hardware_watchpoint
5187 || bptype
== bp_read_watchpoint
5188 || bptype
== bp_access_watchpoint
5189 || bptype
== bp_catchpoint
)
5191 /* Watchpoints and the various bp_catch_* eventpoints should not
5192 have their addresses modified. */
5197 CORE_ADDR adjusted_bpaddr
;
5199 /* Some targets have architectural constraints on the placement
5200 of breakpoint instructions. Obtain the adjusted address. */
5201 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5203 /* An adjusted breakpoint address can significantly alter
5204 a user's expectations. Print a warning if an adjustment
5206 if (adjusted_bpaddr
!= bpaddr
)
5207 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5209 return adjusted_bpaddr
;
5213 /* Allocate a struct bp_location. */
5215 static struct bp_location
*
5216 allocate_bp_location (struct breakpoint
*bpt
)
5218 struct bp_location
*loc
, *loc_p
;
5220 loc
= xmalloc (sizeof (struct bp_location
));
5221 memset (loc
, 0, sizeof (*loc
));
5225 loc
->shlib_disabled
= 0;
5234 case bp_longjmp_resume
:
5235 case bp_step_resume
:
5236 case bp_watchpoint_scope
:
5238 case bp_shlib_event
:
5239 case bp_thread_event
:
5240 case bp_overlay_event
:
5242 case bp_longjmp_master
:
5243 loc
->loc_type
= bp_loc_software_breakpoint
;
5245 case bp_hardware_breakpoint
:
5246 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5248 case bp_hardware_watchpoint
:
5249 case bp_read_watchpoint
:
5250 case bp_access_watchpoint
:
5251 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5256 case bp_fast_tracepoint
:
5257 loc
->loc_type
= bp_loc_other
;
5260 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5266 static void free_bp_location (struct bp_location
*loc
)
5271 if (loc
->function_name
)
5272 xfree (loc
->function_name
);
5277 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5278 that has type BPTYPE and has no locations as yet. */
5279 /* This function is used in gdbtk sources and thus can not be made static. */
5281 static struct breakpoint
*
5282 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5285 struct breakpoint
*b
, *b1
;
5287 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5288 memset (b
, 0, sizeof (*b
));
5291 b
->gdbarch
= gdbarch
;
5292 b
->language
= current_language
->la_language
;
5293 b
->input_radix
= input_radix
;
5295 b
->enable_state
= bp_enabled
;
5298 b
->ignore_count
= 0;
5300 b
->frame_id
= null_frame_id
;
5301 b
->forked_inferior_pid
= null_ptid
;
5302 b
->exec_pathname
= NULL
;
5303 b
->syscalls_to_be_caught
= NULL
;
5305 b
->condition_not_parsed
= 0;
5307 /* Add this breakpoint to the end of the chain
5308 so that a list of breakpoints will come out in order
5309 of increasing numbers. */
5311 b1
= breakpoint_chain
;
5313 breakpoint_chain
= b
;
5323 /* Initialize loc->function_name. */
5325 set_breakpoint_location_function (struct bp_location
*loc
)
5327 if (loc
->owner
->type
== bp_breakpoint
5328 || loc
->owner
->type
== bp_hardware_breakpoint
5329 || tracepoint_type (loc
->owner
))
5331 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5333 if (loc
->function_name
)
5334 loc
->function_name
= xstrdup (loc
->function_name
);
5338 /* Attempt to determine architecture of location identified by SAL. */
5339 static struct gdbarch
*
5340 get_sal_arch (struct symtab_and_line sal
)
5343 return get_objfile_arch (sal
.section
->objfile
);
5345 return get_objfile_arch (sal
.symtab
->objfile
);
5350 /* set_raw_breakpoint is a low level routine for allocating and
5351 partially initializing a breakpoint of type BPTYPE. The newly
5352 created breakpoint's address, section, source file name, and line
5353 number are provided by SAL. The newly created and partially
5354 initialized breakpoint is added to the breakpoint chain and
5355 is also returned as the value of this function.
5357 It is expected that the caller will complete the initialization of
5358 the newly created breakpoint struct as well as output any status
5359 information regarding the creation of a new breakpoint. In
5360 particular, set_raw_breakpoint does NOT set the breakpoint
5361 number! Care should be taken to not allow an error to occur
5362 prior to completing the initialization of the breakpoint. If this
5363 should happen, a bogus breakpoint will be left on the chain. */
5366 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5367 struct symtab_and_line sal
, enum bptype bptype
)
5369 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5370 CORE_ADDR adjusted_address
;
5371 struct gdbarch
*loc_gdbarch
;
5373 loc_gdbarch
= get_sal_arch (sal
);
5375 loc_gdbarch
= b
->gdbarch
;
5377 if (bptype
!= bp_catchpoint
)
5378 gdb_assert (sal
.pspace
!= NULL
);
5380 /* Adjust the breakpoint's address prior to allocating a location.
5381 Once we call allocate_bp_location(), that mostly uninitialized
5382 location will be placed on the location chain. Adjustment of the
5383 breakpoint may cause target_read_memory() to be called and we do
5384 not want its scan of the location chain to find a breakpoint and
5385 location that's only been partially initialized. */
5386 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5388 b
->loc
= allocate_bp_location (b
);
5389 b
->loc
->gdbarch
= loc_gdbarch
;
5390 b
->loc
->requested_address
= sal
.pc
;
5391 b
->loc
->address
= adjusted_address
;
5392 b
->loc
->pspace
= sal
.pspace
;
5394 /* Store the program space that was used to set the breakpoint, for
5395 breakpoint resetting. */
5396 b
->pspace
= sal
.pspace
;
5398 if (sal
.symtab
== NULL
)
5399 b
->source_file
= NULL
;
5401 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5402 b
->loc
->section
= sal
.section
;
5403 b
->line_number
= sal
.line
;
5405 set_breakpoint_location_function (b
->loc
);
5407 breakpoints_changed ();
5413 /* Note that the breakpoint object B describes a permanent breakpoint
5414 instruction, hard-wired into the inferior's code. */
5416 make_breakpoint_permanent (struct breakpoint
*b
)
5418 struct bp_location
*bl
;
5419 b
->enable_state
= bp_permanent
;
5421 /* By definition, permanent breakpoints are already present in the code.
5422 Mark all locations as inserted. For now, make_breakpoint_permanent
5423 is called in just one place, so it's hard to say if it's reasonable
5424 to have permanent breakpoint with multiple locations or not,
5425 but it's easy to implmement. */
5426 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5430 /* Call this routine when stepping and nexting to enable a breakpoint
5431 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5432 set_longjmp_resume_breakpoint() to figure out where we are going. */
5435 set_longjmp_breakpoint (int thread
)
5437 struct breakpoint
*b
, *temp
;
5439 /* To avoid having to rescan all objfile symbols at every step,
5440 we maintain a list of continually-inserted but always disabled
5441 longjmp "master" breakpoints. Here, we simply create momentary
5442 clones of those and enable them for the requested thread. */
5443 ALL_BREAKPOINTS_SAFE (b
, temp
)
5444 if (b
->pspace
== current_program_space
5445 && b
->type
== bp_longjmp_master
)
5447 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5448 clone
->type
= bp_longjmp
;
5449 clone
->thread
= thread
;
5453 /* Delete all longjmp breakpoints from THREAD. */
5455 delete_longjmp_breakpoint (int thread
)
5457 struct breakpoint
*b
, *temp
;
5459 ALL_BREAKPOINTS_SAFE (b
, temp
)
5460 if (b
->type
== bp_longjmp
)
5462 if (b
->thread
== thread
)
5463 delete_breakpoint (b
);
5468 enable_overlay_breakpoints (void)
5470 struct breakpoint
*b
;
5473 if (b
->type
== bp_overlay_event
)
5475 b
->enable_state
= bp_enabled
;
5476 update_global_location_list (1);
5477 overlay_events_enabled
= 1;
5482 disable_overlay_breakpoints (void)
5484 struct breakpoint
*b
;
5487 if (b
->type
== bp_overlay_event
)
5489 b
->enable_state
= bp_disabled
;
5490 update_global_location_list (0);
5491 overlay_events_enabled
= 0;
5496 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5498 struct breakpoint
*b
;
5500 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5502 b
->enable_state
= bp_enabled
;
5503 /* addr_string has to be used or breakpoint_re_set will delete me. */
5505 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5507 update_global_location_list_nothrow (1);
5513 remove_thread_event_breakpoints (void)
5515 struct breakpoint
*b
, *temp
;
5517 ALL_BREAKPOINTS_SAFE (b
, temp
)
5518 if (b
->type
== bp_thread_event
5519 && b
->loc
->pspace
== current_program_space
)
5520 delete_breakpoint (b
);
5523 struct captured_parse_breakpoint_args
5526 struct symtabs_and_lines
*sals_p
;
5527 char ***addr_string_p
;
5531 struct lang_and_radix
5537 /* Create a breakpoint for JIT code registration and unregistration. */
5540 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5542 struct breakpoint
*b
;
5544 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5545 update_global_location_list_nothrow (1);
5550 remove_solib_event_breakpoints (void)
5552 struct breakpoint
*b
, *temp
;
5554 ALL_BREAKPOINTS_SAFE (b
, temp
)
5555 if (b
->type
== bp_shlib_event
5556 && b
->loc
->pspace
== current_program_space
)
5557 delete_breakpoint (b
);
5561 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5563 struct breakpoint
*b
;
5565 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5566 update_global_location_list_nothrow (1);
5570 /* Disable any breakpoints that are on code in shared libraries. Only
5571 apply to enabled breakpoints, disabled ones can just stay disabled. */
5574 disable_breakpoints_in_shlibs (void)
5576 struct bp_location
*loc
, **locp_tmp
;
5578 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5580 struct breakpoint
*b
= loc
->owner
;
5581 /* We apply the check to all breakpoints, including disabled
5582 for those with loc->duplicate set. This is so that when breakpoint
5583 becomes enabled, or the duplicate is removed, gdb will try to insert
5584 all breakpoints. If we don't set shlib_disabled here, we'll try
5585 to insert those breakpoints and fail. */
5586 if (((b
->type
== bp_breakpoint
)
5587 || (b
->type
== bp_jit_event
)
5588 || (b
->type
== bp_hardware_breakpoint
)
5589 || (tracepoint_type (b
)))
5590 && loc
->pspace
== current_program_space
5591 && !loc
->shlib_disabled
5593 && PC_SOLIB (loc
->address
)
5595 && solib_name_from_address (loc
->pspace
, loc
->address
)
5599 loc
->shlib_disabled
= 1;
5604 /* Disable any breakpoints that are in in an unloaded shared library. Only
5605 apply to enabled breakpoints, disabled ones can just stay disabled. */
5608 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5610 struct bp_location
*loc
, **locp_tmp
;
5611 int disabled_shlib_breaks
= 0;
5613 /* SunOS a.out shared libraries are always mapped, so do not
5614 disable breakpoints; they will only be reported as unloaded
5615 through clear_solib when GDB discards its shared library
5616 list. See clear_solib for more information. */
5617 if (exec_bfd
!= NULL
5618 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5621 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5623 struct breakpoint
*b
= loc
->owner
;
5624 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5625 || loc
->loc_type
== bp_loc_software_breakpoint
)
5626 && solib
->pspace
== loc
->pspace
5627 && !loc
->shlib_disabled
5628 && (b
->type
== bp_breakpoint
5629 || b
->type
== bp_jit_event
5630 || b
->type
== bp_hardware_breakpoint
)
5631 && solib_contains_address_p (solib
, loc
->address
))
5633 loc
->shlib_disabled
= 1;
5634 /* At this point, we cannot rely on remove_breakpoint
5635 succeeding so we must mark the breakpoint as not inserted
5636 to prevent future errors occurring in remove_breakpoints. */
5638 if (!disabled_shlib_breaks
)
5640 target_terminal_ours_for_output ();
5641 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5644 disabled_shlib_breaks
= 1;
5649 /* FORK & VFORK catchpoints. */
5651 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5654 insert_catch_fork (struct breakpoint
*b
)
5656 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5659 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5662 remove_catch_fork (struct breakpoint
*b
)
5664 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5667 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5671 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5673 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5676 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5678 static enum print_stop_action
5679 print_it_catch_fork (struct breakpoint
*b
)
5681 annotate_catchpoint (b
->number
);
5682 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5683 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5684 return PRINT_SRC_AND_LOC
;
5687 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5690 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5692 struct value_print_options opts
;
5694 get_user_print_options (&opts
);
5696 /* Field 4, the address, is omitted (which makes the columns
5697 not line up too nicely with the headers, but the effect
5698 is relatively readable). */
5699 if (opts
.addressprint
)
5700 ui_out_field_skip (uiout
, "addr");
5702 ui_out_text (uiout
, "fork");
5703 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5705 ui_out_text (uiout
, ", process ");
5706 ui_out_field_int (uiout
, "what",
5707 ptid_get_pid (b
->forked_inferior_pid
));
5708 ui_out_spaces (uiout
, 1);
5712 /* Implement the "print_mention" breakpoint_ops method for fork
5716 print_mention_catch_fork (struct breakpoint
*b
)
5718 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5721 /* The breakpoint_ops structure to be used in fork catchpoints. */
5723 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5727 breakpoint_hit_catch_fork
,
5728 print_it_catch_fork
,
5729 print_one_catch_fork
,
5730 print_mention_catch_fork
5733 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5736 insert_catch_vfork (struct breakpoint
*b
)
5738 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5741 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5744 remove_catch_vfork (struct breakpoint
*b
)
5746 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5749 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5753 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5755 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5758 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5760 static enum print_stop_action
5761 print_it_catch_vfork (struct breakpoint
*b
)
5763 annotate_catchpoint (b
->number
);
5764 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5765 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5766 return PRINT_SRC_AND_LOC
;
5769 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5772 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5774 struct value_print_options opts
;
5776 get_user_print_options (&opts
);
5777 /* Field 4, the address, is omitted (which makes the columns
5778 not line up too nicely with the headers, but the effect
5779 is relatively readable). */
5780 if (opts
.addressprint
)
5781 ui_out_field_skip (uiout
, "addr");
5783 ui_out_text (uiout
, "vfork");
5784 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5786 ui_out_text (uiout
, ", process ");
5787 ui_out_field_int (uiout
, "what",
5788 ptid_get_pid (b
->forked_inferior_pid
));
5789 ui_out_spaces (uiout
, 1);
5793 /* Implement the "print_mention" breakpoint_ops method for vfork
5797 print_mention_catch_vfork (struct breakpoint
*b
)
5799 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5802 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5804 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5808 breakpoint_hit_catch_vfork
,
5809 print_it_catch_vfork
,
5810 print_one_catch_vfork
,
5811 print_mention_catch_vfork
5814 /* Implement the "insert" breakpoint_ops method for syscall
5818 insert_catch_syscall (struct breakpoint
*b
)
5820 struct inferior
*inf
= current_inferior ();
5822 ++inf
->total_syscalls_count
;
5823 if (!b
->syscalls_to_be_caught
)
5824 ++inf
->any_syscall_count
;
5829 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5833 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5835 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5836 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5838 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5839 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5841 memset ((void *) vec_addr
, 0,
5842 (iter
+ 1 - old_size
) * sizeof (int));
5844 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5845 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5849 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5850 inf
->total_syscalls_count
!= 0,
5851 inf
->any_syscall_count
,
5852 VEC_length (int, inf
->syscalls_counts
),
5853 VEC_address (int, inf
->syscalls_counts
));
5856 /* Implement the "remove" breakpoint_ops method for syscall
5860 remove_catch_syscall (struct breakpoint
*b
)
5862 struct inferior
*inf
= current_inferior ();
5864 --inf
->total_syscalls_count
;
5865 if (!b
->syscalls_to_be_caught
)
5866 --inf
->any_syscall_count
;
5871 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5875 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5876 /* Shouldn't happen. */
5878 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5879 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5883 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5884 inf
->total_syscalls_count
!= 0,
5885 inf
->any_syscall_count
,
5886 VEC_length (int, inf
->syscalls_counts
),
5887 VEC_address (int, inf
->syscalls_counts
));
5890 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5894 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5896 /* We must check if we are catching specific syscalls in this breakpoint.
5897 If we are, then we must guarantee that the called syscall is the same
5898 syscall we are catching. */
5899 int syscall_number
= 0;
5901 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5904 /* Now, checking if the syscall is the same. */
5905 if (b
->syscalls_to_be_caught
)
5909 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5911 if (syscall_number
== iter
)
5921 /* Implement the "print_it" breakpoint_ops method for syscall
5924 static enum print_stop_action
5925 print_it_catch_syscall (struct breakpoint
*b
)
5927 /* These are needed because we want to know in which state a
5928 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
5929 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
5930 must print "called syscall" or "returned from syscall". */
5932 struct target_waitstatus last
;
5934 struct cleanup
*old_chain
;
5937 get_last_target_status (&ptid
, &last
);
5939 get_syscall_by_number (last
.value
.syscall_number
, &s
);
5941 annotate_catchpoint (b
->number
);
5944 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
5946 syscall_id
= xstrprintf ("'%s'", s
.name
);
5948 old_chain
= make_cleanup (xfree
, syscall_id
);
5950 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
5951 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
5952 b
->number
, syscall_id
);
5953 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
5954 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
5955 b
->number
, syscall_id
);
5957 do_cleanups (old_chain
);
5959 return PRINT_SRC_AND_LOC
;
5962 /* Implement the "print_one" breakpoint_ops method for syscall
5966 print_one_catch_syscall (struct breakpoint
*b
,
5967 struct bp_location
**last_loc
)
5969 struct value_print_options opts
;
5971 get_user_print_options (&opts
);
5972 /* Field 4, the address, is omitted (which makes the columns
5973 not line up too nicely with the headers, but the effect
5974 is relatively readable). */
5975 if (opts
.addressprint
)
5976 ui_out_field_skip (uiout
, "addr");
5979 if (b
->syscalls_to_be_caught
5980 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5981 ui_out_text (uiout
, "syscalls \"");
5983 ui_out_text (uiout
, "syscall \"");
5985 if (b
->syscalls_to_be_caught
)
5988 char *text
= xstrprintf ("%s", "");
5990 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5995 get_syscall_by_number (iter
, &s
);
5998 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6000 text
= xstrprintf ("%s%d, ", text
, iter
);
6002 /* We have to xfree the last 'text' (now stored at 'x')
6003 because xstrprintf dinamically allocates new space for it
6007 /* Remove the last comma. */
6008 text
[strlen (text
) - 2] = '\0';
6009 ui_out_field_string (uiout
, "what", text
);
6012 ui_out_field_string (uiout
, "what", "<any syscall>");
6013 ui_out_text (uiout
, "\" ");
6016 /* Implement the "print_mention" breakpoint_ops method for syscall
6020 print_mention_catch_syscall (struct breakpoint
*b
)
6022 if (b
->syscalls_to_be_caught
)
6026 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6027 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6029 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6032 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6036 get_syscall_by_number (iter
, &s
);
6039 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6041 printf_filtered (" %d", s
.number
);
6043 printf_filtered (")");
6046 printf_filtered (_("Catchpoint %d (any syscall)"),
6050 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6052 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6054 insert_catch_syscall
,
6055 remove_catch_syscall
,
6056 breakpoint_hit_catch_syscall
,
6057 print_it_catch_syscall
,
6058 print_one_catch_syscall
,
6059 print_mention_catch_syscall
6062 /* Returns non-zero if 'b' is a syscall catchpoint. */
6065 syscall_catchpoint_p (struct breakpoint
*b
)
6067 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6070 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6071 but does NOT mention it nor update the global location list.
6072 This is useful if you need to fill more fields in the
6073 struct breakpoint before calling mention.
6075 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6076 If COND_STRING is not NULL, then store it in the breakpoint.
6077 OPS, if not NULL, is the breakpoint_ops structure associated
6078 to the catchpoint. */
6080 static struct breakpoint
*
6081 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6083 struct breakpoint_ops
*ops
)
6085 struct symtab_and_line sal
;
6086 struct breakpoint
*b
;
6089 sal
.pspace
= current_program_space
;
6091 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6092 set_breakpoint_count (breakpoint_count
+ 1);
6093 b
->number
= breakpoint_count
;
6095 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6097 b
->addr_string
= NULL
;
6098 b
->enable_state
= bp_enabled
;
6099 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6105 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6107 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6108 If COND_STRING is not NULL, then store it in the breakpoint.
6109 OPS, if not NULL, is the breakpoint_ops structure associated
6110 to the catchpoint. */
6112 static struct breakpoint
*
6113 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6114 char *cond_string
, struct breakpoint_ops
*ops
)
6116 struct breakpoint
*b
=
6117 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6120 update_global_location_list (1);
6126 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6127 int tempflag
, char *cond_string
,
6128 struct breakpoint_ops
*ops
)
6130 struct breakpoint
*b
6131 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6133 /* FIXME: We should put this information in a breakpoint private data
6135 b
->forked_inferior_pid
= null_ptid
;
6138 /* Exec catchpoints. */
6141 insert_catch_exec (struct breakpoint
*b
)
6143 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6147 remove_catch_exec (struct breakpoint
*b
)
6149 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6153 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6155 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6158 static enum print_stop_action
6159 print_it_catch_exec (struct breakpoint
*b
)
6161 annotate_catchpoint (b
->number
);
6162 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6164 return PRINT_SRC_AND_LOC
;
6168 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6170 struct value_print_options opts
;
6172 get_user_print_options (&opts
);
6174 /* Field 4, the address, is omitted (which makes the columns
6175 not line up too nicely with the headers, but the effect
6176 is relatively readable). */
6177 if (opts
.addressprint
)
6178 ui_out_field_skip (uiout
, "addr");
6180 ui_out_text (uiout
, "exec");
6181 if (b
->exec_pathname
!= NULL
)
6183 ui_out_text (uiout
, ", program \"");
6184 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6185 ui_out_text (uiout
, "\" ");
6190 print_mention_catch_exec (struct breakpoint
*b
)
6192 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6195 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6199 breakpoint_hit_catch_exec
,
6200 print_it_catch_exec
,
6201 print_one_catch_exec
,
6202 print_mention_catch_exec
6206 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6207 struct breakpoint_ops
*ops
)
6209 struct gdbarch
*gdbarch
= get_current_arch ();
6210 struct breakpoint
*b
=
6211 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6213 b
->syscalls_to_be_caught
= filter
;
6215 /* Now, we have to mention the breakpoint and update the global
6218 update_global_location_list (1);
6222 hw_breakpoint_used_count (void)
6224 struct breakpoint
*b
;
6229 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6237 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6239 struct breakpoint
*b
;
6242 *other_type_used
= 0;
6245 if (breakpoint_enabled (b
))
6247 if (b
->type
== type
)
6249 else if ((b
->type
== bp_hardware_watchpoint
6250 || b
->type
== bp_read_watchpoint
6251 || b
->type
== bp_access_watchpoint
))
6252 *other_type_used
= 1;
6259 disable_watchpoints_before_interactive_call_start (void)
6261 struct breakpoint
*b
;
6265 if (((b
->type
== bp_watchpoint
)
6266 || (b
->type
== bp_hardware_watchpoint
)
6267 || (b
->type
== bp_read_watchpoint
)
6268 || (b
->type
== bp_access_watchpoint
))
6269 && breakpoint_enabled (b
))
6271 b
->enable_state
= bp_call_disabled
;
6272 update_global_location_list (0);
6278 enable_watchpoints_after_interactive_call_stop (void)
6280 struct breakpoint
*b
;
6284 if (((b
->type
== bp_watchpoint
)
6285 || (b
->type
== bp_hardware_watchpoint
)
6286 || (b
->type
== bp_read_watchpoint
)
6287 || (b
->type
== bp_access_watchpoint
))
6288 && (b
->enable_state
== bp_call_disabled
))
6290 b
->enable_state
= bp_enabled
;
6291 update_global_location_list (1);
6297 disable_breakpoints_before_startup (void)
6299 struct breakpoint
*b
;
6304 if (b
->pspace
!= current_program_space
)
6307 if ((b
->type
== bp_breakpoint
6308 || b
->type
== bp_hardware_breakpoint
)
6309 && breakpoint_enabled (b
))
6311 b
->enable_state
= bp_startup_disabled
;
6317 update_global_location_list (0);
6319 current_program_space
->executing_startup
= 1;
6323 enable_breakpoints_after_startup (void)
6325 struct breakpoint
*b
;
6328 current_program_space
->executing_startup
= 0;
6332 if (b
->pspace
!= current_program_space
)
6335 if ((b
->type
== bp_breakpoint
6336 || b
->type
== bp_hardware_breakpoint
)
6337 && b
->enable_state
== bp_startup_disabled
)
6339 b
->enable_state
= bp_enabled
;
6345 breakpoint_re_set ();
6349 /* Set a breakpoint that will evaporate an end of command
6350 at address specified by SAL.
6351 Restrict it to frame FRAME if FRAME is nonzero. */
6354 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6355 struct frame_id frame_id
, enum bptype type
)
6357 struct breakpoint
*b
;
6359 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6361 gdb_assert (!frame_id_inlined_p (frame_id
));
6363 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6364 b
->enable_state
= bp_enabled
;
6365 b
->disposition
= disp_donttouch
;
6366 b
->frame_id
= frame_id
;
6368 /* If we're debugging a multi-threaded program, then we
6369 want momentary breakpoints to be active in only a
6370 single thread of control. */
6371 if (in_thread_list (inferior_ptid
))
6372 b
->thread
= pid_to_thread_id (inferior_ptid
);
6374 update_global_location_list_nothrow (1);
6379 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6383 clone_momentary_breakpoint (struct breakpoint
*orig
)
6385 struct breakpoint
*copy
;
6387 /* If there's nothing to clone, then return nothing. */
6391 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6392 copy
->loc
= allocate_bp_location (copy
);
6393 set_breakpoint_location_function (copy
->loc
);
6395 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6396 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6397 copy
->loc
->address
= orig
->loc
->address
;
6398 copy
->loc
->section
= orig
->loc
->section
;
6399 copy
->loc
->pspace
= orig
->loc
->pspace
;
6401 if (orig
->source_file
== NULL
)
6402 copy
->source_file
= NULL
;
6404 copy
->source_file
= xstrdup (orig
->source_file
);
6406 copy
->line_number
= orig
->line_number
;
6407 copy
->frame_id
= orig
->frame_id
;
6408 copy
->thread
= orig
->thread
;
6409 copy
->pspace
= orig
->pspace
;
6411 copy
->enable_state
= bp_enabled
;
6412 copy
->disposition
= disp_donttouch
;
6413 copy
->number
= internal_breakpoint_number
--;
6415 update_global_location_list_nothrow (0);
6420 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6423 struct symtab_and_line sal
;
6425 sal
= find_pc_line (pc
, 0);
6427 sal
.section
= find_pc_overlay (pc
);
6428 sal
.explicit_pc
= 1;
6430 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6434 /* Tell the user we have just set a breakpoint B. */
6437 mention (struct breakpoint
*b
)
6440 struct cleanup
*ui_out_chain
;
6441 struct value_print_options opts
;
6443 get_user_print_options (&opts
);
6445 /* FIXME: This is misplaced; mention() is called by things (like
6446 hitting a watchpoint) other than breakpoint creation. It should
6447 be possible to clean this up and at the same time replace the
6448 random calls to breakpoint_changed with this hook. */
6449 observer_notify_breakpoint_created (b
->number
);
6451 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6452 b
->ops
->print_mention (b
);
6457 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6460 ui_out_text (uiout
, "Watchpoint ");
6461 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6462 ui_out_field_int (uiout
, "number", b
->number
);
6463 ui_out_text (uiout
, ": ");
6464 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6465 do_cleanups (ui_out_chain
);
6467 case bp_hardware_watchpoint
:
6468 ui_out_text (uiout
, "Hardware watchpoint ");
6469 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6470 ui_out_field_int (uiout
, "number", b
->number
);
6471 ui_out_text (uiout
, ": ");
6472 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6473 do_cleanups (ui_out_chain
);
6475 case bp_read_watchpoint
:
6476 ui_out_text (uiout
, "Hardware read watchpoint ");
6477 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6478 ui_out_field_int (uiout
, "number", b
->number
);
6479 ui_out_text (uiout
, ": ");
6480 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6481 do_cleanups (ui_out_chain
);
6483 case bp_access_watchpoint
:
6484 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6485 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6486 ui_out_field_int (uiout
, "number", b
->number
);
6487 ui_out_text (uiout
, ": ");
6488 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6489 do_cleanups (ui_out_chain
);
6492 if (ui_out_is_mi_like_p (uiout
))
6497 if (b
->disposition
== disp_del
)
6498 printf_filtered (_("Temporary breakpoint"));
6500 printf_filtered (_("Breakpoint"));
6501 printf_filtered (_(" %d"), b
->number
);
6504 case bp_hardware_breakpoint
:
6505 if (ui_out_is_mi_like_p (uiout
))
6510 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6514 if (ui_out_is_mi_like_p (uiout
))
6519 printf_filtered (_("Tracepoint"));
6520 printf_filtered (_(" %d"), b
->number
);
6523 case bp_fast_tracepoint
:
6524 if (ui_out_is_mi_like_p (uiout
))
6529 printf_filtered (_("Fast tracepoint"));
6530 printf_filtered (_(" %d"), b
->number
);
6537 case bp_longjmp_resume
:
6538 case bp_step_resume
:
6540 case bp_watchpoint_scope
:
6541 case bp_shlib_event
:
6542 case bp_thread_event
:
6543 case bp_overlay_event
:
6545 case bp_longjmp_master
:
6551 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6555 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6559 if (opts
.addressprint
|| b
->source_file
== NULL
)
6561 printf_filtered (" at ");
6562 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6566 printf_filtered (": file %s, line %d.",
6567 b
->source_file
, b
->line_number
);
6571 struct bp_location
*loc
= b
->loc
;
6573 for (; loc
; loc
= loc
->next
)
6575 printf_filtered (" (%d locations)", n
);
6580 if (ui_out_is_mi_like_p (uiout
))
6582 printf_filtered ("\n");
6586 static struct bp_location
*
6587 add_location_to_breakpoint (struct breakpoint
*b
,
6588 const struct symtab_and_line
*sal
)
6590 struct bp_location
*loc
, **tmp
;
6592 loc
= allocate_bp_location (b
);
6593 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6596 loc
->gdbarch
= get_sal_arch (*sal
);
6598 loc
->gdbarch
= b
->gdbarch
;
6599 loc
->requested_address
= sal
->pc
;
6600 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6601 loc
->requested_address
, b
->type
);
6602 loc
->pspace
= sal
->pspace
;
6603 gdb_assert (loc
->pspace
!= NULL
);
6604 loc
->section
= sal
->section
;
6606 set_breakpoint_location_function (loc
);
6611 /* Return 1 if LOC is pointing to a permanent breakpoint,
6612 return 0 otherwise. */
6615 bp_loc_is_permanent (struct bp_location
*loc
)
6619 const gdb_byte
*brk
;
6620 gdb_byte
*target_mem
;
6621 struct cleanup
*cleanup
;
6624 gdb_assert (loc
!= NULL
);
6626 addr
= loc
->address
;
6627 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6629 /* Software breakpoints unsupported? */
6633 target_mem
= alloca (len
);
6635 /* Enable the automatic memory restoration from breakpoints while
6636 we read the memory. Otherwise we could say about our temporary
6637 breakpoints they are permanent. */
6638 cleanup
= save_current_space_and_thread ();
6640 switch_to_program_space_and_thread (loc
->pspace
);
6641 make_show_memory_breakpoints_cleanup (0);
6643 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6644 && memcmp (target_mem
, brk
, len
) == 0)
6647 do_cleanups (cleanup
);
6654 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6655 as textual description of the location, and COND_STRING
6656 as condition expression. */
6659 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6660 struct symtabs_and_lines sals
, char *addr_string
,
6662 enum bptype type
, enum bpdisp disposition
,
6663 int thread
, int task
, int ignore_count
,
6664 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6666 struct breakpoint
*b
= NULL
;
6669 if (type
== bp_hardware_breakpoint
)
6671 int i
= hw_breakpoint_used_count ();
6672 int target_resources_ok
=
6673 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6675 if (target_resources_ok
== 0)
6676 error (_("No hardware breakpoint support in the target."));
6677 else if (target_resources_ok
< 0)
6678 error (_("Hardware breakpoints used exceeds limit."));
6681 gdb_assert (sals
.nelts
> 0);
6683 for (i
= 0; i
< sals
.nelts
; ++i
)
6685 struct symtab_and_line sal
= sals
.sals
[i
];
6686 struct bp_location
*loc
;
6690 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6692 loc_gdbarch
= gdbarch
;
6694 describe_other_breakpoints (loc_gdbarch
,
6695 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6700 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6701 set_breakpoint_count (breakpoint_count
+ 1);
6702 b
->number
= breakpoint_count
;
6706 b
->cond_string
= cond_string
;
6707 b
->ignore_count
= ignore_count
;
6708 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6709 b
->disposition
= disposition
;
6711 b
->pspace
= sals
.sals
[0].pspace
;
6713 if (enabled
&& b
->pspace
->executing_startup
6714 && (b
->type
== bp_breakpoint
6715 || b
->type
== bp_hardware_breakpoint
))
6716 b
->enable_state
= bp_startup_disabled
;
6722 loc
= add_location_to_breakpoint (b
, &sal
);
6725 if (bp_loc_is_permanent (loc
))
6726 make_breakpoint_permanent (b
);
6730 char *arg
= b
->cond_string
;
6731 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6733 error (_("Garbage %s follows condition"), arg
);
6738 b
->addr_string
= addr_string
;
6740 /* addr_string has to be used or breakpoint_re_set will delete
6743 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6749 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6750 elements to fill the void space. */
6752 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6754 int i
= index_to_remove
+1;
6755 int last_index
= sal
->nelts
-1;
6757 for (;i
<= last_index
; ++i
)
6758 sal
->sals
[i
-1] = sal
->sals
[i
];
6763 /* If appropriate, obtains all sals that correspond to the same file
6764 and line as SAL, in all program spaces. Users debugging with IDEs,
6765 will want to set a breakpoint at foo.c:line, and not really care
6766 about program spaces. This is done only if SAL does not have
6767 explicit PC and has line and file information. If we got just a
6768 single expanded sal, return the original.
6770 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6771 which the name of enclosing function is different from SAL. This
6772 makes sure that if we have breakpoint originally set in template
6773 instantiation, say foo<int>(), we won't expand SAL to locations at
6774 the same line in all existing instantiations of 'foo'. */
6776 static struct symtabs_and_lines
6777 expand_line_sal_maybe (struct symtab_and_line sal
)
6779 struct symtabs_and_lines expanded
;
6780 CORE_ADDR original_pc
= sal
.pc
;
6781 char *original_function
= NULL
;
6784 struct cleanup
*old_chain
;
6786 /* If we have explicit pc, don't expand.
6787 If we have no line number, we can't expand. */
6788 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6791 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6792 expanded
.sals
[0] = sal
;
6798 old_chain
= save_current_space_and_thread ();
6800 switch_to_program_space_and_thread (sal
.pspace
);
6802 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6804 /* Note that expand_line_sal visits *all* program spaces. */
6805 expanded
= expand_line_sal (sal
);
6807 if (expanded
.nelts
== 1)
6809 /* We had one sal, we got one sal. Return that sal, adjusting it
6810 past the function prologue if necessary. */
6811 xfree (expanded
.sals
);
6813 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6814 sal
.pc
= original_pc
;
6815 expanded
.sals
[0] = sal
;
6816 skip_prologue_sal (&expanded
.sals
[0]);
6817 do_cleanups (old_chain
);
6821 if (!sal
.explicit_line
)
6823 CORE_ADDR func_addr
, func_end
;
6824 for (i
= 0; i
< expanded
.nelts
; ++i
)
6826 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6827 char *this_function
;
6829 /* We need to switch threads as well since we're about to
6831 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6833 if (find_pc_partial_function (pc
, &this_function
,
6834 &func_addr
, &func_end
))
6837 && strcmp (this_function
, original_function
) != 0)
6839 remove_sal (&expanded
, i
);
6842 else if (func_addr
== pc
)
6844 /* We're at beginning of a function, and should
6846 struct symbol
*sym
= find_pc_function (pc
);
6848 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
6851 /* Since find_pc_partial_function returned true,
6852 we should really always find the section here. */
6853 struct obj_section
*section
= find_pc_section (pc
);
6856 struct gdbarch
*gdbarch
6857 = get_objfile_arch (section
->objfile
);
6859 = gdbarch_skip_prologue (gdbarch
, pc
);
6868 for (i
= 0; i
< expanded
.nelts
; ++i
)
6870 /* If this SAL corresponds to a breakpoint inserted using a
6871 line number, then skip the function prologue if necessary. */
6872 skip_prologue_sal (&expanded
.sals
[i
]);
6876 do_cleanups (old_chain
);
6878 if (expanded
.nelts
<= 1)
6880 /* This is un ugly workaround. If we get zero
6881 expanded sals then something is really wrong.
6882 Fix that by returnign the original sal. */
6883 xfree (expanded
.sals
);
6885 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6886 sal
.pc
= original_pc
;
6887 expanded
.sals
[0] = sal
;
6894 for (i
= 0; i
< expanded
.nelts
; ++i
)
6895 if (expanded
.sals
[i
].pc
== original_pc
)
6906 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6907 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6908 value. COND_STRING, if not NULL, specified the condition to be
6909 used for all breakpoints. Essentially the only case where
6910 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6911 function. In that case, it's still not possible to specify
6912 separate conditions for different overloaded functions, so
6913 we take just a single condition string.
6915 NOTE: If the function succeeds, the caller is expected to cleanup
6916 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6917 array contents). If the function fails (error() is called), the
6918 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6919 COND and SALS arrays and each of those arrays contents. */
6922 create_breakpoints_sal (struct gdbarch
*gdbarch
,
6923 struct symtabs_and_lines sals
, char **addr_string
,
6925 enum bptype type
, enum bpdisp disposition
,
6926 int thread
, int task
, int ignore_count
,
6927 struct breakpoint_ops
*ops
, int from_tty
,
6931 for (i
= 0; i
< sals
.nelts
; ++i
)
6933 struct symtabs_and_lines expanded
=
6934 expand_line_sal_maybe (sals
.sals
[i
]);
6936 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
6937 cond_string
, type
, disposition
,
6938 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6942 /* Parse ARG which is assumed to be a SAL specification possibly
6943 followed by conditionals. On return, SALS contains an array of SAL
6944 addresses found. ADDR_STRING contains a vector of (canonical)
6945 address strings. ARG points to the end of the SAL. */
6948 parse_breakpoint_sals (char **address
,
6949 struct symtabs_and_lines
*sals
,
6950 char ***addr_string
,
6953 char *addr_start
= *address
;
6954 *addr_string
= NULL
;
6955 /* If no arg given, or if first arg is 'if ', use the default
6957 if ((*address
) == NULL
6958 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
6960 if (default_breakpoint_valid
)
6962 struct symtab_and_line sal
;
6963 init_sal (&sal
); /* initialize to zeroes */
6964 sals
->sals
= (struct symtab_and_line
*)
6965 xmalloc (sizeof (struct symtab_and_line
));
6966 sal
.pc
= default_breakpoint_address
;
6967 sal
.line
= default_breakpoint_line
;
6968 sal
.symtab
= default_breakpoint_symtab
;
6969 sal
.pspace
= default_breakpoint_pspace
;
6970 sal
.section
= find_pc_overlay (sal
.pc
);
6972 /* "break" without arguments is equivalent to "break *PC" where PC is
6973 the default_breakpoint_address. So make sure to set
6974 sal.explicit_pc to prevent GDB from trying to expand the list of
6975 sals to include all other instances with the same symtab and line.
6977 sal
.explicit_pc
= 1;
6979 sals
->sals
[0] = sal
;
6983 error (_("No default breakpoint address now."));
6987 /* Force almost all breakpoints to be in terms of the
6988 current_source_symtab (which is decode_line_1's default). This
6989 should produce the results we want almost all of the time while
6990 leaving default_breakpoint_* alone.
6991 ObjC: However, don't match an Objective-C method name which
6992 may have a '+' or '-' succeeded by a '[' */
6994 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
6996 if (default_breakpoint_valid
6998 || ((strchr ("+-", (*address
)[0]) != NULL
)
6999 && ((*address
)[1] != '['))))
7000 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7001 default_breakpoint_line
, addr_string
,
7004 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7005 addr_string
, not_found_ptr
);
7007 /* For any SAL that didn't have a canonical string, fill one in. */
7008 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7009 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7010 if (addr_start
!= (*address
))
7013 for (i
= 0; i
< sals
->nelts
; i
++)
7015 /* Add the string if not present. */
7016 if ((*addr_string
)[i
] == NULL
)
7017 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
7023 /* Convert each SAL into a real PC. Verify that the PC can be
7024 inserted as a breakpoint. If it can't throw an error. */
7027 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
7031 for (i
= 0; i
< sals
->nelts
; i
++)
7032 resolve_sal_pc (&sals
->sals
[i
]);
7035 /* Fast tracepoints may have restrictions on valid locations. For
7036 instance, a fast tracepoint using a jump instead of a trap will
7037 likely have to overwrite more bytes than a trap would, and so can
7038 only be placed where the instruction is longer than the jump, or a
7039 multi-instruction sequence does not have a jump into the middle of
7043 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7044 struct symtabs_and_lines
*sals
)
7047 struct symtab_and_line
*sal
;
7049 struct cleanup
*old_chain
;
7051 for (i
= 0; i
< sals
->nelts
; i
++)
7053 sal
= &sals
->sals
[i
];
7055 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7057 old_chain
= make_cleanup (xfree
, msg
);
7060 error (_("May not have a fast tracepoint at 0x%s%s"),
7061 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7063 do_cleanups (old_chain
);
7068 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7070 struct captured_parse_breakpoint_args
*args
= data
;
7072 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7073 args
->not_found_ptr
);
7076 /* Given TOK, a string specification of condition and thread, as
7077 accepted by the 'break' command, extract the condition
7078 string and thread number and set *COND_STRING and *THREAD.
7079 PC identifies the context at which the condition should be parsed.
7080 If no condition is found, *COND_STRING is set to NULL.
7081 If no thread is found, *THREAD is set to -1. */
7083 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7084 char **cond_string
, int *thread
, int *task
)
7086 *cond_string
= NULL
;
7092 char *cond_start
= NULL
;
7093 char *cond_end
= NULL
;
7094 while (*tok
== ' ' || *tok
== '\t')
7099 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7102 toklen
= end_tok
- tok
;
7104 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7106 struct expression
*expr
;
7108 tok
= cond_start
= end_tok
+ 1;
7109 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7112 *cond_string
= savestring (cond_start
,
7113 cond_end
- cond_start
);
7115 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7121 *thread
= strtol (tok
, &tok
, 0);
7123 error (_("Junk after thread keyword."));
7124 if (!valid_thread_id (*thread
))
7125 error (_("Unknown thread %d."), *thread
);
7127 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7133 *task
= strtol (tok
, &tok
, 0);
7135 error (_("Junk after task keyword."));
7136 if (!valid_task_id (*task
))
7137 error (_("Unknown task %d."), *task
);
7140 error (_("Junk at end of arguments."));
7144 /* Set a breakpoint. This function is shared between CLI and MI
7145 functions for setting a breakpoint. This function has two major
7146 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7147 parameter. If non-zero, the function will parse arg, extracting
7148 breakpoint location, address and thread. Otherwise, ARG is just the
7149 location of breakpoint, with condition and thread specified by the
7150 COND_STRING and THREAD parameters. Returns true if any breakpoint
7151 was created; false otherwise. */
7154 create_breakpoint (struct gdbarch
*gdbarch
,
7155 char *arg
, char *cond_string
, int thread
,
7156 int parse_condition_and_thread
,
7157 int tempflag
, int hardwareflag
, int traceflag
,
7159 enum auto_boolean pending_break_support
,
7160 struct breakpoint_ops
*ops
,
7164 struct gdb_exception e
;
7165 struct symtabs_and_lines sals
;
7166 struct symtab_and_line pending_sal
;
7169 char *addr_start
= arg
;
7171 struct cleanup
*old_chain
;
7172 struct cleanup
*bkpt_chain
= NULL
;
7173 struct captured_parse_breakpoint_args parse_args
;
7177 enum bptype type_wanted
;
7179 int first_bp_set
= breakpoint_count
+ 1;
7185 parse_args
.arg_p
= &arg
;
7186 parse_args
.sals_p
= &sals
;
7187 parse_args
.addr_string_p
= &addr_string
;
7188 parse_args
.not_found_ptr
= ¬_found
;
7190 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7191 &parse_args
, RETURN_MASK_ALL
);
7193 /* If caller is interested in rc value from parse, set value. */
7197 throw_exception (e
);
7201 case NOT_FOUND_ERROR
:
7203 /* If pending breakpoint support is turned off, throw
7206 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7207 throw_exception (e
);
7209 exception_print (gdb_stderr
, e
);
7211 /* If pending breakpoint support is auto query and the user
7212 selects no, then simply return the error code. */
7213 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7214 && !nquery ("Make breakpoint pending on future shared library load? "))
7217 /* At this point, either the user was queried about setting
7218 a pending breakpoint and selected yes, or pending
7219 breakpoint behavior is on and thus a pending breakpoint
7220 is defaulted on behalf of the user. */
7221 copy_arg
= xstrdup (addr_start
);
7222 addr_string
= ©_arg
;
7224 sals
.sals
= &pending_sal
;
7229 throw_exception (e
);
7236 /* Create a chain of things that always need to be cleaned up. */
7237 old_chain
= make_cleanup (null_cleanup
, 0);
7241 /* Make sure that all storage allocated to SALS gets freed. */
7242 make_cleanup (xfree
, sals
.sals
);
7244 /* Cleanup the addr_string array but not its contents. */
7245 make_cleanup (xfree
, addr_string
);
7248 /* ----------------------------- SNIP -----------------------------
7249 Anything added to the cleanup chain beyond this point is assumed
7250 to be part of a breakpoint. If the breakpoint create succeeds
7251 then the memory is not reclaimed. */
7252 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7254 /* Mark the contents of the addr_string for cleanup. These go on
7255 the bkpt_chain and only occur if the breakpoint create fails. */
7256 for (i
= 0; i
< sals
.nelts
; i
++)
7258 if (addr_string
[i
] != NULL
)
7259 make_cleanup (xfree
, addr_string
[i
]);
7262 /* Resolve all line numbers to PC's and verify that the addresses
7263 are ok for the target. */
7265 breakpoint_sals_to_pc (&sals
, addr_start
);
7267 type_wanted
= (traceflag
7268 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7269 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7271 /* Fast tracepoints may have additional restrictions on location. */
7272 if (type_wanted
== bp_fast_tracepoint
)
7273 check_fast_tracepoint_sals (gdbarch
, &sals
);
7275 /* Verify that condition can be parsed, before setting any
7276 breakpoints. Allocate a separate condition expression for each
7280 if (parse_condition_and_thread
)
7282 /* Here we only parse 'arg' to separate condition
7283 from thread number, so parsing in context of first
7284 sal is OK. When setting the breakpoint we'll
7285 re-parse it in context of each sal. */
7288 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7291 make_cleanup (xfree
, cond_string
);
7295 /* Create a private copy of condition string. */
7298 cond_string
= xstrdup (cond_string
);
7299 make_cleanup (xfree
, cond_string
);
7302 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7303 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7304 thread
, task
, ignore_count
, ops
, from_tty
,
7309 struct symtab_and_line sal
= {0};
7310 struct breakpoint
*b
;
7312 make_cleanup (xfree
, copy_arg
);
7314 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7315 set_breakpoint_count (breakpoint_count
+ 1);
7316 b
->number
= breakpoint_count
;
7318 b
->addr_string
= addr_string
[0];
7319 b
->cond_string
= NULL
;
7320 b
->ignore_count
= ignore_count
;
7321 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7322 b
->condition_not_parsed
= 1;
7324 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7325 b
->pspace
= current_program_space
;
7327 if (enabled
&& b
->pspace
->executing_startup
7328 && (b
->type
== bp_breakpoint
7329 || b
->type
== bp_hardware_breakpoint
))
7330 b
->enable_state
= bp_startup_disabled
;
7337 warning (_("Multiple breakpoints were set.\n"
7338 "Use the \"delete\" command to delete unwanted breakpoints."));
7339 multi_start
= first_bp_set
;
7340 multi_end
= breakpoint_count
;
7344 /* That's it. Discard the cleanups for data inserted into the
7346 discard_cleanups (bkpt_chain
);
7347 /* But cleanup everything else. */
7348 do_cleanups (old_chain
);
7350 /* error call may happen here - have BKPT_CHAIN already discarded. */
7351 update_global_location_list (1);
7356 /* Set a breakpoint.
7357 ARG is a string describing breakpoint address,
7358 condition, and thread.
7359 FLAG specifies if a breakpoint is hardware on,
7360 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7364 break_command_1 (char *arg
, int flag
, int from_tty
)
7366 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7367 int tempflag
= flag
& BP_TEMPFLAG
;
7369 create_breakpoint (get_current_arch (),
7371 NULL
, 0, 1 /* parse arg */,
7372 tempflag
, hardwareflag
, 0 /* traceflag */,
7373 0 /* Ignore count */,
7374 pending_break_support
,
7375 NULL
/* breakpoint_ops */,
7382 /* Adjust SAL to the first instruction past the function prologue.
7383 The end of the prologue is determined using the line table from
7384 the debugging information. explicit_pc and explicit_line are
7387 If SAL is already past the prologue, then do nothing. */
7390 skip_prologue_sal (struct symtab_and_line
*sal
)
7393 struct symtab_and_line start_sal
;
7394 struct cleanup
*old_chain
;
7396 old_chain
= save_current_space_and_thread ();
7398 sym
= find_pc_function (sal
->pc
);
7401 start_sal
= find_function_start_sal (sym
, 1);
7402 if (sal
->pc
< start_sal
.pc
)
7404 start_sal
.explicit_line
= sal
->explicit_line
;
7405 start_sal
.explicit_pc
= sal
->explicit_pc
;
7410 do_cleanups (old_chain
);
7413 /* Helper function for break_command_1 and disassemble_command. */
7416 resolve_sal_pc (struct symtab_and_line
*sal
)
7420 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7422 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7423 error (_("No line %d in file \"%s\"."),
7424 sal
->line
, sal
->symtab
->filename
);
7427 /* If this SAL corresponds to a breakpoint inserted using
7428 a line number, then skip the function prologue if necessary. */
7429 if (sal
->explicit_line
)
7431 /* Preserve the original line number. */
7432 int saved_line
= sal
->line
;
7433 skip_prologue_sal (sal
);
7434 sal
->line
= saved_line
;
7438 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7440 struct blockvector
*bv
;
7444 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7447 sym
= block_linkage_function (b
);
7450 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7451 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7455 /* It really is worthwhile to have the section, so we'll just
7456 have to look harder. This case can be executed if we have
7457 line numbers but no functions (as can happen in assembly
7460 struct minimal_symbol
*msym
;
7461 struct cleanup
*old_chain
= save_current_space_and_thread ();
7463 switch_to_program_space_and_thread (sal
->pspace
);
7465 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7467 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7469 do_cleanups (old_chain
);
7476 break_command (char *arg
, int from_tty
)
7478 break_command_1 (arg
, 0, from_tty
);
7482 tbreak_command (char *arg
, int from_tty
)
7484 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7488 hbreak_command (char *arg
, int from_tty
)
7490 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7494 thbreak_command (char *arg
, int from_tty
)
7496 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7500 stop_command (char *arg
, int from_tty
)
7502 printf_filtered (_("Specify the type of breakpoint to set.\n\
7503 Usage: stop in <function | address>\n\
7504 stop at <line>\n"));
7508 stopin_command (char *arg
, int from_tty
)
7512 if (arg
== (char *) NULL
)
7514 else if (*arg
!= '*')
7519 /* look for a ':'. If this is a line number specification, then
7520 say it is bad, otherwise, it should be an address or
7521 function/method name */
7522 while (*argptr
&& !hasColon
)
7524 hasColon
= (*argptr
== ':');
7529 badInput
= (*argptr
!= ':'); /* Not a class::method */
7531 badInput
= isdigit (*arg
); /* a simple line number */
7535 printf_filtered (_("Usage: stop in <function | address>\n"));
7537 break_command_1 (arg
, 0, from_tty
);
7541 stopat_command (char *arg
, int from_tty
)
7545 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7552 /* look for a ':'. If there is a '::' then get out, otherwise
7553 it is probably a line number. */
7554 while (*argptr
&& !hasColon
)
7556 hasColon
= (*argptr
== ':');
7561 badInput
= (*argptr
== ':'); /* we have class::method */
7563 badInput
= !isdigit (*arg
); /* not a line number */
7567 printf_filtered (_("Usage: stop at <line>\n"));
7569 break_command_1 (arg
, 0, from_tty
);
7572 /* accessflag: hw_write: watch write,
7573 hw_read: watch read,
7574 hw_access: watch access (read or write) */
7576 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7578 struct gdbarch
*gdbarch
= get_current_arch ();
7579 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7580 struct expression
*exp
;
7581 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7582 struct value
*val
, *mark
;
7583 struct frame_info
*frame
;
7584 char *exp_start
= NULL
;
7585 char *exp_end
= NULL
;
7586 char *tok
, *id_tok_start
, *end_tok
;
7588 char *cond_start
= NULL
;
7589 char *cond_end
= NULL
;
7590 int i
, other_type_used
, target_resources_ok
= 0;
7591 enum bptype bp_type
;
7595 /* Make sure that we actually have parameters to parse. */
7596 if (arg
!= NULL
&& arg
[0] != '\0')
7598 toklen
= strlen (arg
); /* Size of argument list. */
7600 /* Points tok to the end of the argument list. */
7601 tok
= arg
+ toklen
- 1;
7603 /* Go backwards in the parameters list. Skip the last parameter.
7604 If we're expecting a 'thread <thread_num>' parameter, this should
7605 be the thread identifier. */
7606 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7608 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7611 /* Points end_tok to the beginning of the last token. */
7612 id_tok_start
= tok
+ 1;
7614 /* Go backwards in the parameters list. Skip one more parameter.
7615 If we're expecting a 'thread <thread_num>' parameter, we should
7616 reach a "thread" token. */
7617 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7622 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7625 /* Move the pointer forward to skip the whitespace and
7626 calculate the length of the token. */
7628 toklen
= end_tok
- tok
;
7630 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7632 /* At this point we've found a "thread" token, which means
7633 the user is trying to set a watchpoint that triggers
7634 only in a specific thread. */
7637 /* Extract the thread ID from the next token. */
7638 thread
= strtol (id_tok_start
, &endp
, 0);
7640 /* Check if the user provided a valid numeric value for the
7642 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7643 error (_("Invalid thread ID specification %s."), id_tok_start
);
7645 /* Check if the thread actually exists. */
7646 if (!valid_thread_id (thread
))
7647 error (_("Unknown thread %d."), thread
);
7649 /* Truncate the string and get rid of the thread <thread_num>
7650 parameter before the parameter list is parsed by the
7651 evaluate_expression() function. */
7656 /* Parse the rest of the arguments. */
7657 innermost_block
= NULL
;
7659 exp
= parse_exp_1 (&arg
, 0, 0);
7661 /* Remove trailing whitespace from the expression before saving it.
7662 This makes the eventual display of the expression string a bit
7664 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7667 exp_valid_block
= innermost_block
;
7668 mark
= value_mark ();
7669 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7671 release_value (val
);
7674 while (*tok
== ' ' || *tok
== '\t')
7678 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7681 toklen
= end_tok
- tok
;
7682 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7684 struct expression
*cond
;
7686 innermost_block
= NULL
;
7687 tok
= cond_start
= end_tok
+ 1;
7688 cond
= parse_exp_1 (&tok
, 0, 0);
7690 /* The watchpoint expression may not be local, but the condition
7691 may still be. E.g.: `watch global if local > 0'. */
7692 cond_exp_valid_block
= innermost_block
;
7698 error (_("Junk at end of command."));
7700 if (accessflag
== hw_read
)
7701 bp_type
= bp_read_watchpoint
;
7702 else if (accessflag
== hw_access
)
7703 bp_type
= bp_access_watchpoint
;
7705 bp_type
= bp_hardware_watchpoint
;
7707 mem_cnt
= can_use_hardware_watchpoint (val
);
7708 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7709 error (_("Expression cannot be implemented with read/access watchpoint."));
7712 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7713 target_resources_ok
=
7714 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7716 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7717 error (_("Target does not support this type of hardware watchpoint."));
7719 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7720 error (_("Target can only support one kind of HW watchpoint at a time."));
7723 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7724 watchpoint could not be set. */
7725 if (!mem_cnt
|| target_resources_ok
<= 0)
7726 bp_type
= bp_watchpoint
;
7728 frame
= block_innermost_frame (exp_valid_block
);
7730 /* If the expression is "local", then set up a "watchpoint scope"
7731 breakpoint at the point where we've left the scope of the watchpoint
7732 expression. Create the scope breakpoint before the watchpoint, so
7733 that we will encounter it first in bpstat_stop_status. */
7734 if (exp_valid_block
&& frame
)
7736 if (frame_id_p (frame_unwind_caller_id (frame
)))
7739 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7740 frame_unwind_caller_pc (frame
),
7741 bp_watchpoint_scope
);
7743 scope_breakpoint
->enable_state
= bp_enabled
;
7745 /* Automatically delete the breakpoint when it hits. */
7746 scope_breakpoint
->disposition
= disp_del
;
7748 /* Only break in the proper frame (help with recursion). */
7749 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7751 /* Set the address at which we will stop. */
7752 scope_breakpoint
->loc
->gdbarch
7753 = frame_unwind_caller_arch (frame
);
7754 scope_breakpoint
->loc
->requested_address
7755 = frame_unwind_caller_pc (frame
);
7756 scope_breakpoint
->loc
->address
7757 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7758 scope_breakpoint
->loc
->requested_address
,
7759 scope_breakpoint
->type
);
7763 /* Now set up the breakpoint. */
7764 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7765 set_breakpoint_count (breakpoint_count
+ 1);
7766 b
->number
= breakpoint_count
;
7768 b
->disposition
= disp_donttouch
;
7770 b
->exp_valid_block
= exp_valid_block
;
7771 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7772 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7776 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7782 b
->watchpoint_frame
= get_frame_id (frame
);
7783 b
->watchpoint_thread
= inferior_ptid
;
7787 b
->watchpoint_frame
= null_frame_id
;
7788 b
->watchpoint_thread
= null_ptid
;
7791 if (scope_breakpoint
!= NULL
)
7793 /* The scope breakpoint is related to the watchpoint. We will
7794 need to act on them together. */
7795 b
->related_breakpoint
= scope_breakpoint
;
7796 scope_breakpoint
->related_breakpoint
= b
;
7799 value_free_to_mark (mark
);
7801 /* Finally update the new watchpoint. This creates the locations
7802 that should be inserted. */
7803 update_watchpoint (b
, 1);
7806 update_global_location_list (1);
7809 /* Return count of locations need to be watched and can be handled
7810 in hardware. If the watchpoint can not be handled
7811 in hardware return zero. */
7814 can_use_hardware_watchpoint (struct value
*v
)
7816 int found_memory_cnt
= 0;
7817 struct value
*head
= v
;
7819 /* Did the user specifically forbid us to use hardware watchpoints? */
7820 if (!can_use_hw_watchpoints
)
7823 /* Make sure that the value of the expression depends only upon
7824 memory contents, and values computed from them within GDB. If we
7825 find any register references or function calls, we can't use a
7826 hardware watchpoint.
7828 The idea here is that evaluating an expression generates a series
7829 of values, one holding the value of every subexpression. (The
7830 expression a*b+c has five subexpressions: a, b, a*b, c, and
7831 a*b+c.) GDB's values hold almost enough information to establish
7832 the criteria given above --- they identify memory lvalues,
7833 register lvalues, computed values, etcetera. So we can evaluate
7834 the expression, and then scan the chain of values that leaves
7835 behind to decide whether we can detect any possible change to the
7836 expression's final value using only hardware watchpoints.
7838 However, I don't think that the values returned by inferior
7839 function calls are special in any way. So this function may not
7840 notice that an expression involving an inferior function call
7841 can't be watched with hardware watchpoints. FIXME. */
7842 for (; v
; v
= value_next (v
))
7844 if (VALUE_LVAL (v
) == lval_memory
)
7847 /* A lazy memory lvalue is one that GDB never needed to fetch;
7848 we either just used its address (e.g., `a' in `a.b') or
7849 we never needed it at all (e.g., `a' in `a,b'). */
7853 /* Ahh, memory we actually used! Check if we can cover
7854 it with hardware watchpoints. */
7855 struct type
*vtype
= check_typedef (value_type (v
));
7857 /* We only watch structs and arrays if user asked for it
7858 explicitly, never if they just happen to appear in a
7859 middle of some value chain. */
7861 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7862 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7864 CORE_ADDR vaddr
= value_address (v
);
7865 int len
= TYPE_LENGTH (value_type (v
));
7867 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7874 else if (VALUE_LVAL (v
) != not_lval
7875 && deprecated_value_modifiable (v
) == 0)
7876 return 0; /* ??? What does this represent? */
7877 else if (VALUE_LVAL (v
) == lval_register
)
7878 return 0; /* cannot watch a register with a HW watchpoint */
7881 /* The expression itself looks suitable for using a hardware
7882 watchpoint, but give the target machine a chance to reject it. */
7883 return found_memory_cnt
;
7887 watch_command_wrapper (char *arg
, int from_tty
)
7889 watch_command (arg
, from_tty
);
7893 watch_command (char *arg
, int from_tty
)
7895 watch_command_1 (arg
, hw_write
, from_tty
);
7899 rwatch_command_wrapper (char *arg
, int from_tty
)
7901 rwatch_command (arg
, from_tty
);
7905 rwatch_command (char *arg
, int from_tty
)
7907 watch_command_1 (arg
, hw_read
, from_tty
);
7911 awatch_command_wrapper (char *arg
, int from_tty
)
7913 awatch_command (arg
, from_tty
);
7917 awatch_command (char *arg
, int from_tty
)
7919 watch_command_1 (arg
, hw_access
, from_tty
);
7923 /* Helper routines for the until_command routine in infcmd.c. Here
7924 because it uses the mechanisms of breakpoints. */
7926 struct until_break_command_continuation_args
7928 struct breakpoint
*breakpoint
;
7929 struct breakpoint
*breakpoint2
;
7932 /* This function is called by fetch_inferior_event via the
7933 cmd_continuation pointer, to complete the until command. It takes
7934 care of cleaning up the temporary breakpoints set up by the until
7937 until_break_command_continuation (void *arg
)
7939 struct until_break_command_continuation_args
*a
= arg
;
7941 delete_breakpoint (a
->breakpoint
);
7943 delete_breakpoint (a
->breakpoint2
);
7947 until_break_command (char *arg
, int from_tty
, int anywhere
)
7949 struct symtabs_and_lines sals
;
7950 struct symtab_and_line sal
;
7951 struct frame_info
*frame
= get_selected_frame (NULL
);
7952 struct breakpoint
*breakpoint
;
7953 struct breakpoint
*breakpoint2
= NULL
;
7954 struct cleanup
*old_chain
;
7956 clear_proceed_status ();
7958 /* Set a breakpoint where the user wants it and at return from
7961 if (default_breakpoint_valid
)
7962 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
7963 default_breakpoint_line
, (char ***) NULL
, NULL
);
7965 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
7966 0, (char ***) NULL
, NULL
);
7968 if (sals
.nelts
!= 1)
7969 error (_("Couldn't get information on specified line."));
7972 xfree (sals
.sals
); /* malloc'd, so freed */
7975 error (_("Junk at end of arguments."));
7977 resolve_sal_pc (&sal
);
7980 /* If the user told us to continue until a specified location,
7981 we don't specify a frame at which we need to stop. */
7982 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7983 null_frame_id
, bp_until
);
7985 /* Otherwise, specify the selected frame, because we want to stop only
7986 at the very same frame. */
7987 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7988 get_stack_frame_id (frame
),
7991 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
7993 /* Keep within the current frame, or in frames called by the current
7996 if (frame_id_p (frame_unwind_caller_id (frame
)))
7998 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
7999 sal
.pc
= frame_unwind_caller_pc (frame
);
8000 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8002 frame_unwind_caller_id (frame
),
8004 make_cleanup_delete_breakpoint (breakpoint2
);
8007 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8009 /* If we are running asynchronously, and proceed call above has actually
8010 managed to start the target, arrange for breakpoints to be
8011 deleted when the target stops. Otherwise, we're already stopped and
8012 delete breakpoints via cleanup chain. */
8014 if (target_can_async_p () && is_running (inferior_ptid
))
8016 struct until_break_command_continuation_args
*args
;
8017 args
= xmalloc (sizeof (*args
));
8019 args
->breakpoint
= breakpoint
;
8020 args
->breakpoint2
= breakpoint2
;
8022 discard_cleanups (old_chain
);
8023 add_continuation (inferior_thread (),
8024 until_break_command_continuation
, args
,
8028 do_cleanups (old_chain
);
8032 ep_skip_leading_whitespace (char **s
)
8034 if ((s
== NULL
) || (*s
== NULL
))
8036 while (isspace (**s
))
8040 /* This function attempts to parse an optional "if <cond>" clause
8041 from the arg string. If one is not found, it returns NULL.
8043 Else, it returns a pointer to the condition string. (It does not
8044 attempt to evaluate the string against a particular block.) And,
8045 it updates arg to point to the first character following the parsed
8046 if clause in the arg string. */
8049 ep_parse_optional_if_clause (char **arg
)
8053 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8056 /* Skip the "if" keyword. */
8059 /* Skip any extra leading whitespace, and record the start of the
8060 condition string. */
8061 ep_skip_leading_whitespace (arg
);
8064 /* Assume that the condition occupies the remainder of the arg string. */
8065 (*arg
) += strlen (cond_string
);
8070 /* Commands to deal with catching events, such as signals, exceptions,
8071 process start/exit, etc. */
8075 catch_fork_temporary
, catch_vfork_temporary
,
8076 catch_fork_permanent
, catch_vfork_permanent
8081 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8083 struct gdbarch
*gdbarch
= get_current_arch ();
8084 char *cond_string
= NULL
;
8085 catch_fork_kind fork_kind
;
8088 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8089 tempflag
= (fork_kind
== catch_fork_temporary
8090 || fork_kind
== catch_vfork_temporary
);
8094 ep_skip_leading_whitespace (&arg
);
8096 /* The allowed syntax is:
8098 catch [v]fork if <cond>
8100 First, check if there's an if clause. */
8101 cond_string
= ep_parse_optional_if_clause (&arg
);
8103 if ((*arg
!= '\0') && !isspace (*arg
))
8104 error (_("Junk at end of arguments."));
8106 /* If this target supports it, create a fork or vfork catchpoint
8107 and enable reporting of such events. */
8110 case catch_fork_temporary
:
8111 case catch_fork_permanent
:
8112 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8113 &catch_fork_breakpoint_ops
);
8115 case catch_vfork_temporary
:
8116 case catch_vfork_permanent
:
8117 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8118 &catch_vfork_breakpoint_ops
);
8121 error (_("unsupported or unknown fork kind; cannot catch it"));
8127 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8129 struct gdbarch
*gdbarch
= get_current_arch ();
8131 char *cond_string
= NULL
;
8133 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8137 ep_skip_leading_whitespace (&arg
);
8139 /* The allowed syntax is:
8141 catch exec if <cond>
8143 First, check if there's an if clause. */
8144 cond_string
= ep_parse_optional_if_clause (&arg
);
8146 if ((*arg
!= '\0') && !isspace (*arg
))
8147 error (_("Junk at end of arguments."));
8149 /* If this target supports it, create an exec catchpoint
8150 and enable reporting of such events. */
8151 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8152 &catch_exec_breakpoint_ops
);
8155 static enum print_stop_action
8156 print_exception_catchpoint (struct breakpoint
*b
)
8158 int bp_temp
, bp_throw
;
8160 annotate_catchpoint (b
->number
);
8162 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8163 if (b
->loc
->address
!= b
->loc
->requested_address
)
8164 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8167 bp_temp
= b
->disposition
== disp_del
;
8169 bp_temp
? "Temporary catchpoint "
8171 if (!ui_out_is_mi_like_p (uiout
))
8172 ui_out_field_int (uiout
, "bkptno", b
->number
);
8174 bp_throw
? " (exception thrown), "
8175 : " (exception caught), ");
8176 if (ui_out_is_mi_like_p (uiout
))
8178 ui_out_field_string (uiout
, "reason",
8179 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8180 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8181 ui_out_field_int (uiout
, "bkptno", b
->number
);
8183 return PRINT_SRC_AND_LOC
;
8187 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8189 struct value_print_options opts
;
8190 get_user_print_options (&opts
);
8191 if (opts
.addressprint
)
8194 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8195 ui_out_field_string (uiout
, "addr", "<PENDING>");
8197 ui_out_field_core_addr (uiout
, "addr",
8198 b
->loc
->gdbarch
, b
->loc
->address
);
8203 if (strstr (b
->addr_string
, "throw") != NULL
)
8204 ui_out_field_string (uiout
, "what", "exception throw");
8206 ui_out_field_string (uiout
, "what", "exception catch");
8210 print_mention_exception_catchpoint (struct breakpoint
*b
)
8215 bp_temp
= b
->disposition
== disp_del
;
8216 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8217 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8218 : _("Catchpoint "));
8219 ui_out_field_int (uiout
, "bkptno", b
->number
);
8220 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8224 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8227 NULL
, /* breakpoint_hit */
8228 print_exception_catchpoint
,
8229 print_one_exception_catchpoint
,
8230 print_mention_exception_catchpoint
8234 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8235 enum exception_event_kind ex_event
, int from_tty
)
8237 char *trigger_func_name
;
8239 if (ex_event
== EX_EVENT_CATCH
)
8240 trigger_func_name
= "__cxa_begin_catch";
8242 trigger_func_name
= "__cxa_throw";
8244 create_breakpoint (get_current_arch (),
8245 trigger_func_name
, cond_string
, -1,
8246 0 /* condition and thread are valid. */,
8249 AUTO_BOOLEAN_TRUE
/* pending */,
8250 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8256 /* Deal with "catch catch" and "catch throw" commands */
8259 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8260 int tempflag
, int from_tty
)
8262 char *cond_string
= NULL
;
8263 struct symtab_and_line
*sal
= NULL
;
8267 ep_skip_leading_whitespace (&arg
);
8269 cond_string
= ep_parse_optional_if_clause (&arg
);
8271 if ((*arg
!= '\0') && !isspace (*arg
))
8272 error (_("Junk at end of arguments."));
8274 if (ex_event
!= EX_EVENT_THROW
8275 && ex_event
!= EX_EVENT_CATCH
)
8276 error (_("Unsupported or unknown exception event; cannot catch it"));
8278 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8281 warning (_("Unsupported with this platform/compiler combination."));
8284 /* Implementation of "catch catch" command. */
8287 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8289 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8290 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8293 /* Implementation of "catch throw" command. */
8296 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8298 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8299 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8302 /* Create a breakpoint struct for Ada exception catchpoints. */
8305 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8306 struct symtab_and_line sal
,
8310 struct expression
*cond
,
8311 struct breakpoint_ops
*ops
,
8315 struct breakpoint
*b
;
8319 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8321 loc_gdbarch
= gdbarch
;
8323 describe_other_breakpoints (loc_gdbarch
,
8324 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8325 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8326 version for exception catchpoints, because two catchpoints
8327 used for different exception names will use the same address.
8328 In this case, a "breakpoint ... also set at..." warning is
8329 unproductive. Besides. the warning phrasing is also a bit
8330 inapropriate, we should use the word catchpoint, and tell
8331 the user what type of catchpoint it is. The above is good
8332 enough for now, though. */
8335 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8336 set_breakpoint_count (breakpoint_count
+ 1);
8338 b
->enable_state
= bp_enabled
;
8339 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8340 b
->number
= breakpoint_count
;
8341 b
->ignore_count
= 0;
8342 b
->loc
->cond
= cond
;
8343 b
->addr_string
= addr_string
;
8344 b
->language
= language_ada
;
8345 b
->cond_string
= cond_string
;
8346 b
->exp_string
= exp_string
;
8351 update_global_location_list (1);
8354 /* Implement the "catch exception" command. */
8357 catch_ada_exception_command (char *arg
, int from_tty
,
8358 struct cmd_list_element
*command
)
8360 struct gdbarch
*gdbarch
= get_current_arch ();
8362 struct symtab_and_line sal
;
8364 char *addr_string
= NULL
;
8365 char *exp_string
= NULL
;
8366 char *cond_string
= NULL
;
8367 struct expression
*cond
= NULL
;
8368 struct breakpoint_ops
*ops
= NULL
;
8370 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8374 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8375 &cond_string
, &cond
, &ops
);
8376 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8377 cond_string
, cond
, ops
, tempflag
,
8381 /* Cleanup function for a syscall filter list. */
8383 clean_up_filters (void *arg
)
8385 VEC(int) *iter
= *(VEC(int) **) arg
;
8386 VEC_free (int, iter
);
8389 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8390 filter list, or NULL if no filtering is required. */
8392 catch_syscall_split_args (char *arg
)
8394 VEC(int) *result
= NULL
;
8395 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8397 while (*arg
!= '\0')
8399 int i
, syscall_number
;
8404 /* Skip whitespace. */
8405 while (isspace (*arg
))
8408 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8409 cur_name
[i
] = arg
[i
];
8413 /* Check if the user provided a syscall name or a number. */
8414 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8415 if (*endptr
== '\0')
8416 get_syscall_by_number (syscall_number
, &s
);
8419 /* We have a name. Let's check if it's valid and convert it
8421 get_syscall_by_name (cur_name
, &s
);
8423 if (s
.number
== UNKNOWN_SYSCALL
)
8424 /* Here we have to issue an error instead of a warning, because
8425 GDB cannot do anything useful if there's no syscall number to
8427 error (_("Unknown syscall name '%s'."), cur_name
);
8430 /* Ok, it's valid. */
8431 VEC_safe_push (int, result
, s
.number
);
8434 discard_cleanups (cleanup
);
8438 /* Implement the "catch syscall" command. */
8441 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8446 struct gdbarch
*gdbarch
= get_current_arch ();
8448 /* Checking if the feature if supported. */
8449 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8450 error (_("The feature 'catch syscall' is not supported on \
8451 this architeture yet."));
8453 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8455 ep_skip_leading_whitespace (&arg
);
8457 /* We need to do this first "dummy" translation in order
8458 to get the syscall XML file loaded or, most important,
8459 to display a warning to the user if there's no XML file
8460 for his/her architecture. */
8461 get_syscall_by_number (0, &s
);
8463 /* The allowed syntax is:
8465 catch syscall <name | number> [<name | number> ... <name | number>]
8467 Let's check if there's a syscall name. */
8470 filter
= catch_syscall_split_args (arg
);
8474 create_syscall_event_catchpoint (tempflag
, filter
,
8475 &catch_syscall_breakpoint_ops
);
8478 /* Implement the "catch assert" command. */
8481 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8483 struct gdbarch
*gdbarch
= get_current_arch ();
8485 struct symtab_and_line sal
;
8486 char *addr_string
= NULL
;
8487 struct breakpoint_ops
*ops
= NULL
;
8489 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8493 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8494 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8495 ops
, tempflag
, from_tty
);
8499 catch_command (char *arg
, int from_tty
)
8501 error (_("Catch requires an event name."));
8506 tcatch_command (char *arg
, int from_tty
)
8508 error (_("Catch requires an event name."));
8511 /* Delete breakpoints by address or line. */
8514 clear_command (char *arg
, int from_tty
)
8516 struct breakpoint
*b
;
8517 VEC(breakpoint_p
) *found
= 0;
8520 struct symtabs_and_lines sals
;
8521 struct symtab_and_line sal
;
8526 sals
= decode_line_spec (arg
, 1);
8531 sals
.sals
= (struct symtab_and_line
*)
8532 xmalloc (sizeof (struct symtab_and_line
));
8533 make_cleanup (xfree
, sals
.sals
);
8534 init_sal (&sal
); /* initialize to zeroes */
8535 sal
.line
= default_breakpoint_line
;
8536 sal
.symtab
= default_breakpoint_symtab
;
8537 sal
.pc
= default_breakpoint_address
;
8538 sal
.pspace
= default_breakpoint_pspace
;
8539 if (sal
.symtab
== 0)
8540 error (_("No source file specified."));
8548 /* We don't call resolve_sal_pc here. That's not
8549 as bad as it seems, because all existing breakpoints
8550 typically have both file/line and pc set. So, if
8551 clear is given file/line, we can match this to existing
8552 breakpoint without obtaining pc at all.
8554 We only support clearing given the address explicitly
8555 present in breakpoint table. Say, we've set breakpoint
8556 at file:line. There were several PC values for that file:line,
8557 due to optimization, all in one block.
8558 We've picked one PC value. If "clear" is issued with another
8559 PC corresponding to the same file:line, the breakpoint won't
8560 be cleared. We probably can still clear the breakpoint, but
8561 since the other PC value is never presented to user, user
8562 can only find it by guessing, and it does not seem important
8565 /* For each line spec given, delete bps which correspond
8566 to it. Do it in two passes, solely to preserve the current
8567 behavior that from_tty is forced true if we delete more than
8571 for (i
= 0; i
< sals
.nelts
; i
++)
8573 /* If exact pc given, clear bpts at that pc.
8574 If line given (pc == 0), clear all bpts on specified line.
8575 If defaulting, clear all bpts on default line
8578 defaulting sal.pc != 0 tests to do
8583 1 0 <can't happen> */
8587 /* Find all matching breakpoints and add them to
8592 /* Are we going to delete b? */
8593 if (b
->type
!= bp_none
8594 && b
->type
!= bp_watchpoint
8595 && b
->type
!= bp_hardware_watchpoint
8596 && b
->type
!= bp_read_watchpoint
8597 && b
->type
!= bp_access_watchpoint
)
8599 struct bp_location
*loc
= b
->loc
;
8600 for (; loc
; loc
= loc
->next
)
8602 int pc_match
= sal
.pc
8603 && (loc
->pspace
== sal
.pspace
)
8604 && (loc
->address
== sal
.pc
)
8605 && (!section_is_overlay (loc
->section
)
8606 || loc
->section
== sal
.section
);
8607 int line_match
= ((default_match
|| (0 == sal
.pc
))
8608 && b
->source_file
!= NULL
8609 && sal
.symtab
!= NULL
8610 && sal
.pspace
== loc
->pspace
8611 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8612 && b
->line_number
== sal
.line
);
8613 if (pc_match
|| line_match
)
8622 VEC_safe_push(breakpoint_p
, found
, b
);
8625 /* Now go thru the 'found' chain and delete them. */
8626 if (VEC_empty(breakpoint_p
, found
))
8629 error (_("No breakpoint at %s."), arg
);
8631 error (_("No breakpoint at this line."));
8634 if (VEC_length(breakpoint_p
, found
) > 1)
8635 from_tty
= 1; /* Always report if deleted more than one */
8638 if (VEC_length(breakpoint_p
, found
) == 1)
8639 printf_unfiltered (_("Deleted breakpoint "));
8641 printf_unfiltered (_("Deleted breakpoints "));
8643 breakpoints_changed ();
8645 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8648 printf_unfiltered ("%d ", b
->number
);
8649 delete_breakpoint (b
);
8652 putchar_unfiltered ('\n');
8655 /* Delete breakpoint in BS if they are `delete' breakpoints and
8656 all breakpoints that are marked for deletion, whether hit or not.
8657 This is called after any breakpoint is hit, or after errors. */
8660 breakpoint_auto_delete (bpstat bs
)
8662 struct breakpoint
*b
, *temp
;
8664 for (; bs
; bs
= bs
->next
)
8665 if (bs
->breakpoint_at
8666 && bs
->breakpoint_at
->owner
8667 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8669 delete_breakpoint (bs
->breakpoint_at
->owner
);
8671 ALL_BREAKPOINTS_SAFE (b
, temp
)
8673 if (b
->disposition
== disp_del_at_next_stop
)
8674 delete_breakpoint (b
);
8678 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8679 Sort elements primarily by their ADDRESS (no matter what does
8680 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8681 first bp_permanent OWNERed elements and terciarily just ensuring the array
8682 is sorted stable way despite qsort being an instable algorithm. */
8685 bp_location_compare (const void *ap
, const void *bp
)
8687 struct bp_location
*a
= *(void **) ap
;
8688 struct bp_location
*b
= *(void **) bp
;
8689 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8690 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8692 if (a
->address
!= b
->address
)
8693 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8695 /* Sort permanent breakpoints first. */
8696 if (a_perm
!= b_perm
)
8697 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8699 /* Make the user-visible order stable across GDB runs. Locations of the same
8700 breakpoint can be sorted in arbitrary order. */
8702 if (a
->owner
->number
!= b
->owner
->number
)
8703 return (a
->owner
->number
> b
->owner
->number
)
8704 - (a
->owner
->number
< b
->owner
->number
);
8706 return (a
> b
) - (a
< b
);
8709 /* Set bp_location_placed_address_before_address_max and
8710 bp_location_shadow_len_after_address_max according to the current content of
8711 the bp_location array. */
8714 bp_location_target_extensions_update (void)
8716 struct bp_location
*bl
, **blp_tmp
;
8718 bp_location_placed_address_before_address_max
= 0;
8719 bp_location_shadow_len_after_address_max
= 0;
8721 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8723 CORE_ADDR start
, end
, addr
;
8725 if (!bp_location_has_shadow (bl
))
8728 start
= bl
->target_info
.placed_address
;
8729 end
= start
+ bl
->target_info
.shadow_len
;
8731 gdb_assert (bl
->address
>= start
);
8732 addr
= bl
->address
- start
;
8733 if (addr
> bp_location_placed_address_before_address_max
)
8734 bp_location_placed_address_before_address_max
= addr
;
8736 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8738 gdb_assert (bl
->address
< end
);
8739 addr
= end
- bl
->address
;
8740 if (addr
> bp_location_shadow_len_after_address_max
)
8741 bp_location_shadow_len_after_address_max
= addr
;
8745 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8746 into the inferior, only remove already-inserted locations that no
8747 longer should be inserted. Functions that delete a breakpoint or
8748 breakpoints should pass false, so that deleting a breakpoint
8749 doesn't have the side effect of inserting the locations of other
8750 breakpoints that are marked not-inserted, but should_be_inserted
8751 returns true on them.
8753 This behaviour is useful is situations close to tear-down -- e.g.,
8754 after an exec, while the target still has execution, but breakpoint
8755 shadows of the previous executable image should *NOT* be restored
8756 to the new image; or before detaching, where the target still has
8757 execution and wants to delete breakpoints from GDB's lists, and all
8758 breakpoints had already been removed from the inferior. */
8761 update_global_location_list (int should_insert
)
8763 struct breakpoint
*b
;
8764 struct bp_location
**locp
, *loc
;
8765 struct cleanup
*cleanups
;
8767 /* Used in the duplicates detection below. When iterating over all
8768 bp_locations, points to the first bp_location of a given address.
8769 Breakpoints and watchpoints of different types are never
8770 duplicates of each other. Keep one pointer for each type of
8771 breakpoint/watchpoint, so we only need to loop over all locations
8773 struct bp_location
*bp_loc_first
; /* breakpoint */
8774 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8775 struct bp_location
*awp_loc_first
; /* access watchpoint */
8776 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8778 /* Saved former bp_location array which we compare against the newly built
8779 bp_location from the current state of ALL_BREAKPOINTS. */
8780 struct bp_location
**old_location
, **old_locp
;
8781 unsigned old_location_count
;
8783 old_location
= bp_location
;
8784 old_location_count
= bp_location_count
;
8786 bp_location_count
= 0;
8787 cleanups
= make_cleanup (xfree
, old_location
);
8790 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8791 bp_location_count
++;
8793 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8796 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8798 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8799 bp_location_compare
);
8801 bp_location_target_extensions_update ();
8803 /* Identify bp_location instances that are no longer present in the new
8804 list, and therefore should be freed. Note that it's not necessary that
8805 those locations should be removed from inferior -- if there's another
8806 location at the same address (previously marked as duplicate),
8807 we don't need to remove/insert the location.
8809 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8810 former bp_location array state respectively. */
8813 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8816 struct bp_location
*old_loc
= *old_locp
;
8817 struct bp_location
**loc2p
;
8819 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8821 int found_object
= 0;
8822 /* Tells if the location should remain inserted in the target. */
8823 int keep_in_target
= 0;
8826 /* Skip LOCP entries which will definitely never be needed. Stop either
8827 at or being the one matching OLD_LOC. */
8828 while (locp
< bp_location
+ bp_location_count
8829 && (*locp
)->address
< old_loc
->address
)
8833 (loc2p
< bp_location
+ bp_location_count
8834 && (*loc2p
)->address
== old_loc
->address
);
8837 if (*loc2p
== old_loc
)
8844 /* If this location is no longer present, and inserted, look if there's
8845 maybe a new location at the same address. If so, mark that one
8846 inserted, and don't remove this one. This is needed so that we
8847 don't have a time window where a breakpoint at certain location is not
8850 if (old_loc
->inserted
)
8852 /* If the location is inserted now, we might have to remove it. */
8854 if (found_object
&& should_be_inserted (old_loc
))
8856 /* The location is still present in the location list, and still
8857 should be inserted. Don't do anything. */
8862 /* The location is either no longer present, or got disabled.
8863 See if there's another location at the same address, in which
8864 case we don't need to remove this one from the target. */
8866 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8869 (loc2p
< bp_location
+ bp_location_count
8870 && (*loc2p
)->address
== old_loc
->address
);
8873 struct bp_location
*loc2
= *loc2p
;
8875 if (breakpoint_locations_match (loc2
, old_loc
))
8877 /* For the sake of should_be_inserted.
8878 Duplicates check below will fix up this later. */
8879 loc2
->duplicate
= 0;
8881 /* Read watchpoint locations are switched to
8882 access watchpoints, if the former are not
8883 supported, but the latter are. */
8884 if (is_hardware_watchpoint (old_loc
->owner
))
8886 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8887 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8890 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8893 loc2
->target_info
= old_loc
->target_info
;
8902 if (!keep_in_target
)
8904 if (remove_breakpoint (old_loc
, mark_uninserted
))
8906 /* This is just about all we can do. We could keep this
8907 location on the global list, and try to remove it next
8908 time, but there's no particular reason why we will
8911 Note that at this point, old_loc->owner is still valid,
8912 as delete_breakpoint frees the breakpoint only
8913 after calling us. */
8914 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8915 old_loc
->owner
->number
);
8923 if (removed
&& non_stop
8924 && breakpoint_address_is_meaningful (old_loc
->owner
)
8925 && !is_hardware_watchpoint (old_loc
->owner
))
8927 /* This location was removed from the target. In
8928 non-stop mode, a race condition is possible where
8929 we've removed a breakpoint, but stop events for that
8930 breakpoint are already queued and will arrive later.
8931 We apply an heuristic to be able to distinguish such
8932 SIGTRAPs from other random SIGTRAPs: we keep this
8933 breakpoint location for a bit, and will retire it
8934 after we see some number of events. The theory here
8935 is that reporting of events should, "on the average",
8936 be fair, so after a while we'll see events from all
8937 threads that have anything of interest, and no longer
8938 need to keep this breakpoint location around. We
8939 don't hold locations forever so to reduce chances of
8940 mistaking a non-breakpoint SIGTRAP for a breakpoint
8943 The heuristic failing can be disastrous on
8944 decr_pc_after_break targets.
8946 On decr_pc_after_break targets, like e.g., x86-linux,
8947 if we fail to recognize a late breakpoint SIGTRAP,
8948 because events_till_retirement has reached 0 too
8949 soon, we'll fail to do the PC adjustment, and report
8950 a random SIGTRAP to the user. When the user resumes
8951 the inferior, it will most likely immediately crash
8952 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8953 corrupted, because of being resumed e.g., in the
8954 middle of a multi-byte instruction, or skipped a
8955 one-byte instruction. This was actually seen happen
8956 on native x86-linux, and should be less rare on
8957 targets that do not support new thread events, like
8958 remote, due to the heuristic depending on
8961 Mistaking a random SIGTRAP for a breakpoint trap
8962 causes similar symptoms (PC adjustment applied when
8963 it shouldn't), but then again, playing with SIGTRAPs
8964 behind the debugger's back is asking for trouble.
8966 Since hardware watchpoint traps are always
8967 distinguishable from other traps, so we don't need to
8968 apply keep hardware watchpoint moribund locations
8969 around. We simply always ignore hardware watchpoint
8970 traps we can no longer explain. */
8972 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
8973 old_loc
->owner
= NULL
;
8975 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
8978 free_bp_location (old_loc
);
8982 /* Rescan breakpoints at the same address and section, marking the
8983 first one as "first" and any others as "duplicates". This is so
8984 that the bpt instruction is only inserted once. If we have a
8985 permanent breakpoint at the same place as BPT, make that one the
8986 official one, and the rest as duplicates. Permanent breakpoints
8987 are sorted first for the same address.
8989 Do the same for hardware watchpoints, but also considering the
8990 watchpoint's type (regular/access/read) and length. */
8992 bp_loc_first
= NULL
;
8993 wp_loc_first
= NULL
;
8994 awp_loc_first
= NULL
;
8995 rwp_loc_first
= NULL
;
8996 ALL_BP_LOCATIONS (loc
, locp
)
8998 struct breakpoint
*b
= loc
->owner
;
8999 struct bp_location
**loc_first_p
;
9001 if (b
->enable_state
== bp_disabled
9002 || b
->enable_state
== bp_call_disabled
9003 || b
->enable_state
== bp_startup_disabled
9005 || loc
->shlib_disabled
9006 || !breakpoint_address_is_meaningful (b
)
9007 || tracepoint_type (b
))
9010 /* Permanent breakpoint should always be inserted. */
9011 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9012 internal_error (__FILE__
, __LINE__
,
9013 _("allegedly permanent breakpoint is not "
9014 "actually inserted"));
9016 if (b
->type
== bp_hardware_watchpoint
)
9017 loc_first_p
= &wp_loc_first
;
9018 else if (b
->type
== bp_read_watchpoint
)
9019 loc_first_p
= &rwp_loc_first
;
9020 else if (b
->type
== bp_access_watchpoint
)
9021 loc_first_p
= &awp_loc_first
;
9023 loc_first_p
= &bp_loc_first
;
9025 if (*loc_first_p
== NULL
9026 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9027 || !breakpoint_locations_match (loc
, *loc_first_p
))
9036 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9037 && b
->enable_state
!= bp_permanent
)
9038 internal_error (__FILE__
, __LINE__
,
9039 _("another breakpoint was inserted on top of "
9040 "a permanent breakpoint"));
9043 if (breakpoints_always_inserted_mode () && should_insert
9044 && (have_live_inferiors ()
9045 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9046 insert_breakpoint_locations ();
9048 do_cleanups (cleanups
);
9052 breakpoint_retire_moribund (void)
9054 struct bp_location
*loc
;
9057 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9058 if (--(loc
->events_till_retirement
) == 0)
9060 free_bp_location (loc
);
9061 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9067 update_global_location_list_nothrow (int inserting
)
9069 struct gdb_exception e
;
9070 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9071 update_global_location_list (inserting
);
9074 /* Clear BPT from a BPS. */
9076 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9079 for (bs
= bps
; bs
; bs
= bs
->next
)
9080 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9082 bs
->breakpoint_at
= NULL
;
9084 /* bs->commands will be freed later. */
9088 /* Callback for iterate_over_threads. */
9090 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9092 struct breakpoint
*bpt
= data
;
9093 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9097 /* Delete a breakpoint and clean up all traces of it in the data
9101 delete_breakpoint (struct breakpoint
*bpt
)
9103 struct breakpoint
*b
;
9104 struct bp_location
*loc
, *next
;
9106 gdb_assert (bpt
!= NULL
);
9108 /* Has this bp already been deleted? This can happen because multiple
9109 lists can hold pointers to bp's. bpstat lists are especial culprits.
9111 One example of this happening is a watchpoint's scope bp. When the
9112 scope bp triggers, we notice that the watchpoint is out of scope, and
9113 delete it. We also delete its scope bp. But the scope bp is marked
9114 "auto-deleting", and is already on a bpstat. That bpstat is then
9115 checked for auto-deleting bp's, which are deleted.
9117 A real solution to this problem might involve reference counts in bp's,
9118 and/or giving them pointers back to their referencing bpstat's, and
9119 teaching delete_breakpoint to only free a bp's storage when no more
9120 references were extent. A cheaper bandaid was chosen. */
9121 if (bpt
->type
== bp_none
)
9124 /* At least avoid this stale reference until the reference counting of
9125 breakpoints gets resolved. */
9126 if (bpt
->related_breakpoint
!= NULL
)
9128 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9129 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9130 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9131 bpt
->related_breakpoint
= NULL
;
9134 observer_notify_breakpoint_deleted (bpt
->number
);
9136 if (breakpoint_chain
== bpt
)
9137 breakpoint_chain
= bpt
->next
;
9142 b
->next
= bpt
->next
;
9146 decref_counted_command_line (&bpt
->commands
);
9147 xfree (bpt
->cond_string
);
9148 xfree (bpt
->cond_exp
);
9149 xfree (bpt
->addr_string
);
9151 xfree (bpt
->exp_string
);
9152 value_free (bpt
->val
);
9153 xfree (bpt
->source_file
);
9154 xfree (bpt
->exec_pathname
);
9155 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9157 /* Be sure no bpstat's are pointing at it after it's been freed. */
9158 /* FIXME, how can we find all bpstat's?
9159 We just check stop_bpstat for now. Note that we cannot just
9160 remove bpstats pointing at bpt from the stop_bpstat list
9161 entirely, as breakpoint commands are associated with the bpstat;
9162 if we remove it here, then the later call to
9163 bpstat_do_actions (&stop_bpstat);
9164 in event-top.c won't do anything, and temporary breakpoints
9165 with commands won't work. */
9167 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9169 /* Now that breakpoint is removed from breakpoint
9170 list, update the global location list. This
9171 will remove locations that used to belong to
9172 this breakpoint. Do this before freeing
9173 the breakpoint itself, since remove_breakpoint
9174 looks at location's owner. It might be better
9175 design to have location completely self-contained,
9176 but it's not the case now. */
9177 update_global_location_list (0);
9180 /* On the chance that someone will soon try again to delete this same
9181 bp, we mark it as deleted before freeing its storage. */
9182 bpt
->type
= bp_none
;
9188 do_delete_breakpoint_cleanup (void *b
)
9190 delete_breakpoint (b
);
9194 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9196 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9199 /* A callback for map_breakpoint_numbers that calls
9200 delete_breakpoint. */
9203 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
9205 delete_breakpoint (b
);
9209 delete_command (char *arg
, int from_tty
)
9211 struct breakpoint
*b
, *temp
;
9217 int breaks_to_delete
= 0;
9219 /* Delete all breakpoints if no argument.
9220 Do not delete internal or call-dummy breakpoints, these
9221 have to be deleted with an explicit breakpoint number argument. */
9224 if (b
->type
!= bp_call_dummy
9225 && b
->type
!= bp_shlib_event
9226 && b
->type
!= bp_jit_event
9227 && b
->type
!= bp_thread_event
9228 && b
->type
!= bp_overlay_event
9229 && b
->type
!= bp_longjmp_master
9232 breaks_to_delete
= 1;
9237 /* Ask user only if there are some breakpoints to delete. */
9239 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9241 ALL_BREAKPOINTS_SAFE (b
, temp
)
9243 if (b
->type
!= bp_call_dummy
9244 && b
->type
!= bp_shlib_event
9245 && b
->type
!= bp_thread_event
9246 && b
->type
!= bp_jit_event
9247 && b
->type
!= bp_overlay_event
9248 && b
->type
!= bp_longjmp_master
9250 delete_breakpoint (b
);
9255 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
9259 all_locations_are_pending (struct bp_location
*loc
)
9261 for (; loc
; loc
= loc
->next
)
9262 if (!loc
->shlib_disabled
)
9267 /* Subroutine of update_breakpoint_locations to simplify it.
9268 Return non-zero if multiple fns in list LOC have the same name.
9269 Null names are ignored. */
9272 ambiguous_names_p (struct bp_location
*loc
)
9274 struct bp_location
*l
;
9275 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9276 (int (*) (const void *, const void *)) streq
,
9277 NULL
, xcalloc
, xfree
);
9279 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9282 const char *name
= l
->function_name
;
9284 /* Allow for some names to be NULL, ignore them. */
9288 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9290 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9305 update_breakpoint_locations (struct breakpoint
*b
,
9306 struct symtabs_and_lines sals
)
9310 struct bp_location
*existing_locations
= b
->loc
;
9312 /* If there's no new locations, and all existing locations
9313 are pending, don't do anything. This optimizes
9314 the common case where all locations are in the same
9315 shared library, that was unloaded. We'd like to
9316 retain the location, so that when the library
9317 is loaded again, we don't loose the enabled/disabled
9318 status of the individual locations. */
9319 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9324 for (i
= 0; i
< sals
.nelts
; ++i
)
9326 struct bp_location
*new_loc
=
9327 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9329 /* Reparse conditions, they might contain references to the
9331 if (b
->cond_string
!= NULL
)
9333 struct gdb_exception e
;
9336 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9338 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9343 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9344 b
->number
, e
.message
);
9345 new_loc
->enabled
= 0;
9349 if (b
->source_file
!= NULL
)
9350 xfree (b
->source_file
);
9351 if (sals
.sals
[i
].symtab
== NULL
)
9352 b
->source_file
= NULL
;
9354 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9356 if (b
->line_number
== 0)
9357 b
->line_number
= sals
.sals
[i
].line
;
9360 /* Update locations of permanent breakpoints. */
9361 if (b
->enable_state
== bp_permanent
)
9362 make_breakpoint_permanent (b
);
9364 /* If possible, carry over 'disable' status from existing breakpoints. */
9366 struct bp_location
*e
= existing_locations
;
9367 /* If there are multiple breakpoints with the same function name,
9368 e.g. for inline functions, comparing function names won't work.
9369 Instead compare pc addresses; this is just a heuristic as things
9370 may have moved, but in practice it gives the correct answer
9371 often enough until a better solution is found. */
9372 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9374 for (; e
; e
= e
->next
)
9376 if (!e
->enabled
&& e
->function_name
)
9378 struct bp_location
*l
= b
->loc
;
9379 if (have_ambiguous_names
)
9381 for (; l
; l
= l
->next
)
9382 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9383 l
->pspace
->aspace
, l
->address
))
9391 for (; l
; l
= l
->next
)
9392 if (l
->function_name
9393 && strcmp (e
->function_name
, l
->function_name
) == 0)
9403 update_global_location_list (1);
9407 /* Reset a breakpoint given it's struct breakpoint * BINT.
9408 The value we return ends up being the return value from catch_errors.
9409 Unused in this case. */
9412 breakpoint_re_set_one (void *bint
)
9414 /* get past catch_errs */
9415 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9419 int *not_found_ptr
= ¬_found
;
9420 struct symtabs_and_lines sals
= {0};
9421 struct symtabs_and_lines expanded
= {0};
9423 enum enable_state save_enable
;
9424 struct gdb_exception e
;
9425 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9430 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9434 case bp_hardware_breakpoint
:
9436 case bp_fast_tracepoint
:
9437 /* Do not attempt to re-set breakpoints disabled during startup. */
9438 if (b
->enable_state
== bp_startup_disabled
)
9441 if (b
->addr_string
== NULL
)
9443 /* Anything without a string can't be re-set. */
9444 delete_breakpoint (b
);
9448 set_language (b
->language
);
9449 input_radix
= b
->input_radix
;
9452 save_current_space_and_thread ();
9453 switch_to_program_space_and_thread (b
->pspace
);
9455 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9457 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9462 int not_found_and_ok
= 0;
9463 /* For pending breakpoints, it's expected that parsing
9464 will fail until the right shared library is loaded.
9465 User has already told to create pending breakpoints and
9466 don't need extra messages. If breakpoint is in bp_shlib_disabled
9467 state, then user already saw the message about that breakpoint
9468 being disabled, and don't want to see more errors. */
9470 && (b
->condition_not_parsed
9471 || (b
->loc
&& b
->loc
->shlib_disabled
)
9472 || b
->enable_state
== bp_disabled
))
9473 not_found_and_ok
= 1;
9475 if (!not_found_and_ok
)
9477 /* We surely don't want to warn about the same breakpoint
9478 10 times. One solution, implemented here, is disable
9479 the breakpoint on error. Another solution would be to
9480 have separate 'warning emitted' flag. Since this
9481 happens only when a binary has changed, I don't know
9482 which approach is better. */
9483 b
->enable_state
= bp_disabled
;
9484 throw_exception (e
);
9490 gdb_assert (sals
.nelts
== 1);
9492 resolve_sal_pc (&sals
.sals
[0]);
9493 if (b
->condition_not_parsed
&& s
&& s
[0])
9495 char *cond_string
= 0;
9499 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9500 &cond_string
, &thread
, &task
);
9502 b
->cond_string
= cond_string
;
9505 b
->condition_not_parsed
= 0;
9508 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9511 make_cleanup (xfree
, sals
.sals
);
9512 update_breakpoint_locations (b
, expanded
);
9516 case bp_hardware_watchpoint
:
9517 case bp_read_watchpoint
:
9518 case bp_access_watchpoint
:
9519 /* Watchpoint can be either on expression using entirely global variables,
9520 or it can be on local variables.
9522 Watchpoints of the first kind are never auto-deleted, and even persist
9523 across program restarts. Since they can use variables from shared
9524 libraries, we need to reparse expression as libraries are loaded
9527 Watchpoints on local variables can also change meaning as result
9528 of solib event. For example, if a watchpoint uses both a local and
9529 a global variables in expression, it's a local watchpoint, but
9530 unloading of a shared library will make the expression invalid.
9531 This is not a very common use case, but we still re-evaluate
9532 expression, to avoid surprises to the user.
9534 Note that for local watchpoints, we re-evaluate it only if
9535 watchpoints frame id is still valid. If it's not, it means
9536 the watchpoint is out of scope and will be deleted soon. In fact,
9537 I'm not sure we'll ever be called in this case.
9539 If a local watchpoint's frame id is still valid, then
9540 b->exp_valid_block is likewise valid, and we can safely use it.
9542 Don't do anything about disabled watchpoints, since they will
9543 be reevaluated again when enabled. */
9544 update_watchpoint (b
, 1 /* reparse */);
9546 /* We needn't really do anything to reset these, since the mask
9547 that requests them is unaffected by e.g., new libraries being
9553 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9555 /* Delete overlay event and longjmp master breakpoints; they will be
9556 reset later by breakpoint_re_set. */
9557 case bp_overlay_event
:
9558 case bp_longjmp_master
:
9559 delete_breakpoint (b
);
9562 /* This breakpoint is special, it's set up when the inferior
9563 starts and we really don't want to touch it. */
9564 case bp_shlib_event
:
9566 /* Like bp_shlib_event, this breakpoint type is special.
9567 Once it is set up, we do not want to touch it. */
9568 case bp_thread_event
:
9570 /* Keep temporary breakpoints, which can be encountered when we step
9571 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9572 Otherwise these should have been blown away via the cleanup chain
9573 or by breakpoint_init_inferior when we rerun the executable. */
9576 case bp_watchpoint_scope
:
9578 case bp_step_resume
:
9580 case bp_longjmp_resume
:
9585 do_cleanups (cleanups
);
9589 /* Re-set all breakpoints after symbols have been re-loaded. */
9591 breakpoint_re_set (void)
9593 struct breakpoint
*b
, *temp
;
9594 enum language save_language
;
9595 int save_input_radix
;
9596 struct cleanup
*old_chain
;
9598 save_language
= current_language
->la_language
;
9599 save_input_radix
= input_radix
;
9600 old_chain
= save_current_program_space ();
9602 ALL_BREAKPOINTS_SAFE (b
, temp
)
9604 /* Format possible error msg */
9605 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9607 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9608 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9609 do_cleanups (cleanups
);
9611 set_language (save_language
);
9612 input_radix
= save_input_radix
;
9614 jit_breakpoint_re_set ();
9616 do_cleanups (old_chain
);
9618 create_overlay_event_breakpoint ("_ovly_debug_event");
9619 create_longjmp_master_breakpoint ("longjmp");
9620 create_longjmp_master_breakpoint ("_longjmp");
9621 create_longjmp_master_breakpoint ("siglongjmp");
9622 create_longjmp_master_breakpoint ("_siglongjmp");
9625 /* Reset the thread number of this breakpoint:
9627 - If the breakpoint is for all threads, leave it as-is.
9628 - Else, reset it to the current thread for inferior_ptid. */
9630 breakpoint_re_set_thread (struct breakpoint
*b
)
9632 if (b
->thread
!= -1)
9634 if (in_thread_list (inferior_ptid
))
9635 b
->thread
= pid_to_thread_id (inferior_ptid
);
9637 /* We're being called after following a fork. The new fork is
9638 selected as current, and unless this was a vfork will have a
9639 different program space from the original thread. Reset that
9641 b
->loc
->pspace
= current_program_space
;
9645 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9646 If from_tty is nonzero, it prints a message to that effect,
9647 which ends with a period (no newline). */
9650 set_ignore_count (int bptnum
, int count
, int from_tty
)
9652 struct breakpoint
*b
;
9658 if (b
->number
== bptnum
)
9660 b
->ignore_count
= count
;
9664 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9666 else if (count
== 1)
9667 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9670 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9673 breakpoints_changed ();
9674 observer_notify_breakpoint_modified (b
->number
);
9678 error (_("No breakpoint number %d."), bptnum
);
9682 make_breakpoint_silent (struct breakpoint
*b
)
9684 /* Silence the breakpoint. */
9688 /* Command to set ignore-count of breakpoint N to COUNT. */
9691 ignore_command (char *args
, int from_tty
)
9697 error_no_arg (_("a breakpoint number"));
9699 num
= get_number (&p
);
9701 error (_("bad breakpoint number: '%s'"), args
);
9703 error (_("Second argument (specified ignore-count) is missing."));
9705 set_ignore_count (num
,
9706 longest_to_int (value_as_long (parse_and_eval (p
))),
9709 printf_filtered ("\n");
9712 /* Call FUNCTION on each of the breakpoints
9713 whose numbers are given in ARGS. */
9716 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
9723 struct breakpoint
*b
, *tmp
;
9727 error_no_arg (_("one or more breakpoint numbers"));
9734 num
= get_number_or_range (&p1
);
9737 warning (_("bad breakpoint number at or near '%s'"), p
);
9741 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9742 if (b
->number
== num
)
9744 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9747 if (related_breakpoint
)
9748 function (related_breakpoint
, data
);
9752 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9758 static struct bp_location
*
9759 find_location_by_number (char *number
)
9761 char *dot
= strchr (number
, '.');
9765 struct breakpoint
*b
;
9766 struct bp_location
*loc
;
9771 bp_num
= get_number_or_range (&p1
);
9773 error (_("Bad breakpoint number '%s'"), number
);
9776 if (b
->number
== bp_num
)
9781 if (!b
|| b
->number
!= bp_num
)
9782 error (_("Bad breakpoint number '%s'"), number
);
9785 loc_num
= get_number_or_range (&p1
);
9787 error (_("Bad breakpoint location number '%s'"), number
);
9791 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9794 error (_("Bad breakpoint location number '%s'"), dot
+1);
9800 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9801 If from_tty is nonzero, it prints a message to that effect,
9802 which ends with a period (no newline). */
9805 disable_breakpoint (struct breakpoint
*bpt
)
9807 /* Never disable a watchpoint scope breakpoint; we want to
9808 hit them when we leave scope so we can delete both the
9809 watchpoint and its scope breakpoint at that time. */
9810 if (bpt
->type
== bp_watchpoint_scope
)
9813 /* You can't disable permanent breakpoints. */
9814 if (bpt
->enable_state
== bp_permanent
)
9817 bpt
->enable_state
= bp_disabled
;
9819 update_global_location_list (0);
9821 observer_notify_breakpoint_modified (bpt
->number
);
9824 /* A callback for map_breakpoint_numbers that calls
9825 disable_breakpoint. */
9828 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
9830 disable_breakpoint (b
);
9834 disable_command (char *args
, int from_tty
)
9836 struct breakpoint
*bpt
;
9838 ALL_BREAKPOINTS (bpt
)
9842 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9847 case bp_fast_tracepoint
:
9849 case bp_hardware_breakpoint
:
9851 case bp_hardware_watchpoint
:
9852 case bp_read_watchpoint
:
9853 case bp_access_watchpoint
:
9854 disable_breakpoint (bpt
);
9858 else if (strchr (args
, '.'))
9860 struct bp_location
*loc
= find_location_by_number (args
);
9863 update_global_location_list (0);
9866 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
9870 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9872 int target_resources_ok
, other_type_used
;
9875 if (bpt
->type
== bp_hardware_breakpoint
)
9878 i
= hw_breakpoint_used_count ();
9879 target_resources_ok
=
9880 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9882 if (target_resources_ok
== 0)
9883 error (_("No hardware breakpoint support in the target."));
9884 else if (target_resources_ok
< 0)
9885 error (_("Hardware breakpoints used exceeds limit."));
9888 if (bpt
->type
== bp_watchpoint
9889 || bpt
->type
== bp_hardware_watchpoint
9890 || bpt
->type
== bp_read_watchpoint
9891 || bpt
->type
== bp_access_watchpoint
)
9893 struct gdb_exception e
;
9895 TRY_CATCH (e
, RETURN_MASK_ALL
)
9897 update_watchpoint (bpt
, 1 /* reparse */);
9901 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9907 if (bpt
->enable_state
!= bp_permanent
)
9908 bpt
->enable_state
= bp_enabled
;
9909 bpt
->disposition
= disposition
;
9910 update_global_location_list (1);
9911 breakpoints_changed ();
9913 observer_notify_breakpoint_modified (bpt
->number
);
9918 enable_breakpoint (struct breakpoint
*bpt
)
9920 do_enable_breakpoint (bpt
, bpt
->disposition
);
9923 /* A callback for map_breakpoint_numbers that calls
9924 enable_breakpoint. */
9927 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
9929 enable_breakpoint (b
);
9932 /* The enable command enables the specified breakpoints (or all defined
9933 breakpoints) so they once again become (or continue to be) effective
9934 in stopping the inferior. */
9937 enable_command (char *args
, int from_tty
)
9939 struct breakpoint
*bpt
;
9941 ALL_BREAKPOINTS (bpt
)
9945 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9950 case bp_fast_tracepoint
:
9952 case bp_hardware_breakpoint
:
9954 case bp_hardware_watchpoint
:
9955 case bp_read_watchpoint
:
9956 case bp_access_watchpoint
:
9957 enable_breakpoint (bpt
);
9961 else if (strchr (args
, '.'))
9963 struct bp_location
*loc
= find_location_by_number (args
);
9966 update_global_location_list (1);
9969 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
9973 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
9975 do_enable_breakpoint (bpt
, disp_disable
);
9979 enable_once_command (char *args
, int from_tty
)
9981 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
9985 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
9987 do_enable_breakpoint (bpt
, disp_del
);
9991 enable_delete_command (char *args
, int from_tty
)
9993 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
9997 set_breakpoint_cmd (char *args
, int from_tty
)
10002 show_breakpoint_cmd (char *args
, int from_tty
)
10006 /* Invalidate last known value of any hardware watchpoint if
10007 the memory which that value represents has been written to by
10011 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
10012 const bfd_byte
*data
)
10014 struct breakpoint
*bp
;
10016 ALL_BREAKPOINTS (bp
)
10017 if (bp
->enable_state
== bp_enabled
10018 && bp
->type
== bp_hardware_watchpoint
10019 && bp
->val_valid
&& bp
->val
)
10021 struct bp_location
*loc
;
10023 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
10024 if (loc
->loc_type
== bp_loc_hardware_watchpoint
10025 && loc
->address
+ loc
->length
> addr
10026 && addr
+ len
> loc
->address
)
10028 value_free (bp
->val
);
10035 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
10037 struct symtabs_and_lines
10038 decode_line_spec_1 (char *string
, int funfirstline
)
10040 struct symtabs_and_lines sals
;
10042 error (_("Empty line specification."));
10043 if (default_breakpoint_valid
)
10044 sals
= decode_line_1 (&string
, funfirstline
,
10045 default_breakpoint_symtab
,
10046 default_breakpoint_line
,
10047 (char ***) NULL
, NULL
);
10049 sals
= decode_line_1 (&string
, funfirstline
,
10050 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
10052 error (_("Junk at end of line specification: %s"), string
);
10056 /* Create and insert a raw software breakpoint at PC. Return an
10057 identifier, which should be used to remove the breakpoint later.
10058 In general, places which call this should be using something on the
10059 breakpoint chain instead; this function should be eliminated
10063 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
10064 struct address_space
*aspace
, CORE_ADDR pc
)
10066 struct bp_target_info
*bp_tgt
;
10068 bp_tgt
= XZALLOC (struct bp_target_info
);
10070 bp_tgt
->placed_address_space
= aspace
;
10071 bp_tgt
->placed_address
= pc
;
10073 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
10075 /* Could not insert the breakpoint. */
10083 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
10086 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
10088 struct bp_target_info
*bp_tgt
= bp
;
10091 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
10097 /* One (or perhaps two) breakpoints used for software single stepping. */
10099 static void *single_step_breakpoints
[2];
10100 static struct gdbarch
*single_step_gdbarch
[2];
10102 /* Create and insert a breakpoint for software single step. */
10105 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10106 struct address_space
*aspace
, CORE_ADDR next_pc
)
10110 if (single_step_breakpoints
[0] == NULL
)
10112 bpt_p
= &single_step_breakpoints
[0];
10113 single_step_gdbarch
[0] = gdbarch
;
10117 gdb_assert (single_step_breakpoints
[1] == NULL
);
10118 bpt_p
= &single_step_breakpoints
[1];
10119 single_step_gdbarch
[1] = gdbarch
;
10122 /* NOTE drow/2006-04-11: A future improvement to this function would be
10123 to only create the breakpoints once, and actually put them on the
10124 breakpoint chain. That would let us use set_raw_breakpoint. We could
10125 adjust the addresses each time they were needed. Doing this requires
10126 corresponding changes elsewhere where single step breakpoints are
10127 handled, however. So, for now, we use this. */
10129 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10130 if (*bpt_p
== NULL
)
10131 error (_("Could not insert single-step breakpoint at %s"),
10132 paddress (gdbarch
, next_pc
));
10135 /* Remove and delete any breakpoints used for software single step. */
10138 remove_single_step_breakpoints (void)
10140 gdb_assert (single_step_breakpoints
[0] != NULL
);
10142 /* See insert_single_step_breakpoint for more about this deprecated
10144 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10145 single_step_breakpoints
[0]);
10146 single_step_gdbarch
[0] = NULL
;
10147 single_step_breakpoints
[0] = NULL
;
10149 if (single_step_breakpoints
[1] != NULL
)
10151 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10152 single_step_breakpoints
[1]);
10153 single_step_gdbarch
[1] = NULL
;
10154 single_step_breakpoints
[1] = NULL
;
10158 /* Check whether a software single-step breakpoint is inserted at PC. */
10161 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10165 for (i
= 0; i
< 2; i
++)
10167 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10169 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10170 bp_tgt
->placed_address
,
10178 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10179 non-zero otherwise. */
10181 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10183 if (syscall_catchpoint_p (bp
)
10184 && bp
->enable_state
!= bp_disabled
10185 && bp
->enable_state
!= bp_call_disabled
)
10192 catch_syscall_enabled (void)
10194 struct inferior
*inf
= current_inferior ();
10196 return inf
->total_syscalls_count
!= 0;
10200 catching_syscall_number (int syscall_number
)
10202 struct breakpoint
*bp
;
10204 ALL_BREAKPOINTS (bp
)
10205 if (is_syscall_catchpoint_enabled (bp
))
10207 if (bp
->syscalls_to_be_caught
)
10211 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10213 if (syscall_number
== iter
)
10223 /* Complete syscall names. Used by "catch syscall". */
10225 catch_syscall_completer (struct cmd_list_element
*cmd
,
10226 char *text
, char *word
)
10228 const char **list
= get_syscall_names ();
10229 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10232 /* Tracepoint-specific operations. */
10234 /* Set tracepoint count to NUM. */
10236 set_tracepoint_count (int num
)
10238 tracepoint_count
= num
;
10239 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10243 trace_command (char *arg
, int from_tty
)
10245 if (create_breakpoint (get_current_arch (),
10247 NULL
, 0, 1 /* parse arg */,
10248 0 /* tempflag */, 0 /* hardwareflag */,
10250 0 /* Ignore count */,
10251 pending_break_support
,
10255 set_tracepoint_count (breakpoint_count
);
10259 ftrace_command (char *arg
, int from_tty
)
10261 if (create_breakpoint (get_current_arch (),
10263 NULL
, 0, 1 /* parse arg */,
10264 0 /* tempflag */, 1 /* hardwareflag */,
10266 0 /* Ignore count */,
10267 pending_break_support
,
10271 set_tracepoint_count (breakpoint_count
);
10274 /* Given information about a tracepoint as recorded on a target (which
10275 can be either a live system or a trace file), attempt to create an
10276 equivalent GDB tracepoint. This is not a reliable process, since
10277 the target does not necessarily have all the information used when
10278 the tracepoint was originally defined. */
10280 struct breakpoint
*
10281 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10284 struct breakpoint
*tp
;
10286 /* In the absence of a source location, fall back to raw address. */
10287 sprintf (buf
, "*%s", paddress (get_current_arch(), utp
->addr
));
10289 if (!create_breakpoint (get_current_arch (),
10291 NULL
, 0, 1 /* parse arg */,
10293 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10295 0 /* Ignore count */,
10296 pending_break_support
,
10299 utp
->enabled
/* enabled */))
10302 set_tracepoint_count (breakpoint_count
);
10304 tp
= get_tracepoint (tracepoint_count
);
10305 gdb_assert (tp
!= NULL
);
10309 sprintf (buf
, "%d %d", utp
->pass
, tp
->number
);
10311 trace_pass_command (buf
, 0);
10316 printf_filtered ("Want to restore a condition\n");
10319 if (utp
->numactions
> 0)
10321 printf_filtered ("Want to restore action list\n");
10324 if (utp
->num_step_actions
> 0)
10326 printf_filtered ("Want to restore action list\n");
10332 /* Print information on tracepoint number TPNUM_EXP, or all if
10336 tracepoints_info (char *tpnum_exp
, int from_tty
)
10338 struct breakpoint
*b
;
10339 int tps_to_list
= 0;
10341 /* In the no-arguments case, say "No tracepoints" if none found. */
10342 if (tpnum_exp
== 0)
10344 ALL_TRACEPOINTS (b
)
10346 if (b
->number
>= 0)
10354 ui_out_message (uiout
, 0, "No tracepoints.\n");
10359 /* Otherwise be the same as "info break". */
10360 breakpoints_info (tpnum_exp
, from_tty
);
10363 /* The 'enable trace' command enables tracepoints.
10364 Not supported by all targets. */
10366 enable_trace_command (char *args
, int from_tty
)
10368 enable_command (args
, from_tty
);
10371 /* The 'disable trace' command disables tracepoints.
10372 Not supported by all targets. */
10374 disable_trace_command (char *args
, int from_tty
)
10376 disable_command (args
, from_tty
);
10379 /* Remove a tracepoint (or all if no argument) */
10381 delete_trace_command (char *arg
, int from_tty
)
10383 struct breakpoint
*b
, *temp
;
10389 int breaks_to_delete
= 0;
10391 /* Delete all breakpoints if no argument.
10392 Do not delete internal or call-dummy breakpoints, these
10393 have to be deleted with an explicit breakpoint number argument. */
10394 ALL_TRACEPOINTS (b
)
10396 if (b
->number
>= 0)
10398 breaks_to_delete
= 1;
10403 /* Ask user only if there are some breakpoints to delete. */
10405 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10407 ALL_BREAKPOINTS_SAFE (b
, temp
)
10409 if (tracepoint_type (b
)
10411 delete_breakpoint (b
);
10416 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10419 /* Set passcount for tracepoint.
10421 First command argument is passcount, second is tracepoint number.
10422 If tracepoint number omitted, apply to most recently defined.
10423 Also accepts special argument "all". */
10426 trace_pass_command (char *args
, int from_tty
)
10428 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10429 unsigned int count
;
10432 if (args
== 0 || *args
== 0)
10433 error (_("passcount command requires an argument (count + optional TP num)"));
10435 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10437 while (*args
&& isspace ((int) *args
))
10440 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10442 args
+= 3; /* Skip special argument "all". */
10445 error (_("Junk at end of arguments."));
10448 t1
= get_tracepoint_by_number (&args
, 1, 1);
10454 ALL_TRACEPOINTS (t2
)
10455 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10457 t2
->pass_count
= count
;
10458 observer_notify_tracepoint_modified (t2
->number
);
10460 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10461 t2
->number
, count
);
10463 if (! all
&& *args
)
10464 t1
= get_tracepoint_by_number (&args
, 1, 0);
10470 struct breakpoint
*
10471 get_tracepoint (int num
)
10473 struct breakpoint
*t
;
10475 ALL_TRACEPOINTS (t
)
10476 if (t
->number
== num
)
10482 /* Find the tracepoint with the given target-side number (which may be
10483 different from the tracepoint number after disconnecting and
10486 struct breakpoint
*
10487 get_tracepoint_by_number_on_target (int num
)
10489 struct breakpoint
*t
;
10491 ALL_TRACEPOINTS (t
)
10492 if (t
->number_on_target
== num
)
10498 /* Utility: parse a tracepoint number and look it up in the list.
10499 If MULTI_P is true, there might be a range of tracepoints in ARG.
10500 if OPTIONAL_P is true, then if the argument is missing, the most
10501 recent tracepoint (tracepoint_count) is returned. */
10502 struct breakpoint
*
10503 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10505 extern int tracepoint_count
;
10506 struct breakpoint
*t
;
10508 char *instring
= arg
== NULL
? NULL
: *arg
;
10510 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10513 tpnum
= tracepoint_count
;
10515 error_no_arg (_("tracepoint number"));
10518 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10522 if (instring
&& *instring
)
10523 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10526 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10530 ALL_TRACEPOINTS (t
)
10531 if (t
->number
== tpnum
)
10536 /* FIXME: if we are in the middle of a range we don't want to give
10537 a message. The current interface to get_number_or_range doesn't
10538 allow us to discover this. */
10539 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10543 /* save-tracepoints command */
10545 tracepoint_save_command (char *args
, int from_tty
)
10547 struct breakpoint
*tp
;
10549 struct command_line
*line
;
10552 struct cleanup
*cleanup
;
10553 struct ui_file
*fp
;
10555 if (args
== 0 || *args
== 0)
10556 error (_("Argument required (file name in which to save tracepoints)"));
10558 /* See if we have anything to save. */
10559 ALL_TRACEPOINTS (tp
)
10566 warning (_("save-tracepoints: no tracepoints to save."));
10570 pathname
= tilde_expand (args
);
10571 cleanup
= make_cleanup (xfree
, pathname
);
10572 fp
= gdb_fopen (pathname
, "w");
10574 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10575 args
, safe_strerror (errno
));
10576 make_cleanup_ui_file_delete (fp
);
10578 ALL_TRACEPOINTS (tp
)
10580 if (tp
->addr_string
)
10581 fprintf_unfiltered (fp
, "trace %s\n", tp
->addr_string
);
10584 sprintf_vma (tmp
, tp
->loc
->address
);
10585 fprintf_unfiltered (fp
, "trace *0x%s\n", tmp
);
10588 if (tp
->pass_count
)
10589 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10593 volatile struct gdb_exception ex
;
10595 fprintf_unfiltered (fp
, " actions\n");
10597 ui_out_redirect (uiout
, fp
);
10598 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10600 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10602 ui_out_redirect (uiout
, NULL
);
10605 throw_exception (ex
);
10607 fprintf_unfiltered (fp
, " end\n");
10610 do_cleanups (cleanup
);
10612 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10616 /* Create a vector of all tracepoints. */
10618 VEC(breakpoint_p
) *
10621 VEC(breakpoint_p
) *tp_vec
= 0;
10622 struct breakpoint
*tp
;
10624 ALL_TRACEPOINTS (tp
)
10626 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10633 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10634 It is defined as a macro to prevent duplication.
10635 COMMAND should be a string constant containing the name of the command. */
10636 #define BREAK_ARGS_HELP(command) \
10637 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10638 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10639 If a line number is specified, break at start of code for that line.\n\
10640 If a function is specified, break at start of code for that function.\n\
10641 If an address is specified, break at that exact address.\n\
10642 With no LOCATION, uses current execution address of selected stack frame.\n\
10643 This is useful for breaking on return to a stack frame.\n\
10645 THREADNUM is the number from \"info threads\".\n\
10646 CONDITION is a boolean expression.\n\
10648 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10650 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10652 /* List of subcommands for "catch". */
10653 static struct cmd_list_element
*catch_cmdlist
;
10655 /* List of subcommands for "tcatch". */
10656 static struct cmd_list_element
*tcatch_cmdlist
;
10658 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10659 lists, and pass some additional user data to the command function. */
10661 add_catch_command (char *name
, char *docstring
,
10662 void (*sfunc
) (char *args
, int from_tty
,
10663 struct cmd_list_element
*command
),
10664 char **(*completer
) (struct cmd_list_element
*cmd
,
10665 char *text
, char *word
),
10666 void *user_data_catch
,
10667 void *user_data_tcatch
)
10669 struct cmd_list_element
*command
;
10671 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10673 set_cmd_sfunc (command
, sfunc
);
10674 set_cmd_context (command
, user_data_catch
);
10675 set_cmd_completer (command
, completer
);
10677 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10679 set_cmd_sfunc (command
, sfunc
);
10680 set_cmd_context (command
, user_data_tcatch
);
10681 set_cmd_completer (command
, completer
);
10685 clear_syscall_counts (struct inferior
*inf
)
10687 inf
->total_syscalls_count
= 0;
10688 inf
->any_syscall_count
= 0;
10689 VEC_free (int, inf
->syscalls_counts
);
10693 _initialize_breakpoint (void)
10695 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10696 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10697 struct cmd_list_element
*c
;
10699 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10700 observer_attach_inferior_exit (clear_syscall_counts
);
10701 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10703 breakpoint_chain
= 0;
10704 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10705 before a breakpoint is set. */
10706 breakpoint_count
= 0;
10708 tracepoint_count
= 0;
10710 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10711 Set ignore-count of breakpoint number N to COUNT.\n\
10712 Usage is `ignore N COUNT'."));
10714 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10716 add_com ("commands", class_breakpoint
, commands_command
, _("\
10717 Set commands to be executed when a breakpoint is hit.\n\
10718 Give breakpoint number as argument after \"commands\".\n\
10719 With no argument, the targeted breakpoint is the last one set.\n\
10720 The commands themselves follow starting on the next line.\n\
10721 Type a line containing \"end\" to indicate the end of them.\n\
10722 Give \"silent\" as the first line to make the breakpoint silent;\n\
10723 then no output is printed when it is hit, except what the commands print."));
10725 add_com ("condition", class_breakpoint
, condition_command
, _("\
10726 Specify breakpoint number N to break only if COND is true.\n\
10727 Usage is `condition N COND', where N is an integer and COND is an\n\
10728 expression to be evaluated whenever breakpoint N is reached."));
10730 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10731 Set a temporary breakpoint.\n\
10732 Like \"break\" except the breakpoint is only temporary,\n\
10733 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10734 by using \"enable delete\" on the breakpoint number.\n\
10736 BREAK_ARGS_HELP ("tbreak")));
10737 set_cmd_completer (c
, location_completer
);
10739 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10740 Set a hardware assisted breakpoint.\n\
10741 Like \"break\" except the breakpoint requires hardware support,\n\
10742 some target hardware may not have this support.\n\
10744 BREAK_ARGS_HELP ("hbreak")));
10745 set_cmd_completer (c
, location_completer
);
10747 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10748 Set a temporary hardware assisted breakpoint.\n\
10749 Like \"hbreak\" except the breakpoint is only temporary,\n\
10750 so it will be deleted when hit.\n\
10752 BREAK_ARGS_HELP ("thbreak")));
10753 set_cmd_completer (c
, location_completer
);
10755 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10756 Enable some breakpoints.\n\
10757 Give breakpoint numbers (separated by spaces) as arguments.\n\
10758 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10759 This is used to cancel the effect of the \"disable\" command.\n\
10760 With a subcommand you can enable temporarily."),
10761 &enablelist
, "enable ", 1, &cmdlist
);
10763 add_com ("ab", class_breakpoint
, enable_command
, _("\
10764 Enable some breakpoints.\n\
10765 Give breakpoint numbers (separated by spaces) as arguments.\n\
10766 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10767 This is used to cancel the effect of the \"disable\" command.\n\
10768 With a subcommand you can enable temporarily."));
10770 add_com_alias ("en", "enable", class_breakpoint
, 1);
10772 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10773 Enable some breakpoints.\n\
10774 Give breakpoint numbers (separated by spaces) as arguments.\n\
10775 This is used to cancel the effect of the \"disable\" command.\n\
10776 May be abbreviated to simply \"enable\".\n"),
10777 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10779 add_cmd ("once", no_class
, enable_once_command
, _("\
10780 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10781 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10784 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10785 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10786 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10789 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10790 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10791 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10794 add_cmd ("once", no_class
, enable_once_command
, _("\
10795 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10796 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10799 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10800 Disable some breakpoints.\n\
10801 Arguments are breakpoint numbers with spaces in between.\n\
10802 To disable all breakpoints, give no argument.\n\
10803 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10804 &disablelist
, "disable ", 1, &cmdlist
);
10805 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10806 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10808 add_com ("sb", class_breakpoint
, disable_command
, _("\
10809 Disable some breakpoints.\n\
10810 Arguments are breakpoint numbers with spaces in between.\n\
10811 To disable all breakpoints, give no argument.\n\
10812 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10814 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10815 Disable some breakpoints.\n\
10816 Arguments are breakpoint numbers with spaces in between.\n\
10817 To disable all breakpoints, give no argument.\n\
10818 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10819 This command may be abbreviated \"disable\"."),
10822 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10823 Delete some breakpoints or auto-display expressions.\n\
10824 Arguments are breakpoint numbers with spaces in between.\n\
10825 To delete all breakpoints, give no argument.\n\
10827 Also a prefix command for deletion of other GDB objects.\n\
10828 The \"unset\" command is also an alias for \"delete\"."),
10829 &deletelist
, "delete ", 1, &cmdlist
);
10830 add_com_alias ("d", "delete", class_breakpoint
, 1);
10831 add_com_alias ("del", "delete", class_breakpoint
, 1);
10833 add_com ("db", class_breakpoint
, delete_command
, _("\
10834 Delete some breakpoints.\n\
10835 Arguments are breakpoint numbers with spaces in between.\n\
10836 To delete all breakpoints, give no argument.\n"));
10838 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10839 Delete some breakpoints or auto-display expressions.\n\
10840 Arguments are breakpoint numbers with spaces in between.\n\
10841 To delete all breakpoints, give no argument.\n\
10842 This command may be abbreviated \"delete\"."),
10845 add_com ("clear", class_breakpoint
, clear_command
, _("\
10846 Clear breakpoint at specified line or function.\n\
10847 Argument may be line number, function name, or \"*\" and an address.\n\
10848 If line number is specified, all breakpoints in that line are cleared.\n\
10849 If function is specified, breakpoints at beginning of function are cleared.\n\
10850 If an address is specified, breakpoints at that address are cleared.\n\
10852 With no argument, clears all breakpoints in the line that the selected frame\n\
10853 is executing in.\n\
10855 See also the \"delete\" command which clears breakpoints by number."));
10857 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10858 Set breakpoint at specified line or function.\n"
10859 BREAK_ARGS_HELP ("break")));
10860 set_cmd_completer (c
, location_completer
);
10862 add_com_alias ("b", "break", class_run
, 1);
10863 add_com_alias ("br", "break", class_run
, 1);
10864 add_com_alias ("bre", "break", class_run
, 1);
10865 add_com_alias ("brea", "break", class_run
, 1);
10868 add_com_alias ("ba", "break", class_breakpoint
, 1);
10872 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10873 Break in function/address or break at a line in the current file."),
10874 &stoplist
, "stop ", 1, &cmdlist
);
10875 add_cmd ("in", class_breakpoint
, stopin_command
,
10876 _("Break in function or address."), &stoplist
);
10877 add_cmd ("at", class_breakpoint
, stopat_command
,
10878 _("Break at a line in the current file."), &stoplist
);
10879 add_com ("status", class_info
, breakpoints_info
, _("\
10880 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10881 The \"Type\" column indicates one of:\n\
10882 \tbreakpoint - normal breakpoint\n\
10883 \twatchpoint - watchpoint\n\
10884 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10885 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10886 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10887 address and file/line number respectively.\n\
10889 Convenience variable \"$_\" and default examine address for \"x\"\n\
10890 are set to the address of the last breakpoint listed unless the command\n\
10891 is prefixed with \"server \".\n\n\
10892 Convenience variable \"$bpnum\" contains the number of the last\n\
10893 breakpoint set."));
10896 add_info ("breakpoints", breakpoints_info
, _("\
10897 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10898 The \"Type\" column indicates one of:\n\
10899 \tbreakpoint - normal breakpoint\n\
10900 \twatchpoint - watchpoint\n\
10901 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10902 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10903 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10904 address and file/line number respectively.\n\
10906 Convenience variable \"$_\" and default examine address for \"x\"\n\
10907 are set to the address of the last breakpoint listed unless the command\n\
10908 is prefixed with \"server \".\n\n\
10909 Convenience variable \"$bpnum\" contains the number of the last\n\
10910 breakpoint set."));
10912 add_info_alias ("b", "breakpoints", 1);
10915 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
10916 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10917 The \"Type\" column indicates one of:\n\
10918 \tbreakpoint - normal breakpoint\n\
10919 \twatchpoint - watchpoint\n\
10920 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10921 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10922 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10923 address and file/line number respectively.\n\
10925 Convenience variable \"$_\" and default examine address for \"x\"\n\
10926 are set to the address of the last breakpoint listed unless the command\n\
10927 is prefixed with \"server \".\n\n\
10928 Convenience variable \"$bpnum\" contains the number of the last\n\
10929 breakpoint set."));
10931 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
10932 Status of all breakpoints, or breakpoint number NUMBER.\n\
10933 The \"Type\" column indicates one of:\n\
10934 \tbreakpoint - normal breakpoint\n\
10935 \twatchpoint - watchpoint\n\
10936 \tlongjmp - internal breakpoint used to step through longjmp()\n\
10937 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
10938 \tuntil - internal breakpoint used by the \"until\" command\n\
10939 \tfinish - internal breakpoint used by the \"finish\" command\n\
10940 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10941 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10942 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10943 address and file/line number respectively.\n\
10945 Convenience variable \"$_\" and default examine address for \"x\"\n\
10946 are set to the address of the last breakpoint listed unless the command\n\
10947 is prefixed with \"server \".\n\n\
10948 Convenience variable \"$bpnum\" contains the number of the last\n\
10950 &maintenanceinfolist
);
10952 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
10953 Set catchpoints to catch events."),
10954 &catch_cmdlist
, "catch ",
10955 0/*allow-unknown*/, &cmdlist
);
10957 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
10958 Set temporary catchpoints to catch events."),
10959 &tcatch_cmdlist
, "tcatch ",
10960 0/*allow-unknown*/, &cmdlist
);
10962 /* Add catch and tcatch sub-commands. */
10963 add_catch_command ("catch", _("\
10964 Catch an exception, when caught.\n\
10965 With an argument, catch only exceptions with the given name."),
10966 catch_catch_command
,
10970 add_catch_command ("throw", _("\
10971 Catch an exception, when thrown.\n\
10972 With an argument, catch only exceptions with the given name."),
10973 catch_throw_command
,
10977 add_catch_command ("fork", _("Catch calls to fork."),
10978 catch_fork_command_1
,
10980 (void *) (uintptr_t) catch_fork_permanent
,
10981 (void *) (uintptr_t) catch_fork_temporary
);
10982 add_catch_command ("vfork", _("Catch calls to vfork."),
10983 catch_fork_command_1
,
10985 (void *) (uintptr_t) catch_vfork_permanent
,
10986 (void *) (uintptr_t) catch_vfork_temporary
);
10987 add_catch_command ("exec", _("Catch calls to exec."),
10988 catch_exec_command_1
,
10992 add_catch_command ("syscall", _("\
10993 Catch system calls by their names and/or numbers.\n\
10994 Arguments say which system calls to catch. If no arguments\n\
10995 are given, every system call will be caught.\n\
10996 Arguments, if given, should be one or more system call names\n\
10997 (if your system supports that), or system call numbers."),
10998 catch_syscall_command_1
,
10999 catch_syscall_completer
,
11002 add_catch_command ("exception", _("\
11003 Catch Ada exceptions, when raised.\n\
11004 With an argument, catch only exceptions with the given name."),
11005 catch_ada_exception_command
,
11009 add_catch_command ("assert", _("\
11010 Catch failed Ada assertions, when raised.\n\
11011 With an argument, catch only exceptions with the given name."),
11012 catch_assert_command
,
11017 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
11018 Set a watchpoint for an expression.\n\
11019 A watchpoint stops execution of your program whenever the value of\n\
11020 an expression changes."));
11021 set_cmd_completer (c
, expression_completer
);
11023 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
11024 Set a read watchpoint for an expression.\n\
11025 A watchpoint stops execution of your program whenever the value of\n\
11026 an expression is read."));
11027 set_cmd_completer (c
, expression_completer
);
11029 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
11030 Set a watchpoint for an expression.\n\
11031 A watchpoint stops execution of your program whenever the value of\n\
11032 an expression is either read or written."));
11033 set_cmd_completer (c
, expression_completer
);
11035 add_info ("watchpoints", breakpoints_info
,
11036 _("Synonym for ``info breakpoints''."));
11039 /* XXX: cagney/2005-02-23: This should be a boolean, and should
11040 respond to changes - contrary to the description. */
11041 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
11042 &can_use_hw_watchpoints
, _("\
11043 Set debugger's willingness to use watchpoint hardware."), _("\
11044 Show debugger's willingness to use watchpoint hardware."), _("\
11045 If zero, gdb will not use hardware for new watchpoints, even if\n\
11046 such is available. (However, any hardware watchpoints that were\n\
11047 created before setting this to nonzero, will continue to use watchpoint\n\
11050 show_can_use_hw_watchpoints
,
11051 &setlist
, &showlist
);
11053 can_use_hw_watchpoints
= 1;
11055 /* Tracepoint manipulation commands. */
11057 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
11058 Set a tracepoint at specified line or function.\n\
11060 BREAK_ARGS_HELP ("trace") "\n\
11061 Do \"help tracepoints\" for info on other tracepoint commands."));
11062 set_cmd_completer (c
, location_completer
);
11064 add_com_alias ("tp", "trace", class_alias
, 0);
11065 add_com_alias ("tr", "trace", class_alias
, 1);
11066 add_com_alias ("tra", "trace", class_alias
, 1);
11067 add_com_alias ("trac", "trace", class_alias
, 1);
11069 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
11070 Set a fast tracepoint at specified line or function.\n\
11072 BREAK_ARGS_HELP ("ftrace") "\n\
11073 Do \"help tracepoints\" for info on other tracepoint commands."));
11074 set_cmd_completer (c
, location_completer
);
11076 add_info ("tracepoints", tracepoints_info
, _("\
11077 Status of tracepoints, or tracepoint number NUMBER.\n\
11078 Convenience variable \"$tpnum\" contains the number of the\n\
11079 last tracepoint set."));
11081 add_info_alias ("tp", "tracepoints", 1);
11083 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
11084 Delete specified tracepoints.\n\
11085 Arguments are tracepoint numbers, separated by spaces.\n\
11086 No argument means delete all tracepoints."),
11089 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
11090 Disable specified tracepoints.\n\
11091 Arguments are tracepoint numbers, separated by spaces.\n\
11092 No argument means disable all tracepoints."),
11094 deprecate_cmd (c
, "disable");
11096 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
11097 Enable specified tracepoints.\n\
11098 Arguments are tracepoint numbers, separated by spaces.\n\
11099 No argument means enable all tracepoints."),
11101 deprecate_cmd (c
, "enable");
11103 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11104 Set the passcount for a tracepoint.\n\
11105 The trace will end when the tracepoint has been passed 'count' times.\n\
11106 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11107 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11109 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11110 Save current tracepoint definitions as a script.\n\
11111 Use the 'source' command in another debug session to restore them."));
11112 set_cmd_completer (c
, filename_completer
);
11114 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11115 Breakpoint specific settings\n\
11116 Configure various breakpoint-specific variables such as\n\
11117 pending breakpoint behavior"),
11118 &breakpoint_set_cmdlist
, "set breakpoint ",
11119 0/*allow-unknown*/, &setlist
);
11120 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11121 Breakpoint specific settings\n\
11122 Configure various breakpoint-specific variables such as\n\
11123 pending breakpoint behavior"),
11124 &breakpoint_show_cmdlist
, "show breakpoint ",
11125 0/*allow-unknown*/, &showlist
);
11127 add_setshow_auto_boolean_cmd ("pending", no_class
,
11128 &pending_break_support
, _("\
11129 Set debugger's behavior regarding pending breakpoints."), _("\
11130 Show debugger's behavior regarding pending breakpoints."), _("\
11131 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11132 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11133 an error. If auto, an unrecognized breakpoint location results in a\n\
11134 user-query to see if a pending breakpoint should be created."),
11136 show_pending_break_support
,
11137 &breakpoint_set_cmdlist
,
11138 &breakpoint_show_cmdlist
);
11140 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11142 add_setshow_boolean_cmd ("auto-hw", no_class
,
11143 &automatic_hardware_breakpoints
, _("\
11144 Set automatic usage of hardware breakpoints."), _("\
11145 Show automatic usage of hardware breakpoints."), _("\
11146 If set, the debugger will automatically use hardware breakpoints for\n\
11147 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11148 a warning will be emitted for such breakpoints."),
11150 show_automatic_hardware_breakpoints
,
11151 &breakpoint_set_cmdlist
,
11152 &breakpoint_show_cmdlist
);
11154 add_setshow_enum_cmd ("always-inserted", class_support
,
11155 always_inserted_enums
, &always_inserted_mode
, _("\
11156 Set mode for inserting breakpoints."), _("\
11157 Show mode for inserting breakpoints."), _("\
11158 When this mode is off, breakpoints are inserted in inferior when it is\n\
11159 resumed, and removed when execution stops. When this mode is on,\n\
11160 breakpoints are inserted immediately and removed only when the user\n\
11161 deletes the breakpoint. When this mode is auto (which is the default),\n\
11162 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11163 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11164 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11165 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11167 &show_always_inserted_mode
,
11168 &breakpoint_set_cmdlist
,
11169 &breakpoint_show_cmdlist
);
11171 automatic_hardware_breakpoints
= 1;
11173 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);