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"
67 #include "continuations.h"
69 /* readline include files */
70 #include "readline/readline.h"
71 #include "readline/history.h"
73 /* readline defines this. */
76 #include "mi/mi-common.h"
77 #include "python/python.h"
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void breakpoint_re_set_default (struct breakpoint
*);
99 static void clear_command (char *, int);
101 static void catch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value
*);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint
*);
109 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
111 struct breakpoint_ops
*);
112 /* This function is used in gdbtk sources and thus can not be made
114 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
115 struct symtab_and_line
,
116 enum bptype
, struct breakpoint_ops
*);
118 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
120 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
124 static void describe_other_breakpoints (struct gdbarch
*,
125 struct program_space
*, CORE_ADDR
,
126 struct obj_section
*, int);
128 static int breakpoint_address_match (struct address_space
*aspace1
,
130 struct address_space
*aspace2
,
133 static int watchpoint_locations_match (struct bp_location
*loc1
,
134 struct bp_location
*loc2
);
136 static int breakpoint_location_address_match (struct bp_location
*bl
,
137 struct address_space
*aspace
,
140 static void breakpoints_info (char *, int);
142 static void watchpoints_info (char *, int);
144 static int breakpoint_1 (char *, int,
145 int (*) (const struct breakpoint
*));
147 static int breakpoint_cond_eval (void *);
149 static void cleanup_executing_breakpoints (void *);
151 static void commands_command (char *, int);
153 static void condition_command (char *, int);
162 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
163 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
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 enable_breakpoint_disp (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 statement 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 validates 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 /* BL 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 further 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 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1444 if (target_resources_ok
== 0 && !sw_mode
)
1445 error (_("Target does not support this type of "
1446 "hardware watchpoint."));
1447 else if (target_resources_ok
< 0 && !sw_mode
)
1448 error (_("There are not enough available hardware "
1449 "resources for this watchpoint."));
1451 b
->type
= bp_watchpoint
;
1454 else if (!b
->ops
->works_in_software_mode (b
))
1455 error (_("Expression cannot be implemented with "
1456 "read/access watchpoint."));
1458 b
->type
= bp_watchpoint
;
1460 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1461 : bp_loc_hardware_watchpoint
);
1462 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1463 bl
->loc_type
= loc_type
;
1466 for (v
= val_chain
; v
; v
= next
)
1468 next
= value_next (v
);
1473 /* If a software watchpoint is not watching any memory, then the
1474 above left it without any location set up. But,
1475 bpstat_stop_status requires a location to be able to report
1476 stops, so make sure there's at least a dummy one. */
1477 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1479 b
->loc
= allocate_bp_location (b
);
1480 b
->loc
->pspace
= frame_pspace
;
1481 b
->loc
->address
= -1;
1482 b
->loc
->length
= -1;
1483 b
->loc
->watchpoint_type
= -1;
1486 else if (!within_current_scope
)
1488 printf_filtered (_("\
1489 Watchpoint %d deleted because the program has left the block\n\
1490 in which its expression is valid.\n"),
1492 watchpoint_del_at_next_stop (b
);
1495 /* Restore the selected frame. */
1497 select_frame (frame_find_by_id (saved_frame_id
));
1501 /* Returns 1 iff breakpoint location should be
1502 inserted in the inferior. */
1504 should_be_inserted (struct bp_location
*bl
)
1506 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1509 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1512 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1515 /* This is set for example, when we're attached to the parent of a
1516 vfork, and have detached from the child. The child is running
1517 free, and we expect it to do an exec or exit, at which point the
1518 OS makes the parent schedulable again (and the target reports
1519 that the vfork is done). Until the child is done with the shared
1520 memory region, do not insert breakpoints in the parent, otherwise
1521 the child could still trip on the parent's breakpoints. Since
1522 the parent is blocked anyway, it won't miss any breakpoint. */
1523 if (bl
->pspace
->breakpoints_not_allowed
)
1526 /* Tracepoints are inserted by the target at a time of its choosing,
1528 if (is_tracepoint (bl
->owner
))
1534 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1535 location. Any error messages are printed to TMP_ERROR_STREAM; and
1536 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1538 NOTE drow/2003-09-09: This routine could be broken down to an
1539 object-style method for each breakpoint or catchpoint type. */
1541 insert_bp_location (struct bp_location
*bl
,
1542 struct ui_file
*tmp_error_stream
,
1543 int *disabled_breaks
,
1544 int *hw_breakpoint_error
)
1548 if (!should_be_inserted (bl
) || bl
->inserted
)
1551 /* Initialize the target-specific information. */
1552 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1553 bl
->target_info
.placed_address
= bl
->address
;
1554 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1555 bl
->target_info
.length
= bl
->length
;
1557 if (bl
->loc_type
== bp_loc_software_breakpoint
1558 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1560 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1562 /* If the explicitly specified breakpoint type
1563 is not hardware breakpoint, check the memory map to see
1564 if the breakpoint address is in read only memory or not.
1566 Two important cases are:
1567 - location type is not hardware breakpoint, memory
1568 is readonly. We change the type of the location to
1569 hardware breakpoint.
1570 - location type is hardware breakpoint, memory is
1571 read-write. This means we've previously made the
1572 location hardware one, but then the memory map changed,
1575 When breakpoints are removed, remove_breakpoints will use
1576 location types we've just set here, the only possible
1577 problem is that memory map has changed during running
1578 program, but it's not going to work anyway with current
1580 struct mem_region
*mr
1581 = lookup_mem_region (bl
->target_info
.placed_address
);
1585 if (automatic_hardware_breakpoints
)
1587 enum bp_loc_type new_type
;
1589 if (mr
->attrib
.mode
!= MEM_RW
)
1590 new_type
= bp_loc_hardware_breakpoint
;
1592 new_type
= bp_loc_software_breakpoint
;
1594 if (new_type
!= bl
->loc_type
)
1596 static int said
= 0;
1598 bl
->loc_type
= new_type
;
1601 fprintf_filtered (gdb_stdout
,
1602 _("Note: automatically using "
1603 "hardware breakpoints for "
1604 "read-only addresses.\n"));
1609 else if (bl
->loc_type
== bp_loc_software_breakpoint
1610 && mr
->attrib
.mode
!= MEM_RW
)
1611 warning (_("cannot set software breakpoint "
1612 "at readonly address %s"),
1613 paddress (bl
->gdbarch
, bl
->address
));
1617 /* First check to see if we have to handle an overlay. */
1618 if (overlay_debugging
== ovly_off
1619 || bl
->section
== NULL
1620 || !(section_is_overlay (bl
->section
)))
1622 /* No overlay handling: just set the breakpoint. */
1624 val
= bl
->owner
->ops
->insert_location (bl
);
1628 /* This breakpoint is in an overlay section.
1629 Shall we set a breakpoint at the LMA? */
1630 if (!overlay_events_enabled
)
1632 /* Yes -- overlay event support is not active,
1633 so we must try to set a breakpoint at the LMA.
1634 This will not work for a hardware breakpoint. */
1635 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1636 warning (_("hardware breakpoint %d not supported in overlay!"),
1640 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1642 /* Set a software (trap) breakpoint at the LMA. */
1643 bl
->overlay_target_info
= bl
->target_info
;
1644 bl
->overlay_target_info
.placed_address
= addr
;
1645 val
= target_insert_breakpoint (bl
->gdbarch
,
1646 &bl
->overlay_target_info
);
1648 fprintf_unfiltered (tmp_error_stream
,
1649 "Overlay breakpoint %d "
1650 "failed: in ROM?\n",
1654 /* Shall we set a breakpoint at the VMA? */
1655 if (section_is_mapped (bl
->section
))
1657 /* Yes. This overlay section is mapped into memory. */
1658 val
= bl
->owner
->ops
->insert_location (bl
);
1662 /* No. This breakpoint will not be inserted.
1663 No error, but do not mark the bp as 'inserted'. */
1670 /* Can't set the breakpoint. */
1671 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1673 /* See also: disable_breakpoints_in_shlibs. */
1675 bl
->shlib_disabled
= 1;
1676 observer_notify_breakpoint_modified (bl
->owner
);
1677 if (!*disabled_breaks
)
1679 fprintf_unfiltered (tmp_error_stream
,
1680 "Cannot insert breakpoint %d.\n",
1682 fprintf_unfiltered (tmp_error_stream
,
1683 "Temporarily disabling shared "
1684 "library breakpoints:\n");
1686 *disabled_breaks
= 1;
1687 fprintf_unfiltered (tmp_error_stream
,
1688 "breakpoint #%d\n", bl
->owner
->number
);
1692 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1694 *hw_breakpoint_error
= 1;
1695 fprintf_unfiltered (tmp_error_stream
,
1696 "Cannot insert hardware "
1702 fprintf_unfiltered (tmp_error_stream
,
1703 "Cannot insert breakpoint %d.\n",
1705 fprintf_filtered (tmp_error_stream
,
1706 "Error accessing memory address ");
1707 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1709 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1710 safe_strerror (val
));
1721 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1722 /* NOTE drow/2003-09-08: This state only exists for removing
1723 watchpoints. It's not clear that it's necessary... */
1724 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1726 gdb_assert (bl
->owner
->ops
!= NULL
1727 && bl
->owner
->ops
->insert_location
!= NULL
);
1729 val
= bl
->owner
->ops
->insert_location (bl
);
1731 /* If trying to set a read-watchpoint, and it turns out it's not
1732 supported, try emulating one with an access watchpoint. */
1733 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1735 struct bp_location
*loc
, **loc_temp
;
1737 /* But don't try to insert it, if there's already another
1738 hw_access location that would be considered a duplicate
1740 ALL_BP_LOCATIONS (loc
, loc_temp
)
1742 && loc
->watchpoint_type
== hw_access
1743 && watchpoint_locations_match (bl
, loc
))
1747 bl
->target_info
= loc
->target_info
;
1748 bl
->watchpoint_type
= hw_access
;
1755 bl
->watchpoint_type
= hw_access
;
1756 val
= bl
->owner
->ops
->insert_location (bl
);
1759 /* Back to the original value. */
1760 bl
->watchpoint_type
= hw_read
;
1764 bl
->inserted
= (val
== 0);
1767 else if (bl
->owner
->type
== bp_catchpoint
)
1769 gdb_assert (bl
->owner
->ops
!= NULL
1770 && bl
->owner
->ops
->insert_location
!= NULL
);
1772 val
= bl
->owner
->ops
->insert_location (bl
);
1775 bl
->owner
->enable_state
= bp_disabled
;
1779 Error inserting catchpoint %d: Your system does not support this type\n\
1780 of catchpoint."), bl
->owner
->number
);
1782 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1785 bl
->inserted
= (val
== 0);
1787 /* We've already printed an error message if there was a problem
1788 inserting this catchpoint, and we've disabled the catchpoint,
1789 so just return success. */
1796 /* This function is called when program space PSPACE is about to be
1797 deleted. It takes care of updating breakpoints to not reference
1801 breakpoint_program_space_exit (struct program_space
*pspace
)
1803 struct breakpoint
*b
, *b_temp
;
1804 struct bp_location
*loc
, **loc_temp
;
1806 /* Remove any breakpoint that was set through this program space. */
1807 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1809 if (b
->pspace
== pspace
)
1810 delete_breakpoint (b
);
1813 /* Breakpoints set through other program spaces could have locations
1814 bound to PSPACE as well. Remove those. */
1815 ALL_BP_LOCATIONS (loc
, loc_temp
)
1817 struct bp_location
*tmp
;
1819 if (loc
->pspace
== pspace
)
1821 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1822 if (loc
->owner
->loc
== loc
)
1823 loc
->owner
->loc
= loc
->next
;
1825 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1826 if (tmp
->next
== loc
)
1828 tmp
->next
= loc
->next
;
1834 /* Now update the global location list to permanently delete the
1835 removed locations above. */
1836 update_global_location_list (0);
1839 /* Make sure all breakpoints are inserted in inferior.
1840 Throws exception on any error.
1841 A breakpoint that is already inserted won't be inserted
1842 again, so calling this function twice is safe. */
1844 insert_breakpoints (void)
1846 struct breakpoint
*bpt
;
1848 ALL_BREAKPOINTS (bpt
)
1849 if (is_hardware_watchpoint (bpt
))
1850 update_watchpoint (bpt
, 0 /* don't reparse. */);
1852 update_global_location_list (1);
1854 /* update_global_location_list does not insert breakpoints when
1855 always_inserted_mode is not enabled. Explicitly insert them
1857 if (!breakpoints_always_inserted_mode ())
1858 insert_breakpoint_locations ();
1861 /* insert_breakpoints is used when starting or continuing the program.
1862 remove_breakpoints is used when the program stops.
1863 Both return zero if successful,
1864 or an `errno' value if could not write the inferior. */
1867 insert_breakpoint_locations (void)
1869 struct breakpoint
*bpt
;
1870 struct bp_location
*bl
, **blp_tmp
;
1873 int disabled_breaks
= 0;
1874 int hw_breakpoint_error
= 0;
1876 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1877 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1879 /* Explicitly mark the warning -- this will only be printed if
1880 there was an error. */
1881 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1883 save_current_space_and_thread ();
1885 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1887 if (!should_be_inserted (bl
) || bl
->inserted
)
1890 /* There is no point inserting thread-specific breakpoints if
1891 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1892 has BL->OWNER always non-NULL. */
1893 if (bl
->owner
->thread
!= -1
1894 && !valid_thread_id (bl
->owner
->thread
))
1897 switch_to_program_space_and_thread (bl
->pspace
);
1899 /* For targets that support global breakpoints, there's no need
1900 to select an inferior to insert breakpoint to. In fact, even
1901 if we aren't attached to any process yet, we should still
1902 insert breakpoints. */
1903 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1904 && ptid_equal (inferior_ptid
, null_ptid
))
1907 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1908 &hw_breakpoint_error
);
1913 /* If we failed to insert all locations of a watchpoint, remove
1914 them, as half-inserted watchpoint is of limited use. */
1915 ALL_BREAKPOINTS (bpt
)
1917 int some_failed
= 0;
1918 struct bp_location
*loc
;
1920 if (!is_hardware_watchpoint (bpt
))
1923 if (!breakpoint_enabled (bpt
))
1926 if (bpt
->disposition
== disp_del_at_next_stop
)
1929 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1930 if (!loc
->inserted
&& should_be_inserted (loc
))
1937 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1939 remove_breakpoint (loc
, mark_uninserted
);
1941 hw_breakpoint_error
= 1;
1942 fprintf_unfiltered (tmp_error_stream
,
1943 "Could not insert hardware watchpoint %d.\n",
1951 /* If a hardware breakpoint or watchpoint was inserted, add a
1952 message about possibly exhausted resources. */
1953 if (hw_breakpoint_error
)
1955 fprintf_unfiltered (tmp_error_stream
,
1956 "Could not insert hardware breakpoints:\n\
1957 You may have requested too many hardware breakpoints/watchpoints.\n");
1959 target_terminal_ours_for_output ();
1960 error_stream (tmp_error_stream
);
1963 do_cleanups (cleanups
);
1967 remove_breakpoints (void)
1969 struct bp_location
*bl
, **blp_tmp
;
1972 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1975 val
|= remove_breakpoint (bl
, mark_uninserted
);
1980 /* Remove breakpoints of process PID. */
1983 remove_breakpoints_pid (int pid
)
1985 struct bp_location
*bl
, **blp_tmp
;
1987 struct inferior
*inf
= find_inferior_pid (pid
);
1989 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1991 if (bl
->pspace
!= inf
->pspace
)
1996 val
= remove_breakpoint (bl
, mark_uninserted
);
2005 reattach_breakpoints (int pid
)
2007 struct cleanup
*old_chain
;
2008 struct bp_location
*bl
, **blp_tmp
;
2010 struct ui_file
*tmp_error_stream
;
2011 int dummy1
= 0, dummy2
= 0;
2012 struct inferior
*inf
;
2013 struct thread_info
*tp
;
2015 tp
= any_live_thread_of_process (pid
);
2019 inf
= find_inferior_pid (pid
);
2020 old_chain
= save_inferior_ptid ();
2022 inferior_ptid
= tp
->ptid
;
2024 tmp_error_stream
= mem_fileopen ();
2025 make_cleanup_ui_file_delete (tmp_error_stream
);
2027 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2029 if (bl
->pspace
!= inf
->pspace
)
2035 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2038 do_cleanups (old_chain
);
2043 do_cleanups (old_chain
);
2047 static int internal_breakpoint_number
= -1;
2049 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2050 If INTERNAL is non-zero, the breakpoint number will be populated
2051 from internal_breakpoint_number and that variable decremented.
2052 Otherwise the breakpoint number will be populated from
2053 breakpoint_count and that value incremented. Internal breakpoints
2054 do not set the internal var bpnum. */
2056 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2059 b
->number
= internal_breakpoint_number
--;
2062 set_breakpoint_count (breakpoint_count
+ 1);
2063 b
->number
= breakpoint_count
;
2067 static struct breakpoint
*
2068 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2069 CORE_ADDR address
, enum bptype type
)
2071 struct symtab_and_line sal
;
2072 struct breakpoint
*b
;
2074 init_sal (&sal
); /* Initialize to zeroes. */
2077 sal
.section
= find_pc_overlay (sal
.pc
);
2078 sal
.pspace
= current_program_space
;
2080 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &bkpt_breakpoint_ops
);
2081 b
->number
= internal_breakpoint_number
--;
2082 b
->disposition
= disp_donttouch
;
2087 static const char *const longjmp_names
[] =
2089 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2091 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2093 /* Per-objfile data private to breakpoint.c. */
2094 struct breakpoint_objfile_data
2096 /* Minimal symbol for "_ovly_debug_event" (if any). */
2097 struct minimal_symbol
*overlay_msym
;
2099 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2100 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2102 /* Minimal symbol for "std::terminate()" (if any). */
2103 struct minimal_symbol
*terminate_msym
;
2105 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2106 struct minimal_symbol
*exception_msym
;
2109 static const struct objfile_data
*breakpoint_objfile_key
;
2111 /* Minimal symbol not found sentinel. */
2112 static struct minimal_symbol msym_not_found
;
2114 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2117 msym_not_found_p (const struct minimal_symbol
*msym
)
2119 return msym
== &msym_not_found
;
2122 /* Return per-objfile data needed by breakpoint.c.
2123 Allocate the data if necessary. */
2125 static struct breakpoint_objfile_data
*
2126 get_breakpoint_objfile_data (struct objfile
*objfile
)
2128 struct breakpoint_objfile_data
*bp_objfile_data
;
2130 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2131 if (bp_objfile_data
== NULL
)
2133 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2134 sizeof (*bp_objfile_data
));
2136 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2137 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2139 return bp_objfile_data
;
2143 create_overlay_event_breakpoint (void)
2145 struct objfile
*objfile
;
2146 const char *const func_name
= "_ovly_debug_event";
2148 ALL_OBJFILES (objfile
)
2150 struct breakpoint
*b
;
2151 struct breakpoint_objfile_data
*bp_objfile_data
;
2154 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2156 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2159 if (bp_objfile_data
->overlay_msym
== NULL
)
2161 struct minimal_symbol
*m
;
2163 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2166 /* Avoid future lookups in this objfile. */
2167 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2170 bp_objfile_data
->overlay_msym
= m
;
2173 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2174 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2176 b
->addr_string
= xstrdup (func_name
);
2178 if (overlay_debugging
== ovly_auto
)
2180 b
->enable_state
= bp_enabled
;
2181 overlay_events_enabled
= 1;
2185 b
->enable_state
= bp_disabled
;
2186 overlay_events_enabled
= 0;
2189 update_global_location_list (1);
2193 create_longjmp_master_breakpoint (void)
2195 struct program_space
*pspace
;
2196 struct cleanup
*old_chain
;
2198 old_chain
= save_current_program_space ();
2200 ALL_PSPACES (pspace
)
2202 struct objfile
*objfile
;
2204 set_current_program_space (pspace
);
2206 ALL_OBJFILES (objfile
)
2209 struct gdbarch
*gdbarch
;
2210 struct breakpoint_objfile_data
*bp_objfile_data
;
2212 gdbarch
= get_objfile_arch (objfile
);
2213 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2216 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2218 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2220 struct breakpoint
*b
;
2221 const char *func_name
;
2224 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2227 func_name
= longjmp_names
[i
];
2228 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2230 struct minimal_symbol
*m
;
2232 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2235 /* Prevent future lookups in this objfile. */
2236 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2239 bp_objfile_data
->longjmp_msym
[i
] = m
;
2242 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2243 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
2244 b
->addr_string
= xstrdup (func_name
);
2245 b
->enable_state
= bp_disabled
;
2249 update_global_location_list (1);
2251 do_cleanups (old_chain
);
2254 /* Create a master std::terminate breakpoint. */
2256 create_std_terminate_master_breakpoint (void)
2258 struct program_space
*pspace
;
2259 struct cleanup
*old_chain
;
2260 const char *const func_name
= "std::terminate()";
2262 old_chain
= save_current_program_space ();
2264 ALL_PSPACES (pspace
)
2266 struct objfile
*objfile
;
2269 set_current_program_space (pspace
);
2271 ALL_OBJFILES (objfile
)
2273 struct breakpoint
*b
;
2274 struct breakpoint_objfile_data
*bp_objfile_data
;
2276 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2278 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2281 if (bp_objfile_data
->terminate_msym
== NULL
)
2283 struct minimal_symbol
*m
;
2285 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2286 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2287 && MSYMBOL_TYPE (m
) != mst_file_text
))
2289 /* Prevent future lookups in this objfile. */
2290 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2293 bp_objfile_data
->terminate_msym
= m
;
2296 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2297 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2298 bp_std_terminate_master
);
2299 b
->addr_string
= xstrdup (func_name
);
2300 b
->enable_state
= bp_disabled
;
2304 update_global_location_list (1);
2306 do_cleanups (old_chain
);
2309 /* Install a master breakpoint on the unwinder's debug hook. */
2312 create_exception_master_breakpoint (void)
2314 struct objfile
*objfile
;
2315 const char *const func_name
= "_Unwind_DebugHook";
2317 ALL_OBJFILES (objfile
)
2319 struct breakpoint
*b
;
2320 struct gdbarch
*gdbarch
;
2321 struct breakpoint_objfile_data
*bp_objfile_data
;
2324 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2326 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2329 gdbarch
= get_objfile_arch (objfile
);
2331 if (bp_objfile_data
->exception_msym
== NULL
)
2333 struct minimal_symbol
*debug_hook
;
2335 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2336 if (debug_hook
== NULL
)
2338 bp_objfile_data
->exception_msym
= &msym_not_found
;
2342 bp_objfile_data
->exception_msym
= debug_hook
;
2345 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2346 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2348 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2349 b
->addr_string
= xstrdup (func_name
);
2350 b
->enable_state
= bp_disabled
;
2353 update_global_location_list (1);
2357 update_breakpoints_after_exec (void)
2359 struct breakpoint
*b
, *b_tmp
;
2360 struct bp_location
*bploc
, **bplocp_tmp
;
2362 /* We're about to delete breakpoints from GDB's lists. If the
2363 INSERTED flag is true, GDB will try to lift the breakpoints by
2364 writing the breakpoints' "shadow contents" back into memory. The
2365 "shadow contents" are NOT valid after an exec, so GDB should not
2366 do that. Instead, the target is responsible from marking
2367 breakpoints out as soon as it detects an exec. We don't do that
2368 here instead, because there may be other attempts to delete
2369 breakpoints after detecting an exec and before reaching here. */
2370 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2371 if (bploc
->pspace
== current_program_space
)
2372 gdb_assert (!bploc
->inserted
);
2374 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2376 if (b
->pspace
!= current_program_space
)
2379 /* Solib breakpoints must be explicitly reset after an exec(). */
2380 if (b
->type
== bp_shlib_event
)
2382 delete_breakpoint (b
);
2386 /* JIT breakpoints must be explicitly reset after an exec(). */
2387 if (b
->type
== bp_jit_event
)
2389 delete_breakpoint (b
);
2393 /* Thread event breakpoints must be set anew after an exec(),
2394 as must overlay event and longjmp master breakpoints. */
2395 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2396 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2397 || b
->type
== bp_exception_master
)
2399 delete_breakpoint (b
);
2403 /* Step-resume breakpoints are meaningless after an exec(). */
2404 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2406 delete_breakpoint (b
);
2410 /* Longjmp and longjmp-resume breakpoints are also meaningless
2412 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2413 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2415 delete_breakpoint (b
);
2419 if (b
->type
== bp_catchpoint
)
2421 /* For now, none of the bp_catchpoint breakpoints need to
2422 do anything at this point. In the future, if some of
2423 the catchpoints need to something, we will need to add
2424 a new method, and call this method from here. */
2428 /* bp_finish is a special case. The only way we ought to be able
2429 to see one of these when an exec() has happened, is if the user
2430 caught a vfork, and then said "finish". Ordinarily a finish just
2431 carries them to the call-site of the current callee, by setting
2432 a temporary bp there and resuming. But in this case, the finish
2433 will carry them entirely through the vfork & exec.
2435 We don't want to allow a bp_finish to remain inserted now. But
2436 we can't safely delete it, 'cause finish_command has a handle to
2437 the bp on a bpstat, and will later want to delete it. There's a
2438 chance (and I've seen it happen) that if we delete the bp_finish
2439 here, that its storage will get reused by the time finish_command
2440 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2441 We really must allow finish_command to delete a bp_finish.
2443 In the absence of a general solution for the "how do we know
2444 it's safe to delete something others may have handles to?"
2445 problem, what we'll do here is just uninsert the bp_finish, and
2446 let finish_command delete it.
2448 (We know the bp_finish is "doomed" in the sense that it's
2449 momentary, and will be deleted as soon as finish_command sees
2450 the inferior stopped. So it doesn't matter that the bp's
2451 address is probably bogus in the new a.out, unlike e.g., the
2452 solib breakpoints.) */
2454 if (b
->type
== bp_finish
)
2459 /* Without a symbolic address, we have little hope of the
2460 pre-exec() address meaning the same thing in the post-exec()
2462 if (b
->addr_string
== NULL
)
2464 delete_breakpoint (b
);
2468 /* FIXME what about longjmp breakpoints? Re-create them here? */
2469 create_overlay_event_breakpoint ();
2470 create_longjmp_master_breakpoint ();
2471 create_std_terminate_master_breakpoint ();
2472 create_exception_master_breakpoint ();
2476 detach_breakpoints (int pid
)
2478 struct bp_location
*bl
, **blp_tmp
;
2480 struct cleanup
*old_chain
= save_inferior_ptid ();
2481 struct inferior
*inf
= current_inferior ();
2483 if (pid
== PIDGET (inferior_ptid
))
2484 error (_("Cannot detach breakpoints of inferior_ptid"));
2486 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2487 inferior_ptid
= pid_to_ptid (pid
);
2488 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2490 if (bl
->pspace
!= inf
->pspace
)
2494 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2497 /* Detach single-step breakpoints as well. */
2498 detach_single_step_breakpoints ();
2500 do_cleanups (old_chain
);
2504 /* Remove the breakpoint location BL from the current address space.
2505 Note that this is used to detach breakpoints from a child fork.
2506 When we get here, the child isn't in the inferior list, and neither
2507 do we have objects to represent its address space --- we should
2508 *not* look at bl->pspace->aspace here. */
2511 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2515 /* BL is never in moribund_locations by our callers. */
2516 gdb_assert (bl
->owner
!= NULL
);
2518 if (bl
->owner
->enable_state
== bp_permanent
)
2519 /* Permanent breakpoints cannot be inserted or removed. */
2522 /* The type of none suggests that owner is actually deleted.
2523 This should not ever happen. */
2524 gdb_assert (bl
->owner
->type
!= bp_none
);
2526 if (bl
->loc_type
== bp_loc_software_breakpoint
2527 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2529 /* "Normal" instruction breakpoint: either the standard
2530 trap-instruction bp (bp_breakpoint), or a
2531 bp_hardware_breakpoint. */
2533 /* First check to see if we have to handle an overlay. */
2534 if (overlay_debugging
== ovly_off
2535 || bl
->section
== NULL
2536 || !(section_is_overlay (bl
->section
)))
2538 /* No overlay handling: just remove the breakpoint. */
2539 val
= bl
->owner
->ops
->remove_location (bl
);
2543 /* This breakpoint is in an overlay section.
2544 Did we set a breakpoint at the LMA? */
2545 if (!overlay_events_enabled
)
2547 /* Yes -- overlay event support is not active, so we
2548 should have set a breakpoint at the LMA. Remove it.
2550 /* Ignore any failures: if the LMA is in ROM, we will
2551 have already warned when we failed to insert it. */
2552 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2553 target_remove_hw_breakpoint (bl
->gdbarch
,
2554 &bl
->overlay_target_info
);
2556 target_remove_breakpoint (bl
->gdbarch
,
2557 &bl
->overlay_target_info
);
2559 /* Did we set a breakpoint at the VMA?
2560 If so, we will have marked the breakpoint 'inserted'. */
2563 /* Yes -- remove it. Previously we did not bother to
2564 remove the breakpoint if the section had been
2565 unmapped, but let's not rely on that being safe. We
2566 don't know what the overlay manager might do. */
2568 /* However, we should remove *software* breakpoints only
2569 if the section is still mapped, or else we overwrite
2570 wrong code with the saved shadow contents. */
2571 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2572 || section_is_mapped (bl
->section
))
2573 val
= bl
->owner
->ops
->remove_location (bl
);
2579 /* No -- not inserted, so no need to remove. No error. */
2584 /* In some cases, we might not be able to remove a breakpoint
2585 in a shared library that has already been removed, but we
2586 have not yet processed the shlib unload event. */
2587 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2592 bl
->inserted
= (is
== mark_inserted
);
2594 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2596 gdb_assert (bl
->owner
->ops
!= NULL
2597 && bl
->owner
->ops
->remove_location
!= NULL
);
2599 bl
->inserted
= (is
== mark_inserted
);
2600 bl
->owner
->ops
->remove_location (bl
);
2602 /* Failure to remove any of the hardware watchpoints comes here. */
2603 if ((is
== mark_uninserted
) && (bl
->inserted
))
2604 warning (_("Could not remove hardware watchpoint %d."),
2607 else if (bl
->owner
->type
== bp_catchpoint
2608 && breakpoint_enabled (bl
->owner
)
2611 gdb_assert (bl
->owner
->ops
!= NULL
2612 && bl
->owner
->ops
->remove_location
!= NULL
);
2614 val
= bl
->owner
->ops
->remove_location (bl
);
2618 bl
->inserted
= (is
== mark_inserted
);
2625 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2628 struct cleanup
*old_chain
;
2630 /* BL is never in moribund_locations by our callers. */
2631 gdb_assert (bl
->owner
!= NULL
);
2633 if (bl
->owner
->enable_state
== bp_permanent
)
2634 /* Permanent breakpoints cannot be inserted or removed. */
2637 /* The type of none suggests that owner is actually deleted.
2638 This should not ever happen. */
2639 gdb_assert (bl
->owner
->type
!= bp_none
);
2641 old_chain
= save_current_space_and_thread ();
2643 switch_to_program_space_and_thread (bl
->pspace
);
2645 ret
= remove_breakpoint_1 (bl
, is
);
2647 do_cleanups (old_chain
);
2651 /* Clear the "inserted" flag in all breakpoints. */
2654 mark_breakpoints_out (void)
2656 struct bp_location
*bl
, **blp_tmp
;
2658 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2659 if (bl
->pspace
== current_program_space
)
2663 /* Clear the "inserted" flag in all breakpoints and delete any
2664 breakpoints which should go away between runs of the program.
2666 Plus other such housekeeping that has to be done for breakpoints
2669 Note: this function gets called at the end of a run (by
2670 generic_mourn_inferior) and when a run begins (by
2671 init_wait_for_inferior). */
2676 breakpoint_init_inferior (enum inf_context context
)
2678 struct breakpoint
*b
, *b_tmp
;
2679 struct bp_location
*bl
, **blp_tmp
;
2681 struct program_space
*pspace
= current_program_space
;
2683 /* If breakpoint locations are shared across processes, then there's
2685 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2688 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2690 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2691 if (bl
->pspace
== pspace
2692 && bl
->owner
->enable_state
!= bp_permanent
)
2696 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2698 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2705 /* If the call dummy breakpoint is at the entry point it will
2706 cause problems when the inferior is rerun, so we better get
2709 case bp_watchpoint_scope
:
2711 /* Also get rid of scope breakpoints. */
2713 case bp_shlib_event
:
2715 /* Also remove solib event breakpoints. Their addresses may
2716 have changed since the last time we ran the program.
2717 Actually we may now be debugging against different target;
2718 and so the solib backend that installed this breakpoint may
2719 not be used in by the target. E.g.,
2721 (gdb) file prog-linux
2722 (gdb) run # native linux target
2725 (gdb) file prog-win.exe
2726 (gdb) tar rem :9999 # remote Windows gdbserver.
2729 delete_breakpoint (b
);
2733 case bp_hardware_watchpoint
:
2734 case bp_read_watchpoint
:
2735 case bp_access_watchpoint
:
2737 /* Likewise for watchpoints on local expressions. */
2738 if (b
->exp_valid_block
!= NULL
)
2739 delete_breakpoint (b
);
2740 else if (context
== inf_starting
)
2742 /* Reset val field to force reread of starting value in
2743 insert_breakpoints. */
2745 value_free (b
->val
);
2755 /* Get rid of the moribund locations. */
2756 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2757 decref_bp_location (&bl
);
2758 VEC_free (bp_location_p
, moribund_locations
);
2761 /* These functions concern about actual breakpoints inserted in the
2762 target --- to e.g. check if we need to do decr_pc adjustment or if
2763 we need to hop over the bkpt --- so we check for address space
2764 match, not program space. */
2766 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2767 exists at PC. It returns ordinary_breakpoint_here if it's an
2768 ordinary breakpoint, or permanent_breakpoint_here if it's a
2769 permanent breakpoint.
2770 - When continuing from a location with an ordinary breakpoint, we
2771 actually single step once before calling insert_breakpoints.
2772 - When continuing from a location with a permanent breakpoint, we
2773 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2774 the target, to advance the PC past the breakpoint. */
2776 enum breakpoint_here
2777 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2779 struct bp_location
*bl
, **blp_tmp
;
2780 int any_breakpoint_here
= 0;
2782 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2784 if (bl
->loc_type
!= bp_loc_software_breakpoint
2785 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2788 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2789 if ((breakpoint_enabled (bl
->owner
)
2790 || bl
->owner
->enable_state
== bp_permanent
)
2791 && breakpoint_location_address_match (bl
, aspace
, pc
))
2793 if (overlay_debugging
2794 && section_is_overlay (bl
->section
)
2795 && !section_is_mapped (bl
->section
))
2796 continue; /* unmapped overlay -- can't be a match */
2797 else if (bl
->owner
->enable_state
== bp_permanent
)
2798 return permanent_breakpoint_here
;
2800 any_breakpoint_here
= 1;
2804 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2807 /* Return true if there's a moribund breakpoint at PC. */
2810 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2812 struct bp_location
*loc
;
2815 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2816 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2822 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2823 inserted using regular breakpoint_chain / bp_location array
2824 mechanism. This does not check for single-step breakpoints, which
2825 are inserted and removed using direct target manipulation. */
2828 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2831 struct bp_location
*bl
, **blp_tmp
;
2833 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2835 if (bl
->loc_type
!= bp_loc_software_breakpoint
2836 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2840 && breakpoint_location_address_match (bl
, aspace
, pc
))
2842 if (overlay_debugging
2843 && section_is_overlay (bl
->section
)
2844 && !section_is_mapped (bl
->section
))
2845 continue; /* unmapped overlay -- can't be a match */
2853 /* Returns non-zero iff there's either regular breakpoint
2854 or a single step breakpoint inserted at PC. */
2857 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2859 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2862 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2868 /* This function returns non-zero iff there is a software breakpoint
2872 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2875 struct bp_location
*bl
, **blp_tmp
;
2877 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2879 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2883 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2886 if (overlay_debugging
2887 && section_is_overlay (bl
->section
)
2888 && !section_is_mapped (bl
->section
))
2889 continue; /* unmapped overlay -- can't be a match */
2895 /* Also check for software single-step breakpoints. */
2896 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2903 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2904 CORE_ADDR addr
, ULONGEST len
)
2906 struct breakpoint
*bpt
;
2908 ALL_BREAKPOINTS (bpt
)
2910 struct bp_location
*loc
;
2912 if (bpt
->type
!= bp_hardware_watchpoint
2913 && bpt
->type
!= bp_access_watchpoint
)
2916 if (!breakpoint_enabled (bpt
))
2919 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2920 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2924 /* Check for intersection. */
2925 l
= max (loc
->address
, addr
);
2926 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2934 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2935 PC is valid for process/thread PTID. */
2938 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2941 struct bp_location
*bl
, **blp_tmp
;
2942 /* The thread and task IDs associated to PTID, computed lazily. */
2946 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2948 if (bl
->loc_type
!= bp_loc_software_breakpoint
2949 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2952 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2953 if (!breakpoint_enabled (bl
->owner
)
2954 && bl
->owner
->enable_state
!= bp_permanent
)
2957 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
2960 if (bl
->owner
->thread
!= -1)
2962 /* This is a thread-specific breakpoint. Check that ptid
2963 matches that thread. If thread hasn't been computed yet,
2964 it is now time to do so. */
2966 thread
= pid_to_thread_id (ptid
);
2967 if (bl
->owner
->thread
!= thread
)
2971 if (bl
->owner
->task
!= 0)
2973 /* This is a task-specific breakpoint. Check that ptid
2974 matches that task. If task hasn't been computed yet,
2975 it is now time to do so. */
2977 task
= ada_get_task_number (ptid
);
2978 if (bl
->owner
->task
!= task
)
2982 if (overlay_debugging
2983 && section_is_overlay (bl
->section
)
2984 && !section_is_mapped (bl
->section
))
2985 continue; /* unmapped overlay -- can't be a match */
2994 /* bpstat stuff. External routines' interfaces are documented
2998 ep_is_catchpoint (struct breakpoint
*ep
)
3000 return (ep
->type
== bp_catchpoint
);
3003 /* Frees any storage that is part of a bpstat. Does not walk the
3007 bpstat_free (bpstat bs
)
3009 if (bs
->old_val
!= NULL
)
3010 value_free (bs
->old_val
);
3011 decref_counted_command_line (&bs
->commands
);
3012 decref_bp_location (&bs
->bp_location_at
);
3016 /* Clear a bpstat so that it says we are not at any breakpoint.
3017 Also free any storage that is part of a bpstat. */
3020 bpstat_clear (bpstat
*bsp
)
3037 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3038 is part of the bpstat is copied as well. */
3041 bpstat_copy (bpstat bs
)
3045 bpstat retval
= NULL
;
3050 for (; bs
!= NULL
; bs
= bs
->next
)
3052 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3053 memcpy (tmp
, bs
, sizeof (*tmp
));
3054 incref_counted_command_line (tmp
->commands
);
3055 incref_bp_location (tmp
->bp_location_at
);
3056 if (bs
->old_val
!= NULL
)
3058 tmp
->old_val
= value_copy (bs
->old_val
);
3059 release_value (tmp
->old_val
);
3063 /* This is the first thing in the chain. */
3073 /* Find the bpstat associated with this breakpoint. */
3076 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3081 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3083 if (bsp
->breakpoint_at
== breakpoint
)
3089 /* Put in *NUM the breakpoint number of the first breakpoint we are
3090 stopped at. *BSP upon return is a bpstat which points to the
3091 remaining breakpoints stopped at (but which is not guaranteed to be
3092 good for anything but further calls to bpstat_num).
3094 Return 0 if passed a bpstat which does not indicate any breakpoints.
3095 Return -1 if stopped at a breakpoint that has been deleted since
3097 Return 1 otherwise. */
3100 bpstat_num (bpstat
*bsp
, int *num
)
3102 struct breakpoint
*b
;
3105 return 0; /* No more breakpoint values */
3107 /* We assume we'll never have several bpstats that correspond to a
3108 single breakpoint -- otherwise, this function might return the
3109 same number more than once and this will look ugly. */
3110 b
= (*bsp
)->breakpoint_at
;
3111 *bsp
= (*bsp
)->next
;
3113 return -1; /* breakpoint that's been deleted since */
3115 *num
= b
->number
; /* We have its number */
3119 /* Modify BS so that the actions will not be performed. */
3122 bpstat_clear_actions (bpstat bs
)
3124 for (; bs
!= NULL
; bs
= bs
->next
)
3126 decref_counted_command_line (&bs
->commands
);
3127 bs
->commands_left
= NULL
;
3128 if (bs
->old_val
!= NULL
)
3130 value_free (bs
->old_val
);
3136 /* Called when a command is about to proceed the inferior. */
3139 breakpoint_about_to_proceed (void)
3141 if (!ptid_equal (inferior_ptid
, null_ptid
))
3143 struct thread_info
*tp
= inferior_thread ();
3145 /* Allow inferior function calls in breakpoint commands to not
3146 interrupt the command list. When the call finishes
3147 successfully, the inferior will be standing at the same
3148 breakpoint as if nothing happened. */
3149 if (tp
->control
.in_infcall
)
3153 breakpoint_proceeded
= 1;
3156 /* Stub for cleaning up our state if we error-out of a breakpoint
3159 cleanup_executing_breakpoints (void *ignore
)
3161 executing_breakpoint_commands
= 0;
3164 /* Execute all the commands associated with all the breakpoints at
3165 this location. Any of these commands could cause the process to
3166 proceed beyond this point, etc. We look out for such changes by
3167 checking the global "breakpoint_proceeded" after each command.
3169 Returns true if a breakpoint command resumed the inferior. In that
3170 case, it is the caller's responsibility to recall it again with the
3171 bpstat of the current thread. */
3174 bpstat_do_actions_1 (bpstat
*bsp
)
3177 struct cleanup
*old_chain
;
3180 /* Avoid endless recursion if a `source' command is contained
3182 if (executing_breakpoint_commands
)
3185 executing_breakpoint_commands
= 1;
3186 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3188 prevent_dont_repeat ();
3190 /* This pointer will iterate over the list of bpstat's. */
3193 breakpoint_proceeded
= 0;
3194 for (; bs
!= NULL
; bs
= bs
->next
)
3196 struct counted_command_line
*ccmd
;
3197 struct command_line
*cmd
;
3198 struct cleanup
*this_cmd_tree_chain
;
3200 /* Take ownership of the BSP's command tree, if it has one.
3202 The command tree could legitimately contain commands like
3203 'step' and 'next', which call clear_proceed_status, which
3204 frees stop_bpstat's command tree. To make sure this doesn't
3205 free the tree we're executing out from under us, we need to
3206 take ownership of the tree ourselves. Since a given bpstat's
3207 commands are only executed once, we don't need to copy it; we
3208 can clear the pointer in the bpstat, and make sure we free
3209 the tree when we're done. */
3210 ccmd
= bs
->commands
;
3211 bs
->commands
= NULL
;
3213 = make_cleanup_decref_counted_command_line (&ccmd
);
3214 cmd
= bs
->commands_left
;
3215 bs
->commands_left
= NULL
;
3219 execute_control_command (cmd
);
3221 if (breakpoint_proceeded
)
3227 /* We can free this command tree now. */
3228 do_cleanups (this_cmd_tree_chain
);
3230 if (breakpoint_proceeded
)
3232 if (target_can_async_p ())
3233 /* If we are in async mode, then the target might be still
3234 running, not stopped at any breakpoint, so nothing for
3235 us to do here -- just return to the event loop. */
3238 /* In sync mode, when execute_control_command returns
3239 we're already standing on the next breakpoint.
3240 Breakpoint commands for that stop were not run, since
3241 execute_command does not run breakpoint commands --
3242 only command_line_handler does, but that one is not
3243 involved in execution of breakpoint commands. So, we
3244 can now execute breakpoint commands. It should be
3245 noted that making execute_command do bpstat actions is
3246 not an option -- in this case we'll have recursive
3247 invocation of bpstat for each breakpoint with a
3248 command, and can easily blow up GDB stack. Instead, we
3249 return true, which will trigger the caller to recall us
3250 with the new stop_bpstat. */
3255 do_cleanups (old_chain
);
3260 bpstat_do_actions (void)
3262 /* Do any commands attached to breakpoint we are stopped at. */
3263 while (!ptid_equal (inferior_ptid
, null_ptid
)
3264 && target_has_execution
3265 && !is_exited (inferior_ptid
)
3266 && !is_executing (inferior_ptid
))
3267 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3268 and only return when it is stopped at the next breakpoint, we
3269 keep doing breakpoint actions until it returns false to
3270 indicate the inferior was not resumed. */
3271 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3275 /* Print out the (old or new) value associated with a watchpoint. */
3278 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3281 fprintf_unfiltered (stream
, _("<unreadable>"));
3284 struct value_print_options opts
;
3285 get_user_print_options (&opts
);
3286 value_print (val
, stream
, &opts
);
3290 /* Generic routine for printing messages indicating why we
3291 stopped. The behavior of this function depends on the value
3292 'print_it' in the bpstat structure. Under some circumstances we
3293 may decide not to print anything here and delegate the task to
3296 static enum print_stop_action
3297 print_bp_stop_message (bpstat bs
)
3299 switch (bs
->print_it
)
3302 /* Nothing should be printed for this bpstat entry. */
3303 return PRINT_UNKNOWN
;
3307 /* We still want to print the frame, but we already printed the
3308 relevant messages. */
3309 return PRINT_SRC_AND_LOC
;
3312 case print_it_normal
:
3314 struct breakpoint
*b
= bs
->breakpoint_at
;
3316 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3317 which has since been deleted. */
3319 return PRINT_UNKNOWN
;
3321 /* Normal case. Call the breakpoint's print_it method. */
3322 return b
->ops
->print_it (bs
);
3327 internal_error (__FILE__
, __LINE__
,
3328 _("print_bp_stop_message: unrecognized enum value"));
3333 /* Print a message indicating what happened. This is called from
3334 normal_stop(). The input to this routine is the head of the bpstat
3335 list - a list of the eventpoints that caused this stop. This
3336 routine calls the generic print routine for printing a message
3337 about reasons for stopping. This will print (for example) the
3338 "Breakpoint n," part of the output. The return value of this
3341 PRINT_UNKNOWN: Means we printed nothing.
3342 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3343 code to print the location. An example is
3344 "Breakpoint 1, " which should be followed by
3346 PRINT_SRC_ONLY: Means we printed something, but there is no need
3347 to also print the location part of the message.
3348 An example is the catch/throw messages, which
3349 don't require a location appended to the end.
3350 PRINT_NOTHING: We have done some printing and we don't need any
3351 further info to be printed. */
3353 enum print_stop_action
3354 bpstat_print (bpstat bs
)
3358 /* Maybe another breakpoint in the chain caused us to stop.
3359 (Currently all watchpoints go on the bpstat whether hit or not.
3360 That probably could (should) be changed, provided care is taken
3361 with respect to bpstat_explains_signal). */
3362 for (; bs
; bs
= bs
->next
)
3364 val
= print_bp_stop_message (bs
);
3365 if (val
== PRINT_SRC_ONLY
3366 || val
== PRINT_SRC_AND_LOC
3367 || val
== PRINT_NOTHING
)
3371 /* We reached the end of the chain, or we got a null BS to start
3372 with and nothing was printed. */
3373 return PRINT_UNKNOWN
;
3376 /* Evaluate the expression EXP and return 1 if value is zero. This is
3377 used inside a catch_errors to evaluate the breakpoint condition.
3378 The argument is a "struct expression *" that has been cast to a
3379 "char *" to make it pass through catch_errors. */
3382 breakpoint_cond_eval (void *exp
)
3384 struct value
*mark
= value_mark ();
3385 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3387 value_free_to_mark (mark
);
3391 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3394 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3398 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3400 **bs_link_pointer
= bs
;
3401 *bs_link_pointer
= &bs
->next
;
3402 bs
->breakpoint_at
= bl
->owner
;
3403 bs
->bp_location_at
= bl
;
3404 incref_bp_location (bl
);
3405 /* If the condition is false, etc., don't do the commands. */
3406 bs
->commands
= NULL
;
3407 bs
->commands_left
= NULL
;
3409 bs
->print_it
= print_it_normal
;
3413 /* The target has stopped with waitstatus WS. Check if any hardware
3414 watchpoints have triggered, according to the target. */
3417 watchpoints_triggered (struct target_waitstatus
*ws
)
3419 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3421 struct breakpoint
*b
;
3423 if (!stopped_by_watchpoint
)
3425 /* We were not stopped by a watchpoint. Mark all watchpoints
3426 as not triggered. */
3428 if (is_hardware_watchpoint (b
))
3429 b
->watchpoint_triggered
= watch_triggered_no
;
3434 if (!target_stopped_data_address (¤t_target
, &addr
))
3436 /* We were stopped by a watchpoint, but we don't know where.
3437 Mark all watchpoints as unknown. */
3439 if (is_hardware_watchpoint (b
))
3440 b
->watchpoint_triggered
= watch_triggered_unknown
;
3442 return stopped_by_watchpoint
;
3445 /* The target could report the data address. Mark watchpoints
3446 affected by this data address as triggered, and all others as not
3450 if (is_hardware_watchpoint (b
))
3452 struct bp_location
*loc
;
3454 b
->watchpoint_triggered
= watch_triggered_no
;
3455 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3457 if (is_masked_watchpoint (loc
->owner
))
3459 CORE_ADDR newaddr
= addr
& loc
->owner
->hw_wp_mask
;
3460 CORE_ADDR start
= loc
->address
& loc
->owner
->hw_wp_mask
;
3462 if (newaddr
== start
)
3464 b
->watchpoint_triggered
= watch_triggered_yes
;
3468 /* Exact match not required. Within range is sufficient. */
3469 else if (target_watchpoint_addr_within_range (¤t_target
,
3473 b
->watchpoint_triggered
= watch_triggered_yes
;
3482 /* Possible return values for watchpoint_check (this can't be an enum
3483 because of check_errors). */
3484 /* The watchpoint has been deleted. */
3485 #define WP_DELETED 1
3486 /* The value has changed. */
3487 #define WP_VALUE_CHANGED 2
3488 /* The value has not changed. */
3489 #define WP_VALUE_NOT_CHANGED 3
3490 /* Ignore this watchpoint, no matter if the value changed or not. */
3493 #define BP_TEMPFLAG 1
3494 #define BP_HARDWAREFLAG 2
3496 /* Evaluate watchpoint condition expression and check if its value
3499 P should be a pointer to struct bpstat, but is defined as a void *
3500 in order for this function to be usable with catch_errors. */
3503 watchpoint_check (void *p
)
3505 bpstat bs
= (bpstat
) p
;
3506 struct breakpoint
*b
;
3507 struct frame_info
*fr
;
3508 int within_current_scope
;
3510 /* BS is built from an existing struct breakpoint. */
3511 gdb_assert (bs
->breakpoint_at
!= NULL
);
3512 b
= bs
->breakpoint_at
;
3514 gdb_assert (is_watchpoint (b
));
3516 /* If this is a local watchpoint, we only want to check if the
3517 watchpoint frame is in scope if the current thread is the thread
3518 that was used to create the watchpoint. */
3519 if (!watchpoint_in_thread_scope (b
))
3522 if (b
->exp_valid_block
== NULL
)
3523 within_current_scope
= 1;
3526 struct frame_info
*frame
= get_current_frame ();
3527 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3528 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3530 /* in_function_epilogue_p() returns a non-zero value if we're
3531 still in the function but the stack frame has already been
3532 invalidated. Since we can't rely on the values of local
3533 variables after the stack has been destroyed, we are treating
3534 the watchpoint in that state as `not changed' without further
3535 checking. Don't mark watchpoints as changed if the current
3536 frame is in an epilogue - even if they are in some other
3537 frame, our view of the stack is likely to be wrong and
3538 frame_find_by_id could error out. */
3539 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3542 fr
= frame_find_by_id (b
->watchpoint_frame
);
3543 within_current_scope
= (fr
!= NULL
);
3545 /* If we've gotten confused in the unwinder, we might have
3546 returned a frame that can't describe this variable. */
3547 if (within_current_scope
)
3549 struct symbol
*function
;
3551 function
= get_frame_function (fr
);
3552 if (function
== NULL
3553 || !contained_in (b
->exp_valid_block
,
3554 SYMBOL_BLOCK_VALUE (function
)))
3555 within_current_scope
= 0;
3558 if (within_current_scope
)
3559 /* If we end up stopping, the current frame will get selected
3560 in normal_stop. So this call to select_frame won't affect
3565 if (within_current_scope
)
3567 /* We use value_{,free_to_}mark because it could be a *long*
3568 time before we return to the command level and call
3569 free_all_values. We can't call free_all_values because we
3570 might be in the middle of evaluating a function call. */
3574 struct value
*new_val
;
3576 if (is_masked_watchpoint (b
))
3577 /* Since we don't know the exact trigger address (from
3578 stopped_data_address), just tell the user we've triggered
3579 a mask watchpoint. */
3580 return WP_VALUE_CHANGED
;
3582 mark
= value_mark ();
3583 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3585 /* We use value_equal_contents instead of value_equal because
3586 the latter coerces an array to a pointer, thus comparing just
3587 the address of the array instead of its contents. This is
3588 not what we want. */
3589 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3590 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3592 if (new_val
!= NULL
)
3594 release_value (new_val
);
3595 value_free_to_mark (mark
);
3597 bs
->old_val
= b
->val
;
3600 return WP_VALUE_CHANGED
;
3604 /* Nothing changed. */
3605 value_free_to_mark (mark
);
3606 return WP_VALUE_NOT_CHANGED
;
3611 /* This seems like the only logical thing to do because
3612 if we temporarily ignored the watchpoint, then when
3613 we reenter the block in which it is valid it contains
3614 garbage (in the case of a function, it may have two
3615 garbage values, one before and one after the prologue).
3616 So we can't even detect the first assignment to it and
3617 watch after that (since the garbage may or may not equal
3618 the first value assigned). */
3619 /* We print all the stop information in
3620 breakpoint_ops->print_it, but in this case, by the time we
3621 call breakpoint_ops->print_it this bp will be deleted
3622 already. So we have no choice but print the information
3624 if (ui_out_is_mi_like_p (uiout
))
3626 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3627 ui_out_text (uiout
, "\nWatchpoint ");
3628 ui_out_field_int (uiout
, "wpnum", b
->number
);
3630 " deleted because the program has left the block in\n\
3631 which its expression is valid.\n");
3633 /* Make sure the watchpoint's commands aren't executed. */
3634 decref_counted_command_line (&b
->commands
);
3635 watchpoint_del_at_next_stop (b
);
3641 /* Return true if it looks like target has stopped due to hitting
3642 breakpoint location BL. This function does not check if we should
3643 stop, only if BL explains the stop. */
3646 bpstat_check_location (const struct bp_location
*bl
,
3647 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3649 struct breakpoint
*b
= bl
->owner
;
3651 /* BL is from an existing breakpoint. */
3652 gdb_assert (b
!= NULL
);
3654 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3657 /* If BS refers to a watchpoint, determine if the watched values
3658 has actually changed, and we should stop. If not, set BS->stop
3661 bpstat_check_watchpoint (bpstat bs
)
3663 const struct bp_location
*bl
;
3664 struct breakpoint
*b
;
3666 /* BS is built for existing struct breakpoint. */
3667 bl
= bs
->bp_location_at
;
3668 gdb_assert (bl
!= NULL
);
3669 b
= bs
->breakpoint_at
;
3670 gdb_assert (b
!= NULL
);
3672 if (is_watchpoint (b
))
3674 int must_check_value
= 0;
3676 if (b
->type
== bp_watchpoint
)
3677 /* For a software watchpoint, we must always check the
3679 must_check_value
= 1;
3680 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3681 /* We have a hardware watchpoint (read, write, or access)
3682 and the target earlier reported an address watched by
3684 must_check_value
= 1;
3685 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3686 && b
->type
== bp_hardware_watchpoint
)
3687 /* We were stopped by a hardware watchpoint, but the target could
3688 not report the data address. We must check the watchpoint's
3689 value. Access and read watchpoints are out of luck; without
3690 a data address, we can't figure it out. */
3691 must_check_value
= 1;
3693 if (must_check_value
)
3696 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3698 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3699 int e
= catch_errors (watchpoint_check
, bs
, message
,
3701 do_cleanups (cleanups
);
3705 /* We've already printed what needs to be printed. */
3706 bs
->print_it
= print_it_done
;
3710 bs
->print_it
= print_it_noop
;
3713 case WP_VALUE_CHANGED
:
3714 if (b
->type
== bp_read_watchpoint
)
3716 /* There are two cases to consider here:
3718 1. We're watching the triggered memory for reads.
3719 In that case, trust the target, and always report
3720 the watchpoint hit to the user. Even though
3721 reads don't cause value changes, the value may
3722 have changed since the last time it was read, and
3723 since we're not trapping writes, we will not see
3724 those, and as such we should ignore our notion of
3727 2. We're watching the triggered memory for both
3728 reads and writes. There are two ways this may
3731 2.1. This is a target that can't break on data
3732 reads only, but can break on accesses (reads or
3733 writes), such as e.g., x86. We detect this case
3734 at the time we try to insert read watchpoints.
3736 2.2. Otherwise, the target supports read
3737 watchpoints, but, the user set an access or write
3738 watchpoint watching the same memory as this read
3741 If we're watching memory writes as well as reads,
3742 ignore watchpoint hits when we find that the
3743 value hasn't changed, as reads don't cause
3744 changes. This still gives false positives when
3745 the program writes the same value to memory as
3746 what there was already in memory (we will confuse
3747 it for a read), but it's much better than
3750 int other_write_watchpoint
= 0;
3752 if (bl
->watchpoint_type
== hw_read
)
3754 struct breakpoint
*other_b
;
3756 ALL_BREAKPOINTS (other_b
)
3757 if ((other_b
->type
== bp_hardware_watchpoint
3758 || other_b
->type
== bp_access_watchpoint
)
3759 && (other_b
->watchpoint_triggered
3760 == watch_triggered_yes
))
3762 other_write_watchpoint
= 1;
3767 if (other_write_watchpoint
3768 || bl
->watchpoint_type
== hw_access
)
3770 /* We're watching the same memory for writes,
3771 and the value changed since the last time we
3772 updated it, so this trap must be for a write.
3774 bs
->print_it
= print_it_noop
;
3779 case WP_VALUE_NOT_CHANGED
:
3780 if (b
->type
== bp_hardware_watchpoint
3781 || b
->type
== bp_watchpoint
)
3783 /* Don't stop: write watchpoints shouldn't fire if
3784 the value hasn't changed. */
3785 bs
->print_it
= print_it_noop
;
3793 /* Error from catch_errors. */
3794 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3795 watchpoint_del_at_next_stop (b
);
3796 /* We've already printed what needs to be printed. */
3797 bs
->print_it
= print_it_done
;
3801 else /* must_check_value == 0 */
3803 /* This is a case where some watchpoint(s) triggered, but
3804 not at the address of this watchpoint, or else no
3805 watchpoint triggered after all. So don't print
3806 anything for this watchpoint. */
3807 bs
->print_it
= print_it_noop
;
3814 /* Check conditions (condition proper, frame, thread and ignore count)
3815 of breakpoint referred to by BS. If we should not stop for this
3816 breakpoint, set BS->stop to 0. */
3819 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3821 int thread_id
= pid_to_thread_id (ptid
);
3822 const struct bp_location
*bl
;
3823 struct breakpoint
*b
;
3825 /* BS is built for existing struct breakpoint. */
3826 bl
= bs
->bp_location_at
;
3827 gdb_assert (bl
!= NULL
);
3828 b
= bs
->breakpoint_at
;
3829 gdb_assert (b
!= NULL
);
3831 if (frame_id_p (b
->frame_id
)
3832 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3836 int value_is_zero
= 0;
3837 struct expression
*cond
;
3839 /* Evaluate Python breakpoints that have a "stop"
3840 method implemented. */
3841 if (b
->py_bp_object
)
3842 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
3844 if (is_watchpoint (b
))
3849 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3851 int within_current_scope
= 1;
3853 /* We use value_mark and value_free_to_mark because it could
3854 be a long time before we return to the command level and
3855 call free_all_values. We can't call free_all_values
3856 because we might be in the middle of evaluating a
3858 struct value
*mark
= value_mark ();
3860 /* Need to select the frame, with all that implies so that
3861 the conditions will have the right context. Because we
3862 use the frame, we will not see an inlined function's
3863 variables when we arrive at a breakpoint at the start
3864 of the inlined function; the current frame will be the
3866 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3867 select_frame (get_current_frame ());
3870 struct frame_info
*frame
;
3872 /* For local watchpoint expressions, which particular
3873 instance of a local is being watched matters, so we
3874 keep track of the frame to evaluate the expression
3875 in. To evaluate the condition however, it doesn't
3876 really matter which instantiation of the function
3877 where the condition makes sense triggers the
3878 watchpoint. This allows an expression like "watch
3879 global if q > 10" set in `func', catch writes to
3880 global on all threads that call `func', or catch
3881 writes on all recursive calls of `func' by a single
3882 thread. We simply always evaluate the condition in
3883 the innermost frame that's executing where it makes
3884 sense to evaluate the condition. It seems
3886 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3888 select_frame (frame
);
3890 within_current_scope
= 0;
3892 if (within_current_scope
)
3894 = catch_errors (breakpoint_cond_eval
, cond
,
3895 "Error in testing breakpoint condition:\n",
3899 warning (_("Watchpoint condition cannot be tested "
3900 "in the current scope"));
3901 /* If we failed to set the right context for this
3902 watchpoint, unconditionally report it. */
3905 /* FIXME-someday, should give breakpoint #. */
3906 value_free_to_mark (mark
);
3909 if (cond
&& value_is_zero
)
3913 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3917 else if (b
->ignore_count
> 0)
3920 annotate_ignore_count_change ();
3922 /* Increase the hit count even though we don't stop. */
3924 observer_notify_breakpoint_modified (b
);
3930 /* Get a bpstat associated with having just stopped at address
3931 BP_ADDR in thread PTID.
3933 Determine whether we stopped at a breakpoint, etc, or whether we
3934 don't understand this stop. Result is a chain of bpstat's such
3937 if we don't understand the stop, the result is a null pointer.
3939 if we understand why we stopped, the result is not null.
3941 Each element of the chain refers to a particular breakpoint or
3942 watchpoint at which we have stopped. (We may have stopped for
3943 several reasons concurrently.)
3945 Each element of the chain has valid next, breakpoint_at,
3946 commands, FIXME??? fields. */
3949 bpstat_stop_status (struct address_space
*aspace
,
3950 CORE_ADDR bp_addr
, ptid_t ptid
)
3952 struct breakpoint
*b
= NULL
;
3953 struct bp_location
*bl
;
3954 struct bp_location
*loc
;
3955 /* First item of allocated bpstat's. */
3956 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
3957 /* Pointer to the last thing in the chain currently. */
3960 int need_remove_insert
;
3963 /* First, build the bpstat chain with locations that explain a
3964 target stop, while being careful to not set the target running,
3965 as that may invalidate locations (in particular watchpoint
3966 locations are recreated). Resuming will happen here with
3967 breakpoint conditions or watchpoint expressions that include
3968 inferior function calls. */
3972 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3975 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
3977 /* For hardware watchpoints, we look only at the first
3978 location. The watchpoint_check function will work on the
3979 entire expression, not the individual locations. For
3980 read watchpoints, the watchpoints_triggered function has
3981 checked all locations already. */
3982 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3985 if (bl
->shlib_disabled
)
3988 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
3991 /* Come here if it's a watchpoint, or if the break address
3994 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
3997 /* Assume we stop. Should we find a watchpoint that is not
3998 actually triggered, or if the condition of the breakpoint
3999 evaluates as false, we'll reset 'stop' to 0. */
4003 /* If this is a scope breakpoint, mark the associated
4004 watchpoint as triggered so that we will handle the
4005 out-of-scope event. We'll get to the watchpoint next
4007 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4008 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4012 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4014 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4016 bs
= bpstat_alloc (loc
, &bs_link
);
4017 /* For hits of moribund locations, we should just proceed. */
4020 bs
->print_it
= print_it_noop
;
4024 /* Now go through the locations that caused the target to stop, and
4025 check whether we're interested in reporting this stop to higher
4026 layers, or whether we should resume the target transparently. */
4030 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4035 b
= bs
->breakpoint_at
;
4036 b
->ops
->check_status (bs
);
4039 bpstat_check_breakpoint_conditions (bs
, ptid
);
4044 observer_notify_breakpoint_modified (b
);
4046 /* We will stop here. */
4047 if (b
->disposition
== disp_disable
)
4049 if (b
->enable_state
!= bp_permanent
)
4050 b
->enable_state
= bp_disabled
;
4055 bs
->commands
= b
->commands
;
4056 incref_counted_command_line (bs
->commands
);
4057 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4058 if (bs
->commands_left
4059 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4062 bs
->commands_left
->line
) == 0)))
4064 bs
->commands_left
= bs
->commands_left
->next
;
4069 /* Print nothing for this entry if we don't stop or don't print. */
4070 if (bs
->stop
== 0 || bs
->print
== 0)
4071 bs
->print_it
= print_it_noop
;
4075 /* If we aren't stopping, the value of some hardware watchpoint may
4076 not have changed, but the intermediate memory locations we are
4077 watching may have. Don't bother if we're stopping; this will get
4079 need_remove_insert
= 0;
4080 if (! bpstat_causes_stop (bs_head
))
4081 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4083 && bs
->breakpoint_at
4084 && is_hardware_watchpoint (bs
->breakpoint_at
))
4086 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4087 need_remove_insert
= 1;
4090 if (need_remove_insert
)
4091 update_global_location_list (1);
4092 else if (removed_any
)
4093 update_global_location_list (0);
4099 handle_jit_event (void)
4101 struct frame_info
*frame
;
4102 struct gdbarch
*gdbarch
;
4104 /* Switch terminal for any messages produced by
4105 breakpoint_re_set. */
4106 target_terminal_ours_for_output ();
4108 frame
= get_current_frame ();
4109 gdbarch
= get_frame_arch (frame
);
4111 jit_event_handler (gdbarch
);
4113 target_terminal_inferior ();
4116 /* Prepare WHAT final decision for infrun. */
4118 /* Decide what infrun needs to do with this bpstat. */
4121 bpstat_what (bpstat bs_head
)
4123 struct bpstat_what retval
;
4124 /* We need to defer calling `solib_add', as adding new symbols
4125 resets breakpoints, which in turn deletes breakpoint locations,
4126 and hence may clear unprocessed entries in the BS chain. */
4127 int shlib_event
= 0;
4131 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4132 retval
.call_dummy
= STOP_NONE
;
4133 retval
.is_longjmp
= 0;
4135 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4137 /* Extract this BS's action. After processing each BS, we check
4138 if its action overrides all we've seem so far. */
4139 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4142 if (bs
->breakpoint_at
== NULL
)
4144 /* I suspect this can happen if it was a momentary
4145 breakpoint which has since been deleted. */
4149 bptype
= bs
->breakpoint_at
->type
;
4156 case bp_hardware_breakpoint
:
4162 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4164 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4167 this_action
= BPSTAT_WHAT_SINGLE
;
4170 case bp_hardware_watchpoint
:
4171 case bp_read_watchpoint
:
4172 case bp_access_watchpoint
:
4176 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4178 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4182 /* There was a watchpoint, but we're not stopping.
4183 This requires no further action. */
4188 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4189 retval
.is_longjmp
= bptype
== bp_longjmp
;
4191 case bp_longjmp_resume
:
4192 case bp_exception_resume
:
4193 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4194 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4196 case bp_step_resume
:
4198 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4201 /* It is for the wrong frame. */
4202 this_action
= BPSTAT_WHAT_SINGLE
;
4205 case bp_hp_step_resume
:
4207 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4210 /* It is for the wrong frame. */
4211 this_action
= BPSTAT_WHAT_SINGLE
;
4214 case bp_watchpoint_scope
:
4215 case bp_thread_event
:
4216 case bp_overlay_event
:
4217 case bp_longjmp_master
:
4218 case bp_std_terminate_master
:
4219 case bp_exception_master
:
4220 this_action
= BPSTAT_WHAT_SINGLE
;
4226 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4228 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4232 /* There was a catchpoint, but we're not stopping.
4233 This requires no further action. */
4236 case bp_shlib_event
:
4239 /* If requested, stop when the dynamic linker notifies GDB
4240 of events. This allows the user to get control and place
4241 breakpoints in initializer routines for dynamically
4242 loaded objects (among other things). */
4243 if (stop_on_solib_events
)
4244 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4246 this_action
= BPSTAT_WHAT_SINGLE
;
4250 this_action
= BPSTAT_WHAT_SINGLE
;
4253 /* Make sure the action is stop (silent or noisy),
4254 so infrun.c pops the dummy frame. */
4255 retval
.call_dummy
= STOP_STACK_DUMMY
;
4256 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4258 case bp_std_terminate
:
4259 /* Make sure the action is stop (silent or noisy),
4260 so infrun.c pops the dummy frame. */
4261 retval
.call_dummy
= STOP_STD_TERMINATE
;
4262 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4265 case bp_fast_tracepoint
:
4266 case bp_static_tracepoint
:
4267 /* Tracepoint hits should not be reported back to GDB, and
4268 if one got through somehow, it should have been filtered
4270 internal_error (__FILE__
, __LINE__
,
4271 _("bpstat_what: tracepoint encountered"));
4273 case bp_gnu_ifunc_resolver
:
4274 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4275 this_action
= BPSTAT_WHAT_SINGLE
;
4277 case bp_gnu_ifunc_resolver_return
:
4278 /* The breakpoint will be removed, execution will restart from the
4279 PC of the former breakpoint. */
4280 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4283 internal_error (__FILE__
, __LINE__
,
4284 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4287 retval
.main_action
= max (retval
.main_action
, this_action
);
4290 /* These operations may affect the bs->breakpoint_at state so they are
4291 delayed after MAIN_ACTION is decided above. */
4296 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4298 /* Check for any newly added shared libraries if we're supposed
4299 to be adding them automatically. */
4301 /* Switch terminal for any messages produced by
4302 breakpoint_re_set. */
4303 target_terminal_ours_for_output ();
4306 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4308 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4311 target_terminal_inferior ();
4317 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4319 handle_jit_event ();
4322 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4324 struct breakpoint
*b
= bs
->breakpoint_at
;
4330 case bp_gnu_ifunc_resolver
:
4331 gnu_ifunc_resolver_stop (b
);
4333 case bp_gnu_ifunc_resolver_return
:
4334 gnu_ifunc_resolver_return_stop (b
);
4342 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4343 without hardware support). This isn't related to a specific bpstat,
4344 just to things like whether watchpoints are set. */
4347 bpstat_should_step (void)
4349 struct breakpoint
*b
;
4352 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4358 bpstat_causes_stop (bpstat bs
)
4360 for (; bs
!= NULL
; bs
= bs
->next
)
4369 /* Compute a string of spaces suitable to indent the next line
4370 so it starts at the position corresponding to the table column
4371 named COL_NAME in the currently active table of UIOUT. */
4374 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4376 static char wrap_indent
[80];
4377 int i
, total_width
, width
, align
;
4381 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4383 if (strcmp (text
, col_name
) == 0)
4385 gdb_assert (total_width
< sizeof wrap_indent
);
4386 memset (wrap_indent
, ' ', total_width
);
4387 wrap_indent
[total_width
] = 0;
4392 total_width
+= width
+ 1;
4398 /* Print the LOC location out of the list of B->LOC locations. */
4401 print_breakpoint_location (struct breakpoint
*b
,
4402 struct bp_location
*loc
)
4404 struct cleanup
*old_chain
= save_current_program_space ();
4406 if (loc
!= NULL
&& loc
->shlib_disabled
)
4410 set_current_program_space (loc
->pspace
);
4412 if (b
->display_canonical
)
4413 ui_out_field_string (uiout
, "what", b
->addr_string
);
4414 else if (b
->source_file
&& loc
)
4417 = find_pc_sect_function (loc
->address
, loc
->section
);
4420 ui_out_text (uiout
, "in ");
4421 ui_out_field_string (uiout
, "func",
4422 SYMBOL_PRINT_NAME (sym
));
4423 ui_out_text (uiout
, " ");
4424 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4425 ui_out_text (uiout
, "at ");
4427 ui_out_field_string (uiout
, "file", b
->source_file
);
4428 ui_out_text (uiout
, ":");
4430 if (ui_out_is_mi_like_p (uiout
))
4432 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4433 char *fullname
= symtab_to_fullname (sal
.symtab
);
4436 ui_out_field_string (uiout
, "fullname", fullname
);
4439 ui_out_field_int (uiout
, "line", b
->line_number
);
4443 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4444 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4446 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4448 ui_out_field_stream (uiout
, "at", stb
);
4450 do_cleanups (stb_chain
);
4453 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4455 do_cleanups (old_chain
);
4459 bptype_string (enum bptype type
)
4461 struct ep_type_description
4466 static struct ep_type_description bptypes
[] =
4468 {bp_none
, "?deleted?"},
4469 {bp_breakpoint
, "breakpoint"},
4470 {bp_hardware_breakpoint
, "hw breakpoint"},
4471 {bp_until
, "until"},
4472 {bp_finish
, "finish"},
4473 {bp_watchpoint
, "watchpoint"},
4474 {bp_hardware_watchpoint
, "hw watchpoint"},
4475 {bp_read_watchpoint
, "read watchpoint"},
4476 {bp_access_watchpoint
, "acc watchpoint"},
4477 {bp_longjmp
, "longjmp"},
4478 {bp_longjmp_resume
, "longjmp resume"},
4479 {bp_exception
, "exception"},
4480 {bp_exception_resume
, "exception resume"},
4481 {bp_step_resume
, "step resume"},
4482 {bp_hp_step_resume
, "high-priority step resume"},
4483 {bp_watchpoint_scope
, "watchpoint scope"},
4484 {bp_call_dummy
, "call dummy"},
4485 {bp_std_terminate
, "std::terminate"},
4486 {bp_shlib_event
, "shlib events"},
4487 {bp_thread_event
, "thread events"},
4488 {bp_overlay_event
, "overlay events"},
4489 {bp_longjmp_master
, "longjmp master"},
4490 {bp_std_terminate_master
, "std::terminate master"},
4491 {bp_exception_master
, "exception master"},
4492 {bp_catchpoint
, "catchpoint"},
4493 {bp_tracepoint
, "tracepoint"},
4494 {bp_fast_tracepoint
, "fast tracepoint"},
4495 {bp_static_tracepoint
, "static tracepoint"},
4496 {bp_jit_event
, "jit events"},
4497 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4498 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4501 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4502 || ((int) type
!= bptypes
[(int) type
].type
))
4503 internal_error (__FILE__
, __LINE__
,
4504 _("bptypes table does not describe type #%d."),
4507 return bptypes
[(int) type
].description
;
4510 /* Print B to gdb_stdout. */
4513 print_one_breakpoint_location (struct breakpoint
*b
,
4514 struct bp_location
*loc
,
4516 struct bp_location
**last_loc
,
4519 struct command_line
*l
;
4520 static char bpenables
[] = "nynny";
4522 int header_of_multiple
= 0;
4523 int part_of_multiple
= (loc
!= NULL
);
4524 struct value_print_options opts
;
4526 get_user_print_options (&opts
);
4528 gdb_assert (!loc
|| loc_number
!= 0);
4529 /* See comment in print_one_breakpoint concerning treatment of
4530 breakpoints with single disabled location. */
4533 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4534 header_of_multiple
= 1;
4542 if (part_of_multiple
)
4545 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4546 ui_out_field_string (uiout
, "number", formatted
);
4551 ui_out_field_int (uiout
, "number", b
->number
);
4556 if (part_of_multiple
)
4557 ui_out_field_skip (uiout
, "type");
4559 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4563 if (part_of_multiple
)
4564 ui_out_field_skip (uiout
, "disp");
4566 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4571 if (part_of_multiple
)
4572 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4574 ui_out_field_fmt (uiout
, "enabled", "%c",
4575 bpenables
[(int) b
->enable_state
]);
4576 ui_out_spaces (uiout
, 2);
4580 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4582 /* Although the print_one can possibly print all locations,
4583 calling it here is not likely to get any nice result. So,
4584 make sure there's just one location. */
4585 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4586 b
->ops
->print_one (b
, last_loc
);
4592 internal_error (__FILE__
, __LINE__
,
4593 _("print_one_breakpoint: bp_none encountered\n"));
4597 case bp_hardware_watchpoint
:
4598 case bp_read_watchpoint
:
4599 case bp_access_watchpoint
:
4600 /* Field 4, the address, is omitted (which makes the columns
4601 not line up too nicely with the headers, but the effect
4602 is relatively readable). */
4603 if (opts
.addressprint
)
4604 ui_out_field_skip (uiout
, "addr");
4606 ui_out_field_string (uiout
, "what", b
->exp_string
);
4610 case bp_hardware_breakpoint
:
4614 case bp_longjmp_resume
:
4616 case bp_exception_resume
:
4617 case bp_step_resume
:
4618 case bp_hp_step_resume
:
4619 case bp_watchpoint_scope
:
4621 case bp_std_terminate
:
4622 case bp_shlib_event
:
4623 case bp_thread_event
:
4624 case bp_overlay_event
:
4625 case bp_longjmp_master
:
4626 case bp_std_terminate_master
:
4627 case bp_exception_master
:
4629 case bp_fast_tracepoint
:
4630 case bp_static_tracepoint
:
4632 case bp_gnu_ifunc_resolver
:
4633 case bp_gnu_ifunc_resolver_return
:
4634 if (opts
.addressprint
)
4637 if (header_of_multiple
)
4638 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4639 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4640 ui_out_field_string (uiout
, "addr", "<PENDING>");
4642 ui_out_field_core_addr (uiout
, "addr",
4643 loc
->gdbarch
, loc
->address
);
4646 if (!header_of_multiple
)
4647 print_breakpoint_location (b
, loc
);
4654 /* For backward compatibility, don't display inferiors unless there
4657 && !header_of_multiple
4659 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4660 && (number_of_program_spaces () > 1
4661 || number_of_inferiors () > 1)
4662 /* LOC is for existing B, it cannot be in
4663 moribund_locations and thus having NULL OWNER. */
4664 && loc
->owner
->type
!= bp_catchpoint
)))
4666 struct inferior
*inf
;
4669 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4671 if (inf
->pspace
== loc
->pspace
)
4676 ui_out_text (uiout
, " inf ");
4679 ui_out_text (uiout
, ", ");
4680 ui_out_text (uiout
, plongest (inf
->num
));
4685 if (!part_of_multiple
)
4687 if (b
->thread
!= -1)
4689 /* FIXME: This seems to be redundant and lost here; see the
4690 "stop only in" line a little further down. */
4691 ui_out_text (uiout
, " thread ");
4692 ui_out_field_int (uiout
, "thread", b
->thread
);
4694 else if (b
->task
!= 0)
4696 ui_out_text (uiout
, " task ");
4697 ui_out_field_int (uiout
, "task", b
->task
);
4701 ui_out_text (uiout
, "\n");
4703 if (!part_of_multiple
)
4704 b
->ops
->print_one_detail (b
, uiout
);
4706 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4709 ui_out_text (uiout
, "\tstop only in stack frame at ");
4710 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4712 ui_out_field_core_addr (uiout
, "frame",
4713 b
->gdbarch
, b
->frame_id
.stack_addr
);
4714 ui_out_text (uiout
, "\n");
4717 if (!part_of_multiple
&& b
->cond_string
)
4720 if (is_tracepoint (b
))
4721 ui_out_text (uiout
, "\ttrace only if ");
4723 ui_out_text (uiout
, "\tstop only if ");
4724 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4725 ui_out_text (uiout
, "\n");
4728 if (!part_of_multiple
&& b
->thread
!= -1)
4730 /* FIXME should make an annotation for this. */
4731 ui_out_text (uiout
, "\tstop only in thread ");
4732 ui_out_field_int (uiout
, "thread", b
->thread
);
4733 ui_out_text (uiout
, "\n");
4736 if (!part_of_multiple
&& b
->hit_count
)
4738 /* FIXME should make an annotation for this. */
4739 if (ep_is_catchpoint (b
))
4740 ui_out_text (uiout
, "\tcatchpoint");
4742 ui_out_text (uiout
, "\tbreakpoint");
4743 ui_out_text (uiout
, " already hit ");
4744 ui_out_field_int (uiout
, "times", b
->hit_count
);
4745 if (b
->hit_count
== 1)
4746 ui_out_text (uiout
, " time\n");
4748 ui_out_text (uiout
, " times\n");
4751 /* Output the count also if it is zero, but only if this is mi.
4752 FIXME: Should have a better test for this. */
4753 if (ui_out_is_mi_like_p (uiout
))
4754 if (!part_of_multiple
&& b
->hit_count
== 0)
4755 ui_out_field_int (uiout
, "times", b
->hit_count
);
4757 if (!part_of_multiple
&& b
->ignore_count
)
4760 ui_out_text (uiout
, "\tignore next ");
4761 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4762 ui_out_text (uiout
, " hits\n");
4765 l
= b
->commands
? b
->commands
->commands
: NULL
;
4766 if (!part_of_multiple
&& l
)
4768 struct cleanup
*script_chain
;
4771 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4772 print_command_lines (uiout
, l
, 4);
4773 do_cleanups (script_chain
);
4776 if (!part_of_multiple
&& b
->pass_count
)
4778 annotate_field (10);
4779 ui_out_text (uiout
, "\tpass count ");
4780 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4781 ui_out_text (uiout
, " \n");
4784 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4787 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4788 else if (b
->exp_string
)
4789 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4794 print_one_breakpoint (struct breakpoint
*b
,
4795 struct bp_location
**last_loc
,
4798 struct cleanup
*bkpt_chain
;
4800 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4802 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
4803 do_cleanups (bkpt_chain
);
4805 /* If this breakpoint has custom print function,
4806 it's already printed. Otherwise, print individual
4807 locations, if any. */
4808 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4810 /* If breakpoint has a single location that is disabled, we
4811 print it as if it had several locations, since otherwise it's
4812 hard to represent "breakpoint enabled, location disabled"
4815 Note that while hardware watchpoints have several locations
4816 internally, that's not a property exposed to user. */
4818 && !is_hardware_watchpoint (b
)
4819 && (b
->loc
->next
|| !b
->loc
->enabled
))
4821 struct bp_location
*loc
;
4824 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4826 struct cleanup
*inner2
=
4827 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
4828 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
4829 do_cleanups (inner2
);
4836 breakpoint_address_bits (struct breakpoint
*b
)
4838 int print_address_bits
= 0;
4839 struct bp_location
*loc
;
4841 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4845 /* Software watchpoints that aren't watching memory don't have
4846 an address to print. */
4847 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4850 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4851 if (addr_bit
> print_address_bits
)
4852 print_address_bits
= addr_bit
;
4855 return print_address_bits
;
4858 struct captured_breakpoint_query_args
4864 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4866 struct captured_breakpoint_query_args
*args
= data
;
4867 struct breakpoint
*b
;
4868 struct bp_location
*dummy_loc
= NULL
;
4872 if (args
->bnum
== b
->number
)
4874 print_one_breakpoint (b
, &dummy_loc
, 0);
4882 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
4883 char **error_message
)
4885 struct captured_breakpoint_query_args args
;
4888 /* For the moment we don't trust print_one_breakpoint() to not throw
4890 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4891 error_message
, RETURN_MASK_ALL
) < 0)
4897 /* Return true if this breakpoint was set by the user, false if it is
4898 internal or momentary. */
4901 user_breakpoint_p (struct breakpoint
*b
)
4903 return b
->number
> 0;
4906 /* Print information on user settable breakpoint (watchpoint, etc)
4907 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4908 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4909 FILTER is non-NULL, call it on each breakpoint and only include the
4910 ones for which it returns non-zero. Return the total number of
4911 breakpoints listed. */
4914 breakpoint_1 (char *args
, int allflag
,
4915 int (*filter
) (const struct breakpoint
*))
4917 struct breakpoint
*b
;
4918 struct bp_location
*last_loc
= NULL
;
4919 int nr_printable_breakpoints
;
4920 struct cleanup
*bkpttbl_chain
;
4921 struct value_print_options opts
;
4922 int print_address_bits
= 0;
4923 int print_type_col_width
= 14;
4925 get_user_print_options (&opts
);
4927 /* Compute the number of rows in the table, as well as the size
4928 required for address fields. */
4929 nr_printable_breakpoints
= 0;
4932 /* If we have a filter, only list the breakpoints it accepts. */
4933 if (filter
&& !filter (b
))
4936 /* If we have an "args" string, it is a list of breakpoints to
4937 accept. Skip the others. */
4938 if (args
!= NULL
&& *args
!= '\0')
4940 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
4942 if (!allflag
&& !number_is_in_list (args
, b
->number
))
4946 if (allflag
|| user_breakpoint_p (b
))
4948 int addr_bit
, type_len
;
4950 addr_bit
= breakpoint_address_bits (b
);
4951 if (addr_bit
> print_address_bits
)
4952 print_address_bits
= addr_bit
;
4954 type_len
= strlen (bptype_string (b
->type
));
4955 if (type_len
> print_type_col_width
)
4956 print_type_col_width
= type_len
;
4958 nr_printable_breakpoints
++;
4962 if (opts
.addressprint
)
4964 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
4965 nr_printable_breakpoints
,
4969 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
4970 nr_printable_breakpoints
,
4973 if (nr_printable_breakpoints
> 0)
4974 annotate_breakpoints_headers ();
4975 if (nr_printable_breakpoints
> 0)
4977 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4978 if (nr_printable_breakpoints
> 0)
4980 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
4981 "type", "Type"); /* 2 */
4982 if (nr_printable_breakpoints
> 0)
4984 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4985 if (nr_printable_breakpoints
> 0)
4987 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4988 if (opts
.addressprint
)
4990 if (nr_printable_breakpoints
> 0)
4992 if (print_address_bits
<= 32)
4993 ui_out_table_header (uiout
, 10, ui_left
,
4994 "addr", "Address"); /* 5 */
4996 ui_out_table_header (uiout
, 18, ui_left
,
4997 "addr", "Address"); /* 5 */
4999 if (nr_printable_breakpoints
> 0)
5001 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5002 ui_out_table_body (uiout
);
5003 if (nr_printable_breakpoints
> 0)
5004 annotate_breakpoints_table ();
5009 /* If we have a filter, only list the breakpoints it accepts. */
5010 if (filter
&& !filter (b
))
5013 /* If we have an "args" string, it is a list of breakpoints to
5014 accept. Skip the others. */
5016 if (args
!= NULL
&& *args
!= '\0')
5018 if (allflag
) /* maintenance info breakpoint */
5020 if (parse_and_eval_long (args
) != b
->number
)
5023 else /* all others */
5025 if (!number_is_in_list (args
, b
->number
))
5029 /* We only print out user settable breakpoints unless the
5031 if (allflag
|| user_breakpoint_p (b
))
5032 print_one_breakpoint (b
, &last_loc
, allflag
);
5035 do_cleanups (bkpttbl_chain
);
5037 if (nr_printable_breakpoints
== 0)
5039 /* If there's a filter, let the caller decide how to report
5043 if (args
== NULL
|| *args
== '\0')
5044 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5046 ui_out_message (uiout
, 0,
5047 "No breakpoint or watchpoint matching '%s'.\n",
5053 if (last_loc
&& !server_command
)
5054 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5057 /* FIXME? Should this be moved up so that it is only called when
5058 there have been breakpoints? */
5059 annotate_breakpoints_table_end ();
5061 return nr_printable_breakpoints
;
5064 /* Display the value of default-collect in a way that is generally
5065 compatible with the breakpoint list. */
5068 default_collect_info (void)
5070 /* If it has no value (which is frequently the case), say nothing; a
5071 message like "No default-collect." gets in user's face when it's
5073 if (!*default_collect
)
5076 /* The following phrase lines up nicely with per-tracepoint collect
5078 ui_out_text (uiout
, "default collect ");
5079 ui_out_field_string (uiout
, "default-collect", default_collect
);
5080 ui_out_text (uiout
, " \n");
5084 breakpoints_info (char *args
, int from_tty
)
5086 breakpoint_1 (args
, 0, NULL
);
5088 default_collect_info ();
5092 watchpoints_info (char *args
, int from_tty
)
5094 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5096 if (num_printed
== 0)
5098 if (args
== NULL
|| *args
== '\0')
5099 ui_out_message (uiout
, 0, "No watchpoints.\n");
5101 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5106 maintenance_info_breakpoints (char *args
, int from_tty
)
5108 breakpoint_1 (args
, 1, NULL
);
5110 default_collect_info ();
5114 breakpoint_has_pc (struct breakpoint
*b
,
5115 struct program_space
*pspace
,
5116 CORE_ADDR pc
, struct obj_section
*section
)
5118 struct bp_location
*bl
= b
->loc
;
5120 for (; bl
; bl
= bl
->next
)
5122 if (bl
->pspace
== pspace
5123 && bl
->address
== pc
5124 && (!overlay_debugging
|| bl
->section
== section
))
5130 /* Print a message describing any breakpoints set at PC. This
5131 concerns with logical breakpoints, so we match program spaces, not
5135 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5136 struct program_space
*pspace
, CORE_ADDR pc
,
5137 struct obj_section
*section
, int thread
)
5140 struct breakpoint
*b
;
5143 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5147 printf_filtered (_("Note: breakpoint "));
5148 else /* if (others == ???) */
5149 printf_filtered (_("Note: breakpoints "));
5151 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5154 printf_filtered ("%d", b
->number
);
5155 if (b
->thread
== -1 && thread
!= -1)
5156 printf_filtered (" (all threads)");
5157 else if (b
->thread
!= -1)
5158 printf_filtered (" (thread %d)", b
->thread
);
5159 printf_filtered ("%s%s ",
5160 ((b
->enable_state
== bp_disabled
5161 || b
->enable_state
== bp_call_disabled
5162 || b
->enable_state
== bp_startup_disabled
)
5164 : b
->enable_state
== bp_permanent
5168 : ((others
== 1) ? " and" : ""));
5170 printf_filtered (_("also set at pc "));
5171 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5172 printf_filtered (".\n");
5176 /* Set the default place to put a breakpoint
5177 for the `break' command with no arguments. */
5180 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5181 CORE_ADDR addr
, struct symtab
*symtab
,
5184 default_breakpoint_valid
= valid
;
5185 default_breakpoint_pspace
= pspace
;
5186 default_breakpoint_address
= addr
;
5187 default_breakpoint_symtab
= symtab
;
5188 default_breakpoint_line
= line
;
5191 /* Return true iff it is meaningful to use the address member of
5192 BPT. For some breakpoint types, the address member is irrelevant
5193 and it makes no sense to attempt to compare it to other addresses
5194 (or use it for any other purpose either).
5196 More specifically, each of the following breakpoint types will
5197 always have a zero valued address and we don't want to mark
5198 breakpoints of any of these types to be a duplicate of an actual
5199 breakpoint at address zero:
5207 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5209 enum bptype type
= bpt
->type
;
5211 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5214 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5215 true if LOC1 and LOC2 represent the same watchpoint location. */
5218 watchpoint_locations_match (struct bp_location
*loc1
,
5219 struct bp_location
*loc2
)
5221 /* Both of them must not be in moribund_locations. */
5222 gdb_assert (loc1
->owner
!= NULL
);
5223 gdb_assert (loc2
->owner
!= NULL
);
5225 /* If the target can evaluate the condition expression in hardware,
5226 then we we need to insert both watchpoints even if they are at
5227 the same place. Otherwise the watchpoint will only trigger when
5228 the condition of whichever watchpoint was inserted evaluates to
5229 true, not giving a chance for GDB to check the condition of the
5230 other watchpoint. */
5231 if ((loc1
->owner
->cond_exp
5232 && target_can_accel_watchpoint_condition (loc1
->address
,
5234 loc1
->watchpoint_type
,
5235 loc1
->owner
->cond_exp
))
5236 || (loc2
->owner
->cond_exp
5237 && target_can_accel_watchpoint_condition (loc2
->address
,
5239 loc2
->watchpoint_type
,
5240 loc2
->owner
->cond_exp
)))
5243 /* Note that this checks the owner's type, not the location's. In
5244 case the target does not support read watchpoints, but does
5245 support access watchpoints, we'll have bp_read_watchpoint
5246 watchpoints with hw_access locations. Those should be considered
5247 duplicates of hw_read locations. The hw_read locations will
5248 become hw_access locations later. */
5249 return (loc1
->owner
->type
== loc2
->owner
->type
5250 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5251 && loc1
->address
== loc2
->address
5252 && loc1
->length
== loc2
->length
);
5255 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5256 same breakpoint location. In most targets, this can only be true
5257 if ASPACE1 matches ASPACE2. On targets that have global
5258 breakpoints, the address space doesn't really matter. */
5261 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5262 struct address_space
*aspace2
, CORE_ADDR addr2
)
5264 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5265 || aspace1
== aspace2
)
5269 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5270 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5271 matches ASPACE2. On targets that have global breakpoints, the address
5272 space doesn't really matter. */
5275 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5276 int len1
, struct address_space
*aspace2
,
5279 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5280 || aspace1
== aspace2
)
5281 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5284 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5285 a ranged breakpoint. In most targets, a match happens only if ASPACE
5286 matches the breakpoint's address space. On targets that have global
5287 breakpoints, the address space doesn't really matter. */
5290 breakpoint_location_address_match (struct bp_location
*bl
,
5291 struct address_space
*aspace
,
5294 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5297 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5298 bl
->address
, bl
->length
,
5302 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5303 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5304 represent the same location. */
5307 breakpoint_locations_match (struct bp_location
*loc1
,
5308 struct bp_location
*loc2
)
5310 int hw_point1
, hw_point2
;
5312 /* Both of them must not be in moribund_locations. */
5313 gdb_assert (loc1
->owner
!= NULL
);
5314 gdb_assert (loc2
->owner
!= NULL
);
5316 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5317 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5319 if (hw_point1
!= hw_point2
)
5322 return watchpoint_locations_match (loc1
, loc2
);
5324 /* We compare bp_location.length in order to cover ranged breakpoints. */
5325 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5326 loc2
->pspace
->aspace
, loc2
->address
)
5327 && loc1
->length
== loc2
->length
);
5331 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5332 int bnum
, int have_bnum
)
5334 /* The longest string possibly returned by hex_string_custom
5335 is 50 chars. These must be at least that big for safety. */
5339 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5340 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5342 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5343 bnum
, astr1
, astr2
);
5345 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5348 /* Adjust a breakpoint's address to account for architectural
5349 constraints on breakpoint placement. Return the adjusted address.
5350 Note: Very few targets require this kind of adjustment. For most
5351 targets, this function is simply the identity function. */
5354 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5355 CORE_ADDR bpaddr
, enum bptype bptype
)
5357 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5359 /* Very few targets need any kind of breakpoint adjustment. */
5362 else if (bptype
== bp_watchpoint
5363 || bptype
== bp_hardware_watchpoint
5364 || bptype
== bp_read_watchpoint
5365 || bptype
== bp_access_watchpoint
5366 || bptype
== bp_catchpoint
)
5368 /* Watchpoints and the various bp_catch_* eventpoints should not
5369 have their addresses modified. */
5374 CORE_ADDR adjusted_bpaddr
;
5376 /* Some targets have architectural constraints on the placement
5377 of breakpoint instructions. Obtain the adjusted address. */
5378 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5380 /* An adjusted breakpoint address can significantly alter
5381 a user's expectations. Print a warning if an adjustment
5383 if (adjusted_bpaddr
!= bpaddr
)
5384 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5386 return adjusted_bpaddr
;
5391 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5392 struct breakpoint
*owner
)
5394 memset (loc
, 0, sizeof (*loc
));
5396 gdb_assert (ops
!= NULL
);
5401 loc
->shlib_disabled
= 0;
5404 switch (owner
->type
)
5410 case bp_longjmp_resume
:
5412 case bp_exception_resume
:
5413 case bp_step_resume
:
5414 case bp_hp_step_resume
:
5415 case bp_watchpoint_scope
:
5417 case bp_std_terminate
:
5418 case bp_shlib_event
:
5419 case bp_thread_event
:
5420 case bp_overlay_event
:
5422 case bp_longjmp_master
:
5423 case bp_std_terminate_master
:
5424 case bp_exception_master
:
5425 case bp_gnu_ifunc_resolver
:
5426 case bp_gnu_ifunc_resolver_return
:
5427 loc
->loc_type
= bp_loc_software_breakpoint
;
5429 case bp_hardware_breakpoint
:
5430 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5432 case bp_hardware_watchpoint
:
5433 case bp_read_watchpoint
:
5434 case bp_access_watchpoint
:
5435 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5440 case bp_fast_tracepoint
:
5441 case bp_static_tracepoint
:
5442 loc
->loc_type
= bp_loc_other
;
5445 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5451 /* Allocate a struct bp_location. */
5453 static struct bp_location
*
5454 allocate_bp_location (struct breakpoint
*bpt
)
5456 return bpt
->ops
->allocate_location (bpt
);
5460 free_bp_location (struct bp_location
*loc
)
5462 loc
->ops
->dtor (loc
);
5466 /* Increment reference count. */
5469 incref_bp_location (struct bp_location
*bl
)
5474 /* Decrement reference count. If the reference count reaches 0,
5475 destroy the bp_location. Sets *BLP to NULL. */
5478 decref_bp_location (struct bp_location
**blp
)
5480 gdb_assert ((*blp
)->refc
> 0);
5482 if (--(*blp
)->refc
== 0)
5483 free_bp_location (*blp
);
5487 /* Add breakpoint B at the end of the global breakpoint chain. */
5490 add_to_breakpoint_chain (struct breakpoint
*b
)
5492 struct breakpoint
*b1
;
5494 /* Add this breakpoint to the end of the chain so that a list of
5495 breakpoints will come out in order of increasing numbers. */
5497 b1
= breakpoint_chain
;
5499 breakpoint_chain
= b
;
5508 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5511 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5512 struct gdbarch
*gdbarch
,
5514 struct breakpoint_ops
*ops
)
5516 memset (b
, 0, sizeof (*b
));
5518 gdb_assert (ops
!= NULL
);
5522 b
->gdbarch
= gdbarch
;
5523 b
->language
= current_language
->la_language
;
5524 b
->input_radix
= input_radix
;
5526 b
->enable_state
= bp_enabled
;
5529 b
->ignore_count
= 0;
5531 b
->frame_id
= null_frame_id
;
5532 b
->condition_not_parsed
= 0;
5533 b
->py_bp_object
= NULL
;
5534 b
->related_breakpoint
= b
;
5537 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5538 that has type BPTYPE and has no locations as yet. */
5540 static struct breakpoint
*
5541 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5543 struct breakpoint_ops
*ops
)
5545 struct breakpoint
*b
= XNEW (struct breakpoint
);
5547 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5548 add_to_breakpoint_chain (b
);
5552 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5553 resolutions should be made as the user specified the location explicitly
5557 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5559 gdb_assert (loc
->owner
!= NULL
);
5561 if (loc
->owner
->type
== bp_breakpoint
5562 || loc
->owner
->type
== bp_hardware_breakpoint
5563 || is_tracepoint (loc
->owner
))
5567 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5568 NULL
, NULL
, &is_gnu_ifunc
);
5570 if (is_gnu_ifunc
&& !explicit_loc
)
5572 struct breakpoint
*b
= loc
->owner
;
5574 gdb_assert (loc
->pspace
== current_program_space
);
5575 if (gnu_ifunc_resolve_name (loc
->function_name
,
5576 &loc
->requested_address
))
5578 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5579 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5580 loc
->requested_address
,
5583 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5584 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5586 /* Create only the whole new breakpoint of this type but do not
5587 mess more complicated breakpoints with multiple locations. */
5588 b
->type
= bp_gnu_ifunc_resolver
;
5592 if (loc
->function_name
)
5593 loc
->function_name
= xstrdup (loc
->function_name
);
5597 /* Attempt to determine architecture of location identified by SAL. */
5598 static struct gdbarch
*
5599 get_sal_arch (struct symtab_and_line sal
)
5602 return get_objfile_arch (sal
.section
->objfile
);
5604 return get_objfile_arch (sal
.symtab
->objfile
);
5609 /* Low level routine for partially initializing a breakpoint of type
5610 BPTYPE. The newly created breakpoint's address, section, source
5611 file name, and line number are provided by SAL.
5613 It is expected that the caller will complete the initialization of
5614 the newly created breakpoint struct as well as output any status
5615 information regarding the creation of a new breakpoint. */
5618 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5619 struct symtab_and_line sal
, enum bptype bptype
,
5620 struct breakpoint_ops
*ops
)
5622 CORE_ADDR adjusted_address
;
5623 struct gdbarch
*loc_gdbarch
;
5625 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5627 loc_gdbarch
= get_sal_arch (sal
);
5629 loc_gdbarch
= b
->gdbarch
;
5631 if (bptype
!= bp_catchpoint
)
5632 gdb_assert (sal
.pspace
!= NULL
);
5634 /* Adjust the breakpoint's address prior to allocating a location.
5635 Once we call allocate_bp_location(), that mostly uninitialized
5636 location will be placed on the location chain. Adjustment of the
5637 breakpoint may cause target_read_memory() to be called and we do
5638 not want its scan of the location chain to find a breakpoint and
5639 location that's only been partially initialized. */
5640 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5643 b
->loc
= allocate_bp_location (b
);
5644 b
->loc
->gdbarch
= loc_gdbarch
;
5645 b
->loc
->requested_address
= sal
.pc
;
5646 b
->loc
->address
= adjusted_address
;
5647 b
->loc
->pspace
= sal
.pspace
;
5649 /* Store the program space that was used to set the breakpoint, for
5650 breakpoint resetting. */
5651 b
->pspace
= sal
.pspace
;
5653 if (sal
.symtab
== NULL
)
5654 b
->source_file
= NULL
;
5656 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5657 b
->loc
->section
= sal
.section
;
5658 b
->line_number
= sal
.line
;
5660 set_breakpoint_location_function (b
->loc
,
5661 sal
.explicit_pc
|| sal
.explicit_line
);
5663 breakpoints_changed ();
5666 /* set_raw_breakpoint is a low level routine for allocating and
5667 partially initializing a breakpoint of type BPTYPE. The newly
5668 created breakpoint's address, section, source file name, and line
5669 number are provided by SAL. The newly created and partially
5670 initialized breakpoint is added to the breakpoint chain and
5671 is also returned as the value of this function.
5673 It is expected that the caller will complete the initialization of
5674 the newly created breakpoint struct as well as output any status
5675 information regarding the creation of a new breakpoint. In
5676 particular, set_raw_breakpoint does NOT set the breakpoint
5677 number! Care should be taken to not allow an error to occur
5678 prior to completing the initialization of the breakpoint. If this
5679 should happen, a bogus breakpoint will be left on the chain. */
5682 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5683 struct symtab_and_line sal
, enum bptype bptype
,
5684 struct breakpoint_ops
*ops
)
5686 struct breakpoint
*b
= XNEW (struct breakpoint
);
5688 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5689 add_to_breakpoint_chain (b
);
5694 /* Note that the breakpoint object B describes a permanent breakpoint
5695 instruction, hard-wired into the inferior's code. */
5697 make_breakpoint_permanent (struct breakpoint
*b
)
5699 struct bp_location
*bl
;
5701 b
->enable_state
= bp_permanent
;
5703 /* By definition, permanent breakpoints are already present in the
5704 code. Mark all locations as inserted. For now,
5705 make_breakpoint_permanent is called in just one place, so it's
5706 hard to say if it's reasonable to have permanent breakpoint with
5707 multiple locations or not, but it's easy to implement. */
5708 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5712 /* Call this routine when stepping and nexting to enable a breakpoint
5713 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5714 initiated the operation. */
5717 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5719 struct breakpoint
*b
, *b_tmp
;
5720 int thread
= tp
->num
;
5722 /* To avoid having to rescan all objfile symbols at every step,
5723 we maintain a list of continually-inserted but always disabled
5724 longjmp "master" breakpoints. Here, we simply create momentary
5725 clones of those and enable them for the requested thread. */
5726 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5727 if (b
->pspace
== current_program_space
5728 && (b
->type
== bp_longjmp_master
5729 || b
->type
== bp_exception_master
))
5731 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5733 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5734 clone
->thread
= thread
;
5737 tp
->initiating_frame
= frame
;
5740 /* Delete all longjmp breakpoints from THREAD. */
5742 delete_longjmp_breakpoint (int thread
)
5744 struct breakpoint
*b
, *b_tmp
;
5746 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5747 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5749 if (b
->thread
== thread
)
5750 delete_breakpoint (b
);
5755 enable_overlay_breakpoints (void)
5757 struct breakpoint
*b
;
5760 if (b
->type
== bp_overlay_event
)
5762 b
->enable_state
= bp_enabled
;
5763 update_global_location_list (1);
5764 overlay_events_enabled
= 1;
5769 disable_overlay_breakpoints (void)
5771 struct breakpoint
*b
;
5774 if (b
->type
== bp_overlay_event
)
5776 b
->enable_state
= bp_disabled
;
5777 update_global_location_list (0);
5778 overlay_events_enabled
= 0;
5782 /* Set an active std::terminate breakpoint for each std::terminate
5783 master breakpoint. */
5785 set_std_terminate_breakpoint (void)
5787 struct breakpoint
*b
, *b_tmp
;
5789 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5790 if (b
->pspace
== current_program_space
5791 && b
->type
== bp_std_terminate_master
)
5793 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5794 clone
->type
= bp_std_terminate
;
5798 /* Delete all the std::terminate breakpoints. */
5800 delete_std_terminate_breakpoint (void)
5802 struct breakpoint
*b
, *b_tmp
;
5804 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5805 if (b
->type
== bp_std_terminate
)
5806 delete_breakpoint (b
);
5810 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5812 struct breakpoint
*b
;
5814 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5816 b
->enable_state
= bp_enabled
;
5817 /* addr_string has to be used or breakpoint_re_set will delete me. */
5819 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5821 update_global_location_list_nothrow (1);
5827 remove_thread_event_breakpoints (void)
5829 struct breakpoint
*b
, *b_tmp
;
5831 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5832 if (b
->type
== bp_thread_event
5833 && b
->loc
->pspace
== current_program_space
)
5834 delete_breakpoint (b
);
5837 struct lang_and_radix
5843 /* Create a breakpoint for JIT code registration and unregistration. */
5846 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5848 struct breakpoint
*b
;
5850 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5851 update_global_location_list_nothrow (1);
5855 /* Remove JIT code registration and unregistration breakpoint(s). */
5858 remove_jit_event_breakpoints (void)
5860 struct breakpoint
*b
, *b_tmp
;
5862 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5863 if (b
->type
== bp_jit_event
5864 && b
->loc
->pspace
== current_program_space
)
5865 delete_breakpoint (b
);
5869 remove_solib_event_breakpoints (void)
5871 struct breakpoint
*b
, *b_tmp
;
5873 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5874 if (b
->type
== bp_shlib_event
5875 && b
->loc
->pspace
== current_program_space
)
5876 delete_breakpoint (b
);
5880 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5882 struct breakpoint
*b
;
5884 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5885 update_global_location_list_nothrow (1);
5889 /* Disable any breakpoints that are on code in shared libraries. Only
5890 apply to enabled breakpoints, disabled ones can just stay disabled. */
5893 disable_breakpoints_in_shlibs (void)
5895 struct bp_location
*loc
, **locp_tmp
;
5897 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5899 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5900 struct breakpoint
*b
= loc
->owner
;
5902 /* We apply the check to all breakpoints, including disabled for
5903 those with loc->duplicate set. This is so that when breakpoint
5904 becomes enabled, or the duplicate is removed, gdb will try to
5905 insert all breakpoints. If we don't set shlib_disabled here,
5906 we'll try to insert those breakpoints and fail. */
5907 if (((b
->type
== bp_breakpoint
)
5908 || (b
->type
== bp_jit_event
)
5909 || (b
->type
== bp_hardware_breakpoint
)
5910 || (is_tracepoint (b
)))
5911 && loc
->pspace
== current_program_space
5912 && !loc
->shlib_disabled
5914 && PC_SOLIB (loc
->address
)
5916 && solib_name_from_address (loc
->pspace
, loc
->address
)
5920 loc
->shlib_disabled
= 1;
5925 /* Disable any breakpoints that are in an unloaded shared library.
5926 Only apply to enabled breakpoints, disabled ones can just stay
5930 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5932 struct bp_location
*loc
, **locp_tmp
;
5933 int disabled_shlib_breaks
= 0;
5935 /* SunOS a.out shared libraries are always mapped, so do not
5936 disable breakpoints; they will only be reported as unloaded
5937 through clear_solib when GDB discards its shared library
5938 list. See clear_solib for more information. */
5939 if (exec_bfd
!= NULL
5940 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5943 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5945 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5946 struct breakpoint
*b
= loc
->owner
;
5948 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5949 || loc
->loc_type
== bp_loc_software_breakpoint
)
5950 && solib
->pspace
== loc
->pspace
5951 && !loc
->shlib_disabled
5952 && (b
->type
== bp_breakpoint
5953 || b
->type
== bp_jit_event
5954 || b
->type
== bp_hardware_breakpoint
)
5955 && solib_contains_address_p (solib
, loc
->address
))
5957 loc
->shlib_disabled
= 1;
5958 /* At this point, we cannot rely on remove_breakpoint
5959 succeeding so we must mark the breakpoint as not inserted
5960 to prevent future errors occurring in remove_breakpoints. */
5963 /* This may cause duplicate notifications for the same breakpoint. */
5964 observer_notify_breakpoint_modified (b
);
5966 if (!disabled_shlib_breaks
)
5968 target_terminal_ours_for_output ();
5969 warning (_("Temporarily disabling breakpoints "
5970 "for unloaded shared library \"%s\""),
5973 disabled_shlib_breaks
= 1;
5978 /* FORK & VFORK catchpoints. */
5980 /* An instance of this type is used to represent a fork or vfork
5981 catchpoint. It includes a "struct breakpoint" as a kind of base
5982 class; users downcast to "struct breakpoint *" when needed. A
5983 breakpoint is really of this type iff its ops pointer points to
5984 CATCH_FORK_BREAKPOINT_OPS. */
5986 struct fork_catchpoint
5988 /* The base class. */
5989 struct breakpoint base
;
5991 /* Process id of a child process whose forking triggered this
5992 catchpoint. This field is only valid immediately after this
5993 catchpoint has triggered. */
5994 ptid_t forked_inferior_pid
;
5997 /* Implement the "insert" breakpoint_ops method for fork
6001 insert_catch_fork (struct bp_location
*bl
)
6003 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6006 /* Implement the "remove" breakpoint_ops method for fork
6010 remove_catch_fork (struct bp_location
*bl
)
6012 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6015 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6019 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6020 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6022 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6024 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6027 /* Implement the "print_it" breakpoint_ops method for fork
6030 static enum print_stop_action
6031 print_it_catch_fork (bpstat bs
)
6033 struct breakpoint
*b
= bs
->breakpoint_at
;
6034 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6036 annotate_catchpoint (b
->number
);
6037 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6038 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6039 return PRINT_SRC_AND_LOC
;
6042 /* Implement the "print_one" breakpoint_ops method for fork
6046 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6048 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6049 struct value_print_options opts
;
6051 get_user_print_options (&opts
);
6053 /* Field 4, the address, is omitted (which makes the columns not
6054 line up too nicely with the headers, but the effect is relatively
6056 if (opts
.addressprint
)
6057 ui_out_field_skip (uiout
, "addr");
6059 ui_out_text (uiout
, "fork");
6060 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6062 ui_out_text (uiout
, ", process ");
6063 ui_out_field_int (uiout
, "what",
6064 ptid_get_pid (c
->forked_inferior_pid
));
6065 ui_out_spaces (uiout
, 1);
6069 /* Implement the "print_mention" breakpoint_ops method for fork
6073 print_mention_catch_fork (struct breakpoint
*b
)
6075 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6078 /* Implement the "print_recreate" breakpoint_ops method for fork
6082 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6084 fprintf_unfiltered (fp
, "catch fork");
6087 /* The breakpoint_ops structure to be used in fork catchpoints. */
6089 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6092 bkpt_allocate_location
,
6096 breakpoint_hit_catch_fork
,
6098 null_resources_needed
,
6099 null_works_in_software_mode
,
6100 print_it_catch_fork
,
6101 print_one_catch_fork
,
6102 null_print_one_detail
,
6103 print_mention_catch_fork
,
6104 print_recreate_catch_fork
6107 /* Implement the "insert" breakpoint_ops method for vfork
6111 insert_catch_vfork (struct bp_location
*bl
)
6113 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6116 /* Implement the "remove" breakpoint_ops method for vfork
6120 remove_catch_vfork (struct bp_location
*bl
)
6122 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6125 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6129 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6130 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6132 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6134 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6137 /* Implement the "print_it" breakpoint_ops method for vfork
6140 static enum print_stop_action
6141 print_it_catch_vfork (bpstat bs
)
6143 struct breakpoint
*b
= bs
->breakpoint_at
;
6144 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6146 annotate_catchpoint (b
->number
);
6147 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6148 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6149 return PRINT_SRC_AND_LOC
;
6152 /* Implement the "print_one" breakpoint_ops method for vfork
6156 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6158 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6159 struct value_print_options opts
;
6161 get_user_print_options (&opts
);
6162 /* Field 4, the address, is omitted (which makes the columns not
6163 line up too nicely with the headers, but the effect is relatively
6165 if (opts
.addressprint
)
6166 ui_out_field_skip (uiout
, "addr");
6168 ui_out_text (uiout
, "vfork");
6169 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6171 ui_out_text (uiout
, ", process ");
6172 ui_out_field_int (uiout
, "what",
6173 ptid_get_pid (c
->forked_inferior_pid
));
6174 ui_out_spaces (uiout
, 1);
6178 /* Implement the "print_mention" breakpoint_ops method for vfork
6182 print_mention_catch_vfork (struct breakpoint
*b
)
6184 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6187 /* Implement the "print_recreate" breakpoint_ops method for vfork
6191 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6193 fprintf_unfiltered (fp
, "catch vfork");
6196 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6198 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6201 bkpt_allocate_location
,
6205 breakpoint_hit_catch_vfork
,
6207 null_resources_needed
,
6208 null_works_in_software_mode
,
6209 print_it_catch_vfork
,
6210 print_one_catch_vfork
,
6211 null_print_one_detail
,
6212 print_mention_catch_vfork
,
6213 print_recreate_catch_vfork
6216 /* An instance of this type is used to represent a syscall catchpoint.
6217 It includes a "struct breakpoint" as a kind of base class; users
6218 downcast to "struct breakpoint *" when needed. A breakpoint is
6219 really of this type iff its ops pointer points to
6220 CATCH_SYSCALL_BREAKPOINT_OPS. */
6222 struct syscall_catchpoint
6224 /* The base class. */
6225 struct breakpoint base
;
6227 /* Syscall numbers used for the 'catch syscall' feature. If no
6228 syscall has been specified for filtering, its value is NULL.
6229 Otherwise, it holds a list of all syscalls to be caught. The
6230 list elements are allocated with xmalloc. */
6231 VEC(int) *syscalls_to_be_caught
;
6234 /* Implement the "dtor" breakpoint_ops method for syscall
6238 dtor_catch_syscall (struct breakpoint
*b
)
6240 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6242 VEC_free (int, c
->syscalls_to_be_caught
);
6247 /* Implement the "insert" breakpoint_ops method for syscall
6251 insert_catch_syscall (struct bp_location
*bl
)
6253 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6254 struct inferior
*inf
= current_inferior ();
6256 ++inf
->total_syscalls_count
;
6257 if (!c
->syscalls_to_be_caught
)
6258 ++inf
->any_syscall_count
;
6264 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6269 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6271 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6272 uintptr_t vec_addr_offset
6273 = old_size
* ((uintptr_t) sizeof (int));
6275 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6276 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6278 memset ((void *) vec_addr
, 0,
6279 (iter
+ 1 - old_size
) * sizeof (int));
6281 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6282 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6286 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6287 inf
->total_syscalls_count
!= 0,
6288 inf
->any_syscall_count
,
6289 VEC_length (int, inf
->syscalls_counts
),
6290 VEC_address (int, inf
->syscalls_counts
));
6293 /* Implement the "remove" breakpoint_ops method for syscall
6297 remove_catch_syscall (struct bp_location
*bl
)
6299 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6300 struct inferior
*inf
= current_inferior ();
6302 --inf
->total_syscalls_count
;
6303 if (!c
->syscalls_to_be_caught
)
6304 --inf
->any_syscall_count
;
6310 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6314 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6315 /* Shouldn't happen. */
6317 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6318 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6322 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6323 inf
->total_syscalls_count
!= 0,
6324 inf
->any_syscall_count
,
6325 VEC_length (int, inf
->syscalls_counts
),
6327 inf
->syscalls_counts
));
6330 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6334 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6335 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6337 /* We must check if we are catching specific syscalls in this
6338 breakpoint. If we are, then we must guarantee that the called
6339 syscall is the same syscall we are catching. */
6340 int syscall_number
= 0;
6341 const struct syscall_catchpoint
*c
6342 = (const struct syscall_catchpoint
*) bl
->owner
;
6344 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6347 /* Now, checking if the syscall is the same. */
6348 if (c
->syscalls_to_be_caught
)
6353 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6355 if (syscall_number
== iter
)
6365 /* Implement the "print_it" breakpoint_ops method for syscall
6368 static enum print_stop_action
6369 print_it_catch_syscall (bpstat bs
)
6371 struct breakpoint
*b
= bs
->breakpoint_at
;
6372 /* These are needed because we want to know in which state a
6373 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6374 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6375 must print "called syscall" or "returned from syscall". */
6377 struct target_waitstatus last
;
6379 struct cleanup
*old_chain
;
6382 get_last_target_status (&ptid
, &last
);
6384 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6386 annotate_catchpoint (b
->number
);
6389 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6391 syscall_id
= xstrprintf ("'%s'", s
.name
);
6393 old_chain
= make_cleanup (xfree
, syscall_id
);
6395 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6396 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6397 b
->number
, syscall_id
);
6398 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6399 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6400 b
->number
, syscall_id
);
6402 do_cleanups (old_chain
);
6404 return PRINT_SRC_AND_LOC
;
6407 /* Implement the "print_one" breakpoint_ops method for syscall
6411 print_one_catch_syscall (struct breakpoint
*b
,
6412 struct bp_location
**last_loc
)
6414 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6415 struct value_print_options opts
;
6417 get_user_print_options (&opts
);
6418 /* Field 4, the address, is omitted (which makes the columns not
6419 line up too nicely with the headers, but the effect is relatively
6421 if (opts
.addressprint
)
6422 ui_out_field_skip (uiout
, "addr");
6425 if (c
->syscalls_to_be_caught
6426 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6427 ui_out_text (uiout
, "syscalls \"");
6429 ui_out_text (uiout
, "syscall \"");
6431 if (c
->syscalls_to_be_caught
)
6434 char *text
= xstrprintf ("%s", "");
6437 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6442 get_syscall_by_number (iter
, &s
);
6445 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6447 text
= xstrprintf ("%s%d, ", text
, iter
);
6449 /* We have to xfree the last 'text' (now stored at 'x')
6450 because xstrprintf dynamically allocates new space for it
6454 /* Remove the last comma. */
6455 text
[strlen (text
) - 2] = '\0';
6456 ui_out_field_string (uiout
, "what", text
);
6459 ui_out_field_string (uiout
, "what", "<any syscall>");
6460 ui_out_text (uiout
, "\" ");
6463 /* Implement the "print_mention" breakpoint_ops method for syscall
6467 print_mention_catch_syscall (struct breakpoint
*b
)
6469 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6471 if (c
->syscalls_to_be_caught
)
6475 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6476 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6478 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6481 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6485 get_syscall_by_number (iter
, &s
);
6488 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6490 printf_filtered (" %d", s
.number
);
6492 printf_filtered (")");
6495 printf_filtered (_("Catchpoint %d (any syscall)"),
6499 /* Implement the "print_recreate" breakpoint_ops method for syscall
6503 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6505 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6507 fprintf_unfiltered (fp
, "catch syscall");
6509 if (c
->syscalls_to_be_caught
)
6514 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6519 get_syscall_by_number (iter
, &s
);
6521 fprintf_unfiltered (fp
, " %s", s
.name
);
6523 fprintf_unfiltered (fp
, " %d", s
.number
);
6528 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6530 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6533 bkpt_allocate_location
,
6535 insert_catch_syscall
,
6536 remove_catch_syscall
,
6537 breakpoint_hit_catch_syscall
,
6539 null_resources_needed
,
6540 null_works_in_software_mode
,
6541 print_it_catch_syscall
,
6542 print_one_catch_syscall
,
6543 null_print_one_detail
,
6544 print_mention_catch_syscall
,
6545 print_recreate_catch_syscall
6548 /* Returns non-zero if 'b' is a syscall catchpoint. */
6551 syscall_catchpoint_p (struct breakpoint
*b
)
6553 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6556 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6557 is non-zero, then make the breakpoint temporary. If COND_STRING is
6558 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6559 the breakpoint_ops structure associated to the catchpoint. */
6562 init_catchpoint (struct breakpoint
*b
,
6563 struct gdbarch
*gdbarch
, int tempflag
,
6565 struct breakpoint_ops
*ops
)
6567 struct symtab_and_line sal
;
6570 sal
.pspace
= current_program_space
;
6572 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6574 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6575 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6579 install_breakpoint (struct breakpoint
*b
)
6581 add_to_breakpoint_chain (b
);
6582 set_breakpoint_count (breakpoint_count
+ 1);
6583 b
->number
= breakpoint_count
;
6585 observer_notify_breakpoint_created (b
);
6586 update_global_location_list (1);
6590 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6591 int tempflag
, char *cond_string
,
6592 struct breakpoint_ops
*ops
)
6594 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6596 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6598 c
->forked_inferior_pid
= null_ptid
;
6600 install_breakpoint (&c
->base
);
6603 /* Exec catchpoints. */
6605 /* An instance of this type is used to represent an exec catchpoint.
6606 It includes a "struct breakpoint" as a kind of base class; users
6607 downcast to "struct breakpoint *" when needed. A breakpoint is
6608 really of this type iff its ops pointer points to
6609 CATCH_EXEC_BREAKPOINT_OPS. */
6611 struct exec_catchpoint
6613 /* The base class. */
6614 struct breakpoint base
;
6616 /* Filename of a program whose exec triggered this catchpoint.
6617 This field is only valid immediately after this catchpoint has
6619 char *exec_pathname
;
6622 /* Implement the "dtor" breakpoint_ops method for exec
6626 dtor_catch_exec (struct breakpoint
*b
)
6628 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6630 xfree (c
->exec_pathname
);
6636 insert_catch_exec (struct bp_location
*bl
)
6638 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6642 remove_catch_exec (struct bp_location
*bl
)
6644 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6648 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6649 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6651 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6653 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6656 static enum print_stop_action
6657 print_it_catch_exec (bpstat bs
)
6659 struct breakpoint
*b
= bs
->breakpoint_at
;
6660 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6662 annotate_catchpoint (b
->number
);
6663 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6665 return PRINT_SRC_AND_LOC
;
6669 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6671 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6672 struct value_print_options opts
;
6674 get_user_print_options (&opts
);
6676 /* Field 4, the address, is omitted (which makes the columns
6677 not line up too nicely with the headers, but the effect
6678 is relatively readable). */
6679 if (opts
.addressprint
)
6680 ui_out_field_skip (uiout
, "addr");
6682 ui_out_text (uiout
, "exec");
6683 if (c
->exec_pathname
!= NULL
)
6685 ui_out_text (uiout
, ", program \"");
6686 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6687 ui_out_text (uiout
, "\" ");
6692 print_mention_catch_exec (struct breakpoint
*b
)
6694 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6697 /* Implement the "print_recreate" breakpoint_ops method for exec
6701 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6703 fprintf_unfiltered (fp
, "catch exec");
6706 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6709 bkpt_allocate_location
,
6713 breakpoint_hit_catch_exec
,
6715 null_resources_needed
,
6716 null_works_in_software_mode
,
6717 print_it_catch_exec
,
6718 print_one_catch_exec
,
6719 null_print_one_detail
,
6720 print_mention_catch_exec
,
6721 print_recreate_catch_exec
6725 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6726 struct breakpoint_ops
*ops
)
6728 struct syscall_catchpoint
*c
;
6729 struct gdbarch
*gdbarch
= get_current_arch ();
6731 c
= XNEW (struct syscall_catchpoint
);
6732 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6733 c
->syscalls_to_be_caught
= filter
;
6735 install_breakpoint (&c
->base
);
6739 hw_breakpoint_used_count (void)
6742 struct breakpoint
*b
;
6743 struct bp_location
*bl
;
6747 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6748 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6750 /* Special types of hardware breakpoints may use more than
6752 i
+= b
->ops
->resources_needed (bl
);
6760 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6763 struct breakpoint
*b
;
6764 struct bp_location
*bl
;
6766 *other_type_used
= 0;
6769 if (!breakpoint_enabled (b
))
6772 if (b
->type
== type
)
6773 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6775 /* Special types of hardware watchpoints may use more than
6777 i
+= b
->ops
->resources_needed (bl
);
6779 else if (is_hardware_watchpoint (b
))
6780 *other_type_used
= 1;
6787 disable_watchpoints_before_interactive_call_start (void)
6789 struct breakpoint
*b
;
6793 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6795 b
->enable_state
= bp_call_disabled
;
6796 update_global_location_list (0);
6802 enable_watchpoints_after_interactive_call_stop (void)
6804 struct breakpoint
*b
;
6808 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6810 b
->enable_state
= bp_enabled
;
6811 update_global_location_list (1);
6817 disable_breakpoints_before_startup (void)
6819 struct breakpoint
*b
;
6824 if (b
->pspace
!= current_program_space
)
6827 if ((b
->type
== bp_breakpoint
6828 || b
->type
== bp_hardware_breakpoint
)
6829 && breakpoint_enabled (b
))
6831 b
->enable_state
= bp_startup_disabled
;
6837 update_global_location_list (0);
6839 current_program_space
->executing_startup
= 1;
6843 enable_breakpoints_after_startup (void)
6845 struct breakpoint
*b
;
6848 current_program_space
->executing_startup
= 0;
6852 if (b
->pspace
!= current_program_space
)
6855 if ((b
->type
== bp_breakpoint
6856 || b
->type
== bp_hardware_breakpoint
)
6857 && b
->enable_state
== bp_startup_disabled
)
6859 b
->enable_state
= bp_enabled
;
6865 breakpoint_re_set ();
6869 /* Set a breakpoint that will evaporate an end of command
6870 at address specified by SAL.
6871 Restrict it to frame FRAME if FRAME is nonzero. */
6874 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6875 struct frame_id frame_id
, enum bptype type
)
6877 struct breakpoint
*b
;
6879 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6881 gdb_assert (!frame_id_inlined_p (frame_id
));
6883 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &bkpt_breakpoint_ops
);
6884 b
->enable_state
= bp_enabled
;
6885 b
->disposition
= disp_donttouch
;
6886 b
->frame_id
= frame_id
;
6888 /* If we're debugging a multi-threaded program, then we want
6889 momentary breakpoints to be active in only a single thread of
6891 if (in_thread_list (inferior_ptid
))
6892 b
->thread
= pid_to_thread_id (inferior_ptid
);
6894 update_global_location_list_nothrow (1);
6899 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6903 clone_momentary_breakpoint (struct breakpoint
*orig
)
6905 struct breakpoint
*copy
;
6907 /* If there's nothing to clone, then return nothing. */
6911 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
,
6912 orig
->type
, orig
->ops
);
6913 copy
->loc
= allocate_bp_location (copy
);
6914 set_breakpoint_location_function (copy
->loc
, 1);
6916 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6917 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6918 copy
->loc
->address
= orig
->loc
->address
;
6919 copy
->loc
->section
= orig
->loc
->section
;
6920 copy
->loc
->pspace
= orig
->loc
->pspace
;
6922 if (orig
->source_file
== NULL
)
6923 copy
->source_file
= NULL
;
6925 copy
->source_file
= xstrdup (orig
->source_file
);
6927 copy
->line_number
= orig
->line_number
;
6928 copy
->frame_id
= orig
->frame_id
;
6929 copy
->thread
= orig
->thread
;
6930 copy
->pspace
= orig
->pspace
;
6932 copy
->enable_state
= bp_enabled
;
6933 copy
->disposition
= disp_donttouch
;
6934 copy
->number
= internal_breakpoint_number
--;
6936 update_global_location_list_nothrow (0);
6941 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6944 struct symtab_and_line sal
;
6946 sal
= find_pc_line (pc
, 0);
6948 sal
.section
= find_pc_overlay (pc
);
6949 sal
.explicit_pc
= 1;
6951 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6955 /* Tell the user we have just set a breakpoint B. */
6958 mention (struct breakpoint
*b
)
6960 b
->ops
->print_mention (b
);
6961 if (ui_out_is_mi_like_p (uiout
))
6963 printf_filtered ("\n");
6967 static struct bp_location
*
6968 add_location_to_breakpoint (struct breakpoint
*b
,
6969 const struct symtab_and_line
*sal
)
6971 struct bp_location
*loc
, **tmp
;
6973 loc
= allocate_bp_location (b
);
6974 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6977 loc
->gdbarch
= get_sal_arch (*sal
);
6979 loc
->gdbarch
= b
->gdbarch
;
6980 loc
->requested_address
= sal
->pc
;
6981 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6982 loc
->requested_address
, b
->type
);
6983 loc
->pspace
= sal
->pspace
;
6984 gdb_assert (loc
->pspace
!= NULL
);
6985 loc
->section
= sal
->section
;
6987 set_breakpoint_location_function (loc
,
6988 sal
->explicit_pc
|| sal
->explicit_line
);
6993 /* Return 1 if LOC is pointing to a permanent breakpoint,
6994 return 0 otherwise. */
6997 bp_loc_is_permanent (struct bp_location
*loc
)
7001 const gdb_byte
*brk
;
7002 gdb_byte
*target_mem
;
7003 struct cleanup
*cleanup
;
7006 gdb_assert (loc
!= NULL
);
7008 addr
= loc
->address
;
7009 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7011 /* Software breakpoints unsupported? */
7015 target_mem
= alloca (len
);
7017 /* Enable the automatic memory restoration from breakpoints while
7018 we read the memory. Otherwise we could say about our temporary
7019 breakpoints they are permanent. */
7020 cleanup
= save_current_space_and_thread ();
7022 switch_to_program_space_and_thread (loc
->pspace
);
7023 make_show_memory_breakpoints_cleanup (0);
7025 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7026 && memcmp (target_mem
, brk
, len
) == 0)
7029 do_cleanups (cleanup
);
7036 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7037 as textual description of the location, and COND_STRING
7038 as condition expression. */
7041 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7042 struct symtabs_and_lines sals
, char *addr_string
,
7044 enum bptype type
, enum bpdisp disposition
,
7045 int thread
, int task
, int ignore_count
,
7046 struct breakpoint_ops
*ops
, int from_tty
,
7047 int enabled
, int internal
, int display_canonical
)
7049 struct breakpoint
*b
= NULL
;
7052 if (type
== bp_hardware_breakpoint
)
7054 int i
= hw_breakpoint_used_count ();
7055 int target_resources_ok
=
7056 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7058 if (target_resources_ok
== 0)
7059 error (_("No hardware breakpoint support in the target."));
7060 else if (target_resources_ok
< 0)
7061 error (_("Hardware breakpoints used exceeds limit."));
7064 gdb_assert (sals
.nelts
> 0);
7066 for (i
= 0; i
< sals
.nelts
; ++i
)
7068 struct symtab_and_line sal
= sals
.sals
[i
];
7069 struct bp_location
*loc
;
7073 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7075 loc_gdbarch
= gdbarch
;
7077 describe_other_breakpoints (loc_gdbarch
,
7078 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7083 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
7084 set_breakpoint_number (internal
, b
);
7088 b
->cond_string
= cond_string
;
7089 b
->ignore_count
= ignore_count
;
7090 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7091 b
->disposition
= disposition
;
7092 b
->pspace
= sals
.sals
[0].pspace
;
7094 if (type
== bp_static_tracepoint
)
7096 struct static_tracepoint_marker marker
;
7098 if (is_marker_spec (addr_string
))
7100 /* We already know the marker exists, otherwise, we
7101 wouldn't see a sal for it. */
7102 char *p
= &addr_string
[3];
7107 p
= skip_spaces (p
);
7109 endp
= skip_to_space (p
);
7111 marker_str
= savestring (p
, endp
- p
);
7112 b
->static_trace_marker_id
= marker_str
;
7114 printf_filtered (_("Probed static tracepoint "
7116 b
->static_trace_marker_id
);
7118 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7120 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7121 release_static_tracepoint_marker (&marker
);
7123 printf_filtered (_("Probed static tracepoint "
7125 b
->static_trace_marker_id
);
7128 warning (_("Couldn't determine the static "
7129 "tracepoint marker to probe"));
7132 if (enabled
&& b
->pspace
->executing_startup
7133 && (b
->type
== bp_breakpoint
7134 || b
->type
== bp_hardware_breakpoint
))
7135 b
->enable_state
= bp_startup_disabled
;
7141 loc
= add_location_to_breakpoint (b
, &sal
);
7144 if (bp_loc_is_permanent (loc
))
7145 make_breakpoint_permanent (b
);
7149 char *arg
= b
->cond_string
;
7150 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7152 error (_("Garbage %s follows condition"), arg
);
7156 b
->display_canonical
= display_canonical
;
7158 b
->addr_string
= addr_string
;
7160 /* addr_string has to be used or breakpoint_re_set will delete
7163 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7165 /* Do not mention breakpoints with a negative number, but do
7166 notify observers. */
7169 observer_notify_breakpoint_created (b
);
7172 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7173 elements to fill the void space. */
7175 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7177 int i
= index_to_remove
+1;
7178 int last_index
= sal
->nelts
-1;
7180 for (;i
<= last_index
; ++i
)
7181 sal
->sals
[i
-1] = sal
->sals
[i
];
7186 /* If appropriate, obtains all sals that correspond to the same file
7187 and line as SAL, in all program spaces. Users debugging with IDEs,
7188 will want to set a breakpoint at foo.c:line, and not really care
7189 about program spaces. This is done only if SAL does not have
7190 explicit PC and has line and file information. If we got just a
7191 single expanded sal, return the original.
7193 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7194 which the name of enclosing function is different from SAL. This
7195 makes sure that if we have breakpoint originally set in template
7196 instantiation, say foo<int>(), we won't expand SAL to locations at
7197 the same line in all existing instantiations of 'foo'. */
7199 static struct symtabs_and_lines
7200 expand_line_sal_maybe (struct symtab_and_line sal
)
7202 struct symtabs_and_lines expanded
;
7203 CORE_ADDR original_pc
= sal
.pc
;
7204 char *original_function
= NULL
;
7207 struct cleanup
*old_chain
;
7209 /* If we have explicit pc, don't expand.
7210 If we have no line number, we can't expand. */
7211 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7214 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7215 expanded
.sals
[0] = sal
;
7221 old_chain
= save_current_space_and_thread ();
7223 switch_to_program_space_and_thread (sal
.pspace
);
7225 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7227 /* Note that expand_line_sal visits *all* program spaces. */
7228 expanded
= expand_line_sal (sal
);
7230 if (expanded
.nelts
== 1)
7232 /* We had one sal, we got one sal. Return that sal, adjusting it
7233 past the function prologue if necessary. */
7234 xfree (expanded
.sals
);
7236 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7237 sal
.pc
= original_pc
;
7238 expanded
.sals
[0] = sal
;
7239 skip_prologue_sal (&expanded
.sals
[0]);
7240 do_cleanups (old_chain
);
7244 if (!sal
.explicit_line
)
7246 CORE_ADDR func_addr
, func_end
;
7247 for (i
= 0; i
< expanded
.nelts
; ++i
)
7249 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7250 char *this_function
;
7252 /* We need to switch threads as well since we're about to
7254 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7256 if (find_pc_partial_function (pc
, &this_function
,
7257 &func_addr
, &func_end
))
7260 && strcmp (this_function
, original_function
) != 0)
7262 remove_sal (&expanded
, i
);
7269 /* Skip the function prologue if necessary. */
7270 for (i
= 0; i
< expanded
.nelts
; ++i
)
7271 skip_prologue_sal (&expanded
.sals
[i
]);
7273 do_cleanups (old_chain
);
7275 if (expanded
.nelts
<= 1)
7277 /* This is an ugly workaround. If we get zero expanded sals
7278 then something is really wrong. Fix that by returning the
7281 xfree (expanded
.sals
);
7283 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7284 sal
.pc
= original_pc
;
7285 expanded
.sals
[0] = sal
;
7292 for (i
= 0; i
< expanded
.nelts
; ++i
)
7293 if (expanded
.sals
[i
].pc
== original_pc
)
7304 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7305 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7306 value. COND_STRING, if not NULL, specified the condition to be
7307 used for all breakpoints. Essentially the only case where
7308 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7309 function. In that case, it's still not possible to specify
7310 separate conditions for different overloaded functions, so
7311 we take just a single condition string.
7313 NOTE: If the function succeeds, the caller is expected to cleanup
7314 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7315 array contents). If the function fails (error() is called), the
7316 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7317 COND and SALS arrays and each of those arrays contents. */
7320 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7321 struct symtabs_and_lines sals
,
7322 struct linespec_result
*canonical
,
7324 enum bptype type
, enum bpdisp disposition
,
7325 int thread
, int task
, int ignore_count
,
7326 struct breakpoint_ops
*ops
, int from_tty
,
7327 int enabled
, int internal
)
7331 for (i
= 0; i
< sals
.nelts
; ++i
)
7333 struct symtabs_and_lines expanded
=
7334 expand_line_sal_maybe (sals
.sals
[i
]);
7336 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7337 cond_string
, type
, disposition
,
7338 thread
, task
, ignore_count
, ops
,
7339 from_tty
, enabled
, internal
,
7340 canonical
->special_display
);
7344 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7345 followed by conditionals. On return, SALS contains an array of SAL
7346 addresses found. ADDR_STRING contains a vector of (canonical)
7347 address strings. ADDRESS points to the end of the SAL.
7349 The array and the line spec strings are allocated on the heap, it is
7350 the caller's responsibility to free them. */
7353 parse_breakpoint_sals (char **address
,
7354 struct symtabs_and_lines
*sals
,
7355 struct linespec_result
*canonical
)
7357 char *addr_start
= *address
;
7359 /* If no arg given, or if first arg is 'if ', use the default
7361 if ((*address
) == NULL
7362 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7364 if (default_breakpoint_valid
)
7366 struct symtab_and_line sal
;
7368 init_sal (&sal
); /* Initialize to zeroes. */
7369 sals
->sals
= (struct symtab_and_line
*)
7370 xmalloc (sizeof (struct symtab_and_line
));
7371 sal
.pc
= default_breakpoint_address
;
7372 sal
.line
= default_breakpoint_line
;
7373 sal
.symtab
= default_breakpoint_symtab
;
7374 sal
.pspace
= default_breakpoint_pspace
;
7375 sal
.section
= find_pc_overlay (sal
.pc
);
7377 /* "break" without arguments is equivalent to "break *PC"
7378 where PC is the default_breakpoint_address. So make sure
7379 to set sal.explicit_pc to prevent GDB from trying to
7380 expand the list of sals to include all other instances
7381 with the same symtab and line. */
7382 sal
.explicit_pc
= 1;
7384 sals
->sals
[0] = sal
;
7388 error (_("No default breakpoint address now."));
7392 /* Force almost all breakpoints to be in terms of the
7393 current_source_symtab (which is decode_line_1's default).
7394 This should produce the results we want almost all of the
7395 time while leaving default_breakpoint_* alone.
7397 ObjC: However, don't match an Objective-C method name which
7398 may have a '+' or '-' succeeded by a '[' */
7400 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7402 if (default_breakpoint_valid
7404 || ((strchr ("+-", (*address
)[0]) != NULL
)
7405 && ((*address
)[1] != '['))))
7406 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7407 default_breakpoint_line
, canonical
);
7409 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7412 /* For any SAL that didn't have a canonical string, fill one in. */
7413 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7414 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7415 if (addr_start
!= (*address
))
7419 for (i
= 0; i
< sals
->nelts
; i
++)
7421 /* Add the string if not present. */
7422 if (canonical
->canonical
[i
] == NULL
)
7423 canonical
->canonical
[i
] = savestring (addr_start
,
7424 (*address
) - addr_start
);
7430 /* Convert each SAL into a real PC. Verify that the PC can be
7431 inserted as a breakpoint. If it can't throw an error. */
7434 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7438 for (i
= 0; i
< sals
->nelts
; i
++)
7439 resolve_sal_pc (&sals
->sals
[i
]);
7442 /* Fast tracepoints may have restrictions on valid locations. For
7443 instance, a fast tracepoint using a jump instead of a trap will
7444 likely have to overwrite more bytes than a trap would, and so can
7445 only be placed where the instruction is longer than the jump, or a
7446 multi-instruction sequence does not have a jump into the middle of
7450 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7451 struct symtabs_and_lines
*sals
)
7454 struct symtab_and_line
*sal
;
7456 struct cleanup
*old_chain
;
7458 for (i
= 0; i
< sals
->nelts
; i
++)
7460 sal
= &sals
->sals
[i
];
7462 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7464 old_chain
= make_cleanup (xfree
, msg
);
7467 error (_("May not have a fast tracepoint at 0x%s%s"),
7468 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7470 do_cleanups (old_chain
);
7474 /* Given TOK, a string specification of condition and thread, as
7475 accepted by the 'break' command, extract the condition
7476 string and thread number and set *COND_STRING and *THREAD.
7477 PC identifies the context at which the condition should be parsed.
7478 If no condition is found, *COND_STRING is set to NULL.
7479 If no thread is found, *THREAD is set to -1. */
7481 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7482 char **cond_string
, int *thread
, int *task
)
7484 *cond_string
= NULL
;
7490 char *cond_start
= NULL
;
7491 char *cond_end
= NULL
;
7493 tok
= skip_spaces (tok
);
7495 end_tok
= skip_to_space (tok
);
7497 toklen
= end_tok
- tok
;
7499 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7501 struct expression
*expr
;
7503 tok
= cond_start
= end_tok
+ 1;
7504 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7507 *cond_string
= savestring (cond_start
,
7508 cond_end
- cond_start
);
7510 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7516 *thread
= strtol (tok
, &tok
, 0);
7518 error (_("Junk after thread keyword."));
7519 if (!valid_thread_id (*thread
))
7520 error (_("Unknown thread %d."), *thread
);
7522 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7528 *task
= strtol (tok
, &tok
, 0);
7530 error (_("Junk after task keyword."));
7531 if (!valid_task_id (*task
))
7532 error (_("Unknown task %d."), *task
);
7535 error (_("Junk at end of arguments."));
7539 /* Decode a static tracepoint marker spec. */
7541 static struct symtabs_and_lines
7542 decode_static_tracepoint_spec (char **arg_p
)
7544 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7545 struct symtabs_and_lines sals
;
7546 struct symtab_and_line sal
;
7548 struct cleanup
*old_chain
;
7549 char *p
= &(*arg_p
)[3];
7554 p
= skip_spaces (p
);
7556 endp
= skip_to_space (p
);
7558 marker_str
= savestring (p
, endp
- p
);
7559 old_chain
= make_cleanup (xfree
, marker_str
);
7561 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7562 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7563 error (_("No known static tracepoint marker named %s"), marker_str
);
7565 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7566 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7568 for (i
= 0; i
< sals
.nelts
; i
++)
7570 struct static_tracepoint_marker
*marker
;
7572 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7574 init_sal (&sals
.sals
[i
]);
7576 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7577 sals
.sals
[i
].pc
= marker
->address
;
7579 release_static_tracepoint_marker (marker
);
7582 do_cleanups (old_chain
);
7588 /* Set a breakpoint. This function is shared between CLI and MI
7589 functions for setting a breakpoint. This function has two major
7590 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7591 parameter. If non-zero, the function will parse arg, extracting
7592 breakpoint location, address and thread. Otherwise, ARG is just
7593 the location of breakpoint, with condition and thread specified by
7594 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7595 the breakpoint number will be allocated from the internal
7596 breakpoint count. Returns true if any breakpoint was created;
7600 create_breakpoint (struct gdbarch
*gdbarch
,
7601 char *arg
, char *cond_string
, int thread
,
7602 int parse_condition_and_thread
,
7603 int tempflag
, enum bptype type_wanted
,
7605 enum auto_boolean pending_break_support
,
7606 struct breakpoint_ops
*ops
,
7607 int from_tty
, int enabled
, int internal
)
7609 volatile struct gdb_exception e
;
7610 struct symtabs_and_lines sals
;
7611 struct symtab_and_line pending_sal
;
7613 char *addr_start
= arg
;
7614 struct linespec_result canonical
;
7615 struct cleanup
*old_chain
;
7616 struct cleanup
*bkpt_chain
= NULL
;
7620 int prev_bkpt_count
= breakpoint_count
;
7622 gdb_assert (ops
!= NULL
);
7626 init_linespec_result (&canonical
);
7628 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7632 sals
= decode_static_tracepoint_spec (&arg
);
7634 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7635 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7636 for (i
= 0; i
< sals
.nelts
; i
++)
7637 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7641 TRY_CATCH (e
, RETURN_MASK_ALL
)
7643 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7646 /* If caller is interested in rc value from parse, set value. */
7650 throw_exception (e
);
7654 case NOT_FOUND_ERROR
:
7656 /* If pending breakpoint support is turned off, throw
7659 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7660 throw_exception (e
);
7662 exception_print (gdb_stderr
, e
);
7664 /* If pending breakpoint support is auto query and the user
7665 selects no, then simply return the error code. */
7666 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7667 && !nquery (_("Make breakpoint pending on "
7668 "future shared library load? ")))
7671 /* At this point, either the user was queried about setting
7672 a pending breakpoint and selected yes, or pending
7673 breakpoint behavior is on and thus a pending breakpoint
7674 is defaulted on behalf of the user. */
7675 copy_arg
= xstrdup (addr_start
);
7676 canonical
.canonical
= ©_arg
;
7678 sals
.sals
= &pending_sal
;
7683 throw_exception (e
);
7693 /* Create a chain of things that always need to be cleaned up. */
7694 old_chain
= make_cleanup (null_cleanup
, 0);
7698 /* Make sure that all storage allocated to SALS gets freed. */
7699 make_cleanup (xfree
, sals
.sals
);
7701 /* Cleanup the canonical array but not its contents. */
7702 make_cleanup (xfree
, canonical
.canonical
);
7705 /* ----------------------------- SNIP -----------------------------
7706 Anything added to the cleanup chain beyond this point is assumed
7707 to be part of a breakpoint. If the breakpoint create succeeds
7708 then the memory is not reclaimed. */
7709 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7711 /* Mark the contents of the canonical for cleanup. These go on
7712 the bkpt_chain and only occur if the breakpoint create fails. */
7713 for (i
= 0; i
< sals
.nelts
; i
++)
7715 if (canonical
.canonical
[i
] != NULL
)
7716 make_cleanup (xfree
, canonical
.canonical
[i
]);
7719 /* Resolve all line numbers to PC's and verify that the addresses
7720 are ok for the target. */
7722 breakpoint_sals_to_pc (&sals
);
7724 /* Fast tracepoints may have additional restrictions on location. */
7725 if (type_wanted
== bp_fast_tracepoint
)
7726 check_fast_tracepoint_sals (gdbarch
, &sals
);
7728 /* Verify that condition can be parsed, before setting any
7729 breakpoints. Allocate a separate condition expression for each
7733 if (parse_condition_and_thread
)
7735 /* Here we only parse 'arg' to separate condition
7736 from thread number, so parsing in context of first
7737 sal is OK. When setting the breakpoint we'll
7738 re-parse it in context of each sal. */
7741 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7744 make_cleanup (xfree
, cond_string
);
7748 /* Create a private copy of condition string. */
7751 cond_string
= xstrdup (cond_string
);
7752 make_cleanup (xfree
, cond_string
);
7756 /* If the user is creating a static tracepoint by marker id
7757 (strace -m MARKER_ID), then store the sals index, so that
7758 breakpoint_re_set can try to match up which of the newly
7759 found markers corresponds to this one, and, don't try to
7760 expand multiple locations for each sal, given than SALS
7761 already should contain all sals for MARKER_ID. */
7762 if (type_wanted
== bp_static_tracepoint
7763 && is_marker_spec (canonical
.canonical
[0]))
7767 for (i
= 0; i
< sals
.nelts
; ++i
)
7769 struct symtabs_and_lines expanded
;
7770 struct breakpoint
*tp
;
7771 struct cleanup
*old_chain
;
7774 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7775 expanded
.sals
[0] = sals
.sals
[i
];
7776 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7778 create_breakpoint_sal (gdbarch
, expanded
, canonical
.canonical
[i
],
7779 cond_string
, type_wanted
,
7780 tempflag
? disp_del
: disp_donttouch
,
7781 thread
, task
, ignore_count
, ops
,
7782 from_tty
, enabled
, internal
,
7783 canonical
.special_display
);
7785 do_cleanups (old_chain
);
7787 /* Get the tracepoint we just created. */
7789 tp
= get_breakpoint (internal_breakpoint_number
);
7791 tp
= get_breakpoint (breakpoint_count
);
7792 gdb_assert (tp
!= NULL
);
7794 /* Given that its possible to have multiple markers with
7795 the same string id, if the user is creating a static
7796 tracepoint by marker id ("strace -m MARKER_ID"), then
7797 store the sals index, so that breakpoint_re_set can
7798 try to match up which of the newly found markers
7799 corresponds to this one */
7800 tp
->static_trace_marker_id_idx
= i
;
7804 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
7806 tempflag
? disp_del
: disp_donttouch
,
7807 thread
, task
, ignore_count
, ops
, from_tty
,
7812 struct breakpoint
*b
;
7814 make_cleanup (xfree
, copy_arg
);
7816 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
, ops
);
7817 set_breakpoint_number (internal
, b
);
7819 b
->addr_string
= canonical
.canonical
[0];
7820 b
->cond_string
= NULL
;
7821 b
->ignore_count
= ignore_count
;
7822 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7823 b
->condition_not_parsed
= 1;
7824 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7825 b
->pspace
= current_program_space
;
7826 b
->py_bp_object
= NULL
;
7828 if (enabled
&& b
->pspace
->executing_startup
7829 && (b
->type
== bp_breakpoint
7830 || b
->type
== bp_hardware_breakpoint
))
7831 b
->enable_state
= bp_startup_disabled
;
7834 /* Do not mention breakpoints with a negative number,
7835 but do notify observers. */
7837 observer_notify_breakpoint_created (b
);
7842 warning (_("Multiple breakpoints were set.\nUse the "
7843 "\"delete\" command to delete unwanted breakpoints."));
7844 prev_breakpoint_count
= prev_bkpt_count
;
7847 /* That's it. Discard the cleanups for data inserted into the
7849 discard_cleanups (bkpt_chain
);
7850 /* But cleanup everything else. */
7851 do_cleanups (old_chain
);
7853 /* error call may happen here - have BKPT_CHAIN already discarded. */
7854 update_global_location_list (1);
7859 /* Set a breakpoint.
7860 ARG is a string describing breakpoint address,
7861 condition, and thread.
7862 FLAG specifies if a breakpoint is hardware on,
7863 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7867 break_command_1 (char *arg
, int flag
, int from_tty
)
7869 int tempflag
= flag
& BP_TEMPFLAG
;
7870 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7871 ? bp_hardware_breakpoint
7874 create_breakpoint (get_current_arch (),
7876 NULL
, 0, 1 /* parse arg */,
7877 tempflag
, type_wanted
,
7878 0 /* Ignore count */,
7879 pending_break_support
,
7880 &bkpt_breakpoint_ops
,
7886 /* Helper function for break_command_1 and disassemble_command. */
7889 resolve_sal_pc (struct symtab_and_line
*sal
)
7893 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7895 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7896 error (_("No line %d in file \"%s\"."),
7897 sal
->line
, sal
->symtab
->filename
);
7900 /* If this SAL corresponds to a breakpoint inserted using a line
7901 number, then skip the function prologue if necessary. */
7902 if (sal
->explicit_line
)
7903 skip_prologue_sal (sal
);
7906 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7908 struct blockvector
*bv
;
7912 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7915 sym
= block_linkage_function (b
);
7918 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7919 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7923 /* It really is worthwhile to have the section, so we'll
7924 just have to look harder. This case can be executed
7925 if we have line numbers but no functions (as can
7926 happen in assembly source). */
7928 struct minimal_symbol
*msym
;
7929 struct cleanup
*old_chain
= save_current_space_and_thread ();
7931 switch_to_program_space_and_thread (sal
->pspace
);
7933 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7935 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7937 do_cleanups (old_chain
);
7944 break_command (char *arg
, int from_tty
)
7946 break_command_1 (arg
, 0, from_tty
);
7950 tbreak_command (char *arg
, int from_tty
)
7952 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7956 hbreak_command (char *arg
, int from_tty
)
7958 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7962 thbreak_command (char *arg
, int from_tty
)
7964 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7968 stop_command (char *arg
, int from_tty
)
7970 printf_filtered (_("Specify the type of breakpoint to set.\n\
7971 Usage: stop in <function | address>\n\
7972 stop at <line>\n"));
7976 stopin_command (char *arg
, int from_tty
)
7980 if (arg
== (char *) NULL
)
7982 else if (*arg
!= '*')
7987 /* Look for a ':'. If this is a line number specification, then
7988 say it is bad, otherwise, it should be an address or
7989 function/method name. */
7990 while (*argptr
&& !hasColon
)
7992 hasColon
= (*argptr
== ':');
7997 badInput
= (*argptr
!= ':'); /* Not a class::method */
7999 badInput
= isdigit (*arg
); /* a simple line number */
8003 printf_filtered (_("Usage: stop in <function | address>\n"));
8005 break_command_1 (arg
, 0, from_tty
);
8009 stopat_command (char *arg
, int from_tty
)
8013 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8020 /* Look for a ':'. If there is a '::' then get out, otherwise
8021 it is probably a line number. */
8022 while (*argptr
&& !hasColon
)
8024 hasColon
= (*argptr
== ':');
8029 badInput
= (*argptr
== ':'); /* we have class::method */
8031 badInput
= !isdigit (*arg
); /* not a line number */
8035 printf_filtered (_("Usage: stop at <line>\n"));
8037 break_command_1 (arg
, 0, from_tty
);
8040 /* Implement the "breakpoint_hit" breakpoint_ops method for
8041 ranged breakpoints. */
8044 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8045 struct address_space
*aspace
,
8048 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8049 bl
->length
, aspace
, bp_addr
);
8052 /* Implement the "resources_needed" breakpoint_ops method for
8053 ranged breakpoints. */
8056 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8058 return target_ranged_break_num_registers ();
8061 /* Implement the "print_it" breakpoint_ops method for
8062 ranged breakpoints. */
8064 static enum print_stop_action
8065 print_it_ranged_breakpoint (bpstat bs
)
8067 struct breakpoint
*b
= bs
->breakpoint_at
;
8068 struct bp_location
*bl
= b
->loc
;
8070 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8072 /* Ranged breakpoints have only one location. */
8073 gdb_assert (bl
&& bl
->next
== NULL
);
8075 annotate_breakpoint (b
->number
);
8076 if (b
->disposition
== disp_del
)
8077 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8079 ui_out_text (uiout
, "\nRanged breakpoint ");
8080 if (ui_out_is_mi_like_p (uiout
))
8082 ui_out_field_string (uiout
, "reason",
8083 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8084 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8086 ui_out_field_int (uiout
, "bkptno", b
->number
);
8087 ui_out_text (uiout
, ", ");
8089 return PRINT_SRC_AND_LOC
;
8092 /* Implement the "print_one" breakpoint_ops method for
8093 ranged breakpoints. */
8096 print_one_ranged_breakpoint (struct breakpoint
*b
,
8097 struct bp_location
**last_loc
)
8099 struct bp_location
*bl
= b
->loc
;
8100 struct value_print_options opts
;
8102 /* Ranged breakpoints have only one location. */
8103 gdb_assert (bl
&& bl
->next
== NULL
);
8105 get_user_print_options (&opts
);
8107 if (opts
.addressprint
)
8108 /* We don't print the address range here, it will be printed later
8109 by print_one_detail_ranged_breakpoint. */
8110 ui_out_field_skip (uiout
, "addr");
8112 print_breakpoint_location (b
, bl
);
8116 /* Implement the "print_one_detail" breakpoint_ops method for
8117 ranged breakpoints. */
8120 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8121 struct ui_out
*uiout
)
8123 CORE_ADDR address_start
, address_end
;
8124 struct bp_location
*bl
= b
->loc
;
8125 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8126 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8130 address_start
= bl
->address
;
8131 address_end
= address_start
+ bl
->length
- 1;
8133 ui_out_text (uiout
, "\taddress range: ");
8134 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8135 print_core_address (bl
->gdbarch
, address_start
),
8136 print_core_address (bl
->gdbarch
, address_end
));
8137 ui_out_field_stream (uiout
, "addr", stb
);
8138 ui_out_text (uiout
, "\n");
8140 do_cleanups (cleanup
);
8143 /* Implement the "print_mention" breakpoint_ops method for
8144 ranged breakpoints. */
8147 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8149 struct bp_location
*bl
= b
->loc
;
8152 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8154 if (ui_out_is_mi_like_p (uiout
))
8157 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8158 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8159 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8162 /* Implement the "print_recreate" breakpoint_ops method for
8163 ranged breakpoints. */
8166 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8168 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8169 b
->addr_string_range_end
);
8172 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8174 static struct breakpoint_ops ranged_breakpoint_ops
=
8177 bkpt_allocate_location
,
8179 bkpt_insert_location
,
8180 bkpt_remove_location
,
8181 breakpoint_hit_ranged_breakpoint
,
8183 resources_needed_ranged_breakpoint
,
8184 null_works_in_software_mode
,
8185 print_it_ranged_breakpoint
,
8186 print_one_ranged_breakpoint
,
8187 print_one_detail_ranged_breakpoint
,
8188 print_mention_ranged_breakpoint
,
8189 print_recreate_ranged_breakpoint
8192 /* Find the address where the end of the breakpoint range should be
8193 placed, given the SAL of the end of the range. This is so that if
8194 the user provides a line number, the end of the range is set to the
8195 last instruction of the given line. */
8198 find_breakpoint_range_end (struct symtab_and_line sal
)
8202 /* If the user provided a PC value, use it. Otherwise,
8203 find the address of the end of the given location. */
8204 if (sal
.explicit_pc
)
8211 ret
= find_line_pc_range (sal
, &start
, &end
);
8213 error (_("Could not find location of the end of the range."));
8215 /* find_line_pc_range returns the start of the next line. */
8222 /* Implement the "break-range" CLI command. */
8225 break_range_command (char *arg
, int from_tty
)
8227 char *arg_start
, *addr_string_start
, *addr_string_end
;
8228 struct linespec_result canonical_start
, canonical_end
;
8229 int bp_count
, can_use_bp
, length
;
8231 struct breakpoint
*b
;
8232 struct symtab_and_line sal_start
, sal_end
;
8233 struct symtabs_and_lines sals_start
, sals_end
;
8234 struct cleanup
*cleanup_bkpt
;
8236 /* We don't support software ranged breakpoints. */
8237 if (target_ranged_break_num_registers () < 0)
8238 error (_("This target does not support hardware ranged breakpoints."));
8240 bp_count
= hw_breakpoint_used_count ();
8241 bp_count
+= target_ranged_break_num_registers ();
8242 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8245 error (_("Hardware breakpoints used exceeds limit."));
8247 if (arg
== NULL
|| arg
[0] == '\0')
8248 error(_("No address range specified."));
8250 sals_start
.sals
= NULL
;
8251 sals_start
.nelts
= 0;
8252 init_linespec_result (&canonical_start
);
8254 while (*arg
== ' ' || *arg
== '\t')
8257 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8259 sal_start
= sals_start
.sals
[0];
8260 addr_string_start
= canonical_start
.canonical
[0];
8261 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8262 xfree (sals_start
.sals
);
8263 xfree (canonical_start
.canonical
);
8266 error (_("Too few arguments."));
8267 else if (sals_start
.nelts
== 0)
8268 error (_("Could not find location of the beginning of the range."));
8269 else if (sals_start
.nelts
!= 1)
8270 error (_("Cannot create a ranged breakpoint with multiple locations."));
8272 resolve_sal_pc (&sal_start
);
8274 arg
++; /* Skip the comma. */
8275 while (*arg
== ' ' || *arg
== '\t')
8278 /* Parse the end location. */
8280 sals_end
.sals
= NULL
;
8282 init_linespec_result (&canonical_end
);
8285 /* We call decode_line_1 directly here instead of using
8286 parse_breakpoint_sals because we need to specify the start location's
8287 symtab and line as the default symtab and line for the end of the
8288 range. This makes it possible to have ranges like "foo.c:27, +14",
8289 where +14 means 14 lines from the start location. */
8290 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8293 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8294 if (canonical_end
.canonical
== NULL
)
8295 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8296 /* Add the string if not present. */
8297 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8298 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8300 sal_end
= sals_end
.sals
[0];
8301 addr_string_end
= canonical_end
.canonical
[0];
8302 make_cleanup (xfree
, addr_string_end
);
8303 xfree (sals_end
.sals
);
8304 xfree (canonical_end
.canonical
);
8306 if (sals_end
.nelts
== 0)
8307 error (_("Could not find location of the end of the range."));
8308 else if (sals_end
.nelts
!= 1)
8309 error (_("Cannot create a ranged breakpoint with multiple locations."));
8311 resolve_sal_pc (&sal_end
);
8313 end
= find_breakpoint_range_end (sal_end
);
8314 if (sal_start
.pc
> end
)
8315 error (_("Invalid address range, end precedes start."));
8317 length
= end
- sal_start
.pc
+ 1;
8319 /* Length overflowed. */
8320 error (_("Address range too large."));
8321 else if (length
== 1)
8323 /* This range is simple enough to be handled by
8324 the `hbreak' command. */
8325 hbreak_command (addr_string_start
, 1);
8327 do_cleanups (cleanup_bkpt
);
8332 /* Now set up the breakpoint. */
8333 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8334 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8335 set_breakpoint_count (breakpoint_count
+ 1);
8336 b
->number
= breakpoint_count
;
8337 b
->disposition
= disp_donttouch
;
8338 b
->addr_string
= addr_string_start
;
8339 b
->addr_string_range_end
= addr_string_end
;
8340 b
->loc
->length
= length
;
8342 discard_cleanups (cleanup_bkpt
);
8345 observer_notify_breakpoint_created (b
);
8346 update_global_location_list (1);
8349 /* Return non-zero if EXP is verified as constant. Returned zero
8350 means EXP is variable. Also the constant detection may fail for
8351 some constant expressions and in such case still falsely return
8354 watchpoint_exp_is_const (const struct expression
*exp
)
8362 /* We are only interested in the descriptor of each element. */
8363 operator_length (exp
, i
, &oplenp
, &argsp
);
8366 switch (exp
->elts
[i
].opcode
)
8376 case BINOP_LOGICAL_AND
:
8377 case BINOP_LOGICAL_OR
:
8378 case BINOP_BITWISE_AND
:
8379 case BINOP_BITWISE_IOR
:
8380 case BINOP_BITWISE_XOR
:
8382 case BINOP_NOTEQUAL
:
8398 case TERNOP_SLICE_COUNT
:
8410 case OP_OBJC_NSSTRING
:
8413 case UNOP_LOGICAL_NOT
:
8414 case UNOP_COMPLEMENT
:
8417 /* Unary, binary and ternary operators: We have to check
8418 their operands. If they are constant, then so is the
8419 result of that operation. For instance, if A and B are
8420 determined to be constants, then so is "A + B".
8422 UNOP_IND is one exception to the rule above, because the
8423 value of *ADDR is not necessarily a constant, even when
8428 /* Check whether the associated symbol is a constant.
8430 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8431 possible that a buggy compiler could mark a variable as
8432 constant even when it is not, and TYPE_CONST would return
8433 true in this case, while SYMBOL_CLASS wouldn't.
8435 We also have to check for function symbols because they
8436 are always constant. */
8438 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8440 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8441 && SYMBOL_CLASS (s
) != LOC_CONST
8442 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8447 /* The default action is to return 0 because we are using
8448 the optimistic approach here: If we don't know something,
8449 then it is not a constant. */
8458 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8461 re_set_watchpoint (struct breakpoint
*b
)
8463 /* Watchpoint can be either on expression using entirely global
8464 variables, or it can be on local variables.
8466 Watchpoints of the first kind are never auto-deleted, and even
8467 persist across program restarts. Since they can use variables
8468 from shared libraries, we need to reparse expression as libraries
8469 are loaded and unloaded.
8471 Watchpoints on local variables can also change meaning as result
8472 of solib event. For example, if a watchpoint uses both a local
8473 and a global variables in expression, it's a local watchpoint,
8474 but unloading of a shared library will make the expression
8475 invalid. This is not a very common use case, but we still
8476 re-evaluate expression, to avoid surprises to the user.
8478 Note that for local watchpoints, we re-evaluate it only if
8479 watchpoints frame id is still valid. If it's not, it means the
8480 watchpoint is out of scope and will be deleted soon. In fact,
8481 I'm not sure we'll ever be called in this case.
8483 If a local watchpoint's frame id is still valid, then
8484 b->exp_valid_block is likewise valid, and we can safely use it.
8486 Don't do anything about disabled watchpoints, since they will
8487 be reevaluated again when enabled. */
8488 update_watchpoint (b
, 1 /* reparse */);
8491 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8494 insert_watchpoint (struct bp_location
*bl
)
8496 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8498 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8499 bl
->owner
->cond_exp
);
8502 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8505 remove_watchpoint (struct bp_location
*bl
)
8507 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8509 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8510 bl
->owner
->cond_exp
);
8514 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8515 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8517 struct breakpoint
*b
= bl
->owner
;
8519 /* Continuable hardware watchpoints are treated as non-existent if the
8520 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8521 some data address). Otherwise gdb won't stop on a break instruction
8522 in the code (not from a breakpoint) when a hardware watchpoint has
8523 been defined. Also skip watchpoints which we know did not trigger
8524 (did not match the data address). */
8525 if (is_hardware_watchpoint (b
)
8526 && b
->watchpoint_triggered
== watch_triggered_no
)
8533 check_status_watchpoint (bpstat bs
)
8535 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8537 bpstat_check_watchpoint (bs
);
8540 /* Implement the "resources_needed" breakpoint_ops method for
8541 hardware watchpoints. */
8544 resources_needed_watchpoint (const struct bp_location
*bl
)
8546 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8548 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8551 /* Implement the "works_in_software_mode" breakpoint_ops method for
8552 hardware watchpoints. */
8555 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8557 return b
->type
== bp_hardware_watchpoint
;
8560 static enum print_stop_action
8561 print_it_watchpoint (bpstat bs
)
8563 struct cleanup
*old_chain
;
8564 struct breakpoint
*b
;
8565 const struct bp_location
*bl
;
8566 struct ui_stream
*stb
;
8567 enum print_stop_action result
;
8569 gdb_assert (bs
->bp_location_at
!= NULL
);
8571 bl
= bs
->bp_location_at
;
8572 b
= bs
->breakpoint_at
;
8574 stb
= ui_out_stream_new (uiout
);
8575 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8580 case bp_hardware_watchpoint
:
8581 annotate_watchpoint (b
->number
);
8582 if (ui_out_is_mi_like_p (uiout
))
8585 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8587 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8588 ui_out_text (uiout
, "\nOld value = ");
8589 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8590 ui_out_field_stream (uiout
, "old", stb
);
8591 ui_out_text (uiout
, "\nNew value = ");
8592 watchpoint_value_print (b
->val
, stb
->stream
);
8593 ui_out_field_stream (uiout
, "new", stb
);
8594 ui_out_text (uiout
, "\n");
8595 /* More than one watchpoint may have been triggered. */
8596 result
= PRINT_UNKNOWN
;
8599 case bp_read_watchpoint
:
8600 if (ui_out_is_mi_like_p (uiout
))
8603 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8605 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8606 ui_out_text (uiout
, "\nValue = ");
8607 watchpoint_value_print (b
->val
, stb
->stream
);
8608 ui_out_field_stream (uiout
, "value", stb
);
8609 ui_out_text (uiout
, "\n");
8610 result
= PRINT_UNKNOWN
;
8613 case bp_access_watchpoint
:
8614 if (bs
->old_val
!= NULL
)
8616 annotate_watchpoint (b
->number
);
8617 if (ui_out_is_mi_like_p (uiout
))
8620 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8622 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8623 ui_out_text (uiout
, "\nOld value = ");
8624 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8625 ui_out_field_stream (uiout
, "old", stb
);
8626 ui_out_text (uiout
, "\nNew value = ");
8631 if (ui_out_is_mi_like_p (uiout
))
8634 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8635 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8636 ui_out_text (uiout
, "\nValue = ");
8638 watchpoint_value_print (b
->val
, stb
->stream
);
8639 ui_out_field_stream (uiout
, "new", stb
);
8640 ui_out_text (uiout
, "\n");
8641 result
= PRINT_UNKNOWN
;
8644 result
= PRINT_UNKNOWN
;
8647 do_cleanups (old_chain
);
8651 /* Implement the "print_mention" breakpoint_ops method for hardware
8655 print_mention_watchpoint (struct breakpoint
*b
)
8657 struct cleanup
*ui_out_chain
;
8662 ui_out_text (uiout
, "Watchpoint ");
8663 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8665 case bp_hardware_watchpoint
:
8666 ui_out_text (uiout
, "Hardware watchpoint ");
8667 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8669 case bp_read_watchpoint
:
8670 ui_out_text (uiout
, "Hardware read watchpoint ");
8671 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8673 case bp_access_watchpoint
:
8674 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8675 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8678 internal_error (__FILE__
, __LINE__
,
8679 _("Invalid hardware watchpoint type."));
8682 ui_out_field_int (uiout
, "number", b
->number
);
8683 ui_out_text (uiout
, ": ");
8684 ui_out_field_string (uiout
, "exp", b
->exp_string
);
8685 do_cleanups (ui_out_chain
);
8688 /* Implement the "print_recreate" breakpoint_ops method for
8692 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8697 case bp_hardware_watchpoint
:
8698 fprintf_unfiltered (fp
, "watch");
8700 case bp_read_watchpoint
:
8701 fprintf_unfiltered (fp
, "rwatch");
8703 case bp_access_watchpoint
:
8704 fprintf_unfiltered (fp
, "awatch");
8707 internal_error (__FILE__
, __LINE__
,
8708 _("Invalid watchpoint type."));
8711 fprintf_unfiltered (fp
, " %s", b
->exp_string
);
8714 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8716 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8719 bkpt_allocate_location
,
8723 breakpoint_hit_watchpoint
,
8724 check_status_watchpoint
,
8725 resources_needed_watchpoint
,
8726 works_in_software_mode_watchpoint
,
8727 print_it_watchpoint
,
8728 NULL
, /* print_one */
8729 null_print_one_detail
,
8730 print_mention_watchpoint
,
8731 print_recreate_watchpoint
8734 /* Implement the "insert" breakpoint_ops method for
8735 masked hardware watchpoints. */
8738 insert_masked_watchpoint (struct bp_location
*bl
)
8740 return target_insert_mask_watchpoint (bl
->address
, bl
->owner
->hw_wp_mask
,
8741 bl
->watchpoint_type
);
8744 /* Implement the "remove" breakpoint_ops method for
8745 masked hardware watchpoints. */
8748 remove_masked_watchpoint (struct bp_location
*bl
)
8750 return target_remove_mask_watchpoint (bl
->address
, bl
->owner
->hw_wp_mask
,
8751 bl
->watchpoint_type
);
8754 /* Implement the "resources_needed" breakpoint_ops method for
8755 masked hardware watchpoints. */
8758 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8760 return target_masked_watch_num_registers (bl
->address
,
8761 bl
->owner
->hw_wp_mask
);
8764 /* Implement the "works_in_software_mode" breakpoint_ops method for
8765 masked hardware watchpoints. */
8768 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8773 /* Implement the "print_it" breakpoint_ops method for
8774 masked hardware watchpoints. */
8776 static enum print_stop_action
8777 print_it_masked_watchpoint (bpstat bs
)
8779 struct breakpoint
*b
= bs
->breakpoint_at
;
8781 /* Masked watchpoints have only one location. */
8782 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8786 case bp_hardware_watchpoint
:
8787 annotate_watchpoint (b
->number
);
8788 if (ui_out_is_mi_like_p (uiout
))
8791 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8794 case bp_read_watchpoint
:
8795 if (ui_out_is_mi_like_p (uiout
))
8798 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8801 case bp_access_watchpoint
:
8802 if (ui_out_is_mi_like_p (uiout
))
8805 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8808 internal_error (__FILE__
, __LINE__
,
8809 _("Invalid hardware watchpoint type."));
8813 ui_out_text (uiout
, _("\n\
8814 Check the underlying instruction at PC for the memory\n\
8815 address and value which triggered this watchpoint.\n"));
8816 ui_out_text (uiout
, "\n");
8818 /* More than one watchpoint may have been triggered. */
8819 return PRINT_UNKNOWN
;
8822 /* Implement the "print_one_detail" breakpoint_ops method for
8823 masked hardware watchpoints. */
8826 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8827 struct ui_out
*uiout
)
8829 /* Masked watchpoints have only one location. */
8830 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8832 ui_out_text (uiout
, "\tmask ");
8833 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, b
->hw_wp_mask
);
8834 ui_out_text (uiout
, "\n");
8837 /* Implement the "print_mention" breakpoint_ops method for
8838 masked hardware watchpoints. */
8841 print_mention_masked_watchpoint (struct breakpoint
*b
)
8843 struct cleanup
*ui_out_chain
;
8847 case bp_hardware_watchpoint
:
8848 ui_out_text (uiout
, "Masked hardware watchpoint ");
8849 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8851 case bp_read_watchpoint
:
8852 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8853 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8855 case bp_access_watchpoint
:
8856 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8857 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8860 internal_error (__FILE__
, __LINE__
,
8861 _("Invalid hardware watchpoint type."));
8864 ui_out_field_int (uiout
, "number", b
->number
);
8865 ui_out_text (uiout
, ": ");
8866 ui_out_field_string (uiout
, "exp", b
->exp_string
);
8867 do_cleanups (ui_out_chain
);
8870 /* Implement the "print_recreate" breakpoint_ops method for
8871 masked hardware watchpoints. */
8874 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8880 case bp_hardware_watchpoint
:
8881 fprintf_unfiltered (fp
, "watch");
8883 case bp_read_watchpoint
:
8884 fprintf_unfiltered (fp
, "rwatch");
8886 case bp_access_watchpoint
:
8887 fprintf_unfiltered (fp
, "awatch");
8890 internal_error (__FILE__
, __LINE__
,
8891 _("Invalid hardware watchpoint type."));
8894 sprintf_vma (tmp
, b
->hw_wp_mask
);
8895 fprintf_unfiltered (fp
, " %s mask 0x%s", b
->exp_string
, tmp
);
8898 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
8900 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
=
8903 bkpt_allocate_location
,
8905 insert_masked_watchpoint
,
8906 remove_masked_watchpoint
,
8907 breakpoint_hit_watchpoint
,
8908 check_status_watchpoint
,
8909 resources_needed_masked_watchpoint
,
8910 works_in_software_mode_masked_watchpoint
,
8911 print_it_masked_watchpoint
,
8912 NULL
, /* print_one */
8913 print_one_detail_masked_watchpoint
,
8914 print_mention_masked_watchpoint
,
8915 print_recreate_masked_watchpoint
8918 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
8921 is_masked_watchpoint (const struct breakpoint
*b
)
8923 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
8926 /* accessflag: hw_write: watch write,
8927 hw_read: watch read,
8928 hw_access: watch access (read or write) */
8930 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8931 int just_location
, int internal
)
8933 volatile struct gdb_exception e
;
8934 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8935 struct expression
*exp
;
8936 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8937 struct value
*val
, *mark
, *result
;
8938 struct frame_info
*frame
;
8939 char *exp_start
= NULL
;
8940 char *exp_end
= NULL
;
8941 char *tok
, *end_tok
;
8943 char *cond_start
= NULL
;
8944 char *cond_end
= NULL
;
8945 enum bptype bp_type
;
8948 /* Flag to indicate whether we are going to use masks for
8949 the hardware watchpoint. */
8953 /* Make sure that we actually have parameters to parse. */
8954 if (arg
!= NULL
&& arg
[0] != '\0')
8958 /* Look for "parameter value" pairs at the end
8959 of the arguments string. */
8960 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
8962 /* Skip whitespace at the end of the argument list. */
8963 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8966 /* Find the beginning of the last token.
8967 This is the value of the parameter. */
8968 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8970 value_start
= tok
+ 1;
8972 /* Skip whitespace. */
8973 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8978 /* Find the beginning of the second to last token.
8979 This is the parameter itself. */
8980 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8983 toklen
= end_tok
- tok
+ 1;
8985 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
8987 /* At this point we've found a "thread" token, which means
8988 the user is trying to set a watchpoint that triggers
8989 only in a specific thread. */
8993 error(_("You can specify only one thread."));
8995 /* Extract the thread ID from the next token. */
8996 thread
= strtol (value_start
, &endp
, 0);
8998 /* Check if the user provided a valid numeric value for the
9000 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9001 error (_("Invalid thread ID specification %s."), value_start
);
9003 /* Check if the thread actually exists. */
9004 if (!valid_thread_id (thread
))
9005 error (_("Unknown thread %d."), thread
);
9007 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9009 /* We've found a "mask" token, which means the user wants to
9010 create a hardware watchpoint that is going to have the mask
9012 struct value
*mask_value
, *mark
;
9015 error(_("You can specify only one mask."));
9017 use_mask
= just_location
= 1;
9019 mark
= value_mark ();
9020 mask_value
= parse_to_comma_and_eval (&value_start
);
9021 mask
= value_as_address (mask_value
);
9022 value_free_to_mark (mark
);
9025 /* We didn't recognize what we found. We should stop here. */
9028 /* Truncate the string and get rid of the "parameter value" pair before
9029 the arguments string is parsed by the parse_exp_1 function. */
9034 /* Parse the rest of the arguments. */
9035 innermost_block
= NULL
;
9037 exp
= parse_exp_1 (&arg
, 0, 0);
9039 /* Remove trailing whitespace from the expression before saving it.
9040 This makes the eventual display of the expression string a bit
9042 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9045 /* Checking if the expression is not constant. */
9046 if (watchpoint_exp_is_const (exp
))
9050 len
= exp_end
- exp_start
;
9051 while (len
> 0 && isspace (exp_start
[len
- 1]))
9053 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9056 exp_valid_block
= innermost_block
;
9057 mark
= value_mark ();
9058 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9064 exp_valid_block
= NULL
;
9065 val
= value_addr (result
);
9066 release_value (val
);
9067 value_free_to_mark (mark
);
9071 ret
= target_masked_watch_num_registers (value_as_address (val
),
9074 error (_("This target does not support masked watchpoints."));
9076 error (_("Invalid mask or memory region."));
9079 else if (val
!= NULL
)
9080 release_value (val
);
9082 tok
= skip_spaces (arg
);
9083 end_tok
= skip_to_space (tok
);
9085 toklen
= end_tok
- tok
;
9086 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9088 struct expression
*cond
;
9090 innermost_block
= NULL
;
9091 tok
= cond_start
= end_tok
+ 1;
9092 cond
= parse_exp_1 (&tok
, 0, 0);
9094 /* The watchpoint expression may not be local, but the condition
9095 may still be. E.g.: `watch global if local > 0'. */
9096 cond_exp_valid_block
= innermost_block
;
9102 error (_("Junk at end of command."));
9104 if (accessflag
== hw_read
)
9105 bp_type
= bp_read_watchpoint
;
9106 else if (accessflag
== hw_access
)
9107 bp_type
= bp_access_watchpoint
;
9109 bp_type
= bp_hardware_watchpoint
;
9111 frame
= block_innermost_frame (exp_valid_block
);
9113 /* If the expression is "local", then set up a "watchpoint scope"
9114 breakpoint at the point where we've left the scope of the watchpoint
9115 expression. Create the scope breakpoint before the watchpoint, so
9116 that we will encounter it first in bpstat_stop_status. */
9117 if (exp_valid_block
&& frame
)
9119 if (frame_id_p (frame_unwind_caller_id (frame
)))
9122 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9123 frame_unwind_caller_pc (frame
),
9124 bp_watchpoint_scope
);
9126 scope_breakpoint
->enable_state
= bp_enabled
;
9128 /* Automatically delete the breakpoint when it hits. */
9129 scope_breakpoint
->disposition
= disp_del
;
9131 /* Only break in the proper frame (help with recursion). */
9132 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9134 /* Set the address at which we will stop. */
9135 scope_breakpoint
->loc
->gdbarch
9136 = frame_unwind_caller_arch (frame
);
9137 scope_breakpoint
->loc
->requested_address
9138 = frame_unwind_caller_pc (frame
);
9139 scope_breakpoint
->loc
->address
9140 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9141 scope_breakpoint
->loc
->requested_address
,
9142 scope_breakpoint
->type
);
9146 /* Now set up the breakpoint. */
9148 b
= set_raw_breakpoint_without_location (NULL
, bp_type
,
9149 &masked_watchpoint_breakpoint_ops
);
9151 b
= set_raw_breakpoint_without_location (NULL
, bp_type
,
9152 &watchpoint_breakpoint_ops
);
9154 b
->disposition
= disp_donttouch
;
9156 b
->exp_valid_block
= exp_valid_block
;
9157 b
->cond_exp_valid_block
= cond_exp_valid_block
;
9158 b
->pspace
= current_program_space
;
9161 struct type
*t
= value_type (val
);
9162 CORE_ADDR addr
= value_as_address (val
);
9165 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9166 name
= type_to_string (t
);
9168 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9169 core_addr_to_string (addr
));
9172 b
->exp_string
= xstrprintf ("-location %.*s",
9173 (int) (exp_end
- exp_start
), exp_start
);
9175 /* The above expression is in C. */
9176 b
->language
= language_c
;
9179 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9183 b
->hw_wp_mask
= mask
;
9192 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9198 b
->watchpoint_frame
= get_frame_id (frame
);
9199 b
->watchpoint_thread
= inferior_ptid
;
9203 b
->watchpoint_frame
= null_frame_id
;
9204 b
->watchpoint_thread
= null_ptid
;
9207 if (scope_breakpoint
!= NULL
)
9209 /* The scope breakpoint is related to the watchpoint. We will
9210 need to act on them together. */
9211 b
->related_breakpoint
= scope_breakpoint
;
9212 scope_breakpoint
->related_breakpoint
= b
;
9216 value_free_to_mark (mark
);
9218 TRY_CATCH (e
, RETURN_MASK_ALL
)
9220 /* Finally update the new watchpoint. This creates the locations
9221 that should be inserted. */
9222 update_watchpoint (b
, 1);
9226 delete_breakpoint (b
);
9227 throw_exception (e
);
9230 set_breakpoint_number (internal
, b
);
9232 /* Do not mention breakpoints with a negative number, but do
9233 notify observers. */
9236 observer_notify_breakpoint_created (b
);
9238 update_global_location_list (1);
9241 /* Return count of debug registers needed to watch the given expression.
9242 If the watchpoint cannot be handled in hardware return zero. */
9245 can_use_hardware_watchpoint (struct value
*v
)
9247 int found_memory_cnt
= 0;
9248 struct value
*head
= v
;
9250 /* Did the user specifically forbid us to use hardware watchpoints? */
9251 if (!can_use_hw_watchpoints
)
9254 /* Make sure that the value of the expression depends only upon
9255 memory contents, and values computed from them within GDB. If we
9256 find any register references or function calls, we can't use a
9257 hardware watchpoint.
9259 The idea here is that evaluating an expression generates a series
9260 of values, one holding the value of every subexpression. (The
9261 expression a*b+c has five subexpressions: a, b, a*b, c, and
9262 a*b+c.) GDB's values hold almost enough information to establish
9263 the criteria given above --- they identify memory lvalues,
9264 register lvalues, computed values, etcetera. So we can evaluate
9265 the expression, and then scan the chain of values that leaves
9266 behind to decide whether we can detect any possible change to the
9267 expression's final value using only hardware watchpoints.
9269 However, I don't think that the values returned by inferior
9270 function calls are special in any way. So this function may not
9271 notice that an expression involving an inferior function call
9272 can't be watched with hardware watchpoints. FIXME. */
9273 for (; v
; v
= value_next (v
))
9275 if (VALUE_LVAL (v
) == lval_memory
)
9277 if (v
!= head
&& value_lazy (v
))
9278 /* A lazy memory lvalue in the chain is one that GDB never
9279 needed to fetch; we either just used its address (e.g.,
9280 `a' in `a.b') or we never needed it at all (e.g., `a'
9281 in `a,b'). This doesn't apply to HEAD; if that is
9282 lazy then it was not readable, but watch it anyway. */
9286 /* Ahh, memory we actually used! Check if we can cover
9287 it with hardware watchpoints. */
9288 struct type
*vtype
= check_typedef (value_type (v
));
9290 /* We only watch structs and arrays if user asked for it
9291 explicitly, never if they just happen to appear in a
9292 middle of some value chain. */
9294 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9295 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9297 CORE_ADDR vaddr
= value_address (v
);
9301 len
= (target_exact_watchpoints
9302 && is_scalar_type_recursive (vtype
))?
9303 1 : TYPE_LENGTH (value_type (v
));
9305 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9309 found_memory_cnt
+= num_regs
;
9313 else if (VALUE_LVAL (v
) != not_lval
9314 && deprecated_value_modifiable (v
) == 0)
9315 return 0; /* These are values from the history (e.g., $1). */
9316 else if (VALUE_LVAL (v
) == lval_register
)
9317 return 0; /* Cannot watch a register with a HW watchpoint. */
9320 /* The expression itself looks suitable for using a hardware
9321 watchpoint, but give the target machine a chance to reject it. */
9322 return found_memory_cnt
;
9326 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9328 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9331 /* A helper function that looks for an argument at the start of a
9332 string. The argument must also either be at the end of the string,
9333 or be followed by whitespace. Returns 1 if it finds the argument,
9334 0 otherwise. If the argument is found, it updates *STR. */
9337 check_for_argument (char **str
, char *arg
, int arg_len
)
9339 if (strncmp (*str
, arg
, arg_len
) == 0
9340 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9348 /* A helper function that looks for the "-location" argument and then
9349 calls watch_command_1. */
9352 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9354 int just_location
= 0;
9357 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9358 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9360 arg
= skip_spaces (arg
);
9364 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9368 watch_command (char *arg
, int from_tty
)
9370 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9374 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9376 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9380 rwatch_command (char *arg
, int from_tty
)
9382 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9386 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9388 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9392 awatch_command (char *arg
, int from_tty
)
9394 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9398 /* Helper routines for the until_command routine in infcmd.c. Here
9399 because it uses the mechanisms of breakpoints. */
9401 struct until_break_command_continuation_args
9403 struct breakpoint
*breakpoint
;
9404 struct breakpoint
*breakpoint2
;
9408 /* This function is called by fetch_inferior_event via the
9409 cmd_continuation pointer, to complete the until command. It takes
9410 care of cleaning up the temporary breakpoints set up by the until
9413 until_break_command_continuation (void *arg
, int err
)
9415 struct until_break_command_continuation_args
*a
= arg
;
9417 delete_breakpoint (a
->breakpoint
);
9419 delete_breakpoint (a
->breakpoint2
);
9420 delete_longjmp_breakpoint (a
->thread_num
);
9424 until_break_command (char *arg
, int from_tty
, int anywhere
)
9426 struct symtabs_and_lines sals
;
9427 struct symtab_and_line sal
;
9428 struct frame_info
*frame
= get_selected_frame (NULL
);
9429 struct breakpoint
*breakpoint
;
9430 struct breakpoint
*breakpoint2
= NULL
;
9431 struct cleanup
*old_chain
;
9433 struct thread_info
*tp
;
9435 clear_proceed_status ();
9437 /* Set a breakpoint where the user wants it and at return from
9440 if (default_breakpoint_valid
)
9441 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
9442 default_breakpoint_line
, NULL
);
9444 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9446 if (sals
.nelts
!= 1)
9447 error (_("Couldn't get information on specified line."));
9450 xfree (sals
.sals
); /* malloc'd, so freed. */
9453 error (_("Junk at end of arguments."));
9455 resolve_sal_pc (&sal
);
9458 /* If the user told us to continue until a specified location,
9459 we don't specify a frame at which we need to stop. */
9460 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9461 null_frame_id
, bp_until
);
9463 /* Otherwise, specify the selected frame, because we want to stop
9464 only at the very same frame. */
9465 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9466 get_stack_frame_id (frame
),
9469 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9471 tp
= inferior_thread ();
9474 /* Keep within the current frame, or in frames called by the current
9477 if (frame_id_p (frame_unwind_caller_id (frame
)))
9479 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9480 sal
.pc
= frame_unwind_caller_pc (frame
);
9481 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9483 frame_unwind_caller_id (frame
),
9485 make_cleanup_delete_breakpoint (breakpoint2
);
9487 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9488 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9491 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9493 /* If we are running asynchronously, and proceed call above has
9494 actually managed to start the target, arrange for breakpoints to
9495 be deleted when the target stops. Otherwise, we're already
9496 stopped and delete breakpoints via cleanup chain. */
9498 if (target_can_async_p () && is_running (inferior_ptid
))
9500 struct until_break_command_continuation_args
*args
;
9501 args
= xmalloc (sizeof (*args
));
9503 args
->breakpoint
= breakpoint
;
9504 args
->breakpoint2
= breakpoint2
;
9505 args
->thread_num
= thread
;
9507 discard_cleanups (old_chain
);
9508 add_continuation (inferior_thread (),
9509 until_break_command_continuation
, args
,
9513 do_cleanups (old_chain
);
9516 /* This function attempts to parse an optional "if <cond>" clause
9517 from the arg string. If one is not found, it returns NULL.
9519 Else, it returns a pointer to the condition string. (It does not
9520 attempt to evaluate the string against a particular block.) And,
9521 it updates arg to point to the first character following the parsed
9522 if clause in the arg string. */
9525 ep_parse_optional_if_clause (char **arg
)
9529 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9532 /* Skip the "if" keyword. */
9535 /* Skip any extra leading whitespace, and record the start of the
9536 condition string. */
9537 *arg
= skip_spaces (*arg
);
9540 /* Assume that the condition occupies the remainder of the arg
9542 (*arg
) += strlen (cond_string
);
9547 /* Commands to deal with catching events, such as signals, exceptions,
9548 process start/exit, etc. */
9552 catch_fork_temporary
, catch_vfork_temporary
,
9553 catch_fork_permanent
, catch_vfork_permanent
9558 catch_fork_command_1 (char *arg
, int from_tty
,
9559 struct cmd_list_element
*command
)
9561 struct gdbarch
*gdbarch
= get_current_arch ();
9562 char *cond_string
= NULL
;
9563 catch_fork_kind fork_kind
;
9566 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9567 tempflag
= (fork_kind
== catch_fork_temporary
9568 || fork_kind
== catch_vfork_temporary
);
9572 arg
= skip_spaces (arg
);
9574 /* The allowed syntax is:
9576 catch [v]fork if <cond>
9578 First, check if there's an if clause. */
9579 cond_string
= ep_parse_optional_if_clause (&arg
);
9581 if ((*arg
!= '\0') && !isspace (*arg
))
9582 error (_("Junk at end of arguments."));
9584 /* If this target supports it, create a fork or vfork catchpoint
9585 and enable reporting of such events. */
9588 case catch_fork_temporary
:
9589 case catch_fork_permanent
:
9590 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9591 &catch_fork_breakpoint_ops
);
9593 case catch_vfork_temporary
:
9594 case catch_vfork_permanent
:
9595 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9596 &catch_vfork_breakpoint_ops
);
9599 error (_("unsupported or unknown fork kind; cannot catch it"));
9605 catch_exec_command_1 (char *arg
, int from_tty
,
9606 struct cmd_list_element
*command
)
9608 struct exec_catchpoint
*c
;
9609 struct gdbarch
*gdbarch
= get_current_arch ();
9611 char *cond_string
= NULL
;
9613 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9617 arg
= skip_spaces (arg
);
9619 /* The allowed syntax is:
9621 catch exec if <cond>
9623 First, check if there's an if clause. */
9624 cond_string
= ep_parse_optional_if_clause (&arg
);
9626 if ((*arg
!= '\0') && !isspace (*arg
))
9627 error (_("Junk at end of arguments."));
9629 c
= XNEW (struct exec_catchpoint
);
9630 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9631 &catch_exec_breakpoint_ops
);
9632 c
->exec_pathname
= NULL
;
9634 install_breakpoint (&c
->base
);
9637 static enum print_stop_action
9638 print_it_exception_catchpoint (bpstat bs
)
9640 struct breakpoint
*b
= bs
->breakpoint_at
;
9641 int bp_temp
, bp_throw
;
9643 annotate_catchpoint (b
->number
);
9645 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9646 if (b
->loc
->address
!= b
->loc
->requested_address
)
9647 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9650 bp_temp
= b
->disposition
== disp_del
;
9652 bp_temp
? "Temporary catchpoint "
9654 if (!ui_out_is_mi_like_p (uiout
))
9655 ui_out_field_int (uiout
, "bkptno", b
->number
);
9657 bp_throw
? " (exception thrown), "
9658 : " (exception caught), ");
9659 if (ui_out_is_mi_like_p (uiout
))
9661 ui_out_field_string (uiout
, "reason",
9662 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9663 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9664 ui_out_field_int (uiout
, "bkptno", b
->number
);
9666 return PRINT_SRC_AND_LOC
;
9670 print_one_exception_catchpoint (struct breakpoint
*b
,
9671 struct bp_location
**last_loc
)
9673 struct value_print_options opts
;
9675 get_user_print_options (&opts
);
9676 if (opts
.addressprint
)
9679 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9680 ui_out_field_string (uiout
, "addr", "<PENDING>");
9682 ui_out_field_core_addr (uiout
, "addr",
9683 b
->loc
->gdbarch
, b
->loc
->address
);
9688 if (strstr (b
->addr_string
, "throw") != NULL
)
9689 ui_out_field_string (uiout
, "what", "exception throw");
9691 ui_out_field_string (uiout
, "what", "exception catch");
9695 print_mention_exception_catchpoint (struct breakpoint
*b
)
9700 bp_temp
= b
->disposition
== disp_del
;
9701 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9702 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9703 : _("Catchpoint "));
9704 ui_out_field_int (uiout
, "bkptno", b
->number
);
9705 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9709 /* Implement the "print_recreate" breakpoint_ops method for throw and
9710 catch catchpoints. */
9713 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9719 bp_temp
= b
->disposition
== disp_del
;
9720 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9721 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9722 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9725 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9727 bkpt_allocate_location
,
9729 bkpt_insert_location
,
9730 bkpt_remove_location
,
9731 bkpt_breakpoint_hit
,
9733 bkpt_resources_needed
,
9734 null_works_in_software_mode
,
9735 print_it_exception_catchpoint
,
9736 print_one_exception_catchpoint
,
9737 null_print_one_detail
,
9738 print_mention_exception_catchpoint
,
9739 print_recreate_exception_catchpoint
9743 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9744 enum exception_event_kind ex_event
, int from_tty
)
9746 char *trigger_func_name
;
9748 if (ex_event
== EX_EVENT_CATCH
)
9749 trigger_func_name
= "__cxa_begin_catch";
9751 trigger_func_name
= "__cxa_throw";
9753 create_breakpoint (get_current_arch (),
9754 trigger_func_name
, cond_string
, -1,
9755 0 /* condition and thread are valid. */,
9756 tempflag
, bp_breakpoint
,
9758 AUTO_BOOLEAN_TRUE
/* pending */,
9759 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9766 /* Deal with "catch catch" and "catch throw" commands. */
9769 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9770 int tempflag
, int from_tty
)
9772 char *cond_string
= NULL
;
9776 arg
= skip_spaces (arg
);
9778 cond_string
= ep_parse_optional_if_clause (&arg
);
9780 if ((*arg
!= '\0') && !isspace (*arg
))
9781 error (_("Junk at end of arguments."));
9783 if (ex_event
!= EX_EVENT_THROW
9784 && ex_event
!= EX_EVENT_CATCH
)
9785 error (_("Unsupported or unknown exception event; cannot catch it"));
9787 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9790 warning (_("Unsupported with this platform/compiler combination."));
9793 /* Implementation of "catch catch" command. */
9796 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9798 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9800 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9803 /* Implementation of "catch throw" command. */
9806 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9808 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9810 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9814 init_ada_exception_breakpoint (struct breakpoint
*b
,
9815 struct gdbarch
*gdbarch
,
9816 struct symtab_and_line sal
,
9818 struct breakpoint_ops
*ops
,
9824 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9826 loc_gdbarch
= gdbarch
;
9828 describe_other_breakpoints (loc_gdbarch
,
9829 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9830 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9831 version for exception catchpoints, because two catchpoints
9832 used for different exception names will use the same address.
9833 In this case, a "breakpoint ... also set at..." warning is
9834 unproductive. Besides, the warning phrasing is also a bit
9835 inappropriate, we should use the word catchpoint, and tell
9836 the user what type of catchpoint it is. The above is good
9837 enough for now, though. */
9840 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9842 b
->enable_state
= bp_enabled
;
9843 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9844 b
->addr_string
= addr_string
;
9845 b
->language
= language_ada
;
9848 /* Cleanup function for a syscall filter list. */
9850 clean_up_filters (void *arg
)
9852 VEC(int) *iter
= *(VEC(int) **) arg
;
9853 VEC_free (int, iter
);
9856 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9857 filter list, or NULL if no filtering is required. */
9859 catch_syscall_split_args (char *arg
)
9861 VEC(int) *result
= NULL
;
9862 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9864 while (*arg
!= '\0')
9866 int i
, syscall_number
;
9871 /* Skip whitespace. */
9872 while (isspace (*arg
))
9875 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9876 cur_name
[i
] = arg
[i
];
9880 /* Check if the user provided a syscall name or a number. */
9881 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9882 if (*endptr
== '\0')
9883 get_syscall_by_number (syscall_number
, &s
);
9886 /* We have a name. Let's check if it's valid and convert it
9888 get_syscall_by_name (cur_name
, &s
);
9890 if (s
.number
== UNKNOWN_SYSCALL
)
9891 /* Here we have to issue an error instead of a warning,
9892 because GDB cannot do anything useful if there's no
9893 syscall number to be caught. */
9894 error (_("Unknown syscall name '%s'."), cur_name
);
9897 /* Ok, it's valid. */
9898 VEC_safe_push (int, result
, s
.number
);
9901 discard_cleanups (cleanup
);
9905 /* Implement the "catch syscall" command. */
9908 catch_syscall_command_1 (char *arg
, int from_tty
,
9909 struct cmd_list_element
*command
)
9914 struct gdbarch
*gdbarch
= get_current_arch ();
9916 /* Checking if the feature if supported. */
9917 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9918 error (_("The feature 'catch syscall' is not supported on \
9919 this architecture yet."));
9921 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9923 arg
= skip_spaces (arg
);
9925 /* We need to do this first "dummy" translation in order
9926 to get the syscall XML file loaded or, most important,
9927 to display a warning to the user if there's no XML file
9928 for his/her architecture. */
9929 get_syscall_by_number (0, &s
);
9931 /* The allowed syntax is:
9933 catch syscall <name | number> [<name | number> ... <name | number>]
9935 Let's check if there's a syscall name. */
9938 filter
= catch_syscall_split_args (arg
);
9942 create_syscall_event_catchpoint (tempflag
, filter
,
9943 &catch_syscall_breakpoint_ops
);
9947 catch_command (char *arg
, int from_tty
)
9949 error (_("Catch requires an event name."));
9954 tcatch_command (char *arg
, int from_tty
)
9956 error (_("Catch requires an event name."));
9959 /* Delete breakpoints by address or line. */
9962 clear_command (char *arg
, int from_tty
)
9964 struct breakpoint
*b
;
9965 VEC(breakpoint_p
) *found
= 0;
9968 struct symtabs_and_lines sals
;
9969 struct symtab_and_line sal
;
9974 sals
= decode_line_spec (arg
, 1);
9979 sals
.sals
= (struct symtab_and_line
*)
9980 xmalloc (sizeof (struct symtab_and_line
));
9981 make_cleanup (xfree
, sals
.sals
);
9982 init_sal (&sal
); /* Initialize to zeroes. */
9983 sal
.line
= default_breakpoint_line
;
9984 sal
.symtab
= default_breakpoint_symtab
;
9985 sal
.pc
= default_breakpoint_address
;
9986 sal
.pspace
= default_breakpoint_pspace
;
9987 if (sal
.symtab
== 0)
9988 error (_("No source file specified."));
9996 /* We don't call resolve_sal_pc here. That's not as bad as it
9997 seems, because all existing breakpoints typically have both
9998 file/line and pc set. So, if clear is given file/line, we can
9999 match this to existing breakpoint without obtaining pc at all.
10001 We only support clearing given the address explicitly
10002 present in breakpoint table. Say, we've set breakpoint
10003 at file:line. There were several PC values for that file:line,
10004 due to optimization, all in one block.
10006 We've picked one PC value. If "clear" is issued with another
10007 PC corresponding to the same file:line, the breakpoint won't
10008 be cleared. We probably can still clear the breakpoint, but
10009 since the other PC value is never presented to user, user
10010 can only find it by guessing, and it does not seem important
10011 to support that. */
10013 /* For each line spec given, delete bps which correspond to it. Do
10014 it in two passes, solely to preserve the current behavior that
10015 from_tty is forced true if we delete more than one
10019 for (i
= 0; i
< sals
.nelts
; i
++)
10021 /* If exact pc given, clear bpts at that pc.
10022 If line given (pc == 0), clear all bpts on specified line.
10023 If defaulting, clear all bpts on default line
10026 defaulting sal.pc != 0 tests to do
10031 1 0 <can't happen> */
10033 sal
= sals
.sals
[i
];
10035 /* Find all matching breakpoints and add them to 'found'. */
10036 ALL_BREAKPOINTS (b
)
10039 /* Are we going to delete b? */
10040 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10042 struct bp_location
*loc
= b
->loc
;
10043 for (; loc
; loc
= loc
->next
)
10045 int pc_match
= sal
.pc
10046 && (loc
->pspace
== sal
.pspace
)
10047 && (loc
->address
== sal
.pc
)
10048 && (!section_is_overlay (loc
->section
)
10049 || loc
->section
== sal
.section
);
10050 int line_match
= ((default_match
|| (0 == sal
.pc
))
10051 && b
->source_file
!= NULL
10052 && sal
.symtab
!= NULL
10053 && sal
.pspace
== loc
->pspace
10054 && filename_cmp (b
->source_file
,
10055 sal
.symtab
->filename
) == 0
10056 && b
->line_number
== sal
.line
);
10057 if (pc_match
|| line_match
)
10066 VEC_safe_push(breakpoint_p
, found
, b
);
10069 /* Now go thru the 'found' chain and delete them. */
10070 if (VEC_empty(breakpoint_p
, found
))
10073 error (_("No breakpoint at %s."), arg
);
10075 error (_("No breakpoint at this line."));
10078 if (VEC_length(breakpoint_p
, found
) > 1)
10079 from_tty
= 1; /* Always report if deleted more than one. */
10082 if (VEC_length(breakpoint_p
, found
) == 1)
10083 printf_unfiltered (_("Deleted breakpoint "));
10085 printf_unfiltered (_("Deleted breakpoints "));
10087 breakpoints_changed ();
10089 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10092 printf_unfiltered ("%d ", b
->number
);
10093 delete_breakpoint (b
);
10096 putchar_unfiltered ('\n');
10099 /* Delete breakpoint in BS if they are `delete' breakpoints and
10100 all breakpoints that are marked for deletion, whether hit or not.
10101 This is called after any breakpoint is hit, or after errors. */
10104 breakpoint_auto_delete (bpstat bs
)
10106 struct breakpoint
*b
, *b_tmp
;
10108 for (; bs
; bs
= bs
->next
)
10109 if (bs
->breakpoint_at
10110 && bs
->breakpoint_at
->disposition
== disp_del
10112 delete_breakpoint (bs
->breakpoint_at
);
10114 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10116 if (b
->disposition
== disp_del_at_next_stop
)
10117 delete_breakpoint (b
);
10121 /* A comparison function for bp_location AP and BP being interfaced to
10122 qsort. Sort elements primarily by their ADDRESS (no matter what
10123 does breakpoint_address_is_meaningful say for its OWNER),
10124 secondarily by ordering first bp_permanent OWNERed elements and
10125 terciarily just ensuring the array is sorted stable way despite
10126 qsort being an unstable algorithm. */
10129 bp_location_compare (const void *ap
, const void *bp
)
10131 struct bp_location
*a
= *(void **) ap
;
10132 struct bp_location
*b
= *(void **) bp
;
10133 /* A and B come from existing breakpoints having non-NULL OWNER. */
10134 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10135 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10137 if (a
->address
!= b
->address
)
10138 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10140 /* Sort permanent breakpoints first. */
10141 if (a_perm
!= b_perm
)
10142 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10144 /* Make the user-visible order stable across GDB runs. Locations of
10145 the same breakpoint can be sorted in arbitrary order. */
10147 if (a
->owner
->number
!= b
->owner
->number
)
10148 return (a
->owner
->number
> b
->owner
->number
)
10149 - (a
->owner
->number
< b
->owner
->number
);
10151 return (a
> b
) - (a
< b
);
10154 /* Set bp_location_placed_address_before_address_max and
10155 bp_location_shadow_len_after_address_max according to the current
10156 content of the bp_location array. */
10159 bp_location_target_extensions_update (void)
10161 struct bp_location
*bl
, **blp_tmp
;
10163 bp_location_placed_address_before_address_max
= 0;
10164 bp_location_shadow_len_after_address_max
= 0;
10166 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10168 CORE_ADDR start
, end
, addr
;
10170 if (!bp_location_has_shadow (bl
))
10173 start
= bl
->target_info
.placed_address
;
10174 end
= start
+ bl
->target_info
.shadow_len
;
10176 gdb_assert (bl
->address
>= start
);
10177 addr
= bl
->address
- start
;
10178 if (addr
> bp_location_placed_address_before_address_max
)
10179 bp_location_placed_address_before_address_max
= addr
;
10181 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10183 gdb_assert (bl
->address
< end
);
10184 addr
= end
- bl
->address
;
10185 if (addr
> bp_location_shadow_len_after_address_max
)
10186 bp_location_shadow_len_after_address_max
= addr
;
10190 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10191 into the inferior, only remove already-inserted locations that no
10192 longer should be inserted. Functions that delete a breakpoint or
10193 breakpoints should pass false, so that deleting a breakpoint
10194 doesn't have the side effect of inserting the locations of other
10195 breakpoints that are marked not-inserted, but should_be_inserted
10196 returns true on them.
10198 This behaviour is useful is situations close to tear-down -- e.g.,
10199 after an exec, while the target still has execution, but breakpoint
10200 shadows of the previous executable image should *NOT* be restored
10201 to the new image; or before detaching, where the target still has
10202 execution and wants to delete breakpoints from GDB's lists, and all
10203 breakpoints had already been removed from the inferior. */
10206 update_global_location_list (int should_insert
)
10208 struct breakpoint
*b
;
10209 struct bp_location
**locp
, *loc
;
10210 struct cleanup
*cleanups
;
10212 /* Used in the duplicates detection below. When iterating over all
10213 bp_locations, points to the first bp_location of a given address.
10214 Breakpoints and watchpoints of different types are never
10215 duplicates of each other. Keep one pointer for each type of
10216 breakpoint/watchpoint, so we only need to loop over all locations
10218 struct bp_location
*bp_loc_first
; /* breakpoint */
10219 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10220 struct bp_location
*awp_loc_first
; /* access watchpoint */
10221 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10223 /* Saved former bp_location array which we compare against the newly
10224 built bp_location from the current state of ALL_BREAKPOINTS. */
10225 struct bp_location
**old_location
, **old_locp
;
10226 unsigned old_location_count
;
10228 old_location
= bp_location
;
10229 old_location_count
= bp_location_count
;
10230 bp_location
= NULL
;
10231 bp_location_count
= 0;
10232 cleanups
= make_cleanup (xfree
, old_location
);
10234 ALL_BREAKPOINTS (b
)
10235 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10236 bp_location_count
++;
10238 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10239 locp
= bp_location
;
10240 ALL_BREAKPOINTS (b
)
10241 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10243 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10244 bp_location_compare
);
10246 bp_location_target_extensions_update ();
10248 /* Identify bp_location instances that are no longer present in the
10249 new list, and therefore should be freed. Note that it's not
10250 necessary that those locations should be removed from inferior --
10251 if there's another location at the same address (previously
10252 marked as duplicate), we don't need to remove/insert the
10255 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10256 and former bp_location array state respectively. */
10258 locp
= bp_location
;
10259 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10262 struct bp_location
*old_loc
= *old_locp
;
10263 struct bp_location
**loc2p
;
10265 /* Tells if 'old_loc' is found among the new locations. If
10266 not, we have to free it. */
10267 int found_object
= 0;
10268 /* Tells if the location should remain inserted in the target. */
10269 int keep_in_target
= 0;
10272 /* Skip LOCP entries which will definitely never be needed.
10273 Stop either at or being the one matching OLD_LOC. */
10274 while (locp
< bp_location
+ bp_location_count
10275 && (*locp
)->address
< old_loc
->address
)
10279 (loc2p
< bp_location
+ bp_location_count
10280 && (*loc2p
)->address
== old_loc
->address
);
10283 if (*loc2p
== old_loc
)
10290 /* If this location is no longer present, and inserted, look if
10291 there's maybe a new location at the same address. If so,
10292 mark that one inserted, and don't remove this one. This is
10293 needed so that we don't have a time window where a breakpoint
10294 at certain location is not inserted. */
10296 if (old_loc
->inserted
)
10298 /* If the location is inserted now, we might have to remove
10301 if (found_object
&& should_be_inserted (old_loc
))
10303 /* The location is still present in the location list,
10304 and still should be inserted. Don't do anything. */
10305 keep_in_target
= 1;
10309 /* The location is either no longer present, or got
10310 disabled. See if there's another location at the
10311 same address, in which case we don't need to remove
10312 this one from the target. */
10314 /* OLD_LOC comes from existing struct breakpoint. */
10315 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10318 (loc2p
< bp_location
+ bp_location_count
10319 && (*loc2p
)->address
== old_loc
->address
);
10322 struct bp_location
*loc2
= *loc2p
;
10324 if (breakpoint_locations_match (loc2
, old_loc
))
10326 /* For the sake of should_be_inserted.
10327 Duplicates check below will fix up this
10329 loc2
->duplicate
= 0;
10331 /* Read watchpoint locations are switched to
10332 access watchpoints, if the former are not
10333 supported, but the latter are. */
10334 if (is_hardware_watchpoint (old_loc
->owner
))
10336 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10337 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10340 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
10342 loc2
->inserted
= 1;
10343 loc2
->target_info
= old_loc
->target_info
;
10344 keep_in_target
= 1;
10352 if (!keep_in_target
)
10354 if (remove_breakpoint (old_loc
, mark_uninserted
))
10356 /* This is just about all we can do. We could keep
10357 this location on the global list, and try to
10358 remove it next time, but there's no particular
10359 reason why we will succeed next time.
10361 Note that at this point, old_loc->owner is still
10362 valid, as delete_breakpoint frees the breakpoint
10363 only after calling us. */
10364 printf_filtered (_("warning: Error removing "
10365 "breakpoint %d\n"),
10366 old_loc
->owner
->number
);
10374 if (removed
&& non_stop
10375 && breakpoint_address_is_meaningful (old_loc
->owner
)
10376 && !is_hardware_watchpoint (old_loc
->owner
))
10378 /* This location was removed from the target. In
10379 non-stop mode, a race condition is possible where
10380 we've removed a breakpoint, but stop events for that
10381 breakpoint are already queued and will arrive later.
10382 We apply an heuristic to be able to distinguish such
10383 SIGTRAPs from other random SIGTRAPs: we keep this
10384 breakpoint location for a bit, and will retire it
10385 after we see some number of events. The theory here
10386 is that reporting of events should, "on the average",
10387 be fair, so after a while we'll see events from all
10388 threads that have anything of interest, and no longer
10389 need to keep this breakpoint location around. We
10390 don't hold locations forever so to reduce chances of
10391 mistaking a non-breakpoint SIGTRAP for a breakpoint
10394 The heuristic failing can be disastrous on
10395 decr_pc_after_break targets.
10397 On decr_pc_after_break targets, like e.g., x86-linux,
10398 if we fail to recognize a late breakpoint SIGTRAP,
10399 because events_till_retirement has reached 0 too
10400 soon, we'll fail to do the PC adjustment, and report
10401 a random SIGTRAP to the user. When the user resumes
10402 the inferior, it will most likely immediately crash
10403 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10404 corrupted, because of being resumed e.g., in the
10405 middle of a multi-byte instruction, or skipped a
10406 one-byte instruction. This was actually seen happen
10407 on native x86-linux, and should be less rare on
10408 targets that do not support new thread events, like
10409 remote, due to the heuristic depending on
10412 Mistaking a random SIGTRAP for a breakpoint trap
10413 causes similar symptoms (PC adjustment applied when
10414 it shouldn't), but then again, playing with SIGTRAPs
10415 behind the debugger's back is asking for trouble.
10417 Since hardware watchpoint traps are always
10418 distinguishable from other traps, so we don't need to
10419 apply keep hardware watchpoint moribund locations
10420 around. We simply always ignore hardware watchpoint
10421 traps we can no longer explain. */
10423 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10424 old_loc
->owner
= NULL
;
10426 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10430 old_loc
->owner
= NULL
;
10431 decref_bp_location (&old_loc
);
10436 /* Rescan breakpoints at the same address and section, marking the
10437 first one as "first" and any others as "duplicates". This is so
10438 that the bpt instruction is only inserted once. If we have a
10439 permanent breakpoint at the same place as BPT, make that one the
10440 official one, and the rest as duplicates. Permanent breakpoints
10441 are sorted first for the same address.
10443 Do the same for hardware watchpoints, but also considering the
10444 watchpoint's type (regular/access/read) and length. */
10446 bp_loc_first
= NULL
;
10447 wp_loc_first
= NULL
;
10448 awp_loc_first
= NULL
;
10449 rwp_loc_first
= NULL
;
10450 ALL_BP_LOCATIONS (loc
, locp
)
10452 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10454 struct breakpoint
*b
= loc
->owner
;
10455 struct bp_location
**loc_first_p
;
10457 if (b
->enable_state
== bp_disabled
10458 || b
->enable_state
== bp_call_disabled
10459 || b
->enable_state
== bp_startup_disabled
10461 || loc
->shlib_disabled
10462 || !breakpoint_address_is_meaningful (b
)
10463 || is_tracepoint (b
))
10466 /* Permanent breakpoint should always be inserted. */
10467 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10468 internal_error (__FILE__
, __LINE__
,
10469 _("allegedly permanent breakpoint is not "
10470 "actually inserted"));
10472 if (b
->type
== bp_hardware_watchpoint
)
10473 loc_first_p
= &wp_loc_first
;
10474 else if (b
->type
== bp_read_watchpoint
)
10475 loc_first_p
= &rwp_loc_first
;
10476 else if (b
->type
== bp_access_watchpoint
)
10477 loc_first_p
= &awp_loc_first
;
10479 loc_first_p
= &bp_loc_first
;
10481 if (*loc_first_p
== NULL
10482 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10483 || !breakpoint_locations_match (loc
, *loc_first_p
))
10485 *loc_first_p
= loc
;
10486 loc
->duplicate
= 0;
10490 loc
->duplicate
= 1;
10492 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10493 && b
->enable_state
!= bp_permanent
)
10494 internal_error (__FILE__
, __LINE__
,
10495 _("another breakpoint was inserted on top of "
10496 "a permanent breakpoint"));
10499 if (breakpoints_always_inserted_mode () && should_insert
10500 && (have_live_inferiors ()
10501 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10502 insert_breakpoint_locations ();
10504 do_cleanups (cleanups
);
10508 breakpoint_retire_moribund (void)
10510 struct bp_location
*loc
;
10513 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10514 if (--(loc
->events_till_retirement
) == 0)
10516 decref_bp_location (&loc
);
10517 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10523 update_global_location_list_nothrow (int inserting
)
10525 struct gdb_exception e
;
10527 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10528 update_global_location_list (inserting
);
10531 /* Clear BKP from a BPS. */
10534 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10538 for (bs
= bps
; bs
; bs
= bs
->next
)
10539 if (bs
->breakpoint_at
== bpt
)
10541 bs
->breakpoint_at
= NULL
;
10542 bs
->old_val
= NULL
;
10543 /* bs->commands will be freed later. */
10547 /* Callback for iterate_over_threads. */
10549 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10551 struct breakpoint
*bpt
= data
;
10553 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10557 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10561 say_where (struct breakpoint
*b
)
10563 struct value_print_options opts
;
10565 get_user_print_options (&opts
);
10567 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10569 if (b
->loc
== NULL
)
10571 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10575 if (opts
.addressprint
|| b
->source_file
== NULL
)
10577 printf_filtered (" at ");
10578 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10581 if (b
->source_file
)
10582 printf_filtered (": file %s, line %d.",
10583 b
->source_file
, b
->line_number
);
10587 struct bp_location
*loc
= b
->loc
;
10589 for (; loc
; loc
= loc
->next
)
10591 printf_filtered (" (%d locations)", n
);
10596 /* Default breakpoint_ops methods that do nothing. */
10599 null_re_set (struct breakpoint
*b
)
10601 /* Nothing to re-set. */
10605 null_check_status (bpstat bs
)
10610 /* A "works_in_software_mode" breakpoint_ops method that just internal
10614 null_works_in_software_mode (const struct breakpoint
*b
)
10616 gdb_assert_not_reached ("null_works_in_software_mode called");
10619 /* A "resources_needed" breakpoint_ops method that just internal
10623 null_resources_needed (const struct bp_location
*bl
)
10625 gdb_assert_not_reached ("null_resources_needed");
10629 null_print_one_detail (const struct breakpoint
*self
,
10630 struct ui_out
*uiout
)
10635 /* Default bp_location_ops methods. */
10638 bp_location_dtor (struct bp_location
*self
)
10640 xfree (self
->cond
);
10641 xfree (self
->function_name
);
10644 static const struct bp_location_ops bp_location_ops
=
10649 /* Default breakpoint_ops methods. */
10652 bkpt_dtor (struct breakpoint
*self
)
10654 decref_counted_command_line (&self
->commands
);
10655 xfree (self
->cond_string
);
10656 xfree (self
->cond_exp
);
10657 xfree (self
->addr_string
);
10658 xfree (self
->addr_string_range_end
);
10660 xfree (self
->exp_string
);
10661 xfree (self
->exp_string_reparse
);
10662 value_free (self
->val
);
10663 xfree (self
->source_file
);
10666 struct bp_location
*
10667 bkpt_allocate_location (struct breakpoint
*self
)
10669 struct bp_location
*loc
;
10671 loc
= XNEW (struct bp_location
);
10672 init_bp_location (loc
, &bp_location_ops
, self
);
10677 bkpt_re_set (struct breakpoint
*b
)
10681 case bp_breakpoint
:
10682 case bp_hardware_breakpoint
:
10683 case bp_gnu_ifunc_resolver
:
10684 /* Do not attempt to re-set breakpoints disabled during
10686 if (b
->enable_state
== bp_startup_disabled
)
10689 if (b
->addr_string
== NULL
)
10691 /* Anything without a string can't be re-set. */
10692 delete_breakpoint (b
);
10696 breakpoint_re_set_default (b
);
10700 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10702 /* Delete overlay event and longjmp master breakpoints; they
10703 will be reset later by breakpoint_re_set. */
10704 case bp_overlay_event
:
10705 case bp_longjmp_master
:
10706 case bp_std_terminate_master
:
10707 case bp_exception_master
:
10708 delete_breakpoint (b
);
10711 /* This breakpoint is special, it's set up when the inferior
10712 starts and we really don't want to touch it. */
10713 case bp_shlib_event
:
10715 /* Like bp_shlib_event, this breakpoint type is special. Once
10716 it is set up, we do not want to touch it. */
10717 case bp_thread_event
:
10719 /* Keep temporary breakpoints, which can be encountered when we
10720 step over a dlopen call and SOLIB_ADD is resetting the
10721 breakpoints. Otherwise these should have been blown away via
10722 the cleanup chain or by breakpoint_init_inferior when we
10723 rerun the executable. */
10726 case bp_watchpoint_scope
:
10727 case bp_call_dummy
:
10728 case bp_std_terminate
:
10729 case bp_step_resume
:
10730 case bp_hp_step_resume
:
10732 case bp_longjmp_resume
:
10734 case bp_exception_resume
:
10736 case bp_gnu_ifunc_resolver_return
:
10742 bkpt_insert_location (struct bp_location
*bl
)
10744 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10745 return target_insert_hw_breakpoint (bl
->gdbarch
,
10748 return target_insert_breakpoint (bl
->gdbarch
,
10753 bkpt_remove_location (struct bp_location
*bl
)
10755 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10756 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10758 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10762 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10763 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10765 struct breakpoint
*b
= bl
->owner
;
10767 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10771 if (overlay_debugging
/* unmapped overlay section */
10772 && section_is_overlay (bl
->section
)
10773 && !section_is_mapped (bl
->section
))
10780 bkpt_check_status (bpstat bs
)
10782 struct breakpoint
*b
= bs
->breakpoint_at
;
10784 if (b
->type
== bp_thread_event
10785 || b
->type
== bp_overlay_event
10786 || b
->type
== bp_longjmp_master
10787 || b
->type
== bp_std_terminate_master
10788 || b
->type
== bp_exception_master
)
10789 /* We do not stop for these. */
10794 bkpt_resources_needed (const struct bp_location
*bl
)
10796 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10802 bkpt_works_in_software_mode (const struct breakpoint
*b
)
10804 gdb_assert_not_reached ("bkpt_works_in_software_mode called");
10807 enum print_stop_action
10808 bkpt_print_it (bpstat bs
)
10810 struct cleanup
*old_chain
;
10811 struct breakpoint
*b
;
10812 const struct bp_location
*bl
;
10813 struct ui_stream
*stb
;
10815 enum print_stop_action result
;
10817 gdb_assert (bs
->bp_location_at
!= NULL
);
10819 bl
= bs
->bp_location_at
;
10820 b
= bs
->breakpoint_at
;
10822 stb
= ui_out_stream_new (uiout
);
10823 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
10827 case bp_breakpoint
:
10828 case bp_hardware_breakpoint
:
10829 bp_temp
= b
->disposition
== disp_del
;
10830 if (bl
->address
!= bl
->requested_address
)
10831 breakpoint_adjustment_warning (bl
->requested_address
,
10834 annotate_breakpoint (b
->number
);
10836 ui_out_text (uiout
, "\nTemporary breakpoint ");
10838 ui_out_text (uiout
, "\nBreakpoint ");
10839 if (ui_out_is_mi_like_p (uiout
))
10841 ui_out_field_string (uiout
, "reason",
10842 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10843 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10845 ui_out_field_int (uiout
, "bkptno", b
->number
);
10846 ui_out_text (uiout
, ", ");
10847 result
= PRINT_SRC_AND_LOC
;
10850 case bp_shlib_event
:
10851 /* Did we stop because the user set the stop_on_solib_events
10852 variable? (If so, we report this as a generic, "Stopped due
10853 to shlib event" message.) */
10854 printf_filtered (_("Stopped due to shared library event\n"));
10855 result
= PRINT_NOTHING
;
10858 case bp_thread_event
:
10859 /* Not sure how we will get here.
10860 GDB should not stop for these breakpoints. */
10861 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
10862 result
= PRINT_NOTHING
;
10865 case bp_overlay_event
:
10866 /* By analogy with the thread event, GDB should not stop for these. */
10867 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
10868 result
= PRINT_NOTHING
;
10871 case bp_longjmp_master
:
10872 /* These should never be enabled. */
10873 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
10874 result
= PRINT_NOTHING
;
10877 case bp_std_terminate_master
:
10878 /* These should never be enabled. */
10879 printf_filtered (_("std::terminate Master Breakpoint: "
10880 "gdb should not stop!\n"));
10881 result
= PRINT_NOTHING
;
10884 case bp_exception_master
:
10885 /* These should never be enabled. */
10886 printf_filtered (_("Exception Master Breakpoint: "
10887 "gdb should not stop!\n"));
10888 result
= PRINT_NOTHING
;
10891 /* Fall through, we don't deal with these types of breakpoints
10895 if (ui_out_is_mi_like_p (uiout
))
10896 ui_out_field_string
10898 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
10899 result
= PRINT_UNKNOWN
;
10903 if (ui_out_is_mi_like_p (uiout
))
10904 ui_out_field_string
10906 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
10907 result
= PRINT_UNKNOWN
;
10912 case bp_longjmp_resume
:
10914 case bp_exception_resume
:
10915 case bp_step_resume
:
10916 case bp_hp_step_resume
:
10917 case bp_watchpoint_scope
:
10918 case bp_call_dummy
:
10919 case bp_std_terminate
:
10921 case bp_gnu_ifunc_resolver
:
10922 case bp_gnu_ifunc_resolver_return
:
10924 result
= PRINT_UNKNOWN
;
10928 do_cleanups (old_chain
);
10933 bkpt_print_mention (struct breakpoint
*b
)
10935 if (ui_out_is_mi_like_p (uiout
))
10940 case bp_breakpoint
:
10941 case bp_gnu_ifunc_resolver
:
10942 if (b
->disposition
== disp_del
)
10943 printf_filtered (_("Temporary breakpoint"));
10945 printf_filtered (_("Breakpoint"));
10946 printf_filtered (_(" %d"), b
->number
);
10947 if (b
->type
== bp_gnu_ifunc_resolver
)
10948 printf_filtered (_(" at gnu-indirect-function resolver"));
10951 case bp_hardware_breakpoint
:
10952 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
10958 case bp_longjmp_resume
:
10960 case bp_exception_resume
:
10961 case bp_step_resume
:
10962 case bp_hp_step_resume
:
10963 case bp_call_dummy
:
10964 case bp_std_terminate
:
10965 case bp_watchpoint_scope
:
10966 case bp_shlib_event
:
10967 case bp_thread_event
:
10968 case bp_overlay_event
:
10970 case bp_longjmp_master
:
10971 case bp_std_terminate_master
:
10972 case bp_exception_master
:
10973 case bp_gnu_ifunc_resolver_return
:
10979 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
10981 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10982 fprintf_unfiltered (fp
, "tbreak");
10983 else if (tp
->type
== bp_breakpoint
)
10984 fprintf_unfiltered (fp
, "break");
10985 else if (tp
->type
== bp_hardware_breakpoint
10986 && tp
->disposition
== disp_del
)
10987 fprintf_unfiltered (fp
, "thbreak");
10988 else if (tp
->type
== bp_hardware_breakpoint
)
10989 fprintf_unfiltered (fp
, "hbreak");
10991 internal_error (__FILE__
, __LINE__
,
10992 _("unhandled breakpoint type %d"), (int) tp
->type
);
10994 if (tp
->exp_string
)
10995 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
10996 else if (tp
->addr_string
)
10997 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11002 sprintf_vma (tmp
, tp
->loc
->address
);
11003 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11007 /* The breakpoint_ops structure to be used in regular breakpoints. */
11009 struct breakpoint_ops bkpt_breakpoint_ops
=
11012 bkpt_allocate_location
,
11014 bkpt_insert_location
,
11015 bkpt_remove_location
,
11016 bkpt_breakpoint_hit
,
11018 bkpt_resources_needed
,
11019 null_works_in_software_mode
,
11021 NULL
, /* print_one */
11022 null_print_one_detail
,
11023 bkpt_print_mention
,
11024 bkpt_print_recreate
11027 /* The breakpoint_ops structure to be used in tracepoints. */
11030 tracepoint_re_set (struct breakpoint
*b
)
11032 breakpoint_re_set_default (b
);
11036 tracepoint_insert_location (struct bp_location
*bl
)
11038 gdb_assert_not_reached ("tracepoint_insert_location called");
11042 tracepoint_remove_location (struct bp_location
*bl
)
11044 gdb_assert_not_reached ("tracepoint_remove_location called");
11048 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11049 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11051 /* By definition, the inferior does not report stops at
11057 tracepoint_check_status (bpstat bs
)
11059 gdb_assert_not_reached ("tracepoint_check_status called");
11063 tracepoint_works_in_software_mode (const struct breakpoint
*b
)
11065 gdb_assert_not_reached ("tracepoint_works_in_software_mode called");
11068 static enum print_stop_action
11069 tracepoint_print_it (bpstat bs
)
11071 gdb_assert_not_reached ("tracepoint_print_it called");
11075 tracepoint_print_one_detail (const struct breakpoint
*self
,
11076 struct ui_out
*uiout
)
11078 if (self
->static_trace_marker_id
)
11080 gdb_assert (self
->type
== bp_static_tracepoint
);
11082 ui_out_text (uiout
, "\tmarker id is ");
11083 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11084 self
->static_trace_marker_id
);
11085 ui_out_text (uiout
, "\n");
11090 tracepoint_print_mention (struct breakpoint
*b
)
11092 if (ui_out_is_mi_like_p (uiout
))
11097 case bp_tracepoint
:
11098 printf_filtered (_("Tracepoint"));
11099 printf_filtered (_(" %d"), b
->number
);
11101 case bp_fast_tracepoint
:
11102 printf_filtered (_("Fast tracepoint"));
11103 printf_filtered (_(" %d"), b
->number
);
11105 case bp_static_tracepoint
:
11106 printf_filtered (_("Static tracepoint"));
11107 printf_filtered (_(" %d"), b
->number
);
11110 internal_error (__FILE__
, __LINE__
,
11111 _("unhandled tracepoint type %d"), (int) b
->type
);
11118 tracepoint_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11120 if (tp
->type
== bp_fast_tracepoint
)
11121 fprintf_unfiltered (fp
, "ftrace");
11122 if (tp
->type
== bp_static_tracepoint
)
11123 fprintf_unfiltered (fp
, "strace");
11124 else if (tp
->type
== bp_tracepoint
)
11125 fprintf_unfiltered (fp
, "trace");
11127 internal_error (__FILE__
, __LINE__
,
11128 _("unhandled tracepoint type %d"), (int) tp
->type
);
11130 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11133 struct breakpoint_ops tracepoint_breakpoint_ops
=
11136 bkpt_allocate_location
,
11138 tracepoint_insert_location
,
11139 tracepoint_remove_location
,
11140 tracepoint_breakpoint_hit
,
11141 tracepoint_check_status
,
11142 null_resources_needed
,
11143 tracepoint_works_in_software_mode
,
11144 tracepoint_print_it
,
11145 NULL
, /* print_one */
11146 tracepoint_print_one_detail
,
11147 tracepoint_print_mention
,
11148 tracepoint_print_recreate
11151 /* Delete a breakpoint and clean up all traces of it in the data
11155 delete_breakpoint (struct breakpoint
*bpt
)
11157 struct breakpoint
*b
;
11159 gdb_assert (bpt
!= NULL
);
11161 /* Has this bp already been deleted? This can happen because
11162 multiple lists can hold pointers to bp's. bpstat lists are
11165 One example of this happening is a watchpoint's scope bp. When
11166 the scope bp triggers, we notice that the watchpoint is out of
11167 scope, and delete it. We also delete its scope bp. But the
11168 scope bp is marked "auto-deleting", and is already on a bpstat.
11169 That bpstat is then checked for auto-deleting bp's, which are
11172 A real solution to this problem might involve reference counts in
11173 bp's, and/or giving them pointers back to their referencing
11174 bpstat's, and teaching delete_breakpoint to only free a bp's
11175 storage when no more references were extent. A cheaper bandaid
11177 if (bpt
->type
== bp_none
)
11180 /* At least avoid this stale reference until the reference counting
11181 of breakpoints gets resolved. */
11182 if (bpt
->related_breakpoint
!= bpt
)
11184 struct breakpoint
*related
;
11186 if (bpt
->type
== bp_watchpoint_scope
)
11187 watchpoint_del_at_next_stop (bpt
->related_breakpoint
);
11188 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11189 watchpoint_del_at_next_stop (bpt
);
11191 /* Unlink bpt from the bpt->related_breakpoint ring. */
11192 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11193 related
= related
->related_breakpoint
);
11194 related
->related_breakpoint
= bpt
->related_breakpoint
;
11195 bpt
->related_breakpoint
= bpt
;
11198 /* watch_command_1 creates a watchpoint but only sets its number if
11199 update_watchpoint succeeds in creating its bp_locations. If there's
11200 a problem in that process, we'll be asked to delete the half-created
11201 watchpoint. In that case, don't announce the deletion. */
11203 observer_notify_breakpoint_deleted (bpt
);
11205 if (breakpoint_chain
== bpt
)
11206 breakpoint_chain
= bpt
->next
;
11208 ALL_BREAKPOINTS (b
)
11209 if (b
->next
== bpt
)
11211 b
->next
= bpt
->next
;
11215 /* Be sure no bpstat's are pointing at the breakpoint after it's
11217 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11218 in all threads for now. Note that we cannot just remove bpstats
11219 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11220 commands are associated with the bpstat; if we remove it here,
11221 then the later call to bpstat_do_actions (&stop_bpstat); in
11222 event-top.c won't do anything, and temporary breakpoints with
11223 commands won't work. */
11225 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11227 /* Now that breakpoint is removed from breakpoint list, update the
11228 global location list. This will remove locations that used to
11229 belong to this breakpoint. Do this before freeing the breakpoint
11230 itself, since remove_breakpoint looks at location's owner. It
11231 might be better design to have location completely
11232 self-contained, but it's not the case now. */
11233 update_global_location_list (0);
11235 bpt
->ops
->dtor (bpt
);
11236 /* On the chance that someone will soon try again to delete this
11237 same bp, we mark it as deleted before freeing its storage. */
11238 bpt
->type
= bp_none
;
11243 do_delete_breakpoint_cleanup (void *b
)
11245 delete_breakpoint (b
);
11249 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11251 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11254 /* Iterator function to call a user-provided callback function once
11255 for each of B and its related breakpoints. */
11258 iterate_over_related_breakpoints (struct breakpoint
*b
,
11259 void (*function
) (struct breakpoint
*,
11263 struct breakpoint
*related
;
11268 struct breakpoint
*next
;
11270 /* FUNCTION may delete RELATED. */
11271 next
= related
->related_breakpoint
;
11273 if (next
== related
)
11275 /* RELATED is the last ring entry. */
11276 function (related
, data
);
11278 /* FUNCTION may have deleted it, so we'd never reach back to
11279 B. There's nothing left to do anyway, so just break
11284 function (related
, data
);
11288 while (related
!= b
);
11292 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11294 delete_breakpoint (b
);
11297 /* A callback for map_breakpoint_numbers that calls
11298 delete_breakpoint. */
11301 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11303 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11307 delete_command (char *arg
, int from_tty
)
11309 struct breakpoint
*b
, *b_tmp
;
11315 int breaks_to_delete
= 0;
11317 /* Delete all breakpoints if no argument. Do not delete
11318 internal breakpoints, these have to be deleted with an
11319 explicit breakpoint number argument. */
11320 ALL_BREAKPOINTS (b
)
11321 if (user_breakpoint_p (b
))
11323 breaks_to_delete
= 1;
11327 /* Ask user only if there are some breakpoints to delete. */
11329 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11331 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11332 if (user_breakpoint_p (b
))
11333 delete_breakpoint (b
);
11337 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11341 all_locations_are_pending (struct bp_location
*loc
)
11343 for (; loc
; loc
= loc
->next
)
11344 if (!loc
->shlib_disabled
)
11349 /* Subroutine of update_breakpoint_locations to simplify it.
11350 Return non-zero if multiple fns in list LOC have the same name.
11351 Null names are ignored. */
11354 ambiguous_names_p (struct bp_location
*loc
)
11356 struct bp_location
*l
;
11357 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11358 (int (*) (const void *,
11359 const void *)) streq
,
11360 NULL
, xcalloc
, xfree
);
11362 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11365 const char *name
= l
->function_name
;
11367 /* Allow for some names to be NULL, ignore them. */
11371 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11373 /* NOTE: We can assume slot != NULL here because xcalloc never
11377 htab_delete (htab
);
11383 htab_delete (htab
);
11387 /* When symbols change, it probably means the sources changed as well,
11388 and it might mean the static tracepoint markers are no longer at
11389 the same address or line numbers they used to be at last we
11390 checked. Losing your static tracepoints whenever you rebuild is
11391 undesirable. This function tries to resync/rematch gdb static
11392 tracepoints with the markers on the target, for static tracepoints
11393 that have not been set by marker id. Static tracepoint that have
11394 been set by marker id are reset by marker id in breakpoint_re_set.
11397 1) For a tracepoint set at a specific address, look for a marker at
11398 the old PC. If one is found there, assume to be the same marker.
11399 If the name / string id of the marker found is different from the
11400 previous known name, assume that means the user renamed the marker
11401 in the sources, and output a warning.
11403 2) For a tracepoint set at a given line number, look for a marker
11404 at the new address of the old line number. If one is found there,
11405 assume to be the same marker. If the name / string id of the
11406 marker found is different from the previous known name, assume that
11407 means the user renamed the marker in the sources, and output a
11410 3) If a marker is no longer found at the same address or line, it
11411 may mean the marker no longer exists. But it may also just mean
11412 the code changed a bit. Maybe the user added a few lines of code
11413 that made the marker move up or down (in line number terms). Ask
11414 the target for info about the marker with the string id as we knew
11415 it. If found, update line number and address in the matching
11416 static tracepoint. This will get confused if there's more than one
11417 marker with the same ID (possible in UST, although unadvised
11418 precisely because it confuses tools). */
11420 static struct symtab_and_line
11421 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11423 struct static_tracepoint_marker marker
;
11429 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11431 if (target_static_tracepoint_marker_at (pc
, &marker
))
11433 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
11434 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11436 b
->static_trace_marker_id
, marker
.str_id
);
11438 xfree (b
->static_trace_marker_id
);
11439 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11440 release_static_tracepoint_marker (&marker
);
11445 /* Old marker wasn't found on target at lineno. Try looking it up
11447 if (!sal
.explicit_pc
11449 && sal
.symtab
!= NULL
11450 && b
->static_trace_marker_id
!= NULL
)
11452 VEC(static_tracepoint_marker_p
) *markers
;
11455 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
11457 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11459 struct symtab_and_line sal
;
11460 struct symbol
*sym
;
11461 struct static_tracepoint_marker
*marker
;
11463 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11465 xfree (b
->static_trace_marker_id
);
11466 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11468 warning (_("marker for static tracepoint %d (%s) not "
11469 "found at previous line number"),
11470 b
->number
, b
->static_trace_marker_id
);
11474 sal
.pc
= marker
->address
;
11476 sal
= find_pc_line (marker
->address
, 0);
11477 sym
= find_pc_sect_function (marker
->address
, NULL
);
11478 ui_out_text (uiout
, "Now in ");
11481 ui_out_field_string (uiout
, "func",
11482 SYMBOL_PRINT_NAME (sym
));
11483 ui_out_text (uiout
, " at ");
11485 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11486 ui_out_text (uiout
, ":");
11488 if (ui_out_is_mi_like_p (uiout
))
11490 char *fullname
= symtab_to_fullname (sal
.symtab
);
11493 ui_out_field_string (uiout
, "fullname", fullname
);
11496 ui_out_field_int (uiout
, "line", sal
.line
);
11497 ui_out_text (uiout
, "\n");
11499 b
->line_number
= sal
.line
;
11501 xfree (b
->source_file
);
11503 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11505 b
->source_file
= NULL
;
11507 xfree (b
->addr_string
);
11508 b
->addr_string
= xstrprintf ("%s:%d",
11509 sal
.symtab
->filename
, b
->line_number
);
11511 /* Might be nice to check if function changed, and warn if
11514 release_static_tracepoint_marker (marker
);
11520 /* Returns 1 iff locations A and B are sufficiently same that
11521 we don't need to report breakpoint as changed. */
11524 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11528 if (a
->address
!= b
->address
)
11531 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11534 if (a
->enabled
!= b
->enabled
)
11541 if ((a
== NULL
) != (b
== NULL
))
11547 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11548 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11549 a ranged breakpoint. */
11552 update_breakpoint_locations (struct breakpoint
*b
,
11553 struct symtabs_and_lines sals
,
11554 struct symtabs_and_lines sals_end
)
11557 struct bp_location
*existing_locations
= b
->loc
;
11559 /* Ranged breakpoints have only one start location and one end location. */
11560 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11562 /* If there's no new locations, and all existing locations are
11563 pending, don't do anything. This optimizes the common case where
11564 all locations are in the same shared library, that was unloaded.
11565 We'd like to retain the location, so that when the library is
11566 loaded again, we don't loose the enabled/disabled status of the
11567 individual locations. */
11568 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11573 for (i
= 0; i
< sals
.nelts
; ++i
)
11575 struct bp_location
*new_loc
=
11576 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11578 /* Reparse conditions, they might contain references to the
11580 if (b
->cond_string
!= NULL
)
11583 struct gdb_exception e
;
11585 s
= b
->cond_string
;
11586 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11588 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11593 warning (_("failed to reevaluate condition "
11594 "for breakpoint %d: %s"),
11595 b
->number
, e
.message
);
11596 new_loc
->enabled
= 0;
11600 if (b
->source_file
!= NULL
)
11601 xfree (b
->source_file
);
11602 if (sals
.sals
[i
].symtab
== NULL
)
11603 b
->source_file
= NULL
;
11605 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11607 if (b
->line_number
== 0)
11608 b
->line_number
= sals
.sals
[i
].line
;
11610 if (sals_end
.nelts
)
11612 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11614 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11618 /* Update locations of permanent breakpoints. */
11619 if (b
->enable_state
== bp_permanent
)
11620 make_breakpoint_permanent (b
);
11622 /* If possible, carry over 'disable' status from existing
11625 struct bp_location
*e
= existing_locations
;
11626 /* If there are multiple breakpoints with the same function name,
11627 e.g. for inline functions, comparing function names won't work.
11628 Instead compare pc addresses; this is just a heuristic as things
11629 may have moved, but in practice it gives the correct answer
11630 often enough until a better solution is found. */
11631 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11633 for (; e
; e
= e
->next
)
11635 if (!e
->enabled
&& e
->function_name
)
11637 struct bp_location
*l
= b
->loc
;
11638 if (have_ambiguous_names
)
11640 for (; l
; l
= l
->next
)
11641 if (breakpoint_locations_match (e
, l
))
11649 for (; l
; l
= l
->next
)
11650 if (l
->function_name
11651 && strcmp (e
->function_name
, l
->function_name
) == 0)
11661 if (!locations_are_equal (existing_locations
, b
->loc
))
11662 observer_notify_breakpoint_modified (b
);
11664 update_global_location_list (1);
11667 /* Find the SaL locations corresponding to the given ADDR_STRING.
11668 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11670 static struct symtabs_and_lines
11671 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11675 struct symtabs_and_lines sals
= {0};
11676 struct gdb_exception e
;
11679 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11681 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11685 sals
= decode_static_tracepoint_spec (&s
);
11686 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
11688 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
11692 error (_("marker %s not found"), b
->static_trace_marker_id
);
11695 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11699 int not_found_and_ok
= 0;
11700 /* For pending breakpoints, it's expected that parsing will
11701 fail until the right shared library is loaded. User has
11702 already told to create pending breakpoints and don't need
11703 extra messages. If breakpoint is in bp_shlib_disabled
11704 state, then user already saw the message about that
11705 breakpoint being disabled, and don't want to see more
11707 if (e
.error
== NOT_FOUND_ERROR
11708 && (b
->condition_not_parsed
11709 || (b
->loc
&& b
->loc
->shlib_disabled
)
11710 || b
->enable_state
== bp_disabled
))
11711 not_found_and_ok
= 1;
11713 if (!not_found_and_ok
)
11715 /* We surely don't want to warn about the same breakpoint
11716 10 times. One solution, implemented here, is disable
11717 the breakpoint on error. Another solution would be to
11718 have separate 'warning emitted' flag. Since this
11719 happens only when a binary has changed, I don't know
11720 which approach is better. */
11721 b
->enable_state
= bp_disabled
;
11722 throw_exception (e
);
11726 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11728 gdb_assert (sals
.nelts
== 1);
11730 resolve_sal_pc (&sals
.sals
[0]);
11731 if (b
->condition_not_parsed
&& s
&& s
[0])
11733 char *cond_string
= 0;
11737 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11738 &cond_string
, &thread
, &task
);
11740 b
->cond_string
= cond_string
;
11741 b
->thread
= thread
;
11743 b
->condition_not_parsed
= 0;
11746 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11747 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11757 /* The default re_set method, for typical hardware or software
11758 breakpoints. Reevaluate the breakpoint and recreate its
11762 breakpoint_re_set_default (struct breakpoint
*b
)
11765 struct symtabs_and_lines sals
, sals_end
;
11766 struct symtabs_and_lines expanded
= {0};
11767 struct symtabs_and_lines expanded_end
= {0};
11769 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11772 make_cleanup (xfree
, sals
.sals
);
11773 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
11776 if (b
->addr_string_range_end
)
11778 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11781 make_cleanup (xfree
, sals_end
.sals
);
11782 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
11786 update_breakpoint_locations (b
, expanded
, expanded_end
);
11789 /* Prepare the global context for a re-set of breakpoint B. */
11791 static struct cleanup
*
11792 prepare_re_set_context (struct breakpoint
*b
)
11794 struct cleanup
*cleanups
;
11796 input_radix
= b
->input_radix
;
11797 cleanups
= save_current_space_and_thread ();
11798 switch_to_program_space_and_thread (b
->pspace
);
11799 set_language (b
->language
);
11804 /* Reset a breakpoint given it's struct breakpoint * BINT.
11805 The value we return ends up being the return value from catch_errors.
11806 Unused in this case. */
11809 breakpoint_re_set_one (void *bint
)
11811 /* Get past catch_errs. */
11812 struct breakpoint
*b
= (struct breakpoint
*) bint
;
11813 struct cleanup
*cleanups
;
11815 cleanups
= prepare_re_set_context (b
);
11816 b
->ops
->re_set (b
);
11817 do_cleanups (cleanups
);
11821 /* Re-set all breakpoints after symbols have been re-loaded. */
11823 breakpoint_re_set (void)
11825 struct breakpoint
*b
, *b_tmp
;
11826 enum language save_language
;
11827 int save_input_radix
;
11828 struct cleanup
*old_chain
;
11830 save_language
= current_language
->la_language
;
11831 save_input_radix
= input_radix
;
11832 old_chain
= save_current_program_space ();
11834 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11836 /* Format possible error msg. */
11837 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
11839 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
11840 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
11841 do_cleanups (cleanups
);
11843 set_language (save_language
);
11844 input_radix
= save_input_radix
;
11846 jit_breakpoint_re_set ();
11848 do_cleanups (old_chain
);
11850 create_overlay_event_breakpoint ();
11851 create_longjmp_master_breakpoint ();
11852 create_std_terminate_master_breakpoint ();
11853 create_exception_master_breakpoint ();
11856 /* Reset the thread number of this breakpoint:
11858 - If the breakpoint is for all threads, leave it as-is.
11859 - Else, reset it to the current thread for inferior_ptid. */
11861 breakpoint_re_set_thread (struct breakpoint
*b
)
11863 if (b
->thread
!= -1)
11865 if (in_thread_list (inferior_ptid
))
11866 b
->thread
= pid_to_thread_id (inferior_ptid
);
11868 /* We're being called after following a fork. The new fork is
11869 selected as current, and unless this was a vfork will have a
11870 different program space from the original thread. Reset that
11872 b
->loc
->pspace
= current_program_space
;
11876 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11877 If from_tty is nonzero, it prints a message to that effect,
11878 which ends with a period (no newline). */
11881 set_ignore_count (int bptnum
, int count
, int from_tty
)
11883 struct breakpoint
*b
;
11888 ALL_BREAKPOINTS (b
)
11889 if (b
->number
== bptnum
)
11891 if (is_tracepoint (b
))
11893 if (from_tty
&& count
!= 0)
11894 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11899 b
->ignore_count
= count
;
11903 printf_filtered (_("Will stop next time "
11904 "breakpoint %d is reached."),
11906 else if (count
== 1)
11907 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11910 printf_filtered (_("Will ignore next %d "
11911 "crossings of breakpoint %d."),
11914 breakpoints_changed ();
11915 observer_notify_breakpoint_modified (b
);
11919 error (_("No breakpoint number %d."), bptnum
);
11922 /* Command to set ignore-count of breakpoint N to COUNT. */
11925 ignore_command (char *args
, int from_tty
)
11931 error_no_arg (_("a breakpoint number"));
11933 num
= get_number (&p
);
11935 error (_("bad breakpoint number: '%s'"), args
);
11937 error (_("Second argument (specified ignore-count) is missing."));
11939 set_ignore_count (num
,
11940 longest_to_int (value_as_long (parse_and_eval (p
))),
11943 printf_filtered ("\n");
11946 /* Call FUNCTION on each of the breakpoints
11947 whose numbers are given in ARGS. */
11950 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
11955 struct breakpoint
*b
, *tmp
;
11957 struct get_number_or_range_state state
;
11960 error_no_arg (_("one or more breakpoint numbers"));
11962 init_number_or_range (&state
, args
);
11964 while (!state
.finished
)
11966 char *p
= state
.string
;
11970 num
= get_number_or_range (&state
);
11973 warning (_("bad breakpoint number at or near '%s'"), p
);
11977 ALL_BREAKPOINTS_SAFE (b
, tmp
)
11978 if (b
->number
== num
)
11981 function (b
, data
);
11985 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
11990 static struct bp_location
*
11991 find_location_by_number (char *number
)
11993 char *dot
= strchr (number
, '.');
11997 struct breakpoint
*b
;
11998 struct bp_location
*loc
;
12003 bp_num
= get_number (&p1
);
12005 error (_("Bad breakpoint number '%s'"), number
);
12007 ALL_BREAKPOINTS (b
)
12008 if (b
->number
== bp_num
)
12013 if (!b
|| b
->number
!= bp_num
)
12014 error (_("Bad breakpoint number '%s'"), number
);
12017 loc_num
= get_number (&p1
);
12019 error (_("Bad breakpoint location number '%s'"), number
);
12023 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12026 error (_("Bad breakpoint location number '%s'"), dot
+1);
12032 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12033 If from_tty is nonzero, it prints a message to that effect,
12034 which ends with a period (no newline). */
12037 disable_breakpoint (struct breakpoint
*bpt
)
12039 /* Never disable a watchpoint scope breakpoint; we want to
12040 hit them when we leave scope so we can delete both the
12041 watchpoint and its scope breakpoint at that time. */
12042 if (bpt
->type
== bp_watchpoint_scope
)
12045 /* You can't disable permanent breakpoints. */
12046 if (bpt
->enable_state
== bp_permanent
)
12049 bpt
->enable_state
= bp_disabled
;
12051 if (target_supports_enable_disable_tracepoint ()
12052 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12054 struct bp_location
*location
;
12056 for (location
= bpt
->loc
; location
; location
= location
->next
)
12057 target_disable_tracepoint (location
);
12060 update_global_location_list (0);
12062 observer_notify_breakpoint_modified (bpt
);
12065 /* A callback for iterate_over_related_breakpoints. */
12068 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12070 disable_breakpoint (b
);
12073 /* A callback for map_breakpoint_numbers that calls
12074 disable_breakpoint. */
12077 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12079 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12083 disable_command (char *args
, int from_tty
)
12087 struct breakpoint
*bpt
;
12089 ALL_BREAKPOINTS (bpt
)
12090 if (user_breakpoint_p (bpt
))
12091 disable_breakpoint (bpt
);
12093 else if (strchr (args
, '.'))
12095 struct bp_location
*loc
= find_location_by_number (args
);
12099 if (target_supports_enable_disable_tracepoint ()
12100 && current_trace_status ()->running
&& loc
->owner
12101 && is_tracepoint (loc
->owner
))
12102 target_disable_tracepoint (loc
);
12104 update_global_location_list (0);
12107 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12111 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12113 int target_resources_ok
;
12115 if (bpt
->type
== bp_hardware_breakpoint
)
12118 i
= hw_breakpoint_used_count ();
12119 target_resources_ok
=
12120 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12122 if (target_resources_ok
== 0)
12123 error (_("No hardware breakpoint support in the target."));
12124 else if (target_resources_ok
< 0)
12125 error (_("Hardware breakpoints used exceeds limit."));
12128 if (is_watchpoint (bpt
))
12130 /* Initialize it just to avoid a GCC false warning. */
12131 enum enable_state orig_enable_state
= 0;
12132 struct gdb_exception e
;
12134 TRY_CATCH (e
, RETURN_MASK_ALL
)
12136 orig_enable_state
= bpt
->enable_state
;
12137 bpt
->enable_state
= bp_enabled
;
12138 update_watchpoint (bpt
, 1 /* reparse */);
12142 bpt
->enable_state
= orig_enable_state
;
12143 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12149 if (bpt
->enable_state
!= bp_permanent
)
12150 bpt
->enable_state
= bp_enabled
;
12152 if (target_supports_enable_disable_tracepoint ()
12153 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12155 struct bp_location
*location
;
12157 for (location
= bpt
->loc
; location
; location
= location
->next
)
12158 target_enable_tracepoint (location
);
12161 bpt
->disposition
= disposition
;
12162 update_global_location_list (1);
12163 breakpoints_changed ();
12165 observer_notify_breakpoint_modified (bpt
);
12170 enable_breakpoint (struct breakpoint
*bpt
)
12172 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12176 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12178 enable_breakpoint (bpt
);
12181 /* A callback for map_breakpoint_numbers that calls
12182 enable_breakpoint. */
12185 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12187 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12190 /* The enable command enables the specified breakpoints (or all defined
12191 breakpoints) so they once again become (or continue to be) effective
12192 in stopping the inferior. */
12195 enable_command (char *args
, int from_tty
)
12199 struct breakpoint
*bpt
;
12201 ALL_BREAKPOINTS (bpt
)
12202 if (user_breakpoint_p (bpt
))
12203 enable_breakpoint (bpt
);
12205 else if (strchr (args
, '.'))
12207 struct bp_location
*loc
= find_location_by_number (args
);
12211 if (target_supports_enable_disable_tracepoint ()
12212 && current_trace_status ()->running
&& loc
->owner
12213 && is_tracepoint (loc
->owner
))
12214 target_enable_tracepoint (loc
);
12216 update_global_location_list (1);
12219 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12223 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12225 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12227 enable_breakpoint_disp (bpt
, disp
);
12231 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12233 enum bpdisp disp
= disp_disable
;
12235 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12239 enable_once_command (char *args
, int from_tty
)
12241 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12245 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12247 enum bpdisp disp
= disp_del
;
12249 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12253 enable_delete_command (char *args
, int from_tty
)
12255 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12259 set_breakpoint_cmd (char *args
, int from_tty
)
12264 show_breakpoint_cmd (char *args
, int from_tty
)
12268 /* Invalidate last known value of any hardware watchpoint if
12269 the memory which that value represents has been written to by
12273 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12274 const bfd_byte
*data
)
12276 struct breakpoint
*bp
;
12278 ALL_BREAKPOINTS (bp
)
12279 if (bp
->enable_state
== bp_enabled
12280 && bp
->type
== bp_hardware_watchpoint
12281 && bp
->val_valid
&& bp
->val
)
12283 struct bp_location
*loc
;
12285 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12286 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12287 && loc
->address
+ loc
->length
> addr
12288 && addr
+ len
> loc
->address
)
12290 value_free (bp
->val
);
12297 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12299 struct symtabs_and_lines
12300 decode_line_spec_1 (char *string
, int funfirstline
)
12302 struct symtabs_and_lines sals
;
12305 error (_("Empty line specification."));
12306 if (default_breakpoint_valid
)
12307 sals
= decode_line_1 (&string
, funfirstline
,
12308 default_breakpoint_symtab
,
12309 default_breakpoint_line
,
12312 sals
= decode_line_1 (&string
, funfirstline
,
12313 (struct symtab
*) NULL
, 0, NULL
);
12315 error (_("Junk at end of line specification: %s"), string
);
12319 /* Create and insert a raw software breakpoint at PC. Return an
12320 identifier, which should be used to remove the breakpoint later.
12321 In general, places which call this should be using something on the
12322 breakpoint chain instead; this function should be eliminated
12326 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12327 struct address_space
*aspace
, CORE_ADDR pc
)
12329 struct bp_target_info
*bp_tgt
;
12331 bp_tgt
= XZALLOC (struct bp_target_info
);
12333 bp_tgt
->placed_address_space
= aspace
;
12334 bp_tgt
->placed_address
= pc
;
12336 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12338 /* Could not insert the breakpoint. */
12346 /* Remove a breakpoint BP inserted by
12347 deprecated_insert_raw_breakpoint. */
12350 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12352 struct bp_target_info
*bp_tgt
= bp
;
12355 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12361 /* One (or perhaps two) breakpoints used for software single
12364 static void *single_step_breakpoints
[2];
12365 static struct gdbarch
*single_step_gdbarch
[2];
12367 /* Create and insert a breakpoint for software single step. */
12370 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12371 struct address_space
*aspace
,
12376 if (single_step_breakpoints
[0] == NULL
)
12378 bpt_p
= &single_step_breakpoints
[0];
12379 single_step_gdbarch
[0] = gdbarch
;
12383 gdb_assert (single_step_breakpoints
[1] == NULL
);
12384 bpt_p
= &single_step_breakpoints
[1];
12385 single_step_gdbarch
[1] = gdbarch
;
12388 /* NOTE drow/2006-04-11: A future improvement to this function would
12389 be to only create the breakpoints once, and actually put them on
12390 the breakpoint chain. That would let us use set_raw_breakpoint.
12391 We could adjust the addresses each time they were needed. Doing
12392 this requires corresponding changes elsewhere where single step
12393 breakpoints are handled, however. So, for now, we use this. */
12395 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12396 if (*bpt_p
== NULL
)
12397 error (_("Could not insert single-step breakpoint at %s"),
12398 paddress (gdbarch
, next_pc
));
12401 /* Check if the breakpoints used for software single stepping
12402 were inserted or not. */
12405 single_step_breakpoints_inserted (void)
12407 return (single_step_breakpoints
[0] != NULL
12408 || single_step_breakpoints
[1] != NULL
);
12411 /* Remove and delete any breakpoints used for software single step. */
12414 remove_single_step_breakpoints (void)
12416 gdb_assert (single_step_breakpoints
[0] != NULL
);
12418 /* See insert_single_step_breakpoint for more about this deprecated
12420 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12421 single_step_breakpoints
[0]);
12422 single_step_gdbarch
[0] = NULL
;
12423 single_step_breakpoints
[0] = NULL
;
12425 if (single_step_breakpoints
[1] != NULL
)
12427 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12428 single_step_breakpoints
[1]);
12429 single_step_gdbarch
[1] = NULL
;
12430 single_step_breakpoints
[1] = NULL
;
12434 /* Delete software single step breakpoints without removing them from
12435 the inferior. This is intended to be used if the inferior's address
12436 space where they were inserted is already gone, e.g. after exit or
12440 cancel_single_step_breakpoints (void)
12444 for (i
= 0; i
< 2; i
++)
12445 if (single_step_breakpoints
[i
])
12447 xfree (single_step_breakpoints
[i
]);
12448 single_step_breakpoints
[i
] = NULL
;
12449 single_step_gdbarch
[i
] = NULL
;
12453 /* Detach software single-step breakpoints from INFERIOR_PTID without
12457 detach_single_step_breakpoints (void)
12461 for (i
= 0; i
< 2; i
++)
12462 if (single_step_breakpoints
[i
])
12463 target_remove_breakpoint (single_step_gdbarch
[i
],
12464 single_step_breakpoints
[i
]);
12467 /* Check whether a software single-step breakpoint is inserted at
12471 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12476 for (i
= 0; i
< 2; i
++)
12478 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12480 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12481 bp_tgt
->placed_address
,
12489 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12490 non-zero otherwise. */
12492 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12494 if (syscall_catchpoint_p (bp
)
12495 && bp
->enable_state
!= bp_disabled
12496 && bp
->enable_state
!= bp_call_disabled
)
12503 catch_syscall_enabled (void)
12505 struct inferior
*inf
= current_inferior ();
12507 return inf
->total_syscalls_count
!= 0;
12511 catching_syscall_number (int syscall_number
)
12513 struct breakpoint
*bp
;
12515 ALL_BREAKPOINTS (bp
)
12516 if (is_syscall_catchpoint_enabled (bp
))
12518 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12520 if (c
->syscalls_to_be_caught
)
12524 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12526 if (syscall_number
== iter
)
12536 /* Complete syscall names. Used by "catch syscall". */
12538 catch_syscall_completer (struct cmd_list_element
*cmd
,
12539 char *text
, char *word
)
12541 const char **list
= get_syscall_names ();
12543 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12549 /* Tracepoint-specific operations. */
12551 /* Set tracepoint count to NUM. */
12553 set_tracepoint_count (int num
)
12555 tracepoint_count
= num
;
12556 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12560 trace_command (char *arg
, int from_tty
)
12562 if (create_breakpoint (get_current_arch (),
12564 NULL
, 0, 1 /* parse arg */,
12566 bp_tracepoint
/* type_wanted */,
12567 0 /* Ignore count */,
12568 pending_break_support
,
12569 &tracepoint_breakpoint_ops
,
12573 set_tracepoint_count (breakpoint_count
);
12577 ftrace_command (char *arg
, int from_tty
)
12579 if (create_breakpoint (get_current_arch (),
12581 NULL
, 0, 1 /* parse arg */,
12583 bp_fast_tracepoint
/* type_wanted */,
12584 0 /* Ignore count */,
12585 pending_break_support
,
12586 &tracepoint_breakpoint_ops
,
12590 set_tracepoint_count (breakpoint_count
);
12593 /* strace command implementation. Creates a static tracepoint. */
12596 strace_command (char *arg
, int from_tty
)
12598 if (create_breakpoint (get_current_arch (),
12600 NULL
, 0, 1 /* parse arg */,
12602 bp_static_tracepoint
/* type_wanted */,
12603 0 /* Ignore count */,
12604 pending_break_support
,
12605 &tracepoint_breakpoint_ops
,
12609 set_tracepoint_count (breakpoint_count
);
12612 /* Set up a fake reader function that gets command lines from a linked
12613 list that was acquired during tracepoint uploading. */
12615 static struct uploaded_tp
*this_utp
;
12616 static int next_cmd
;
12619 read_uploaded_action (void)
12623 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12630 /* Given information about a tracepoint as recorded on a target (which
12631 can be either a live system or a trace file), attempt to create an
12632 equivalent GDB tracepoint. This is not a reliable process, since
12633 the target does not necessarily have all the information used when
12634 the tracepoint was originally defined. */
12636 struct breakpoint
*
12637 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12639 char *addr_str
, small_buf
[100];
12640 struct breakpoint
*tp
;
12642 if (utp
->at_string
)
12643 addr_str
= utp
->at_string
;
12646 /* In the absence of a source location, fall back to raw
12647 address. Since there is no way to confirm that the address
12648 means the same thing as when the trace was started, warn the
12650 warning (_("Uploaded tracepoint %d has no "
12651 "source location, using raw address"),
12653 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12654 addr_str
= small_buf
;
12657 /* There's not much we can do with a sequence of bytecodes. */
12658 if (utp
->cond
&& !utp
->cond_string
)
12659 warning (_("Uploaded tracepoint %d condition "
12660 "has no source form, ignoring it"),
12663 if (!create_breakpoint (get_current_arch (),
12665 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12667 utp
->type
/* type_wanted */,
12668 0 /* Ignore count */,
12669 pending_break_support
,
12670 &tracepoint_breakpoint_ops
,
12672 utp
->enabled
/* enabled */,
12676 set_tracepoint_count (breakpoint_count
);
12678 /* Get the tracepoint we just created. */
12679 tp
= get_tracepoint (tracepoint_count
);
12680 gdb_assert (tp
!= NULL
);
12684 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
12686 trace_pass_command (small_buf
, 0);
12689 /* If we have uploaded versions of the original commands, set up a
12690 special-purpose "reader" function and call the usual command line
12691 reader, then pass the result to the breakpoint command-setting
12693 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12695 struct command_line
*cmd_list
;
12700 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12702 breakpoint_set_commands (tp
, cmd_list
);
12704 else if (!VEC_empty (char_ptr
, utp
->actions
)
12705 || !VEC_empty (char_ptr
, utp
->step_actions
))
12706 warning (_("Uploaded tracepoint %d actions "
12707 "have no source form, ignoring them"),
12713 /* Print information on tracepoint number TPNUM_EXP, or all if
12717 tracepoints_info (char *args
, int from_tty
)
12721 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12723 if (num_printed
== 0)
12725 if (args
== NULL
|| *args
== '\0')
12726 ui_out_message (uiout
, 0, "No tracepoints.\n");
12728 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12731 default_collect_info ();
12734 /* The 'enable trace' command enables tracepoints.
12735 Not supported by all targets. */
12737 enable_trace_command (char *args
, int from_tty
)
12739 enable_command (args
, from_tty
);
12742 /* The 'disable trace' command disables tracepoints.
12743 Not supported by all targets. */
12745 disable_trace_command (char *args
, int from_tty
)
12747 disable_command (args
, from_tty
);
12750 /* Remove a tracepoint (or all if no argument). */
12752 delete_trace_command (char *arg
, int from_tty
)
12754 struct breakpoint
*b
, *b_tmp
;
12760 int breaks_to_delete
= 0;
12762 /* Delete all breakpoints if no argument.
12763 Do not delete internal or call-dummy breakpoints, these
12764 have to be deleted with an explicit breakpoint number
12766 ALL_TRACEPOINTS (b
)
12767 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12769 breaks_to_delete
= 1;
12773 /* Ask user only if there are some breakpoints to delete. */
12775 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12777 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12778 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12779 delete_breakpoint (b
);
12783 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12786 /* Helper function for trace_pass_command. */
12789 trace_pass_set_count (struct breakpoint
*bp
, int count
, int from_tty
)
12791 bp
->pass_count
= count
;
12792 observer_notify_tracepoint_modified (bp
->number
);
12794 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12795 bp
->number
, count
);
12798 /* Set passcount for tracepoint.
12800 First command argument is passcount, second is tracepoint number.
12801 If tracepoint number omitted, apply to most recently defined.
12802 Also accepts special argument "all". */
12805 trace_pass_command (char *args
, int from_tty
)
12807 struct breakpoint
*t1
;
12808 unsigned int count
;
12810 if (args
== 0 || *args
== 0)
12811 error (_("passcount command requires an "
12812 "argument (count + optional TP num)"));
12814 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
12816 while (*args
&& isspace ((int) *args
))
12819 if (*args
&& strncasecmp (args
, "all", 3) == 0)
12821 args
+= 3; /* Skip special argument "all". */
12823 error (_("Junk at end of arguments."));
12825 ALL_TRACEPOINTS (t1
)
12827 trace_pass_set_count (t1
, count
, from_tty
);
12830 else if (*args
== '\0')
12832 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
12834 trace_pass_set_count (t1
, count
, from_tty
);
12838 struct get_number_or_range_state state
;
12840 init_number_or_range (&state
, args
);
12841 while (!state
.finished
)
12843 t1
= get_tracepoint_by_number (&args
, &state
, 1);
12845 trace_pass_set_count (t1
, count
, from_tty
);
12850 struct breakpoint
*
12851 get_tracepoint (int num
)
12853 struct breakpoint
*t
;
12855 ALL_TRACEPOINTS (t
)
12856 if (t
->number
== num
)
12862 /* Find the tracepoint with the given target-side number (which may be
12863 different from the tracepoint number after disconnecting and
12866 struct breakpoint
*
12867 get_tracepoint_by_number_on_target (int num
)
12869 struct breakpoint
*t
;
12871 ALL_TRACEPOINTS (t
)
12872 if (t
->number_on_target
== num
)
12878 /* Utility: parse a tracepoint number and look it up in the list.
12879 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12880 If OPTIONAL_P is true, then if the argument is missing, the most
12881 recent tracepoint (tracepoint_count) is returned. */
12882 struct breakpoint
*
12883 get_tracepoint_by_number (char **arg
,
12884 struct get_number_or_range_state
*state
,
12887 extern int tracepoint_count
;
12888 struct breakpoint
*t
;
12890 char *instring
= arg
== NULL
? NULL
: *arg
;
12894 gdb_assert (!state
->finished
);
12895 tpnum
= get_number_or_range (state
);
12897 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
12900 tpnum
= tracepoint_count
;
12902 error_no_arg (_("tracepoint number"));
12905 tpnum
= get_number (arg
);
12909 if (instring
&& *instring
)
12910 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12913 printf_filtered (_("Tracepoint argument missing "
12914 "and no previous tracepoint\n"));
12918 ALL_TRACEPOINTS (t
)
12919 if (t
->number
== tpnum
)
12924 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
12928 /* Save information on user settable breakpoints (watchpoints, etc) to
12929 a new script file named FILENAME. If FILTER is non-NULL, call it
12930 on each breakpoint and only include the ones for which it returns
12934 save_breakpoints (char *filename
, int from_tty
,
12935 int (*filter
) (const struct breakpoint
*))
12937 struct breakpoint
*tp
;
12940 struct cleanup
*cleanup
;
12941 struct ui_file
*fp
;
12942 int extra_trace_bits
= 0;
12944 if (filename
== 0 || *filename
== 0)
12945 error (_("Argument required (file name in which to save)"));
12947 /* See if we have anything to save. */
12948 ALL_BREAKPOINTS (tp
)
12950 /* Skip internal and momentary breakpoints. */
12951 if (!user_breakpoint_p (tp
))
12954 /* If we have a filter, only save the breakpoints it accepts. */
12955 if (filter
&& !filter (tp
))
12960 if (is_tracepoint (tp
))
12962 extra_trace_bits
= 1;
12964 /* We can stop searching. */
12971 warning (_("Nothing to save."));
12975 pathname
= tilde_expand (filename
);
12976 cleanup
= make_cleanup (xfree
, pathname
);
12977 fp
= gdb_fopen (pathname
, "w");
12979 error (_("Unable to open file '%s' for saving (%s)"),
12980 filename
, safe_strerror (errno
));
12981 make_cleanup_ui_file_delete (fp
);
12983 if (extra_trace_bits
)
12984 save_trace_state_variables (fp
);
12986 ALL_BREAKPOINTS (tp
)
12988 /* Skip internal and momentary breakpoints. */
12989 if (!user_breakpoint_p (tp
))
12992 /* If we have a filter, only save the breakpoints it accepts. */
12993 if (filter
&& !filter (tp
))
12996 tp
->ops
->print_recreate (tp
, fp
);
12998 if (tp
->thread
!= -1)
12999 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
13002 fprintf_unfiltered (fp
, " task %d", tp
->task
);
13004 fprintf_unfiltered (fp
, "\n");
13006 /* Note, we can't rely on tp->number for anything, as we can't
13007 assume the recreated breakpoint numbers will match. Use $bpnum
13010 if (tp
->cond_string
)
13011 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13013 if (tp
->ignore_count
)
13014 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13016 if (tp
->pass_count
)
13017 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13021 volatile struct gdb_exception ex
;
13023 fprintf_unfiltered (fp
, " commands\n");
13025 ui_out_redirect (uiout
, fp
);
13026 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13028 print_command_lines (uiout
, tp
->commands
->commands
, 2);
13030 ui_out_redirect (uiout
, NULL
);
13033 throw_exception (ex
);
13035 fprintf_unfiltered (fp
, " end\n");
13038 if (tp
->enable_state
== bp_disabled
)
13039 fprintf_unfiltered (fp
, "disable\n");
13041 /* If this is a multi-location breakpoint, check if the locations
13042 should be individually disabled. Watchpoint locations are
13043 special, and not user visible. */
13044 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13046 struct bp_location
*loc
;
13049 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13051 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13055 if (extra_trace_bits
&& *default_collect
)
13056 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13058 do_cleanups (cleanup
);
13060 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13063 /* The `save breakpoints' command. */
13066 save_breakpoints_command (char *args
, int from_tty
)
13068 save_breakpoints (args
, from_tty
, NULL
);
13071 /* The `save tracepoints' command. */
13074 save_tracepoints_command (char *args
, int from_tty
)
13076 save_breakpoints (args
, from_tty
, is_tracepoint
);
13079 /* Create a vector of all tracepoints. */
13081 VEC(breakpoint_p
) *
13082 all_tracepoints (void)
13084 VEC(breakpoint_p
) *tp_vec
= 0;
13085 struct breakpoint
*tp
;
13087 ALL_TRACEPOINTS (tp
)
13089 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13096 /* This help string is used for the break, hbreak, tbreak and thbreak
13097 commands. It is defined as a macro to prevent duplication.
13098 COMMAND should be a string constant containing the name of the
13100 #define BREAK_ARGS_HELP(command) \
13101 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13102 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13103 If a line number is specified, break at start of code for that line.\n\
13104 If a function is specified, break at start of code for that function.\n\
13105 If an address is specified, break at that exact address.\n\
13106 With no LOCATION, uses current execution address of the selected\n\
13107 stack frame. This is useful for breaking on return to a stack frame.\n\
13109 THREADNUM is the number from \"info threads\".\n\
13110 CONDITION is a boolean expression.\n\
13112 Multiple breakpoints at one place are permitted, and useful if their\n\
13113 conditions are different.\n\
13115 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13117 /* List of subcommands for "catch". */
13118 static struct cmd_list_element
*catch_cmdlist
;
13120 /* List of subcommands for "tcatch". */
13121 static struct cmd_list_element
*tcatch_cmdlist
;
13124 add_catch_command (char *name
, char *docstring
,
13125 void (*sfunc
) (char *args
, int from_tty
,
13126 struct cmd_list_element
*command
),
13127 char **(*completer
) (struct cmd_list_element
*cmd
,
13128 char *text
, char *word
),
13129 void *user_data_catch
,
13130 void *user_data_tcatch
)
13132 struct cmd_list_element
*command
;
13134 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13136 set_cmd_sfunc (command
, sfunc
);
13137 set_cmd_context (command
, user_data_catch
);
13138 set_cmd_completer (command
, completer
);
13140 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13142 set_cmd_sfunc (command
, sfunc
);
13143 set_cmd_context (command
, user_data_tcatch
);
13144 set_cmd_completer (command
, completer
);
13148 clear_syscall_counts (struct inferior
*inf
)
13150 inf
->total_syscalls_count
= 0;
13151 inf
->any_syscall_count
= 0;
13152 VEC_free (int, inf
->syscalls_counts
);
13156 save_command (char *arg
, int from_tty
)
13158 printf_unfiltered (_("\"save\" must be followed by "
13159 "the name of a save subcommand.\n"));
13160 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13163 struct breakpoint
*
13164 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13167 struct breakpoint
*b
, *b_tmp
;
13169 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13171 if ((*callback
) (b
, data
))
13179 _initialize_breakpoint (void)
13181 struct cmd_list_element
*c
;
13183 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13184 observer_attach_inferior_exit (clear_syscall_counts
);
13185 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13187 breakpoint_objfile_key
= register_objfile_data ();
13189 breakpoint_chain
= 0;
13190 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13191 before a breakpoint is set. */
13192 breakpoint_count
= 0;
13194 tracepoint_count
= 0;
13196 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13197 Set ignore-count of breakpoint number N to COUNT.\n\
13198 Usage is `ignore N COUNT'."));
13200 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13202 add_com ("commands", class_breakpoint
, commands_command
, _("\
13203 Set commands to be executed when a breakpoint is hit.\n\
13204 Give breakpoint number as argument after \"commands\".\n\
13205 With no argument, the targeted breakpoint is the last one set.\n\
13206 The commands themselves follow starting on the next line.\n\
13207 Type a line containing \"end\" to indicate the end of them.\n\
13208 Give \"silent\" as the first line to make the breakpoint silent;\n\
13209 then no output is printed when it is hit, except what the commands print."));
13211 add_com ("condition", class_breakpoint
, condition_command
, _("\
13212 Specify breakpoint number N to break only if COND is true.\n\
13213 Usage is `condition N COND', where N is an integer and COND is an\n\
13214 expression to be evaluated whenever breakpoint N is reached."));
13216 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13217 Set a temporary breakpoint.\n\
13218 Like \"break\" except the breakpoint is only temporary,\n\
13219 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13220 by using \"enable delete\" on the breakpoint number.\n\
13222 BREAK_ARGS_HELP ("tbreak")));
13223 set_cmd_completer (c
, location_completer
);
13225 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13226 Set a hardware assisted breakpoint.\n\
13227 Like \"break\" except the breakpoint requires hardware support,\n\
13228 some target hardware may not have this support.\n\
13230 BREAK_ARGS_HELP ("hbreak")));
13231 set_cmd_completer (c
, location_completer
);
13233 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13234 Set a temporary hardware assisted breakpoint.\n\
13235 Like \"hbreak\" except the breakpoint is only temporary,\n\
13236 so it will be deleted when hit.\n\
13238 BREAK_ARGS_HELP ("thbreak")));
13239 set_cmd_completer (c
, location_completer
);
13241 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13242 Enable some breakpoints.\n\
13243 Give breakpoint numbers (separated by spaces) as arguments.\n\
13244 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13245 This is used to cancel the effect of the \"disable\" command.\n\
13246 With a subcommand you can enable temporarily."),
13247 &enablelist
, "enable ", 1, &cmdlist
);
13249 add_com ("ab", class_breakpoint
, enable_command
, _("\
13250 Enable some breakpoints.\n\
13251 Give breakpoint numbers (separated by spaces) as arguments.\n\
13252 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13253 This is used to cancel the effect of the \"disable\" command.\n\
13254 With a subcommand you can enable temporarily."));
13256 add_com_alias ("en", "enable", class_breakpoint
, 1);
13258 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13259 Enable some breakpoints.\n\
13260 Give breakpoint numbers (separated by spaces) as arguments.\n\
13261 This is used to cancel the effect of the \"disable\" command.\n\
13262 May be abbreviated to simply \"enable\".\n"),
13263 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13265 add_cmd ("once", no_class
, enable_once_command
, _("\
13266 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13267 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13270 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13271 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13272 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13275 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13276 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13277 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13280 add_cmd ("once", no_class
, enable_once_command
, _("\
13281 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13282 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13285 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13286 Disable some breakpoints.\n\
13287 Arguments are breakpoint numbers with spaces in between.\n\
13288 To disable all breakpoints, give no argument.\n\
13289 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13290 &disablelist
, "disable ", 1, &cmdlist
);
13291 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13292 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13294 add_com ("sb", class_breakpoint
, disable_command
, _("\
13295 Disable some breakpoints.\n\
13296 Arguments are breakpoint numbers with spaces in between.\n\
13297 To disable all breakpoints, give no argument.\n\
13298 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13300 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13301 Disable some breakpoints.\n\
13302 Arguments are breakpoint numbers with spaces in between.\n\
13303 To disable all breakpoints, give no argument.\n\
13304 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13305 This command may be abbreviated \"disable\"."),
13308 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13309 Delete some breakpoints or auto-display expressions.\n\
13310 Arguments are breakpoint numbers with spaces in between.\n\
13311 To delete all breakpoints, give no argument.\n\
13313 Also a prefix command for deletion of other GDB objects.\n\
13314 The \"unset\" command is also an alias for \"delete\"."),
13315 &deletelist
, "delete ", 1, &cmdlist
);
13316 add_com_alias ("d", "delete", class_breakpoint
, 1);
13317 add_com_alias ("del", "delete", class_breakpoint
, 1);
13319 add_com ("db", class_breakpoint
, delete_command
, _("\
13320 Delete some breakpoints.\n\
13321 Arguments are breakpoint numbers with spaces in between.\n\
13322 To delete all breakpoints, give no argument.\n"));
13324 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13325 Delete some breakpoints or auto-display expressions.\n\
13326 Arguments are breakpoint numbers with spaces in between.\n\
13327 To delete all breakpoints, give no argument.\n\
13328 This command may be abbreviated \"delete\"."),
13331 add_com ("clear", class_breakpoint
, clear_command
, _("\
13332 Clear breakpoint at specified line or function.\n\
13333 Argument may be line number, function name, or \"*\" and an address.\n\
13334 If line number is specified, all breakpoints in that line are cleared.\n\
13335 If function is specified, breakpoints at beginning of function are cleared.\n\
13336 If an address is specified, breakpoints at that address are cleared.\n\
13338 With no argument, clears all breakpoints in the line that the selected frame\n\
13339 is executing in.\n\
13341 See also the \"delete\" command which clears breakpoints by number."));
13342 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13344 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13345 Set breakpoint at specified line or function.\n"
13346 BREAK_ARGS_HELP ("break")));
13347 set_cmd_completer (c
, location_completer
);
13349 add_com_alias ("b", "break", class_run
, 1);
13350 add_com_alias ("br", "break", class_run
, 1);
13351 add_com_alias ("bre", "break", class_run
, 1);
13352 add_com_alias ("brea", "break", class_run
, 1);
13355 add_com_alias ("ba", "break", class_breakpoint
, 1);
13359 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13360 Break in function/address or break at a line in the current file."),
13361 &stoplist
, "stop ", 1, &cmdlist
);
13362 add_cmd ("in", class_breakpoint
, stopin_command
,
13363 _("Break in function or address."), &stoplist
);
13364 add_cmd ("at", class_breakpoint
, stopat_command
,
13365 _("Break at a line in the current file."), &stoplist
);
13366 add_com ("status", class_info
, breakpoints_info
, _("\
13367 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13368 The \"Type\" column indicates one of:\n\
13369 \tbreakpoint - normal breakpoint\n\
13370 \twatchpoint - watchpoint\n\
13371 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13372 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13373 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13374 address and file/line number respectively.\n\
13376 Convenience variable \"$_\" and default examine address for \"x\"\n\
13377 are set to the address of the last breakpoint listed unless the command\n\
13378 is prefixed with \"server \".\n\n\
13379 Convenience variable \"$bpnum\" contains the number of the last\n\
13380 breakpoint set."));
13383 add_info ("breakpoints", breakpoints_info
, _("\
13384 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13385 The \"Type\" column indicates one of:\n\
13386 \tbreakpoint - normal breakpoint\n\
13387 \twatchpoint - watchpoint\n\
13388 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13389 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13390 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13391 address and file/line number respectively.\n\
13393 Convenience variable \"$_\" and default examine address for \"x\"\n\
13394 are set to the address of the last breakpoint listed unless the command\n\
13395 is prefixed with \"server \".\n\n\
13396 Convenience variable \"$bpnum\" contains the number of the last\n\
13397 breakpoint set."));
13399 add_info_alias ("b", "breakpoints", 1);
13402 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13403 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13404 The \"Type\" column indicates one of:\n\
13405 \tbreakpoint - normal breakpoint\n\
13406 \twatchpoint - watchpoint\n\
13407 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13408 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13409 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13410 address and file/line number respectively.\n\
13412 Convenience variable \"$_\" and default examine address for \"x\"\n\
13413 are set to the address of the last breakpoint listed unless the command\n\
13414 is prefixed with \"server \".\n\n\
13415 Convenience variable \"$bpnum\" contains the number of the last\n\
13416 breakpoint set."));
13418 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13419 Status of all breakpoints, or breakpoint number NUMBER.\n\
13420 The \"Type\" column indicates one of:\n\
13421 \tbreakpoint - normal breakpoint\n\
13422 \twatchpoint - watchpoint\n\
13423 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13424 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13425 \tuntil - internal breakpoint used by the \"until\" command\n\
13426 \tfinish - internal breakpoint used by the \"finish\" command\n\
13427 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13428 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13429 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13430 address and file/line number respectively.\n\
13432 Convenience variable \"$_\" and default examine address for \"x\"\n\
13433 are set to the address of the last breakpoint listed unless the command\n\
13434 is prefixed with \"server \".\n\n\
13435 Convenience variable \"$bpnum\" contains the number of the last\n\
13437 &maintenanceinfolist
);
13439 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13440 Set catchpoints to catch events."),
13441 &catch_cmdlist
, "catch ",
13442 0/*allow-unknown*/, &cmdlist
);
13444 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13445 Set temporary catchpoints to catch events."),
13446 &tcatch_cmdlist
, "tcatch ",
13447 0/*allow-unknown*/, &cmdlist
);
13449 /* Add catch and tcatch sub-commands. */
13450 add_catch_command ("catch", _("\
13451 Catch an exception, when caught.\n\
13452 With an argument, catch only exceptions with the given name."),
13453 catch_catch_command
,
13457 add_catch_command ("throw", _("\
13458 Catch an exception, when thrown.\n\
13459 With an argument, catch only exceptions with the given name."),
13460 catch_throw_command
,
13464 add_catch_command ("fork", _("Catch calls to fork."),
13465 catch_fork_command_1
,
13467 (void *) (uintptr_t) catch_fork_permanent
,
13468 (void *) (uintptr_t) catch_fork_temporary
);
13469 add_catch_command ("vfork", _("Catch calls to vfork."),
13470 catch_fork_command_1
,
13472 (void *) (uintptr_t) catch_vfork_permanent
,
13473 (void *) (uintptr_t) catch_vfork_temporary
);
13474 add_catch_command ("exec", _("Catch calls to exec."),
13475 catch_exec_command_1
,
13479 add_catch_command ("syscall", _("\
13480 Catch system calls by their names and/or numbers.\n\
13481 Arguments say which system calls to catch. If no arguments\n\
13482 are given, every system call will be caught.\n\
13483 Arguments, if given, should be one or more system call names\n\
13484 (if your system supports that), or system call numbers."),
13485 catch_syscall_command_1
,
13486 catch_syscall_completer
,
13490 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13491 Set a watchpoint for an expression.\n\
13492 Usage: watch [-l|-location] EXPRESSION\n\
13493 A watchpoint stops execution of your program whenever the value of\n\
13494 an expression changes.\n\
13495 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13496 the memory to which it refers."));
13497 set_cmd_completer (c
, expression_completer
);
13499 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13500 Set a read watchpoint for an expression.\n\
13501 Usage: rwatch [-l|-location] EXPRESSION\n\
13502 A watchpoint stops execution of your program whenever the value of\n\
13503 an expression is read.\n\
13504 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13505 the memory to which it refers."));
13506 set_cmd_completer (c
, expression_completer
);
13508 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13509 Set a watchpoint for an expression.\n\
13510 Usage: awatch [-l|-location] EXPRESSION\n\
13511 A watchpoint stops execution of your program whenever the value of\n\
13512 an expression is either read or written.\n\
13513 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13514 the memory to which it refers."));
13515 set_cmd_completer (c
, expression_completer
);
13517 add_info ("watchpoints", watchpoints_info
, _("\
13518 Status of specified watchpoints (all watchpoints if no argument)."));
13520 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13521 respond to changes - contrary to the description. */
13522 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13523 &can_use_hw_watchpoints
, _("\
13524 Set debugger's willingness to use watchpoint hardware."), _("\
13525 Show debugger's willingness to use watchpoint hardware."), _("\
13526 If zero, gdb will not use hardware for new watchpoints, even if\n\
13527 such is available. (However, any hardware watchpoints that were\n\
13528 created before setting this to nonzero, will continue to use watchpoint\n\
13531 show_can_use_hw_watchpoints
,
13532 &setlist
, &showlist
);
13534 can_use_hw_watchpoints
= 1;
13536 /* Tracepoint manipulation commands. */
13538 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13539 Set a tracepoint at specified line or function.\n\
13541 BREAK_ARGS_HELP ("trace") "\n\
13542 Do \"help tracepoints\" for info on other tracepoint commands."));
13543 set_cmd_completer (c
, location_completer
);
13545 add_com_alias ("tp", "trace", class_alias
, 0);
13546 add_com_alias ("tr", "trace", class_alias
, 1);
13547 add_com_alias ("tra", "trace", class_alias
, 1);
13548 add_com_alias ("trac", "trace", class_alias
, 1);
13550 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13551 Set a fast tracepoint at specified line or function.\n\
13553 BREAK_ARGS_HELP ("ftrace") "\n\
13554 Do \"help tracepoints\" for info on other tracepoint commands."));
13555 set_cmd_completer (c
, location_completer
);
13557 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13558 Set a static tracepoint at specified line, function or marker.\n\
13560 strace [LOCATION] [if CONDITION]\n\
13561 LOCATION may be a line number, function name, \"*\" and an address,\n\
13562 or -m MARKER_ID.\n\
13563 If a line number is specified, probe the marker at start of code\n\
13564 for that line. If a function is specified, probe the marker at start\n\
13565 of code for that function. If an address is specified, probe the marker\n\
13566 at that exact address. If a marker id is specified, probe the marker\n\
13567 with that name. With no LOCATION, uses current execution address of\n\
13568 the selected stack frame.\n\
13569 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13570 This collects arbitrary user data passed in the probe point call to the\n\
13571 tracing library. You can inspect it when analyzing the trace buffer,\n\
13572 by printing the $_sdata variable like any other convenience variable.\n\
13574 CONDITION is a boolean expression.\n\
13576 Multiple tracepoints at one place are permitted, and useful if their\n\
13577 conditions are different.\n\
13579 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13580 Do \"help tracepoints\" for info on other tracepoint commands."));
13581 set_cmd_completer (c
, location_completer
);
13583 add_info ("tracepoints", tracepoints_info
, _("\
13584 Status of specified tracepoints (all tracepoints if no argument).\n\
13585 Convenience variable \"$tpnum\" contains the number of the\n\
13586 last tracepoint set."));
13588 add_info_alias ("tp", "tracepoints", 1);
13590 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13591 Delete specified tracepoints.\n\
13592 Arguments are tracepoint numbers, separated by spaces.\n\
13593 No argument means delete all tracepoints."),
13596 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13597 Disable specified tracepoints.\n\
13598 Arguments are tracepoint numbers, separated by spaces.\n\
13599 No argument means disable all tracepoints."),
13601 deprecate_cmd (c
, "disable");
13603 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
13604 Enable specified tracepoints.\n\
13605 Arguments are tracepoint numbers, separated by spaces.\n\
13606 No argument means enable all tracepoints."),
13608 deprecate_cmd (c
, "enable");
13610 add_com ("passcount", class_trace
, trace_pass_command
, _("\
13611 Set the passcount for a tracepoint.\n\
13612 The trace will end when the tracepoint has been passed 'count' times.\n\
13613 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13614 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13616 add_prefix_cmd ("save", class_breakpoint
, save_command
,
13617 _("Save breakpoint definitions as a script."),
13618 &save_cmdlist
, "save ",
13619 0/*allow-unknown*/, &cmdlist
);
13621 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
13622 Save current breakpoint definitions as a script.\n\
13623 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13624 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13625 session to restore them."),
13627 set_cmd_completer (c
, filename_completer
);
13629 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
13630 Save current tracepoint definitions as a script.\n\
13631 Use the 'source' command in another debug session to restore them."),
13633 set_cmd_completer (c
, filename_completer
);
13635 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
13636 deprecate_cmd (c
, "save tracepoints");
13638 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
13639 Breakpoint specific settings\n\
13640 Configure various breakpoint-specific variables such as\n\
13641 pending breakpoint behavior"),
13642 &breakpoint_set_cmdlist
, "set breakpoint ",
13643 0/*allow-unknown*/, &setlist
);
13644 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
13645 Breakpoint specific settings\n\
13646 Configure various breakpoint-specific variables such as\n\
13647 pending breakpoint behavior"),
13648 &breakpoint_show_cmdlist
, "show breakpoint ",
13649 0/*allow-unknown*/, &showlist
);
13651 add_setshow_auto_boolean_cmd ("pending", no_class
,
13652 &pending_break_support
, _("\
13653 Set debugger's behavior regarding pending breakpoints."), _("\
13654 Show debugger's behavior regarding pending breakpoints."), _("\
13655 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13656 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13657 an error. If auto, an unrecognized breakpoint location results in a\n\
13658 user-query to see if a pending breakpoint should be created."),
13660 show_pending_break_support
,
13661 &breakpoint_set_cmdlist
,
13662 &breakpoint_show_cmdlist
);
13664 pending_break_support
= AUTO_BOOLEAN_AUTO
;
13666 add_setshow_boolean_cmd ("auto-hw", no_class
,
13667 &automatic_hardware_breakpoints
, _("\
13668 Set automatic usage of hardware breakpoints."), _("\
13669 Show automatic usage of hardware breakpoints."), _("\
13670 If set, the debugger will automatically use hardware breakpoints for\n\
13671 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13672 a warning will be emitted for such breakpoints."),
13674 show_automatic_hardware_breakpoints
,
13675 &breakpoint_set_cmdlist
,
13676 &breakpoint_show_cmdlist
);
13678 add_setshow_enum_cmd ("always-inserted", class_support
,
13679 always_inserted_enums
, &always_inserted_mode
, _("\
13680 Set mode for inserting breakpoints."), _("\
13681 Show mode for inserting breakpoints."), _("\
13682 When this mode is off, breakpoints are inserted in inferior when it is\n\
13683 resumed, and removed when execution stops. When this mode is on,\n\
13684 breakpoints are inserted immediately and removed only when the user\n\
13685 deletes the breakpoint. When this mode is auto (which is the default),\n\
13686 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13687 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13688 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13689 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13691 &show_always_inserted_mode
,
13692 &breakpoint_set_cmdlist
,
13693 &breakpoint_show_cmdlist
);
13695 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
13696 Set a breakpoint for an address range.\n\
13697 break-range START-LOCATION, END-LOCATION\n\
13698 where START-LOCATION and END-LOCATION can be one of the following:\n\
13699 LINENUM, for that line in the current file,\n\
13700 FILE:LINENUM, for that line in that file,\n\
13701 +OFFSET, for that number of lines after the current line\n\
13702 or the start of the range\n\
13703 FUNCTION, for the first line in that function,\n\
13704 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13705 *ADDRESS, for the instruction at that address.\n\
13707 The breakpoint will stop execution of the inferior whenever it executes\n\
13708 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13709 range (including START-LOCATION and END-LOCATION)."));
13711 automatic_hardware_breakpoints
= 1;
13713 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);