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, 2011 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"
42 #include "filenames.h"
48 #include "completer.h"
51 #include "cli/cli-script.h"
52 #include "gdb_assert.h"
57 #include "exceptions.h"
64 #include "xml-syscall.h"
65 #include "parser-defs.h"
66 #include "cli/cli-utils.h"
68 /* readline include files */
69 #include "readline/readline.h"
70 #include "readline/history.h"
72 /* readline defines this. */
75 #include "mi/mi-common.h"
76 #include "python/python.h"
78 /* Arguments to pass as context to some catch command handlers. */
79 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
80 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
82 /* Prototypes for local functions. */
84 static void enable_delete_command (char *, int);
86 static void enable_once_command (char *, int);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
96 static void ignore_command (char *, int);
98 static int breakpoint_re_set_one (void *);
100 static void clear_command (char *, int);
102 static void catch_command (char *, int);
104 static int can_use_hardware_watchpoint (struct value
*);
106 static void break_command_1 (char *, int, int);
108 static void mention (struct breakpoint
*);
110 /* This function is used in gdbtk sources and thus can not be made
112 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
113 struct symtab_and_line
,
116 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
118 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
122 static void describe_other_breakpoints (struct gdbarch
*,
123 struct program_space
*, CORE_ADDR
,
124 struct obj_section
*, int);
126 static int breakpoint_address_match (struct address_space
*aspace1
,
128 struct address_space
*aspace2
,
131 static int watchpoint_locations_match (struct bp_location
*loc1
,
132 struct bp_location
*loc2
);
134 static int breakpoint_location_address_match (struct bp_location
*bl
,
135 struct address_space
*aspace
,
138 static void breakpoints_info (char *, int);
140 static void watchpoints_info (char *, int);
142 static int breakpoint_1 (char *, int,
143 int (*) (const struct breakpoint
*));
145 static int breakpoint_cond_eval (void *);
147 static void cleanup_executing_breakpoints (void *);
149 static void commands_command (char *, int);
151 static void condition_command (char *, int);
160 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
161 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
163 static enum print_stop_action
print_it_typical (bpstat
);
165 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
167 static int watchpoint_check (void *);
169 static void maintenance_info_breakpoints (char *, int);
171 static int hw_breakpoint_used_count (void);
173 static int hw_watchpoint_used_count (enum bptype
, int *);
175 static void hbreak_command (char *, int);
177 static void thbreak_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 detach_single_step_breakpoints (void);
196 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
199 static void free_bp_location (struct bp_location
*loc
);
200 static void incref_bp_location (struct bp_location
*loc
);
201 static void decref_bp_location (struct bp_location
**loc
);
203 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
205 static void update_global_location_list (int);
207 static void update_global_location_list_nothrow (int);
209 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
211 static int is_watchpoint (const struct breakpoint
*bpt
);
213 static void insert_breakpoint_locations (void);
215 static int syscall_catchpoint_p (struct breakpoint
*b
);
217 static void tracepoints_info (char *, int);
219 static void delete_trace_command (char *, int);
221 static void enable_trace_command (char *, int);
223 static void disable_trace_command (char *, int);
225 static void trace_pass_command (char *, int);
227 static int is_masked_watchpoint (const struct breakpoint
*b
);
229 /* Assuming we're creating a static tracepoint, does S look like a
230 static tracepoint marker spec ("-m MARKER_ID")? */
231 #define is_marker_spec(s) \
232 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
234 /* A reference-counted struct command_line. This lets multiple
235 breakpoints share a single command list. */
236 struct counted_command_line
238 /* The reference count. */
241 /* The command list. */
242 struct command_line
*commands
;
245 struct command_line
*
246 breakpoint_commands (struct breakpoint
*b
)
248 return b
->commands
? b
->commands
->commands
: NULL
;
251 /* Flag indicating that a command has proceeded the inferior past the
252 current breakpoint. */
254 static int breakpoint_proceeded
;
257 bpdisp_text (enum bpdisp disp
)
259 /* NOTE: the following values are a part of MI protocol and
260 represent values of 'disp' field returned when inferior stops at
262 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
264 return bpdisps
[(int) disp
];
267 /* Prototypes for exported functions. */
268 /* If FALSE, gdb will not use hardware support for watchpoints, even
269 if such is available. */
270 static int can_use_hw_watchpoints
;
273 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
274 struct cmd_list_element
*c
,
277 fprintf_filtered (file
,
278 _("Debugger's willingness to use "
279 "watchpoint hardware is %s.\n"),
283 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
284 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
285 for unrecognized breakpoint locations.
286 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
287 static enum auto_boolean pending_break_support
;
289 show_pending_break_support (struct ui_file
*file
, int from_tty
,
290 struct cmd_list_element
*c
,
293 fprintf_filtered (file
,
294 _("Debugger's behavior regarding "
295 "pending breakpoints is %s.\n"),
299 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
300 set with "break" but falling in read-only memory.
301 If 0, gdb will warn about such breakpoints, but won't automatically
302 use hardware breakpoints. */
303 static int automatic_hardware_breakpoints
;
305 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
306 struct cmd_list_element
*c
,
309 fprintf_filtered (file
,
310 _("Automatic usage of hardware breakpoints is %s.\n"),
314 /* If on, gdb will keep breakpoints inserted even as inferior is
315 stopped, and immediately insert any new breakpoints. If off, gdb
316 will insert breakpoints into inferior only when resuming it, and
317 will remove breakpoints upon stop. If auto, GDB will behave as ON
318 if in non-stop mode, and as OFF if all-stop mode.*/
320 static const char always_inserted_auto
[] = "auto";
321 static const char always_inserted_on
[] = "on";
322 static const char always_inserted_off
[] = "off";
323 static const char *always_inserted_enums
[] = {
324 always_inserted_auto
,
329 static const char *always_inserted_mode
= always_inserted_auto
;
331 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
332 struct cmd_list_element
*c
, const char *value
)
334 if (always_inserted_mode
== always_inserted_auto
)
335 fprintf_filtered (file
,
336 _("Always inserted breakpoint "
337 "mode is %s (currently %s).\n"),
339 breakpoints_always_inserted_mode () ? "on" : "off");
341 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
346 breakpoints_always_inserted_mode (void)
348 return (always_inserted_mode
== always_inserted_on
349 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
352 void _initialize_breakpoint (void);
354 /* Are we executing breakpoint commands? */
355 static int executing_breakpoint_commands
;
357 /* Are overlay event breakpoints enabled? */
358 static int overlay_events_enabled
;
360 /* See description in breakpoint.h. */
361 int target_exact_watchpoints
= 0;
363 /* Walk the following statement or block through all breakpoints.
364 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the
365 current breakpoint. */
367 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
369 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
370 for (B = breakpoint_chain; \
371 B ? (TMP=B->next, 1): 0; \
374 /* Similar iterator for the low-level breakpoints. SAFE variant is
375 not provided so update_global_location_list must not be called
376 while executing the block of ALL_BP_LOCATIONS. */
378 #define ALL_BP_LOCATIONS(B,BP_TMP) \
379 for (BP_TMP = bp_location; \
380 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
383 /* Iterator for tracepoints only. */
385 #define ALL_TRACEPOINTS(B) \
386 for (B = breakpoint_chain; B; B = B->next) \
387 if (is_tracepoint (B))
389 /* Chains of all breakpoints defined. */
391 struct breakpoint
*breakpoint_chain
;
393 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
395 static struct bp_location
**bp_location
;
397 /* Number of elements of BP_LOCATION. */
399 static unsigned bp_location_count
;
401 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
402 ADDRESS for the current elements of BP_LOCATION which get a valid
403 result from bp_location_has_shadow. You can use it for roughly
404 limiting the subrange of BP_LOCATION to scan for shadow bytes for
405 an address you need to read. */
407 static CORE_ADDR bp_location_placed_address_before_address_max
;
409 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
410 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
411 BP_LOCATION which get a valid result from bp_location_has_shadow.
412 You can use it for roughly limiting the subrange of BP_LOCATION to
413 scan for shadow bytes for an address you need to read. */
415 static CORE_ADDR bp_location_shadow_len_after_address_max
;
417 /* The locations that no longer correspond to any breakpoint, unlinked
418 from bp_location array, but for which a hit may still be reported
420 VEC(bp_location_p
) *moribund_locations
= NULL
;
422 /* Number of last breakpoint made. */
424 static int breakpoint_count
;
426 /* The value of `breakpoint_count' before the last command that
427 created breakpoints. If the last (break-like) command created more
428 than one breakpoint, then the difference between BREAKPOINT_COUNT
429 and PREV_BREAKPOINT_COUNT is more than one. */
430 static int prev_breakpoint_count
;
432 /* Number of last tracepoint made. */
434 static int tracepoint_count
;
436 static struct cmd_list_element
*breakpoint_set_cmdlist
;
437 static struct cmd_list_element
*breakpoint_show_cmdlist
;
438 struct cmd_list_element
*save_cmdlist
;
440 /* Return whether a breakpoint is an active enabled breakpoint. */
442 breakpoint_enabled (struct breakpoint
*b
)
444 return (b
->enable_state
== bp_enabled
);
447 /* Set breakpoint count to NUM. */
450 set_breakpoint_count (int num
)
452 prev_breakpoint_count
= breakpoint_count
;
453 breakpoint_count
= num
;
454 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
457 /* Used by `start_rbreak_breakpoints' below, to record the current
458 breakpoint count before "rbreak" creates any breakpoint. */
459 static int rbreak_start_breakpoint_count
;
461 /* Called at the start an "rbreak" command to record the first
465 start_rbreak_breakpoints (void)
467 rbreak_start_breakpoint_count
= breakpoint_count
;
470 /* Called at the end of an "rbreak" command to record the last
474 end_rbreak_breakpoints (void)
476 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
479 /* Used in run_command to zero the hit count when a new run starts. */
482 clear_breakpoint_hit_counts (void)
484 struct breakpoint
*b
;
490 /* Allocate a new counted_command_line with reference count of 1.
491 The new structure owns COMMANDS. */
493 static struct counted_command_line
*
494 alloc_counted_command_line (struct command_line
*commands
)
496 struct counted_command_line
*result
497 = xmalloc (sizeof (struct counted_command_line
));
500 result
->commands
= commands
;
504 /* Increment reference count. This does nothing if CMD is NULL. */
507 incref_counted_command_line (struct counted_command_line
*cmd
)
513 /* Decrement reference count. If the reference count reaches 0,
514 destroy the counted_command_line. Sets *CMDP to NULL. This does
515 nothing if *CMDP is NULL. */
518 decref_counted_command_line (struct counted_command_line
**cmdp
)
522 if (--(*cmdp
)->refc
== 0)
524 free_command_lines (&(*cmdp
)->commands
);
531 /* A cleanup function that calls decref_counted_command_line. */
534 do_cleanup_counted_command_line (void *arg
)
536 decref_counted_command_line (arg
);
539 /* Create a cleanup that calls decref_counted_command_line on the
542 static struct cleanup
*
543 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
545 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
548 /* Default address, symtab and line to put a breakpoint at
549 for "break" command with no arg.
550 If default_breakpoint_valid is zero, the other three are
551 not valid, and "break" with no arg is an error.
553 This set by print_stack_frame, which calls set_default_breakpoint. */
555 int default_breakpoint_valid
;
556 CORE_ADDR default_breakpoint_address
;
557 struct symtab
*default_breakpoint_symtab
;
558 int default_breakpoint_line
;
559 struct program_space
*default_breakpoint_pspace
;
562 /* Return the breakpoint with the specified number, or NULL
563 if the number does not refer to an existing breakpoint. */
566 get_breakpoint (int num
)
568 struct breakpoint
*b
;
571 if (b
->number
== num
)
580 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
583 struct bp_location
*loc
= b
->loc
;
585 for (; loc
; loc
= loc
->next
)
590 xfree (b
->cond_string
);
591 b
->cond_string
= NULL
;
598 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
604 /* I don't know if it matters whether this is the string the user
605 typed in or the decompiled expression. */
606 b
->cond_string
= xstrdup (arg
);
607 b
->condition_not_parsed
= 0;
609 if (is_watchpoint (b
))
611 innermost_block
= NULL
;
613 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
615 error (_("Junk at end of expression"));
616 b
->cond_exp_valid_block
= innermost_block
;
620 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
624 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
626 error (_("Junk at end of expression"));
630 breakpoints_changed ();
631 observer_notify_breakpoint_modified (b
);
634 /* condition N EXP -- set break condition of breakpoint N to EXP. */
637 condition_command (char *arg
, int from_tty
)
639 struct breakpoint
*b
;
644 error_no_arg (_("breakpoint number"));
647 bnum
= get_number (&p
);
649 error (_("Bad breakpoint argument: '%s'"), arg
);
652 if (b
->number
== bnum
)
654 /* Check if this breakpoint has a Python object assigned to
655 it, and if it has a definition of the "stop"
656 method. This method and conditions entered into GDB from
657 the CLI are mutually exclusive. */
659 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
660 error (_("Cannot set a condition where a Python 'stop' "
661 "method has been defined in the breakpoint."));
662 set_breakpoint_condition (b
, p
, from_tty
);
666 error (_("No breakpoint number %d."), bnum
);
669 /* Check that COMMAND do not contain commands that are suitable
670 only for tracepoints and not suitable for ordinary breakpoints.
671 Throw if any such commands is found. */
674 check_no_tracepoint_commands (struct command_line
*commands
)
676 struct command_line
*c
;
678 for (c
= commands
; c
; c
= c
->next
)
682 if (c
->control_type
== while_stepping_control
)
683 error (_("The 'while-stepping' command can "
684 "only be used for tracepoints"));
686 for (i
= 0; i
< c
->body_count
; ++i
)
687 check_no_tracepoint_commands ((c
->body_list
)[i
]);
689 /* Not that command parsing removes leading whitespace and comment
690 lines and also empty lines. So, we only need to check for
692 if (strstr (c
->line
, "collect ") == c
->line
)
693 error (_("The 'collect' command can only be used for tracepoints"));
695 if (strstr (c
->line
, "teval ") == c
->line
)
696 error (_("The 'teval' command can only be used for tracepoints"));
700 /* Encapsulate tests for different types of tracepoints. */
703 is_tracepoint (const struct breakpoint
*b
)
705 return (b
->type
== bp_tracepoint
706 || b
->type
== bp_fast_tracepoint
707 || b
->type
== bp_static_tracepoint
);
710 /* A helper function that validsates that COMMANDS are valid for a
711 breakpoint. This function will throw an exception if a problem is
715 validate_commands_for_breakpoint (struct breakpoint
*b
,
716 struct command_line
*commands
)
718 if (is_tracepoint (b
))
720 /* We need to verify that each top-level element of commands is
721 valid for tracepoints, that there's at most one
722 while-stepping element, and that while-stepping's body has
723 valid tracing commands excluding nested while-stepping. */
724 struct command_line
*c
;
725 struct command_line
*while_stepping
= 0;
726 for (c
= commands
; c
; c
= c
->next
)
728 if (c
->control_type
== while_stepping_control
)
730 if (b
->type
== bp_fast_tracepoint
)
731 error (_("The 'while-stepping' command "
732 "cannot be used for fast tracepoint"));
733 else if (b
->type
== bp_static_tracepoint
)
734 error (_("The 'while-stepping' command "
735 "cannot be used for static tracepoint"));
738 error (_("The 'while-stepping' command "
739 "can be used only once"));
746 struct command_line
*c2
;
748 gdb_assert (while_stepping
->body_count
== 1);
749 c2
= while_stepping
->body_list
[0];
750 for (; c2
; c2
= c2
->next
)
752 if (c2
->control_type
== while_stepping_control
)
753 error (_("The 'while-stepping' command cannot be nested"));
759 check_no_tracepoint_commands (commands
);
763 /* Return a vector of all the static tracepoints set at ADDR. The
764 caller is responsible for releasing the vector. */
767 static_tracepoints_here (CORE_ADDR addr
)
769 struct breakpoint
*b
;
770 VEC(breakpoint_p
) *found
= 0;
771 struct bp_location
*loc
;
774 if (b
->type
== bp_static_tracepoint
)
776 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
777 if (loc
->address
== addr
)
778 VEC_safe_push(breakpoint_p
, found
, b
);
784 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
785 validate that only allowed commands are included. */
788 breakpoint_set_commands (struct breakpoint
*b
,
789 struct command_line
*commands
)
791 validate_commands_for_breakpoint (b
, commands
);
793 decref_counted_command_line (&b
->commands
);
794 b
->commands
= alloc_counted_command_line (commands
);
795 breakpoints_changed ();
796 observer_notify_breakpoint_modified (b
);
799 /* Set the internal `silent' flag on the breakpoint. Note that this
800 is not the same as the "silent" that may appear in the breakpoint's
804 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
806 int old_silent
= b
->silent
;
809 if (old_silent
!= silent
)
810 observer_notify_breakpoint_modified (b
);
813 /* Set the thread for this breakpoint. If THREAD is -1, make the
814 breakpoint work for any thread. */
817 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
819 int old_thread
= b
->thread
;
822 if (old_thread
!= thread
)
823 observer_notify_breakpoint_modified (b
);
826 /* Set the task for this breakpoint. If TASK is 0, make the
827 breakpoint work for any task. */
830 breakpoint_set_task (struct breakpoint
*b
, int task
)
832 int old_task
= b
->task
;
835 if (old_task
!= task
)
836 observer_notify_breakpoint_modified (b
);
840 check_tracepoint_command (char *line
, void *closure
)
842 struct breakpoint
*b
= closure
;
844 validate_actionline (&line
, b
);
847 /* A structure used to pass information through
848 map_breakpoint_numbers. */
852 /* True if the command was typed at a tty. */
855 /* The breakpoint range spec. */
858 /* Non-NULL if the body of the commands are being read from this
859 already-parsed command. */
860 struct command_line
*control
;
862 /* The command lines read from the user, or NULL if they have not
864 struct counted_command_line
*cmd
;
867 /* A callback for map_breakpoint_numbers that sets the commands for
871 do_map_commands_command (struct breakpoint
*b
, void *data
)
873 struct commands_info
*info
= data
;
875 if (info
->cmd
== NULL
)
877 struct command_line
*l
;
879 if (info
->control
!= NULL
)
880 l
= copy_command_lines (info
->control
->body_list
[0]);
883 struct cleanup
*old_chain
;
886 str
= xstrprintf (_("Type commands for breakpoint(s) "
887 "%s, one per line."),
890 old_chain
= make_cleanup (xfree
, str
);
892 l
= read_command_lines (str
,
895 ? check_tracepoint_command
: 0),
898 do_cleanups (old_chain
);
901 info
->cmd
= alloc_counted_command_line (l
);
904 /* If a breakpoint was on the list more than once, we don't need to
906 if (b
->commands
!= info
->cmd
)
908 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
909 incref_counted_command_line (info
->cmd
);
910 decref_counted_command_line (&b
->commands
);
911 b
->commands
= info
->cmd
;
912 breakpoints_changed ();
913 observer_notify_breakpoint_modified (b
);
918 commands_command_1 (char *arg
, int from_tty
,
919 struct command_line
*control
)
921 struct cleanup
*cleanups
;
922 struct commands_info info
;
924 info
.from_tty
= from_tty
;
925 info
.control
= control
;
927 /* If we read command lines from the user, then `info' will hold an
928 extra reference to the commands that we must clean up. */
929 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
931 if (arg
== NULL
|| !*arg
)
933 if (breakpoint_count
- prev_breakpoint_count
> 1)
934 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
936 else if (breakpoint_count
> 0)
937 arg
= xstrprintf ("%d", breakpoint_count
);
940 /* So that we don't try to free the incoming non-NULL
941 argument in the cleanup below. Mapping breakpoint
942 numbers will fail in this case. */
947 /* The command loop has some static state, so we need to preserve
952 make_cleanup (xfree
, arg
);
956 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
958 if (info
.cmd
== NULL
)
959 error (_("No breakpoints specified."));
961 do_cleanups (cleanups
);
965 commands_command (char *arg
, int from_tty
)
967 commands_command_1 (arg
, from_tty
, NULL
);
970 /* Like commands_command, but instead of reading the commands from
971 input stream, takes them from an already parsed command structure.
973 This is used by cli-script.c to DTRT with breakpoint commands
974 that are part of if and while bodies. */
975 enum command_control_type
976 commands_from_control_command (char *arg
, struct command_line
*cmd
)
978 commands_command_1 (arg
, 0, cmd
);
979 return simple_control
;
982 /* Return non-zero if BL->TARGET_INFO contains valid information. */
985 bp_location_has_shadow (struct bp_location
*bl
)
987 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
991 if (bl
->target_info
.shadow_len
== 0)
992 /* bp isn't valid, or doesn't shadow memory. */
997 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
998 by replacing any memory breakpoints with their shadowed contents.
1000 The range of shadowed area by each bp_location is:
1001 bl->address - bp_location_placed_address_before_address_max
1002 up to bl->address + bp_location_shadow_len_after_address_max
1003 The range we were requested to resolve shadows for is:
1004 memaddr ... memaddr + len
1005 Thus the safe cutoff boundaries for performance optimization are
1006 memaddr + len <= (bl->address
1007 - bp_location_placed_address_before_address_max)
1009 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1012 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1014 /* Left boundary, right boundary and median element of our binary
1016 unsigned bc_l
, bc_r
, bc
;
1018 /* Find BC_L which is a leftmost element which may affect BUF
1019 content. It is safe to report lower value but a failure to
1020 report higher one. */
1023 bc_r
= bp_location_count
;
1024 while (bc_l
+ 1 < bc_r
)
1026 struct bp_location
*bl
;
1028 bc
= (bc_l
+ bc_r
) / 2;
1029 bl
= bp_location
[bc
];
1031 /* Check first BL->ADDRESS will not overflow due to the added
1032 constant. Then advance the left boundary only if we are sure
1033 the BC element can in no way affect the BUF content (MEMADDR
1034 to MEMADDR + LEN range).
1036 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1037 offset so that we cannot miss a breakpoint with its shadow
1038 range tail still reaching MEMADDR. */
1040 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1042 && (bl
->address
+ bp_location_shadow_len_after_address_max
1049 /* Due to the binary search above, we need to make sure we pick the
1050 first location that's at BC_L's address. E.g., if there are
1051 multiple locations at the same address, BC_L may end up pointing
1052 at a duplicate location, and miss the "master"/"inserted"
1053 location. Say, given locations L1, L2 and L3 at addresses A and
1056 L1@A, L2@A, L3@B, ...
1058 BC_L could end up pointing at location L2, while the "master"
1059 location could be L1. Since the `loc->inserted' flag is only set
1060 on "master" locations, we'd forget to restore the shadow of L1
1063 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1066 /* Now do full processing of the found relevant range of elements. */
1068 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1070 struct bp_location
*bl
= bp_location
[bc
];
1071 CORE_ADDR bp_addr
= 0;
1075 /* bp_location array has BL->OWNER always non-NULL. */
1076 if (bl
->owner
->type
== bp_none
)
1077 warning (_("reading through apparently deleted breakpoint #%d?"),
1080 /* Performance optimization: any futher element can no longer affect BUF
1083 if (bl
->address
>= bp_location_placed_address_before_address_max
1084 && memaddr
+ len
<= (bl
->address
1085 - bp_location_placed_address_before_address_max
))
1088 if (!bp_location_has_shadow (bl
))
1090 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1091 current_program_space
->aspace
, 0))
1094 /* Addresses and length of the part of the breakpoint that
1096 bp_addr
= bl
->target_info
.placed_address
;
1097 bp_size
= bl
->target_info
.shadow_len
;
1099 if (bp_addr
+ bp_size
<= memaddr
)
1100 /* The breakpoint is entirely before the chunk of memory we
1104 if (bp_addr
>= memaddr
+ len
)
1105 /* The breakpoint is entirely after the chunk of memory we are
1109 /* Offset within shadow_contents. */
1110 if (bp_addr
< memaddr
)
1112 /* Only copy the second part of the breakpoint. */
1113 bp_size
-= memaddr
- bp_addr
;
1114 bptoffset
= memaddr
- bp_addr
;
1118 if (bp_addr
+ bp_size
> memaddr
+ len
)
1120 /* Only copy the first part of the breakpoint. */
1121 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1124 memcpy (buf
+ bp_addr
- memaddr
,
1125 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1130 /* Return true if BPT is of any hardware watchpoint kind. */
1133 is_hardware_watchpoint (const 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 (const struct breakpoint
*bpt
)
1146 return (is_hardware_watchpoint (bpt
)
1147 || bpt
->type
== bp_watchpoint
);
1150 /* Assuming that B is a watchpoint: returns true if the current thread
1151 and its running state are safe to evaluate or update watchpoint B.
1152 Watchpoints on local expressions need to be evaluated in the
1153 context of the thread that was current when the watchpoint was
1154 created, and, that thread needs to be stopped to be able to select
1155 the correct frame context. Watchpoints on global expressions can
1156 be evaluated on any thread, and in any state. It is presently left
1157 to the target allowing memory accesses when threads are
1161 watchpoint_in_thread_scope (struct breakpoint
*b
)
1163 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1164 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1165 && !is_executing (inferior_ptid
)));
1168 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1169 associated bp_watchpoint_scope breakpoint. */
1172 watchpoint_del_at_next_stop (struct breakpoint
*b
)
1174 gdb_assert (is_watchpoint (b
));
1176 if (b
->related_breakpoint
!= b
)
1178 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1179 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1180 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1181 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1182 b
->related_breakpoint
= b
;
1184 b
->disposition
= disp_del_at_next_stop
;
1187 /* Assuming that B is a watchpoint:
1188 - Reparse watchpoint expression, if REPARSE is non-zero
1189 - Evaluate expression and store the result in B->val
1190 - Evaluate the condition if there is one, and store the result
1192 - Update the list of values that must be watched in B->loc.
1194 If the watchpoint disposition is disp_del_at_next_stop, then do
1195 nothing. If this is local watchpoint that is out of scope, delete
1198 Even with `set breakpoint always-inserted on' the watchpoints are
1199 removed + inserted on each stop here. Normal breakpoints must
1200 never be removed because they might be missed by a running thread
1201 when debugging in non-stop mode. On the other hand, hardware
1202 watchpoints (is_hardware_watchpoint; processed here) are specific
1203 to each LWP since they are stored in each LWP's hardware debug
1204 registers. Therefore, such LWP must be stopped first in order to
1205 be able to modify its hardware watchpoints.
1207 Hardware watchpoints must be reset exactly once after being
1208 presented to the user. It cannot be done sooner, because it would
1209 reset the data used to present the watchpoint hit to the user. And
1210 it must not be done later because it could display the same single
1211 watchpoint hit during multiple GDB stops. Note that the latter is
1212 relevant only to the hardware watchpoint types bp_read_watchpoint
1213 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1214 not user-visible - its hit is suppressed if the memory content has
1217 The following constraints influence the location where we can reset
1218 hardware watchpoints:
1220 * target_stopped_by_watchpoint and target_stopped_data_address are
1221 called several times when GDB stops.
1224 * Multiple hardware watchpoints can be hit at the same time,
1225 causing GDB to stop. GDB only presents one hardware watchpoint
1226 hit at a time as the reason for stopping, and all the other hits
1227 are presented later, one after the other, each time the user
1228 requests the execution to be resumed. Execution is not resumed
1229 for the threads still having pending hit event stored in
1230 LWP_INFO->STATUS. While the watchpoint is already removed from
1231 the inferior on the first stop the thread hit event is kept being
1232 reported from its cached value by linux_nat_stopped_data_address
1233 until the real thread resume happens after the watchpoint gets
1234 presented and thus its LWP_INFO->STATUS gets reset.
1236 Therefore the hardware watchpoint hit can get safely reset on the
1237 watchpoint removal from inferior. */
1240 update_watchpoint (struct breakpoint
*b
, int reparse
)
1242 int within_current_scope
;
1243 struct frame_id saved_frame_id
;
1246 gdb_assert (is_watchpoint (b
));
1248 /* If this is a local watchpoint, we only want to check if the
1249 watchpoint frame is in scope if the current thread is the thread
1250 that was used to create the watchpoint. */
1251 if (!watchpoint_in_thread_scope (b
))
1254 if (b
->disposition
== disp_del_at_next_stop
)
1259 /* Determine if the watchpoint is within scope. */
1260 if (b
->exp_valid_block
== NULL
)
1261 within_current_scope
= 1;
1264 struct frame_info
*fi
= get_current_frame ();
1265 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1266 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1268 /* If we're in a function epilogue, unwinding may not work
1269 properly, so do not attempt to recreate locations at this
1270 point. See similar comments in watchpoint_check. */
1271 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1274 /* Save the current frame's ID so we can restore it after
1275 evaluating the watchpoint expression on its own frame. */
1276 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1277 took a frame parameter, so that we didn't have to change the
1280 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1282 fi
= frame_find_by_id (b
->watchpoint_frame
);
1283 within_current_scope
= (fi
!= NULL
);
1284 if (within_current_scope
)
1288 /* We don't free locations. They are stored in the bp_location array
1289 and update_global_location_list will eventually delete them and
1290 remove breakpoints if needed. */
1293 if (within_current_scope
&& reparse
)
1302 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1303 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1304 /* If the meaning of expression itself changed, the old value is
1305 no longer relevant. We don't want to report a watchpoint hit
1306 to the user when the old value and the new value may actually
1307 be completely different objects. */
1308 value_free (b
->val
);
1312 /* Note that unlike with breakpoints, the watchpoint's condition
1313 expression is stored in the breakpoint object, not in the
1314 locations (re)created below. */
1315 if (b
->cond_string
!= NULL
)
1317 if (b
->cond_exp
!= NULL
)
1319 xfree (b
->cond_exp
);
1324 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1328 /* If we failed to parse the expression, for example because
1329 it refers to a global variable in a not-yet-loaded shared library,
1330 don't try to insert watchpoint. We don't automatically delete
1331 such watchpoint, though, since failure to parse expression
1332 is different from out-of-scope watchpoint. */
1333 if ( !target_has_execution
)
1335 /* Without execution, memory can't change. No use to try and
1336 set watchpoint locations. The watchpoint will be reset when
1337 the target gains execution, through breakpoint_re_set. */
1339 else if (within_current_scope
&& b
->exp
)
1342 struct value
*val_chain
, *v
, *result
, *next
;
1343 struct program_space
*frame_pspace
;
1345 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1347 /* Avoid setting b->val if it's already set. The meaning of
1348 b->val is 'the last value' user saw, and we should update
1349 it only if we reported that last value to user. As it
1350 happens, the code that reports it updates b->val directly.
1351 We don't keep track of the memory value for masked
1353 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1359 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1361 /* Look at each value on the value chain. */
1362 for (v
= val_chain
; v
; v
= value_next (v
))
1364 /* If it's a memory location, and GDB actually needed
1365 its contents to evaluate the expression, then we
1366 must watch it. If the first value returned is
1367 still lazy, that means an error occurred reading it;
1368 watch it anyway in case it becomes readable. */
1369 if (VALUE_LVAL (v
) == lval_memory
1370 && (v
== val_chain
|| ! value_lazy (v
)))
1372 struct type
*vtype
= check_typedef (value_type (v
));
1374 /* We only watch structs and arrays if user asked
1375 for it explicitly, never if they just happen to
1376 appear in the middle of some value chain. */
1378 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1379 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1383 struct bp_location
*loc
, **tmp
;
1385 addr
= value_address (v
);
1386 len
= TYPE_LENGTH (value_type (v
));
1388 if (b
->type
== bp_read_watchpoint
)
1390 else if (b
->type
== bp_access_watchpoint
)
1393 loc
= allocate_bp_location (b
);
1394 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1397 loc
->gdbarch
= get_type_arch (value_type (v
));
1399 loc
->pspace
= frame_pspace
;
1400 loc
->address
= addr
;
1402 loc
->watchpoint_type
= type
;
1407 /* Change the type of breakpoint between hardware assisted or
1408 an ordinary watchpoint depending on the hardware support
1409 and free hardware slots. REPARSE is set when the inferior
1414 enum bp_loc_type loc_type
;
1415 struct bp_location
*bl
;
1417 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1421 int i
, target_resources_ok
, other_type_used
;
1423 /* Use an exact watchpoint when there's only one memory region to be
1424 watched, and only one debug register is needed to watch it. */
1425 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1427 /* We need to determine how many resources are already
1428 used for all other hardware watchpoints plus this one
1429 to see if we still have enough resources to also fit
1430 this watchpoint in as well. To guarantee the
1431 hw_watchpoint_used_count call below counts this
1432 watchpoint, make sure that it is marked as a hardware
1434 if (b
->type
== bp_watchpoint
)
1435 b
->type
= bp_hardware_watchpoint
;
1437 i
= hw_watchpoint_used_count (b
->type
, &other_type_used
);
1438 target_resources_ok
= target_can_use_hardware_watchpoint
1439 (b
->type
, i
, other_type_used
);
1440 if (target_resources_ok
<= 0)
1442 /* If there's no works_in_software_mode method, we
1443 assume that the watchpoint works in software mode. */
1444 int sw_mode
= (!b
->ops
|| !b
->ops
->works_in_software_mode
1445 || b
->ops
->works_in_software_mode (b
));
1447 if (target_resources_ok
== 0 && !sw_mode
)
1448 error (_("Target does not support this type of "
1449 "hardware watchpoint."));
1450 else if (target_resources_ok
< 0 && !sw_mode
)
1451 error (_("There are not enough available hardware "
1452 "resources for this watchpoint."));
1454 b
->type
= bp_watchpoint
;
1457 else if (b
->ops
&& b
->ops
->works_in_software_mode
1458 && !b
->ops
->works_in_software_mode (b
))
1459 error (_("Expression cannot be implemented with "
1460 "read/access watchpoint."));
1462 b
->type
= bp_watchpoint
;
1464 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1465 : bp_loc_hardware_watchpoint
);
1466 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1467 bl
->loc_type
= loc_type
;
1470 for (v
= val_chain
; v
; v
= next
)
1472 next
= value_next (v
);
1477 /* If a software watchpoint is not watching any memory, then the
1478 above left it without any location set up. But,
1479 bpstat_stop_status requires a location to be able to report
1480 stops, so make sure there's at least a dummy one. */
1481 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1483 b
->loc
= allocate_bp_location (b
);
1484 b
->loc
->pspace
= frame_pspace
;
1485 b
->loc
->address
= -1;
1486 b
->loc
->length
= -1;
1487 b
->loc
->watchpoint_type
= -1;
1490 else if (!within_current_scope
)
1492 printf_filtered (_("\
1493 Watchpoint %d deleted because the program has left the block\n\
1494 in which its expression is valid.\n"),
1496 watchpoint_del_at_next_stop (b
);
1499 /* Restore the selected frame. */
1501 select_frame (frame_find_by_id (saved_frame_id
));
1505 /* Returns 1 iff breakpoint location should be
1506 inserted in the inferior. */
1508 should_be_inserted (struct bp_location
*bl
)
1510 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1513 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1516 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1519 /* This is set for example, when we're attached to the parent of a
1520 vfork, and have detached from the child. The child is running
1521 free, and we expect it to do an exec or exit, at which point the
1522 OS makes the parent schedulable again (and the target reports
1523 that the vfork is done). Until the child is done with the shared
1524 memory region, do not insert breakpoints in the parent, otherwise
1525 the child could still trip on the parent's breakpoints. Since
1526 the parent is blocked anyway, it won't miss any breakpoint. */
1527 if (bl
->pspace
->breakpoints_not_allowed
)
1530 /* Tracepoints are inserted by the target at a time of its choosing,
1532 if (is_tracepoint (bl
->owner
))
1538 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1539 location. Any error messages are printed to TMP_ERROR_STREAM; and
1540 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1542 NOTE drow/2003-09-09: This routine could be broken down to an
1543 object-style method for each breakpoint or catchpoint type. */
1545 insert_bp_location (struct bp_location
*bl
,
1546 struct ui_file
*tmp_error_stream
,
1547 int *disabled_breaks
,
1548 int *hw_breakpoint_error
)
1552 if (!should_be_inserted (bl
) || bl
->inserted
)
1555 /* Initialize the target-specific information. */
1556 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1557 bl
->target_info
.placed_address
= bl
->address
;
1558 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1559 bl
->target_info
.length
= bl
->length
;
1561 if (bl
->loc_type
== bp_loc_software_breakpoint
1562 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1564 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1566 /* If the explicitly specified breakpoint type
1567 is not hardware breakpoint, check the memory map to see
1568 if the breakpoint address is in read only memory or not.
1570 Two important cases are:
1571 - location type is not hardware breakpoint, memory
1572 is readonly. We change the type of the location to
1573 hardware breakpoint.
1574 - location type is hardware breakpoint, memory is
1575 read-write. This means we've previously made the
1576 location hardware one, but then the memory map changed,
1579 When breakpoints are removed, remove_breakpoints will use
1580 location types we've just set here, the only possible
1581 problem is that memory map has changed during running
1582 program, but it's not going to work anyway with current
1584 struct mem_region
*mr
1585 = lookup_mem_region (bl
->target_info
.placed_address
);
1589 if (automatic_hardware_breakpoints
)
1591 enum bp_loc_type new_type
;
1593 if (mr
->attrib
.mode
!= MEM_RW
)
1594 new_type
= bp_loc_hardware_breakpoint
;
1596 new_type
= bp_loc_software_breakpoint
;
1598 if (new_type
!= bl
->loc_type
)
1600 static int said
= 0;
1602 bl
->loc_type
= new_type
;
1605 fprintf_filtered (gdb_stdout
,
1606 _("Note: automatically using "
1607 "hardware breakpoints for "
1608 "read-only addresses.\n"));
1613 else if (bl
->loc_type
== bp_loc_software_breakpoint
1614 && mr
->attrib
.mode
!= MEM_RW
)
1615 warning (_("cannot set software breakpoint "
1616 "at readonly address %s"),
1617 paddress (bl
->gdbarch
, bl
->address
));
1621 /* First check to see if we have to handle an overlay. */
1622 if (overlay_debugging
== ovly_off
1623 || bl
->section
== NULL
1624 || !(section_is_overlay (bl
->section
)))
1626 /* No overlay handling: just set the breakpoint. */
1628 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1629 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1632 val
= target_insert_breakpoint (bl
->gdbarch
,
1637 /* This breakpoint is in an overlay section.
1638 Shall we set a breakpoint at the LMA? */
1639 if (!overlay_events_enabled
)
1641 /* Yes -- overlay event support is not active,
1642 so we must try to set a breakpoint at the LMA.
1643 This will not work for a hardware breakpoint. */
1644 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1645 warning (_("hardware breakpoint %d not supported in overlay!"),
1649 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1651 /* Set a software (trap) breakpoint at the LMA. */
1652 bl
->overlay_target_info
= bl
->target_info
;
1653 bl
->overlay_target_info
.placed_address
= addr
;
1654 val
= target_insert_breakpoint (bl
->gdbarch
,
1655 &bl
->overlay_target_info
);
1657 fprintf_unfiltered (tmp_error_stream
,
1658 "Overlay breakpoint %d "
1659 "failed: in ROM?\n",
1663 /* Shall we set a breakpoint at the VMA? */
1664 if (section_is_mapped (bl
->section
))
1666 /* Yes. This overlay section is mapped into memory. */
1667 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1668 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1671 val
= target_insert_breakpoint (bl
->gdbarch
,
1676 /* No. This breakpoint will not be inserted.
1677 No error, but do not mark the bp as 'inserted'. */
1684 /* Can't set the breakpoint. */
1685 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1687 /* See also: disable_breakpoints_in_shlibs. */
1689 bl
->shlib_disabled
= 1;
1690 observer_notify_breakpoint_modified (bl
->owner
);
1691 if (!*disabled_breaks
)
1693 fprintf_unfiltered (tmp_error_stream
,
1694 "Cannot insert breakpoint %d.\n",
1696 fprintf_unfiltered (tmp_error_stream
,
1697 "Temporarily disabling shared "
1698 "library breakpoints:\n");
1700 *disabled_breaks
= 1;
1701 fprintf_unfiltered (tmp_error_stream
,
1702 "breakpoint #%d\n", bl
->owner
->number
);
1706 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1708 *hw_breakpoint_error
= 1;
1709 fprintf_unfiltered (tmp_error_stream
,
1710 "Cannot insert hardware "
1716 fprintf_unfiltered (tmp_error_stream
,
1717 "Cannot insert breakpoint %d.\n",
1719 fprintf_filtered (tmp_error_stream
,
1720 "Error accessing memory address ");
1721 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1723 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1724 safe_strerror (val
));
1735 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1736 /* NOTE drow/2003-09-08: This state only exists for removing
1737 watchpoints. It's not clear that it's necessary... */
1738 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1740 gdb_assert (bl
->owner
->ops
!= NULL
1741 && bl
->owner
->ops
->insert_location
!= NULL
);
1743 val
= bl
->owner
->ops
->insert_location (bl
);
1745 /* If trying to set a read-watchpoint, and it turns out it's not
1746 supported, try emulating one with an access watchpoint. */
1747 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1749 struct bp_location
*loc
, **loc_temp
;
1751 /* But don't try to insert it, if there's already another
1752 hw_access location that would be considered a duplicate
1754 ALL_BP_LOCATIONS (loc
, loc_temp
)
1756 && loc
->watchpoint_type
== hw_access
1757 && watchpoint_locations_match (bl
, loc
))
1761 bl
->target_info
= loc
->target_info
;
1762 bl
->watchpoint_type
= hw_access
;
1769 bl
->watchpoint_type
= hw_access
;
1770 val
= bl
->owner
->ops
->insert_location (bl
);
1773 /* Back to the original value. */
1774 bl
->watchpoint_type
= hw_read
;
1778 bl
->inserted
= (val
== 0);
1781 else if (bl
->owner
->type
== bp_catchpoint
)
1783 gdb_assert (bl
->owner
->ops
!= NULL
1784 && bl
->owner
->ops
->insert_location
!= NULL
);
1786 val
= bl
->owner
->ops
->insert_location (bl
);
1789 bl
->owner
->enable_state
= bp_disabled
;
1793 Error inserting catchpoint %d: Your system does not support this type\n\
1794 of catchpoint."), bl
->owner
->number
);
1796 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1799 bl
->inserted
= (val
== 0);
1801 /* We've already printed an error message if there was a problem
1802 inserting this catchpoint, and we've disabled the catchpoint,
1803 so just return success. */
1810 /* This function is called when program space PSPACE is about to be
1811 deleted. It takes care of updating breakpoints to not reference
1815 breakpoint_program_space_exit (struct program_space
*pspace
)
1817 struct breakpoint
*b
, *b_temp
;
1818 struct bp_location
*loc
, **loc_temp
;
1820 /* Remove any breakpoint that was set through this program space. */
1821 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1823 if (b
->pspace
== pspace
)
1824 delete_breakpoint (b
);
1827 /* Breakpoints set through other program spaces could have locations
1828 bound to PSPACE as well. Remove those. */
1829 ALL_BP_LOCATIONS (loc
, loc_temp
)
1831 struct bp_location
*tmp
;
1833 if (loc
->pspace
== pspace
)
1835 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1836 if (loc
->owner
->loc
== loc
)
1837 loc
->owner
->loc
= loc
->next
;
1839 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1840 if (tmp
->next
== loc
)
1842 tmp
->next
= loc
->next
;
1848 /* Now update the global location list to permanently delete the
1849 removed locations above. */
1850 update_global_location_list (0);
1853 /* Make sure all breakpoints are inserted in inferior.
1854 Throws exception on any error.
1855 A breakpoint that is already inserted won't be inserted
1856 again, so calling this function twice is safe. */
1858 insert_breakpoints (void)
1860 struct breakpoint
*bpt
;
1862 ALL_BREAKPOINTS (bpt
)
1863 if (is_hardware_watchpoint (bpt
))
1864 update_watchpoint (bpt
, 0 /* don't reparse. */);
1866 update_global_location_list (1);
1868 /* update_global_location_list does not insert breakpoints when
1869 always_inserted_mode is not enabled. Explicitly insert them
1871 if (!breakpoints_always_inserted_mode ())
1872 insert_breakpoint_locations ();
1875 /* insert_breakpoints is used when starting or continuing the program.
1876 remove_breakpoints is used when the program stops.
1877 Both return zero if successful,
1878 or an `errno' value if could not write the inferior. */
1881 insert_breakpoint_locations (void)
1883 struct breakpoint
*bpt
;
1884 struct bp_location
*bl
, **blp_tmp
;
1887 int disabled_breaks
= 0;
1888 int hw_breakpoint_error
= 0;
1890 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1891 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1893 /* Explicitly mark the warning -- this will only be printed if
1894 there was an error. */
1895 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1897 save_current_space_and_thread ();
1899 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1901 if (!should_be_inserted (bl
) || bl
->inserted
)
1904 /* There is no point inserting thread-specific breakpoints if
1905 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1906 has BL->OWNER always non-NULL. */
1907 if (bl
->owner
->thread
!= -1
1908 && !valid_thread_id (bl
->owner
->thread
))
1911 switch_to_program_space_and_thread (bl
->pspace
);
1913 /* For targets that support global breakpoints, there's no need
1914 to select an inferior to insert breakpoint to. In fact, even
1915 if we aren't attached to any process yet, we should still
1916 insert breakpoints. */
1917 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1918 && ptid_equal (inferior_ptid
, null_ptid
))
1921 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1922 &hw_breakpoint_error
);
1927 /* If we failed to insert all locations of a watchpoint, remove
1928 them, as half-inserted watchpoint is of limited use. */
1929 ALL_BREAKPOINTS (bpt
)
1931 int some_failed
= 0;
1932 struct bp_location
*loc
;
1934 if (!is_hardware_watchpoint (bpt
))
1937 if (!breakpoint_enabled (bpt
))
1940 if (bpt
->disposition
== disp_del_at_next_stop
)
1943 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1944 if (!loc
->inserted
&& should_be_inserted (loc
))
1951 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1953 remove_breakpoint (loc
, mark_uninserted
);
1955 hw_breakpoint_error
= 1;
1956 fprintf_unfiltered (tmp_error_stream
,
1957 "Could not insert hardware watchpoint %d.\n",
1965 /* If a hardware breakpoint or watchpoint was inserted, add a
1966 message about possibly exhausted resources. */
1967 if (hw_breakpoint_error
)
1969 fprintf_unfiltered (tmp_error_stream
,
1970 "Could not insert hardware breakpoints:\n\
1971 You may have requested too many hardware breakpoints/watchpoints.\n");
1973 target_terminal_ours_for_output ();
1974 error_stream (tmp_error_stream
);
1977 do_cleanups (cleanups
);
1981 remove_breakpoints (void)
1983 struct bp_location
*bl
, **blp_tmp
;
1986 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1989 val
|= remove_breakpoint (bl
, mark_uninserted
);
1994 /* Remove breakpoints of process PID. */
1997 remove_breakpoints_pid (int pid
)
1999 struct bp_location
*bl
, **blp_tmp
;
2001 struct inferior
*inf
= find_inferior_pid (pid
);
2003 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2005 if (bl
->pspace
!= inf
->pspace
)
2010 val
= remove_breakpoint (bl
, mark_uninserted
);
2019 remove_hw_watchpoints (void)
2021 struct bp_location
*bl
, **blp_tmp
;
2024 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2026 if (bl
->inserted
&& bl
->loc_type
== bp_loc_hardware_watchpoint
)
2027 val
|= remove_breakpoint (bl
, mark_uninserted
);
2033 reattach_breakpoints (int pid
)
2035 struct cleanup
*old_chain
;
2036 struct bp_location
*bl
, **blp_tmp
;
2038 struct ui_file
*tmp_error_stream
;
2039 int dummy1
= 0, dummy2
= 0;
2040 struct inferior
*inf
;
2041 struct thread_info
*tp
;
2043 tp
= any_live_thread_of_process (pid
);
2047 inf
= find_inferior_pid (pid
);
2048 old_chain
= save_inferior_ptid ();
2050 inferior_ptid
= tp
->ptid
;
2052 tmp_error_stream
= mem_fileopen ();
2053 make_cleanup_ui_file_delete (tmp_error_stream
);
2055 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2057 if (bl
->pspace
!= inf
->pspace
)
2063 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2066 do_cleanups (old_chain
);
2071 do_cleanups (old_chain
);
2075 static int internal_breakpoint_number
= -1;
2077 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2078 If INTERNAL is non-zero, the breakpoint number will be populated
2079 from internal_breakpoint_number and that variable decremented.
2080 Otherwis the breakpoint number will be populated from
2081 breakpoint_count and that value incremented. Internal breakpoints
2082 do not set the internal var bpnum. */
2084 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2087 b
->number
= internal_breakpoint_number
--;
2090 set_breakpoint_count (breakpoint_count
+ 1);
2091 b
->number
= breakpoint_count
;
2095 static struct breakpoint
*
2096 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2097 CORE_ADDR address
, enum bptype type
)
2099 struct symtab_and_line sal
;
2100 struct breakpoint
*b
;
2102 init_sal (&sal
); /* Initialize to zeroes. */
2105 sal
.section
= find_pc_overlay (sal
.pc
);
2106 sal
.pspace
= current_program_space
;
2108 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2109 b
->number
= internal_breakpoint_number
--;
2110 b
->disposition
= disp_donttouch
;
2115 static const char *const longjmp_names
[] =
2117 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2119 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2121 /* Per-objfile data private to breakpoint.c. */
2122 struct breakpoint_objfile_data
2124 /* Minimal symbol for "_ovly_debug_event" (if any). */
2125 struct minimal_symbol
*overlay_msym
;
2127 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2128 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2130 /* Minimal symbol for "std::terminate()" (if any). */
2131 struct minimal_symbol
*terminate_msym
;
2133 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2134 struct minimal_symbol
*exception_msym
;
2137 static const struct objfile_data
*breakpoint_objfile_key
;
2139 /* Minimal symbol not found sentinel. */
2140 static struct minimal_symbol msym_not_found
;
2142 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2145 msym_not_found_p (const struct minimal_symbol
*msym
)
2147 return msym
== &msym_not_found
;
2150 /* Return per-objfile data needed by breakpoint.c.
2151 Allocate the data if necessary. */
2153 static struct breakpoint_objfile_data
*
2154 get_breakpoint_objfile_data (struct objfile
*objfile
)
2156 struct breakpoint_objfile_data
*bp_objfile_data
;
2158 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2159 if (bp_objfile_data
== NULL
)
2161 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2162 sizeof (*bp_objfile_data
));
2164 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2165 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2167 return bp_objfile_data
;
2171 create_overlay_event_breakpoint (void)
2173 struct objfile
*objfile
;
2174 const char *const func_name
= "_ovly_debug_event";
2176 ALL_OBJFILES (objfile
)
2178 struct breakpoint
*b
;
2179 struct breakpoint_objfile_data
*bp_objfile_data
;
2182 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2184 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2187 if (bp_objfile_data
->overlay_msym
== NULL
)
2189 struct minimal_symbol
*m
;
2191 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2194 /* Avoid future lookups in this objfile. */
2195 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2198 bp_objfile_data
->overlay_msym
= m
;
2201 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2202 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2204 b
->addr_string
= xstrdup (func_name
);
2206 if (overlay_debugging
== ovly_auto
)
2208 b
->enable_state
= bp_enabled
;
2209 overlay_events_enabled
= 1;
2213 b
->enable_state
= bp_disabled
;
2214 overlay_events_enabled
= 0;
2217 update_global_location_list (1);
2221 create_longjmp_master_breakpoint (void)
2223 struct program_space
*pspace
;
2224 struct cleanup
*old_chain
;
2226 old_chain
= save_current_program_space ();
2228 ALL_PSPACES (pspace
)
2230 struct objfile
*objfile
;
2232 set_current_program_space (pspace
);
2234 ALL_OBJFILES (objfile
)
2237 struct gdbarch
*gdbarch
;
2238 struct breakpoint_objfile_data
*bp_objfile_data
;
2240 gdbarch
= get_objfile_arch (objfile
);
2241 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2244 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2246 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2248 struct breakpoint
*b
;
2249 const char *func_name
;
2252 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2255 func_name
= longjmp_names
[i
];
2256 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2258 struct minimal_symbol
*m
;
2260 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2263 /* Prevent future lookups in this objfile. */
2264 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2267 bp_objfile_data
->longjmp_msym
[i
] = m
;
2270 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2271 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
2272 b
->addr_string
= xstrdup (func_name
);
2273 b
->enable_state
= bp_disabled
;
2277 update_global_location_list (1);
2279 do_cleanups (old_chain
);
2282 /* Create a master std::terminate breakpoint. */
2284 create_std_terminate_master_breakpoint (void)
2286 struct program_space
*pspace
;
2287 struct cleanup
*old_chain
;
2288 const char *const func_name
= "std::terminate()";
2290 old_chain
= save_current_program_space ();
2292 ALL_PSPACES (pspace
)
2294 struct objfile
*objfile
;
2297 set_current_program_space (pspace
);
2299 ALL_OBJFILES (objfile
)
2301 struct breakpoint
*b
;
2302 struct breakpoint_objfile_data
*bp_objfile_data
;
2304 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2306 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2309 if (bp_objfile_data
->terminate_msym
== NULL
)
2311 struct minimal_symbol
*m
;
2313 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2314 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2315 && MSYMBOL_TYPE (m
) != mst_file_text
))
2317 /* Prevent future lookups in this objfile. */
2318 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2321 bp_objfile_data
->terminate_msym
= m
;
2324 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2325 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2326 bp_std_terminate_master
);
2327 b
->addr_string
= xstrdup (func_name
);
2328 b
->enable_state
= bp_disabled
;
2332 update_global_location_list (1);
2334 do_cleanups (old_chain
);
2337 /* Install a master breakpoint on the unwinder's debug hook. */
2340 create_exception_master_breakpoint (void)
2342 struct objfile
*objfile
;
2343 const char *const func_name
= "_Unwind_DebugHook";
2345 ALL_OBJFILES (objfile
)
2347 struct breakpoint
*b
;
2348 struct gdbarch
*gdbarch
;
2349 struct breakpoint_objfile_data
*bp_objfile_data
;
2352 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2354 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2357 gdbarch
= get_objfile_arch (objfile
);
2359 if (bp_objfile_data
->exception_msym
== NULL
)
2361 struct minimal_symbol
*debug_hook
;
2363 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2364 if (debug_hook
== NULL
)
2366 bp_objfile_data
->exception_msym
= &msym_not_found
;
2370 bp_objfile_data
->exception_msym
= debug_hook
;
2373 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2374 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2376 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2377 b
->addr_string
= xstrdup (func_name
);
2378 b
->enable_state
= bp_disabled
;
2381 update_global_location_list (1);
2385 update_breakpoints_after_exec (void)
2387 struct breakpoint
*b
, *b_tmp
;
2388 struct bp_location
*bploc
, **bplocp_tmp
;
2390 /* We're about to delete breakpoints from GDB's lists. If the
2391 INSERTED flag is true, GDB will try to lift the breakpoints by
2392 writing the breakpoints' "shadow contents" back into memory. The
2393 "shadow contents" are NOT valid after an exec, so GDB should not
2394 do that. Instead, the target is responsible from marking
2395 breakpoints out as soon as it detects an exec. We don't do that
2396 here instead, because there may be other attempts to delete
2397 breakpoints after detecting an exec and before reaching here. */
2398 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2399 if (bploc
->pspace
== current_program_space
)
2400 gdb_assert (!bploc
->inserted
);
2402 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2404 if (b
->pspace
!= current_program_space
)
2407 /* Solib breakpoints must be explicitly reset after an exec(). */
2408 if (b
->type
== bp_shlib_event
)
2410 delete_breakpoint (b
);
2414 /* JIT breakpoints must be explicitly reset after an exec(). */
2415 if (b
->type
== bp_jit_event
)
2417 delete_breakpoint (b
);
2421 /* Thread event breakpoints must be set anew after an exec(),
2422 as must overlay event and longjmp master breakpoints. */
2423 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2424 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2425 || b
->type
== bp_exception_master
)
2427 delete_breakpoint (b
);
2431 /* Step-resume breakpoints are meaningless after an exec(). */
2432 if (b
->type
== bp_step_resume
)
2434 delete_breakpoint (b
);
2438 /* Longjmp and longjmp-resume breakpoints are also meaningless
2440 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2441 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2443 delete_breakpoint (b
);
2447 if (b
->type
== bp_catchpoint
)
2449 /* For now, none of the bp_catchpoint breakpoints need to
2450 do anything at this point. In the future, if some of
2451 the catchpoints need to something, we will need to add
2452 a new method, and call this method from here. */
2456 /* bp_finish is a special case. The only way we ought to be able
2457 to see one of these when an exec() has happened, is if the user
2458 caught a vfork, and then said "finish". Ordinarily a finish just
2459 carries them to the call-site of the current callee, by setting
2460 a temporary bp there and resuming. But in this case, the finish
2461 will carry them entirely through the vfork & exec.
2463 We don't want to allow a bp_finish to remain inserted now. But
2464 we can't safely delete it, 'cause finish_command has a handle to
2465 the bp on a bpstat, and will later want to delete it. There's a
2466 chance (and I've seen it happen) that if we delete the bp_finish
2467 here, that its storage will get reused by the time finish_command
2468 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2469 We really must allow finish_command to delete a bp_finish.
2471 In the absense of a general solution for the "how do we know
2472 it's safe to delete something others may have handles to?"
2473 problem, what we'll do here is just uninsert the bp_finish, and
2474 let finish_command delete it.
2476 (We know the bp_finish is "doomed" in the sense that it's
2477 momentary, and will be deleted as soon as finish_command sees
2478 the inferior stopped. So it doesn't matter that the bp's
2479 address is probably bogus in the new a.out, unlike e.g., the
2480 solib breakpoints.) */
2482 if (b
->type
== bp_finish
)
2487 /* Without a symbolic address, we have little hope of the
2488 pre-exec() address meaning the same thing in the post-exec()
2490 if (b
->addr_string
== NULL
)
2492 delete_breakpoint (b
);
2496 /* FIXME what about longjmp breakpoints? Re-create them here? */
2497 create_overlay_event_breakpoint ();
2498 create_longjmp_master_breakpoint ();
2499 create_std_terminate_master_breakpoint ();
2500 create_exception_master_breakpoint ();
2504 detach_breakpoints (int pid
)
2506 struct bp_location
*bl
, **blp_tmp
;
2508 struct cleanup
*old_chain
= save_inferior_ptid ();
2509 struct inferior
*inf
= current_inferior ();
2511 if (pid
== PIDGET (inferior_ptid
))
2512 error (_("Cannot detach breakpoints of inferior_ptid"));
2514 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2515 inferior_ptid
= pid_to_ptid (pid
);
2516 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2518 if (bl
->pspace
!= inf
->pspace
)
2522 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2525 /* Detach single-step breakpoints as well. */
2526 detach_single_step_breakpoints ();
2528 do_cleanups (old_chain
);
2532 /* Remove the breakpoint location BL from the current address space.
2533 Note that this is used to detach breakpoints from a child fork.
2534 When we get here, the child isn't in the inferior list, and neither
2535 do we have objects to represent its address space --- we should
2536 *not* look at bl->pspace->aspace here. */
2539 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2543 /* BL is never in moribund_locations by our callers. */
2544 gdb_assert (bl
->owner
!= NULL
);
2546 if (bl
->owner
->enable_state
== bp_permanent
)
2547 /* Permanent breakpoints cannot be inserted or removed. */
2550 /* The type of none suggests that owner is actually deleted.
2551 This should not ever happen. */
2552 gdb_assert (bl
->owner
->type
!= bp_none
);
2554 if (bl
->loc_type
== bp_loc_software_breakpoint
2555 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2557 /* "Normal" instruction breakpoint: either the standard
2558 trap-instruction bp (bp_breakpoint), or a
2559 bp_hardware_breakpoint. */
2561 /* First check to see if we have to handle an overlay. */
2562 if (overlay_debugging
== ovly_off
2563 || bl
->section
== NULL
2564 || !(section_is_overlay (bl
->section
)))
2566 /* No overlay handling: just remove the breakpoint. */
2568 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2569 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2571 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2575 /* This breakpoint is in an overlay section.
2576 Did we set a breakpoint at the LMA? */
2577 if (!overlay_events_enabled
)
2579 /* Yes -- overlay event support is not active, so we
2580 should have set a breakpoint at the LMA. Remove it.
2582 /* Ignore any failures: if the LMA is in ROM, we will
2583 have already warned when we failed to insert it. */
2584 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2585 target_remove_hw_breakpoint (bl
->gdbarch
,
2586 &bl
->overlay_target_info
);
2588 target_remove_breakpoint (bl
->gdbarch
,
2589 &bl
->overlay_target_info
);
2591 /* Did we set a breakpoint at the VMA?
2592 If so, we will have marked the breakpoint 'inserted'. */
2595 /* Yes -- remove it. Previously we did not bother to
2596 remove the breakpoint if the section had been
2597 unmapped, but let's not rely on that being safe. We
2598 don't know what the overlay manager might do. */
2599 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2600 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2603 /* However, we should remove *software* breakpoints only
2604 if the section is still mapped, or else we overwrite
2605 wrong code with the saved shadow contents. */
2606 else if (section_is_mapped (bl
->section
))
2607 val
= target_remove_breakpoint (bl
->gdbarch
,
2614 /* No -- not inserted, so no need to remove. No error. */
2619 /* In some cases, we might not be able to remove a breakpoint
2620 in a shared library that has already been removed, but we
2621 have not yet processed the shlib unload event. */
2622 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2627 bl
->inserted
= (is
== mark_inserted
);
2629 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2631 gdb_assert (bl
->owner
->ops
!= NULL
2632 && bl
->owner
->ops
->remove_location
!= NULL
);
2634 bl
->inserted
= (is
== mark_inserted
);
2635 bl
->owner
->ops
->remove_location (bl
);
2637 /* Failure to remove any of the hardware watchpoints comes here. */
2638 if ((is
== mark_uninserted
) && (bl
->inserted
))
2639 warning (_("Could not remove hardware watchpoint %d."),
2642 else if (bl
->owner
->type
== bp_catchpoint
2643 && breakpoint_enabled (bl
->owner
)
2646 gdb_assert (bl
->owner
->ops
!= NULL
2647 && bl
->owner
->ops
->remove_location
!= NULL
);
2649 val
= bl
->owner
->ops
->remove_location (bl
);
2653 bl
->inserted
= (is
== mark_inserted
);
2660 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2663 struct cleanup
*old_chain
;
2665 /* BL is never in moribund_locations by our callers. */
2666 gdb_assert (bl
->owner
!= NULL
);
2668 if (bl
->owner
->enable_state
== bp_permanent
)
2669 /* Permanent breakpoints cannot be inserted or removed. */
2672 /* The type of none suggests that owner is actually deleted.
2673 This should not ever happen. */
2674 gdb_assert (bl
->owner
->type
!= bp_none
);
2676 old_chain
= save_current_space_and_thread ();
2678 switch_to_program_space_and_thread (bl
->pspace
);
2680 ret
= remove_breakpoint_1 (bl
, is
);
2682 do_cleanups (old_chain
);
2686 /* Clear the "inserted" flag in all breakpoints. */
2689 mark_breakpoints_out (void)
2691 struct bp_location
*bl
, **blp_tmp
;
2693 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2694 if (bl
->pspace
== current_program_space
)
2698 /* Clear the "inserted" flag in all breakpoints and delete any
2699 breakpoints which should go away between runs of the program.
2701 Plus other such housekeeping that has to be done for breakpoints
2704 Note: this function gets called at the end of a run (by
2705 generic_mourn_inferior) and when a run begins (by
2706 init_wait_for_inferior). */
2711 breakpoint_init_inferior (enum inf_context context
)
2713 struct breakpoint
*b
, *b_tmp
;
2714 struct bp_location
*bl
, **blp_tmp
;
2716 struct program_space
*pspace
= current_program_space
;
2718 /* If breakpoint locations are shared across processes, then there's
2720 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2723 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2725 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2726 if (bl
->pspace
== pspace
2727 && bl
->owner
->enable_state
!= bp_permanent
)
2731 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2733 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2740 /* If the call dummy breakpoint is at the entry point it will
2741 cause problems when the inferior is rerun, so we better get
2744 case bp_watchpoint_scope
:
2746 /* Also get rid of scope breakpoints. */
2748 case bp_shlib_event
:
2750 /* Also remove solib event breakpoints. Their addresses may
2751 have changed since the last time we ran the program.
2752 Actually we may now be debugging against different target;
2753 and so the solib backend that installed this breakpoint may
2754 not be used in by the target. E.g.,
2756 (gdb) file prog-linux
2757 (gdb) run # native linux target
2760 (gdb) file prog-win.exe
2761 (gdb) tar rem :9999 # remote Windows gdbserver.
2764 delete_breakpoint (b
);
2768 case bp_hardware_watchpoint
:
2769 case bp_read_watchpoint
:
2770 case bp_access_watchpoint
:
2772 /* Likewise for watchpoints on local expressions. */
2773 if (b
->exp_valid_block
!= NULL
)
2774 delete_breakpoint (b
);
2775 else if (context
== inf_starting
)
2777 /* Reset val field to force reread of starting value in
2778 insert_breakpoints. */
2780 value_free (b
->val
);
2790 /* Get rid of the moribund locations. */
2791 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2792 decref_bp_location (&bl
);
2793 VEC_free (bp_location_p
, moribund_locations
);
2796 /* These functions concern about actual breakpoints inserted in the
2797 target --- to e.g. check if we need to do decr_pc adjustment or if
2798 we need to hop over the bkpt --- so we check for address space
2799 match, not program space. */
2801 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2802 exists at PC. It returns ordinary_breakpoint_here if it's an
2803 ordinary breakpoint, or permanent_breakpoint_here if it's a
2804 permanent breakpoint.
2805 - When continuing from a location with an ordinary breakpoint, we
2806 actually single step once before calling insert_breakpoints.
2807 - When continuing from a localion with a permanent breakpoint, we
2808 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2809 the target, to advance the PC past the breakpoint. */
2811 enum breakpoint_here
2812 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2814 struct bp_location
*bl
, **blp_tmp
;
2815 int any_breakpoint_here
= 0;
2817 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2819 if (bl
->loc_type
!= bp_loc_software_breakpoint
2820 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2823 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2824 if ((breakpoint_enabled (bl
->owner
)
2825 || bl
->owner
->enable_state
== bp_permanent
)
2826 && breakpoint_location_address_match (bl
, aspace
, pc
))
2828 if (overlay_debugging
2829 && section_is_overlay (bl
->section
)
2830 && !section_is_mapped (bl
->section
))
2831 continue; /* unmapped overlay -- can't be a match */
2832 else if (bl
->owner
->enable_state
== bp_permanent
)
2833 return permanent_breakpoint_here
;
2835 any_breakpoint_here
= 1;
2839 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2842 /* Return true if there's a moribund breakpoint at PC. */
2845 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2847 struct bp_location
*loc
;
2850 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2851 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2857 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2858 inserted using regular breakpoint_chain / bp_location array
2859 mechanism. This does not check for single-step breakpoints, which
2860 are inserted and removed using direct target manipulation. */
2863 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2866 struct bp_location
*bl
, **blp_tmp
;
2868 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2870 if (bl
->loc_type
!= bp_loc_software_breakpoint
2871 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2875 && breakpoint_location_address_match (bl
, aspace
, pc
))
2877 if (overlay_debugging
2878 && section_is_overlay (bl
->section
)
2879 && !section_is_mapped (bl
->section
))
2880 continue; /* unmapped overlay -- can't be a match */
2888 /* Returns non-zero iff there's either regular breakpoint
2889 or a single step breakpoint inserted at PC. */
2892 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2894 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2897 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2903 /* This function returns non-zero iff there is a software breakpoint
2907 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2910 struct bp_location
*bl
, **blp_tmp
;
2912 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2914 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2918 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2921 if (overlay_debugging
2922 && section_is_overlay (bl
->section
)
2923 && !section_is_mapped (bl
->section
))
2924 continue; /* unmapped overlay -- can't be a match */
2930 /* Also check for software single-step breakpoints. */
2931 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2938 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2939 CORE_ADDR addr
, ULONGEST len
)
2941 struct breakpoint
*bpt
;
2943 ALL_BREAKPOINTS (bpt
)
2945 struct bp_location
*loc
;
2947 if (bpt
->type
!= bp_hardware_watchpoint
2948 && bpt
->type
!= bp_access_watchpoint
)
2951 if (!breakpoint_enabled (bpt
))
2954 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2955 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2959 /* Check for intersection. */
2960 l
= max (loc
->address
, addr
);
2961 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2969 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2970 PC is valid for process/thread PTID. */
2973 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2976 struct bp_location
*bl
, **blp_tmp
;
2977 /* The thread and task IDs associated to PTID, computed lazily. */
2981 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2983 if (bl
->loc_type
!= bp_loc_software_breakpoint
2984 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2987 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2988 if (!breakpoint_enabled (bl
->owner
)
2989 && bl
->owner
->enable_state
!= bp_permanent
)
2992 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
2995 if (bl
->owner
->thread
!= -1)
2997 /* This is a thread-specific breakpoint. Check that ptid
2998 matches that thread. If thread hasn't been computed yet,
2999 it is now time to do so. */
3001 thread
= pid_to_thread_id (ptid
);
3002 if (bl
->owner
->thread
!= thread
)
3006 if (bl
->owner
->task
!= 0)
3008 /* This is a task-specific breakpoint. Check that ptid
3009 matches that task. If task hasn't been computed yet,
3010 it is now time to do so. */
3012 task
= ada_get_task_number (ptid
);
3013 if (bl
->owner
->task
!= task
)
3017 if (overlay_debugging
3018 && section_is_overlay (bl
->section
)
3019 && !section_is_mapped (bl
->section
))
3020 continue; /* unmapped overlay -- can't be a match */
3029 /* bpstat stuff. External routines' interfaces are documented
3033 ep_is_catchpoint (struct breakpoint
*ep
)
3035 return (ep
->type
== bp_catchpoint
);
3038 /* Frees any storage that is part of a bpstat. Does not walk the
3042 bpstat_free (bpstat bs
)
3044 if (bs
->old_val
!= NULL
)
3045 value_free (bs
->old_val
);
3046 decref_counted_command_line (&bs
->commands
);
3047 decref_bp_location (&bs
->bp_location_at
);
3051 /* Clear a bpstat so that it says we are not at any breakpoint.
3052 Also free any storage that is part of a bpstat. */
3055 bpstat_clear (bpstat
*bsp
)
3072 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3073 is part of the bpstat is copied as well. */
3076 bpstat_copy (bpstat bs
)
3080 bpstat retval
= NULL
;
3085 for (; bs
!= NULL
; bs
= bs
->next
)
3087 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3088 memcpy (tmp
, bs
, sizeof (*tmp
));
3089 incref_counted_command_line (tmp
->commands
);
3090 incref_bp_location (tmp
->bp_location_at
);
3091 if (bs
->old_val
!= NULL
)
3093 tmp
->old_val
= value_copy (bs
->old_val
);
3094 release_value (tmp
->old_val
);
3098 /* This is the first thing in the chain. */
3108 /* Find the bpstat associated with this breakpoint. */
3111 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3116 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3118 if (bsp
->breakpoint_at
== breakpoint
)
3124 /* Put in *NUM the breakpoint number of the first breakpoint we are
3125 stopped at. *BSP upon return is a bpstat which points to the
3126 remaining breakpoints stopped at (but which is not guaranteed to be
3127 good for anything but further calls to bpstat_num).
3129 Return 0 if passed a bpstat which does not indicate any breakpoints.
3130 Return -1 if stopped at a breakpoint that has been deleted since
3132 Return 1 otherwise. */
3135 bpstat_num (bpstat
*bsp
, int *num
)
3137 struct breakpoint
*b
;
3140 return 0; /* No more breakpoint values */
3142 /* We assume we'll never have several bpstats that correspond to a
3143 single breakpoint -- otherwise, this function might return the
3144 same number more than once and this will look ugly. */
3145 b
= (*bsp
)->breakpoint_at
;
3146 *bsp
= (*bsp
)->next
;
3148 return -1; /* breakpoint that's been deleted since */
3150 *num
= b
->number
; /* We have its number */
3154 /* Modify BS so that the actions will not be performed. */
3157 bpstat_clear_actions (bpstat bs
)
3159 for (; bs
!= NULL
; bs
= bs
->next
)
3161 decref_counted_command_line (&bs
->commands
);
3162 bs
->commands_left
= NULL
;
3163 if (bs
->old_val
!= NULL
)
3165 value_free (bs
->old_val
);
3171 /* Called when a command is about to proceed the inferior. */
3174 breakpoint_about_to_proceed (void)
3176 if (!ptid_equal (inferior_ptid
, null_ptid
))
3178 struct thread_info
*tp
= inferior_thread ();
3180 /* Allow inferior function calls in breakpoint commands to not
3181 interrupt the command list. When the call finishes
3182 successfully, the inferior will be standing at the same
3183 breakpoint as if nothing happened. */
3184 if (tp
->control
.in_infcall
)
3188 breakpoint_proceeded
= 1;
3191 /* Stub for cleaning up our state if we error-out of a breakpoint
3194 cleanup_executing_breakpoints (void *ignore
)
3196 executing_breakpoint_commands
= 0;
3199 /* Execute all the commands associated with all the breakpoints at
3200 this location. Any of these commands could cause the process to
3201 proceed beyond this point, etc. We look out for such changes by
3202 checking the global "breakpoint_proceeded" after each command.
3204 Returns true if a breakpoint command resumed the inferior. In that
3205 case, it is the caller's responsibility to recall it again with the
3206 bpstat of the current thread. */
3209 bpstat_do_actions_1 (bpstat
*bsp
)
3212 struct cleanup
*old_chain
;
3215 /* Avoid endless recursion if a `source' command is contained
3217 if (executing_breakpoint_commands
)
3220 executing_breakpoint_commands
= 1;
3221 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3223 /* This pointer will iterate over the list of bpstat's. */
3226 breakpoint_proceeded
= 0;
3227 for (; bs
!= NULL
; bs
= bs
->next
)
3229 struct counted_command_line
*ccmd
;
3230 struct command_line
*cmd
;
3231 struct cleanup
*this_cmd_tree_chain
;
3233 /* Take ownership of the BSP's command tree, if it has one.
3235 The command tree could legitimately contain commands like
3236 'step' and 'next', which call clear_proceed_status, which
3237 frees stop_bpstat's command tree. To make sure this doesn't
3238 free the tree we're executing out from under us, we need to
3239 take ownership of the tree ourselves. Since a given bpstat's
3240 commands are only executed once, we don't need to copy it; we
3241 can clear the pointer in the bpstat, and make sure we free
3242 the tree when we're done. */
3243 ccmd
= bs
->commands
;
3244 bs
->commands
= NULL
;
3246 = make_cleanup_decref_counted_command_line (&ccmd
);
3247 cmd
= bs
->commands_left
;
3248 bs
->commands_left
= NULL
;
3252 execute_control_command (cmd
);
3254 if (breakpoint_proceeded
)
3260 /* We can free this command tree now. */
3261 do_cleanups (this_cmd_tree_chain
);
3263 if (breakpoint_proceeded
)
3265 if (target_can_async_p ())
3266 /* If we are in async mode, then the target might be still
3267 running, not stopped at any breakpoint, so nothing for
3268 us to do here -- just return to the event loop. */
3271 /* In sync mode, when execute_control_command returns
3272 we're already standing on the next breakpoint.
3273 Breakpoint commands for that stop were not run, since
3274 execute_command does not run breakpoint commands --
3275 only command_line_handler does, but that one is not
3276 involved in execution of breakpoint commands. So, we
3277 can now execute breakpoint commands. It should be
3278 noted that making execute_command do bpstat actions is
3279 not an option -- in this case we'll have recursive
3280 invocation of bpstat for each breakpoint with a
3281 command, and can easily blow up GDB stack. Instead, we
3282 return true, which will trigger the caller to recall us
3283 with the new stop_bpstat. */
3288 do_cleanups (old_chain
);
3293 bpstat_do_actions (void)
3295 /* Do any commands attached to breakpoint we are stopped at. */
3296 while (!ptid_equal (inferior_ptid
, null_ptid
)
3297 && target_has_execution
3298 && !is_exited (inferior_ptid
)
3299 && !is_executing (inferior_ptid
))
3300 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3301 and only return when it is stopped at the next breakpoint, we
3302 keep doing breakpoint actions until it returns false to
3303 indicate the inferior was not resumed. */
3304 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3308 /* Print out the (old or new) value associated with a watchpoint. */
3311 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3314 fprintf_unfiltered (stream
, _("<unreadable>"));
3317 struct value_print_options opts
;
3318 get_user_print_options (&opts
);
3319 value_print (val
, stream
, &opts
);
3323 /* This is the normal print function for a bpstat. In the future,
3324 much of this logic could (should?) be moved to bpstat_stop_status,
3325 by having it set different print_it values.
3327 Current scheme: When we stop, bpstat_print() is called. It loops
3328 through the bpstat list of things causing this stop, calling the
3329 print_bp_stop_message function on each one. The behavior of the
3330 print_bp_stop_message function depends on the print_it field of
3331 bpstat. If such field so indicates, call this function here.
3333 Return values from this routine (ultimately used by bpstat_print()
3334 and normal_stop() to decide what to do):
3335 PRINT_NOTHING: Means we already printed all we needed to print,
3336 don't print anything else.
3337 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3338 that something to be followed by a location.
3339 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3340 that something to be followed by a location.
3341 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3344 static enum print_stop_action
3345 print_it_typical (bpstat bs
)
3347 struct cleanup
*old_chain
;
3348 struct breakpoint
*b
;
3349 const struct bp_location
*bl
;
3350 struct ui_stream
*stb
;
3352 enum print_stop_action result
;
3354 gdb_assert (bs
->bp_location_at
!= NULL
);
3356 bl
= bs
->bp_location_at
;
3357 b
= bs
->breakpoint_at
;
3359 stb
= ui_out_stream_new (uiout
);
3360 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3365 case bp_hardware_breakpoint
:
3366 bp_temp
= b
->disposition
== disp_del
;
3367 if (bl
->address
!= bl
->requested_address
)
3368 breakpoint_adjustment_warning (bl
->requested_address
,
3371 annotate_breakpoint (b
->number
);
3373 ui_out_text (uiout
, "\nTemporary breakpoint ");
3375 ui_out_text (uiout
, "\nBreakpoint ");
3376 if (ui_out_is_mi_like_p (uiout
))
3378 ui_out_field_string (uiout
, "reason",
3379 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3380 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3382 ui_out_field_int (uiout
, "bkptno", b
->number
);
3383 ui_out_text (uiout
, ", ");
3384 result
= PRINT_SRC_AND_LOC
;
3387 case bp_shlib_event
:
3388 /* Did we stop because the user set the stop_on_solib_events
3389 variable? (If so, we report this as a generic, "Stopped due
3390 to shlib event" message.) */
3391 printf_filtered (_("Stopped due to shared library event\n"));
3392 result
= PRINT_NOTHING
;
3395 case bp_thread_event
:
3396 /* Not sure how we will get here.
3397 GDB should not stop for these breakpoints. */
3398 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3399 result
= PRINT_NOTHING
;
3402 case bp_overlay_event
:
3403 /* By analogy with the thread event, GDB should not stop for these. */
3404 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3405 result
= PRINT_NOTHING
;
3408 case bp_longjmp_master
:
3409 /* These should never be enabled. */
3410 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3411 result
= PRINT_NOTHING
;
3414 case bp_std_terminate_master
:
3415 /* These should never be enabled. */
3416 printf_filtered (_("std::terminate Master Breakpoint: "
3417 "gdb should not stop!\n"));
3418 result
= PRINT_NOTHING
;
3421 case bp_exception_master
:
3422 /* These should never be enabled. */
3423 printf_filtered (_("Exception Master Breakpoint: "
3424 "gdb should not stop!\n"));
3425 result
= PRINT_NOTHING
;
3429 case bp_hardware_watchpoint
:
3430 annotate_watchpoint (b
->number
);
3431 if (ui_out_is_mi_like_p (uiout
))
3434 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3436 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3437 ui_out_text (uiout
, "\nOld value = ");
3438 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3439 ui_out_field_stream (uiout
, "old", stb
);
3440 ui_out_text (uiout
, "\nNew value = ");
3441 watchpoint_value_print (b
->val
, stb
->stream
);
3442 ui_out_field_stream (uiout
, "new", stb
);
3443 ui_out_text (uiout
, "\n");
3444 /* More than one watchpoint may have been triggered. */
3445 result
= PRINT_UNKNOWN
;
3448 case bp_read_watchpoint
:
3449 if (ui_out_is_mi_like_p (uiout
))
3452 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3454 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3455 ui_out_text (uiout
, "\nValue = ");
3456 watchpoint_value_print (b
->val
, stb
->stream
);
3457 ui_out_field_stream (uiout
, "value", stb
);
3458 ui_out_text (uiout
, "\n");
3459 result
= PRINT_UNKNOWN
;
3462 case bp_access_watchpoint
:
3463 if (bs
->old_val
!= NULL
)
3465 annotate_watchpoint (b
->number
);
3466 if (ui_out_is_mi_like_p (uiout
))
3469 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3471 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3472 ui_out_text (uiout
, "\nOld value = ");
3473 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3474 ui_out_field_stream (uiout
, "old", stb
);
3475 ui_out_text (uiout
, "\nNew value = ");
3480 if (ui_out_is_mi_like_p (uiout
))
3483 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3484 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3485 ui_out_text (uiout
, "\nValue = ");
3487 watchpoint_value_print (b
->val
, stb
->stream
);
3488 ui_out_field_stream (uiout
, "new", stb
);
3489 ui_out_text (uiout
, "\n");
3490 result
= PRINT_UNKNOWN
;
3493 /* Fall through, we don't deal with these types of breakpoints
3497 if (ui_out_is_mi_like_p (uiout
))
3500 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3501 result
= PRINT_UNKNOWN
;
3505 if (ui_out_is_mi_like_p (uiout
))
3508 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3509 result
= PRINT_UNKNOWN
;
3514 case bp_longjmp_resume
:
3516 case bp_exception_resume
:
3517 case bp_step_resume
:
3518 case bp_watchpoint_scope
:
3520 case bp_std_terminate
:
3522 case bp_fast_tracepoint
:
3524 case bp_gnu_ifunc_resolver
:
3525 case bp_gnu_ifunc_resolver_return
:
3527 result
= PRINT_UNKNOWN
;
3531 do_cleanups (old_chain
);
3535 /* Generic routine for printing messages indicating why we
3536 stopped. The behavior of this function depends on the value
3537 'print_it' in the bpstat structure. Under some circumstances we
3538 may decide not to print anything here and delegate the task to
3541 static enum print_stop_action
3542 print_bp_stop_message (bpstat bs
)
3544 switch (bs
->print_it
)
3547 /* Nothing should be printed for this bpstat entry. */
3548 return PRINT_UNKNOWN
;
3552 /* We still want to print the frame, but we already printed the
3553 relevant messages. */
3554 return PRINT_SRC_AND_LOC
;
3557 case print_it_normal
:
3559 struct breakpoint
*b
= bs
->breakpoint_at
;
3561 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3562 which has since been deleted. */
3564 return PRINT_UNKNOWN
;
3566 /* Normal case. Call the breakpoint's print_it method, or
3567 print_it_typical. */
3568 if (b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3569 return b
->ops
->print_it (b
);
3571 return print_it_typical (bs
);
3576 internal_error (__FILE__
, __LINE__
,
3577 _("print_bp_stop_message: unrecognized enum value"));
3582 /* Print a message indicating what happened. This is called from
3583 normal_stop(). The input to this routine is the head of the bpstat
3584 list - a list of the eventpoints that caused this stop. This
3585 routine calls the generic print routine for printing a message
3586 about reasons for stopping. This will print (for example) the
3587 "Breakpoint n," part of the output. The return value of this
3590 PRINT_UNKNOWN: Means we printed nothing.
3591 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3592 code to print the location. An example is
3593 "Breakpoint 1, " which should be followed by
3595 PRINT_SRC_ONLY: Means we printed something, but there is no need
3596 to also print the location part of the message.
3597 An example is the catch/throw messages, which
3598 don't require a location appended to the end.
3599 PRINT_NOTHING: We have done some printing and we don't need any
3600 further info to be printed. */
3602 enum print_stop_action
3603 bpstat_print (bpstat bs
)
3607 /* Maybe another breakpoint in the chain caused us to stop.
3608 (Currently all watchpoints go on the bpstat whether hit or not.
3609 That probably could (should) be changed, provided care is taken
3610 with respect to bpstat_explains_signal). */
3611 for (; bs
; bs
= bs
->next
)
3613 val
= print_bp_stop_message (bs
);
3614 if (val
== PRINT_SRC_ONLY
3615 || val
== PRINT_SRC_AND_LOC
3616 || val
== PRINT_NOTHING
)
3620 /* We reached the end of the chain, or we got a null BS to start
3621 with and nothing was printed. */
3622 return PRINT_UNKNOWN
;
3625 /* Evaluate the expression EXP and return 1 if value is zero. This is
3626 used inside a catch_errors to evaluate the breakpoint condition.
3627 The argument is a "struct expression *" that has been cast to a
3628 "char *" to make it pass through catch_errors. */
3631 breakpoint_cond_eval (void *exp
)
3633 struct value
*mark
= value_mark ();
3634 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3636 value_free_to_mark (mark
);
3640 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3643 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3647 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3649 **bs_link_pointer
= bs
;
3650 *bs_link_pointer
= &bs
->next
;
3651 bs
->breakpoint_at
= bl
->owner
;
3652 bs
->bp_location_at
= bl
;
3653 incref_bp_location (bl
);
3654 /* If the condition is false, etc., don't do the commands. */
3655 bs
->commands
= NULL
;
3656 bs
->commands_left
= NULL
;
3658 bs
->print_it
= print_it_normal
;
3662 /* The target has stopped with waitstatus WS. Check if any hardware
3663 watchpoints have triggered, according to the target. */
3666 watchpoints_triggered (struct target_waitstatus
*ws
)
3668 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3670 struct breakpoint
*b
;
3672 if (!stopped_by_watchpoint
)
3674 /* We were not stopped by a watchpoint. Mark all watchpoints
3675 as not triggered. */
3677 if (is_hardware_watchpoint (b
))
3678 b
->watchpoint_triggered
= watch_triggered_no
;
3683 if (!target_stopped_data_address (¤t_target
, &addr
))
3685 /* We were stopped by a watchpoint, but we don't know where.
3686 Mark all watchpoints as unknown. */
3688 if (is_hardware_watchpoint (b
))
3689 b
->watchpoint_triggered
= watch_triggered_unknown
;
3691 return stopped_by_watchpoint
;
3694 /* The target could report the data address. Mark watchpoints
3695 affected by this data address as triggered, and all others as not
3699 if (is_hardware_watchpoint (b
))
3701 struct bp_location
*loc
;
3703 b
->watchpoint_triggered
= watch_triggered_no
;
3704 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3706 if (is_masked_watchpoint (loc
->owner
))
3708 CORE_ADDR newaddr
= addr
& loc
->owner
->hw_wp_mask
;
3709 CORE_ADDR start
= loc
->address
& loc
->owner
->hw_wp_mask
;
3711 if (newaddr
== start
)
3713 b
->watchpoint_triggered
= watch_triggered_yes
;
3717 /* Exact match not required. Within range is sufficient. */
3718 else if (target_watchpoint_addr_within_range (¤t_target
,
3722 b
->watchpoint_triggered
= watch_triggered_yes
;
3731 /* Possible return values for watchpoint_check (this can't be an enum
3732 because of check_errors). */
3733 /* The watchpoint has been deleted. */
3734 #define WP_DELETED 1
3735 /* The value has changed. */
3736 #define WP_VALUE_CHANGED 2
3737 /* The value has not changed. */
3738 #define WP_VALUE_NOT_CHANGED 3
3739 /* Ignore this watchpoint, no matter if the value changed or not. */
3742 #define BP_TEMPFLAG 1
3743 #define BP_HARDWAREFLAG 2
3745 /* Evaluate watchpoint condition expression and check if its value
3748 P should be a pointer to struct bpstat, but is defined as a void *
3749 in order for this function to be usable with catch_errors. */
3752 watchpoint_check (void *p
)
3754 bpstat bs
= (bpstat
) p
;
3755 struct breakpoint
*b
;
3756 struct frame_info
*fr
;
3757 int within_current_scope
;
3759 /* BS is built from an existing struct breakpoint. */
3760 gdb_assert (bs
->breakpoint_at
!= NULL
);
3761 b
= bs
->breakpoint_at
;
3763 gdb_assert (is_watchpoint (b
));
3765 /* If this is a local watchpoint, we only want to check if the
3766 watchpoint frame is in scope if the current thread is the thread
3767 that was used to create the watchpoint. */
3768 if (!watchpoint_in_thread_scope (b
))
3771 if (b
->exp_valid_block
== NULL
)
3772 within_current_scope
= 1;
3775 struct frame_info
*frame
= get_current_frame ();
3776 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3777 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3779 /* in_function_epilogue_p() returns a non-zero value if we're
3780 still in the function but the stack frame has already been
3781 invalidated. Since we can't rely on the values of local
3782 variables after the stack has been destroyed, we are treating
3783 the watchpoint in that state as `not changed' without further
3784 checking. Don't mark watchpoints as changed if the current
3785 frame is in an epilogue - even if they are in some other
3786 frame, our view of the stack is likely to be wrong and
3787 frame_find_by_id could error out. */
3788 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3791 fr
= frame_find_by_id (b
->watchpoint_frame
);
3792 within_current_scope
= (fr
!= NULL
);
3794 /* If we've gotten confused in the unwinder, we might have
3795 returned a frame that can't describe this variable. */
3796 if (within_current_scope
)
3798 struct symbol
*function
;
3800 function
= get_frame_function (fr
);
3801 if (function
== NULL
3802 || !contained_in (b
->exp_valid_block
,
3803 SYMBOL_BLOCK_VALUE (function
)))
3804 within_current_scope
= 0;
3807 if (within_current_scope
)
3808 /* If we end up stopping, the current frame will get selected
3809 in normal_stop. So this call to select_frame won't affect
3814 if (within_current_scope
)
3816 /* We use value_{,free_to_}mark because it could be a *long*
3817 time before we return to the command level and call
3818 free_all_values. We can't call free_all_values because we
3819 might be in the middle of evaluating a function call. */
3823 struct value
*new_val
;
3825 if (is_masked_watchpoint (b
))
3826 /* Since we don't know the exact trigger address (from
3827 stopped_data_address), just tell the user we've triggered
3828 a mask watchpoint. */
3829 return WP_VALUE_CHANGED
;
3831 mark
= value_mark ();
3832 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3834 /* We use value_equal_contents instead of value_equal because
3835 the latter coerces an array to a pointer, thus comparing just
3836 the address of the array instead of its contents. This is
3837 not what we want. */
3838 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3839 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3841 if (new_val
!= NULL
)
3843 release_value (new_val
);
3844 value_free_to_mark (mark
);
3846 bs
->old_val
= b
->val
;
3849 return WP_VALUE_CHANGED
;
3853 /* Nothing changed. */
3854 value_free_to_mark (mark
);
3855 return WP_VALUE_NOT_CHANGED
;
3860 /* This seems like the only logical thing to do because
3861 if we temporarily ignored the watchpoint, then when
3862 we reenter the block in which it is valid it contains
3863 garbage (in the case of a function, it may have two
3864 garbage values, one before and one after the prologue).
3865 So we can't even detect the first assignment to it and
3866 watch after that (since the garbage may or may not equal
3867 the first value assigned). */
3868 /* We print all the stop information in print_it_typical(), but
3869 in this case, by the time we call print_it_typical() this bp
3870 will be deleted already. So we have no choice but print the
3871 information here. */
3872 if (ui_out_is_mi_like_p (uiout
))
3874 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3875 ui_out_text (uiout
, "\nWatchpoint ");
3876 ui_out_field_int (uiout
, "wpnum", b
->number
);
3878 " deleted because the program has left the block in\n\
3879 which its expression is valid.\n");
3881 watchpoint_del_at_next_stop (b
);
3887 /* Return true if it looks like target has stopped due to hitting
3888 breakpoint location BL. This function does not check if we
3889 should stop, only if BL explains the stop. */
3891 bpstat_check_location (const struct bp_location
*bl
,
3892 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3894 struct breakpoint
*b
= bl
->owner
;
3896 /* BL is from existing struct breakpoint. */
3897 gdb_assert (b
!= NULL
);
3899 if (b
->ops
&& b
->ops
->breakpoint_hit
)
3900 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3902 /* By definition, the inferior does not report stops at
3904 if (is_tracepoint (b
))
3907 if (!is_watchpoint (b
)
3908 && b
->type
!= bp_hardware_breakpoint
3909 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3911 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3914 if (overlay_debugging
/* unmapped overlay section */
3915 && section_is_overlay (bl
->section
)
3916 && !section_is_mapped (bl
->section
))
3920 /* Continuable hardware watchpoints are treated as non-existent if the
3921 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3922 some data address). Otherwise gdb won't stop on a break instruction
3923 in the code (not from a breakpoint) when a hardware watchpoint has
3924 been defined. Also skip watchpoints which we know did not trigger
3925 (did not match the data address). */
3927 if (is_hardware_watchpoint (b
)
3928 && b
->watchpoint_triggered
== watch_triggered_no
)
3931 if (b
->type
== bp_hardware_breakpoint
)
3933 if (bl
->address
!= bp_addr
)
3935 if (overlay_debugging
/* unmapped overlay section */
3936 && section_is_overlay (bl
->section
)
3937 && !section_is_mapped (bl
->section
))
3944 /* If BS refers to a watchpoint, determine if the watched values
3945 has actually changed, and we should stop. If not, set BS->stop
3948 bpstat_check_watchpoint (bpstat bs
)
3950 const struct bp_location
*bl
;
3951 struct breakpoint
*b
;
3953 /* BS is built for existing struct breakpoint. */
3954 bl
= bs
->bp_location_at
;
3955 gdb_assert (bl
!= NULL
);
3956 b
= bs
->breakpoint_at
;
3957 gdb_assert (b
!= NULL
);
3959 if (is_watchpoint (b
))
3961 int must_check_value
= 0;
3963 if (b
->type
== bp_watchpoint
)
3964 /* For a software watchpoint, we must always check the
3966 must_check_value
= 1;
3967 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3968 /* We have a hardware watchpoint (read, write, or access)
3969 and the target earlier reported an address watched by
3971 must_check_value
= 1;
3972 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3973 && b
->type
== bp_hardware_watchpoint
)
3974 /* We were stopped by a hardware watchpoint, but the target could
3975 not report the data address. We must check the watchpoint's
3976 value. Access and read watchpoints are out of luck; without
3977 a data address, we can't figure it out. */
3978 must_check_value
= 1;
3980 if (must_check_value
)
3983 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3985 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3986 int e
= catch_errors (watchpoint_check
, bs
, message
,
3988 do_cleanups (cleanups
);
3992 /* We've already printed what needs to be printed. */
3993 bs
->print_it
= print_it_done
;
3997 bs
->print_it
= print_it_noop
;
4000 case WP_VALUE_CHANGED
:
4001 if (b
->type
== bp_read_watchpoint
)
4003 /* There are two cases to consider here:
4005 1. We're watching the triggered memory for reads.
4006 In that case, trust the target, and always report
4007 the watchpoint hit to the user. Even though
4008 reads don't cause value changes, the value may
4009 have changed since the last time it was read, and
4010 since we're not trapping writes, we will not see
4011 those, and as such we should ignore our notion of
4014 2. We're watching the triggered memory for both
4015 reads and writes. There are two ways this may
4018 2.1. This is a target that can't break on data
4019 reads only, but can break on accesses (reads or
4020 writes), such as e.g., x86. We detect this case
4021 at the time we try to insert read watchpoints.
4023 2.2. Otherwise, the target supports read
4024 watchpoints, but, the user set an access or write
4025 watchpoint watching the same memory as this read
4028 If we're watching memory writes as well as reads,
4029 ignore watchpoint hits when we find that the
4030 value hasn't changed, as reads don't cause
4031 changes. This still gives false positives when
4032 the program writes the same value to memory as
4033 what there was already in memory (we will confuse
4034 it for a read), but it's much better than
4037 int other_write_watchpoint
= 0;
4039 if (bl
->watchpoint_type
== hw_read
)
4041 struct breakpoint
*other_b
;
4043 ALL_BREAKPOINTS (other_b
)
4044 if ((other_b
->type
== bp_hardware_watchpoint
4045 || other_b
->type
== bp_access_watchpoint
)
4046 && (other_b
->watchpoint_triggered
4047 == watch_triggered_yes
))
4049 other_write_watchpoint
= 1;
4054 if (other_write_watchpoint
4055 || bl
->watchpoint_type
== hw_access
)
4057 /* We're watching the same memory for writes,
4058 and the value changed since the last time we
4059 updated it, so this trap must be for a write.
4061 bs
->print_it
= print_it_noop
;
4066 case WP_VALUE_NOT_CHANGED
:
4067 if (b
->type
== bp_hardware_watchpoint
4068 || b
->type
== bp_watchpoint
)
4070 /* Don't stop: write watchpoints shouldn't fire if
4071 the value hasn't changed. */
4072 bs
->print_it
= print_it_noop
;
4080 /* Error from catch_errors. */
4081 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
4082 watchpoint_del_at_next_stop (b
);
4083 /* We've already printed what needs to be printed. */
4084 bs
->print_it
= print_it_done
;
4088 else /* must_check_value == 0 */
4090 /* This is a case where some watchpoint(s) triggered, but
4091 not at the address of this watchpoint, or else no
4092 watchpoint triggered after all. So don't print
4093 anything for this watchpoint. */
4094 bs
->print_it
= print_it_noop
;
4101 /* Check conditions (condition proper, frame, thread and ignore count)
4102 of breakpoint referred to by BS. If we should not stop for this
4103 breakpoint, set BS->stop to 0. */
4106 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4108 int thread_id
= pid_to_thread_id (ptid
);
4109 const struct bp_location
*bl
;
4110 struct breakpoint
*b
;
4112 /* BS is built for existing struct breakpoint. */
4113 bl
= bs
->bp_location_at
;
4114 gdb_assert (bl
!= NULL
);
4115 b
= bs
->breakpoint_at
;
4116 gdb_assert (b
!= NULL
);
4118 if (frame_id_p (b
->frame_id
)
4119 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4123 int value_is_zero
= 0;
4124 struct expression
*cond
;
4126 /* Evaluate Python breakpoints that have a "stop"
4127 method implemented. */
4128 if (b
->py_bp_object
)
4129 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4131 if (is_watchpoint (b
))
4136 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4138 int within_current_scope
= 1;
4140 /* We use value_mark and value_free_to_mark because it could
4141 be a long time before we return to the command level and
4142 call free_all_values. We can't call free_all_values
4143 because we might be in the middle of evaluating a
4145 struct value
*mark
= value_mark ();
4147 /* Need to select the frame, with all that implies so that
4148 the conditions will have the right context. Because we
4149 use the frame, we will not see an inlined function's
4150 variables when we arrive at a breakpoint at the start
4151 of the inlined function; the current frame will be the
4153 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4154 select_frame (get_current_frame ());
4157 struct frame_info
*frame
;
4159 /* For local watchpoint expressions, which particular
4160 instance of a local is being watched matters, so we
4161 keep track of the frame to evaluate the expression
4162 in. To evaluate the condition however, it doesn't
4163 really matter which instantiation of the function
4164 where the condition makes sense triggers the
4165 watchpoint. This allows an expression like "watch
4166 global if q > 10" set in `func', catch writes to
4167 global on all threads that call `func', or catch
4168 writes on all recursive calls of `func' by a single
4169 thread. We simply always evaluate the condition in
4170 the innermost frame that's executing where it makes
4171 sense to evaluate the condition. It seems
4173 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4175 select_frame (frame
);
4177 within_current_scope
= 0;
4179 if (within_current_scope
)
4181 = catch_errors (breakpoint_cond_eval
, cond
,
4182 "Error in testing breakpoint condition:\n",
4186 warning (_("Watchpoint condition cannot be tested "
4187 "in the current scope"));
4188 /* If we failed to set the right context for this
4189 watchpoint, unconditionally report it. */
4192 /* FIXME-someday, should give breakpoint #. */
4193 value_free_to_mark (mark
);
4196 if (cond
&& value_is_zero
)
4200 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4204 else if (b
->ignore_count
> 0)
4207 annotate_ignore_count_change ();
4209 /* Increase the hit count even though we don't stop. */
4211 observer_notify_breakpoint_modified (b
);
4217 /* Get a bpstat associated with having just stopped at address
4218 BP_ADDR in thread PTID.
4220 Determine whether we stopped at a breakpoint, etc, or whether we
4221 don't understand this stop. Result is a chain of bpstat's such
4224 if we don't understand the stop, the result is a null pointer.
4226 if we understand why we stopped, the result is not null.
4228 Each element of the chain refers to a particular breakpoint or
4229 watchpoint at which we have stopped. (We may have stopped for
4230 several reasons concurrently.)
4232 Each element of the chain has valid next, breakpoint_at,
4233 commands, FIXME??? fields. */
4236 bpstat_stop_status (struct address_space
*aspace
,
4237 CORE_ADDR bp_addr
, ptid_t ptid
)
4239 struct breakpoint
*b
= NULL
;
4240 struct bp_location
*bl
;
4241 struct bp_location
*loc
;
4242 /* First item of allocated bpstat's. */
4243 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4244 /* Pointer to the last thing in the chain currently. */
4247 int need_remove_insert
;
4250 /* First, build the bpstat chain with locations that explain a
4251 target stop, while being careful to not set the target running,
4252 as that may invalidate locations (in particular watchpoint
4253 locations are recreated). Resuming will happen here with
4254 breakpoint conditions or watchpoint expressions that include
4255 inferior function calls. */
4259 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4262 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4264 /* For hardware watchpoints, we look only at the first
4265 location. The watchpoint_check function will work on the
4266 entire expression, not the individual locations. For
4267 read watchpoints, the watchpoints_triggered function has
4268 checked all locations already. */
4269 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4272 if (bl
->shlib_disabled
)
4275 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4278 /* Come here if it's a watchpoint, or if the break address
4281 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4284 /* Assume we stop. Should we find a watchpoint that is not
4285 actually triggered, or if the condition of the breakpoint
4286 evaluates as false, we'll reset 'stop' to 0. */
4290 /* If this is a scope breakpoint, mark the associated
4291 watchpoint as triggered so that we will handle the
4292 out-of-scope event. We'll get to the watchpoint next
4294 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4295 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4299 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4301 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4303 bs
= bpstat_alloc (loc
, &bs_link
);
4304 /* For hits of moribund locations, we should just proceed. */
4307 bs
->print_it
= print_it_noop
;
4311 /* Now go through the locations that caused the target to stop, and
4312 check whether we're interested in reporting this stop to higher
4313 layers, or whether we should resume the target transparently. */
4317 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4322 bpstat_check_watchpoint (bs
);
4326 b
= bs
->breakpoint_at
;
4328 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4329 || b
->type
== bp_longjmp_master
4330 || b
->type
== bp_std_terminate_master
4331 || b
->type
== bp_exception_master
)
4332 /* We do not stop for these. */
4335 bpstat_check_breakpoint_conditions (bs
, ptid
);
4340 observer_notify_breakpoint_modified (b
);
4342 /* We will stop here. */
4343 if (b
->disposition
== disp_disable
)
4345 if (b
->enable_state
!= bp_permanent
)
4346 b
->enable_state
= bp_disabled
;
4351 bs
->commands
= b
->commands
;
4352 incref_counted_command_line (bs
->commands
);
4353 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4354 if (bs
->commands_left
4355 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4358 bs
->commands_left
->line
) == 0)))
4360 bs
->commands_left
= bs
->commands_left
->next
;
4365 /* Print nothing for this entry if we dont stop or dont print. */
4366 if (bs
->stop
== 0 || bs
->print
== 0)
4367 bs
->print_it
= print_it_noop
;
4370 /* If we aren't stopping, the value of some hardware watchpoint may
4371 not have changed, but the intermediate memory locations we are
4372 watching may have. Don't bother if we're stopping; this will get
4374 need_remove_insert
= 0;
4375 if (! bpstat_causes_stop (bs_head
))
4376 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4378 && bs
->breakpoint_at
4379 && is_hardware_watchpoint (bs
->breakpoint_at
))
4381 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4382 need_remove_insert
= 1;
4385 if (need_remove_insert
)
4386 update_global_location_list (1);
4387 else if (removed_any
)
4388 update_global_location_list (0);
4394 handle_jit_event (void)
4396 struct frame_info
*frame
;
4397 struct gdbarch
*gdbarch
;
4399 /* Switch terminal for any messages produced by
4400 breakpoint_re_set. */
4401 target_terminal_ours_for_output ();
4403 frame
= get_current_frame ();
4404 gdbarch
= get_frame_arch (frame
);
4406 jit_event_handler (gdbarch
);
4408 target_terminal_inferior ();
4411 /* Prepare WHAT final decision for infrun. */
4413 /* Decide what infrun needs to do with this bpstat. */
4416 bpstat_what (bpstat bs_head
)
4418 struct bpstat_what retval
;
4419 /* We need to defer calling `solib_add', as adding new symbols
4420 resets breakpoints, which in turn deletes breakpoint locations,
4421 and hence may clear unprocessed entries in the BS chain. */
4422 int shlib_event
= 0;
4426 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4427 retval
.call_dummy
= STOP_NONE
;
4428 retval
.is_longjmp
= 0;
4430 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4432 /* Extract this BS's action. After processing each BS, we check
4433 if its action overrides all we've seem so far. */
4434 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4437 if (bs
->breakpoint_at
== NULL
)
4439 /* I suspect this can happen if it was a momentary
4440 breakpoint which has since been deleted. */
4443 else if (bs
->breakpoint_at
== NULL
)
4446 bptype
= bs
->breakpoint_at
->type
;
4453 case bp_hardware_breakpoint
:
4459 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4461 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4464 this_action
= BPSTAT_WHAT_SINGLE
;
4467 case bp_hardware_watchpoint
:
4468 case bp_read_watchpoint
:
4469 case bp_access_watchpoint
:
4473 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4475 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4479 /* There was a watchpoint, but we're not stopping.
4480 This requires no further action. */
4485 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4486 retval
.is_longjmp
= bptype
== bp_longjmp
;
4488 case bp_longjmp_resume
:
4489 case bp_exception_resume
:
4490 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4491 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4493 case bp_step_resume
:
4495 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4498 /* It is for the wrong frame. */
4499 this_action
= BPSTAT_WHAT_SINGLE
;
4502 case bp_watchpoint_scope
:
4503 case bp_thread_event
:
4504 case bp_overlay_event
:
4505 case bp_longjmp_master
:
4506 case bp_std_terminate_master
:
4507 case bp_exception_master
:
4508 this_action
= BPSTAT_WHAT_SINGLE
;
4514 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4516 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4520 /* There was a catchpoint, but we're not stopping.
4521 This requires no further action. */
4524 case bp_shlib_event
:
4527 /* If requested, stop when the dynamic linker notifies GDB
4528 of events. This allows the user to get control and place
4529 breakpoints in initializer routines for dynamically
4530 loaded objects (among other things). */
4531 if (stop_on_solib_events
)
4532 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4534 this_action
= BPSTAT_WHAT_SINGLE
;
4538 this_action
= BPSTAT_WHAT_SINGLE
;
4541 /* Make sure the action is stop (silent or noisy),
4542 so infrun.c pops the dummy frame. */
4543 retval
.call_dummy
= STOP_STACK_DUMMY
;
4544 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4546 case bp_std_terminate
:
4547 /* Make sure the action is stop (silent or noisy),
4548 so infrun.c pops the dummy frame. */
4549 retval
.call_dummy
= STOP_STD_TERMINATE
;
4550 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4553 case bp_fast_tracepoint
:
4554 case bp_static_tracepoint
:
4555 /* Tracepoint hits should not be reported back to GDB, and
4556 if one got through somehow, it should have been filtered
4558 internal_error (__FILE__
, __LINE__
,
4559 _("bpstat_what: tracepoint encountered"));
4561 case bp_gnu_ifunc_resolver
:
4562 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4563 this_action
= BPSTAT_WHAT_SINGLE
;
4565 case bp_gnu_ifunc_resolver_return
:
4566 /* The breakpoint will be removed, execution will restart from the
4567 PC of the former breakpoint. */
4568 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4571 internal_error (__FILE__
, __LINE__
,
4572 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4575 retval
.main_action
= max (retval
.main_action
, this_action
);
4578 /* These operations may affect the bs->breakpoint_at state so they are
4579 delayed after MAIN_ACTION is decided above. */
4584 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4586 /* Check for any newly added shared libraries if we're supposed
4587 to be adding them automatically. */
4589 /* Switch terminal for any messages produced by
4590 breakpoint_re_set. */
4591 target_terminal_ours_for_output ();
4594 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4596 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4599 target_terminal_inferior ();
4605 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4607 handle_jit_event ();
4610 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4612 struct breakpoint
*b
= bs
->breakpoint_at
;
4618 case bp_gnu_ifunc_resolver
:
4619 gnu_ifunc_resolver_stop (b
);
4621 case bp_gnu_ifunc_resolver_return
:
4622 gnu_ifunc_resolver_return_stop (b
);
4630 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4631 without hardware support). This isn't related to a specific bpstat,
4632 just to things like whether watchpoints are set. */
4635 bpstat_should_step (void)
4637 struct breakpoint
*b
;
4640 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4646 bpstat_causes_stop (bpstat bs
)
4648 for (; bs
!= NULL
; bs
= bs
->next
)
4657 /* Compute a string of spaces suitable to indent the next line
4658 so it starts at the position corresponding to the table column
4659 named COL_NAME in the currently active table of UIOUT. */
4662 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4664 static char wrap_indent
[80];
4665 int i
, total_width
, width
, align
;
4669 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4671 if (strcmp (text
, col_name
) == 0)
4673 gdb_assert (total_width
< sizeof wrap_indent
);
4674 memset (wrap_indent
, ' ', total_width
);
4675 wrap_indent
[total_width
] = 0;
4680 total_width
+= width
+ 1;
4686 /* Print the LOC location out of the list of B->LOC locations. */
4689 print_breakpoint_location (struct breakpoint
*b
,
4690 struct bp_location
*loc
)
4692 struct cleanup
*old_chain
= save_current_program_space ();
4694 if (loc
!= NULL
&& loc
->shlib_disabled
)
4698 set_current_program_space (loc
->pspace
);
4700 if (b
->display_canonical
)
4701 ui_out_field_string (uiout
, "what", b
->addr_string
);
4702 else if (b
->source_file
&& loc
)
4705 = find_pc_sect_function (loc
->address
, loc
->section
);
4708 ui_out_text (uiout
, "in ");
4709 ui_out_field_string (uiout
, "func",
4710 SYMBOL_PRINT_NAME (sym
));
4711 ui_out_text (uiout
, " ");
4712 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4713 ui_out_text (uiout
, "at ");
4715 ui_out_field_string (uiout
, "file", b
->source_file
);
4716 ui_out_text (uiout
, ":");
4718 if (ui_out_is_mi_like_p (uiout
))
4720 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4721 char *fullname
= symtab_to_fullname (sal
.symtab
);
4724 ui_out_field_string (uiout
, "fullname", fullname
);
4727 ui_out_field_int (uiout
, "line", b
->line_number
);
4731 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4732 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4734 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4736 ui_out_field_stream (uiout
, "at", stb
);
4738 do_cleanups (stb_chain
);
4741 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4743 do_cleanups (old_chain
);
4747 bptype_string (enum bptype type
)
4749 struct ep_type_description
4754 static struct ep_type_description bptypes
[] =
4756 {bp_none
, "?deleted?"},
4757 {bp_breakpoint
, "breakpoint"},
4758 {bp_hardware_breakpoint
, "hw breakpoint"},
4759 {bp_until
, "until"},
4760 {bp_finish
, "finish"},
4761 {bp_watchpoint
, "watchpoint"},
4762 {bp_hardware_watchpoint
, "hw watchpoint"},
4763 {bp_read_watchpoint
, "read watchpoint"},
4764 {bp_access_watchpoint
, "acc watchpoint"},
4765 {bp_longjmp
, "longjmp"},
4766 {bp_longjmp_resume
, "longjmp resume"},
4767 {bp_exception
, "exception"},
4768 {bp_exception_resume
, "exception resume"},
4769 {bp_step_resume
, "step resume"},
4770 {bp_watchpoint_scope
, "watchpoint scope"},
4771 {bp_call_dummy
, "call dummy"},
4772 {bp_std_terminate
, "std::terminate"},
4773 {bp_shlib_event
, "shlib events"},
4774 {bp_thread_event
, "thread events"},
4775 {bp_overlay_event
, "overlay events"},
4776 {bp_longjmp_master
, "longjmp master"},
4777 {bp_std_terminate_master
, "std::terminate master"},
4778 {bp_exception_master
, "exception master"},
4779 {bp_catchpoint
, "catchpoint"},
4780 {bp_tracepoint
, "tracepoint"},
4781 {bp_fast_tracepoint
, "fast tracepoint"},
4782 {bp_static_tracepoint
, "static tracepoint"},
4783 {bp_jit_event
, "jit events"},
4784 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4785 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4788 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4789 || ((int) type
!= bptypes
[(int) type
].type
))
4790 internal_error (__FILE__
, __LINE__
,
4791 _("bptypes table does not describe type #%d."),
4794 return bptypes
[(int) type
].description
;
4797 /* Print B to gdb_stdout. */
4800 print_one_breakpoint_location (struct breakpoint
*b
,
4801 struct bp_location
*loc
,
4803 struct bp_location
**last_loc
,
4806 struct command_line
*l
;
4807 static char bpenables
[] = "nynny";
4809 int header_of_multiple
= 0;
4810 int part_of_multiple
= (loc
!= NULL
);
4811 struct value_print_options opts
;
4813 get_user_print_options (&opts
);
4815 gdb_assert (!loc
|| loc_number
!= 0);
4816 /* See comment in print_one_breakpoint concerning treatment of
4817 breakpoints with single disabled location. */
4820 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4821 header_of_multiple
= 1;
4829 if (part_of_multiple
)
4832 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4833 ui_out_field_string (uiout
, "number", formatted
);
4838 ui_out_field_int (uiout
, "number", b
->number
);
4843 if (part_of_multiple
)
4844 ui_out_field_skip (uiout
, "type");
4846 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4850 if (part_of_multiple
)
4851 ui_out_field_skip (uiout
, "disp");
4853 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4858 if (part_of_multiple
)
4859 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4861 ui_out_field_fmt (uiout
, "enabled", "%c",
4862 bpenables
[(int) b
->enable_state
]);
4863 ui_out_spaces (uiout
, 2);
4867 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4869 /* Although the print_one can possibly print all locations,
4870 calling it here is not likely to get any nice result. So,
4871 make sure there's just one location. */
4872 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4873 b
->ops
->print_one (b
, last_loc
);
4879 internal_error (__FILE__
, __LINE__
,
4880 _("print_one_breakpoint: bp_none encountered\n"));
4884 case bp_hardware_watchpoint
:
4885 case bp_read_watchpoint
:
4886 case bp_access_watchpoint
:
4887 /* Field 4, the address, is omitted (which makes the columns
4888 not line up too nicely with the headers, but the effect
4889 is relatively readable). */
4890 if (opts
.addressprint
)
4891 ui_out_field_skip (uiout
, "addr");
4893 ui_out_field_string (uiout
, "what", b
->exp_string
);
4897 case bp_hardware_breakpoint
:
4901 case bp_longjmp_resume
:
4903 case bp_exception_resume
:
4904 case bp_step_resume
:
4905 case bp_watchpoint_scope
:
4907 case bp_std_terminate
:
4908 case bp_shlib_event
:
4909 case bp_thread_event
:
4910 case bp_overlay_event
:
4911 case bp_longjmp_master
:
4912 case bp_std_terminate_master
:
4913 case bp_exception_master
:
4915 case bp_fast_tracepoint
:
4916 case bp_static_tracepoint
:
4918 case bp_gnu_ifunc_resolver
:
4919 case bp_gnu_ifunc_resolver_return
:
4920 if (opts
.addressprint
)
4923 if (header_of_multiple
)
4924 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4925 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4926 ui_out_field_string (uiout
, "addr", "<PENDING>");
4928 ui_out_field_core_addr (uiout
, "addr",
4929 loc
->gdbarch
, loc
->address
);
4932 if (!header_of_multiple
)
4933 print_breakpoint_location (b
, loc
);
4940 /* For backward compatibility, don't display inferiors unless there
4943 && !header_of_multiple
4945 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4946 && (number_of_program_spaces () > 1
4947 || number_of_inferiors () > 1)
4948 /* LOC is for existing B, it cannot be in
4949 moribund_locations and thus having NULL OWNER. */
4950 && loc
->owner
->type
!= bp_catchpoint
)))
4952 struct inferior
*inf
;
4955 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4957 if (inf
->pspace
== loc
->pspace
)
4962 ui_out_text (uiout
, " inf ");
4965 ui_out_text (uiout
, ", ");
4966 ui_out_text (uiout
, plongest (inf
->num
));
4971 if (!part_of_multiple
)
4973 if (b
->thread
!= -1)
4975 /* FIXME: This seems to be redundant and lost here; see the
4976 "stop only in" line a little further down. */
4977 ui_out_text (uiout
, " thread ");
4978 ui_out_field_int (uiout
, "thread", b
->thread
);
4980 else if (b
->task
!= 0)
4982 ui_out_text (uiout
, " task ");
4983 ui_out_field_int (uiout
, "task", b
->task
);
4987 ui_out_text (uiout
, "\n");
4989 if (!part_of_multiple
&& b
->ops
&& b
->ops
->print_one_detail
)
4990 b
->ops
->print_one_detail (b
, uiout
);
4992 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4994 gdb_assert (b
->type
== bp_static_tracepoint
);
4996 ui_out_text (uiout
, "\tmarker id is ");
4997 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4998 b
->static_trace_marker_id
);
4999 ui_out_text (uiout
, "\n");
5002 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5005 ui_out_text (uiout
, "\tstop only in stack frame at ");
5006 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
5008 ui_out_field_core_addr (uiout
, "frame",
5009 b
->gdbarch
, b
->frame_id
.stack_addr
);
5010 ui_out_text (uiout
, "\n");
5013 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
5015 /* We do not print the condition for Ada exception catchpoints
5016 because the condition is an internal implementation detail
5017 that we do not want to expose to the user. */
5019 if (is_tracepoint (b
))
5020 ui_out_text (uiout
, "\ttrace only if ");
5022 ui_out_text (uiout
, "\tstop only if ");
5023 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5024 ui_out_text (uiout
, "\n");
5027 if (!part_of_multiple
&& b
->thread
!= -1)
5029 /* FIXME should make an annotation for this. */
5030 ui_out_text (uiout
, "\tstop only in thread ");
5031 ui_out_field_int (uiout
, "thread", b
->thread
);
5032 ui_out_text (uiout
, "\n");
5035 if (!part_of_multiple
&& b
->hit_count
)
5037 /* FIXME should make an annotation for this. */
5038 if (ep_is_catchpoint (b
))
5039 ui_out_text (uiout
, "\tcatchpoint");
5041 ui_out_text (uiout
, "\tbreakpoint");
5042 ui_out_text (uiout
, " already hit ");
5043 ui_out_field_int (uiout
, "times", b
->hit_count
);
5044 if (b
->hit_count
== 1)
5045 ui_out_text (uiout
, " time\n");
5047 ui_out_text (uiout
, " times\n");
5050 /* Output the count also if it is zero, but only if this is mi.
5051 FIXME: Should have a better test for this. */
5052 if (ui_out_is_mi_like_p (uiout
))
5053 if (!part_of_multiple
&& b
->hit_count
== 0)
5054 ui_out_field_int (uiout
, "times", b
->hit_count
);
5056 if (!part_of_multiple
&& b
->ignore_count
)
5059 ui_out_text (uiout
, "\tignore next ");
5060 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5061 ui_out_text (uiout
, " hits\n");
5064 l
= b
->commands
? b
->commands
->commands
: NULL
;
5065 if (!part_of_multiple
&& l
)
5067 struct cleanup
*script_chain
;
5070 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5071 print_command_lines (uiout
, l
, 4);
5072 do_cleanups (script_chain
);
5075 if (!part_of_multiple
&& b
->pass_count
)
5077 annotate_field (10);
5078 ui_out_text (uiout
, "\tpass count ");
5079 ui_out_field_int (uiout
, "pass", b
->pass_count
);
5080 ui_out_text (uiout
, " \n");
5083 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5086 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5087 else if (b
->exp_string
)
5088 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
5093 print_one_breakpoint (struct breakpoint
*b
,
5094 struct bp_location
**last_loc
,
5097 struct cleanup
*bkpt_chain
;
5099 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5101 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5102 do_cleanups (bkpt_chain
);
5104 /* If this breakpoint has custom print function,
5105 it's already printed. Otherwise, print individual
5106 locations, if any. */
5107 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5109 /* If breakpoint has a single location that is disabled, we
5110 print it as if it had several locations, since otherwise it's
5111 hard to represent "breakpoint enabled, location disabled"
5114 Note that while hardware watchpoints have several locations
5115 internally, that's not a property exposed to user. */
5117 && !is_hardware_watchpoint (b
)
5118 && (b
->loc
->next
|| !b
->loc
->enabled
))
5120 struct bp_location
*loc
;
5123 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5125 struct cleanup
*inner2
=
5126 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5127 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5128 do_cleanups (inner2
);
5135 breakpoint_address_bits (struct breakpoint
*b
)
5137 int print_address_bits
= 0;
5138 struct bp_location
*loc
;
5140 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5144 /* Software watchpoints that aren't watching memory don't have
5145 an address to print. */
5146 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5149 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5150 if (addr_bit
> print_address_bits
)
5151 print_address_bits
= addr_bit
;
5154 return print_address_bits
;
5157 struct captured_breakpoint_query_args
5163 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5165 struct captured_breakpoint_query_args
*args
= data
;
5166 struct breakpoint
*b
;
5167 struct bp_location
*dummy_loc
= NULL
;
5171 if (args
->bnum
== b
->number
)
5173 print_one_breakpoint (b
, &dummy_loc
, 0);
5181 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5182 char **error_message
)
5184 struct captured_breakpoint_query_args args
;
5187 /* For the moment we don't trust print_one_breakpoint() to not throw
5189 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5190 error_message
, RETURN_MASK_ALL
) < 0)
5196 /* Return true if this breakpoint was set by the user, false if it is
5197 internal or momentary. */
5200 user_breakpoint_p (struct breakpoint
*b
)
5202 return b
->number
> 0;
5205 /* Print information on user settable breakpoint (watchpoint, etc)
5206 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5207 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5208 FILTER is non-NULL, call it on each breakpoint and only include the
5209 ones for which it returns non-zero. Return the total number of
5210 breakpoints listed. */
5213 breakpoint_1 (char *args
, int allflag
,
5214 int (*filter
) (const struct breakpoint
*))
5216 struct breakpoint
*b
;
5217 struct bp_location
*last_loc
= NULL
;
5218 int nr_printable_breakpoints
;
5219 struct cleanup
*bkpttbl_chain
;
5220 struct value_print_options opts
;
5221 int print_address_bits
= 0;
5222 int print_type_col_width
= 14;
5224 get_user_print_options (&opts
);
5226 /* Compute the number of rows in the table, as well as the size
5227 required for address fields. */
5228 nr_printable_breakpoints
= 0;
5231 /* If we have a filter, only list the breakpoints it accepts. */
5232 if (filter
&& !filter (b
))
5235 /* If we have an "args" string, it is a list of breakpoints to
5236 accept. Skip the others. */
5237 if (args
!= NULL
&& *args
!= '\0')
5239 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5241 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5245 if (allflag
|| user_breakpoint_p (b
))
5247 int addr_bit
, type_len
;
5249 addr_bit
= breakpoint_address_bits (b
);
5250 if (addr_bit
> print_address_bits
)
5251 print_address_bits
= addr_bit
;
5253 type_len
= strlen (bptype_string (b
->type
));
5254 if (type_len
> print_type_col_width
)
5255 print_type_col_width
= type_len
;
5257 nr_printable_breakpoints
++;
5261 if (opts
.addressprint
)
5263 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5264 nr_printable_breakpoints
,
5268 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5269 nr_printable_breakpoints
,
5272 if (nr_printable_breakpoints
> 0)
5273 annotate_breakpoints_headers ();
5274 if (nr_printable_breakpoints
> 0)
5276 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5277 if (nr_printable_breakpoints
> 0)
5279 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5280 "type", "Type"); /* 2 */
5281 if (nr_printable_breakpoints
> 0)
5283 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5284 if (nr_printable_breakpoints
> 0)
5286 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5287 if (opts
.addressprint
)
5289 if (nr_printable_breakpoints
> 0)
5291 if (print_address_bits
<= 32)
5292 ui_out_table_header (uiout
, 10, ui_left
,
5293 "addr", "Address"); /* 5 */
5295 ui_out_table_header (uiout
, 18, ui_left
,
5296 "addr", "Address"); /* 5 */
5298 if (nr_printable_breakpoints
> 0)
5300 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5301 ui_out_table_body (uiout
);
5302 if (nr_printable_breakpoints
> 0)
5303 annotate_breakpoints_table ();
5308 /* If we have a filter, only list the breakpoints it accepts. */
5309 if (filter
&& !filter (b
))
5312 /* If we have an "args" string, it is a list of breakpoints to
5313 accept. Skip the others. */
5315 if (args
!= NULL
&& *args
!= '\0')
5317 if (allflag
) /* maintenance info breakpoint */
5319 if (parse_and_eval_long (args
) != b
->number
)
5322 else /* all others */
5324 if (!number_is_in_list (args
, b
->number
))
5328 /* We only print out user settable breakpoints unless the
5330 if (allflag
|| user_breakpoint_p (b
))
5331 print_one_breakpoint (b
, &last_loc
, allflag
);
5334 do_cleanups (bkpttbl_chain
);
5336 if (nr_printable_breakpoints
== 0)
5338 /* If there's a filter, let the caller decide how to report
5342 if (args
== NULL
|| *args
== '\0')
5343 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5345 ui_out_message (uiout
, 0,
5346 "No breakpoint or watchpoint matching '%s'.\n",
5352 if (last_loc
&& !server_command
)
5353 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5356 /* FIXME? Should this be moved up so that it is only called when
5357 there have been breakpoints? */
5358 annotate_breakpoints_table_end ();
5360 return nr_printable_breakpoints
;
5363 /* Display the value of default-collect in a way that is generally
5364 compatible with the breakpoint list. */
5367 default_collect_info (void)
5369 /* If it has no value (which is frequently the case), say nothing; a
5370 message like "No default-collect." gets in user's face when it's
5372 if (!*default_collect
)
5375 /* The following phrase lines up nicely with per-tracepoint collect
5377 ui_out_text (uiout
, "default collect ");
5378 ui_out_field_string (uiout
, "default-collect", default_collect
);
5379 ui_out_text (uiout
, " \n");
5383 breakpoints_info (char *args
, int from_tty
)
5385 breakpoint_1 (args
, 0, NULL
);
5387 default_collect_info ();
5391 watchpoints_info (char *args
, int from_tty
)
5393 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5395 if (num_printed
== 0)
5397 if (args
== NULL
|| *args
== '\0')
5398 ui_out_message (uiout
, 0, "No watchpoints.\n");
5400 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5405 maintenance_info_breakpoints (char *args
, int from_tty
)
5407 breakpoint_1 (args
, 1, NULL
);
5409 default_collect_info ();
5413 breakpoint_has_pc (struct breakpoint
*b
,
5414 struct program_space
*pspace
,
5415 CORE_ADDR pc
, struct obj_section
*section
)
5417 struct bp_location
*bl
= b
->loc
;
5419 for (; bl
; bl
= bl
->next
)
5421 if (bl
->pspace
== pspace
5422 && bl
->address
== pc
5423 && (!overlay_debugging
|| bl
->section
== section
))
5429 /* Print a message describing any breakpoints set at PC. This
5430 concerns with logical breakpoints, so we match program spaces, not
5434 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5435 struct program_space
*pspace
, CORE_ADDR pc
,
5436 struct obj_section
*section
, int thread
)
5439 struct breakpoint
*b
;
5442 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5446 printf_filtered (_("Note: breakpoint "));
5447 else /* if (others == ???) */
5448 printf_filtered (_("Note: breakpoints "));
5450 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5453 printf_filtered ("%d", b
->number
);
5454 if (b
->thread
== -1 && thread
!= -1)
5455 printf_filtered (" (all threads)");
5456 else if (b
->thread
!= -1)
5457 printf_filtered (" (thread %d)", b
->thread
);
5458 printf_filtered ("%s%s ",
5459 ((b
->enable_state
== bp_disabled
5460 || b
->enable_state
== bp_call_disabled
5461 || b
->enable_state
== bp_startup_disabled
)
5463 : b
->enable_state
== bp_permanent
5467 : ((others
== 1) ? " and" : ""));
5469 printf_filtered (_("also set at pc "));
5470 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5471 printf_filtered (".\n");
5475 /* Set the default place to put a breakpoint
5476 for the `break' command with no arguments. */
5479 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5480 CORE_ADDR addr
, struct symtab
*symtab
,
5483 default_breakpoint_valid
= valid
;
5484 default_breakpoint_pspace
= pspace
;
5485 default_breakpoint_address
= addr
;
5486 default_breakpoint_symtab
= symtab
;
5487 default_breakpoint_line
= line
;
5490 /* Return true iff it is meaningful to use the address member of
5491 BPT. For some breakpoint types, the address member is irrelevant
5492 and it makes no sense to attempt to compare it to other addresses
5493 (or use it for any other purpose either).
5495 More specifically, each of the following breakpoint types will
5496 always have a zero valued address and we don't want to mark
5497 breakpoints of any of these types to be a duplicate of an actual
5498 breakpoint at address zero:
5506 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5508 enum bptype type
= bpt
->type
;
5510 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5513 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5514 true if LOC1 and LOC2 represent the same watchpoint location. */
5517 watchpoint_locations_match (struct bp_location
*loc1
,
5518 struct bp_location
*loc2
)
5520 /* Both of them must not be in moribund_locations. */
5521 gdb_assert (loc1
->owner
!= NULL
);
5522 gdb_assert (loc2
->owner
!= NULL
);
5524 /* If the target can evaluate the condition expression in hardware,
5525 then we we need to insert both watchpoints even if they are at
5526 the same place. Otherwise the watchpoint will only trigger when
5527 the condition of whichever watchpoint was inserted evaluates to
5528 true, not giving a chance for GDB to check the condition of the
5529 other watchpoint. */
5530 if ((loc1
->owner
->cond_exp
5531 && target_can_accel_watchpoint_condition (loc1
->address
,
5533 loc1
->watchpoint_type
,
5534 loc1
->owner
->cond_exp
))
5535 || (loc2
->owner
->cond_exp
5536 && target_can_accel_watchpoint_condition (loc2
->address
,
5538 loc2
->watchpoint_type
,
5539 loc2
->owner
->cond_exp
)))
5542 /* Note that this checks the owner's type, not the location's. In
5543 case the target does not support read watchpoints, but does
5544 support access watchpoints, we'll have bp_read_watchpoint
5545 watchpoints with hw_access locations. Those should be considered
5546 duplicates of hw_read locations. The hw_read locations will
5547 become hw_access locations later. */
5548 return (loc1
->owner
->type
== loc2
->owner
->type
5549 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5550 && loc1
->address
== loc2
->address
5551 && loc1
->length
== loc2
->length
);
5554 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5555 same breakpoint location. In most targets, this can only be true
5556 if ASPACE1 matches ASPACE2. On targets that have global
5557 breakpoints, the address space doesn't really matter. */
5560 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5561 struct address_space
*aspace2
, CORE_ADDR addr2
)
5563 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5564 || aspace1
== aspace2
)
5568 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5569 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5570 matches ASPACE2. On targets that have global breakpoints, the address
5571 space doesn't really matter. */
5574 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5575 int len1
, struct address_space
*aspace2
,
5578 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5579 || aspace1
== aspace2
)
5580 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5583 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5584 a ranged breakpoint. In most targets, a match happens only if ASPACE
5585 matches the breakpoint's address space. On targets that have global
5586 breakpoints, the address space doesn't really matter. */
5589 breakpoint_location_address_match (struct bp_location
*bl
,
5590 struct address_space
*aspace
,
5593 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5596 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5597 bl
->address
, bl
->length
,
5601 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5602 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5603 represent the same location. */
5606 breakpoint_locations_match (struct bp_location
*loc1
,
5607 struct bp_location
*loc2
)
5609 int hw_point1
, hw_point2
;
5611 /* Both of them must not be in moribund_locations. */
5612 gdb_assert (loc1
->owner
!= NULL
);
5613 gdb_assert (loc2
->owner
!= NULL
);
5615 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5616 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5618 if (hw_point1
!= hw_point2
)
5621 return watchpoint_locations_match (loc1
, loc2
);
5623 /* We compare bp_location.length in order to cover ranged breakpoints. */
5624 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5625 loc2
->pspace
->aspace
, loc2
->address
)
5626 && loc1
->length
== loc2
->length
);
5630 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5631 int bnum
, int have_bnum
)
5633 /* The longest string possibly returned by hex_string_custom
5634 is 50 chars. These must be at least that big for safety. */
5638 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5639 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5641 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5642 bnum
, astr1
, astr2
);
5644 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5647 /* Adjust a breakpoint's address to account for architectural
5648 constraints on breakpoint placement. Return the adjusted address.
5649 Note: Very few targets require this kind of adjustment. For most
5650 targets, this function is simply the identity function. */
5653 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5654 CORE_ADDR bpaddr
, enum bptype bptype
)
5656 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5658 /* Very few targets need any kind of breakpoint adjustment. */
5661 else if (bptype
== bp_watchpoint
5662 || bptype
== bp_hardware_watchpoint
5663 || bptype
== bp_read_watchpoint
5664 || bptype
== bp_access_watchpoint
5665 || bptype
== bp_catchpoint
)
5667 /* Watchpoints and the various bp_catch_* eventpoints should not
5668 have their addresses modified. */
5673 CORE_ADDR adjusted_bpaddr
;
5675 /* Some targets have architectural constraints on the placement
5676 of breakpoint instructions. Obtain the adjusted address. */
5677 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5679 /* An adjusted breakpoint address can significantly alter
5680 a user's expectations. Print a warning if an adjustment
5682 if (adjusted_bpaddr
!= bpaddr
)
5683 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5685 return adjusted_bpaddr
;
5689 /* Allocate a struct bp_location. */
5691 static struct bp_location
*
5692 allocate_bp_location (struct breakpoint
*bpt
)
5694 struct bp_location
*loc
;
5696 loc
= xmalloc (sizeof (struct bp_location
));
5697 memset (loc
, 0, sizeof (*loc
));
5701 loc
->shlib_disabled
= 0;
5710 case bp_longjmp_resume
:
5712 case bp_exception_resume
:
5713 case bp_step_resume
:
5714 case bp_watchpoint_scope
:
5716 case bp_std_terminate
:
5717 case bp_shlib_event
:
5718 case bp_thread_event
:
5719 case bp_overlay_event
:
5721 case bp_longjmp_master
:
5722 case bp_std_terminate_master
:
5723 case bp_exception_master
:
5724 case bp_gnu_ifunc_resolver
:
5725 case bp_gnu_ifunc_resolver_return
:
5726 loc
->loc_type
= bp_loc_software_breakpoint
;
5728 case bp_hardware_breakpoint
:
5729 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5731 case bp_hardware_watchpoint
:
5732 case bp_read_watchpoint
:
5733 case bp_access_watchpoint
:
5734 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5739 case bp_fast_tracepoint
:
5740 case bp_static_tracepoint
:
5741 loc
->loc_type
= bp_loc_other
;
5744 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5752 free_bp_location (struct bp_location
*loc
)
5757 if (loc
->function_name
)
5758 xfree (loc
->function_name
);
5763 /* Increment reference count. */
5766 incref_bp_location (struct bp_location
*bl
)
5771 /* Decrement reference count. If the reference count reaches 0,
5772 destroy the bp_location. Sets *BLP to NULL. */
5775 decref_bp_location (struct bp_location
**blp
)
5777 gdb_assert ((*blp
)->refc
> 0);
5779 if (--(*blp
)->refc
== 0)
5780 free_bp_location (*blp
);
5784 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5785 type BPTYPE and has no locations as yet. */
5786 /* This function is used in gdbtk sources and thus can not be made
5789 static struct breakpoint
*
5790 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5793 struct breakpoint
*b
, *b1
;
5795 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5796 memset (b
, 0, sizeof (*b
));
5799 b
->gdbarch
= gdbarch
;
5800 b
->language
= current_language
->la_language
;
5801 b
->input_radix
= input_radix
;
5803 b
->enable_state
= bp_enabled
;
5806 b
->ignore_count
= 0;
5808 b
->frame_id
= null_frame_id
;
5809 b
->forked_inferior_pid
= null_ptid
;
5810 b
->exec_pathname
= NULL
;
5811 b
->syscalls_to_be_caught
= NULL
;
5813 b
->condition_not_parsed
= 0;
5814 b
->py_bp_object
= NULL
;
5815 b
->related_breakpoint
= b
;
5817 /* Add this breakpoint to the end of the chain so that a list of
5818 breakpoints will come out in order of increasing numbers. */
5820 b1
= breakpoint_chain
;
5822 breakpoint_chain
= b
;
5832 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5833 resolutions should be made as the user specified the location explicitly
5837 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5839 gdb_assert (loc
->owner
!= NULL
);
5841 if (loc
->owner
->type
== bp_breakpoint
5842 || loc
->owner
->type
== bp_hardware_breakpoint
5843 || is_tracepoint (loc
->owner
))
5847 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5848 NULL
, NULL
, &is_gnu_ifunc
);
5850 if (is_gnu_ifunc
&& !explicit_loc
)
5852 struct breakpoint
*b
= loc
->owner
;
5854 gdb_assert (loc
->pspace
== current_program_space
);
5855 if (gnu_ifunc_resolve_name (loc
->function_name
,
5856 &loc
->requested_address
))
5858 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5859 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5860 loc
->requested_address
,
5863 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5864 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5866 /* Create only the whole new breakpoint of this type but do not
5867 mess more complicated breakpoints with multiple locations. */
5868 b
->type
= bp_gnu_ifunc_resolver
;
5872 if (loc
->function_name
)
5873 loc
->function_name
= xstrdup (loc
->function_name
);
5877 /* Attempt to determine architecture of location identified by SAL. */
5878 static struct gdbarch
*
5879 get_sal_arch (struct symtab_and_line sal
)
5882 return get_objfile_arch (sal
.section
->objfile
);
5884 return get_objfile_arch (sal
.symtab
->objfile
);
5889 /* set_raw_breakpoint is a low level routine for allocating and
5890 partially initializing a breakpoint of type BPTYPE. The newly
5891 created breakpoint's address, section, source file name, and line
5892 number are provided by SAL. The newly created and partially
5893 initialized breakpoint is added to the breakpoint chain and
5894 is also returned as the value of this function.
5896 It is expected that the caller will complete the initialization of
5897 the newly created breakpoint struct as well as output any status
5898 information regarding the creation of a new breakpoint. In
5899 particular, set_raw_breakpoint does NOT set the breakpoint
5900 number! Care should be taken to not allow an error to occur
5901 prior to completing the initialization of the breakpoint. If this
5902 should happen, a bogus breakpoint will be left on the chain. */
5905 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5906 struct symtab_and_line sal
, enum bptype bptype
)
5908 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5910 CORE_ADDR adjusted_address
;
5911 struct gdbarch
*loc_gdbarch
;
5913 loc_gdbarch
= get_sal_arch (sal
);
5915 loc_gdbarch
= b
->gdbarch
;
5917 if (bptype
!= bp_catchpoint
)
5918 gdb_assert (sal
.pspace
!= NULL
);
5920 /* Adjust the breakpoint's address prior to allocating a location.
5921 Once we call allocate_bp_location(), that mostly uninitialized
5922 location will be placed on the location chain. Adjustment of the
5923 breakpoint may cause target_read_memory() to be called and we do
5924 not want its scan of the location chain to find a breakpoint and
5925 location that's only been partially initialized. */
5926 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5929 b
->loc
= allocate_bp_location (b
);
5930 b
->loc
->gdbarch
= loc_gdbarch
;
5931 b
->loc
->requested_address
= sal
.pc
;
5932 b
->loc
->address
= adjusted_address
;
5933 b
->loc
->pspace
= sal
.pspace
;
5935 /* Store the program space that was used to set the breakpoint, for
5936 breakpoint resetting. */
5937 b
->pspace
= sal
.pspace
;
5939 if (sal
.symtab
== NULL
)
5940 b
->source_file
= NULL
;
5942 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5943 b
->loc
->section
= sal
.section
;
5944 b
->line_number
= sal
.line
;
5946 set_breakpoint_location_function (b
->loc
,
5947 sal
.explicit_pc
|| sal
.explicit_line
);
5949 breakpoints_changed ();
5955 /* Note that the breakpoint object B describes a permanent breakpoint
5956 instruction, hard-wired into the inferior's code. */
5958 make_breakpoint_permanent (struct breakpoint
*b
)
5960 struct bp_location
*bl
;
5962 b
->enable_state
= bp_permanent
;
5964 /* By definition, permanent breakpoints are already present in the
5965 code. Mark all locations as inserted. For now,
5966 make_breakpoint_permanent is called in just one place, so it's
5967 hard to say if it's reasonable to have permanent breakpoint with
5968 multiple locations or not, but it's easy to implmement. */
5969 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5973 /* Call this routine when stepping and nexting to enable a breakpoint
5974 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5975 initiated the operation. */
5978 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5980 struct breakpoint
*b
, *b_tmp
;
5981 int thread
= tp
->num
;
5983 /* To avoid having to rescan all objfile symbols at every step,
5984 we maintain a list of continually-inserted but always disabled
5985 longjmp "master" breakpoints. Here, we simply create momentary
5986 clones of those and enable them for the requested thread. */
5987 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5988 if (b
->pspace
== current_program_space
5989 && (b
->type
== bp_longjmp_master
5990 || b
->type
== bp_exception_master
))
5992 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5994 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5995 clone
->thread
= thread
;
5998 tp
->initiating_frame
= frame
;
6001 /* Delete all longjmp breakpoints from THREAD. */
6003 delete_longjmp_breakpoint (int thread
)
6005 struct breakpoint
*b
, *b_tmp
;
6007 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6008 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6010 if (b
->thread
== thread
)
6011 delete_breakpoint (b
);
6016 enable_overlay_breakpoints (void)
6018 struct breakpoint
*b
;
6021 if (b
->type
== bp_overlay_event
)
6023 b
->enable_state
= bp_enabled
;
6024 update_global_location_list (1);
6025 overlay_events_enabled
= 1;
6030 disable_overlay_breakpoints (void)
6032 struct breakpoint
*b
;
6035 if (b
->type
== bp_overlay_event
)
6037 b
->enable_state
= bp_disabled
;
6038 update_global_location_list (0);
6039 overlay_events_enabled
= 0;
6043 /* Set an active std::terminate breakpoint for each std::terminate
6044 master breakpoint. */
6046 set_std_terminate_breakpoint (void)
6048 struct breakpoint
*b
, *b_tmp
;
6050 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6051 if (b
->pspace
== current_program_space
6052 && b
->type
== bp_std_terminate_master
)
6054 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
6055 clone
->type
= bp_std_terminate
;
6059 /* Delete all the std::terminate breakpoints. */
6061 delete_std_terminate_breakpoint (void)
6063 struct breakpoint
*b
, *b_tmp
;
6065 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6066 if (b
->type
== bp_std_terminate
)
6067 delete_breakpoint (b
);
6071 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6073 struct breakpoint
*b
;
6075 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
6077 b
->enable_state
= bp_enabled
;
6078 /* addr_string has to be used or breakpoint_re_set will delete me. */
6080 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6082 update_global_location_list_nothrow (1);
6088 remove_thread_event_breakpoints (void)
6090 struct breakpoint
*b
, *b_tmp
;
6092 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6093 if (b
->type
== bp_thread_event
6094 && b
->loc
->pspace
== current_program_space
)
6095 delete_breakpoint (b
);
6098 struct lang_and_radix
6104 /* Create a breakpoint for JIT code registration and unregistration. */
6107 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6109 struct breakpoint
*b
;
6111 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
6112 update_global_location_list_nothrow (1);
6116 /* Remove JIT code registration and unregistration breakpoint(s). */
6119 remove_jit_event_breakpoints (void)
6121 struct breakpoint
*b
, *b_tmp
;
6123 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6124 if (b
->type
== bp_jit_event
6125 && b
->loc
->pspace
== current_program_space
)
6126 delete_breakpoint (b
);
6130 remove_solib_event_breakpoints (void)
6132 struct breakpoint
*b
, *b_tmp
;
6134 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6135 if (b
->type
== bp_shlib_event
6136 && b
->loc
->pspace
== current_program_space
)
6137 delete_breakpoint (b
);
6141 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6143 struct breakpoint
*b
;
6145 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
6146 update_global_location_list_nothrow (1);
6150 /* Disable any breakpoints that are on code in shared libraries. Only
6151 apply to enabled breakpoints, disabled ones can just stay disabled. */
6154 disable_breakpoints_in_shlibs (void)
6156 struct bp_location
*loc
, **locp_tmp
;
6158 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6160 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6161 struct breakpoint
*b
= loc
->owner
;
6163 /* We apply the check to all breakpoints, including disabled for
6164 those with loc->duplicate set. This is so that when breakpoint
6165 becomes enabled, or the duplicate is removed, gdb will try to
6166 insert all breakpoints. If we don't set shlib_disabled here,
6167 we'll try to insert those breakpoints and fail. */
6168 if (((b
->type
== bp_breakpoint
)
6169 || (b
->type
== bp_jit_event
)
6170 || (b
->type
== bp_hardware_breakpoint
)
6171 || (is_tracepoint (b
)))
6172 && loc
->pspace
== current_program_space
6173 && !loc
->shlib_disabled
6175 && PC_SOLIB (loc
->address
)
6177 && solib_name_from_address (loc
->pspace
, loc
->address
)
6181 loc
->shlib_disabled
= 1;
6186 /* Disable any breakpoints that are in an unloaded shared library.
6187 Only apply to enabled breakpoints, disabled ones can just stay
6191 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6193 struct bp_location
*loc
, **locp_tmp
;
6194 int disabled_shlib_breaks
= 0;
6196 /* SunOS a.out shared libraries are always mapped, so do not
6197 disable breakpoints; they will only be reported as unloaded
6198 through clear_solib when GDB discards its shared library
6199 list. See clear_solib for more information. */
6200 if (exec_bfd
!= NULL
6201 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6204 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6206 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6207 struct breakpoint
*b
= loc
->owner
;
6209 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6210 || loc
->loc_type
== bp_loc_software_breakpoint
)
6211 && solib
->pspace
== loc
->pspace
6212 && !loc
->shlib_disabled
6213 && (b
->type
== bp_breakpoint
6214 || b
->type
== bp_jit_event
6215 || b
->type
== bp_hardware_breakpoint
)
6216 && solib_contains_address_p (solib
, loc
->address
))
6218 loc
->shlib_disabled
= 1;
6219 /* At this point, we cannot rely on remove_breakpoint
6220 succeeding so we must mark the breakpoint as not inserted
6221 to prevent future errors occurring in remove_breakpoints. */
6224 /* This may cause duplicate notifications for the same breakpoint. */
6225 observer_notify_breakpoint_modified (b
);
6227 if (!disabled_shlib_breaks
)
6229 target_terminal_ours_for_output ();
6230 warning (_("Temporarily disabling breakpoints "
6231 "for unloaded shared library \"%s\""),
6234 disabled_shlib_breaks
= 1;
6239 /* FORK & VFORK catchpoints. */
6241 /* Implement the "insert" breakpoint_ops method for fork
6245 insert_catch_fork (struct bp_location
*bl
)
6247 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6250 /* Implement the "remove" breakpoint_ops method for fork
6254 remove_catch_fork (struct bp_location
*bl
)
6256 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6259 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6263 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6264 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6266 return inferior_has_forked (inferior_ptid
, &bl
->owner
->forked_inferior_pid
);
6269 /* Implement the "print_it" breakpoint_ops method for fork
6272 static enum print_stop_action
6273 print_it_catch_fork (struct breakpoint
*b
)
6275 annotate_catchpoint (b
->number
);
6276 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6277 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6278 return PRINT_SRC_AND_LOC
;
6281 /* Implement the "print_one" breakpoint_ops method for fork
6285 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6287 struct value_print_options opts
;
6289 get_user_print_options (&opts
);
6291 /* Field 4, the address, is omitted (which makes the columns not
6292 line up too nicely with the headers, but the effect is relatively
6294 if (opts
.addressprint
)
6295 ui_out_field_skip (uiout
, "addr");
6297 ui_out_text (uiout
, "fork");
6298 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6300 ui_out_text (uiout
, ", process ");
6301 ui_out_field_int (uiout
, "what",
6302 ptid_get_pid (b
->forked_inferior_pid
));
6303 ui_out_spaces (uiout
, 1);
6307 /* Implement the "print_mention" breakpoint_ops method for fork
6311 print_mention_catch_fork (struct breakpoint
*b
)
6313 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6316 /* Implement the "print_recreate" breakpoint_ops method for fork
6320 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6322 fprintf_unfiltered (fp
, "catch fork");
6325 /* The breakpoint_ops structure to be used in fork catchpoints. */
6327 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6331 breakpoint_hit_catch_fork
,
6332 NULL
, /* resources_needed */
6333 NULL
, /* works_in_software_mode */
6334 print_it_catch_fork
,
6335 print_one_catch_fork
,
6336 NULL
, /* print_one_detail */
6337 print_mention_catch_fork
,
6338 print_recreate_catch_fork
6341 /* Implement the "insert" breakpoint_ops method for vfork
6345 insert_catch_vfork (struct bp_location
*bl
)
6347 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6350 /* Implement the "remove" breakpoint_ops method for vfork
6354 remove_catch_vfork (struct bp_location
*bl
)
6356 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6359 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6363 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6364 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6366 return inferior_has_vforked (inferior_ptid
, &bl
->owner
->forked_inferior_pid
);
6369 /* Implement the "print_it" breakpoint_ops method for vfork
6372 static enum print_stop_action
6373 print_it_catch_vfork (struct breakpoint
*b
)
6375 annotate_catchpoint (b
->number
);
6376 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6377 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6378 return PRINT_SRC_AND_LOC
;
6381 /* Implement the "print_one" breakpoint_ops method for vfork
6385 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6387 struct value_print_options opts
;
6389 get_user_print_options (&opts
);
6390 /* Field 4, the address, is omitted (which makes the columns not
6391 line up too nicely with the headers, but the effect is relatively
6393 if (opts
.addressprint
)
6394 ui_out_field_skip (uiout
, "addr");
6396 ui_out_text (uiout
, "vfork");
6397 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6399 ui_out_text (uiout
, ", process ");
6400 ui_out_field_int (uiout
, "what",
6401 ptid_get_pid (b
->forked_inferior_pid
));
6402 ui_out_spaces (uiout
, 1);
6406 /* Implement the "print_mention" breakpoint_ops method for vfork
6410 print_mention_catch_vfork (struct breakpoint
*b
)
6412 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6415 /* Implement the "print_recreate" breakpoint_ops method for vfork
6419 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6421 fprintf_unfiltered (fp
, "catch vfork");
6424 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6426 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6430 breakpoint_hit_catch_vfork
,
6431 NULL
, /* resources_needed */
6432 NULL
, /* works_in_software_mode */
6433 print_it_catch_vfork
,
6434 print_one_catch_vfork
,
6435 NULL
, /* print_one_detail */
6436 print_mention_catch_vfork
,
6437 print_recreate_catch_vfork
6440 /* Implement the "insert" breakpoint_ops method for syscall
6444 insert_catch_syscall (struct bp_location
*bl
)
6446 struct inferior
*inf
= current_inferior ();
6448 ++inf
->total_syscalls_count
;
6449 if (!bl
->owner
->syscalls_to_be_caught
)
6450 ++inf
->any_syscall_count
;
6456 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6461 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6463 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6464 uintptr_t vec_addr_offset
6465 = old_size
* ((uintptr_t) sizeof (int));
6467 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6468 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6470 memset ((void *) vec_addr
, 0,
6471 (iter
+ 1 - old_size
) * sizeof (int));
6473 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6474 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6478 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6479 inf
->total_syscalls_count
!= 0,
6480 inf
->any_syscall_count
,
6481 VEC_length (int, inf
->syscalls_counts
),
6482 VEC_address (int, inf
->syscalls_counts
));
6485 /* Implement the "remove" breakpoint_ops method for syscall
6489 remove_catch_syscall (struct bp_location
*bl
)
6491 struct inferior
*inf
= current_inferior ();
6493 --inf
->total_syscalls_count
;
6494 if (!bl
->owner
->syscalls_to_be_caught
)
6495 --inf
->any_syscall_count
;
6501 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6505 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6506 /* Shouldn't happen. */
6508 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6509 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6513 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6514 inf
->total_syscalls_count
!= 0,
6515 inf
->any_syscall_count
,
6516 VEC_length (int, inf
->syscalls_counts
),
6518 inf
->syscalls_counts
));
6521 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6525 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6526 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6528 /* We must check if we are catching specific syscalls in this
6529 breakpoint. If we are, then we must guarantee that the called
6530 syscall is the same syscall we are catching. */
6531 int syscall_number
= 0;
6532 const struct breakpoint
*b
= bl
->owner
;
6534 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6537 /* Now, checking if the syscall is the same. */
6538 if (b
->syscalls_to_be_caught
)
6543 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6545 if (syscall_number
== iter
)
6555 /* Implement the "print_it" breakpoint_ops method for syscall
6558 static enum print_stop_action
6559 print_it_catch_syscall (struct breakpoint
*b
)
6561 /* These are needed because we want to know in which state a
6562 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6563 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6564 must print "called syscall" or "returned from syscall". */
6566 struct target_waitstatus last
;
6568 struct cleanup
*old_chain
;
6571 get_last_target_status (&ptid
, &last
);
6573 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6575 annotate_catchpoint (b
->number
);
6578 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6580 syscall_id
= xstrprintf ("'%s'", s
.name
);
6582 old_chain
= make_cleanup (xfree
, syscall_id
);
6584 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6585 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6586 b
->number
, syscall_id
);
6587 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6588 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6589 b
->number
, syscall_id
);
6591 do_cleanups (old_chain
);
6593 return PRINT_SRC_AND_LOC
;
6596 /* Implement the "print_one" breakpoint_ops method for syscall
6600 print_one_catch_syscall (struct breakpoint
*b
,
6601 struct bp_location
**last_loc
)
6603 struct value_print_options opts
;
6605 get_user_print_options (&opts
);
6606 /* Field 4, the address, is omitted (which makes the columns not
6607 line up too nicely with the headers, but the effect is relatively
6609 if (opts
.addressprint
)
6610 ui_out_field_skip (uiout
, "addr");
6613 if (b
->syscalls_to_be_caught
6614 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6615 ui_out_text (uiout
, "syscalls \"");
6617 ui_out_text (uiout
, "syscall \"");
6619 if (b
->syscalls_to_be_caught
)
6622 char *text
= xstrprintf ("%s", "");
6625 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6630 get_syscall_by_number (iter
, &s
);
6633 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6635 text
= xstrprintf ("%s%d, ", text
, iter
);
6637 /* We have to xfree the last 'text' (now stored at 'x')
6638 because xstrprintf dinamically allocates new space for it
6642 /* Remove the last comma. */
6643 text
[strlen (text
) - 2] = '\0';
6644 ui_out_field_string (uiout
, "what", text
);
6647 ui_out_field_string (uiout
, "what", "<any syscall>");
6648 ui_out_text (uiout
, "\" ");
6651 /* Implement the "print_mention" breakpoint_ops method for syscall
6655 print_mention_catch_syscall (struct breakpoint
*b
)
6657 if (b
->syscalls_to_be_caught
)
6661 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6662 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6664 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6667 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6671 get_syscall_by_number (iter
, &s
);
6674 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6676 printf_filtered (" %d", s
.number
);
6678 printf_filtered (")");
6681 printf_filtered (_("Catchpoint %d (any syscall)"),
6685 /* Implement the "print_recreate" breakpoint_ops method for syscall
6689 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6691 fprintf_unfiltered (fp
, "catch syscall");
6693 if (b
->syscalls_to_be_caught
)
6698 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6703 get_syscall_by_number (iter
, &s
);
6705 fprintf_unfiltered (fp
, " %s", s
.name
);
6707 fprintf_unfiltered (fp
, " %d", s
.number
);
6712 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6714 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6716 insert_catch_syscall
,
6717 remove_catch_syscall
,
6718 breakpoint_hit_catch_syscall
,
6719 NULL
, /* resources_needed */
6720 NULL
, /* works_in_software_mode */
6721 print_it_catch_syscall
,
6722 print_one_catch_syscall
,
6723 NULL
, /* print_one_detail */
6724 print_mention_catch_syscall
,
6725 print_recreate_catch_syscall
6728 /* Returns non-zero if 'b' is a syscall catchpoint. */
6731 syscall_catchpoint_p (struct breakpoint
*b
)
6733 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6736 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6737 but does NOT mention it nor update the global location list.
6738 This is useful if you need to fill more fields in the
6739 struct breakpoint before calling mention.
6741 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6742 If COND_STRING is not NULL, then store it in the breakpoint.
6743 OPS, if not NULL, is the breakpoint_ops structure associated
6744 to the catchpoint. */
6746 static struct breakpoint
*
6747 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6749 struct breakpoint_ops
*ops
)
6751 struct symtab_and_line sal
;
6752 struct breakpoint
*b
;
6755 sal
.pspace
= current_program_space
;
6757 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6758 set_breakpoint_count (breakpoint_count
+ 1);
6759 b
->number
= breakpoint_count
;
6761 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6763 b
->addr_string
= NULL
;
6764 b
->enable_state
= bp_enabled
;
6765 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6771 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6773 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6774 If COND_STRING is not NULL, then store it in the breakpoint.
6775 OPS, if not NULL, is the breakpoint_ops structure associated
6776 to the catchpoint. */
6778 static struct breakpoint
*
6779 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6780 char *cond_string
, struct breakpoint_ops
*ops
)
6782 struct breakpoint
*b
=
6783 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6786 observer_notify_breakpoint_created (b
);
6787 update_global_location_list (1);
6793 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6794 int tempflag
, char *cond_string
,
6795 struct breakpoint_ops
*ops
)
6797 struct breakpoint
*b
6798 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6800 /* FIXME: We should put this information in a breakpoint private data
6802 b
->forked_inferior_pid
= null_ptid
;
6805 /* Exec catchpoints. */
6808 insert_catch_exec (struct bp_location
*bl
)
6810 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6814 remove_catch_exec (struct bp_location
*bl
)
6816 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6820 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6821 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6823 return inferior_has_execd (inferior_ptid
, &bl
->owner
->exec_pathname
);
6826 static enum print_stop_action
6827 print_it_catch_exec (struct breakpoint
*b
)
6829 annotate_catchpoint (b
->number
);
6830 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6832 return PRINT_SRC_AND_LOC
;
6836 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6838 struct value_print_options opts
;
6840 get_user_print_options (&opts
);
6842 /* Field 4, the address, is omitted (which makes the columns
6843 not line up too nicely with the headers, but the effect
6844 is relatively readable). */
6845 if (opts
.addressprint
)
6846 ui_out_field_skip (uiout
, "addr");
6848 ui_out_text (uiout
, "exec");
6849 if (b
->exec_pathname
!= NULL
)
6851 ui_out_text (uiout
, ", program \"");
6852 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6853 ui_out_text (uiout
, "\" ");
6858 print_mention_catch_exec (struct breakpoint
*b
)
6860 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6863 /* Implement the "print_recreate" breakpoint_ops method for exec
6867 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6869 fprintf_unfiltered (fp
, "catch exec");
6872 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6876 breakpoint_hit_catch_exec
,
6877 NULL
, /* resources_needed */
6878 NULL
, /* works_in_software_mode */
6879 print_it_catch_exec
,
6880 print_one_catch_exec
,
6881 NULL
, /* print_one_detail */
6882 print_mention_catch_exec
,
6883 print_recreate_catch_exec
6887 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6888 struct breakpoint_ops
*ops
)
6890 struct gdbarch
*gdbarch
= get_current_arch ();
6891 struct breakpoint
*b
=
6892 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6894 b
->syscalls_to_be_caught
= filter
;
6896 /* Now, we have to mention the breakpoint and update the global
6899 observer_notify_breakpoint_created (b
);
6900 update_global_location_list (1);
6904 hw_breakpoint_used_count (void)
6907 struct breakpoint
*b
;
6908 struct bp_location
*bl
;
6912 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6913 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6915 /* Special types of hardware breakpoints may use more than
6917 if (b
->ops
&& b
->ops
->resources_needed
)
6918 i
+= b
->ops
->resources_needed (bl
);
6928 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6931 struct breakpoint
*b
;
6932 struct bp_location
*bl
;
6934 *other_type_used
= 0;
6937 if (!breakpoint_enabled (b
))
6940 if (b
->type
== type
)
6941 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6943 /* Special types of hardware watchpoints may use more than
6945 if (b
->ops
&& b
->ops
->resources_needed
)
6946 i
+= b
->ops
->resources_needed (bl
);
6950 else if (is_hardware_watchpoint (b
))
6951 *other_type_used
= 1;
6958 disable_watchpoints_before_interactive_call_start (void)
6960 struct breakpoint
*b
;
6964 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6966 b
->enable_state
= bp_call_disabled
;
6967 update_global_location_list (0);
6973 enable_watchpoints_after_interactive_call_stop (void)
6975 struct breakpoint
*b
;
6979 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6981 b
->enable_state
= bp_enabled
;
6982 update_global_location_list (1);
6988 disable_breakpoints_before_startup (void)
6990 struct breakpoint
*b
;
6995 if (b
->pspace
!= current_program_space
)
6998 if ((b
->type
== bp_breakpoint
6999 || b
->type
== bp_hardware_breakpoint
)
7000 && breakpoint_enabled (b
))
7002 b
->enable_state
= bp_startup_disabled
;
7008 update_global_location_list (0);
7010 current_program_space
->executing_startup
= 1;
7014 enable_breakpoints_after_startup (void)
7016 struct breakpoint
*b
;
7019 current_program_space
->executing_startup
= 0;
7023 if (b
->pspace
!= current_program_space
)
7026 if ((b
->type
== bp_breakpoint
7027 || b
->type
== bp_hardware_breakpoint
)
7028 && b
->enable_state
== bp_startup_disabled
)
7030 b
->enable_state
= bp_enabled
;
7036 breakpoint_re_set ();
7040 /* Set a breakpoint that will evaporate an end of command
7041 at address specified by SAL.
7042 Restrict it to frame FRAME if FRAME is nonzero. */
7045 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7046 struct frame_id frame_id
, enum bptype type
)
7048 struct breakpoint
*b
;
7050 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7052 gdb_assert (!frame_id_inlined_p (frame_id
));
7054 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7055 b
->enable_state
= bp_enabled
;
7056 b
->disposition
= disp_donttouch
;
7057 b
->frame_id
= frame_id
;
7059 /* If we're debugging a multi-threaded program, then we want
7060 momentary breakpoints to be active in only a single thread of
7062 if (in_thread_list (inferior_ptid
))
7063 b
->thread
= pid_to_thread_id (inferior_ptid
);
7065 update_global_location_list_nothrow (1);
7070 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7074 clone_momentary_breakpoint (struct breakpoint
*orig
)
7076 struct breakpoint
*copy
;
7078 /* If there's nothing to clone, then return nothing. */
7082 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
7083 copy
->loc
= allocate_bp_location (copy
);
7084 set_breakpoint_location_function (copy
->loc
, 1);
7086 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7087 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7088 copy
->loc
->address
= orig
->loc
->address
;
7089 copy
->loc
->section
= orig
->loc
->section
;
7090 copy
->loc
->pspace
= orig
->loc
->pspace
;
7092 if (orig
->source_file
== NULL
)
7093 copy
->source_file
= NULL
;
7095 copy
->source_file
= xstrdup (orig
->source_file
);
7097 copy
->line_number
= orig
->line_number
;
7098 copy
->frame_id
= orig
->frame_id
;
7099 copy
->thread
= orig
->thread
;
7100 copy
->pspace
= orig
->pspace
;
7102 copy
->enable_state
= bp_enabled
;
7103 copy
->disposition
= disp_donttouch
;
7104 copy
->number
= internal_breakpoint_number
--;
7106 update_global_location_list_nothrow (0);
7111 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7114 struct symtab_and_line sal
;
7116 sal
= find_pc_line (pc
, 0);
7118 sal
.section
= find_pc_overlay (pc
);
7119 sal
.explicit_pc
= 1;
7121 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7125 /* Tell the user we have just set a breakpoint B. */
7128 mention (struct breakpoint
*b
)
7131 struct cleanup
*ui_out_chain
;
7132 struct value_print_options opts
;
7134 get_user_print_options (&opts
);
7136 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
7137 b
->ops
->print_mention (b
);
7142 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
7146 ui_out_text (uiout
, "Watchpoint ");
7147 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
7148 ui_out_field_int (uiout
, "number", b
->number
);
7149 ui_out_text (uiout
, ": ");
7150 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7151 do_cleanups (ui_out_chain
);
7153 case bp_hardware_watchpoint
:
7154 ui_out_text (uiout
, "Hardware watchpoint ");
7155 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
7156 ui_out_field_int (uiout
, "number", b
->number
);
7157 ui_out_text (uiout
, ": ");
7158 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7159 do_cleanups (ui_out_chain
);
7161 case bp_read_watchpoint
:
7162 ui_out_text (uiout
, "Hardware read watchpoint ");
7163 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
7164 ui_out_field_int (uiout
, "number", b
->number
);
7165 ui_out_text (uiout
, ": ");
7166 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7167 do_cleanups (ui_out_chain
);
7169 case bp_access_watchpoint
:
7170 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
7171 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
7172 ui_out_field_int (uiout
, "number", b
->number
);
7173 ui_out_text (uiout
, ": ");
7174 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7175 do_cleanups (ui_out_chain
);
7178 case bp_gnu_ifunc_resolver
:
7179 if (ui_out_is_mi_like_p (uiout
))
7184 if (b
->disposition
== disp_del
)
7185 printf_filtered (_("Temporary breakpoint"));
7187 printf_filtered (_("Breakpoint"));
7188 printf_filtered (_(" %d"), b
->number
);
7189 if (b
->type
== bp_gnu_ifunc_resolver
)
7190 printf_filtered (_(" at gnu-indirect-function resolver"));
7193 case bp_hardware_breakpoint
:
7194 if (ui_out_is_mi_like_p (uiout
))
7199 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
7203 if (ui_out_is_mi_like_p (uiout
))
7208 printf_filtered (_("Tracepoint"));
7209 printf_filtered (_(" %d"), b
->number
);
7212 case bp_fast_tracepoint
:
7213 if (ui_out_is_mi_like_p (uiout
))
7218 printf_filtered (_("Fast tracepoint"));
7219 printf_filtered (_(" %d"), b
->number
);
7222 case bp_static_tracepoint
:
7223 if (ui_out_is_mi_like_p (uiout
))
7228 printf_filtered (_("Static tracepoint"));
7229 printf_filtered (_(" %d"), b
->number
);
7236 case bp_longjmp_resume
:
7238 case bp_exception_resume
:
7239 case bp_step_resume
:
7241 case bp_std_terminate
:
7242 case bp_watchpoint_scope
:
7243 case bp_shlib_event
:
7244 case bp_thread_event
:
7245 case bp_overlay_event
:
7247 case bp_longjmp_master
:
7248 case bp_std_terminate_master
:
7249 case bp_exception_master
:
7250 case bp_gnu_ifunc_resolver_return
:
7256 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7260 printf_filtered (_(" (%s) pending."), b
->addr_string
);
7264 if (opts
.addressprint
|| b
->source_file
== NULL
)
7266 printf_filtered (" at ");
7267 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
7271 printf_filtered (": file %s, line %d.",
7272 b
->source_file
, b
->line_number
);
7276 struct bp_location
*loc
= b
->loc
;
7278 for (; loc
; loc
= loc
->next
)
7280 printf_filtered (" (%d locations)", n
);
7285 if (ui_out_is_mi_like_p (uiout
))
7287 printf_filtered ("\n");
7291 static struct bp_location
*
7292 add_location_to_breakpoint (struct breakpoint
*b
,
7293 const struct symtab_and_line
*sal
)
7295 struct bp_location
*loc
, **tmp
;
7297 loc
= allocate_bp_location (b
);
7298 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7301 loc
->gdbarch
= get_sal_arch (*sal
);
7303 loc
->gdbarch
= b
->gdbarch
;
7304 loc
->requested_address
= sal
->pc
;
7305 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7306 loc
->requested_address
, b
->type
);
7307 loc
->pspace
= sal
->pspace
;
7308 gdb_assert (loc
->pspace
!= NULL
);
7309 loc
->section
= sal
->section
;
7311 set_breakpoint_location_function (loc
,
7312 sal
->explicit_pc
|| sal
->explicit_line
);
7317 /* Return 1 if LOC is pointing to a permanent breakpoint,
7318 return 0 otherwise. */
7321 bp_loc_is_permanent (struct bp_location
*loc
)
7325 const gdb_byte
*brk
;
7326 gdb_byte
*target_mem
;
7327 struct cleanup
*cleanup
;
7330 gdb_assert (loc
!= NULL
);
7332 addr
= loc
->address
;
7333 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7335 /* Software breakpoints unsupported? */
7339 target_mem
= alloca (len
);
7341 /* Enable the automatic memory restoration from breakpoints while
7342 we read the memory. Otherwise we could say about our temporary
7343 breakpoints they are permanent. */
7344 cleanup
= save_current_space_and_thread ();
7346 switch_to_program_space_and_thread (loc
->pspace
);
7347 make_show_memory_breakpoints_cleanup (0);
7349 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7350 && memcmp (target_mem
, brk
, len
) == 0)
7353 do_cleanups (cleanup
);
7360 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7361 as textual description of the location, and COND_STRING
7362 as condition expression. */
7365 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7366 struct symtabs_and_lines sals
, char *addr_string
,
7368 enum bptype type
, enum bpdisp disposition
,
7369 int thread
, int task
, int ignore_count
,
7370 struct breakpoint_ops
*ops
, int from_tty
,
7371 int enabled
, int internal
, int display_canonical
)
7373 struct breakpoint
*b
= NULL
;
7376 if (type
== bp_hardware_breakpoint
)
7378 int i
= hw_breakpoint_used_count ();
7379 int target_resources_ok
=
7380 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7382 if (target_resources_ok
== 0)
7383 error (_("No hardware breakpoint support in the target."));
7384 else if (target_resources_ok
< 0)
7385 error (_("Hardware breakpoints used exceeds limit."));
7388 gdb_assert (sals
.nelts
> 0);
7390 for (i
= 0; i
< sals
.nelts
; ++i
)
7392 struct symtab_and_line sal
= sals
.sals
[i
];
7393 struct bp_location
*loc
;
7397 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7399 loc_gdbarch
= gdbarch
;
7401 describe_other_breakpoints (loc_gdbarch
,
7402 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7407 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7408 set_breakpoint_number (internal
, b
);
7412 b
->cond_string
= cond_string
;
7413 b
->ignore_count
= ignore_count
;
7414 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7415 b
->disposition
= disposition
;
7416 b
->pspace
= sals
.sals
[0].pspace
;
7418 if (type
== bp_static_tracepoint
)
7420 struct static_tracepoint_marker marker
;
7422 if (is_marker_spec (addr_string
))
7424 /* We already know the marker exists, otherwise, we
7425 wouldn't see a sal for it. */
7426 char *p
= &addr_string
[3];
7431 p
= skip_spaces (p
);
7433 endp
= skip_to_space (p
);
7435 marker_str
= savestring (p
, endp
- p
);
7436 b
->static_trace_marker_id
= marker_str
;
7438 printf_filtered (_("Probed static tracepoint "
7440 b
->static_trace_marker_id
);
7442 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7444 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7445 release_static_tracepoint_marker (&marker
);
7447 printf_filtered (_("Probed static tracepoint "
7449 b
->static_trace_marker_id
);
7452 warning (_("Couldn't determine the static "
7453 "tracepoint marker to probe"));
7456 if (enabled
&& b
->pspace
->executing_startup
7457 && (b
->type
== bp_breakpoint
7458 || b
->type
== bp_hardware_breakpoint
))
7459 b
->enable_state
= bp_startup_disabled
;
7465 loc
= add_location_to_breakpoint (b
, &sal
);
7468 if (bp_loc_is_permanent (loc
))
7469 make_breakpoint_permanent (b
);
7473 char *arg
= b
->cond_string
;
7474 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7476 error (_("Garbage %s follows condition"), arg
);
7480 b
->display_canonical
= display_canonical
;
7482 b
->addr_string
= addr_string
;
7484 /* addr_string has to be used or breakpoint_re_set will delete
7487 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7490 /* Do not mention breakpoints with a negative number, but do
7491 notify observers. */
7494 observer_notify_breakpoint_created (b
);
7497 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7498 elements to fill the void space. */
7500 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7502 int i
= index_to_remove
+1;
7503 int last_index
= sal
->nelts
-1;
7505 for (;i
<= last_index
; ++i
)
7506 sal
->sals
[i
-1] = sal
->sals
[i
];
7511 /* If appropriate, obtains all sals that correspond to the same file
7512 and line as SAL, in all program spaces. Users debugging with IDEs,
7513 will want to set a breakpoint at foo.c:line, and not really care
7514 about program spaces. This is done only if SAL does not have
7515 explicit PC and has line and file information. If we got just a
7516 single expanded sal, return the original.
7518 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7519 which the name of enclosing function is different from SAL. This
7520 makes sure that if we have breakpoint originally set in template
7521 instantiation, say foo<int>(), we won't expand SAL to locations at
7522 the same line in all existing instantiations of 'foo'. */
7524 static struct symtabs_and_lines
7525 expand_line_sal_maybe (struct symtab_and_line sal
)
7527 struct symtabs_and_lines expanded
;
7528 CORE_ADDR original_pc
= sal
.pc
;
7529 char *original_function
= NULL
;
7532 struct cleanup
*old_chain
;
7534 /* If we have explicit pc, don't expand.
7535 If we have no line number, we can't expand. */
7536 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7539 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7540 expanded
.sals
[0] = sal
;
7546 old_chain
= save_current_space_and_thread ();
7548 switch_to_program_space_and_thread (sal
.pspace
);
7550 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7552 /* Note that expand_line_sal visits *all* program spaces. */
7553 expanded
= expand_line_sal (sal
);
7555 if (expanded
.nelts
== 1)
7557 /* We had one sal, we got one sal. Return that sal, adjusting it
7558 past the function prologue if necessary. */
7559 xfree (expanded
.sals
);
7561 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7562 sal
.pc
= original_pc
;
7563 expanded
.sals
[0] = sal
;
7564 skip_prologue_sal (&expanded
.sals
[0]);
7565 do_cleanups (old_chain
);
7569 if (!sal
.explicit_line
)
7571 CORE_ADDR func_addr
, func_end
;
7572 for (i
= 0; i
< expanded
.nelts
; ++i
)
7574 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7575 char *this_function
;
7577 /* We need to switch threads as well since we're about to
7579 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7581 if (find_pc_partial_function (pc
, &this_function
,
7582 &func_addr
, &func_end
))
7585 && strcmp (this_function
, original_function
) != 0)
7587 remove_sal (&expanded
, i
);
7594 /* Skip the function prologue if necessary. */
7595 for (i
= 0; i
< expanded
.nelts
; ++i
)
7596 skip_prologue_sal (&expanded
.sals
[i
]);
7598 do_cleanups (old_chain
);
7600 if (expanded
.nelts
<= 1)
7602 /* This is un ugly workaround. If we get zero expanded sals
7603 then something is really wrong. Fix that by returning the
7606 xfree (expanded
.sals
);
7608 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7609 sal
.pc
= original_pc
;
7610 expanded
.sals
[0] = sal
;
7617 for (i
= 0; i
< expanded
.nelts
; ++i
)
7618 if (expanded
.sals
[i
].pc
== original_pc
)
7629 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7630 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7631 value. COND_STRING, if not NULL, specified the condition to be
7632 used for all breakpoints. Essentially the only case where
7633 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7634 function. In that case, it's still not possible to specify
7635 separate conditions for different overloaded functions, so
7636 we take just a single condition string.
7638 NOTE: If the function succeeds, the caller is expected to cleanup
7639 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7640 array contents). If the function fails (error() is called), the
7641 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7642 COND and SALS arrays and each of those arrays contents. */
7645 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7646 struct symtabs_and_lines sals
,
7647 struct linespec_result
*canonical
,
7649 enum bptype type
, enum bpdisp disposition
,
7650 int thread
, int task
, int ignore_count
,
7651 struct breakpoint_ops
*ops
, int from_tty
,
7652 int enabled
, int internal
)
7656 for (i
= 0; i
< sals
.nelts
; ++i
)
7658 struct symtabs_and_lines expanded
=
7659 expand_line_sal_maybe (sals
.sals
[i
]);
7661 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7662 cond_string
, type
, disposition
,
7663 thread
, task
, ignore_count
, ops
,
7664 from_tty
, enabled
, internal
,
7665 canonical
->special_display
);
7669 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7670 followed by conditionals. On return, SALS contains an array of SAL
7671 addresses found. ADDR_STRING contains a vector of (canonical)
7672 address strings. ADDRESS points to the end of the SAL.
7674 The array and the line spec strings are allocated on the heap, it is
7675 the caller's responsibility to free them. */
7678 parse_breakpoint_sals (char **address
,
7679 struct symtabs_and_lines
*sals
,
7680 struct linespec_result
*canonical
)
7682 char *addr_start
= *address
;
7684 /* If no arg given, or if first arg is 'if ', use the default
7686 if ((*address
) == NULL
7687 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7689 if (default_breakpoint_valid
)
7691 struct symtab_and_line sal
;
7693 init_sal (&sal
); /* Initialize to zeroes. */
7694 sals
->sals
= (struct symtab_and_line
*)
7695 xmalloc (sizeof (struct symtab_and_line
));
7696 sal
.pc
= default_breakpoint_address
;
7697 sal
.line
= default_breakpoint_line
;
7698 sal
.symtab
= default_breakpoint_symtab
;
7699 sal
.pspace
= default_breakpoint_pspace
;
7700 sal
.section
= find_pc_overlay (sal
.pc
);
7702 /* "break" without arguments is equivalent to "break *PC"
7703 where PC is the default_breakpoint_address. So make sure
7704 to set sal.explicit_pc to prevent GDB from trying to
7705 expand the list of sals to include all other instances
7706 with the same symtab and line. */
7707 sal
.explicit_pc
= 1;
7709 sals
->sals
[0] = sal
;
7713 error (_("No default breakpoint address now."));
7717 /* Force almost all breakpoints to be in terms of the
7718 current_source_symtab (which is decode_line_1's default).
7719 This should produce the results we want almost all of the
7720 time while leaving default_breakpoint_* alone.
7722 ObjC: However, don't match an Objective-C method name which
7723 may have a '+' or '-' succeeded by a '[' */
7725 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7727 if (default_breakpoint_valid
7729 || ((strchr ("+-", (*address
)[0]) != NULL
)
7730 && ((*address
)[1] != '['))))
7731 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7732 default_breakpoint_line
, canonical
);
7734 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7737 /* For any SAL that didn't have a canonical string, fill one in. */
7738 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7739 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7740 if (addr_start
!= (*address
))
7744 for (i
= 0; i
< sals
->nelts
; i
++)
7746 /* Add the string if not present. */
7747 if (canonical
->canonical
[i
] == NULL
)
7748 canonical
->canonical
[i
] = savestring (addr_start
,
7749 (*address
) - addr_start
);
7755 /* Convert each SAL into a real PC. Verify that the PC can be
7756 inserted as a breakpoint. If it can't throw an error. */
7759 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7763 for (i
= 0; i
< sals
->nelts
; i
++)
7764 resolve_sal_pc (&sals
->sals
[i
]);
7767 /* Fast tracepoints may have restrictions on valid locations. For
7768 instance, a fast tracepoint using a jump instead of a trap will
7769 likely have to overwrite more bytes than a trap would, and so can
7770 only be placed where the instruction is longer than the jump, or a
7771 multi-instruction sequence does not have a jump into the middle of
7775 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7776 struct symtabs_and_lines
*sals
)
7779 struct symtab_and_line
*sal
;
7781 struct cleanup
*old_chain
;
7783 for (i
= 0; i
< sals
->nelts
; i
++)
7785 sal
= &sals
->sals
[i
];
7787 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7789 old_chain
= make_cleanup (xfree
, msg
);
7792 error (_("May not have a fast tracepoint at 0x%s%s"),
7793 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7795 do_cleanups (old_chain
);
7799 /* Given TOK, a string specification of condition and thread, as
7800 accepted by the 'break' command, extract the condition
7801 string and thread number and set *COND_STRING and *THREAD.
7802 PC identifies the context at which the condition should be parsed.
7803 If no condition is found, *COND_STRING is set to NULL.
7804 If no thread is found, *THREAD is set to -1. */
7806 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7807 char **cond_string
, int *thread
, int *task
)
7809 *cond_string
= NULL
;
7815 char *cond_start
= NULL
;
7816 char *cond_end
= NULL
;
7818 tok
= skip_spaces (tok
);
7820 end_tok
= skip_to_space (tok
);
7822 toklen
= end_tok
- tok
;
7824 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7826 struct expression
*expr
;
7828 tok
= cond_start
= end_tok
+ 1;
7829 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7832 *cond_string
= savestring (cond_start
,
7833 cond_end
- cond_start
);
7835 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7841 *thread
= strtol (tok
, &tok
, 0);
7843 error (_("Junk after thread keyword."));
7844 if (!valid_thread_id (*thread
))
7845 error (_("Unknown thread %d."), *thread
);
7847 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7853 *task
= strtol (tok
, &tok
, 0);
7855 error (_("Junk after task keyword."));
7856 if (!valid_task_id (*task
))
7857 error (_("Unknown task %d."), *task
);
7860 error (_("Junk at end of arguments."));
7864 /* Decode a static tracepoint marker spec. */
7866 static struct symtabs_and_lines
7867 decode_static_tracepoint_spec (char **arg_p
)
7869 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7870 struct symtabs_and_lines sals
;
7871 struct symtab_and_line sal
;
7873 struct cleanup
*old_chain
;
7874 char *p
= &(*arg_p
)[3];
7879 p
= skip_spaces (p
);
7881 endp
= skip_to_space (p
);
7883 marker_str
= savestring (p
, endp
- p
);
7884 old_chain
= make_cleanup (xfree
, marker_str
);
7886 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7887 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7888 error (_("No known static tracepoint marker named %s"), marker_str
);
7890 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7891 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7893 for (i
= 0; i
< sals
.nelts
; i
++)
7895 struct static_tracepoint_marker
*marker
;
7897 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7899 init_sal (&sals
.sals
[i
]);
7901 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7902 sals
.sals
[i
].pc
= marker
->address
;
7904 release_static_tracepoint_marker (marker
);
7907 do_cleanups (old_chain
);
7913 /* Set a breakpoint. This function is shared between CLI and MI
7914 functions for setting a breakpoint. This function has two major
7915 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7916 parameter. If non-zero, the function will parse arg, extracting
7917 breakpoint location, address and thread. Otherwise, ARG is just
7918 the location of breakpoint, with condition and thread specified by
7919 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7920 the breakpoint number will be allocated from the internal
7921 breakpoint count. Returns true if any breakpoint was created;
7925 create_breakpoint (struct gdbarch
*gdbarch
,
7926 char *arg
, char *cond_string
, int thread
,
7927 int parse_condition_and_thread
,
7928 int tempflag
, enum bptype type_wanted
,
7930 enum auto_boolean pending_break_support
,
7931 struct breakpoint_ops
*ops
,
7932 int from_tty
, int enabled
, int internal
)
7934 volatile struct gdb_exception e
;
7935 struct symtabs_and_lines sals
;
7936 struct symtab_and_line pending_sal
;
7938 char *addr_start
= arg
;
7939 struct linespec_result canonical
;
7940 struct cleanup
*old_chain
;
7941 struct cleanup
*bkpt_chain
= NULL
;
7945 int prev_bkpt_count
= breakpoint_count
;
7949 init_linespec_result (&canonical
);
7951 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7955 sals
= decode_static_tracepoint_spec (&arg
);
7957 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7958 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7959 for (i
= 0; i
< sals
.nelts
; i
++)
7960 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7964 TRY_CATCH (e
, RETURN_MASK_ALL
)
7966 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7969 /* If caller is interested in rc value from parse, set value. */
7973 throw_exception (e
);
7977 case NOT_FOUND_ERROR
:
7979 /* If pending breakpoint support is turned off, throw
7982 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7983 throw_exception (e
);
7985 exception_print (gdb_stderr
, e
);
7987 /* If pending breakpoint support is auto query and the user
7988 selects no, then simply return the error code. */
7989 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7990 && !nquery (_("Make breakpoint pending on "
7991 "future shared library load? ")))
7994 /* At this point, either the user was queried about setting
7995 a pending breakpoint and selected yes, or pending
7996 breakpoint behavior is on and thus a pending breakpoint
7997 is defaulted on behalf of the user. */
7998 copy_arg
= xstrdup (addr_start
);
7999 canonical
.canonical
= ©_arg
;
8001 sals
.sals
= &pending_sal
;
8006 throw_exception (e
);
8016 /* Create a chain of things that always need to be cleaned up. */
8017 old_chain
= make_cleanup (null_cleanup
, 0);
8021 /* Make sure that all storage allocated to SALS gets freed. */
8022 make_cleanup (xfree
, sals
.sals
);
8024 /* Cleanup the canonical array but not its contents. */
8025 make_cleanup (xfree
, canonical
.canonical
);
8028 /* ----------------------------- SNIP -----------------------------
8029 Anything added to the cleanup chain beyond this point is assumed
8030 to be part of a breakpoint. If the breakpoint create succeeds
8031 then the memory is not reclaimed. */
8032 bkpt_chain
= make_cleanup (null_cleanup
, 0);
8034 /* Mark the contents of the canonical for cleanup. These go on
8035 the bkpt_chain and only occur if the breakpoint create fails. */
8036 for (i
= 0; i
< sals
.nelts
; i
++)
8038 if (canonical
.canonical
[i
] != NULL
)
8039 make_cleanup (xfree
, canonical
.canonical
[i
]);
8042 /* Resolve all line numbers to PC's and verify that the addresses
8043 are ok for the target. */
8045 breakpoint_sals_to_pc (&sals
);
8047 /* Fast tracepoints may have additional restrictions on location. */
8048 if (type_wanted
== bp_fast_tracepoint
)
8049 check_fast_tracepoint_sals (gdbarch
, &sals
);
8051 /* Verify that condition can be parsed, before setting any
8052 breakpoints. Allocate a separate condition expression for each
8056 if (parse_condition_and_thread
)
8058 /* Here we only parse 'arg' to separate condition
8059 from thread number, so parsing in context of first
8060 sal is OK. When setting the breakpoint we'll
8061 re-parse it in context of each sal. */
8064 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
8067 make_cleanup (xfree
, cond_string
);
8071 /* Create a private copy of condition string. */
8074 cond_string
= xstrdup (cond_string
);
8075 make_cleanup (xfree
, cond_string
);
8079 /* If the user is creating a static tracepoint by marker id
8080 (strace -m MARKER_ID), then store the sals index, so that
8081 breakpoint_re_set can try to match up which of the newly
8082 found markers corresponds to this one, and, don't try to
8083 expand multiple locations for each sal, given than SALS
8084 already should contain all sals for MARKER_ID. */
8085 if (type_wanted
== bp_static_tracepoint
8086 && is_marker_spec (canonical
.canonical
[0]))
8090 for (i
= 0; i
< sals
.nelts
; ++i
)
8092 struct symtabs_and_lines expanded
;
8093 struct breakpoint
*tp
;
8094 struct cleanup
*old_chain
;
8097 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
8098 expanded
.sals
[0] = sals
.sals
[i
];
8099 old_chain
= make_cleanup (xfree
, expanded
.sals
);
8101 create_breakpoint_sal (gdbarch
, expanded
, canonical
.canonical
[i
],
8102 cond_string
, type_wanted
,
8103 tempflag
? disp_del
: disp_donttouch
,
8104 thread
, task
, ignore_count
, ops
,
8105 from_tty
, enabled
, internal
,
8106 canonical
.special_display
);
8108 do_cleanups (old_chain
);
8110 /* Get the tracepoint we just created. */
8112 tp
= get_breakpoint (internal_breakpoint_number
);
8114 tp
= get_breakpoint (breakpoint_count
);
8115 gdb_assert (tp
!= NULL
);
8117 /* Given that its possible to have multiple markers with
8118 the same string id, if the user is creating a static
8119 tracepoint by marker id ("strace -m MARKER_ID"), then
8120 store the sals index, so that breakpoint_re_set can
8121 try to match up which of the newly found markers
8122 corresponds to this one */
8123 tp
->static_trace_marker_id_idx
= i
;
8127 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
8129 tempflag
? disp_del
: disp_donttouch
,
8130 thread
, task
, ignore_count
, ops
, from_tty
,
8135 struct breakpoint
*b
;
8137 make_cleanup (xfree
, copy_arg
);
8139 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
8140 set_breakpoint_number (internal
, b
);
8142 b
->addr_string
= canonical
.canonical
[0];
8143 b
->cond_string
= NULL
;
8144 b
->ignore_count
= ignore_count
;
8145 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8146 b
->condition_not_parsed
= 1;
8148 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8149 b
->pspace
= current_program_space
;
8150 b
->py_bp_object
= NULL
;
8152 if (enabled
&& b
->pspace
->executing_startup
8153 && (b
->type
== bp_breakpoint
8154 || b
->type
== bp_hardware_breakpoint
))
8155 b
->enable_state
= bp_startup_disabled
;
8158 /* Do not mention breakpoints with a negative number,
8159 but do notify observers. */
8161 observer_notify_breakpoint_created (b
);
8166 warning (_("Multiple breakpoints were set.\nUse the "
8167 "\"delete\" command to delete unwanted breakpoints."));
8168 prev_breakpoint_count
= prev_bkpt_count
;
8171 /* That's it. Discard the cleanups for data inserted into the
8173 discard_cleanups (bkpt_chain
);
8174 /* But cleanup everything else. */
8175 do_cleanups (old_chain
);
8177 /* error call may happen here - have BKPT_CHAIN already discarded. */
8178 update_global_location_list (1);
8183 /* Set a breakpoint.
8184 ARG is a string describing breakpoint address,
8185 condition, and thread.
8186 FLAG specifies if a breakpoint is hardware on,
8187 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8191 break_command_1 (char *arg
, int flag
, int from_tty
)
8193 int tempflag
= flag
& BP_TEMPFLAG
;
8194 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8195 ? bp_hardware_breakpoint
8198 create_breakpoint (get_current_arch (),
8200 NULL
, 0, 1 /* parse arg */,
8201 tempflag
, type_wanted
,
8202 0 /* Ignore count */,
8203 pending_break_support
,
8204 NULL
/* breakpoint_ops */,
8211 /* Helper function for break_command_1 and disassemble_command. */
8214 resolve_sal_pc (struct symtab_and_line
*sal
)
8218 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8220 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8221 error (_("No line %d in file \"%s\"."),
8222 sal
->line
, sal
->symtab
->filename
);
8225 /* If this SAL corresponds to a breakpoint inserted using a line
8226 number, then skip the function prologue if necessary. */
8227 if (sal
->explicit_line
)
8228 skip_prologue_sal (sal
);
8231 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8233 struct blockvector
*bv
;
8237 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8240 sym
= block_linkage_function (b
);
8243 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8244 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8248 /* It really is worthwhile to have the section, so we'll
8249 just have to look harder. This case can be executed
8250 if we have line numbers but no functions (as can
8251 happen in assembly source). */
8253 struct minimal_symbol
*msym
;
8254 struct cleanup
*old_chain
= save_current_space_and_thread ();
8256 switch_to_program_space_and_thread (sal
->pspace
);
8258 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8260 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8262 do_cleanups (old_chain
);
8269 break_command (char *arg
, int from_tty
)
8271 break_command_1 (arg
, 0, from_tty
);
8275 tbreak_command (char *arg
, int from_tty
)
8277 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8281 hbreak_command (char *arg
, int from_tty
)
8283 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8287 thbreak_command (char *arg
, int from_tty
)
8289 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8293 stop_command (char *arg
, int from_tty
)
8295 printf_filtered (_("Specify the type of breakpoint to set.\n\
8296 Usage: stop in <function | address>\n\
8297 stop at <line>\n"));
8301 stopin_command (char *arg
, int from_tty
)
8305 if (arg
== (char *) NULL
)
8307 else if (*arg
!= '*')
8312 /* Look for a ':'. If this is a line number specification, then
8313 say it is bad, otherwise, it should be an address or
8314 function/method name. */
8315 while (*argptr
&& !hasColon
)
8317 hasColon
= (*argptr
== ':');
8322 badInput
= (*argptr
!= ':'); /* Not a class::method */
8324 badInput
= isdigit (*arg
); /* a simple line number */
8328 printf_filtered (_("Usage: stop in <function | address>\n"));
8330 break_command_1 (arg
, 0, from_tty
);
8334 stopat_command (char *arg
, int from_tty
)
8338 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8345 /* Look for a ':'. If there is a '::' then get out, otherwise
8346 it is probably a line number. */
8347 while (*argptr
&& !hasColon
)
8349 hasColon
= (*argptr
== ':');
8354 badInput
= (*argptr
== ':'); /* we have class::method */
8356 badInput
= !isdigit (*arg
); /* not a line number */
8360 printf_filtered (_("Usage: stop at <line>\n"));
8362 break_command_1 (arg
, 0, from_tty
);
8365 /* Implement the "breakpoint_hit" breakpoint_ops method for
8366 ranged breakpoints. */
8369 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8370 struct address_space
*aspace
,
8373 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8374 bl
->length
, aspace
, bp_addr
);
8377 /* Implement the "resources_needed" breakpoint_ops method for
8378 ranged breakpoints. */
8381 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8383 return target_ranged_break_num_registers ();
8386 /* Implement the "print_it" breakpoint_ops method for
8387 ranged breakpoints. */
8389 static enum print_stop_action
8390 print_it_ranged_breakpoint (struct breakpoint
*b
)
8392 struct bp_location
*bl
= b
->loc
;
8394 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8396 /* Ranged breakpoints have only one location. */
8397 gdb_assert (bl
&& bl
->next
== NULL
);
8399 annotate_breakpoint (b
->number
);
8400 if (b
->disposition
== disp_del
)
8401 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8403 ui_out_text (uiout
, "\nRanged breakpoint ");
8404 if (ui_out_is_mi_like_p (uiout
))
8406 ui_out_field_string (uiout
, "reason",
8407 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8408 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8410 ui_out_field_int (uiout
, "bkptno", b
->number
);
8411 ui_out_text (uiout
, ", ");
8413 return PRINT_SRC_AND_LOC
;
8416 /* Implement the "print_one" breakpoint_ops method for
8417 ranged breakpoints. */
8420 print_one_ranged_breakpoint (struct breakpoint
*b
,
8421 struct bp_location
**last_loc
)
8423 struct bp_location
*bl
= b
->loc
;
8424 struct value_print_options opts
;
8426 /* Ranged breakpoints have only one location. */
8427 gdb_assert (bl
&& bl
->next
== NULL
);
8429 get_user_print_options (&opts
);
8431 if (opts
.addressprint
)
8432 /* We don't print the address range here, it will be printed later
8433 by print_one_detail_ranged_breakpoint. */
8434 ui_out_field_skip (uiout
, "addr");
8436 print_breakpoint_location (b
, bl
);
8440 /* Implement the "print_one_detail" breakpoint_ops method for
8441 ranged breakpoints. */
8444 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8445 struct ui_out
*uiout
)
8447 CORE_ADDR address_start
, address_end
;
8448 struct bp_location
*bl
= b
->loc
;
8449 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8450 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8454 address_start
= bl
->address
;
8455 address_end
= address_start
+ bl
->length
- 1;
8457 ui_out_text (uiout
, "\taddress range: ");
8458 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8459 print_core_address (bl
->gdbarch
, address_start
),
8460 print_core_address (bl
->gdbarch
, address_end
));
8461 ui_out_field_stream (uiout
, "addr", stb
);
8462 ui_out_text (uiout
, "\n");
8464 do_cleanups (cleanup
);
8467 /* Implement the "print_mention" breakpoint_ops method for
8468 ranged breakpoints. */
8471 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8473 struct bp_location
*bl
= b
->loc
;
8476 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8478 if (ui_out_is_mi_like_p (uiout
))
8481 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8482 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8483 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8486 /* Implement the "print_recreate" breakpoint_ops method for
8487 ranged breakpoints. */
8490 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8492 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8493 b
->addr_string_range_end
);
8496 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8498 static struct breakpoint_ops ranged_breakpoint_ops
=
8502 breakpoint_hit_ranged_breakpoint
,
8503 resources_needed_ranged_breakpoint
,
8504 NULL
, /* works_in_software_mode */
8505 print_it_ranged_breakpoint
,
8506 print_one_ranged_breakpoint
,
8507 print_one_detail_ranged_breakpoint
,
8508 print_mention_ranged_breakpoint
,
8509 print_recreate_ranged_breakpoint
8512 /* Find the address where the end of the breakpoint range should be
8513 placed, given the SAL of the end of the range. This is so that if
8514 the user provides a line number, the end of the range is set to the
8515 last instruction of the given line. */
8518 find_breakpoint_range_end (struct symtab_and_line sal
)
8522 /* If the user provided a PC value, use it. Otherwise,
8523 find the address of the end of the given location. */
8524 if (sal
.explicit_pc
)
8531 ret
= find_line_pc_range (sal
, &start
, &end
);
8533 error (_("Could not find location of the end of the range."));
8535 /* find_line_pc_range returns the start of the next line. */
8542 /* Implement the "break-range" CLI command. */
8545 break_range_command (char *arg
, int from_tty
)
8547 char *arg_start
, *addr_string_start
, *addr_string_end
;
8548 struct linespec_result canonical_start
, canonical_end
;
8549 int bp_count
, can_use_bp
, length
;
8551 struct breakpoint
*b
;
8552 struct symtab_and_line sal_start
, sal_end
;
8553 struct symtabs_and_lines sals_start
, sals_end
;
8554 struct cleanup
*cleanup_bkpt
;
8556 /* We don't support software ranged breakpoints. */
8557 if (target_ranged_break_num_registers () < 0)
8558 error (_("This target does not support hardware ranged breakpoints."));
8560 bp_count
= hw_breakpoint_used_count ();
8561 bp_count
+= target_ranged_break_num_registers ();
8562 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8565 error (_("Hardware breakpoints used exceeds limit."));
8567 if (arg
== NULL
|| arg
[0] == '\0')
8568 error(_("No address range specified."));
8570 sals_start
.sals
= NULL
;
8571 sals_start
.nelts
= 0;
8572 init_linespec_result (&canonical_start
);
8574 while (*arg
== ' ' || *arg
== '\t')
8577 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8579 sal_start
= sals_start
.sals
[0];
8580 addr_string_start
= canonical_start
.canonical
[0];
8581 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8582 xfree (sals_start
.sals
);
8583 xfree (canonical_start
.canonical
);
8586 error (_("Too few arguments."));
8587 else if (sals_start
.nelts
== 0)
8588 error (_("Could not find location of the beginning of the range."));
8589 else if (sals_start
.nelts
!= 1)
8590 error (_("Cannot create a ranged breakpoint with multiple locations."));
8592 resolve_sal_pc (&sal_start
);
8594 arg
++; /* Skip the comma. */
8595 while (*arg
== ' ' || *arg
== '\t')
8598 /* Parse the end location. */
8600 sals_end
.sals
= NULL
;
8602 init_linespec_result (&canonical_end
);
8605 /* We call decode_line_1 directly here instead of using
8606 parse_breakpoint_sals because we need to specify the start location's
8607 symtab and line as the default symtab and line for the end of the
8608 range. This makes it possible to have ranges like "foo.c:27, +14",
8609 where +14 means 14 lines from the start location. */
8610 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8613 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8614 if (canonical_end
.canonical
== NULL
)
8615 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8616 /* Add the string if not present. */
8617 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8618 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8620 sal_end
= sals_end
.sals
[0];
8621 addr_string_end
= canonical_end
.canonical
[0];
8622 make_cleanup (xfree
, addr_string_end
);
8623 xfree (sals_end
.sals
);
8624 xfree (canonical_end
.canonical
);
8626 if (sals_end
.nelts
== 0)
8627 error (_("Could not find location of the end of the range."));
8628 else if (sals_end
.nelts
!= 1)
8629 error (_("Cannot create a ranged breakpoint with multiple locations."));
8631 resolve_sal_pc (&sal_end
);
8633 end
= find_breakpoint_range_end (sal_end
);
8634 if (sal_start
.pc
> end
)
8635 error (_("Invalid address range, end preceeds start."));
8637 length
= end
- sal_start
.pc
+ 1;
8639 /* Length overflowed. */
8640 error (_("Address range too large."));
8641 else if (length
== 1)
8643 /* This range is simple enough to be handled by
8644 the `hbreak' command. */
8645 hbreak_command (addr_string_start
, 1);
8647 do_cleanups (cleanup_bkpt
);
8652 /* Now set up the breakpoint. */
8653 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8654 bp_hardware_breakpoint
);
8655 set_breakpoint_count (breakpoint_count
+ 1);
8656 b
->number
= breakpoint_count
;
8657 b
->disposition
= disp_donttouch
;
8658 b
->addr_string
= addr_string_start
;
8659 b
->addr_string_range_end
= addr_string_end
;
8660 b
->ops
= &ranged_breakpoint_ops
;
8661 b
->loc
->length
= length
;
8663 discard_cleanups (cleanup_bkpt
);
8666 observer_notify_breakpoint_created (b
);
8667 update_global_location_list (1);
8670 /* Return non-zero if EXP is verified as constant. Returned zero
8671 means EXP is variable. Also the constant detection may fail for
8672 some constant expressions and in such case still falsely return
8675 watchpoint_exp_is_const (const struct expression
*exp
)
8683 /* We are only interested in the descriptor of each element. */
8684 operator_length (exp
, i
, &oplenp
, &argsp
);
8687 switch (exp
->elts
[i
].opcode
)
8697 case BINOP_LOGICAL_AND
:
8698 case BINOP_LOGICAL_OR
:
8699 case BINOP_BITWISE_AND
:
8700 case BINOP_BITWISE_IOR
:
8701 case BINOP_BITWISE_XOR
:
8703 case BINOP_NOTEQUAL
:
8719 case TERNOP_SLICE_COUNT
:
8731 case OP_OBJC_NSSTRING
:
8734 case UNOP_LOGICAL_NOT
:
8735 case UNOP_COMPLEMENT
:
8738 /* Unary, binary and ternary operators: We have to check
8739 their operands. If they are constant, then so is the
8740 result of that operation. For instance, if A and B are
8741 determined to be constants, then so is "A + B".
8743 UNOP_IND is one exception to the rule above, because the
8744 value of *ADDR is not necessarily a constant, even when
8749 /* Check whether the associated symbol is a constant.
8751 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8752 possible that a buggy compiler could mark a variable as
8753 constant even when it is not, and TYPE_CONST would return
8754 true in this case, while SYMBOL_CLASS wouldn't.
8756 We also have to check for function symbols because they
8757 are always constant. */
8759 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8761 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8762 && SYMBOL_CLASS (s
) != LOC_CONST
8763 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8768 /* The default action is to return 0 because we are using
8769 the optimistic approach here: If we don't know something,
8770 then it is not a constant. */
8779 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8782 insert_watchpoint (struct bp_location
*bl
)
8784 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8786 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8787 bl
->owner
->cond_exp
);
8790 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8793 remove_watchpoint (struct bp_location
*bl
)
8795 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8797 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8798 bl
->owner
->cond_exp
);
8801 /* Implement the "resources_needed" breakpoint_ops method for
8802 hardware watchpoints. */
8805 resources_needed_watchpoint (const struct bp_location
*bl
)
8807 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8809 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8812 /* Implement the "works_in_software_mode" breakpoint_ops method for
8813 hardware watchpoints. */
8816 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8818 return b
->type
== bp_hardware_watchpoint
;
8821 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8823 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8827 NULL
, /* breakpoint_hit */
8828 resources_needed_watchpoint
,
8829 works_in_software_mode_watchpoint
,
8830 NULL
, /* print_it */
8831 NULL
, /* print_one */
8832 NULL
, /* print_one_detail */
8833 NULL
, /* print_mention */
8834 NULL
/* print_recreate */
8837 /* Implement the "insert" breakpoint_ops method for
8838 masked hardware watchpoints. */
8841 insert_masked_watchpoint (struct bp_location
*bl
)
8843 return target_insert_mask_watchpoint (bl
->address
, bl
->owner
->hw_wp_mask
,
8844 bl
->watchpoint_type
);
8847 /* Implement the "remove" breakpoint_ops method for
8848 masked hardware watchpoints. */
8851 remove_masked_watchpoint (struct bp_location
*bl
)
8853 return target_remove_mask_watchpoint (bl
->address
, bl
->owner
->hw_wp_mask
,
8854 bl
->watchpoint_type
);
8857 /* Implement the "resources_needed" breakpoint_ops method for
8858 masked hardware watchpoints. */
8861 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8863 return target_masked_watch_num_registers (bl
->address
,
8864 bl
->owner
->hw_wp_mask
);
8867 /* Implement the "works_in_software_mode" breakpoint_ops method for
8868 masked hardware watchpoints. */
8871 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8876 /* Implement the "print_it" breakpoint_ops method for
8877 masked hardware watchpoints. */
8879 static enum print_stop_action
8880 print_it_masked_watchpoint (struct breakpoint
*b
)
8882 /* Masked watchpoints have only one location. */
8883 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8887 case bp_hardware_watchpoint
:
8888 annotate_watchpoint (b
->number
);
8889 if (ui_out_is_mi_like_p (uiout
))
8892 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8895 case bp_read_watchpoint
:
8896 if (ui_out_is_mi_like_p (uiout
))
8899 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8902 case bp_access_watchpoint
:
8903 if (ui_out_is_mi_like_p (uiout
))
8906 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8909 internal_error (__FILE__
, __LINE__
,
8910 _("Invalid hardware watchpoint type."));
8914 ui_out_text (uiout
, _("\n\
8915 Check the underlying instruction at PC for the memory\n\
8916 address and value which triggered this watchpoint.\n"));
8917 ui_out_text (uiout
, "\n");
8919 /* More than one watchpoint may have been triggered. */
8920 return PRINT_UNKNOWN
;
8923 /* Implement the "print_one_detail" breakpoint_ops method for
8924 masked hardware watchpoints. */
8927 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8928 struct ui_out
*uiout
)
8930 /* Masked watchpoints have only one location. */
8931 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8933 ui_out_text (uiout
, "\tmask ");
8934 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, b
->hw_wp_mask
);
8935 ui_out_text (uiout
, "\n");
8938 /* Implement the "print_mention" breakpoint_ops method for
8939 masked hardware watchpoints. */
8942 print_mention_masked_watchpoint (struct breakpoint
*b
)
8944 struct cleanup
*ui_out_chain
;
8948 case bp_hardware_watchpoint
:
8949 ui_out_text (uiout
, "Masked hardware watchpoint ");
8950 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8952 case bp_read_watchpoint
:
8953 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8954 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8956 case bp_access_watchpoint
:
8957 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8958 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8961 internal_error (__FILE__
, __LINE__
,
8962 _("Invalid hardware watchpoint type."));
8965 ui_out_field_int (uiout
, "number", b
->number
);
8966 ui_out_text (uiout
, ": ");
8967 ui_out_field_string (uiout
, "exp", b
->exp_string
);
8968 do_cleanups (ui_out_chain
);
8971 /* Implement the "print_recreate" breakpoint_ops method for
8972 masked hardware watchpoints. */
8975 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8981 case bp_hardware_watchpoint
:
8982 fprintf_unfiltered (fp
, "watch");
8984 case bp_read_watchpoint
:
8985 fprintf_unfiltered (fp
, "rwatch");
8987 case bp_access_watchpoint
:
8988 fprintf_unfiltered (fp
, "awatch");
8991 internal_error (__FILE__
, __LINE__
,
8992 _("Invalid hardware watchpoint type."));
8995 sprintf_vma (tmp
, b
->hw_wp_mask
);
8996 fprintf_unfiltered (fp
, " %s mask 0x%s", b
->exp_string
, tmp
);
8999 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9001 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
=
9003 insert_masked_watchpoint
,
9004 remove_masked_watchpoint
,
9005 NULL
, /* breakpoint_hit */
9006 resources_needed_masked_watchpoint
,
9007 works_in_software_mode_masked_watchpoint
,
9008 print_it_masked_watchpoint
,
9009 NULL
, /* print_one */
9010 print_one_detail_masked_watchpoint
,
9011 print_mention_masked_watchpoint
,
9012 print_recreate_masked_watchpoint
9015 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9018 is_masked_watchpoint (const struct breakpoint
*b
)
9020 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
9023 /* accessflag: hw_write: watch write,
9024 hw_read: watch read,
9025 hw_access: watch access (read or write) */
9027 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
9028 int just_location
, int internal
)
9030 volatile struct gdb_exception e
;
9031 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9032 struct expression
*exp
;
9033 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9034 struct value
*val
, *mark
, *result
;
9035 struct frame_info
*frame
;
9036 char *exp_start
= NULL
;
9037 char *exp_end
= NULL
;
9038 char *tok
, *end_tok
;
9040 char *cond_start
= NULL
;
9041 char *cond_end
= NULL
;
9042 enum bptype bp_type
;
9045 /* Flag to indicate whether we are going to use masks for
9046 the hardware watchpoint. */
9050 /* Make sure that we actually have parameters to parse. */
9051 if (arg
!= NULL
&& arg
[0] != '\0')
9055 /* Look for "parameter value" pairs at the end
9056 of the arguments string. */
9057 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9059 /* Skip whitespace at the end of the argument list. */
9060 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9063 /* Find the beginning of the last token.
9064 This is the value of the parameter. */
9065 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9067 value_start
= tok
+ 1;
9069 /* Skip whitespace. */
9070 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9075 /* Find the beginning of the second to last token.
9076 This is the parameter itself. */
9077 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9080 toklen
= end_tok
- tok
+ 1;
9082 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9084 /* At this point we've found a "thread" token, which means
9085 the user is trying to set a watchpoint that triggers
9086 only in a specific thread. */
9090 error(_("You can specify only one thread."));
9092 /* Extract the thread ID from the next token. */
9093 thread
= strtol (value_start
, &endp
, 0);
9095 /* Check if the user provided a valid numeric value for the
9097 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9098 error (_("Invalid thread ID specification %s."), value_start
);
9100 /* Check if the thread actually exists. */
9101 if (!valid_thread_id (thread
))
9102 error (_("Unknown thread %d."), thread
);
9104 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9106 /* We've found a "mask" token, which means the user wants to
9107 create a hardware watchpoint that is going to have the mask
9109 struct value
*mask_value
, *mark
;
9112 error(_("You can specify only one mask."));
9114 use_mask
= just_location
= 1;
9116 mark
= value_mark ();
9117 mask_value
= parse_to_comma_and_eval (&value_start
);
9118 mask
= value_as_address (mask_value
);
9119 value_free_to_mark (mark
);
9122 /* We didn't recognize what we found. We should stop here. */
9125 /* Truncate the string and get rid of the "parameter value" pair before
9126 the arguments string is parsed by the parse_exp_1 function. */
9131 /* Parse the rest of the arguments. */
9132 innermost_block
= NULL
;
9134 exp
= parse_exp_1 (&arg
, 0, 0);
9136 /* Remove trailing whitespace from the expression before saving it.
9137 This makes the eventual display of the expression string a bit
9139 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9142 /* Checking if the expression is not constant. */
9143 if (watchpoint_exp_is_const (exp
))
9147 len
= exp_end
- exp_start
;
9148 while (len
> 0 && isspace (exp_start
[len
- 1]))
9150 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9153 exp_valid_block
= innermost_block
;
9154 mark
= value_mark ();
9155 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9161 exp_valid_block
= NULL
;
9162 val
= value_addr (result
);
9163 release_value (val
);
9164 value_free_to_mark (mark
);
9168 ret
= target_masked_watch_num_registers (value_as_address (val
),
9171 error (_("This target does not support masked watchpoints."));
9173 error (_("Invalid mask or memory region."));
9176 else if (val
!= NULL
)
9177 release_value (val
);
9179 tok
= skip_spaces (arg
);
9180 end_tok
= skip_to_space (tok
);
9182 toklen
= end_tok
- tok
;
9183 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9185 struct expression
*cond
;
9187 innermost_block
= NULL
;
9188 tok
= cond_start
= end_tok
+ 1;
9189 cond
= parse_exp_1 (&tok
, 0, 0);
9191 /* The watchpoint expression may not be local, but the condition
9192 may still be. E.g.: `watch global if local > 0'. */
9193 cond_exp_valid_block
= innermost_block
;
9199 error (_("Junk at end of command."));
9201 if (accessflag
== hw_read
)
9202 bp_type
= bp_read_watchpoint
;
9203 else if (accessflag
== hw_access
)
9204 bp_type
= bp_access_watchpoint
;
9206 bp_type
= bp_hardware_watchpoint
;
9208 frame
= block_innermost_frame (exp_valid_block
);
9210 /* If the expression is "local", then set up a "watchpoint scope"
9211 breakpoint at the point where we've left the scope of the watchpoint
9212 expression. Create the scope breakpoint before the watchpoint, so
9213 that we will encounter it first in bpstat_stop_status. */
9214 if (exp_valid_block
&& frame
)
9216 if (frame_id_p (frame_unwind_caller_id (frame
)))
9219 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9220 frame_unwind_caller_pc (frame
),
9221 bp_watchpoint_scope
);
9223 scope_breakpoint
->enable_state
= bp_enabled
;
9225 /* Automatically delete the breakpoint when it hits. */
9226 scope_breakpoint
->disposition
= disp_del
;
9228 /* Only break in the proper frame (help with recursion). */
9229 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9231 /* Set the address at which we will stop. */
9232 scope_breakpoint
->loc
->gdbarch
9233 = frame_unwind_caller_arch (frame
);
9234 scope_breakpoint
->loc
->requested_address
9235 = frame_unwind_caller_pc (frame
);
9236 scope_breakpoint
->loc
->address
9237 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9238 scope_breakpoint
->loc
->requested_address
,
9239 scope_breakpoint
->type
);
9243 /* Now set up the breakpoint. */
9244 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
9246 b
->disposition
= disp_donttouch
;
9248 b
->exp_valid_block
= exp_valid_block
;
9249 b
->cond_exp_valid_block
= cond_exp_valid_block
;
9252 struct type
*t
= value_type (val
);
9253 CORE_ADDR addr
= value_as_address (val
);
9256 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9257 name
= type_to_string (t
);
9259 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9260 core_addr_to_string (addr
));
9263 b
->exp_string
= xstrprintf ("-location %.*s",
9264 (int) (exp_end
- exp_start
), exp_start
);
9266 /* The above expression is in C. */
9267 b
->language
= language_c
;
9270 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9274 b
->hw_wp_mask
= mask
;
9275 b
->ops
= &masked_watchpoint_breakpoint_ops
;
9281 b
->ops
= &watchpoint_breakpoint_ops
;
9285 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9291 b
->watchpoint_frame
= get_frame_id (frame
);
9292 b
->watchpoint_thread
= inferior_ptid
;
9296 b
->watchpoint_frame
= null_frame_id
;
9297 b
->watchpoint_thread
= null_ptid
;
9300 if (scope_breakpoint
!= NULL
)
9302 /* The scope breakpoint is related to the watchpoint. We will
9303 need to act on them together. */
9304 b
->related_breakpoint
= scope_breakpoint
;
9305 scope_breakpoint
->related_breakpoint
= b
;
9309 value_free_to_mark (mark
);
9311 TRY_CATCH (e
, RETURN_MASK_ALL
)
9313 /* Finally update the new watchpoint. This creates the locations
9314 that should be inserted. */
9315 update_watchpoint (b
, 1);
9319 delete_breakpoint (b
);
9320 throw_exception (e
);
9323 set_breakpoint_number (internal
, b
);
9325 /* Do not mention breakpoints with a negative number, but do
9326 notify observers. */
9329 observer_notify_breakpoint_created (b
);
9331 update_global_location_list (1);
9334 /* Return count of debug registers needed to watch the given expression.
9335 If the watchpoint cannot be handled in hardware return zero. */
9338 can_use_hardware_watchpoint (struct value
*v
)
9340 int found_memory_cnt
= 0;
9341 struct value
*head
= v
;
9343 /* Did the user specifically forbid us to use hardware watchpoints? */
9344 if (!can_use_hw_watchpoints
)
9347 /* Make sure that the value of the expression depends only upon
9348 memory contents, and values computed from them within GDB. If we
9349 find any register references or function calls, we can't use a
9350 hardware watchpoint.
9352 The idea here is that evaluating an expression generates a series
9353 of values, one holding the value of every subexpression. (The
9354 expression a*b+c has five subexpressions: a, b, a*b, c, and
9355 a*b+c.) GDB's values hold almost enough information to establish
9356 the criteria given above --- they identify memory lvalues,
9357 register lvalues, computed values, etcetera. So we can evaluate
9358 the expression, and then scan the chain of values that leaves
9359 behind to decide whether we can detect any possible change to the
9360 expression's final value using only hardware watchpoints.
9362 However, I don't think that the values returned by inferior
9363 function calls are special in any way. So this function may not
9364 notice that an expression involving an inferior function call
9365 can't be watched with hardware watchpoints. FIXME. */
9366 for (; v
; v
= value_next (v
))
9368 if (VALUE_LVAL (v
) == lval_memory
)
9370 if (v
!= head
&& value_lazy (v
))
9371 /* A lazy memory lvalue in the chain is one that GDB never
9372 needed to fetch; we either just used its address (e.g.,
9373 `a' in `a.b') or we never needed it at all (e.g., `a'
9374 in `a,b'). This doesn't apply to HEAD; if that is
9375 lazy then it was not readable, but watch it anyway. */
9379 /* Ahh, memory we actually used! Check if we can cover
9380 it with hardware watchpoints. */
9381 struct type
*vtype
= check_typedef (value_type (v
));
9383 /* We only watch structs and arrays if user asked for it
9384 explicitly, never if they just happen to appear in a
9385 middle of some value chain. */
9387 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9388 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9390 CORE_ADDR vaddr
= value_address (v
);
9394 len
= (target_exact_watchpoints
9395 && is_scalar_type_recursive (vtype
))?
9396 1 : TYPE_LENGTH (value_type (v
));
9398 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9402 found_memory_cnt
+= num_regs
;
9406 else if (VALUE_LVAL (v
) != not_lval
9407 && deprecated_value_modifiable (v
) == 0)
9408 return 0; /* These are values from the history (e.g., $1). */
9409 else if (VALUE_LVAL (v
) == lval_register
)
9410 return 0; /* Cannot watch a register with a HW watchpoint. */
9413 /* The expression itself looks suitable for using a hardware
9414 watchpoint, but give the target machine a chance to reject it. */
9415 return found_memory_cnt
;
9419 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9421 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9424 /* A helper function that looks for an argument at the start of a
9425 string. The argument must also either be at the end of the string,
9426 or be followed by whitespace. Returns 1 if it finds the argument,
9427 0 otherwise. If the argument is found, it updates *STR. */
9430 check_for_argument (char **str
, char *arg
, int arg_len
)
9432 if (strncmp (*str
, arg
, arg_len
) == 0
9433 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9441 /* A helper function that looks for the "-location" argument and then
9442 calls watch_command_1. */
9445 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9447 int just_location
= 0;
9450 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9451 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9453 arg
= skip_spaces (arg
);
9457 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9461 watch_command (char *arg
, int from_tty
)
9463 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9467 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9469 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9473 rwatch_command (char *arg
, int from_tty
)
9475 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9479 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9481 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9485 awatch_command (char *arg
, int from_tty
)
9487 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9491 /* Helper routines for the until_command routine in infcmd.c. Here
9492 because it uses the mechanisms of breakpoints. */
9494 struct until_break_command_continuation_args
9496 struct breakpoint
*breakpoint
;
9497 struct breakpoint
*breakpoint2
;
9501 /* This function is called by fetch_inferior_event via the
9502 cmd_continuation pointer, to complete the until command. It takes
9503 care of cleaning up the temporary breakpoints set up by the until
9506 until_break_command_continuation (void *arg
)
9508 struct until_break_command_continuation_args
*a
= arg
;
9510 delete_breakpoint (a
->breakpoint
);
9512 delete_breakpoint (a
->breakpoint2
);
9513 delete_longjmp_breakpoint (a
->thread_num
);
9517 until_break_command (char *arg
, int from_tty
, int anywhere
)
9519 struct symtabs_and_lines sals
;
9520 struct symtab_and_line sal
;
9521 struct frame_info
*frame
= get_selected_frame (NULL
);
9522 struct breakpoint
*breakpoint
;
9523 struct breakpoint
*breakpoint2
= NULL
;
9524 struct cleanup
*old_chain
;
9526 struct thread_info
*tp
;
9528 clear_proceed_status ();
9530 /* Set a breakpoint where the user wants it and at return from
9533 if (default_breakpoint_valid
)
9534 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
9535 default_breakpoint_line
, NULL
);
9537 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9539 if (sals
.nelts
!= 1)
9540 error (_("Couldn't get information on specified line."));
9543 xfree (sals
.sals
); /* malloc'd, so freed. */
9546 error (_("Junk at end of arguments."));
9548 resolve_sal_pc (&sal
);
9551 /* If the user told us to continue until a specified location,
9552 we don't specify a frame at which we need to stop. */
9553 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9554 null_frame_id
, bp_until
);
9556 /* Otherwise, specify the selected frame, because we want to stop
9557 only at the very same frame. */
9558 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9559 get_stack_frame_id (frame
),
9562 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9564 tp
= inferior_thread ();
9567 /* Keep within the current frame, or in frames called by the current
9570 if (frame_id_p (frame_unwind_caller_id (frame
)))
9572 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9573 sal
.pc
= frame_unwind_caller_pc (frame
);
9574 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9576 frame_unwind_caller_id (frame
),
9578 make_cleanup_delete_breakpoint (breakpoint2
);
9580 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9581 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9584 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9586 /* If we are running asynchronously, and proceed call above has
9587 actually managed to start the target, arrange for breakpoints to
9588 be deleted when the target stops. Otherwise, we're already
9589 stopped and delete breakpoints via cleanup chain. */
9591 if (target_can_async_p () && is_running (inferior_ptid
))
9593 struct until_break_command_continuation_args
*args
;
9594 args
= xmalloc (sizeof (*args
));
9596 args
->breakpoint
= breakpoint
;
9597 args
->breakpoint2
= breakpoint2
;
9598 args
->thread_num
= thread
;
9600 discard_cleanups (old_chain
);
9601 add_continuation (inferior_thread (),
9602 until_break_command_continuation
, args
,
9606 do_cleanups (old_chain
);
9609 /* This function attempts to parse an optional "if <cond>" clause
9610 from the arg string. If one is not found, it returns NULL.
9612 Else, it returns a pointer to the condition string. (It does not
9613 attempt to evaluate the string against a particular block.) And,
9614 it updates arg to point to the first character following the parsed
9615 if clause in the arg string. */
9618 ep_parse_optional_if_clause (char **arg
)
9622 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9625 /* Skip the "if" keyword. */
9628 /* Skip any extra leading whitespace, and record the start of the
9629 condition string. */
9630 *arg
= skip_spaces (*arg
);
9633 /* Assume that the condition occupies the remainder of the arg
9635 (*arg
) += strlen (cond_string
);
9640 /* Commands to deal with catching events, such as signals, exceptions,
9641 process start/exit, etc. */
9645 catch_fork_temporary
, catch_vfork_temporary
,
9646 catch_fork_permanent
, catch_vfork_permanent
9651 catch_fork_command_1 (char *arg
, int from_tty
,
9652 struct cmd_list_element
*command
)
9654 struct gdbarch
*gdbarch
= get_current_arch ();
9655 char *cond_string
= NULL
;
9656 catch_fork_kind fork_kind
;
9659 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9660 tempflag
= (fork_kind
== catch_fork_temporary
9661 || fork_kind
== catch_vfork_temporary
);
9665 arg
= skip_spaces (arg
);
9667 /* The allowed syntax is:
9669 catch [v]fork if <cond>
9671 First, check if there's an if clause. */
9672 cond_string
= ep_parse_optional_if_clause (&arg
);
9674 if ((*arg
!= '\0') && !isspace (*arg
))
9675 error (_("Junk at end of arguments."));
9677 /* If this target supports it, create a fork or vfork catchpoint
9678 and enable reporting of such events. */
9681 case catch_fork_temporary
:
9682 case catch_fork_permanent
:
9683 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9684 &catch_fork_breakpoint_ops
);
9686 case catch_vfork_temporary
:
9687 case catch_vfork_permanent
:
9688 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9689 &catch_vfork_breakpoint_ops
);
9692 error (_("unsupported or unknown fork kind; cannot catch it"));
9698 catch_exec_command_1 (char *arg
, int from_tty
,
9699 struct cmd_list_element
*command
)
9701 struct gdbarch
*gdbarch
= get_current_arch ();
9703 char *cond_string
= NULL
;
9705 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9709 arg
= skip_spaces (arg
);
9711 /* The allowed syntax is:
9713 catch exec if <cond>
9715 First, check if there's an if clause. */
9716 cond_string
= ep_parse_optional_if_clause (&arg
);
9718 if ((*arg
!= '\0') && !isspace (*arg
))
9719 error (_("Junk at end of arguments."));
9721 /* If this target supports it, create an exec catchpoint
9722 and enable reporting of such events. */
9723 create_catchpoint (gdbarch
, tempflag
, cond_string
,
9724 &catch_exec_breakpoint_ops
);
9727 static enum print_stop_action
9728 print_it_exception_catchpoint (struct breakpoint
*b
)
9730 int bp_temp
, bp_throw
;
9732 annotate_catchpoint (b
->number
);
9734 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9735 if (b
->loc
->address
!= b
->loc
->requested_address
)
9736 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9739 bp_temp
= b
->disposition
== disp_del
;
9741 bp_temp
? "Temporary catchpoint "
9743 if (!ui_out_is_mi_like_p (uiout
))
9744 ui_out_field_int (uiout
, "bkptno", b
->number
);
9746 bp_throw
? " (exception thrown), "
9747 : " (exception caught), ");
9748 if (ui_out_is_mi_like_p (uiout
))
9750 ui_out_field_string (uiout
, "reason",
9751 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9752 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9753 ui_out_field_int (uiout
, "bkptno", b
->number
);
9755 return PRINT_SRC_AND_LOC
;
9759 print_one_exception_catchpoint (struct breakpoint
*b
,
9760 struct bp_location
**last_loc
)
9762 struct value_print_options opts
;
9764 get_user_print_options (&opts
);
9765 if (opts
.addressprint
)
9768 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9769 ui_out_field_string (uiout
, "addr", "<PENDING>");
9771 ui_out_field_core_addr (uiout
, "addr",
9772 b
->loc
->gdbarch
, b
->loc
->address
);
9777 if (strstr (b
->addr_string
, "throw") != NULL
)
9778 ui_out_field_string (uiout
, "what", "exception throw");
9780 ui_out_field_string (uiout
, "what", "exception catch");
9784 print_mention_exception_catchpoint (struct breakpoint
*b
)
9789 bp_temp
= b
->disposition
== disp_del
;
9790 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9791 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9792 : _("Catchpoint "));
9793 ui_out_field_int (uiout
, "bkptno", b
->number
);
9794 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9798 /* Implement the "print_recreate" breakpoint_ops method for throw and
9799 catch catchpoints. */
9802 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9808 bp_temp
= b
->disposition
== disp_del
;
9809 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9810 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9811 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9814 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9817 NULL
, /* breakpoint_hit */
9818 NULL
, /* resources_needed */
9819 NULL
, /* works_in_software_mode */
9820 print_it_exception_catchpoint
,
9821 print_one_exception_catchpoint
,
9822 NULL
, /* print_one_detail */
9823 print_mention_exception_catchpoint
,
9824 print_recreate_exception_catchpoint
9828 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9829 enum exception_event_kind ex_event
, int from_tty
)
9831 char *trigger_func_name
;
9833 if (ex_event
== EX_EVENT_CATCH
)
9834 trigger_func_name
= "__cxa_begin_catch";
9836 trigger_func_name
= "__cxa_throw";
9838 create_breakpoint (get_current_arch (),
9839 trigger_func_name
, cond_string
, -1,
9840 0 /* condition and thread are valid. */,
9841 tempflag
, bp_breakpoint
,
9843 AUTO_BOOLEAN_TRUE
/* pending */,
9844 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9851 /* Deal with "catch catch" and "catch throw" commands. */
9854 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9855 int tempflag
, int from_tty
)
9857 char *cond_string
= NULL
;
9861 arg
= skip_spaces (arg
);
9863 cond_string
= ep_parse_optional_if_clause (&arg
);
9865 if ((*arg
!= '\0') && !isspace (*arg
))
9866 error (_("Junk at end of arguments."));
9868 if (ex_event
!= EX_EVENT_THROW
9869 && ex_event
!= EX_EVENT_CATCH
)
9870 error (_("Unsupported or unknown exception event; cannot catch it"));
9872 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9875 warning (_("Unsupported with this platform/compiler combination."));
9878 /* Implementation of "catch catch" command. */
9881 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9883 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9885 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9888 /* Implementation of "catch throw" command. */
9891 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9893 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9895 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9898 /* Create a breakpoint struct for Ada exception catchpoints. */
9901 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9902 struct symtab_and_line sal
,
9906 struct expression
*cond
,
9907 struct breakpoint_ops
*ops
,
9911 struct breakpoint
*b
;
9915 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9917 loc_gdbarch
= gdbarch
;
9919 describe_other_breakpoints (loc_gdbarch
,
9920 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9921 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9922 version for exception catchpoints, because two catchpoints
9923 used for different exception names will use the same address.
9924 In this case, a "breakpoint ... also set at..." warning is
9925 unproductive. Besides, the warning phrasing is also a bit
9926 inapropriate, we should use the word catchpoint, and tell
9927 the user what type of catchpoint it is. The above is good
9928 enough for now, though. */
9931 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9932 set_breakpoint_count (breakpoint_count
+ 1);
9934 b
->enable_state
= bp_enabled
;
9935 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9936 b
->number
= breakpoint_count
;
9937 b
->ignore_count
= 0;
9938 b
->loc
->cond
= cond
;
9939 b
->addr_string
= addr_string
;
9940 b
->language
= language_ada
;
9941 b
->cond_string
= cond_string
;
9942 b
->exp_string
= exp_string
;
9947 observer_notify_breakpoint_created (b
);
9948 update_global_location_list (1);
9951 /* Implement the "catch exception" command. */
9954 catch_ada_exception_command (char *arg
, int from_tty
,
9955 struct cmd_list_element
*command
)
9957 struct gdbarch
*gdbarch
= get_current_arch ();
9959 struct symtab_and_line sal
;
9960 char *addr_string
= NULL
;
9961 char *exp_string
= NULL
;
9962 char *cond_string
= NULL
;
9963 struct expression
*cond
= NULL
;
9964 struct breakpoint_ops
*ops
= NULL
;
9966 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9970 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9971 &cond_string
, &cond
, &ops
);
9972 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9973 cond_string
, cond
, ops
, tempflag
,
9977 /* Cleanup function for a syscall filter list. */
9979 clean_up_filters (void *arg
)
9981 VEC(int) *iter
= *(VEC(int) **) arg
;
9982 VEC_free (int, iter
);
9985 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9986 filter list, or NULL if no filtering is required. */
9988 catch_syscall_split_args (char *arg
)
9990 VEC(int) *result
= NULL
;
9991 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9993 while (*arg
!= '\0')
9995 int i
, syscall_number
;
10000 /* Skip whitespace. */
10001 while (isspace (*arg
))
10004 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
10005 cur_name
[i
] = arg
[i
];
10006 cur_name
[i
] = '\0';
10009 /* Check if the user provided a syscall name or a number. */
10010 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
10011 if (*endptr
== '\0')
10012 get_syscall_by_number (syscall_number
, &s
);
10015 /* We have a name. Let's check if it's valid and convert it
10017 get_syscall_by_name (cur_name
, &s
);
10019 if (s
.number
== UNKNOWN_SYSCALL
)
10020 /* Here we have to issue an error instead of a warning,
10021 because GDB cannot do anything useful if there's no
10022 syscall number to be caught. */
10023 error (_("Unknown syscall name '%s'."), cur_name
);
10026 /* Ok, it's valid. */
10027 VEC_safe_push (int, result
, s
.number
);
10030 discard_cleanups (cleanup
);
10034 /* Implement the "catch syscall" command. */
10037 catch_syscall_command_1 (char *arg
, int from_tty
,
10038 struct cmd_list_element
*command
)
10043 struct gdbarch
*gdbarch
= get_current_arch ();
10045 /* Checking if the feature if supported. */
10046 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
10047 error (_("The feature 'catch syscall' is not supported on \
10048 this architecture yet."));
10050 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10052 arg
= skip_spaces (arg
);
10054 /* We need to do this first "dummy" translation in order
10055 to get the syscall XML file loaded or, most important,
10056 to display a warning to the user if there's no XML file
10057 for his/her architecture. */
10058 get_syscall_by_number (0, &s
);
10060 /* The allowed syntax is:
10062 catch syscall <name | number> [<name | number> ... <name | number>]
10064 Let's check if there's a syscall name. */
10067 filter
= catch_syscall_split_args (arg
);
10071 create_syscall_event_catchpoint (tempflag
, filter
,
10072 &catch_syscall_breakpoint_ops
);
10075 /* Implement the "catch assert" command. */
10078 catch_assert_command (char *arg
, int from_tty
,
10079 struct cmd_list_element
*command
)
10081 struct gdbarch
*gdbarch
= get_current_arch ();
10083 struct symtab_and_line sal
;
10084 char *addr_string
= NULL
;
10085 struct breakpoint_ops
*ops
= NULL
;
10087 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10091 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
10092 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
10093 ops
, tempflag
, from_tty
);
10097 catch_command (char *arg
, int from_tty
)
10099 error (_("Catch requires an event name."));
10104 tcatch_command (char *arg
, int from_tty
)
10106 error (_("Catch requires an event name."));
10109 /* Delete breakpoints by address or line. */
10112 clear_command (char *arg
, int from_tty
)
10114 struct breakpoint
*b
;
10115 VEC(breakpoint_p
) *found
= 0;
10118 struct symtabs_and_lines sals
;
10119 struct symtab_and_line sal
;
10124 sals
= decode_line_spec (arg
, 1);
10129 sals
.sals
= (struct symtab_and_line
*)
10130 xmalloc (sizeof (struct symtab_and_line
));
10131 make_cleanup (xfree
, sals
.sals
);
10132 init_sal (&sal
); /* Initialize to zeroes. */
10133 sal
.line
= default_breakpoint_line
;
10134 sal
.symtab
= default_breakpoint_symtab
;
10135 sal
.pc
= default_breakpoint_address
;
10136 sal
.pspace
= default_breakpoint_pspace
;
10137 if (sal
.symtab
== 0)
10138 error (_("No source file specified."));
10140 sals
.sals
[0] = sal
;
10146 /* We don't call resolve_sal_pc here. That's not as bad as it
10147 seems, because all existing breakpoints typically have both
10148 file/line and pc set. So, if clear is given file/line, we can
10149 match this to existing breakpoint without obtaining pc at all.
10151 We only support clearing given the address explicitly
10152 present in breakpoint table. Say, we've set breakpoint
10153 at file:line. There were several PC values for that file:line,
10154 due to optimization, all in one block.
10156 We've picked one PC value. If "clear" is issued with another
10157 PC corresponding to the same file:line, the breakpoint won't
10158 be cleared. We probably can still clear the breakpoint, but
10159 since the other PC value is never presented to user, user
10160 can only find it by guessing, and it does not seem important
10161 to support that. */
10163 /* For each line spec given, delete bps which correspond to it. Do
10164 it in two passes, solely to preserve the current behavior that
10165 from_tty is forced true if we delete more than one
10169 for (i
= 0; i
< sals
.nelts
; i
++)
10171 /* If exact pc given, clear bpts at that pc.
10172 If line given (pc == 0), clear all bpts on specified line.
10173 If defaulting, clear all bpts on default line
10176 defaulting sal.pc != 0 tests to do
10181 1 0 <can't happen> */
10183 sal
= sals
.sals
[i
];
10185 /* Find all matching breakpoints and add them to 'found'. */
10186 ALL_BREAKPOINTS (b
)
10189 /* Are we going to delete b? */
10190 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10192 struct bp_location
*loc
= b
->loc
;
10193 for (; loc
; loc
= loc
->next
)
10195 int pc_match
= sal
.pc
10196 && (loc
->pspace
== sal
.pspace
)
10197 && (loc
->address
== sal
.pc
)
10198 && (!section_is_overlay (loc
->section
)
10199 || loc
->section
== sal
.section
);
10200 int line_match
= ((default_match
|| (0 == sal
.pc
))
10201 && b
->source_file
!= NULL
10202 && sal
.symtab
!= NULL
10203 && sal
.pspace
== loc
->pspace
10204 && filename_cmp (b
->source_file
,
10205 sal
.symtab
->filename
) == 0
10206 && b
->line_number
== sal
.line
);
10207 if (pc_match
|| line_match
)
10216 VEC_safe_push(breakpoint_p
, found
, b
);
10219 /* Now go thru the 'found' chain and delete them. */
10220 if (VEC_empty(breakpoint_p
, found
))
10223 error (_("No breakpoint at %s."), arg
);
10225 error (_("No breakpoint at this line."));
10228 if (VEC_length(breakpoint_p
, found
) > 1)
10229 from_tty
= 1; /* Always report if deleted more than one. */
10232 if (VEC_length(breakpoint_p
, found
) == 1)
10233 printf_unfiltered (_("Deleted breakpoint "));
10235 printf_unfiltered (_("Deleted breakpoints "));
10237 breakpoints_changed ();
10239 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10242 printf_unfiltered ("%d ", b
->number
);
10243 delete_breakpoint (b
);
10246 putchar_unfiltered ('\n');
10249 /* Delete breakpoint in BS if they are `delete' breakpoints and
10250 all breakpoints that are marked for deletion, whether hit or not.
10251 This is called after any breakpoint is hit, or after errors. */
10254 breakpoint_auto_delete (bpstat bs
)
10256 struct breakpoint
*b
, *b_tmp
;
10258 for (; bs
; bs
= bs
->next
)
10259 if (bs
->breakpoint_at
10260 && bs
->breakpoint_at
->disposition
== disp_del
10262 delete_breakpoint (bs
->breakpoint_at
);
10264 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10266 if (b
->disposition
== disp_del_at_next_stop
)
10267 delete_breakpoint (b
);
10271 /* A comparison function for bp_location AP and BP being interfaced to
10272 qsort. Sort elements primarily by their ADDRESS (no matter what
10273 does breakpoint_address_is_meaningful say for its OWNER),
10274 secondarily by ordering first bp_permanent OWNERed elements and
10275 terciarily just ensuring the array is sorted stable way despite
10276 qsort being an instable algorithm. */
10279 bp_location_compare (const void *ap
, const void *bp
)
10281 struct bp_location
*a
= *(void **) ap
;
10282 struct bp_location
*b
= *(void **) bp
;
10283 /* A and B come from existing breakpoints having non-NULL OWNER. */
10284 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10285 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10287 if (a
->address
!= b
->address
)
10288 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10290 /* Sort permanent breakpoints first. */
10291 if (a_perm
!= b_perm
)
10292 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10294 /* Make the user-visible order stable across GDB runs. Locations of
10295 the same breakpoint can be sorted in arbitrary order. */
10297 if (a
->owner
->number
!= b
->owner
->number
)
10298 return (a
->owner
->number
> b
->owner
->number
)
10299 - (a
->owner
->number
< b
->owner
->number
);
10301 return (a
> b
) - (a
< b
);
10304 /* Set bp_location_placed_address_before_address_max and
10305 bp_location_shadow_len_after_address_max according to the current
10306 content of the bp_location array. */
10309 bp_location_target_extensions_update (void)
10311 struct bp_location
*bl
, **blp_tmp
;
10313 bp_location_placed_address_before_address_max
= 0;
10314 bp_location_shadow_len_after_address_max
= 0;
10316 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10318 CORE_ADDR start
, end
, addr
;
10320 if (!bp_location_has_shadow (bl
))
10323 start
= bl
->target_info
.placed_address
;
10324 end
= start
+ bl
->target_info
.shadow_len
;
10326 gdb_assert (bl
->address
>= start
);
10327 addr
= bl
->address
- start
;
10328 if (addr
> bp_location_placed_address_before_address_max
)
10329 bp_location_placed_address_before_address_max
= addr
;
10331 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10333 gdb_assert (bl
->address
< end
);
10334 addr
= end
- bl
->address
;
10335 if (addr
> bp_location_shadow_len_after_address_max
)
10336 bp_location_shadow_len_after_address_max
= addr
;
10340 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10341 into the inferior, only remove already-inserted locations that no
10342 longer should be inserted. Functions that delete a breakpoint or
10343 breakpoints should pass false, so that deleting a breakpoint
10344 doesn't have the side effect of inserting the locations of other
10345 breakpoints that are marked not-inserted, but should_be_inserted
10346 returns true on them.
10348 This behaviour is useful is situations close to tear-down -- e.g.,
10349 after an exec, while the target still has execution, but breakpoint
10350 shadows of the previous executable image should *NOT* be restored
10351 to the new image; or before detaching, where the target still has
10352 execution and wants to delete breakpoints from GDB's lists, and all
10353 breakpoints had already been removed from the inferior. */
10356 update_global_location_list (int should_insert
)
10358 struct breakpoint
*b
;
10359 struct bp_location
**locp
, *loc
;
10360 struct cleanup
*cleanups
;
10362 /* Used in the duplicates detection below. When iterating over all
10363 bp_locations, points to the first bp_location of a given address.
10364 Breakpoints and watchpoints of different types are never
10365 duplicates of each other. Keep one pointer for each type of
10366 breakpoint/watchpoint, so we only need to loop over all locations
10368 struct bp_location
*bp_loc_first
; /* breakpoint */
10369 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10370 struct bp_location
*awp_loc_first
; /* access watchpoint */
10371 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10373 /* Saved former bp_location array which we compare against the newly
10374 built bp_location from the current state of ALL_BREAKPOINTS. */
10375 struct bp_location
**old_location
, **old_locp
;
10376 unsigned old_location_count
;
10378 old_location
= bp_location
;
10379 old_location_count
= bp_location_count
;
10380 bp_location
= NULL
;
10381 bp_location_count
= 0;
10382 cleanups
= make_cleanup (xfree
, old_location
);
10384 ALL_BREAKPOINTS (b
)
10385 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10386 bp_location_count
++;
10388 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10389 locp
= bp_location
;
10390 ALL_BREAKPOINTS (b
)
10391 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10393 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10394 bp_location_compare
);
10396 bp_location_target_extensions_update ();
10398 /* Identify bp_location instances that are no longer present in the
10399 new list, and therefore should be freed. Note that it's not
10400 necessary that those locations should be removed from inferior --
10401 if there's another location at the same address (previously
10402 marked as duplicate), we don't need to remove/insert the
10405 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10406 and former bp_location array state respectively. */
10408 locp
= bp_location
;
10409 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10412 struct bp_location
*old_loc
= *old_locp
;
10413 struct bp_location
**loc2p
;
10415 /* Tells if 'old_loc' is found amoung the new locations. If
10416 not, we have to free it. */
10417 int found_object
= 0;
10418 /* Tells if the location should remain inserted in the target. */
10419 int keep_in_target
= 0;
10422 /* Skip LOCP entries which will definitely never be needed.
10423 Stop either at or being the one matching OLD_LOC. */
10424 while (locp
< bp_location
+ bp_location_count
10425 && (*locp
)->address
< old_loc
->address
)
10429 (loc2p
< bp_location
+ bp_location_count
10430 && (*loc2p
)->address
== old_loc
->address
);
10433 if (*loc2p
== old_loc
)
10440 /* If this location is no longer present, and inserted, look if
10441 there's maybe a new location at the same address. If so,
10442 mark that one inserted, and don't remove this one. This is
10443 needed so that we don't have a time window where a breakpoint
10444 at certain location is not inserted. */
10446 if (old_loc
->inserted
)
10448 /* If the location is inserted now, we might have to remove
10451 if (found_object
&& should_be_inserted (old_loc
))
10453 /* The location is still present in the location list,
10454 and still should be inserted. Don't do anything. */
10455 keep_in_target
= 1;
10459 /* The location is either no longer present, or got
10460 disabled. See if there's another location at the
10461 same address, in which case we don't need to remove
10462 this one from the target. */
10464 /* OLD_LOC comes from existing struct breakpoint. */
10465 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10468 (loc2p
< bp_location
+ bp_location_count
10469 && (*loc2p
)->address
== old_loc
->address
);
10472 struct bp_location
*loc2
= *loc2p
;
10474 if (breakpoint_locations_match (loc2
, old_loc
))
10476 /* For the sake of should_be_inserted.
10477 Duplicates check below will fix up this
10479 loc2
->duplicate
= 0;
10481 /* Read watchpoint locations are switched to
10482 access watchpoints, if the former are not
10483 supported, but the latter are. */
10484 if (is_hardware_watchpoint (old_loc
->owner
))
10486 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10487 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10490 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
10492 loc2
->inserted
= 1;
10493 loc2
->target_info
= old_loc
->target_info
;
10494 keep_in_target
= 1;
10502 if (!keep_in_target
)
10504 if (remove_breakpoint (old_loc
, mark_uninserted
))
10506 /* This is just about all we can do. We could keep
10507 this location on the global list, and try to
10508 remove it next time, but there's no particular
10509 reason why we will succeed next time.
10511 Note that at this point, old_loc->owner is still
10512 valid, as delete_breakpoint frees the breakpoint
10513 only after calling us. */
10514 printf_filtered (_("warning: Error removing "
10515 "breakpoint %d\n"),
10516 old_loc
->owner
->number
);
10524 if (removed
&& non_stop
10525 && breakpoint_address_is_meaningful (old_loc
->owner
)
10526 && !is_hardware_watchpoint (old_loc
->owner
))
10528 /* This location was removed from the target. In
10529 non-stop mode, a race condition is possible where
10530 we've removed a breakpoint, but stop events for that
10531 breakpoint are already queued and will arrive later.
10532 We apply an heuristic to be able to distinguish such
10533 SIGTRAPs from other random SIGTRAPs: we keep this
10534 breakpoint location for a bit, and will retire it
10535 after we see some number of events. The theory here
10536 is that reporting of events should, "on the average",
10537 be fair, so after a while we'll see events from all
10538 threads that have anything of interest, and no longer
10539 need to keep this breakpoint location around. We
10540 don't hold locations forever so to reduce chances of
10541 mistaking a non-breakpoint SIGTRAP for a breakpoint
10544 The heuristic failing can be disastrous on
10545 decr_pc_after_break targets.
10547 On decr_pc_after_break targets, like e.g., x86-linux,
10548 if we fail to recognize a late breakpoint SIGTRAP,
10549 because events_till_retirement has reached 0 too
10550 soon, we'll fail to do the PC adjustment, and report
10551 a random SIGTRAP to the user. When the user resumes
10552 the inferior, it will most likely immediately crash
10553 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10554 corrupted, because of being resumed e.g., in the
10555 middle of a multi-byte instruction, or skipped a
10556 one-byte instruction. This was actually seen happen
10557 on native x86-linux, and should be less rare on
10558 targets that do not support new thread events, like
10559 remote, due to the heuristic depending on
10562 Mistaking a random SIGTRAP for a breakpoint trap
10563 causes similar symptoms (PC adjustment applied when
10564 it shouldn't), but then again, playing with SIGTRAPs
10565 behind the debugger's back is asking for trouble.
10567 Since hardware watchpoint traps are always
10568 distinguishable from other traps, so we don't need to
10569 apply keep hardware watchpoint moribund locations
10570 around. We simply always ignore hardware watchpoint
10571 traps we can no longer explain. */
10573 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10574 old_loc
->owner
= NULL
;
10576 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10580 old_loc
->owner
= NULL
;
10581 decref_bp_location (&old_loc
);
10586 /* Rescan breakpoints at the same address and section, marking the
10587 first one as "first" and any others as "duplicates". This is so
10588 that the bpt instruction is only inserted once. If we have a
10589 permanent breakpoint at the same place as BPT, make that one the
10590 official one, and the rest as duplicates. Permanent breakpoints
10591 are sorted first for the same address.
10593 Do the same for hardware watchpoints, but also considering the
10594 watchpoint's type (regular/access/read) and length. */
10596 bp_loc_first
= NULL
;
10597 wp_loc_first
= NULL
;
10598 awp_loc_first
= NULL
;
10599 rwp_loc_first
= NULL
;
10600 ALL_BP_LOCATIONS (loc
, locp
)
10602 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10604 struct breakpoint
*b
= loc
->owner
;
10605 struct bp_location
**loc_first_p
;
10607 if (b
->enable_state
== bp_disabled
10608 || b
->enable_state
== bp_call_disabled
10609 || b
->enable_state
== bp_startup_disabled
10611 || loc
->shlib_disabled
10612 || !breakpoint_address_is_meaningful (b
)
10613 || is_tracepoint (b
))
10616 /* Permanent breakpoint should always be inserted. */
10617 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10618 internal_error (__FILE__
, __LINE__
,
10619 _("allegedly permanent breakpoint is not "
10620 "actually inserted"));
10622 if (b
->type
== bp_hardware_watchpoint
)
10623 loc_first_p
= &wp_loc_first
;
10624 else if (b
->type
== bp_read_watchpoint
)
10625 loc_first_p
= &rwp_loc_first
;
10626 else if (b
->type
== bp_access_watchpoint
)
10627 loc_first_p
= &awp_loc_first
;
10629 loc_first_p
= &bp_loc_first
;
10631 if (*loc_first_p
== NULL
10632 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10633 || !breakpoint_locations_match (loc
, *loc_first_p
))
10635 *loc_first_p
= loc
;
10636 loc
->duplicate
= 0;
10640 loc
->duplicate
= 1;
10642 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10643 && b
->enable_state
!= bp_permanent
)
10644 internal_error (__FILE__
, __LINE__
,
10645 _("another breakpoint was inserted on top of "
10646 "a permanent breakpoint"));
10649 if (breakpoints_always_inserted_mode () && should_insert
10650 && (have_live_inferiors ()
10651 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10652 insert_breakpoint_locations ();
10654 do_cleanups (cleanups
);
10658 breakpoint_retire_moribund (void)
10660 struct bp_location
*loc
;
10663 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10664 if (--(loc
->events_till_retirement
) == 0)
10666 decref_bp_location (&loc
);
10667 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10673 update_global_location_list_nothrow (int inserting
)
10675 struct gdb_exception e
;
10677 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10678 update_global_location_list (inserting
);
10681 /* Clear BKP from a BPS. */
10684 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10688 for (bs
= bps
; bs
; bs
= bs
->next
)
10689 if (bs
->breakpoint_at
== bpt
)
10691 bs
->breakpoint_at
= NULL
;
10692 bs
->old_val
= NULL
;
10693 /* bs->commands will be freed later. */
10697 /* Callback for iterate_over_threads. */
10699 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10701 struct breakpoint
*bpt
= data
;
10703 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10707 /* Delete a breakpoint and clean up all traces of it in the data
10711 delete_breakpoint (struct breakpoint
*bpt
)
10713 struct breakpoint
*b
;
10715 gdb_assert (bpt
!= NULL
);
10717 /* Has this bp already been deleted? This can happen because
10718 multiple lists can hold pointers to bp's. bpstat lists are
10721 One example of this happening is a watchpoint's scope bp. When
10722 the scope bp triggers, we notice that the watchpoint is out of
10723 scope, and delete it. We also delete its scope bp. But the
10724 scope bp is marked "auto-deleting", and is already on a bpstat.
10725 That bpstat is then checked for auto-deleting bp's, which are
10728 A real solution to this problem might involve reference counts in
10729 bp's, and/or giving them pointers back to their referencing
10730 bpstat's, and teaching delete_breakpoint to only free a bp's
10731 storage when no more references were extent. A cheaper bandaid
10733 if (bpt
->type
== bp_none
)
10736 /* At least avoid this stale reference until the reference counting
10737 of breakpoints gets resolved. */
10738 if (bpt
->related_breakpoint
!= bpt
)
10740 struct breakpoint
*related
;
10742 if (bpt
->type
== bp_watchpoint_scope
)
10743 watchpoint_del_at_next_stop (bpt
->related_breakpoint
);
10744 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
10745 watchpoint_del_at_next_stop (bpt
);
10747 /* Unlink bpt from the bpt->related_breakpoint ring. */
10748 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
10749 related
= related
->related_breakpoint
);
10750 related
->related_breakpoint
= bpt
->related_breakpoint
;
10751 bpt
->related_breakpoint
= bpt
;
10754 /* watch_command_1 creates a watchpoint but only sets its number if
10755 update_watchpoint succeeds in creating its bp_locations. If there's
10756 a problem in that process, we'll be asked to delete the half-created
10757 watchpoint. In that case, don't announce the deletion. */
10759 observer_notify_breakpoint_deleted (bpt
);
10761 if (breakpoint_chain
== bpt
)
10762 breakpoint_chain
= bpt
->next
;
10764 ALL_BREAKPOINTS (b
)
10765 if (b
->next
== bpt
)
10767 b
->next
= bpt
->next
;
10771 decref_counted_command_line (&bpt
->commands
);
10772 xfree (bpt
->cond_string
);
10773 xfree (bpt
->cond_exp
);
10774 xfree (bpt
->addr_string
);
10775 xfree (bpt
->addr_string_range_end
);
10777 xfree (bpt
->exp_string
);
10778 xfree (bpt
->exp_string_reparse
);
10779 value_free (bpt
->val
);
10780 xfree (bpt
->source_file
);
10781 xfree (bpt
->exec_pathname
);
10782 clean_up_filters (&bpt
->syscalls_to_be_caught
);
10785 /* Be sure no bpstat's are pointing at the breakpoint after it's
10787 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10788 in all threeds for now. Note that we cannot just remove bpstats
10789 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10790 commands are associated with the bpstat; if we remove it here,
10791 then the later call to bpstat_do_actions (&stop_bpstat); in
10792 event-top.c won't do anything, and temporary breakpoints with
10793 commands won't work. */
10795 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
10797 /* Now that breakpoint is removed from breakpoint list, update the
10798 global location list. This will remove locations that used to
10799 belong to this breakpoint. Do this before freeing the breakpoint
10800 itself, since remove_breakpoint looks at location's owner. It
10801 might be better design to have location completely
10802 self-contained, but it's not the case now. */
10803 update_global_location_list (0);
10806 /* On the chance that someone will soon try again to delete this
10807 same bp, we mark it as deleted before freeing its storage. */
10808 bpt
->type
= bp_none
;
10814 do_delete_breakpoint_cleanup (void *b
)
10816 delete_breakpoint (b
);
10820 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
10822 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
10825 /* A callback for map_breakpoint_numbers that calls
10826 delete_breakpoint. */
10829 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
10831 delete_breakpoint (b
);
10835 delete_command (char *arg
, int from_tty
)
10837 struct breakpoint
*b
, *b_tmp
;
10843 int breaks_to_delete
= 0;
10845 /* Delete all breakpoints if no argument. Do not delete
10846 internal breakpoints, these have to be deleted with an
10847 explicit breakpoint number argument. */
10848 ALL_BREAKPOINTS (b
)
10849 if (user_breakpoint_p (b
))
10851 breaks_to_delete
= 1;
10855 /* Ask user only if there are some breakpoints to delete. */
10857 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10859 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10860 if (user_breakpoint_p (b
))
10861 delete_breakpoint (b
);
10865 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10869 all_locations_are_pending (struct bp_location
*loc
)
10871 for (; loc
; loc
= loc
->next
)
10872 if (!loc
->shlib_disabled
)
10877 /* Subroutine of update_breakpoint_locations to simplify it.
10878 Return non-zero if multiple fns in list LOC have the same name.
10879 Null names are ignored. */
10882 ambiguous_names_p (struct bp_location
*loc
)
10884 struct bp_location
*l
;
10885 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10886 (int (*) (const void *,
10887 const void *)) streq
,
10888 NULL
, xcalloc
, xfree
);
10890 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10893 const char *name
= l
->function_name
;
10895 /* Allow for some names to be NULL, ignore them. */
10899 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10901 /* NOTE: We can assume slot != NULL here because xcalloc never
10905 htab_delete (htab
);
10911 htab_delete (htab
);
10915 /* When symbols change, it probably means the sources changed as well,
10916 and it might mean the static tracepoint markers are no longer at
10917 the same address or line numbers they used to be at last we
10918 checked. Losing your static tracepoints whenever you rebuild is
10919 undesirable. This function tries to resync/rematch gdb static
10920 tracepoints with the markers on the target, for static tracepoints
10921 that have not been set by marker id. Static tracepoint that have
10922 been set by marker id are reset by marker id in breakpoint_re_set.
10925 1) For a tracepoint set at a specific address, look for a marker at
10926 the old PC. If one is found there, assume to be the same marker.
10927 If the name / string id of the marker found is different from the
10928 previous known name, assume that means the user renamed the marker
10929 in the sources, and output a warning.
10931 2) For a tracepoint set at a given line number, look for a marker
10932 at the new address of the old line number. If one is found there,
10933 assume to be the same marker. If the name / string id of the
10934 marker found is different from the previous known name, assume that
10935 means the user renamed the marker in the sources, and output a
10938 3) If a marker is no longer found at the same address or line, it
10939 may mean the marker no longer exists. But it may also just mean
10940 the code changed a bit. Maybe the user added a few lines of code
10941 that made the marker move up or down (in line number terms). Ask
10942 the target for info about the marker with the string id as we knew
10943 it. If found, update line number and address in the matching
10944 static tracepoint. This will get confused if there's more than one
10945 marker with the same ID (possible in UST, although unadvised
10946 precisely because it confuses tools). */
10948 static struct symtab_and_line
10949 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10951 struct static_tracepoint_marker marker
;
10957 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10959 if (target_static_tracepoint_marker_at (pc
, &marker
))
10961 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10962 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10964 b
->static_trace_marker_id
, marker
.str_id
);
10966 xfree (b
->static_trace_marker_id
);
10967 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10968 release_static_tracepoint_marker (&marker
);
10973 /* Old marker wasn't found on target at lineno. Try looking it up
10975 if (!sal
.explicit_pc
10977 && sal
.symtab
!= NULL
10978 && b
->static_trace_marker_id
!= NULL
)
10980 VEC(static_tracepoint_marker_p
) *markers
;
10983 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10985 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10987 struct symtab_and_line sal
;
10988 struct symbol
*sym
;
10989 struct static_tracepoint_marker
*marker
;
10991 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10993 xfree (b
->static_trace_marker_id
);
10994 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10996 warning (_("marker for static tracepoint %d (%s) not "
10997 "found at previous line number"),
10998 b
->number
, b
->static_trace_marker_id
);
11002 sal
.pc
= marker
->address
;
11004 sal
= find_pc_line (marker
->address
, 0);
11005 sym
= find_pc_sect_function (marker
->address
, NULL
);
11006 ui_out_text (uiout
, "Now in ");
11009 ui_out_field_string (uiout
, "func",
11010 SYMBOL_PRINT_NAME (sym
));
11011 ui_out_text (uiout
, " at ");
11013 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11014 ui_out_text (uiout
, ":");
11016 if (ui_out_is_mi_like_p (uiout
))
11018 char *fullname
= symtab_to_fullname (sal
.symtab
);
11021 ui_out_field_string (uiout
, "fullname", fullname
);
11024 ui_out_field_int (uiout
, "line", sal
.line
);
11025 ui_out_text (uiout
, "\n");
11027 b
->line_number
= sal
.line
;
11029 xfree (b
->source_file
);
11031 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11033 b
->source_file
= NULL
;
11035 xfree (b
->addr_string
);
11036 b
->addr_string
= xstrprintf ("%s:%d",
11037 sal
.symtab
->filename
, b
->line_number
);
11039 /* Might be nice to check if function changed, and warn if
11042 release_static_tracepoint_marker (marker
);
11048 /* Returns 1 iff locations A and B are sufficiently same that
11049 we don't need to report breakpoint as changed. */
11052 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11056 if (a
->address
!= b
->address
)
11059 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11062 if (a
->enabled
!= b
->enabled
)
11069 if ((a
== NULL
) != (b
== NULL
))
11075 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11076 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11077 a ranged breakpoint. */
11080 update_breakpoint_locations (struct breakpoint
*b
,
11081 struct symtabs_and_lines sals
,
11082 struct symtabs_and_lines sals_end
)
11085 struct bp_location
*existing_locations
= b
->loc
;
11087 /* Ranged breakpoints have only one start location and one end location. */
11088 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11090 /* If there's no new locations, and all existing locations are
11091 pending, don't do anything. This optimizes the common case where
11092 all locations are in the same shared library, that was unloaded.
11093 We'd like to retain the location, so that when the library is
11094 loaded again, we don't loose the enabled/disabled status of the
11095 individual locations. */
11096 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11101 for (i
= 0; i
< sals
.nelts
; ++i
)
11103 struct bp_location
*new_loc
=
11104 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11106 /* Reparse conditions, they might contain references to the
11108 if (b
->cond_string
!= NULL
)
11111 struct gdb_exception e
;
11113 s
= b
->cond_string
;
11114 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11116 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11121 warning (_("failed to reevaluate condition "
11122 "for breakpoint %d: %s"),
11123 b
->number
, e
.message
);
11124 new_loc
->enabled
= 0;
11128 if (b
->source_file
!= NULL
)
11129 xfree (b
->source_file
);
11130 if (sals
.sals
[i
].symtab
== NULL
)
11131 b
->source_file
= NULL
;
11133 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11135 if (b
->line_number
== 0)
11136 b
->line_number
= sals
.sals
[i
].line
;
11138 if (sals_end
.nelts
)
11140 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11142 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11146 /* Update locations of permanent breakpoints. */
11147 if (b
->enable_state
== bp_permanent
)
11148 make_breakpoint_permanent (b
);
11150 /* If possible, carry over 'disable' status from existing
11153 struct bp_location
*e
= existing_locations
;
11154 /* If there are multiple breakpoints with the same function name,
11155 e.g. for inline functions, comparing function names won't work.
11156 Instead compare pc addresses; this is just a heuristic as things
11157 may have moved, but in practice it gives the correct answer
11158 often enough until a better solution is found. */
11159 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11161 for (; e
; e
= e
->next
)
11163 if (!e
->enabled
&& e
->function_name
)
11165 struct bp_location
*l
= b
->loc
;
11166 if (have_ambiguous_names
)
11168 for (; l
; l
= l
->next
)
11169 if (breakpoint_locations_match (e
, l
))
11177 for (; l
; l
= l
->next
)
11178 if (l
->function_name
11179 && strcmp (e
->function_name
, l
->function_name
) == 0)
11189 if (!locations_are_equal (existing_locations
, b
->loc
))
11190 observer_notify_breakpoint_modified (b
);
11192 update_global_location_list (1);
11195 /* Find the SaL locations corresponding to the given ADDR_STRING.
11196 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11198 static struct symtabs_and_lines
11199 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11203 struct symtabs_and_lines sals
= {0};
11204 struct gdb_exception e
;
11207 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11209 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11213 sals
= decode_static_tracepoint_spec (&s
);
11214 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
11216 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
11220 error (_("marker %s not found"), b
->static_trace_marker_id
);
11223 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11227 int not_found_and_ok
= 0;
11228 /* For pending breakpoints, it's expected that parsing will
11229 fail until the right shared library is loaded. User has
11230 already told to create pending breakpoints and don't need
11231 extra messages. If breakpoint is in bp_shlib_disabled
11232 state, then user already saw the message about that
11233 breakpoint being disabled, and don't want to see more
11235 if (e
.error
== NOT_FOUND_ERROR
11236 && (b
->condition_not_parsed
11237 || (b
->loc
&& b
->loc
->shlib_disabled
)
11238 || b
->enable_state
== bp_disabled
))
11239 not_found_and_ok
= 1;
11241 if (!not_found_and_ok
)
11243 /* We surely don't want to warn about the same breakpoint
11244 10 times. One solution, implemented here, is disable
11245 the breakpoint on error. Another solution would be to
11246 have separate 'warning emitted' flag. Since this
11247 happens only when a binary has changed, I don't know
11248 which approach is better. */
11249 b
->enable_state
= bp_disabled
;
11250 throw_exception (e
);
11254 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11256 gdb_assert (sals
.nelts
== 1);
11258 resolve_sal_pc (&sals
.sals
[0]);
11259 if (b
->condition_not_parsed
&& s
&& s
[0])
11261 char *cond_string
= 0;
11265 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11266 &cond_string
, &thread
, &task
);
11268 b
->cond_string
= cond_string
;
11269 b
->thread
= thread
;
11271 b
->condition_not_parsed
= 0;
11274 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11275 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11285 /* Reevaluate a hardware or software breakpoint and recreate its locations.
11286 This is necessary after symbols are read (e.g., an executable or DSO
11287 was loaded, or the inferior just started). */
11290 re_set_breakpoint (struct breakpoint
*b
)
11293 struct symtabs_and_lines sals
, sals_end
;
11294 struct symtabs_and_lines expanded
= {0};
11295 struct symtabs_and_lines expanded_end
= {0};
11296 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11298 input_radix
= b
->input_radix
;
11299 save_current_space_and_thread ();
11300 switch_to_program_space_and_thread (b
->pspace
);
11301 set_language (b
->language
);
11303 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11306 make_cleanup (xfree
, sals
.sals
);
11307 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
11310 if (b
->addr_string_range_end
)
11312 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11315 make_cleanup (xfree
, sals_end
.sals
);
11316 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
11320 update_breakpoint_locations (b
, expanded
, expanded_end
);
11321 do_cleanups (cleanups
);
11324 /* Reset a breakpoint given it's struct breakpoint * BINT.
11325 The value we return ends up being the return value from catch_errors.
11326 Unused in this case. */
11329 breakpoint_re_set_one (void *bint
)
11331 /* Get past catch_errs. */
11332 struct breakpoint
*b
= (struct breakpoint
*) bint
;
11337 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
11340 case bp_breakpoint
:
11341 case bp_hardware_breakpoint
:
11342 case bp_tracepoint
:
11343 case bp_fast_tracepoint
:
11344 case bp_static_tracepoint
:
11345 case bp_gnu_ifunc_resolver
:
11346 /* Do not attempt to re-set breakpoints disabled during startup. */
11347 if (b
->enable_state
== bp_startup_disabled
)
11350 if (b
->addr_string
== NULL
)
11352 /* Anything without a string can't be re-set. */
11353 delete_breakpoint (b
);
11357 re_set_breakpoint (b
);
11360 case bp_watchpoint
:
11361 case bp_hardware_watchpoint
:
11362 case bp_read_watchpoint
:
11363 case bp_access_watchpoint
:
11364 /* Watchpoint can be either on expression using entirely global
11365 variables, or it can be on local variables.
11367 Watchpoints of the first kind are never auto-deleted, and
11368 even persist across program restarts. Since they can use
11369 variables from shared libraries, we need to reparse
11370 expression as libraries are loaded and unloaded.
11372 Watchpoints on local variables can also change meaning as
11373 result of solib event. For example, if a watchpoint uses
11374 both a local and a global variables in expression, it's a
11375 local watchpoint, but unloading of a shared library will make
11376 the expression invalid. This is not a very common use case,
11377 but we still re-evaluate expression, to avoid surprises to
11380 Note that for local watchpoints, we re-evaluate it only if
11381 watchpoints frame id is still valid. If it's not, it means
11382 the watchpoint is out of scope and will be deleted soon. In
11383 fact, I'm not sure we'll ever be called in this case.
11385 If a local watchpoint's frame id is still valid, then
11386 b->exp_valid_block is likewise valid, and we can safely use it.
11388 Don't do anything about disabled watchpoints, since they will
11389 be reevaluated again when enabled. */
11390 update_watchpoint (b
, 1 /* reparse */);
11392 /* We needn't really do anything to reset these, since the mask
11393 that requests them is unaffected by e.g., new libraries being
11395 case bp_catchpoint
:
11399 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
11401 /* Delete overlay event and longjmp master breakpoints; they will be
11402 reset later by breakpoint_re_set. */
11403 case bp_overlay_event
:
11404 case bp_longjmp_master
:
11405 case bp_std_terminate_master
:
11406 case bp_exception_master
:
11407 delete_breakpoint (b
);
11410 /* This breakpoint is special, it's set up when the inferior
11411 starts and we really don't want to touch it. */
11412 case bp_shlib_event
:
11414 /* Like bp_shlib_event, this breakpoint type is special.
11415 Once it is set up, we do not want to touch it. */
11416 case bp_thread_event
:
11418 /* Keep temporary breakpoints, which can be encountered when we
11419 step over a dlopen call and SOLIB_ADD is resetting the
11420 breakpoints. Otherwise these should have been blown away via
11421 the cleanup chain or by breakpoint_init_inferior when we
11422 rerun the executable. */
11425 case bp_watchpoint_scope
:
11426 case bp_call_dummy
:
11427 case bp_std_terminate
:
11428 case bp_step_resume
:
11430 case bp_longjmp_resume
:
11432 case bp_exception_resume
:
11434 case bp_gnu_ifunc_resolver_return
:
11441 /* Re-set all breakpoints after symbols have been re-loaded. */
11443 breakpoint_re_set (void)
11445 struct breakpoint
*b
, *b_tmp
;
11446 enum language save_language
;
11447 int save_input_radix
;
11448 struct cleanup
*old_chain
;
11450 save_language
= current_language
->la_language
;
11451 save_input_radix
= input_radix
;
11452 old_chain
= save_current_program_space ();
11454 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11456 /* Format possible error msg. */
11457 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
11459 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
11460 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
11461 do_cleanups (cleanups
);
11463 set_language (save_language
);
11464 input_radix
= save_input_radix
;
11466 jit_breakpoint_re_set ();
11468 do_cleanups (old_chain
);
11470 create_overlay_event_breakpoint ();
11471 create_longjmp_master_breakpoint ();
11472 create_std_terminate_master_breakpoint ();
11473 create_exception_master_breakpoint ();
11476 /* Reset the thread number of this breakpoint:
11478 - If the breakpoint is for all threads, leave it as-is.
11479 - Else, reset it to the current thread for inferior_ptid. */
11481 breakpoint_re_set_thread (struct breakpoint
*b
)
11483 if (b
->thread
!= -1)
11485 if (in_thread_list (inferior_ptid
))
11486 b
->thread
= pid_to_thread_id (inferior_ptid
);
11488 /* We're being called after following a fork. The new fork is
11489 selected as current, and unless this was a vfork will have a
11490 different program space from the original thread. Reset that
11492 b
->loc
->pspace
= current_program_space
;
11496 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11497 If from_tty is nonzero, it prints a message to that effect,
11498 which ends with a period (no newline). */
11501 set_ignore_count (int bptnum
, int count
, int from_tty
)
11503 struct breakpoint
*b
;
11508 ALL_BREAKPOINTS (b
)
11509 if (b
->number
== bptnum
)
11511 if (is_tracepoint (b
))
11513 if (from_tty
&& count
!= 0)
11514 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11519 b
->ignore_count
= count
;
11523 printf_filtered (_("Will stop next time "
11524 "breakpoint %d is reached."),
11526 else if (count
== 1)
11527 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11530 printf_filtered (_("Will ignore next %d "
11531 "crossings of breakpoint %d."),
11534 breakpoints_changed ();
11535 observer_notify_breakpoint_modified (b
);
11539 error (_("No breakpoint number %d."), bptnum
);
11542 /* Command to set ignore-count of breakpoint N to COUNT. */
11545 ignore_command (char *args
, int from_tty
)
11551 error_no_arg (_("a breakpoint number"));
11553 num
= get_number (&p
);
11555 error (_("bad breakpoint number: '%s'"), args
);
11557 error (_("Second argument (specified ignore-count) is missing."));
11559 set_ignore_count (num
,
11560 longest_to_int (value_as_long (parse_and_eval (p
))),
11563 printf_filtered ("\n");
11566 /* Call FUNCTION on each of the breakpoints
11567 whose numbers are given in ARGS. */
11570 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
11575 struct breakpoint
*b
, *tmp
;
11577 struct get_number_or_range_state state
;
11580 error_no_arg (_("one or more breakpoint numbers"));
11582 init_number_or_range (&state
, args
);
11584 while (!state
.finished
)
11586 char *p
= state
.string
;
11590 num
= get_number_or_range (&state
);
11593 warning (_("bad breakpoint number at or near '%s'"), p
);
11597 ALL_BREAKPOINTS_SAFE (b
, tmp
)
11598 if (b
->number
== num
)
11600 struct breakpoint
*related_breakpoint
;
11603 related_breakpoint
= b
;
11606 struct breakpoint
*next_related_b
;
11608 /* FUNCTION can be also delete_breakpoint. */
11609 next_related_b
= related_breakpoint
->related_breakpoint
;
11610 function (related_breakpoint
, data
);
11612 /* For delete_breakpoint of the last entry of the ring we
11613 were traversing we would never get back to B. */
11614 if (next_related_b
== related_breakpoint
)
11616 related_breakpoint
= next_related_b
;
11618 while (related_breakpoint
!= b
);
11622 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
11627 static struct bp_location
*
11628 find_location_by_number (char *number
)
11630 char *dot
= strchr (number
, '.');
11634 struct breakpoint
*b
;
11635 struct bp_location
*loc
;
11640 bp_num
= get_number (&p1
);
11642 error (_("Bad breakpoint number '%s'"), number
);
11644 ALL_BREAKPOINTS (b
)
11645 if (b
->number
== bp_num
)
11650 if (!b
|| b
->number
!= bp_num
)
11651 error (_("Bad breakpoint number '%s'"), number
);
11654 loc_num
= get_number (&p1
);
11656 error (_("Bad breakpoint location number '%s'"), number
);
11660 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
11663 error (_("Bad breakpoint location number '%s'"), dot
+1);
11669 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11670 If from_tty is nonzero, it prints a message to that effect,
11671 which ends with a period (no newline). */
11674 disable_breakpoint (struct breakpoint
*bpt
)
11676 /* Never disable a watchpoint scope breakpoint; we want to
11677 hit them when we leave scope so we can delete both the
11678 watchpoint and its scope breakpoint at that time. */
11679 if (bpt
->type
== bp_watchpoint_scope
)
11682 /* You can't disable permanent breakpoints. */
11683 if (bpt
->enable_state
== bp_permanent
)
11686 bpt
->enable_state
= bp_disabled
;
11688 update_global_location_list (0);
11690 observer_notify_breakpoint_modified (bpt
);
11693 /* A callback for map_breakpoint_numbers that calls
11694 disable_breakpoint. */
11697 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
11699 disable_breakpoint (b
);
11703 disable_command (char *args
, int from_tty
)
11707 struct breakpoint
*bpt
;
11709 ALL_BREAKPOINTS (bpt
)
11710 if (user_breakpoint_p (bpt
))
11711 disable_breakpoint (bpt
);
11713 else if (strchr (args
, '.'))
11715 struct bp_location
*loc
= find_location_by_number (args
);
11718 update_global_location_list (0);
11721 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
11725 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
11727 int target_resources_ok
;
11729 if (bpt
->type
== bp_hardware_breakpoint
)
11732 i
= hw_breakpoint_used_count ();
11733 target_resources_ok
=
11734 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
11736 if (target_resources_ok
== 0)
11737 error (_("No hardware breakpoint support in the target."));
11738 else if (target_resources_ok
< 0)
11739 error (_("Hardware breakpoints used exceeds limit."));
11742 if (is_watchpoint (bpt
))
11744 /* Initialize it just to avoid a GCC false warning. */
11745 enum enable_state orig_enable_state
= 0;
11746 struct gdb_exception e
;
11748 TRY_CATCH (e
, RETURN_MASK_ALL
)
11750 orig_enable_state
= bpt
->enable_state
;
11751 bpt
->enable_state
= bp_enabled
;
11752 update_watchpoint (bpt
, 1 /* reparse */);
11756 bpt
->enable_state
= orig_enable_state
;
11757 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
11763 if (bpt
->enable_state
!= bp_permanent
)
11764 bpt
->enable_state
= bp_enabled
;
11765 bpt
->disposition
= disposition
;
11766 update_global_location_list (1);
11767 breakpoints_changed ();
11769 observer_notify_breakpoint_modified (bpt
);
11774 enable_breakpoint (struct breakpoint
*bpt
)
11776 do_enable_breakpoint (bpt
, bpt
->disposition
);
11779 /* A callback for map_breakpoint_numbers that calls
11780 enable_breakpoint. */
11783 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
11785 enable_breakpoint (b
);
11788 /* The enable command enables the specified breakpoints (or all defined
11789 breakpoints) so they once again become (or continue to be) effective
11790 in stopping the inferior. */
11793 enable_command (char *args
, int from_tty
)
11797 struct breakpoint
*bpt
;
11799 ALL_BREAKPOINTS (bpt
)
11800 if (user_breakpoint_p (bpt
))
11801 enable_breakpoint (bpt
);
11803 else if (strchr (args
, '.'))
11805 struct bp_location
*loc
= find_location_by_number (args
);
11808 update_global_location_list (1);
11811 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
11815 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11817 do_enable_breakpoint (bpt
, disp_disable
);
11821 enable_once_command (char *args
, int from_tty
)
11823 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
11827 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11829 do_enable_breakpoint (bpt
, disp_del
);
11833 enable_delete_command (char *args
, int from_tty
)
11835 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
11839 set_breakpoint_cmd (char *args
, int from_tty
)
11844 show_breakpoint_cmd (char *args
, int from_tty
)
11848 /* Invalidate last known value of any hardware watchpoint if
11849 the memory which that value represents has been written to by
11853 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
11854 const bfd_byte
*data
)
11856 struct breakpoint
*bp
;
11858 ALL_BREAKPOINTS (bp
)
11859 if (bp
->enable_state
== bp_enabled
11860 && bp
->type
== bp_hardware_watchpoint
11861 && bp
->val_valid
&& bp
->val
)
11863 struct bp_location
*loc
;
11865 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
11866 if (loc
->loc_type
== bp_loc_hardware_watchpoint
11867 && loc
->address
+ loc
->length
> addr
11868 && addr
+ len
> loc
->address
)
11870 value_free (bp
->val
);
11877 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11879 struct symtabs_and_lines
11880 decode_line_spec_1 (char *string
, int funfirstline
)
11882 struct symtabs_and_lines sals
;
11885 error (_("Empty line specification."));
11886 if (default_breakpoint_valid
)
11887 sals
= decode_line_1 (&string
, funfirstline
,
11888 default_breakpoint_symtab
,
11889 default_breakpoint_line
,
11892 sals
= decode_line_1 (&string
, funfirstline
,
11893 (struct symtab
*) NULL
, 0, NULL
);
11895 error (_("Junk at end of line specification: %s"), string
);
11899 /* Create and insert a raw software breakpoint at PC. Return an
11900 identifier, which should be used to remove the breakpoint later.
11901 In general, places which call this should be using something on the
11902 breakpoint chain instead; this function should be eliminated
11906 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11907 struct address_space
*aspace
, CORE_ADDR pc
)
11909 struct bp_target_info
*bp_tgt
;
11911 bp_tgt
= XZALLOC (struct bp_target_info
);
11913 bp_tgt
->placed_address_space
= aspace
;
11914 bp_tgt
->placed_address
= pc
;
11916 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11918 /* Could not insert the breakpoint. */
11926 /* Remove a breakpoint BP inserted by
11927 deprecated_insert_raw_breakpoint. */
11930 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11932 struct bp_target_info
*bp_tgt
= bp
;
11935 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11941 /* One (or perhaps two) breakpoints used for software single
11944 static void *single_step_breakpoints
[2];
11945 static struct gdbarch
*single_step_gdbarch
[2];
11947 /* Create and insert a breakpoint for software single step. */
11950 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11951 struct address_space
*aspace
,
11956 if (single_step_breakpoints
[0] == NULL
)
11958 bpt_p
= &single_step_breakpoints
[0];
11959 single_step_gdbarch
[0] = gdbarch
;
11963 gdb_assert (single_step_breakpoints
[1] == NULL
);
11964 bpt_p
= &single_step_breakpoints
[1];
11965 single_step_gdbarch
[1] = gdbarch
;
11968 /* NOTE drow/2006-04-11: A future improvement to this function would
11969 be to only create the breakpoints once, and actually put them on
11970 the breakpoint chain. That would let us use set_raw_breakpoint.
11971 We could adjust the addresses each time they were needed. Doing
11972 this requires corresponding changes elsewhere where single step
11973 breakpoints are handled, however. So, for now, we use this. */
11975 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11976 if (*bpt_p
== NULL
)
11977 error (_("Could not insert single-step breakpoint at %s"),
11978 paddress (gdbarch
, next_pc
));
11981 /* Check if the breakpoints used for software single stepping
11982 were inserted or not. */
11985 single_step_breakpoints_inserted (void)
11987 return (single_step_breakpoints
[0] != NULL
11988 || single_step_breakpoints
[1] != NULL
);
11991 /* Remove and delete any breakpoints used for software single step. */
11994 remove_single_step_breakpoints (void)
11996 gdb_assert (single_step_breakpoints
[0] != NULL
);
11998 /* See insert_single_step_breakpoint for more about this deprecated
12000 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12001 single_step_breakpoints
[0]);
12002 single_step_gdbarch
[0] = NULL
;
12003 single_step_breakpoints
[0] = NULL
;
12005 if (single_step_breakpoints
[1] != NULL
)
12007 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12008 single_step_breakpoints
[1]);
12009 single_step_gdbarch
[1] = NULL
;
12010 single_step_breakpoints
[1] = NULL
;
12014 /* Delete software single step breakpoints without removing them from
12015 the inferior. This is intended to be used if the inferior's address
12016 space where they were inserted is already gone, e.g. after exit or
12020 cancel_single_step_breakpoints (void)
12024 for (i
= 0; i
< 2; i
++)
12025 if (single_step_breakpoints
[i
])
12027 xfree (single_step_breakpoints
[i
]);
12028 single_step_breakpoints
[i
] = NULL
;
12029 single_step_gdbarch
[i
] = NULL
;
12033 /* Detach software single-step breakpoints from INFERIOR_PTID without
12037 detach_single_step_breakpoints (void)
12041 for (i
= 0; i
< 2; i
++)
12042 if (single_step_breakpoints
[i
])
12043 target_remove_breakpoint (single_step_gdbarch
[i
],
12044 single_step_breakpoints
[i
]);
12047 /* Check whether a software single-step breakpoint is inserted at
12051 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12056 for (i
= 0; i
< 2; i
++)
12058 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12060 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12061 bp_tgt
->placed_address
,
12069 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12070 non-zero otherwise. */
12072 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12074 if (syscall_catchpoint_p (bp
)
12075 && bp
->enable_state
!= bp_disabled
12076 && bp
->enable_state
!= bp_call_disabled
)
12083 catch_syscall_enabled (void)
12085 struct inferior
*inf
= current_inferior ();
12087 return inf
->total_syscalls_count
!= 0;
12091 catching_syscall_number (int syscall_number
)
12093 struct breakpoint
*bp
;
12095 ALL_BREAKPOINTS (bp
)
12096 if (is_syscall_catchpoint_enabled (bp
))
12098 if (bp
->syscalls_to_be_caught
)
12102 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
12104 if (syscall_number
== iter
)
12114 /* Complete syscall names. Used by "catch syscall". */
12116 catch_syscall_completer (struct cmd_list_element
*cmd
,
12117 char *text
, char *word
)
12119 const char **list
= get_syscall_names ();
12121 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12127 /* Tracepoint-specific operations. */
12129 /* Set tracepoint count to NUM. */
12131 set_tracepoint_count (int num
)
12133 tracepoint_count
= num
;
12134 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12138 trace_command (char *arg
, int from_tty
)
12140 if (create_breakpoint (get_current_arch (),
12142 NULL
, 0, 1 /* parse arg */,
12144 bp_tracepoint
/* type_wanted */,
12145 0 /* Ignore count */,
12146 pending_break_support
,
12151 set_tracepoint_count (breakpoint_count
);
12155 ftrace_command (char *arg
, int from_tty
)
12157 if (create_breakpoint (get_current_arch (),
12159 NULL
, 0, 1 /* parse arg */,
12161 bp_fast_tracepoint
/* type_wanted */,
12162 0 /* Ignore count */,
12163 pending_break_support
,
12168 set_tracepoint_count (breakpoint_count
);
12171 /* strace command implementation. Creates a static tracepoint. */
12174 strace_command (char *arg
, int from_tty
)
12176 if (create_breakpoint (get_current_arch (),
12178 NULL
, 0, 1 /* parse arg */,
12180 bp_static_tracepoint
/* type_wanted */,
12181 0 /* Ignore count */,
12182 pending_break_support
,
12187 set_tracepoint_count (breakpoint_count
);
12190 /* Set up a fake reader function that gets command lines from a linked
12191 list that was acquired during tracepoint uploading. */
12193 static struct uploaded_tp
*this_utp
;
12194 static int next_cmd
;
12197 read_uploaded_action (void)
12201 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12208 /* Given information about a tracepoint as recorded on a target (which
12209 can be either a live system or a trace file), attempt to create an
12210 equivalent GDB tracepoint. This is not a reliable process, since
12211 the target does not necessarily have all the information used when
12212 the tracepoint was originally defined. */
12214 struct breakpoint
*
12215 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12217 char *addr_str
, small_buf
[100];
12218 struct breakpoint
*tp
;
12220 if (utp
->at_string
)
12221 addr_str
= utp
->at_string
;
12224 /* In the absence of a source location, fall back to raw
12225 address. Since there is no way to confirm that the address
12226 means the same thing as when the trace was started, warn the
12228 warning (_("Uploaded tracepoint %d has no "
12229 "source location, using raw address"),
12231 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12232 addr_str
= small_buf
;
12235 /* There's not much we can do with a sequence of bytecodes. */
12236 if (utp
->cond
&& !utp
->cond_string
)
12237 warning (_("Uploaded tracepoint %d condition "
12238 "has no source form, ignoring it"),
12241 if (!create_breakpoint (get_current_arch (),
12243 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12245 utp
->type
/* type_wanted */,
12246 0 /* Ignore count */,
12247 pending_break_support
,
12250 utp
->enabled
/* enabled */,
12254 set_tracepoint_count (breakpoint_count
);
12256 /* Get the tracepoint we just created. */
12257 tp
= get_tracepoint (tracepoint_count
);
12258 gdb_assert (tp
!= NULL
);
12262 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
12264 trace_pass_command (small_buf
, 0);
12267 /* If we have uploaded versions of the original commands, set up a
12268 special-purpose "reader" function and call the usual command line
12269 reader, then pass the result to the breakpoint command-setting
12271 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12273 struct command_line
*cmd_list
;
12278 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12280 breakpoint_set_commands (tp
, cmd_list
);
12282 else if (!VEC_empty (char_ptr
, utp
->actions
)
12283 || !VEC_empty (char_ptr
, utp
->step_actions
))
12284 warning (_("Uploaded tracepoint %d actions "
12285 "have no source form, ignoring them"),
12291 /* Print information on tracepoint number TPNUM_EXP, or all if
12295 tracepoints_info (char *args
, int from_tty
)
12299 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12301 if (num_printed
== 0)
12303 if (args
== NULL
|| *args
== '\0')
12304 ui_out_message (uiout
, 0, "No tracepoints.\n");
12306 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12309 default_collect_info ();
12312 /* The 'enable trace' command enables tracepoints.
12313 Not supported by all targets. */
12315 enable_trace_command (char *args
, int from_tty
)
12317 enable_command (args
, from_tty
);
12320 /* The 'disable trace' command disables tracepoints.
12321 Not supported by all targets. */
12323 disable_trace_command (char *args
, int from_tty
)
12325 disable_command (args
, from_tty
);
12328 /* Remove a tracepoint (or all if no argument). */
12330 delete_trace_command (char *arg
, int from_tty
)
12332 struct breakpoint
*b
, *b_tmp
;
12338 int breaks_to_delete
= 0;
12340 /* Delete all breakpoints if no argument.
12341 Do not delete internal or call-dummy breakpoints, these
12342 have to be deleted with an explicit breakpoint number
12344 ALL_TRACEPOINTS (b
)
12345 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12347 breaks_to_delete
= 1;
12351 /* Ask user only if there are some breakpoints to delete. */
12353 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12355 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12356 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12357 delete_breakpoint (b
);
12361 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
12364 /* Helper function for trace_pass_command. */
12367 trace_pass_set_count (struct breakpoint
*bp
, int count
, int from_tty
)
12369 bp
->pass_count
= count
;
12370 observer_notify_tracepoint_modified (bp
->number
);
12372 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12373 bp
->number
, count
);
12376 /* Set passcount for tracepoint.
12378 First command argument is passcount, second is tracepoint number.
12379 If tracepoint number omitted, apply to most recently defined.
12380 Also accepts special argument "all". */
12383 trace_pass_command (char *args
, int from_tty
)
12385 struct breakpoint
*t1
;
12386 unsigned int count
;
12388 if (args
== 0 || *args
== 0)
12389 error (_("passcount command requires an "
12390 "argument (count + optional TP num)"));
12392 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
12394 while (*args
&& isspace ((int) *args
))
12397 if (*args
&& strncasecmp (args
, "all", 3) == 0)
12399 args
+= 3; /* Skip special argument "all". */
12401 error (_("Junk at end of arguments."));
12403 ALL_TRACEPOINTS (t1
)
12405 trace_pass_set_count (t1
, count
, from_tty
);
12408 else if (*args
== '\0')
12410 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
12412 trace_pass_set_count (t1
, count
, from_tty
);
12416 struct get_number_or_range_state state
;
12418 init_number_or_range (&state
, args
);
12419 while (!state
.finished
)
12421 t1
= get_tracepoint_by_number (&args
, &state
, 1);
12423 trace_pass_set_count (t1
, count
, from_tty
);
12428 struct breakpoint
*
12429 get_tracepoint (int num
)
12431 struct breakpoint
*t
;
12433 ALL_TRACEPOINTS (t
)
12434 if (t
->number
== num
)
12440 /* Find the tracepoint with the given target-side number (which may be
12441 different from the tracepoint number after disconnecting and
12444 struct breakpoint
*
12445 get_tracepoint_by_number_on_target (int num
)
12447 struct breakpoint
*t
;
12449 ALL_TRACEPOINTS (t
)
12450 if (t
->number_on_target
== num
)
12456 /* Utility: parse a tracepoint number and look it up in the list.
12457 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12458 If OPTIONAL_P is true, then if the argument is missing, the most
12459 recent tracepoint (tracepoint_count) is returned. */
12460 struct breakpoint
*
12461 get_tracepoint_by_number (char **arg
,
12462 struct get_number_or_range_state
*state
,
12465 extern int tracepoint_count
;
12466 struct breakpoint
*t
;
12468 char *instring
= arg
== NULL
? NULL
: *arg
;
12472 gdb_assert (!state
->finished
);
12473 tpnum
= get_number_or_range (state
);
12475 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
12478 tpnum
= tracepoint_count
;
12480 error_no_arg (_("tracepoint number"));
12483 tpnum
= get_number (arg
);
12487 if (instring
&& *instring
)
12488 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12491 printf_filtered (_("Tracepoint argument missing "
12492 "and no previous tracepoint\n"));
12496 ALL_TRACEPOINTS (t
)
12497 if (t
->number
== tpnum
)
12502 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
12506 /* Save information on user settable breakpoints (watchpoints, etc) to
12507 a new script file named FILENAME. If FILTER is non-NULL, call it
12508 on each breakpoint and only include the ones for which it returns
12512 save_breakpoints (char *filename
, int from_tty
,
12513 int (*filter
) (const struct breakpoint
*))
12515 struct breakpoint
*tp
;
12518 struct cleanup
*cleanup
;
12519 struct ui_file
*fp
;
12520 int extra_trace_bits
= 0;
12522 if (filename
== 0 || *filename
== 0)
12523 error (_("Argument required (file name in which to save)"));
12525 /* See if we have anything to save. */
12526 ALL_BREAKPOINTS (tp
)
12528 /* Skip internal and momentary breakpoints. */
12529 if (!user_breakpoint_p (tp
))
12532 /* If we have a filter, only save the breakpoints it accepts. */
12533 if (filter
&& !filter (tp
))
12538 if (is_tracepoint (tp
))
12540 extra_trace_bits
= 1;
12542 /* We can stop searching. */
12549 warning (_("Nothing to save."));
12553 pathname
= tilde_expand (filename
);
12554 cleanup
= make_cleanup (xfree
, pathname
);
12555 fp
= gdb_fopen (pathname
, "w");
12557 error (_("Unable to open file '%s' for saving (%s)"),
12558 filename
, safe_strerror (errno
));
12559 make_cleanup_ui_file_delete (fp
);
12561 if (extra_trace_bits
)
12562 save_trace_state_variables (fp
);
12564 ALL_BREAKPOINTS (tp
)
12566 /* Skip internal and momentary breakpoints. */
12567 if (!user_breakpoint_p (tp
))
12570 /* If we have a filter, only save the breakpoints it accepts. */
12571 if (filter
&& !filter (tp
))
12574 if (tp
->ops
!= NULL
&& tp
->ops
->print_recreate
!= NULL
)
12575 (tp
->ops
->print_recreate
) (tp
, fp
);
12578 if (tp
->type
== bp_fast_tracepoint
)
12579 fprintf_unfiltered (fp
, "ftrace");
12580 if (tp
->type
== bp_static_tracepoint
)
12581 fprintf_unfiltered (fp
, "strace");
12582 else if (tp
->type
== bp_tracepoint
)
12583 fprintf_unfiltered (fp
, "trace");
12584 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12585 fprintf_unfiltered (fp
, "tbreak");
12586 else if (tp
->type
== bp_breakpoint
)
12587 fprintf_unfiltered (fp
, "break");
12588 else if (tp
->type
== bp_hardware_breakpoint
12589 && tp
->disposition
== disp_del
)
12590 fprintf_unfiltered (fp
, "thbreak");
12591 else if (tp
->type
== bp_hardware_breakpoint
)
12592 fprintf_unfiltered (fp
, "hbreak");
12593 else if (tp
->type
== bp_watchpoint
)
12594 fprintf_unfiltered (fp
, "watch");
12595 else if (tp
->type
== bp_hardware_watchpoint
)
12596 fprintf_unfiltered (fp
, "watch");
12597 else if (tp
->type
== bp_read_watchpoint
)
12598 fprintf_unfiltered (fp
, "rwatch");
12599 else if (tp
->type
== bp_access_watchpoint
)
12600 fprintf_unfiltered (fp
, "awatch");
12602 internal_error (__FILE__
, __LINE__
,
12603 _("unhandled breakpoint type %d"), (int) tp
->type
);
12605 if (tp
->exp_string
)
12606 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
12607 else if (tp
->addr_string
)
12608 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12613 sprintf_vma (tmp
, tp
->loc
->address
);
12614 fprintf_unfiltered (fp
, " *0x%s", tmp
);
12618 if (tp
->thread
!= -1)
12619 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
12622 fprintf_unfiltered (fp
, " task %d", tp
->task
);
12624 fprintf_unfiltered (fp
, "\n");
12626 /* Note, we can't rely on tp->number for anything, as we can't
12627 assume the recreated breakpoint numbers will match. Use $bpnum
12630 if (tp
->cond_string
)
12631 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
12633 if (tp
->ignore_count
)
12634 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
12636 if (tp
->pass_count
)
12637 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12641 volatile struct gdb_exception ex
;
12643 fprintf_unfiltered (fp
, " commands\n");
12645 ui_out_redirect (uiout
, fp
);
12646 TRY_CATCH (ex
, RETURN_MASK_ALL
)
12648 print_command_lines (uiout
, tp
->commands
->commands
, 2);
12650 ui_out_redirect (uiout
, NULL
);
12653 throw_exception (ex
);
12655 fprintf_unfiltered (fp
, " end\n");
12658 if (tp
->enable_state
== bp_disabled
)
12659 fprintf_unfiltered (fp
, "disable\n");
12661 /* If this is a multi-location breakpoint, check if the locations
12662 should be individually disabled. Watchpoint locations are
12663 special, and not user visible. */
12664 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
12666 struct bp_location
*loc
;
12669 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
12671 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
12675 if (extra_trace_bits
&& *default_collect
)
12676 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
12678 do_cleanups (cleanup
);
12680 printf_filtered (_("Saved to file '%s'.\n"), filename
);
12683 /* The `save breakpoints' command. */
12686 save_breakpoints_command (char *args
, int from_tty
)
12688 save_breakpoints (args
, from_tty
, NULL
);
12691 /* The `save tracepoints' command. */
12694 save_tracepoints_command (char *args
, int from_tty
)
12696 save_breakpoints (args
, from_tty
, is_tracepoint
);
12699 /* Create a vector of all tracepoints. */
12701 VEC(breakpoint_p
) *
12702 all_tracepoints (void)
12704 VEC(breakpoint_p
) *tp_vec
= 0;
12705 struct breakpoint
*tp
;
12707 ALL_TRACEPOINTS (tp
)
12709 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
12716 /* This help string is used for the break, hbreak, tbreak and thbreak
12717 commands. It is defined as a macro to prevent duplication.
12718 COMMAND should be a string constant containing the name of the
12720 #define BREAK_ARGS_HELP(command) \
12721 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
12722 LOCATION may be a line number, function name, or \"*\" and an address.\n\
12723 If a line number is specified, break at start of code for that line.\n\
12724 If a function is specified, break at start of code for that function.\n\
12725 If an address is specified, break at that exact address.\n\
12726 With no LOCATION, uses current execution address of the selected\n\
12727 stack frame. This is useful for breaking on return to a stack frame.\n\
12729 THREADNUM is the number from \"info threads\".\n\
12730 CONDITION is a boolean expression.\n\
12732 Multiple breakpoints at one place are permitted, and useful if their\n\
12733 conditions are different.\n\
12735 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
12737 /* List of subcommands for "catch". */
12738 static struct cmd_list_element
*catch_cmdlist
;
12740 /* List of subcommands for "tcatch". */
12741 static struct cmd_list_element
*tcatch_cmdlist
;
12743 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
12744 lists, and pass some additional user data to the command function. */
12746 add_catch_command (char *name
, char *docstring
,
12747 void (*sfunc
) (char *args
, int from_tty
,
12748 struct cmd_list_element
*command
),
12749 char **(*completer
) (struct cmd_list_element
*cmd
,
12750 char *text
, char *word
),
12751 void *user_data_catch
,
12752 void *user_data_tcatch
)
12754 struct cmd_list_element
*command
;
12756 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12758 set_cmd_sfunc (command
, sfunc
);
12759 set_cmd_context (command
, user_data_catch
);
12760 set_cmd_completer (command
, completer
);
12762 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12764 set_cmd_sfunc (command
, sfunc
);
12765 set_cmd_context (command
, user_data_tcatch
);
12766 set_cmd_completer (command
, completer
);
12770 clear_syscall_counts (struct inferior
*inf
)
12772 inf
->total_syscalls_count
= 0;
12773 inf
->any_syscall_count
= 0;
12774 VEC_free (int, inf
->syscalls_counts
);
12778 save_command (char *arg
, int from_tty
)
12780 printf_unfiltered (_("\"save\" must be followed by "
12781 "the name of a save subcommand.\n"));
12782 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
12785 struct breakpoint
*
12786 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
12789 struct breakpoint
*b
, *b_tmp
;
12791 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12793 if ((*callback
) (b
, data
))
12801 _initialize_breakpoint (void)
12803 struct cmd_list_element
*c
;
12805 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
12806 observer_attach_inferior_exit (clear_syscall_counts
);
12807 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
12809 breakpoint_objfile_key
= register_objfile_data ();
12811 breakpoint_chain
= 0;
12812 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12813 before a breakpoint is set. */
12814 breakpoint_count
= 0;
12816 tracepoint_count
= 0;
12818 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
12819 Set ignore-count of breakpoint number N to COUNT.\n\
12820 Usage is `ignore N COUNT'."));
12822 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
12824 add_com ("commands", class_breakpoint
, commands_command
, _("\
12825 Set commands to be executed when a breakpoint is hit.\n\
12826 Give breakpoint number as argument after \"commands\".\n\
12827 With no argument, the targeted breakpoint is the last one set.\n\
12828 The commands themselves follow starting on the next line.\n\
12829 Type a line containing \"end\" to indicate the end of them.\n\
12830 Give \"silent\" as the first line to make the breakpoint silent;\n\
12831 then no output is printed when it is hit, except what the commands print."));
12833 add_com ("condition", class_breakpoint
, condition_command
, _("\
12834 Specify breakpoint number N to break only if COND is true.\n\
12835 Usage is `condition N COND', where N is an integer and COND is an\n\
12836 expression to be evaluated whenever breakpoint N is reached."));
12838 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
12839 Set a temporary breakpoint.\n\
12840 Like \"break\" except the breakpoint is only temporary,\n\
12841 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12842 by using \"enable delete\" on the breakpoint number.\n\
12844 BREAK_ARGS_HELP ("tbreak")));
12845 set_cmd_completer (c
, location_completer
);
12847 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
12848 Set a hardware assisted breakpoint.\n\
12849 Like \"break\" except the breakpoint requires hardware support,\n\
12850 some target hardware may not have this support.\n\
12852 BREAK_ARGS_HELP ("hbreak")));
12853 set_cmd_completer (c
, location_completer
);
12855 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
12856 Set a temporary hardware assisted breakpoint.\n\
12857 Like \"hbreak\" except the breakpoint is only temporary,\n\
12858 so it will be deleted when hit.\n\
12860 BREAK_ARGS_HELP ("thbreak")));
12861 set_cmd_completer (c
, location_completer
);
12863 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
12864 Enable some breakpoints.\n\
12865 Give breakpoint numbers (separated by spaces) as arguments.\n\
12866 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12867 This is used to cancel the effect of the \"disable\" command.\n\
12868 With a subcommand you can enable temporarily."),
12869 &enablelist
, "enable ", 1, &cmdlist
);
12871 add_com ("ab", class_breakpoint
, enable_command
, _("\
12872 Enable some breakpoints.\n\
12873 Give breakpoint numbers (separated by spaces) as arguments.\n\
12874 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12875 This is used to cancel the effect of the \"disable\" command.\n\
12876 With a subcommand you can enable temporarily."));
12878 add_com_alias ("en", "enable", class_breakpoint
, 1);
12880 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
12881 Enable some breakpoints.\n\
12882 Give breakpoint numbers (separated by spaces) as arguments.\n\
12883 This is used to cancel the effect of the \"disable\" command.\n\
12884 May be abbreviated to simply \"enable\".\n"),
12885 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
12887 add_cmd ("once", no_class
, enable_once_command
, _("\
12888 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12889 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12892 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12893 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12894 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12897 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12898 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12899 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12902 add_cmd ("once", no_class
, enable_once_command
, _("\
12903 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12904 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12907 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12908 Disable some breakpoints.\n\
12909 Arguments are breakpoint numbers with spaces in between.\n\
12910 To disable all breakpoints, give no argument.\n\
12911 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12912 &disablelist
, "disable ", 1, &cmdlist
);
12913 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12914 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12916 add_com ("sb", class_breakpoint
, disable_command
, _("\
12917 Disable some breakpoints.\n\
12918 Arguments are breakpoint numbers with spaces in between.\n\
12919 To disable all breakpoints, give no argument.\n\
12920 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12922 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12923 Disable some breakpoints.\n\
12924 Arguments are breakpoint numbers with spaces in between.\n\
12925 To disable all breakpoints, give no argument.\n\
12926 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12927 This command may be abbreviated \"disable\"."),
12930 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12931 Delete some breakpoints or auto-display expressions.\n\
12932 Arguments are breakpoint numbers with spaces in between.\n\
12933 To delete all breakpoints, give no argument.\n\
12935 Also a prefix command for deletion of other GDB objects.\n\
12936 The \"unset\" command is also an alias for \"delete\"."),
12937 &deletelist
, "delete ", 1, &cmdlist
);
12938 add_com_alias ("d", "delete", class_breakpoint
, 1);
12939 add_com_alias ("del", "delete", class_breakpoint
, 1);
12941 add_com ("db", class_breakpoint
, delete_command
, _("\
12942 Delete some breakpoints.\n\
12943 Arguments are breakpoint numbers with spaces in between.\n\
12944 To delete all breakpoints, give no argument.\n"));
12946 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12947 Delete some breakpoints or auto-display expressions.\n\
12948 Arguments are breakpoint numbers with spaces in between.\n\
12949 To delete all breakpoints, give no argument.\n\
12950 This command may be abbreviated \"delete\"."),
12953 add_com ("clear", class_breakpoint
, clear_command
, _("\
12954 Clear breakpoint at specified line or function.\n\
12955 Argument may be line number, function name, or \"*\" and an address.\n\
12956 If line number is specified, all breakpoints in that line are cleared.\n\
12957 If function is specified, breakpoints at beginning of function are cleared.\n\
12958 If an address is specified, breakpoints at that address are cleared.\n\
12960 With no argument, clears all breakpoints in the line that the selected frame\n\
12961 is executing in.\n\
12963 See also the \"delete\" command which clears breakpoints by number."));
12964 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12966 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12967 Set breakpoint at specified line or function.\n"
12968 BREAK_ARGS_HELP ("break")));
12969 set_cmd_completer (c
, location_completer
);
12971 add_com_alias ("b", "break", class_run
, 1);
12972 add_com_alias ("br", "break", class_run
, 1);
12973 add_com_alias ("bre", "break", class_run
, 1);
12974 add_com_alias ("brea", "break", class_run
, 1);
12977 add_com_alias ("ba", "break", class_breakpoint
, 1);
12981 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12982 Break in function/address or break at a line in the current file."),
12983 &stoplist
, "stop ", 1, &cmdlist
);
12984 add_cmd ("in", class_breakpoint
, stopin_command
,
12985 _("Break in function or address."), &stoplist
);
12986 add_cmd ("at", class_breakpoint
, stopat_command
,
12987 _("Break at a line in the current file."), &stoplist
);
12988 add_com ("status", class_info
, breakpoints_info
, _("\
12989 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12990 The \"Type\" column indicates one of:\n\
12991 \tbreakpoint - normal breakpoint\n\
12992 \twatchpoint - watchpoint\n\
12993 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12994 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12995 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12996 address and file/line number respectively.\n\
12998 Convenience variable \"$_\" and default examine address for \"x\"\n\
12999 are set to the address of the last breakpoint listed unless the command\n\
13000 is prefixed with \"server \".\n\n\
13001 Convenience variable \"$bpnum\" contains the number of the last\n\
13002 breakpoint set."));
13005 add_info ("breakpoints", breakpoints_info
, _("\
13006 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13007 The \"Type\" column indicates one of:\n\
13008 \tbreakpoint - normal breakpoint\n\
13009 \twatchpoint - watchpoint\n\
13010 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13011 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13012 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13013 address and file/line number respectively.\n\
13015 Convenience variable \"$_\" and default examine address for \"x\"\n\
13016 are set to the address of the last breakpoint listed unless the command\n\
13017 is prefixed with \"server \".\n\n\
13018 Convenience variable \"$bpnum\" contains the number of the last\n\
13019 breakpoint set."));
13021 add_info_alias ("b", "breakpoints", 1);
13024 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13025 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13026 The \"Type\" column indicates one of:\n\
13027 \tbreakpoint - normal breakpoint\n\
13028 \twatchpoint - watchpoint\n\
13029 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13030 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13031 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13032 address and file/line number respectively.\n\
13034 Convenience variable \"$_\" and default examine address for \"x\"\n\
13035 are set to the address of the last breakpoint listed unless the command\n\
13036 is prefixed with \"server \".\n\n\
13037 Convenience variable \"$bpnum\" contains the number of the last\n\
13038 breakpoint set."));
13040 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13041 Status of all breakpoints, or breakpoint number NUMBER.\n\
13042 The \"Type\" column indicates one of:\n\
13043 \tbreakpoint - normal breakpoint\n\
13044 \twatchpoint - watchpoint\n\
13045 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13046 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13047 \tuntil - internal breakpoint used by the \"until\" command\n\
13048 \tfinish - internal breakpoint used by the \"finish\" command\n\
13049 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13050 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13051 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13052 address and file/line number respectively.\n\
13054 Convenience variable \"$_\" and default examine address for \"x\"\n\
13055 are set to the address of the last breakpoint listed unless the command\n\
13056 is prefixed with \"server \".\n\n\
13057 Convenience variable \"$bpnum\" contains the number of the last\n\
13059 &maintenanceinfolist
);
13061 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13062 Set catchpoints to catch events."),
13063 &catch_cmdlist
, "catch ",
13064 0/*allow-unknown*/, &cmdlist
);
13066 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13067 Set temporary catchpoints to catch events."),
13068 &tcatch_cmdlist
, "tcatch ",
13069 0/*allow-unknown*/, &cmdlist
);
13071 /* Add catch and tcatch sub-commands. */
13072 add_catch_command ("catch", _("\
13073 Catch an exception, when caught.\n\
13074 With an argument, catch only exceptions with the given name."),
13075 catch_catch_command
,
13079 add_catch_command ("throw", _("\
13080 Catch an exception, when thrown.\n\
13081 With an argument, catch only exceptions with the given name."),
13082 catch_throw_command
,
13086 add_catch_command ("fork", _("Catch calls to fork."),
13087 catch_fork_command_1
,
13089 (void *) (uintptr_t) catch_fork_permanent
,
13090 (void *) (uintptr_t) catch_fork_temporary
);
13091 add_catch_command ("vfork", _("Catch calls to vfork."),
13092 catch_fork_command_1
,
13094 (void *) (uintptr_t) catch_vfork_permanent
,
13095 (void *) (uintptr_t) catch_vfork_temporary
);
13096 add_catch_command ("exec", _("Catch calls to exec."),
13097 catch_exec_command_1
,
13101 add_catch_command ("syscall", _("\
13102 Catch system calls by their names and/or numbers.\n\
13103 Arguments say which system calls to catch. If no arguments\n\
13104 are given, every system call will be caught.\n\
13105 Arguments, if given, should be one or more system call names\n\
13106 (if your system supports that), or system call numbers."),
13107 catch_syscall_command_1
,
13108 catch_syscall_completer
,
13111 add_catch_command ("exception", _("\
13112 Catch Ada exceptions, when raised.\n\
13113 With an argument, catch only exceptions with the given name."),
13114 catch_ada_exception_command
,
13118 add_catch_command ("assert", _("\
13119 Catch failed Ada assertions, when raised.\n\
13120 With an argument, catch only exceptions with the given name."),
13121 catch_assert_command
,
13126 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13127 Set a watchpoint for an expression.\n\
13128 Usage: watch [-l|-location] EXPRESSION\n\
13129 A watchpoint stops execution of your program whenever the value of\n\
13130 an expression changes.\n\
13131 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13132 the memory to which it refers."));
13133 set_cmd_completer (c
, expression_completer
);
13135 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13136 Set a read watchpoint for an expression.\n\
13137 Usage: rwatch [-l|-location] EXPRESSION\n\
13138 A watchpoint stops execution of your program whenever the value of\n\
13139 an expression is read.\n\
13140 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13141 the memory to which it refers."));
13142 set_cmd_completer (c
, expression_completer
);
13144 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13145 Set a watchpoint for an expression.\n\
13146 Usage: awatch [-l|-location] EXPRESSION\n\
13147 A watchpoint stops execution of your program whenever the value of\n\
13148 an expression is either read or written.\n\
13149 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13150 the memory to which it refers."));
13151 set_cmd_completer (c
, expression_completer
);
13153 add_info ("watchpoints", watchpoints_info
, _("\
13154 Status of specified watchpoints (all watchpoints if no argument)."));
13156 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13157 respond to changes - contrary to the description. */
13158 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13159 &can_use_hw_watchpoints
, _("\
13160 Set debugger's willingness to use watchpoint hardware."), _("\
13161 Show debugger's willingness to use watchpoint hardware."), _("\
13162 If zero, gdb will not use hardware for new watchpoints, even if\n\
13163 such is available. (However, any hardware watchpoints that were\n\
13164 created before setting this to nonzero, will continue to use watchpoint\n\
13167 show_can_use_hw_watchpoints
,
13168 &setlist
, &showlist
);
13170 can_use_hw_watchpoints
= 1;
13172 /* Tracepoint manipulation commands. */
13174 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13175 Set a tracepoint at specified line or function.\n\
13177 BREAK_ARGS_HELP ("trace") "\n\
13178 Do \"help tracepoints\" for info on other tracepoint commands."));
13179 set_cmd_completer (c
, location_completer
);
13181 add_com_alias ("tp", "trace", class_alias
, 0);
13182 add_com_alias ("tr", "trace", class_alias
, 1);
13183 add_com_alias ("tra", "trace", class_alias
, 1);
13184 add_com_alias ("trac", "trace", class_alias
, 1);
13186 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13187 Set a fast tracepoint at specified line or function.\n\
13189 BREAK_ARGS_HELP ("ftrace") "\n\
13190 Do \"help tracepoints\" for info on other tracepoint commands."));
13191 set_cmd_completer (c
, location_completer
);
13193 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13194 Set a static tracepoint at specified line, function or marker.\n\
13196 strace [LOCATION] [if CONDITION]\n\
13197 LOCATION may be a line number, function name, \"*\" and an address,\n\
13198 or -m MARKER_ID.\n\
13199 If a line number is specified, probe the marker at start of code\n\
13200 for that line. If a function is specified, probe the marker at start\n\
13201 of code for that function. If an address is specified, probe the marker\n\
13202 at that exact address. If a marker id is specified, probe the marker\n\
13203 with that name. With no LOCATION, uses current execution address of\n\
13204 the selected stack frame.\n\
13205 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13206 This collects arbitrary user data passed in the probe point call to the\n\
13207 tracing library. You can inspect it when analyzing the trace buffer,\n\
13208 by printing the $_sdata variable like any other convenience variable.\n\
13210 CONDITION is a boolean expression.\n\
13212 Multiple tracepoints at one place are permitted, and useful if their\n\
13213 conditions are different.\n\
13215 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13216 Do \"help tracepoints\" for info on other tracepoint commands."));
13217 set_cmd_completer (c
, location_completer
);
13219 add_info ("tracepoints", tracepoints_info
, _("\
13220 Status of specified tracepoints (all tracepoints if no argument).\n\
13221 Convenience variable \"$tpnum\" contains the number of the\n\
13222 last tracepoint set."));
13224 add_info_alias ("tp", "tracepoints", 1);
13226 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13227 Delete specified tracepoints.\n\
13228 Arguments are tracepoint numbers, separated by spaces.\n\
13229 No argument means delete all tracepoints."),
13232 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13233 Disable specified tracepoints.\n\
13234 Arguments are tracepoint numbers, separated by spaces.\n\
13235 No argument means disable all tracepoints."),
13237 deprecate_cmd (c
, "disable");
13239 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
13240 Enable specified tracepoints.\n\
13241 Arguments are tracepoint numbers, separated by spaces.\n\
13242 No argument means enable all tracepoints."),
13244 deprecate_cmd (c
, "enable");
13246 add_com ("passcount", class_trace
, trace_pass_command
, _("\
13247 Set the passcount for a tracepoint.\n\
13248 The trace will end when the tracepoint has been passed 'count' times.\n\
13249 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13250 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13252 add_prefix_cmd ("save", class_breakpoint
, save_command
,
13253 _("Save breakpoint definitions as a script."),
13254 &save_cmdlist
, "save ",
13255 0/*allow-unknown*/, &cmdlist
);
13257 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
13258 Save current breakpoint definitions as a script.\n\
13259 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13260 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13261 session to restore them."),
13263 set_cmd_completer (c
, filename_completer
);
13265 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
13266 Save current tracepoint definitions as a script.\n\
13267 Use the 'source' command in another debug session to restore them."),
13269 set_cmd_completer (c
, filename_completer
);
13271 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
13272 deprecate_cmd (c
, "save tracepoints");
13274 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
13275 Breakpoint specific settings\n\
13276 Configure various breakpoint-specific variables such as\n\
13277 pending breakpoint behavior"),
13278 &breakpoint_set_cmdlist
, "set breakpoint ",
13279 0/*allow-unknown*/, &setlist
);
13280 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
13281 Breakpoint specific settings\n\
13282 Configure various breakpoint-specific variables such as\n\
13283 pending breakpoint behavior"),
13284 &breakpoint_show_cmdlist
, "show breakpoint ",
13285 0/*allow-unknown*/, &showlist
);
13287 add_setshow_auto_boolean_cmd ("pending", no_class
,
13288 &pending_break_support
, _("\
13289 Set debugger's behavior regarding pending breakpoints."), _("\
13290 Show debugger's behavior regarding pending breakpoints."), _("\
13291 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13292 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13293 an error. If auto, an unrecognized breakpoint location results in a\n\
13294 user-query to see if a pending breakpoint should be created."),
13296 show_pending_break_support
,
13297 &breakpoint_set_cmdlist
,
13298 &breakpoint_show_cmdlist
);
13300 pending_break_support
= AUTO_BOOLEAN_AUTO
;
13302 add_setshow_boolean_cmd ("auto-hw", no_class
,
13303 &automatic_hardware_breakpoints
, _("\
13304 Set automatic usage of hardware breakpoints."), _("\
13305 Show automatic usage of hardware breakpoints."), _("\
13306 If set, the debugger will automatically use hardware breakpoints for\n\
13307 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13308 a warning will be emitted for such breakpoints."),
13310 show_automatic_hardware_breakpoints
,
13311 &breakpoint_set_cmdlist
,
13312 &breakpoint_show_cmdlist
);
13314 add_setshow_enum_cmd ("always-inserted", class_support
,
13315 always_inserted_enums
, &always_inserted_mode
, _("\
13316 Set mode for inserting breakpoints."), _("\
13317 Show mode for inserting breakpoints."), _("\
13318 When this mode is off, breakpoints are inserted in inferior when it is\n\
13319 resumed, and removed when execution stops. When this mode is on,\n\
13320 breakpoints are inserted immediately and removed only when the user\n\
13321 deletes the breakpoint. When this mode is auto (which is the default),\n\
13322 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13323 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13324 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13325 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13327 &show_always_inserted_mode
,
13328 &breakpoint_set_cmdlist
,
13329 &breakpoint_show_cmdlist
);
13331 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
13332 Set a breakpoint for an address range.\n\
13333 break-range START-LOCATION, END-LOCATION\n\
13334 where START-LOCATION and END-LOCATION can be one of the following:\n\
13335 LINENUM, for that line in the current file,\n\
13336 FILE:LINENUM, for that line in that file,\n\
13337 +OFFSET, for that number of lines after the current line\n\
13338 or the start of the range\n\
13339 FUNCTION, for the first line in that function,\n\
13340 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13341 *ADDRESS, for the instruction at that address.\n\
13343 The breakpoint will stop execution of the inferior whenever it executes\n\
13344 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13345 range (including START-LOCATION and END-LOCATION)."));
13347 automatic_hardware_breakpoints
= 1;
13349 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);