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 /* Print the LOC location out of the list of B->LOC locations. */
4570 static void print_breakpoint_location (struct breakpoint
*b
,
4571 struct bp_location
*loc
,
4573 struct ui_stream
*stb
)
4575 struct cleanup
*old_chain
= save_current_program_space ();
4577 if (loc
!= NULL
&& loc
->shlib_disabled
)
4581 set_current_program_space (loc
->pspace
);
4583 if (b
->source_file
&& loc
)
4586 = find_pc_sect_function (loc
->address
, loc
->section
);
4589 ui_out_text (uiout
, "in ");
4590 ui_out_field_string (uiout
, "func",
4591 SYMBOL_PRINT_NAME (sym
));
4592 ui_out_wrap_hint (uiout
, wrap_indent
);
4593 ui_out_text (uiout
, " at ");
4595 ui_out_field_string (uiout
, "file", b
->source_file
);
4596 ui_out_text (uiout
, ":");
4598 if (ui_out_is_mi_like_p (uiout
))
4600 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4601 char *fullname
= symtab_to_fullname (sal
.symtab
);
4604 ui_out_field_string (uiout
, "fullname", fullname
);
4607 ui_out_field_int (uiout
, "line", b
->line_number
);
4611 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4613 ui_out_field_stream (uiout
, "at", stb
);
4616 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4618 do_cleanups (old_chain
);
4622 bptype_string (enum bptype type
)
4624 struct ep_type_description
4629 static struct ep_type_description bptypes
[] =
4631 {bp_none
, "?deleted?"},
4632 {bp_breakpoint
, "breakpoint"},
4633 {bp_hardware_breakpoint
, "hw breakpoint"},
4634 {bp_until
, "until"},
4635 {bp_finish
, "finish"},
4636 {bp_watchpoint
, "watchpoint"},
4637 {bp_hardware_watchpoint
, "hw watchpoint"},
4638 {bp_read_watchpoint
, "read watchpoint"},
4639 {bp_access_watchpoint
, "acc watchpoint"},
4640 {bp_longjmp
, "longjmp"},
4641 {bp_longjmp_resume
, "longjmp resume"},
4642 {bp_exception
, "exception"},
4643 {bp_exception_resume
, "exception resume"},
4644 {bp_step_resume
, "step resume"},
4645 {bp_watchpoint_scope
, "watchpoint scope"},
4646 {bp_call_dummy
, "call dummy"},
4647 {bp_std_terminate
, "std::terminate"},
4648 {bp_shlib_event
, "shlib events"},
4649 {bp_thread_event
, "thread events"},
4650 {bp_overlay_event
, "overlay events"},
4651 {bp_longjmp_master
, "longjmp master"},
4652 {bp_std_terminate_master
, "std::terminate master"},
4653 {bp_exception_master
, "exception master"},
4654 {bp_catchpoint
, "catchpoint"},
4655 {bp_tracepoint
, "tracepoint"},
4656 {bp_fast_tracepoint
, "fast tracepoint"},
4657 {bp_static_tracepoint
, "static tracepoint"},
4658 {bp_jit_event
, "jit events"},
4661 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4662 || ((int) type
!= bptypes
[(int) type
].type
))
4663 internal_error (__FILE__
, __LINE__
,
4664 _("bptypes table does not describe type #%d."),
4667 return bptypes
[(int) type
].description
;
4670 /* Print B to gdb_stdout. */
4673 print_one_breakpoint_location (struct breakpoint
*b
,
4674 struct bp_location
*loc
,
4676 struct bp_location
**last_loc
,
4677 int print_address_bits
,
4680 struct command_line
*l
;
4681 static char bpenables
[] = "nynny";
4682 char wrap_indent
[80];
4683 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4684 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4685 struct cleanup
*bkpt_chain
;
4687 int header_of_multiple
= 0;
4688 int part_of_multiple
= (loc
!= NULL
);
4689 struct value_print_options opts
;
4691 get_user_print_options (&opts
);
4693 gdb_assert (!loc
|| loc_number
!= 0);
4694 /* See comment in print_one_breakpoint concerning treatment of
4695 breakpoints with single disabled location. */
4698 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4699 header_of_multiple
= 1;
4704 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4708 if (part_of_multiple
)
4711 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4712 ui_out_field_string (uiout
, "number", formatted
);
4717 ui_out_field_int (uiout
, "number", b
->number
);
4722 if (part_of_multiple
)
4723 ui_out_field_skip (uiout
, "type");
4725 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4729 if (part_of_multiple
)
4730 ui_out_field_skip (uiout
, "disp");
4732 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4737 if (part_of_multiple
)
4738 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4740 ui_out_field_fmt (uiout
, "enabled", "%c",
4741 bpenables
[(int) b
->enable_state
]);
4742 ui_out_spaces (uiout
, 2);
4746 strcpy (wrap_indent
, " ");
4747 if (opts
.addressprint
)
4749 if (print_address_bits
<= 32)
4750 strcat (wrap_indent
, " ");
4752 strcat (wrap_indent
, " ");
4755 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4757 /* Although the print_one can possibly print all locations,
4758 calling it here is not likely to get any nice result. So,
4759 make sure there's just one location. */
4760 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4761 b
->ops
->print_one (b
, last_loc
);
4767 internal_error (__FILE__
, __LINE__
,
4768 _("print_one_breakpoint: bp_none encountered\n"));
4772 case bp_hardware_watchpoint
:
4773 case bp_read_watchpoint
:
4774 case bp_access_watchpoint
:
4775 /* Field 4, the address, is omitted (which makes the columns
4776 not line up too nicely with the headers, but the effect
4777 is relatively readable). */
4778 if (opts
.addressprint
)
4779 ui_out_field_skip (uiout
, "addr");
4781 ui_out_field_string (uiout
, "what", b
->exp_string
);
4785 case bp_hardware_breakpoint
:
4789 case bp_longjmp_resume
:
4791 case bp_exception_resume
:
4792 case bp_step_resume
:
4793 case bp_watchpoint_scope
:
4795 case bp_std_terminate
:
4796 case bp_shlib_event
:
4797 case bp_thread_event
:
4798 case bp_overlay_event
:
4799 case bp_longjmp_master
:
4800 case bp_std_terminate_master
:
4801 case bp_exception_master
:
4803 case bp_fast_tracepoint
:
4804 case bp_static_tracepoint
:
4806 if (opts
.addressprint
)
4809 if (header_of_multiple
)
4810 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4811 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4812 ui_out_field_string (uiout
, "addr", "<PENDING>");
4814 ui_out_field_core_addr (uiout
, "addr",
4815 loc
->gdbarch
, loc
->address
);
4818 if (!header_of_multiple
)
4819 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4826 /* For backward compatibility, don't display inferiors unless there
4829 && !header_of_multiple
4831 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4832 && (number_of_program_spaces () > 1
4833 || number_of_inferiors () > 1)
4834 /* LOC is for existing B, it cannot be in
4835 moribund_locations and thus having NULL OWNER. */
4836 && loc
->owner
->type
!= bp_catchpoint
)))
4838 struct inferior
*inf
;
4841 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4843 if (inf
->pspace
== loc
->pspace
)
4848 ui_out_text (uiout
, " inf ");
4851 ui_out_text (uiout
, ", ");
4852 ui_out_text (uiout
, plongest (inf
->num
));
4857 if (!part_of_multiple
)
4859 if (b
->thread
!= -1)
4861 /* FIXME: This seems to be redundant and lost here; see the
4862 "stop only in" line a little further down. */
4863 ui_out_text (uiout
, " thread ");
4864 ui_out_field_int (uiout
, "thread", b
->thread
);
4866 else if (b
->task
!= 0)
4868 ui_out_text (uiout
, " task ");
4869 ui_out_field_int (uiout
, "task", b
->task
);
4873 ui_out_text (uiout
, "\n");
4875 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4877 gdb_assert (b
->type
== bp_static_tracepoint
);
4879 ui_out_text (uiout
, "\tmarker id is ");
4880 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4881 b
->static_trace_marker_id
);
4882 ui_out_text (uiout
, "\n");
4885 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4888 ui_out_text (uiout
, "\tstop only in stack frame at ");
4889 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4891 ui_out_field_core_addr (uiout
, "frame",
4892 b
->gdbarch
, b
->frame_id
.stack_addr
);
4893 ui_out_text (uiout
, "\n");
4896 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4898 /* We do not print the condition for Ada exception catchpoints
4899 because the condition is an internal implementation detail
4900 that we do not want to expose to the user. */
4902 if (is_tracepoint (b
))
4903 ui_out_text (uiout
, "\ttrace only if ");
4905 ui_out_text (uiout
, "\tstop only if ");
4906 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4907 ui_out_text (uiout
, "\n");
4910 if (!part_of_multiple
&& b
->thread
!= -1)
4912 /* FIXME should make an annotation for this. */
4913 ui_out_text (uiout
, "\tstop only in thread ");
4914 ui_out_field_int (uiout
, "thread", b
->thread
);
4915 ui_out_text (uiout
, "\n");
4918 if (!part_of_multiple
&& b
->hit_count
)
4920 /* FIXME should make an annotation for this. */
4921 if (ep_is_catchpoint (b
))
4922 ui_out_text (uiout
, "\tcatchpoint");
4924 ui_out_text (uiout
, "\tbreakpoint");
4925 ui_out_text (uiout
, " already hit ");
4926 ui_out_field_int (uiout
, "times", b
->hit_count
);
4927 if (b
->hit_count
== 1)
4928 ui_out_text (uiout
, " time\n");
4930 ui_out_text (uiout
, " times\n");
4933 /* Output the count also if it is zero, but only if this is mi.
4934 FIXME: Should have a better test for this. */
4935 if (ui_out_is_mi_like_p (uiout
))
4936 if (!part_of_multiple
&& b
->hit_count
== 0)
4937 ui_out_field_int (uiout
, "times", b
->hit_count
);
4939 if (!part_of_multiple
&& b
->ignore_count
)
4942 ui_out_text (uiout
, "\tignore next ");
4943 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4944 ui_out_text (uiout
, " hits\n");
4947 l
= b
->commands
? b
->commands
->commands
: NULL
;
4948 if (!part_of_multiple
&& l
)
4950 struct cleanup
*script_chain
;
4953 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4954 print_command_lines (uiout
, l
, 4);
4955 do_cleanups (script_chain
);
4958 if (!part_of_multiple
&& b
->pass_count
)
4960 annotate_field (10);
4961 ui_out_text (uiout
, "\tpass count ");
4962 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4963 ui_out_text (uiout
, " \n");
4966 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4969 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4970 else if (b
->exp_string
)
4971 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4974 do_cleanups (bkpt_chain
);
4975 do_cleanups (old_chain
);
4979 print_one_breakpoint (struct breakpoint
*b
,
4980 struct bp_location
**last_loc
,
4981 int print_address_bits
,
4984 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4985 print_address_bits
, allflag
);
4987 /* If this breakpoint has custom print function,
4988 it's already printed. Otherwise, print individual
4989 locations, if any. */
4990 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4992 /* If breakpoint has a single location that is disabled, we
4993 print it as if it had several locations, since otherwise it's
4994 hard to represent "breakpoint enabled, location disabled"
4997 Note that while hardware watchpoints have several locations
4998 internally, that's not a property exposed to user. */
5000 && !is_hardware_watchpoint (b
)
5001 && (b
->loc
->next
|| !b
->loc
->enabled
)
5002 && !ui_out_is_mi_like_p (uiout
))
5004 struct bp_location
*loc
;
5006 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5007 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
5008 print_address_bits
, allflag
);
5014 breakpoint_address_bits (struct breakpoint
*b
)
5016 int print_address_bits
= 0;
5017 struct bp_location
*loc
;
5019 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5023 /* Software watchpoints that aren't watching memory don't have
5024 an address to print. */
5025 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5028 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5029 if (addr_bit
> print_address_bits
)
5030 print_address_bits
= addr_bit
;
5033 return print_address_bits
;
5036 struct captured_breakpoint_query_args
5042 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5044 struct captured_breakpoint_query_args
*args
= data
;
5045 struct breakpoint
*b
;
5046 struct bp_location
*dummy_loc
= NULL
;
5050 if (args
->bnum
== b
->number
)
5052 int print_address_bits
= breakpoint_address_bits (b
);
5054 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
5062 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5063 char **error_message
)
5065 struct captured_breakpoint_query_args args
;
5068 /* For the moment we don't trust print_one_breakpoint() to not throw
5070 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5071 error_message
, RETURN_MASK_ALL
) < 0)
5077 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5078 catchpoints, et.al.). */
5081 user_settable_breakpoint (const struct breakpoint
*b
)
5083 return (b
->type
== bp_breakpoint
5084 || b
->type
== bp_catchpoint
5085 || b
->type
== bp_hardware_breakpoint
5086 || is_tracepoint (b
)
5087 || is_watchpoint (b
));
5090 /* Return true if this breakpoint was set by the user, false if it is
5091 internal or momentary. */
5094 user_breakpoint_p (struct breakpoint
*b
)
5096 return user_settable_breakpoint (b
) && b
->number
> 0;
5099 /* Print information on user settable breakpoint (watchpoint, etc)
5100 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5101 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5102 FILTER is non-NULL, call it on each breakpoint and only include the
5103 ones for which it returns non-zero. Return the total number of
5104 breakpoints listed. */
5107 breakpoint_1 (char *args
, int allflag
,
5108 int (*filter
) (const struct breakpoint
*))
5110 struct breakpoint
*b
;
5111 struct bp_location
*last_loc
= NULL
;
5112 int nr_printable_breakpoints
;
5113 struct cleanup
*bkpttbl_chain
;
5114 struct value_print_options opts
;
5115 int print_address_bits
= 0;
5116 int print_type_col_width
= 14;
5118 get_user_print_options (&opts
);
5120 /* Compute the number of rows in the table, as well as the size
5121 required for address fields. */
5122 nr_printable_breakpoints
= 0;
5125 /* If we have a filter, only list the breakpoints it accepts. */
5126 if (filter
&& !filter (b
))
5129 /* If we have an "args" string, it is a list of breakpoints to
5130 accept. Skip the others. */
5131 if (args
!= NULL
&& *args
!= '\0')
5133 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5135 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5139 if (allflag
|| user_breakpoint_p (b
))
5141 int addr_bit
, type_len
;
5143 addr_bit
= breakpoint_address_bits (b
);
5144 if (addr_bit
> print_address_bits
)
5145 print_address_bits
= addr_bit
;
5147 type_len
= strlen (bptype_string (b
->type
));
5148 if (type_len
> print_type_col_width
)
5149 print_type_col_width
= type_len
;
5151 nr_printable_breakpoints
++;
5155 if (opts
.addressprint
)
5157 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5158 nr_printable_breakpoints
,
5162 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5163 nr_printable_breakpoints
,
5166 if (nr_printable_breakpoints
> 0)
5167 annotate_breakpoints_headers ();
5168 if (nr_printable_breakpoints
> 0)
5170 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5171 if (nr_printable_breakpoints
> 0)
5173 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5174 "type", "Type"); /* 2 */
5175 if (nr_printable_breakpoints
> 0)
5177 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5178 if (nr_printable_breakpoints
> 0)
5180 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5181 if (opts
.addressprint
)
5183 if (nr_printable_breakpoints
> 0)
5185 if (print_address_bits
<= 32)
5186 ui_out_table_header (uiout
, 10, ui_left
,
5187 "addr", "Address"); /* 5 */
5189 ui_out_table_header (uiout
, 18, ui_left
,
5190 "addr", "Address"); /* 5 */
5192 if (nr_printable_breakpoints
> 0)
5194 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5195 ui_out_table_body (uiout
);
5196 if (nr_printable_breakpoints
> 0)
5197 annotate_breakpoints_table ();
5202 /* If we have a filter, only list the breakpoints it accepts. */
5203 if (filter
&& !filter (b
))
5206 /* If we have an "args" string, it is a list of breakpoints to
5207 accept. Skip the others. */
5209 if (args
!= NULL
&& *args
!= '\0')
5211 if (allflag
) /* maintenance info breakpoint */
5213 if (parse_and_eval_long (args
) != b
->number
)
5216 else /* all others */
5218 if (!number_is_in_list (args
, b
->number
))
5222 /* We only print out user settable breakpoints unless the
5224 if (allflag
|| user_breakpoint_p (b
))
5225 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5228 do_cleanups (bkpttbl_chain
);
5230 if (nr_printable_breakpoints
== 0)
5232 /* If there's a filter, let the caller decide how to report
5236 if (args
== NULL
|| *args
== '\0')
5237 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5239 ui_out_message (uiout
, 0,
5240 "No breakpoint or watchpoint matching '%s'.\n",
5246 if (last_loc
&& !server_command
)
5247 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5250 /* FIXME? Should this be moved up so that it is only called when
5251 there have been breakpoints? */
5252 annotate_breakpoints_table_end ();
5254 return nr_printable_breakpoints
;
5257 /* Display the value of default-collect in a way that is generally
5258 compatible with the breakpoint list. */
5261 default_collect_info (void)
5263 /* If it has no value (which is frequently the case), say nothing; a
5264 message like "No default-collect." gets in user's face when it's
5266 if (!*default_collect
)
5269 /* The following phrase lines up nicely with per-tracepoint collect
5271 ui_out_text (uiout
, "default collect ");
5272 ui_out_field_string (uiout
, "default-collect", default_collect
);
5273 ui_out_text (uiout
, " \n");
5277 breakpoints_info (char *args
, int from_tty
)
5279 breakpoint_1 (args
, 0, NULL
);
5281 default_collect_info ();
5285 watchpoints_info (char *args
, int from_tty
)
5287 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5289 if (num_printed
== 0)
5291 if (args
== NULL
|| *args
== '\0')
5292 ui_out_message (uiout
, 0, "No watchpoints.\n");
5294 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5299 maintenance_info_breakpoints (char *args
, int from_tty
)
5301 breakpoint_1 (args
, 1, NULL
);
5303 default_collect_info ();
5307 breakpoint_has_pc (struct breakpoint
*b
,
5308 struct program_space
*pspace
,
5309 CORE_ADDR pc
, struct obj_section
*section
)
5311 struct bp_location
*bl
= b
->loc
;
5313 for (; bl
; bl
= bl
->next
)
5315 if (bl
->pspace
== pspace
5316 && bl
->address
== pc
5317 && (!overlay_debugging
|| bl
->section
== section
))
5323 /* Print a message describing any breakpoints set at PC. This
5324 concerns with logical breakpoints, so we match program spaces, not
5328 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5329 struct program_space
*pspace
, CORE_ADDR pc
,
5330 struct obj_section
*section
, int thread
)
5333 struct breakpoint
*b
;
5336 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5340 printf_filtered (_("Note: breakpoint "));
5341 else /* if (others == ???) */
5342 printf_filtered (_("Note: breakpoints "));
5344 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5347 printf_filtered ("%d", b
->number
);
5348 if (b
->thread
== -1 && thread
!= -1)
5349 printf_filtered (" (all threads)");
5350 else if (b
->thread
!= -1)
5351 printf_filtered (" (thread %d)", b
->thread
);
5352 printf_filtered ("%s%s ",
5353 ((b
->enable_state
== bp_disabled
5354 || b
->enable_state
== bp_call_disabled
5355 || b
->enable_state
== bp_startup_disabled
)
5357 : b
->enable_state
== bp_permanent
5361 : ((others
== 1) ? " and" : ""));
5363 printf_filtered (_("also set at pc "));
5364 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5365 printf_filtered (".\n");
5369 /* Set the default place to put a breakpoint
5370 for the `break' command with no arguments. */
5373 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5374 CORE_ADDR addr
, struct symtab
*symtab
,
5377 default_breakpoint_valid
= valid
;
5378 default_breakpoint_pspace
= pspace
;
5379 default_breakpoint_address
= addr
;
5380 default_breakpoint_symtab
= symtab
;
5381 default_breakpoint_line
= line
;
5384 /* Return true iff it is meaningful to use the address member of
5385 BPT. For some breakpoint types, the address member is irrelevant
5386 and it makes no sense to attempt to compare it to other addresses
5387 (or use it for any other purpose either).
5389 More specifically, each of the following breakpoint types will
5390 always have a zero valued address and we don't want to mark
5391 breakpoints of any of these types to be a duplicate of an actual
5392 breakpoint at address zero:
5400 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5402 enum bptype type
= bpt
->type
;
5404 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5407 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5408 true if LOC1 and LOC2 represent the same watchpoint location. */
5411 watchpoint_locations_match (struct bp_location
*loc1
,
5412 struct bp_location
*loc2
)
5414 /* Both of them must not be in moribund_locations. */
5415 gdb_assert (loc1
->owner
!= NULL
);
5416 gdb_assert (loc2
->owner
!= NULL
);
5418 /* If the target can evaluate the condition expression in hardware,
5419 then we we need to insert both watchpoints even if they are at
5420 the same place. Otherwise the watchpoint will only trigger when
5421 the condition of whichever watchpoint was inserted evaluates to
5422 true, not giving a chance for GDB to check the condition of the
5423 other watchpoint. */
5424 if ((loc1
->owner
->cond_exp
5425 && target_can_accel_watchpoint_condition (loc1
->address
,
5427 loc1
->watchpoint_type
,
5428 loc1
->owner
->cond_exp
))
5429 || (loc2
->owner
->cond_exp
5430 && target_can_accel_watchpoint_condition (loc2
->address
,
5432 loc2
->watchpoint_type
,
5433 loc2
->owner
->cond_exp
)))
5436 /* Note that this checks the owner's type, not the location's. In
5437 case the target does not support read watchpoints, but does
5438 support access watchpoints, we'll have bp_read_watchpoint
5439 watchpoints with hw_access locations. Those should be considered
5440 duplicates of hw_read locations. The hw_read locations will
5441 become hw_access locations later. */
5442 return (loc1
->owner
->type
== loc2
->owner
->type
5443 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5444 && loc1
->address
== loc2
->address
5445 && loc1
->length
== loc2
->length
);
5448 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5449 same breakpoint location. In most targets, this can only be true
5450 if ASPACE1 matches ASPACE2. On targets that have global
5451 breakpoints, the address space doesn't really matter. */
5454 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5455 struct address_space
*aspace2
, CORE_ADDR addr2
)
5457 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5458 || aspace1
== aspace2
)
5462 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5463 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5464 represent the same location. */
5467 breakpoint_locations_match (struct bp_location
*loc1
,
5468 struct bp_location
*loc2
)
5470 int hw_point1
, hw_point2
;
5472 /* Both of them must not be in moribund_locations. */
5473 gdb_assert (loc1
->owner
!= NULL
);
5474 gdb_assert (loc2
->owner
!= NULL
);
5476 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5477 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5479 if (hw_point1
!= hw_point2
)
5482 return watchpoint_locations_match (loc1
, loc2
);
5484 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5485 loc2
->pspace
->aspace
, loc2
->address
);
5489 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5490 int bnum
, int have_bnum
)
5495 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5496 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5498 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5499 bnum
, astr1
, astr2
);
5501 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5504 /* Adjust a breakpoint's address to account for architectural
5505 constraints on breakpoint placement. Return the adjusted address.
5506 Note: Very few targets require this kind of adjustment. For most
5507 targets, this function is simply the identity function. */
5510 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5511 CORE_ADDR bpaddr
, enum bptype bptype
)
5513 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5515 /* Very few targets need any kind of breakpoint adjustment. */
5518 else if (bptype
== bp_watchpoint
5519 || bptype
== bp_hardware_watchpoint
5520 || bptype
== bp_read_watchpoint
5521 || bptype
== bp_access_watchpoint
5522 || bptype
== bp_catchpoint
)
5524 /* Watchpoints and the various bp_catch_* eventpoints should not
5525 have their addresses modified. */
5530 CORE_ADDR adjusted_bpaddr
;
5532 /* Some targets have architectural constraints on the placement
5533 of breakpoint instructions. Obtain the adjusted address. */
5534 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5536 /* An adjusted breakpoint address can significantly alter
5537 a user's expectations. Print a warning if an adjustment
5539 if (adjusted_bpaddr
!= bpaddr
)
5540 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5542 return adjusted_bpaddr
;
5546 /* Allocate a struct bp_location. */
5548 static struct bp_location
*
5549 allocate_bp_location (struct breakpoint
*bpt
)
5551 struct bp_location
*loc
;
5553 loc
= xmalloc (sizeof (struct bp_location
));
5554 memset (loc
, 0, sizeof (*loc
));
5558 loc
->shlib_disabled
= 0;
5567 case bp_longjmp_resume
:
5569 case bp_exception_resume
:
5570 case bp_step_resume
:
5571 case bp_watchpoint_scope
:
5573 case bp_std_terminate
:
5574 case bp_shlib_event
:
5575 case bp_thread_event
:
5576 case bp_overlay_event
:
5578 case bp_longjmp_master
:
5579 case bp_std_terminate_master
:
5580 case bp_exception_master
:
5581 loc
->loc_type
= bp_loc_software_breakpoint
;
5583 case bp_hardware_breakpoint
:
5584 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5586 case bp_hardware_watchpoint
:
5587 case bp_read_watchpoint
:
5588 case bp_access_watchpoint
:
5589 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5594 case bp_fast_tracepoint
:
5595 case bp_static_tracepoint
:
5596 loc
->loc_type
= bp_loc_other
;
5599 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5607 free_bp_location (struct bp_location
*loc
)
5612 if (loc
->function_name
)
5613 xfree (loc
->function_name
);
5618 /* Increment reference count. */
5621 incref_bp_location (struct bp_location
*bl
)
5626 /* Decrement reference count. If the reference count reaches 0,
5627 destroy the bp_location. Sets *BLP to NULL. */
5630 decref_bp_location (struct bp_location
**blp
)
5632 gdb_assert ((*blp
)->refc
> 0);
5634 if (--(*blp
)->refc
== 0)
5635 free_bp_location (*blp
);
5639 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5640 type BPTYPE and has no locations as yet. */
5641 /* This function is used in gdbtk sources and thus can not be made
5644 static struct breakpoint
*
5645 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5648 struct breakpoint
*b
, *b1
;
5650 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5651 memset (b
, 0, sizeof (*b
));
5654 b
->gdbarch
= gdbarch
;
5655 b
->language
= current_language
->la_language
;
5656 b
->input_radix
= input_radix
;
5658 b
->enable_state
= bp_enabled
;
5661 b
->ignore_count
= 0;
5663 b
->frame_id
= null_frame_id
;
5664 b
->forked_inferior_pid
= null_ptid
;
5665 b
->exec_pathname
= NULL
;
5666 b
->syscalls_to_be_caught
= NULL
;
5668 b
->condition_not_parsed
= 0;
5669 b
->py_bp_object
= NULL
;
5671 /* Add this breakpoint to the end of the chain so that a list of
5672 breakpoints will come out in order of increasing numbers. */
5674 b1
= breakpoint_chain
;
5676 breakpoint_chain
= b
;
5686 /* Initialize loc->function_name. */
5688 set_breakpoint_location_function (struct bp_location
*loc
)
5690 gdb_assert (loc
->owner
!= NULL
);
5692 if (loc
->owner
->type
== bp_breakpoint
5693 || loc
->owner
->type
== bp_hardware_breakpoint
5694 || is_tracepoint (loc
->owner
))
5696 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5698 if (loc
->function_name
)
5699 loc
->function_name
= xstrdup (loc
->function_name
);
5703 /* Attempt to determine architecture of location identified by SAL. */
5704 static struct gdbarch
*
5705 get_sal_arch (struct symtab_and_line sal
)
5708 return get_objfile_arch (sal
.section
->objfile
);
5710 return get_objfile_arch (sal
.symtab
->objfile
);
5715 /* set_raw_breakpoint is a low level routine for allocating and
5716 partially initializing a breakpoint of type BPTYPE. The newly
5717 created breakpoint's address, section, source file name, and line
5718 number are provided by SAL. The newly created and partially
5719 initialized breakpoint is added to the breakpoint chain and
5720 is also returned as the value of this function.
5722 It is expected that the caller will complete the initialization of
5723 the newly created breakpoint struct as well as output any status
5724 information regarding the creation of a new breakpoint. In
5725 particular, set_raw_breakpoint does NOT set the breakpoint
5726 number! Care should be taken to not allow an error to occur
5727 prior to completing the initialization of the breakpoint. If this
5728 should happen, a bogus breakpoint will be left on the chain. */
5731 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5732 struct symtab_and_line sal
, enum bptype bptype
)
5734 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5736 CORE_ADDR adjusted_address
;
5737 struct gdbarch
*loc_gdbarch
;
5739 loc_gdbarch
= get_sal_arch (sal
);
5741 loc_gdbarch
= b
->gdbarch
;
5743 if (bptype
!= bp_catchpoint
)
5744 gdb_assert (sal
.pspace
!= NULL
);
5746 /* Adjust the breakpoint's address prior to allocating a location.
5747 Once we call allocate_bp_location(), that mostly uninitialized
5748 location will be placed on the location chain. Adjustment of the
5749 breakpoint may cause target_read_memory() to be called and we do
5750 not want its scan of the location chain to find a breakpoint and
5751 location that's only been partially initialized. */
5752 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5755 b
->loc
= allocate_bp_location (b
);
5756 b
->loc
->gdbarch
= loc_gdbarch
;
5757 b
->loc
->requested_address
= sal
.pc
;
5758 b
->loc
->address
= adjusted_address
;
5759 b
->loc
->pspace
= sal
.pspace
;
5761 /* Store the program space that was used to set the breakpoint, for
5762 breakpoint resetting. */
5763 b
->pspace
= sal
.pspace
;
5765 if (sal
.symtab
== NULL
)
5766 b
->source_file
= NULL
;
5768 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5769 b
->loc
->section
= sal
.section
;
5770 b
->line_number
= sal
.line
;
5772 set_breakpoint_location_function (b
->loc
);
5774 breakpoints_changed ();
5780 /* Note that the breakpoint object B describes a permanent breakpoint
5781 instruction, hard-wired into the inferior's code. */
5783 make_breakpoint_permanent (struct breakpoint
*b
)
5785 struct bp_location
*bl
;
5787 b
->enable_state
= bp_permanent
;
5789 /* By definition, permanent breakpoints are already present in the
5790 code. Mark all locations as inserted. For now,
5791 make_breakpoint_permanent is called in just one place, so it's
5792 hard to say if it's reasonable to have permanent breakpoint with
5793 multiple locations or not, but it's easy to implmement. */
5794 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5798 /* Call this routine when stepping and nexting to enable a breakpoint
5799 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5800 initiated the operation. */
5803 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5805 struct breakpoint
*b
, *b_tmp
;
5806 int thread
= tp
->num
;
5808 /* To avoid having to rescan all objfile symbols at every step,
5809 we maintain a list of continually-inserted but always disabled
5810 longjmp "master" breakpoints. Here, we simply create momentary
5811 clones of those and enable them for the requested thread. */
5812 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5813 if (b
->pspace
== current_program_space
5814 && (b
->type
== bp_longjmp_master
5815 || b
->type
== bp_exception_master
))
5817 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5819 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5820 clone
->thread
= thread
;
5823 tp
->initiating_frame
= frame
;
5826 /* Delete all longjmp breakpoints from THREAD. */
5828 delete_longjmp_breakpoint (int thread
)
5830 struct breakpoint
*b
, *b_tmp
;
5832 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5833 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5835 if (b
->thread
== thread
)
5836 delete_breakpoint (b
);
5841 enable_overlay_breakpoints (void)
5843 struct breakpoint
*b
;
5846 if (b
->type
== bp_overlay_event
)
5848 b
->enable_state
= bp_enabled
;
5849 update_global_location_list (1);
5850 overlay_events_enabled
= 1;
5855 disable_overlay_breakpoints (void)
5857 struct breakpoint
*b
;
5860 if (b
->type
== bp_overlay_event
)
5862 b
->enable_state
= bp_disabled
;
5863 update_global_location_list (0);
5864 overlay_events_enabled
= 0;
5868 /* Set an active std::terminate breakpoint for each std::terminate
5869 master breakpoint. */
5871 set_std_terminate_breakpoint (void)
5873 struct breakpoint
*b
, *b_tmp
;
5875 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5876 if (b
->pspace
== current_program_space
5877 && b
->type
== bp_std_terminate_master
)
5879 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5880 clone
->type
= bp_std_terminate
;
5884 /* Delete all the std::terminate breakpoints. */
5886 delete_std_terminate_breakpoint (void)
5888 struct breakpoint
*b
, *b_tmp
;
5890 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5891 if (b
->type
== bp_std_terminate
)
5892 delete_breakpoint (b
);
5896 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5898 struct breakpoint
*b
;
5900 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5902 b
->enable_state
= bp_enabled
;
5903 /* addr_string has to be used or breakpoint_re_set will delete me. */
5905 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5907 update_global_location_list_nothrow (1);
5913 remove_thread_event_breakpoints (void)
5915 struct breakpoint
*b
, *b_tmp
;
5917 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5918 if (b
->type
== bp_thread_event
5919 && b
->loc
->pspace
== current_program_space
)
5920 delete_breakpoint (b
);
5923 struct captured_parse_breakpoint_args
5926 struct symtabs_and_lines
*sals_p
;
5927 char ***addr_string_p
;
5931 struct lang_and_radix
5937 /* Create a breakpoint for JIT code registration and unregistration. */
5940 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5942 struct breakpoint
*b
;
5944 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5945 update_global_location_list_nothrow (1);
5949 /* Remove JIT code registration and unregistration breakpoint(s). */
5952 remove_jit_event_breakpoints (void)
5954 struct breakpoint
*b
, *b_tmp
;
5956 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5957 if (b
->type
== bp_jit_event
5958 && b
->loc
->pspace
== current_program_space
)
5959 delete_breakpoint (b
);
5963 remove_solib_event_breakpoints (void)
5965 struct breakpoint
*b
, *b_tmp
;
5967 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5968 if (b
->type
== bp_shlib_event
5969 && b
->loc
->pspace
== current_program_space
)
5970 delete_breakpoint (b
);
5974 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5976 struct breakpoint
*b
;
5978 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5979 update_global_location_list_nothrow (1);
5983 /* Disable any breakpoints that are on code in shared libraries. Only
5984 apply to enabled breakpoints, disabled ones can just stay disabled. */
5987 disable_breakpoints_in_shlibs (void)
5989 struct bp_location
*loc
, **locp_tmp
;
5991 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5993 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5994 struct breakpoint
*b
= loc
->owner
;
5996 /* We apply the check to all breakpoints, including disabled for
5997 those with loc->duplicate set. This is so that when breakpoint
5998 becomes enabled, or the duplicate is removed, gdb will try to
5999 insert all breakpoints. If we don't set shlib_disabled here,
6000 we'll try to insert those breakpoints and fail. */
6001 if (((b
->type
== bp_breakpoint
)
6002 || (b
->type
== bp_jit_event
)
6003 || (b
->type
== bp_hardware_breakpoint
)
6004 || (is_tracepoint (b
)))
6005 && loc
->pspace
== current_program_space
6006 && !loc
->shlib_disabled
6008 && PC_SOLIB (loc
->address
)
6010 && solib_name_from_address (loc
->pspace
, loc
->address
)
6014 loc
->shlib_disabled
= 1;
6019 /* Disable any breakpoints that are in in an unloaded shared library.
6020 Only apply to enabled breakpoints, disabled ones can just stay
6024 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6026 struct bp_location
*loc
, **locp_tmp
;
6027 int disabled_shlib_breaks
= 0;
6029 /* SunOS a.out shared libraries are always mapped, so do not
6030 disable breakpoints; they will only be reported as unloaded
6031 through clear_solib when GDB discards its shared library
6032 list. See clear_solib for more information. */
6033 if (exec_bfd
!= NULL
6034 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6037 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6039 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6040 struct breakpoint
*b
= loc
->owner
;
6042 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6043 || loc
->loc_type
== bp_loc_software_breakpoint
)
6044 && solib
->pspace
== loc
->pspace
6045 && !loc
->shlib_disabled
6046 && (b
->type
== bp_breakpoint
6047 || b
->type
== bp_jit_event
6048 || b
->type
== bp_hardware_breakpoint
)
6049 && solib_contains_address_p (solib
, loc
->address
))
6051 loc
->shlib_disabled
= 1;
6052 /* At this point, we cannot rely on remove_breakpoint
6053 succeeding so we must mark the breakpoint as not inserted
6054 to prevent future errors occurring in remove_breakpoints. */
6056 if (!disabled_shlib_breaks
)
6058 target_terminal_ours_for_output ();
6059 warning (_("Temporarily disabling breakpoints "
6060 "for unloaded shared library \"%s\""),
6063 disabled_shlib_breaks
= 1;
6068 /* FORK & VFORK catchpoints. */
6070 /* Implement the "insert" breakpoint_ops method for fork
6074 insert_catch_fork (struct bp_location
*bl
)
6076 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6079 /* Implement the "remove" breakpoint_ops method for fork
6083 remove_catch_fork (struct bp_location
*bl
)
6085 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6088 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6092 breakpoint_hit_catch_fork (struct breakpoint
*b
)
6094 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
6097 /* Implement the "print_it" breakpoint_ops method for fork
6100 static enum print_stop_action
6101 print_it_catch_fork (struct breakpoint
*b
)
6103 annotate_catchpoint (b
->number
);
6104 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6105 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6106 return PRINT_SRC_AND_LOC
;
6109 /* Implement the "print_one" breakpoint_ops method for fork
6113 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6115 struct value_print_options opts
;
6117 get_user_print_options (&opts
);
6119 /* Field 4, the address, is omitted (which makes the columns not
6120 line up too nicely with the headers, but the effect is relatively
6122 if (opts
.addressprint
)
6123 ui_out_field_skip (uiout
, "addr");
6125 ui_out_text (uiout
, "fork");
6126 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6128 ui_out_text (uiout
, ", process ");
6129 ui_out_field_int (uiout
, "what",
6130 ptid_get_pid (b
->forked_inferior_pid
));
6131 ui_out_spaces (uiout
, 1);
6135 /* Implement the "print_mention" breakpoint_ops method for fork
6139 print_mention_catch_fork (struct breakpoint
*b
)
6141 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6144 /* Implement the "print_recreate" breakpoint_ops method for fork
6148 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6150 fprintf_unfiltered (fp
, "catch fork");
6153 /* The breakpoint_ops structure to be used in fork catchpoints. */
6155 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6159 breakpoint_hit_catch_fork
,
6160 NULL
, /* resources_needed */
6161 print_it_catch_fork
,
6162 print_one_catch_fork
,
6163 print_mention_catch_fork
,
6164 print_recreate_catch_fork
6167 /* Implement the "insert" breakpoint_ops method for vfork
6171 insert_catch_vfork (struct bp_location
*bl
)
6173 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6176 /* Implement the "remove" breakpoint_ops method for vfork
6180 remove_catch_vfork (struct bp_location
*bl
)
6182 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6185 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6189 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6191 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6194 /* Implement the "print_it" breakpoint_ops method for vfork
6197 static enum print_stop_action
6198 print_it_catch_vfork (struct breakpoint
*b
)
6200 annotate_catchpoint (b
->number
);
6201 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6202 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6203 return PRINT_SRC_AND_LOC
;
6206 /* Implement the "print_one" breakpoint_ops method for vfork
6210 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6212 struct value_print_options opts
;
6214 get_user_print_options (&opts
);
6215 /* Field 4, the address, is omitted (which makes the columns not
6216 line up too nicely with the headers, but the effect is relatively
6218 if (opts
.addressprint
)
6219 ui_out_field_skip (uiout
, "addr");
6221 ui_out_text (uiout
, "vfork");
6222 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6224 ui_out_text (uiout
, ", process ");
6225 ui_out_field_int (uiout
, "what",
6226 ptid_get_pid (b
->forked_inferior_pid
));
6227 ui_out_spaces (uiout
, 1);
6231 /* Implement the "print_mention" breakpoint_ops method for vfork
6235 print_mention_catch_vfork (struct breakpoint
*b
)
6237 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6240 /* Implement the "print_recreate" breakpoint_ops method for vfork
6244 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6246 fprintf_unfiltered (fp
, "catch vfork");
6249 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6251 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6255 breakpoint_hit_catch_vfork
,
6256 NULL
, /* resources_needed */
6257 print_it_catch_vfork
,
6258 print_one_catch_vfork
,
6259 print_mention_catch_vfork
,
6260 print_recreate_catch_vfork
6263 /* Implement the "insert" breakpoint_ops method for syscall
6267 insert_catch_syscall (struct bp_location
*bl
)
6269 struct inferior
*inf
= current_inferior ();
6271 ++inf
->total_syscalls_count
;
6272 if (!bl
->owner
->syscalls_to_be_caught
)
6273 ++inf
->any_syscall_count
;
6279 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6284 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6286 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6287 uintptr_t vec_addr_offset
6288 = old_size
* ((uintptr_t) sizeof (int));
6290 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6291 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6293 memset ((void *) vec_addr
, 0,
6294 (iter
+ 1 - old_size
) * sizeof (int));
6296 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6297 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6301 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6302 inf
->total_syscalls_count
!= 0,
6303 inf
->any_syscall_count
,
6304 VEC_length (int, inf
->syscalls_counts
),
6305 VEC_address (int, inf
->syscalls_counts
));
6308 /* Implement the "remove" breakpoint_ops method for syscall
6312 remove_catch_syscall (struct bp_location
*bl
)
6314 struct inferior
*inf
= current_inferior ();
6316 --inf
->total_syscalls_count
;
6317 if (!bl
->owner
->syscalls_to_be_caught
)
6318 --inf
->any_syscall_count
;
6324 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6328 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6329 /* Shouldn't happen. */
6331 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6332 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6336 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6337 inf
->total_syscalls_count
!= 0,
6338 inf
->any_syscall_count
,
6339 VEC_length (int, inf
->syscalls_counts
),
6341 inf
->syscalls_counts
));
6344 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6348 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6350 /* We must check if we are catching specific syscalls in this
6351 breakpoint. If we are, then we must guarantee that the called
6352 syscall is the same syscall we are catching. */
6353 int syscall_number
= 0;
6355 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6358 /* Now, checking if the syscall is the same. */
6359 if (b
->syscalls_to_be_caught
)
6364 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6366 if (syscall_number
== iter
)
6376 /* Implement the "print_it" breakpoint_ops method for syscall
6379 static enum print_stop_action
6380 print_it_catch_syscall (struct breakpoint
*b
)
6382 /* These are needed because we want to know in which state a
6383 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6384 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6385 must print "called syscall" or "returned from syscall". */
6387 struct target_waitstatus last
;
6389 struct cleanup
*old_chain
;
6392 get_last_target_status (&ptid
, &last
);
6394 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6396 annotate_catchpoint (b
->number
);
6399 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6401 syscall_id
= xstrprintf ("'%s'", s
.name
);
6403 old_chain
= make_cleanup (xfree
, syscall_id
);
6405 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6406 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6407 b
->number
, syscall_id
);
6408 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6409 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6410 b
->number
, syscall_id
);
6412 do_cleanups (old_chain
);
6414 return PRINT_SRC_AND_LOC
;
6417 /* Implement the "print_one" breakpoint_ops method for syscall
6421 print_one_catch_syscall (struct breakpoint
*b
,
6422 struct bp_location
**last_loc
)
6424 struct value_print_options opts
;
6426 get_user_print_options (&opts
);
6427 /* Field 4, the address, is omitted (which makes the columns not
6428 line up too nicely with the headers, but the effect is relatively
6430 if (opts
.addressprint
)
6431 ui_out_field_skip (uiout
, "addr");
6434 if (b
->syscalls_to_be_caught
6435 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6436 ui_out_text (uiout
, "syscalls \"");
6438 ui_out_text (uiout
, "syscall \"");
6440 if (b
->syscalls_to_be_caught
)
6443 char *text
= xstrprintf ("%s", "");
6446 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6451 get_syscall_by_number (iter
, &s
);
6454 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6456 text
= xstrprintf ("%s%d, ", text
, iter
);
6458 /* We have to xfree the last 'text' (now stored at 'x')
6459 because xstrprintf dinamically allocates new space for it
6463 /* Remove the last comma. */
6464 text
[strlen (text
) - 2] = '\0';
6465 ui_out_field_string (uiout
, "what", text
);
6468 ui_out_field_string (uiout
, "what", "<any syscall>");
6469 ui_out_text (uiout
, "\" ");
6472 /* Implement the "print_mention" breakpoint_ops method for syscall
6476 print_mention_catch_syscall (struct breakpoint
*b
)
6478 if (b
->syscalls_to_be_caught
)
6482 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6483 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6485 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6488 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6492 get_syscall_by_number (iter
, &s
);
6495 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6497 printf_filtered (" %d", s
.number
);
6499 printf_filtered (")");
6502 printf_filtered (_("Catchpoint %d (any syscall)"),
6506 /* Implement the "print_recreate" breakpoint_ops method for syscall
6510 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6512 fprintf_unfiltered (fp
, "catch syscall");
6514 if (b
->syscalls_to_be_caught
)
6519 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6524 get_syscall_by_number (iter
, &s
);
6526 fprintf_unfiltered (fp
, " %s", s
.name
);
6528 fprintf_unfiltered (fp
, " %d", s
.number
);
6533 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6535 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6537 insert_catch_syscall
,
6538 remove_catch_syscall
,
6539 breakpoint_hit_catch_syscall
,
6540 NULL
, /* resources_needed */
6541 print_it_catch_syscall
,
6542 print_one_catch_syscall
,
6543 print_mention_catch_syscall
,
6544 print_recreate_catch_syscall
6547 /* Returns non-zero if 'b' is a syscall catchpoint. */
6550 syscall_catchpoint_p (struct breakpoint
*b
)
6552 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6555 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6556 but does NOT mention it nor update the global location list.
6557 This is useful if you need to fill more fields in the
6558 struct breakpoint before calling mention.
6560 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6561 If COND_STRING is not NULL, then store it in the breakpoint.
6562 OPS, if not NULL, is the breakpoint_ops structure associated
6563 to the catchpoint. */
6565 static struct breakpoint
*
6566 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6568 struct breakpoint_ops
*ops
)
6570 struct symtab_and_line sal
;
6571 struct breakpoint
*b
;
6574 sal
.pspace
= current_program_space
;
6576 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6577 set_breakpoint_count (breakpoint_count
+ 1);
6578 b
->number
= breakpoint_count
;
6580 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6582 b
->addr_string
= NULL
;
6583 b
->enable_state
= bp_enabled
;
6584 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6590 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6592 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6593 If COND_STRING is not NULL, then store it in the breakpoint.
6594 OPS, if not NULL, is the breakpoint_ops structure associated
6595 to the catchpoint. */
6597 static struct breakpoint
*
6598 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6599 char *cond_string
, struct breakpoint_ops
*ops
)
6601 struct breakpoint
*b
=
6602 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6605 update_global_location_list (1);
6611 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6612 int tempflag
, char *cond_string
,
6613 struct breakpoint_ops
*ops
)
6615 struct breakpoint
*b
6616 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6618 /* FIXME: We should put this information in a breakpoint private data
6620 b
->forked_inferior_pid
= null_ptid
;
6623 /* Exec catchpoints. */
6626 insert_catch_exec (struct bp_location
*bl
)
6628 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6632 remove_catch_exec (struct bp_location
*bl
)
6634 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6638 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6640 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6643 static enum print_stop_action
6644 print_it_catch_exec (struct breakpoint
*b
)
6646 annotate_catchpoint (b
->number
);
6647 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6649 return PRINT_SRC_AND_LOC
;
6653 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6655 struct value_print_options opts
;
6657 get_user_print_options (&opts
);
6659 /* Field 4, the address, is omitted (which makes the columns
6660 not line up too nicely with the headers, but the effect
6661 is relatively readable). */
6662 if (opts
.addressprint
)
6663 ui_out_field_skip (uiout
, "addr");
6665 ui_out_text (uiout
, "exec");
6666 if (b
->exec_pathname
!= NULL
)
6668 ui_out_text (uiout
, ", program \"");
6669 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6670 ui_out_text (uiout
, "\" ");
6675 print_mention_catch_exec (struct breakpoint
*b
)
6677 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6680 /* Implement the "print_recreate" breakpoint_ops method for exec
6684 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6686 fprintf_unfiltered (fp
, "catch exec");
6689 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6693 breakpoint_hit_catch_exec
,
6694 NULL
, /* resources_needed */
6695 print_it_catch_exec
,
6696 print_one_catch_exec
,
6697 print_mention_catch_exec
,
6698 print_recreate_catch_exec
6702 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6703 struct breakpoint_ops
*ops
)
6705 struct gdbarch
*gdbarch
= get_current_arch ();
6706 struct breakpoint
*b
=
6707 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6709 b
->syscalls_to_be_caught
= filter
;
6711 /* Now, we have to mention the breakpoint and update the global
6714 update_global_location_list (1);
6718 hw_breakpoint_used_count (void)
6720 struct breakpoint
*b
;
6725 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6733 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6736 struct breakpoint
*b
;
6737 struct bp_location
*bl
;
6739 *other_type_used
= 0;
6742 if (!breakpoint_enabled (b
))
6745 if (b
->type
== type
)
6746 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6748 /* Special types of hardware watchpoints may use more than
6750 if (b
->ops
&& b
->ops
->resources_needed
)
6751 i
+= b
->ops
->resources_needed (bl
);
6755 else if (is_hardware_watchpoint (b
))
6756 *other_type_used
= 1;
6763 disable_watchpoints_before_interactive_call_start (void)
6765 struct breakpoint
*b
;
6769 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6771 b
->enable_state
= bp_call_disabled
;
6772 update_global_location_list (0);
6778 enable_watchpoints_after_interactive_call_stop (void)
6780 struct breakpoint
*b
;
6784 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6786 b
->enable_state
= bp_enabled
;
6787 update_global_location_list (1);
6793 disable_breakpoints_before_startup (void)
6795 struct breakpoint
*b
;
6800 if (b
->pspace
!= current_program_space
)
6803 if ((b
->type
== bp_breakpoint
6804 || b
->type
== bp_hardware_breakpoint
)
6805 && breakpoint_enabled (b
))
6807 b
->enable_state
= bp_startup_disabled
;
6813 update_global_location_list (0);
6815 current_program_space
->executing_startup
= 1;
6819 enable_breakpoints_after_startup (void)
6821 struct breakpoint
*b
;
6824 current_program_space
->executing_startup
= 0;
6828 if (b
->pspace
!= current_program_space
)
6831 if ((b
->type
== bp_breakpoint
6832 || b
->type
== bp_hardware_breakpoint
)
6833 && b
->enable_state
== bp_startup_disabled
)
6835 b
->enable_state
= bp_enabled
;
6841 breakpoint_re_set ();
6845 /* Set a breakpoint that will evaporate an end of command
6846 at address specified by SAL.
6847 Restrict it to frame FRAME if FRAME is nonzero. */
6850 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6851 struct frame_id frame_id
, enum bptype type
)
6853 struct breakpoint
*b
;
6855 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6857 gdb_assert (!frame_id_inlined_p (frame_id
));
6859 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6860 b
->enable_state
= bp_enabled
;
6861 b
->disposition
= disp_donttouch
;
6862 b
->frame_id
= frame_id
;
6864 /* If we're debugging a multi-threaded program, then we want
6865 momentary breakpoints to be active in only a single thread of
6867 if (in_thread_list (inferior_ptid
))
6868 b
->thread
= pid_to_thread_id (inferior_ptid
);
6870 update_global_location_list_nothrow (1);
6875 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6879 clone_momentary_breakpoint (struct breakpoint
*orig
)
6881 struct breakpoint
*copy
;
6883 /* If there's nothing to clone, then return nothing. */
6887 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6888 copy
->loc
= allocate_bp_location (copy
);
6889 set_breakpoint_location_function (copy
->loc
);
6891 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6892 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6893 copy
->loc
->address
= orig
->loc
->address
;
6894 copy
->loc
->section
= orig
->loc
->section
;
6895 copy
->loc
->pspace
= orig
->loc
->pspace
;
6897 if (orig
->source_file
== NULL
)
6898 copy
->source_file
= NULL
;
6900 copy
->source_file
= xstrdup (orig
->source_file
);
6902 copy
->line_number
= orig
->line_number
;
6903 copy
->frame_id
= orig
->frame_id
;
6904 copy
->thread
= orig
->thread
;
6905 copy
->pspace
= orig
->pspace
;
6907 copy
->enable_state
= bp_enabled
;
6908 copy
->disposition
= disp_donttouch
;
6909 copy
->number
= internal_breakpoint_number
--;
6911 update_global_location_list_nothrow (0);
6916 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6919 struct symtab_and_line sal
;
6921 sal
= find_pc_line (pc
, 0);
6923 sal
.section
= find_pc_overlay (pc
);
6924 sal
.explicit_pc
= 1;
6926 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6930 /* Tell the user we have just set a breakpoint B. */
6933 mention (struct breakpoint
*b
)
6936 struct cleanup
*ui_out_chain
;
6937 struct value_print_options opts
;
6939 get_user_print_options (&opts
);
6941 /* FIXME: This is misplaced; mention() is called by things (like
6942 hitting a watchpoint) other than breakpoint creation. It should
6943 be possible to clean this up and at the same time replace the
6944 random calls to breakpoint_changed with this hook. */
6945 observer_notify_breakpoint_created (b
->number
);
6947 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6948 b
->ops
->print_mention (b
);
6953 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
6957 ui_out_text (uiout
, "Watchpoint ");
6958 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6959 ui_out_field_int (uiout
, "number", b
->number
);
6960 ui_out_text (uiout
, ": ");
6961 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6962 do_cleanups (ui_out_chain
);
6964 case bp_hardware_watchpoint
:
6965 ui_out_text (uiout
, "Hardware watchpoint ");
6966 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6967 ui_out_field_int (uiout
, "number", b
->number
);
6968 ui_out_text (uiout
, ": ");
6969 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6970 do_cleanups (ui_out_chain
);
6972 case bp_read_watchpoint
:
6973 ui_out_text (uiout
, "Hardware read watchpoint ");
6974 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6975 ui_out_field_int (uiout
, "number", b
->number
);
6976 ui_out_text (uiout
, ": ");
6977 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6978 do_cleanups (ui_out_chain
);
6980 case bp_access_watchpoint
:
6981 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6982 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6983 ui_out_field_int (uiout
, "number", b
->number
);
6984 ui_out_text (uiout
, ": ");
6985 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6986 do_cleanups (ui_out_chain
);
6989 if (ui_out_is_mi_like_p (uiout
))
6994 if (b
->disposition
== disp_del
)
6995 printf_filtered (_("Temporary breakpoint"));
6997 printf_filtered (_("Breakpoint"));
6998 printf_filtered (_(" %d"), b
->number
);
7001 case bp_hardware_breakpoint
:
7002 if (ui_out_is_mi_like_p (uiout
))
7007 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
7011 if (ui_out_is_mi_like_p (uiout
))
7016 printf_filtered (_("Tracepoint"));
7017 printf_filtered (_(" %d"), b
->number
);
7020 case bp_fast_tracepoint
:
7021 if (ui_out_is_mi_like_p (uiout
))
7026 printf_filtered (_("Fast tracepoint"));
7027 printf_filtered (_(" %d"), b
->number
);
7030 case bp_static_tracepoint
:
7031 if (ui_out_is_mi_like_p (uiout
))
7036 printf_filtered (_("Static tracepoint"));
7037 printf_filtered (_(" %d"), b
->number
);
7044 case bp_longjmp_resume
:
7046 case bp_exception_resume
:
7047 case bp_step_resume
:
7049 case bp_std_terminate
:
7050 case bp_watchpoint_scope
:
7051 case bp_shlib_event
:
7052 case bp_thread_event
:
7053 case bp_overlay_event
:
7055 case bp_longjmp_master
:
7056 case bp_std_terminate_master
:
7057 case bp_exception_master
:
7063 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7067 printf_filtered (_(" (%s) pending."), b
->addr_string
);
7071 if (opts
.addressprint
|| b
->source_file
== NULL
)
7073 printf_filtered (" at ");
7074 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
7078 printf_filtered (": file %s, line %d.",
7079 b
->source_file
, b
->line_number
);
7083 struct bp_location
*loc
= b
->loc
;
7085 for (; loc
; loc
= loc
->next
)
7087 printf_filtered (" (%d locations)", n
);
7092 if (ui_out_is_mi_like_p (uiout
))
7094 printf_filtered ("\n");
7098 static struct bp_location
*
7099 add_location_to_breakpoint (struct breakpoint
*b
,
7100 const struct symtab_and_line
*sal
)
7102 struct bp_location
*loc
, **tmp
;
7104 loc
= allocate_bp_location (b
);
7105 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7108 loc
->gdbarch
= get_sal_arch (*sal
);
7110 loc
->gdbarch
= b
->gdbarch
;
7111 loc
->requested_address
= sal
->pc
;
7112 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7113 loc
->requested_address
, b
->type
);
7114 loc
->pspace
= sal
->pspace
;
7115 gdb_assert (loc
->pspace
!= NULL
);
7116 loc
->section
= sal
->section
;
7118 set_breakpoint_location_function (loc
);
7123 /* Return 1 if LOC is pointing to a permanent breakpoint,
7124 return 0 otherwise. */
7127 bp_loc_is_permanent (struct bp_location
*loc
)
7131 const gdb_byte
*brk
;
7132 gdb_byte
*target_mem
;
7133 struct cleanup
*cleanup
;
7136 gdb_assert (loc
!= NULL
);
7138 addr
= loc
->address
;
7139 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7141 /* Software breakpoints unsupported? */
7145 target_mem
= alloca (len
);
7147 /* Enable the automatic memory restoration from breakpoints while
7148 we read the memory. Otherwise we could say about our temporary
7149 breakpoints they are permanent. */
7150 cleanup
= save_current_space_and_thread ();
7152 switch_to_program_space_and_thread (loc
->pspace
);
7153 make_show_memory_breakpoints_cleanup (0);
7155 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7156 && memcmp (target_mem
, brk
, len
) == 0)
7159 do_cleanups (cleanup
);
7166 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7167 as textual description of the location, and COND_STRING
7168 as condition expression. */
7171 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7172 struct symtabs_and_lines sals
, char *addr_string
,
7174 enum bptype type
, enum bpdisp disposition
,
7175 int thread
, int task
, int ignore_count
,
7176 struct breakpoint_ops
*ops
, int from_tty
,
7177 int enabled
, int internal
)
7179 struct breakpoint
*b
= NULL
;
7182 if (type
== bp_hardware_breakpoint
)
7184 int i
= hw_breakpoint_used_count ();
7185 int target_resources_ok
=
7186 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7188 if (target_resources_ok
== 0)
7189 error (_("No hardware breakpoint support in the target."));
7190 else if (target_resources_ok
< 0)
7191 error (_("Hardware breakpoints used exceeds limit."));
7194 gdb_assert (sals
.nelts
> 0);
7196 for (i
= 0; i
< sals
.nelts
; ++i
)
7198 struct symtab_and_line sal
= sals
.sals
[i
];
7199 struct bp_location
*loc
;
7203 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7205 loc_gdbarch
= gdbarch
;
7207 describe_other_breakpoints (loc_gdbarch
,
7208 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7213 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7214 set_breakpoint_number (internal
, b
);
7218 b
->cond_string
= cond_string
;
7219 b
->ignore_count
= ignore_count
;
7220 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7221 b
->disposition
= disposition
;
7222 b
->pspace
= sals
.sals
[0].pspace
;
7224 if (type
== bp_static_tracepoint
)
7226 struct static_tracepoint_marker marker
;
7228 if (is_marker_spec (addr_string
))
7230 /* We already know the marker exists, otherwise, we
7231 wouldn't see a sal for it. */
7232 char *p
= &addr_string
[3];
7237 p
= skip_spaces (p
);
7239 endp
= skip_to_space (p
);
7241 marker_str
= savestring (p
, endp
- p
);
7242 b
->static_trace_marker_id
= marker_str
;
7244 printf_filtered (_("Probed static tracepoint "
7246 b
->static_trace_marker_id
);
7248 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7250 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7251 release_static_tracepoint_marker (&marker
);
7253 printf_filtered (_("Probed static tracepoint "
7255 b
->static_trace_marker_id
);
7258 warning (_("Couldn't determine the static "
7259 "tracepoint marker to probe"));
7262 if (enabled
&& b
->pspace
->executing_startup
7263 && (b
->type
== bp_breakpoint
7264 || b
->type
== bp_hardware_breakpoint
))
7265 b
->enable_state
= bp_startup_disabled
;
7271 loc
= add_location_to_breakpoint (b
, &sal
);
7274 if (bp_loc_is_permanent (loc
))
7275 make_breakpoint_permanent (b
);
7279 char *arg
= b
->cond_string
;
7280 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7282 error (_("Garbage %s follows condition"), arg
);
7287 b
->addr_string
= addr_string
;
7289 /* addr_string has to be used or breakpoint_re_set will delete
7292 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7296 /* Do not mention breakpoints with a negative number, but do
7297 notify observers. */
7298 observer_notify_breakpoint_created (b
->number
);
7303 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7304 elements to fill the void space. */
7306 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7308 int i
= index_to_remove
+1;
7309 int last_index
= sal
->nelts
-1;
7311 for (;i
<= last_index
; ++i
)
7312 sal
->sals
[i
-1] = sal
->sals
[i
];
7317 /* If appropriate, obtains all sals that correspond to the same file
7318 and line as SAL, in all program spaces. Users debugging with IDEs,
7319 will want to set a breakpoint at foo.c:line, and not really care
7320 about program spaces. This is done only if SAL does not have
7321 explicit PC and has line and file information. If we got just a
7322 single expanded sal, return the original.
7324 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7325 which the name of enclosing function is different from SAL. This
7326 makes sure that if we have breakpoint originally set in template
7327 instantiation, say foo<int>(), we won't expand SAL to locations at
7328 the same line in all existing instantiations of 'foo'. */
7330 static struct symtabs_and_lines
7331 expand_line_sal_maybe (struct symtab_and_line sal
)
7333 struct symtabs_and_lines expanded
;
7334 CORE_ADDR original_pc
= sal
.pc
;
7335 char *original_function
= NULL
;
7338 struct cleanup
*old_chain
;
7340 /* If we have explicit pc, don't expand.
7341 If we have no line number, we can't expand. */
7342 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7345 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7346 expanded
.sals
[0] = sal
;
7352 old_chain
= save_current_space_and_thread ();
7354 switch_to_program_space_and_thread (sal
.pspace
);
7356 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7358 /* Note that expand_line_sal visits *all* program spaces. */
7359 expanded
= expand_line_sal (sal
);
7361 if (expanded
.nelts
== 1)
7363 /* We had one sal, we got one sal. Return that sal, adjusting it
7364 past the function prologue if necessary. */
7365 xfree (expanded
.sals
);
7367 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7368 sal
.pc
= original_pc
;
7369 expanded
.sals
[0] = sal
;
7370 skip_prologue_sal (&expanded
.sals
[0]);
7371 do_cleanups (old_chain
);
7375 if (!sal
.explicit_line
)
7377 CORE_ADDR func_addr
, func_end
;
7378 for (i
= 0; i
< expanded
.nelts
; ++i
)
7380 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7381 char *this_function
;
7383 /* We need to switch threads as well since we're about to
7385 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7387 if (find_pc_partial_function (pc
, &this_function
,
7388 &func_addr
, &func_end
))
7391 && strcmp (this_function
, original_function
) != 0)
7393 remove_sal (&expanded
, i
);
7400 /* Skip the function prologue if necessary. */
7401 for (i
= 0; i
< expanded
.nelts
; ++i
)
7402 skip_prologue_sal (&expanded
.sals
[i
]);
7404 do_cleanups (old_chain
);
7406 if (expanded
.nelts
<= 1)
7408 /* This is un ugly workaround. If we get zero expanded sals
7409 then something is really wrong. Fix that by returning the
7412 xfree (expanded
.sals
);
7414 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7415 sal
.pc
= original_pc
;
7416 expanded
.sals
[0] = sal
;
7423 for (i
= 0; i
< expanded
.nelts
; ++i
)
7424 if (expanded
.sals
[i
].pc
== original_pc
)
7435 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7436 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7437 value. COND_STRING, if not NULL, specified the condition to be
7438 used for all breakpoints. Essentially the only case where
7439 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7440 function. In that case, it's still not possible to specify
7441 separate conditions for different overloaded functions, so
7442 we take just a single condition string.
7444 NOTE: If the function succeeds, the caller is expected to cleanup
7445 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7446 array contents). If the function fails (error() is called), the
7447 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7448 COND and SALS arrays and each of those arrays contents. */
7451 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7452 struct symtabs_and_lines sals
, char **addr_string
,
7454 enum bptype type
, enum bpdisp disposition
,
7455 int thread
, int task
, int ignore_count
,
7456 struct breakpoint_ops
*ops
, int from_tty
,
7457 int enabled
, int internal
)
7461 for (i
= 0; i
< sals
.nelts
; ++i
)
7463 struct symtabs_and_lines expanded
=
7464 expand_line_sal_maybe (sals
.sals
[i
]);
7466 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7467 cond_string
, type
, disposition
,
7468 thread
, task
, ignore_count
, ops
,
7469 from_tty
, enabled
, internal
);
7473 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7474 followed by conditionals. On return, SALS contains an array of SAL
7475 addresses found. ADDR_STRING contains a vector of (canonical)
7476 address strings. ADDRESS points to the end of the SAL.
7478 The array and the line spec strings are allocated on the heap, it is
7479 the caller's responsibility to free them. */
7482 parse_breakpoint_sals (char **address
,
7483 struct symtabs_and_lines
*sals
,
7484 char ***addr_string
,
7487 char *addr_start
= *address
;
7489 *addr_string
= NULL
;
7490 /* If no arg given, or if first arg is 'if ', use the default
7492 if ((*address
) == NULL
7493 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7495 if (default_breakpoint_valid
)
7497 struct symtab_and_line sal
;
7499 init_sal (&sal
); /* Initialize to zeroes. */
7500 sals
->sals
= (struct symtab_and_line
*)
7501 xmalloc (sizeof (struct symtab_and_line
));
7502 sal
.pc
= default_breakpoint_address
;
7503 sal
.line
= default_breakpoint_line
;
7504 sal
.symtab
= default_breakpoint_symtab
;
7505 sal
.pspace
= default_breakpoint_pspace
;
7506 sal
.section
= find_pc_overlay (sal
.pc
);
7508 /* "break" without arguments is equivalent to "break *PC"
7509 where PC is the default_breakpoint_address. So make sure
7510 to set sal.explicit_pc to prevent GDB from trying to
7511 expand the list of sals to include all other instances
7512 with the same symtab and line. */
7513 sal
.explicit_pc
= 1;
7515 sals
->sals
[0] = sal
;
7519 error (_("No default breakpoint address now."));
7523 /* Force almost all breakpoints to be in terms of the
7524 current_source_symtab (which is decode_line_1's default).
7525 This should produce the results we want almost all of the
7526 time while leaving default_breakpoint_* alone.
7528 ObjC: However, don't match an Objective-C method name which
7529 may have a '+' or '-' succeeded by a '[' */
7531 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7533 if (default_breakpoint_valid
7535 || ((strchr ("+-", (*address
)[0]) != NULL
)
7536 && ((*address
)[1] != '['))))
7537 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7538 default_breakpoint_line
, addr_string
,
7541 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7542 addr_string
, not_found_ptr
);
7544 /* For any SAL that didn't have a canonical string, fill one in. */
7545 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7546 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7547 if (addr_start
!= (*address
))
7551 for (i
= 0; i
< sals
->nelts
; i
++)
7553 /* Add the string if not present. */
7554 if ((*addr_string
)[i
] == NULL
)
7555 (*addr_string
)[i
] = savestring (addr_start
,
7556 (*address
) - addr_start
);
7562 /* Convert each SAL into a real PC. Verify that the PC can be
7563 inserted as a breakpoint. If it can't throw an error. */
7566 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7570 for (i
= 0; i
< sals
->nelts
; i
++)
7571 resolve_sal_pc (&sals
->sals
[i
]);
7574 /* Fast tracepoints may have restrictions on valid locations. For
7575 instance, a fast tracepoint using a jump instead of a trap will
7576 likely have to overwrite more bytes than a trap would, and so can
7577 only be placed where the instruction is longer than the jump, or a
7578 multi-instruction sequence does not have a jump into the middle of
7582 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7583 struct symtabs_and_lines
*sals
)
7586 struct symtab_and_line
*sal
;
7588 struct cleanup
*old_chain
;
7590 for (i
= 0; i
< sals
->nelts
; i
++)
7592 sal
= &sals
->sals
[i
];
7594 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7596 old_chain
= make_cleanup (xfree
, msg
);
7599 error (_("May not have a fast tracepoint at 0x%s%s"),
7600 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7602 do_cleanups (old_chain
);
7607 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7609 struct captured_parse_breakpoint_args
*args
= data
;
7611 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7612 args
->not_found_ptr
);
7615 /* Given TOK, a string specification of condition and thread, as
7616 accepted by the 'break' command, extract the condition
7617 string and thread number and set *COND_STRING and *THREAD.
7618 PC identifies the context at which the condition should be parsed.
7619 If no condition is found, *COND_STRING is set to NULL.
7620 If no thread is found, *THREAD is set to -1. */
7622 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7623 char **cond_string
, int *thread
, int *task
)
7625 *cond_string
= NULL
;
7631 char *cond_start
= NULL
;
7632 char *cond_end
= NULL
;
7634 tok
= skip_spaces (tok
);
7636 end_tok
= skip_to_space (tok
);
7638 toklen
= end_tok
- tok
;
7640 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7642 struct expression
*expr
;
7644 tok
= cond_start
= end_tok
+ 1;
7645 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7648 *cond_string
= savestring (cond_start
,
7649 cond_end
- cond_start
);
7651 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7657 *thread
= strtol (tok
, &tok
, 0);
7659 error (_("Junk after thread keyword."));
7660 if (!valid_thread_id (*thread
))
7661 error (_("Unknown thread %d."), *thread
);
7663 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7669 *task
= strtol (tok
, &tok
, 0);
7671 error (_("Junk after task keyword."));
7672 if (!valid_task_id (*task
))
7673 error (_("Unknown task %d."), *task
);
7676 error (_("Junk at end of arguments."));
7680 /* Decode a static tracepoint marker spec. */
7682 static struct symtabs_and_lines
7683 decode_static_tracepoint_spec (char **arg_p
)
7685 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7686 struct symtabs_and_lines sals
;
7687 struct symtab_and_line sal
;
7689 struct cleanup
*old_chain
;
7690 char *p
= &(*arg_p
)[3];
7695 p
= skip_spaces (p
);
7697 endp
= skip_to_space (p
);
7699 marker_str
= savestring (p
, endp
- p
);
7700 old_chain
= make_cleanup (xfree
, marker_str
);
7702 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7703 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7704 error (_("No known static tracepoint marker named %s"), marker_str
);
7706 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7707 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7709 for (i
= 0; i
< sals
.nelts
; i
++)
7711 struct static_tracepoint_marker
*marker
;
7713 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7715 init_sal (&sals
.sals
[i
]);
7717 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7718 sals
.sals
[i
].pc
= marker
->address
;
7720 release_static_tracepoint_marker (marker
);
7723 do_cleanups (old_chain
);
7729 /* Set a breakpoint. This function is shared between CLI and MI
7730 functions for setting a breakpoint. This function has two major
7731 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7732 parameter. If non-zero, the function will parse arg, extracting
7733 breakpoint location, address and thread. Otherwise, ARG is just
7734 the location of breakpoint, with condition and thread specified by
7735 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7736 the breakpoint number will be allocated from the internal
7737 breakpoint count. Returns true if any breakpoint was created;
7741 create_breakpoint (struct gdbarch
*gdbarch
,
7742 char *arg
, char *cond_string
, int thread
,
7743 int parse_condition_and_thread
,
7744 int tempflag
, enum bptype type_wanted
,
7746 enum auto_boolean pending_break_support
,
7747 struct breakpoint_ops
*ops
,
7748 int from_tty
, int enabled
, int internal
)
7750 struct gdb_exception e
;
7751 struct symtabs_and_lines sals
;
7752 struct symtab_and_line pending_sal
;
7754 char *addr_start
= arg
;
7756 struct cleanup
*old_chain
;
7757 struct cleanup
*bkpt_chain
= NULL
;
7758 struct captured_parse_breakpoint_args parse_args
;
7763 int prev_bkpt_count
= breakpoint_count
;
7769 parse_args
.arg_p
= &arg
;
7770 parse_args
.sals_p
= &sals
;
7771 parse_args
.addr_string_p
= &addr_string
;
7772 parse_args
.not_found_ptr
= ¬_found
;
7774 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7778 sals
= decode_static_tracepoint_spec (&arg
);
7780 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7781 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7782 for (i
= 0; i
< sals
.nelts
; i
++)
7783 addr_string
[i
] = xstrdup (copy_arg
);
7787 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7788 &parse_args
, RETURN_MASK_ALL
);
7790 /* If caller is interested in rc value from parse, set value. */
7794 throw_exception (e
);
7798 case NOT_FOUND_ERROR
:
7800 /* If pending breakpoint support is turned off, throw
7803 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7804 throw_exception (e
);
7806 exception_print (gdb_stderr
, e
);
7808 /* If pending breakpoint support is auto query and the user
7809 selects no, then simply return the error code. */
7810 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7811 && !nquery (_("Make breakpoint pending on "
7812 "future shared library load? ")))
7815 /* At this point, either the user was queried about setting
7816 a pending breakpoint and selected yes, or pending
7817 breakpoint behavior is on and thus a pending breakpoint
7818 is defaulted on behalf of the user. */
7819 copy_arg
= xstrdup (addr_start
);
7820 addr_string
= ©_arg
;
7822 sals
.sals
= &pending_sal
;
7827 throw_exception (e
);
7836 /* Create a chain of things that always need to be cleaned up. */
7837 old_chain
= make_cleanup (null_cleanup
, 0);
7841 /* Make sure that all storage allocated to SALS gets freed. */
7842 make_cleanup (xfree
, sals
.sals
);
7844 /* Cleanup the addr_string array but not its contents. */
7845 make_cleanup (xfree
, addr_string
);
7848 /* ----------------------------- SNIP -----------------------------
7849 Anything added to the cleanup chain beyond this point is assumed
7850 to be part of a breakpoint. If the breakpoint create succeeds
7851 then the memory is not reclaimed. */
7852 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7854 /* Mark the contents of the addr_string for cleanup. These go on
7855 the bkpt_chain and only occur if the breakpoint create fails. */
7856 for (i
= 0; i
< sals
.nelts
; i
++)
7858 if (addr_string
[i
] != NULL
)
7859 make_cleanup (xfree
, addr_string
[i
]);
7862 /* Resolve all line numbers to PC's and verify that the addresses
7863 are ok for the target. */
7865 breakpoint_sals_to_pc (&sals
);
7867 /* Fast tracepoints may have additional restrictions on location. */
7868 if (type_wanted
== bp_fast_tracepoint
)
7869 check_fast_tracepoint_sals (gdbarch
, &sals
);
7871 /* Verify that condition can be parsed, before setting any
7872 breakpoints. Allocate a separate condition expression for each
7876 if (parse_condition_and_thread
)
7878 /* Here we only parse 'arg' to separate condition
7879 from thread number, so parsing in context of first
7880 sal is OK. When setting the breakpoint we'll
7881 re-parse it in context of each sal. */
7884 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7887 make_cleanup (xfree
, cond_string
);
7891 /* Create a private copy of condition string. */
7894 cond_string
= xstrdup (cond_string
);
7895 make_cleanup (xfree
, cond_string
);
7899 /* If the user is creating a static tracepoint by marker id
7900 (strace -m MARKER_ID), then store the sals index, so that
7901 breakpoint_re_set can try to match up which of the newly
7902 found markers corresponds to this one, and, don't try to
7903 expand multiple locations for each sal, given than SALS
7904 already should contain all sals for MARKER_ID. */
7905 if (type_wanted
== bp_static_tracepoint
7906 && is_marker_spec (addr_string
[0]))
7910 for (i
= 0; i
< sals
.nelts
; ++i
)
7912 struct symtabs_and_lines expanded
;
7913 struct breakpoint
*tp
;
7914 struct cleanup
*old_chain
;
7917 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7918 expanded
.sals
[0] = sals
.sals
[i
];
7919 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7921 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7922 cond_string
, type_wanted
,
7923 tempflag
? disp_del
: disp_donttouch
,
7924 thread
, task
, ignore_count
, ops
,
7925 from_tty
, enabled
, internal
);
7927 do_cleanups (old_chain
);
7929 /* Get the tracepoint we just created. */
7931 tp
= get_breakpoint (internal_breakpoint_number
);
7933 tp
= get_breakpoint (breakpoint_count
);
7934 gdb_assert (tp
!= NULL
);
7936 /* Given that its possible to have multiple markers with
7937 the same string id, if the user is creating a static
7938 tracepoint by marker id ("strace -m MARKER_ID"), then
7939 store the sals index, so that breakpoint_re_set can
7940 try to match up which of the newly found markers
7941 corresponds to this one */
7942 tp
->static_trace_marker_id_idx
= i
;
7946 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7948 tempflag
? disp_del
: disp_donttouch
,
7949 thread
, task
, ignore_count
, ops
, from_tty
,
7954 struct breakpoint
*b
;
7956 make_cleanup (xfree
, copy_arg
);
7958 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7959 set_breakpoint_number (internal
, b
);
7961 b
->addr_string
= addr_string
[0];
7962 b
->cond_string
= NULL
;
7963 b
->ignore_count
= ignore_count
;
7964 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7965 b
->condition_not_parsed
= 1;
7967 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7968 b
->pspace
= current_program_space
;
7969 b
->py_bp_object
= NULL
;
7971 if (enabled
&& b
->pspace
->executing_startup
7972 && (b
->type
== bp_breakpoint
7973 || b
->type
== bp_hardware_breakpoint
))
7974 b
->enable_state
= bp_startup_disabled
;
7977 /* Do not mention breakpoints with a negative number,
7978 but do notify observers. */
7979 observer_notify_breakpoint_created (b
->number
);
7986 warning (_("Multiple breakpoints were set.\nUse the "
7987 "\"delete\" command to delete unwanted breakpoints."));
7988 prev_breakpoint_count
= prev_bkpt_count
;
7991 /* That's it. Discard the cleanups for data inserted into the
7993 discard_cleanups (bkpt_chain
);
7994 /* But cleanup everything else. */
7995 do_cleanups (old_chain
);
7997 /* error call may happen here - have BKPT_CHAIN already discarded. */
7998 update_global_location_list (1);
8003 /* Set a breakpoint.
8004 ARG is a string describing breakpoint address,
8005 condition, and thread.
8006 FLAG specifies if a breakpoint is hardware on,
8007 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8011 break_command_1 (char *arg
, int flag
, int from_tty
)
8013 int tempflag
= flag
& BP_TEMPFLAG
;
8014 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8015 ? bp_hardware_breakpoint
8018 create_breakpoint (get_current_arch (),
8020 NULL
, 0, 1 /* parse arg */,
8021 tempflag
, type_wanted
,
8022 0 /* Ignore count */,
8023 pending_break_support
,
8024 NULL
/* breakpoint_ops */,
8031 /* Helper function for break_command_1 and disassemble_command. */
8034 resolve_sal_pc (struct symtab_and_line
*sal
)
8038 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8040 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8041 error (_("No line %d in file \"%s\"."),
8042 sal
->line
, sal
->symtab
->filename
);
8045 /* If this SAL corresponds to a breakpoint inserted using a line
8046 number, then skip the function prologue if necessary. */
8047 if (sal
->explicit_line
)
8048 skip_prologue_sal (sal
);
8051 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8053 struct blockvector
*bv
;
8057 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8060 sym
= block_linkage_function (b
);
8063 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8064 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8068 /* It really is worthwhile to have the section, so we'll
8069 just have to look harder. This case can be executed
8070 if we have line numbers but no functions (as can
8071 happen in assembly source). */
8073 struct minimal_symbol
*msym
;
8074 struct cleanup
*old_chain
= save_current_space_and_thread ();
8076 switch_to_program_space_and_thread (sal
->pspace
);
8078 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8080 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8082 do_cleanups (old_chain
);
8089 break_command (char *arg
, int from_tty
)
8091 break_command_1 (arg
, 0, from_tty
);
8095 tbreak_command (char *arg
, int from_tty
)
8097 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8101 hbreak_command (char *arg
, int from_tty
)
8103 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8107 thbreak_command (char *arg
, int from_tty
)
8109 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8113 stop_command (char *arg
, int from_tty
)
8115 printf_filtered (_("Specify the type of breakpoint to set.\n\
8116 Usage: stop in <function | address>\n\
8117 stop at <line>\n"));
8121 stopin_command (char *arg
, int from_tty
)
8125 if (arg
== (char *) NULL
)
8127 else if (*arg
!= '*')
8132 /* Look for a ':'. If this is a line number specification, then
8133 say it is bad, otherwise, it should be an address or
8134 function/method name. */
8135 while (*argptr
&& !hasColon
)
8137 hasColon
= (*argptr
== ':');
8142 badInput
= (*argptr
!= ':'); /* Not a class::method */
8144 badInput
= isdigit (*arg
); /* a simple line number */
8148 printf_filtered (_("Usage: stop in <function | address>\n"));
8150 break_command_1 (arg
, 0, from_tty
);
8154 stopat_command (char *arg
, int from_tty
)
8158 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8165 /* Look for a ':'. If there is a '::' then get out, otherwise
8166 it is probably a line number. */
8167 while (*argptr
&& !hasColon
)
8169 hasColon
= (*argptr
== ':');
8174 badInput
= (*argptr
== ':'); /* we have class::method */
8176 badInput
= !isdigit (*arg
); /* not a line number */
8180 printf_filtered (_("Usage: stop at <line>\n"));
8182 break_command_1 (arg
, 0, from_tty
);
8185 /* Return non-zero if EXP is verified as constant. Returned zero
8186 means EXP is variable. Also the constant detection may fail for
8187 some constant expressions and in such case still falsely return
8190 watchpoint_exp_is_const (const struct expression
*exp
)
8198 /* We are only interested in the descriptor of each element. */
8199 operator_length (exp
, i
, &oplenp
, &argsp
);
8202 switch (exp
->elts
[i
].opcode
)
8212 case BINOP_LOGICAL_AND
:
8213 case BINOP_LOGICAL_OR
:
8214 case BINOP_BITWISE_AND
:
8215 case BINOP_BITWISE_IOR
:
8216 case BINOP_BITWISE_XOR
:
8218 case BINOP_NOTEQUAL
:
8234 case TERNOP_SLICE_COUNT
:
8246 case OP_OBJC_NSSTRING
:
8249 case UNOP_LOGICAL_NOT
:
8250 case UNOP_COMPLEMENT
:
8253 /* Unary, binary and ternary operators: We have to check
8254 their operands. If they are constant, then so is the
8255 result of that operation. For instance, if A and B are
8256 determined to be constants, then so is "A + B".
8258 UNOP_IND is one exception to the rule above, because the
8259 value of *ADDR is not necessarily a constant, even when
8264 /* Check whether the associated symbol is a constant.
8266 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8267 possible that a buggy compiler could mark a variable as
8268 constant even when it is not, and TYPE_CONST would return
8269 true in this case, while SYMBOL_CLASS wouldn't.
8271 We also have to check for function symbols because they
8272 are always constant. */
8274 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8276 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8277 && SYMBOL_CLASS (s
) != LOC_CONST
8278 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8283 /* The default action is to return 0 because we are using
8284 the optimistic approach here: If we don't know something,
8285 then it is not a constant. */
8294 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8297 insert_watchpoint (struct bp_location
*bl
)
8299 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8301 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8302 bl
->owner
->cond_exp
);
8305 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8308 remove_watchpoint (struct bp_location
*bl
)
8310 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8312 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8313 bl
->owner
->cond_exp
);
8316 /* Implement the "resources_needed" breakpoint_ops method for
8317 hardware watchpoints. */
8320 resources_needed_watchpoint (const struct bp_location
*bl
)
8322 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8324 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8327 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8329 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8333 NULL
, /* breakpoint_hit */
8334 resources_needed_watchpoint
,
8335 NULL
, /* print_it */
8336 NULL
, /* print_one */
8337 NULL
, /* print_mention */
8338 NULL
/* print_recreate */
8341 /* accessflag: hw_write: watch write,
8342 hw_read: watch read,
8343 hw_access: watch access (read or write) */
8345 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8346 int just_location
, int internal
)
8348 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8349 struct expression
*exp
;
8350 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8351 struct value
*val
, *mark
, *result
;
8352 struct frame_info
*frame
;
8353 char *exp_start
= NULL
;
8354 char *exp_end
= NULL
;
8355 char *tok
, *id_tok_start
, *end_tok
;
8357 char *cond_start
= NULL
;
8358 char *cond_end
= NULL
;
8359 int i
, other_type_used
, target_resources_ok
= 0;
8360 enum bptype bp_type
;
8365 /* Make sure that we actually have parameters to parse. */
8366 if (arg
!= NULL
&& arg
[0] != '\0')
8368 toklen
= strlen (arg
); /* Size of argument list. */
8370 /* Points tok to the end of the argument list. */
8371 tok
= arg
+ toklen
- 1;
8373 /* Go backwards in the parameters list. Skip the last
8374 parameter. If we're expecting a 'thread <thread_num>'
8375 parameter, this should be the thread identifier. */
8376 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8378 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8381 /* Points end_tok to the beginning of the last token. */
8382 id_tok_start
= tok
+ 1;
8384 /* Go backwards in the parameters list. Skip one more
8385 parameter. If we're expecting a 'thread <thread_num>'
8386 parameter, we should reach a "thread" token. */
8387 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8392 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8395 /* Move the pointer forward to skip the whitespace and
8396 calculate the length of the token. */
8398 toklen
= end_tok
- tok
;
8400 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8402 /* At this point we've found a "thread" token, which means
8403 the user is trying to set a watchpoint that triggers
8404 only in a specific thread. */
8407 /* Extract the thread ID from the next token. */
8408 thread
= strtol (id_tok_start
, &endp
, 0);
8410 /* Check if the user provided a valid numeric value for the
8412 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8413 error (_("Invalid thread ID specification %s."), id_tok_start
);
8415 /* Check if the thread actually exists. */
8416 if (!valid_thread_id (thread
))
8417 error (_("Unknown thread %d."), thread
);
8419 /* Truncate the string and get rid of the thread <thread_num>
8420 parameter before the parameter list is parsed by the
8421 evaluate_expression() function. */
8426 /* Parse the rest of the arguments. */
8427 innermost_block
= NULL
;
8429 exp
= parse_exp_1 (&arg
, 0, 0);
8431 /* Remove trailing whitespace from the expression before saving it.
8432 This makes the eventual display of the expression string a bit
8434 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8437 /* Checking if the expression is not constant. */
8438 if (watchpoint_exp_is_const (exp
))
8442 len
= exp_end
- exp_start
;
8443 while (len
> 0 && isspace (exp_start
[len
- 1]))
8445 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8448 exp_valid_block
= innermost_block
;
8449 mark
= value_mark ();
8450 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8454 exp_valid_block
= NULL
;
8455 val
= value_addr (result
);
8456 release_value (val
);
8457 value_free_to_mark (mark
);
8459 else if (val
!= NULL
)
8460 release_value (val
);
8462 tok
= skip_spaces (arg
);
8463 end_tok
= skip_to_space (tok
);
8465 toklen
= end_tok
- tok
;
8466 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8468 struct expression
*cond
;
8470 innermost_block
= NULL
;
8471 tok
= cond_start
= end_tok
+ 1;
8472 cond
= parse_exp_1 (&tok
, 0, 0);
8474 /* The watchpoint expression may not be local, but the condition
8475 may still be. E.g.: `watch global if local > 0'. */
8476 cond_exp_valid_block
= innermost_block
;
8482 error (_("Junk at end of command."));
8484 if (accessflag
== hw_read
)
8485 bp_type
= bp_read_watchpoint
;
8486 else if (accessflag
== hw_access
)
8487 bp_type
= bp_access_watchpoint
;
8489 bp_type
= bp_hardware_watchpoint
;
8491 reg_cnt
= can_use_hardware_watchpoint (val
, target_exact_watchpoints
);
8492 if (reg_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8493 error (_("Expression cannot be implemented with read/access watchpoint."));
8496 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8497 target_resources_ok
=
8498 target_can_use_hardware_watchpoint (bp_type
, i
+ reg_cnt
,
8500 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8501 error (_("Target does not support this type of hardware watchpoint."));
8503 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8504 error (_("Target can only support one kind "
8505 "of HW watchpoint at a time."));
8508 /* Change the type of breakpoint to an ordinary watchpoint if a
8509 hardware watchpoint could not be set. */
8510 if (!reg_cnt
|| target_resources_ok
<= 0)
8511 bp_type
= bp_watchpoint
;
8513 frame
= block_innermost_frame (exp_valid_block
);
8515 /* If the expression is "local", then set up a "watchpoint scope"
8516 breakpoint at the point where we've left the scope of the watchpoint
8517 expression. Create the scope breakpoint before the watchpoint, so
8518 that we will encounter it first in bpstat_stop_status. */
8519 if (exp_valid_block
&& frame
)
8521 if (frame_id_p (frame_unwind_caller_id (frame
)))
8524 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8525 frame_unwind_caller_pc (frame
),
8526 bp_watchpoint_scope
);
8528 scope_breakpoint
->enable_state
= bp_enabled
;
8530 /* Automatically delete the breakpoint when it hits. */
8531 scope_breakpoint
->disposition
= disp_del
;
8533 /* Only break in the proper frame (help with recursion). */
8534 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8536 /* Set the address at which we will stop. */
8537 scope_breakpoint
->loc
->gdbarch
8538 = frame_unwind_caller_arch (frame
);
8539 scope_breakpoint
->loc
->requested_address
8540 = frame_unwind_caller_pc (frame
);
8541 scope_breakpoint
->loc
->address
8542 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8543 scope_breakpoint
->loc
->requested_address
,
8544 scope_breakpoint
->type
);
8548 /* Now set up the breakpoint. */
8549 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8550 set_breakpoint_number (internal
, b
);
8552 b
->disposition
= disp_donttouch
;
8554 b
->exp_valid_block
= exp_valid_block
;
8555 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8558 struct type
*t
= value_type (val
);
8559 CORE_ADDR addr
= value_as_address (val
);
8562 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8563 name
= type_to_string (t
);
8565 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8566 core_addr_to_string (addr
));
8569 b
->exp_string
= xstrprintf ("-location: %.*s",
8570 (int) (exp_end
- exp_start
), exp_start
);
8572 /* The above expression is in C. */
8573 b
->language
= language_c
;
8576 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8579 b
->ops
= &watchpoint_breakpoint_ops
;
8581 /* Use an exact watchpoint when there's only one memory region to be
8582 watched, and only one debug register is needed to watch it. */
8583 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
8586 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8592 b
->watchpoint_frame
= get_frame_id (frame
);
8593 b
->watchpoint_thread
= inferior_ptid
;
8597 b
->watchpoint_frame
= null_frame_id
;
8598 b
->watchpoint_thread
= null_ptid
;
8601 if (scope_breakpoint
!= NULL
)
8603 /* The scope breakpoint is related to the watchpoint. We will
8604 need to act on them together. */
8605 b
->related_breakpoint
= scope_breakpoint
;
8606 scope_breakpoint
->related_breakpoint
= b
;
8610 value_free_to_mark (mark
);
8612 /* Finally update the new watchpoint. This creates the locations
8613 that should be inserted. */
8614 update_watchpoint (b
, 1);
8616 /* Do not mention breakpoints with a negative number, but do
8617 notify observers. */
8618 observer_notify_breakpoint_created (b
->number
);
8621 update_global_location_list (1);
8624 /* Return count of debug registers needed to watch the given expression.
8625 If EXACT_WATCHPOINTS is 1, then consider that only the address of
8626 the start of the watched region will be monitored (i.e., all accesses
8627 will be aligned). This uses less debug registers on some targets.
8629 If the watchpoint cannot be handled in hardware return zero. */
8632 can_use_hardware_watchpoint (struct value
*v
, int exact_watchpoints
)
8634 int found_memory_cnt
= 0;
8635 struct value
*head
= v
;
8637 /* Did the user specifically forbid us to use hardware watchpoints? */
8638 if (!can_use_hw_watchpoints
)
8641 /* Make sure that the value of the expression depends only upon
8642 memory contents, and values computed from them within GDB. If we
8643 find any register references or function calls, we can't use a
8644 hardware watchpoint.
8646 The idea here is that evaluating an expression generates a series
8647 of values, one holding the value of every subexpression. (The
8648 expression a*b+c has five subexpressions: a, b, a*b, c, and
8649 a*b+c.) GDB's values hold almost enough information to establish
8650 the criteria given above --- they identify memory lvalues,
8651 register lvalues, computed values, etcetera. So we can evaluate
8652 the expression, and then scan the chain of values that leaves
8653 behind to decide whether we can detect any possible change to the
8654 expression's final value using only hardware watchpoints.
8656 However, I don't think that the values returned by inferior
8657 function calls are special in any way. So this function may not
8658 notice that an expression involving an inferior function call
8659 can't be watched with hardware watchpoints. FIXME. */
8660 for (; v
; v
= value_next (v
))
8662 if (VALUE_LVAL (v
) == lval_memory
)
8664 if (v
!= head
&& value_lazy (v
))
8665 /* A lazy memory lvalue in the chain is one that GDB never
8666 needed to fetch; we either just used its address (e.g.,
8667 `a' in `a.b') or we never needed it at all (e.g., `a'
8668 in `a,b'). This doesn't apply to HEAD; if that is
8669 lazy then it was not readable, but watch it anyway. */
8673 /* Ahh, memory we actually used! Check if we can cover
8674 it with hardware watchpoints. */
8675 struct type
*vtype
= check_typedef (value_type (v
));
8677 /* We only watch structs and arrays if user asked for it
8678 explicitly, never if they just happen to appear in a
8679 middle of some value chain. */
8681 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8682 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8684 CORE_ADDR vaddr
= value_address (v
);
8688 len
= (exact_watchpoints
8689 && is_scalar_type_recursive (vtype
))?
8690 1 : TYPE_LENGTH (value_type (v
));
8692 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
8696 found_memory_cnt
+= num_regs
;
8700 else if (VALUE_LVAL (v
) != not_lval
8701 && deprecated_value_modifiable (v
) == 0)
8702 return 0; /* These are values from the history (e.g., $1). */
8703 else if (VALUE_LVAL (v
) == lval_register
)
8704 return 0; /* Cannot watch a register with a HW watchpoint. */
8707 /* The expression itself looks suitable for using a hardware
8708 watchpoint, but give the target machine a chance to reject it. */
8709 return found_memory_cnt
;
8713 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8715 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8718 /* A helper function that looks for an argument at the start of a
8719 string. The argument must also either be at the end of the string,
8720 or be followed by whitespace. Returns 1 if it finds the argument,
8721 0 otherwise. If the argument is found, it updates *STR. */
8724 check_for_argument (char **str
, char *arg
, int arg_len
)
8726 if (strncmp (*str
, arg
, arg_len
) == 0
8727 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8735 /* A helper function that looks for the "-location" argument and then
8736 calls watch_command_1. */
8739 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8741 int just_location
= 0;
8744 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8745 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8747 arg
= skip_spaces (arg
);
8751 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8755 watch_command (char *arg
, int from_tty
)
8757 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8761 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8763 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8767 rwatch_command (char *arg
, int from_tty
)
8769 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8773 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8775 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8779 awatch_command (char *arg
, int from_tty
)
8781 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8785 /* Helper routines for the until_command routine in infcmd.c. Here
8786 because it uses the mechanisms of breakpoints. */
8788 struct until_break_command_continuation_args
8790 struct breakpoint
*breakpoint
;
8791 struct breakpoint
*breakpoint2
;
8795 /* This function is called by fetch_inferior_event via the
8796 cmd_continuation pointer, to complete the until command. It takes
8797 care of cleaning up the temporary breakpoints set up by the until
8800 until_break_command_continuation (void *arg
)
8802 struct until_break_command_continuation_args
*a
= arg
;
8804 delete_breakpoint (a
->breakpoint
);
8806 delete_breakpoint (a
->breakpoint2
);
8807 delete_longjmp_breakpoint (a
->thread_num
);
8811 until_break_command (char *arg
, int from_tty
, int anywhere
)
8813 struct symtabs_and_lines sals
;
8814 struct symtab_and_line sal
;
8815 struct frame_info
*frame
= get_selected_frame (NULL
);
8816 struct breakpoint
*breakpoint
;
8817 struct breakpoint
*breakpoint2
= NULL
;
8818 struct cleanup
*old_chain
;
8820 struct thread_info
*tp
;
8822 clear_proceed_status ();
8824 /* Set a breakpoint where the user wants it and at return from
8827 if (default_breakpoint_valid
)
8828 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8829 default_breakpoint_line
, (char ***) NULL
, NULL
);
8831 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8832 0, (char ***) NULL
, NULL
);
8834 if (sals
.nelts
!= 1)
8835 error (_("Couldn't get information on specified line."));
8838 xfree (sals
.sals
); /* malloc'd, so freed. */
8841 error (_("Junk at end of arguments."));
8843 resolve_sal_pc (&sal
);
8846 /* If the user told us to continue until a specified location,
8847 we don't specify a frame at which we need to stop. */
8848 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8849 null_frame_id
, bp_until
);
8851 /* Otherwise, specify the selected frame, because we want to stop
8852 only at the very same frame. */
8853 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8854 get_stack_frame_id (frame
),
8857 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8859 tp
= inferior_thread ();
8862 /* Keep within the current frame, or in frames called by the current
8865 if (frame_id_p (frame_unwind_caller_id (frame
)))
8867 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8868 sal
.pc
= frame_unwind_caller_pc (frame
);
8869 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8871 frame_unwind_caller_id (frame
),
8873 make_cleanup_delete_breakpoint (breakpoint2
);
8875 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
8876 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
8879 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8881 /* If we are running asynchronously, and proceed call above has
8882 actually managed to start the target, arrange for breakpoints to
8883 be deleted when the target stops. Otherwise, we're already
8884 stopped and delete breakpoints via cleanup chain. */
8886 if (target_can_async_p () && is_running (inferior_ptid
))
8888 struct until_break_command_continuation_args
*args
;
8889 args
= xmalloc (sizeof (*args
));
8891 args
->breakpoint
= breakpoint
;
8892 args
->breakpoint2
= breakpoint2
;
8893 args
->thread_num
= thread
;
8895 discard_cleanups (old_chain
);
8896 add_continuation (inferior_thread (),
8897 until_break_command_continuation
, args
,
8901 do_cleanups (old_chain
);
8904 /* This function attempts to parse an optional "if <cond>" clause
8905 from the arg string. If one is not found, it returns NULL.
8907 Else, it returns a pointer to the condition string. (It does not
8908 attempt to evaluate the string against a particular block.) And,
8909 it updates arg to point to the first character following the parsed
8910 if clause in the arg string. */
8913 ep_parse_optional_if_clause (char **arg
)
8917 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8920 /* Skip the "if" keyword. */
8923 /* Skip any extra leading whitespace, and record the start of the
8924 condition string. */
8925 *arg
= skip_spaces (*arg
);
8928 /* Assume that the condition occupies the remainder of the arg
8930 (*arg
) += strlen (cond_string
);
8935 /* Commands to deal with catching events, such as signals, exceptions,
8936 process start/exit, etc. */
8940 catch_fork_temporary
, catch_vfork_temporary
,
8941 catch_fork_permanent
, catch_vfork_permanent
8946 catch_fork_command_1 (char *arg
, int from_tty
,
8947 struct cmd_list_element
*command
)
8949 struct gdbarch
*gdbarch
= get_current_arch ();
8950 char *cond_string
= NULL
;
8951 catch_fork_kind fork_kind
;
8954 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8955 tempflag
= (fork_kind
== catch_fork_temporary
8956 || fork_kind
== catch_vfork_temporary
);
8960 arg
= skip_spaces (arg
);
8962 /* The allowed syntax is:
8964 catch [v]fork if <cond>
8966 First, check if there's an if clause. */
8967 cond_string
= ep_parse_optional_if_clause (&arg
);
8969 if ((*arg
!= '\0') && !isspace (*arg
))
8970 error (_("Junk at end of arguments."));
8972 /* If this target supports it, create a fork or vfork catchpoint
8973 and enable reporting of such events. */
8976 case catch_fork_temporary
:
8977 case catch_fork_permanent
:
8978 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8979 &catch_fork_breakpoint_ops
);
8981 case catch_vfork_temporary
:
8982 case catch_vfork_permanent
:
8983 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8984 &catch_vfork_breakpoint_ops
);
8987 error (_("unsupported or unknown fork kind; cannot catch it"));
8993 catch_exec_command_1 (char *arg
, int from_tty
,
8994 struct cmd_list_element
*command
)
8996 struct gdbarch
*gdbarch
= get_current_arch ();
8998 char *cond_string
= NULL
;
9000 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9004 arg
= skip_spaces (arg
);
9006 /* The allowed syntax is:
9008 catch exec if <cond>
9010 First, check if there's an if clause. */
9011 cond_string
= ep_parse_optional_if_clause (&arg
);
9013 if ((*arg
!= '\0') && !isspace (*arg
))
9014 error (_("Junk at end of arguments."));
9016 /* If this target supports it, create an exec catchpoint
9017 and enable reporting of such events. */
9018 create_catchpoint (gdbarch
, tempflag
, cond_string
,
9019 &catch_exec_breakpoint_ops
);
9022 static enum print_stop_action
9023 print_exception_catchpoint (struct breakpoint
*b
)
9025 int bp_temp
, bp_throw
;
9027 annotate_catchpoint (b
->number
);
9029 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9030 if (b
->loc
->address
!= b
->loc
->requested_address
)
9031 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9034 bp_temp
= b
->disposition
== disp_del
;
9036 bp_temp
? "Temporary catchpoint "
9038 if (!ui_out_is_mi_like_p (uiout
))
9039 ui_out_field_int (uiout
, "bkptno", b
->number
);
9041 bp_throw
? " (exception thrown), "
9042 : " (exception caught), ");
9043 if (ui_out_is_mi_like_p (uiout
))
9045 ui_out_field_string (uiout
, "reason",
9046 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9047 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9048 ui_out_field_int (uiout
, "bkptno", b
->number
);
9050 return PRINT_SRC_AND_LOC
;
9054 print_one_exception_catchpoint (struct breakpoint
*b
,
9055 struct bp_location
**last_loc
)
9057 struct value_print_options opts
;
9059 get_user_print_options (&opts
);
9060 if (opts
.addressprint
)
9063 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9064 ui_out_field_string (uiout
, "addr", "<PENDING>");
9066 ui_out_field_core_addr (uiout
, "addr",
9067 b
->loc
->gdbarch
, b
->loc
->address
);
9072 if (strstr (b
->addr_string
, "throw") != NULL
)
9073 ui_out_field_string (uiout
, "what", "exception throw");
9075 ui_out_field_string (uiout
, "what", "exception catch");
9079 print_mention_exception_catchpoint (struct breakpoint
*b
)
9084 bp_temp
= b
->disposition
== disp_del
;
9085 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9086 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9087 : _("Catchpoint "));
9088 ui_out_field_int (uiout
, "bkptno", b
->number
);
9089 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9093 /* Implement the "print_recreate" breakpoint_ops method for throw and
9094 catch catchpoints. */
9097 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9103 bp_temp
= b
->disposition
== disp_del
;
9104 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9105 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9106 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9109 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9112 NULL
, /* breakpoint_hit */
9113 NULL
, /* resources_needed */
9114 print_exception_catchpoint
,
9115 print_one_exception_catchpoint
,
9116 print_mention_exception_catchpoint
,
9117 print_recreate_exception_catchpoint
9121 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9122 enum exception_event_kind ex_event
, int from_tty
)
9124 char *trigger_func_name
;
9126 if (ex_event
== EX_EVENT_CATCH
)
9127 trigger_func_name
= "__cxa_begin_catch";
9129 trigger_func_name
= "__cxa_throw";
9131 create_breakpoint (get_current_arch (),
9132 trigger_func_name
, cond_string
, -1,
9133 0 /* condition and thread are valid. */,
9134 tempflag
, bp_breakpoint
,
9136 AUTO_BOOLEAN_TRUE
/* pending */,
9137 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9144 /* Deal with "catch catch" and "catch throw" commands. */
9147 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9148 int tempflag
, int from_tty
)
9150 char *cond_string
= NULL
;
9154 arg
= skip_spaces (arg
);
9156 cond_string
= ep_parse_optional_if_clause (&arg
);
9158 if ((*arg
!= '\0') && !isspace (*arg
))
9159 error (_("Junk at end of arguments."));
9161 if (ex_event
!= EX_EVENT_THROW
9162 && ex_event
!= EX_EVENT_CATCH
)
9163 error (_("Unsupported or unknown exception event; cannot catch it"));
9165 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9168 warning (_("Unsupported with this platform/compiler combination."));
9171 /* Implementation of "catch catch" command. */
9174 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9176 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9178 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9181 /* Implementation of "catch throw" command. */
9184 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9186 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9188 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9191 /* Create a breakpoint struct for Ada exception catchpoints. */
9194 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9195 struct symtab_and_line sal
,
9199 struct expression
*cond
,
9200 struct breakpoint_ops
*ops
,
9204 struct breakpoint
*b
;
9208 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9210 loc_gdbarch
= gdbarch
;
9212 describe_other_breakpoints (loc_gdbarch
,
9213 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9214 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9215 version for exception catchpoints, because two catchpoints
9216 used for different exception names will use the same address.
9217 In this case, a "breakpoint ... also set at..." warning is
9218 unproductive. Besides, the warning phrasing is also a bit
9219 inapropriate, we should use the word catchpoint, and tell
9220 the user what type of catchpoint it is. The above is good
9221 enough for now, though. */
9224 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9225 set_breakpoint_count (breakpoint_count
+ 1);
9227 b
->enable_state
= bp_enabled
;
9228 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9229 b
->number
= breakpoint_count
;
9230 b
->ignore_count
= 0;
9231 b
->loc
->cond
= cond
;
9232 b
->addr_string
= addr_string
;
9233 b
->language
= language_ada
;
9234 b
->cond_string
= cond_string
;
9235 b
->exp_string
= exp_string
;
9240 update_global_location_list (1);
9243 /* Implement the "catch exception" command. */
9246 catch_ada_exception_command (char *arg
, int from_tty
,
9247 struct cmd_list_element
*command
)
9249 struct gdbarch
*gdbarch
= get_current_arch ();
9251 struct symtab_and_line sal
;
9252 char *addr_string
= NULL
;
9253 char *exp_string
= NULL
;
9254 char *cond_string
= NULL
;
9255 struct expression
*cond
= NULL
;
9256 struct breakpoint_ops
*ops
= NULL
;
9258 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9262 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9263 &cond_string
, &cond
, &ops
);
9264 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9265 cond_string
, cond
, ops
, tempflag
,
9269 /* Cleanup function for a syscall filter list. */
9271 clean_up_filters (void *arg
)
9273 VEC(int) *iter
= *(VEC(int) **) arg
;
9274 VEC_free (int, iter
);
9277 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9278 filter list, or NULL if no filtering is required. */
9280 catch_syscall_split_args (char *arg
)
9282 VEC(int) *result
= NULL
;
9283 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9285 while (*arg
!= '\0')
9287 int i
, syscall_number
;
9292 /* Skip whitespace. */
9293 while (isspace (*arg
))
9296 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9297 cur_name
[i
] = arg
[i
];
9301 /* Check if the user provided a syscall name or a number. */
9302 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9303 if (*endptr
== '\0')
9304 get_syscall_by_number (syscall_number
, &s
);
9307 /* We have a name. Let's check if it's valid and convert it
9309 get_syscall_by_name (cur_name
, &s
);
9311 if (s
.number
== UNKNOWN_SYSCALL
)
9312 /* Here we have to issue an error instead of a warning,
9313 because GDB cannot do anything useful if there's no
9314 syscall number to be caught. */
9315 error (_("Unknown syscall name '%s'."), cur_name
);
9318 /* Ok, it's valid. */
9319 VEC_safe_push (int, result
, s
.number
);
9322 discard_cleanups (cleanup
);
9326 /* Implement the "catch syscall" command. */
9329 catch_syscall_command_1 (char *arg
, int from_tty
,
9330 struct cmd_list_element
*command
)
9335 struct gdbarch
*gdbarch
= get_current_arch ();
9337 /* Checking if the feature if supported. */
9338 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9339 error (_("The feature 'catch syscall' is not supported on \
9340 this architecture yet."));
9342 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9344 arg
= skip_spaces (arg
);
9346 /* We need to do this first "dummy" translation in order
9347 to get the syscall XML file loaded or, most important,
9348 to display a warning to the user if there's no XML file
9349 for his/her architecture. */
9350 get_syscall_by_number (0, &s
);
9352 /* The allowed syntax is:
9354 catch syscall <name | number> [<name | number> ... <name | number>]
9356 Let's check if there's a syscall name. */
9359 filter
= catch_syscall_split_args (arg
);
9363 create_syscall_event_catchpoint (tempflag
, filter
,
9364 &catch_syscall_breakpoint_ops
);
9367 /* Implement the "catch assert" command. */
9370 catch_assert_command (char *arg
, int from_tty
,
9371 struct cmd_list_element
*command
)
9373 struct gdbarch
*gdbarch
= get_current_arch ();
9375 struct symtab_and_line sal
;
9376 char *addr_string
= NULL
;
9377 struct breakpoint_ops
*ops
= NULL
;
9379 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9383 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9384 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9385 ops
, tempflag
, from_tty
);
9389 catch_command (char *arg
, int from_tty
)
9391 error (_("Catch requires an event name."));
9396 tcatch_command (char *arg
, int from_tty
)
9398 error (_("Catch requires an event name."));
9401 /* Delete breakpoints by address or line. */
9404 clear_command (char *arg
, int from_tty
)
9406 struct breakpoint
*b
;
9407 VEC(breakpoint_p
) *found
= 0;
9410 struct symtabs_and_lines sals
;
9411 struct symtab_and_line sal
;
9416 sals
= decode_line_spec (arg
, 1);
9421 sals
.sals
= (struct symtab_and_line
*)
9422 xmalloc (sizeof (struct symtab_and_line
));
9423 make_cleanup (xfree
, sals
.sals
);
9424 init_sal (&sal
); /* Initialize to zeroes. */
9425 sal
.line
= default_breakpoint_line
;
9426 sal
.symtab
= default_breakpoint_symtab
;
9427 sal
.pc
= default_breakpoint_address
;
9428 sal
.pspace
= default_breakpoint_pspace
;
9429 if (sal
.symtab
== 0)
9430 error (_("No source file specified."));
9438 /* We don't call resolve_sal_pc here. That's not as bad as it
9439 seems, because all existing breakpoints typically have both
9440 file/line and pc set. So, if clear is given file/line, we can
9441 match this to existing breakpoint without obtaining pc at all.
9443 We only support clearing given the address explicitly
9444 present in breakpoint table. Say, we've set breakpoint
9445 at file:line. There were several PC values for that file:line,
9446 due to optimization, all in one block.
9448 We've picked one PC value. If "clear" is issued with another
9449 PC corresponding to the same file:line, the breakpoint won't
9450 be cleared. We probably can still clear the breakpoint, but
9451 since the other PC value is never presented to user, user
9452 can only find it by guessing, and it does not seem important
9455 /* For each line spec given, delete bps which correspond to it. Do
9456 it in two passes, solely to preserve the current behavior that
9457 from_tty is forced true if we delete more than one
9461 for (i
= 0; i
< sals
.nelts
; i
++)
9463 /* If exact pc given, clear bpts at that pc.
9464 If line given (pc == 0), clear all bpts on specified line.
9465 If defaulting, clear all bpts on default line
9468 defaulting sal.pc != 0 tests to do
9473 1 0 <can't happen> */
9477 /* Find all matching breakpoints and add them to 'found'. */
9481 /* Are we going to delete b? */
9482 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9484 struct bp_location
*loc
= b
->loc
;
9485 for (; loc
; loc
= loc
->next
)
9487 int pc_match
= sal
.pc
9488 && (loc
->pspace
== sal
.pspace
)
9489 && (loc
->address
== sal
.pc
)
9490 && (!section_is_overlay (loc
->section
)
9491 || loc
->section
== sal
.section
);
9492 int line_match
= ((default_match
|| (0 == sal
.pc
))
9493 && b
->source_file
!= NULL
9494 && sal
.symtab
!= NULL
9495 && sal
.pspace
== loc
->pspace
9496 && strcmp (b
->source_file
,
9497 sal
.symtab
->filename
) == 0
9498 && b
->line_number
== sal
.line
);
9499 if (pc_match
|| line_match
)
9508 VEC_safe_push(breakpoint_p
, found
, b
);
9511 /* Now go thru the 'found' chain and delete them. */
9512 if (VEC_empty(breakpoint_p
, found
))
9515 error (_("No breakpoint at %s."), arg
);
9517 error (_("No breakpoint at this line."));
9520 if (VEC_length(breakpoint_p
, found
) > 1)
9521 from_tty
= 1; /* Always report if deleted more than one. */
9524 if (VEC_length(breakpoint_p
, found
) == 1)
9525 printf_unfiltered (_("Deleted breakpoint "));
9527 printf_unfiltered (_("Deleted breakpoints "));
9529 breakpoints_changed ();
9531 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9534 printf_unfiltered ("%d ", b
->number
);
9535 delete_breakpoint (b
);
9538 putchar_unfiltered ('\n');
9541 /* Delete breakpoint in BS if they are `delete' breakpoints and
9542 all breakpoints that are marked for deletion, whether hit or not.
9543 This is called after any breakpoint is hit, or after errors. */
9546 breakpoint_auto_delete (bpstat bs
)
9548 struct breakpoint
*b
, *b_tmp
;
9550 for (; bs
; bs
= bs
->next
)
9551 if (bs
->breakpoint_at
9552 && bs
->breakpoint_at
->disposition
== disp_del
9554 delete_breakpoint (bs
->breakpoint_at
);
9556 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9558 if (b
->disposition
== disp_del_at_next_stop
)
9559 delete_breakpoint (b
);
9563 /* A comparison function for bp_location AP and BP being interfaced to
9564 qsort. Sort elements primarily by their ADDRESS (no matter what
9565 does breakpoint_address_is_meaningful say for its OWNER),
9566 secondarily by ordering first bp_permanent OWNERed elements and
9567 terciarily just ensuring the array is sorted stable way despite
9568 qsort being an instable algorithm. */
9571 bp_location_compare (const void *ap
, const void *bp
)
9573 struct bp_location
*a
= *(void **) ap
;
9574 struct bp_location
*b
= *(void **) bp
;
9575 /* A and B come from existing breakpoints having non-NULL OWNER. */
9576 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9577 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9579 if (a
->address
!= b
->address
)
9580 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9582 /* Sort permanent breakpoints first. */
9583 if (a_perm
!= b_perm
)
9584 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9586 /* Make the user-visible order stable across GDB runs. Locations of
9587 the same breakpoint can be sorted in arbitrary order. */
9589 if (a
->owner
->number
!= b
->owner
->number
)
9590 return (a
->owner
->number
> b
->owner
->number
)
9591 - (a
->owner
->number
< b
->owner
->number
);
9593 return (a
> b
) - (a
< b
);
9596 /* Set bp_location_placed_address_before_address_max and
9597 bp_location_shadow_len_after_address_max according to the current
9598 content of the bp_location array. */
9601 bp_location_target_extensions_update (void)
9603 struct bp_location
*bl
, **blp_tmp
;
9605 bp_location_placed_address_before_address_max
= 0;
9606 bp_location_shadow_len_after_address_max
= 0;
9608 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9610 CORE_ADDR start
, end
, addr
;
9612 if (!bp_location_has_shadow (bl
))
9615 start
= bl
->target_info
.placed_address
;
9616 end
= start
+ bl
->target_info
.shadow_len
;
9618 gdb_assert (bl
->address
>= start
);
9619 addr
= bl
->address
- start
;
9620 if (addr
> bp_location_placed_address_before_address_max
)
9621 bp_location_placed_address_before_address_max
= addr
;
9623 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9625 gdb_assert (bl
->address
< end
);
9626 addr
= end
- bl
->address
;
9627 if (addr
> bp_location_shadow_len_after_address_max
)
9628 bp_location_shadow_len_after_address_max
= addr
;
9632 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9633 into the inferior, only remove already-inserted locations that no
9634 longer should be inserted. Functions that delete a breakpoint or
9635 breakpoints should pass false, so that deleting a breakpoint
9636 doesn't have the side effect of inserting the locations of other
9637 breakpoints that are marked not-inserted, but should_be_inserted
9638 returns true on them.
9640 This behaviour is useful is situations close to tear-down -- e.g.,
9641 after an exec, while the target still has execution, but breakpoint
9642 shadows of the previous executable image should *NOT* be restored
9643 to the new image; or before detaching, where the target still has
9644 execution and wants to delete breakpoints from GDB's lists, and all
9645 breakpoints had already been removed from the inferior. */
9648 update_global_location_list (int should_insert
)
9650 struct breakpoint
*b
;
9651 struct bp_location
**locp
, *loc
;
9652 struct cleanup
*cleanups
;
9654 /* Used in the duplicates detection below. When iterating over all
9655 bp_locations, points to the first bp_location of a given address.
9656 Breakpoints and watchpoints of different types are never
9657 duplicates of each other. Keep one pointer for each type of
9658 breakpoint/watchpoint, so we only need to loop over all locations
9660 struct bp_location
*bp_loc_first
; /* breakpoint */
9661 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9662 struct bp_location
*awp_loc_first
; /* access watchpoint */
9663 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9665 /* Saved former bp_location array which we compare against the newly
9666 built bp_location from the current state of ALL_BREAKPOINTS. */
9667 struct bp_location
**old_location
, **old_locp
;
9668 unsigned old_location_count
;
9670 old_location
= bp_location
;
9671 old_location_count
= bp_location_count
;
9673 bp_location_count
= 0;
9674 cleanups
= make_cleanup (xfree
, old_location
);
9677 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9678 bp_location_count
++;
9680 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9683 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9685 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9686 bp_location_compare
);
9688 bp_location_target_extensions_update ();
9690 /* Identify bp_location instances that are no longer present in the
9691 new list, and therefore should be freed. Note that it's not
9692 necessary that those locations should be removed from inferior --
9693 if there's another location at the same address (previously
9694 marked as duplicate), we don't need to remove/insert the
9697 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9698 and former bp_location array state respectively. */
9701 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9704 struct bp_location
*old_loc
= *old_locp
;
9705 struct bp_location
**loc2p
;
9707 /* Tells if 'old_loc' is found amoung the new locations. If
9708 not, we have to free it. */
9709 int found_object
= 0;
9710 /* Tells if the location should remain inserted in the target. */
9711 int keep_in_target
= 0;
9714 /* Skip LOCP entries which will definitely never be needed.
9715 Stop either at or being the one matching OLD_LOC. */
9716 while (locp
< bp_location
+ bp_location_count
9717 && (*locp
)->address
< old_loc
->address
)
9721 (loc2p
< bp_location
+ bp_location_count
9722 && (*loc2p
)->address
== old_loc
->address
);
9725 if (*loc2p
== old_loc
)
9732 /* If this location is no longer present, and inserted, look if
9733 there's maybe a new location at the same address. If so,
9734 mark that one inserted, and don't remove this one. This is
9735 needed so that we don't have a time window where a breakpoint
9736 at certain location is not inserted. */
9738 if (old_loc
->inserted
)
9740 /* If the location is inserted now, we might have to remove
9743 if (found_object
&& should_be_inserted (old_loc
))
9745 /* The location is still present in the location list,
9746 and still should be inserted. Don't do anything. */
9751 /* The location is either no longer present, or got
9752 disabled. See if there's another location at the
9753 same address, in which case we don't need to remove
9754 this one from the target. */
9756 /* OLD_LOC comes from existing struct breakpoint. */
9757 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9760 (loc2p
< bp_location
+ bp_location_count
9761 && (*loc2p
)->address
== old_loc
->address
);
9764 struct bp_location
*loc2
= *loc2p
;
9766 if (breakpoint_locations_match (loc2
, old_loc
))
9768 /* For the sake of should_be_inserted.
9769 Duplicates check below will fix up this
9771 loc2
->duplicate
= 0;
9773 /* Read watchpoint locations are switched to
9774 access watchpoints, if the former are not
9775 supported, but the latter are. */
9776 if (is_hardware_watchpoint (old_loc
->owner
))
9778 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9779 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9782 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9785 loc2
->target_info
= old_loc
->target_info
;
9794 if (!keep_in_target
)
9796 if (remove_breakpoint (old_loc
, mark_uninserted
))
9798 /* This is just about all we can do. We could keep
9799 this location on the global list, and try to
9800 remove it next time, but there's no particular
9801 reason why we will succeed next time.
9803 Note that at this point, old_loc->owner is still
9804 valid, as delete_breakpoint frees the breakpoint
9805 only after calling us. */
9806 printf_filtered (_("warning: Error removing "
9808 old_loc
->owner
->number
);
9816 if (removed
&& non_stop
9817 && breakpoint_address_is_meaningful (old_loc
->owner
)
9818 && !is_hardware_watchpoint (old_loc
->owner
))
9820 /* This location was removed from the target. In
9821 non-stop mode, a race condition is possible where
9822 we've removed a breakpoint, but stop events for that
9823 breakpoint are already queued and will arrive later.
9824 We apply an heuristic to be able to distinguish such
9825 SIGTRAPs from other random SIGTRAPs: we keep this
9826 breakpoint location for a bit, and will retire it
9827 after we see some number of events. The theory here
9828 is that reporting of events should, "on the average",
9829 be fair, so after a while we'll see events from all
9830 threads that have anything of interest, and no longer
9831 need to keep this breakpoint location around. We
9832 don't hold locations forever so to reduce chances of
9833 mistaking a non-breakpoint SIGTRAP for a breakpoint
9836 The heuristic failing can be disastrous on
9837 decr_pc_after_break targets.
9839 On decr_pc_after_break targets, like e.g., x86-linux,
9840 if we fail to recognize a late breakpoint SIGTRAP,
9841 because events_till_retirement has reached 0 too
9842 soon, we'll fail to do the PC adjustment, and report
9843 a random SIGTRAP to the user. When the user resumes
9844 the inferior, it will most likely immediately crash
9845 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9846 corrupted, because of being resumed e.g., in the
9847 middle of a multi-byte instruction, or skipped a
9848 one-byte instruction. This was actually seen happen
9849 on native x86-linux, and should be less rare on
9850 targets that do not support new thread events, like
9851 remote, due to the heuristic depending on
9854 Mistaking a random SIGTRAP for a breakpoint trap
9855 causes similar symptoms (PC adjustment applied when
9856 it shouldn't), but then again, playing with SIGTRAPs
9857 behind the debugger's back is asking for trouble.
9859 Since hardware watchpoint traps are always
9860 distinguishable from other traps, so we don't need to
9861 apply keep hardware watchpoint moribund locations
9862 around. We simply always ignore hardware watchpoint
9863 traps we can no longer explain. */
9865 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9866 old_loc
->owner
= NULL
;
9868 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9872 old_loc
->owner
= NULL
;
9873 decref_bp_location (&old_loc
);
9878 /* Rescan breakpoints at the same address and section, marking the
9879 first one as "first" and any others as "duplicates". This is so
9880 that the bpt instruction is only inserted once. If we have a
9881 permanent breakpoint at the same place as BPT, make that one the
9882 official one, and the rest as duplicates. Permanent breakpoints
9883 are sorted first for the same address.
9885 Do the same for hardware watchpoints, but also considering the
9886 watchpoint's type (regular/access/read) and length. */
9888 bp_loc_first
= NULL
;
9889 wp_loc_first
= NULL
;
9890 awp_loc_first
= NULL
;
9891 rwp_loc_first
= NULL
;
9892 ALL_BP_LOCATIONS (loc
, locp
)
9894 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
9896 struct breakpoint
*b
= loc
->owner
;
9897 struct bp_location
**loc_first_p
;
9899 if (b
->enable_state
== bp_disabled
9900 || b
->enable_state
== bp_call_disabled
9901 || b
->enable_state
== bp_startup_disabled
9903 || loc
->shlib_disabled
9904 || !breakpoint_address_is_meaningful (b
)
9905 || is_tracepoint (b
))
9908 /* Permanent breakpoint should always be inserted. */
9909 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9910 internal_error (__FILE__
, __LINE__
,
9911 _("allegedly permanent breakpoint is not "
9912 "actually inserted"));
9914 if (b
->type
== bp_hardware_watchpoint
)
9915 loc_first_p
= &wp_loc_first
;
9916 else if (b
->type
== bp_read_watchpoint
)
9917 loc_first_p
= &rwp_loc_first
;
9918 else if (b
->type
== bp_access_watchpoint
)
9919 loc_first_p
= &awp_loc_first
;
9921 loc_first_p
= &bp_loc_first
;
9923 if (*loc_first_p
== NULL
9924 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9925 || !breakpoint_locations_match (loc
, *loc_first_p
))
9934 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9935 && b
->enable_state
!= bp_permanent
)
9936 internal_error (__FILE__
, __LINE__
,
9937 _("another breakpoint was inserted on top of "
9938 "a permanent breakpoint"));
9941 if (breakpoints_always_inserted_mode () && should_insert
9942 && (have_live_inferiors ()
9943 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9944 insert_breakpoint_locations ();
9946 do_cleanups (cleanups
);
9950 breakpoint_retire_moribund (void)
9952 struct bp_location
*loc
;
9955 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
9956 if (--(loc
->events_till_retirement
) == 0)
9958 decref_bp_location (&loc
);
9959 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
9965 update_global_location_list_nothrow (int inserting
)
9967 struct gdb_exception e
;
9969 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9970 update_global_location_list (inserting
);
9973 /* Clear BKP from a BPS. */
9976 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
9980 for (bs
= bps
; bs
; bs
= bs
->next
)
9981 if (bs
->breakpoint_at
== bpt
)
9983 bs
->breakpoint_at
= NULL
;
9985 /* bs->commands will be freed later. */
9989 /* Callback for iterate_over_threads. */
9991 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9993 struct breakpoint
*bpt
= data
;
9995 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
9999 /* Delete a breakpoint and clean up all traces of it in the data
10003 delete_breakpoint (struct breakpoint
*bpt
)
10005 struct breakpoint
*b
;
10007 gdb_assert (bpt
!= NULL
);
10009 /* Has this bp already been deleted? This can happen because
10010 multiple lists can hold pointers to bp's. bpstat lists are
10013 One example of this happening is a watchpoint's scope bp. When
10014 the scope bp triggers, we notice that the watchpoint is out of
10015 scope, and delete it. We also delete its scope bp. But the
10016 scope bp is marked "auto-deleting", and is already on a bpstat.
10017 That bpstat is then checked for auto-deleting bp's, which are
10020 A real solution to this problem might involve reference counts in
10021 bp's, and/or giving them pointers back to their referencing
10022 bpstat's, and teaching delete_breakpoint to only free a bp's
10023 storage when no more references were extent. A cheaper bandaid
10025 if (bpt
->type
== bp_none
)
10028 /* At least avoid this stale reference until the reference counting
10029 of breakpoints gets resolved. */
10030 if (bpt
->related_breakpoint
!= NULL
)
10032 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
10033 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
10034 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
10035 bpt
->related_breakpoint
= NULL
;
10038 observer_notify_breakpoint_deleted (bpt
->number
);
10040 if (breakpoint_chain
== bpt
)
10041 breakpoint_chain
= bpt
->next
;
10043 ALL_BREAKPOINTS (b
)
10044 if (b
->next
== bpt
)
10046 b
->next
= bpt
->next
;
10050 decref_counted_command_line (&bpt
->commands
);
10051 xfree (bpt
->cond_string
);
10052 xfree (bpt
->cond_exp
);
10053 xfree (bpt
->addr_string
);
10055 xfree (bpt
->exp_string
);
10056 xfree (bpt
->exp_string_reparse
);
10057 value_free (bpt
->val
);
10058 xfree (bpt
->source_file
);
10059 xfree (bpt
->exec_pathname
);
10060 clean_up_filters (&bpt
->syscalls_to_be_caught
);
10063 /* Be sure no bpstat's are pointing at the breakpoint after it's
10065 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10066 in all threeds for now. Note that we cannot just remove bpstats
10067 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10068 commands are associated with the bpstat; if we remove it here,
10069 then the later call to bpstat_do_actions (&stop_bpstat); in
10070 event-top.c won't do anything, and temporary breakpoints with
10071 commands won't work. */
10073 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
10075 /* Now that breakpoint is removed from breakpoint list, update the
10076 global location list. This will remove locations that used to
10077 belong to this breakpoint. Do this before freeing the breakpoint
10078 itself, since remove_breakpoint looks at location's owner. It
10079 might be better design to have location completely
10080 self-contained, but it's not the case now. */
10081 update_global_location_list (0);
10084 /* On the chance that someone will soon try again to delete this
10085 same bp, we mark it as deleted before freeing its storage. */
10086 bpt
->type
= bp_none
;
10092 do_delete_breakpoint_cleanup (void *b
)
10094 delete_breakpoint (b
);
10098 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
10100 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
10103 /* A callback for map_breakpoint_numbers that calls
10104 delete_breakpoint. */
10107 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
10109 delete_breakpoint (b
);
10113 delete_command (char *arg
, int from_tty
)
10115 struct breakpoint
*b
, *b_tmp
;
10121 int breaks_to_delete
= 0;
10123 /* Delete all breakpoints if no argument.
10124 Do not delete internal or call-dummy breakpoints, these have
10125 to be deleted with an explicit breakpoint number argument. */
10126 ALL_BREAKPOINTS (b
)
10128 if (b
->type
!= bp_call_dummy
10129 && b
->type
!= bp_std_terminate
10130 && b
->type
!= bp_shlib_event
10131 && b
->type
!= bp_jit_event
10132 && b
->type
!= bp_thread_event
10133 && b
->type
!= bp_overlay_event
10134 && b
->type
!= bp_longjmp_master
10135 && b
->type
!= bp_std_terminate_master
10136 && b
->type
!= bp_exception_master
10139 breaks_to_delete
= 1;
10144 /* Ask user only if there are some breakpoints to delete. */
10146 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10148 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10150 if (b
->type
!= bp_call_dummy
10151 && b
->type
!= bp_std_terminate
10152 && b
->type
!= bp_shlib_event
10153 && b
->type
!= bp_thread_event
10154 && b
->type
!= bp_jit_event
10155 && b
->type
!= bp_overlay_event
10156 && b
->type
!= bp_longjmp_master
10157 && b
->type
!= bp_std_terminate_master
10158 && b
->type
!= bp_exception_master
10160 delete_breakpoint (b
);
10165 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10169 all_locations_are_pending (struct bp_location
*loc
)
10171 for (; loc
; loc
= loc
->next
)
10172 if (!loc
->shlib_disabled
)
10177 /* Subroutine of update_breakpoint_locations to simplify it.
10178 Return non-zero if multiple fns in list LOC have the same name.
10179 Null names are ignored. */
10182 ambiguous_names_p (struct bp_location
*loc
)
10184 struct bp_location
*l
;
10185 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10186 (int (*) (const void *,
10187 const void *)) streq
,
10188 NULL
, xcalloc
, xfree
);
10190 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10193 const char *name
= l
->function_name
;
10195 /* Allow for some names to be NULL, ignore them. */
10199 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10201 /* NOTE: We can assume slot != NULL here because xcalloc never
10205 htab_delete (htab
);
10211 htab_delete (htab
);
10215 /* When symbols change, it probably means the sources changed as well,
10216 and it might mean the static tracepoint markers are no longer at
10217 the same address or line numbers they used to be at last we
10218 checked. Losing your static tracepoints whenever you rebuild is
10219 undesirable. This function tries to resync/rematch gdb static
10220 tracepoints with the markers on the target, for static tracepoints
10221 that have not been set by marker id. Static tracepoint that have
10222 been set by marker id are reset by marker id in breakpoint_re_set.
10225 1) For a tracepoint set at a specific address, look for a marker at
10226 the old PC. If one is found there, assume to be the same marker.
10227 If the name / string id of the marker found is different from the
10228 previous known name, assume that means the user renamed the marker
10229 in the sources, and output a warning.
10231 2) For a tracepoint set at a given line number, look for a marker
10232 at the new address of the old line number. If one is found there,
10233 assume to be the same marker. If the name / string id of the
10234 marker found is different from the previous known name, assume that
10235 means the user renamed the marker in the sources, and output a
10238 3) If a marker is no longer found at the same address or line, it
10239 may mean the marker no longer exists. But it may also just mean
10240 the code changed a bit. Maybe the user added a few lines of code
10241 that made the marker move up or down (in line number terms). Ask
10242 the target for info about the marker with the string id as we knew
10243 it. If found, update line number and address in the matching
10244 static tracepoint. This will get confused if there's more than one
10245 marker with the same ID (possible in UST, although unadvised
10246 precisely because it confuses tools). */
10248 static struct symtab_and_line
10249 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10251 struct static_tracepoint_marker marker
;
10257 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10259 if (target_static_tracepoint_marker_at (pc
, &marker
))
10261 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10262 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10264 b
->static_trace_marker_id
, marker
.str_id
);
10266 xfree (b
->static_trace_marker_id
);
10267 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10268 release_static_tracepoint_marker (&marker
);
10273 /* Old marker wasn't found on target at lineno. Try looking it up
10275 if (!sal
.explicit_pc
10277 && sal
.symtab
!= NULL
10278 && b
->static_trace_marker_id
!= NULL
)
10280 VEC(static_tracepoint_marker_p
) *markers
;
10283 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10285 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10287 struct symtab_and_line sal
;
10288 struct symbol
*sym
;
10289 struct static_tracepoint_marker
*marker
;
10291 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10293 xfree (b
->static_trace_marker_id
);
10294 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10296 warning (_("marker for static tracepoint %d (%s) not "
10297 "found at previous line number"),
10298 b
->number
, b
->static_trace_marker_id
);
10302 sal
.pc
= marker
->address
;
10304 sal
= find_pc_line (marker
->address
, 0);
10305 sym
= find_pc_sect_function (marker
->address
, NULL
);
10306 ui_out_text (uiout
, "Now in ");
10309 ui_out_field_string (uiout
, "func",
10310 SYMBOL_PRINT_NAME (sym
));
10311 ui_out_text (uiout
, " at ");
10313 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10314 ui_out_text (uiout
, ":");
10316 if (ui_out_is_mi_like_p (uiout
))
10318 char *fullname
= symtab_to_fullname (sal
.symtab
);
10321 ui_out_field_string (uiout
, "fullname", fullname
);
10324 ui_out_field_int (uiout
, "line", sal
.line
);
10325 ui_out_text (uiout
, "\n");
10327 b
->line_number
= sal
.line
;
10329 xfree (b
->source_file
);
10331 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10333 b
->source_file
= NULL
;
10335 xfree (b
->addr_string
);
10336 b
->addr_string
= xstrprintf ("%s:%d",
10337 sal
.symtab
->filename
, b
->line_number
);
10339 /* Might be nice to check if function changed, and warn if
10342 release_static_tracepoint_marker (marker
);
10349 update_breakpoint_locations (struct breakpoint
*b
,
10350 struct symtabs_and_lines sals
)
10354 struct bp_location
*existing_locations
= b
->loc
;
10356 /* If there's no new locations, and all existing locations are
10357 pending, don't do anything. This optimizes the common case where
10358 all locations are in the same shared library, that was unloaded.
10359 We'd like to retain the location, so that when the library is
10360 loaded again, we don't loose the enabled/disabled status of the
10361 individual locations. */
10362 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10367 for (i
= 0; i
< sals
.nelts
; ++i
)
10369 struct bp_location
*new_loc
=
10370 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10372 /* Reparse conditions, they might contain references to the
10374 if (b
->cond_string
!= NULL
)
10376 struct gdb_exception e
;
10378 s
= b
->cond_string
;
10379 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10381 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10386 warning (_("failed to reevaluate condition "
10387 "for breakpoint %d: %s"),
10388 b
->number
, e
.message
);
10389 new_loc
->enabled
= 0;
10393 if (b
->source_file
!= NULL
)
10394 xfree (b
->source_file
);
10395 if (sals
.sals
[i
].symtab
== NULL
)
10396 b
->source_file
= NULL
;
10398 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10400 if (b
->line_number
== 0)
10401 b
->line_number
= sals
.sals
[i
].line
;
10404 /* Update locations of permanent breakpoints. */
10405 if (b
->enable_state
== bp_permanent
)
10406 make_breakpoint_permanent (b
);
10408 /* If possible, carry over 'disable' status from existing
10411 struct bp_location
*e
= existing_locations
;
10412 /* If there are multiple breakpoints with the same function name,
10413 e.g. for inline functions, comparing function names won't work.
10414 Instead compare pc addresses; this is just a heuristic as things
10415 may have moved, but in practice it gives the correct answer
10416 often enough until a better solution is found. */
10417 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10419 for (; e
; e
= e
->next
)
10421 if (!e
->enabled
&& e
->function_name
)
10423 struct bp_location
*l
= b
->loc
;
10424 if (have_ambiguous_names
)
10426 for (; l
; l
= l
->next
)
10427 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10428 l
->pspace
->aspace
, l
->address
))
10436 for (; l
; l
= l
->next
)
10437 if (l
->function_name
10438 && strcmp (e
->function_name
, l
->function_name
) == 0)
10448 update_global_location_list (1);
10451 /* Reset a breakpoint given it's struct breakpoint * BINT.
10452 The value we return ends up being the return value from catch_errors.
10453 Unused in this case. */
10456 breakpoint_re_set_one (void *bint
)
10458 /* Get past catch_errs. */
10459 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10461 int *not_found_ptr
= ¬_found
;
10462 struct symtabs_and_lines sals
= {0};
10463 struct symtabs_and_lines expanded
= {0};
10465 struct gdb_exception e
;
10466 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10467 int marker_spec
= 0;
10472 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10475 case bp_breakpoint
:
10476 case bp_hardware_breakpoint
:
10477 case bp_tracepoint
:
10478 case bp_fast_tracepoint
:
10479 case bp_static_tracepoint
:
10480 /* Do not attempt to re-set breakpoints disabled during startup. */
10481 if (b
->enable_state
== bp_startup_disabled
)
10484 if (b
->addr_string
== NULL
)
10486 /* Anything without a string can't be re-set. */
10487 delete_breakpoint (b
);
10491 input_radix
= b
->input_radix
;
10492 s
= b
->addr_string
;
10494 save_current_space_and_thread ();
10495 switch_to_program_space_and_thread (b
->pspace
);
10497 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10499 set_language (b
->language
);
10500 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10504 sals
= decode_static_tracepoint_spec (&s
);
10505 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10507 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10511 error (_("marker %s not found"), b
->static_trace_marker_id
);
10514 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0,
10515 (char ***) NULL
, not_found_ptr
);
10519 int not_found_and_ok
= 0;
10520 /* For pending breakpoints, it's expected that parsing will
10521 fail until the right shared library is loaded. User has
10522 already told to create pending breakpoints and don't need
10523 extra messages. If breakpoint is in bp_shlib_disabled
10524 state, then user already saw the message about that
10525 breakpoint being disabled, and don't want to see more
10528 && (b
->condition_not_parsed
10529 || (b
->loc
&& b
->loc
->shlib_disabled
)
10530 || b
->enable_state
== bp_disabled
))
10531 not_found_and_ok
= 1;
10533 if (!not_found_and_ok
)
10535 /* We surely don't want to warn about the same breakpoint
10536 10 times. One solution, implemented here, is disable
10537 the breakpoint on error. Another solution would be to
10538 have separate 'warning emitted' flag. Since this
10539 happens only when a binary has changed, I don't know
10540 which approach is better. */
10541 b
->enable_state
= bp_disabled
;
10542 throw_exception (e
);
10548 gdb_assert (sals
.nelts
== 1);
10550 resolve_sal_pc (&sals
.sals
[0]);
10551 if (b
->condition_not_parsed
&& s
&& s
[0])
10553 char *cond_string
= 0;
10557 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10558 &cond_string
, &thread
, &task
);
10560 b
->cond_string
= cond_string
;
10561 b
->thread
= thread
;
10563 b
->condition_not_parsed
= 0;
10566 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10567 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10569 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10572 make_cleanup (xfree
, sals
.sals
);
10573 update_breakpoint_locations (b
, expanded
);
10576 case bp_watchpoint
:
10577 case bp_hardware_watchpoint
:
10578 case bp_read_watchpoint
:
10579 case bp_access_watchpoint
:
10580 /* Watchpoint can be either on expression using entirely global
10581 variables, or it can be on local variables.
10583 Watchpoints of the first kind are never auto-deleted, and
10584 even persist across program restarts. Since they can use
10585 variables from shared libraries, we need to reparse
10586 expression as libraries are loaded and unloaded.
10588 Watchpoints on local variables can also change meaning as
10589 result of solib event. For example, if a watchpoint uses
10590 both a local and a global variables in expression, it's a
10591 local watchpoint, but unloading of a shared library will make
10592 the expression invalid. This is not a very common use case,
10593 but we still re-evaluate expression, to avoid surprises to
10596 Note that for local watchpoints, we re-evaluate it only if
10597 watchpoints frame id is still valid. If it's not, it means
10598 the watchpoint is out of scope and will be deleted soon. In
10599 fact, I'm not sure we'll ever be called in this case.
10601 If a local watchpoint's frame id is still valid, then
10602 b->exp_valid_block is likewise valid, and we can safely use it.
10604 Don't do anything about disabled watchpoints, since they will
10605 be reevaluated again when enabled. */
10606 update_watchpoint (b
, 1 /* reparse */);
10608 /* We needn't really do anything to reset these, since the mask
10609 that requests them is unaffected by e.g., new libraries being
10611 case bp_catchpoint
:
10615 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10617 /* Delete overlay event and longjmp master breakpoints; they will be
10618 reset later by breakpoint_re_set. */
10619 case bp_overlay_event
:
10620 case bp_longjmp_master
:
10621 case bp_std_terminate_master
:
10622 case bp_exception_master
:
10623 delete_breakpoint (b
);
10626 /* This breakpoint is special, it's set up when the inferior
10627 starts and we really don't want to touch it. */
10628 case bp_shlib_event
:
10630 /* Like bp_shlib_event, this breakpoint type is special.
10631 Once it is set up, we do not want to touch it. */
10632 case bp_thread_event
:
10634 /* Keep temporary breakpoints, which can be encountered when we
10635 step over a dlopen call and SOLIB_ADD is resetting the
10636 breakpoints. Otherwise these should have been blown away via
10637 the cleanup chain or by breakpoint_init_inferior when we
10638 rerun the executable. */
10641 case bp_watchpoint_scope
:
10642 case bp_call_dummy
:
10643 case bp_std_terminate
:
10644 case bp_step_resume
:
10646 case bp_longjmp_resume
:
10648 case bp_exception_resume
:
10653 do_cleanups (cleanups
);
10657 /* Re-set all breakpoints after symbols have been re-loaded. */
10659 breakpoint_re_set (void)
10661 struct breakpoint
*b
, *b_tmp
;
10662 enum language save_language
;
10663 int save_input_radix
;
10664 struct cleanup
*old_chain
;
10666 save_language
= current_language
->la_language
;
10667 save_input_radix
= input_radix
;
10668 old_chain
= save_current_program_space ();
10670 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10672 /* Format possible error msg. */
10673 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10675 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10676 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10677 do_cleanups (cleanups
);
10679 set_language (save_language
);
10680 input_radix
= save_input_radix
;
10682 jit_breakpoint_re_set ();
10684 do_cleanups (old_chain
);
10686 create_overlay_event_breakpoint ();
10687 create_longjmp_master_breakpoint ();
10688 create_std_terminate_master_breakpoint ();
10689 create_exception_master_breakpoint ();
10692 /* Reset the thread number of this breakpoint:
10694 - If the breakpoint is for all threads, leave it as-is.
10695 - Else, reset it to the current thread for inferior_ptid. */
10697 breakpoint_re_set_thread (struct breakpoint
*b
)
10699 if (b
->thread
!= -1)
10701 if (in_thread_list (inferior_ptid
))
10702 b
->thread
= pid_to_thread_id (inferior_ptid
);
10704 /* We're being called after following a fork. The new fork is
10705 selected as current, and unless this was a vfork will have a
10706 different program space from the original thread. Reset that
10708 b
->loc
->pspace
= current_program_space
;
10712 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10713 If from_tty is nonzero, it prints a message to that effect,
10714 which ends with a period (no newline). */
10717 set_ignore_count (int bptnum
, int count
, int from_tty
)
10719 struct breakpoint
*b
;
10724 ALL_BREAKPOINTS (b
)
10725 if (b
->number
== bptnum
)
10727 if (is_tracepoint (b
))
10729 if (from_tty
&& count
!= 0)
10730 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10735 b
->ignore_count
= count
;
10739 printf_filtered (_("Will stop next time "
10740 "breakpoint %d is reached."),
10742 else if (count
== 1)
10743 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10746 printf_filtered (_("Will ignore next %d "
10747 "crossings of breakpoint %d."),
10750 breakpoints_changed ();
10751 observer_notify_breakpoint_modified (b
->number
);
10755 error (_("No breakpoint number %d."), bptnum
);
10758 /* Command to set ignore-count of breakpoint N to COUNT. */
10761 ignore_command (char *args
, int from_tty
)
10767 error_no_arg (_("a breakpoint number"));
10769 num
= get_number (&p
);
10771 error (_("bad breakpoint number: '%s'"), args
);
10773 error (_("Second argument (specified ignore-count) is missing."));
10775 set_ignore_count (num
,
10776 longest_to_int (value_as_long (parse_and_eval (p
))),
10779 printf_filtered ("\n");
10782 /* Call FUNCTION on each of the breakpoints
10783 whose numbers are given in ARGS. */
10786 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10793 struct breakpoint
*b
, *tmp
;
10797 error_no_arg (_("one or more breakpoint numbers"));
10804 num
= get_number_or_range (&p1
);
10807 warning (_("bad breakpoint number at or near '%s'"), p
);
10811 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10812 if (b
->number
== num
)
10814 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10816 function (b
, data
);
10817 if (related_breakpoint
)
10818 function (related_breakpoint
, data
);
10822 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10828 static struct bp_location
*
10829 find_location_by_number (char *number
)
10831 char *dot
= strchr (number
, '.');
10835 struct breakpoint
*b
;
10836 struct bp_location
*loc
;
10841 bp_num
= get_number_or_range (&p1
);
10843 error (_("Bad breakpoint number '%s'"), number
);
10845 ALL_BREAKPOINTS (b
)
10846 if (b
->number
== bp_num
)
10851 if (!b
|| b
->number
!= bp_num
)
10852 error (_("Bad breakpoint number '%s'"), number
);
10855 loc_num
= get_number_or_range (&p1
);
10857 error (_("Bad breakpoint location number '%s'"), number
);
10861 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10864 error (_("Bad breakpoint location number '%s'"), dot
+1);
10870 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10871 If from_tty is nonzero, it prints a message to that effect,
10872 which ends with a period (no newline). */
10875 disable_breakpoint (struct breakpoint
*bpt
)
10877 /* Never disable a watchpoint scope breakpoint; we want to
10878 hit them when we leave scope so we can delete both the
10879 watchpoint and its scope breakpoint at that time. */
10880 if (bpt
->type
== bp_watchpoint_scope
)
10883 /* You can't disable permanent breakpoints. */
10884 if (bpt
->enable_state
== bp_permanent
)
10887 bpt
->enable_state
= bp_disabled
;
10889 update_global_location_list (0);
10891 observer_notify_breakpoint_modified (bpt
->number
);
10894 /* A callback for map_breakpoint_numbers that calls
10895 disable_breakpoint. */
10898 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10900 disable_breakpoint (b
);
10904 disable_command (char *args
, int from_tty
)
10906 struct breakpoint
*bpt
;
10909 ALL_BREAKPOINTS (bpt
)
10913 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10916 case bp_breakpoint
:
10917 case bp_tracepoint
:
10918 case bp_fast_tracepoint
:
10919 case bp_static_tracepoint
:
10920 case bp_catchpoint
:
10921 case bp_hardware_breakpoint
:
10922 case bp_watchpoint
:
10923 case bp_hardware_watchpoint
:
10924 case bp_read_watchpoint
:
10925 case bp_access_watchpoint
:
10926 disable_breakpoint (bpt
);
10930 else if (strchr (args
, '.'))
10932 struct bp_location
*loc
= find_location_by_number (args
);
10935 update_global_location_list (0);
10938 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10942 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10944 int target_resources_ok
;
10946 if (bpt
->type
== bp_hardware_breakpoint
)
10949 i
= hw_breakpoint_used_count ();
10950 target_resources_ok
=
10951 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10953 if (target_resources_ok
== 0)
10954 error (_("No hardware breakpoint support in the target."));
10955 else if (target_resources_ok
< 0)
10956 error (_("Hardware breakpoints used exceeds limit."));
10959 if (is_watchpoint (bpt
))
10961 struct gdb_exception e
;
10963 TRY_CATCH (e
, RETURN_MASK_ALL
)
10965 update_watchpoint (bpt
, 1 /* reparse */);
10969 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
10975 if (bpt
->enable_state
!= bp_permanent
)
10976 bpt
->enable_state
= bp_enabled
;
10977 bpt
->disposition
= disposition
;
10978 update_global_location_list (1);
10979 breakpoints_changed ();
10981 observer_notify_breakpoint_modified (bpt
->number
);
10986 enable_breakpoint (struct breakpoint
*bpt
)
10988 do_enable_breakpoint (bpt
, bpt
->disposition
);
10991 /* A callback for map_breakpoint_numbers that calls
10992 enable_breakpoint. */
10995 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
10997 enable_breakpoint (b
);
11000 /* The enable command enables the specified breakpoints (or all defined
11001 breakpoints) so they once again become (or continue to be) effective
11002 in stopping the inferior. */
11005 enable_command (char *args
, int from_tty
)
11007 struct breakpoint
*bpt
;
11010 ALL_BREAKPOINTS (bpt
)
11014 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
11017 case bp_breakpoint
:
11018 case bp_tracepoint
:
11019 case bp_fast_tracepoint
:
11020 case bp_static_tracepoint
:
11021 case bp_catchpoint
:
11022 case bp_hardware_breakpoint
:
11023 case bp_watchpoint
:
11024 case bp_hardware_watchpoint
:
11025 case bp_read_watchpoint
:
11026 case bp_access_watchpoint
:
11027 enable_breakpoint (bpt
);
11031 else if (strchr (args
, '.'))
11033 struct bp_location
*loc
= find_location_by_number (args
);
11036 update_global_location_list (1);
11039 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
11043 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11045 do_enable_breakpoint (bpt
, disp_disable
);
11049 enable_once_command (char *args
, int from_tty
)
11051 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
11055 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11057 do_enable_breakpoint (bpt
, disp_del
);
11061 enable_delete_command (char *args
, int from_tty
)
11063 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
11067 set_breakpoint_cmd (char *args
, int from_tty
)
11072 show_breakpoint_cmd (char *args
, int from_tty
)
11076 /* Invalidate last known value of any hardware watchpoint if
11077 the memory which that value represents has been written to by
11081 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
11082 const bfd_byte
*data
)
11084 struct breakpoint
*bp
;
11086 ALL_BREAKPOINTS (bp
)
11087 if (bp
->enable_state
== bp_enabled
11088 && bp
->type
== bp_hardware_watchpoint
11089 && bp
->val_valid
&& bp
->val
)
11091 struct bp_location
*loc
;
11093 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
11094 if (loc
->loc_type
== bp_loc_hardware_watchpoint
11095 && loc
->address
+ loc
->length
> addr
11096 && addr
+ len
> loc
->address
)
11098 value_free (bp
->val
);
11105 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11107 struct symtabs_and_lines
11108 decode_line_spec_1 (char *string
, int funfirstline
)
11110 struct symtabs_and_lines sals
;
11113 error (_("Empty line specification."));
11114 if (default_breakpoint_valid
)
11115 sals
= decode_line_1 (&string
, funfirstline
,
11116 default_breakpoint_symtab
,
11117 default_breakpoint_line
,
11118 (char ***) NULL
, NULL
);
11120 sals
= decode_line_1 (&string
, funfirstline
,
11121 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
11123 error (_("Junk at end of line specification: %s"), string
);
11127 /* Create and insert a raw software breakpoint at PC. Return an
11128 identifier, which should be used to remove the breakpoint later.
11129 In general, places which call this should be using something on the
11130 breakpoint chain instead; this function should be eliminated
11134 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11135 struct address_space
*aspace
, CORE_ADDR pc
)
11137 struct bp_target_info
*bp_tgt
;
11139 bp_tgt
= XZALLOC (struct bp_target_info
);
11141 bp_tgt
->placed_address_space
= aspace
;
11142 bp_tgt
->placed_address
= pc
;
11144 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11146 /* Could not insert the breakpoint. */
11154 /* Remove a breakpoint BP inserted by
11155 deprecated_insert_raw_breakpoint. */
11158 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11160 struct bp_target_info
*bp_tgt
= bp
;
11163 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11169 /* One (or perhaps two) breakpoints used for software single
11172 static void *single_step_breakpoints
[2];
11173 static struct gdbarch
*single_step_gdbarch
[2];
11175 /* Create and insert a breakpoint for software single step. */
11178 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11179 struct address_space
*aspace
,
11184 if (single_step_breakpoints
[0] == NULL
)
11186 bpt_p
= &single_step_breakpoints
[0];
11187 single_step_gdbarch
[0] = gdbarch
;
11191 gdb_assert (single_step_breakpoints
[1] == NULL
);
11192 bpt_p
= &single_step_breakpoints
[1];
11193 single_step_gdbarch
[1] = gdbarch
;
11196 /* NOTE drow/2006-04-11: A future improvement to this function would
11197 be to only create the breakpoints once, and actually put them on
11198 the breakpoint chain. That would let us use set_raw_breakpoint.
11199 We could adjust the addresses each time they were needed. Doing
11200 this requires corresponding changes elsewhere where single step
11201 breakpoints are handled, however. So, for now, we use this. */
11203 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11204 if (*bpt_p
== NULL
)
11205 error (_("Could not insert single-step breakpoint at %s"),
11206 paddress (gdbarch
, next_pc
));
11209 /* Check if the breakpoints used for software single stepping
11210 were inserted or not. */
11213 single_step_breakpoints_inserted (void)
11215 return (single_step_breakpoints
[0] != NULL
11216 || single_step_breakpoints
[1] != NULL
);
11219 /* Remove and delete any breakpoints used for software single step. */
11222 remove_single_step_breakpoints (void)
11224 gdb_assert (single_step_breakpoints
[0] != NULL
);
11226 /* See insert_single_step_breakpoint for more about this deprecated
11228 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11229 single_step_breakpoints
[0]);
11230 single_step_gdbarch
[0] = NULL
;
11231 single_step_breakpoints
[0] = NULL
;
11233 if (single_step_breakpoints
[1] != NULL
)
11235 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11236 single_step_breakpoints
[1]);
11237 single_step_gdbarch
[1] = NULL
;
11238 single_step_breakpoints
[1] = NULL
;
11242 /* Delete software single step breakpoints without removing them from
11243 the inferior. This is intended to be used if the inferior's address
11244 space where they were inserted is already gone, e.g. after exit or
11248 cancel_single_step_breakpoints (void)
11252 for (i
= 0; i
< 2; i
++)
11253 if (single_step_breakpoints
[i
])
11255 xfree (single_step_breakpoints
[i
]);
11256 single_step_breakpoints
[i
] = NULL
;
11257 single_step_gdbarch
[i
] = NULL
;
11261 /* Detach software single-step breakpoints from INFERIOR_PTID without
11265 detach_single_step_breakpoints (void)
11269 for (i
= 0; i
< 2; i
++)
11270 if (single_step_breakpoints
[i
])
11271 target_remove_breakpoint (single_step_gdbarch
[i
],
11272 single_step_breakpoints
[i
]);
11275 /* Check whether a software single-step breakpoint is inserted at
11279 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11284 for (i
= 0; i
< 2; i
++)
11286 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11288 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11289 bp_tgt
->placed_address
,
11297 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11298 non-zero otherwise. */
11300 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11302 if (syscall_catchpoint_p (bp
)
11303 && bp
->enable_state
!= bp_disabled
11304 && bp
->enable_state
!= bp_call_disabled
)
11311 catch_syscall_enabled (void)
11313 struct inferior
*inf
= current_inferior ();
11315 return inf
->total_syscalls_count
!= 0;
11319 catching_syscall_number (int syscall_number
)
11321 struct breakpoint
*bp
;
11323 ALL_BREAKPOINTS (bp
)
11324 if (is_syscall_catchpoint_enabled (bp
))
11326 if (bp
->syscalls_to_be_caught
)
11330 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11332 if (syscall_number
== iter
)
11342 /* Complete syscall names. Used by "catch syscall". */
11344 catch_syscall_completer (struct cmd_list_element
*cmd
,
11345 char *text
, char *word
)
11347 const char **list
= get_syscall_names ();
11349 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11352 /* Tracepoint-specific operations. */
11354 /* Set tracepoint count to NUM. */
11356 set_tracepoint_count (int num
)
11358 tracepoint_count
= num
;
11359 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11363 trace_command (char *arg
, int from_tty
)
11365 if (create_breakpoint (get_current_arch (),
11367 NULL
, 0, 1 /* parse arg */,
11369 bp_tracepoint
/* type_wanted */,
11370 0 /* Ignore count */,
11371 pending_break_support
,
11376 set_tracepoint_count (breakpoint_count
);
11380 ftrace_command (char *arg
, int from_tty
)
11382 if (create_breakpoint (get_current_arch (),
11384 NULL
, 0, 1 /* parse arg */,
11386 bp_fast_tracepoint
/* type_wanted */,
11387 0 /* Ignore count */,
11388 pending_break_support
,
11393 set_tracepoint_count (breakpoint_count
);
11396 /* strace command implementation. Creates a static tracepoint. */
11399 strace_command (char *arg
, int from_tty
)
11401 if (create_breakpoint (get_current_arch (),
11403 NULL
, 0, 1 /* parse arg */,
11405 bp_static_tracepoint
/* type_wanted */,
11406 0 /* Ignore count */,
11407 pending_break_support
,
11412 set_tracepoint_count (breakpoint_count
);
11415 /* Set up a fake reader function that gets command lines from a linked
11416 list that was acquired during tracepoint uploading. */
11418 static struct uploaded_tp
*this_utp
;
11419 static int next_cmd
;
11422 read_uploaded_action (void)
11426 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11433 /* Given information about a tracepoint as recorded on a target (which
11434 can be either a live system or a trace file), attempt to create an
11435 equivalent GDB tracepoint. This is not a reliable process, since
11436 the target does not necessarily have all the information used when
11437 the tracepoint was originally defined. */
11439 struct breakpoint
*
11440 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11442 char *addr_str
, small_buf
[100];
11443 struct breakpoint
*tp
;
11445 if (utp
->at_string
)
11446 addr_str
= utp
->at_string
;
11449 /* In the absence of a source location, fall back to raw
11450 address. Since there is no way to confirm that the address
11451 means the same thing as when the trace was started, warn the
11453 warning (_("Uploaded tracepoint %d has no "
11454 "source location, using raw address"),
11456 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11457 addr_str
= small_buf
;
11460 /* There's not much we can do with a sequence of bytecodes. */
11461 if (utp
->cond
&& !utp
->cond_string
)
11462 warning (_("Uploaded tracepoint %d condition "
11463 "has no source form, ignoring it"),
11466 if (!create_breakpoint (get_current_arch (),
11468 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11470 utp
->type
/* type_wanted */,
11471 0 /* Ignore count */,
11472 pending_break_support
,
11475 utp
->enabled
/* enabled */,
11479 set_tracepoint_count (breakpoint_count
);
11481 /* Get the tracepoint we just created. */
11482 tp
= get_tracepoint (tracepoint_count
);
11483 gdb_assert (tp
!= NULL
);
11487 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11489 trace_pass_command (small_buf
, 0);
11492 /* If we have uploaded versions of the original commands, set up a
11493 special-purpose "reader" function and call the usual command line
11494 reader, then pass the result to the breakpoint command-setting
11496 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11498 struct command_line
*cmd_list
;
11503 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11505 breakpoint_set_commands (tp
, cmd_list
);
11507 else if (!VEC_empty (char_ptr
, utp
->actions
)
11508 || !VEC_empty (char_ptr
, utp
->step_actions
))
11509 warning (_("Uploaded tracepoint %d actions "
11510 "have no source form, ignoring them"),
11516 /* Print information on tracepoint number TPNUM_EXP, or all if
11520 tracepoints_info (char *args
, int from_tty
)
11524 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
11526 if (num_printed
== 0)
11528 if (args
== NULL
|| *args
== '\0')
11529 ui_out_message (uiout
, 0, "No tracepoints.\n");
11531 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
11534 default_collect_info ();
11537 /* The 'enable trace' command enables tracepoints.
11538 Not supported by all targets. */
11540 enable_trace_command (char *args
, int from_tty
)
11542 enable_command (args
, from_tty
);
11545 /* The 'disable trace' command disables tracepoints.
11546 Not supported by all targets. */
11548 disable_trace_command (char *args
, int from_tty
)
11550 disable_command (args
, from_tty
);
11553 /* Remove a tracepoint (or all if no argument). */
11555 delete_trace_command (char *arg
, int from_tty
)
11557 struct breakpoint
*b
, *b_tmp
;
11563 int breaks_to_delete
= 0;
11565 /* Delete all breakpoints if no argument.
11566 Do not delete internal or call-dummy breakpoints, these
11567 have to be deleted with an explicit breakpoint number
11569 ALL_TRACEPOINTS (b
)
11571 if (b
->number
>= 0)
11573 breaks_to_delete
= 1;
11578 /* Ask user only if there are some breakpoints to delete. */
11580 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11582 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11584 if (is_tracepoint (b
)
11586 delete_breakpoint (b
);
11591 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11594 /* Set passcount for tracepoint.
11596 First command argument is passcount, second is tracepoint number.
11597 If tracepoint number omitted, apply to most recently defined.
11598 Also accepts special argument "all". */
11601 trace_pass_command (char *args
, int from_tty
)
11603 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11604 unsigned int count
;
11607 if (args
== 0 || *args
== 0)
11608 error (_("passcount command requires an "
11609 "argument (count + optional TP num)"));
11611 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11613 while (*args
&& isspace ((int) *args
))
11616 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11618 args
+= 3; /* Skip special argument "all". */
11621 error (_("Junk at end of arguments."));
11624 t1
= get_tracepoint_by_number (&args
, 1, 1);
11630 ALL_TRACEPOINTS (t2
)
11631 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11633 t2
->pass_count
= count
;
11634 observer_notify_tracepoint_modified (t2
->number
);
11636 printf_filtered (_("Setting tracepoint %d's "
11637 "passcount to %d\n"),
11638 t2
->number
, count
);
11640 if (! all
&& *args
)
11641 t1
= get_tracepoint_by_number (&args
, 1, 0);
11647 struct breakpoint
*
11648 get_tracepoint (int num
)
11650 struct breakpoint
*t
;
11652 ALL_TRACEPOINTS (t
)
11653 if (t
->number
== num
)
11659 /* Find the tracepoint with the given target-side number (which may be
11660 different from the tracepoint number after disconnecting and
11663 struct breakpoint
*
11664 get_tracepoint_by_number_on_target (int num
)
11666 struct breakpoint
*t
;
11668 ALL_TRACEPOINTS (t
)
11669 if (t
->number_on_target
== num
)
11675 /* Utility: parse a tracepoint number and look it up in the list.
11676 If MULTI_P is true, there might be a range of tracepoints in ARG.
11677 if OPTIONAL_P is true, then if the argument is missing, the most
11678 recent tracepoint (tracepoint_count) is returned. */
11679 struct breakpoint
*
11680 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11682 extern int tracepoint_count
;
11683 struct breakpoint
*t
;
11685 char *instring
= arg
== NULL
? NULL
: *arg
;
11687 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11690 tpnum
= tracepoint_count
;
11692 error_no_arg (_("tracepoint number"));
11695 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11699 if (instring
&& *instring
)
11700 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11703 printf_filtered (_("Tracepoint argument missing "
11704 "and no previous tracepoint\n"));
11708 ALL_TRACEPOINTS (t
)
11709 if (t
->number
== tpnum
)
11714 /* FIXME: if we are in the middle of a range we don't want to give
11715 a message. The current interface to get_number_or_range doesn't
11716 allow us to discover this. */
11717 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11721 /* Save information on user settable breakpoints (watchpoints, etc) to
11722 a new script file named FILENAME. If FILTER is non-NULL, call it
11723 on each breakpoint and only include the ones for which it returns
11727 save_breakpoints (char *filename
, int from_tty
,
11728 int (*filter
) (const struct breakpoint
*))
11730 struct breakpoint
*tp
;
11733 struct cleanup
*cleanup
;
11734 struct ui_file
*fp
;
11735 int extra_trace_bits
= 0;
11737 if (filename
== 0 || *filename
== 0)
11738 error (_("Argument required (file name in which to save)"));
11740 /* See if we have anything to save. */
11741 ALL_BREAKPOINTS (tp
)
11743 /* Skip internal and momentary breakpoints. */
11744 if (!user_breakpoint_p (tp
))
11747 /* If we have a filter, only save the breakpoints it accepts. */
11748 if (filter
&& !filter (tp
))
11753 if (is_tracepoint (tp
))
11755 extra_trace_bits
= 1;
11757 /* We can stop searching. */
11764 warning (_("Nothing to save."));
11768 pathname
= tilde_expand (filename
);
11769 cleanup
= make_cleanup (xfree
, pathname
);
11770 fp
= gdb_fopen (pathname
, "w");
11772 error (_("Unable to open file '%s' for saving (%s)"),
11773 filename
, safe_strerror (errno
));
11774 make_cleanup_ui_file_delete (fp
);
11776 if (extra_trace_bits
)
11777 save_trace_state_variables (fp
);
11779 ALL_BREAKPOINTS (tp
)
11781 /* Skip internal and momentary breakpoints. */
11782 if (!user_breakpoint_p (tp
))
11785 /* If we have a filter, only save the breakpoints it accepts. */
11786 if (filter
&& !filter (tp
))
11789 if (tp
->ops
!= NULL
)
11790 (tp
->ops
->print_recreate
) (tp
, fp
);
11793 if (tp
->type
== bp_fast_tracepoint
)
11794 fprintf_unfiltered (fp
, "ftrace");
11795 if (tp
->type
== bp_static_tracepoint
)
11796 fprintf_unfiltered (fp
, "strace");
11797 else if (tp
->type
== bp_tracepoint
)
11798 fprintf_unfiltered (fp
, "trace");
11799 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11800 fprintf_unfiltered (fp
, "tbreak");
11801 else if (tp
->type
== bp_breakpoint
)
11802 fprintf_unfiltered (fp
, "break");
11803 else if (tp
->type
== bp_hardware_breakpoint
11804 && tp
->disposition
== disp_del
)
11805 fprintf_unfiltered (fp
, "thbreak");
11806 else if (tp
->type
== bp_hardware_breakpoint
)
11807 fprintf_unfiltered (fp
, "hbreak");
11808 else if (tp
->type
== bp_watchpoint
)
11809 fprintf_unfiltered (fp
, "watch");
11810 else if (tp
->type
== bp_hardware_watchpoint
)
11811 fprintf_unfiltered (fp
, "watch");
11812 else if (tp
->type
== bp_read_watchpoint
)
11813 fprintf_unfiltered (fp
, "rwatch");
11814 else if (tp
->type
== bp_access_watchpoint
)
11815 fprintf_unfiltered (fp
, "awatch");
11817 internal_error (__FILE__
, __LINE__
,
11818 _("unhandled breakpoint type %d"), (int) tp
->type
);
11820 if (tp
->exp_string
)
11821 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11822 else if (tp
->addr_string
)
11823 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11828 sprintf_vma (tmp
, tp
->loc
->address
);
11829 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11833 if (tp
->thread
!= -1)
11834 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
11837 fprintf_unfiltered (fp
, " task %d", tp
->task
);
11839 fprintf_unfiltered (fp
, "\n");
11841 /* Note, we can't rely on tp->number for anything, as we can't
11842 assume the recreated breakpoint numbers will match. Use $bpnum
11845 if (tp
->cond_string
)
11846 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
11848 if (tp
->ignore_count
)
11849 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
11851 if (tp
->pass_count
)
11852 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11856 volatile struct gdb_exception ex
;
11858 fprintf_unfiltered (fp
, " commands\n");
11860 ui_out_redirect (uiout
, fp
);
11861 TRY_CATCH (ex
, RETURN_MASK_ALL
)
11863 print_command_lines (uiout
, tp
->commands
->commands
, 2);
11865 ui_out_redirect (uiout
, NULL
);
11868 throw_exception (ex
);
11870 fprintf_unfiltered (fp
, " end\n");
11873 if (tp
->enable_state
== bp_disabled
)
11874 fprintf_unfiltered (fp
, "disable\n");
11876 /* If this is a multi-location breakpoint, check if the locations
11877 should be individually disabled. Watchpoint locations are
11878 special, and not user visible. */
11879 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
11881 struct bp_location
*loc
;
11884 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
11886 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
11890 if (extra_trace_bits
&& *default_collect
)
11891 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
11893 do_cleanups (cleanup
);
11895 printf_filtered (_("Saved to file '%s'.\n"), filename
);
11898 /* The `save breakpoints' command. */
11901 save_breakpoints_command (char *args
, int from_tty
)
11903 save_breakpoints (args
, from_tty
, NULL
);
11906 /* The `save tracepoints' command. */
11909 save_tracepoints_command (char *args
, int from_tty
)
11911 save_breakpoints (args
, from_tty
, is_tracepoint
);
11914 /* Create a vector of all tracepoints. */
11916 VEC(breakpoint_p
) *
11919 VEC(breakpoint_p
) *tp_vec
= 0;
11920 struct breakpoint
*tp
;
11922 ALL_TRACEPOINTS (tp
)
11924 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11931 /* This help string is used for the break, hbreak, tbreak and thbreak
11932 commands. It is defined as a macro to prevent duplication.
11933 COMMAND should be a string constant containing the name of the
11935 #define BREAK_ARGS_HELP(command) \
11936 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11937 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11938 If a line number is specified, break at start of code for that line.\n\
11939 If a function is specified, break at start of code for that function.\n\
11940 If an address is specified, break at that exact address.\n\
11941 With no LOCATION, uses current execution address of the selected\n\
11942 stack frame. This is useful for breaking on return to a stack frame.\n\
11944 THREADNUM is the number from \"info threads\".\n\
11945 CONDITION is a boolean expression.\n\
11947 Multiple breakpoints at one place are permitted, and useful if their\n\
11948 conditions are different.\n\
11950 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
11952 /* List of subcommands for "catch". */
11953 static struct cmd_list_element
*catch_cmdlist
;
11955 /* List of subcommands for "tcatch". */
11956 static struct cmd_list_element
*tcatch_cmdlist
;
11958 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
11959 lists, and pass some additional user data to the command function. */
11961 add_catch_command (char *name
, char *docstring
,
11962 void (*sfunc
) (char *args
, int from_tty
,
11963 struct cmd_list_element
*command
),
11964 char **(*completer
) (struct cmd_list_element
*cmd
,
11965 char *text
, char *word
),
11966 void *user_data_catch
,
11967 void *user_data_tcatch
)
11969 struct cmd_list_element
*command
;
11971 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11973 set_cmd_sfunc (command
, sfunc
);
11974 set_cmd_context (command
, user_data_catch
);
11975 set_cmd_completer (command
, completer
);
11977 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
11979 set_cmd_sfunc (command
, sfunc
);
11980 set_cmd_context (command
, user_data_tcatch
);
11981 set_cmd_completer (command
, completer
);
11985 clear_syscall_counts (struct inferior
*inf
)
11987 inf
->total_syscalls_count
= 0;
11988 inf
->any_syscall_count
= 0;
11989 VEC_free (int, inf
->syscalls_counts
);
11993 save_command (char *arg
, int from_tty
)
11995 printf_unfiltered (_("\"save\" must be followed by "
11996 "the name of a save subcommand.\n"));
11997 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
12000 struct breakpoint
*
12001 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
12004 struct breakpoint
*b
, *b_tmp
;
12006 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12008 if ((*callback
) (b
, data
))
12016 _initialize_breakpoint (void)
12018 struct cmd_list_element
*c
;
12020 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
12021 observer_attach_inferior_exit (clear_syscall_counts
);
12022 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
12024 breakpoint_objfile_key
= register_objfile_data ();
12026 breakpoint_chain
= 0;
12027 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12028 before a breakpoint is set. */
12029 breakpoint_count
= 0;
12031 tracepoint_count
= 0;
12033 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
12034 Set ignore-count of breakpoint number N to COUNT.\n\
12035 Usage is `ignore N COUNT'."));
12037 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
12039 add_com ("commands", class_breakpoint
, commands_command
, _("\
12040 Set commands to be executed when a breakpoint is hit.\n\
12041 Give breakpoint number as argument after \"commands\".\n\
12042 With no argument, the targeted breakpoint is the last one set.\n\
12043 The commands themselves follow starting on the next line.\n\
12044 Type a line containing \"end\" to indicate the end of them.\n\
12045 Give \"silent\" as the first line to make the breakpoint silent;\n\
12046 then no output is printed when it is hit, except what the commands print."));
12048 add_com ("condition", class_breakpoint
, condition_command
, _("\
12049 Specify breakpoint number N to break only if COND is true.\n\
12050 Usage is `condition N COND', where N is an integer and COND is an\n\
12051 expression to be evaluated whenever breakpoint N is reached."));
12053 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
12054 Set a temporary breakpoint.\n\
12055 Like \"break\" except the breakpoint is only temporary,\n\
12056 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12057 by using \"enable delete\" on the breakpoint number.\n\
12059 BREAK_ARGS_HELP ("tbreak")));
12060 set_cmd_completer (c
, location_completer
);
12062 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
12063 Set a hardware assisted breakpoint.\n\
12064 Like \"break\" except the breakpoint requires hardware support,\n\
12065 some target hardware may not have this support.\n\
12067 BREAK_ARGS_HELP ("hbreak")));
12068 set_cmd_completer (c
, location_completer
);
12070 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
12071 Set a temporary hardware assisted breakpoint.\n\
12072 Like \"hbreak\" except the breakpoint is only temporary,\n\
12073 so it will be deleted when hit.\n\
12075 BREAK_ARGS_HELP ("thbreak")));
12076 set_cmd_completer (c
, location_completer
);
12078 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
12079 Enable some breakpoints.\n\
12080 Give breakpoint numbers (separated by spaces) as arguments.\n\
12081 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12082 This is used to cancel the effect of the \"disable\" command.\n\
12083 With a subcommand you can enable temporarily."),
12084 &enablelist
, "enable ", 1, &cmdlist
);
12086 add_com ("ab", class_breakpoint
, enable_command
, _("\
12087 Enable some breakpoints.\n\
12088 Give breakpoint numbers (separated by spaces) as arguments.\n\
12089 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12090 This is used to cancel the effect of the \"disable\" command.\n\
12091 With a subcommand you can enable temporarily."));
12093 add_com_alias ("en", "enable", class_breakpoint
, 1);
12095 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
12096 Enable some breakpoints.\n\
12097 Give breakpoint numbers (separated by spaces) as arguments.\n\
12098 This is used to cancel the effect of the \"disable\" command.\n\
12099 May be abbreviated to simply \"enable\".\n"),
12100 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
12102 add_cmd ("once", no_class
, enable_once_command
, _("\
12103 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12104 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12107 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12108 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12109 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12112 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12113 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12114 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12117 add_cmd ("once", no_class
, enable_once_command
, _("\
12118 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12119 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12122 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12123 Disable some breakpoints.\n\
12124 Arguments are breakpoint numbers with spaces in between.\n\
12125 To disable all breakpoints, give no argument.\n\
12126 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12127 &disablelist
, "disable ", 1, &cmdlist
);
12128 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12129 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12131 add_com ("sb", class_breakpoint
, disable_command
, _("\
12132 Disable some breakpoints.\n\
12133 Arguments are breakpoint numbers with spaces in between.\n\
12134 To disable all breakpoints, give no argument.\n\
12135 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12137 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12138 Disable some breakpoints.\n\
12139 Arguments are breakpoint numbers with spaces in between.\n\
12140 To disable all breakpoints, give no argument.\n\
12141 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12142 This command may be abbreviated \"disable\"."),
12145 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12146 Delete some breakpoints or auto-display expressions.\n\
12147 Arguments are breakpoint numbers with spaces in between.\n\
12148 To delete all breakpoints, give no argument.\n\
12150 Also a prefix command for deletion of other GDB objects.\n\
12151 The \"unset\" command is also an alias for \"delete\"."),
12152 &deletelist
, "delete ", 1, &cmdlist
);
12153 add_com_alias ("d", "delete", class_breakpoint
, 1);
12154 add_com_alias ("del", "delete", class_breakpoint
, 1);
12156 add_com ("db", class_breakpoint
, delete_command
, _("\
12157 Delete some breakpoints.\n\
12158 Arguments are breakpoint numbers with spaces in between.\n\
12159 To delete all breakpoints, give no argument.\n"));
12161 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12162 Delete some breakpoints or auto-display expressions.\n\
12163 Arguments are breakpoint numbers with spaces in between.\n\
12164 To delete all breakpoints, give no argument.\n\
12165 This command may be abbreviated \"delete\"."),
12168 add_com ("clear", class_breakpoint
, clear_command
, _("\
12169 Clear breakpoint at specified line or function.\n\
12170 Argument may be line number, function name, or \"*\" and an address.\n\
12171 If line number is specified, all breakpoints in that line are cleared.\n\
12172 If function is specified, breakpoints at beginning of function are cleared.\n\
12173 If an address is specified, breakpoints at that address are cleared.\n\
12175 With no argument, clears all breakpoints in the line that the selected frame\n\
12176 is executing in.\n\
12178 See also the \"delete\" command which clears breakpoints by number."));
12179 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12181 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12182 Set breakpoint at specified line or function.\n"
12183 BREAK_ARGS_HELP ("break")));
12184 set_cmd_completer (c
, location_completer
);
12186 add_com_alias ("b", "break", class_run
, 1);
12187 add_com_alias ("br", "break", class_run
, 1);
12188 add_com_alias ("bre", "break", class_run
, 1);
12189 add_com_alias ("brea", "break", class_run
, 1);
12192 add_com_alias ("ba", "break", class_breakpoint
, 1);
12196 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12197 Break in function/address or break at a line in the current file."),
12198 &stoplist
, "stop ", 1, &cmdlist
);
12199 add_cmd ("in", class_breakpoint
, stopin_command
,
12200 _("Break in function or address."), &stoplist
);
12201 add_cmd ("at", class_breakpoint
, stopat_command
,
12202 _("Break at a line in the current file."), &stoplist
);
12203 add_com ("status", class_info
, breakpoints_info
, _("\
12204 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12205 The \"Type\" column indicates one of:\n\
12206 \tbreakpoint - normal breakpoint\n\
12207 \twatchpoint - watchpoint\n\
12208 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12209 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12210 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12211 address and file/line number respectively.\n\
12213 Convenience variable \"$_\" and default examine address for \"x\"\n\
12214 are set to the address of the last breakpoint listed unless the command\n\
12215 is prefixed with \"server \".\n\n\
12216 Convenience variable \"$bpnum\" contains the number of the last\n\
12217 breakpoint set."));
12220 add_info ("breakpoints", breakpoints_info
, _("\
12221 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
12222 The \"Type\" column indicates one of:\n\
12223 \tbreakpoint - normal breakpoint\n\
12224 \twatchpoint - watchpoint\n\
12225 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12226 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12227 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12228 address and file/line number respectively.\n\
12230 Convenience variable \"$_\" and default examine address for \"x\"\n\
12231 are set to the address of the last breakpoint listed unless the command\n\
12232 is prefixed with \"server \".\n\n\
12233 Convenience variable \"$bpnum\" contains the number of the last\n\
12234 breakpoint set."));
12236 add_info_alias ("b", "breakpoints", 1);
12239 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12240 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12241 The \"Type\" column indicates one of:\n\
12242 \tbreakpoint - normal breakpoint\n\
12243 \twatchpoint - watchpoint\n\
12244 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12245 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12246 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12247 address and file/line number respectively.\n\
12249 Convenience variable \"$_\" and default examine address for \"x\"\n\
12250 are set to the address of the last breakpoint listed unless the command\n\
12251 is prefixed with \"server \".\n\n\
12252 Convenience variable \"$bpnum\" contains the number of the last\n\
12253 breakpoint set."));
12255 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12256 Status of all breakpoints, or breakpoint number NUMBER.\n\
12257 The \"Type\" column indicates one of:\n\
12258 \tbreakpoint - normal breakpoint\n\
12259 \twatchpoint - watchpoint\n\
12260 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12261 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12262 \tuntil - internal breakpoint used by the \"until\" command\n\
12263 \tfinish - internal breakpoint used by the \"finish\" command\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\
12274 &maintenanceinfolist
);
12276 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12277 Set catchpoints to catch events."),
12278 &catch_cmdlist
, "catch ",
12279 0/*allow-unknown*/, &cmdlist
);
12281 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12282 Set temporary catchpoints to catch events."),
12283 &tcatch_cmdlist
, "tcatch ",
12284 0/*allow-unknown*/, &cmdlist
);
12286 /* Add catch and tcatch sub-commands. */
12287 add_catch_command ("catch", _("\
12288 Catch an exception, when caught.\n\
12289 With an argument, catch only exceptions with the given name."),
12290 catch_catch_command
,
12294 add_catch_command ("throw", _("\
12295 Catch an exception, when thrown.\n\
12296 With an argument, catch only exceptions with the given name."),
12297 catch_throw_command
,
12301 add_catch_command ("fork", _("Catch calls to fork."),
12302 catch_fork_command_1
,
12304 (void *) (uintptr_t) catch_fork_permanent
,
12305 (void *) (uintptr_t) catch_fork_temporary
);
12306 add_catch_command ("vfork", _("Catch calls to vfork."),
12307 catch_fork_command_1
,
12309 (void *) (uintptr_t) catch_vfork_permanent
,
12310 (void *) (uintptr_t) catch_vfork_temporary
);
12311 add_catch_command ("exec", _("Catch calls to exec."),
12312 catch_exec_command_1
,
12316 add_catch_command ("syscall", _("\
12317 Catch system calls by their names and/or numbers.\n\
12318 Arguments say which system calls to catch. If no arguments\n\
12319 are given, every system call will be caught.\n\
12320 Arguments, if given, should be one or more system call names\n\
12321 (if your system supports that), or system call numbers."),
12322 catch_syscall_command_1
,
12323 catch_syscall_completer
,
12326 add_catch_command ("exception", _("\
12327 Catch Ada exceptions, when raised.\n\
12328 With an argument, catch only exceptions with the given name."),
12329 catch_ada_exception_command
,
12333 add_catch_command ("assert", _("\
12334 Catch failed Ada assertions, when raised.\n\
12335 With an argument, catch only exceptions with the given name."),
12336 catch_assert_command
,
12341 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12342 Set a watchpoint for an expression.\n\
12343 Usage: watch [-l|-location] EXPRESSION\n\
12344 A watchpoint stops execution of your program whenever the value of\n\
12345 an expression changes.\n\
12346 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12347 the memory to which it refers."));
12348 set_cmd_completer (c
, expression_completer
);
12350 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12351 Set a read watchpoint for an expression.\n\
12352 Usage: rwatch [-l|-location] EXPRESSION\n\
12353 A watchpoint stops execution of your program whenever the value of\n\
12354 an expression is read.\n\
12355 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12356 the memory to which it refers."));
12357 set_cmd_completer (c
, expression_completer
);
12359 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12360 Set a watchpoint for an expression.\n\
12361 Usage: awatch [-l|-location] EXPRESSION\n\
12362 A watchpoint stops execution of your program whenever the value of\n\
12363 an expression is either read or written.\n\
12364 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12365 the memory to which it refers."));
12366 set_cmd_completer (c
, expression_completer
);
12368 add_info ("watchpoints", watchpoints_info
, _("\
12369 Status of specified watchpoints (all watchpoints if no argument)."));
12371 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12372 respond to changes - contrary to the description. */
12373 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12374 &can_use_hw_watchpoints
, _("\
12375 Set debugger's willingness to use watchpoint hardware."), _("\
12376 Show debugger's willingness to use watchpoint hardware."), _("\
12377 If zero, gdb will not use hardware for new watchpoints, even if\n\
12378 such is available. (However, any hardware watchpoints that were\n\
12379 created before setting this to nonzero, will continue to use watchpoint\n\
12382 show_can_use_hw_watchpoints
,
12383 &setlist
, &showlist
);
12385 can_use_hw_watchpoints
= 1;
12387 /* Tracepoint manipulation commands. */
12389 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12390 Set a tracepoint at specified line or function.\n\
12392 BREAK_ARGS_HELP ("trace") "\n\
12393 Do \"help tracepoints\" for info on other tracepoint commands."));
12394 set_cmd_completer (c
, location_completer
);
12396 add_com_alias ("tp", "trace", class_alias
, 0);
12397 add_com_alias ("tr", "trace", class_alias
, 1);
12398 add_com_alias ("tra", "trace", class_alias
, 1);
12399 add_com_alias ("trac", "trace", class_alias
, 1);
12401 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12402 Set a fast tracepoint at specified line or function.\n\
12404 BREAK_ARGS_HELP ("ftrace") "\n\
12405 Do \"help tracepoints\" for info on other tracepoint commands."));
12406 set_cmd_completer (c
, location_completer
);
12408 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12409 Set a static tracepoint at specified line, function or marker.\n\
12411 strace [LOCATION] [if CONDITION]\n\
12412 LOCATION may be a line number, function name, \"*\" and an address,\n\
12413 or -m MARKER_ID.\n\
12414 If a line number is specified, probe the marker at start of code\n\
12415 for that line. If a function is specified, probe the marker at start\n\
12416 of code for that function. If an address is specified, probe the marker\n\
12417 at that exact address. If a marker id is specified, probe the marker\n\
12418 with that name. With no LOCATION, uses current execution address of\n\
12419 the selected stack frame.\n\
12420 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12421 This collects arbitrary user data passed in the probe point call to the\n\
12422 tracing library. You can inspect it when analyzing the trace buffer,\n\
12423 by printing the $_sdata variable like any other convenience variable.\n\
12425 CONDITION is a boolean expression.\n\
12427 Multiple tracepoints at one place are permitted, and useful if their\n\
12428 conditions are different.\n\
12430 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12431 Do \"help tracepoints\" for info on other tracepoint commands."));
12432 set_cmd_completer (c
, location_completer
);
12434 add_info ("tracepoints", tracepoints_info
, _("\
12435 Status of specified tracepoints (all tracepoints if no argument).\n\
12436 Convenience variable \"$tpnum\" contains the number of the\n\
12437 last tracepoint set."));
12439 add_info_alias ("tp", "tracepoints", 1);
12441 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12442 Delete specified tracepoints.\n\
12443 Arguments are tracepoint numbers, separated by spaces.\n\
12444 No argument means delete all tracepoints."),
12447 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12448 Disable specified tracepoints.\n\
12449 Arguments are tracepoint numbers, separated by spaces.\n\
12450 No argument means disable all tracepoints."),
12452 deprecate_cmd (c
, "disable");
12454 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12455 Enable specified tracepoints.\n\
12456 Arguments are tracepoint numbers, separated by spaces.\n\
12457 No argument means enable all tracepoints."),
12459 deprecate_cmd (c
, "enable");
12461 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12462 Set the passcount for a tracepoint.\n\
12463 The trace will end when the tracepoint has been passed 'count' times.\n\
12464 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12465 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12467 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12468 _("Save breakpoint definitions as a script."),
12469 &save_cmdlist
, "save ",
12470 0/*allow-unknown*/, &cmdlist
);
12472 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12473 Save current breakpoint definitions as a script.\n\
12474 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12475 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12476 session to restore them."),
12478 set_cmd_completer (c
, filename_completer
);
12480 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12481 Save current tracepoint definitions as a script.\n\
12482 Use the 'source' command in another debug session to restore them."),
12484 set_cmd_completer (c
, filename_completer
);
12486 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12487 deprecate_cmd (c
, "save tracepoints");
12489 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12490 Breakpoint specific settings\n\
12491 Configure various breakpoint-specific variables such as\n\
12492 pending breakpoint behavior"),
12493 &breakpoint_set_cmdlist
, "set breakpoint ",
12494 0/*allow-unknown*/, &setlist
);
12495 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12496 Breakpoint specific settings\n\
12497 Configure various breakpoint-specific variables such as\n\
12498 pending breakpoint behavior"),
12499 &breakpoint_show_cmdlist
, "show breakpoint ",
12500 0/*allow-unknown*/, &showlist
);
12502 add_setshow_auto_boolean_cmd ("pending", no_class
,
12503 &pending_break_support
, _("\
12504 Set debugger's behavior regarding pending breakpoints."), _("\
12505 Show debugger's behavior regarding pending breakpoints."), _("\
12506 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12507 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12508 an error. If auto, an unrecognized breakpoint location results in a\n\
12509 user-query to see if a pending breakpoint should be created."),
12511 show_pending_break_support
,
12512 &breakpoint_set_cmdlist
,
12513 &breakpoint_show_cmdlist
);
12515 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12517 add_setshow_boolean_cmd ("auto-hw", no_class
,
12518 &automatic_hardware_breakpoints
, _("\
12519 Set automatic usage of hardware breakpoints."), _("\
12520 Show automatic usage of hardware breakpoints."), _("\
12521 If set, the debugger will automatically use hardware breakpoints for\n\
12522 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12523 a warning will be emitted for such breakpoints."),
12525 show_automatic_hardware_breakpoints
,
12526 &breakpoint_set_cmdlist
,
12527 &breakpoint_show_cmdlist
);
12529 add_setshow_enum_cmd ("always-inserted", class_support
,
12530 always_inserted_enums
, &always_inserted_mode
, _("\
12531 Set mode for inserting breakpoints."), _("\
12532 Show mode for inserting breakpoints."), _("\
12533 When this mode is off, breakpoints are inserted in inferior when it is\n\
12534 resumed, and removed when execution stops. When this mode is on,\n\
12535 breakpoints are inserted immediately and removed only when the user\n\
12536 deletes the breakpoint. When this mode is auto (which is the default),\n\
12537 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12538 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12539 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12540 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12542 &show_always_inserted_mode
,
12543 &breakpoint_set_cmdlist
,
12544 &breakpoint_show_cmdlist
);
12546 automatic_hardware_breakpoints
= 1;
12548 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);