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
;
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 tmp_error_stream
= mem_fileopen ();
2007 make_cleanup_ui_file_delete (tmp_error_stream
);
2009 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2011 if (bl
->pspace
!= inf
->pspace
)
2017 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2020 do_cleanups (old_chain
);
2025 do_cleanups (old_chain
);
2029 static int internal_breakpoint_number
= -1;
2031 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2032 If INTERNAL is non-zero, the breakpoint number will be populated
2033 from internal_breakpoint_number and that variable decremented.
2034 Otherwis the breakpoint number will be populated from
2035 breakpoint_count and that value incremented. Internal breakpoints
2036 do not set the internal var bpnum. */
2038 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2041 b
->number
= internal_breakpoint_number
--;
2044 set_breakpoint_count (breakpoint_count
+ 1);
2045 b
->number
= breakpoint_count
;
2049 static struct breakpoint
*
2050 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2051 CORE_ADDR address
, enum bptype type
)
2053 struct symtab_and_line sal
;
2054 struct breakpoint
*b
;
2056 init_sal (&sal
); /* Initialize to zeroes. */
2059 sal
.section
= find_pc_overlay (sal
.pc
);
2060 sal
.pspace
= current_program_space
;
2062 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2063 b
->number
= internal_breakpoint_number
--;
2064 b
->disposition
= disp_donttouch
;
2069 static const char *const longjmp_names
[] =
2071 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2073 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2075 /* Per-objfile data private to breakpoint.c. */
2076 struct breakpoint_objfile_data
2078 /* Minimal symbol for "_ovly_debug_event" (if any). */
2079 struct minimal_symbol
*overlay_msym
;
2081 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2082 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2084 /* Minimal symbol for "std::terminate()" (if any). */
2085 struct minimal_symbol
*terminate_msym
;
2087 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2088 struct minimal_symbol
*exception_msym
;
2091 static const struct objfile_data
*breakpoint_objfile_key
;
2093 /* Minimal symbol not found sentinel. */
2094 static struct minimal_symbol msym_not_found
;
2096 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2099 msym_not_found_p (const struct minimal_symbol
*msym
)
2101 return msym
== &msym_not_found
;
2104 /* Return per-objfile data needed by breakpoint.c.
2105 Allocate the data if necessary. */
2107 static struct breakpoint_objfile_data
*
2108 get_breakpoint_objfile_data (struct objfile
*objfile
)
2110 struct breakpoint_objfile_data
*bp_objfile_data
;
2112 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2113 if (bp_objfile_data
== NULL
)
2115 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2116 sizeof (*bp_objfile_data
));
2118 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2119 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2121 return bp_objfile_data
;
2125 create_overlay_event_breakpoint (void)
2127 struct objfile
*objfile
;
2128 const char *const func_name
= "_ovly_debug_event";
2130 ALL_OBJFILES (objfile
)
2132 struct breakpoint
*b
;
2133 struct breakpoint_objfile_data
*bp_objfile_data
;
2136 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2138 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2141 if (bp_objfile_data
->overlay_msym
== NULL
)
2143 struct minimal_symbol
*m
;
2145 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2148 /* Avoid future lookups in this objfile. */
2149 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2152 bp_objfile_data
->overlay_msym
= m
;
2155 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2156 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2158 b
->addr_string
= xstrdup (func_name
);
2160 if (overlay_debugging
== ovly_auto
)
2162 b
->enable_state
= bp_enabled
;
2163 overlay_events_enabled
= 1;
2167 b
->enable_state
= bp_disabled
;
2168 overlay_events_enabled
= 0;
2171 update_global_location_list (1);
2175 create_longjmp_master_breakpoint (void)
2177 struct program_space
*pspace
;
2178 struct cleanup
*old_chain
;
2180 old_chain
= save_current_program_space ();
2182 ALL_PSPACES (pspace
)
2184 struct objfile
*objfile
;
2186 set_current_program_space (pspace
);
2188 ALL_OBJFILES (objfile
)
2191 struct gdbarch
*gdbarch
;
2192 struct breakpoint_objfile_data
*bp_objfile_data
;
2194 gdbarch
= get_objfile_arch (objfile
);
2195 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2198 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2200 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2202 struct breakpoint
*b
;
2203 const char *func_name
;
2206 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2209 func_name
= longjmp_names
[i
];
2210 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2212 struct minimal_symbol
*m
;
2214 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2217 /* Prevent future lookups in this objfile. */
2218 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2221 bp_objfile_data
->longjmp_msym
[i
] = m
;
2224 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2225 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
2226 b
->addr_string
= xstrdup (func_name
);
2227 b
->enable_state
= bp_disabled
;
2231 update_global_location_list (1);
2233 do_cleanups (old_chain
);
2236 /* Create a master std::terminate breakpoint. */
2238 create_std_terminate_master_breakpoint (void)
2240 struct program_space
*pspace
;
2241 struct cleanup
*old_chain
;
2242 const char *const func_name
= "std::terminate()";
2244 old_chain
= save_current_program_space ();
2246 ALL_PSPACES (pspace
)
2248 struct objfile
*objfile
;
2251 set_current_program_space (pspace
);
2253 ALL_OBJFILES (objfile
)
2255 struct breakpoint
*b
;
2256 struct breakpoint_objfile_data
*bp_objfile_data
;
2258 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2260 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2263 if (bp_objfile_data
->terminate_msym
== NULL
)
2265 struct minimal_symbol
*m
;
2267 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2268 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2269 && MSYMBOL_TYPE (m
) != mst_file_text
))
2271 /* Prevent future lookups in this objfile. */
2272 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2275 bp_objfile_data
->terminate_msym
= m
;
2278 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2279 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2280 bp_std_terminate_master
);
2281 b
->addr_string
= xstrdup (func_name
);
2282 b
->enable_state
= bp_disabled
;
2286 update_global_location_list (1);
2288 do_cleanups (old_chain
);
2291 /* Install a master breakpoint on the unwinder's debug hook. */
2294 create_exception_master_breakpoint (void)
2296 struct objfile
*objfile
;
2297 const char *const func_name
= "_Unwind_DebugHook";
2299 ALL_OBJFILES (objfile
)
2301 struct breakpoint
*b
;
2302 struct gdbarch
*gdbarch
;
2303 struct breakpoint_objfile_data
*bp_objfile_data
;
2306 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2308 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2311 gdbarch
= get_objfile_arch (objfile
);
2313 if (bp_objfile_data
->exception_msym
== NULL
)
2315 struct minimal_symbol
*debug_hook
;
2317 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2318 if (debug_hook
== NULL
)
2320 bp_objfile_data
->exception_msym
= &msym_not_found
;
2324 bp_objfile_data
->exception_msym
= debug_hook
;
2327 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2328 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2330 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2331 b
->addr_string
= xstrdup (func_name
);
2332 b
->enable_state
= bp_disabled
;
2335 update_global_location_list (1);
2339 update_breakpoints_after_exec (void)
2341 struct breakpoint
*b
, *b_tmp
;
2342 struct bp_location
*bploc
, **bplocp_tmp
;
2344 /* We're about to delete breakpoints from GDB's lists. If the
2345 INSERTED flag is true, GDB will try to lift the breakpoints by
2346 writing the breakpoints' "shadow contents" back into memory. The
2347 "shadow contents" are NOT valid after an exec, so GDB should not
2348 do that. Instead, the target is responsible from marking
2349 breakpoints out as soon as it detects an exec. We don't do that
2350 here instead, because there may be other attempts to delete
2351 breakpoints after detecting an exec and before reaching here. */
2352 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2353 if (bploc
->pspace
== current_program_space
)
2354 gdb_assert (!bploc
->inserted
);
2356 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2358 if (b
->pspace
!= current_program_space
)
2361 /* Solib breakpoints must be explicitly reset after an exec(). */
2362 if (b
->type
== bp_shlib_event
)
2364 delete_breakpoint (b
);
2368 /* JIT breakpoints must be explicitly reset after an exec(). */
2369 if (b
->type
== bp_jit_event
)
2371 delete_breakpoint (b
);
2375 /* Thread event breakpoints must be set anew after an exec(),
2376 as must overlay event and longjmp master breakpoints. */
2377 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2378 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2379 || b
->type
== bp_exception_master
)
2381 delete_breakpoint (b
);
2385 /* Step-resume breakpoints are meaningless after an exec(). */
2386 if (b
->type
== bp_step_resume
)
2388 delete_breakpoint (b
);
2392 /* Longjmp and longjmp-resume breakpoints are also meaningless
2394 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2395 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2397 delete_breakpoint (b
);
2401 if (b
->type
== bp_catchpoint
)
2403 /* For now, none of the bp_catchpoint breakpoints need to
2404 do anything at this point. In the future, if some of
2405 the catchpoints need to something, we will need to add
2406 a new method, and call this method from here. */
2410 /* bp_finish is a special case. The only way we ought to be able
2411 to see one of these when an exec() has happened, is if the user
2412 caught a vfork, and then said "finish". Ordinarily a finish just
2413 carries them to the call-site of the current callee, by setting
2414 a temporary bp there and resuming. But in this case, the finish
2415 will carry them entirely through the vfork & exec.
2417 We don't want to allow a bp_finish to remain inserted now. But
2418 we can't safely delete it, 'cause finish_command has a handle to
2419 the bp on a bpstat, and will later want to delete it. There's a
2420 chance (and I've seen it happen) that if we delete the bp_finish
2421 here, that its storage will get reused by the time finish_command
2422 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2423 We really must allow finish_command to delete a bp_finish.
2425 In the absense of a general solution for the "how do we know
2426 it's safe to delete something others may have handles to?"
2427 problem, what we'll do here is just uninsert the bp_finish, and
2428 let finish_command delete it.
2430 (We know the bp_finish is "doomed" in the sense that it's
2431 momentary, and will be deleted as soon as finish_command sees
2432 the inferior stopped. So it doesn't matter that the bp's
2433 address is probably bogus in the new a.out, unlike e.g., the
2434 solib breakpoints.) */
2436 if (b
->type
== bp_finish
)
2441 /* Without a symbolic address, we have little hope of the
2442 pre-exec() address meaning the same thing in the post-exec()
2444 if (b
->addr_string
== NULL
)
2446 delete_breakpoint (b
);
2450 /* FIXME what about longjmp breakpoints? Re-create them here? */
2451 create_overlay_event_breakpoint ();
2452 create_longjmp_master_breakpoint ();
2453 create_std_terminate_master_breakpoint ();
2454 create_exception_master_breakpoint ();
2458 detach_breakpoints (int pid
)
2460 struct bp_location
*bl
, **blp_tmp
;
2462 struct cleanup
*old_chain
= save_inferior_ptid ();
2463 struct inferior
*inf
= current_inferior ();
2465 if (pid
== PIDGET (inferior_ptid
))
2466 error (_("Cannot detach breakpoints of inferior_ptid"));
2468 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2469 inferior_ptid
= pid_to_ptid (pid
);
2470 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2472 if (bl
->pspace
!= inf
->pspace
)
2476 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2479 /* Detach single-step breakpoints as well. */
2480 detach_single_step_breakpoints ();
2482 do_cleanups (old_chain
);
2486 /* Remove the breakpoint location BL from the current address space.
2487 Note that this is used to detach breakpoints from a child fork.
2488 When we get here, the child isn't in the inferior list, and neither
2489 do we have objects to represent its address space --- we should
2490 *not* look at bl->pspace->aspace here. */
2493 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2497 /* BL is never in moribund_locations by our callers. */
2498 gdb_assert (bl
->owner
!= NULL
);
2500 if (bl
->owner
->enable_state
== bp_permanent
)
2501 /* Permanent breakpoints cannot be inserted or removed. */
2504 /* The type of none suggests that owner is actually deleted.
2505 This should not ever happen. */
2506 gdb_assert (bl
->owner
->type
!= bp_none
);
2508 if (bl
->loc_type
== bp_loc_software_breakpoint
2509 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2511 /* "Normal" instruction breakpoint: either the standard
2512 trap-instruction bp (bp_breakpoint), or a
2513 bp_hardware_breakpoint. */
2515 /* First check to see if we have to handle an overlay. */
2516 if (overlay_debugging
== ovly_off
2517 || bl
->section
== NULL
2518 || !(section_is_overlay (bl
->section
)))
2520 /* No overlay handling: just remove the breakpoint. */
2522 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2523 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2525 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2529 /* This breakpoint is in an overlay section.
2530 Did we set a breakpoint at the LMA? */
2531 if (!overlay_events_enabled
)
2533 /* Yes -- overlay event support is not active, so we
2534 should have set a breakpoint at the LMA. Remove it.
2536 /* Ignore any failures: if the LMA is in ROM, we will
2537 have already warned when we failed to insert it. */
2538 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2539 target_remove_hw_breakpoint (bl
->gdbarch
,
2540 &bl
->overlay_target_info
);
2542 target_remove_breakpoint (bl
->gdbarch
,
2543 &bl
->overlay_target_info
);
2545 /* Did we set a breakpoint at the VMA?
2546 If so, we will have marked the breakpoint 'inserted'. */
2549 /* Yes -- remove it. Previously we did not bother to
2550 remove the breakpoint if the section had been
2551 unmapped, but let's not rely on that being safe. We
2552 don't know what the overlay manager might do. */
2553 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2554 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2557 /* However, we should remove *software* breakpoints only
2558 if the section is still mapped, or else we overwrite
2559 wrong code with the saved shadow contents. */
2560 else if (section_is_mapped (bl
->section
))
2561 val
= target_remove_breakpoint (bl
->gdbarch
,
2568 /* No -- not inserted, so no need to remove. No error. */
2573 /* In some cases, we might not be able to remove a breakpoint
2574 in a shared library that has already been removed, but we
2575 have not yet processed the shlib unload event. */
2576 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2581 bl
->inserted
= (is
== mark_inserted
);
2583 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2585 gdb_assert (bl
->owner
->ops
!= NULL
2586 && bl
->owner
->ops
->remove_location
!= NULL
);
2588 bl
->inserted
= (is
== mark_inserted
);
2589 bl
->owner
->ops
->remove_location (bl
);
2591 /* Failure to remove any of the hardware watchpoints comes here. */
2592 if ((is
== mark_uninserted
) && (bl
->inserted
))
2593 warning (_("Could not remove hardware watchpoint %d."),
2596 else if (bl
->owner
->type
== bp_catchpoint
2597 && breakpoint_enabled (bl
->owner
)
2600 gdb_assert (bl
->owner
->ops
!= NULL
2601 && bl
->owner
->ops
->remove_location
!= NULL
);
2603 val
= bl
->owner
->ops
->remove_location (bl
);
2607 bl
->inserted
= (is
== mark_inserted
);
2614 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2617 struct cleanup
*old_chain
;
2619 /* BL is never in moribund_locations by our callers. */
2620 gdb_assert (bl
->owner
!= NULL
);
2622 if (bl
->owner
->enable_state
== bp_permanent
)
2623 /* Permanent breakpoints cannot be inserted or removed. */
2626 /* The type of none suggests that owner is actually deleted.
2627 This should not ever happen. */
2628 gdb_assert (bl
->owner
->type
!= bp_none
);
2630 old_chain
= save_current_space_and_thread ();
2632 switch_to_program_space_and_thread (bl
->pspace
);
2634 ret
= remove_breakpoint_1 (bl
, is
);
2636 do_cleanups (old_chain
);
2640 /* Clear the "inserted" flag in all breakpoints. */
2643 mark_breakpoints_out (void)
2645 struct bp_location
*bl
, **blp_tmp
;
2647 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2648 if (bl
->pspace
== current_program_space
)
2652 /* Clear the "inserted" flag in all breakpoints and delete any
2653 breakpoints which should go away between runs of the program.
2655 Plus other such housekeeping that has to be done for breakpoints
2658 Note: this function gets called at the end of a run (by
2659 generic_mourn_inferior) and when a run begins (by
2660 init_wait_for_inferior). */
2665 breakpoint_init_inferior (enum inf_context context
)
2667 struct breakpoint
*b
, *b_tmp
;
2668 struct bp_location
*bl
, **blp_tmp
;
2670 struct program_space
*pspace
= current_program_space
;
2672 /* If breakpoint locations are shared across processes, then there's
2674 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2677 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2679 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2680 if (bl
->pspace
== pspace
2681 && bl
->owner
->enable_state
!= bp_permanent
)
2685 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2687 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2694 /* If the call dummy breakpoint is at the entry point it will
2695 cause problems when the inferior is rerun, so we better get
2698 case bp_watchpoint_scope
:
2700 /* Also get rid of scope breakpoints. */
2702 case bp_shlib_event
:
2704 /* Also remove solib event breakpoints. Their addresses may
2705 have changed since the last time we ran the program.
2706 Actually we may now be debugging against different target;
2707 and so the solib backend that installed this breakpoint may
2708 not be used in by the target. E.g.,
2710 (gdb) file prog-linux
2711 (gdb) run # native linux target
2714 (gdb) file prog-win.exe
2715 (gdb) tar rem :9999 # remote Windows gdbserver.
2718 delete_breakpoint (b
);
2722 case bp_hardware_watchpoint
:
2723 case bp_read_watchpoint
:
2724 case bp_access_watchpoint
:
2726 /* Likewise for watchpoints on local expressions. */
2727 if (b
->exp_valid_block
!= NULL
)
2728 delete_breakpoint (b
);
2729 else if (context
== inf_starting
)
2731 /* Reset val field to force reread of starting value in
2732 insert_breakpoints. */
2734 value_free (b
->val
);
2744 /* Get rid of the moribund locations. */
2745 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2746 decref_bp_location (&bl
);
2747 VEC_free (bp_location_p
, moribund_locations
);
2750 /* These functions concern about actual breakpoints inserted in the
2751 target --- to e.g. check if we need to do decr_pc adjustment or if
2752 we need to hop over the bkpt --- so we check for address space
2753 match, not program space. */
2755 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2756 exists at PC. It returns ordinary_breakpoint_here if it's an
2757 ordinary breakpoint, or permanent_breakpoint_here if it's a
2758 permanent breakpoint.
2759 - When continuing from a location with an ordinary breakpoint, we
2760 actually single step once before calling insert_breakpoints.
2761 - When continuing from a localion with a permanent breakpoint, we
2762 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2763 the target, to advance the PC past the breakpoint. */
2765 enum breakpoint_here
2766 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2768 struct bp_location
*bl
, **blp_tmp
;
2769 int any_breakpoint_here
= 0;
2771 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2773 if (bl
->loc_type
!= bp_loc_software_breakpoint
2774 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2777 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2778 if ((breakpoint_enabled (bl
->owner
)
2779 || bl
->owner
->enable_state
== bp_permanent
)
2780 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2783 if (overlay_debugging
2784 && section_is_overlay (bl
->section
)
2785 && !section_is_mapped (bl
->section
))
2786 continue; /* unmapped overlay -- can't be a match */
2787 else if (bl
->owner
->enable_state
== bp_permanent
)
2788 return permanent_breakpoint_here
;
2790 any_breakpoint_here
= 1;
2794 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2797 /* Return true if there's a moribund breakpoint at PC. */
2800 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2802 struct bp_location
*loc
;
2805 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2806 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2813 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2814 inserted using regular breakpoint_chain / bp_location array
2815 mechanism. This does not check for single-step breakpoints, which
2816 are inserted and removed using direct target manipulation. */
2819 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2822 struct bp_location
*bl
, **blp_tmp
;
2824 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2826 if (bl
->loc_type
!= bp_loc_software_breakpoint
2827 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2831 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2834 if (overlay_debugging
2835 && section_is_overlay (bl
->section
)
2836 && !section_is_mapped (bl
->section
))
2837 continue; /* unmapped overlay -- can't be a match */
2845 /* Returns non-zero iff there's either regular breakpoint
2846 or a single step breakpoint inserted at PC. */
2849 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2851 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2854 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2860 /* This function returns non-zero iff there is a software breakpoint
2864 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2867 struct bp_location
*bl
, **blp_tmp
;
2869 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2871 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2875 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2878 if (overlay_debugging
2879 && section_is_overlay (bl
->section
)
2880 && !section_is_mapped (bl
->section
))
2881 continue; /* unmapped overlay -- can't be a match */
2887 /* Also check for software single-step breakpoints. */
2888 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2895 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2896 CORE_ADDR addr
, ULONGEST len
)
2898 struct breakpoint
*bpt
;
2900 ALL_BREAKPOINTS (bpt
)
2902 struct bp_location
*loc
;
2904 if (bpt
->type
!= bp_hardware_watchpoint
2905 && bpt
->type
!= bp_access_watchpoint
)
2908 if (!breakpoint_enabled (bpt
))
2911 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2912 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2916 /* Check for intersection. */
2917 l
= max (loc
->address
, addr
);
2918 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2926 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2927 PC is valid for process/thread PTID. */
2930 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2933 struct bp_location
*bl
, **blp_tmp
;
2934 /* The thread and task IDs associated to PTID, computed lazily. */
2938 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2940 if (bl
->loc_type
!= bp_loc_software_breakpoint
2941 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2944 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2945 if (!breakpoint_enabled (bl
->owner
)
2946 && bl
->owner
->enable_state
!= bp_permanent
)
2949 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2953 if (bl
->owner
->thread
!= -1)
2955 /* This is a thread-specific breakpoint. Check that ptid
2956 matches that thread. If thread hasn't been computed yet,
2957 it is now time to do so. */
2959 thread
= pid_to_thread_id (ptid
);
2960 if (bl
->owner
->thread
!= thread
)
2964 if (bl
->owner
->task
!= 0)
2966 /* This is a task-specific breakpoint. Check that ptid
2967 matches that task. If task hasn't been computed yet,
2968 it is now time to do so. */
2970 task
= ada_get_task_number (ptid
);
2971 if (bl
->owner
->task
!= task
)
2975 if (overlay_debugging
2976 && section_is_overlay (bl
->section
)
2977 && !section_is_mapped (bl
->section
))
2978 continue; /* unmapped overlay -- can't be a match */
2987 /* bpstat stuff. External routines' interfaces are documented
2991 ep_is_catchpoint (struct breakpoint
*ep
)
2993 return (ep
->type
== bp_catchpoint
);
2996 /* Frees any storage that is part of a bpstat. Does not walk the
3000 bpstat_free (bpstat bs
)
3002 if (bs
->old_val
!= NULL
)
3003 value_free (bs
->old_val
);
3004 decref_counted_command_line (&bs
->commands
);
3005 decref_bp_location (&bs
->bp_location_at
);
3009 /* Clear a bpstat so that it says we are not at any breakpoint.
3010 Also free any storage that is part of a bpstat. */
3013 bpstat_clear (bpstat
*bsp
)
3030 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3031 is part of the bpstat is copied as well. */
3034 bpstat_copy (bpstat bs
)
3038 bpstat retval
= NULL
;
3043 for (; bs
!= NULL
; bs
= bs
->next
)
3045 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3046 memcpy (tmp
, bs
, sizeof (*tmp
));
3047 incref_counted_command_line (tmp
->commands
);
3048 incref_bp_location (tmp
->bp_location_at
);
3049 if (bs
->old_val
!= NULL
)
3051 tmp
->old_val
= value_copy (bs
->old_val
);
3052 release_value (tmp
->old_val
);
3056 /* This is the first thing in the chain. */
3066 /* Find the bpstat associated with this breakpoint. */
3069 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3074 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3076 if (bsp
->breakpoint_at
== breakpoint
)
3082 /* Put in *NUM the breakpoint number of the first breakpoint we are
3083 stopped at. *BSP upon return is a bpstat which points to the
3084 remaining breakpoints stopped at (but which is not guaranteed to be
3085 good for anything but further calls to bpstat_num).
3087 Return 0 if passed a bpstat which does not indicate any breakpoints.
3088 Return -1 if stopped at a breakpoint that has been deleted since
3090 Return 1 otherwise. */
3093 bpstat_num (bpstat
*bsp
, int *num
)
3095 struct breakpoint
*b
;
3098 return 0; /* No more breakpoint values */
3100 /* We assume we'll never have several bpstats that correspond to a
3101 single breakpoint -- otherwise, this function might return the
3102 same number more than once and this will look ugly. */
3103 b
= (*bsp
)->breakpoint_at
;
3104 *bsp
= (*bsp
)->next
;
3106 return -1; /* breakpoint that's been deleted since */
3108 *num
= b
->number
; /* We have its number */
3112 /* Modify BS so that the actions will not be performed. */
3115 bpstat_clear_actions (bpstat bs
)
3117 for (; bs
!= NULL
; bs
= bs
->next
)
3119 decref_counted_command_line (&bs
->commands
);
3120 bs
->commands_left
= NULL
;
3121 if (bs
->old_val
!= NULL
)
3123 value_free (bs
->old_val
);
3129 /* Called when a command is about to proceed the inferior. */
3132 breakpoint_about_to_proceed (void)
3134 if (!ptid_equal (inferior_ptid
, null_ptid
))
3136 struct thread_info
*tp
= inferior_thread ();
3138 /* Allow inferior function calls in breakpoint commands to not
3139 interrupt the command list. When the call finishes
3140 successfully, the inferior will be standing at the same
3141 breakpoint as if nothing happened. */
3142 if (tp
->control
.in_infcall
)
3146 breakpoint_proceeded
= 1;
3149 /* Stub for cleaning up our state if we error-out of a breakpoint
3152 cleanup_executing_breakpoints (void *ignore
)
3154 executing_breakpoint_commands
= 0;
3157 /* Execute all the commands associated with all the breakpoints at
3158 this location. Any of these commands could cause the process to
3159 proceed beyond this point, etc. We look out for such changes by
3160 checking the global "breakpoint_proceeded" after each command.
3162 Returns true if a breakpoint command resumed the inferior. In that
3163 case, it is the caller's responsibility to recall it again with the
3164 bpstat of the current thread. */
3167 bpstat_do_actions_1 (bpstat
*bsp
)
3170 struct cleanup
*old_chain
;
3173 /* Avoid endless recursion if a `source' command is contained
3175 if (executing_breakpoint_commands
)
3178 executing_breakpoint_commands
= 1;
3179 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3181 /* This pointer will iterate over the list of bpstat's. */
3184 breakpoint_proceeded
= 0;
3185 for (; bs
!= NULL
; bs
= bs
->next
)
3187 struct counted_command_line
*ccmd
;
3188 struct command_line
*cmd
;
3189 struct cleanup
*this_cmd_tree_chain
;
3191 /* Take ownership of the BSP's command tree, if it has one.
3193 The command tree could legitimately contain commands like
3194 'step' and 'next', which call clear_proceed_status, which
3195 frees stop_bpstat's command tree. To make sure this doesn't
3196 free the tree we're executing out from under us, we need to
3197 take ownership of the tree ourselves. Since a given bpstat's
3198 commands are only executed once, we don't need to copy it; we
3199 can clear the pointer in the bpstat, and make sure we free
3200 the tree when we're done. */
3201 ccmd
= bs
->commands
;
3202 bs
->commands
= NULL
;
3204 = make_cleanup_decref_counted_command_line (&ccmd
);
3205 cmd
= bs
->commands_left
;
3206 bs
->commands_left
= NULL
;
3210 execute_control_command (cmd
);
3212 if (breakpoint_proceeded
)
3218 /* We can free this command tree now. */
3219 do_cleanups (this_cmd_tree_chain
);
3221 if (breakpoint_proceeded
)
3223 if (target_can_async_p ())
3224 /* If we are in async mode, then the target might be still
3225 running, not stopped at any breakpoint, so nothing for
3226 us to do here -- just return to the event loop. */
3229 /* In sync mode, when execute_control_command returns
3230 we're already standing on the next breakpoint.
3231 Breakpoint commands for that stop were not run, since
3232 execute_command does not run breakpoint commands --
3233 only command_line_handler does, but that one is not
3234 involved in execution of breakpoint commands. So, we
3235 can now execute breakpoint commands. It should be
3236 noted that making execute_command do bpstat actions is
3237 not an option -- in this case we'll have recursive
3238 invocation of bpstat for each breakpoint with a
3239 command, and can easily blow up GDB stack. Instead, we
3240 return true, which will trigger the caller to recall us
3241 with the new stop_bpstat. */
3246 do_cleanups (old_chain
);
3251 bpstat_do_actions (void)
3253 /* Do any commands attached to breakpoint we are stopped at. */
3254 while (!ptid_equal (inferior_ptid
, null_ptid
)
3255 && target_has_execution
3256 && !is_exited (inferior_ptid
)
3257 && !is_executing (inferior_ptid
))
3258 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3259 and only return when it is stopped at the next breakpoint, we
3260 keep doing breakpoint actions until it returns false to
3261 indicate the inferior was not resumed. */
3262 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3266 /* Print out the (old or new) value associated with a watchpoint. */
3269 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3272 fprintf_unfiltered (stream
, _("<unreadable>"));
3275 struct value_print_options opts
;
3276 get_user_print_options (&opts
);
3277 value_print (val
, stream
, &opts
);
3281 /* This is the normal print function for a bpstat. In the future,
3282 much of this logic could (should?) be moved to bpstat_stop_status,
3283 by having it set different print_it values.
3285 Current scheme: When we stop, bpstat_print() is called. It loops
3286 through the bpstat list of things causing this stop, calling the
3287 print_bp_stop_message function on each one. The behavior of the
3288 print_bp_stop_message function depends on the print_it field of
3289 bpstat. If such field so indicates, call this function here.
3291 Return values from this routine (ultimately used by bpstat_print()
3292 and normal_stop() to decide what to do):
3293 PRINT_NOTHING: Means we already printed all we needed to print,
3294 don't print anything else.
3295 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3296 that something to be followed by a location.
3297 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3298 that something to be followed by a location.
3299 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3302 static enum print_stop_action
3303 print_it_typical (bpstat bs
)
3305 struct cleanup
*old_chain
;
3306 struct breakpoint
*b
;
3307 const struct bp_location
*bl
;
3308 struct ui_stream
*stb
;
3310 enum print_stop_action result
;
3312 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3313 which has since been deleted. */
3314 if (bs
->breakpoint_at
== NULL
)
3315 return PRINT_UNKNOWN
;
3317 gdb_assert (bs
->bp_location_at
!= NULL
);
3319 bl
= bs
->bp_location_at
;
3320 b
= bs
->breakpoint_at
;
3322 stb
= ui_out_stream_new (uiout
);
3323 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3328 case bp_hardware_breakpoint
:
3329 bp_temp
= b
->disposition
== disp_del
;
3330 if (bl
->address
!= bl
->requested_address
)
3331 breakpoint_adjustment_warning (bl
->requested_address
,
3334 annotate_breakpoint (b
->number
);
3336 ui_out_text (uiout
, "\nTemporary breakpoint ");
3338 ui_out_text (uiout
, "\nBreakpoint ");
3339 if (ui_out_is_mi_like_p (uiout
))
3341 ui_out_field_string (uiout
, "reason",
3342 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3343 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3345 ui_out_field_int (uiout
, "bkptno", b
->number
);
3346 ui_out_text (uiout
, ", ");
3347 result
= PRINT_SRC_AND_LOC
;
3350 case bp_shlib_event
:
3351 /* Did we stop because the user set the stop_on_solib_events
3352 variable? (If so, we report this as a generic, "Stopped due
3353 to shlib event" message.) */
3354 printf_filtered (_("Stopped due to shared library event\n"));
3355 result
= PRINT_NOTHING
;
3358 case bp_thread_event
:
3359 /* Not sure how we will get here.
3360 GDB should not stop for these breakpoints. */
3361 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3362 result
= PRINT_NOTHING
;
3365 case bp_overlay_event
:
3366 /* By analogy with the thread event, GDB should not stop for these. */
3367 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3368 result
= PRINT_NOTHING
;
3371 case bp_longjmp_master
:
3372 /* These should never be enabled. */
3373 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3374 result
= PRINT_NOTHING
;
3377 case bp_std_terminate_master
:
3378 /* These should never be enabled. */
3379 printf_filtered (_("std::terminate Master Breakpoint: "
3380 "gdb should not stop!\n"));
3381 result
= PRINT_NOTHING
;
3384 case bp_exception_master
:
3385 /* These should never be enabled. */
3386 printf_filtered (_("Exception Master Breakpoint: "
3387 "gdb should not stop!\n"));
3388 result
= PRINT_NOTHING
;
3392 case bp_hardware_watchpoint
:
3393 annotate_watchpoint (b
->number
);
3394 if (ui_out_is_mi_like_p (uiout
))
3397 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3399 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3400 ui_out_text (uiout
, "\nOld value = ");
3401 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3402 ui_out_field_stream (uiout
, "old", stb
);
3403 ui_out_text (uiout
, "\nNew value = ");
3404 watchpoint_value_print (b
->val
, stb
->stream
);
3405 ui_out_field_stream (uiout
, "new", stb
);
3406 ui_out_text (uiout
, "\n");
3407 /* More than one watchpoint may have been triggered. */
3408 result
= PRINT_UNKNOWN
;
3411 case bp_read_watchpoint
:
3412 if (ui_out_is_mi_like_p (uiout
))
3415 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3417 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3418 ui_out_text (uiout
, "\nValue = ");
3419 watchpoint_value_print (b
->val
, stb
->stream
);
3420 ui_out_field_stream (uiout
, "value", stb
);
3421 ui_out_text (uiout
, "\n");
3422 result
= PRINT_UNKNOWN
;
3425 case bp_access_watchpoint
:
3426 if (bs
->old_val
!= NULL
)
3428 annotate_watchpoint (b
->number
);
3429 if (ui_out_is_mi_like_p (uiout
))
3432 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3434 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3435 ui_out_text (uiout
, "\nOld value = ");
3436 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3437 ui_out_field_stream (uiout
, "old", stb
);
3438 ui_out_text (uiout
, "\nNew value = ");
3443 if (ui_out_is_mi_like_p (uiout
))
3446 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3447 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3448 ui_out_text (uiout
, "\nValue = ");
3450 watchpoint_value_print (b
->val
, stb
->stream
);
3451 ui_out_field_stream (uiout
, "new", stb
);
3452 ui_out_text (uiout
, "\n");
3453 result
= PRINT_UNKNOWN
;
3456 /* Fall through, we don't deal with these types of breakpoints
3460 if (ui_out_is_mi_like_p (uiout
))
3463 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3464 result
= PRINT_UNKNOWN
;
3468 if (ui_out_is_mi_like_p (uiout
))
3471 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3472 result
= PRINT_UNKNOWN
;
3477 case bp_longjmp_resume
:
3479 case bp_exception_resume
:
3480 case bp_step_resume
:
3481 case bp_watchpoint_scope
:
3483 case bp_std_terminate
:
3485 case bp_fast_tracepoint
:
3488 result
= PRINT_UNKNOWN
;
3492 do_cleanups (old_chain
);
3496 /* Generic routine for printing messages indicating why we
3497 stopped. The behavior of this function depends on the value
3498 'print_it' in the bpstat structure. Under some circumstances we
3499 may decide not to print anything here and delegate the task to
3502 static enum print_stop_action
3503 print_bp_stop_message (bpstat bs
)
3505 switch (bs
->print_it
)
3508 /* Nothing should be printed for this bpstat entry. */
3509 return PRINT_UNKNOWN
;
3513 /* We still want to print the frame, but we already printed the
3514 relevant messages. */
3515 return PRINT_SRC_AND_LOC
;
3518 case print_it_normal
:
3520 struct breakpoint
*b
= bs
->breakpoint_at
;
3522 /* Normal case. Call the breakpoint's print_it method, or
3523 print_it_typical. */
3524 /* FIXME: how breakpoint can ever be NULL here? */
3525 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3526 return b
->ops
->print_it (b
);
3528 return print_it_typical (bs
);
3533 internal_error (__FILE__
, __LINE__
,
3534 _("print_bp_stop_message: unrecognized enum value"));
3539 /* Print a message indicating what happened. This is called from
3540 normal_stop(). The input to this routine is the head of the bpstat
3541 list - a list of the eventpoints that caused this stop. This
3542 routine calls the generic print routine for printing a message
3543 about reasons for stopping. This will print (for example) the
3544 "Breakpoint n," part of the output. The return value of this
3547 PRINT_UNKNOWN: Means we printed nothing.
3548 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3549 code to print the location. An example is
3550 "Breakpoint 1, " which should be followed by
3552 PRINT_SRC_ONLY: Means we printed something, but there is no need
3553 to also print the location part of the message.
3554 An example is the catch/throw messages, which
3555 don't require a location appended to the end.
3556 PRINT_NOTHING: We have done some printing and we don't need any
3557 further info to be printed. */
3559 enum print_stop_action
3560 bpstat_print (bpstat bs
)
3564 /* Maybe another breakpoint in the chain caused us to stop.
3565 (Currently all watchpoints go on the bpstat whether hit or not.
3566 That probably could (should) be changed, provided care is taken
3567 with respect to bpstat_explains_signal). */
3568 for (; bs
; bs
= bs
->next
)
3570 val
= print_bp_stop_message (bs
);
3571 if (val
== PRINT_SRC_ONLY
3572 || val
== PRINT_SRC_AND_LOC
3573 || val
== PRINT_NOTHING
)
3577 /* We reached the end of the chain, or we got a null BS to start
3578 with and nothing was printed. */
3579 return PRINT_UNKNOWN
;
3582 /* Evaluate the expression EXP and return 1 if value is zero. This is
3583 used inside a catch_errors to evaluate the breakpoint condition.
3584 The argument is a "struct expression *" that has been cast to a
3585 "char *" to make it pass through catch_errors. */
3588 breakpoint_cond_eval (void *exp
)
3590 struct value
*mark
= value_mark ();
3591 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3593 value_free_to_mark (mark
);
3597 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3600 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3604 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3606 **bs_link_pointer
= bs
;
3607 *bs_link_pointer
= &bs
->next
;
3608 bs
->breakpoint_at
= bl
->owner
;
3609 bs
->bp_location_at
= bl
;
3610 incref_bp_location (bl
);
3611 /* If the condition is false, etc., don't do the commands. */
3612 bs
->commands
= NULL
;
3613 bs
->commands_left
= NULL
;
3615 bs
->print_it
= print_it_normal
;
3619 /* The target has stopped with waitstatus WS. Check if any hardware
3620 watchpoints have triggered, according to the target. */
3623 watchpoints_triggered (struct target_waitstatus
*ws
)
3625 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3627 struct breakpoint
*b
;
3629 if (!stopped_by_watchpoint
)
3631 /* We were not stopped by a watchpoint. Mark all watchpoints
3632 as not triggered. */
3634 if (is_hardware_watchpoint (b
))
3635 b
->watchpoint_triggered
= watch_triggered_no
;
3640 if (!target_stopped_data_address (¤t_target
, &addr
))
3642 /* We were stopped by a watchpoint, but we don't know where.
3643 Mark all watchpoints as unknown. */
3645 if (is_hardware_watchpoint (b
))
3646 b
->watchpoint_triggered
= watch_triggered_unknown
;
3648 return stopped_by_watchpoint
;
3651 /* The target could report the data address. Mark watchpoints
3652 affected by this data address as triggered, and all others as not
3656 if (is_hardware_watchpoint (b
))
3658 struct bp_location
*loc
;
3660 b
->watchpoint_triggered
= watch_triggered_no
;
3661 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3662 /* Exact match not required. Within range is
3664 if (target_watchpoint_addr_within_range (¤t_target
,
3668 b
->watchpoint_triggered
= watch_triggered_yes
;
3676 /* Possible return values for watchpoint_check (this can't be an enum
3677 because of check_errors). */
3678 /* The watchpoint has been deleted. */
3679 #define WP_DELETED 1
3680 /* The value has changed. */
3681 #define WP_VALUE_CHANGED 2
3682 /* The value has not changed. */
3683 #define WP_VALUE_NOT_CHANGED 3
3684 /* Ignore this watchpoint, no matter if the value changed or not. */
3687 #define BP_TEMPFLAG 1
3688 #define BP_HARDWAREFLAG 2
3690 /* Evaluate watchpoint condition expression and check if its value
3693 P should be a pointer to struct bpstat, but is defined as a void *
3694 in order for this function to be usable with catch_errors. */
3697 watchpoint_check (void *p
)
3699 bpstat bs
= (bpstat
) p
;
3700 struct breakpoint
*b
;
3701 struct frame_info
*fr
;
3702 int within_current_scope
;
3704 /* BS is built from an existing struct breakpoint. */
3705 gdb_assert (bs
->breakpoint_at
!= NULL
);
3706 b
= bs
->breakpoint_at
;
3708 /* If this is a local watchpoint, we only want to check if the
3709 watchpoint frame is in scope if the current thread is the thread
3710 that was used to create the watchpoint. */
3711 if (!watchpoint_in_thread_scope (b
))
3714 if (b
->exp_valid_block
== NULL
)
3715 within_current_scope
= 1;
3718 struct frame_info
*frame
= get_current_frame ();
3719 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3720 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3722 /* in_function_epilogue_p() returns a non-zero value if we're
3723 still in the function but the stack frame has already been
3724 invalidated. Since we can't rely on the values of local
3725 variables after the stack has been destroyed, we are treating
3726 the watchpoint in that state as `not changed' without further
3727 checking. Don't mark watchpoints as changed if the current
3728 frame is in an epilogue - even if they are in some other
3729 frame, our view of the stack is likely to be wrong and
3730 frame_find_by_id could error out. */
3731 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3734 fr
= frame_find_by_id (b
->watchpoint_frame
);
3735 within_current_scope
= (fr
!= NULL
);
3737 /* If we've gotten confused in the unwinder, we might have
3738 returned a frame that can't describe this variable. */
3739 if (within_current_scope
)
3741 struct symbol
*function
;
3743 function
= get_frame_function (fr
);
3744 if (function
== NULL
3745 || !contained_in (b
->exp_valid_block
,
3746 SYMBOL_BLOCK_VALUE (function
)))
3747 within_current_scope
= 0;
3750 if (within_current_scope
)
3751 /* If we end up stopping, the current frame will get selected
3752 in normal_stop. So this call to select_frame won't affect
3757 if (within_current_scope
)
3759 /* We use value_{,free_to_}mark because it could be a *long*
3760 time before we return to the command level and call
3761 free_all_values. We can't call free_all_values because we
3762 might be in the middle of evaluating a function call. */
3765 struct value
*mark
= value_mark ();
3766 struct value
*new_val
;
3768 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3770 /* We use value_equal_contents instead of value_equal because
3771 the latter coerces an array to a pointer, thus comparing just
3772 the address of the array instead of its contents. This is
3773 not what we want. */
3774 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3775 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3777 if (new_val
!= NULL
)
3779 release_value (new_val
);
3780 value_free_to_mark (mark
);
3782 bs
->old_val
= b
->val
;
3785 return WP_VALUE_CHANGED
;
3789 /* Nothing changed. */
3790 value_free_to_mark (mark
);
3791 return WP_VALUE_NOT_CHANGED
;
3796 /* This seems like the only logical thing to do because
3797 if we temporarily ignored the watchpoint, then when
3798 we reenter the block in which it is valid it contains
3799 garbage (in the case of a function, it may have two
3800 garbage values, one before and one after the prologue).
3801 So we can't even detect the first assignment to it and
3802 watch after that (since the garbage may or may not equal
3803 the first value assigned). */
3804 /* We print all the stop information in print_it_typical(), but
3805 in this case, by the time we call print_it_typical() this bp
3806 will be deleted already. So we have no choice but print the
3807 information here. */
3808 if (ui_out_is_mi_like_p (uiout
))
3810 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3811 ui_out_text (uiout
, "\nWatchpoint ");
3812 ui_out_field_int (uiout
, "wpnum", b
->number
);
3814 " deleted because the program has left the block in\n\
3815 which its expression is valid.\n");
3817 if (b
->related_breakpoint
)
3819 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3820 b
->related_breakpoint
->related_breakpoint
= NULL
;
3821 b
->related_breakpoint
= NULL
;
3823 b
->disposition
= disp_del_at_next_stop
;
3829 /* Return true if it looks like target has stopped due to hitting
3830 breakpoint location BL. This function does not check if we
3831 should stop, only if BL explains the stop. */
3833 bpstat_check_location (const struct bp_location
*bl
,
3834 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3836 struct breakpoint
*b
= bl
->owner
;
3838 /* BL is from existing struct breakpoint. */
3839 gdb_assert (b
!= NULL
);
3841 /* By definition, the inferior does not report stops at
3843 if (is_tracepoint (b
))
3846 if (!is_watchpoint (b
)
3847 && b
->type
!= bp_hardware_breakpoint
3848 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3850 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3853 if (overlay_debugging
/* unmapped overlay section */
3854 && section_is_overlay (bl
->section
)
3855 && !section_is_mapped (bl
->section
))
3859 /* Continuable hardware watchpoints are treated as non-existent if the
3860 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3861 some data address). Otherwise gdb won't stop on a break instruction
3862 in the code (not from a breakpoint) when a hardware watchpoint has
3863 been defined. Also skip watchpoints which we know did not trigger
3864 (did not match the data address). */
3866 if (is_hardware_watchpoint (b
)
3867 && b
->watchpoint_triggered
== watch_triggered_no
)
3870 if (b
->type
== bp_hardware_breakpoint
)
3872 if (bl
->address
!= bp_addr
)
3874 if (overlay_debugging
/* unmapped overlay section */
3875 && section_is_overlay (bl
->section
)
3876 && !section_is_mapped (bl
->section
))
3880 if (b
->type
== bp_catchpoint
)
3882 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3883 if (!b
->ops
->breakpoint_hit (b
))
3890 /* If BS refers to a watchpoint, determine if the watched values
3891 has actually changed, and we should stop. If not, set BS->stop
3894 bpstat_check_watchpoint (bpstat bs
)
3896 const struct bp_location
*bl
;
3897 struct breakpoint
*b
;
3899 /* BS is built for existing struct breakpoint. */
3900 bl
= bs
->bp_location_at
;
3901 gdb_assert (bl
!= NULL
);
3902 b
= bs
->breakpoint_at
;
3903 gdb_assert (b
!= NULL
);
3905 if (is_watchpoint (b
))
3907 int must_check_value
= 0;
3909 if (b
->type
== bp_watchpoint
)
3910 /* For a software watchpoint, we must always check the
3912 must_check_value
= 1;
3913 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3914 /* We have a hardware watchpoint (read, write, or access)
3915 and the target earlier reported an address watched by
3917 must_check_value
= 1;
3918 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3919 && b
->type
== bp_hardware_watchpoint
)
3920 /* We were stopped by a hardware watchpoint, but the target could
3921 not report the data address. We must check the watchpoint's
3922 value. Access and read watchpoints are out of luck; without
3923 a data address, we can't figure it out. */
3924 must_check_value
= 1;
3926 if (must_check_value
)
3929 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3931 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3932 int e
= catch_errors (watchpoint_check
, bs
, message
,
3934 do_cleanups (cleanups
);
3938 /* We've already printed what needs to be printed. */
3939 bs
->print_it
= print_it_done
;
3943 bs
->print_it
= print_it_noop
;
3946 case WP_VALUE_CHANGED
:
3947 if (b
->type
== bp_read_watchpoint
)
3949 /* There are two cases to consider here:
3951 1. We're watching the triggered memory for reads.
3952 In that case, trust the target, and always report
3953 the watchpoint hit to the user. Even though
3954 reads don't cause value changes, the value may
3955 have changed since the last time it was read, and
3956 since we're not trapping writes, we will not see
3957 those, and as such we should ignore our notion of
3960 2. We're watching the triggered memory for both
3961 reads and writes. There are two ways this may
3964 2.1. This is a target that can't break on data
3965 reads only, but can break on accesses (reads or
3966 writes), such as e.g., x86. We detect this case
3967 at the time we try to insert read watchpoints.
3969 2.2. Otherwise, the target supports read
3970 watchpoints, but, the user set an access or write
3971 watchpoint watching the same memory as this read
3974 If we're watching memory writes as well as reads,
3975 ignore watchpoint hits when we find that the
3976 value hasn't changed, as reads don't cause
3977 changes. This still gives false positives when
3978 the program writes the same value to memory as
3979 what there was already in memory (we will confuse
3980 it for a read), but it's much better than
3983 int other_write_watchpoint
= 0;
3985 if (bl
->watchpoint_type
== hw_read
)
3987 struct breakpoint
*other_b
;
3989 ALL_BREAKPOINTS (other_b
)
3990 if ((other_b
->type
== bp_hardware_watchpoint
3991 || other_b
->type
== bp_access_watchpoint
)
3992 && (other_b
->watchpoint_triggered
3993 == watch_triggered_yes
))
3995 other_write_watchpoint
= 1;
4000 if (other_write_watchpoint
4001 || bl
->watchpoint_type
== hw_access
)
4003 /* We're watching the same memory for writes,
4004 and the value changed since the last time we
4005 updated it, so this trap must be for a write.
4007 bs
->print_it
= print_it_noop
;
4012 case WP_VALUE_NOT_CHANGED
:
4013 if (b
->type
== bp_hardware_watchpoint
4014 || b
->type
== bp_watchpoint
)
4016 /* Don't stop: write watchpoints shouldn't fire if
4017 the value hasn't changed. */
4018 bs
->print_it
= print_it_noop
;
4026 /* Error from catch_errors. */
4027 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
4028 if (b
->related_breakpoint
)
4029 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
4030 b
->disposition
= disp_del_at_next_stop
;
4031 /* We've already printed what needs to be printed. */
4032 bs
->print_it
= print_it_done
;
4036 else /* must_check_value == 0 */
4038 /* This is a case where some watchpoint(s) triggered, but
4039 not at the address of this watchpoint, or else no
4040 watchpoint triggered after all. So don't print
4041 anything for this watchpoint. */
4042 bs
->print_it
= print_it_noop
;
4049 /* Check conditions (condition proper, frame, thread and ignore count)
4050 of breakpoint referred to by BS. If we should not stop for this
4051 breakpoint, set BS->stop to 0. */
4054 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4056 int thread_id
= pid_to_thread_id (ptid
);
4057 const struct bp_location
*bl
;
4058 struct breakpoint
*b
;
4060 /* BS is built for existing struct breakpoint. */
4061 bl
= bs
->bp_location_at
;
4062 gdb_assert (bl
!= NULL
);
4063 b
= bs
->breakpoint_at
;
4064 gdb_assert (b
!= NULL
);
4066 if (frame_id_p (b
->frame_id
)
4067 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4071 int value_is_zero
= 0;
4072 struct expression
*cond
;
4074 if (is_watchpoint (b
))
4079 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4081 int within_current_scope
= 1;
4083 /* We use value_mark and value_free_to_mark because it could
4084 be a long time before we return to the command level and
4085 call free_all_values. We can't call free_all_values
4086 because we might be in the middle of evaluating a
4088 struct value
*mark
= value_mark ();
4090 /* Need to select the frame, with all that implies so that
4091 the conditions will have the right context. Because we
4092 use the frame, we will not see an inlined function's
4093 variables when we arrive at a breakpoint at the start
4094 of the inlined function; the current frame will be the
4096 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4097 select_frame (get_current_frame ());
4100 struct frame_info
*frame
;
4102 /* For local watchpoint expressions, which particular
4103 instance of a local is being watched matters, so we
4104 keep track of the frame to evaluate the expression
4105 in. To evaluate the condition however, it doesn't
4106 really matter which instantiation of the function
4107 where the condition makes sense triggers the
4108 watchpoint. This allows an expression like "watch
4109 global if q > 10" set in `func', catch writes to
4110 global on all threads that call `func', or catch
4111 writes on all recursive calls of `func' by a single
4112 thread. We simply always evaluate the condition in
4113 the innermost frame that's executing where it makes
4114 sense to evaluate the condition. It seems
4116 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4118 select_frame (frame
);
4120 within_current_scope
= 0;
4122 if (within_current_scope
)
4124 = catch_errors (breakpoint_cond_eval
, cond
,
4125 "Error in testing breakpoint condition:\n",
4129 warning (_("Watchpoint condition cannot be tested "
4130 "in the current scope"));
4131 /* If we failed to set the right context for this
4132 watchpoint, unconditionally report it. */
4135 /* FIXME-someday, should give breakpoint #. */
4136 value_free_to_mark (mark
);
4139 if (cond
&& value_is_zero
)
4143 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4147 else if (b
->ignore_count
> 0)
4150 annotate_ignore_count_change ();
4152 /* Increase the hit count even though we don't stop. */
4159 /* Get a bpstat associated with having just stopped at address
4160 BP_ADDR in thread PTID.
4162 Determine whether we stopped at a breakpoint, etc, or whether we
4163 don't understand this stop. Result is a chain of bpstat's such
4166 if we don't understand the stop, the result is a null pointer.
4168 if we understand why we stopped, the result is not null.
4170 Each element of the chain refers to a particular breakpoint or
4171 watchpoint at which we have stopped. (We may have stopped for
4172 several reasons concurrently.)
4174 Each element of the chain has valid next, breakpoint_at,
4175 commands, FIXME??? fields. */
4178 bpstat_stop_status (struct address_space
*aspace
,
4179 CORE_ADDR bp_addr
, ptid_t ptid
)
4181 struct breakpoint
*b
= NULL
;
4182 struct bp_location
*bl
;
4183 struct bp_location
*loc
;
4184 /* First item of allocated bpstat's. */
4185 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4186 /* Pointer to the last thing in the chain currently. */
4189 int need_remove_insert
;
4192 /* First, build the bpstat chain with locations that explain a
4193 target stop, while being careful to not set the target running,
4194 as that may invalidate locations (in particular watchpoint
4195 locations are recreated). Resuming will happen here with
4196 breakpoint conditions or watchpoint expressions that include
4197 inferior function calls. */
4201 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4204 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4206 /* For hardware watchpoints, we look only at the first
4207 location. The watchpoint_check function will work on the
4208 entire expression, not the individual locations. For
4209 read watchpoints, the watchpoints_triggered function has
4210 checked all locations already. */
4211 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4214 if (bl
->shlib_disabled
)
4217 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4220 /* Come here if it's a watchpoint, or if the break address
4223 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4226 /* Assume we stop. Should we find a watchpoint that is not
4227 actually triggered, or if the condition of the breakpoint
4228 evaluates as false, we'll reset 'stop' to 0. */
4232 /* If this is a scope breakpoint, mark the associated
4233 watchpoint as triggered so that we will handle the
4234 out-of-scope event. We'll get to the watchpoint next
4236 if (b
->type
== bp_watchpoint_scope
)
4237 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4241 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4243 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4246 bs
= bpstat_alloc (loc
, &bs_link
);
4247 /* For hits of moribund locations, we should just proceed. */
4250 bs
->print_it
= print_it_noop
;
4254 /* Now go through the locations that caused the target to stop, and
4255 check whether we're interested in reporting this stop to higher
4256 layers, or whether we should resume the target transparently. */
4260 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4265 bpstat_check_watchpoint (bs
);
4269 b
= bs
->breakpoint_at
;
4271 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4272 || b
->type
== bp_longjmp_master
4273 || b
->type
== bp_std_terminate_master
4274 || b
->type
== bp_exception_master
)
4275 /* We do not stop for these. */
4278 bpstat_check_breakpoint_conditions (bs
, ptid
);
4284 /* We will stop here. */
4285 if (b
->disposition
== disp_disable
)
4287 if (b
->enable_state
!= bp_permanent
)
4288 b
->enable_state
= bp_disabled
;
4293 bs
->commands
= b
->commands
;
4294 incref_counted_command_line (bs
->commands
);
4295 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4296 if (bs
->commands_left
4297 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4300 bs
->commands_left
->line
) == 0)))
4302 bs
->commands_left
= bs
->commands_left
->next
;
4307 /* Print nothing for this entry if we dont stop or dont print. */
4308 if (bs
->stop
== 0 || bs
->print
== 0)
4309 bs
->print_it
= print_it_noop
;
4312 /* If we aren't stopping, the value of some hardware watchpoint may
4313 not have changed, but the intermediate memory locations we are
4314 watching may have. Don't bother if we're stopping; this will get
4316 need_remove_insert
= 0;
4317 if (! bpstat_causes_stop (bs_head
))
4318 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4320 && bs
->breakpoint_at
4321 && is_hardware_watchpoint (bs
->breakpoint_at
))
4323 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4324 need_remove_insert
= 1;
4327 if (need_remove_insert
)
4328 update_global_location_list (1);
4329 else if (removed_any
)
4330 update_global_location_list (0);
4336 handle_jit_event (void)
4338 struct frame_info
*frame
;
4339 struct gdbarch
*gdbarch
;
4341 /* Switch terminal for any messages produced by
4342 breakpoint_re_set. */
4343 target_terminal_ours_for_output ();
4345 frame
= get_current_frame ();
4346 gdbarch
= get_frame_arch (frame
);
4348 jit_event_handler (gdbarch
);
4350 target_terminal_inferior ();
4353 /* Prepare WHAT final decision for infrun. */
4355 /* Decide what infrun needs to do with this bpstat. */
4358 bpstat_what (bpstat bs
)
4360 struct bpstat_what retval
;
4361 /* We need to defer calling `solib_add', as adding new symbols
4362 resets breakpoints, which in turn deletes breakpoint locations,
4363 and hence may clear unprocessed entries in the BS chain. */
4364 int shlib_event
= 0;
4367 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4368 retval
.call_dummy
= STOP_NONE
;
4369 retval
.is_longjmp
= 0;
4371 for (; bs
!= NULL
; bs
= bs
->next
)
4373 /* Extract this BS's action. After processing each BS, we check
4374 if its action overrides all we've seem so far. */
4375 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4378 if (bs
->breakpoint_at
== NULL
)
4380 /* I suspect this can happen if it was a momentary
4381 breakpoint which has since been deleted. */
4384 else if (bs
->breakpoint_at
== NULL
)
4387 bptype
= bs
->breakpoint_at
->type
;
4394 case bp_hardware_breakpoint
:
4400 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4402 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4405 this_action
= BPSTAT_WHAT_SINGLE
;
4408 case bp_hardware_watchpoint
:
4409 case bp_read_watchpoint
:
4410 case bp_access_watchpoint
:
4414 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4416 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4420 /* There was a watchpoint, but we're not stopping.
4421 This requires no further action. */
4426 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4427 retval
.is_longjmp
= bptype
== bp_longjmp
;
4429 case bp_longjmp_resume
:
4430 case bp_exception_resume
:
4431 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4432 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4434 case bp_step_resume
:
4436 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4439 /* It is for the wrong frame. */
4440 this_action
= BPSTAT_WHAT_SINGLE
;
4443 case bp_watchpoint_scope
:
4444 case bp_thread_event
:
4445 case bp_overlay_event
:
4446 case bp_longjmp_master
:
4447 case bp_std_terminate_master
:
4448 case bp_exception_master
:
4449 this_action
= BPSTAT_WHAT_SINGLE
;
4455 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4457 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4461 /* There was a catchpoint, but we're not stopping.
4462 This requires no further action. */
4465 case bp_shlib_event
:
4468 /* If requested, stop when the dynamic linker notifies GDB
4469 of events. This allows the user to get control and place
4470 breakpoints in initializer routines for dynamically
4471 loaded objects (among other things). */
4472 if (stop_on_solib_events
)
4473 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4475 this_action
= BPSTAT_WHAT_SINGLE
;
4479 this_action
= BPSTAT_WHAT_SINGLE
;
4482 /* Make sure the action is stop (silent or noisy),
4483 so infrun.c pops the dummy frame. */
4484 retval
.call_dummy
= STOP_STACK_DUMMY
;
4485 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4487 case bp_std_terminate
:
4488 /* Make sure the action is stop (silent or noisy),
4489 so infrun.c pops the dummy frame. */
4490 retval
.call_dummy
= STOP_STD_TERMINATE
;
4491 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4494 case bp_fast_tracepoint
:
4495 case bp_static_tracepoint
:
4496 /* Tracepoint hits should not be reported back to GDB, and
4497 if one got through somehow, it should have been filtered
4499 internal_error (__FILE__
, __LINE__
,
4500 _("bpstat_what: tracepoint encountered"));
4502 internal_error (__FILE__
, __LINE__
,
4503 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4506 retval
.main_action
= max (retval
.main_action
, this_action
);
4512 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4514 /* Check for any newly added shared libraries if we're supposed
4515 to be adding them automatically. */
4517 /* Switch terminal for any messages produced by
4518 breakpoint_re_set. */
4519 target_terminal_ours_for_output ();
4522 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4524 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4527 target_terminal_inferior ();
4533 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4535 handle_jit_event ();
4541 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4542 without hardware support). This isn't related to a specific bpstat,
4543 just to things like whether watchpoints are set. */
4546 bpstat_should_step (void)
4548 struct breakpoint
*b
;
4551 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4557 bpstat_causes_stop (bpstat bs
)
4559 for (; bs
!= NULL
; bs
= bs
->next
)
4568 /* Compute a string of spaces suitable to indent the next line
4569 so it starts at the position corresponding to the table column
4570 named COL_NAME in the currently active table of UIOUT. */
4573 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4575 static char wrap_indent
[80];
4576 int i
, total_width
, width
, align
;
4580 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4582 if (strcmp (text
, col_name
) == 0)
4584 gdb_assert (total_width
< sizeof wrap_indent
);
4585 memset (wrap_indent
, ' ', total_width
);
4586 wrap_indent
[total_width
] = 0;
4591 total_width
+= width
+ 1;
4597 /* Print the LOC location out of the list of B->LOC locations. */
4600 print_breakpoint_location (struct breakpoint
*b
,
4601 struct bp_location
*loc
)
4603 struct cleanup
*old_chain
= save_current_program_space ();
4605 if (loc
!= NULL
&& loc
->shlib_disabled
)
4609 set_current_program_space (loc
->pspace
);
4611 if (b
->source_file
&& loc
)
4614 = find_pc_sect_function (loc
->address
, loc
->section
);
4617 ui_out_text (uiout
, "in ");
4618 ui_out_field_string (uiout
, "func",
4619 SYMBOL_PRINT_NAME (sym
));
4620 ui_out_text (uiout
, " ");
4621 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4622 ui_out_text (uiout
, "at ");
4624 ui_out_field_string (uiout
, "file", b
->source_file
);
4625 ui_out_text (uiout
, ":");
4627 if (ui_out_is_mi_like_p (uiout
))
4629 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4630 char *fullname
= symtab_to_fullname (sal
.symtab
);
4633 ui_out_field_string (uiout
, "fullname", fullname
);
4636 ui_out_field_int (uiout
, "line", b
->line_number
);
4640 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4641 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4643 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4645 ui_out_field_stream (uiout
, "at", stb
);
4647 do_cleanups (stb_chain
);
4650 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4652 do_cleanups (old_chain
);
4656 bptype_string (enum bptype type
)
4658 struct ep_type_description
4663 static struct ep_type_description bptypes
[] =
4665 {bp_none
, "?deleted?"},
4666 {bp_breakpoint
, "breakpoint"},
4667 {bp_hardware_breakpoint
, "hw breakpoint"},
4668 {bp_until
, "until"},
4669 {bp_finish
, "finish"},
4670 {bp_watchpoint
, "watchpoint"},
4671 {bp_hardware_watchpoint
, "hw watchpoint"},
4672 {bp_read_watchpoint
, "read watchpoint"},
4673 {bp_access_watchpoint
, "acc watchpoint"},
4674 {bp_longjmp
, "longjmp"},
4675 {bp_longjmp_resume
, "longjmp resume"},
4676 {bp_exception
, "exception"},
4677 {bp_exception_resume
, "exception resume"},
4678 {bp_step_resume
, "step resume"},
4679 {bp_watchpoint_scope
, "watchpoint scope"},
4680 {bp_call_dummy
, "call dummy"},
4681 {bp_std_terminate
, "std::terminate"},
4682 {bp_shlib_event
, "shlib events"},
4683 {bp_thread_event
, "thread events"},
4684 {bp_overlay_event
, "overlay events"},
4685 {bp_longjmp_master
, "longjmp master"},
4686 {bp_std_terminate_master
, "std::terminate master"},
4687 {bp_exception_master
, "exception master"},
4688 {bp_catchpoint
, "catchpoint"},
4689 {bp_tracepoint
, "tracepoint"},
4690 {bp_fast_tracepoint
, "fast tracepoint"},
4691 {bp_static_tracepoint
, "static tracepoint"},
4692 {bp_jit_event
, "jit events"},
4695 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4696 || ((int) type
!= bptypes
[(int) type
].type
))
4697 internal_error (__FILE__
, __LINE__
,
4698 _("bptypes table does not describe type #%d."),
4701 return bptypes
[(int) type
].description
;
4704 /* Print B to gdb_stdout. */
4707 print_one_breakpoint_location (struct breakpoint
*b
,
4708 struct bp_location
*loc
,
4710 struct bp_location
**last_loc
,
4713 struct command_line
*l
;
4714 static char bpenables
[] = "nynny";
4715 struct cleanup
*bkpt_chain
;
4717 int header_of_multiple
= 0;
4718 int part_of_multiple
= (loc
!= NULL
);
4719 struct value_print_options opts
;
4721 get_user_print_options (&opts
);
4723 gdb_assert (!loc
|| loc_number
!= 0);
4724 /* See comment in print_one_breakpoint concerning treatment of
4725 breakpoints with single disabled location. */
4728 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4729 header_of_multiple
= 1;
4734 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4738 if (part_of_multiple
)
4741 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4742 ui_out_field_string (uiout
, "number", formatted
);
4747 ui_out_field_int (uiout
, "number", b
->number
);
4752 if (part_of_multiple
)
4753 ui_out_field_skip (uiout
, "type");
4755 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4759 if (part_of_multiple
)
4760 ui_out_field_skip (uiout
, "disp");
4762 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4767 if (part_of_multiple
)
4768 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4770 ui_out_field_fmt (uiout
, "enabled", "%c",
4771 bpenables
[(int) b
->enable_state
]);
4772 ui_out_spaces (uiout
, 2);
4776 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4778 /* Although the print_one can possibly print all locations,
4779 calling it here is not likely to get any nice result. So,
4780 make sure there's just one location. */
4781 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4782 b
->ops
->print_one (b
, last_loc
);
4788 internal_error (__FILE__
, __LINE__
,
4789 _("print_one_breakpoint: bp_none encountered\n"));
4793 case bp_hardware_watchpoint
:
4794 case bp_read_watchpoint
:
4795 case bp_access_watchpoint
:
4796 /* Field 4, the address, is omitted (which makes the columns
4797 not line up too nicely with the headers, but the effect
4798 is relatively readable). */
4799 if (opts
.addressprint
)
4800 ui_out_field_skip (uiout
, "addr");
4802 ui_out_field_string (uiout
, "what", b
->exp_string
);
4806 case bp_hardware_breakpoint
:
4810 case bp_longjmp_resume
:
4812 case bp_exception_resume
:
4813 case bp_step_resume
:
4814 case bp_watchpoint_scope
:
4816 case bp_std_terminate
:
4817 case bp_shlib_event
:
4818 case bp_thread_event
:
4819 case bp_overlay_event
:
4820 case bp_longjmp_master
:
4821 case bp_std_terminate_master
:
4822 case bp_exception_master
:
4824 case bp_fast_tracepoint
:
4825 case bp_static_tracepoint
:
4827 if (opts
.addressprint
)
4830 if (header_of_multiple
)
4831 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4832 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4833 ui_out_field_string (uiout
, "addr", "<PENDING>");
4835 ui_out_field_core_addr (uiout
, "addr",
4836 loc
->gdbarch
, loc
->address
);
4839 if (!header_of_multiple
)
4840 print_breakpoint_location (b
, loc
);
4847 /* For backward compatibility, don't display inferiors unless there
4850 && !header_of_multiple
4852 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4853 && (number_of_program_spaces () > 1
4854 || number_of_inferiors () > 1)
4855 /* LOC is for existing B, it cannot be in
4856 moribund_locations and thus having NULL OWNER. */
4857 && loc
->owner
->type
!= bp_catchpoint
)))
4859 struct inferior
*inf
;
4862 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4864 if (inf
->pspace
== loc
->pspace
)
4869 ui_out_text (uiout
, " inf ");
4872 ui_out_text (uiout
, ", ");
4873 ui_out_text (uiout
, plongest (inf
->num
));
4878 if (!part_of_multiple
)
4880 if (b
->thread
!= -1)
4882 /* FIXME: This seems to be redundant and lost here; see the
4883 "stop only in" line a little further down. */
4884 ui_out_text (uiout
, " thread ");
4885 ui_out_field_int (uiout
, "thread", b
->thread
);
4887 else if (b
->task
!= 0)
4889 ui_out_text (uiout
, " task ");
4890 ui_out_field_int (uiout
, "task", b
->task
);
4894 ui_out_text (uiout
, "\n");
4896 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4898 gdb_assert (b
->type
== bp_static_tracepoint
);
4900 ui_out_text (uiout
, "\tmarker id is ");
4901 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4902 b
->static_trace_marker_id
);
4903 ui_out_text (uiout
, "\n");
4906 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4909 ui_out_text (uiout
, "\tstop only in stack frame at ");
4910 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4912 ui_out_field_core_addr (uiout
, "frame",
4913 b
->gdbarch
, b
->frame_id
.stack_addr
);
4914 ui_out_text (uiout
, "\n");
4917 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4919 /* We do not print the condition for Ada exception catchpoints
4920 because the condition is an internal implementation detail
4921 that we do not want to expose to the user. */
4923 if (is_tracepoint (b
))
4924 ui_out_text (uiout
, "\ttrace only if ");
4926 ui_out_text (uiout
, "\tstop only if ");
4927 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4928 ui_out_text (uiout
, "\n");
4931 if (!part_of_multiple
&& b
->thread
!= -1)
4933 /* FIXME should make an annotation for this. */
4934 ui_out_text (uiout
, "\tstop only in thread ");
4935 ui_out_field_int (uiout
, "thread", b
->thread
);
4936 ui_out_text (uiout
, "\n");
4939 if (!part_of_multiple
&& b
->hit_count
)
4941 /* FIXME should make an annotation for this. */
4942 if (ep_is_catchpoint (b
))
4943 ui_out_text (uiout
, "\tcatchpoint");
4945 ui_out_text (uiout
, "\tbreakpoint");
4946 ui_out_text (uiout
, " already hit ");
4947 ui_out_field_int (uiout
, "times", b
->hit_count
);
4948 if (b
->hit_count
== 1)
4949 ui_out_text (uiout
, " time\n");
4951 ui_out_text (uiout
, " times\n");
4954 /* Output the count also if it is zero, but only if this is mi.
4955 FIXME: Should have a better test for this. */
4956 if (ui_out_is_mi_like_p (uiout
))
4957 if (!part_of_multiple
&& b
->hit_count
== 0)
4958 ui_out_field_int (uiout
, "times", b
->hit_count
);
4960 if (!part_of_multiple
&& b
->ignore_count
)
4963 ui_out_text (uiout
, "\tignore next ");
4964 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4965 ui_out_text (uiout
, " hits\n");
4968 l
= b
->commands
? b
->commands
->commands
: NULL
;
4969 if (!part_of_multiple
&& l
)
4971 struct cleanup
*script_chain
;
4974 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4975 print_command_lines (uiout
, l
, 4);
4976 do_cleanups (script_chain
);
4979 if (!part_of_multiple
&& b
->pass_count
)
4981 annotate_field (10);
4982 ui_out_text (uiout
, "\tpass count ");
4983 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4984 ui_out_text (uiout
, " \n");
4987 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4990 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4991 else if (b
->exp_string
)
4992 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4995 do_cleanups (bkpt_chain
);
4999 print_one_breakpoint (struct breakpoint
*b
,
5000 struct bp_location
**last_loc
,
5003 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5005 /* If this breakpoint has custom print function,
5006 it's already printed. Otherwise, print individual
5007 locations, if any. */
5008 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5010 /* If breakpoint has a single location that is disabled, we
5011 print it as if it had several locations, since otherwise it's
5012 hard to represent "breakpoint enabled, location disabled"
5015 Note that while hardware watchpoints have several locations
5016 internally, that's not a property exposed to user. */
5018 && !is_hardware_watchpoint (b
)
5019 && (b
->loc
->next
|| !b
->loc
->enabled
)
5020 && !ui_out_is_mi_like_p (uiout
))
5022 struct bp_location
*loc
;
5024 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5025 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5031 breakpoint_address_bits (struct breakpoint
*b
)
5033 int print_address_bits
= 0;
5034 struct bp_location
*loc
;
5036 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5040 /* Software watchpoints that aren't watching memory don't have
5041 an address to print. */
5042 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5045 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5046 if (addr_bit
> print_address_bits
)
5047 print_address_bits
= addr_bit
;
5050 return print_address_bits
;
5053 struct captured_breakpoint_query_args
5059 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5061 struct captured_breakpoint_query_args
*args
= data
;
5062 struct breakpoint
*b
;
5063 struct bp_location
*dummy_loc
= NULL
;
5067 if (args
->bnum
== b
->number
)
5069 print_one_breakpoint (b
, &dummy_loc
, 0);
5077 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5078 char **error_message
)
5080 struct captured_breakpoint_query_args args
;
5083 /* For the moment we don't trust print_one_breakpoint() to not throw
5085 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5086 error_message
, RETURN_MASK_ALL
) < 0)
5092 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5093 catchpoints, et.al.). */
5096 user_settable_breakpoint (const struct breakpoint
*b
)
5098 return (b
->type
== bp_breakpoint
5099 || b
->type
== bp_catchpoint
5100 || b
->type
== bp_hardware_breakpoint
5101 || is_tracepoint (b
)
5102 || is_watchpoint (b
));
5105 /* Return true if this breakpoint was set by the user, false if it is
5106 internal or momentary. */
5109 user_breakpoint_p (struct breakpoint
*b
)
5111 return user_settable_breakpoint (b
) && b
->number
> 0;
5114 /* Print information on user settable breakpoint (watchpoint, etc)
5115 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5116 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5117 FILTER is non-NULL, call it on each breakpoint and only include the
5118 ones for which it returns non-zero. Return the total number of
5119 breakpoints listed. */
5122 breakpoint_1 (char *args
, int allflag
,
5123 int (*filter
) (const struct breakpoint
*))
5125 struct breakpoint
*b
;
5126 struct bp_location
*last_loc
= NULL
;
5127 int nr_printable_breakpoints
;
5128 struct cleanup
*bkpttbl_chain
;
5129 struct value_print_options opts
;
5130 int print_address_bits
= 0;
5131 int print_type_col_width
= 14;
5133 get_user_print_options (&opts
);
5135 /* Compute the number of rows in the table, as well as the size
5136 required for address fields. */
5137 nr_printable_breakpoints
= 0;
5140 /* If we have a filter, only list the breakpoints it accepts. */
5141 if (filter
&& !filter (b
))
5144 /* If we have an "args" string, it is a list of breakpoints to
5145 accept. Skip the others. */
5146 if (args
!= NULL
&& *args
!= '\0')
5148 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5150 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5154 if (allflag
|| user_breakpoint_p (b
))
5156 int addr_bit
, type_len
;
5158 addr_bit
= breakpoint_address_bits (b
);
5159 if (addr_bit
> print_address_bits
)
5160 print_address_bits
= addr_bit
;
5162 type_len
= strlen (bptype_string (b
->type
));
5163 if (type_len
> print_type_col_width
)
5164 print_type_col_width
= type_len
;
5166 nr_printable_breakpoints
++;
5170 if (opts
.addressprint
)
5172 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5173 nr_printable_breakpoints
,
5177 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5178 nr_printable_breakpoints
,
5181 if (nr_printable_breakpoints
> 0)
5182 annotate_breakpoints_headers ();
5183 if (nr_printable_breakpoints
> 0)
5185 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5186 if (nr_printable_breakpoints
> 0)
5188 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5189 "type", "Type"); /* 2 */
5190 if (nr_printable_breakpoints
> 0)
5192 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5193 if (nr_printable_breakpoints
> 0)
5195 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5196 if (opts
.addressprint
)
5198 if (nr_printable_breakpoints
> 0)
5200 if (print_address_bits
<= 32)
5201 ui_out_table_header (uiout
, 10, ui_left
,
5202 "addr", "Address"); /* 5 */
5204 ui_out_table_header (uiout
, 18, ui_left
,
5205 "addr", "Address"); /* 5 */
5207 if (nr_printable_breakpoints
> 0)
5209 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5210 ui_out_table_body (uiout
);
5211 if (nr_printable_breakpoints
> 0)
5212 annotate_breakpoints_table ();
5217 /* If we have a filter, only list the breakpoints it accepts. */
5218 if (filter
&& !filter (b
))
5221 /* If we have an "args" string, it is a list of breakpoints to
5222 accept. Skip the others. */
5224 if (args
!= NULL
&& *args
!= '\0')
5226 if (allflag
) /* maintenance info breakpoint */
5228 if (parse_and_eval_long (args
) != b
->number
)
5231 else /* all others */
5233 if (!number_is_in_list (args
, b
->number
))
5237 /* We only print out user settable breakpoints unless the
5239 if (allflag
|| user_breakpoint_p (b
))
5240 print_one_breakpoint (b
, &last_loc
, allflag
);
5243 do_cleanups (bkpttbl_chain
);
5245 if (nr_printable_breakpoints
== 0)
5247 /* If there's a filter, let the caller decide how to report
5251 if (args
== NULL
|| *args
== '\0')
5252 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5254 ui_out_message (uiout
, 0,
5255 "No breakpoint or watchpoint matching '%s'.\n",
5261 if (last_loc
&& !server_command
)
5262 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5265 /* FIXME? Should this be moved up so that it is only called when
5266 there have been breakpoints? */
5267 annotate_breakpoints_table_end ();
5269 return nr_printable_breakpoints
;
5272 /* Display the value of default-collect in a way that is generally
5273 compatible with the breakpoint list. */
5276 default_collect_info (void)
5278 /* If it has no value (which is frequently the case), say nothing; a
5279 message like "No default-collect." gets in user's face when it's
5281 if (!*default_collect
)
5284 /* The following phrase lines up nicely with per-tracepoint collect
5286 ui_out_text (uiout
, "default collect ");
5287 ui_out_field_string (uiout
, "default-collect", default_collect
);
5288 ui_out_text (uiout
, " \n");
5292 breakpoints_info (char *args
, int from_tty
)
5294 breakpoint_1 (args
, 0, NULL
);
5296 default_collect_info ();
5300 watchpoints_info (char *args
, int from_tty
)
5302 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5304 if (num_printed
== 0)
5306 if (args
== NULL
|| *args
== '\0')
5307 ui_out_message (uiout
, 0, "No watchpoints.\n");
5309 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5314 maintenance_info_breakpoints (char *args
, int from_tty
)
5316 breakpoint_1 (args
, 1, NULL
);
5318 default_collect_info ();
5322 breakpoint_has_pc (struct breakpoint
*b
,
5323 struct program_space
*pspace
,
5324 CORE_ADDR pc
, struct obj_section
*section
)
5326 struct bp_location
*bl
= b
->loc
;
5328 for (; bl
; bl
= bl
->next
)
5330 if (bl
->pspace
== pspace
5331 && bl
->address
== pc
5332 && (!overlay_debugging
|| bl
->section
== section
))
5338 /* Print a message describing any breakpoints set at PC. This
5339 concerns with logical breakpoints, so we match program spaces, not
5343 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5344 struct program_space
*pspace
, CORE_ADDR pc
,
5345 struct obj_section
*section
, int thread
)
5348 struct breakpoint
*b
;
5351 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5355 printf_filtered (_("Note: breakpoint "));
5356 else /* if (others == ???) */
5357 printf_filtered (_("Note: breakpoints "));
5359 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5362 printf_filtered ("%d", b
->number
);
5363 if (b
->thread
== -1 && thread
!= -1)
5364 printf_filtered (" (all threads)");
5365 else if (b
->thread
!= -1)
5366 printf_filtered (" (thread %d)", b
->thread
);
5367 printf_filtered ("%s%s ",
5368 ((b
->enable_state
== bp_disabled
5369 || b
->enable_state
== bp_call_disabled
5370 || b
->enable_state
== bp_startup_disabled
)
5372 : b
->enable_state
== bp_permanent
5376 : ((others
== 1) ? " and" : ""));
5378 printf_filtered (_("also set at pc "));
5379 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5380 printf_filtered (".\n");
5384 /* Set the default place to put a breakpoint
5385 for the `break' command with no arguments. */
5388 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5389 CORE_ADDR addr
, struct symtab
*symtab
,
5392 default_breakpoint_valid
= valid
;
5393 default_breakpoint_pspace
= pspace
;
5394 default_breakpoint_address
= addr
;
5395 default_breakpoint_symtab
= symtab
;
5396 default_breakpoint_line
= line
;
5399 /* Return true iff it is meaningful to use the address member of
5400 BPT. For some breakpoint types, the address member is irrelevant
5401 and it makes no sense to attempt to compare it to other addresses
5402 (or use it for any other purpose either).
5404 More specifically, each of the following breakpoint types will
5405 always have a zero valued address and we don't want to mark
5406 breakpoints of any of these types to be a duplicate of an actual
5407 breakpoint at address zero:
5415 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5417 enum bptype type
= bpt
->type
;
5419 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5422 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5423 true if LOC1 and LOC2 represent the same watchpoint location. */
5426 watchpoint_locations_match (struct bp_location
*loc1
,
5427 struct bp_location
*loc2
)
5429 /* Both of them must not be in moribund_locations. */
5430 gdb_assert (loc1
->owner
!= NULL
);
5431 gdb_assert (loc2
->owner
!= NULL
);
5433 /* If the target can evaluate the condition expression in hardware,
5434 then we we need to insert both watchpoints even if they are at
5435 the same place. Otherwise the watchpoint will only trigger when
5436 the condition of whichever watchpoint was inserted evaluates to
5437 true, not giving a chance for GDB to check the condition of the
5438 other watchpoint. */
5439 if ((loc1
->owner
->cond_exp
5440 && target_can_accel_watchpoint_condition (loc1
->address
,
5442 loc1
->watchpoint_type
,
5443 loc1
->owner
->cond_exp
))
5444 || (loc2
->owner
->cond_exp
5445 && target_can_accel_watchpoint_condition (loc2
->address
,
5447 loc2
->watchpoint_type
,
5448 loc2
->owner
->cond_exp
)))
5451 /* Note that this checks the owner's type, not the location's. In
5452 case the target does not support read watchpoints, but does
5453 support access watchpoints, we'll have bp_read_watchpoint
5454 watchpoints with hw_access locations. Those should be considered
5455 duplicates of hw_read locations. The hw_read locations will
5456 become hw_access locations later. */
5457 return (loc1
->owner
->type
== loc2
->owner
->type
5458 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5459 && loc1
->address
== loc2
->address
5460 && loc1
->length
== loc2
->length
);
5463 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5464 same breakpoint location. In most targets, this can only be true
5465 if ASPACE1 matches ASPACE2. On targets that have global
5466 breakpoints, the address space doesn't really matter. */
5469 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5470 struct address_space
*aspace2
, CORE_ADDR addr2
)
5472 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5473 || aspace1
== aspace2
)
5477 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5478 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5479 represent the same location. */
5482 breakpoint_locations_match (struct bp_location
*loc1
,
5483 struct bp_location
*loc2
)
5485 int hw_point1
, hw_point2
;
5487 /* Both of them must not be in moribund_locations. */
5488 gdb_assert (loc1
->owner
!= NULL
);
5489 gdb_assert (loc2
->owner
!= NULL
);
5491 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5492 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5494 if (hw_point1
!= hw_point2
)
5497 return watchpoint_locations_match (loc1
, loc2
);
5499 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5500 loc2
->pspace
->aspace
, loc2
->address
);
5504 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5505 int bnum
, int have_bnum
)
5507 /* The longest string possibly returned by hex_string_custom
5508 is 50 chars. These must be at least that big for safety. */
5512 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5513 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5515 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5516 bnum
, astr1
, astr2
);
5518 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5521 /* Adjust a breakpoint's address to account for architectural
5522 constraints on breakpoint placement. Return the adjusted address.
5523 Note: Very few targets require this kind of adjustment. For most
5524 targets, this function is simply the identity function. */
5527 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5528 CORE_ADDR bpaddr
, enum bptype bptype
)
5530 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5532 /* Very few targets need any kind of breakpoint adjustment. */
5535 else if (bptype
== bp_watchpoint
5536 || bptype
== bp_hardware_watchpoint
5537 || bptype
== bp_read_watchpoint
5538 || bptype
== bp_access_watchpoint
5539 || bptype
== bp_catchpoint
)
5541 /* Watchpoints and the various bp_catch_* eventpoints should not
5542 have their addresses modified. */
5547 CORE_ADDR adjusted_bpaddr
;
5549 /* Some targets have architectural constraints on the placement
5550 of breakpoint instructions. Obtain the adjusted address. */
5551 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5553 /* An adjusted breakpoint address can significantly alter
5554 a user's expectations. Print a warning if an adjustment
5556 if (adjusted_bpaddr
!= bpaddr
)
5557 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5559 return adjusted_bpaddr
;
5563 /* Allocate a struct bp_location. */
5565 static struct bp_location
*
5566 allocate_bp_location (struct breakpoint
*bpt
)
5568 struct bp_location
*loc
;
5570 loc
= xmalloc (sizeof (struct bp_location
));
5571 memset (loc
, 0, sizeof (*loc
));
5575 loc
->shlib_disabled
= 0;
5584 case bp_longjmp_resume
:
5586 case bp_exception_resume
:
5587 case bp_step_resume
:
5588 case bp_watchpoint_scope
:
5590 case bp_std_terminate
:
5591 case bp_shlib_event
:
5592 case bp_thread_event
:
5593 case bp_overlay_event
:
5595 case bp_longjmp_master
:
5596 case bp_std_terminate_master
:
5597 case bp_exception_master
:
5598 loc
->loc_type
= bp_loc_software_breakpoint
;
5600 case bp_hardware_breakpoint
:
5601 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5603 case bp_hardware_watchpoint
:
5604 case bp_read_watchpoint
:
5605 case bp_access_watchpoint
:
5606 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5611 case bp_fast_tracepoint
:
5612 case bp_static_tracepoint
:
5613 loc
->loc_type
= bp_loc_other
;
5616 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5624 free_bp_location (struct bp_location
*loc
)
5629 if (loc
->function_name
)
5630 xfree (loc
->function_name
);
5635 /* Increment reference count. */
5638 incref_bp_location (struct bp_location
*bl
)
5643 /* Decrement reference count. If the reference count reaches 0,
5644 destroy the bp_location. Sets *BLP to NULL. */
5647 decref_bp_location (struct bp_location
**blp
)
5649 gdb_assert ((*blp
)->refc
> 0);
5651 if (--(*blp
)->refc
== 0)
5652 free_bp_location (*blp
);
5656 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5657 type BPTYPE and has no locations as yet. */
5658 /* This function is used in gdbtk sources and thus can not be made
5661 static struct breakpoint
*
5662 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5665 struct breakpoint
*b
, *b1
;
5667 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5668 memset (b
, 0, sizeof (*b
));
5671 b
->gdbarch
= gdbarch
;
5672 b
->language
= current_language
->la_language
;
5673 b
->input_radix
= input_radix
;
5675 b
->enable_state
= bp_enabled
;
5678 b
->ignore_count
= 0;
5680 b
->frame_id
= null_frame_id
;
5681 b
->forked_inferior_pid
= null_ptid
;
5682 b
->exec_pathname
= NULL
;
5683 b
->syscalls_to_be_caught
= NULL
;
5685 b
->condition_not_parsed
= 0;
5686 b
->py_bp_object
= NULL
;
5688 /* Add this breakpoint to the end of the chain so that a list of
5689 breakpoints will come out in order of increasing numbers. */
5691 b1
= breakpoint_chain
;
5693 breakpoint_chain
= b
;
5703 /* Initialize loc->function_name. */
5705 set_breakpoint_location_function (struct bp_location
*loc
)
5707 gdb_assert (loc
->owner
!= NULL
);
5709 if (loc
->owner
->type
== bp_breakpoint
5710 || loc
->owner
->type
== bp_hardware_breakpoint
5711 || is_tracepoint (loc
->owner
))
5713 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5715 if (loc
->function_name
)
5716 loc
->function_name
= xstrdup (loc
->function_name
);
5720 /* Attempt to determine architecture of location identified by SAL. */
5721 static struct gdbarch
*
5722 get_sal_arch (struct symtab_and_line sal
)
5725 return get_objfile_arch (sal
.section
->objfile
);
5727 return get_objfile_arch (sal
.symtab
->objfile
);
5732 /* set_raw_breakpoint is a low level routine for allocating and
5733 partially initializing a breakpoint of type BPTYPE. The newly
5734 created breakpoint's address, section, source file name, and line
5735 number are provided by SAL. The newly created and partially
5736 initialized breakpoint is added to the breakpoint chain and
5737 is also returned as the value of this function.
5739 It is expected that the caller will complete the initialization of
5740 the newly created breakpoint struct as well as output any status
5741 information regarding the creation of a new breakpoint. In
5742 particular, set_raw_breakpoint does NOT set the breakpoint
5743 number! Care should be taken to not allow an error to occur
5744 prior to completing the initialization of the breakpoint. If this
5745 should happen, a bogus breakpoint will be left on the chain. */
5748 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5749 struct symtab_and_line sal
, enum bptype bptype
)
5751 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5753 CORE_ADDR adjusted_address
;
5754 struct gdbarch
*loc_gdbarch
;
5756 loc_gdbarch
= get_sal_arch (sal
);
5758 loc_gdbarch
= b
->gdbarch
;
5760 if (bptype
!= bp_catchpoint
)
5761 gdb_assert (sal
.pspace
!= NULL
);
5763 /* Adjust the breakpoint's address prior to allocating a location.
5764 Once we call allocate_bp_location(), that mostly uninitialized
5765 location will be placed on the location chain. Adjustment of the
5766 breakpoint may cause target_read_memory() to be called and we do
5767 not want its scan of the location chain to find a breakpoint and
5768 location that's only been partially initialized. */
5769 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5772 b
->loc
= allocate_bp_location (b
);
5773 b
->loc
->gdbarch
= loc_gdbarch
;
5774 b
->loc
->requested_address
= sal
.pc
;
5775 b
->loc
->address
= adjusted_address
;
5776 b
->loc
->pspace
= sal
.pspace
;
5778 /* Store the program space that was used to set the breakpoint, for
5779 breakpoint resetting. */
5780 b
->pspace
= sal
.pspace
;
5782 if (sal
.symtab
== NULL
)
5783 b
->source_file
= NULL
;
5785 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5786 b
->loc
->section
= sal
.section
;
5787 b
->line_number
= sal
.line
;
5789 set_breakpoint_location_function (b
->loc
);
5791 breakpoints_changed ();
5797 /* Note that the breakpoint object B describes a permanent breakpoint
5798 instruction, hard-wired into the inferior's code. */
5800 make_breakpoint_permanent (struct breakpoint
*b
)
5802 struct bp_location
*bl
;
5804 b
->enable_state
= bp_permanent
;
5806 /* By definition, permanent breakpoints are already present in the
5807 code. Mark all locations as inserted. For now,
5808 make_breakpoint_permanent is called in just one place, so it's
5809 hard to say if it's reasonable to have permanent breakpoint with
5810 multiple locations or not, but it's easy to implmement. */
5811 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5815 /* Call this routine when stepping and nexting to enable a breakpoint
5816 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5817 initiated the operation. */
5820 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5822 struct breakpoint
*b
, *b_tmp
;
5823 int thread
= tp
->num
;
5825 /* To avoid having to rescan all objfile symbols at every step,
5826 we maintain a list of continually-inserted but always disabled
5827 longjmp "master" breakpoints. Here, we simply create momentary
5828 clones of those and enable them for the requested thread. */
5829 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5830 if (b
->pspace
== current_program_space
5831 && (b
->type
== bp_longjmp_master
5832 || b
->type
== bp_exception_master
))
5834 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5836 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5837 clone
->thread
= thread
;
5840 tp
->initiating_frame
= frame
;
5843 /* Delete all longjmp breakpoints from THREAD. */
5845 delete_longjmp_breakpoint (int thread
)
5847 struct breakpoint
*b
, *b_tmp
;
5849 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5850 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5852 if (b
->thread
== thread
)
5853 delete_breakpoint (b
);
5858 enable_overlay_breakpoints (void)
5860 struct breakpoint
*b
;
5863 if (b
->type
== bp_overlay_event
)
5865 b
->enable_state
= bp_enabled
;
5866 update_global_location_list (1);
5867 overlay_events_enabled
= 1;
5872 disable_overlay_breakpoints (void)
5874 struct breakpoint
*b
;
5877 if (b
->type
== bp_overlay_event
)
5879 b
->enable_state
= bp_disabled
;
5880 update_global_location_list (0);
5881 overlay_events_enabled
= 0;
5885 /* Set an active std::terminate breakpoint for each std::terminate
5886 master breakpoint. */
5888 set_std_terminate_breakpoint (void)
5890 struct breakpoint
*b
, *b_tmp
;
5892 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5893 if (b
->pspace
== current_program_space
5894 && b
->type
== bp_std_terminate_master
)
5896 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5897 clone
->type
= bp_std_terminate
;
5901 /* Delete all the std::terminate breakpoints. */
5903 delete_std_terminate_breakpoint (void)
5905 struct breakpoint
*b
, *b_tmp
;
5907 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5908 if (b
->type
== bp_std_terminate
)
5909 delete_breakpoint (b
);
5913 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5915 struct breakpoint
*b
;
5917 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5919 b
->enable_state
= bp_enabled
;
5920 /* addr_string has to be used or breakpoint_re_set will delete me. */
5922 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5924 update_global_location_list_nothrow (1);
5930 remove_thread_event_breakpoints (void)
5932 struct breakpoint
*b
, *b_tmp
;
5934 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5935 if (b
->type
== bp_thread_event
5936 && b
->loc
->pspace
== current_program_space
)
5937 delete_breakpoint (b
);
5940 struct captured_parse_breakpoint_args
5943 struct symtabs_and_lines
*sals_p
;
5944 char ***addr_string_p
;
5948 struct lang_and_radix
5954 /* Create a breakpoint for JIT code registration and unregistration. */
5957 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5959 struct breakpoint
*b
;
5961 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5962 update_global_location_list_nothrow (1);
5966 /* Remove JIT code registration and unregistration breakpoint(s). */
5969 remove_jit_event_breakpoints (void)
5971 struct breakpoint
*b
, *b_tmp
;
5973 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5974 if (b
->type
== bp_jit_event
5975 && b
->loc
->pspace
== current_program_space
)
5976 delete_breakpoint (b
);
5980 remove_solib_event_breakpoints (void)
5982 struct breakpoint
*b
, *b_tmp
;
5984 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5985 if (b
->type
== bp_shlib_event
5986 && b
->loc
->pspace
== current_program_space
)
5987 delete_breakpoint (b
);
5991 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5993 struct breakpoint
*b
;
5995 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5996 update_global_location_list_nothrow (1);
6000 /* Disable any breakpoints that are on code in shared libraries. Only
6001 apply to enabled breakpoints, disabled ones can just stay disabled. */
6004 disable_breakpoints_in_shlibs (void)
6006 struct bp_location
*loc
, **locp_tmp
;
6008 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6010 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6011 struct breakpoint
*b
= loc
->owner
;
6013 /* We apply the check to all breakpoints, including disabled for
6014 those with loc->duplicate set. This is so that when breakpoint
6015 becomes enabled, or the duplicate is removed, gdb will try to
6016 insert all breakpoints. If we don't set shlib_disabled here,
6017 we'll try to insert those breakpoints and fail. */
6018 if (((b
->type
== bp_breakpoint
)
6019 || (b
->type
== bp_jit_event
)
6020 || (b
->type
== bp_hardware_breakpoint
)
6021 || (is_tracepoint (b
)))
6022 && loc
->pspace
== current_program_space
6023 && !loc
->shlib_disabled
6025 && PC_SOLIB (loc
->address
)
6027 && solib_name_from_address (loc
->pspace
, loc
->address
)
6031 loc
->shlib_disabled
= 1;
6036 /* Disable any breakpoints that are in in an unloaded shared library.
6037 Only apply to enabled breakpoints, disabled ones can just stay
6041 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6043 struct bp_location
*loc
, **locp_tmp
;
6044 int disabled_shlib_breaks
= 0;
6046 /* SunOS a.out shared libraries are always mapped, so do not
6047 disable breakpoints; they will only be reported as unloaded
6048 through clear_solib when GDB discards its shared library
6049 list. See clear_solib for more information. */
6050 if (exec_bfd
!= NULL
6051 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6054 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6056 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6057 struct breakpoint
*b
= loc
->owner
;
6059 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6060 || loc
->loc_type
== bp_loc_software_breakpoint
)
6061 && solib
->pspace
== loc
->pspace
6062 && !loc
->shlib_disabled
6063 && (b
->type
== bp_breakpoint
6064 || b
->type
== bp_jit_event
6065 || b
->type
== bp_hardware_breakpoint
)
6066 && solib_contains_address_p (solib
, loc
->address
))
6068 loc
->shlib_disabled
= 1;
6069 /* At this point, we cannot rely on remove_breakpoint
6070 succeeding so we must mark the breakpoint as not inserted
6071 to prevent future errors occurring in remove_breakpoints. */
6073 if (!disabled_shlib_breaks
)
6075 target_terminal_ours_for_output ();
6076 warning (_("Temporarily disabling breakpoints "
6077 "for unloaded shared library \"%s\""),
6080 disabled_shlib_breaks
= 1;
6085 /* FORK & VFORK catchpoints. */
6087 /* Implement the "insert" breakpoint_ops method for fork
6091 insert_catch_fork (struct bp_location
*bl
)
6093 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6096 /* Implement the "remove" breakpoint_ops method for fork
6100 remove_catch_fork (struct bp_location
*bl
)
6102 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6105 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6109 breakpoint_hit_catch_fork (struct breakpoint
*b
)
6111 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
6114 /* Implement the "print_it" breakpoint_ops method for fork
6117 static enum print_stop_action
6118 print_it_catch_fork (struct breakpoint
*b
)
6120 annotate_catchpoint (b
->number
);
6121 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6122 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6123 return PRINT_SRC_AND_LOC
;
6126 /* Implement the "print_one" breakpoint_ops method for fork
6130 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6132 struct value_print_options opts
;
6134 get_user_print_options (&opts
);
6136 /* Field 4, the address, is omitted (which makes the columns not
6137 line up too nicely with the headers, but the effect is relatively
6139 if (opts
.addressprint
)
6140 ui_out_field_skip (uiout
, "addr");
6142 ui_out_text (uiout
, "fork");
6143 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6145 ui_out_text (uiout
, ", process ");
6146 ui_out_field_int (uiout
, "what",
6147 ptid_get_pid (b
->forked_inferior_pid
));
6148 ui_out_spaces (uiout
, 1);
6152 /* Implement the "print_mention" breakpoint_ops method for fork
6156 print_mention_catch_fork (struct breakpoint
*b
)
6158 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6161 /* Implement the "print_recreate" breakpoint_ops method for fork
6165 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6167 fprintf_unfiltered (fp
, "catch fork");
6170 /* The breakpoint_ops structure to be used in fork catchpoints. */
6172 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6176 breakpoint_hit_catch_fork
,
6177 NULL
, /* resources_needed */
6178 print_it_catch_fork
,
6179 print_one_catch_fork
,
6180 print_mention_catch_fork
,
6181 print_recreate_catch_fork
6184 /* Implement the "insert" breakpoint_ops method for vfork
6188 insert_catch_vfork (struct bp_location
*bl
)
6190 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6193 /* Implement the "remove" breakpoint_ops method for vfork
6197 remove_catch_vfork (struct bp_location
*bl
)
6199 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6202 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6206 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6208 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6211 /* Implement the "print_it" breakpoint_ops method for vfork
6214 static enum print_stop_action
6215 print_it_catch_vfork (struct breakpoint
*b
)
6217 annotate_catchpoint (b
->number
);
6218 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6219 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6220 return PRINT_SRC_AND_LOC
;
6223 /* Implement the "print_one" breakpoint_ops method for vfork
6227 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6229 struct value_print_options opts
;
6231 get_user_print_options (&opts
);
6232 /* Field 4, the address, is omitted (which makes the columns not
6233 line up too nicely with the headers, but the effect is relatively
6235 if (opts
.addressprint
)
6236 ui_out_field_skip (uiout
, "addr");
6238 ui_out_text (uiout
, "vfork");
6239 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6241 ui_out_text (uiout
, ", process ");
6242 ui_out_field_int (uiout
, "what",
6243 ptid_get_pid (b
->forked_inferior_pid
));
6244 ui_out_spaces (uiout
, 1);
6248 /* Implement the "print_mention" breakpoint_ops method for vfork
6252 print_mention_catch_vfork (struct breakpoint
*b
)
6254 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6257 /* Implement the "print_recreate" breakpoint_ops method for vfork
6261 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6263 fprintf_unfiltered (fp
, "catch vfork");
6266 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6268 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6272 breakpoint_hit_catch_vfork
,
6273 NULL
, /* resources_needed */
6274 print_it_catch_vfork
,
6275 print_one_catch_vfork
,
6276 print_mention_catch_vfork
,
6277 print_recreate_catch_vfork
6280 /* Implement the "insert" breakpoint_ops method for syscall
6284 insert_catch_syscall (struct bp_location
*bl
)
6286 struct inferior
*inf
= current_inferior ();
6288 ++inf
->total_syscalls_count
;
6289 if (!bl
->owner
->syscalls_to_be_caught
)
6290 ++inf
->any_syscall_count
;
6296 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6301 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6303 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6304 uintptr_t vec_addr_offset
6305 = old_size
* ((uintptr_t) sizeof (int));
6307 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6308 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6310 memset ((void *) vec_addr
, 0,
6311 (iter
+ 1 - old_size
) * sizeof (int));
6313 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6314 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6318 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6319 inf
->total_syscalls_count
!= 0,
6320 inf
->any_syscall_count
,
6321 VEC_length (int, inf
->syscalls_counts
),
6322 VEC_address (int, inf
->syscalls_counts
));
6325 /* Implement the "remove" breakpoint_ops method for syscall
6329 remove_catch_syscall (struct bp_location
*bl
)
6331 struct inferior
*inf
= current_inferior ();
6333 --inf
->total_syscalls_count
;
6334 if (!bl
->owner
->syscalls_to_be_caught
)
6335 --inf
->any_syscall_count
;
6341 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6345 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6346 /* Shouldn't happen. */
6348 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6349 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6353 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6354 inf
->total_syscalls_count
!= 0,
6355 inf
->any_syscall_count
,
6356 VEC_length (int, inf
->syscalls_counts
),
6358 inf
->syscalls_counts
));
6361 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6365 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6367 /* We must check if we are catching specific syscalls in this
6368 breakpoint. If we are, then we must guarantee that the called
6369 syscall is the same syscall we are catching. */
6370 int syscall_number
= 0;
6372 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6375 /* Now, checking if the syscall is the same. */
6376 if (b
->syscalls_to_be_caught
)
6381 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6383 if (syscall_number
== iter
)
6393 /* Implement the "print_it" breakpoint_ops method for syscall
6396 static enum print_stop_action
6397 print_it_catch_syscall (struct breakpoint
*b
)
6399 /* These are needed because we want to know in which state a
6400 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6401 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6402 must print "called syscall" or "returned from syscall". */
6404 struct target_waitstatus last
;
6406 struct cleanup
*old_chain
;
6409 get_last_target_status (&ptid
, &last
);
6411 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6413 annotate_catchpoint (b
->number
);
6416 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6418 syscall_id
= xstrprintf ("'%s'", s
.name
);
6420 old_chain
= make_cleanup (xfree
, syscall_id
);
6422 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6423 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6424 b
->number
, syscall_id
);
6425 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6426 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6427 b
->number
, syscall_id
);
6429 do_cleanups (old_chain
);
6431 return PRINT_SRC_AND_LOC
;
6434 /* Implement the "print_one" breakpoint_ops method for syscall
6438 print_one_catch_syscall (struct breakpoint
*b
,
6439 struct bp_location
**last_loc
)
6441 struct value_print_options opts
;
6443 get_user_print_options (&opts
);
6444 /* Field 4, the address, is omitted (which makes the columns not
6445 line up too nicely with the headers, but the effect is relatively
6447 if (opts
.addressprint
)
6448 ui_out_field_skip (uiout
, "addr");
6451 if (b
->syscalls_to_be_caught
6452 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6453 ui_out_text (uiout
, "syscalls \"");
6455 ui_out_text (uiout
, "syscall \"");
6457 if (b
->syscalls_to_be_caught
)
6460 char *text
= xstrprintf ("%s", "");
6463 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6468 get_syscall_by_number (iter
, &s
);
6471 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6473 text
= xstrprintf ("%s%d, ", text
, iter
);
6475 /* We have to xfree the last 'text' (now stored at 'x')
6476 because xstrprintf dinamically allocates new space for it
6480 /* Remove the last comma. */
6481 text
[strlen (text
) - 2] = '\0';
6482 ui_out_field_string (uiout
, "what", text
);
6485 ui_out_field_string (uiout
, "what", "<any syscall>");
6486 ui_out_text (uiout
, "\" ");
6489 /* Implement the "print_mention" breakpoint_ops method for syscall
6493 print_mention_catch_syscall (struct breakpoint
*b
)
6495 if (b
->syscalls_to_be_caught
)
6499 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6500 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6502 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6505 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6509 get_syscall_by_number (iter
, &s
);
6512 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6514 printf_filtered (" %d", s
.number
);
6516 printf_filtered (")");
6519 printf_filtered (_("Catchpoint %d (any syscall)"),
6523 /* Implement the "print_recreate" breakpoint_ops method for syscall
6527 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6529 fprintf_unfiltered (fp
, "catch syscall");
6531 if (b
->syscalls_to_be_caught
)
6536 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6541 get_syscall_by_number (iter
, &s
);
6543 fprintf_unfiltered (fp
, " %s", s
.name
);
6545 fprintf_unfiltered (fp
, " %d", s
.number
);
6550 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6552 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6554 insert_catch_syscall
,
6555 remove_catch_syscall
,
6556 breakpoint_hit_catch_syscall
,
6557 NULL
, /* resources_needed */
6558 print_it_catch_syscall
,
6559 print_one_catch_syscall
,
6560 print_mention_catch_syscall
,
6561 print_recreate_catch_syscall
6564 /* Returns non-zero if 'b' is a syscall catchpoint. */
6567 syscall_catchpoint_p (struct breakpoint
*b
)
6569 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6572 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6573 but does NOT mention it nor update the global location list.
6574 This is useful if you need to fill more fields in the
6575 struct breakpoint before calling mention.
6577 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6578 If COND_STRING is not NULL, then store it in the breakpoint.
6579 OPS, if not NULL, is the breakpoint_ops structure associated
6580 to the catchpoint. */
6582 static struct breakpoint
*
6583 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6585 struct breakpoint_ops
*ops
)
6587 struct symtab_and_line sal
;
6588 struct breakpoint
*b
;
6591 sal
.pspace
= current_program_space
;
6593 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6594 set_breakpoint_count (breakpoint_count
+ 1);
6595 b
->number
= breakpoint_count
;
6597 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6599 b
->addr_string
= NULL
;
6600 b
->enable_state
= bp_enabled
;
6601 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6607 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6609 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6610 If COND_STRING is not NULL, then store it in the breakpoint.
6611 OPS, if not NULL, is the breakpoint_ops structure associated
6612 to the catchpoint. */
6614 static struct breakpoint
*
6615 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6616 char *cond_string
, struct breakpoint_ops
*ops
)
6618 struct breakpoint
*b
=
6619 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6622 update_global_location_list (1);
6628 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6629 int tempflag
, char *cond_string
,
6630 struct breakpoint_ops
*ops
)
6632 struct breakpoint
*b
6633 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6635 /* FIXME: We should put this information in a breakpoint private data
6637 b
->forked_inferior_pid
= null_ptid
;
6640 /* Exec catchpoints. */
6643 insert_catch_exec (struct bp_location
*bl
)
6645 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6649 remove_catch_exec (struct bp_location
*bl
)
6651 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6655 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6657 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6660 static enum print_stop_action
6661 print_it_catch_exec (struct breakpoint
*b
)
6663 annotate_catchpoint (b
->number
);
6664 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6666 return PRINT_SRC_AND_LOC
;
6670 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6672 struct value_print_options opts
;
6674 get_user_print_options (&opts
);
6676 /* Field 4, the address, is omitted (which makes the columns
6677 not line up too nicely with the headers, but the effect
6678 is relatively readable). */
6679 if (opts
.addressprint
)
6680 ui_out_field_skip (uiout
, "addr");
6682 ui_out_text (uiout
, "exec");
6683 if (b
->exec_pathname
!= NULL
)
6685 ui_out_text (uiout
, ", program \"");
6686 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6687 ui_out_text (uiout
, "\" ");
6692 print_mention_catch_exec (struct breakpoint
*b
)
6694 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6697 /* Implement the "print_recreate" breakpoint_ops method for exec
6701 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6703 fprintf_unfiltered (fp
, "catch exec");
6706 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6710 breakpoint_hit_catch_exec
,
6711 NULL
, /* resources_needed */
6712 print_it_catch_exec
,
6713 print_one_catch_exec
,
6714 print_mention_catch_exec
,
6715 print_recreate_catch_exec
6719 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6720 struct breakpoint_ops
*ops
)
6722 struct gdbarch
*gdbarch
= get_current_arch ();
6723 struct breakpoint
*b
=
6724 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6726 b
->syscalls_to_be_caught
= filter
;
6728 /* Now, we have to mention the breakpoint and update the global
6731 update_global_location_list (1);
6735 hw_breakpoint_used_count (void)
6737 struct breakpoint
*b
;
6742 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6750 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6753 struct breakpoint
*b
;
6754 struct bp_location
*bl
;
6756 *other_type_used
= 0;
6759 if (!breakpoint_enabled (b
))
6762 if (b
->type
== type
)
6763 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6765 /* Special types of hardware watchpoints may use more than
6767 if (b
->ops
&& b
->ops
->resources_needed
)
6768 i
+= b
->ops
->resources_needed (bl
);
6772 else if (is_hardware_watchpoint (b
))
6773 *other_type_used
= 1;
6780 disable_watchpoints_before_interactive_call_start (void)
6782 struct breakpoint
*b
;
6786 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6788 b
->enable_state
= bp_call_disabled
;
6789 update_global_location_list (0);
6795 enable_watchpoints_after_interactive_call_stop (void)
6797 struct breakpoint
*b
;
6801 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6803 b
->enable_state
= bp_enabled
;
6804 update_global_location_list (1);
6810 disable_breakpoints_before_startup (void)
6812 struct breakpoint
*b
;
6817 if (b
->pspace
!= current_program_space
)
6820 if ((b
->type
== bp_breakpoint
6821 || b
->type
== bp_hardware_breakpoint
)
6822 && breakpoint_enabled (b
))
6824 b
->enable_state
= bp_startup_disabled
;
6830 update_global_location_list (0);
6832 current_program_space
->executing_startup
= 1;
6836 enable_breakpoints_after_startup (void)
6838 struct breakpoint
*b
;
6841 current_program_space
->executing_startup
= 0;
6845 if (b
->pspace
!= current_program_space
)
6848 if ((b
->type
== bp_breakpoint
6849 || b
->type
== bp_hardware_breakpoint
)
6850 && b
->enable_state
== bp_startup_disabled
)
6852 b
->enable_state
= bp_enabled
;
6858 breakpoint_re_set ();
6862 /* Set a breakpoint that will evaporate an end of command
6863 at address specified by SAL.
6864 Restrict it to frame FRAME if FRAME is nonzero. */
6867 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6868 struct frame_id frame_id
, enum bptype type
)
6870 struct breakpoint
*b
;
6872 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6874 gdb_assert (!frame_id_inlined_p (frame_id
));
6876 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6877 b
->enable_state
= bp_enabled
;
6878 b
->disposition
= disp_donttouch
;
6879 b
->frame_id
= frame_id
;
6881 /* If we're debugging a multi-threaded program, then we want
6882 momentary breakpoints to be active in only a single thread of
6884 if (in_thread_list (inferior_ptid
))
6885 b
->thread
= pid_to_thread_id (inferior_ptid
);
6887 update_global_location_list_nothrow (1);
6892 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6896 clone_momentary_breakpoint (struct breakpoint
*orig
)
6898 struct breakpoint
*copy
;
6900 /* If there's nothing to clone, then return nothing. */
6904 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6905 copy
->loc
= allocate_bp_location (copy
);
6906 set_breakpoint_location_function (copy
->loc
);
6908 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6909 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6910 copy
->loc
->address
= orig
->loc
->address
;
6911 copy
->loc
->section
= orig
->loc
->section
;
6912 copy
->loc
->pspace
= orig
->loc
->pspace
;
6914 if (orig
->source_file
== NULL
)
6915 copy
->source_file
= NULL
;
6917 copy
->source_file
= xstrdup (orig
->source_file
);
6919 copy
->line_number
= orig
->line_number
;
6920 copy
->frame_id
= orig
->frame_id
;
6921 copy
->thread
= orig
->thread
;
6922 copy
->pspace
= orig
->pspace
;
6924 copy
->enable_state
= bp_enabled
;
6925 copy
->disposition
= disp_donttouch
;
6926 copy
->number
= internal_breakpoint_number
--;
6928 update_global_location_list_nothrow (0);
6933 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6936 struct symtab_and_line sal
;
6938 sal
= find_pc_line (pc
, 0);
6940 sal
.section
= find_pc_overlay (pc
);
6941 sal
.explicit_pc
= 1;
6943 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6947 /* Tell the user we have just set a breakpoint B. */
6950 mention (struct breakpoint
*b
)
6953 struct cleanup
*ui_out_chain
;
6954 struct value_print_options opts
;
6956 get_user_print_options (&opts
);
6958 /* FIXME: This is misplaced; mention() is called by things (like
6959 hitting a watchpoint) other than breakpoint creation. It should
6960 be possible to clean this up and at the same time replace the
6961 random calls to breakpoint_changed with this hook. */
6962 observer_notify_breakpoint_created (b
->number
);
6964 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6965 b
->ops
->print_mention (b
);
6970 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
6974 ui_out_text (uiout
, "Watchpoint ");
6975 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6976 ui_out_field_int (uiout
, "number", b
->number
);
6977 ui_out_text (uiout
, ": ");
6978 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6979 do_cleanups (ui_out_chain
);
6981 case bp_hardware_watchpoint
:
6982 ui_out_text (uiout
, "Hardware watchpoint ");
6983 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6984 ui_out_field_int (uiout
, "number", b
->number
);
6985 ui_out_text (uiout
, ": ");
6986 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6987 do_cleanups (ui_out_chain
);
6989 case bp_read_watchpoint
:
6990 ui_out_text (uiout
, "Hardware read watchpoint ");
6991 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6992 ui_out_field_int (uiout
, "number", b
->number
);
6993 ui_out_text (uiout
, ": ");
6994 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6995 do_cleanups (ui_out_chain
);
6997 case bp_access_watchpoint
:
6998 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6999 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
7000 ui_out_field_int (uiout
, "number", b
->number
);
7001 ui_out_text (uiout
, ": ");
7002 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7003 do_cleanups (ui_out_chain
);
7006 if (ui_out_is_mi_like_p (uiout
))
7011 if (b
->disposition
== disp_del
)
7012 printf_filtered (_("Temporary breakpoint"));
7014 printf_filtered (_("Breakpoint"));
7015 printf_filtered (_(" %d"), b
->number
);
7018 case bp_hardware_breakpoint
:
7019 if (ui_out_is_mi_like_p (uiout
))
7024 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
7028 if (ui_out_is_mi_like_p (uiout
))
7033 printf_filtered (_("Tracepoint"));
7034 printf_filtered (_(" %d"), b
->number
);
7037 case bp_fast_tracepoint
:
7038 if (ui_out_is_mi_like_p (uiout
))
7043 printf_filtered (_("Fast tracepoint"));
7044 printf_filtered (_(" %d"), b
->number
);
7047 case bp_static_tracepoint
:
7048 if (ui_out_is_mi_like_p (uiout
))
7053 printf_filtered (_("Static tracepoint"));
7054 printf_filtered (_(" %d"), b
->number
);
7061 case bp_longjmp_resume
:
7063 case bp_exception_resume
:
7064 case bp_step_resume
:
7066 case bp_std_terminate
:
7067 case bp_watchpoint_scope
:
7068 case bp_shlib_event
:
7069 case bp_thread_event
:
7070 case bp_overlay_event
:
7072 case bp_longjmp_master
:
7073 case bp_std_terminate_master
:
7074 case bp_exception_master
:
7080 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7084 printf_filtered (_(" (%s) pending."), b
->addr_string
);
7088 if (opts
.addressprint
|| b
->source_file
== NULL
)
7090 printf_filtered (" at ");
7091 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
7095 printf_filtered (": file %s, line %d.",
7096 b
->source_file
, b
->line_number
);
7100 struct bp_location
*loc
= b
->loc
;
7102 for (; loc
; loc
= loc
->next
)
7104 printf_filtered (" (%d locations)", n
);
7109 if (ui_out_is_mi_like_p (uiout
))
7111 printf_filtered ("\n");
7115 static struct bp_location
*
7116 add_location_to_breakpoint (struct breakpoint
*b
,
7117 const struct symtab_and_line
*sal
)
7119 struct bp_location
*loc
, **tmp
;
7121 loc
= allocate_bp_location (b
);
7122 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7125 loc
->gdbarch
= get_sal_arch (*sal
);
7127 loc
->gdbarch
= b
->gdbarch
;
7128 loc
->requested_address
= sal
->pc
;
7129 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7130 loc
->requested_address
, b
->type
);
7131 loc
->pspace
= sal
->pspace
;
7132 gdb_assert (loc
->pspace
!= NULL
);
7133 loc
->section
= sal
->section
;
7135 set_breakpoint_location_function (loc
);
7140 /* Return 1 if LOC is pointing to a permanent breakpoint,
7141 return 0 otherwise. */
7144 bp_loc_is_permanent (struct bp_location
*loc
)
7148 const gdb_byte
*brk
;
7149 gdb_byte
*target_mem
;
7150 struct cleanup
*cleanup
;
7153 gdb_assert (loc
!= NULL
);
7155 addr
= loc
->address
;
7156 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7158 /* Software breakpoints unsupported? */
7162 target_mem
= alloca (len
);
7164 /* Enable the automatic memory restoration from breakpoints while
7165 we read the memory. Otherwise we could say about our temporary
7166 breakpoints they are permanent. */
7167 cleanup
= save_current_space_and_thread ();
7169 switch_to_program_space_and_thread (loc
->pspace
);
7170 make_show_memory_breakpoints_cleanup (0);
7172 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7173 && memcmp (target_mem
, brk
, len
) == 0)
7176 do_cleanups (cleanup
);
7183 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7184 as textual description of the location, and COND_STRING
7185 as condition expression. */
7188 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7189 struct symtabs_and_lines sals
, char *addr_string
,
7191 enum bptype type
, enum bpdisp disposition
,
7192 int thread
, int task
, int ignore_count
,
7193 struct breakpoint_ops
*ops
, int from_tty
,
7194 int enabled
, int internal
)
7196 struct breakpoint
*b
= NULL
;
7199 if (type
== bp_hardware_breakpoint
)
7201 int i
= hw_breakpoint_used_count ();
7202 int target_resources_ok
=
7203 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7205 if (target_resources_ok
== 0)
7206 error (_("No hardware breakpoint support in the target."));
7207 else if (target_resources_ok
< 0)
7208 error (_("Hardware breakpoints used exceeds limit."));
7211 gdb_assert (sals
.nelts
> 0);
7213 for (i
= 0; i
< sals
.nelts
; ++i
)
7215 struct symtab_and_line sal
= sals
.sals
[i
];
7216 struct bp_location
*loc
;
7220 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7222 loc_gdbarch
= gdbarch
;
7224 describe_other_breakpoints (loc_gdbarch
,
7225 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7230 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7231 set_breakpoint_number (internal
, b
);
7235 b
->cond_string
= cond_string
;
7236 b
->ignore_count
= ignore_count
;
7237 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7238 b
->disposition
= disposition
;
7239 b
->pspace
= sals
.sals
[0].pspace
;
7241 if (type
== bp_static_tracepoint
)
7243 struct static_tracepoint_marker marker
;
7245 if (is_marker_spec (addr_string
))
7247 /* We already know the marker exists, otherwise, we
7248 wouldn't see a sal for it. */
7249 char *p
= &addr_string
[3];
7254 p
= skip_spaces (p
);
7256 endp
= skip_to_space (p
);
7258 marker_str
= savestring (p
, endp
- p
);
7259 b
->static_trace_marker_id
= marker_str
;
7261 printf_filtered (_("Probed static tracepoint "
7263 b
->static_trace_marker_id
);
7265 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7267 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7268 release_static_tracepoint_marker (&marker
);
7270 printf_filtered (_("Probed static tracepoint "
7272 b
->static_trace_marker_id
);
7275 warning (_("Couldn't determine the static "
7276 "tracepoint marker to probe"));
7279 if (enabled
&& b
->pspace
->executing_startup
7280 && (b
->type
== bp_breakpoint
7281 || b
->type
== bp_hardware_breakpoint
))
7282 b
->enable_state
= bp_startup_disabled
;
7288 loc
= add_location_to_breakpoint (b
, &sal
);
7291 if (bp_loc_is_permanent (loc
))
7292 make_breakpoint_permanent (b
);
7296 char *arg
= b
->cond_string
;
7297 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7299 error (_("Garbage %s follows condition"), arg
);
7304 b
->addr_string
= addr_string
;
7306 /* addr_string has to be used or breakpoint_re_set will delete
7309 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7313 /* Do not mention breakpoints with a negative number, but do
7314 notify observers. */
7315 observer_notify_breakpoint_created (b
->number
);
7320 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7321 elements to fill the void space. */
7323 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7325 int i
= index_to_remove
+1;
7326 int last_index
= sal
->nelts
-1;
7328 for (;i
<= last_index
; ++i
)
7329 sal
->sals
[i
-1] = sal
->sals
[i
];
7334 /* If appropriate, obtains all sals that correspond to the same file
7335 and line as SAL, in all program spaces. Users debugging with IDEs,
7336 will want to set a breakpoint at foo.c:line, and not really care
7337 about program spaces. This is done only if SAL does not have
7338 explicit PC and has line and file information. If we got just a
7339 single expanded sal, return the original.
7341 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7342 which the name of enclosing function is different from SAL. This
7343 makes sure that if we have breakpoint originally set in template
7344 instantiation, say foo<int>(), we won't expand SAL to locations at
7345 the same line in all existing instantiations of 'foo'. */
7347 static struct symtabs_and_lines
7348 expand_line_sal_maybe (struct symtab_and_line sal
)
7350 struct symtabs_and_lines expanded
;
7351 CORE_ADDR original_pc
= sal
.pc
;
7352 char *original_function
= NULL
;
7355 struct cleanup
*old_chain
;
7357 /* If we have explicit pc, don't expand.
7358 If we have no line number, we can't expand. */
7359 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7362 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7363 expanded
.sals
[0] = sal
;
7369 old_chain
= save_current_space_and_thread ();
7371 switch_to_program_space_and_thread (sal
.pspace
);
7373 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7375 /* Note that expand_line_sal visits *all* program spaces. */
7376 expanded
= expand_line_sal (sal
);
7378 if (expanded
.nelts
== 1)
7380 /* We had one sal, we got one sal. Return that sal, adjusting it
7381 past the function prologue if necessary. */
7382 xfree (expanded
.sals
);
7384 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7385 sal
.pc
= original_pc
;
7386 expanded
.sals
[0] = sal
;
7387 skip_prologue_sal (&expanded
.sals
[0]);
7388 do_cleanups (old_chain
);
7392 if (!sal
.explicit_line
)
7394 CORE_ADDR func_addr
, func_end
;
7395 for (i
= 0; i
< expanded
.nelts
; ++i
)
7397 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7398 char *this_function
;
7400 /* We need to switch threads as well since we're about to
7402 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7404 if (find_pc_partial_function (pc
, &this_function
,
7405 &func_addr
, &func_end
))
7408 && strcmp (this_function
, original_function
) != 0)
7410 remove_sal (&expanded
, i
);
7417 /* Skip the function prologue if necessary. */
7418 for (i
= 0; i
< expanded
.nelts
; ++i
)
7419 skip_prologue_sal (&expanded
.sals
[i
]);
7421 do_cleanups (old_chain
);
7423 if (expanded
.nelts
<= 1)
7425 /* This is un ugly workaround. If we get zero expanded sals
7426 then something is really wrong. Fix that by returning the
7429 xfree (expanded
.sals
);
7431 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7432 sal
.pc
= original_pc
;
7433 expanded
.sals
[0] = sal
;
7440 for (i
= 0; i
< expanded
.nelts
; ++i
)
7441 if (expanded
.sals
[i
].pc
== original_pc
)
7452 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7453 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7454 value. COND_STRING, if not NULL, specified the condition to be
7455 used for all breakpoints. Essentially the only case where
7456 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7457 function. In that case, it's still not possible to specify
7458 separate conditions for different overloaded functions, so
7459 we take just a single condition string.
7461 NOTE: If the function succeeds, the caller is expected to cleanup
7462 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7463 array contents). If the function fails (error() is called), the
7464 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7465 COND and SALS arrays and each of those arrays contents. */
7468 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7469 struct symtabs_and_lines sals
, char **addr_string
,
7471 enum bptype type
, enum bpdisp disposition
,
7472 int thread
, int task
, int ignore_count
,
7473 struct breakpoint_ops
*ops
, int from_tty
,
7474 int enabled
, int internal
)
7478 for (i
= 0; i
< sals
.nelts
; ++i
)
7480 struct symtabs_and_lines expanded
=
7481 expand_line_sal_maybe (sals
.sals
[i
]);
7483 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7484 cond_string
, type
, disposition
,
7485 thread
, task
, ignore_count
, ops
,
7486 from_tty
, enabled
, internal
);
7490 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7491 followed by conditionals. On return, SALS contains an array of SAL
7492 addresses found. ADDR_STRING contains a vector of (canonical)
7493 address strings. ADDRESS points to the end of the SAL.
7495 The array and the line spec strings are allocated on the heap, it is
7496 the caller's responsibility to free them. */
7499 parse_breakpoint_sals (char **address
,
7500 struct symtabs_and_lines
*sals
,
7501 char ***addr_string
,
7504 char *addr_start
= *address
;
7506 *addr_string
= NULL
;
7507 /* If no arg given, or if first arg is 'if ', use the default
7509 if ((*address
) == NULL
7510 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7512 if (default_breakpoint_valid
)
7514 struct symtab_and_line sal
;
7516 init_sal (&sal
); /* Initialize to zeroes. */
7517 sals
->sals
= (struct symtab_and_line
*)
7518 xmalloc (sizeof (struct symtab_and_line
));
7519 sal
.pc
= default_breakpoint_address
;
7520 sal
.line
= default_breakpoint_line
;
7521 sal
.symtab
= default_breakpoint_symtab
;
7522 sal
.pspace
= default_breakpoint_pspace
;
7523 sal
.section
= find_pc_overlay (sal
.pc
);
7525 /* "break" without arguments is equivalent to "break *PC"
7526 where PC is the default_breakpoint_address. So make sure
7527 to set sal.explicit_pc to prevent GDB from trying to
7528 expand the list of sals to include all other instances
7529 with the same symtab and line. */
7530 sal
.explicit_pc
= 1;
7532 sals
->sals
[0] = sal
;
7536 error (_("No default breakpoint address now."));
7540 /* Force almost all breakpoints to be in terms of the
7541 current_source_symtab (which is decode_line_1's default).
7542 This should produce the results we want almost all of the
7543 time while leaving default_breakpoint_* alone.
7545 ObjC: However, don't match an Objective-C method name which
7546 may have a '+' or '-' succeeded by a '[' */
7548 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7550 if (default_breakpoint_valid
7552 || ((strchr ("+-", (*address
)[0]) != NULL
)
7553 && ((*address
)[1] != '['))))
7554 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7555 default_breakpoint_line
, addr_string
,
7558 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7559 addr_string
, not_found_ptr
);
7561 /* For any SAL that didn't have a canonical string, fill one in. */
7562 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7563 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7564 if (addr_start
!= (*address
))
7568 for (i
= 0; i
< sals
->nelts
; i
++)
7570 /* Add the string if not present. */
7571 if ((*addr_string
)[i
] == NULL
)
7572 (*addr_string
)[i
] = savestring (addr_start
,
7573 (*address
) - addr_start
);
7579 /* Convert each SAL into a real PC. Verify that the PC can be
7580 inserted as a breakpoint. If it can't throw an error. */
7583 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7587 for (i
= 0; i
< sals
->nelts
; i
++)
7588 resolve_sal_pc (&sals
->sals
[i
]);
7591 /* Fast tracepoints may have restrictions on valid locations. For
7592 instance, a fast tracepoint using a jump instead of a trap will
7593 likely have to overwrite more bytes than a trap would, and so can
7594 only be placed where the instruction is longer than the jump, or a
7595 multi-instruction sequence does not have a jump into the middle of
7599 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7600 struct symtabs_and_lines
*sals
)
7603 struct symtab_and_line
*sal
;
7605 struct cleanup
*old_chain
;
7607 for (i
= 0; i
< sals
->nelts
; i
++)
7609 sal
= &sals
->sals
[i
];
7611 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7613 old_chain
= make_cleanup (xfree
, msg
);
7616 error (_("May not have a fast tracepoint at 0x%s%s"),
7617 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7619 do_cleanups (old_chain
);
7624 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7626 struct captured_parse_breakpoint_args
*args
= data
;
7628 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7629 args
->not_found_ptr
);
7632 /* Given TOK, a string specification of condition and thread, as
7633 accepted by the 'break' command, extract the condition
7634 string and thread number and set *COND_STRING and *THREAD.
7635 PC identifies the context at which the condition should be parsed.
7636 If no condition is found, *COND_STRING is set to NULL.
7637 If no thread is found, *THREAD is set to -1. */
7639 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7640 char **cond_string
, int *thread
, int *task
)
7642 *cond_string
= NULL
;
7648 char *cond_start
= NULL
;
7649 char *cond_end
= NULL
;
7651 tok
= skip_spaces (tok
);
7653 end_tok
= skip_to_space (tok
);
7655 toklen
= end_tok
- tok
;
7657 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7659 struct expression
*expr
;
7661 tok
= cond_start
= end_tok
+ 1;
7662 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7665 *cond_string
= savestring (cond_start
,
7666 cond_end
- cond_start
);
7668 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7674 *thread
= strtol (tok
, &tok
, 0);
7676 error (_("Junk after thread keyword."));
7677 if (!valid_thread_id (*thread
))
7678 error (_("Unknown thread %d."), *thread
);
7680 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7686 *task
= strtol (tok
, &tok
, 0);
7688 error (_("Junk after task keyword."));
7689 if (!valid_task_id (*task
))
7690 error (_("Unknown task %d."), *task
);
7693 error (_("Junk at end of arguments."));
7697 /* Decode a static tracepoint marker spec. */
7699 static struct symtabs_and_lines
7700 decode_static_tracepoint_spec (char **arg_p
)
7702 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7703 struct symtabs_and_lines sals
;
7704 struct symtab_and_line sal
;
7706 struct cleanup
*old_chain
;
7707 char *p
= &(*arg_p
)[3];
7712 p
= skip_spaces (p
);
7714 endp
= skip_to_space (p
);
7716 marker_str
= savestring (p
, endp
- p
);
7717 old_chain
= make_cleanup (xfree
, marker_str
);
7719 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7720 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7721 error (_("No known static tracepoint marker named %s"), marker_str
);
7723 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7724 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7726 for (i
= 0; i
< sals
.nelts
; i
++)
7728 struct static_tracepoint_marker
*marker
;
7730 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7732 init_sal (&sals
.sals
[i
]);
7734 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7735 sals
.sals
[i
].pc
= marker
->address
;
7737 release_static_tracepoint_marker (marker
);
7740 do_cleanups (old_chain
);
7746 /* Set a breakpoint. This function is shared between CLI and MI
7747 functions for setting a breakpoint. This function has two major
7748 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7749 parameter. If non-zero, the function will parse arg, extracting
7750 breakpoint location, address and thread. Otherwise, ARG is just
7751 the location of breakpoint, with condition and thread specified by
7752 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7753 the breakpoint number will be allocated from the internal
7754 breakpoint count. Returns true if any breakpoint was created;
7758 create_breakpoint (struct gdbarch
*gdbarch
,
7759 char *arg
, char *cond_string
, int thread
,
7760 int parse_condition_and_thread
,
7761 int tempflag
, enum bptype type_wanted
,
7763 enum auto_boolean pending_break_support
,
7764 struct breakpoint_ops
*ops
,
7765 int from_tty
, int enabled
, int internal
)
7767 struct gdb_exception e
;
7768 struct symtabs_and_lines sals
;
7769 struct symtab_and_line pending_sal
;
7771 char *addr_start
= arg
;
7773 struct cleanup
*old_chain
;
7774 struct cleanup
*bkpt_chain
= NULL
;
7775 struct captured_parse_breakpoint_args parse_args
;
7780 int prev_bkpt_count
= breakpoint_count
;
7786 parse_args
.arg_p
= &arg
;
7787 parse_args
.sals_p
= &sals
;
7788 parse_args
.addr_string_p
= &addr_string
;
7789 parse_args
.not_found_ptr
= ¬_found
;
7791 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7795 sals
= decode_static_tracepoint_spec (&arg
);
7797 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7798 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7799 for (i
= 0; i
< sals
.nelts
; i
++)
7800 addr_string
[i
] = xstrdup (copy_arg
);
7804 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7805 &parse_args
, RETURN_MASK_ALL
);
7807 /* If caller is interested in rc value from parse, set value. */
7811 throw_exception (e
);
7815 case NOT_FOUND_ERROR
:
7817 /* If pending breakpoint support is turned off, throw
7820 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7821 throw_exception (e
);
7823 exception_print (gdb_stderr
, e
);
7825 /* If pending breakpoint support is auto query and the user
7826 selects no, then simply return the error code. */
7827 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7828 && !nquery (_("Make breakpoint pending on "
7829 "future shared library load? ")))
7832 /* At this point, either the user was queried about setting
7833 a pending breakpoint and selected yes, or pending
7834 breakpoint behavior is on and thus a pending breakpoint
7835 is defaulted on behalf of the user. */
7836 copy_arg
= xstrdup (addr_start
);
7837 addr_string
= ©_arg
;
7839 sals
.sals
= &pending_sal
;
7844 throw_exception (e
);
7853 /* Create a chain of things that always need to be cleaned up. */
7854 old_chain
= make_cleanup (null_cleanup
, 0);
7858 /* Make sure that all storage allocated to SALS gets freed. */
7859 make_cleanup (xfree
, sals
.sals
);
7861 /* Cleanup the addr_string array but not its contents. */
7862 make_cleanup (xfree
, addr_string
);
7865 /* ----------------------------- SNIP -----------------------------
7866 Anything added to the cleanup chain beyond this point is assumed
7867 to be part of a breakpoint. If the breakpoint create succeeds
7868 then the memory is not reclaimed. */
7869 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7871 /* Mark the contents of the addr_string for cleanup. These go on
7872 the bkpt_chain and only occur if the breakpoint create fails. */
7873 for (i
= 0; i
< sals
.nelts
; i
++)
7875 if (addr_string
[i
] != NULL
)
7876 make_cleanup (xfree
, addr_string
[i
]);
7879 /* Resolve all line numbers to PC's and verify that the addresses
7880 are ok for the target. */
7882 breakpoint_sals_to_pc (&sals
);
7884 /* Fast tracepoints may have additional restrictions on location. */
7885 if (type_wanted
== bp_fast_tracepoint
)
7886 check_fast_tracepoint_sals (gdbarch
, &sals
);
7888 /* Verify that condition can be parsed, before setting any
7889 breakpoints. Allocate a separate condition expression for each
7893 if (parse_condition_and_thread
)
7895 /* Here we only parse 'arg' to separate condition
7896 from thread number, so parsing in context of first
7897 sal is OK. When setting the breakpoint we'll
7898 re-parse it in context of each sal. */
7901 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7904 make_cleanup (xfree
, cond_string
);
7908 /* Create a private copy of condition string. */
7911 cond_string
= xstrdup (cond_string
);
7912 make_cleanup (xfree
, cond_string
);
7916 /* If the user is creating a static tracepoint by marker id
7917 (strace -m MARKER_ID), then store the sals index, so that
7918 breakpoint_re_set can try to match up which of the newly
7919 found markers corresponds to this one, and, don't try to
7920 expand multiple locations for each sal, given than SALS
7921 already should contain all sals for MARKER_ID. */
7922 if (type_wanted
== bp_static_tracepoint
7923 && is_marker_spec (addr_string
[0]))
7927 for (i
= 0; i
< sals
.nelts
; ++i
)
7929 struct symtabs_and_lines expanded
;
7930 struct breakpoint
*tp
;
7931 struct cleanup
*old_chain
;
7934 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7935 expanded
.sals
[0] = sals
.sals
[i
];
7936 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7938 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7939 cond_string
, type_wanted
,
7940 tempflag
? disp_del
: disp_donttouch
,
7941 thread
, task
, ignore_count
, ops
,
7942 from_tty
, enabled
, internal
);
7944 do_cleanups (old_chain
);
7946 /* Get the tracepoint we just created. */
7948 tp
= get_breakpoint (internal_breakpoint_number
);
7950 tp
= get_breakpoint (breakpoint_count
);
7951 gdb_assert (tp
!= NULL
);
7953 /* Given that its possible to have multiple markers with
7954 the same string id, if the user is creating a static
7955 tracepoint by marker id ("strace -m MARKER_ID"), then
7956 store the sals index, so that breakpoint_re_set can
7957 try to match up which of the newly found markers
7958 corresponds to this one */
7959 tp
->static_trace_marker_id_idx
= i
;
7963 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7965 tempflag
? disp_del
: disp_donttouch
,
7966 thread
, task
, ignore_count
, ops
, from_tty
,
7971 struct breakpoint
*b
;
7973 make_cleanup (xfree
, copy_arg
);
7975 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7976 set_breakpoint_number (internal
, b
);
7978 b
->addr_string
= addr_string
[0];
7979 b
->cond_string
= NULL
;
7980 b
->ignore_count
= ignore_count
;
7981 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7982 b
->condition_not_parsed
= 1;
7984 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7985 b
->pspace
= current_program_space
;
7986 b
->py_bp_object
= NULL
;
7988 if (enabled
&& b
->pspace
->executing_startup
7989 && (b
->type
== bp_breakpoint
7990 || b
->type
== bp_hardware_breakpoint
))
7991 b
->enable_state
= bp_startup_disabled
;
7994 /* Do not mention breakpoints with a negative number,
7995 but do notify observers. */
7996 observer_notify_breakpoint_created (b
->number
);
8003 warning (_("Multiple breakpoints were set.\nUse the "
8004 "\"delete\" command to delete unwanted breakpoints."));
8005 prev_breakpoint_count
= prev_bkpt_count
;
8008 /* That's it. Discard the cleanups for data inserted into the
8010 discard_cleanups (bkpt_chain
);
8011 /* But cleanup everything else. */
8012 do_cleanups (old_chain
);
8014 /* error call may happen here - have BKPT_CHAIN already discarded. */
8015 update_global_location_list (1);
8020 /* Set a breakpoint.
8021 ARG is a string describing breakpoint address,
8022 condition, and thread.
8023 FLAG specifies if a breakpoint is hardware on,
8024 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8028 break_command_1 (char *arg
, int flag
, int from_tty
)
8030 int tempflag
= flag
& BP_TEMPFLAG
;
8031 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8032 ? bp_hardware_breakpoint
8035 create_breakpoint (get_current_arch (),
8037 NULL
, 0, 1 /* parse arg */,
8038 tempflag
, type_wanted
,
8039 0 /* Ignore count */,
8040 pending_break_support
,
8041 NULL
/* breakpoint_ops */,
8048 /* Helper function for break_command_1 and disassemble_command. */
8051 resolve_sal_pc (struct symtab_and_line
*sal
)
8055 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8057 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8058 error (_("No line %d in file \"%s\"."),
8059 sal
->line
, sal
->symtab
->filename
);
8062 /* If this SAL corresponds to a breakpoint inserted using a line
8063 number, then skip the function prologue if necessary. */
8064 if (sal
->explicit_line
)
8065 skip_prologue_sal (sal
);
8068 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8070 struct blockvector
*bv
;
8074 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8077 sym
= block_linkage_function (b
);
8080 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8081 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8085 /* It really is worthwhile to have the section, so we'll
8086 just have to look harder. This case can be executed
8087 if we have line numbers but no functions (as can
8088 happen in assembly source). */
8090 struct minimal_symbol
*msym
;
8091 struct cleanup
*old_chain
= save_current_space_and_thread ();
8093 switch_to_program_space_and_thread (sal
->pspace
);
8095 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8097 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8099 do_cleanups (old_chain
);
8106 break_command (char *arg
, int from_tty
)
8108 break_command_1 (arg
, 0, from_tty
);
8112 tbreak_command (char *arg
, int from_tty
)
8114 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8118 hbreak_command (char *arg
, int from_tty
)
8120 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8124 thbreak_command (char *arg
, int from_tty
)
8126 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8130 stop_command (char *arg
, int from_tty
)
8132 printf_filtered (_("Specify the type of breakpoint to set.\n\
8133 Usage: stop in <function | address>\n\
8134 stop at <line>\n"));
8138 stopin_command (char *arg
, int from_tty
)
8142 if (arg
== (char *) NULL
)
8144 else if (*arg
!= '*')
8149 /* Look for a ':'. If this is a line number specification, then
8150 say it is bad, otherwise, it should be an address or
8151 function/method name. */
8152 while (*argptr
&& !hasColon
)
8154 hasColon
= (*argptr
== ':');
8159 badInput
= (*argptr
!= ':'); /* Not a class::method */
8161 badInput
= isdigit (*arg
); /* a simple line number */
8165 printf_filtered (_("Usage: stop in <function | address>\n"));
8167 break_command_1 (arg
, 0, from_tty
);
8171 stopat_command (char *arg
, int from_tty
)
8175 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8182 /* Look for a ':'. If there is a '::' then get out, otherwise
8183 it is probably a line number. */
8184 while (*argptr
&& !hasColon
)
8186 hasColon
= (*argptr
== ':');
8191 badInput
= (*argptr
== ':'); /* we have class::method */
8193 badInput
= !isdigit (*arg
); /* not a line number */
8197 printf_filtered (_("Usage: stop at <line>\n"));
8199 break_command_1 (arg
, 0, from_tty
);
8202 /* Return non-zero if EXP is verified as constant. Returned zero
8203 means EXP is variable. Also the constant detection may fail for
8204 some constant expressions and in such case still falsely return
8207 watchpoint_exp_is_const (const struct expression
*exp
)
8215 /* We are only interested in the descriptor of each element. */
8216 operator_length (exp
, i
, &oplenp
, &argsp
);
8219 switch (exp
->elts
[i
].opcode
)
8229 case BINOP_LOGICAL_AND
:
8230 case BINOP_LOGICAL_OR
:
8231 case BINOP_BITWISE_AND
:
8232 case BINOP_BITWISE_IOR
:
8233 case BINOP_BITWISE_XOR
:
8235 case BINOP_NOTEQUAL
:
8251 case TERNOP_SLICE_COUNT
:
8263 case OP_OBJC_NSSTRING
:
8266 case UNOP_LOGICAL_NOT
:
8267 case UNOP_COMPLEMENT
:
8270 /* Unary, binary and ternary operators: We have to check
8271 their operands. If they are constant, then so is the
8272 result of that operation. For instance, if A and B are
8273 determined to be constants, then so is "A + B".
8275 UNOP_IND is one exception to the rule above, because the
8276 value of *ADDR is not necessarily a constant, even when
8281 /* Check whether the associated symbol is a constant.
8283 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8284 possible that a buggy compiler could mark a variable as
8285 constant even when it is not, and TYPE_CONST would return
8286 true in this case, while SYMBOL_CLASS wouldn't.
8288 We also have to check for function symbols because they
8289 are always constant. */
8291 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8293 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8294 && SYMBOL_CLASS (s
) != LOC_CONST
8295 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8300 /* The default action is to return 0 because we are using
8301 the optimistic approach here: If we don't know something,
8302 then it is not a constant. */
8311 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8314 insert_watchpoint (struct bp_location
*bl
)
8316 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8318 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8319 bl
->owner
->cond_exp
);
8322 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8325 remove_watchpoint (struct bp_location
*bl
)
8327 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8329 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8330 bl
->owner
->cond_exp
);
8333 /* Implement the "resources_needed" breakpoint_ops method for
8334 hardware watchpoints. */
8337 resources_needed_watchpoint (const struct bp_location
*bl
)
8339 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8341 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8344 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8346 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8350 NULL
, /* breakpoint_hit */
8351 resources_needed_watchpoint
,
8352 NULL
, /* print_it */
8353 NULL
, /* print_one */
8354 NULL
, /* print_mention */
8355 NULL
/* print_recreate */
8358 /* accessflag: hw_write: watch write,
8359 hw_read: watch read,
8360 hw_access: watch access (read or write) */
8362 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8363 int just_location
, int internal
)
8365 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8366 struct expression
*exp
;
8367 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8368 struct value
*val
, *mark
, *result
;
8369 struct frame_info
*frame
;
8370 char *exp_start
= NULL
;
8371 char *exp_end
= NULL
;
8372 char *tok
, *id_tok_start
, *end_tok
;
8374 char *cond_start
= NULL
;
8375 char *cond_end
= NULL
;
8376 int i
, other_type_used
, target_resources_ok
= 0;
8377 enum bptype bp_type
;
8382 /* Make sure that we actually have parameters to parse. */
8383 if (arg
!= NULL
&& arg
[0] != '\0')
8385 toklen
= strlen (arg
); /* Size of argument list. */
8387 /* Points tok to the end of the argument list. */
8388 tok
= arg
+ toklen
- 1;
8390 /* Go backwards in the parameters list. Skip the last
8391 parameter. If we're expecting a 'thread <thread_num>'
8392 parameter, this should be the thread identifier. */
8393 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8395 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8398 /* Points end_tok to the beginning of the last token. */
8399 id_tok_start
= tok
+ 1;
8401 /* Go backwards in the parameters list. Skip one more
8402 parameter. If we're expecting a 'thread <thread_num>'
8403 parameter, we should reach a "thread" token. */
8404 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8409 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8412 /* Move the pointer forward to skip the whitespace and
8413 calculate the length of the token. */
8415 toklen
= end_tok
- tok
;
8417 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8419 /* At this point we've found a "thread" token, which means
8420 the user is trying to set a watchpoint that triggers
8421 only in a specific thread. */
8424 /* Extract the thread ID from the next token. */
8425 thread
= strtol (id_tok_start
, &endp
, 0);
8427 /* Check if the user provided a valid numeric value for the
8429 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8430 error (_("Invalid thread ID specification %s."), id_tok_start
);
8432 /* Check if the thread actually exists. */
8433 if (!valid_thread_id (thread
))
8434 error (_("Unknown thread %d."), thread
);
8436 /* Truncate the string and get rid of the thread <thread_num>
8437 parameter before the parameter list is parsed by the
8438 evaluate_expression() function. */
8443 /* Parse the rest of the arguments. */
8444 innermost_block
= NULL
;
8446 exp
= parse_exp_1 (&arg
, 0, 0);
8448 /* Remove trailing whitespace from the expression before saving it.
8449 This makes the eventual display of the expression string a bit
8451 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8454 /* Checking if the expression is not constant. */
8455 if (watchpoint_exp_is_const (exp
))
8459 len
= exp_end
- exp_start
;
8460 while (len
> 0 && isspace (exp_start
[len
- 1]))
8462 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8465 exp_valid_block
= innermost_block
;
8466 mark
= value_mark ();
8467 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8471 exp_valid_block
= NULL
;
8472 val
= value_addr (result
);
8473 release_value (val
);
8474 value_free_to_mark (mark
);
8476 else if (val
!= NULL
)
8477 release_value (val
);
8479 tok
= skip_spaces (arg
);
8480 end_tok
= skip_to_space (tok
);
8482 toklen
= end_tok
- tok
;
8483 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8485 struct expression
*cond
;
8487 innermost_block
= NULL
;
8488 tok
= cond_start
= end_tok
+ 1;
8489 cond
= parse_exp_1 (&tok
, 0, 0);
8491 /* The watchpoint expression may not be local, but the condition
8492 may still be. E.g.: `watch global if local > 0'. */
8493 cond_exp_valid_block
= innermost_block
;
8499 error (_("Junk at end of command."));
8501 if (accessflag
== hw_read
)
8502 bp_type
= bp_read_watchpoint
;
8503 else if (accessflag
== hw_access
)
8504 bp_type
= bp_access_watchpoint
;
8506 bp_type
= bp_hardware_watchpoint
;
8508 reg_cnt
= can_use_hardware_watchpoint (val
, target_exact_watchpoints
);
8509 if (reg_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8510 error (_("Expression cannot be implemented with read/access watchpoint."));
8513 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8514 target_resources_ok
=
8515 target_can_use_hardware_watchpoint (bp_type
, i
+ reg_cnt
,
8517 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8518 error (_("Target does not support this type of hardware watchpoint."));
8520 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8521 error (_("Target can only support one kind "
8522 "of HW watchpoint at a time."));
8525 /* Change the type of breakpoint to an ordinary watchpoint if a
8526 hardware watchpoint could not be set. */
8527 if (!reg_cnt
|| target_resources_ok
<= 0)
8528 bp_type
= bp_watchpoint
;
8530 frame
= block_innermost_frame (exp_valid_block
);
8532 /* If the expression is "local", then set up a "watchpoint scope"
8533 breakpoint at the point where we've left the scope of the watchpoint
8534 expression. Create the scope breakpoint before the watchpoint, so
8535 that we will encounter it first in bpstat_stop_status. */
8536 if (exp_valid_block
&& frame
)
8538 if (frame_id_p (frame_unwind_caller_id (frame
)))
8541 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8542 frame_unwind_caller_pc (frame
),
8543 bp_watchpoint_scope
);
8545 scope_breakpoint
->enable_state
= bp_enabled
;
8547 /* Automatically delete the breakpoint when it hits. */
8548 scope_breakpoint
->disposition
= disp_del
;
8550 /* Only break in the proper frame (help with recursion). */
8551 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8553 /* Set the address at which we will stop. */
8554 scope_breakpoint
->loc
->gdbarch
8555 = frame_unwind_caller_arch (frame
);
8556 scope_breakpoint
->loc
->requested_address
8557 = frame_unwind_caller_pc (frame
);
8558 scope_breakpoint
->loc
->address
8559 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8560 scope_breakpoint
->loc
->requested_address
,
8561 scope_breakpoint
->type
);
8565 /* Now set up the breakpoint. */
8566 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8567 set_breakpoint_number (internal
, b
);
8569 b
->disposition
= disp_donttouch
;
8571 b
->exp_valid_block
= exp_valid_block
;
8572 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8575 struct type
*t
= value_type (val
);
8576 CORE_ADDR addr
= value_as_address (val
);
8579 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8580 name
= type_to_string (t
);
8582 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8583 core_addr_to_string (addr
));
8586 b
->exp_string
= xstrprintf ("-location: %.*s",
8587 (int) (exp_end
- exp_start
), exp_start
);
8589 /* The above expression is in C. */
8590 b
->language
= language_c
;
8593 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8596 b
->ops
= &watchpoint_breakpoint_ops
;
8598 /* Use an exact watchpoint when there's only one memory region to be
8599 watched, and only one debug register is needed to watch it. */
8600 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
8603 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8609 b
->watchpoint_frame
= get_frame_id (frame
);
8610 b
->watchpoint_thread
= inferior_ptid
;
8614 b
->watchpoint_frame
= null_frame_id
;
8615 b
->watchpoint_thread
= null_ptid
;
8618 if (scope_breakpoint
!= NULL
)
8620 /* The scope breakpoint is related to the watchpoint. We will
8621 need to act on them together. */
8622 b
->related_breakpoint
= scope_breakpoint
;
8623 scope_breakpoint
->related_breakpoint
= b
;
8627 value_free_to_mark (mark
);
8629 /* Finally update the new watchpoint. This creates the locations
8630 that should be inserted. */
8631 update_watchpoint (b
, 1);
8633 /* Do not mention breakpoints with a negative number, but do
8634 notify observers. */
8635 observer_notify_breakpoint_created (b
->number
);
8638 update_global_location_list (1);
8641 /* Return count of debug registers needed to watch the given expression.
8642 If EXACT_WATCHPOINTS is 1, then consider that only the address of
8643 the start of the watched region will be monitored (i.e., all accesses
8644 will be aligned). This uses less debug registers on some targets.
8646 If the watchpoint cannot be handled in hardware return zero. */
8649 can_use_hardware_watchpoint (struct value
*v
, int exact_watchpoints
)
8651 int found_memory_cnt
= 0;
8652 struct value
*head
= v
;
8654 /* Did the user specifically forbid us to use hardware watchpoints? */
8655 if (!can_use_hw_watchpoints
)
8658 /* Make sure that the value of the expression depends only upon
8659 memory contents, and values computed from them within GDB. If we
8660 find any register references or function calls, we can't use a
8661 hardware watchpoint.
8663 The idea here is that evaluating an expression generates a series
8664 of values, one holding the value of every subexpression. (The
8665 expression a*b+c has five subexpressions: a, b, a*b, c, and
8666 a*b+c.) GDB's values hold almost enough information to establish
8667 the criteria given above --- they identify memory lvalues,
8668 register lvalues, computed values, etcetera. So we can evaluate
8669 the expression, and then scan the chain of values that leaves
8670 behind to decide whether we can detect any possible change to the
8671 expression's final value using only hardware watchpoints.
8673 However, I don't think that the values returned by inferior
8674 function calls are special in any way. So this function may not
8675 notice that an expression involving an inferior function call
8676 can't be watched with hardware watchpoints. FIXME. */
8677 for (; v
; v
= value_next (v
))
8679 if (VALUE_LVAL (v
) == lval_memory
)
8681 if (v
!= head
&& value_lazy (v
))
8682 /* A lazy memory lvalue in the chain is one that GDB never
8683 needed to fetch; we either just used its address (e.g.,
8684 `a' in `a.b') or we never needed it at all (e.g., `a'
8685 in `a,b'). This doesn't apply to HEAD; if that is
8686 lazy then it was not readable, but watch it anyway. */
8690 /* Ahh, memory we actually used! Check if we can cover
8691 it with hardware watchpoints. */
8692 struct type
*vtype
= check_typedef (value_type (v
));
8694 /* We only watch structs and arrays if user asked for it
8695 explicitly, never if they just happen to appear in a
8696 middle of some value chain. */
8698 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8699 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8701 CORE_ADDR vaddr
= value_address (v
);
8705 len
= (exact_watchpoints
8706 && is_scalar_type_recursive (vtype
))?
8707 1 : TYPE_LENGTH (value_type (v
));
8709 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
8713 found_memory_cnt
+= num_regs
;
8717 else if (VALUE_LVAL (v
) != not_lval
8718 && deprecated_value_modifiable (v
) == 0)
8719 return 0; /* These are values from the history (e.g., $1). */
8720 else if (VALUE_LVAL (v
) == lval_register
)
8721 return 0; /* Cannot watch a register with a HW watchpoint. */
8724 /* The expression itself looks suitable for using a hardware
8725 watchpoint, but give the target machine a chance to reject it. */
8726 return found_memory_cnt
;
8730 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8732 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8735 /* A helper function that looks for an argument at the start of a
8736 string. The argument must also either be at the end of the string,
8737 or be followed by whitespace. Returns 1 if it finds the argument,
8738 0 otherwise. If the argument is found, it updates *STR. */
8741 check_for_argument (char **str
, char *arg
, int arg_len
)
8743 if (strncmp (*str
, arg
, arg_len
) == 0
8744 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8752 /* A helper function that looks for the "-location" argument and then
8753 calls watch_command_1. */
8756 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8758 int just_location
= 0;
8761 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8762 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8764 arg
= skip_spaces (arg
);
8768 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8772 watch_command (char *arg
, int from_tty
)
8774 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8778 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8780 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8784 rwatch_command (char *arg
, int from_tty
)
8786 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8790 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8792 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8796 awatch_command (char *arg
, int from_tty
)
8798 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8802 /* Helper routines for the until_command routine in infcmd.c. Here
8803 because it uses the mechanisms of breakpoints. */
8805 struct until_break_command_continuation_args
8807 struct breakpoint
*breakpoint
;
8808 struct breakpoint
*breakpoint2
;
8812 /* This function is called by fetch_inferior_event via the
8813 cmd_continuation pointer, to complete the until command. It takes
8814 care of cleaning up the temporary breakpoints set up by the until
8817 until_break_command_continuation (void *arg
)
8819 struct until_break_command_continuation_args
*a
= arg
;
8821 delete_breakpoint (a
->breakpoint
);
8823 delete_breakpoint (a
->breakpoint2
);
8824 delete_longjmp_breakpoint (a
->thread_num
);
8828 until_break_command (char *arg
, int from_tty
, int anywhere
)
8830 struct symtabs_and_lines sals
;
8831 struct symtab_and_line sal
;
8832 struct frame_info
*frame
= get_selected_frame (NULL
);
8833 struct breakpoint
*breakpoint
;
8834 struct breakpoint
*breakpoint2
= NULL
;
8835 struct cleanup
*old_chain
;
8837 struct thread_info
*tp
;
8839 clear_proceed_status ();
8841 /* Set a breakpoint where the user wants it and at return from
8844 if (default_breakpoint_valid
)
8845 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8846 default_breakpoint_line
, (char ***) NULL
, NULL
);
8848 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8849 0, (char ***) NULL
, NULL
);
8851 if (sals
.nelts
!= 1)
8852 error (_("Couldn't get information on specified line."));
8855 xfree (sals
.sals
); /* malloc'd, so freed. */
8858 error (_("Junk at end of arguments."));
8860 resolve_sal_pc (&sal
);
8863 /* If the user told us to continue until a specified location,
8864 we don't specify a frame at which we need to stop. */
8865 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8866 null_frame_id
, bp_until
);
8868 /* Otherwise, specify the selected frame, because we want to stop
8869 only at the very same frame. */
8870 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8871 get_stack_frame_id (frame
),
8874 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8876 tp
= inferior_thread ();
8879 /* Keep within the current frame, or in frames called by the current
8882 if (frame_id_p (frame_unwind_caller_id (frame
)))
8884 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8885 sal
.pc
= frame_unwind_caller_pc (frame
);
8886 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8888 frame_unwind_caller_id (frame
),
8890 make_cleanup_delete_breakpoint (breakpoint2
);
8892 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
8893 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
8896 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8898 /* If we are running asynchronously, and proceed call above has
8899 actually managed to start the target, arrange for breakpoints to
8900 be deleted when the target stops. Otherwise, we're already
8901 stopped and delete breakpoints via cleanup chain. */
8903 if (target_can_async_p () && is_running (inferior_ptid
))
8905 struct until_break_command_continuation_args
*args
;
8906 args
= xmalloc (sizeof (*args
));
8908 args
->breakpoint
= breakpoint
;
8909 args
->breakpoint2
= breakpoint2
;
8910 args
->thread_num
= thread
;
8912 discard_cleanups (old_chain
);
8913 add_continuation (inferior_thread (),
8914 until_break_command_continuation
, args
,
8918 do_cleanups (old_chain
);
8921 /* This function attempts to parse an optional "if <cond>" clause
8922 from the arg string. If one is not found, it returns NULL.
8924 Else, it returns a pointer to the condition string. (It does not
8925 attempt to evaluate the string against a particular block.) And,
8926 it updates arg to point to the first character following the parsed
8927 if clause in the arg string. */
8930 ep_parse_optional_if_clause (char **arg
)
8934 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8937 /* Skip the "if" keyword. */
8940 /* Skip any extra leading whitespace, and record the start of the
8941 condition string. */
8942 *arg
= skip_spaces (*arg
);
8945 /* Assume that the condition occupies the remainder of the arg
8947 (*arg
) += strlen (cond_string
);
8952 /* Commands to deal with catching events, such as signals, exceptions,
8953 process start/exit, etc. */
8957 catch_fork_temporary
, catch_vfork_temporary
,
8958 catch_fork_permanent
, catch_vfork_permanent
8963 catch_fork_command_1 (char *arg
, int from_tty
,
8964 struct cmd_list_element
*command
)
8966 struct gdbarch
*gdbarch
= get_current_arch ();
8967 char *cond_string
= NULL
;
8968 catch_fork_kind fork_kind
;
8971 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8972 tempflag
= (fork_kind
== catch_fork_temporary
8973 || fork_kind
== catch_vfork_temporary
);
8977 arg
= skip_spaces (arg
);
8979 /* The allowed syntax is:
8981 catch [v]fork if <cond>
8983 First, check if there's an if clause. */
8984 cond_string
= ep_parse_optional_if_clause (&arg
);
8986 if ((*arg
!= '\0') && !isspace (*arg
))
8987 error (_("Junk at end of arguments."));
8989 /* If this target supports it, create a fork or vfork catchpoint
8990 and enable reporting of such events. */
8993 case catch_fork_temporary
:
8994 case catch_fork_permanent
:
8995 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8996 &catch_fork_breakpoint_ops
);
8998 case catch_vfork_temporary
:
8999 case catch_vfork_permanent
:
9000 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9001 &catch_vfork_breakpoint_ops
);
9004 error (_("unsupported or unknown fork kind; cannot catch it"));
9010 catch_exec_command_1 (char *arg
, int from_tty
,
9011 struct cmd_list_element
*command
)
9013 struct gdbarch
*gdbarch
= get_current_arch ();
9015 char *cond_string
= NULL
;
9017 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9021 arg
= skip_spaces (arg
);
9023 /* The allowed syntax is:
9025 catch exec if <cond>
9027 First, check if there's an if clause. */
9028 cond_string
= ep_parse_optional_if_clause (&arg
);
9030 if ((*arg
!= '\0') && !isspace (*arg
))
9031 error (_("Junk at end of arguments."));
9033 /* If this target supports it, create an exec catchpoint
9034 and enable reporting of such events. */
9035 create_catchpoint (gdbarch
, tempflag
, cond_string
,
9036 &catch_exec_breakpoint_ops
);
9039 static enum print_stop_action
9040 print_exception_catchpoint (struct breakpoint
*b
)
9042 int bp_temp
, bp_throw
;
9044 annotate_catchpoint (b
->number
);
9046 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9047 if (b
->loc
->address
!= b
->loc
->requested_address
)
9048 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9051 bp_temp
= b
->disposition
== disp_del
;
9053 bp_temp
? "Temporary catchpoint "
9055 if (!ui_out_is_mi_like_p (uiout
))
9056 ui_out_field_int (uiout
, "bkptno", b
->number
);
9058 bp_throw
? " (exception thrown), "
9059 : " (exception caught), ");
9060 if (ui_out_is_mi_like_p (uiout
))
9062 ui_out_field_string (uiout
, "reason",
9063 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9064 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9065 ui_out_field_int (uiout
, "bkptno", b
->number
);
9067 return PRINT_SRC_AND_LOC
;
9071 print_one_exception_catchpoint (struct breakpoint
*b
,
9072 struct bp_location
**last_loc
)
9074 struct value_print_options opts
;
9076 get_user_print_options (&opts
);
9077 if (opts
.addressprint
)
9080 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9081 ui_out_field_string (uiout
, "addr", "<PENDING>");
9083 ui_out_field_core_addr (uiout
, "addr",
9084 b
->loc
->gdbarch
, b
->loc
->address
);
9089 if (strstr (b
->addr_string
, "throw") != NULL
)
9090 ui_out_field_string (uiout
, "what", "exception throw");
9092 ui_out_field_string (uiout
, "what", "exception catch");
9096 print_mention_exception_catchpoint (struct breakpoint
*b
)
9101 bp_temp
= b
->disposition
== disp_del
;
9102 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9103 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9104 : _("Catchpoint "));
9105 ui_out_field_int (uiout
, "bkptno", b
->number
);
9106 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9110 /* Implement the "print_recreate" breakpoint_ops method for throw and
9111 catch catchpoints. */
9114 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9120 bp_temp
= b
->disposition
== disp_del
;
9121 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9122 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9123 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9126 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9129 NULL
, /* breakpoint_hit */
9130 NULL
, /* resources_needed */
9131 print_exception_catchpoint
,
9132 print_one_exception_catchpoint
,
9133 print_mention_exception_catchpoint
,
9134 print_recreate_exception_catchpoint
9138 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9139 enum exception_event_kind ex_event
, int from_tty
)
9141 char *trigger_func_name
;
9143 if (ex_event
== EX_EVENT_CATCH
)
9144 trigger_func_name
= "__cxa_begin_catch";
9146 trigger_func_name
= "__cxa_throw";
9148 create_breakpoint (get_current_arch (),
9149 trigger_func_name
, cond_string
, -1,
9150 0 /* condition and thread are valid. */,
9151 tempflag
, bp_breakpoint
,
9153 AUTO_BOOLEAN_TRUE
/* pending */,
9154 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9161 /* Deal with "catch catch" and "catch throw" commands. */
9164 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9165 int tempflag
, int from_tty
)
9167 char *cond_string
= NULL
;
9171 arg
= skip_spaces (arg
);
9173 cond_string
= ep_parse_optional_if_clause (&arg
);
9175 if ((*arg
!= '\0') && !isspace (*arg
))
9176 error (_("Junk at end of arguments."));
9178 if (ex_event
!= EX_EVENT_THROW
9179 && ex_event
!= EX_EVENT_CATCH
)
9180 error (_("Unsupported or unknown exception event; cannot catch it"));
9182 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9185 warning (_("Unsupported with this platform/compiler combination."));
9188 /* Implementation of "catch catch" command. */
9191 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9193 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9195 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9198 /* Implementation of "catch throw" command. */
9201 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9203 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9205 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9208 /* Create a breakpoint struct for Ada exception catchpoints. */
9211 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9212 struct symtab_and_line sal
,
9216 struct expression
*cond
,
9217 struct breakpoint_ops
*ops
,
9221 struct breakpoint
*b
;
9225 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9227 loc_gdbarch
= gdbarch
;
9229 describe_other_breakpoints (loc_gdbarch
,
9230 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9231 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9232 version for exception catchpoints, because two catchpoints
9233 used for different exception names will use the same address.
9234 In this case, a "breakpoint ... also set at..." warning is
9235 unproductive. Besides, the warning phrasing is also a bit
9236 inapropriate, we should use the word catchpoint, and tell
9237 the user what type of catchpoint it is. The above is good
9238 enough for now, though. */
9241 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9242 set_breakpoint_count (breakpoint_count
+ 1);
9244 b
->enable_state
= bp_enabled
;
9245 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9246 b
->number
= breakpoint_count
;
9247 b
->ignore_count
= 0;
9248 b
->loc
->cond
= cond
;
9249 b
->addr_string
= addr_string
;
9250 b
->language
= language_ada
;
9251 b
->cond_string
= cond_string
;
9252 b
->exp_string
= exp_string
;
9257 update_global_location_list (1);
9260 /* Implement the "catch exception" command. */
9263 catch_ada_exception_command (char *arg
, int from_tty
,
9264 struct cmd_list_element
*command
)
9266 struct gdbarch
*gdbarch
= get_current_arch ();
9268 struct symtab_and_line sal
;
9269 char *addr_string
= NULL
;
9270 char *exp_string
= NULL
;
9271 char *cond_string
= NULL
;
9272 struct expression
*cond
= NULL
;
9273 struct breakpoint_ops
*ops
= NULL
;
9275 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9279 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9280 &cond_string
, &cond
, &ops
);
9281 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9282 cond_string
, cond
, ops
, tempflag
,
9286 /* Cleanup function for a syscall filter list. */
9288 clean_up_filters (void *arg
)
9290 VEC(int) *iter
= *(VEC(int) **) arg
;
9291 VEC_free (int, iter
);
9294 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9295 filter list, or NULL if no filtering is required. */
9297 catch_syscall_split_args (char *arg
)
9299 VEC(int) *result
= NULL
;
9300 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9302 while (*arg
!= '\0')
9304 int i
, syscall_number
;
9309 /* Skip whitespace. */
9310 while (isspace (*arg
))
9313 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9314 cur_name
[i
] = arg
[i
];
9318 /* Check if the user provided a syscall name or a number. */
9319 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9320 if (*endptr
== '\0')
9321 get_syscall_by_number (syscall_number
, &s
);
9324 /* We have a name. Let's check if it's valid and convert it
9326 get_syscall_by_name (cur_name
, &s
);
9328 if (s
.number
== UNKNOWN_SYSCALL
)
9329 /* Here we have to issue an error instead of a warning,
9330 because GDB cannot do anything useful if there's no
9331 syscall number to be caught. */
9332 error (_("Unknown syscall name '%s'."), cur_name
);
9335 /* Ok, it's valid. */
9336 VEC_safe_push (int, result
, s
.number
);
9339 discard_cleanups (cleanup
);
9343 /* Implement the "catch syscall" command. */
9346 catch_syscall_command_1 (char *arg
, int from_tty
,
9347 struct cmd_list_element
*command
)
9352 struct gdbarch
*gdbarch
= get_current_arch ();
9354 /* Checking if the feature if supported. */
9355 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9356 error (_("The feature 'catch syscall' is not supported on \
9357 this architecture yet."));
9359 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9361 arg
= skip_spaces (arg
);
9363 /* We need to do this first "dummy" translation in order
9364 to get the syscall XML file loaded or, most important,
9365 to display a warning to the user if there's no XML file
9366 for his/her architecture. */
9367 get_syscall_by_number (0, &s
);
9369 /* The allowed syntax is:
9371 catch syscall <name | number> [<name | number> ... <name | number>]
9373 Let's check if there's a syscall name. */
9376 filter
= catch_syscall_split_args (arg
);
9380 create_syscall_event_catchpoint (tempflag
, filter
,
9381 &catch_syscall_breakpoint_ops
);
9384 /* Implement the "catch assert" command. */
9387 catch_assert_command (char *arg
, int from_tty
,
9388 struct cmd_list_element
*command
)
9390 struct gdbarch
*gdbarch
= get_current_arch ();
9392 struct symtab_and_line sal
;
9393 char *addr_string
= NULL
;
9394 struct breakpoint_ops
*ops
= NULL
;
9396 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9400 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9401 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9402 ops
, tempflag
, from_tty
);
9406 catch_command (char *arg
, int from_tty
)
9408 error (_("Catch requires an event name."));
9413 tcatch_command (char *arg
, int from_tty
)
9415 error (_("Catch requires an event name."));
9418 /* Delete breakpoints by address or line. */
9421 clear_command (char *arg
, int from_tty
)
9423 struct breakpoint
*b
;
9424 VEC(breakpoint_p
) *found
= 0;
9427 struct symtabs_and_lines sals
;
9428 struct symtab_and_line sal
;
9433 sals
= decode_line_spec (arg
, 1);
9438 sals
.sals
= (struct symtab_and_line
*)
9439 xmalloc (sizeof (struct symtab_and_line
));
9440 make_cleanup (xfree
, sals
.sals
);
9441 init_sal (&sal
); /* Initialize to zeroes. */
9442 sal
.line
= default_breakpoint_line
;
9443 sal
.symtab
= default_breakpoint_symtab
;
9444 sal
.pc
= default_breakpoint_address
;
9445 sal
.pspace
= default_breakpoint_pspace
;
9446 if (sal
.symtab
== 0)
9447 error (_("No source file specified."));
9455 /* We don't call resolve_sal_pc here. That's not as bad as it
9456 seems, because all existing breakpoints typically have both
9457 file/line and pc set. So, if clear is given file/line, we can
9458 match this to existing breakpoint without obtaining pc at all.
9460 We only support clearing given the address explicitly
9461 present in breakpoint table. Say, we've set breakpoint
9462 at file:line. There were several PC values for that file:line,
9463 due to optimization, all in one block.
9465 We've picked one PC value. If "clear" is issued with another
9466 PC corresponding to the same file:line, the breakpoint won't
9467 be cleared. We probably can still clear the breakpoint, but
9468 since the other PC value is never presented to user, user
9469 can only find it by guessing, and it does not seem important
9472 /* For each line spec given, delete bps which correspond to it. Do
9473 it in two passes, solely to preserve the current behavior that
9474 from_tty is forced true if we delete more than one
9478 for (i
= 0; i
< sals
.nelts
; i
++)
9480 /* If exact pc given, clear bpts at that pc.
9481 If line given (pc == 0), clear all bpts on specified line.
9482 If defaulting, clear all bpts on default line
9485 defaulting sal.pc != 0 tests to do
9490 1 0 <can't happen> */
9494 /* Find all matching breakpoints and add them to 'found'. */
9498 /* Are we going to delete b? */
9499 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9501 struct bp_location
*loc
= b
->loc
;
9502 for (; loc
; loc
= loc
->next
)
9504 int pc_match
= sal
.pc
9505 && (loc
->pspace
== sal
.pspace
)
9506 && (loc
->address
== sal
.pc
)
9507 && (!section_is_overlay (loc
->section
)
9508 || loc
->section
== sal
.section
);
9509 int line_match
= ((default_match
|| (0 == sal
.pc
))
9510 && b
->source_file
!= NULL
9511 && sal
.symtab
!= NULL
9512 && sal
.pspace
== loc
->pspace
9513 && strcmp (b
->source_file
,
9514 sal
.symtab
->filename
) == 0
9515 && b
->line_number
== sal
.line
);
9516 if (pc_match
|| line_match
)
9525 VEC_safe_push(breakpoint_p
, found
, b
);
9528 /* Now go thru the 'found' chain and delete them. */
9529 if (VEC_empty(breakpoint_p
, found
))
9532 error (_("No breakpoint at %s."), arg
);
9534 error (_("No breakpoint at this line."));
9537 if (VEC_length(breakpoint_p
, found
) > 1)
9538 from_tty
= 1; /* Always report if deleted more than one. */
9541 if (VEC_length(breakpoint_p
, found
) == 1)
9542 printf_unfiltered (_("Deleted breakpoint "));
9544 printf_unfiltered (_("Deleted breakpoints "));
9546 breakpoints_changed ();
9548 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9551 printf_unfiltered ("%d ", b
->number
);
9552 delete_breakpoint (b
);
9555 putchar_unfiltered ('\n');
9558 /* Delete breakpoint in BS if they are `delete' breakpoints and
9559 all breakpoints that are marked for deletion, whether hit or not.
9560 This is called after any breakpoint is hit, or after errors. */
9563 breakpoint_auto_delete (bpstat bs
)
9565 struct breakpoint
*b
, *b_tmp
;
9567 for (; bs
; bs
= bs
->next
)
9568 if (bs
->breakpoint_at
9569 && bs
->breakpoint_at
->disposition
== disp_del
9571 delete_breakpoint (bs
->breakpoint_at
);
9573 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9575 if (b
->disposition
== disp_del_at_next_stop
)
9576 delete_breakpoint (b
);
9580 /* A comparison function for bp_location AP and BP being interfaced to
9581 qsort. Sort elements primarily by their ADDRESS (no matter what
9582 does breakpoint_address_is_meaningful say for its OWNER),
9583 secondarily by ordering first bp_permanent OWNERed elements and
9584 terciarily just ensuring the array is sorted stable way despite
9585 qsort being an instable algorithm. */
9588 bp_location_compare (const void *ap
, const void *bp
)
9590 struct bp_location
*a
= *(void **) ap
;
9591 struct bp_location
*b
= *(void **) bp
;
9592 /* A and B come from existing breakpoints having non-NULL OWNER. */
9593 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9594 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9596 if (a
->address
!= b
->address
)
9597 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9599 /* Sort permanent breakpoints first. */
9600 if (a_perm
!= b_perm
)
9601 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9603 /* Make the user-visible order stable across GDB runs. Locations of
9604 the same breakpoint can be sorted in arbitrary order. */
9606 if (a
->owner
->number
!= b
->owner
->number
)
9607 return (a
->owner
->number
> b
->owner
->number
)
9608 - (a
->owner
->number
< b
->owner
->number
);
9610 return (a
> b
) - (a
< b
);
9613 /* Set bp_location_placed_address_before_address_max and
9614 bp_location_shadow_len_after_address_max according to the current
9615 content of the bp_location array. */
9618 bp_location_target_extensions_update (void)
9620 struct bp_location
*bl
, **blp_tmp
;
9622 bp_location_placed_address_before_address_max
= 0;
9623 bp_location_shadow_len_after_address_max
= 0;
9625 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9627 CORE_ADDR start
, end
, addr
;
9629 if (!bp_location_has_shadow (bl
))
9632 start
= bl
->target_info
.placed_address
;
9633 end
= start
+ bl
->target_info
.shadow_len
;
9635 gdb_assert (bl
->address
>= start
);
9636 addr
= bl
->address
- start
;
9637 if (addr
> bp_location_placed_address_before_address_max
)
9638 bp_location_placed_address_before_address_max
= addr
;
9640 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9642 gdb_assert (bl
->address
< end
);
9643 addr
= end
- bl
->address
;
9644 if (addr
> bp_location_shadow_len_after_address_max
)
9645 bp_location_shadow_len_after_address_max
= addr
;
9649 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9650 into the inferior, only remove already-inserted locations that no
9651 longer should be inserted. Functions that delete a breakpoint or
9652 breakpoints should pass false, so that deleting a breakpoint
9653 doesn't have the side effect of inserting the locations of other
9654 breakpoints that are marked not-inserted, but should_be_inserted
9655 returns true on them.
9657 This behaviour is useful is situations close to tear-down -- e.g.,
9658 after an exec, while the target still has execution, but breakpoint
9659 shadows of the previous executable image should *NOT* be restored
9660 to the new image; or before detaching, where the target still has
9661 execution and wants to delete breakpoints from GDB's lists, and all
9662 breakpoints had already been removed from the inferior. */
9665 update_global_location_list (int should_insert
)
9667 struct breakpoint
*b
;
9668 struct bp_location
**locp
, *loc
;
9669 struct cleanup
*cleanups
;
9671 /* Used in the duplicates detection below. When iterating over all
9672 bp_locations, points to the first bp_location of a given address.
9673 Breakpoints and watchpoints of different types are never
9674 duplicates of each other. Keep one pointer for each type of
9675 breakpoint/watchpoint, so we only need to loop over all locations
9677 struct bp_location
*bp_loc_first
; /* breakpoint */
9678 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9679 struct bp_location
*awp_loc_first
; /* access watchpoint */
9680 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9682 /* Saved former bp_location array which we compare against the newly
9683 built bp_location from the current state of ALL_BREAKPOINTS. */
9684 struct bp_location
**old_location
, **old_locp
;
9685 unsigned old_location_count
;
9687 old_location
= bp_location
;
9688 old_location_count
= bp_location_count
;
9690 bp_location_count
= 0;
9691 cleanups
= make_cleanup (xfree
, old_location
);
9694 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9695 bp_location_count
++;
9697 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9700 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9702 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9703 bp_location_compare
);
9705 bp_location_target_extensions_update ();
9707 /* Identify bp_location instances that are no longer present in the
9708 new list, and therefore should be freed. Note that it's not
9709 necessary that those locations should be removed from inferior --
9710 if there's another location at the same address (previously
9711 marked as duplicate), we don't need to remove/insert the
9714 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9715 and former bp_location array state respectively. */
9718 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9721 struct bp_location
*old_loc
= *old_locp
;
9722 struct bp_location
**loc2p
;
9724 /* Tells if 'old_loc' is found amoung the new locations. If
9725 not, we have to free it. */
9726 int found_object
= 0;
9727 /* Tells if the location should remain inserted in the target. */
9728 int keep_in_target
= 0;
9731 /* Skip LOCP entries which will definitely never be needed.
9732 Stop either at or being the one matching OLD_LOC. */
9733 while (locp
< bp_location
+ bp_location_count
9734 && (*locp
)->address
< old_loc
->address
)
9738 (loc2p
< bp_location
+ bp_location_count
9739 && (*loc2p
)->address
== old_loc
->address
);
9742 if (*loc2p
== old_loc
)
9749 /* If this location is no longer present, and inserted, look if
9750 there's maybe a new location at the same address. If so,
9751 mark that one inserted, and don't remove this one. This is
9752 needed so that we don't have a time window where a breakpoint
9753 at certain location is not inserted. */
9755 if (old_loc
->inserted
)
9757 /* If the location is inserted now, we might have to remove
9760 if (found_object
&& should_be_inserted (old_loc
))
9762 /* The location is still present in the location list,
9763 and still should be inserted. Don't do anything. */
9768 /* The location is either no longer present, or got
9769 disabled. See if there's another location at the
9770 same address, in which case we don't need to remove
9771 this one from the target. */
9773 /* OLD_LOC comes from existing struct breakpoint. */
9774 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9777 (loc2p
< bp_location
+ bp_location_count
9778 && (*loc2p
)->address
== old_loc
->address
);
9781 struct bp_location
*loc2
= *loc2p
;
9783 if (breakpoint_locations_match (loc2
, old_loc
))
9785 /* For the sake of should_be_inserted.
9786 Duplicates check below will fix up this
9788 loc2
->duplicate
= 0;
9790 /* Read watchpoint locations are switched to
9791 access watchpoints, if the former are not
9792 supported, but the latter are. */
9793 if (is_hardware_watchpoint (old_loc
->owner
))
9795 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9796 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9799 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9802 loc2
->target_info
= old_loc
->target_info
;
9811 if (!keep_in_target
)
9813 if (remove_breakpoint (old_loc
, mark_uninserted
))
9815 /* This is just about all we can do. We could keep
9816 this location on the global list, and try to
9817 remove it next time, but there's no particular
9818 reason why we will succeed next time.
9820 Note that at this point, old_loc->owner is still
9821 valid, as delete_breakpoint frees the breakpoint
9822 only after calling us. */
9823 printf_filtered (_("warning: Error removing "
9825 old_loc
->owner
->number
);
9833 if (removed
&& non_stop
9834 && breakpoint_address_is_meaningful (old_loc
->owner
)
9835 && !is_hardware_watchpoint (old_loc
->owner
))
9837 /* This location was removed from the target. In
9838 non-stop mode, a race condition is possible where
9839 we've removed a breakpoint, but stop events for that
9840 breakpoint are already queued and will arrive later.
9841 We apply an heuristic to be able to distinguish such
9842 SIGTRAPs from other random SIGTRAPs: we keep this
9843 breakpoint location for a bit, and will retire it
9844 after we see some number of events. The theory here
9845 is that reporting of events should, "on the average",
9846 be fair, so after a while we'll see events from all
9847 threads that have anything of interest, and no longer
9848 need to keep this breakpoint location around. We
9849 don't hold locations forever so to reduce chances of
9850 mistaking a non-breakpoint SIGTRAP for a breakpoint
9853 The heuristic failing can be disastrous on
9854 decr_pc_after_break targets.
9856 On decr_pc_after_break targets, like e.g., x86-linux,
9857 if we fail to recognize a late breakpoint SIGTRAP,
9858 because events_till_retirement has reached 0 too
9859 soon, we'll fail to do the PC adjustment, and report
9860 a random SIGTRAP to the user. When the user resumes
9861 the inferior, it will most likely immediately crash
9862 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9863 corrupted, because of being resumed e.g., in the
9864 middle of a multi-byte instruction, or skipped a
9865 one-byte instruction. This was actually seen happen
9866 on native x86-linux, and should be less rare on
9867 targets that do not support new thread events, like
9868 remote, due to the heuristic depending on
9871 Mistaking a random SIGTRAP for a breakpoint trap
9872 causes similar symptoms (PC adjustment applied when
9873 it shouldn't), but then again, playing with SIGTRAPs
9874 behind the debugger's back is asking for trouble.
9876 Since hardware watchpoint traps are always
9877 distinguishable from other traps, so we don't need to
9878 apply keep hardware watchpoint moribund locations
9879 around. We simply always ignore hardware watchpoint
9880 traps we can no longer explain. */
9882 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9883 old_loc
->owner
= NULL
;
9885 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9889 old_loc
->owner
= NULL
;
9890 decref_bp_location (&old_loc
);
9895 /* Rescan breakpoints at the same address and section, marking the
9896 first one as "first" and any others as "duplicates". This is so
9897 that the bpt instruction is only inserted once. If we have a
9898 permanent breakpoint at the same place as BPT, make that one the
9899 official one, and the rest as duplicates. Permanent breakpoints
9900 are sorted first for the same address.
9902 Do the same for hardware watchpoints, but also considering the
9903 watchpoint's type (regular/access/read) and length. */
9905 bp_loc_first
= NULL
;
9906 wp_loc_first
= NULL
;
9907 awp_loc_first
= NULL
;
9908 rwp_loc_first
= NULL
;
9909 ALL_BP_LOCATIONS (loc
, locp
)
9911 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
9913 struct breakpoint
*b
= loc
->owner
;
9914 struct bp_location
**loc_first_p
;
9916 if (b
->enable_state
== bp_disabled
9917 || b
->enable_state
== bp_call_disabled
9918 || b
->enable_state
== bp_startup_disabled
9920 || loc
->shlib_disabled
9921 || !breakpoint_address_is_meaningful (b
)
9922 || is_tracepoint (b
))
9925 /* Permanent breakpoint should always be inserted. */
9926 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9927 internal_error (__FILE__
, __LINE__
,
9928 _("allegedly permanent breakpoint is not "
9929 "actually inserted"));
9931 if (b
->type
== bp_hardware_watchpoint
)
9932 loc_first_p
= &wp_loc_first
;
9933 else if (b
->type
== bp_read_watchpoint
)
9934 loc_first_p
= &rwp_loc_first
;
9935 else if (b
->type
== bp_access_watchpoint
)
9936 loc_first_p
= &awp_loc_first
;
9938 loc_first_p
= &bp_loc_first
;
9940 if (*loc_first_p
== NULL
9941 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9942 || !breakpoint_locations_match (loc
, *loc_first_p
))
9951 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9952 && b
->enable_state
!= bp_permanent
)
9953 internal_error (__FILE__
, __LINE__
,
9954 _("another breakpoint was inserted on top of "
9955 "a permanent breakpoint"));
9958 if (breakpoints_always_inserted_mode () && should_insert
9959 && (have_live_inferiors ()
9960 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9961 insert_breakpoint_locations ();
9963 do_cleanups (cleanups
);
9967 breakpoint_retire_moribund (void)
9969 struct bp_location
*loc
;
9972 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9973 if (--(loc
->events_till_retirement
) == 0)
9975 decref_bp_location (&loc
);
9976 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9982 update_global_location_list_nothrow (int inserting
)
9984 struct gdb_exception e
;
9986 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9987 update_global_location_list (inserting
);
9990 /* Clear BKP from a BPS. */
9993 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
9997 for (bs
= bps
; bs
; bs
= bs
->next
)
9998 if (bs
->breakpoint_at
== bpt
)
10000 bs
->breakpoint_at
= NULL
;
10001 bs
->old_val
= NULL
;
10002 /* bs->commands will be freed later. */
10006 /* Callback for iterate_over_threads. */
10008 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10010 struct breakpoint
*bpt
= data
;
10012 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10016 /* Delete a breakpoint and clean up all traces of it in the data
10020 delete_breakpoint (struct breakpoint
*bpt
)
10022 struct breakpoint
*b
;
10024 gdb_assert (bpt
!= NULL
);
10026 /* Has this bp already been deleted? This can happen because
10027 multiple lists can hold pointers to bp's. bpstat lists are
10030 One example of this happening is a watchpoint's scope bp. When
10031 the scope bp triggers, we notice that the watchpoint is out of
10032 scope, and delete it. We also delete its scope bp. But the
10033 scope bp is marked "auto-deleting", and is already on a bpstat.
10034 That bpstat is then checked for auto-deleting bp's, which are
10037 A real solution to this problem might involve reference counts in
10038 bp's, and/or giving them pointers back to their referencing
10039 bpstat's, and teaching delete_breakpoint to only free a bp's
10040 storage when no more references were extent. A cheaper bandaid
10042 if (bpt
->type
== bp_none
)
10045 /* At least avoid this stale reference until the reference counting
10046 of breakpoints gets resolved. */
10047 if (bpt
->related_breakpoint
!= NULL
)
10049 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
10050 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
10051 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
10052 bpt
->related_breakpoint
= NULL
;
10055 observer_notify_breakpoint_deleted (bpt
->number
);
10057 if (breakpoint_chain
== bpt
)
10058 breakpoint_chain
= bpt
->next
;
10060 ALL_BREAKPOINTS (b
)
10061 if (b
->next
== bpt
)
10063 b
->next
= bpt
->next
;
10067 decref_counted_command_line (&bpt
->commands
);
10068 xfree (bpt
->cond_string
);
10069 xfree (bpt
->cond_exp
);
10070 xfree (bpt
->addr_string
);
10072 xfree (bpt
->exp_string
);
10073 xfree (bpt
->exp_string_reparse
);
10074 value_free (bpt
->val
);
10075 xfree (bpt
->source_file
);
10076 xfree (bpt
->exec_pathname
);
10077 clean_up_filters (&bpt
->syscalls_to_be_caught
);
10080 /* Be sure no bpstat's are pointing at the breakpoint after it's
10082 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10083 in all threeds for now. Note that we cannot just remove bpstats
10084 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10085 commands are associated with the bpstat; if we remove it here,
10086 then the later call to bpstat_do_actions (&stop_bpstat); in
10087 event-top.c won't do anything, and temporary breakpoints with
10088 commands won't work. */
10090 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
10092 /* Now that breakpoint is removed from breakpoint list, update the
10093 global location list. This will remove locations that used to
10094 belong to this breakpoint. Do this before freeing the breakpoint
10095 itself, since remove_breakpoint looks at location's owner. It
10096 might be better design to have location completely
10097 self-contained, but it's not the case now. */
10098 update_global_location_list (0);
10101 /* On the chance that someone will soon try again to delete this
10102 same bp, we mark it as deleted before freeing its storage. */
10103 bpt
->type
= bp_none
;
10109 do_delete_breakpoint_cleanup (void *b
)
10111 delete_breakpoint (b
);
10115 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
10117 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
10120 /* A callback for map_breakpoint_numbers that calls
10121 delete_breakpoint. */
10124 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
10126 delete_breakpoint (b
);
10130 delete_command (char *arg
, int from_tty
)
10132 struct breakpoint
*b
, *b_tmp
;
10138 int breaks_to_delete
= 0;
10140 /* Delete all breakpoints if no argument.
10141 Do not delete internal or call-dummy breakpoints, these have
10142 to be deleted with an explicit breakpoint number argument. */
10143 ALL_BREAKPOINTS (b
)
10145 if (b
->type
!= bp_call_dummy
10146 && b
->type
!= bp_std_terminate
10147 && b
->type
!= bp_shlib_event
10148 && b
->type
!= bp_jit_event
10149 && b
->type
!= bp_thread_event
10150 && b
->type
!= bp_overlay_event
10151 && b
->type
!= bp_longjmp_master
10152 && b
->type
!= bp_std_terminate_master
10153 && b
->type
!= bp_exception_master
10156 breaks_to_delete
= 1;
10161 /* Ask user only if there are some breakpoints to delete. */
10163 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10165 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10167 if (b
->type
!= bp_call_dummy
10168 && b
->type
!= bp_std_terminate
10169 && b
->type
!= bp_shlib_event
10170 && b
->type
!= bp_thread_event
10171 && b
->type
!= bp_jit_event
10172 && b
->type
!= bp_overlay_event
10173 && b
->type
!= bp_longjmp_master
10174 && b
->type
!= bp_std_terminate_master
10175 && b
->type
!= bp_exception_master
10177 delete_breakpoint (b
);
10182 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10186 all_locations_are_pending (struct bp_location
*loc
)
10188 for (; loc
; loc
= loc
->next
)
10189 if (!loc
->shlib_disabled
)
10194 /* Subroutine of update_breakpoint_locations to simplify it.
10195 Return non-zero if multiple fns in list LOC have the same name.
10196 Null names are ignored. */
10199 ambiguous_names_p (struct bp_location
*loc
)
10201 struct bp_location
*l
;
10202 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10203 (int (*) (const void *,
10204 const void *)) streq
,
10205 NULL
, xcalloc
, xfree
);
10207 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10210 const char *name
= l
->function_name
;
10212 /* Allow for some names to be NULL, ignore them. */
10216 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10218 /* NOTE: We can assume slot != NULL here because xcalloc never
10222 htab_delete (htab
);
10228 htab_delete (htab
);
10232 /* When symbols change, it probably means the sources changed as well,
10233 and it might mean the static tracepoint markers are no longer at
10234 the same address or line numbers they used to be at last we
10235 checked. Losing your static tracepoints whenever you rebuild is
10236 undesirable. This function tries to resync/rematch gdb static
10237 tracepoints with the markers on the target, for static tracepoints
10238 that have not been set by marker id. Static tracepoint that have
10239 been set by marker id are reset by marker id in breakpoint_re_set.
10242 1) For a tracepoint set at a specific address, look for a marker at
10243 the old PC. If one is found there, assume to be the same marker.
10244 If the name / string id of the marker found is different from the
10245 previous known name, assume that means the user renamed the marker
10246 in the sources, and output a warning.
10248 2) For a tracepoint set at a given line number, look for a marker
10249 at the new address of the old line number. If one is found there,
10250 assume to be the same marker. If the name / string id of the
10251 marker found is different from the previous known name, assume that
10252 means the user renamed the marker in the sources, and output a
10255 3) If a marker is no longer found at the same address or line, it
10256 may mean the marker no longer exists. But it may also just mean
10257 the code changed a bit. Maybe the user added a few lines of code
10258 that made the marker move up or down (in line number terms). Ask
10259 the target for info about the marker with the string id as we knew
10260 it. If found, update line number and address in the matching
10261 static tracepoint. This will get confused if there's more than one
10262 marker with the same ID (possible in UST, although unadvised
10263 precisely because it confuses tools). */
10265 static struct symtab_and_line
10266 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10268 struct static_tracepoint_marker marker
;
10274 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10276 if (target_static_tracepoint_marker_at (pc
, &marker
))
10278 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10279 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10281 b
->static_trace_marker_id
, marker
.str_id
);
10283 xfree (b
->static_trace_marker_id
);
10284 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10285 release_static_tracepoint_marker (&marker
);
10290 /* Old marker wasn't found on target at lineno. Try looking it up
10292 if (!sal
.explicit_pc
10294 && sal
.symtab
!= NULL
10295 && b
->static_trace_marker_id
!= NULL
)
10297 VEC(static_tracepoint_marker_p
) *markers
;
10300 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10302 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10304 struct symtab_and_line sal
;
10305 struct symbol
*sym
;
10306 struct static_tracepoint_marker
*marker
;
10308 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10310 xfree (b
->static_trace_marker_id
);
10311 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10313 warning (_("marker for static tracepoint %d (%s) not "
10314 "found at previous line number"),
10315 b
->number
, b
->static_trace_marker_id
);
10319 sal
.pc
= marker
->address
;
10321 sal
= find_pc_line (marker
->address
, 0);
10322 sym
= find_pc_sect_function (marker
->address
, NULL
);
10323 ui_out_text (uiout
, "Now in ");
10326 ui_out_field_string (uiout
, "func",
10327 SYMBOL_PRINT_NAME (sym
));
10328 ui_out_text (uiout
, " at ");
10330 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10331 ui_out_text (uiout
, ":");
10333 if (ui_out_is_mi_like_p (uiout
))
10335 char *fullname
= symtab_to_fullname (sal
.symtab
);
10338 ui_out_field_string (uiout
, "fullname", fullname
);
10341 ui_out_field_int (uiout
, "line", sal
.line
);
10342 ui_out_text (uiout
, "\n");
10344 b
->line_number
= sal
.line
;
10346 xfree (b
->source_file
);
10348 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10350 b
->source_file
= NULL
;
10352 xfree (b
->addr_string
);
10353 b
->addr_string
= xstrprintf ("%s:%d",
10354 sal
.symtab
->filename
, b
->line_number
);
10356 /* Might be nice to check if function changed, and warn if
10359 release_static_tracepoint_marker (marker
);
10366 update_breakpoint_locations (struct breakpoint
*b
,
10367 struct symtabs_and_lines sals
)
10371 struct bp_location
*existing_locations
= b
->loc
;
10373 /* If there's no new locations, and all existing locations are
10374 pending, don't do anything. This optimizes the common case where
10375 all locations are in the same shared library, that was unloaded.
10376 We'd like to retain the location, so that when the library is
10377 loaded again, we don't loose the enabled/disabled status of the
10378 individual locations. */
10379 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10384 for (i
= 0; i
< sals
.nelts
; ++i
)
10386 struct bp_location
*new_loc
=
10387 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10389 /* Reparse conditions, they might contain references to the
10391 if (b
->cond_string
!= NULL
)
10393 struct gdb_exception e
;
10395 s
= b
->cond_string
;
10396 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10398 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10403 warning (_("failed to reevaluate condition "
10404 "for breakpoint %d: %s"),
10405 b
->number
, e
.message
);
10406 new_loc
->enabled
= 0;
10410 if (b
->source_file
!= NULL
)
10411 xfree (b
->source_file
);
10412 if (sals
.sals
[i
].symtab
== NULL
)
10413 b
->source_file
= NULL
;
10415 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10417 if (b
->line_number
== 0)
10418 b
->line_number
= sals
.sals
[i
].line
;
10421 /* Update locations of permanent breakpoints. */
10422 if (b
->enable_state
== bp_permanent
)
10423 make_breakpoint_permanent (b
);
10425 /* If possible, carry over 'disable' status from existing
10428 struct bp_location
*e
= existing_locations
;
10429 /* If there are multiple breakpoints with the same function name,
10430 e.g. for inline functions, comparing function names won't work.
10431 Instead compare pc addresses; this is just a heuristic as things
10432 may have moved, but in practice it gives the correct answer
10433 often enough until a better solution is found. */
10434 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10436 for (; e
; e
= e
->next
)
10438 if (!e
->enabled
&& e
->function_name
)
10440 struct bp_location
*l
= b
->loc
;
10441 if (have_ambiguous_names
)
10443 for (; l
; l
= l
->next
)
10444 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10445 l
->pspace
->aspace
, l
->address
))
10453 for (; l
; l
= l
->next
)
10454 if (l
->function_name
10455 && strcmp (e
->function_name
, l
->function_name
) == 0)
10465 update_global_location_list (1);
10468 /* Reset a breakpoint given it's struct breakpoint * BINT.
10469 The value we return ends up being the return value from catch_errors.
10470 Unused in this case. */
10473 breakpoint_re_set_one (void *bint
)
10475 /* Get past catch_errs. */
10476 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10478 int *not_found_ptr
= ¬_found
;
10479 struct symtabs_and_lines sals
= {0};
10480 struct symtabs_and_lines expanded
= {0};
10482 struct gdb_exception e
;
10483 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10484 int marker_spec
= 0;
10489 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10492 case bp_breakpoint
:
10493 case bp_hardware_breakpoint
:
10494 case bp_tracepoint
:
10495 case bp_fast_tracepoint
:
10496 case bp_static_tracepoint
:
10497 /* Do not attempt to re-set breakpoints disabled during startup. */
10498 if (b
->enable_state
== bp_startup_disabled
)
10501 if (b
->addr_string
== NULL
)
10503 /* Anything without a string can't be re-set. */
10504 delete_breakpoint (b
);
10508 input_radix
= b
->input_radix
;
10509 s
= b
->addr_string
;
10511 save_current_space_and_thread ();
10512 switch_to_program_space_and_thread (b
->pspace
);
10514 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10516 set_language (b
->language
);
10517 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10521 sals
= decode_static_tracepoint_spec (&s
);
10522 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10524 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10528 error (_("marker %s not found"), b
->static_trace_marker_id
);
10531 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0,
10532 (char ***) NULL
, not_found_ptr
);
10536 int not_found_and_ok
= 0;
10537 /* For pending breakpoints, it's expected that parsing will
10538 fail until the right shared library is loaded. User has
10539 already told to create pending breakpoints and don't need
10540 extra messages. If breakpoint is in bp_shlib_disabled
10541 state, then user already saw the message about that
10542 breakpoint being disabled, and don't want to see more
10545 && (b
->condition_not_parsed
10546 || (b
->loc
&& b
->loc
->shlib_disabled
)
10547 || b
->enable_state
== bp_disabled
))
10548 not_found_and_ok
= 1;
10550 if (!not_found_and_ok
)
10552 /* We surely don't want to warn about the same breakpoint
10553 10 times. One solution, implemented here, is disable
10554 the breakpoint on error. Another solution would be to
10555 have separate 'warning emitted' flag. Since this
10556 happens only when a binary has changed, I don't know
10557 which approach is better. */
10558 b
->enable_state
= bp_disabled
;
10559 throw_exception (e
);
10565 gdb_assert (sals
.nelts
== 1);
10567 resolve_sal_pc (&sals
.sals
[0]);
10568 if (b
->condition_not_parsed
&& s
&& s
[0])
10570 char *cond_string
= 0;
10574 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10575 &cond_string
, &thread
, &task
);
10577 b
->cond_string
= cond_string
;
10578 b
->thread
= thread
;
10580 b
->condition_not_parsed
= 0;
10583 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10584 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10586 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10589 make_cleanup (xfree
, sals
.sals
);
10590 update_breakpoint_locations (b
, expanded
);
10593 case bp_watchpoint
:
10594 case bp_hardware_watchpoint
:
10595 case bp_read_watchpoint
:
10596 case bp_access_watchpoint
:
10597 /* Watchpoint can be either on expression using entirely global
10598 variables, or it can be on local variables.
10600 Watchpoints of the first kind are never auto-deleted, and
10601 even persist across program restarts. Since they can use
10602 variables from shared libraries, we need to reparse
10603 expression as libraries are loaded and unloaded.
10605 Watchpoints on local variables can also change meaning as
10606 result of solib event. For example, if a watchpoint uses
10607 both a local and a global variables in expression, it's a
10608 local watchpoint, but unloading of a shared library will make
10609 the expression invalid. This is not a very common use case,
10610 but we still re-evaluate expression, to avoid surprises to
10613 Note that for local watchpoints, we re-evaluate it only if
10614 watchpoints frame id is still valid. If it's not, it means
10615 the watchpoint is out of scope and will be deleted soon. In
10616 fact, I'm not sure we'll ever be called in this case.
10618 If a local watchpoint's frame id is still valid, then
10619 b->exp_valid_block is likewise valid, and we can safely use it.
10621 Don't do anything about disabled watchpoints, since they will
10622 be reevaluated again when enabled. */
10623 update_watchpoint (b
, 1 /* reparse */);
10625 /* We needn't really do anything to reset these, since the mask
10626 that requests them is unaffected by e.g., new libraries being
10628 case bp_catchpoint
:
10632 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10634 /* Delete overlay event and longjmp master breakpoints; they will be
10635 reset later by breakpoint_re_set. */
10636 case bp_overlay_event
:
10637 case bp_longjmp_master
:
10638 case bp_std_terminate_master
:
10639 case bp_exception_master
:
10640 delete_breakpoint (b
);
10643 /* This breakpoint is special, it's set up when the inferior
10644 starts and we really don't want to touch it. */
10645 case bp_shlib_event
:
10647 /* Like bp_shlib_event, this breakpoint type is special.
10648 Once it is set up, we do not want to touch it. */
10649 case bp_thread_event
:
10651 /* Keep temporary breakpoints, which can be encountered when we
10652 step over a dlopen call and SOLIB_ADD is resetting the
10653 breakpoints. Otherwise these should have been blown away via
10654 the cleanup chain or by breakpoint_init_inferior when we
10655 rerun the executable. */
10658 case bp_watchpoint_scope
:
10659 case bp_call_dummy
:
10660 case bp_std_terminate
:
10661 case bp_step_resume
:
10663 case bp_longjmp_resume
:
10665 case bp_exception_resume
:
10670 do_cleanups (cleanups
);
10674 /* Re-set all breakpoints after symbols have been re-loaded. */
10676 breakpoint_re_set (void)
10678 struct breakpoint
*b
, *b_tmp
;
10679 enum language save_language
;
10680 int save_input_radix
;
10681 struct cleanup
*old_chain
;
10683 save_language
= current_language
->la_language
;
10684 save_input_radix
= input_radix
;
10685 old_chain
= save_current_program_space ();
10687 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10689 /* Format possible error msg. */
10690 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10692 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10693 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10694 do_cleanups (cleanups
);
10696 set_language (save_language
);
10697 input_radix
= save_input_radix
;
10699 jit_breakpoint_re_set ();
10701 do_cleanups (old_chain
);
10703 create_overlay_event_breakpoint ();
10704 create_longjmp_master_breakpoint ();
10705 create_std_terminate_master_breakpoint ();
10706 create_exception_master_breakpoint ();
10709 /* Reset the thread number of this breakpoint:
10711 - If the breakpoint is for all threads, leave it as-is.
10712 - Else, reset it to the current thread for inferior_ptid. */
10714 breakpoint_re_set_thread (struct breakpoint
*b
)
10716 if (b
->thread
!= -1)
10718 if (in_thread_list (inferior_ptid
))
10719 b
->thread
= pid_to_thread_id (inferior_ptid
);
10721 /* We're being called after following a fork. The new fork is
10722 selected as current, and unless this was a vfork will have a
10723 different program space from the original thread. Reset that
10725 b
->loc
->pspace
= current_program_space
;
10729 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10730 If from_tty is nonzero, it prints a message to that effect,
10731 which ends with a period (no newline). */
10734 set_ignore_count (int bptnum
, int count
, int from_tty
)
10736 struct breakpoint
*b
;
10741 ALL_BREAKPOINTS (b
)
10742 if (b
->number
== bptnum
)
10744 if (is_tracepoint (b
))
10746 if (from_tty
&& count
!= 0)
10747 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10752 b
->ignore_count
= count
;
10756 printf_filtered (_("Will stop next time "
10757 "breakpoint %d is reached."),
10759 else if (count
== 1)
10760 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10763 printf_filtered (_("Will ignore next %d "
10764 "crossings of breakpoint %d."),
10767 breakpoints_changed ();
10768 observer_notify_breakpoint_modified (b
->number
);
10772 error (_("No breakpoint number %d."), bptnum
);
10775 /* Command to set ignore-count of breakpoint N to COUNT. */
10778 ignore_command (char *args
, int from_tty
)
10784 error_no_arg (_("a breakpoint number"));
10786 num
= get_number (&p
);
10788 error (_("bad breakpoint number: '%s'"), args
);
10790 error (_("Second argument (specified ignore-count) is missing."));
10792 set_ignore_count (num
,
10793 longest_to_int (value_as_long (parse_and_eval (p
))),
10796 printf_filtered ("\n");
10799 /* Call FUNCTION on each of the breakpoints
10800 whose numbers are given in ARGS. */
10803 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10810 struct breakpoint
*b
, *tmp
;
10814 error_no_arg (_("one or more breakpoint numbers"));
10821 num
= get_number_or_range (&p1
);
10824 warning (_("bad breakpoint number at or near '%s'"), p
);
10828 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10829 if (b
->number
== num
)
10831 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10833 function (b
, data
);
10834 if (related_breakpoint
)
10835 function (related_breakpoint
, data
);
10839 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10845 static struct bp_location
*
10846 find_location_by_number (char *number
)
10848 char *dot
= strchr (number
, '.');
10852 struct breakpoint
*b
;
10853 struct bp_location
*loc
;
10858 bp_num
= get_number_or_range (&p1
);
10860 error (_("Bad breakpoint number '%s'"), number
);
10862 ALL_BREAKPOINTS (b
)
10863 if (b
->number
== bp_num
)
10868 if (!b
|| b
->number
!= bp_num
)
10869 error (_("Bad breakpoint number '%s'"), number
);
10872 loc_num
= get_number_or_range (&p1
);
10874 error (_("Bad breakpoint location number '%s'"), number
);
10878 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10881 error (_("Bad breakpoint location number '%s'"), dot
+1);
10887 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10888 If from_tty is nonzero, it prints a message to that effect,
10889 which ends with a period (no newline). */
10892 disable_breakpoint (struct breakpoint
*bpt
)
10894 /* Never disable a watchpoint scope breakpoint; we want to
10895 hit them when we leave scope so we can delete both the
10896 watchpoint and its scope breakpoint at that time. */
10897 if (bpt
->type
== bp_watchpoint_scope
)
10900 /* You can't disable permanent breakpoints. */
10901 if (bpt
->enable_state
== bp_permanent
)
10904 bpt
->enable_state
= bp_disabled
;
10906 update_global_location_list (0);
10908 observer_notify_breakpoint_modified (bpt
->number
);
10911 /* A callback for map_breakpoint_numbers that calls
10912 disable_breakpoint. */
10915 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10917 disable_breakpoint (b
);
10921 disable_command (char *args
, int from_tty
)
10923 struct breakpoint
*bpt
;
10926 ALL_BREAKPOINTS (bpt
)
10930 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10933 case bp_breakpoint
:
10934 case bp_tracepoint
:
10935 case bp_fast_tracepoint
:
10936 case bp_static_tracepoint
:
10937 case bp_catchpoint
:
10938 case bp_hardware_breakpoint
:
10939 case bp_watchpoint
:
10940 case bp_hardware_watchpoint
:
10941 case bp_read_watchpoint
:
10942 case bp_access_watchpoint
:
10943 disable_breakpoint (bpt
);
10947 else if (strchr (args
, '.'))
10949 struct bp_location
*loc
= find_location_by_number (args
);
10952 update_global_location_list (0);
10955 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10959 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10961 int target_resources_ok
;
10963 if (bpt
->type
== bp_hardware_breakpoint
)
10966 i
= hw_breakpoint_used_count ();
10967 target_resources_ok
=
10968 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10970 if (target_resources_ok
== 0)
10971 error (_("No hardware breakpoint support in the target."));
10972 else if (target_resources_ok
< 0)
10973 error (_("Hardware breakpoints used exceeds limit."));
10976 if (is_watchpoint (bpt
))
10978 struct gdb_exception e
;
10980 TRY_CATCH (e
, RETURN_MASK_ALL
)
10982 update_watchpoint (bpt
, 1 /* reparse */);
10986 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10992 if (bpt
->enable_state
!= bp_permanent
)
10993 bpt
->enable_state
= bp_enabled
;
10994 bpt
->disposition
= disposition
;
10995 update_global_location_list (1);
10996 breakpoints_changed ();
10998 observer_notify_breakpoint_modified (bpt
->number
);
11003 enable_breakpoint (struct breakpoint
*bpt
)
11005 do_enable_breakpoint (bpt
, bpt
->disposition
);
11008 /* A callback for map_breakpoint_numbers that calls
11009 enable_breakpoint. */
11012 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
11014 enable_breakpoint (b
);
11017 /* The enable command enables the specified breakpoints (or all defined
11018 breakpoints) so they once again become (or continue to be) effective
11019 in stopping the inferior. */
11022 enable_command (char *args
, int from_tty
)
11024 struct breakpoint
*bpt
;
11027 ALL_BREAKPOINTS (bpt
)
11031 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
11034 case bp_breakpoint
:
11035 case bp_tracepoint
:
11036 case bp_fast_tracepoint
:
11037 case bp_static_tracepoint
:
11038 case bp_catchpoint
:
11039 case bp_hardware_breakpoint
:
11040 case bp_watchpoint
:
11041 case bp_hardware_watchpoint
:
11042 case bp_read_watchpoint
:
11043 case bp_access_watchpoint
:
11044 enable_breakpoint (bpt
);
11048 else if (strchr (args
, '.'))
11050 struct bp_location
*loc
= find_location_by_number (args
);
11053 update_global_location_list (1);
11056 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
11060 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11062 do_enable_breakpoint (bpt
, disp_disable
);
11066 enable_once_command (char *args
, int from_tty
)
11068 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
11072 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11074 do_enable_breakpoint (bpt
, disp_del
);
11078 enable_delete_command (char *args
, int from_tty
)
11080 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
11084 set_breakpoint_cmd (char *args
, int from_tty
)
11089 show_breakpoint_cmd (char *args
, int from_tty
)
11093 /* Invalidate last known value of any hardware watchpoint if
11094 the memory which that value represents has been written to by
11098 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
11099 const bfd_byte
*data
)
11101 struct breakpoint
*bp
;
11103 ALL_BREAKPOINTS (bp
)
11104 if (bp
->enable_state
== bp_enabled
11105 && bp
->type
== bp_hardware_watchpoint
11106 && bp
->val_valid
&& bp
->val
)
11108 struct bp_location
*loc
;
11110 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
11111 if (loc
->loc_type
== bp_loc_hardware_watchpoint
11112 && loc
->address
+ loc
->length
> addr
11113 && addr
+ len
> loc
->address
)
11115 value_free (bp
->val
);
11122 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11124 struct symtabs_and_lines
11125 decode_line_spec_1 (char *string
, int funfirstline
)
11127 struct symtabs_and_lines sals
;
11130 error (_("Empty line specification."));
11131 if (default_breakpoint_valid
)
11132 sals
= decode_line_1 (&string
, funfirstline
,
11133 default_breakpoint_symtab
,
11134 default_breakpoint_line
,
11135 (char ***) NULL
, NULL
);
11137 sals
= decode_line_1 (&string
, funfirstline
,
11138 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
11140 error (_("Junk at end of line specification: %s"), string
);
11144 /* Create and insert a raw software breakpoint at PC. Return an
11145 identifier, which should be used to remove the breakpoint later.
11146 In general, places which call this should be using something on the
11147 breakpoint chain instead; this function should be eliminated
11151 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11152 struct address_space
*aspace
, CORE_ADDR pc
)
11154 struct bp_target_info
*bp_tgt
;
11156 bp_tgt
= XZALLOC (struct bp_target_info
);
11158 bp_tgt
->placed_address_space
= aspace
;
11159 bp_tgt
->placed_address
= pc
;
11161 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11163 /* Could not insert the breakpoint. */
11171 /* Remove a breakpoint BP inserted by
11172 deprecated_insert_raw_breakpoint. */
11175 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11177 struct bp_target_info
*bp_tgt
= bp
;
11180 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11186 /* One (or perhaps two) breakpoints used for software single
11189 static void *single_step_breakpoints
[2];
11190 static struct gdbarch
*single_step_gdbarch
[2];
11192 /* Create and insert a breakpoint for software single step. */
11195 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11196 struct address_space
*aspace
,
11201 if (single_step_breakpoints
[0] == NULL
)
11203 bpt_p
= &single_step_breakpoints
[0];
11204 single_step_gdbarch
[0] = gdbarch
;
11208 gdb_assert (single_step_breakpoints
[1] == NULL
);
11209 bpt_p
= &single_step_breakpoints
[1];
11210 single_step_gdbarch
[1] = gdbarch
;
11213 /* NOTE drow/2006-04-11: A future improvement to this function would
11214 be to only create the breakpoints once, and actually put them on
11215 the breakpoint chain. That would let us use set_raw_breakpoint.
11216 We could adjust the addresses each time they were needed. Doing
11217 this requires corresponding changes elsewhere where single step
11218 breakpoints are handled, however. So, for now, we use this. */
11220 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11221 if (*bpt_p
== NULL
)
11222 error (_("Could not insert single-step breakpoint at %s"),
11223 paddress (gdbarch
, next_pc
));
11226 /* Check if the breakpoints used for software single stepping
11227 were inserted or not. */
11230 single_step_breakpoints_inserted (void)
11232 return (single_step_breakpoints
[0] != NULL
11233 || single_step_breakpoints
[1] != NULL
);
11236 /* Remove and delete any breakpoints used for software single step. */
11239 remove_single_step_breakpoints (void)
11241 gdb_assert (single_step_breakpoints
[0] != NULL
);
11243 /* See insert_single_step_breakpoint for more about this deprecated
11245 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11246 single_step_breakpoints
[0]);
11247 single_step_gdbarch
[0] = NULL
;
11248 single_step_breakpoints
[0] = NULL
;
11250 if (single_step_breakpoints
[1] != NULL
)
11252 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11253 single_step_breakpoints
[1]);
11254 single_step_gdbarch
[1] = NULL
;
11255 single_step_breakpoints
[1] = NULL
;
11259 /* Delete software single step breakpoints without removing them from
11260 the inferior. This is intended to be used if the inferior's address
11261 space where they were inserted is already gone, e.g. after exit or
11265 cancel_single_step_breakpoints (void)
11269 for (i
= 0; i
< 2; i
++)
11270 if (single_step_breakpoints
[i
])
11272 xfree (single_step_breakpoints
[i
]);
11273 single_step_breakpoints
[i
] = NULL
;
11274 single_step_gdbarch
[i
] = NULL
;
11278 /* Detach software single-step breakpoints from INFERIOR_PTID without
11282 detach_single_step_breakpoints (void)
11286 for (i
= 0; i
< 2; i
++)
11287 if (single_step_breakpoints
[i
])
11288 target_remove_breakpoint (single_step_gdbarch
[i
],
11289 single_step_breakpoints
[i
]);
11292 /* Check whether a software single-step breakpoint is inserted at
11296 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11301 for (i
= 0; i
< 2; i
++)
11303 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11305 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11306 bp_tgt
->placed_address
,
11314 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11315 non-zero otherwise. */
11317 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11319 if (syscall_catchpoint_p (bp
)
11320 && bp
->enable_state
!= bp_disabled
11321 && bp
->enable_state
!= bp_call_disabled
)
11328 catch_syscall_enabled (void)
11330 struct inferior
*inf
= current_inferior ();
11332 return inf
->total_syscalls_count
!= 0;
11336 catching_syscall_number (int syscall_number
)
11338 struct breakpoint
*bp
;
11340 ALL_BREAKPOINTS (bp
)
11341 if (is_syscall_catchpoint_enabled (bp
))
11343 if (bp
->syscalls_to_be_caught
)
11347 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11349 if (syscall_number
== iter
)
11359 /* Complete syscall names. Used by "catch syscall". */
11361 catch_syscall_completer (struct cmd_list_element
*cmd
,
11362 char *text
, char *word
)
11364 const char **list
= get_syscall_names ();
11366 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11372 /* Tracepoint-specific operations. */
11374 /* Set tracepoint count to NUM. */
11376 set_tracepoint_count (int num
)
11378 tracepoint_count
= num
;
11379 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11383 trace_command (char *arg
, int from_tty
)
11385 if (create_breakpoint (get_current_arch (),
11387 NULL
, 0, 1 /* parse arg */,
11389 bp_tracepoint
/* type_wanted */,
11390 0 /* Ignore count */,
11391 pending_break_support
,
11396 set_tracepoint_count (breakpoint_count
);
11400 ftrace_command (char *arg
, int from_tty
)
11402 if (create_breakpoint (get_current_arch (),
11404 NULL
, 0, 1 /* parse arg */,
11406 bp_fast_tracepoint
/* type_wanted */,
11407 0 /* Ignore count */,
11408 pending_break_support
,
11413 set_tracepoint_count (breakpoint_count
);
11416 /* strace command implementation. Creates a static tracepoint. */
11419 strace_command (char *arg
, int from_tty
)
11421 if (create_breakpoint (get_current_arch (),
11423 NULL
, 0, 1 /* parse arg */,
11425 bp_static_tracepoint
/* type_wanted */,
11426 0 /* Ignore count */,
11427 pending_break_support
,
11432 set_tracepoint_count (breakpoint_count
);
11435 /* Set up a fake reader function that gets command lines from a linked
11436 list that was acquired during tracepoint uploading. */
11438 static struct uploaded_tp
*this_utp
;
11439 static int next_cmd
;
11442 read_uploaded_action (void)
11446 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11453 /* Given information about a tracepoint as recorded on a target (which
11454 can be either a live system or a trace file), attempt to create an
11455 equivalent GDB tracepoint. This is not a reliable process, since
11456 the target does not necessarily have all the information used when
11457 the tracepoint was originally defined. */
11459 struct breakpoint
*
11460 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11462 char *addr_str
, small_buf
[100];
11463 struct breakpoint
*tp
;
11465 if (utp
->at_string
)
11466 addr_str
= utp
->at_string
;
11469 /* In the absence of a source location, fall back to raw
11470 address. Since there is no way to confirm that the address
11471 means the same thing as when the trace was started, warn the
11473 warning (_("Uploaded tracepoint %d has no "
11474 "source location, using raw address"),
11476 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11477 addr_str
= small_buf
;
11480 /* There's not much we can do with a sequence of bytecodes. */
11481 if (utp
->cond
&& !utp
->cond_string
)
11482 warning (_("Uploaded tracepoint %d condition "
11483 "has no source form, ignoring it"),
11486 if (!create_breakpoint (get_current_arch (),
11488 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11490 utp
->type
/* type_wanted */,
11491 0 /* Ignore count */,
11492 pending_break_support
,
11495 utp
->enabled
/* enabled */,
11499 set_tracepoint_count (breakpoint_count
);
11501 /* Get the tracepoint we just created. */
11502 tp
= get_tracepoint (tracepoint_count
);
11503 gdb_assert (tp
!= NULL
);
11507 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11509 trace_pass_command (small_buf
, 0);
11512 /* If we have uploaded versions of the original commands, set up a
11513 special-purpose "reader" function and call the usual command line
11514 reader, then pass the result to the breakpoint command-setting
11516 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11518 struct command_line
*cmd_list
;
11523 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11525 breakpoint_set_commands (tp
, cmd_list
);
11527 else if (!VEC_empty (char_ptr
, utp
->actions
)
11528 || !VEC_empty (char_ptr
, utp
->step_actions
))
11529 warning (_("Uploaded tracepoint %d actions "
11530 "have no source form, ignoring them"),
11536 /* Print information on tracepoint number TPNUM_EXP, or all if
11540 tracepoints_info (char *args
, int from_tty
)
11544 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
11546 if (num_printed
== 0)
11548 if (args
== NULL
|| *args
== '\0')
11549 ui_out_message (uiout
, 0, "No tracepoints.\n");
11551 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
11554 default_collect_info ();
11557 /* The 'enable trace' command enables tracepoints.
11558 Not supported by all targets. */
11560 enable_trace_command (char *args
, int from_tty
)
11562 enable_command (args
, from_tty
);
11565 /* The 'disable trace' command disables tracepoints.
11566 Not supported by all targets. */
11568 disable_trace_command (char *args
, int from_tty
)
11570 disable_command (args
, from_tty
);
11573 /* Remove a tracepoint (or all if no argument). */
11575 delete_trace_command (char *arg
, int from_tty
)
11577 struct breakpoint
*b
, *b_tmp
;
11583 int breaks_to_delete
= 0;
11585 /* Delete all breakpoints if no argument.
11586 Do not delete internal or call-dummy breakpoints, these
11587 have to be deleted with an explicit breakpoint number
11589 ALL_TRACEPOINTS (b
)
11591 if (b
->number
>= 0)
11593 breaks_to_delete
= 1;
11598 /* Ask user only if there are some breakpoints to delete. */
11600 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11602 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11604 if (is_tracepoint (b
)
11606 delete_breakpoint (b
);
11611 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11614 /* Set passcount for tracepoint.
11616 First command argument is passcount, second is tracepoint number.
11617 If tracepoint number omitted, apply to most recently defined.
11618 Also accepts special argument "all". */
11621 trace_pass_command (char *args
, int from_tty
)
11623 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11624 unsigned int count
;
11627 if (args
== 0 || *args
== 0)
11628 error (_("passcount command requires an "
11629 "argument (count + optional TP num)"));
11631 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11633 while (*args
&& isspace ((int) *args
))
11636 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11638 args
+= 3; /* Skip special argument "all". */
11641 error (_("Junk at end of arguments."));
11644 t1
= get_tracepoint_by_number (&args
, 1, 1);
11650 ALL_TRACEPOINTS (t2
)
11651 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11653 t2
->pass_count
= count
;
11654 observer_notify_tracepoint_modified (t2
->number
);
11656 printf_filtered (_("Setting tracepoint %d's "
11657 "passcount to %d\n"),
11658 t2
->number
, count
);
11660 if (! all
&& *args
)
11661 t1
= get_tracepoint_by_number (&args
, 1, 0);
11667 struct breakpoint
*
11668 get_tracepoint (int num
)
11670 struct breakpoint
*t
;
11672 ALL_TRACEPOINTS (t
)
11673 if (t
->number
== num
)
11679 /* Find the tracepoint with the given target-side number (which may be
11680 different from the tracepoint number after disconnecting and
11683 struct breakpoint
*
11684 get_tracepoint_by_number_on_target (int num
)
11686 struct breakpoint
*t
;
11688 ALL_TRACEPOINTS (t
)
11689 if (t
->number_on_target
== num
)
11695 /* Utility: parse a tracepoint number and look it up in the list.
11696 If MULTI_P is true, there might be a range of tracepoints in ARG.
11697 if OPTIONAL_P is true, then if the argument is missing, the most
11698 recent tracepoint (tracepoint_count) is returned. */
11699 struct breakpoint
*
11700 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11702 extern int tracepoint_count
;
11703 struct breakpoint
*t
;
11705 char *instring
= arg
== NULL
? NULL
: *arg
;
11707 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11710 tpnum
= tracepoint_count
;
11712 error_no_arg (_("tracepoint number"));
11715 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11719 if (instring
&& *instring
)
11720 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11723 printf_filtered (_("Tracepoint argument missing "
11724 "and no previous tracepoint\n"));
11728 ALL_TRACEPOINTS (t
)
11729 if (t
->number
== tpnum
)
11734 /* FIXME: if we are in the middle of a range we don't want to give
11735 a message. The current interface to get_number_or_range doesn't
11736 allow us to discover this. */
11737 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11741 /* Save information on user settable breakpoints (watchpoints, etc) to
11742 a new script file named FILENAME. If FILTER is non-NULL, call it
11743 on each breakpoint and only include the ones for which it returns
11747 save_breakpoints (char *filename
, int from_tty
,
11748 int (*filter
) (const struct breakpoint
*))
11750 struct breakpoint
*tp
;
11753 struct cleanup
*cleanup
;
11754 struct ui_file
*fp
;
11755 int extra_trace_bits
= 0;
11757 if (filename
== 0 || *filename
== 0)
11758 error (_("Argument required (file name in which to save)"));
11760 /* See if we have anything to save. */
11761 ALL_BREAKPOINTS (tp
)
11763 /* Skip internal and momentary breakpoints. */
11764 if (!user_breakpoint_p (tp
))
11767 /* If we have a filter, only save the breakpoints it accepts. */
11768 if (filter
&& !filter (tp
))
11773 if (is_tracepoint (tp
))
11775 extra_trace_bits
= 1;
11777 /* We can stop searching. */
11784 warning (_("Nothing to save."));
11788 pathname
= tilde_expand (filename
);
11789 cleanup
= make_cleanup (xfree
, pathname
);
11790 fp
= gdb_fopen (pathname
, "w");
11792 error (_("Unable to open file '%s' for saving (%s)"),
11793 filename
, safe_strerror (errno
));
11794 make_cleanup_ui_file_delete (fp
);
11796 if (extra_trace_bits
)
11797 save_trace_state_variables (fp
);
11799 ALL_BREAKPOINTS (tp
)
11801 /* Skip internal and momentary breakpoints. */
11802 if (!user_breakpoint_p (tp
))
11805 /* If we have a filter, only save the breakpoints it accepts. */
11806 if (filter
&& !filter (tp
))
11809 if (tp
->ops
!= NULL
)
11810 (tp
->ops
->print_recreate
) (tp
, fp
);
11813 if (tp
->type
== bp_fast_tracepoint
)
11814 fprintf_unfiltered (fp
, "ftrace");
11815 if (tp
->type
== bp_static_tracepoint
)
11816 fprintf_unfiltered (fp
, "strace");
11817 else if (tp
->type
== bp_tracepoint
)
11818 fprintf_unfiltered (fp
, "trace");
11819 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11820 fprintf_unfiltered (fp
, "tbreak");
11821 else if (tp
->type
== bp_breakpoint
)
11822 fprintf_unfiltered (fp
, "break");
11823 else if (tp
->type
== bp_hardware_breakpoint
11824 && tp
->disposition
== disp_del
)
11825 fprintf_unfiltered (fp
, "thbreak");
11826 else if (tp
->type
== bp_hardware_breakpoint
)
11827 fprintf_unfiltered (fp
, "hbreak");
11828 else if (tp
->type
== bp_watchpoint
)
11829 fprintf_unfiltered (fp
, "watch");
11830 else if (tp
->type
== bp_hardware_watchpoint
)
11831 fprintf_unfiltered (fp
, "watch");
11832 else if (tp
->type
== bp_read_watchpoint
)
11833 fprintf_unfiltered (fp
, "rwatch");
11834 else if (tp
->type
== bp_access_watchpoint
)
11835 fprintf_unfiltered (fp
, "awatch");
11837 internal_error (__FILE__
, __LINE__
,
11838 _("unhandled breakpoint type %d"), (int) tp
->type
);
11840 if (tp
->exp_string
)
11841 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11842 else if (tp
->addr_string
)
11843 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11848 sprintf_vma (tmp
, tp
->loc
->address
);
11849 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11853 if (tp
->thread
!= -1)
11854 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
11857 fprintf_unfiltered (fp
, " task %d", tp
->task
);
11859 fprintf_unfiltered (fp
, "\n");
11861 /* Note, we can't rely on tp->number for anything, as we can't
11862 assume the recreated breakpoint numbers will match. Use $bpnum
11865 if (tp
->cond_string
)
11866 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
11868 if (tp
->ignore_count
)
11869 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
11871 if (tp
->pass_count
)
11872 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11876 volatile struct gdb_exception ex
;
11878 fprintf_unfiltered (fp
, " commands\n");
11880 ui_out_redirect (uiout
, fp
);
11881 TRY_CATCH (ex
, RETURN_MASK_ALL
)
11883 print_command_lines (uiout
, tp
->commands
->commands
, 2);
11885 ui_out_redirect (uiout
, NULL
);
11888 throw_exception (ex
);
11890 fprintf_unfiltered (fp
, " end\n");
11893 if (tp
->enable_state
== bp_disabled
)
11894 fprintf_unfiltered (fp
, "disable\n");
11896 /* If this is a multi-location breakpoint, check if the locations
11897 should be individually disabled. Watchpoint locations are
11898 special, and not user visible. */
11899 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
11901 struct bp_location
*loc
;
11904 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
11906 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
11910 if (extra_trace_bits
&& *default_collect
)
11911 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
11913 do_cleanups (cleanup
);
11915 printf_filtered (_("Saved to file '%s'.\n"), filename
);
11918 /* The `save breakpoints' command. */
11921 save_breakpoints_command (char *args
, int from_tty
)
11923 save_breakpoints (args
, from_tty
, NULL
);
11926 /* The `save tracepoints' command. */
11929 save_tracepoints_command (char *args
, int from_tty
)
11931 save_breakpoints (args
, from_tty
, is_tracepoint
);
11934 /* Create a vector of all tracepoints. */
11936 VEC(breakpoint_p
) *
11939 VEC(breakpoint_p
) *tp_vec
= 0;
11940 struct breakpoint
*tp
;
11942 ALL_TRACEPOINTS (tp
)
11944 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11951 /* This help string is used for the break, hbreak, tbreak and thbreak
11952 commands. It is defined as a macro to prevent duplication.
11953 COMMAND should be a string constant containing the name of the
11955 #define BREAK_ARGS_HELP(command) \
11956 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11957 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11958 If a line number is specified, break at start of code for that line.\n\
11959 If a function is specified, break at start of code for that function.\n\
11960 If an address is specified, break at that exact address.\n\
11961 With no LOCATION, uses current execution address of the selected\n\
11962 stack frame. This is useful for breaking on return to a stack frame.\n\
11964 THREADNUM is the number from \"info threads\".\n\
11965 CONDITION is a boolean expression.\n\
11967 Multiple breakpoints at one place are permitted, and useful if their\n\
11968 conditions are different.\n\
11970 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11972 /* List of subcommands for "catch". */
11973 static struct cmd_list_element
*catch_cmdlist
;
11975 /* List of subcommands for "tcatch". */
11976 static struct cmd_list_element
*tcatch_cmdlist
;
11978 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11979 lists, and pass some additional user data to the command function. */
11981 add_catch_command (char *name
, char *docstring
,
11982 void (*sfunc
) (char *args
, int from_tty
,
11983 struct cmd_list_element
*command
),
11984 char **(*completer
) (struct cmd_list_element
*cmd
,
11985 char *text
, char *word
),
11986 void *user_data_catch
,
11987 void *user_data_tcatch
)
11989 struct cmd_list_element
*command
;
11991 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11993 set_cmd_sfunc (command
, sfunc
);
11994 set_cmd_context (command
, user_data_catch
);
11995 set_cmd_completer (command
, completer
);
11997 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11999 set_cmd_sfunc (command
, sfunc
);
12000 set_cmd_context (command
, user_data_tcatch
);
12001 set_cmd_completer (command
, completer
);
12005 clear_syscall_counts (struct inferior
*inf
)
12007 inf
->total_syscalls_count
= 0;
12008 inf
->any_syscall_count
= 0;
12009 VEC_free (int, inf
->syscalls_counts
);
12013 save_command (char *arg
, int from_tty
)
12015 printf_unfiltered (_("\"save\" must be followed by "
12016 "the name of a save subcommand.\n"));
12017 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
12020 struct breakpoint
*
12021 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
12024 struct breakpoint
*b
, *b_tmp
;
12026 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12028 if ((*callback
) (b
, data
))
12036 _initialize_breakpoint (void)
12038 struct cmd_list_element
*c
;
12040 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
12041 observer_attach_inferior_exit (clear_syscall_counts
);
12042 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
12044 breakpoint_objfile_key
= register_objfile_data ();
12046 breakpoint_chain
= 0;
12047 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12048 before a breakpoint is set. */
12049 breakpoint_count
= 0;
12051 tracepoint_count
= 0;
12053 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
12054 Set ignore-count of breakpoint number N to COUNT.\n\
12055 Usage is `ignore N COUNT'."));
12057 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
12059 add_com ("commands", class_breakpoint
, commands_command
, _("\
12060 Set commands to be executed when a breakpoint is hit.\n\
12061 Give breakpoint number as argument after \"commands\".\n\
12062 With no argument, the targeted breakpoint is the last one set.\n\
12063 The commands themselves follow starting on the next line.\n\
12064 Type a line containing \"end\" to indicate the end of them.\n\
12065 Give \"silent\" as the first line to make the breakpoint silent;\n\
12066 then no output is printed when it is hit, except what the commands print."));
12068 add_com ("condition", class_breakpoint
, condition_command
, _("\
12069 Specify breakpoint number N to break only if COND is true.\n\
12070 Usage is `condition N COND', where N is an integer and COND is an\n\
12071 expression to be evaluated whenever breakpoint N is reached."));
12073 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
12074 Set a temporary breakpoint.\n\
12075 Like \"break\" except the breakpoint is only temporary,\n\
12076 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12077 by using \"enable delete\" on the breakpoint number.\n\
12079 BREAK_ARGS_HELP ("tbreak")));
12080 set_cmd_completer (c
, location_completer
);
12082 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
12083 Set a hardware assisted breakpoint.\n\
12084 Like \"break\" except the breakpoint requires hardware support,\n\
12085 some target hardware may not have this support.\n\
12087 BREAK_ARGS_HELP ("hbreak")));
12088 set_cmd_completer (c
, location_completer
);
12090 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
12091 Set a temporary hardware assisted breakpoint.\n\
12092 Like \"hbreak\" except the breakpoint is only temporary,\n\
12093 so it will be deleted when hit.\n\
12095 BREAK_ARGS_HELP ("thbreak")));
12096 set_cmd_completer (c
, location_completer
);
12098 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
12099 Enable some breakpoints.\n\
12100 Give breakpoint numbers (separated by spaces) as arguments.\n\
12101 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12102 This is used to cancel the effect of the \"disable\" command.\n\
12103 With a subcommand you can enable temporarily."),
12104 &enablelist
, "enable ", 1, &cmdlist
);
12106 add_com ("ab", class_breakpoint
, enable_command
, _("\
12107 Enable some breakpoints.\n\
12108 Give breakpoint numbers (separated by spaces) as arguments.\n\
12109 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12110 This is used to cancel the effect of the \"disable\" command.\n\
12111 With a subcommand you can enable temporarily."));
12113 add_com_alias ("en", "enable", class_breakpoint
, 1);
12115 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
12116 Enable some breakpoints.\n\
12117 Give breakpoint numbers (separated by spaces) as arguments.\n\
12118 This is used to cancel the effect of the \"disable\" command.\n\
12119 May be abbreviated to simply \"enable\".\n"),
12120 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
12122 add_cmd ("once", no_class
, enable_once_command
, _("\
12123 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12124 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12127 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12128 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12129 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12132 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12133 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12134 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12137 add_cmd ("once", no_class
, enable_once_command
, _("\
12138 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12139 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12142 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12143 Disable some breakpoints.\n\
12144 Arguments are breakpoint numbers with spaces in between.\n\
12145 To disable all breakpoints, give no argument.\n\
12146 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12147 &disablelist
, "disable ", 1, &cmdlist
);
12148 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12149 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12151 add_com ("sb", class_breakpoint
, disable_command
, _("\
12152 Disable some breakpoints.\n\
12153 Arguments are breakpoint numbers with spaces in between.\n\
12154 To disable all breakpoints, give no argument.\n\
12155 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12157 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12158 Disable some breakpoints.\n\
12159 Arguments are breakpoint numbers with spaces in between.\n\
12160 To disable all breakpoints, give no argument.\n\
12161 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12162 This command may be abbreviated \"disable\"."),
12165 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12166 Delete some breakpoints or auto-display expressions.\n\
12167 Arguments are breakpoint numbers with spaces in between.\n\
12168 To delete all breakpoints, give no argument.\n\
12170 Also a prefix command for deletion of other GDB objects.\n\
12171 The \"unset\" command is also an alias for \"delete\"."),
12172 &deletelist
, "delete ", 1, &cmdlist
);
12173 add_com_alias ("d", "delete", class_breakpoint
, 1);
12174 add_com_alias ("del", "delete", class_breakpoint
, 1);
12176 add_com ("db", class_breakpoint
, delete_command
, _("\
12177 Delete some breakpoints.\n\
12178 Arguments are breakpoint numbers with spaces in between.\n\
12179 To delete all breakpoints, give no argument.\n"));
12181 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12182 Delete some breakpoints or auto-display expressions.\n\
12183 Arguments are breakpoint numbers with spaces in between.\n\
12184 To delete all breakpoints, give no argument.\n\
12185 This command may be abbreviated \"delete\"."),
12188 add_com ("clear", class_breakpoint
, clear_command
, _("\
12189 Clear breakpoint at specified line or function.\n\
12190 Argument may be line number, function name, or \"*\" and an address.\n\
12191 If line number is specified, all breakpoints in that line are cleared.\n\
12192 If function is specified, breakpoints at beginning of function are cleared.\n\
12193 If an address is specified, breakpoints at that address are cleared.\n\
12195 With no argument, clears all breakpoints in the line that the selected frame\n\
12196 is executing in.\n\
12198 See also the \"delete\" command which clears breakpoints by number."));
12199 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12201 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12202 Set breakpoint at specified line or function.\n"
12203 BREAK_ARGS_HELP ("break")));
12204 set_cmd_completer (c
, location_completer
);
12206 add_com_alias ("b", "break", class_run
, 1);
12207 add_com_alias ("br", "break", class_run
, 1);
12208 add_com_alias ("bre", "break", class_run
, 1);
12209 add_com_alias ("brea", "break", class_run
, 1);
12212 add_com_alias ("ba", "break", class_breakpoint
, 1);
12216 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12217 Break in function/address or break at a line in the current file."),
12218 &stoplist
, "stop ", 1, &cmdlist
);
12219 add_cmd ("in", class_breakpoint
, stopin_command
,
12220 _("Break in function or address."), &stoplist
);
12221 add_cmd ("at", class_breakpoint
, stopat_command
,
12222 _("Break at a line in the current file."), &stoplist
);
12223 add_com ("status", class_info
, breakpoints_info
, _("\
12224 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12225 The \"Type\" column indicates one of:\n\
12226 \tbreakpoint - normal breakpoint\n\
12227 \twatchpoint - watchpoint\n\
12228 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12229 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12230 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12231 address and file/line number respectively.\n\
12233 Convenience variable \"$_\" and default examine address for \"x\"\n\
12234 are set to the address of the last breakpoint listed unless the command\n\
12235 is prefixed with \"server \".\n\n\
12236 Convenience variable \"$bpnum\" contains the number of the last\n\
12237 breakpoint set."));
12240 add_info ("breakpoints", breakpoints_info
, _("\
12241 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
12242 The \"Type\" column indicates one of:\n\
12243 \tbreakpoint - normal breakpoint\n\
12244 \twatchpoint - watchpoint\n\
12245 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12246 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12247 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12248 address and file/line number respectively.\n\
12250 Convenience variable \"$_\" and default examine address for \"x\"\n\
12251 are set to the address of the last breakpoint listed unless the command\n\
12252 is prefixed with \"server \".\n\n\
12253 Convenience variable \"$bpnum\" contains the number of the last\n\
12254 breakpoint set."));
12256 add_info_alias ("b", "breakpoints", 1);
12259 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12260 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12261 The \"Type\" column indicates one of:\n\
12262 \tbreakpoint - normal breakpoint\n\
12263 \twatchpoint - watchpoint\n\
12264 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12265 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12266 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12267 address and file/line number respectively.\n\
12269 Convenience variable \"$_\" and default examine address for \"x\"\n\
12270 are set to the address of the last breakpoint listed unless the command\n\
12271 is prefixed with \"server \".\n\n\
12272 Convenience variable \"$bpnum\" contains the number of the last\n\
12273 breakpoint set."));
12275 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12276 Status of all breakpoints, or breakpoint number NUMBER.\n\
12277 The \"Type\" column indicates one of:\n\
12278 \tbreakpoint - normal breakpoint\n\
12279 \twatchpoint - watchpoint\n\
12280 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12281 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12282 \tuntil - internal breakpoint used by the \"until\" command\n\
12283 \tfinish - internal breakpoint used by the \"finish\" command\n\
12284 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12285 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12286 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12287 address and file/line number respectively.\n\
12289 Convenience variable \"$_\" and default examine address for \"x\"\n\
12290 are set to the address of the last breakpoint listed unless the command\n\
12291 is prefixed with \"server \".\n\n\
12292 Convenience variable \"$bpnum\" contains the number of the last\n\
12294 &maintenanceinfolist
);
12296 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12297 Set catchpoints to catch events."),
12298 &catch_cmdlist
, "catch ",
12299 0/*allow-unknown*/, &cmdlist
);
12301 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12302 Set temporary catchpoints to catch events."),
12303 &tcatch_cmdlist
, "tcatch ",
12304 0/*allow-unknown*/, &cmdlist
);
12306 /* Add catch and tcatch sub-commands. */
12307 add_catch_command ("catch", _("\
12308 Catch an exception, when caught.\n\
12309 With an argument, catch only exceptions with the given name."),
12310 catch_catch_command
,
12314 add_catch_command ("throw", _("\
12315 Catch an exception, when thrown.\n\
12316 With an argument, catch only exceptions with the given name."),
12317 catch_throw_command
,
12321 add_catch_command ("fork", _("Catch calls to fork."),
12322 catch_fork_command_1
,
12324 (void *) (uintptr_t) catch_fork_permanent
,
12325 (void *) (uintptr_t) catch_fork_temporary
);
12326 add_catch_command ("vfork", _("Catch calls to vfork."),
12327 catch_fork_command_1
,
12329 (void *) (uintptr_t) catch_vfork_permanent
,
12330 (void *) (uintptr_t) catch_vfork_temporary
);
12331 add_catch_command ("exec", _("Catch calls to exec."),
12332 catch_exec_command_1
,
12336 add_catch_command ("syscall", _("\
12337 Catch system calls by their names and/or numbers.\n\
12338 Arguments say which system calls to catch. If no arguments\n\
12339 are given, every system call will be caught.\n\
12340 Arguments, if given, should be one or more system call names\n\
12341 (if your system supports that), or system call numbers."),
12342 catch_syscall_command_1
,
12343 catch_syscall_completer
,
12346 add_catch_command ("exception", _("\
12347 Catch Ada exceptions, when raised.\n\
12348 With an argument, catch only exceptions with the given name."),
12349 catch_ada_exception_command
,
12353 add_catch_command ("assert", _("\
12354 Catch failed Ada assertions, when raised.\n\
12355 With an argument, catch only exceptions with the given name."),
12356 catch_assert_command
,
12361 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12362 Set a watchpoint for an expression.\n\
12363 Usage: watch [-l|-location] EXPRESSION\n\
12364 A watchpoint stops execution of your program whenever the value of\n\
12365 an expression changes.\n\
12366 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12367 the memory to which it refers."));
12368 set_cmd_completer (c
, expression_completer
);
12370 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12371 Set a read watchpoint for an expression.\n\
12372 Usage: rwatch [-l|-location] EXPRESSION\n\
12373 A watchpoint stops execution of your program whenever the value of\n\
12374 an expression is read.\n\
12375 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12376 the memory to which it refers."));
12377 set_cmd_completer (c
, expression_completer
);
12379 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12380 Set a watchpoint for an expression.\n\
12381 Usage: awatch [-l|-location] EXPRESSION\n\
12382 A watchpoint stops execution of your program whenever the value of\n\
12383 an expression is either read or written.\n\
12384 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12385 the memory to which it refers."));
12386 set_cmd_completer (c
, expression_completer
);
12388 add_info ("watchpoints", watchpoints_info
, _("\
12389 Status of specified watchpoints (all watchpoints if no argument)."));
12391 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12392 respond to changes - contrary to the description. */
12393 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12394 &can_use_hw_watchpoints
, _("\
12395 Set debugger's willingness to use watchpoint hardware."), _("\
12396 Show debugger's willingness to use watchpoint hardware."), _("\
12397 If zero, gdb will not use hardware for new watchpoints, even if\n\
12398 such is available. (However, any hardware watchpoints that were\n\
12399 created before setting this to nonzero, will continue to use watchpoint\n\
12402 show_can_use_hw_watchpoints
,
12403 &setlist
, &showlist
);
12405 can_use_hw_watchpoints
= 1;
12407 /* Tracepoint manipulation commands. */
12409 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12410 Set a tracepoint at specified line or function.\n\
12412 BREAK_ARGS_HELP ("trace") "\n\
12413 Do \"help tracepoints\" for info on other tracepoint commands."));
12414 set_cmd_completer (c
, location_completer
);
12416 add_com_alias ("tp", "trace", class_alias
, 0);
12417 add_com_alias ("tr", "trace", class_alias
, 1);
12418 add_com_alias ("tra", "trace", class_alias
, 1);
12419 add_com_alias ("trac", "trace", class_alias
, 1);
12421 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12422 Set a fast tracepoint at specified line or function.\n\
12424 BREAK_ARGS_HELP ("ftrace") "\n\
12425 Do \"help tracepoints\" for info on other tracepoint commands."));
12426 set_cmd_completer (c
, location_completer
);
12428 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12429 Set a static tracepoint at specified line, function or marker.\n\
12431 strace [LOCATION] [if CONDITION]\n\
12432 LOCATION may be a line number, function name, \"*\" and an address,\n\
12433 or -m MARKER_ID.\n\
12434 If a line number is specified, probe the marker at start of code\n\
12435 for that line. If a function is specified, probe the marker at start\n\
12436 of code for that function. If an address is specified, probe the marker\n\
12437 at that exact address. If a marker id is specified, probe the marker\n\
12438 with that name. With no LOCATION, uses current execution address of\n\
12439 the selected stack frame.\n\
12440 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12441 This collects arbitrary user data passed in the probe point call to the\n\
12442 tracing library. You can inspect it when analyzing the trace buffer,\n\
12443 by printing the $_sdata variable like any other convenience variable.\n\
12445 CONDITION is a boolean expression.\n\
12447 Multiple tracepoints at one place are permitted, and useful if their\n\
12448 conditions are different.\n\
12450 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12451 Do \"help tracepoints\" for info on other tracepoint commands."));
12452 set_cmd_completer (c
, location_completer
);
12454 add_info ("tracepoints", tracepoints_info
, _("\
12455 Status of specified tracepoints (all tracepoints if no argument).\n\
12456 Convenience variable \"$tpnum\" contains the number of the\n\
12457 last tracepoint set."));
12459 add_info_alias ("tp", "tracepoints", 1);
12461 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12462 Delete specified tracepoints.\n\
12463 Arguments are tracepoint numbers, separated by spaces.\n\
12464 No argument means delete all tracepoints."),
12467 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12468 Disable specified tracepoints.\n\
12469 Arguments are tracepoint numbers, separated by spaces.\n\
12470 No argument means disable all tracepoints."),
12472 deprecate_cmd (c
, "disable");
12474 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12475 Enable specified tracepoints.\n\
12476 Arguments are tracepoint numbers, separated by spaces.\n\
12477 No argument means enable all tracepoints."),
12479 deprecate_cmd (c
, "enable");
12481 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12482 Set the passcount for a tracepoint.\n\
12483 The trace will end when the tracepoint has been passed 'count' times.\n\
12484 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12485 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12487 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12488 _("Save breakpoint definitions as a script."),
12489 &save_cmdlist
, "save ",
12490 0/*allow-unknown*/, &cmdlist
);
12492 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12493 Save current breakpoint definitions as a script.\n\
12494 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12495 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12496 session to restore them."),
12498 set_cmd_completer (c
, filename_completer
);
12500 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12501 Save current tracepoint definitions as a script.\n\
12502 Use the 'source' command in another debug session to restore them."),
12504 set_cmd_completer (c
, filename_completer
);
12506 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12507 deprecate_cmd (c
, "save tracepoints");
12509 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12510 Breakpoint specific settings\n\
12511 Configure various breakpoint-specific variables such as\n\
12512 pending breakpoint behavior"),
12513 &breakpoint_set_cmdlist
, "set breakpoint ",
12514 0/*allow-unknown*/, &setlist
);
12515 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12516 Breakpoint specific settings\n\
12517 Configure various breakpoint-specific variables such as\n\
12518 pending breakpoint behavior"),
12519 &breakpoint_show_cmdlist
, "show breakpoint ",
12520 0/*allow-unknown*/, &showlist
);
12522 add_setshow_auto_boolean_cmd ("pending", no_class
,
12523 &pending_break_support
, _("\
12524 Set debugger's behavior regarding pending breakpoints."), _("\
12525 Show debugger's behavior regarding pending breakpoints."), _("\
12526 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12527 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12528 an error. If auto, an unrecognized breakpoint location results in a\n\
12529 user-query to see if a pending breakpoint should be created."),
12531 show_pending_break_support
,
12532 &breakpoint_set_cmdlist
,
12533 &breakpoint_show_cmdlist
);
12535 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12537 add_setshow_boolean_cmd ("auto-hw", no_class
,
12538 &automatic_hardware_breakpoints
, _("\
12539 Set automatic usage of hardware breakpoints."), _("\
12540 Show automatic usage of hardware breakpoints."), _("\
12541 If set, the debugger will automatically use hardware breakpoints for\n\
12542 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12543 a warning will be emitted for such breakpoints."),
12545 show_automatic_hardware_breakpoints
,
12546 &breakpoint_set_cmdlist
,
12547 &breakpoint_show_cmdlist
);
12549 add_setshow_enum_cmd ("always-inserted", class_support
,
12550 always_inserted_enums
, &always_inserted_mode
, _("\
12551 Set mode for inserting breakpoints."), _("\
12552 Show mode for inserting breakpoints."), _("\
12553 When this mode is off, breakpoints are inserted in inferior when it is\n\
12554 resumed, and removed when execution stops. When this mode is on,\n\
12555 breakpoints are inserted immediately and removed only when the user\n\
12556 deletes the breakpoint. When this mode is auto (which is the default),\n\
12557 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12558 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12559 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12560 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12562 &show_always_inserted_mode
,
12563 &breakpoint_set_cmdlist
,
12564 &breakpoint_show_cmdlist
);
12566 automatic_hardware_breakpoints
= 1;
12568 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);