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"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
64 #include "parser-defs.h"
65 #include "cli/cli-utils.h"
67 /* readline include files */
68 #include "readline/readline.h"
69 #include "readline/history.h"
71 /* readline defines this. */
74 #include "mi/mi-common.h"
76 /* Arguments to pass as context to some catch command handlers. */
77 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
78 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
80 /* Prototypes for local functions. */
82 static void enable_delete_command (char *, int);
84 static void enable_once_command (char *, int);
86 static void disable_command (char *, int);
88 static void enable_command (char *, int);
90 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
94 static void ignore_command (char *, int);
96 static int breakpoint_re_set_one (void *);
98 static void clear_command (char *, int);
100 static void catch_command (char *, int);
102 static int can_use_hardware_watchpoint (struct value
*, int);
104 static void break_command_1 (char *, int, int);
106 static void mention (struct breakpoint
*);
108 /* This function is used in gdbtk sources and thus can not be made
110 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
111 struct symtab_and_line
,
114 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
116 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
120 static void describe_other_breakpoints (struct gdbarch
*,
121 struct program_space
*, CORE_ADDR
,
122 struct obj_section
*, int);
124 static int breakpoint_address_match (struct address_space
*aspace1
,
126 struct address_space
*aspace2
,
129 static int watchpoint_locations_match (struct bp_location
*loc1
,
130 struct bp_location
*loc2
);
132 static void breakpoints_info (char *, int);
134 static void watchpoints_info (char *, int);
136 static int breakpoint_1 (char *, int,
137 int (*) (const struct breakpoint
*));
139 static int breakpoint_cond_eval (void *);
141 static void cleanup_executing_breakpoints (void *);
143 static void commands_command (char *, int);
145 static void condition_command (char *, int);
154 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
155 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
157 static enum print_stop_action
print_it_typical (bpstat
);
159 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
161 static int watchpoint_check (void *);
163 static void maintenance_info_breakpoints (char *, int);
165 static int hw_breakpoint_used_count (void);
167 static int hw_watchpoint_used_count (enum bptype
, int *);
169 static void hbreak_command (char *, int);
171 static void thbreak_command (char *, int);
173 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
175 static void stop_command (char *arg
, int from_tty
);
177 static void stopin_command (char *arg
, int from_tty
);
179 static void stopat_command (char *arg
, int from_tty
);
181 static char *ep_parse_optional_if_clause (char **arg
);
183 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
184 char *arg
, int tempflag
, int from_tty
);
186 static void tcatch_command (char *arg
, int from_tty
);
188 static void detach_single_step_breakpoints (void);
190 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
193 static void free_bp_location (struct bp_location
*loc
);
194 static void incref_bp_location (struct bp_location
*loc
);
195 static void decref_bp_location (struct bp_location
**loc
);
197 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
199 static void update_global_location_list (int);
201 static void update_global_location_list_nothrow (int);
203 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
205 static int is_watchpoint (const struct breakpoint
*bpt
);
207 static void insert_breakpoint_locations (void);
209 static int syscall_catchpoint_p (struct breakpoint
*b
);
211 static void tracepoints_info (char *, int);
213 static void delete_trace_command (char *, int);
215 static void enable_trace_command (char *, int);
217 static void disable_trace_command (char *, int);
219 static void trace_pass_command (char *, int);
221 /* Assuming we're creating a static tracepoint, does S look like a
222 static tracepoint marker spec ("-m MARKER_ID")? */
223 #define is_marker_spec(s) \
224 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
226 /* A reference-counted struct command_line. This lets multiple
227 breakpoints share a single command list. */
228 struct counted_command_line
230 /* The reference count. */
233 /* The command list. */
234 struct command_line
*commands
;
237 struct command_line
*
238 breakpoint_commands (struct breakpoint
*b
)
240 return b
->commands
? b
->commands
->commands
: NULL
;
243 /* Flag indicating that a command has proceeded the inferior past the
244 current breakpoint. */
246 static int breakpoint_proceeded
;
249 bpdisp_text (enum bpdisp disp
)
251 /* NOTE: the following values are a part of MI protocol and
252 represent values of 'disp' field returned when inferior stops at
254 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
256 return bpdisps
[(int) disp
];
259 /* Prototypes for exported functions. */
260 /* If FALSE, gdb will not use hardware support for watchpoints, even
261 if such is available. */
262 static int can_use_hw_watchpoints
;
265 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
266 struct cmd_list_element
*c
,
269 fprintf_filtered (file
,
270 _("Debugger's willingness to use "
271 "watchpoint hardware is %s.\n"),
275 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
276 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
277 for unrecognized breakpoint locations.
278 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
279 static enum auto_boolean pending_break_support
;
281 show_pending_break_support (struct ui_file
*file
, int from_tty
,
282 struct cmd_list_element
*c
,
285 fprintf_filtered (file
,
286 _("Debugger's behavior regarding "
287 "pending breakpoints is %s.\n"),
291 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
292 set with "break" but falling in read-only memory.
293 If 0, gdb will warn about such breakpoints, but won't automatically
294 use hardware breakpoints. */
295 static int automatic_hardware_breakpoints
;
297 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
298 struct cmd_list_element
*c
,
301 fprintf_filtered (file
,
302 _("Automatic usage of hardware breakpoints is %s.\n"),
306 /* If on, gdb will keep breakpoints inserted even as inferior is
307 stopped, and immediately insert any new breakpoints. If off, gdb
308 will insert breakpoints into inferior only when resuming it, and
309 will remove breakpoints upon stop. If auto, GDB will behave as ON
310 if in non-stop mode, and as OFF if all-stop mode.*/
312 static const char always_inserted_auto
[] = "auto";
313 static const char always_inserted_on
[] = "on";
314 static const char always_inserted_off
[] = "off";
315 static const char *always_inserted_enums
[] = {
316 always_inserted_auto
,
321 static const char *always_inserted_mode
= always_inserted_auto
;
323 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
324 struct cmd_list_element
*c
, const char *value
)
326 if (always_inserted_mode
== always_inserted_auto
)
327 fprintf_filtered (file
,
328 _("Always inserted breakpoint "
329 "mode is %s (currently %s).\n"),
331 breakpoints_always_inserted_mode () ? "on" : "off");
333 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
338 breakpoints_always_inserted_mode (void)
340 return (always_inserted_mode
== always_inserted_on
341 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
344 void _initialize_breakpoint (void);
346 /* Are we executing breakpoint commands? */
347 static int executing_breakpoint_commands
;
349 /* Are overlay event breakpoints enabled? */
350 static int overlay_events_enabled
;
352 /* See description in breakpoint.h. */
353 int target_exact_watchpoints
= 0;
355 /* Walk the following statement or block through all breakpoints.
356 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the
357 current breakpoint. */
359 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
361 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
362 for (B = breakpoint_chain; \
363 B ? (TMP=B->next, 1): 0; \
366 /* Similar iterator for the low-level breakpoints. SAFE variant is
367 not provided so update_global_location_list must not be called
368 while executing the block of ALL_BP_LOCATIONS. */
370 #define ALL_BP_LOCATIONS(B,BP_TMP) \
371 for (BP_TMP = bp_location; \
372 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
375 /* Iterator for tracepoints only. */
377 #define ALL_TRACEPOINTS(B) \
378 for (B = breakpoint_chain; B; B = B->next) \
379 if (is_tracepoint (B))
381 /* Chains of all breakpoints defined. */
383 struct breakpoint
*breakpoint_chain
;
385 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
387 static struct bp_location
**bp_location
;
389 /* Number of elements of BP_LOCATION. */
391 static unsigned bp_location_count
;
393 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
394 ADDRESS for the current elements of BP_LOCATION which get a valid
395 result from bp_location_has_shadow. You can use it for roughly
396 limiting the subrange of BP_LOCATION to scan for shadow bytes for
397 an address you need to read. */
399 static CORE_ADDR bp_location_placed_address_before_address_max
;
401 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
402 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
403 BP_LOCATION which get a valid result from bp_location_has_shadow.
404 You can use it for roughly limiting the subrange of BP_LOCATION to
405 scan for shadow bytes for an address you need to read. */
407 static CORE_ADDR bp_location_shadow_len_after_address_max
;
409 /* The locations that no longer correspond to any breakpoint, unlinked
410 from bp_location array, but for which a hit may still be reported
412 VEC(bp_location_p
) *moribund_locations
= NULL
;
414 /* Number of last breakpoint made. */
416 static int breakpoint_count
;
418 /* The value of `breakpoint_count' before the last command that
419 created breakpoints. If the last (break-like) command created more
420 than one breakpoint, then the difference between BREAKPOINT_COUNT
421 and PREV_BREAKPOINT_COUNT is more than one. */
422 static int prev_breakpoint_count
;
424 /* Number of last tracepoint made. */
426 static int tracepoint_count
;
428 static struct cmd_list_element
*breakpoint_set_cmdlist
;
429 static struct cmd_list_element
*breakpoint_show_cmdlist
;
430 struct cmd_list_element
*save_cmdlist
;
432 /* Return whether a breakpoint is an active enabled breakpoint. */
434 breakpoint_enabled (struct breakpoint
*b
)
436 return (b
->enable_state
== bp_enabled
);
439 /* Set breakpoint count to NUM. */
442 set_breakpoint_count (int num
)
444 prev_breakpoint_count
= breakpoint_count
;
445 breakpoint_count
= num
;
446 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
449 /* Used by `start_rbreak_breakpoints' below, to record the current
450 breakpoint count before "rbreak" creates any breakpoint. */
451 static int rbreak_start_breakpoint_count
;
453 /* Called at the start an "rbreak" command to record the first
457 start_rbreak_breakpoints (void)
459 rbreak_start_breakpoint_count
= breakpoint_count
;
462 /* Called at the end of an "rbreak" command to record the last
466 end_rbreak_breakpoints (void)
468 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
471 /* Used in run_command to zero the hit count when a new run starts. */
474 clear_breakpoint_hit_counts (void)
476 struct breakpoint
*b
;
482 /* Allocate a new counted_command_line with reference count of 1.
483 The new structure owns COMMANDS. */
485 static struct counted_command_line
*
486 alloc_counted_command_line (struct command_line
*commands
)
488 struct counted_command_line
*result
489 = xmalloc (sizeof (struct counted_command_line
));
492 result
->commands
= commands
;
496 /* Increment reference count. This does nothing if CMD is NULL. */
499 incref_counted_command_line (struct counted_command_line
*cmd
)
505 /* Decrement reference count. If the reference count reaches 0,
506 destroy the counted_command_line. Sets *CMDP to NULL. This does
507 nothing if *CMDP is NULL. */
510 decref_counted_command_line (struct counted_command_line
**cmdp
)
514 if (--(*cmdp
)->refc
== 0)
516 free_command_lines (&(*cmdp
)->commands
);
523 /* A cleanup function that calls decref_counted_command_line. */
526 do_cleanup_counted_command_line (void *arg
)
528 decref_counted_command_line (arg
);
531 /* Create a cleanup that calls decref_counted_command_line on the
534 static struct cleanup
*
535 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
537 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
540 /* Default address, symtab and line to put a breakpoint at
541 for "break" command with no arg.
542 If default_breakpoint_valid is zero, the other three are
543 not valid, and "break" with no arg is an error.
545 This set by print_stack_frame, which calls set_default_breakpoint. */
547 int default_breakpoint_valid
;
548 CORE_ADDR default_breakpoint_address
;
549 struct symtab
*default_breakpoint_symtab
;
550 int default_breakpoint_line
;
551 struct program_space
*default_breakpoint_pspace
;
554 /* Return the breakpoint with the specified number, or NULL
555 if the number does not refer to an existing breakpoint. */
558 get_breakpoint (int num
)
560 struct breakpoint
*b
;
563 if (b
->number
== num
)
572 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
575 struct bp_location
*loc
= b
->loc
;
577 for (; loc
; loc
= loc
->next
)
582 xfree (b
->cond_string
);
583 b
->cond_string
= NULL
;
590 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
596 /* I don't know if it matters whether this is the string the user
597 typed in or the decompiled expression. */
598 b
->cond_string
= xstrdup (arg
);
599 b
->condition_not_parsed
= 0;
601 if (is_watchpoint (b
))
603 innermost_block
= NULL
;
605 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
607 error (_("Junk at end of expression"));
608 b
->cond_exp_valid_block
= innermost_block
;
612 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
616 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
618 error (_("Junk at end of expression"));
622 breakpoints_changed ();
623 observer_notify_breakpoint_modified (b
->number
);
626 /* condition N EXP -- set break condition of breakpoint N to EXP. */
629 condition_command (char *arg
, int from_tty
)
631 struct breakpoint
*b
;
636 error_no_arg (_("breakpoint number"));
639 bnum
= get_number (&p
);
641 error (_("Bad breakpoint argument: '%s'"), arg
);
644 if (b
->number
== bnum
)
646 set_breakpoint_condition (b
, p
, from_tty
);
650 error (_("No breakpoint number %d."), bnum
);
653 /* Check that COMMAND do not contain commands that are suitable
654 only for tracepoints and not suitable for ordinary breakpoints.
655 Throw if any such commands is found. */
658 check_no_tracepoint_commands (struct command_line
*commands
)
660 struct command_line
*c
;
662 for (c
= commands
; c
; c
= c
->next
)
666 if (c
->control_type
== while_stepping_control
)
667 error (_("The 'while-stepping' command can "
668 "only be used for tracepoints"));
670 for (i
= 0; i
< c
->body_count
; ++i
)
671 check_no_tracepoint_commands ((c
->body_list
)[i
]);
673 /* Not that command parsing removes leading whitespace and comment
674 lines and also empty lines. So, we only need to check for
676 if (strstr (c
->line
, "collect ") == c
->line
)
677 error (_("The 'collect' command can only be used for tracepoints"));
679 if (strstr (c
->line
, "teval ") == c
->line
)
680 error (_("The 'teval' command can only be used for tracepoints"));
684 /* Encapsulate tests for different types of tracepoints. */
687 is_tracepoint (const struct breakpoint
*b
)
689 return (b
->type
== bp_tracepoint
690 || b
->type
== bp_fast_tracepoint
691 || b
->type
== bp_static_tracepoint
);
694 /* A helper function that validsates that COMMANDS are valid for a
695 breakpoint. This function will throw an exception if a problem is
699 validate_commands_for_breakpoint (struct breakpoint
*b
,
700 struct command_line
*commands
)
702 if (is_tracepoint (b
))
704 /* We need to verify that each top-level element of commands is
705 valid for tracepoints, that there's at most one
706 while-stepping element, and that while-stepping's body has
707 valid tracing commands excluding nested while-stepping. */
708 struct command_line
*c
;
709 struct command_line
*while_stepping
= 0;
710 for (c
= commands
; c
; c
= c
->next
)
712 if (c
->control_type
== while_stepping_control
)
714 if (b
->type
== bp_fast_tracepoint
)
715 error (_("The 'while-stepping' command "
716 "cannot be used for fast tracepoint"));
717 else if (b
->type
== bp_static_tracepoint
)
718 error (_("The 'while-stepping' command "
719 "cannot be used for static tracepoint"));
722 error (_("The 'while-stepping' command "
723 "can be used only once"));
730 struct command_line
*c2
;
732 gdb_assert (while_stepping
->body_count
== 1);
733 c2
= while_stepping
->body_list
[0];
734 for (; c2
; c2
= c2
->next
)
736 if (c2
->control_type
== while_stepping_control
)
737 error (_("The 'while-stepping' command cannot be nested"));
743 check_no_tracepoint_commands (commands
);
747 /* Return a vector of all the static tracepoints set at ADDR. The
748 caller is responsible for releasing the vector. */
751 static_tracepoints_here (CORE_ADDR addr
)
753 struct breakpoint
*b
;
754 VEC(breakpoint_p
) *found
= 0;
755 struct bp_location
*loc
;
758 if (b
->type
== bp_static_tracepoint
)
760 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
761 if (loc
->address
== addr
)
762 VEC_safe_push(breakpoint_p
, found
, b
);
768 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
769 validate that only allowed commands are included. */
772 breakpoint_set_commands (struct breakpoint
*b
,
773 struct command_line
*commands
)
775 validate_commands_for_breakpoint (b
, commands
);
777 decref_counted_command_line (&b
->commands
);
778 b
->commands
= alloc_counted_command_line (commands
);
779 breakpoints_changed ();
780 observer_notify_breakpoint_modified (b
->number
);
783 /* Set the internal `silent' flag on the breakpoint. Note that this
784 is not the same as the "silent" that may appear in the breakpoint's
788 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
790 int old_silent
= b
->silent
;
793 if (old_silent
!= silent
)
794 observer_notify_breakpoint_modified (b
->number
);
797 /* Set the thread for this breakpoint. If THREAD is -1, make the
798 breakpoint work for any thread. */
801 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
803 int old_thread
= b
->thread
;
806 if (old_thread
!= thread
)
807 observer_notify_breakpoint_modified (b
->number
);
810 /* Set the task for this breakpoint. If TASK is 0, make the
811 breakpoint work for any task. */
814 breakpoint_set_task (struct breakpoint
*b
, int task
)
816 int old_task
= b
->task
;
819 if (old_task
!= task
)
820 observer_notify_breakpoint_modified (b
->number
);
824 check_tracepoint_command (char *line
, void *closure
)
826 struct breakpoint
*b
= closure
;
828 validate_actionline (&line
, b
);
831 /* A structure used to pass information through
832 map_breakpoint_numbers. */
836 /* True if the command was typed at a tty. */
839 /* The breakpoint range spec. */
842 /* Non-NULL if the body of the commands are being read from this
843 already-parsed command. */
844 struct command_line
*control
;
846 /* The command lines read from the user, or NULL if they have not
848 struct counted_command_line
*cmd
;
851 /* A callback for map_breakpoint_numbers that sets the commands for
855 do_map_commands_command (struct breakpoint
*b
, void *data
)
857 struct commands_info
*info
= data
;
859 if (info
->cmd
== NULL
)
861 struct command_line
*l
;
863 if (info
->control
!= NULL
)
864 l
= copy_command_lines (info
->control
->body_list
[0]);
867 struct cleanup
*old_chain
;
870 str
= xstrprintf (_("Type commands for breakpoint(s) "
871 "%s, one per line."),
874 old_chain
= make_cleanup (xfree
, str
);
876 l
= read_command_lines (str
,
879 ? check_tracepoint_command
: 0),
882 do_cleanups (old_chain
);
885 info
->cmd
= alloc_counted_command_line (l
);
888 /* If a breakpoint was on the list more than once, we don't need to
890 if (b
->commands
!= info
->cmd
)
892 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
893 incref_counted_command_line (info
->cmd
);
894 decref_counted_command_line (&b
->commands
);
895 b
->commands
= info
->cmd
;
896 breakpoints_changed ();
897 observer_notify_breakpoint_modified (b
->number
);
902 commands_command_1 (char *arg
, int from_tty
,
903 struct command_line
*control
)
905 struct cleanup
*cleanups
;
906 struct commands_info info
;
908 info
.from_tty
= from_tty
;
909 info
.control
= control
;
911 /* If we read command lines from the user, then `info' will hold an
912 extra reference to the commands that we must clean up. */
913 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
915 if (arg
== NULL
|| !*arg
)
917 if (breakpoint_count
- prev_breakpoint_count
> 1)
918 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
920 else if (breakpoint_count
> 0)
921 arg
= xstrprintf ("%d", breakpoint_count
);
924 /* So that we don't try to free the incoming non-NULL
925 argument in the cleanup below. Mapping breakpoint
926 numbers will fail in this case. */
931 /* The command loop has some static state, so we need to preserve
936 make_cleanup (xfree
, arg
);
940 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
942 if (info
.cmd
== NULL
)
943 error (_("No breakpoints specified."));
945 do_cleanups (cleanups
);
949 commands_command (char *arg
, int from_tty
)
951 commands_command_1 (arg
, from_tty
, NULL
);
954 /* Like commands_command, but instead of reading the commands from
955 input stream, takes them from an already parsed command structure.
957 This is used by cli-script.c to DTRT with breakpoint commands
958 that are part of if and while bodies. */
959 enum command_control_type
960 commands_from_control_command (char *arg
, struct command_line
*cmd
)
962 commands_command_1 (arg
, 0, cmd
);
963 return simple_control
;
966 /* Return non-zero if BL->TARGET_INFO contains valid information. */
969 bp_location_has_shadow (struct bp_location
*bl
)
971 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
975 if (bl
->target_info
.shadow_len
== 0)
976 /* bp isn't valid, or doesn't shadow memory. */
981 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
982 by replacing any memory breakpoints with their shadowed contents.
984 The range of shadowed area by each bp_location is:
985 bl->address - bp_location_placed_address_before_address_max
986 up to bl->address + bp_location_shadow_len_after_address_max
987 The range we were requested to resolve shadows for is:
988 memaddr ... memaddr + len
989 Thus the safe cutoff boundaries for performance optimization are
990 memaddr + len <= (bl->address
991 - bp_location_placed_address_before_address_max)
993 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
996 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
998 /* Left boundary, right boundary and median element of our binary
1000 unsigned bc_l
, bc_r
, bc
;
1002 /* Find BC_L which is a leftmost element which may affect BUF
1003 content. It is safe to report lower value but a failure to
1004 report higher one. */
1007 bc_r
= bp_location_count
;
1008 while (bc_l
+ 1 < bc_r
)
1010 struct bp_location
*bl
;
1012 bc
= (bc_l
+ bc_r
) / 2;
1013 bl
= bp_location
[bc
];
1015 /* Check first BL->ADDRESS will not overflow due to the added
1016 constant. Then advance the left boundary only if we are sure
1017 the BC element can in no way affect the BUF content (MEMADDR
1018 to MEMADDR + LEN range).
1020 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1021 offset so that we cannot miss a breakpoint with its shadow
1022 range tail still reaching MEMADDR. */
1024 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1026 && (bl
->address
+ bp_location_shadow_len_after_address_max
1033 /* Due to the binary search above, we need to make sure we pick the
1034 first location that's at BC_L's address. E.g., if there are
1035 multiple locations at the same address, BC_L may end up pointing
1036 at a duplicate location, and miss the "master"/"inserted"
1037 location. Say, given locations L1, L2 and L3 at addresses A and
1040 L1@A, L2@A, L3@B, ...
1042 BC_L could end up pointing at location L2, while the "master"
1043 location could be L1. Since the `loc->inserted' flag is only set
1044 on "master" locations, we'd forget to restore the shadow of L1
1047 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1050 /* Now do full processing of the found relevant range of elements. */
1052 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1054 struct bp_location
*bl
= bp_location
[bc
];
1055 CORE_ADDR bp_addr
= 0;
1059 /* bp_location array has BL->OWNER always non-NULL. */
1060 if (bl
->owner
->type
== bp_none
)
1061 warning (_("reading through apparently deleted breakpoint #%d?"),
1064 /* Performance optimization: any futher element can no longer affect BUF
1067 if (bl
->address
>= bp_location_placed_address_before_address_max
1068 && memaddr
+ len
<= (bl
->address
1069 - bp_location_placed_address_before_address_max
))
1072 if (!bp_location_has_shadow (bl
))
1074 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1075 current_program_space
->aspace
, 0))
1078 /* Addresses and length of the part of the breakpoint that
1080 bp_addr
= bl
->target_info
.placed_address
;
1081 bp_size
= bl
->target_info
.shadow_len
;
1083 if (bp_addr
+ bp_size
<= memaddr
)
1084 /* The breakpoint is entirely before the chunk of memory we
1088 if (bp_addr
>= memaddr
+ len
)
1089 /* The breakpoint is entirely after the chunk of memory we are
1093 /* Offset within shadow_contents. */
1094 if (bp_addr
< memaddr
)
1096 /* Only copy the second part of the breakpoint. */
1097 bp_size
-= memaddr
- bp_addr
;
1098 bptoffset
= memaddr
- bp_addr
;
1102 if (bp_addr
+ bp_size
> memaddr
+ len
)
1104 /* Only copy the first part of the breakpoint. */
1105 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1108 memcpy (buf
+ bp_addr
- memaddr
,
1109 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1114 /* Return true if BPT is of any hardware watchpoint kind. */
1117 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1119 return (bpt
->type
== bp_hardware_watchpoint
1120 || bpt
->type
== bp_read_watchpoint
1121 || bpt
->type
== bp_access_watchpoint
);
1124 /* Return true if BPT is of any watchpoint kind, hardware or
1128 is_watchpoint (const struct breakpoint
*bpt
)
1130 return (is_hardware_watchpoint (bpt
)
1131 || bpt
->type
== bp_watchpoint
);
1134 /* Assuming that B is a watchpoint: returns true if the current thread
1135 and its running state are safe to evaluate or update watchpoint B.
1136 Watchpoints on local expressions need to be evaluated in the
1137 context of the thread that was current when the watchpoint was
1138 created, and, that thread needs to be stopped to be able to select
1139 the correct frame context. Watchpoints on global expressions can
1140 be evaluated on any thread, and in any state. It is presently left
1141 to the target allowing memory accesses when threads are
1145 watchpoint_in_thread_scope (struct breakpoint
*b
)
1147 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1148 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1149 && !is_executing (inferior_ptid
)));
1152 /* Assuming that B is a watchpoint:
1153 - Reparse watchpoint expression, if REPARSE is non-zero
1154 - Evaluate expression and store the result in B->val
1155 - Evaluate the condition if there is one, and store the result
1157 - Update the list of values that must be watched in B->loc.
1159 If the watchpoint disposition is disp_del_at_next_stop, then do
1160 nothing. If this is local watchpoint that is out of scope, delete
1163 Even with `set breakpoint always-inserted on' the watchpoints are
1164 removed + inserted on each stop here. Normal breakpoints must
1165 never be removed because they might be missed by a running thread
1166 when debugging in non-stop mode. On the other hand, hardware
1167 watchpoints (is_hardware_watchpoint; processed here) are specific
1168 to each LWP since they are stored in each LWP's hardware debug
1169 registers. Therefore, such LWP must be stopped first in order to
1170 be able to modify its hardware watchpoints.
1172 Hardware watchpoints must be reset exactly once after being
1173 presented to the user. It cannot be done sooner, because it would
1174 reset the data used to present the watchpoint hit to the user. And
1175 it must not be done later because it could display the same single
1176 watchpoint hit during multiple GDB stops. Note that the latter is
1177 relevant only to the hardware watchpoint types bp_read_watchpoint
1178 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1179 not user-visible - its hit is suppressed if the memory content has
1182 The following constraints influence the location where we can reset
1183 hardware watchpoints:
1185 * target_stopped_by_watchpoint and target_stopped_data_address are
1186 called several times when GDB stops.
1189 * Multiple hardware watchpoints can be hit at the same time,
1190 causing GDB to stop. GDB only presents one hardware watchpoint
1191 hit at a time as the reason for stopping, and all the other hits
1192 are presented later, one after the other, each time the user
1193 requests the execution to be resumed. Execution is not resumed
1194 for the threads still having pending hit event stored in
1195 LWP_INFO->STATUS. While the watchpoint is already removed from
1196 the inferior on the first stop the thread hit event is kept being
1197 reported from its cached value by linux_nat_stopped_data_address
1198 until the real thread resume happens after the watchpoint gets
1199 presented and thus its LWP_INFO->STATUS gets reset.
1201 Therefore the hardware watchpoint hit can get safely reset on the
1202 watchpoint removal from inferior. */
1205 update_watchpoint (struct breakpoint
*b
, int reparse
)
1207 int within_current_scope
;
1208 struct frame_id saved_frame_id
;
1211 /* If this is a local watchpoint, we only want to check if the
1212 watchpoint frame is in scope if the current thread is the thread
1213 that was used to create the watchpoint. */
1214 if (!watchpoint_in_thread_scope (b
))
1217 if (b
->disposition
== disp_del_at_next_stop
)
1222 /* Determine if the watchpoint is within scope. */
1223 if (b
->exp_valid_block
== NULL
)
1224 within_current_scope
= 1;
1227 struct frame_info
*fi
= get_current_frame ();
1228 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1229 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1231 /* If we're in a function epilogue, unwinding may not work
1232 properly, so do not attempt to recreate locations at this
1233 point. See similar comments in watchpoint_check. */
1234 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1237 /* Save the current frame's ID so we can restore it after
1238 evaluating the watchpoint expression on its own frame. */
1239 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1240 took a frame parameter, so that we didn't have to change the
1243 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1245 fi
= frame_find_by_id (b
->watchpoint_frame
);
1246 within_current_scope
= (fi
!= NULL
);
1247 if (within_current_scope
)
1251 /* We don't free locations. They are stored in the bp_location array
1252 and update_global_location_list will eventually delete them and
1253 remove breakpoints if needed. */
1256 if (within_current_scope
&& reparse
)
1265 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1266 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1267 /* If the meaning of expression itself changed, the old value is
1268 no longer relevant. We don't want to report a watchpoint hit
1269 to the user when the old value and the new value may actually
1270 be completely different objects. */
1271 value_free (b
->val
);
1275 /* Note that unlike with breakpoints, the watchpoint's condition
1276 expression is stored in the breakpoint object, not in the
1277 locations (re)created below. */
1278 if (b
->cond_string
!= NULL
)
1280 if (b
->cond_exp
!= NULL
)
1282 xfree (b
->cond_exp
);
1287 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1291 /* If we failed to parse the expression, for example because
1292 it refers to a global variable in a not-yet-loaded shared library,
1293 don't try to insert watchpoint. We don't automatically delete
1294 such watchpoint, though, since failure to parse expression
1295 is different from out-of-scope watchpoint. */
1296 if ( !target_has_execution
)
1298 /* Without execution, memory can't change. No use to try and
1299 set watchpoint locations. The watchpoint will be reset when
1300 the target gains execution, through breakpoint_re_set. */
1302 else if (within_current_scope
&& b
->exp
)
1305 struct value
*val_chain
, *v
, *result
, *next
;
1306 struct program_space
*frame_pspace
;
1308 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1310 /* Avoid setting b->val if it's already set. The meaning of
1311 b->val is 'the last value' user saw, and we should update
1312 it only if we reported that last value to user. As it
1313 happens, the code that reports it updates b->val directly. */
1320 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1322 /* Look at each value on the value chain. */
1323 for (v
= val_chain
; v
; v
= value_next (v
))
1325 /* If it's a memory location, and GDB actually needed
1326 its contents to evaluate the expression, then we
1327 must watch it. If the first value returned is
1328 still lazy, that means an error occurred reading it;
1329 watch it anyway in case it becomes readable. */
1330 if (VALUE_LVAL (v
) == lval_memory
1331 && (v
== val_chain
|| ! value_lazy (v
)))
1333 struct type
*vtype
= check_typedef (value_type (v
));
1335 /* We only watch structs and arrays if user asked
1336 for it explicitly, never if they just happen to
1337 appear in the middle of some value chain. */
1339 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1340 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1344 struct bp_location
*loc
, **tmp
;
1346 addr
= value_address (v
);
1347 len
= TYPE_LENGTH (value_type (v
));
1349 if (b
->type
== bp_read_watchpoint
)
1351 else if (b
->type
== bp_access_watchpoint
)
1354 loc
= allocate_bp_location (b
);
1355 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1358 loc
->gdbarch
= get_type_arch (value_type (v
));
1360 loc
->pspace
= frame_pspace
;
1361 loc
->address
= addr
;
1363 loc
->watchpoint_type
= type
;
1368 /* Change the type of breakpoint between hardware assisted or
1369 an ordinary watchpoint depending on the hardware support
1370 and free hardware slots. REPARSE is set when the inferior
1372 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1376 enum bp_loc_type loc_type
;
1377 struct bp_location
*bl
;
1379 reg_cnt
= can_use_hardware_watchpoint (val_chain
, b
->exact
);
1383 int i
, target_resources_ok
, other_type_used
;
1384 enum enable_state orig_enable_state
;
1386 /* We need to determine how many resources are already
1387 used for all other hardware watchpoints plus this one
1388 to see if we still have enough resources to also fit
1389 this watchpoint in as well. To guarantee the
1390 hw_watchpoint_used_count call below counts this
1391 watchpoint, make sure that it is marked as a hardware
1393 b
->type
= bp_hardware_watchpoint
;
1395 /* hw_watchpoint_used_count ignores disabled watchpoints,
1396 and b might be disabled if we're being called from
1397 do_enable_breakpoint. */
1398 orig_enable_state
= b
->enable_state
;
1399 b
->enable_state
= bp_enabled
;
1401 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1404 b
->enable_state
= orig_enable_state
;
1406 target_resources_ok
= target_can_use_hardware_watchpoint
1407 (bp_hardware_watchpoint
, i
, other_type_used
);
1408 if (target_resources_ok
<= 0)
1409 b
->type
= bp_watchpoint
;
1412 b
->type
= bp_watchpoint
;
1414 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1415 : bp_loc_hardware_watchpoint
);
1416 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1417 bl
->loc_type
= loc_type
;
1420 for (v
= val_chain
; v
; v
= next
)
1422 next
= value_next (v
);
1427 /* If a software watchpoint is not watching any memory, then the
1428 above left it without any location set up. But,
1429 bpstat_stop_status requires a location to be able to report
1430 stops, so make sure there's at least a dummy one. */
1431 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1433 b
->loc
= allocate_bp_location (b
);
1434 b
->loc
->pspace
= frame_pspace
;
1435 b
->loc
->address
= -1;
1436 b
->loc
->length
= -1;
1437 b
->loc
->watchpoint_type
= -1;
1440 else if (!within_current_scope
)
1442 printf_filtered (_("\
1443 Watchpoint %d deleted because the program has left the block\n\
1444 in which its expression is valid.\n"),
1446 if (b
->related_breakpoint
)
1448 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1449 b
->related_breakpoint
->related_breakpoint
= NULL
;
1450 b
->related_breakpoint
= NULL
;
1452 b
->disposition
= disp_del_at_next_stop
;
1455 /* Restore the selected frame. */
1457 select_frame (frame_find_by_id (saved_frame_id
));
1461 /* Returns 1 iff breakpoint location should be
1462 inserted in the inferior. */
1464 should_be_inserted (struct bp_location
*bl
)
1466 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1469 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1472 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1475 /* This is set for example, when we're attached to the parent of a
1476 vfork, and have detached from the child. The child is running
1477 free, and we expect it to do an exec or exit, at which point the
1478 OS makes the parent schedulable again (and the target reports
1479 that the vfork is done). Until the child is done with the shared
1480 memory region, do not insert breakpoints in the parent, otherwise
1481 the child could still trip on the parent's breakpoints. Since
1482 the parent is blocked anyway, it won't miss any breakpoint. */
1483 if (bl
->pspace
->breakpoints_not_allowed
)
1486 /* Tracepoints are inserted by the target at a time of its choosing,
1488 if (is_tracepoint (bl
->owner
))
1494 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1495 location. Any error messages are printed to TMP_ERROR_STREAM; and
1496 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1498 NOTE drow/2003-09-09: This routine could be broken down to an
1499 object-style method for each breakpoint or catchpoint type. */
1501 insert_bp_location (struct bp_location
*bl
,
1502 struct ui_file
*tmp_error_stream
,
1503 int *disabled_breaks
,
1504 int *hw_breakpoint_error
)
1508 if (!should_be_inserted (bl
) || bl
->inserted
)
1511 /* Initialize the target-specific information. */
1512 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1513 bl
->target_info
.placed_address
= bl
->address
;
1514 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1516 if (bl
->loc_type
== bp_loc_software_breakpoint
1517 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1519 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1521 /* If the explicitly specified breakpoint type
1522 is not hardware breakpoint, check the memory map to see
1523 if the breakpoint address is in read only memory or not.
1525 Two important cases are:
1526 - location type is not hardware breakpoint, memory
1527 is readonly. We change the type of the location to
1528 hardware breakpoint.
1529 - location type is hardware breakpoint, memory is
1530 read-write. This means we've previously made the
1531 location hardware one, but then the memory map changed,
1534 When breakpoints are removed, remove_breakpoints will use
1535 location types we've just set here, the only possible
1536 problem is that memory map has changed during running
1537 program, but it's not going to work anyway with current
1539 struct mem_region
*mr
1540 = lookup_mem_region (bl
->target_info
.placed_address
);
1544 if (automatic_hardware_breakpoints
)
1546 enum bp_loc_type new_type
;
1548 if (mr
->attrib
.mode
!= MEM_RW
)
1549 new_type
= bp_loc_hardware_breakpoint
;
1551 new_type
= bp_loc_software_breakpoint
;
1553 if (new_type
!= bl
->loc_type
)
1555 static int said
= 0;
1557 bl
->loc_type
= new_type
;
1560 fprintf_filtered (gdb_stdout
,
1561 _("Note: automatically using "
1562 "hardware breakpoints for "
1563 "read-only addresses.\n"));
1568 else if (bl
->loc_type
== bp_loc_software_breakpoint
1569 && mr
->attrib
.mode
!= MEM_RW
)
1570 warning (_("cannot set software breakpoint "
1571 "at readonly address %s"),
1572 paddress (bl
->gdbarch
, bl
->address
));
1576 /* First check to see if we have to handle an overlay. */
1577 if (overlay_debugging
== ovly_off
1578 || bl
->section
== NULL
1579 || !(section_is_overlay (bl
->section
)))
1581 /* No overlay handling: just set the breakpoint. */
1583 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1584 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1587 val
= target_insert_breakpoint (bl
->gdbarch
,
1592 /* This breakpoint is in an overlay section.
1593 Shall we set a breakpoint at the LMA? */
1594 if (!overlay_events_enabled
)
1596 /* Yes -- overlay event support is not active,
1597 so we must try to set a breakpoint at the LMA.
1598 This will not work for a hardware breakpoint. */
1599 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1600 warning (_("hardware breakpoint %d not supported in overlay!"),
1604 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1606 /* Set a software (trap) breakpoint at the LMA. */
1607 bl
->overlay_target_info
= bl
->target_info
;
1608 bl
->overlay_target_info
.placed_address
= addr
;
1609 val
= target_insert_breakpoint (bl
->gdbarch
,
1610 &bl
->overlay_target_info
);
1612 fprintf_unfiltered (tmp_error_stream
,
1613 "Overlay breakpoint %d "
1614 "failed: in ROM?\n",
1618 /* Shall we set a breakpoint at the VMA? */
1619 if (section_is_mapped (bl
->section
))
1621 /* Yes. This overlay section is mapped into memory. */
1622 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1623 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1626 val
= target_insert_breakpoint (bl
->gdbarch
,
1631 /* No. This breakpoint will not be inserted.
1632 No error, but do not mark the bp as 'inserted'. */
1639 /* Can't set the breakpoint. */
1640 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1642 /* See also: disable_breakpoints_in_shlibs. */
1644 bl
->shlib_disabled
= 1;
1645 if (!*disabled_breaks
)
1647 fprintf_unfiltered (tmp_error_stream
,
1648 "Cannot insert breakpoint %d.\n",
1650 fprintf_unfiltered (tmp_error_stream
,
1651 "Temporarily disabling shared "
1652 "library breakpoints:\n");
1654 *disabled_breaks
= 1;
1655 fprintf_unfiltered (tmp_error_stream
,
1656 "breakpoint #%d\n", bl
->owner
->number
);
1660 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1662 *hw_breakpoint_error
= 1;
1663 fprintf_unfiltered (tmp_error_stream
,
1664 "Cannot insert hardware "
1670 fprintf_unfiltered (tmp_error_stream
,
1671 "Cannot insert breakpoint %d.\n",
1673 fprintf_filtered (tmp_error_stream
,
1674 "Error accessing memory address ");
1675 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1677 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1678 safe_strerror (val
));
1689 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1690 /* NOTE drow/2003-09-08: This state only exists for removing
1691 watchpoints. It's not clear that it's necessary... */
1692 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1694 gdb_assert (bl
->owner
->ops
!= NULL
1695 && bl
->owner
->ops
->insert_location
!= NULL
);
1697 val
= bl
->owner
->ops
->insert_location (bl
);
1699 /* If trying to set a read-watchpoint, and it turns out it's not
1700 supported, try emulating one with an access watchpoint. */
1701 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1703 struct bp_location
*loc
, **loc_temp
;
1705 /* But don't try to insert it, if there's already another
1706 hw_access location that would be considered a duplicate
1708 ALL_BP_LOCATIONS (loc
, loc_temp
)
1710 && loc
->watchpoint_type
== hw_access
1711 && watchpoint_locations_match (bl
, loc
))
1715 bl
->target_info
= loc
->target_info
;
1716 bl
->watchpoint_type
= hw_access
;
1723 bl
->watchpoint_type
= hw_access
;
1724 val
= bl
->owner
->ops
->insert_location (bl
);
1727 /* Back to the original value. */
1728 bl
->watchpoint_type
= hw_read
;
1732 bl
->inserted
= (val
== 0);
1735 else if (bl
->owner
->type
== bp_catchpoint
)
1737 gdb_assert (bl
->owner
->ops
!= NULL
1738 && bl
->owner
->ops
->insert_location
!= NULL
);
1740 val
= bl
->owner
->ops
->insert_location (bl
);
1743 bl
->owner
->enable_state
= bp_disabled
;
1747 Error inserting catchpoint %d: Your system does not support this type\n\
1748 of catchpoint."), bl
->owner
->number
);
1750 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1753 bl
->inserted
= (val
== 0);
1755 /* We've already printed an error message if there was a problem
1756 inserting this catchpoint, and we've disabled the catchpoint,
1757 so just return success. */
1764 /* This function is called when program space PSPACE is about to be
1765 deleted. It takes care of updating breakpoints to not reference
1769 breakpoint_program_space_exit (struct program_space
*pspace
)
1771 struct breakpoint
*b
, *b_temp
;
1772 struct bp_location
*loc
, **loc_temp
;
1774 /* Remove any breakpoint that was set through this program space. */
1775 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1777 if (b
->pspace
== pspace
)
1778 delete_breakpoint (b
);
1781 /* Breakpoints set through other program spaces could have locations
1782 bound to PSPACE as well. Remove those. */
1783 ALL_BP_LOCATIONS (loc
, loc_temp
)
1785 struct bp_location
*tmp
;
1787 if (loc
->pspace
== pspace
)
1789 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1790 if (loc
->owner
->loc
== loc
)
1791 loc
->owner
->loc
= loc
->next
;
1793 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1794 if (tmp
->next
== loc
)
1796 tmp
->next
= loc
->next
;
1802 /* Now update the global location list to permanently delete the
1803 removed locations above. */
1804 update_global_location_list (0);
1807 /* Make sure all breakpoints are inserted in inferior.
1808 Throws exception on any error.
1809 A breakpoint that is already inserted won't be inserted
1810 again, so calling this function twice is safe. */
1812 insert_breakpoints (void)
1814 struct breakpoint
*bpt
;
1816 ALL_BREAKPOINTS (bpt
)
1817 if (is_hardware_watchpoint (bpt
))
1818 update_watchpoint (bpt
, 0 /* don't reparse. */);
1820 update_global_location_list (1);
1822 /* update_global_location_list does not insert breakpoints when
1823 always_inserted_mode is not enabled. Explicitly insert them
1825 if (!breakpoints_always_inserted_mode ())
1826 insert_breakpoint_locations ();
1829 /* insert_breakpoints is used when starting or continuing the program.
1830 remove_breakpoints is used when the program stops.
1831 Both return zero if successful,
1832 or an `errno' value if could not write the inferior. */
1835 insert_breakpoint_locations (void)
1837 struct breakpoint
*bpt
;
1838 struct bp_location
*bl
, **blp_tmp
;
1841 int disabled_breaks
= 0;
1842 int hw_breakpoint_error
= 0;
1844 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1845 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1847 /* Explicitly mark the warning -- this will only be printed if
1848 there was an error. */
1849 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1851 save_current_space_and_thread ();
1853 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1855 if (!should_be_inserted (bl
) || bl
->inserted
)
1858 /* There is no point inserting thread-specific breakpoints if
1859 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1860 has BL->OWNER always non-NULL. */
1861 if (bl
->owner
->thread
!= -1
1862 && !valid_thread_id (bl
->owner
->thread
))
1865 switch_to_program_space_and_thread (bl
->pspace
);
1867 /* For targets that support global breakpoints, there's no need
1868 to select an inferior to insert breakpoint to. In fact, even
1869 if we aren't attached to any process yet, we should still
1870 insert breakpoints. */
1871 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1872 && ptid_equal (inferior_ptid
, null_ptid
))
1875 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1876 &hw_breakpoint_error
);
1881 /* If we failed to insert all locations of a watchpoint, remove
1882 them, as half-inserted watchpoint is of limited use. */
1883 ALL_BREAKPOINTS (bpt
)
1885 int some_failed
= 0;
1886 struct bp_location
*loc
;
1888 if (!is_hardware_watchpoint (bpt
))
1891 if (!breakpoint_enabled (bpt
))
1894 if (bpt
->disposition
== disp_del_at_next_stop
)
1897 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1898 if (!loc
->inserted
&& should_be_inserted (loc
))
1905 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1907 remove_breakpoint (loc
, mark_uninserted
);
1909 hw_breakpoint_error
= 1;
1910 fprintf_unfiltered (tmp_error_stream
,
1911 "Could not insert hardware watchpoint %d.\n",
1919 /* If a hardware breakpoint or watchpoint was inserted, add a
1920 message about possibly exhausted resources. */
1921 if (hw_breakpoint_error
)
1923 fprintf_unfiltered (tmp_error_stream
,
1924 "Could not insert hardware breakpoints:\n\
1925 You may have requested too many hardware breakpoints/watchpoints.\n");
1927 target_terminal_ours_for_output ();
1928 error_stream (tmp_error_stream
);
1931 do_cleanups (cleanups
);
1935 remove_breakpoints (void)
1937 struct bp_location
*bl
, **blp_tmp
;
1940 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1943 val
|= remove_breakpoint (bl
, mark_uninserted
);
1948 /* Remove breakpoints of process PID. */
1951 remove_breakpoints_pid (int pid
)
1953 struct bp_location
*bl
, **blp_tmp
;
1955 struct inferior
*inf
= find_inferior_pid (pid
);
1957 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1959 if (bl
->pspace
!= inf
->pspace
)
1964 val
= remove_breakpoint (bl
, mark_uninserted
);
1973 remove_hw_watchpoints (void)
1975 struct bp_location
*bl
, **blp_tmp
;
1978 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1980 if (bl
->inserted
&& bl
->loc_type
== bp_loc_hardware_watchpoint
)
1981 val
|= remove_breakpoint (bl
, mark_uninserted
);
1987 reattach_breakpoints (int pid
)
1989 struct cleanup
*old_chain
;
1990 struct bp_location
*bl
, **blp_tmp
;
1992 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1993 int dummy1
= 0, dummy2
= 0;
1994 struct inferior
*inf
;
1995 struct thread_info
*tp
;
1997 tp
= any_live_thread_of_process (pid
);
2001 inf
= find_inferior_pid (pid
);
2002 old_chain
= save_inferior_ptid ();
2004 inferior_ptid
= tp
->ptid
;
2006 make_cleanup_ui_file_delete (tmp_error_stream
);
2008 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2010 if (bl
->pspace
!= inf
->pspace
)
2016 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2019 do_cleanups (old_chain
);
2024 do_cleanups (old_chain
);
2028 static int internal_breakpoint_number
= -1;
2030 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2031 If INTERNAL is non-zero, the breakpoint number will be populated
2032 from internal_breakpoint_number and that variable decremented.
2033 Otherwis the breakpoint number will be populated from
2034 breakpoint_count and that value incremented. Internal breakpoints
2035 do not set the internal var bpnum. */
2037 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2040 b
->number
= internal_breakpoint_number
--;
2043 set_breakpoint_count (breakpoint_count
+ 1);
2044 b
->number
= breakpoint_count
;
2048 static struct breakpoint
*
2049 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2050 CORE_ADDR address
, enum bptype type
)
2052 struct symtab_and_line sal
;
2053 struct breakpoint
*b
;
2055 init_sal (&sal
); /* Initialize to zeroes. */
2058 sal
.section
= find_pc_overlay (sal
.pc
);
2059 sal
.pspace
= current_program_space
;
2061 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2062 b
->number
= internal_breakpoint_number
--;
2063 b
->disposition
= disp_donttouch
;
2068 static const char *const longjmp_names
[] =
2070 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2072 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2074 /* Per-objfile data private to breakpoint.c. */
2075 struct breakpoint_objfile_data
2077 /* Minimal symbol for "_ovly_debug_event" (if any). */
2078 struct minimal_symbol
*overlay_msym
;
2080 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2081 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2083 /* Minimal symbol for "std::terminate()" (if any). */
2084 struct minimal_symbol
*terminate_msym
;
2086 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2087 struct minimal_symbol
*exception_msym
;
2090 static const struct objfile_data
*breakpoint_objfile_key
;
2092 /* Minimal symbol not found sentinel. */
2093 static struct minimal_symbol msym_not_found
;
2095 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2098 msym_not_found_p (const struct minimal_symbol
*msym
)
2100 return msym
== &msym_not_found
;
2103 /* Return per-objfile data needed by breakpoint.c.
2104 Allocate the data if necessary. */
2106 static struct breakpoint_objfile_data
*
2107 get_breakpoint_objfile_data (struct objfile
*objfile
)
2109 struct breakpoint_objfile_data
*bp_objfile_data
;
2111 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2112 if (bp_objfile_data
== NULL
)
2114 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2115 sizeof (*bp_objfile_data
));
2117 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2118 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2120 return bp_objfile_data
;
2124 create_overlay_event_breakpoint (void)
2126 struct objfile
*objfile
;
2127 const char *const func_name
= "_ovly_debug_event";
2129 ALL_OBJFILES (objfile
)
2131 struct breakpoint
*b
;
2132 struct breakpoint_objfile_data
*bp_objfile_data
;
2135 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2137 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2140 if (bp_objfile_data
->overlay_msym
== NULL
)
2142 struct minimal_symbol
*m
;
2144 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2147 /* Avoid future lookups in this objfile. */
2148 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2151 bp_objfile_data
->overlay_msym
= m
;
2154 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2155 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2157 b
->addr_string
= xstrdup (func_name
);
2159 if (overlay_debugging
== ovly_auto
)
2161 b
->enable_state
= bp_enabled
;
2162 overlay_events_enabled
= 1;
2166 b
->enable_state
= bp_disabled
;
2167 overlay_events_enabled
= 0;
2170 update_global_location_list (1);
2174 create_longjmp_master_breakpoint (void)
2176 struct program_space
*pspace
;
2177 struct cleanup
*old_chain
;
2179 old_chain
= save_current_program_space ();
2181 ALL_PSPACES (pspace
)
2183 struct objfile
*objfile
;
2185 set_current_program_space (pspace
);
2187 ALL_OBJFILES (objfile
)
2190 struct gdbarch
*gdbarch
;
2191 struct breakpoint_objfile_data
*bp_objfile_data
;
2193 gdbarch
= get_objfile_arch (objfile
);
2194 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2197 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2199 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2201 struct breakpoint
*b
;
2202 const char *func_name
;
2205 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2208 func_name
= longjmp_names
[i
];
2209 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2211 struct minimal_symbol
*m
;
2213 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2216 /* Prevent future lookups in this objfile. */
2217 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2220 bp_objfile_data
->longjmp_msym
[i
] = m
;
2223 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2224 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
2225 b
->addr_string
= xstrdup (func_name
);
2226 b
->enable_state
= bp_disabled
;
2230 update_global_location_list (1);
2232 do_cleanups (old_chain
);
2235 /* Create a master std::terminate breakpoint. */
2237 create_std_terminate_master_breakpoint (void)
2239 struct program_space
*pspace
;
2240 struct cleanup
*old_chain
;
2241 const char *const func_name
= "std::terminate()";
2243 old_chain
= save_current_program_space ();
2245 ALL_PSPACES (pspace
)
2247 struct objfile
*objfile
;
2250 set_current_program_space (pspace
);
2252 ALL_OBJFILES (objfile
)
2254 struct breakpoint
*b
;
2255 struct breakpoint_objfile_data
*bp_objfile_data
;
2257 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2259 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2262 if (bp_objfile_data
->terminate_msym
== NULL
)
2264 struct minimal_symbol
*m
;
2266 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2267 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2268 && MSYMBOL_TYPE (m
) != mst_file_text
))
2270 /* Prevent future lookups in this objfile. */
2271 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2274 bp_objfile_data
->terminate_msym
= m
;
2277 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2278 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2279 bp_std_terminate_master
);
2280 b
->addr_string
= xstrdup (func_name
);
2281 b
->enable_state
= bp_disabled
;
2285 update_global_location_list (1);
2287 do_cleanups (old_chain
);
2290 /* Install a master breakpoint on the unwinder's debug hook. */
2293 create_exception_master_breakpoint (void)
2295 struct objfile
*objfile
;
2296 const char *const func_name
= "_Unwind_DebugHook";
2298 ALL_OBJFILES (objfile
)
2300 struct breakpoint
*b
;
2301 struct gdbarch
*gdbarch
;
2302 struct breakpoint_objfile_data
*bp_objfile_data
;
2305 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2307 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2310 gdbarch
= get_objfile_arch (objfile
);
2312 if (bp_objfile_data
->exception_msym
== NULL
)
2314 struct minimal_symbol
*debug_hook
;
2316 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2317 if (debug_hook
== NULL
)
2319 bp_objfile_data
->exception_msym
= &msym_not_found
;
2323 bp_objfile_data
->exception_msym
= debug_hook
;
2326 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2327 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2329 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2330 b
->addr_string
= xstrdup (func_name
);
2331 b
->enable_state
= bp_disabled
;
2334 update_global_location_list (1);
2338 update_breakpoints_after_exec (void)
2340 struct breakpoint
*b
, *b_tmp
;
2341 struct bp_location
*bploc
, **bplocp_tmp
;
2343 /* We're about to delete breakpoints from GDB's lists. If the
2344 INSERTED flag is true, GDB will try to lift the breakpoints by
2345 writing the breakpoints' "shadow contents" back into memory. The
2346 "shadow contents" are NOT valid after an exec, so GDB should not
2347 do that. Instead, the target is responsible from marking
2348 breakpoints out as soon as it detects an exec. We don't do that
2349 here instead, because there may be other attempts to delete
2350 breakpoints after detecting an exec and before reaching here. */
2351 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2352 if (bploc
->pspace
== current_program_space
)
2353 gdb_assert (!bploc
->inserted
);
2355 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2357 if (b
->pspace
!= current_program_space
)
2360 /* Solib breakpoints must be explicitly reset after an exec(). */
2361 if (b
->type
== bp_shlib_event
)
2363 delete_breakpoint (b
);
2367 /* JIT breakpoints must be explicitly reset after an exec(). */
2368 if (b
->type
== bp_jit_event
)
2370 delete_breakpoint (b
);
2374 /* Thread event breakpoints must be set anew after an exec(),
2375 as must overlay event and longjmp master breakpoints. */
2376 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2377 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2378 || b
->type
== bp_exception_master
)
2380 delete_breakpoint (b
);
2384 /* Step-resume breakpoints are meaningless after an exec(). */
2385 if (b
->type
== bp_step_resume
)
2387 delete_breakpoint (b
);
2391 /* Longjmp and longjmp-resume breakpoints are also meaningless
2393 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2394 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2396 delete_breakpoint (b
);
2400 if (b
->type
== bp_catchpoint
)
2402 /* For now, none of the bp_catchpoint breakpoints need to
2403 do anything at this point. In the future, if some of
2404 the catchpoints need to something, we will need to add
2405 a new method, and call this method from here. */
2409 /* bp_finish is a special case. The only way we ought to be able
2410 to see one of these when an exec() has happened, is if the user
2411 caught a vfork, and then said "finish". Ordinarily a finish just
2412 carries them to the call-site of the current callee, by setting
2413 a temporary bp there and resuming. But in this case, the finish
2414 will carry them entirely through the vfork & exec.
2416 We don't want to allow a bp_finish to remain inserted now. But
2417 we can't safely delete it, 'cause finish_command has a handle to
2418 the bp on a bpstat, and will later want to delete it. There's a
2419 chance (and I've seen it happen) that if we delete the bp_finish
2420 here, that its storage will get reused by the time finish_command
2421 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2422 We really must allow finish_command to delete a bp_finish.
2424 In the absense of a general solution for the "how do we know
2425 it's safe to delete something others may have handles to?"
2426 problem, what we'll do here is just uninsert the bp_finish, and
2427 let finish_command delete it.
2429 (We know the bp_finish is "doomed" in the sense that it's
2430 momentary, and will be deleted as soon as finish_command sees
2431 the inferior stopped. So it doesn't matter that the bp's
2432 address is probably bogus in the new a.out, unlike e.g., the
2433 solib breakpoints.) */
2435 if (b
->type
== bp_finish
)
2440 /* Without a symbolic address, we have little hope of the
2441 pre-exec() address meaning the same thing in the post-exec()
2443 if (b
->addr_string
== NULL
)
2445 delete_breakpoint (b
);
2449 /* FIXME what about longjmp breakpoints? Re-create them here? */
2450 create_overlay_event_breakpoint ();
2451 create_longjmp_master_breakpoint ();
2452 create_std_terminate_master_breakpoint ();
2453 create_exception_master_breakpoint ();
2457 detach_breakpoints (int pid
)
2459 struct bp_location
*bl
, **blp_tmp
;
2461 struct cleanup
*old_chain
= save_inferior_ptid ();
2462 struct inferior
*inf
= current_inferior ();
2464 if (pid
== PIDGET (inferior_ptid
))
2465 error (_("Cannot detach breakpoints of inferior_ptid"));
2467 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2468 inferior_ptid
= pid_to_ptid (pid
);
2469 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2471 if (bl
->pspace
!= inf
->pspace
)
2475 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2478 /* Detach single-step breakpoints as well. */
2479 detach_single_step_breakpoints ();
2481 do_cleanups (old_chain
);
2485 /* Remove the breakpoint location BL from the current address space.
2486 Note that this is used to detach breakpoints from a child fork.
2487 When we get here, the child isn't in the inferior list, and neither
2488 do we have objects to represent its address space --- we should
2489 *not* look at bl->pspace->aspace here. */
2492 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2496 /* BL is never in moribund_locations by our callers. */
2497 gdb_assert (bl
->owner
!= NULL
);
2499 if (bl
->owner
->enable_state
== bp_permanent
)
2500 /* Permanent breakpoints cannot be inserted or removed. */
2503 /* The type of none suggests that owner is actually deleted.
2504 This should not ever happen. */
2505 gdb_assert (bl
->owner
->type
!= bp_none
);
2507 if (bl
->loc_type
== bp_loc_software_breakpoint
2508 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2510 /* "Normal" instruction breakpoint: either the standard
2511 trap-instruction bp (bp_breakpoint), or a
2512 bp_hardware_breakpoint. */
2514 /* First check to see if we have to handle an overlay. */
2515 if (overlay_debugging
== ovly_off
2516 || bl
->section
== NULL
2517 || !(section_is_overlay (bl
->section
)))
2519 /* No overlay handling: just remove the breakpoint. */
2521 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2522 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2524 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2528 /* This breakpoint is in an overlay section.
2529 Did we set a breakpoint at the LMA? */
2530 if (!overlay_events_enabled
)
2532 /* Yes -- overlay event support is not active, so we
2533 should have set a breakpoint at the LMA. Remove it.
2535 /* Ignore any failures: if the LMA is in ROM, we will
2536 have already warned when we failed to insert it. */
2537 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2538 target_remove_hw_breakpoint (bl
->gdbarch
,
2539 &bl
->overlay_target_info
);
2541 target_remove_breakpoint (bl
->gdbarch
,
2542 &bl
->overlay_target_info
);
2544 /* Did we set a breakpoint at the VMA?
2545 If so, we will have marked the breakpoint 'inserted'. */
2548 /* Yes -- remove it. Previously we did not bother to
2549 remove the breakpoint if the section had been
2550 unmapped, but let's not rely on that being safe. We
2551 don't know what the overlay manager might do. */
2552 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2553 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2556 /* However, we should remove *software* breakpoints only
2557 if the section is still mapped, or else we overwrite
2558 wrong code with the saved shadow contents. */
2559 else if (section_is_mapped (bl
->section
))
2560 val
= target_remove_breakpoint (bl
->gdbarch
,
2567 /* No -- not inserted, so no need to remove. No error. */
2572 /* In some cases, we might not be able to remove a breakpoint
2573 in a shared library that has already been removed, but we
2574 have not yet processed the shlib unload event. */
2575 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2580 bl
->inserted
= (is
== mark_inserted
);
2582 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2584 gdb_assert (bl
->owner
->ops
!= NULL
2585 && bl
->owner
->ops
->remove_location
!= NULL
);
2587 bl
->inserted
= (is
== mark_inserted
);
2588 bl
->owner
->ops
->remove_location (bl
);
2590 /* Failure to remove any of the hardware watchpoints comes here. */
2591 if ((is
== mark_uninserted
) && (bl
->inserted
))
2592 warning (_("Could not remove hardware watchpoint %d."),
2595 else if (bl
->owner
->type
== bp_catchpoint
2596 && breakpoint_enabled (bl
->owner
)
2599 gdb_assert (bl
->owner
->ops
!= NULL
2600 && bl
->owner
->ops
->remove_location
!= NULL
);
2602 val
= bl
->owner
->ops
->remove_location (bl
);
2606 bl
->inserted
= (is
== mark_inserted
);
2613 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2616 struct cleanup
*old_chain
;
2618 /* BL is never in moribund_locations by our callers. */
2619 gdb_assert (bl
->owner
!= NULL
);
2621 if (bl
->owner
->enable_state
== bp_permanent
)
2622 /* Permanent breakpoints cannot be inserted or removed. */
2625 /* The type of none suggests that owner is actually deleted.
2626 This should not ever happen. */
2627 gdb_assert (bl
->owner
->type
!= bp_none
);
2629 old_chain
= save_current_space_and_thread ();
2631 switch_to_program_space_and_thread (bl
->pspace
);
2633 ret
= remove_breakpoint_1 (bl
, is
);
2635 do_cleanups (old_chain
);
2639 /* Clear the "inserted" flag in all breakpoints. */
2642 mark_breakpoints_out (void)
2644 struct bp_location
*bl
, **blp_tmp
;
2646 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2647 if (bl
->pspace
== current_program_space
)
2651 /* Clear the "inserted" flag in all breakpoints and delete any
2652 breakpoints which should go away between runs of the program.
2654 Plus other such housekeeping that has to be done for breakpoints
2657 Note: this function gets called at the end of a run (by
2658 generic_mourn_inferior) and when a run begins (by
2659 init_wait_for_inferior). */
2664 breakpoint_init_inferior (enum inf_context context
)
2666 struct breakpoint
*b
, *b_tmp
;
2667 struct bp_location
*bl
, **blp_tmp
;
2669 struct program_space
*pspace
= current_program_space
;
2671 /* If breakpoint locations are shared across processes, then there's
2673 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2676 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2678 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2679 if (bl
->pspace
== pspace
2680 && bl
->owner
->enable_state
!= bp_permanent
)
2684 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2686 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2693 /* If the call dummy breakpoint is at the entry point it will
2694 cause problems when the inferior is rerun, so we better get
2697 case bp_watchpoint_scope
:
2699 /* Also get rid of scope breakpoints. */
2701 case bp_shlib_event
:
2703 /* Also remove solib event breakpoints. Their addresses may
2704 have changed since the last time we ran the program.
2705 Actually we may now be debugging against different target;
2706 and so the solib backend that installed this breakpoint may
2707 not be used in by the target. E.g.,
2709 (gdb) file prog-linux
2710 (gdb) run # native linux target
2713 (gdb) file prog-win.exe
2714 (gdb) tar rem :9999 # remote Windows gdbserver.
2717 delete_breakpoint (b
);
2721 case bp_hardware_watchpoint
:
2722 case bp_read_watchpoint
:
2723 case bp_access_watchpoint
:
2725 /* Likewise for watchpoints on local expressions. */
2726 if (b
->exp_valid_block
!= NULL
)
2727 delete_breakpoint (b
);
2728 else if (context
== inf_starting
)
2730 /* Reset val field to force reread of starting value in
2731 insert_breakpoints. */
2733 value_free (b
->val
);
2743 /* Get rid of the moribund locations. */
2744 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2745 decref_bp_location (&bl
);
2746 VEC_free (bp_location_p
, moribund_locations
);
2749 /* These functions concern about actual breakpoints inserted in the
2750 target --- to e.g. check if we need to do decr_pc adjustment or if
2751 we need to hop over the bkpt --- so we check for address space
2752 match, not program space. */
2754 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2755 exists at PC. It returns ordinary_breakpoint_here if it's an
2756 ordinary breakpoint, or permanent_breakpoint_here if it's a
2757 permanent breakpoint.
2758 - When continuing from a location with an ordinary breakpoint, we
2759 actually single step once before calling insert_breakpoints.
2760 - When continuing from a localion with a permanent breakpoint, we
2761 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2762 the target, to advance the PC past the breakpoint. */
2764 enum breakpoint_here
2765 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2767 struct bp_location
*bl
, **blp_tmp
;
2768 int any_breakpoint_here
= 0;
2770 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2772 if (bl
->loc_type
!= bp_loc_software_breakpoint
2773 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2776 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2777 if ((breakpoint_enabled (bl
->owner
)
2778 || bl
->owner
->enable_state
== bp_permanent
)
2779 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2782 if (overlay_debugging
2783 && section_is_overlay (bl
->section
)
2784 && !section_is_mapped (bl
->section
))
2785 continue; /* unmapped overlay -- can't be a match */
2786 else if (bl
->owner
->enable_state
== bp_permanent
)
2787 return permanent_breakpoint_here
;
2789 any_breakpoint_here
= 1;
2793 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2796 /* Return true if there's a moribund breakpoint at PC. */
2799 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2801 struct bp_location
*loc
;
2804 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2805 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2812 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2813 inserted using regular breakpoint_chain / bp_location array
2814 mechanism. This does not check for single-step breakpoints, which
2815 are inserted and removed using direct target manipulation. */
2818 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2821 struct bp_location
*bl
, **blp_tmp
;
2823 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2825 if (bl
->loc_type
!= bp_loc_software_breakpoint
2826 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2830 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2833 if (overlay_debugging
2834 && section_is_overlay (bl
->section
)
2835 && !section_is_mapped (bl
->section
))
2836 continue; /* unmapped overlay -- can't be a match */
2844 /* Returns non-zero iff there's either regular breakpoint
2845 or a single step breakpoint inserted at PC. */
2848 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2850 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2853 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2859 /* This function returns non-zero iff there is a software breakpoint
2863 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2866 struct bp_location
*bl
, **blp_tmp
;
2868 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2870 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2874 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2877 if (overlay_debugging
2878 && section_is_overlay (bl
->section
)
2879 && !section_is_mapped (bl
->section
))
2880 continue; /* unmapped overlay -- can't be a match */
2886 /* Also check for software single-step breakpoints. */
2887 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2894 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2895 CORE_ADDR addr
, ULONGEST len
)
2897 struct breakpoint
*bpt
;
2899 ALL_BREAKPOINTS (bpt
)
2901 struct bp_location
*loc
;
2903 if (bpt
->type
!= bp_hardware_watchpoint
2904 && bpt
->type
!= bp_access_watchpoint
)
2907 if (!breakpoint_enabled (bpt
))
2910 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2911 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2915 /* Check for intersection. */
2916 l
= max (loc
->address
, addr
);
2917 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2925 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2926 PC is valid for process/thread PTID. */
2929 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2932 struct bp_location
*bl
, **blp_tmp
;
2933 /* The thread and task IDs associated to PTID, computed lazily. */
2937 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2939 if (bl
->loc_type
!= bp_loc_software_breakpoint
2940 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2943 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2944 if (!breakpoint_enabled (bl
->owner
)
2945 && bl
->owner
->enable_state
!= bp_permanent
)
2948 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2952 if (bl
->owner
->thread
!= -1)
2954 /* This is a thread-specific breakpoint. Check that ptid
2955 matches that thread. If thread hasn't been computed yet,
2956 it is now time to do so. */
2958 thread
= pid_to_thread_id (ptid
);
2959 if (bl
->owner
->thread
!= thread
)
2963 if (bl
->owner
->task
!= 0)
2965 /* This is a task-specific breakpoint. Check that ptid
2966 matches that task. If task hasn't been computed yet,
2967 it is now time to do so. */
2969 task
= ada_get_task_number (ptid
);
2970 if (bl
->owner
->task
!= task
)
2974 if (overlay_debugging
2975 && section_is_overlay (bl
->section
)
2976 && !section_is_mapped (bl
->section
))
2977 continue; /* unmapped overlay -- can't be a match */
2986 /* bpstat stuff. External routines' interfaces are documented
2990 ep_is_catchpoint (struct breakpoint
*ep
)
2992 return (ep
->type
== bp_catchpoint
);
2995 /* Frees any storage that is part of a bpstat. Does not walk the
2999 bpstat_free (bpstat bs
)
3001 if (bs
->old_val
!= NULL
)
3002 value_free (bs
->old_val
);
3003 decref_counted_command_line (&bs
->commands
);
3004 decref_bp_location (&bs
->bp_location_at
);
3008 /* Clear a bpstat so that it says we are not at any breakpoint.
3009 Also free any storage that is part of a bpstat. */
3012 bpstat_clear (bpstat
*bsp
)
3029 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3030 is part of the bpstat is copied as well. */
3033 bpstat_copy (bpstat bs
)
3037 bpstat retval
= NULL
;
3042 for (; bs
!= NULL
; bs
= bs
->next
)
3044 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3045 memcpy (tmp
, bs
, sizeof (*tmp
));
3046 incref_counted_command_line (tmp
->commands
);
3047 incref_bp_location (tmp
->bp_location_at
);
3048 if (bs
->old_val
!= NULL
)
3050 tmp
->old_val
= value_copy (bs
->old_val
);
3051 release_value (tmp
->old_val
);
3055 /* This is the first thing in the chain. */
3065 /* Find the bpstat associated with this breakpoint. */
3068 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3073 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3075 if (bsp
->breakpoint_at
== breakpoint
)
3081 /* Put in *NUM the breakpoint number of the first breakpoint we are
3082 stopped at. *BSP upon return is a bpstat which points to the
3083 remaining breakpoints stopped at (but which is not guaranteed to be
3084 good for anything but further calls to bpstat_num).
3086 Return 0 if passed a bpstat which does not indicate any breakpoints.
3087 Return -1 if stopped at a breakpoint that has been deleted since
3089 Return 1 otherwise. */
3092 bpstat_num (bpstat
*bsp
, int *num
)
3094 struct breakpoint
*b
;
3097 return 0; /* No more breakpoint values */
3099 /* We assume we'll never have several bpstats that correspond to a
3100 single breakpoint -- otherwise, this function might return the
3101 same number more than once and this will look ugly. */
3102 b
= (*bsp
)->breakpoint_at
;
3103 *bsp
= (*bsp
)->next
;
3105 return -1; /* breakpoint that's been deleted since */
3107 *num
= b
->number
; /* We have its number */
3111 /* Modify BS so that the actions will not be performed. */
3114 bpstat_clear_actions (bpstat bs
)
3116 for (; bs
!= NULL
; bs
= bs
->next
)
3118 decref_counted_command_line (&bs
->commands
);
3119 bs
->commands_left
= NULL
;
3120 if (bs
->old_val
!= NULL
)
3122 value_free (bs
->old_val
);
3128 /* Called when a command is about to proceed the inferior. */
3131 breakpoint_about_to_proceed (void)
3133 if (!ptid_equal (inferior_ptid
, null_ptid
))
3135 struct thread_info
*tp
= inferior_thread ();
3137 /* Allow inferior function calls in breakpoint commands to not
3138 interrupt the command list. When the call finishes
3139 successfully, the inferior will be standing at the same
3140 breakpoint as if nothing happened. */
3141 if (tp
->control
.in_infcall
)
3145 breakpoint_proceeded
= 1;
3148 /* Stub for cleaning up our state if we error-out of a breakpoint
3151 cleanup_executing_breakpoints (void *ignore
)
3153 executing_breakpoint_commands
= 0;
3156 /* Execute all the commands associated with all the breakpoints at
3157 this location. Any of these commands could cause the process to
3158 proceed beyond this point, etc. We look out for such changes by
3159 checking the global "breakpoint_proceeded" after each command.
3161 Returns true if a breakpoint command resumed the inferior. In that
3162 case, it is the caller's responsibility to recall it again with the
3163 bpstat of the current thread. */
3166 bpstat_do_actions_1 (bpstat
*bsp
)
3169 struct cleanup
*old_chain
;
3172 /* Avoid endless recursion if a `source' command is contained
3174 if (executing_breakpoint_commands
)
3177 executing_breakpoint_commands
= 1;
3178 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3180 /* This pointer will iterate over the list of bpstat's. */
3183 breakpoint_proceeded
= 0;
3184 for (; bs
!= NULL
; bs
= bs
->next
)
3186 struct counted_command_line
*ccmd
;
3187 struct command_line
*cmd
;
3188 struct cleanup
*this_cmd_tree_chain
;
3190 /* Take ownership of the BSP's command tree, if it has one.
3192 The command tree could legitimately contain commands like
3193 'step' and 'next', which call clear_proceed_status, which
3194 frees stop_bpstat's command tree. To make sure this doesn't
3195 free the tree we're executing out from under us, we need to
3196 take ownership of the tree ourselves. Since a given bpstat's
3197 commands are only executed once, we don't need to copy it; we
3198 can clear the pointer in the bpstat, and make sure we free
3199 the tree when we're done. */
3200 ccmd
= bs
->commands
;
3201 bs
->commands
= NULL
;
3203 = make_cleanup_decref_counted_command_line (&ccmd
);
3204 cmd
= bs
->commands_left
;
3205 bs
->commands_left
= NULL
;
3209 execute_control_command (cmd
);
3211 if (breakpoint_proceeded
)
3217 /* We can free this command tree now. */
3218 do_cleanups (this_cmd_tree_chain
);
3220 if (breakpoint_proceeded
)
3222 if (target_can_async_p ())
3223 /* If we are in async mode, then the target might be still
3224 running, not stopped at any breakpoint, so nothing for
3225 us to do here -- just return to the event loop. */
3228 /* In sync mode, when execute_control_command returns
3229 we're already standing on the next breakpoint.
3230 Breakpoint commands for that stop were not run, since
3231 execute_command does not run breakpoint commands --
3232 only command_line_handler does, but that one is not
3233 involved in execution of breakpoint commands. So, we
3234 can now execute breakpoint commands. It should be
3235 noted that making execute_command do bpstat actions is
3236 not an option -- in this case we'll have recursive
3237 invocation of bpstat for each breakpoint with a
3238 command, and can easily blow up GDB stack. Instead, we
3239 return true, which will trigger the caller to recall us
3240 with the new stop_bpstat. */
3245 do_cleanups (old_chain
);
3250 bpstat_do_actions (void)
3252 /* Do any commands attached to breakpoint we are stopped at. */
3253 while (!ptid_equal (inferior_ptid
, null_ptid
)
3254 && target_has_execution
3255 && !is_exited (inferior_ptid
)
3256 && !is_executing (inferior_ptid
))
3257 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3258 and only return when it is stopped at the next breakpoint, we
3259 keep doing breakpoint actions until it returns false to
3260 indicate the inferior was not resumed. */
3261 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3265 /* Print out the (old or new) value associated with a watchpoint. */
3268 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3271 fprintf_unfiltered (stream
, _("<unreadable>"));
3274 struct value_print_options opts
;
3275 get_user_print_options (&opts
);
3276 value_print (val
, stream
, &opts
);
3280 /* This is the normal print function for a bpstat. In the future,
3281 much of this logic could (should?) be moved to bpstat_stop_status,
3282 by having it set different print_it values.
3284 Current scheme: When we stop, bpstat_print() is called. It loops
3285 through the bpstat list of things causing this stop, calling the
3286 print_bp_stop_message function on each one. The behavior of the
3287 print_bp_stop_message function depends on the print_it field of
3288 bpstat. If such field so indicates, call this function here.
3290 Return values from this routine (ultimately used by bpstat_print()
3291 and normal_stop() to decide what to do):
3292 PRINT_NOTHING: Means we already printed all we needed to print,
3293 don't print anything else.
3294 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3295 that something to be followed by a location.
3296 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3297 that something to be followed by a location.
3298 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3301 static enum print_stop_action
3302 print_it_typical (bpstat bs
)
3304 struct cleanup
*old_chain
;
3305 struct breakpoint
*b
;
3306 const struct bp_location
*bl
;
3307 struct ui_stream
*stb
;
3309 enum print_stop_action result
;
3311 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3312 which has since been deleted. */
3313 if (bs
->breakpoint_at
== NULL
)
3314 return PRINT_UNKNOWN
;
3316 gdb_assert (bs
->bp_location_at
!= NULL
);
3318 bl
= bs
->bp_location_at
;
3319 b
= bs
->breakpoint_at
;
3321 stb
= ui_out_stream_new (uiout
);
3322 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3327 case bp_hardware_breakpoint
:
3328 bp_temp
= b
->disposition
== disp_del
;
3329 if (bl
->address
!= bl
->requested_address
)
3330 breakpoint_adjustment_warning (bl
->requested_address
,
3333 annotate_breakpoint (b
->number
);
3335 ui_out_text (uiout
, "\nTemporary breakpoint ");
3337 ui_out_text (uiout
, "\nBreakpoint ");
3338 if (ui_out_is_mi_like_p (uiout
))
3340 ui_out_field_string (uiout
, "reason",
3341 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3342 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3344 ui_out_field_int (uiout
, "bkptno", b
->number
);
3345 ui_out_text (uiout
, ", ");
3346 result
= PRINT_SRC_AND_LOC
;
3349 case bp_shlib_event
:
3350 /* Did we stop because the user set the stop_on_solib_events
3351 variable? (If so, we report this as a generic, "Stopped due
3352 to shlib event" message.) */
3353 printf_filtered (_("Stopped due to shared library event\n"));
3354 result
= PRINT_NOTHING
;
3357 case bp_thread_event
:
3358 /* Not sure how we will get here.
3359 GDB should not stop for these breakpoints. */
3360 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3361 result
= PRINT_NOTHING
;
3364 case bp_overlay_event
:
3365 /* By analogy with the thread event, GDB should not stop for these. */
3366 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3367 result
= PRINT_NOTHING
;
3370 case bp_longjmp_master
:
3371 /* These should never be enabled. */
3372 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3373 result
= PRINT_NOTHING
;
3376 case bp_std_terminate_master
:
3377 /* These should never be enabled. */
3378 printf_filtered (_("std::terminate Master Breakpoint: "
3379 "gdb should not stop!\n"));
3380 result
= PRINT_NOTHING
;
3383 case bp_exception_master
:
3384 /* These should never be enabled. */
3385 printf_filtered (_("Exception Master Breakpoint: "
3386 "gdb should not stop!\n"));
3387 result
= PRINT_NOTHING
;
3391 case bp_hardware_watchpoint
:
3392 annotate_watchpoint (b
->number
);
3393 if (ui_out_is_mi_like_p (uiout
))
3396 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3398 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3399 ui_out_text (uiout
, "\nOld value = ");
3400 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3401 ui_out_field_stream (uiout
, "old", stb
);
3402 ui_out_text (uiout
, "\nNew value = ");
3403 watchpoint_value_print (b
->val
, stb
->stream
);
3404 ui_out_field_stream (uiout
, "new", stb
);
3405 ui_out_text (uiout
, "\n");
3406 /* More than one watchpoint may have been triggered. */
3407 result
= PRINT_UNKNOWN
;
3410 case bp_read_watchpoint
:
3411 if (ui_out_is_mi_like_p (uiout
))
3414 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3416 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3417 ui_out_text (uiout
, "\nValue = ");
3418 watchpoint_value_print (b
->val
, stb
->stream
);
3419 ui_out_field_stream (uiout
, "value", stb
);
3420 ui_out_text (uiout
, "\n");
3421 result
= PRINT_UNKNOWN
;
3424 case bp_access_watchpoint
:
3425 if (bs
->old_val
!= NULL
)
3427 annotate_watchpoint (b
->number
);
3428 if (ui_out_is_mi_like_p (uiout
))
3431 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3433 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3434 ui_out_text (uiout
, "\nOld value = ");
3435 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3436 ui_out_field_stream (uiout
, "old", stb
);
3437 ui_out_text (uiout
, "\nNew value = ");
3442 if (ui_out_is_mi_like_p (uiout
))
3445 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3446 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3447 ui_out_text (uiout
, "\nValue = ");
3449 watchpoint_value_print (b
->val
, stb
->stream
);
3450 ui_out_field_stream (uiout
, "new", stb
);
3451 ui_out_text (uiout
, "\n");
3452 result
= PRINT_UNKNOWN
;
3455 /* Fall through, we don't deal with these types of breakpoints
3459 if (ui_out_is_mi_like_p (uiout
))
3462 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3463 result
= PRINT_UNKNOWN
;
3467 if (ui_out_is_mi_like_p (uiout
))
3470 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3471 result
= PRINT_UNKNOWN
;
3476 case bp_longjmp_resume
:
3478 case bp_exception_resume
:
3479 case bp_step_resume
:
3480 case bp_watchpoint_scope
:
3482 case bp_std_terminate
:
3484 case bp_fast_tracepoint
:
3487 result
= PRINT_UNKNOWN
;
3491 do_cleanups (old_chain
);
3495 /* Generic routine for printing messages indicating why we
3496 stopped. The behavior of this function depends on the value
3497 'print_it' in the bpstat structure. Under some circumstances we
3498 may decide not to print anything here and delegate the task to
3501 static enum print_stop_action
3502 print_bp_stop_message (bpstat bs
)
3504 switch (bs
->print_it
)
3507 /* Nothing should be printed for this bpstat entry. */
3508 return PRINT_UNKNOWN
;
3512 /* We still want to print the frame, but we already printed the
3513 relevant messages. */
3514 return PRINT_SRC_AND_LOC
;
3517 case print_it_normal
:
3519 struct breakpoint
*b
= bs
->breakpoint_at
;
3521 /* Normal case. Call the breakpoint's print_it method, or
3522 print_it_typical. */
3523 /* FIXME: how breakpoint can ever be NULL here? */
3524 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3525 return b
->ops
->print_it (b
);
3527 return print_it_typical (bs
);
3532 internal_error (__FILE__
, __LINE__
,
3533 _("print_bp_stop_message: unrecognized enum value"));
3538 /* Print a message indicating what happened. This is called from
3539 normal_stop(). The input to this routine is the head of the bpstat
3540 list - a list of the eventpoints that caused this stop. This
3541 routine calls the generic print routine for printing a message
3542 about reasons for stopping. This will print (for example) the
3543 "Breakpoint n," part of the output. The return value of this
3546 PRINT_UNKNOWN: Means we printed nothing.
3547 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3548 code to print the location. An example is
3549 "Breakpoint 1, " which should be followed by
3551 PRINT_SRC_ONLY: Means we printed something, but there is no need
3552 to also print the location part of the message.
3553 An example is the catch/throw messages, which
3554 don't require a location appended to the end.
3555 PRINT_NOTHING: We have done some printing and we don't need any
3556 further info to be printed. */
3558 enum print_stop_action
3559 bpstat_print (bpstat bs
)
3563 /* Maybe another breakpoint in the chain caused us to stop.
3564 (Currently all watchpoints go on the bpstat whether hit or not.
3565 That probably could (should) be changed, provided care is taken
3566 with respect to bpstat_explains_signal). */
3567 for (; bs
; bs
= bs
->next
)
3569 val
= print_bp_stop_message (bs
);
3570 if (val
== PRINT_SRC_ONLY
3571 || val
== PRINT_SRC_AND_LOC
3572 || val
== PRINT_NOTHING
)
3576 /* We reached the end of the chain, or we got a null BS to start
3577 with and nothing was printed. */
3578 return PRINT_UNKNOWN
;
3581 /* Evaluate the expression EXP and return 1 if value is zero. This is
3582 used inside a catch_errors to evaluate the breakpoint condition.
3583 The argument is a "struct expression *" that has been cast to a
3584 "char *" to make it pass through catch_errors. */
3587 breakpoint_cond_eval (void *exp
)
3589 struct value
*mark
= value_mark ();
3590 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3592 value_free_to_mark (mark
);
3596 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3599 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3603 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3605 **bs_link_pointer
= bs
;
3606 *bs_link_pointer
= &bs
->next
;
3607 bs
->breakpoint_at
= bl
->owner
;
3608 bs
->bp_location_at
= bl
;
3609 incref_bp_location (bl
);
3610 /* If the condition is false, etc., don't do the commands. */
3611 bs
->commands
= NULL
;
3612 bs
->commands_left
= NULL
;
3614 bs
->print_it
= print_it_normal
;
3618 /* The target has stopped with waitstatus WS. Check if any hardware
3619 watchpoints have triggered, according to the target. */
3622 watchpoints_triggered (struct target_waitstatus
*ws
)
3624 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3626 struct breakpoint
*b
;
3628 if (!stopped_by_watchpoint
)
3630 /* We were not stopped by a watchpoint. Mark all watchpoints
3631 as not triggered. */
3633 if (is_hardware_watchpoint (b
))
3634 b
->watchpoint_triggered
= watch_triggered_no
;
3639 if (!target_stopped_data_address (¤t_target
, &addr
))
3641 /* We were stopped by a watchpoint, but we don't know where.
3642 Mark all watchpoints as unknown. */
3644 if (is_hardware_watchpoint (b
))
3645 b
->watchpoint_triggered
= watch_triggered_unknown
;
3647 return stopped_by_watchpoint
;
3650 /* The target could report the data address. Mark watchpoints
3651 affected by this data address as triggered, and all others as not
3655 if (is_hardware_watchpoint (b
))
3657 struct bp_location
*loc
;
3659 b
->watchpoint_triggered
= watch_triggered_no
;
3660 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3661 /* Exact match not required. Within range is
3663 if (target_watchpoint_addr_within_range (¤t_target
,
3667 b
->watchpoint_triggered
= watch_triggered_yes
;
3675 /* Possible return values for watchpoint_check (this can't be an enum
3676 because of check_errors). */
3677 /* The watchpoint has been deleted. */
3678 #define WP_DELETED 1
3679 /* The value has changed. */
3680 #define WP_VALUE_CHANGED 2
3681 /* The value has not changed. */
3682 #define WP_VALUE_NOT_CHANGED 3
3683 /* Ignore this watchpoint, no matter if the value changed or not. */
3686 #define BP_TEMPFLAG 1
3687 #define BP_HARDWAREFLAG 2
3689 /* Evaluate watchpoint condition expression and check if its value
3692 P should be a pointer to struct bpstat, but is defined as a void *
3693 in order for this function to be usable with catch_errors. */
3696 watchpoint_check (void *p
)
3698 bpstat bs
= (bpstat
) p
;
3699 struct breakpoint
*b
;
3700 struct frame_info
*fr
;
3701 int within_current_scope
;
3703 /* BS is built from an existing struct breakpoint. */
3704 gdb_assert (bs
->breakpoint_at
!= NULL
);
3705 b
= bs
->breakpoint_at
;
3707 /* If this is a local watchpoint, we only want to check if the
3708 watchpoint frame is in scope if the current thread is the thread
3709 that was used to create the watchpoint. */
3710 if (!watchpoint_in_thread_scope (b
))
3713 if (b
->exp_valid_block
== NULL
)
3714 within_current_scope
= 1;
3717 struct frame_info
*frame
= get_current_frame ();
3718 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3719 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3721 /* in_function_epilogue_p() returns a non-zero value if we're
3722 still in the function but the stack frame has already been
3723 invalidated. Since we can't rely on the values of local
3724 variables after the stack has been destroyed, we are treating
3725 the watchpoint in that state as `not changed' without further
3726 checking. Don't mark watchpoints as changed if the current
3727 frame is in an epilogue - even if they are in some other
3728 frame, our view of the stack is likely to be wrong and
3729 frame_find_by_id could error out. */
3730 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3733 fr
= frame_find_by_id (b
->watchpoint_frame
);
3734 within_current_scope
= (fr
!= NULL
);
3736 /* If we've gotten confused in the unwinder, we might have
3737 returned a frame that can't describe this variable. */
3738 if (within_current_scope
)
3740 struct symbol
*function
;
3742 function
= get_frame_function (fr
);
3743 if (function
== NULL
3744 || !contained_in (b
->exp_valid_block
,
3745 SYMBOL_BLOCK_VALUE (function
)))
3746 within_current_scope
= 0;
3749 if (within_current_scope
)
3750 /* If we end up stopping, the current frame will get selected
3751 in normal_stop. So this call to select_frame won't affect
3756 if (within_current_scope
)
3758 /* We use value_{,free_to_}mark because it could be a *long*
3759 time before we return to the command level and call
3760 free_all_values. We can't call free_all_values because we
3761 might be in the middle of evaluating a function call. */
3764 struct value
*mark
= value_mark ();
3765 struct value
*new_val
;
3767 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3769 /* We use value_equal_contents instead of value_equal because
3770 the latter coerces an array to a pointer, thus comparing just
3771 the address of the array instead of its contents. This is
3772 not what we want. */
3773 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3774 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3776 if (new_val
!= NULL
)
3778 release_value (new_val
);
3779 value_free_to_mark (mark
);
3781 bs
->old_val
= b
->val
;
3784 return WP_VALUE_CHANGED
;
3788 /* Nothing changed. */
3789 value_free_to_mark (mark
);
3790 return WP_VALUE_NOT_CHANGED
;
3795 /* This seems like the only logical thing to do because
3796 if we temporarily ignored the watchpoint, then when
3797 we reenter the block in which it is valid it contains
3798 garbage (in the case of a function, it may have two
3799 garbage values, one before and one after the prologue).
3800 So we can't even detect the first assignment to it and
3801 watch after that (since the garbage may or may not equal
3802 the first value assigned). */
3803 /* We print all the stop information in print_it_typical(), but
3804 in this case, by the time we call print_it_typical() this bp
3805 will be deleted already. So we have no choice but print the
3806 information here. */
3807 if (ui_out_is_mi_like_p (uiout
))
3809 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3810 ui_out_text (uiout
, "\nWatchpoint ");
3811 ui_out_field_int (uiout
, "wpnum", b
->number
);
3813 " deleted because the program has left the block in\n\
3814 which its expression is valid.\n");
3816 if (b
->related_breakpoint
)
3818 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3819 b
->related_breakpoint
->related_breakpoint
= NULL
;
3820 b
->related_breakpoint
= NULL
;
3822 b
->disposition
= disp_del_at_next_stop
;
3828 /* Return true if it looks like target has stopped due to hitting
3829 breakpoint location BL. This function does not check if we
3830 should stop, only if BL explains the stop. */
3832 bpstat_check_location (const struct bp_location
*bl
,
3833 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3835 struct breakpoint
*b
= bl
->owner
;
3837 /* BL is from existing struct breakpoint. */
3838 gdb_assert (b
!= NULL
);
3840 /* By definition, the inferior does not report stops at
3842 if (is_tracepoint (b
))
3845 if (!is_watchpoint (b
)
3846 && b
->type
!= bp_hardware_breakpoint
3847 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3849 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3852 if (overlay_debugging
/* unmapped overlay section */
3853 && section_is_overlay (bl
->section
)
3854 && !section_is_mapped (bl
->section
))
3858 /* Continuable hardware watchpoints are treated as non-existent if the
3859 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3860 some data address). Otherwise gdb won't stop on a break instruction
3861 in the code (not from a breakpoint) when a hardware watchpoint has
3862 been defined. Also skip watchpoints which we know did not trigger
3863 (did not match the data address). */
3865 if (is_hardware_watchpoint (b
)
3866 && b
->watchpoint_triggered
== watch_triggered_no
)
3869 if (b
->type
== bp_hardware_breakpoint
)
3871 if (bl
->address
!= bp_addr
)
3873 if (overlay_debugging
/* unmapped overlay section */
3874 && section_is_overlay (bl
->section
)
3875 && !section_is_mapped (bl
->section
))
3879 if (b
->type
== bp_catchpoint
)
3881 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3882 if (!b
->ops
->breakpoint_hit (b
))
3889 /* If BS refers to a watchpoint, determine if the watched values
3890 has actually changed, and we should stop. If not, set BS->stop
3893 bpstat_check_watchpoint (bpstat bs
)
3895 const struct bp_location
*bl
;
3896 struct breakpoint
*b
;
3898 /* BS is built for existing struct breakpoint. */
3899 bl
= bs
->bp_location_at
;
3900 gdb_assert (bl
!= NULL
);
3901 b
= bs
->breakpoint_at
;
3902 gdb_assert (b
!= NULL
);
3904 if (is_watchpoint (b
))
3906 int must_check_value
= 0;
3908 if (b
->type
== bp_watchpoint
)
3909 /* For a software watchpoint, we must always check the
3911 must_check_value
= 1;
3912 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3913 /* We have a hardware watchpoint (read, write, or access)
3914 and the target earlier reported an address watched by
3916 must_check_value
= 1;
3917 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3918 && b
->type
== bp_hardware_watchpoint
)
3919 /* We were stopped by a hardware watchpoint, but the target could
3920 not report the data address. We must check the watchpoint's
3921 value. Access and read watchpoints are out of luck; without
3922 a data address, we can't figure it out. */
3923 must_check_value
= 1;
3925 if (must_check_value
)
3928 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3930 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3931 int e
= catch_errors (watchpoint_check
, bs
, message
,
3933 do_cleanups (cleanups
);
3937 /* We've already printed what needs to be printed. */
3938 bs
->print_it
= print_it_done
;
3942 bs
->print_it
= print_it_noop
;
3945 case WP_VALUE_CHANGED
:
3946 if (b
->type
== bp_read_watchpoint
)
3948 /* There are two cases to consider here:
3950 1. We're watching the triggered memory for reads.
3951 In that case, trust the target, and always report
3952 the watchpoint hit to the user. Even though
3953 reads don't cause value changes, the value may
3954 have changed since the last time it was read, and
3955 since we're not trapping writes, we will not see
3956 those, and as such we should ignore our notion of
3959 2. We're watching the triggered memory for both
3960 reads and writes. There are two ways this may
3963 2.1. This is a target that can't break on data
3964 reads only, but can break on accesses (reads or
3965 writes), such as e.g., x86. We detect this case
3966 at the time we try to insert read watchpoints.
3968 2.2. Otherwise, the target supports read
3969 watchpoints, but, the user set an access or write
3970 watchpoint watching the same memory as this read
3973 If we're watching memory writes as well as reads,
3974 ignore watchpoint hits when we find that the
3975 value hasn't changed, as reads don't cause
3976 changes. This still gives false positives when
3977 the program writes the same value to memory as
3978 what there was already in memory (we will confuse
3979 it for a read), but it's much better than
3982 int other_write_watchpoint
= 0;
3984 if (bl
->watchpoint_type
== hw_read
)
3986 struct breakpoint
*other_b
;
3988 ALL_BREAKPOINTS (other_b
)
3989 if ((other_b
->type
== bp_hardware_watchpoint
3990 || other_b
->type
== bp_access_watchpoint
)
3991 && (other_b
->watchpoint_triggered
3992 == watch_triggered_yes
))
3994 other_write_watchpoint
= 1;
3999 if (other_write_watchpoint
4000 || bl
->watchpoint_type
== hw_access
)
4002 /* We're watching the same memory for writes,
4003 and the value changed since the last time we
4004 updated it, so this trap must be for a write.
4006 bs
->print_it
= print_it_noop
;
4011 case WP_VALUE_NOT_CHANGED
:
4012 if (b
->type
== bp_hardware_watchpoint
4013 || b
->type
== bp_watchpoint
)
4015 /* Don't stop: write watchpoints shouldn't fire if
4016 the value hasn't changed. */
4017 bs
->print_it
= print_it_noop
;
4025 /* Error from catch_errors. */
4026 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
4027 if (b
->related_breakpoint
)
4028 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
4029 b
->disposition
= disp_del_at_next_stop
;
4030 /* We've already printed what needs to be printed. */
4031 bs
->print_it
= print_it_done
;
4035 else /* must_check_value == 0 */
4037 /* This is a case where some watchpoint(s) triggered, but
4038 not at the address of this watchpoint, or else no
4039 watchpoint triggered after all. So don't print
4040 anything for this watchpoint. */
4041 bs
->print_it
= print_it_noop
;
4048 /* Check conditions (condition proper, frame, thread and ignore count)
4049 of breakpoint referred to by BS. If we should not stop for this
4050 breakpoint, set BS->stop to 0. */
4053 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4055 int thread_id
= pid_to_thread_id (ptid
);
4056 const struct bp_location
*bl
;
4057 struct breakpoint
*b
;
4059 /* BS is built for existing struct breakpoint. */
4060 bl
= bs
->bp_location_at
;
4061 gdb_assert (bl
!= NULL
);
4062 b
= bs
->breakpoint_at
;
4063 gdb_assert (b
!= NULL
);
4065 if (frame_id_p (b
->frame_id
)
4066 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4070 int value_is_zero
= 0;
4071 struct expression
*cond
;
4073 if (is_watchpoint (b
))
4078 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4080 int within_current_scope
= 1;
4082 /* We use value_mark and value_free_to_mark because it could
4083 be a long time before we return to the command level and
4084 call free_all_values. We can't call free_all_values
4085 because we might be in the middle of evaluating a
4087 struct value
*mark
= value_mark ();
4089 /* Need to select the frame, with all that implies so that
4090 the conditions will have the right context. Because we
4091 use the frame, we will not see an inlined function's
4092 variables when we arrive at a breakpoint at the start
4093 of the inlined function; the current frame will be the
4095 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4096 select_frame (get_current_frame ());
4099 struct frame_info
*frame
;
4101 /* For local watchpoint expressions, which particular
4102 instance of a local is being watched matters, so we
4103 keep track of the frame to evaluate the expression
4104 in. To evaluate the condition however, it doesn't
4105 really matter which instantiation of the function
4106 where the condition makes sense triggers the
4107 watchpoint. This allows an expression like "watch
4108 global if q > 10" set in `func', catch writes to
4109 global on all threads that call `func', or catch
4110 writes on all recursive calls of `func' by a single
4111 thread. We simply always evaluate the condition in
4112 the innermost frame that's executing where it makes
4113 sense to evaluate the condition. It seems
4115 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4117 select_frame (frame
);
4119 within_current_scope
= 0;
4121 if (within_current_scope
)
4123 = catch_errors (breakpoint_cond_eval
, cond
,
4124 "Error in testing breakpoint condition:\n",
4128 warning (_("Watchpoint condition cannot be tested "
4129 "in the current scope"));
4130 /* If we failed to set the right context for this
4131 watchpoint, unconditionally report it. */
4134 /* FIXME-someday, should give breakpoint #. */
4135 value_free_to_mark (mark
);
4138 if (cond
&& value_is_zero
)
4142 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4146 else if (b
->ignore_count
> 0)
4149 annotate_ignore_count_change ();
4151 /* Increase the hit count even though we don't stop. */
4158 /* Get a bpstat associated with having just stopped at address
4159 BP_ADDR in thread PTID.
4161 Determine whether we stopped at a breakpoint, etc, or whether we
4162 don't understand this stop. Result is a chain of bpstat's such
4165 if we don't understand the stop, the result is a null pointer.
4167 if we understand why we stopped, the result is not null.
4169 Each element of the chain refers to a particular breakpoint or
4170 watchpoint at which we have stopped. (We may have stopped for
4171 several reasons concurrently.)
4173 Each element of the chain has valid next, breakpoint_at,
4174 commands, FIXME??? fields. */
4177 bpstat_stop_status (struct address_space
*aspace
,
4178 CORE_ADDR bp_addr
, ptid_t ptid
)
4180 struct breakpoint
*b
= NULL
;
4181 struct bp_location
*bl
;
4182 struct bp_location
*loc
;
4183 /* First item of allocated bpstat's. */
4184 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4185 /* Pointer to the last thing in the chain currently. */
4188 int need_remove_insert
;
4191 /* First, build the bpstat chain with locations that explain a
4192 target stop, while being careful to not set the target running,
4193 as that may invalidate locations (in particular watchpoint
4194 locations are recreated). Resuming will happen here with
4195 breakpoint conditions or watchpoint expressions that include
4196 inferior function calls. */
4200 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4203 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4205 /* For hardware watchpoints, we look only at the first
4206 location. The watchpoint_check function will work on the
4207 entire expression, not the individual locations. For
4208 read watchpoints, the watchpoints_triggered function has
4209 checked all locations already. */
4210 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4213 if (bl
->shlib_disabled
)
4216 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4219 /* Come here if it's a watchpoint, or if the break address
4222 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4225 /* Assume we stop. Should we find a watchpoint that is not
4226 actually triggered, or if the condition of the breakpoint
4227 evaluates as false, we'll reset 'stop' to 0. */
4231 /* If this is a scope breakpoint, mark the associated
4232 watchpoint as triggered so that we will handle the
4233 out-of-scope event. We'll get to the watchpoint next
4235 if (b
->type
== bp_watchpoint_scope
)
4236 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4240 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4242 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4245 bs
= bpstat_alloc (loc
, &bs_link
);
4246 /* For hits of moribund locations, we should just proceed. */
4249 bs
->print_it
= print_it_noop
;
4253 /* Now go through the locations that caused the target to stop, and
4254 check whether we're interested in reporting this stop to higher
4255 layers, or whether we should resume the target transparently. */
4259 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4264 bpstat_check_watchpoint (bs
);
4268 b
= bs
->breakpoint_at
;
4270 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4271 || b
->type
== bp_longjmp_master
4272 || b
->type
== bp_std_terminate_master
4273 || b
->type
== bp_exception_master
)
4274 /* We do not stop for these. */
4277 bpstat_check_breakpoint_conditions (bs
, ptid
);
4283 /* We will stop here. */
4284 if (b
->disposition
== disp_disable
)
4286 if (b
->enable_state
!= bp_permanent
)
4287 b
->enable_state
= bp_disabled
;
4292 bs
->commands
= b
->commands
;
4293 incref_counted_command_line (bs
->commands
);
4294 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4295 if (bs
->commands_left
4296 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4299 bs
->commands_left
->line
) == 0)))
4301 bs
->commands_left
= bs
->commands_left
->next
;
4306 /* Print nothing for this entry if we dont stop or dont print. */
4307 if (bs
->stop
== 0 || bs
->print
== 0)
4308 bs
->print_it
= print_it_noop
;
4311 /* If we aren't stopping, the value of some hardware watchpoint may
4312 not have changed, but the intermediate memory locations we are
4313 watching may have. Don't bother if we're stopping; this will get
4315 need_remove_insert
= 0;
4316 if (! bpstat_causes_stop (bs_head
))
4317 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4319 && bs
->breakpoint_at
4320 && is_hardware_watchpoint (bs
->breakpoint_at
))
4322 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4323 need_remove_insert
= 1;
4326 if (need_remove_insert
)
4327 update_global_location_list (1);
4328 else if (removed_any
)
4329 update_global_location_list (0);
4335 handle_jit_event (void)
4337 struct frame_info
*frame
;
4338 struct gdbarch
*gdbarch
;
4340 /* Switch terminal for any messages produced by
4341 breakpoint_re_set. */
4342 target_terminal_ours_for_output ();
4344 frame
= get_current_frame ();
4345 gdbarch
= get_frame_arch (frame
);
4347 jit_event_handler (gdbarch
);
4349 target_terminal_inferior ();
4352 /* Prepare WHAT final decision for infrun. */
4354 /* Decide what infrun needs to do with this bpstat. */
4357 bpstat_what (bpstat bs
)
4359 struct bpstat_what retval
;
4360 /* We need to defer calling `solib_add', as adding new symbols
4361 resets breakpoints, which in turn deletes breakpoint locations,
4362 and hence may clear unprocessed entries in the BS chain. */
4363 int shlib_event
= 0;
4366 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4367 retval
.call_dummy
= STOP_NONE
;
4368 retval
.is_longjmp
= 0;
4370 for (; bs
!= NULL
; bs
= bs
->next
)
4372 /* Extract this BS's action. After processing each BS, we check
4373 if its action overrides all we've seem so far. */
4374 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4377 if (bs
->breakpoint_at
== NULL
)
4379 /* I suspect this can happen if it was a momentary
4380 breakpoint which has since been deleted. */
4383 else if (bs
->breakpoint_at
== NULL
)
4386 bptype
= bs
->breakpoint_at
->type
;
4393 case bp_hardware_breakpoint
:
4399 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4401 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4404 this_action
= BPSTAT_WHAT_SINGLE
;
4407 case bp_hardware_watchpoint
:
4408 case bp_read_watchpoint
:
4409 case bp_access_watchpoint
:
4413 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4415 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4419 /* There was a watchpoint, but we're not stopping.
4420 This requires no further action. */
4425 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4426 retval
.is_longjmp
= bptype
== bp_longjmp
;
4428 case bp_longjmp_resume
:
4429 case bp_exception_resume
:
4430 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4431 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4433 case bp_step_resume
:
4435 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4438 /* It is for the wrong frame. */
4439 this_action
= BPSTAT_WHAT_SINGLE
;
4442 case bp_watchpoint_scope
:
4443 case bp_thread_event
:
4444 case bp_overlay_event
:
4445 case bp_longjmp_master
:
4446 case bp_std_terminate_master
:
4447 case bp_exception_master
:
4448 this_action
= BPSTAT_WHAT_SINGLE
;
4454 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4456 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4460 /* There was a catchpoint, but we're not stopping.
4461 This requires no further action. */
4464 case bp_shlib_event
:
4467 /* If requested, stop when the dynamic linker notifies GDB
4468 of events. This allows the user to get control and place
4469 breakpoints in initializer routines for dynamically
4470 loaded objects (among other things). */
4471 if (stop_on_solib_events
)
4472 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4474 this_action
= BPSTAT_WHAT_SINGLE
;
4478 this_action
= BPSTAT_WHAT_SINGLE
;
4481 /* Make sure the action is stop (silent or noisy),
4482 so infrun.c pops the dummy frame. */
4483 retval
.call_dummy
= STOP_STACK_DUMMY
;
4484 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4486 case bp_std_terminate
:
4487 /* Make sure the action is stop (silent or noisy),
4488 so infrun.c pops the dummy frame. */
4489 retval
.call_dummy
= STOP_STD_TERMINATE
;
4490 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4493 case bp_fast_tracepoint
:
4494 case bp_static_tracepoint
:
4495 /* Tracepoint hits should not be reported back to GDB, and
4496 if one got through somehow, it should have been filtered
4498 internal_error (__FILE__
, __LINE__
,
4499 _("bpstat_what: tracepoint encountered"));
4501 internal_error (__FILE__
, __LINE__
,
4502 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4505 retval
.main_action
= max (retval
.main_action
, this_action
);
4511 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4513 /* Check for any newly added shared libraries if we're supposed
4514 to be adding them automatically. */
4516 /* Switch terminal for any messages produced by
4517 breakpoint_re_set. */
4518 target_terminal_ours_for_output ();
4521 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4523 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4526 target_terminal_inferior ();
4532 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4534 handle_jit_event ();
4540 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4541 without hardware support). This isn't related to a specific bpstat,
4542 just to things like whether watchpoints are set. */
4545 bpstat_should_step (void)
4547 struct breakpoint
*b
;
4550 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4556 bpstat_causes_stop (bpstat bs
)
4558 for (; bs
!= NULL
; bs
= bs
->next
)
4567 /* Print the LOC location out of the list of B->LOC locations. */
4569 static void print_breakpoint_location (struct breakpoint
*b
,
4570 struct bp_location
*loc
,
4572 struct ui_stream
*stb
)
4574 struct cleanup
*old_chain
= save_current_program_space ();
4576 if (loc
!= NULL
&& loc
->shlib_disabled
)
4580 set_current_program_space (loc
->pspace
);
4582 if (b
->source_file
&& loc
)
4585 = find_pc_sect_function (loc
->address
, loc
->section
);
4588 ui_out_text (uiout
, "in ");
4589 ui_out_field_string (uiout
, "func",
4590 SYMBOL_PRINT_NAME (sym
));
4591 ui_out_wrap_hint (uiout
, wrap_indent
);
4592 ui_out_text (uiout
, " at ");
4594 ui_out_field_string (uiout
, "file", b
->source_file
);
4595 ui_out_text (uiout
, ":");
4597 if (ui_out_is_mi_like_p (uiout
))
4599 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4600 char *fullname
= symtab_to_fullname (sal
.symtab
);
4603 ui_out_field_string (uiout
, "fullname", fullname
);
4606 ui_out_field_int (uiout
, "line", b
->line_number
);
4610 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4612 ui_out_field_stream (uiout
, "at", stb
);
4615 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4617 do_cleanups (old_chain
);
4621 bptype_string (enum bptype type
)
4623 struct ep_type_description
4628 static struct ep_type_description bptypes
[] =
4630 {bp_none
, "?deleted?"},
4631 {bp_breakpoint
, "breakpoint"},
4632 {bp_hardware_breakpoint
, "hw breakpoint"},
4633 {bp_until
, "until"},
4634 {bp_finish
, "finish"},
4635 {bp_watchpoint
, "watchpoint"},
4636 {bp_hardware_watchpoint
, "hw watchpoint"},
4637 {bp_read_watchpoint
, "read watchpoint"},
4638 {bp_access_watchpoint
, "acc watchpoint"},
4639 {bp_longjmp
, "longjmp"},
4640 {bp_longjmp_resume
, "longjmp resume"},
4641 {bp_exception
, "exception"},
4642 {bp_exception_resume
, "exception resume"},
4643 {bp_step_resume
, "step resume"},
4644 {bp_watchpoint_scope
, "watchpoint scope"},
4645 {bp_call_dummy
, "call dummy"},
4646 {bp_std_terminate
, "std::terminate"},
4647 {bp_shlib_event
, "shlib events"},
4648 {bp_thread_event
, "thread events"},
4649 {bp_overlay_event
, "overlay events"},
4650 {bp_longjmp_master
, "longjmp master"},
4651 {bp_std_terminate_master
, "std::terminate master"},
4652 {bp_exception_master
, "exception master"},
4653 {bp_catchpoint
, "catchpoint"},
4654 {bp_tracepoint
, "tracepoint"},
4655 {bp_fast_tracepoint
, "fast tracepoint"},
4656 {bp_static_tracepoint
, "static tracepoint"},
4657 {bp_jit_event
, "jit events"},
4660 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4661 || ((int) type
!= bptypes
[(int) type
].type
))
4662 internal_error (__FILE__
, __LINE__
,
4663 _("bptypes table does not describe type #%d."),
4666 return bptypes
[(int) type
].description
;
4669 /* Print B to gdb_stdout. */
4672 print_one_breakpoint_location (struct breakpoint
*b
,
4673 struct bp_location
*loc
,
4675 struct bp_location
**last_loc
,
4676 int print_address_bits
,
4679 struct command_line
*l
;
4680 static char bpenables
[] = "nynny";
4681 char wrap_indent
[80];
4682 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4683 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4684 struct cleanup
*bkpt_chain
;
4686 int header_of_multiple
= 0;
4687 int part_of_multiple
= (loc
!= NULL
);
4688 struct value_print_options opts
;
4690 get_user_print_options (&opts
);
4692 gdb_assert (!loc
|| loc_number
!= 0);
4693 /* See comment in print_one_breakpoint concerning treatment of
4694 breakpoints with single disabled location. */
4697 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4698 header_of_multiple
= 1;
4703 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4707 if (part_of_multiple
)
4710 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4711 ui_out_field_string (uiout
, "number", formatted
);
4716 ui_out_field_int (uiout
, "number", b
->number
);
4721 if (part_of_multiple
)
4722 ui_out_field_skip (uiout
, "type");
4724 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4728 if (part_of_multiple
)
4729 ui_out_field_skip (uiout
, "disp");
4731 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4736 if (part_of_multiple
)
4737 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4739 ui_out_field_fmt (uiout
, "enabled", "%c",
4740 bpenables
[(int) b
->enable_state
]);
4741 ui_out_spaces (uiout
, 2);
4745 strcpy (wrap_indent
, " ");
4746 if (opts
.addressprint
)
4748 if (print_address_bits
<= 32)
4749 strcat (wrap_indent
, " ");
4751 strcat (wrap_indent
, " ");
4754 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4756 /* Although the print_one can possibly print all locations,
4757 calling it here is not likely to get any nice result. So,
4758 make sure there's just one location. */
4759 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4760 b
->ops
->print_one (b
, last_loc
);
4766 internal_error (__FILE__
, __LINE__
,
4767 _("print_one_breakpoint: bp_none encountered\n"));
4771 case bp_hardware_watchpoint
:
4772 case bp_read_watchpoint
:
4773 case bp_access_watchpoint
:
4774 /* Field 4, the address, is omitted (which makes the columns
4775 not line up too nicely with the headers, but the effect
4776 is relatively readable). */
4777 if (opts
.addressprint
)
4778 ui_out_field_skip (uiout
, "addr");
4780 ui_out_field_string (uiout
, "what", b
->exp_string
);
4784 case bp_hardware_breakpoint
:
4788 case bp_longjmp_resume
:
4790 case bp_exception_resume
:
4791 case bp_step_resume
:
4792 case bp_watchpoint_scope
:
4794 case bp_std_terminate
:
4795 case bp_shlib_event
:
4796 case bp_thread_event
:
4797 case bp_overlay_event
:
4798 case bp_longjmp_master
:
4799 case bp_std_terminate_master
:
4800 case bp_exception_master
:
4802 case bp_fast_tracepoint
:
4803 case bp_static_tracepoint
:
4805 if (opts
.addressprint
)
4808 if (header_of_multiple
)
4809 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4810 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4811 ui_out_field_string (uiout
, "addr", "<PENDING>");
4813 ui_out_field_core_addr (uiout
, "addr",
4814 loc
->gdbarch
, loc
->address
);
4817 if (!header_of_multiple
)
4818 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4825 /* For backward compatibility, don't display inferiors unless there
4828 && !header_of_multiple
4830 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4831 && (number_of_program_spaces () > 1
4832 || number_of_inferiors () > 1)
4833 /* LOC is for existing B, it cannot be in
4834 moribund_locations and thus having NULL OWNER. */
4835 && loc
->owner
->type
!= bp_catchpoint
)))
4837 struct inferior
*inf
;
4840 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4842 if (inf
->pspace
== loc
->pspace
)
4847 ui_out_text (uiout
, " inf ");
4850 ui_out_text (uiout
, ", ");
4851 ui_out_text (uiout
, plongest (inf
->num
));
4856 if (!part_of_multiple
)
4858 if (b
->thread
!= -1)
4860 /* FIXME: This seems to be redundant and lost here; see the
4861 "stop only in" line a little further down. */
4862 ui_out_text (uiout
, " thread ");
4863 ui_out_field_int (uiout
, "thread", b
->thread
);
4865 else if (b
->task
!= 0)
4867 ui_out_text (uiout
, " task ");
4868 ui_out_field_int (uiout
, "task", b
->task
);
4872 ui_out_text (uiout
, "\n");
4874 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4876 gdb_assert (b
->type
== bp_static_tracepoint
);
4878 ui_out_text (uiout
, "\tmarker id is ");
4879 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4880 b
->static_trace_marker_id
);
4881 ui_out_text (uiout
, "\n");
4884 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4887 ui_out_text (uiout
, "\tstop only in stack frame at ");
4888 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4890 ui_out_field_core_addr (uiout
, "frame",
4891 b
->gdbarch
, b
->frame_id
.stack_addr
);
4892 ui_out_text (uiout
, "\n");
4895 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4897 /* We do not print the condition for Ada exception catchpoints
4898 because the condition is an internal implementation detail
4899 that we do not want to expose to the user. */
4901 if (is_tracepoint (b
))
4902 ui_out_text (uiout
, "\ttrace only if ");
4904 ui_out_text (uiout
, "\tstop only if ");
4905 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4906 ui_out_text (uiout
, "\n");
4909 if (!part_of_multiple
&& b
->thread
!= -1)
4911 /* FIXME should make an annotation for this. */
4912 ui_out_text (uiout
, "\tstop only in thread ");
4913 ui_out_field_int (uiout
, "thread", b
->thread
);
4914 ui_out_text (uiout
, "\n");
4917 if (!part_of_multiple
&& b
->hit_count
)
4919 /* FIXME should make an annotation for this. */
4920 if (ep_is_catchpoint (b
))
4921 ui_out_text (uiout
, "\tcatchpoint");
4923 ui_out_text (uiout
, "\tbreakpoint");
4924 ui_out_text (uiout
, " already hit ");
4925 ui_out_field_int (uiout
, "times", b
->hit_count
);
4926 if (b
->hit_count
== 1)
4927 ui_out_text (uiout
, " time\n");
4929 ui_out_text (uiout
, " times\n");
4932 /* Output the count also if it is zero, but only if this is mi.
4933 FIXME: Should have a better test for this. */
4934 if (ui_out_is_mi_like_p (uiout
))
4935 if (!part_of_multiple
&& b
->hit_count
== 0)
4936 ui_out_field_int (uiout
, "times", b
->hit_count
);
4938 if (!part_of_multiple
&& b
->ignore_count
)
4941 ui_out_text (uiout
, "\tignore next ");
4942 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4943 ui_out_text (uiout
, " hits\n");
4946 l
= b
->commands
? b
->commands
->commands
: NULL
;
4947 if (!part_of_multiple
&& l
)
4949 struct cleanup
*script_chain
;
4952 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4953 print_command_lines (uiout
, l
, 4);
4954 do_cleanups (script_chain
);
4957 if (!part_of_multiple
&& b
->pass_count
)
4959 annotate_field (10);
4960 ui_out_text (uiout
, "\tpass count ");
4961 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4962 ui_out_text (uiout
, " \n");
4965 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4968 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4969 else if (b
->exp_string
)
4970 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4973 do_cleanups (bkpt_chain
);
4974 do_cleanups (old_chain
);
4978 print_one_breakpoint (struct breakpoint
*b
,
4979 struct bp_location
**last_loc
,
4980 int print_address_bits
,
4983 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4984 print_address_bits
, allflag
);
4986 /* If this breakpoint has custom print function,
4987 it's already printed. Otherwise, print individual
4988 locations, if any. */
4989 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4991 /* If breakpoint has a single location that is disabled, we
4992 print it as if it had several locations, since otherwise it's
4993 hard to represent "breakpoint enabled, location disabled"
4996 Note that while hardware watchpoints have several locations
4997 internally, that's not a property exposed to user. */
4999 && !is_hardware_watchpoint (b
)
5000 && (b
->loc
->next
|| !b
->loc
->enabled
)
5001 && !ui_out_is_mi_like_p (uiout
))
5003 struct bp_location
*loc
;
5005 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5006 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
5007 print_address_bits
, allflag
);
5013 breakpoint_address_bits (struct breakpoint
*b
)
5015 int print_address_bits
= 0;
5016 struct bp_location
*loc
;
5018 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5022 /* Software watchpoints that aren't watching memory don't have
5023 an address to print. */
5024 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5027 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5028 if (addr_bit
> print_address_bits
)
5029 print_address_bits
= addr_bit
;
5032 return print_address_bits
;
5035 struct captured_breakpoint_query_args
5041 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5043 struct captured_breakpoint_query_args
*args
= data
;
5044 struct breakpoint
*b
;
5045 struct bp_location
*dummy_loc
= NULL
;
5049 if (args
->bnum
== b
->number
)
5051 int print_address_bits
= breakpoint_address_bits (b
);
5053 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
5061 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5062 char **error_message
)
5064 struct captured_breakpoint_query_args args
;
5067 /* For the moment we don't trust print_one_breakpoint() to not throw
5069 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5070 error_message
, RETURN_MASK_ALL
) < 0)
5076 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5077 catchpoints, et.al.). */
5080 user_settable_breakpoint (const struct breakpoint
*b
)
5082 return (b
->type
== bp_breakpoint
5083 || b
->type
== bp_catchpoint
5084 || b
->type
== bp_hardware_breakpoint
5085 || is_tracepoint (b
)
5086 || is_watchpoint (b
));
5089 /* Return true if this breakpoint was set by the user, false if it is
5090 internal or momentary. */
5093 user_breakpoint_p (struct breakpoint
*b
)
5095 return user_settable_breakpoint (b
) && b
->number
> 0;
5098 /* Print information on user settable breakpoint (watchpoint, etc)
5099 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5100 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5101 FILTER is non-NULL, call it on each breakpoint and only include the
5102 ones for which it returns non-zero. Return the total number of
5103 breakpoints listed. */
5106 breakpoint_1 (char *args
, int allflag
,
5107 int (*filter
) (const struct breakpoint
*))
5109 struct breakpoint
*b
;
5110 struct bp_location
*last_loc
= NULL
;
5111 int nr_printable_breakpoints
;
5112 struct cleanup
*bkpttbl_chain
;
5113 struct value_print_options opts
;
5114 int print_address_bits
= 0;
5115 int print_type_col_width
= 14;
5117 get_user_print_options (&opts
);
5119 /* Compute the number of rows in the table, as well as the size
5120 required for address fields. */
5121 nr_printable_breakpoints
= 0;
5124 /* If we have a filter, only list the breakpoints it accepts. */
5125 if (filter
&& !filter (b
))
5128 /* If we have an "args" string, it is a list of breakpoints to
5129 accept. Skip the others. */
5130 if (args
!= NULL
&& *args
!= '\0')
5132 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5134 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5138 if (allflag
|| user_breakpoint_p (b
))
5140 int addr_bit
, type_len
;
5142 addr_bit
= breakpoint_address_bits (b
);
5143 if (addr_bit
> print_address_bits
)
5144 print_address_bits
= addr_bit
;
5146 type_len
= strlen (bptype_string (b
->type
));
5147 if (type_len
> print_type_col_width
)
5148 print_type_col_width
= type_len
;
5150 nr_printable_breakpoints
++;
5154 if (opts
.addressprint
)
5156 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5157 nr_printable_breakpoints
,
5161 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5162 nr_printable_breakpoints
,
5165 if (nr_printable_breakpoints
> 0)
5166 annotate_breakpoints_headers ();
5167 if (nr_printable_breakpoints
> 0)
5169 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5170 if (nr_printable_breakpoints
> 0)
5172 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5173 "type", "Type"); /* 2 */
5174 if (nr_printable_breakpoints
> 0)
5176 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5177 if (nr_printable_breakpoints
> 0)
5179 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5180 if (opts
.addressprint
)
5182 if (nr_printable_breakpoints
> 0)
5184 if (print_address_bits
<= 32)
5185 ui_out_table_header (uiout
, 10, ui_left
,
5186 "addr", "Address"); /* 5 */
5188 ui_out_table_header (uiout
, 18, ui_left
,
5189 "addr", "Address"); /* 5 */
5191 if (nr_printable_breakpoints
> 0)
5193 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5194 ui_out_table_body (uiout
);
5195 if (nr_printable_breakpoints
> 0)
5196 annotate_breakpoints_table ();
5201 /* If we have a filter, only list the breakpoints it accepts. */
5202 if (filter
&& !filter (b
))
5205 /* If we have an "args" string, it is a list of breakpoints to
5206 accept. Skip the others. */
5208 if (args
!= NULL
&& *args
!= '\0')
5210 if (allflag
) /* maintenance info breakpoint */
5212 if (parse_and_eval_long (args
) != b
->number
)
5215 else /* all others */
5217 if (!number_is_in_list (args
, b
->number
))
5221 /* We only print out user settable breakpoints unless the
5223 if (allflag
|| user_breakpoint_p (b
))
5224 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5227 do_cleanups (bkpttbl_chain
);
5229 if (nr_printable_breakpoints
== 0)
5231 /* If there's a filter, let the caller decide how to report
5235 if (args
== NULL
|| *args
== '\0')
5236 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5238 ui_out_message (uiout
, 0,
5239 "No breakpoint or watchpoint matching '%s'.\n",
5245 if (last_loc
&& !server_command
)
5246 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5249 /* FIXME? Should this be moved up so that it is only called when
5250 there have been breakpoints? */
5251 annotate_breakpoints_table_end ();
5253 return nr_printable_breakpoints
;
5256 /* Display the value of default-collect in a way that is generally
5257 compatible with the breakpoint list. */
5260 default_collect_info (void)
5262 /* If it has no value (which is frequently the case), say nothing; a
5263 message like "No default-collect." gets in user's face when it's
5265 if (!*default_collect
)
5268 /* The following phrase lines up nicely with per-tracepoint collect
5270 ui_out_text (uiout
, "default collect ");
5271 ui_out_field_string (uiout
, "default-collect", default_collect
);
5272 ui_out_text (uiout
, " \n");
5276 breakpoints_info (char *args
, int from_tty
)
5278 breakpoint_1 (args
, 0, NULL
);
5280 default_collect_info ();
5284 watchpoints_info (char *args
, int from_tty
)
5286 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5288 if (num_printed
== 0)
5290 if (args
== NULL
|| *args
== '\0')
5291 ui_out_message (uiout
, 0, "No watchpoints.\n");
5293 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5298 maintenance_info_breakpoints (char *args
, int from_tty
)
5300 breakpoint_1 (args
, 1, NULL
);
5302 default_collect_info ();
5306 breakpoint_has_pc (struct breakpoint
*b
,
5307 struct program_space
*pspace
,
5308 CORE_ADDR pc
, struct obj_section
*section
)
5310 struct bp_location
*bl
= b
->loc
;
5312 for (; bl
; bl
= bl
->next
)
5314 if (bl
->pspace
== pspace
5315 && bl
->address
== pc
5316 && (!overlay_debugging
|| bl
->section
== section
))
5322 /* Print a message describing any breakpoints set at PC. This
5323 concerns with logical breakpoints, so we match program spaces, not
5327 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5328 struct program_space
*pspace
, CORE_ADDR pc
,
5329 struct obj_section
*section
, int thread
)
5332 struct breakpoint
*b
;
5335 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5339 printf_filtered (_("Note: breakpoint "));
5340 else /* if (others == ???) */
5341 printf_filtered (_("Note: breakpoints "));
5343 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5346 printf_filtered ("%d", b
->number
);
5347 if (b
->thread
== -1 && thread
!= -1)
5348 printf_filtered (" (all threads)");
5349 else if (b
->thread
!= -1)
5350 printf_filtered (" (thread %d)", b
->thread
);
5351 printf_filtered ("%s%s ",
5352 ((b
->enable_state
== bp_disabled
5353 || b
->enable_state
== bp_call_disabled
5354 || b
->enable_state
== bp_startup_disabled
)
5356 : b
->enable_state
== bp_permanent
5360 : ((others
== 1) ? " and" : ""));
5362 printf_filtered (_("also set at pc "));
5363 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5364 printf_filtered (".\n");
5368 /* Set the default place to put a breakpoint
5369 for the `break' command with no arguments. */
5372 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5373 CORE_ADDR addr
, struct symtab
*symtab
,
5376 default_breakpoint_valid
= valid
;
5377 default_breakpoint_pspace
= pspace
;
5378 default_breakpoint_address
= addr
;
5379 default_breakpoint_symtab
= symtab
;
5380 default_breakpoint_line
= line
;
5383 /* Return true iff it is meaningful to use the address member of
5384 BPT. For some breakpoint types, the address member is irrelevant
5385 and it makes no sense to attempt to compare it to other addresses
5386 (or use it for any other purpose either).
5388 More specifically, each of the following breakpoint types will
5389 always have a zero valued address and we don't want to mark
5390 breakpoints of any of these types to be a duplicate of an actual
5391 breakpoint at address zero:
5399 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5401 enum bptype type
= bpt
->type
;
5403 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5406 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5407 true if LOC1 and LOC2 represent the same watchpoint location. */
5410 watchpoint_locations_match (struct bp_location
*loc1
,
5411 struct bp_location
*loc2
)
5413 /* Both of them must not be in moribund_locations. */
5414 gdb_assert (loc1
->owner
!= NULL
);
5415 gdb_assert (loc2
->owner
!= NULL
);
5417 /* If the target can evaluate the condition expression in hardware,
5418 then we we need to insert both watchpoints even if they are at
5419 the same place. Otherwise the watchpoint will only trigger when
5420 the condition of whichever watchpoint was inserted evaluates to
5421 true, not giving a chance for GDB to check the condition of the
5422 other watchpoint. */
5423 if ((loc1
->owner
->cond_exp
5424 && target_can_accel_watchpoint_condition (loc1
->address
,
5426 loc1
->watchpoint_type
,
5427 loc1
->owner
->cond_exp
))
5428 || (loc2
->owner
->cond_exp
5429 && target_can_accel_watchpoint_condition (loc2
->address
,
5431 loc2
->watchpoint_type
,
5432 loc2
->owner
->cond_exp
)))
5435 /* Note that this checks the owner's type, not the location's. In
5436 case the target does not support read watchpoints, but does
5437 support access watchpoints, we'll have bp_read_watchpoint
5438 watchpoints with hw_access locations. Those should be considered
5439 duplicates of hw_read locations. The hw_read locations will
5440 become hw_access locations later. */
5441 return (loc1
->owner
->type
== loc2
->owner
->type
5442 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5443 && loc1
->address
== loc2
->address
5444 && loc1
->length
== loc2
->length
);
5447 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5448 same breakpoint location. In most targets, this can only be true
5449 if ASPACE1 matches ASPACE2. On targets that have global
5450 breakpoints, the address space doesn't really matter. */
5453 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5454 struct address_space
*aspace2
, CORE_ADDR addr2
)
5456 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5457 || aspace1
== aspace2
)
5461 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5462 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5463 represent the same location. */
5466 breakpoint_locations_match (struct bp_location
*loc1
,
5467 struct bp_location
*loc2
)
5469 int hw_point1
, hw_point2
;
5471 /* Both of them must not be in moribund_locations. */
5472 gdb_assert (loc1
->owner
!= NULL
);
5473 gdb_assert (loc2
->owner
!= NULL
);
5475 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5476 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5478 if (hw_point1
!= hw_point2
)
5481 return watchpoint_locations_match (loc1
, loc2
);
5483 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5484 loc2
->pspace
->aspace
, loc2
->address
);
5488 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5489 int bnum
, int have_bnum
)
5494 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5495 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5497 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5498 bnum
, astr1
, astr2
);
5500 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5503 /* Adjust a breakpoint's address to account for architectural
5504 constraints on breakpoint placement. Return the adjusted address.
5505 Note: Very few targets require this kind of adjustment. For most
5506 targets, this function is simply the identity function. */
5509 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5510 CORE_ADDR bpaddr
, enum bptype bptype
)
5512 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5514 /* Very few targets need any kind of breakpoint adjustment. */
5517 else if (bptype
== bp_watchpoint
5518 || bptype
== bp_hardware_watchpoint
5519 || bptype
== bp_read_watchpoint
5520 || bptype
== bp_access_watchpoint
5521 || bptype
== bp_catchpoint
)
5523 /* Watchpoints and the various bp_catch_* eventpoints should not
5524 have their addresses modified. */
5529 CORE_ADDR adjusted_bpaddr
;
5531 /* Some targets have architectural constraints on the placement
5532 of breakpoint instructions. Obtain the adjusted address. */
5533 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5535 /* An adjusted breakpoint address can significantly alter
5536 a user's expectations. Print a warning if an adjustment
5538 if (adjusted_bpaddr
!= bpaddr
)
5539 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5541 return adjusted_bpaddr
;
5545 /* Allocate a struct bp_location. */
5547 static struct bp_location
*
5548 allocate_bp_location (struct breakpoint
*bpt
)
5550 struct bp_location
*loc
;
5552 loc
= xmalloc (sizeof (struct bp_location
));
5553 memset (loc
, 0, sizeof (*loc
));
5557 loc
->shlib_disabled
= 0;
5566 case bp_longjmp_resume
:
5568 case bp_exception_resume
:
5569 case bp_step_resume
:
5570 case bp_watchpoint_scope
:
5572 case bp_std_terminate
:
5573 case bp_shlib_event
:
5574 case bp_thread_event
:
5575 case bp_overlay_event
:
5577 case bp_longjmp_master
:
5578 case bp_std_terminate_master
:
5579 case bp_exception_master
:
5580 loc
->loc_type
= bp_loc_software_breakpoint
;
5582 case bp_hardware_breakpoint
:
5583 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5585 case bp_hardware_watchpoint
:
5586 case bp_read_watchpoint
:
5587 case bp_access_watchpoint
:
5588 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5593 case bp_fast_tracepoint
:
5594 case bp_static_tracepoint
:
5595 loc
->loc_type
= bp_loc_other
;
5598 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5606 free_bp_location (struct bp_location
*loc
)
5611 if (loc
->function_name
)
5612 xfree (loc
->function_name
);
5617 /* Increment reference count. */
5620 incref_bp_location (struct bp_location
*bl
)
5625 /* Decrement reference count. If the reference count reaches 0,
5626 destroy the bp_location. Sets *BLP to NULL. */
5629 decref_bp_location (struct bp_location
**blp
)
5631 gdb_assert ((*blp
)->refc
> 0);
5633 if (--(*blp
)->refc
== 0)
5634 free_bp_location (*blp
);
5638 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5639 type BPTYPE and has no locations as yet. */
5640 /* This function is used in gdbtk sources and thus can not be made
5643 static struct breakpoint
*
5644 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5647 struct breakpoint
*b
, *b1
;
5649 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5650 memset (b
, 0, sizeof (*b
));
5653 b
->gdbarch
= gdbarch
;
5654 b
->language
= current_language
->la_language
;
5655 b
->input_radix
= input_radix
;
5657 b
->enable_state
= bp_enabled
;
5660 b
->ignore_count
= 0;
5662 b
->frame_id
= null_frame_id
;
5663 b
->forked_inferior_pid
= null_ptid
;
5664 b
->exec_pathname
= NULL
;
5665 b
->syscalls_to_be_caught
= NULL
;
5667 b
->condition_not_parsed
= 0;
5668 b
->py_bp_object
= NULL
;
5670 /* Add this breakpoint to the end of the chain so that a list of
5671 breakpoints will come out in order of increasing numbers. */
5673 b1
= breakpoint_chain
;
5675 breakpoint_chain
= b
;
5685 /* Initialize loc->function_name. */
5687 set_breakpoint_location_function (struct bp_location
*loc
)
5689 gdb_assert (loc
->owner
!= NULL
);
5691 if (loc
->owner
->type
== bp_breakpoint
5692 || loc
->owner
->type
== bp_hardware_breakpoint
5693 || is_tracepoint (loc
->owner
))
5695 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5697 if (loc
->function_name
)
5698 loc
->function_name
= xstrdup (loc
->function_name
);
5702 /* Attempt to determine architecture of location identified by SAL. */
5703 static struct gdbarch
*
5704 get_sal_arch (struct symtab_and_line sal
)
5707 return get_objfile_arch (sal
.section
->objfile
);
5709 return get_objfile_arch (sal
.symtab
->objfile
);
5714 /* set_raw_breakpoint is a low level routine for allocating and
5715 partially initializing a breakpoint of type BPTYPE. The newly
5716 created breakpoint's address, section, source file name, and line
5717 number are provided by SAL. The newly created and partially
5718 initialized breakpoint is added to the breakpoint chain and
5719 is also returned as the value of this function.
5721 It is expected that the caller will complete the initialization of
5722 the newly created breakpoint struct as well as output any status
5723 information regarding the creation of a new breakpoint. In
5724 particular, set_raw_breakpoint does NOT set the breakpoint
5725 number! Care should be taken to not allow an error to occur
5726 prior to completing the initialization of the breakpoint. If this
5727 should happen, a bogus breakpoint will be left on the chain. */
5730 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5731 struct symtab_and_line sal
, enum bptype bptype
)
5733 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5735 CORE_ADDR adjusted_address
;
5736 struct gdbarch
*loc_gdbarch
;
5738 loc_gdbarch
= get_sal_arch (sal
);
5740 loc_gdbarch
= b
->gdbarch
;
5742 if (bptype
!= bp_catchpoint
)
5743 gdb_assert (sal
.pspace
!= NULL
);
5745 /* Adjust the breakpoint's address prior to allocating a location.
5746 Once we call allocate_bp_location(), that mostly uninitialized
5747 location will be placed on the location chain. Adjustment of the
5748 breakpoint may cause target_read_memory() to be called and we do
5749 not want its scan of the location chain to find a breakpoint and
5750 location that's only been partially initialized. */
5751 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5754 b
->loc
= allocate_bp_location (b
);
5755 b
->loc
->gdbarch
= loc_gdbarch
;
5756 b
->loc
->requested_address
= sal
.pc
;
5757 b
->loc
->address
= adjusted_address
;
5758 b
->loc
->pspace
= sal
.pspace
;
5760 /* Store the program space that was used to set the breakpoint, for
5761 breakpoint resetting. */
5762 b
->pspace
= sal
.pspace
;
5764 if (sal
.symtab
== NULL
)
5765 b
->source_file
= NULL
;
5767 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5768 b
->loc
->section
= sal
.section
;
5769 b
->line_number
= sal
.line
;
5771 set_breakpoint_location_function (b
->loc
);
5773 breakpoints_changed ();
5779 /* Note that the breakpoint object B describes a permanent breakpoint
5780 instruction, hard-wired into the inferior's code. */
5782 make_breakpoint_permanent (struct breakpoint
*b
)
5784 struct bp_location
*bl
;
5786 b
->enable_state
= bp_permanent
;
5788 /* By definition, permanent breakpoints are already present in the
5789 code. Mark all locations as inserted. For now,
5790 make_breakpoint_permanent is called in just one place, so it's
5791 hard to say if it's reasonable to have permanent breakpoint with
5792 multiple locations or not, but it's easy to implmement. */
5793 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5797 /* Call this routine when stepping and nexting to enable a breakpoint
5798 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5799 initiated the operation. */
5802 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5804 struct breakpoint
*b
, *b_tmp
;
5805 int thread
= tp
->num
;
5807 /* To avoid having to rescan all objfile symbols at every step,
5808 we maintain a list of continually-inserted but always disabled
5809 longjmp "master" breakpoints. Here, we simply create momentary
5810 clones of those and enable them for the requested thread. */
5811 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5812 if (b
->pspace
== current_program_space
5813 && (b
->type
== bp_longjmp_master
5814 || b
->type
== bp_exception_master
))
5816 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5818 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5819 clone
->thread
= thread
;
5822 tp
->initiating_frame
= frame
;
5825 /* Delete all longjmp breakpoints from THREAD. */
5827 delete_longjmp_breakpoint (int thread
)
5829 struct breakpoint
*b
, *b_tmp
;
5831 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5832 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5834 if (b
->thread
== thread
)
5835 delete_breakpoint (b
);
5840 enable_overlay_breakpoints (void)
5842 struct breakpoint
*b
;
5845 if (b
->type
== bp_overlay_event
)
5847 b
->enable_state
= bp_enabled
;
5848 update_global_location_list (1);
5849 overlay_events_enabled
= 1;
5854 disable_overlay_breakpoints (void)
5856 struct breakpoint
*b
;
5859 if (b
->type
== bp_overlay_event
)
5861 b
->enable_state
= bp_disabled
;
5862 update_global_location_list (0);
5863 overlay_events_enabled
= 0;
5867 /* Set an active std::terminate breakpoint for each std::terminate
5868 master breakpoint. */
5870 set_std_terminate_breakpoint (void)
5872 struct breakpoint
*b
, *b_tmp
;
5874 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5875 if (b
->pspace
== current_program_space
5876 && b
->type
== bp_std_terminate_master
)
5878 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5879 clone
->type
= bp_std_terminate
;
5883 /* Delete all the std::terminate breakpoints. */
5885 delete_std_terminate_breakpoint (void)
5887 struct breakpoint
*b
, *b_tmp
;
5889 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5890 if (b
->type
== bp_std_terminate
)
5891 delete_breakpoint (b
);
5895 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5897 struct breakpoint
*b
;
5899 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5901 b
->enable_state
= bp_enabled
;
5902 /* addr_string has to be used or breakpoint_re_set will delete me. */
5904 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5906 update_global_location_list_nothrow (1);
5912 remove_thread_event_breakpoints (void)
5914 struct breakpoint
*b
, *b_tmp
;
5916 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5917 if (b
->type
== bp_thread_event
5918 && b
->loc
->pspace
== current_program_space
)
5919 delete_breakpoint (b
);
5922 struct captured_parse_breakpoint_args
5925 struct symtabs_and_lines
*sals_p
;
5926 char ***addr_string_p
;
5930 struct lang_and_radix
5936 /* Create a breakpoint for JIT code registration and unregistration. */
5939 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5941 struct breakpoint
*b
;
5943 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5944 update_global_location_list_nothrow (1);
5948 /* Remove JIT code registration and unregistration breakpoint(s). */
5951 remove_jit_event_breakpoints (void)
5953 struct breakpoint
*b
, *b_tmp
;
5955 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5956 if (b
->type
== bp_jit_event
5957 && b
->loc
->pspace
== current_program_space
)
5958 delete_breakpoint (b
);
5962 remove_solib_event_breakpoints (void)
5964 struct breakpoint
*b
, *b_tmp
;
5966 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5967 if (b
->type
== bp_shlib_event
5968 && b
->loc
->pspace
== current_program_space
)
5969 delete_breakpoint (b
);
5973 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5975 struct breakpoint
*b
;
5977 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5978 update_global_location_list_nothrow (1);
5982 /* Disable any breakpoints that are on code in shared libraries. Only
5983 apply to enabled breakpoints, disabled ones can just stay disabled. */
5986 disable_breakpoints_in_shlibs (void)
5988 struct bp_location
*loc
, **locp_tmp
;
5990 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5992 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5993 struct breakpoint
*b
= loc
->owner
;
5995 /* We apply the check to all breakpoints, including disabled for
5996 those with loc->duplicate set. This is so that when breakpoint
5997 becomes enabled, or the duplicate is removed, gdb will try to
5998 insert all breakpoints. If we don't set shlib_disabled here,
5999 we'll try to insert those breakpoints and fail. */
6000 if (((b
->type
== bp_breakpoint
)
6001 || (b
->type
== bp_jit_event
)
6002 || (b
->type
== bp_hardware_breakpoint
)
6003 || (is_tracepoint (b
)))
6004 && loc
->pspace
== current_program_space
6005 && !loc
->shlib_disabled
6007 && PC_SOLIB (loc
->address
)
6009 && solib_name_from_address (loc
->pspace
, loc
->address
)
6013 loc
->shlib_disabled
= 1;
6018 /* Disable any breakpoints that are in in an unloaded shared library.
6019 Only apply to enabled breakpoints, disabled ones can just stay
6023 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6025 struct bp_location
*loc
, **locp_tmp
;
6026 int disabled_shlib_breaks
= 0;
6028 /* SunOS a.out shared libraries are always mapped, so do not
6029 disable breakpoints; they will only be reported as unloaded
6030 through clear_solib when GDB discards its shared library
6031 list. See clear_solib for more information. */
6032 if (exec_bfd
!= NULL
6033 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6036 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6038 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6039 struct breakpoint
*b
= loc
->owner
;
6041 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6042 || loc
->loc_type
== bp_loc_software_breakpoint
)
6043 && solib
->pspace
== loc
->pspace
6044 && !loc
->shlib_disabled
6045 && (b
->type
== bp_breakpoint
6046 || b
->type
== bp_jit_event
6047 || b
->type
== bp_hardware_breakpoint
)
6048 && solib_contains_address_p (solib
, loc
->address
))
6050 loc
->shlib_disabled
= 1;
6051 /* At this point, we cannot rely on remove_breakpoint
6052 succeeding so we must mark the breakpoint as not inserted
6053 to prevent future errors occurring in remove_breakpoints. */
6055 if (!disabled_shlib_breaks
)
6057 target_terminal_ours_for_output ();
6058 warning (_("Temporarily disabling breakpoints "
6059 "for unloaded shared library \"%s\""),
6062 disabled_shlib_breaks
= 1;
6067 /* FORK & VFORK catchpoints. */
6069 /* Implement the "insert" breakpoint_ops method for fork
6073 insert_catch_fork (struct bp_location
*bl
)
6075 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6078 /* Implement the "remove" breakpoint_ops method for fork
6082 remove_catch_fork (struct bp_location
*bl
)
6084 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6087 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6091 breakpoint_hit_catch_fork (struct breakpoint
*b
)
6093 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
6096 /* Implement the "print_it" breakpoint_ops method for fork
6099 static enum print_stop_action
6100 print_it_catch_fork (struct breakpoint
*b
)
6102 annotate_catchpoint (b
->number
);
6103 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6104 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6105 return PRINT_SRC_AND_LOC
;
6108 /* Implement the "print_one" breakpoint_ops method for fork
6112 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6114 struct value_print_options opts
;
6116 get_user_print_options (&opts
);
6118 /* Field 4, the address, is omitted (which makes the columns not
6119 line up too nicely with the headers, but the effect is relatively
6121 if (opts
.addressprint
)
6122 ui_out_field_skip (uiout
, "addr");
6124 ui_out_text (uiout
, "fork");
6125 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6127 ui_out_text (uiout
, ", process ");
6128 ui_out_field_int (uiout
, "what",
6129 ptid_get_pid (b
->forked_inferior_pid
));
6130 ui_out_spaces (uiout
, 1);
6134 /* Implement the "print_mention" breakpoint_ops method for fork
6138 print_mention_catch_fork (struct breakpoint
*b
)
6140 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6143 /* Implement the "print_recreate" breakpoint_ops method for fork
6147 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6149 fprintf_unfiltered (fp
, "catch fork");
6152 /* The breakpoint_ops structure to be used in fork catchpoints. */
6154 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6158 breakpoint_hit_catch_fork
,
6159 NULL
, /* resources_needed */
6160 print_it_catch_fork
,
6161 print_one_catch_fork
,
6162 print_mention_catch_fork
,
6163 print_recreate_catch_fork
6166 /* Implement the "insert" breakpoint_ops method for vfork
6170 insert_catch_vfork (struct bp_location
*bl
)
6172 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6175 /* Implement the "remove" breakpoint_ops method for vfork
6179 remove_catch_vfork (struct bp_location
*bl
)
6181 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6184 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6188 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6190 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6193 /* Implement the "print_it" breakpoint_ops method for vfork
6196 static enum print_stop_action
6197 print_it_catch_vfork (struct breakpoint
*b
)
6199 annotate_catchpoint (b
->number
);
6200 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6201 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6202 return PRINT_SRC_AND_LOC
;
6205 /* Implement the "print_one" breakpoint_ops method for vfork
6209 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6211 struct value_print_options opts
;
6213 get_user_print_options (&opts
);
6214 /* Field 4, the address, is omitted (which makes the columns not
6215 line up too nicely with the headers, but the effect is relatively
6217 if (opts
.addressprint
)
6218 ui_out_field_skip (uiout
, "addr");
6220 ui_out_text (uiout
, "vfork");
6221 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6223 ui_out_text (uiout
, ", process ");
6224 ui_out_field_int (uiout
, "what",
6225 ptid_get_pid (b
->forked_inferior_pid
));
6226 ui_out_spaces (uiout
, 1);
6230 /* Implement the "print_mention" breakpoint_ops method for vfork
6234 print_mention_catch_vfork (struct breakpoint
*b
)
6236 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6239 /* Implement the "print_recreate" breakpoint_ops method for vfork
6243 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6245 fprintf_unfiltered (fp
, "catch vfork");
6248 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6250 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6254 breakpoint_hit_catch_vfork
,
6255 NULL
, /* resources_needed */
6256 print_it_catch_vfork
,
6257 print_one_catch_vfork
,
6258 print_mention_catch_vfork
,
6259 print_recreate_catch_vfork
6262 /* Implement the "insert" breakpoint_ops method for syscall
6266 insert_catch_syscall (struct bp_location
*bl
)
6268 struct inferior
*inf
= current_inferior ();
6270 ++inf
->total_syscalls_count
;
6271 if (!bl
->owner
->syscalls_to_be_caught
)
6272 ++inf
->any_syscall_count
;
6278 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6283 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6285 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6286 uintptr_t vec_addr_offset
6287 = old_size
* ((uintptr_t) sizeof (int));
6289 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6290 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6292 memset ((void *) vec_addr
, 0,
6293 (iter
+ 1 - old_size
) * sizeof (int));
6295 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6296 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6300 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6301 inf
->total_syscalls_count
!= 0,
6302 inf
->any_syscall_count
,
6303 VEC_length (int, inf
->syscalls_counts
),
6304 VEC_address (int, inf
->syscalls_counts
));
6307 /* Implement the "remove" breakpoint_ops method for syscall
6311 remove_catch_syscall (struct bp_location
*bl
)
6313 struct inferior
*inf
= current_inferior ();
6315 --inf
->total_syscalls_count
;
6316 if (!bl
->owner
->syscalls_to_be_caught
)
6317 --inf
->any_syscall_count
;
6323 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6327 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6328 /* Shouldn't happen. */
6330 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6331 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6335 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6336 inf
->total_syscalls_count
!= 0,
6337 inf
->any_syscall_count
,
6338 VEC_length (int, inf
->syscalls_counts
),
6340 inf
->syscalls_counts
));
6343 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6347 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6349 /* We must check if we are catching specific syscalls in this
6350 breakpoint. If we are, then we must guarantee that the called
6351 syscall is the same syscall we are catching. */
6352 int syscall_number
= 0;
6354 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6357 /* Now, checking if the syscall is the same. */
6358 if (b
->syscalls_to_be_caught
)
6363 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6365 if (syscall_number
== iter
)
6375 /* Implement the "print_it" breakpoint_ops method for syscall
6378 static enum print_stop_action
6379 print_it_catch_syscall (struct breakpoint
*b
)
6381 /* These are needed because we want to know in which state a
6382 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6383 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6384 must print "called syscall" or "returned from syscall". */
6386 struct target_waitstatus last
;
6388 struct cleanup
*old_chain
;
6391 get_last_target_status (&ptid
, &last
);
6393 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6395 annotate_catchpoint (b
->number
);
6398 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6400 syscall_id
= xstrprintf ("'%s'", s
.name
);
6402 old_chain
= make_cleanup (xfree
, syscall_id
);
6404 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6405 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6406 b
->number
, syscall_id
);
6407 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6408 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6409 b
->number
, syscall_id
);
6411 do_cleanups (old_chain
);
6413 return PRINT_SRC_AND_LOC
;
6416 /* Implement the "print_one" breakpoint_ops method for syscall
6420 print_one_catch_syscall (struct breakpoint
*b
,
6421 struct bp_location
**last_loc
)
6423 struct value_print_options opts
;
6425 get_user_print_options (&opts
);
6426 /* Field 4, the address, is omitted (which makes the columns not
6427 line up too nicely with the headers, but the effect is relatively
6429 if (opts
.addressprint
)
6430 ui_out_field_skip (uiout
, "addr");
6433 if (b
->syscalls_to_be_caught
6434 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6435 ui_out_text (uiout
, "syscalls \"");
6437 ui_out_text (uiout
, "syscall \"");
6439 if (b
->syscalls_to_be_caught
)
6442 char *text
= xstrprintf ("%s", "");
6445 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6450 get_syscall_by_number (iter
, &s
);
6453 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6455 text
= xstrprintf ("%s%d, ", text
, iter
);
6457 /* We have to xfree the last 'text' (now stored at 'x')
6458 because xstrprintf dinamically allocates new space for it
6462 /* Remove the last comma. */
6463 text
[strlen (text
) - 2] = '\0';
6464 ui_out_field_string (uiout
, "what", text
);
6467 ui_out_field_string (uiout
, "what", "<any syscall>");
6468 ui_out_text (uiout
, "\" ");
6471 /* Implement the "print_mention" breakpoint_ops method for syscall
6475 print_mention_catch_syscall (struct breakpoint
*b
)
6477 if (b
->syscalls_to_be_caught
)
6481 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6482 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6484 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6487 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6491 get_syscall_by_number (iter
, &s
);
6494 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6496 printf_filtered (" %d", s
.number
);
6498 printf_filtered (")");
6501 printf_filtered (_("Catchpoint %d (any syscall)"),
6505 /* Implement the "print_recreate" breakpoint_ops method for syscall
6509 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6511 fprintf_unfiltered (fp
, "catch syscall");
6513 if (b
->syscalls_to_be_caught
)
6518 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6523 get_syscall_by_number (iter
, &s
);
6525 fprintf_unfiltered (fp
, " %s", s
.name
);
6527 fprintf_unfiltered (fp
, " %d", s
.number
);
6532 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6534 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6536 insert_catch_syscall
,
6537 remove_catch_syscall
,
6538 breakpoint_hit_catch_syscall
,
6539 NULL
, /* resources_needed */
6540 print_it_catch_syscall
,
6541 print_one_catch_syscall
,
6542 print_mention_catch_syscall
,
6543 print_recreate_catch_syscall
6546 /* Returns non-zero if 'b' is a syscall catchpoint. */
6549 syscall_catchpoint_p (struct breakpoint
*b
)
6551 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6554 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6555 but does NOT mention it nor update the global location list.
6556 This is useful if you need to fill more fields in the
6557 struct breakpoint before calling mention.
6559 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6560 If COND_STRING is not NULL, then store it in the breakpoint.
6561 OPS, if not NULL, is the breakpoint_ops structure associated
6562 to the catchpoint. */
6564 static struct breakpoint
*
6565 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6567 struct breakpoint_ops
*ops
)
6569 struct symtab_and_line sal
;
6570 struct breakpoint
*b
;
6573 sal
.pspace
= current_program_space
;
6575 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6576 set_breakpoint_count (breakpoint_count
+ 1);
6577 b
->number
= breakpoint_count
;
6579 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6581 b
->addr_string
= NULL
;
6582 b
->enable_state
= bp_enabled
;
6583 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6589 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6591 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6592 If COND_STRING is not NULL, then store it in the breakpoint.
6593 OPS, if not NULL, is the breakpoint_ops structure associated
6594 to the catchpoint. */
6596 static struct breakpoint
*
6597 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6598 char *cond_string
, struct breakpoint_ops
*ops
)
6600 struct breakpoint
*b
=
6601 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6604 update_global_location_list (1);
6610 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6611 int tempflag
, char *cond_string
,
6612 struct breakpoint_ops
*ops
)
6614 struct breakpoint
*b
6615 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6617 /* FIXME: We should put this information in a breakpoint private data
6619 b
->forked_inferior_pid
= null_ptid
;
6622 /* Exec catchpoints. */
6625 insert_catch_exec (struct bp_location
*bl
)
6627 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6631 remove_catch_exec (struct bp_location
*bl
)
6633 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6637 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6639 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6642 static enum print_stop_action
6643 print_it_catch_exec (struct breakpoint
*b
)
6645 annotate_catchpoint (b
->number
);
6646 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6648 return PRINT_SRC_AND_LOC
;
6652 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6654 struct value_print_options opts
;
6656 get_user_print_options (&opts
);
6658 /* Field 4, the address, is omitted (which makes the columns
6659 not line up too nicely with the headers, but the effect
6660 is relatively readable). */
6661 if (opts
.addressprint
)
6662 ui_out_field_skip (uiout
, "addr");
6664 ui_out_text (uiout
, "exec");
6665 if (b
->exec_pathname
!= NULL
)
6667 ui_out_text (uiout
, ", program \"");
6668 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6669 ui_out_text (uiout
, "\" ");
6674 print_mention_catch_exec (struct breakpoint
*b
)
6676 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6679 /* Implement the "print_recreate" breakpoint_ops method for exec
6683 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6685 fprintf_unfiltered (fp
, "catch exec");
6688 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6692 breakpoint_hit_catch_exec
,
6693 NULL
, /* resources_needed */
6694 print_it_catch_exec
,
6695 print_one_catch_exec
,
6696 print_mention_catch_exec
,
6697 print_recreate_catch_exec
6701 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6702 struct breakpoint_ops
*ops
)
6704 struct gdbarch
*gdbarch
= get_current_arch ();
6705 struct breakpoint
*b
=
6706 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6708 b
->syscalls_to_be_caught
= filter
;
6710 /* Now, we have to mention the breakpoint and update the global
6713 update_global_location_list (1);
6717 hw_breakpoint_used_count (void)
6719 struct breakpoint
*b
;
6724 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6732 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6735 struct breakpoint
*b
;
6736 struct bp_location
*bl
;
6738 *other_type_used
= 0;
6741 if (!breakpoint_enabled (b
))
6744 if (b
->type
== type
)
6745 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6747 /* Special types of hardware watchpoints may use more than
6749 if (b
->ops
&& b
->ops
->resources_needed
)
6750 i
+= b
->ops
->resources_needed (bl
);
6754 else if (is_hardware_watchpoint (b
))
6755 *other_type_used
= 1;
6762 disable_watchpoints_before_interactive_call_start (void)
6764 struct breakpoint
*b
;
6768 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6770 b
->enable_state
= bp_call_disabled
;
6771 update_global_location_list (0);
6777 enable_watchpoints_after_interactive_call_stop (void)
6779 struct breakpoint
*b
;
6783 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6785 b
->enable_state
= bp_enabled
;
6786 update_global_location_list (1);
6792 disable_breakpoints_before_startup (void)
6794 struct breakpoint
*b
;
6799 if (b
->pspace
!= current_program_space
)
6802 if ((b
->type
== bp_breakpoint
6803 || b
->type
== bp_hardware_breakpoint
)
6804 && breakpoint_enabled (b
))
6806 b
->enable_state
= bp_startup_disabled
;
6812 update_global_location_list (0);
6814 current_program_space
->executing_startup
= 1;
6818 enable_breakpoints_after_startup (void)
6820 struct breakpoint
*b
;
6823 current_program_space
->executing_startup
= 0;
6827 if (b
->pspace
!= current_program_space
)
6830 if ((b
->type
== bp_breakpoint
6831 || b
->type
== bp_hardware_breakpoint
)
6832 && b
->enable_state
== bp_startup_disabled
)
6834 b
->enable_state
= bp_enabled
;
6840 breakpoint_re_set ();
6844 /* Set a breakpoint that will evaporate an end of command
6845 at address specified by SAL.
6846 Restrict it to frame FRAME if FRAME is nonzero. */
6849 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6850 struct frame_id frame_id
, enum bptype type
)
6852 struct breakpoint
*b
;
6854 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6856 gdb_assert (!frame_id_inlined_p (frame_id
));
6858 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6859 b
->enable_state
= bp_enabled
;
6860 b
->disposition
= disp_donttouch
;
6861 b
->frame_id
= frame_id
;
6863 /* If we're debugging a multi-threaded program, then we want
6864 momentary breakpoints to be active in only a single thread of
6866 if (in_thread_list (inferior_ptid
))
6867 b
->thread
= pid_to_thread_id (inferior_ptid
);
6869 update_global_location_list_nothrow (1);
6874 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6878 clone_momentary_breakpoint (struct breakpoint
*orig
)
6880 struct breakpoint
*copy
;
6882 /* If there's nothing to clone, then return nothing. */
6886 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6887 copy
->loc
= allocate_bp_location (copy
);
6888 set_breakpoint_location_function (copy
->loc
);
6890 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6891 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6892 copy
->loc
->address
= orig
->loc
->address
;
6893 copy
->loc
->section
= orig
->loc
->section
;
6894 copy
->loc
->pspace
= orig
->loc
->pspace
;
6896 if (orig
->source_file
== NULL
)
6897 copy
->source_file
= NULL
;
6899 copy
->source_file
= xstrdup (orig
->source_file
);
6901 copy
->line_number
= orig
->line_number
;
6902 copy
->frame_id
= orig
->frame_id
;
6903 copy
->thread
= orig
->thread
;
6904 copy
->pspace
= orig
->pspace
;
6906 copy
->enable_state
= bp_enabled
;
6907 copy
->disposition
= disp_donttouch
;
6908 copy
->number
= internal_breakpoint_number
--;
6910 update_global_location_list_nothrow (0);
6915 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6918 struct symtab_and_line sal
;
6920 sal
= find_pc_line (pc
, 0);
6922 sal
.section
= find_pc_overlay (pc
);
6923 sal
.explicit_pc
= 1;
6925 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6929 /* Tell the user we have just set a breakpoint B. */
6932 mention (struct breakpoint
*b
)
6935 struct cleanup
*ui_out_chain
;
6936 struct value_print_options opts
;
6938 get_user_print_options (&opts
);
6940 /* FIXME: This is misplaced; mention() is called by things (like
6941 hitting a watchpoint) other than breakpoint creation. It should
6942 be possible to clean this up and at the same time replace the
6943 random calls to breakpoint_changed with this hook. */
6944 observer_notify_breakpoint_created (b
->number
);
6946 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6947 b
->ops
->print_mention (b
);
6952 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
6956 ui_out_text (uiout
, "Watchpoint ");
6957 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6958 ui_out_field_int (uiout
, "number", b
->number
);
6959 ui_out_text (uiout
, ": ");
6960 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6961 do_cleanups (ui_out_chain
);
6963 case bp_hardware_watchpoint
:
6964 ui_out_text (uiout
, "Hardware watchpoint ");
6965 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6966 ui_out_field_int (uiout
, "number", b
->number
);
6967 ui_out_text (uiout
, ": ");
6968 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6969 do_cleanups (ui_out_chain
);
6971 case bp_read_watchpoint
:
6972 ui_out_text (uiout
, "Hardware read watchpoint ");
6973 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6974 ui_out_field_int (uiout
, "number", b
->number
);
6975 ui_out_text (uiout
, ": ");
6976 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6977 do_cleanups (ui_out_chain
);
6979 case bp_access_watchpoint
:
6980 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6981 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6982 ui_out_field_int (uiout
, "number", b
->number
);
6983 ui_out_text (uiout
, ": ");
6984 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6985 do_cleanups (ui_out_chain
);
6988 if (ui_out_is_mi_like_p (uiout
))
6993 if (b
->disposition
== disp_del
)
6994 printf_filtered (_("Temporary breakpoint"));
6996 printf_filtered (_("Breakpoint"));
6997 printf_filtered (_(" %d"), b
->number
);
7000 case bp_hardware_breakpoint
:
7001 if (ui_out_is_mi_like_p (uiout
))
7006 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
7010 if (ui_out_is_mi_like_p (uiout
))
7015 printf_filtered (_("Tracepoint"));
7016 printf_filtered (_(" %d"), b
->number
);
7019 case bp_fast_tracepoint
:
7020 if (ui_out_is_mi_like_p (uiout
))
7025 printf_filtered (_("Fast tracepoint"));
7026 printf_filtered (_(" %d"), b
->number
);
7029 case bp_static_tracepoint
:
7030 if (ui_out_is_mi_like_p (uiout
))
7035 printf_filtered (_("Static tracepoint"));
7036 printf_filtered (_(" %d"), b
->number
);
7043 case bp_longjmp_resume
:
7045 case bp_exception_resume
:
7046 case bp_step_resume
:
7048 case bp_std_terminate
:
7049 case bp_watchpoint_scope
:
7050 case bp_shlib_event
:
7051 case bp_thread_event
:
7052 case bp_overlay_event
:
7054 case bp_longjmp_master
:
7055 case bp_std_terminate_master
:
7056 case bp_exception_master
:
7062 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7066 printf_filtered (_(" (%s) pending."), b
->addr_string
);
7070 if (opts
.addressprint
|| b
->source_file
== NULL
)
7072 printf_filtered (" at ");
7073 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
7077 printf_filtered (": file %s, line %d.",
7078 b
->source_file
, b
->line_number
);
7082 struct bp_location
*loc
= b
->loc
;
7084 for (; loc
; loc
= loc
->next
)
7086 printf_filtered (" (%d locations)", n
);
7091 if (ui_out_is_mi_like_p (uiout
))
7093 printf_filtered ("\n");
7097 static struct bp_location
*
7098 add_location_to_breakpoint (struct breakpoint
*b
,
7099 const struct symtab_and_line
*sal
)
7101 struct bp_location
*loc
, **tmp
;
7103 loc
= allocate_bp_location (b
);
7104 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7107 loc
->gdbarch
= get_sal_arch (*sal
);
7109 loc
->gdbarch
= b
->gdbarch
;
7110 loc
->requested_address
= sal
->pc
;
7111 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7112 loc
->requested_address
, b
->type
);
7113 loc
->pspace
= sal
->pspace
;
7114 gdb_assert (loc
->pspace
!= NULL
);
7115 loc
->section
= sal
->section
;
7117 set_breakpoint_location_function (loc
);
7122 /* Return 1 if LOC is pointing to a permanent breakpoint,
7123 return 0 otherwise. */
7126 bp_loc_is_permanent (struct bp_location
*loc
)
7130 const gdb_byte
*brk
;
7131 gdb_byte
*target_mem
;
7132 struct cleanup
*cleanup
;
7135 gdb_assert (loc
!= NULL
);
7137 addr
= loc
->address
;
7138 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7140 /* Software breakpoints unsupported? */
7144 target_mem
= alloca (len
);
7146 /* Enable the automatic memory restoration from breakpoints while
7147 we read the memory. Otherwise we could say about our temporary
7148 breakpoints they are permanent. */
7149 cleanup
= save_current_space_and_thread ();
7151 switch_to_program_space_and_thread (loc
->pspace
);
7152 make_show_memory_breakpoints_cleanup (0);
7154 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7155 && memcmp (target_mem
, brk
, len
) == 0)
7158 do_cleanups (cleanup
);
7165 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7166 as textual description of the location, and COND_STRING
7167 as condition expression. */
7170 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7171 struct symtabs_and_lines sals
, char *addr_string
,
7173 enum bptype type
, enum bpdisp disposition
,
7174 int thread
, int task
, int ignore_count
,
7175 struct breakpoint_ops
*ops
, int from_tty
,
7176 int enabled
, int internal
)
7178 struct breakpoint
*b
= NULL
;
7181 if (type
== bp_hardware_breakpoint
)
7183 int i
= hw_breakpoint_used_count ();
7184 int target_resources_ok
=
7185 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7187 if (target_resources_ok
== 0)
7188 error (_("No hardware breakpoint support in the target."));
7189 else if (target_resources_ok
< 0)
7190 error (_("Hardware breakpoints used exceeds limit."));
7193 gdb_assert (sals
.nelts
> 0);
7195 for (i
= 0; i
< sals
.nelts
; ++i
)
7197 struct symtab_and_line sal
= sals
.sals
[i
];
7198 struct bp_location
*loc
;
7202 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7204 loc_gdbarch
= gdbarch
;
7206 describe_other_breakpoints (loc_gdbarch
,
7207 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7212 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7213 set_breakpoint_number (internal
, b
);
7217 b
->cond_string
= cond_string
;
7218 b
->ignore_count
= ignore_count
;
7219 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7220 b
->disposition
= disposition
;
7221 b
->pspace
= sals
.sals
[0].pspace
;
7223 if (type
== bp_static_tracepoint
)
7225 struct static_tracepoint_marker marker
;
7227 if (is_marker_spec (addr_string
))
7229 /* We already know the marker exists, otherwise, we
7230 wouldn't see a sal for it. */
7231 char *p
= &addr_string
[3];
7236 p
= skip_spaces (p
);
7238 endp
= skip_to_space (p
);
7240 marker_str
= savestring (p
, endp
- p
);
7241 b
->static_trace_marker_id
= marker_str
;
7243 printf_filtered (_("Probed static tracepoint "
7245 b
->static_trace_marker_id
);
7247 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7249 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7250 release_static_tracepoint_marker (&marker
);
7252 printf_filtered (_("Probed static tracepoint "
7254 b
->static_trace_marker_id
);
7257 warning (_("Couldn't determine the static "
7258 "tracepoint marker to probe"));
7261 if (enabled
&& b
->pspace
->executing_startup
7262 && (b
->type
== bp_breakpoint
7263 || b
->type
== bp_hardware_breakpoint
))
7264 b
->enable_state
= bp_startup_disabled
;
7270 loc
= add_location_to_breakpoint (b
, &sal
);
7273 if (bp_loc_is_permanent (loc
))
7274 make_breakpoint_permanent (b
);
7278 char *arg
= b
->cond_string
;
7279 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7281 error (_("Garbage %s follows condition"), arg
);
7286 b
->addr_string
= addr_string
;
7288 /* addr_string has to be used or breakpoint_re_set will delete
7291 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7295 /* Do not mention breakpoints with a negative number, but do
7296 notify observers. */
7297 observer_notify_breakpoint_created (b
->number
);
7302 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7303 elements to fill the void space. */
7305 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7307 int i
= index_to_remove
+1;
7308 int last_index
= sal
->nelts
-1;
7310 for (;i
<= last_index
; ++i
)
7311 sal
->sals
[i
-1] = sal
->sals
[i
];
7316 /* If appropriate, obtains all sals that correspond to the same file
7317 and line as SAL, in all program spaces. Users debugging with IDEs,
7318 will want to set a breakpoint at foo.c:line, and not really care
7319 about program spaces. This is done only if SAL does not have
7320 explicit PC and has line and file information. If we got just a
7321 single expanded sal, return the original.
7323 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7324 which the name of enclosing function is different from SAL. This
7325 makes sure that if we have breakpoint originally set in template
7326 instantiation, say foo<int>(), we won't expand SAL to locations at
7327 the same line in all existing instantiations of 'foo'. */
7329 static struct symtabs_and_lines
7330 expand_line_sal_maybe (struct symtab_and_line sal
)
7332 struct symtabs_and_lines expanded
;
7333 CORE_ADDR original_pc
= sal
.pc
;
7334 char *original_function
= NULL
;
7337 struct cleanup
*old_chain
;
7339 /* If we have explicit pc, don't expand.
7340 If we have no line number, we can't expand. */
7341 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7344 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7345 expanded
.sals
[0] = sal
;
7351 old_chain
= save_current_space_and_thread ();
7353 switch_to_program_space_and_thread (sal
.pspace
);
7355 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7357 /* Note that expand_line_sal visits *all* program spaces. */
7358 expanded
= expand_line_sal (sal
);
7360 if (expanded
.nelts
== 1)
7362 /* We had one sal, we got one sal. Return that sal, adjusting it
7363 past the function prologue if necessary. */
7364 xfree (expanded
.sals
);
7366 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7367 sal
.pc
= original_pc
;
7368 expanded
.sals
[0] = sal
;
7369 skip_prologue_sal (&expanded
.sals
[0]);
7370 do_cleanups (old_chain
);
7374 if (!sal
.explicit_line
)
7376 CORE_ADDR func_addr
, func_end
;
7377 for (i
= 0; i
< expanded
.nelts
; ++i
)
7379 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7380 char *this_function
;
7382 /* We need to switch threads as well since we're about to
7384 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7386 if (find_pc_partial_function (pc
, &this_function
,
7387 &func_addr
, &func_end
))
7390 && strcmp (this_function
, original_function
) != 0)
7392 remove_sal (&expanded
, i
);
7399 /* Skip the function prologue if necessary. */
7400 for (i
= 0; i
< expanded
.nelts
; ++i
)
7401 skip_prologue_sal (&expanded
.sals
[i
]);
7403 do_cleanups (old_chain
);
7405 if (expanded
.nelts
<= 1)
7407 /* This is un ugly workaround. If we get zero expanded sals
7408 then something is really wrong. Fix that by returning the
7411 xfree (expanded
.sals
);
7413 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7414 sal
.pc
= original_pc
;
7415 expanded
.sals
[0] = sal
;
7422 for (i
= 0; i
< expanded
.nelts
; ++i
)
7423 if (expanded
.sals
[i
].pc
== original_pc
)
7434 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7435 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7436 value. COND_STRING, if not NULL, specified the condition to be
7437 used for all breakpoints. Essentially the only case where
7438 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7439 function. In that case, it's still not possible to specify
7440 separate conditions for different overloaded functions, so
7441 we take just a single condition string.
7443 NOTE: If the function succeeds, the caller is expected to cleanup
7444 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7445 array contents). If the function fails (error() is called), the
7446 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7447 COND and SALS arrays and each of those arrays contents. */
7450 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7451 struct symtabs_and_lines sals
, char **addr_string
,
7453 enum bptype type
, enum bpdisp disposition
,
7454 int thread
, int task
, int ignore_count
,
7455 struct breakpoint_ops
*ops
, int from_tty
,
7456 int enabled
, int internal
)
7460 for (i
= 0; i
< sals
.nelts
; ++i
)
7462 struct symtabs_and_lines expanded
=
7463 expand_line_sal_maybe (sals
.sals
[i
]);
7465 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7466 cond_string
, type
, disposition
,
7467 thread
, task
, ignore_count
, ops
,
7468 from_tty
, enabled
, internal
);
7472 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7473 followed by conditionals. On return, SALS contains an array of SAL
7474 addresses found. ADDR_STRING contains a vector of (canonical)
7475 address strings. ADDRESS points to the end of the SAL.
7477 The array and the line spec strings are allocated on the heap, it is
7478 the caller's responsibility to free them. */
7481 parse_breakpoint_sals (char **address
,
7482 struct symtabs_and_lines
*sals
,
7483 char ***addr_string
,
7486 char *addr_start
= *address
;
7488 *addr_string
= NULL
;
7489 /* If no arg given, or if first arg is 'if ', use the default
7491 if ((*address
) == NULL
7492 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7494 if (default_breakpoint_valid
)
7496 struct symtab_and_line sal
;
7498 init_sal (&sal
); /* Initialize to zeroes. */
7499 sals
->sals
= (struct symtab_and_line
*)
7500 xmalloc (sizeof (struct symtab_and_line
));
7501 sal
.pc
= default_breakpoint_address
;
7502 sal
.line
= default_breakpoint_line
;
7503 sal
.symtab
= default_breakpoint_symtab
;
7504 sal
.pspace
= default_breakpoint_pspace
;
7505 sal
.section
= find_pc_overlay (sal
.pc
);
7507 /* "break" without arguments is equivalent to "break *PC"
7508 where PC is the default_breakpoint_address. So make sure
7509 to set sal.explicit_pc to prevent GDB from trying to
7510 expand the list of sals to include all other instances
7511 with the same symtab and line. */
7512 sal
.explicit_pc
= 1;
7514 sals
->sals
[0] = sal
;
7518 error (_("No default breakpoint address now."));
7522 /* Force almost all breakpoints to be in terms of the
7523 current_source_symtab (which is decode_line_1's default).
7524 This should produce the results we want almost all of the
7525 time while leaving default_breakpoint_* alone.
7527 ObjC: However, don't match an Objective-C method name which
7528 may have a '+' or '-' succeeded by a '[' */
7530 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7532 if (default_breakpoint_valid
7534 || ((strchr ("+-", (*address
)[0]) != NULL
)
7535 && ((*address
)[1] != '['))))
7536 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7537 default_breakpoint_line
, addr_string
,
7540 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7541 addr_string
, not_found_ptr
);
7543 /* For any SAL that didn't have a canonical string, fill one in. */
7544 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7545 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7546 if (addr_start
!= (*address
))
7550 for (i
= 0; i
< sals
->nelts
; i
++)
7552 /* Add the string if not present. */
7553 if ((*addr_string
)[i
] == NULL
)
7554 (*addr_string
)[i
] = savestring (addr_start
,
7555 (*address
) - addr_start
);
7561 /* Convert each SAL into a real PC. Verify that the PC can be
7562 inserted as a breakpoint. If it can't throw an error. */
7565 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7569 for (i
= 0; i
< sals
->nelts
; i
++)
7570 resolve_sal_pc (&sals
->sals
[i
]);
7573 /* Fast tracepoints may have restrictions on valid locations. For
7574 instance, a fast tracepoint using a jump instead of a trap will
7575 likely have to overwrite more bytes than a trap would, and so can
7576 only be placed where the instruction is longer than the jump, or a
7577 multi-instruction sequence does not have a jump into the middle of
7581 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7582 struct symtabs_and_lines
*sals
)
7585 struct symtab_and_line
*sal
;
7587 struct cleanup
*old_chain
;
7589 for (i
= 0; i
< sals
->nelts
; i
++)
7591 sal
= &sals
->sals
[i
];
7593 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7595 old_chain
= make_cleanup (xfree
, msg
);
7598 error (_("May not have a fast tracepoint at 0x%s%s"),
7599 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7601 do_cleanups (old_chain
);
7606 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7608 struct captured_parse_breakpoint_args
*args
= data
;
7610 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7611 args
->not_found_ptr
);
7614 /* Given TOK, a string specification of condition and thread, as
7615 accepted by the 'break' command, extract the condition
7616 string and thread number and set *COND_STRING and *THREAD.
7617 PC identifies the context at which the condition should be parsed.
7618 If no condition is found, *COND_STRING is set to NULL.
7619 If no thread is found, *THREAD is set to -1. */
7621 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7622 char **cond_string
, int *thread
, int *task
)
7624 *cond_string
= NULL
;
7630 char *cond_start
= NULL
;
7631 char *cond_end
= NULL
;
7633 tok
= skip_spaces (tok
);
7635 end_tok
= skip_to_space (tok
);
7637 toklen
= end_tok
- tok
;
7639 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7641 struct expression
*expr
;
7643 tok
= cond_start
= end_tok
+ 1;
7644 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7647 *cond_string
= savestring (cond_start
,
7648 cond_end
- cond_start
);
7650 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7656 *thread
= strtol (tok
, &tok
, 0);
7658 error (_("Junk after thread keyword."));
7659 if (!valid_thread_id (*thread
))
7660 error (_("Unknown thread %d."), *thread
);
7662 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7668 *task
= strtol (tok
, &tok
, 0);
7670 error (_("Junk after task keyword."));
7671 if (!valid_task_id (*task
))
7672 error (_("Unknown task %d."), *task
);
7675 error (_("Junk at end of arguments."));
7679 /* Decode a static tracepoint marker spec. */
7681 static struct symtabs_and_lines
7682 decode_static_tracepoint_spec (char **arg_p
)
7684 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7685 struct symtabs_and_lines sals
;
7686 struct symtab_and_line sal
;
7688 struct cleanup
*old_chain
;
7689 char *p
= &(*arg_p
)[3];
7694 p
= skip_spaces (p
);
7696 endp
= skip_to_space (p
);
7698 marker_str
= savestring (p
, endp
- p
);
7699 old_chain
= make_cleanup (xfree
, marker_str
);
7701 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7702 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7703 error (_("No known static tracepoint marker named %s"), marker_str
);
7705 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7706 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7708 for (i
= 0; i
< sals
.nelts
; i
++)
7710 struct static_tracepoint_marker
*marker
;
7712 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7714 init_sal (&sals
.sals
[i
]);
7716 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7717 sals
.sals
[i
].pc
= marker
->address
;
7719 release_static_tracepoint_marker (marker
);
7722 do_cleanups (old_chain
);
7728 /* Set a breakpoint. This function is shared between CLI and MI
7729 functions for setting a breakpoint. This function has two major
7730 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7731 parameter. If non-zero, the function will parse arg, extracting
7732 breakpoint location, address and thread. Otherwise, ARG is just
7733 the location of breakpoint, with condition and thread specified by
7734 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7735 the breakpoint number will be allocated from the internal
7736 breakpoint count. Returns true if any breakpoint was created;
7740 create_breakpoint (struct gdbarch
*gdbarch
,
7741 char *arg
, char *cond_string
, int thread
,
7742 int parse_condition_and_thread
,
7743 int tempflag
, enum bptype type_wanted
,
7745 enum auto_boolean pending_break_support
,
7746 struct breakpoint_ops
*ops
,
7747 int from_tty
, int enabled
, int internal
)
7749 struct gdb_exception e
;
7750 struct symtabs_and_lines sals
;
7751 struct symtab_and_line pending_sal
;
7753 char *addr_start
= arg
;
7755 struct cleanup
*old_chain
;
7756 struct cleanup
*bkpt_chain
= NULL
;
7757 struct captured_parse_breakpoint_args parse_args
;
7762 int prev_bkpt_count
= breakpoint_count
;
7768 parse_args
.arg_p
= &arg
;
7769 parse_args
.sals_p
= &sals
;
7770 parse_args
.addr_string_p
= &addr_string
;
7771 parse_args
.not_found_ptr
= ¬_found
;
7773 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7777 sals
= decode_static_tracepoint_spec (&arg
);
7779 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7780 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7781 for (i
= 0; i
< sals
.nelts
; i
++)
7782 addr_string
[i
] = xstrdup (copy_arg
);
7786 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7787 &parse_args
, RETURN_MASK_ALL
);
7789 /* If caller is interested in rc value from parse, set value. */
7793 throw_exception (e
);
7797 case NOT_FOUND_ERROR
:
7799 /* If pending breakpoint support is turned off, throw
7802 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7803 throw_exception (e
);
7805 exception_print (gdb_stderr
, e
);
7807 /* If pending breakpoint support is auto query and the user
7808 selects no, then simply return the error code. */
7809 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7810 && !nquery (_("Make breakpoint pending on "
7811 "future shared library load? ")))
7814 /* At this point, either the user was queried about setting
7815 a pending breakpoint and selected yes, or pending
7816 breakpoint behavior is on and thus a pending breakpoint
7817 is defaulted on behalf of the user. */
7818 copy_arg
= xstrdup (addr_start
);
7819 addr_string
= ©_arg
;
7821 sals
.sals
= &pending_sal
;
7826 throw_exception (e
);
7835 /* Create a chain of things that always need to be cleaned up. */
7836 old_chain
= make_cleanup (null_cleanup
, 0);
7840 /* Make sure that all storage allocated to SALS gets freed. */
7841 make_cleanup (xfree
, sals
.sals
);
7843 /* Cleanup the addr_string array but not its contents. */
7844 make_cleanup (xfree
, addr_string
);
7847 /* ----------------------------- SNIP -----------------------------
7848 Anything added to the cleanup chain beyond this point is assumed
7849 to be part of a breakpoint. If the breakpoint create succeeds
7850 then the memory is not reclaimed. */
7851 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7853 /* Mark the contents of the addr_string for cleanup. These go on
7854 the bkpt_chain and only occur if the breakpoint create fails. */
7855 for (i
= 0; i
< sals
.nelts
; i
++)
7857 if (addr_string
[i
] != NULL
)
7858 make_cleanup (xfree
, addr_string
[i
]);
7861 /* Resolve all line numbers to PC's and verify that the addresses
7862 are ok for the target. */
7864 breakpoint_sals_to_pc (&sals
);
7866 /* Fast tracepoints may have additional restrictions on location. */
7867 if (type_wanted
== bp_fast_tracepoint
)
7868 check_fast_tracepoint_sals (gdbarch
, &sals
);
7870 /* Verify that condition can be parsed, before setting any
7871 breakpoints. Allocate a separate condition expression for each
7875 if (parse_condition_and_thread
)
7877 /* Here we only parse 'arg' to separate condition
7878 from thread number, so parsing in context of first
7879 sal is OK. When setting the breakpoint we'll
7880 re-parse it in context of each sal. */
7883 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7886 make_cleanup (xfree
, cond_string
);
7890 /* Create a private copy of condition string. */
7893 cond_string
= xstrdup (cond_string
);
7894 make_cleanup (xfree
, cond_string
);
7898 /* If the user is creating a static tracepoint by marker id
7899 (strace -m MARKER_ID), then store the sals index, so that
7900 breakpoint_re_set can try to match up which of the newly
7901 found markers corresponds to this one, and, don't try to
7902 expand multiple locations for each sal, given than SALS
7903 already should contain all sals for MARKER_ID. */
7904 if (type_wanted
== bp_static_tracepoint
7905 && is_marker_spec (addr_string
[0]))
7909 for (i
= 0; i
< sals
.nelts
; ++i
)
7911 struct symtabs_and_lines expanded
;
7912 struct breakpoint
*tp
;
7913 struct cleanup
*old_chain
;
7916 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7917 expanded
.sals
[0] = sals
.sals
[i
];
7918 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7920 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7921 cond_string
, type_wanted
,
7922 tempflag
? disp_del
: disp_donttouch
,
7923 thread
, task
, ignore_count
, ops
,
7924 from_tty
, enabled
, internal
);
7926 do_cleanups (old_chain
);
7928 /* Get the tracepoint we just created. */
7930 tp
= get_breakpoint (internal_breakpoint_number
);
7932 tp
= get_breakpoint (breakpoint_count
);
7933 gdb_assert (tp
!= NULL
);
7935 /* Given that its possible to have multiple markers with
7936 the same string id, if the user is creating a static
7937 tracepoint by marker id ("strace -m MARKER_ID"), then
7938 store the sals index, so that breakpoint_re_set can
7939 try to match up which of the newly found markers
7940 corresponds to this one */
7941 tp
->static_trace_marker_id_idx
= i
;
7945 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7947 tempflag
? disp_del
: disp_donttouch
,
7948 thread
, task
, ignore_count
, ops
, from_tty
,
7953 struct breakpoint
*b
;
7955 make_cleanup (xfree
, copy_arg
);
7957 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7958 set_breakpoint_number (internal
, b
);
7960 b
->addr_string
= addr_string
[0];
7961 b
->cond_string
= NULL
;
7962 b
->ignore_count
= ignore_count
;
7963 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7964 b
->condition_not_parsed
= 1;
7966 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7967 b
->pspace
= current_program_space
;
7968 b
->py_bp_object
= NULL
;
7970 if (enabled
&& b
->pspace
->executing_startup
7971 && (b
->type
== bp_breakpoint
7972 || b
->type
== bp_hardware_breakpoint
))
7973 b
->enable_state
= bp_startup_disabled
;
7976 /* Do not mention breakpoints with a negative number,
7977 but do notify observers. */
7978 observer_notify_breakpoint_created (b
->number
);
7985 warning (_("Multiple breakpoints were set.\nUse the "
7986 "\"delete\" command to delete unwanted breakpoints."));
7987 prev_breakpoint_count
= prev_bkpt_count
;
7990 /* That's it. Discard the cleanups for data inserted into the
7992 discard_cleanups (bkpt_chain
);
7993 /* But cleanup everything else. */
7994 do_cleanups (old_chain
);
7996 /* error call may happen here - have BKPT_CHAIN already discarded. */
7997 update_global_location_list (1);
8002 /* Set a breakpoint.
8003 ARG is a string describing breakpoint address,
8004 condition, and thread.
8005 FLAG specifies if a breakpoint is hardware on,
8006 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8010 break_command_1 (char *arg
, int flag
, int from_tty
)
8012 int tempflag
= flag
& BP_TEMPFLAG
;
8013 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8014 ? bp_hardware_breakpoint
8017 create_breakpoint (get_current_arch (),
8019 NULL
, 0, 1 /* parse arg */,
8020 tempflag
, type_wanted
,
8021 0 /* Ignore count */,
8022 pending_break_support
,
8023 NULL
/* breakpoint_ops */,
8030 /* Helper function for break_command_1 and disassemble_command. */
8033 resolve_sal_pc (struct symtab_and_line
*sal
)
8037 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8039 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8040 error (_("No line %d in file \"%s\"."),
8041 sal
->line
, sal
->symtab
->filename
);
8044 /* If this SAL corresponds to a breakpoint inserted using a line
8045 number, then skip the function prologue if necessary. */
8046 if (sal
->explicit_line
)
8047 skip_prologue_sal (sal
);
8050 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8052 struct blockvector
*bv
;
8056 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8059 sym
= block_linkage_function (b
);
8062 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8063 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8067 /* It really is worthwhile to have the section, so we'll
8068 just have to look harder. This case can be executed
8069 if we have line numbers but no functions (as can
8070 happen in assembly source). */
8072 struct minimal_symbol
*msym
;
8073 struct cleanup
*old_chain
= save_current_space_and_thread ();
8075 switch_to_program_space_and_thread (sal
->pspace
);
8077 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8079 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8081 do_cleanups (old_chain
);
8088 break_command (char *arg
, int from_tty
)
8090 break_command_1 (arg
, 0, from_tty
);
8094 tbreak_command (char *arg
, int from_tty
)
8096 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8100 hbreak_command (char *arg
, int from_tty
)
8102 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8106 thbreak_command (char *arg
, int from_tty
)
8108 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8112 stop_command (char *arg
, int from_tty
)
8114 printf_filtered (_("Specify the type of breakpoint to set.\n\
8115 Usage: stop in <function | address>\n\
8116 stop at <line>\n"));
8120 stopin_command (char *arg
, int from_tty
)
8124 if (arg
== (char *) NULL
)
8126 else if (*arg
!= '*')
8131 /* Look for a ':'. If this is a line number specification, then
8132 say it is bad, otherwise, it should be an address or
8133 function/method name. */
8134 while (*argptr
&& !hasColon
)
8136 hasColon
= (*argptr
== ':');
8141 badInput
= (*argptr
!= ':'); /* Not a class::method */
8143 badInput
= isdigit (*arg
); /* a simple line number */
8147 printf_filtered (_("Usage: stop in <function | address>\n"));
8149 break_command_1 (arg
, 0, from_tty
);
8153 stopat_command (char *arg
, int from_tty
)
8157 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8164 /* Look for a ':'. If there is a '::' then get out, otherwise
8165 it is probably a line number. */
8166 while (*argptr
&& !hasColon
)
8168 hasColon
= (*argptr
== ':');
8173 badInput
= (*argptr
== ':'); /* we have class::method */
8175 badInput
= !isdigit (*arg
); /* not a line number */
8179 printf_filtered (_("Usage: stop at <line>\n"));
8181 break_command_1 (arg
, 0, from_tty
);
8184 /* Return non-zero if EXP is verified as constant. Returned zero
8185 means EXP is variable. Also the constant detection may fail for
8186 some constant expressions and in such case still falsely return
8189 watchpoint_exp_is_const (const struct expression
*exp
)
8197 /* We are only interested in the descriptor of each element. */
8198 operator_length (exp
, i
, &oplenp
, &argsp
);
8201 switch (exp
->elts
[i
].opcode
)
8211 case BINOP_LOGICAL_AND
:
8212 case BINOP_LOGICAL_OR
:
8213 case BINOP_BITWISE_AND
:
8214 case BINOP_BITWISE_IOR
:
8215 case BINOP_BITWISE_XOR
:
8217 case BINOP_NOTEQUAL
:
8233 case TERNOP_SLICE_COUNT
:
8245 case OP_OBJC_NSSTRING
:
8248 case UNOP_LOGICAL_NOT
:
8249 case UNOP_COMPLEMENT
:
8252 /* Unary, binary and ternary operators: We have to check
8253 their operands. If they are constant, then so is the
8254 result of that operation. For instance, if A and B are
8255 determined to be constants, then so is "A + B".
8257 UNOP_IND is one exception to the rule above, because the
8258 value of *ADDR is not necessarily a constant, even when
8263 /* Check whether the associated symbol is a constant.
8265 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8266 possible that a buggy compiler could mark a variable as
8267 constant even when it is not, and TYPE_CONST would return
8268 true in this case, while SYMBOL_CLASS wouldn't.
8270 We also have to check for function symbols because they
8271 are always constant. */
8273 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8275 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8276 && SYMBOL_CLASS (s
) != LOC_CONST
8277 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8282 /* The default action is to return 0 because we are using
8283 the optimistic approach here: If we don't know something,
8284 then it is not a constant. */
8293 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8296 insert_watchpoint (struct bp_location
*bl
)
8298 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8300 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8301 bl
->owner
->cond_exp
);
8304 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8307 remove_watchpoint (struct bp_location
*bl
)
8309 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8311 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8312 bl
->owner
->cond_exp
);
8315 /* Implement the "resources_needed" breakpoint_ops method for
8316 hardware watchpoints. */
8319 resources_needed_watchpoint (const struct bp_location
*bl
)
8321 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8323 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8326 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8328 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8332 NULL
, /* breakpoint_hit */
8333 resources_needed_watchpoint
,
8334 NULL
, /* print_it */
8335 NULL
, /* print_one */
8336 NULL
, /* print_mention */
8337 NULL
/* print_recreate */
8340 /* accessflag: hw_write: watch write,
8341 hw_read: watch read,
8342 hw_access: watch access (read or write) */
8344 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8345 int just_location
, int internal
)
8347 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8348 struct expression
*exp
;
8349 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8350 struct value
*val
, *mark
, *result
;
8351 struct frame_info
*frame
;
8352 char *exp_start
= NULL
;
8353 char *exp_end
= NULL
;
8354 char *tok
, *id_tok_start
, *end_tok
;
8356 char *cond_start
= NULL
;
8357 char *cond_end
= NULL
;
8358 int i
, other_type_used
, target_resources_ok
= 0;
8359 enum bptype bp_type
;
8364 /* Make sure that we actually have parameters to parse. */
8365 if (arg
!= NULL
&& arg
[0] != '\0')
8367 toklen
= strlen (arg
); /* Size of argument list. */
8369 /* Points tok to the end of the argument list. */
8370 tok
= arg
+ toklen
- 1;
8372 /* Go backwards in the parameters list. Skip the last
8373 parameter. If we're expecting a 'thread <thread_num>'
8374 parameter, this should be the thread identifier. */
8375 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8377 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8380 /* Points end_tok to the beginning of the last token. */
8381 id_tok_start
= tok
+ 1;
8383 /* Go backwards in the parameters list. Skip one more
8384 parameter. If we're expecting a 'thread <thread_num>'
8385 parameter, we should reach a "thread" token. */
8386 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8391 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8394 /* Move the pointer forward to skip the whitespace and
8395 calculate the length of the token. */
8397 toklen
= end_tok
- tok
;
8399 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8401 /* At this point we've found a "thread" token, which means
8402 the user is trying to set a watchpoint that triggers
8403 only in a specific thread. */
8406 /* Extract the thread ID from the next token. */
8407 thread
= strtol (id_tok_start
, &endp
, 0);
8409 /* Check if the user provided a valid numeric value for the
8411 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8412 error (_("Invalid thread ID specification %s."), id_tok_start
);
8414 /* Check if the thread actually exists. */
8415 if (!valid_thread_id (thread
))
8416 error (_("Unknown thread %d."), thread
);
8418 /* Truncate the string and get rid of the thread <thread_num>
8419 parameter before the parameter list is parsed by the
8420 evaluate_expression() function. */
8425 /* Parse the rest of the arguments. */
8426 innermost_block
= NULL
;
8428 exp
= parse_exp_1 (&arg
, 0, 0);
8430 /* Remove trailing whitespace from the expression before saving it.
8431 This makes the eventual display of the expression string a bit
8433 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8436 /* Checking if the expression is not constant. */
8437 if (watchpoint_exp_is_const (exp
))
8441 len
= exp_end
- exp_start
;
8442 while (len
> 0 && isspace (exp_start
[len
- 1]))
8444 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8447 exp_valid_block
= innermost_block
;
8448 mark
= value_mark ();
8449 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8453 exp_valid_block
= NULL
;
8454 val
= value_addr (result
);
8455 release_value (val
);
8456 value_free_to_mark (mark
);
8458 else if (val
!= NULL
)
8459 release_value (val
);
8461 tok
= skip_spaces (arg
);
8462 end_tok
= skip_to_space (tok
);
8464 toklen
= end_tok
- tok
;
8465 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8467 struct expression
*cond
;
8469 innermost_block
= NULL
;
8470 tok
= cond_start
= end_tok
+ 1;
8471 cond
= parse_exp_1 (&tok
, 0, 0);
8473 /* The watchpoint expression may not be local, but the condition
8474 may still be. E.g.: `watch global if local > 0'. */
8475 cond_exp_valid_block
= innermost_block
;
8481 error (_("Junk at end of command."));
8483 if (accessflag
== hw_read
)
8484 bp_type
= bp_read_watchpoint
;
8485 else if (accessflag
== hw_access
)
8486 bp_type
= bp_access_watchpoint
;
8488 bp_type
= bp_hardware_watchpoint
;
8490 reg_cnt
= can_use_hardware_watchpoint (val
, target_exact_watchpoints
);
8491 if (reg_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8492 error (_("Expression cannot be implemented with read/access watchpoint."));
8495 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8496 target_resources_ok
=
8497 target_can_use_hardware_watchpoint (bp_type
, i
+ reg_cnt
,
8499 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8500 error (_("Target does not support this type of hardware watchpoint."));
8502 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8503 error (_("Target can only support one kind "
8504 "of HW watchpoint at a time."));
8507 /* Change the type of breakpoint to an ordinary watchpoint if a
8508 hardware watchpoint could not be set. */
8509 if (!reg_cnt
|| target_resources_ok
<= 0)
8510 bp_type
= bp_watchpoint
;
8512 frame
= block_innermost_frame (exp_valid_block
);
8514 /* If the expression is "local", then set up a "watchpoint scope"
8515 breakpoint at the point where we've left the scope of the watchpoint
8516 expression. Create the scope breakpoint before the watchpoint, so
8517 that we will encounter it first in bpstat_stop_status. */
8518 if (exp_valid_block
&& frame
)
8520 if (frame_id_p (frame_unwind_caller_id (frame
)))
8523 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8524 frame_unwind_caller_pc (frame
),
8525 bp_watchpoint_scope
);
8527 scope_breakpoint
->enable_state
= bp_enabled
;
8529 /* Automatically delete the breakpoint when it hits. */
8530 scope_breakpoint
->disposition
= disp_del
;
8532 /* Only break in the proper frame (help with recursion). */
8533 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8535 /* Set the address at which we will stop. */
8536 scope_breakpoint
->loc
->gdbarch
8537 = frame_unwind_caller_arch (frame
);
8538 scope_breakpoint
->loc
->requested_address
8539 = frame_unwind_caller_pc (frame
);
8540 scope_breakpoint
->loc
->address
8541 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8542 scope_breakpoint
->loc
->requested_address
,
8543 scope_breakpoint
->type
);
8547 /* Now set up the breakpoint. */
8548 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8549 set_breakpoint_number (internal
, b
);
8551 b
->disposition
= disp_donttouch
;
8553 b
->exp_valid_block
= exp_valid_block
;
8554 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8557 struct type
*t
= value_type (val
);
8558 CORE_ADDR addr
= value_as_address (val
);
8561 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8562 name
= type_to_string (t
);
8564 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8565 core_addr_to_string (addr
));
8568 b
->exp_string
= xstrprintf ("-location: %.*s",
8569 (int) (exp_end
- exp_start
), exp_start
);
8571 /* The above expression is in C. */
8572 b
->language
= language_c
;
8575 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8578 b
->ops
= &watchpoint_breakpoint_ops
;
8580 /* Use an exact watchpoint when there's only one memory region to be
8581 watched, and only one debug register is needed to watch it. */
8582 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
8585 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8591 b
->watchpoint_frame
= get_frame_id (frame
);
8592 b
->watchpoint_thread
= inferior_ptid
;
8596 b
->watchpoint_frame
= null_frame_id
;
8597 b
->watchpoint_thread
= null_ptid
;
8600 if (scope_breakpoint
!= NULL
)
8602 /* The scope breakpoint is related to the watchpoint. We will
8603 need to act on them together. */
8604 b
->related_breakpoint
= scope_breakpoint
;
8605 scope_breakpoint
->related_breakpoint
= b
;
8609 value_free_to_mark (mark
);
8611 /* Finally update the new watchpoint. This creates the locations
8612 that should be inserted. */
8613 update_watchpoint (b
, 1);
8615 /* Do not mention breakpoints with a negative number, but do
8616 notify observers. */
8617 observer_notify_breakpoint_created (b
->number
);
8620 update_global_location_list (1);
8623 /* Return count of debug registers needed to watch the given expression.
8624 If EXACT_WATCHPOINTS is 1, then consider that only the address of
8625 the start of the watched region will be monitored (i.e., all accesses
8626 will be aligned). This uses less debug registers on some targets.
8628 If the watchpoint cannot be handled in hardware return zero. */
8631 can_use_hardware_watchpoint (struct value
*v
, int exact_watchpoints
)
8633 int found_memory_cnt
= 0;
8634 struct value
*head
= v
;
8636 /* Did the user specifically forbid us to use hardware watchpoints? */
8637 if (!can_use_hw_watchpoints
)
8640 /* Make sure that the value of the expression depends only upon
8641 memory contents, and values computed from them within GDB. If we
8642 find any register references or function calls, we can't use a
8643 hardware watchpoint.
8645 The idea here is that evaluating an expression generates a series
8646 of values, one holding the value of every subexpression. (The
8647 expression a*b+c has five subexpressions: a, b, a*b, c, and
8648 a*b+c.) GDB's values hold almost enough information to establish
8649 the criteria given above --- they identify memory lvalues,
8650 register lvalues, computed values, etcetera. So we can evaluate
8651 the expression, and then scan the chain of values that leaves
8652 behind to decide whether we can detect any possible change to the
8653 expression's final value using only hardware watchpoints.
8655 However, I don't think that the values returned by inferior
8656 function calls are special in any way. So this function may not
8657 notice that an expression involving an inferior function call
8658 can't be watched with hardware watchpoints. FIXME. */
8659 for (; v
; v
= value_next (v
))
8661 if (VALUE_LVAL (v
) == lval_memory
)
8663 if (v
!= head
&& value_lazy (v
))
8664 /* A lazy memory lvalue in the chain is one that GDB never
8665 needed to fetch; we either just used its address (e.g.,
8666 `a' in `a.b') or we never needed it at all (e.g., `a'
8667 in `a,b'). This doesn't apply to HEAD; if that is
8668 lazy then it was not readable, but watch it anyway. */
8672 /* Ahh, memory we actually used! Check if we can cover
8673 it with hardware watchpoints. */
8674 struct type
*vtype
= check_typedef (value_type (v
));
8676 /* We only watch structs and arrays if user asked for it
8677 explicitly, never if they just happen to appear in a
8678 middle of some value chain. */
8680 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8681 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8683 CORE_ADDR vaddr
= value_address (v
);
8687 len
= (exact_watchpoints
8688 && is_scalar_type_recursive (vtype
))?
8689 1 : TYPE_LENGTH (value_type (v
));
8691 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
8695 found_memory_cnt
+= num_regs
;
8699 else if (VALUE_LVAL (v
) != not_lval
8700 && deprecated_value_modifiable (v
) == 0)
8701 return 0; /* These are values from the history (e.g., $1). */
8702 else if (VALUE_LVAL (v
) == lval_register
)
8703 return 0; /* Cannot watch a register with a HW watchpoint. */
8706 /* The expression itself looks suitable for using a hardware
8707 watchpoint, but give the target machine a chance to reject it. */
8708 return found_memory_cnt
;
8712 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8714 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8717 /* A helper function that looks for an argument at the start of a
8718 string. The argument must also either be at the end of the string,
8719 or be followed by whitespace. Returns 1 if it finds the argument,
8720 0 otherwise. If the argument is found, it updates *STR. */
8723 check_for_argument (char **str
, char *arg
, int arg_len
)
8725 if (strncmp (*str
, arg
, arg_len
) == 0
8726 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8734 /* A helper function that looks for the "-location" argument and then
8735 calls watch_command_1. */
8738 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8740 int just_location
= 0;
8743 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8744 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8746 arg
= skip_spaces (arg
);
8750 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8754 watch_command (char *arg
, int from_tty
)
8756 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8760 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8762 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8766 rwatch_command (char *arg
, int from_tty
)
8768 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8772 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8774 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8778 awatch_command (char *arg
, int from_tty
)
8780 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8784 /* Helper routines for the until_command routine in infcmd.c. Here
8785 because it uses the mechanisms of breakpoints. */
8787 struct until_break_command_continuation_args
8789 struct breakpoint
*breakpoint
;
8790 struct breakpoint
*breakpoint2
;
8794 /* This function is called by fetch_inferior_event via the
8795 cmd_continuation pointer, to complete the until command. It takes
8796 care of cleaning up the temporary breakpoints set up by the until
8799 until_break_command_continuation (void *arg
)
8801 struct until_break_command_continuation_args
*a
= arg
;
8803 delete_breakpoint (a
->breakpoint
);
8805 delete_breakpoint (a
->breakpoint2
);
8806 delete_longjmp_breakpoint (a
->thread_num
);
8810 until_break_command (char *arg
, int from_tty
, int anywhere
)
8812 struct symtabs_and_lines sals
;
8813 struct symtab_and_line sal
;
8814 struct frame_info
*frame
= get_selected_frame (NULL
);
8815 struct breakpoint
*breakpoint
;
8816 struct breakpoint
*breakpoint2
= NULL
;
8817 struct cleanup
*old_chain
;
8819 struct thread_info
*tp
;
8821 clear_proceed_status ();
8823 /* Set a breakpoint where the user wants it and at return from
8826 if (default_breakpoint_valid
)
8827 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8828 default_breakpoint_line
, (char ***) NULL
, NULL
);
8830 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8831 0, (char ***) NULL
, NULL
);
8833 if (sals
.nelts
!= 1)
8834 error (_("Couldn't get information on specified line."));
8837 xfree (sals
.sals
); /* malloc'd, so freed. */
8840 error (_("Junk at end of arguments."));
8842 resolve_sal_pc (&sal
);
8845 /* If the user told us to continue until a specified location,
8846 we don't specify a frame at which we need to stop. */
8847 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8848 null_frame_id
, bp_until
);
8850 /* Otherwise, specify the selected frame, because we want to stop
8851 only at the very same frame. */
8852 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8853 get_stack_frame_id (frame
),
8856 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8858 tp
= inferior_thread ();
8861 /* Keep within the current frame, or in frames called by the current
8864 if (frame_id_p (frame_unwind_caller_id (frame
)))
8866 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8867 sal
.pc
= frame_unwind_caller_pc (frame
);
8868 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8870 frame_unwind_caller_id (frame
),
8872 make_cleanup_delete_breakpoint (breakpoint2
);
8874 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
8875 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
8878 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8880 /* If we are running asynchronously, and proceed call above has
8881 actually managed to start the target, arrange for breakpoints to
8882 be deleted when the target stops. Otherwise, we're already
8883 stopped and delete breakpoints via cleanup chain. */
8885 if (target_can_async_p () && is_running (inferior_ptid
))
8887 struct until_break_command_continuation_args
*args
;
8888 args
= xmalloc (sizeof (*args
));
8890 args
->breakpoint
= breakpoint
;
8891 args
->breakpoint2
= breakpoint2
;
8892 args
->thread_num
= thread
;
8894 discard_cleanups (old_chain
);
8895 add_continuation (inferior_thread (),
8896 until_break_command_continuation
, args
,
8900 do_cleanups (old_chain
);
8903 /* This function attempts to parse an optional "if <cond>" clause
8904 from the arg string. If one is not found, it returns NULL.
8906 Else, it returns a pointer to the condition string. (It does not
8907 attempt to evaluate the string against a particular block.) And,
8908 it updates arg to point to the first character following the parsed
8909 if clause in the arg string. */
8912 ep_parse_optional_if_clause (char **arg
)
8916 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8919 /* Skip the "if" keyword. */
8922 /* Skip any extra leading whitespace, and record the start of the
8923 condition string. */
8924 *arg
= skip_spaces (*arg
);
8927 /* Assume that the condition occupies the remainder of the arg
8929 (*arg
) += strlen (cond_string
);
8934 /* Commands to deal with catching events, such as signals, exceptions,
8935 process start/exit, etc. */
8939 catch_fork_temporary
, catch_vfork_temporary
,
8940 catch_fork_permanent
, catch_vfork_permanent
8945 catch_fork_command_1 (char *arg
, int from_tty
,
8946 struct cmd_list_element
*command
)
8948 struct gdbarch
*gdbarch
= get_current_arch ();
8949 char *cond_string
= NULL
;
8950 catch_fork_kind fork_kind
;
8953 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8954 tempflag
= (fork_kind
== catch_fork_temporary
8955 || fork_kind
== catch_vfork_temporary
);
8959 arg
= skip_spaces (arg
);
8961 /* The allowed syntax is:
8963 catch [v]fork if <cond>
8965 First, check if there's an if clause. */
8966 cond_string
= ep_parse_optional_if_clause (&arg
);
8968 if ((*arg
!= '\0') && !isspace (*arg
))
8969 error (_("Junk at end of arguments."));
8971 /* If this target supports it, create a fork or vfork catchpoint
8972 and enable reporting of such events. */
8975 case catch_fork_temporary
:
8976 case catch_fork_permanent
:
8977 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8978 &catch_fork_breakpoint_ops
);
8980 case catch_vfork_temporary
:
8981 case catch_vfork_permanent
:
8982 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8983 &catch_vfork_breakpoint_ops
);
8986 error (_("unsupported or unknown fork kind; cannot catch it"));
8992 catch_exec_command_1 (char *arg
, int from_tty
,
8993 struct cmd_list_element
*command
)
8995 struct gdbarch
*gdbarch
= get_current_arch ();
8997 char *cond_string
= NULL
;
8999 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9003 arg
= skip_spaces (arg
);
9005 /* The allowed syntax is:
9007 catch exec if <cond>
9009 First, check if there's an if clause. */
9010 cond_string
= ep_parse_optional_if_clause (&arg
);
9012 if ((*arg
!= '\0') && !isspace (*arg
))
9013 error (_("Junk at end of arguments."));
9015 /* If this target supports it, create an exec catchpoint
9016 and enable reporting of such events. */
9017 create_catchpoint (gdbarch
, tempflag
, cond_string
,
9018 &catch_exec_breakpoint_ops
);
9021 static enum print_stop_action
9022 print_exception_catchpoint (struct breakpoint
*b
)
9024 int bp_temp
, bp_throw
;
9026 annotate_catchpoint (b
->number
);
9028 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9029 if (b
->loc
->address
!= b
->loc
->requested_address
)
9030 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9033 bp_temp
= b
->disposition
== disp_del
;
9035 bp_temp
? "Temporary catchpoint "
9037 if (!ui_out_is_mi_like_p (uiout
))
9038 ui_out_field_int (uiout
, "bkptno", b
->number
);
9040 bp_throw
? " (exception thrown), "
9041 : " (exception caught), ");
9042 if (ui_out_is_mi_like_p (uiout
))
9044 ui_out_field_string (uiout
, "reason",
9045 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9046 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9047 ui_out_field_int (uiout
, "bkptno", b
->number
);
9049 return PRINT_SRC_AND_LOC
;
9053 print_one_exception_catchpoint (struct breakpoint
*b
,
9054 struct bp_location
**last_loc
)
9056 struct value_print_options opts
;
9058 get_user_print_options (&opts
);
9059 if (opts
.addressprint
)
9062 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9063 ui_out_field_string (uiout
, "addr", "<PENDING>");
9065 ui_out_field_core_addr (uiout
, "addr",
9066 b
->loc
->gdbarch
, b
->loc
->address
);
9071 if (strstr (b
->addr_string
, "throw") != NULL
)
9072 ui_out_field_string (uiout
, "what", "exception throw");
9074 ui_out_field_string (uiout
, "what", "exception catch");
9078 print_mention_exception_catchpoint (struct breakpoint
*b
)
9083 bp_temp
= b
->disposition
== disp_del
;
9084 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9085 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9086 : _("Catchpoint "));
9087 ui_out_field_int (uiout
, "bkptno", b
->number
);
9088 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9092 /* Implement the "print_recreate" breakpoint_ops method for throw and
9093 catch catchpoints. */
9096 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9102 bp_temp
= b
->disposition
== disp_del
;
9103 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9104 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9105 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9108 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9111 NULL
, /* breakpoint_hit */
9112 NULL
, /* resources_needed */
9113 print_exception_catchpoint
,
9114 print_one_exception_catchpoint
,
9115 print_mention_exception_catchpoint
,
9116 print_recreate_exception_catchpoint
9120 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9121 enum exception_event_kind ex_event
, int from_tty
)
9123 char *trigger_func_name
;
9125 if (ex_event
== EX_EVENT_CATCH
)
9126 trigger_func_name
= "__cxa_begin_catch";
9128 trigger_func_name
= "__cxa_throw";
9130 create_breakpoint (get_current_arch (),
9131 trigger_func_name
, cond_string
, -1,
9132 0 /* condition and thread are valid. */,
9133 tempflag
, bp_breakpoint
,
9135 AUTO_BOOLEAN_TRUE
/* pending */,
9136 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9143 /* Deal with "catch catch" and "catch throw" commands. */
9146 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9147 int tempflag
, int from_tty
)
9149 char *cond_string
= NULL
;
9153 arg
= skip_spaces (arg
);
9155 cond_string
= ep_parse_optional_if_clause (&arg
);
9157 if ((*arg
!= '\0') && !isspace (*arg
))
9158 error (_("Junk at end of arguments."));
9160 if (ex_event
!= EX_EVENT_THROW
9161 && ex_event
!= EX_EVENT_CATCH
)
9162 error (_("Unsupported or unknown exception event; cannot catch it"));
9164 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9167 warning (_("Unsupported with this platform/compiler combination."));
9170 /* Implementation of "catch catch" command. */
9173 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9175 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9177 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9180 /* Implementation of "catch throw" command. */
9183 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9185 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9187 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9190 /* Create a breakpoint struct for Ada exception catchpoints. */
9193 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9194 struct symtab_and_line sal
,
9198 struct expression
*cond
,
9199 struct breakpoint_ops
*ops
,
9203 struct breakpoint
*b
;
9207 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9209 loc_gdbarch
= gdbarch
;
9211 describe_other_breakpoints (loc_gdbarch
,
9212 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9213 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9214 version for exception catchpoints, because two catchpoints
9215 used for different exception names will use the same address.
9216 In this case, a "breakpoint ... also set at..." warning is
9217 unproductive. Besides, the warning phrasing is also a bit
9218 inapropriate, we should use the word catchpoint, and tell
9219 the user what type of catchpoint it is. The above is good
9220 enough for now, though. */
9223 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9224 set_breakpoint_count (breakpoint_count
+ 1);
9226 b
->enable_state
= bp_enabled
;
9227 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9228 b
->number
= breakpoint_count
;
9229 b
->ignore_count
= 0;
9230 b
->loc
->cond
= cond
;
9231 b
->addr_string
= addr_string
;
9232 b
->language
= language_ada
;
9233 b
->cond_string
= cond_string
;
9234 b
->exp_string
= exp_string
;
9239 update_global_location_list (1);
9242 /* Implement the "catch exception" command. */
9245 catch_ada_exception_command (char *arg
, int from_tty
,
9246 struct cmd_list_element
*command
)
9248 struct gdbarch
*gdbarch
= get_current_arch ();
9250 struct symtab_and_line sal
;
9251 char *addr_string
= NULL
;
9252 char *exp_string
= NULL
;
9253 char *cond_string
= NULL
;
9254 struct expression
*cond
= NULL
;
9255 struct breakpoint_ops
*ops
= NULL
;
9257 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9261 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9262 &cond_string
, &cond
, &ops
);
9263 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9264 cond_string
, cond
, ops
, tempflag
,
9268 /* Cleanup function for a syscall filter list. */
9270 clean_up_filters (void *arg
)
9272 VEC(int) *iter
= *(VEC(int) **) arg
;
9273 VEC_free (int, iter
);
9276 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9277 filter list, or NULL if no filtering is required. */
9279 catch_syscall_split_args (char *arg
)
9281 VEC(int) *result
= NULL
;
9282 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9284 while (*arg
!= '\0')
9286 int i
, syscall_number
;
9291 /* Skip whitespace. */
9292 while (isspace (*arg
))
9295 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9296 cur_name
[i
] = arg
[i
];
9300 /* Check if the user provided a syscall name or a number. */
9301 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9302 if (*endptr
== '\0')
9303 get_syscall_by_number (syscall_number
, &s
);
9306 /* We have a name. Let's check if it's valid and convert it
9308 get_syscall_by_name (cur_name
, &s
);
9310 if (s
.number
== UNKNOWN_SYSCALL
)
9311 /* Here we have to issue an error instead of a warning,
9312 because GDB cannot do anything useful if there's no
9313 syscall number to be caught. */
9314 error (_("Unknown syscall name '%s'."), cur_name
);
9317 /* Ok, it's valid. */
9318 VEC_safe_push (int, result
, s
.number
);
9321 discard_cleanups (cleanup
);
9325 /* Implement the "catch syscall" command. */
9328 catch_syscall_command_1 (char *arg
, int from_tty
,
9329 struct cmd_list_element
*command
)
9334 struct gdbarch
*gdbarch
= get_current_arch ();
9336 /* Checking if the feature if supported. */
9337 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9338 error (_("The feature 'catch syscall' is not supported on \
9339 this architecture yet."));
9341 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9343 arg
= skip_spaces (arg
);
9345 /* We need to do this first "dummy" translation in order
9346 to get the syscall XML file loaded or, most important,
9347 to display a warning to the user if there's no XML file
9348 for his/her architecture. */
9349 get_syscall_by_number (0, &s
);
9351 /* The allowed syntax is:
9353 catch syscall <name | number> [<name | number> ... <name | number>]
9355 Let's check if there's a syscall name. */
9358 filter
= catch_syscall_split_args (arg
);
9362 create_syscall_event_catchpoint (tempflag
, filter
,
9363 &catch_syscall_breakpoint_ops
);
9366 /* Implement the "catch assert" command. */
9369 catch_assert_command (char *arg
, int from_tty
,
9370 struct cmd_list_element
*command
)
9372 struct gdbarch
*gdbarch
= get_current_arch ();
9374 struct symtab_and_line sal
;
9375 char *addr_string
= NULL
;
9376 struct breakpoint_ops
*ops
= NULL
;
9378 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9382 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9383 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9384 ops
, tempflag
, from_tty
);
9388 catch_command (char *arg
, int from_tty
)
9390 error (_("Catch requires an event name."));
9395 tcatch_command (char *arg
, int from_tty
)
9397 error (_("Catch requires an event name."));
9400 /* Delete breakpoints by address or line. */
9403 clear_command (char *arg
, int from_tty
)
9405 struct breakpoint
*b
;
9406 VEC(breakpoint_p
) *found
= 0;
9409 struct symtabs_and_lines sals
;
9410 struct symtab_and_line sal
;
9415 sals
= decode_line_spec (arg
, 1);
9420 sals
.sals
= (struct symtab_and_line
*)
9421 xmalloc (sizeof (struct symtab_and_line
));
9422 make_cleanup (xfree
, sals
.sals
);
9423 init_sal (&sal
); /* Initialize to zeroes. */
9424 sal
.line
= default_breakpoint_line
;
9425 sal
.symtab
= default_breakpoint_symtab
;
9426 sal
.pc
= default_breakpoint_address
;
9427 sal
.pspace
= default_breakpoint_pspace
;
9428 if (sal
.symtab
== 0)
9429 error (_("No source file specified."));
9437 /* We don't call resolve_sal_pc here. That's not as bad as it
9438 seems, because all existing breakpoints typically have both
9439 file/line and pc set. So, if clear is given file/line, we can
9440 match this to existing breakpoint without obtaining pc at all.
9442 We only support clearing given the address explicitly
9443 present in breakpoint table. Say, we've set breakpoint
9444 at file:line. There were several PC values for that file:line,
9445 due to optimization, all in one block.
9447 We've picked one PC value. If "clear" is issued with another
9448 PC corresponding to the same file:line, the breakpoint won't
9449 be cleared. We probably can still clear the breakpoint, but
9450 since the other PC value is never presented to user, user
9451 can only find it by guessing, and it does not seem important
9454 /* For each line spec given, delete bps which correspond to it. Do
9455 it in two passes, solely to preserve the current behavior that
9456 from_tty is forced true if we delete more than one
9460 for (i
= 0; i
< sals
.nelts
; i
++)
9462 /* If exact pc given, clear bpts at that pc.
9463 If line given (pc == 0), clear all bpts on specified line.
9464 If defaulting, clear all bpts on default line
9467 defaulting sal.pc != 0 tests to do
9472 1 0 <can't happen> */
9476 /* Find all matching breakpoints and add them to 'found'. */
9480 /* Are we going to delete b? */
9481 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9483 struct bp_location
*loc
= b
->loc
;
9484 for (; loc
; loc
= loc
->next
)
9486 int pc_match
= sal
.pc
9487 && (loc
->pspace
== sal
.pspace
)
9488 && (loc
->address
== sal
.pc
)
9489 && (!section_is_overlay (loc
->section
)
9490 || loc
->section
== sal
.section
);
9491 int line_match
= ((default_match
|| (0 == sal
.pc
))
9492 && b
->source_file
!= NULL
9493 && sal
.symtab
!= NULL
9494 && sal
.pspace
== loc
->pspace
9495 && strcmp (b
->source_file
,
9496 sal
.symtab
->filename
) == 0
9497 && b
->line_number
== sal
.line
);
9498 if (pc_match
|| line_match
)
9507 VEC_safe_push(breakpoint_p
, found
, b
);
9510 /* Now go thru the 'found' chain and delete them. */
9511 if (VEC_empty(breakpoint_p
, found
))
9514 error (_("No breakpoint at %s."), arg
);
9516 error (_("No breakpoint at this line."));
9519 if (VEC_length(breakpoint_p
, found
) > 1)
9520 from_tty
= 1; /* Always report if deleted more than one. */
9523 if (VEC_length(breakpoint_p
, found
) == 1)
9524 printf_unfiltered (_("Deleted breakpoint "));
9526 printf_unfiltered (_("Deleted breakpoints "));
9528 breakpoints_changed ();
9530 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9533 printf_unfiltered ("%d ", b
->number
);
9534 delete_breakpoint (b
);
9537 putchar_unfiltered ('\n');
9540 /* Delete breakpoint in BS if they are `delete' breakpoints and
9541 all breakpoints that are marked for deletion, whether hit or not.
9542 This is called after any breakpoint is hit, or after errors. */
9545 breakpoint_auto_delete (bpstat bs
)
9547 struct breakpoint
*b
, *b_tmp
;
9549 for (; bs
; bs
= bs
->next
)
9550 if (bs
->breakpoint_at
9551 && bs
->breakpoint_at
->disposition
== disp_del
9553 delete_breakpoint (bs
->breakpoint_at
);
9555 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9557 if (b
->disposition
== disp_del_at_next_stop
)
9558 delete_breakpoint (b
);
9562 /* A comparison function for bp_location AP and BP being interfaced to
9563 qsort. Sort elements primarily by their ADDRESS (no matter what
9564 does breakpoint_address_is_meaningful say for its OWNER),
9565 secondarily by ordering first bp_permanent OWNERed elements and
9566 terciarily just ensuring the array is sorted stable way despite
9567 qsort being an instable algorithm. */
9570 bp_location_compare (const void *ap
, const void *bp
)
9572 struct bp_location
*a
= *(void **) ap
;
9573 struct bp_location
*b
= *(void **) bp
;
9574 /* A and B come from existing breakpoints having non-NULL OWNER. */
9575 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9576 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9578 if (a
->address
!= b
->address
)
9579 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9581 /* Sort permanent breakpoints first. */
9582 if (a_perm
!= b_perm
)
9583 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9585 /* Make the user-visible order stable across GDB runs. Locations of
9586 the same breakpoint can be sorted in arbitrary order. */
9588 if (a
->owner
->number
!= b
->owner
->number
)
9589 return (a
->owner
->number
> b
->owner
->number
)
9590 - (a
->owner
->number
< b
->owner
->number
);
9592 return (a
> b
) - (a
< b
);
9595 /* Set bp_location_placed_address_before_address_max and
9596 bp_location_shadow_len_after_address_max according to the current
9597 content of the bp_location array. */
9600 bp_location_target_extensions_update (void)
9602 struct bp_location
*bl
, **blp_tmp
;
9604 bp_location_placed_address_before_address_max
= 0;
9605 bp_location_shadow_len_after_address_max
= 0;
9607 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9609 CORE_ADDR start
, end
, addr
;
9611 if (!bp_location_has_shadow (bl
))
9614 start
= bl
->target_info
.placed_address
;
9615 end
= start
+ bl
->target_info
.shadow_len
;
9617 gdb_assert (bl
->address
>= start
);
9618 addr
= bl
->address
- start
;
9619 if (addr
> bp_location_placed_address_before_address_max
)
9620 bp_location_placed_address_before_address_max
= addr
;
9622 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9624 gdb_assert (bl
->address
< end
);
9625 addr
= end
- bl
->address
;
9626 if (addr
> bp_location_shadow_len_after_address_max
)
9627 bp_location_shadow_len_after_address_max
= addr
;
9631 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9632 into the inferior, only remove already-inserted locations that no
9633 longer should be inserted. Functions that delete a breakpoint or
9634 breakpoints should pass false, so that deleting a breakpoint
9635 doesn't have the side effect of inserting the locations of other
9636 breakpoints that are marked not-inserted, but should_be_inserted
9637 returns true on them.
9639 This behaviour is useful is situations close to tear-down -- e.g.,
9640 after an exec, while the target still has execution, but breakpoint
9641 shadows of the previous executable image should *NOT* be restored
9642 to the new image; or before detaching, where the target still has
9643 execution and wants to delete breakpoints from GDB's lists, and all
9644 breakpoints had already been removed from the inferior. */
9647 update_global_location_list (int should_insert
)
9649 struct breakpoint
*b
;
9650 struct bp_location
**locp
, *loc
;
9651 struct cleanup
*cleanups
;
9653 /* Used in the duplicates detection below. When iterating over all
9654 bp_locations, points to the first bp_location of a given address.
9655 Breakpoints and watchpoints of different types are never
9656 duplicates of each other. Keep one pointer for each type of
9657 breakpoint/watchpoint, so we only need to loop over all locations
9659 struct bp_location
*bp_loc_first
; /* breakpoint */
9660 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9661 struct bp_location
*awp_loc_first
; /* access watchpoint */
9662 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9664 /* Saved former bp_location array which we compare against the newly
9665 built bp_location from the current state of ALL_BREAKPOINTS. */
9666 struct bp_location
**old_location
, **old_locp
;
9667 unsigned old_location_count
;
9669 old_location
= bp_location
;
9670 old_location_count
= bp_location_count
;
9672 bp_location_count
= 0;
9673 cleanups
= make_cleanup (xfree
, old_location
);
9676 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9677 bp_location_count
++;
9679 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9682 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9684 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9685 bp_location_compare
);
9687 bp_location_target_extensions_update ();
9689 /* Identify bp_location instances that are no longer present in the
9690 new list, and therefore should be freed. Note that it's not
9691 necessary that those locations should be removed from inferior --
9692 if there's another location at the same address (previously
9693 marked as duplicate), we don't need to remove/insert the
9696 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9697 and former bp_location array state respectively. */
9700 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9703 struct bp_location
*old_loc
= *old_locp
;
9704 struct bp_location
**loc2p
;
9706 /* Tells if 'old_loc' is found amoung the new locations. If
9707 not, we have to free it. */
9708 int found_object
= 0;
9709 /* Tells if the location should remain inserted in the target. */
9710 int keep_in_target
= 0;
9713 /* Skip LOCP entries which will definitely never be needed.
9714 Stop either at or being the one matching OLD_LOC. */
9715 while (locp
< bp_location
+ bp_location_count
9716 && (*locp
)->address
< old_loc
->address
)
9720 (loc2p
< bp_location
+ bp_location_count
9721 && (*loc2p
)->address
== old_loc
->address
);
9724 if (*loc2p
== old_loc
)
9731 /* If this location is no longer present, and inserted, look if
9732 there's maybe a new location at the same address. If so,
9733 mark that one inserted, and don't remove this one. This is
9734 needed so that we don't have a time window where a breakpoint
9735 at certain location is not inserted. */
9737 if (old_loc
->inserted
)
9739 /* If the location is inserted now, we might have to remove
9742 if (found_object
&& should_be_inserted (old_loc
))
9744 /* The location is still present in the location list,
9745 and still should be inserted. Don't do anything. */
9750 /* The location is either no longer present, or got
9751 disabled. See if there's another location at the
9752 same address, in which case we don't need to remove
9753 this one from the target. */
9755 /* OLD_LOC comes from existing struct breakpoint. */
9756 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9759 (loc2p
< bp_location
+ bp_location_count
9760 && (*loc2p
)->address
== old_loc
->address
);
9763 struct bp_location
*loc2
= *loc2p
;
9765 if (breakpoint_locations_match (loc2
, old_loc
))
9767 /* For the sake of should_be_inserted.
9768 Duplicates check below will fix up this
9770 loc2
->duplicate
= 0;
9772 /* Read watchpoint locations are switched to
9773 access watchpoints, if the former are not
9774 supported, but the latter are. */
9775 if (is_hardware_watchpoint (old_loc
->owner
))
9777 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9778 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9781 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9784 loc2
->target_info
= old_loc
->target_info
;
9793 if (!keep_in_target
)
9795 if (remove_breakpoint (old_loc
, mark_uninserted
))
9797 /* This is just about all we can do. We could keep
9798 this location on the global list, and try to
9799 remove it next time, but there's no particular
9800 reason why we will succeed next time.
9802 Note that at this point, old_loc->owner is still
9803 valid, as delete_breakpoint frees the breakpoint
9804 only after calling us. */
9805 printf_filtered (_("warning: Error removing "
9807 old_loc
->owner
->number
);
9815 if (removed
&& non_stop
9816 && breakpoint_address_is_meaningful (old_loc
->owner
)
9817 && !is_hardware_watchpoint (old_loc
->owner
))
9819 /* This location was removed from the target. In
9820 non-stop mode, a race condition is possible where
9821 we've removed a breakpoint, but stop events for that
9822 breakpoint are already queued and will arrive later.
9823 We apply an heuristic to be able to distinguish such
9824 SIGTRAPs from other random SIGTRAPs: we keep this
9825 breakpoint location for a bit, and will retire it
9826 after we see some number of events. The theory here
9827 is that reporting of events should, "on the average",
9828 be fair, so after a while we'll see events from all
9829 threads that have anything of interest, and no longer
9830 need to keep this breakpoint location around. We
9831 don't hold locations forever so to reduce chances of
9832 mistaking a non-breakpoint SIGTRAP for a breakpoint
9835 The heuristic failing can be disastrous on
9836 decr_pc_after_break targets.
9838 On decr_pc_after_break targets, like e.g., x86-linux,
9839 if we fail to recognize a late breakpoint SIGTRAP,
9840 because events_till_retirement has reached 0 too
9841 soon, we'll fail to do the PC adjustment, and report
9842 a random SIGTRAP to the user. When the user resumes
9843 the inferior, it will most likely immediately crash
9844 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9845 corrupted, because of being resumed e.g., in the
9846 middle of a multi-byte instruction, or skipped a
9847 one-byte instruction. This was actually seen happen
9848 on native x86-linux, and should be less rare on
9849 targets that do not support new thread events, like
9850 remote, due to the heuristic depending on
9853 Mistaking a random SIGTRAP for a breakpoint trap
9854 causes similar symptoms (PC adjustment applied when
9855 it shouldn't), but then again, playing with SIGTRAPs
9856 behind the debugger's back is asking for trouble.
9858 Since hardware watchpoint traps are always
9859 distinguishable from other traps, so we don't need to
9860 apply keep hardware watchpoint moribund locations
9861 around. We simply always ignore hardware watchpoint
9862 traps we can no longer explain. */
9864 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9865 old_loc
->owner
= NULL
;
9867 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9871 old_loc
->owner
= NULL
;
9872 decref_bp_location (&old_loc
);
9877 /* Rescan breakpoints at the same address and section, marking the
9878 first one as "first" and any others as "duplicates". This is so
9879 that the bpt instruction is only inserted once. If we have a
9880 permanent breakpoint at the same place as BPT, make that one the
9881 official one, and the rest as duplicates. Permanent breakpoints
9882 are sorted first for the same address.
9884 Do the same for hardware watchpoints, but also considering the
9885 watchpoint's type (regular/access/read) and length. */
9887 bp_loc_first
= NULL
;
9888 wp_loc_first
= NULL
;
9889 awp_loc_first
= NULL
;
9890 rwp_loc_first
= NULL
;
9891 ALL_BP_LOCATIONS (loc
, locp
)
9893 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
9895 struct breakpoint
*b
= loc
->owner
;
9896 struct bp_location
**loc_first_p
;
9898 if (b
->enable_state
== bp_disabled
9899 || b
->enable_state
== bp_call_disabled
9900 || b
->enable_state
== bp_startup_disabled
9902 || loc
->shlib_disabled
9903 || !breakpoint_address_is_meaningful (b
)
9904 || is_tracepoint (b
))
9907 /* Permanent breakpoint should always be inserted. */
9908 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9909 internal_error (__FILE__
, __LINE__
,
9910 _("allegedly permanent breakpoint is not "
9911 "actually inserted"));
9913 if (b
->type
== bp_hardware_watchpoint
)
9914 loc_first_p
= &wp_loc_first
;
9915 else if (b
->type
== bp_read_watchpoint
)
9916 loc_first_p
= &rwp_loc_first
;
9917 else if (b
->type
== bp_access_watchpoint
)
9918 loc_first_p
= &awp_loc_first
;
9920 loc_first_p
= &bp_loc_first
;
9922 if (*loc_first_p
== NULL
9923 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9924 || !breakpoint_locations_match (loc
, *loc_first_p
))
9933 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9934 && b
->enable_state
!= bp_permanent
)
9935 internal_error (__FILE__
, __LINE__
,
9936 _("another breakpoint was inserted on top of "
9937 "a permanent breakpoint"));
9940 if (breakpoints_always_inserted_mode () && should_insert
9941 && (have_live_inferiors ()
9942 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9943 insert_breakpoint_locations ();
9945 do_cleanups (cleanups
);
9949 breakpoint_retire_moribund (void)
9951 struct bp_location
*loc
;
9954 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9955 if (--(loc
->events_till_retirement
) == 0)
9957 decref_bp_location (&loc
);
9958 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9964 update_global_location_list_nothrow (int inserting
)
9966 struct gdb_exception e
;
9968 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9969 update_global_location_list (inserting
);
9972 /* Clear BKP from a BPS. */
9975 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
9979 for (bs
= bps
; bs
; bs
= bs
->next
)
9980 if (bs
->breakpoint_at
== bpt
)
9982 bs
->breakpoint_at
= NULL
;
9984 /* bs->commands will be freed later. */
9988 /* Callback for iterate_over_threads. */
9990 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9992 struct breakpoint
*bpt
= data
;
9994 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
9998 /* Delete a breakpoint and clean up all traces of it in the data
10002 delete_breakpoint (struct breakpoint
*bpt
)
10004 struct breakpoint
*b
;
10006 gdb_assert (bpt
!= NULL
);
10008 /* Has this bp already been deleted? This can happen because
10009 multiple lists can hold pointers to bp's. bpstat lists are
10012 One example of this happening is a watchpoint's scope bp. When
10013 the scope bp triggers, we notice that the watchpoint is out of
10014 scope, and delete it. We also delete its scope bp. But the
10015 scope bp is marked "auto-deleting", and is already on a bpstat.
10016 That bpstat is then checked for auto-deleting bp's, which are
10019 A real solution to this problem might involve reference counts in
10020 bp's, and/or giving them pointers back to their referencing
10021 bpstat's, and teaching delete_breakpoint to only free a bp's
10022 storage when no more references were extent. A cheaper bandaid
10024 if (bpt
->type
== bp_none
)
10027 /* At least avoid this stale reference until the reference counting
10028 of breakpoints gets resolved. */
10029 if (bpt
->related_breakpoint
!= NULL
)
10031 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
10032 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
10033 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
10034 bpt
->related_breakpoint
= NULL
;
10037 observer_notify_breakpoint_deleted (bpt
->number
);
10039 if (breakpoint_chain
== bpt
)
10040 breakpoint_chain
= bpt
->next
;
10042 ALL_BREAKPOINTS (b
)
10043 if (b
->next
== bpt
)
10045 b
->next
= bpt
->next
;
10049 decref_counted_command_line (&bpt
->commands
);
10050 xfree (bpt
->cond_string
);
10051 xfree (bpt
->cond_exp
);
10052 xfree (bpt
->addr_string
);
10054 xfree (bpt
->exp_string
);
10055 xfree (bpt
->exp_string_reparse
);
10056 value_free (bpt
->val
);
10057 xfree (bpt
->source_file
);
10058 xfree (bpt
->exec_pathname
);
10059 clean_up_filters (&bpt
->syscalls_to_be_caught
);
10062 /* Be sure no bpstat's are pointing at the breakpoint after it's
10064 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10065 in all threeds for now. Note that we cannot just remove bpstats
10066 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10067 commands are associated with the bpstat; if we remove it here,
10068 then the later call to bpstat_do_actions (&stop_bpstat); in
10069 event-top.c won't do anything, and temporary breakpoints with
10070 commands won't work. */
10072 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
10074 /* Now that breakpoint is removed from breakpoint list, update the
10075 global location list. This will remove locations that used to
10076 belong to this breakpoint. Do this before freeing the breakpoint
10077 itself, since remove_breakpoint looks at location's owner. It
10078 might be better design to have location completely
10079 self-contained, but it's not the case now. */
10080 update_global_location_list (0);
10083 /* On the chance that someone will soon try again to delete this
10084 same bp, we mark it as deleted before freeing its storage. */
10085 bpt
->type
= bp_none
;
10091 do_delete_breakpoint_cleanup (void *b
)
10093 delete_breakpoint (b
);
10097 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
10099 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
10102 /* A callback for map_breakpoint_numbers that calls
10103 delete_breakpoint. */
10106 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
10108 delete_breakpoint (b
);
10112 delete_command (char *arg
, int from_tty
)
10114 struct breakpoint
*b
, *b_tmp
;
10120 int breaks_to_delete
= 0;
10122 /* Delete all breakpoints if no argument.
10123 Do not delete internal or call-dummy breakpoints, these have
10124 to be deleted with an explicit breakpoint number argument. */
10125 ALL_BREAKPOINTS (b
)
10127 if (b
->type
!= bp_call_dummy
10128 && b
->type
!= bp_std_terminate
10129 && b
->type
!= bp_shlib_event
10130 && b
->type
!= bp_jit_event
10131 && b
->type
!= bp_thread_event
10132 && b
->type
!= bp_overlay_event
10133 && b
->type
!= bp_longjmp_master
10134 && b
->type
!= bp_std_terminate_master
10135 && b
->type
!= bp_exception_master
10138 breaks_to_delete
= 1;
10143 /* Ask user only if there are some breakpoints to delete. */
10145 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10147 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10149 if (b
->type
!= bp_call_dummy
10150 && b
->type
!= bp_std_terminate
10151 && b
->type
!= bp_shlib_event
10152 && b
->type
!= bp_thread_event
10153 && b
->type
!= bp_jit_event
10154 && b
->type
!= bp_overlay_event
10155 && b
->type
!= bp_longjmp_master
10156 && b
->type
!= bp_std_terminate_master
10157 && b
->type
!= bp_exception_master
10159 delete_breakpoint (b
);
10164 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10168 all_locations_are_pending (struct bp_location
*loc
)
10170 for (; loc
; loc
= loc
->next
)
10171 if (!loc
->shlib_disabled
)
10176 /* Subroutine of update_breakpoint_locations to simplify it.
10177 Return non-zero if multiple fns in list LOC have the same name.
10178 Null names are ignored. */
10181 ambiguous_names_p (struct bp_location
*loc
)
10183 struct bp_location
*l
;
10184 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10185 (int (*) (const void *,
10186 const void *)) streq
,
10187 NULL
, xcalloc
, xfree
);
10189 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10192 const char *name
= l
->function_name
;
10194 /* Allow for some names to be NULL, ignore them. */
10198 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10200 /* NOTE: We can assume slot != NULL here because xcalloc never
10204 htab_delete (htab
);
10210 htab_delete (htab
);
10214 /* When symbols change, it probably means the sources changed as well,
10215 and it might mean the static tracepoint markers are no longer at
10216 the same address or line numbers they used to be at last we
10217 checked. Losing your static tracepoints whenever you rebuild is
10218 undesirable. This function tries to resync/rematch gdb static
10219 tracepoints with the markers on the target, for static tracepoints
10220 that have not been set by marker id. Static tracepoint that have
10221 been set by marker id are reset by marker id in breakpoint_re_set.
10224 1) For a tracepoint set at a specific address, look for a marker at
10225 the old PC. If one is found there, assume to be the same marker.
10226 If the name / string id of the marker found is different from the
10227 previous known name, assume that means the user renamed the marker
10228 in the sources, and output a warning.
10230 2) For a tracepoint set at a given line number, look for a marker
10231 at the new address of the old line number. If one is found there,
10232 assume to be the same marker. If the name / string id of the
10233 marker found is different from the previous known name, assume that
10234 means the user renamed the marker in the sources, and output a
10237 3) If a marker is no longer found at the same address or line, it
10238 may mean the marker no longer exists. But it may also just mean
10239 the code changed a bit. Maybe the user added a few lines of code
10240 that made the marker move up or down (in line number terms). Ask
10241 the target for info about the marker with the string id as we knew
10242 it. If found, update line number and address in the matching
10243 static tracepoint. This will get confused if there's more than one
10244 marker with the same ID (possible in UST, although unadvised
10245 precisely because it confuses tools). */
10247 static struct symtab_and_line
10248 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10250 struct static_tracepoint_marker marker
;
10256 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10258 if (target_static_tracepoint_marker_at (pc
, &marker
))
10260 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10261 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10263 b
->static_trace_marker_id
, marker
.str_id
);
10265 xfree (b
->static_trace_marker_id
);
10266 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10267 release_static_tracepoint_marker (&marker
);
10272 /* Old marker wasn't found on target at lineno. Try looking it up
10274 if (!sal
.explicit_pc
10276 && sal
.symtab
!= NULL
10277 && b
->static_trace_marker_id
!= NULL
)
10279 VEC(static_tracepoint_marker_p
) *markers
;
10282 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10284 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10286 struct symtab_and_line sal
;
10287 struct symbol
*sym
;
10288 struct static_tracepoint_marker
*marker
;
10290 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10292 xfree (b
->static_trace_marker_id
);
10293 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10295 warning (_("marker for static tracepoint %d (%s) not "
10296 "found at previous line number"),
10297 b
->number
, b
->static_trace_marker_id
);
10301 sal
.pc
= marker
->address
;
10303 sal
= find_pc_line (marker
->address
, 0);
10304 sym
= find_pc_sect_function (marker
->address
, NULL
);
10305 ui_out_text (uiout
, "Now in ");
10308 ui_out_field_string (uiout
, "func",
10309 SYMBOL_PRINT_NAME (sym
));
10310 ui_out_text (uiout
, " at ");
10312 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10313 ui_out_text (uiout
, ":");
10315 if (ui_out_is_mi_like_p (uiout
))
10317 char *fullname
= symtab_to_fullname (sal
.symtab
);
10320 ui_out_field_string (uiout
, "fullname", fullname
);
10323 ui_out_field_int (uiout
, "line", sal
.line
);
10324 ui_out_text (uiout
, "\n");
10326 b
->line_number
= sal
.line
;
10328 xfree (b
->source_file
);
10330 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10332 b
->source_file
= NULL
;
10334 xfree (b
->addr_string
);
10335 b
->addr_string
= xstrprintf ("%s:%d",
10336 sal
.symtab
->filename
, b
->line_number
);
10338 /* Might be nice to check if function changed, and warn if
10341 release_static_tracepoint_marker (marker
);
10348 update_breakpoint_locations (struct breakpoint
*b
,
10349 struct symtabs_and_lines sals
)
10353 struct bp_location
*existing_locations
= b
->loc
;
10355 /* If there's no new locations, and all existing locations are
10356 pending, don't do anything. This optimizes the common case where
10357 all locations are in the same shared library, that was unloaded.
10358 We'd like to retain the location, so that when the library is
10359 loaded again, we don't loose the enabled/disabled status of the
10360 individual locations. */
10361 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10366 for (i
= 0; i
< sals
.nelts
; ++i
)
10368 struct bp_location
*new_loc
=
10369 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10371 /* Reparse conditions, they might contain references to the
10373 if (b
->cond_string
!= NULL
)
10375 struct gdb_exception e
;
10377 s
= b
->cond_string
;
10378 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10380 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10385 warning (_("failed to reevaluate condition "
10386 "for breakpoint %d: %s"),
10387 b
->number
, e
.message
);
10388 new_loc
->enabled
= 0;
10392 if (b
->source_file
!= NULL
)
10393 xfree (b
->source_file
);
10394 if (sals
.sals
[i
].symtab
== NULL
)
10395 b
->source_file
= NULL
;
10397 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10399 if (b
->line_number
== 0)
10400 b
->line_number
= sals
.sals
[i
].line
;
10403 /* Update locations of permanent breakpoints. */
10404 if (b
->enable_state
== bp_permanent
)
10405 make_breakpoint_permanent (b
);
10407 /* If possible, carry over 'disable' status from existing
10410 struct bp_location
*e
= existing_locations
;
10411 /* If there are multiple breakpoints with the same function name,
10412 e.g. for inline functions, comparing function names won't work.
10413 Instead compare pc addresses; this is just a heuristic as things
10414 may have moved, but in practice it gives the correct answer
10415 often enough until a better solution is found. */
10416 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10418 for (; e
; e
= e
->next
)
10420 if (!e
->enabled
&& e
->function_name
)
10422 struct bp_location
*l
= b
->loc
;
10423 if (have_ambiguous_names
)
10425 for (; l
; l
= l
->next
)
10426 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10427 l
->pspace
->aspace
, l
->address
))
10435 for (; l
; l
= l
->next
)
10436 if (l
->function_name
10437 && strcmp (e
->function_name
, l
->function_name
) == 0)
10447 update_global_location_list (1);
10450 /* Reset a breakpoint given it's struct breakpoint * BINT.
10451 The value we return ends up being the return value from catch_errors.
10452 Unused in this case. */
10455 breakpoint_re_set_one (void *bint
)
10457 /* Get past catch_errs. */
10458 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10460 int *not_found_ptr
= ¬_found
;
10461 struct symtabs_and_lines sals
= {0};
10462 struct symtabs_and_lines expanded
= {0};
10464 struct gdb_exception e
;
10465 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10466 int marker_spec
= 0;
10471 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10474 case bp_breakpoint
:
10475 case bp_hardware_breakpoint
:
10476 case bp_tracepoint
:
10477 case bp_fast_tracepoint
:
10478 case bp_static_tracepoint
:
10479 /* Do not attempt to re-set breakpoints disabled during startup. */
10480 if (b
->enable_state
== bp_startup_disabled
)
10483 if (b
->addr_string
== NULL
)
10485 /* Anything without a string can't be re-set. */
10486 delete_breakpoint (b
);
10490 input_radix
= b
->input_radix
;
10491 s
= b
->addr_string
;
10493 save_current_space_and_thread ();
10494 switch_to_program_space_and_thread (b
->pspace
);
10496 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10498 set_language (b
->language
);
10499 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10503 sals
= decode_static_tracepoint_spec (&s
);
10504 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10506 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10510 error (_("marker %s not found"), b
->static_trace_marker_id
);
10513 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0,
10514 (char ***) NULL
, not_found_ptr
);
10518 int not_found_and_ok
= 0;
10519 /* For pending breakpoints, it's expected that parsing will
10520 fail until the right shared library is loaded. User has
10521 already told to create pending breakpoints and don't need
10522 extra messages. If breakpoint is in bp_shlib_disabled
10523 state, then user already saw the message about that
10524 breakpoint being disabled, and don't want to see more
10527 && (b
->condition_not_parsed
10528 || (b
->loc
&& b
->loc
->shlib_disabled
)
10529 || b
->enable_state
== bp_disabled
))
10530 not_found_and_ok
= 1;
10532 if (!not_found_and_ok
)
10534 /* We surely don't want to warn about the same breakpoint
10535 10 times. One solution, implemented here, is disable
10536 the breakpoint on error. Another solution would be to
10537 have separate 'warning emitted' flag. Since this
10538 happens only when a binary has changed, I don't know
10539 which approach is better. */
10540 b
->enable_state
= bp_disabled
;
10541 throw_exception (e
);
10547 gdb_assert (sals
.nelts
== 1);
10549 resolve_sal_pc (&sals
.sals
[0]);
10550 if (b
->condition_not_parsed
&& s
&& s
[0])
10552 char *cond_string
= 0;
10556 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10557 &cond_string
, &thread
, &task
);
10559 b
->cond_string
= cond_string
;
10560 b
->thread
= thread
;
10562 b
->condition_not_parsed
= 0;
10565 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10566 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10568 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10571 make_cleanup (xfree
, sals
.sals
);
10572 update_breakpoint_locations (b
, expanded
);
10575 case bp_watchpoint
:
10576 case bp_hardware_watchpoint
:
10577 case bp_read_watchpoint
:
10578 case bp_access_watchpoint
:
10579 /* Watchpoint can be either on expression using entirely global
10580 variables, or it can be on local variables.
10582 Watchpoints of the first kind are never auto-deleted, and
10583 even persist across program restarts. Since they can use
10584 variables from shared libraries, we need to reparse
10585 expression as libraries are loaded and unloaded.
10587 Watchpoints on local variables can also change meaning as
10588 result of solib event. For example, if a watchpoint uses
10589 both a local and a global variables in expression, it's a
10590 local watchpoint, but unloading of a shared library will make
10591 the expression invalid. This is not a very common use case,
10592 but we still re-evaluate expression, to avoid surprises to
10595 Note that for local watchpoints, we re-evaluate it only if
10596 watchpoints frame id is still valid. If it's not, it means
10597 the watchpoint is out of scope and will be deleted soon. In
10598 fact, I'm not sure we'll ever be called in this case.
10600 If a local watchpoint's frame id is still valid, then
10601 b->exp_valid_block is likewise valid, and we can safely use it.
10603 Don't do anything about disabled watchpoints, since they will
10604 be reevaluated again when enabled. */
10605 update_watchpoint (b
, 1 /* reparse */);
10607 /* We needn't really do anything to reset these, since the mask
10608 that requests them is unaffected by e.g., new libraries being
10610 case bp_catchpoint
:
10614 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10616 /* Delete overlay event and longjmp master breakpoints; they will be
10617 reset later by breakpoint_re_set. */
10618 case bp_overlay_event
:
10619 case bp_longjmp_master
:
10620 case bp_std_terminate_master
:
10621 case bp_exception_master
:
10622 delete_breakpoint (b
);
10625 /* This breakpoint is special, it's set up when the inferior
10626 starts and we really don't want to touch it. */
10627 case bp_shlib_event
:
10629 /* Like bp_shlib_event, this breakpoint type is special.
10630 Once it is set up, we do not want to touch it. */
10631 case bp_thread_event
:
10633 /* Keep temporary breakpoints, which can be encountered when we
10634 step over a dlopen call and SOLIB_ADD is resetting the
10635 breakpoints. Otherwise these should have been blown away via
10636 the cleanup chain or by breakpoint_init_inferior when we
10637 rerun the executable. */
10640 case bp_watchpoint_scope
:
10641 case bp_call_dummy
:
10642 case bp_std_terminate
:
10643 case bp_step_resume
:
10645 case bp_longjmp_resume
:
10647 case bp_exception_resume
:
10652 do_cleanups (cleanups
);
10656 /* Re-set all breakpoints after symbols have been re-loaded. */
10658 breakpoint_re_set (void)
10660 struct breakpoint
*b
, *b_tmp
;
10661 enum language save_language
;
10662 int save_input_radix
;
10663 struct cleanup
*old_chain
;
10665 save_language
= current_language
->la_language
;
10666 save_input_radix
= input_radix
;
10667 old_chain
= save_current_program_space ();
10669 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10671 /* Format possible error msg. */
10672 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10674 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10675 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10676 do_cleanups (cleanups
);
10678 set_language (save_language
);
10679 input_radix
= save_input_radix
;
10681 jit_breakpoint_re_set ();
10683 do_cleanups (old_chain
);
10685 create_overlay_event_breakpoint ();
10686 create_longjmp_master_breakpoint ();
10687 create_std_terminate_master_breakpoint ();
10688 create_exception_master_breakpoint ();
10691 /* Reset the thread number of this breakpoint:
10693 - If the breakpoint is for all threads, leave it as-is.
10694 - Else, reset it to the current thread for inferior_ptid. */
10696 breakpoint_re_set_thread (struct breakpoint
*b
)
10698 if (b
->thread
!= -1)
10700 if (in_thread_list (inferior_ptid
))
10701 b
->thread
= pid_to_thread_id (inferior_ptid
);
10703 /* We're being called after following a fork. The new fork is
10704 selected as current, and unless this was a vfork will have a
10705 different program space from the original thread. Reset that
10707 b
->loc
->pspace
= current_program_space
;
10711 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10712 If from_tty is nonzero, it prints a message to that effect,
10713 which ends with a period (no newline). */
10716 set_ignore_count (int bptnum
, int count
, int from_tty
)
10718 struct breakpoint
*b
;
10723 ALL_BREAKPOINTS (b
)
10724 if (b
->number
== bptnum
)
10726 if (is_tracepoint (b
))
10728 if (from_tty
&& count
!= 0)
10729 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10734 b
->ignore_count
= count
;
10738 printf_filtered (_("Will stop next time "
10739 "breakpoint %d is reached."),
10741 else if (count
== 1)
10742 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10745 printf_filtered (_("Will ignore next %d "
10746 "crossings of breakpoint %d."),
10749 breakpoints_changed ();
10750 observer_notify_breakpoint_modified (b
->number
);
10754 error (_("No breakpoint number %d."), bptnum
);
10757 /* Command to set ignore-count of breakpoint N to COUNT. */
10760 ignore_command (char *args
, int from_tty
)
10766 error_no_arg (_("a breakpoint number"));
10768 num
= get_number (&p
);
10770 error (_("bad breakpoint number: '%s'"), args
);
10772 error (_("Second argument (specified ignore-count) is missing."));
10774 set_ignore_count (num
,
10775 longest_to_int (value_as_long (parse_and_eval (p
))),
10778 printf_filtered ("\n");
10781 /* Call FUNCTION on each of the breakpoints
10782 whose numbers are given in ARGS. */
10785 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10792 struct breakpoint
*b
, *tmp
;
10796 error_no_arg (_("one or more breakpoint numbers"));
10803 num
= get_number_or_range (&p1
);
10806 warning (_("bad breakpoint number at or near '%s'"), p
);
10810 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10811 if (b
->number
== num
)
10813 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10815 function (b
, data
);
10816 if (related_breakpoint
)
10817 function (related_breakpoint
, data
);
10821 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10827 static struct bp_location
*
10828 find_location_by_number (char *number
)
10830 char *dot
= strchr (number
, '.');
10834 struct breakpoint
*b
;
10835 struct bp_location
*loc
;
10840 bp_num
= get_number_or_range (&p1
);
10842 error (_("Bad breakpoint number '%s'"), number
);
10844 ALL_BREAKPOINTS (b
)
10845 if (b
->number
== bp_num
)
10850 if (!b
|| b
->number
!= bp_num
)
10851 error (_("Bad breakpoint number '%s'"), number
);
10854 loc_num
= get_number_or_range (&p1
);
10856 error (_("Bad breakpoint location number '%s'"), number
);
10860 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10863 error (_("Bad breakpoint location number '%s'"), dot
+1);
10869 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10870 If from_tty is nonzero, it prints a message to that effect,
10871 which ends with a period (no newline). */
10874 disable_breakpoint (struct breakpoint
*bpt
)
10876 /* Never disable a watchpoint scope breakpoint; we want to
10877 hit them when we leave scope so we can delete both the
10878 watchpoint and its scope breakpoint at that time. */
10879 if (bpt
->type
== bp_watchpoint_scope
)
10882 /* You can't disable permanent breakpoints. */
10883 if (bpt
->enable_state
== bp_permanent
)
10886 bpt
->enable_state
= bp_disabled
;
10888 update_global_location_list (0);
10890 observer_notify_breakpoint_modified (bpt
->number
);
10893 /* A callback for map_breakpoint_numbers that calls
10894 disable_breakpoint. */
10897 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10899 disable_breakpoint (b
);
10903 disable_command (char *args
, int from_tty
)
10905 struct breakpoint
*bpt
;
10908 ALL_BREAKPOINTS (bpt
)
10912 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10915 case bp_breakpoint
:
10916 case bp_tracepoint
:
10917 case bp_fast_tracepoint
:
10918 case bp_static_tracepoint
:
10919 case bp_catchpoint
:
10920 case bp_hardware_breakpoint
:
10921 case bp_watchpoint
:
10922 case bp_hardware_watchpoint
:
10923 case bp_read_watchpoint
:
10924 case bp_access_watchpoint
:
10925 disable_breakpoint (bpt
);
10929 else if (strchr (args
, '.'))
10931 struct bp_location
*loc
= find_location_by_number (args
);
10934 update_global_location_list (0);
10937 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10941 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10943 int target_resources_ok
;
10945 if (bpt
->type
== bp_hardware_breakpoint
)
10948 i
= hw_breakpoint_used_count ();
10949 target_resources_ok
=
10950 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10952 if (target_resources_ok
== 0)
10953 error (_("No hardware breakpoint support in the target."));
10954 else if (target_resources_ok
< 0)
10955 error (_("Hardware breakpoints used exceeds limit."));
10958 if (is_watchpoint (bpt
))
10960 struct gdb_exception e
;
10962 TRY_CATCH (e
, RETURN_MASK_ALL
)
10964 update_watchpoint (bpt
, 1 /* reparse */);
10968 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10974 if (bpt
->enable_state
!= bp_permanent
)
10975 bpt
->enable_state
= bp_enabled
;
10976 bpt
->disposition
= disposition
;
10977 update_global_location_list (1);
10978 breakpoints_changed ();
10980 observer_notify_breakpoint_modified (bpt
->number
);
10985 enable_breakpoint (struct breakpoint
*bpt
)
10987 do_enable_breakpoint (bpt
, bpt
->disposition
);
10990 /* A callback for map_breakpoint_numbers that calls
10991 enable_breakpoint. */
10994 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10996 enable_breakpoint (b
);
10999 /* The enable command enables the specified breakpoints (or all defined
11000 breakpoints) so they once again become (or continue to be) effective
11001 in stopping the inferior. */
11004 enable_command (char *args
, int from_tty
)
11006 struct breakpoint
*bpt
;
11009 ALL_BREAKPOINTS (bpt
)
11013 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
11016 case bp_breakpoint
:
11017 case bp_tracepoint
:
11018 case bp_fast_tracepoint
:
11019 case bp_static_tracepoint
:
11020 case bp_catchpoint
:
11021 case bp_hardware_breakpoint
:
11022 case bp_watchpoint
:
11023 case bp_hardware_watchpoint
:
11024 case bp_read_watchpoint
:
11025 case bp_access_watchpoint
:
11026 enable_breakpoint (bpt
);
11030 else if (strchr (args
, '.'))
11032 struct bp_location
*loc
= find_location_by_number (args
);
11035 update_global_location_list (1);
11038 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
11042 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11044 do_enable_breakpoint (bpt
, disp_disable
);
11048 enable_once_command (char *args
, int from_tty
)
11050 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
11054 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11056 do_enable_breakpoint (bpt
, disp_del
);
11060 enable_delete_command (char *args
, int from_tty
)
11062 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
11066 set_breakpoint_cmd (char *args
, int from_tty
)
11071 show_breakpoint_cmd (char *args
, int from_tty
)
11075 /* Invalidate last known value of any hardware watchpoint if
11076 the memory which that value represents has been written to by
11080 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
11081 const bfd_byte
*data
)
11083 struct breakpoint
*bp
;
11085 ALL_BREAKPOINTS (bp
)
11086 if (bp
->enable_state
== bp_enabled
11087 && bp
->type
== bp_hardware_watchpoint
11088 && bp
->val_valid
&& bp
->val
)
11090 struct bp_location
*loc
;
11092 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
11093 if (loc
->loc_type
== bp_loc_hardware_watchpoint
11094 && loc
->address
+ loc
->length
> addr
11095 && addr
+ len
> loc
->address
)
11097 value_free (bp
->val
);
11104 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11106 struct symtabs_and_lines
11107 decode_line_spec_1 (char *string
, int funfirstline
)
11109 struct symtabs_and_lines sals
;
11112 error (_("Empty line specification."));
11113 if (default_breakpoint_valid
)
11114 sals
= decode_line_1 (&string
, funfirstline
,
11115 default_breakpoint_symtab
,
11116 default_breakpoint_line
,
11117 (char ***) NULL
, NULL
);
11119 sals
= decode_line_1 (&string
, funfirstline
,
11120 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
11122 error (_("Junk at end of line specification: %s"), string
);
11126 /* Create and insert a raw software breakpoint at PC. Return an
11127 identifier, which should be used to remove the breakpoint later.
11128 In general, places which call this should be using something on the
11129 breakpoint chain instead; this function should be eliminated
11133 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11134 struct address_space
*aspace
, CORE_ADDR pc
)
11136 struct bp_target_info
*bp_tgt
;
11138 bp_tgt
= XZALLOC (struct bp_target_info
);
11140 bp_tgt
->placed_address_space
= aspace
;
11141 bp_tgt
->placed_address
= pc
;
11143 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11145 /* Could not insert the breakpoint. */
11153 /* Remove a breakpoint BP inserted by
11154 deprecated_insert_raw_breakpoint. */
11157 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11159 struct bp_target_info
*bp_tgt
= bp
;
11162 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11168 /* One (or perhaps two) breakpoints used for software single
11171 static void *single_step_breakpoints
[2];
11172 static struct gdbarch
*single_step_gdbarch
[2];
11174 /* Create and insert a breakpoint for software single step. */
11177 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11178 struct address_space
*aspace
,
11183 if (single_step_breakpoints
[0] == NULL
)
11185 bpt_p
= &single_step_breakpoints
[0];
11186 single_step_gdbarch
[0] = gdbarch
;
11190 gdb_assert (single_step_breakpoints
[1] == NULL
);
11191 bpt_p
= &single_step_breakpoints
[1];
11192 single_step_gdbarch
[1] = gdbarch
;
11195 /* NOTE drow/2006-04-11: A future improvement to this function would
11196 be to only create the breakpoints once, and actually put them on
11197 the breakpoint chain. That would let us use set_raw_breakpoint.
11198 We could adjust the addresses each time they were needed. Doing
11199 this requires corresponding changes elsewhere where single step
11200 breakpoints are handled, however. So, for now, we use this. */
11202 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11203 if (*bpt_p
== NULL
)
11204 error (_("Could not insert single-step breakpoint at %s"),
11205 paddress (gdbarch
, next_pc
));
11208 /* Check if the breakpoints used for software single stepping
11209 were inserted or not. */
11212 single_step_breakpoints_inserted (void)
11214 return (single_step_breakpoints
[0] != NULL
11215 || single_step_breakpoints
[1] != NULL
);
11218 /* Remove and delete any breakpoints used for software single step. */
11221 remove_single_step_breakpoints (void)
11223 gdb_assert (single_step_breakpoints
[0] != NULL
);
11225 /* See insert_single_step_breakpoint for more about this deprecated
11227 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11228 single_step_breakpoints
[0]);
11229 single_step_gdbarch
[0] = NULL
;
11230 single_step_breakpoints
[0] = NULL
;
11232 if (single_step_breakpoints
[1] != NULL
)
11234 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11235 single_step_breakpoints
[1]);
11236 single_step_gdbarch
[1] = NULL
;
11237 single_step_breakpoints
[1] = NULL
;
11241 /* Delete software single step breakpoints without removing them from
11242 the inferior. This is intended to be used if the inferior's address
11243 space where they were inserted is already gone, e.g. after exit or
11247 cancel_single_step_breakpoints (void)
11251 for (i
= 0; i
< 2; i
++)
11252 if (single_step_breakpoints
[i
])
11254 xfree (single_step_breakpoints
[i
]);
11255 single_step_breakpoints
[i
] = NULL
;
11256 single_step_gdbarch
[i
] = NULL
;
11260 /* Detach software single-step breakpoints from INFERIOR_PTID without
11264 detach_single_step_breakpoints (void)
11268 for (i
= 0; i
< 2; i
++)
11269 if (single_step_breakpoints
[i
])
11270 target_remove_breakpoint (single_step_gdbarch
[i
],
11271 single_step_breakpoints
[i
]);
11274 /* Check whether a software single-step breakpoint is inserted at
11278 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11283 for (i
= 0; i
< 2; i
++)
11285 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11287 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11288 bp_tgt
->placed_address
,
11296 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11297 non-zero otherwise. */
11299 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11301 if (syscall_catchpoint_p (bp
)
11302 && bp
->enable_state
!= bp_disabled
11303 && bp
->enable_state
!= bp_call_disabled
)
11310 catch_syscall_enabled (void)
11312 struct inferior
*inf
= current_inferior ();
11314 return inf
->total_syscalls_count
!= 0;
11318 catching_syscall_number (int syscall_number
)
11320 struct breakpoint
*bp
;
11322 ALL_BREAKPOINTS (bp
)
11323 if (is_syscall_catchpoint_enabled (bp
))
11325 if (bp
->syscalls_to_be_caught
)
11329 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11331 if (syscall_number
== iter
)
11341 /* Complete syscall names. Used by "catch syscall". */
11343 catch_syscall_completer (struct cmd_list_element
*cmd
,
11344 char *text
, char *word
)
11346 const char **list
= get_syscall_names ();
11348 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11351 /* Tracepoint-specific operations. */
11353 /* Set tracepoint count to NUM. */
11355 set_tracepoint_count (int num
)
11357 tracepoint_count
= num
;
11358 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11362 trace_command (char *arg
, int from_tty
)
11364 if (create_breakpoint (get_current_arch (),
11366 NULL
, 0, 1 /* parse arg */,
11368 bp_tracepoint
/* type_wanted */,
11369 0 /* Ignore count */,
11370 pending_break_support
,
11375 set_tracepoint_count (breakpoint_count
);
11379 ftrace_command (char *arg
, int from_tty
)
11381 if (create_breakpoint (get_current_arch (),
11383 NULL
, 0, 1 /* parse arg */,
11385 bp_fast_tracepoint
/* type_wanted */,
11386 0 /* Ignore count */,
11387 pending_break_support
,
11392 set_tracepoint_count (breakpoint_count
);
11395 /* strace command implementation. Creates a static tracepoint. */
11398 strace_command (char *arg
, int from_tty
)
11400 if (create_breakpoint (get_current_arch (),
11402 NULL
, 0, 1 /* parse arg */,
11404 bp_static_tracepoint
/* type_wanted */,
11405 0 /* Ignore count */,
11406 pending_break_support
,
11411 set_tracepoint_count (breakpoint_count
);
11414 /* Set up a fake reader function that gets command lines from a linked
11415 list that was acquired during tracepoint uploading. */
11417 static struct uploaded_tp
*this_utp
;
11418 static int next_cmd
;
11421 read_uploaded_action (void)
11425 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11432 /* Given information about a tracepoint as recorded on a target (which
11433 can be either a live system or a trace file), attempt to create an
11434 equivalent GDB tracepoint. This is not a reliable process, since
11435 the target does not necessarily have all the information used when
11436 the tracepoint was originally defined. */
11438 struct breakpoint
*
11439 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11441 char *addr_str
, small_buf
[100];
11442 struct breakpoint
*tp
;
11444 if (utp
->at_string
)
11445 addr_str
= utp
->at_string
;
11448 /* In the absence of a source location, fall back to raw
11449 address. Since there is no way to confirm that the address
11450 means the same thing as when the trace was started, warn the
11452 warning (_("Uploaded tracepoint %d has no "
11453 "source location, using raw address"),
11455 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11456 addr_str
= small_buf
;
11459 /* There's not much we can do with a sequence of bytecodes. */
11460 if (utp
->cond
&& !utp
->cond_string
)
11461 warning (_("Uploaded tracepoint %d condition "
11462 "has no source form, ignoring it"),
11465 if (!create_breakpoint (get_current_arch (),
11467 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11469 utp
->type
/* type_wanted */,
11470 0 /* Ignore count */,
11471 pending_break_support
,
11474 utp
->enabled
/* enabled */,
11478 set_tracepoint_count (breakpoint_count
);
11480 /* Get the tracepoint we just created. */
11481 tp
= get_tracepoint (tracepoint_count
);
11482 gdb_assert (tp
!= NULL
);
11486 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11488 trace_pass_command (small_buf
, 0);
11491 /* If we have uploaded versions of the original commands, set up a
11492 special-purpose "reader" function and call the usual command line
11493 reader, then pass the result to the breakpoint command-setting
11495 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11497 struct command_line
*cmd_list
;
11502 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11504 breakpoint_set_commands (tp
, cmd_list
);
11506 else if (!VEC_empty (char_ptr
, utp
->actions
)
11507 || !VEC_empty (char_ptr
, utp
->step_actions
))
11508 warning (_("Uploaded tracepoint %d actions "
11509 "have no source form, ignoring them"),
11515 /* Print information on tracepoint number TPNUM_EXP, or all if
11519 tracepoints_info (char *args
, int from_tty
)
11523 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
11525 if (num_printed
== 0)
11527 if (args
== NULL
|| *args
== '\0')
11528 ui_out_message (uiout
, 0, "No tracepoints.\n");
11530 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
11533 default_collect_info ();
11536 /* The 'enable trace' command enables tracepoints.
11537 Not supported by all targets. */
11539 enable_trace_command (char *args
, int from_tty
)
11541 enable_command (args
, from_tty
);
11544 /* The 'disable trace' command disables tracepoints.
11545 Not supported by all targets. */
11547 disable_trace_command (char *args
, int from_tty
)
11549 disable_command (args
, from_tty
);
11552 /* Remove a tracepoint (or all if no argument). */
11554 delete_trace_command (char *arg
, int from_tty
)
11556 struct breakpoint
*b
, *b_tmp
;
11562 int breaks_to_delete
= 0;
11564 /* Delete all breakpoints if no argument.
11565 Do not delete internal or call-dummy breakpoints, these
11566 have to be deleted with an explicit breakpoint number
11568 ALL_TRACEPOINTS (b
)
11570 if (b
->number
>= 0)
11572 breaks_to_delete
= 1;
11577 /* Ask user only if there are some breakpoints to delete. */
11579 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11581 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11583 if (is_tracepoint (b
)
11585 delete_breakpoint (b
);
11590 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11593 /* Set passcount for tracepoint.
11595 First command argument is passcount, second is tracepoint number.
11596 If tracepoint number omitted, apply to most recently defined.
11597 Also accepts special argument "all". */
11600 trace_pass_command (char *args
, int from_tty
)
11602 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11603 unsigned int count
;
11606 if (args
== 0 || *args
== 0)
11607 error (_("passcount command requires an "
11608 "argument (count + optional TP num)"));
11610 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11612 while (*args
&& isspace ((int) *args
))
11615 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11617 args
+= 3; /* Skip special argument "all". */
11620 error (_("Junk at end of arguments."));
11623 t1
= get_tracepoint_by_number (&args
, 1, 1);
11629 ALL_TRACEPOINTS (t2
)
11630 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11632 t2
->pass_count
= count
;
11633 observer_notify_tracepoint_modified (t2
->number
);
11635 printf_filtered (_("Setting tracepoint %d's "
11636 "passcount to %d\n"),
11637 t2
->number
, count
);
11639 if (! all
&& *args
)
11640 t1
= get_tracepoint_by_number (&args
, 1, 0);
11646 struct breakpoint
*
11647 get_tracepoint (int num
)
11649 struct breakpoint
*t
;
11651 ALL_TRACEPOINTS (t
)
11652 if (t
->number
== num
)
11658 /* Find the tracepoint with the given target-side number (which may be
11659 different from the tracepoint number after disconnecting and
11662 struct breakpoint
*
11663 get_tracepoint_by_number_on_target (int num
)
11665 struct breakpoint
*t
;
11667 ALL_TRACEPOINTS (t
)
11668 if (t
->number_on_target
== num
)
11674 /* Utility: parse a tracepoint number and look it up in the list.
11675 If MULTI_P is true, there might be a range of tracepoints in ARG.
11676 if OPTIONAL_P is true, then if the argument is missing, the most
11677 recent tracepoint (tracepoint_count) is returned. */
11678 struct breakpoint
*
11679 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11681 extern int tracepoint_count
;
11682 struct breakpoint
*t
;
11684 char *instring
= arg
== NULL
? NULL
: *arg
;
11686 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11689 tpnum
= tracepoint_count
;
11691 error_no_arg (_("tracepoint number"));
11694 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11698 if (instring
&& *instring
)
11699 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11702 printf_filtered (_("Tracepoint argument missing "
11703 "and no previous tracepoint\n"));
11707 ALL_TRACEPOINTS (t
)
11708 if (t
->number
== tpnum
)
11713 /* FIXME: if we are in the middle of a range we don't want to give
11714 a message. The current interface to get_number_or_range doesn't
11715 allow us to discover this. */
11716 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11720 /* Save information on user settable breakpoints (watchpoints, etc) to
11721 a new script file named FILENAME. If FILTER is non-NULL, call it
11722 on each breakpoint and only include the ones for which it returns
11726 save_breakpoints (char *filename
, int from_tty
,
11727 int (*filter
) (const struct breakpoint
*))
11729 struct breakpoint
*tp
;
11732 struct cleanup
*cleanup
;
11733 struct ui_file
*fp
;
11734 int extra_trace_bits
= 0;
11736 if (filename
== 0 || *filename
== 0)
11737 error (_("Argument required (file name in which to save)"));
11739 /* See if we have anything to save. */
11740 ALL_BREAKPOINTS (tp
)
11742 /* Skip internal and momentary breakpoints. */
11743 if (!user_breakpoint_p (tp
))
11746 /* If we have a filter, only save the breakpoints it accepts. */
11747 if (filter
&& !filter (tp
))
11752 if (is_tracepoint (tp
))
11754 extra_trace_bits
= 1;
11756 /* We can stop searching. */
11763 warning (_("Nothing to save."));
11767 pathname
= tilde_expand (filename
);
11768 cleanup
= make_cleanup (xfree
, pathname
);
11769 fp
= gdb_fopen (pathname
, "w");
11771 error (_("Unable to open file '%s' for saving (%s)"),
11772 filename
, safe_strerror (errno
));
11773 make_cleanup_ui_file_delete (fp
);
11775 if (extra_trace_bits
)
11776 save_trace_state_variables (fp
);
11778 ALL_BREAKPOINTS (tp
)
11780 /* Skip internal and momentary breakpoints. */
11781 if (!user_breakpoint_p (tp
))
11784 /* If we have a filter, only save the breakpoints it accepts. */
11785 if (filter
&& !filter (tp
))
11788 if (tp
->ops
!= NULL
)
11789 (tp
->ops
->print_recreate
) (tp
, fp
);
11792 if (tp
->type
== bp_fast_tracepoint
)
11793 fprintf_unfiltered (fp
, "ftrace");
11794 if (tp
->type
== bp_static_tracepoint
)
11795 fprintf_unfiltered (fp
, "strace");
11796 else if (tp
->type
== bp_tracepoint
)
11797 fprintf_unfiltered (fp
, "trace");
11798 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11799 fprintf_unfiltered (fp
, "tbreak");
11800 else if (tp
->type
== bp_breakpoint
)
11801 fprintf_unfiltered (fp
, "break");
11802 else if (tp
->type
== bp_hardware_breakpoint
11803 && tp
->disposition
== disp_del
)
11804 fprintf_unfiltered (fp
, "thbreak");
11805 else if (tp
->type
== bp_hardware_breakpoint
)
11806 fprintf_unfiltered (fp
, "hbreak");
11807 else if (tp
->type
== bp_watchpoint
)
11808 fprintf_unfiltered (fp
, "watch");
11809 else if (tp
->type
== bp_hardware_watchpoint
)
11810 fprintf_unfiltered (fp
, "watch");
11811 else if (tp
->type
== bp_read_watchpoint
)
11812 fprintf_unfiltered (fp
, "rwatch");
11813 else if (tp
->type
== bp_access_watchpoint
)
11814 fprintf_unfiltered (fp
, "awatch");
11816 internal_error (__FILE__
, __LINE__
,
11817 _("unhandled breakpoint type %d"), (int) tp
->type
);
11819 if (tp
->exp_string
)
11820 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11821 else if (tp
->addr_string
)
11822 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11827 sprintf_vma (tmp
, tp
->loc
->address
);
11828 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11832 if (tp
->thread
!= -1)
11833 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
11836 fprintf_unfiltered (fp
, " task %d", tp
->task
);
11838 fprintf_unfiltered (fp
, "\n");
11840 /* Note, we can't rely on tp->number for anything, as we can't
11841 assume the recreated breakpoint numbers will match. Use $bpnum
11844 if (tp
->cond_string
)
11845 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
11847 if (tp
->ignore_count
)
11848 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
11850 if (tp
->pass_count
)
11851 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11855 volatile struct gdb_exception ex
;
11857 fprintf_unfiltered (fp
, " commands\n");
11859 ui_out_redirect (uiout
, fp
);
11860 TRY_CATCH (ex
, RETURN_MASK_ALL
)
11862 print_command_lines (uiout
, tp
->commands
->commands
, 2);
11864 ui_out_redirect (uiout
, NULL
);
11867 throw_exception (ex
);
11869 fprintf_unfiltered (fp
, " end\n");
11872 if (tp
->enable_state
== bp_disabled
)
11873 fprintf_unfiltered (fp
, "disable\n");
11875 /* If this is a multi-location breakpoint, check if the locations
11876 should be individually disabled. Watchpoint locations are
11877 special, and not user visible. */
11878 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
11880 struct bp_location
*loc
;
11883 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
11885 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
11889 if (extra_trace_bits
&& *default_collect
)
11890 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
11892 do_cleanups (cleanup
);
11894 printf_filtered (_("Saved to file '%s'.\n"), filename
);
11897 /* The `save breakpoints' command. */
11900 save_breakpoints_command (char *args
, int from_tty
)
11902 save_breakpoints (args
, from_tty
, NULL
);
11905 /* The `save tracepoints' command. */
11908 save_tracepoints_command (char *args
, int from_tty
)
11910 save_breakpoints (args
, from_tty
, is_tracepoint
);
11913 /* Create a vector of all tracepoints. */
11915 VEC(breakpoint_p
) *
11918 VEC(breakpoint_p
) *tp_vec
= 0;
11919 struct breakpoint
*tp
;
11921 ALL_TRACEPOINTS (tp
)
11923 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11930 /* This help string is used for the break, hbreak, tbreak and thbreak
11931 commands. It is defined as a macro to prevent duplication.
11932 COMMAND should be a string constant containing the name of the
11934 #define BREAK_ARGS_HELP(command) \
11935 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11936 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11937 If a line number is specified, break at start of code for that line.\n\
11938 If a function is specified, break at start of code for that function.\n\
11939 If an address is specified, break at that exact address.\n\
11940 With no LOCATION, uses current execution address of the selected\n\
11941 stack frame. This is useful for breaking on return to a stack frame.\n\
11943 THREADNUM is the number from \"info threads\".\n\
11944 CONDITION is a boolean expression.\n\
11946 Multiple breakpoints at one place are permitted, and useful if their\n\
11947 conditions are different.\n\
11949 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11951 /* List of subcommands for "catch". */
11952 static struct cmd_list_element
*catch_cmdlist
;
11954 /* List of subcommands for "tcatch". */
11955 static struct cmd_list_element
*tcatch_cmdlist
;
11957 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11958 lists, and pass some additional user data to the command function. */
11960 add_catch_command (char *name
, char *docstring
,
11961 void (*sfunc
) (char *args
, int from_tty
,
11962 struct cmd_list_element
*command
),
11963 char **(*completer
) (struct cmd_list_element
*cmd
,
11964 char *text
, char *word
),
11965 void *user_data_catch
,
11966 void *user_data_tcatch
)
11968 struct cmd_list_element
*command
;
11970 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11972 set_cmd_sfunc (command
, sfunc
);
11973 set_cmd_context (command
, user_data_catch
);
11974 set_cmd_completer (command
, completer
);
11976 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11978 set_cmd_sfunc (command
, sfunc
);
11979 set_cmd_context (command
, user_data_tcatch
);
11980 set_cmd_completer (command
, completer
);
11984 clear_syscall_counts (struct inferior
*inf
)
11986 inf
->total_syscalls_count
= 0;
11987 inf
->any_syscall_count
= 0;
11988 VEC_free (int, inf
->syscalls_counts
);
11992 save_command (char *arg
, int from_tty
)
11994 printf_unfiltered (_("\"save\" must be followed by "
11995 "the name of a save subcommand.\n"));
11996 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
11999 struct breakpoint
*
12000 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
12003 struct breakpoint
*b
, *b_tmp
;
12005 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12007 if ((*callback
) (b
, data
))
12015 _initialize_breakpoint (void)
12017 struct cmd_list_element
*c
;
12019 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
12020 observer_attach_inferior_exit (clear_syscall_counts
);
12021 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
12023 breakpoint_objfile_key
= register_objfile_data ();
12025 breakpoint_chain
= 0;
12026 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12027 before a breakpoint is set. */
12028 breakpoint_count
= 0;
12030 tracepoint_count
= 0;
12032 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
12033 Set ignore-count of breakpoint number N to COUNT.\n\
12034 Usage is `ignore N COUNT'."));
12036 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
12038 add_com ("commands", class_breakpoint
, commands_command
, _("\
12039 Set commands to be executed when a breakpoint is hit.\n\
12040 Give breakpoint number as argument after \"commands\".\n\
12041 With no argument, the targeted breakpoint is the last one set.\n\
12042 The commands themselves follow starting on the next line.\n\
12043 Type a line containing \"end\" to indicate the end of them.\n\
12044 Give \"silent\" as the first line to make the breakpoint silent;\n\
12045 then no output is printed when it is hit, except what the commands print."));
12047 add_com ("condition", class_breakpoint
, condition_command
, _("\
12048 Specify breakpoint number N to break only if COND is true.\n\
12049 Usage is `condition N COND', where N is an integer and COND is an\n\
12050 expression to be evaluated whenever breakpoint N is reached."));
12052 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
12053 Set a temporary breakpoint.\n\
12054 Like \"break\" except the breakpoint is only temporary,\n\
12055 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12056 by using \"enable delete\" on the breakpoint number.\n\
12058 BREAK_ARGS_HELP ("tbreak")));
12059 set_cmd_completer (c
, location_completer
);
12061 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
12062 Set a hardware assisted breakpoint.\n\
12063 Like \"break\" except the breakpoint requires hardware support,\n\
12064 some target hardware may not have this support.\n\
12066 BREAK_ARGS_HELP ("hbreak")));
12067 set_cmd_completer (c
, location_completer
);
12069 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
12070 Set a temporary hardware assisted breakpoint.\n\
12071 Like \"hbreak\" except the breakpoint is only temporary,\n\
12072 so it will be deleted when hit.\n\
12074 BREAK_ARGS_HELP ("thbreak")));
12075 set_cmd_completer (c
, location_completer
);
12077 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
12078 Enable some breakpoints.\n\
12079 Give breakpoint numbers (separated by spaces) as arguments.\n\
12080 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12081 This is used to cancel the effect of the \"disable\" command.\n\
12082 With a subcommand you can enable temporarily."),
12083 &enablelist
, "enable ", 1, &cmdlist
);
12085 add_com ("ab", class_breakpoint
, enable_command
, _("\
12086 Enable some breakpoints.\n\
12087 Give breakpoint numbers (separated by spaces) as arguments.\n\
12088 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12089 This is used to cancel the effect of the \"disable\" command.\n\
12090 With a subcommand you can enable temporarily."));
12092 add_com_alias ("en", "enable", class_breakpoint
, 1);
12094 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
12095 Enable some breakpoints.\n\
12096 Give breakpoint numbers (separated by spaces) as arguments.\n\
12097 This is used to cancel the effect of the \"disable\" command.\n\
12098 May be abbreviated to simply \"enable\".\n"),
12099 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
12101 add_cmd ("once", no_class
, enable_once_command
, _("\
12102 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12103 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12106 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12107 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12108 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12111 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12112 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12113 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12116 add_cmd ("once", no_class
, enable_once_command
, _("\
12117 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12118 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12121 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12122 Disable some breakpoints.\n\
12123 Arguments are breakpoint numbers with spaces in between.\n\
12124 To disable all breakpoints, give no argument.\n\
12125 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12126 &disablelist
, "disable ", 1, &cmdlist
);
12127 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12128 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12130 add_com ("sb", class_breakpoint
, disable_command
, _("\
12131 Disable some breakpoints.\n\
12132 Arguments are breakpoint numbers with spaces in between.\n\
12133 To disable all breakpoints, give no argument.\n\
12134 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12136 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12137 Disable some breakpoints.\n\
12138 Arguments are breakpoint numbers with spaces in between.\n\
12139 To disable all breakpoints, give no argument.\n\
12140 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12141 This command may be abbreviated \"disable\"."),
12144 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12145 Delete some breakpoints or auto-display expressions.\n\
12146 Arguments are breakpoint numbers with spaces in between.\n\
12147 To delete all breakpoints, give no argument.\n\
12149 Also a prefix command for deletion of other GDB objects.\n\
12150 The \"unset\" command is also an alias for \"delete\"."),
12151 &deletelist
, "delete ", 1, &cmdlist
);
12152 add_com_alias ("d", "delete", class_breakpoint
, 1);
12153 add_com_alias ("del", "delete", class_breakpoint
, 1);
12155 add_com ("db", class_breakpoint
, delete_command
, _("\
12156 Delete some breakpoints.\n\
12157 Arguments are breakpoint numbers with spaces in between.\n\
12158 To delete all breakpoints, give no argument.\n"));
12160 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12161 Delete some breakpoints or auto-display expressions.\n\
12162 Arguments are breakpoint numbers with spaces in between.\n\
12163 To delete all breakpoints, give no argument.\n\
12164 This command may be abbreviated \"delete\"."),
12167 add_com ("clear", class_breakpoint
, clear_command
, _("\
12168 Clear breakpoint at specified line or function.\n\
12169 Argument may be line number, function name, or \"*\" and an address.\n\
12170 If line number is specified, all breakpoints in that line are cleared.\n\
12171 If function is specified, breakpoints at beginning of function are cleared.\n\
12172 If an address is specified, breakpoints at that address are cleared.\n\
12174 With no argument, clears all breakpoints in the line that the selected frame\n\
12175 is executing in.\n\
12177 See also the \"delete\" command which clears breakpoints by number."));
12178 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12180 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12181 Set breakpoint at specified line or function.\n"
12182 BREAK_ARGS_HELP ("break")));
12183 set_cmd_completer (c
, location_completer
);
12185 add_com_alias ("b", "break", class_run
, 1);
12186 add_com_alias ("br", "break", class_run
, 1);
12187 add_com_alias ("bre", "break", class_run
, 1);
12188 add_com_alias ("brea", "break", class_run
, 1);
12191 add_com_alias ("ba", "break", class_breakpoint
, 1);
12195 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12196 Break in function/address or break at a line in the current file."),
12197 &stoplist
, "stop ", 1, &cmdlist
);
12198 add_cmd ("in", class_breakpoint
, stopin_command
,
12199 _("Break in function or address."), &stoplist
);
12200 add_cmd ("at", class_breakpoint
, stopat_command
,
12201 _("Break at a line in the current file."), &stoplist
);
12202 add_com ("status", class_info
, breakpoints_info
, _("\
12203 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12204 The \"Type\" column indicates one of:\n\
12205 \tbreakpoint - normal breakpoint\n\
12206 \twatchpoint - watchpoint\n\
12207 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12208 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12209 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12210 address and file/line number respectively.\n\
12212 Convenience variable \"$_\" and default examine address for \"x\"\n\
12213 are set to the address of the last breakpoint listed unless the command\n\
12214 is prefixed with \"server \".\n\n\
12215 Convenience variable \"$bpnum\" contains the number of the last\n\
12216 breakpoint set."));
12219 add_info ("breakpoints", breakpoints_info
, _("\
12220 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
12221 The \"Type\" column indicates one of:\n\
12222 \tbreakpoint - normal breakpoint\n\
12223 \twatchpoint - watchpoint\n\
12224 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12225 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12226 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12227 address and file/line number respectively.\n\
12229 Convenience variable \"$_\" and default examine address for \"x\"\n\
12230 are set to the address of the last breakpoint listed unless the command\n\
12231 is prefixed with \"server \".\n\n\
12232 Convenience variable \"$bpnum\" contains the number of the last\n\
12233 breakpoint set."));
12235 add_info_alias ("b", "breakpoints", 1);
12238 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12239 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12240 The \"Type\" column indicates one of:\n\
12241 \tbreakpoint - normal breakpoint\n\
12242 \twatchpoint - watchpoint\n\
12243 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12244 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12245 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12246 address and file/line number respectively.\n\
12248 Convenience variable \"$_\" and default examine address for \"x\"\n\
12249 are set to the address of the last breakpoint listed unless the command\n\
12250 is prefixed with \"server \".\n\n\
12251 Convenience variable \"$bpnum\" contains the number of the last\n\
12252 breakpoint set."));
12254 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12255 Status of all breakpoints, or breakpoint number NUMBER.\n\
12256 The \"Type\" column indicates one of:\n\
12257 \tbreakpoint - normal breakpoint\n\
12258 \twatchpoint - watchpoint\n\
12259 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12260 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12261 \tuntil - internal breakpoint used by the \"until\" command\n\
12262 \tfinish - internal breakpoint used by the \"finish\" command\n\
12263 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12264 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12265 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12266 address and file/line number respectively.\n\
12268 Convenience variable \"$_\" and default examine address for \"x\"\n\
12269 are set to the address of the last breakpoint listed unless the command\n\
12270 is prefixed with \"server \".\n\n\
12271 Convenience variable \"$bpnum\" contains the number of the last\n\
12273 &maintenanceinfolist
);
12275 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12276 Set catchpoints to catch events."),
12277 &catch_cmdlist
, "catch ",
12278 0/*allow-unknown*/, &cmdlist
);
12280 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12281 Set temporary catchpoints to catch events."),
12282 &tcatch_cmdlist
, "tcatch ",
12283 0/*allow-unknown*/, &cmdlist
);
12285 /* Add catch and tcatch sub-commands. */
12286 add_catch_command ("catch", _("\
12287 Catch an exception, when caught.\n\
12288 With an argument, catch only exceptions with the given name."),
12289 catch_catch_command
,
12293 add_catch_command ("throw", _("\
12294 Catch an exception, when thrown.\n\
12295 With an argument, catch only exceptions with the given name."),
12296 catch_throw_command
,
12300 add_catch_command ("fork", _("Catch calls to fork."),
12301 catch_fork_command_1
,
12303 (void *) (uintptr_t) catch_fork_permanent
,
12304 (void *) (uintptr_t) catch_fork_temporary
);
12305 add_catch_command ("vfork", _("Catch calls to vfork."),
12306 catch_fork_command_1
,
12308 (void *) (uintptr_t) catch_vfork_permanent
,
12309 (void *) (uintptr_t) catch_vfork_temporary
);
12310 add_catch_command ("exec", _("Catch calls to exec."),
12311 catch_exec_command_1
,
12315 add_catch_command ("syscall", _("\
12316 Catch system calls by their names and/or numbers.\n\
12317 Arguments say which system calls to catch. If no arguments\n\
12318 are given, every system call will be caught.\n\
12319 Arguments, if given, should be one or more system call names\n\
12320 (if your system supports that), or system call numbers."),
12321 catch_syscall_command_1
,
12322 catch_syscall_completer
,
12325 add_catch_command ("exception", _("\
12326 Catch Ada exceptions, when raised.\n\
12327 With an argument, catch only exceptions with the given name."),
12328 catch_ada_exception_command
,
12332 add_catch_command ("assert", _("\
12333 Catch failed Ada assertions, when raised.\n\
12334 With an argument, catch only exceptions with the given name."),
12335 catch_assert_command
,
12340 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12341 Set a watchpoint for an expression.\n\
12342 Usage: watch [-l|-location] EXPRESSION\n\
12343 A watchpoint stops execution of your program whenever the value of\n\
12344 an expression changes.\n\
12345 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12346 the memory to which it refers."));
12347 set_cmd_completer (c
, expression_completer
);
12349 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12350 Set a read watchpoint for an expression.\n\
12351 Usage: rwatch [-l|-location] EXPRESSION\n\
12352 A watchpoint stops execution of your program whenever the value of\n\
12353 an expression is read.\n\
12354 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12355 the memory to which it refers."));
12356 set_cmd_completer (c
, expression_completer
);
12358 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12359 Set a watchpoint for an expression.\n\
12360 Usage: awatch [-l|-location] EXPRESSION\n\
12361 A watchpoint stops execution of your program whenever the value of\n\
12362 an expression is either read or written.\n\
12363 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12364 the memory to which it refers."));
12365 set_cmd_completer (c
, expression_completer
);
12367 add_info ("watchpoints", watchpoints_info
, _("\
12368 Status of specified watchpoints (all watchpoints if no argument)."));
12370 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12371 respond to changes - contrary to the description. */
12372 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12373 &can_use_hw_watchpoints
, _("\
12374 Set debugger's willingness to use watchpoint hardware."), _("\
12375 Show debugger's willingness to use watchpoint hardware."), _("\
12376 If zero, gdb will not use hardware for new watchpoints, even if\n\
12377 such is available. (However, any hardware watchpoints that were\n\
12378 created before setting this to nonzero, will continue to use watchpoint\n\
12381 show_can_use_hw_watchpoints
,
12382 &setlist
, &showlist
);
12384 can_use_hw_watchpoints
= 1;
12386 /* Tracepoint manipulation commands. */
12388 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12389 Set a tracepoint at specified line or function.\n\
12391 BREAK_ARGS_HELP ("trace") "\n\
12392 Do \"help tracepoints\" for info on other tracepoint commands."));
12393 set_cmd_completer (c
, location_completer
);
12395 add_com_alias ("tp", "trace", class_alias
, 0);
12396 add_com_alias ("tr", "trace", class_alias
, 1);
12397 add_com_alias ("tra", "trace", class_alias
, 1);
12398 add_com_alias ("trac", "trace", class_alias
, 1);
12400 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12401 Set a fast tracepoint at specified line or function.\n\
12403 BREAK_ARGS_HELP ("ftrace") "\n\
12404 Do \"help tracepoints\" for info on other tracepoint commands."));
12405 set_cmd_completer (c
, location_completer
);
12407 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12408 Set a static tracepoint at specified line, function or marker.\n\
12410 strace [LOCATION] [if CONDITION]\n\
12411 LOCATION may be a line number, function name, \"*\" and an address,\n\
12412 or -m MARKER_ID.\n\
12413 If a line number is specified, probe the marker at start of code\n\
12414 for that line. If a function is specified, probe the marker at start\n\
12415 of code for that function. If an address is specified, probe the marker\n\
12416 at that exact address. If a marker id is specified, probe the marker\n\
12417 with that name. With no LOCATION, uses current execution address of\n\
12418 the selected stack frame.\n\
12419 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12420 This collects arbitrary user data passed in the probe point call to the\n\
12421 tracing library. You can inspect it when analyzing the trace buffer,\n\
12422 by printing the $_sdata variable like any other convenience variable.\n\
12424 CONDITION is a boolean expression.\n\
12426 Multiple tracepoints at one place are permitted, and useful if their\n\
12427 conditions are different.\n\
12429 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12430 Do \"help tracepoints\" for info on other tracepoint commands."));
12431 set_cmd_completer (c
, location_completer
);
12433 add_info ("tracepoints", tracepoints_info
, _("\
12434 Status of specified tracepoints (all tracepoints if no argument).\n\
12435 Convenience variable \"$tpnum\" contains the number of the\n\
12436 last tracepoint set."));
12438 add_info_alias ("tp", "tracepoints", 1);
12440 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12441 Delete specified tracepoints.\n\
12442 Arguments are tracepoint numbers, separated by spaces.\n\
12443 No argument means delete all tracepoints."),
12446 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12447 Disable specified tracepoints.\n\
12448 Arguments are tracepoint numbers, separated by spaces.\n\
12449 No argument means disable all tracepoints."),
12451 deprecate_cmd (c
, "disable");
12453 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12454 Enable specified tracepoints.\n\
12455 Arguments are tracepoint numbers, separated by spaces.\n\
12456 No argument means enable all tracepoints."),
12458 deprecate_cmd (c
, "enable");
12460 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12461 Set the passcount for a tracepoint.\n\
12462 The trace will end when the tracepoint has been passed 'count' times.\n\
12463 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12464 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12466 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12467 _("Save breakpoint definitions as a script."),
12468 &save_cmdlist
, "save ",
12469 0/*allow-unknown*/, &cmdlist
);
12471 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12472 Save current breakpoint definitions as a script.\n\
12473 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12474 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12475 session to restore them."),
12477 set_cmd_completer (c
, filename_completer
);
12479 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12480 Save current tracepoint definitions as a script.\n\
12481 Use the 'source' command in another debug session to restore them."),
12483 set_cmd_completer (c
, filename_completer
);
12485 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12486 deprecate_cmd (c
, "save tracepoints");
12488 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12489 Breakpoint specific settings\n\
12490 Configure various breakpoint-specific variables such as\n\
12491 pending breakpoint behavior"),
12492 &breakpoint_set_cmdlist
, "set breakpoint ",
12493 0/*allow-unknown*/, &setlist
);
12494 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12495 Breakpoint specific settings\n\
12496 Configure various breakpoint-specific variables such as\n\
12497 pending breakpoint behavior"),
12498 &breakpoint_show_cmdlist
, "show breakpoint ",
12499 0/*allow-unknown*/, &showlist
);
12501 add_setshow_auto_boolean_cmd ("pending", no_class
,
12502 &pending_break_support
, _("\
12503 Set debugger's behavior regarding pending breakpoints."), _("\
12504 Show debugger's behavior regarding pending breakpoints."), _("\
12505 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12506 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12507 an error. If auto, an unrecognized breakpoint location results in a\n\
12508 user-query to see if a pending breakpoint should be created."),
12510 show_pending_break_support
,
12511 &breakpoint_set_cmdlist
,
12512 &breakpoint_show_cmdlist
);
12514 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12516 add_setshow_boolean_cmd ("auto-hw", no_class
,
12517 &automatic_hardware_breakpoints
, _("\
12518 Set automatic usage of hardware breakpoints."), _("\
12519 Show automatic usage of hardware breakpoints."), _("\
12520 If set, the debugger will automatically use hardware breakpoints for\n\
12521 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12522 a warning will be emitted for such breakpoints."),
12524 show_automatic_hardware_breakpoints
,
12525 &breakpoint_set_cmdlist
,
12526 &breakpoint_show_cmdlist
);
12528 add_setshow_enum_cmd ("always-inserted", class_support
,
12529 always_inserted_enums
, &always_inserted_mode
, _("\
12530 Set mode for inserting breakpoints."), _("\
12531 Show mode for inserting breakpoints."), _("\
12532 When this mode is off, breakpoints are inserted in inferior when it is\n\
12533 resumed, and removed when execution stops. When this mode is on,\n\
12534 breakpoints are inserted immediately and removed only when the user\n\
12535 deletes the breakpoint. When this mode is auto (which is the default),\n\
12536 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12537 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12538 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12539 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12541 &show_always_inserted_mode
,
12542 &breakpoint_set_cmdlist
,
12543 &breakpoint_show_cmdlist
);
12545 automatic_hardware_breakpoints
= 1;
12547 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);