1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
42 #include "filenames.h"
48 #include "completer.h"
51 #include "cli/cli-script.h"
52 #include "gdb_assert.h"
57 #include "exceptions.h"
64 #include "xml-syscall.h"
65 #include "parser-defs.h"
66 #include "cli/cli-utils.h"
67 #include "continuations.h"
69 /* readline include files */
70 #include "readline/readline.h"
71 #include "readline/history.h"
73 /* readline defines this. */
76 #include "mi/mi-common.h"
77 #include "python/python.h"
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void breakpoint_re_set_default (struct breakpoint
*);
99 static void clear_command (char *, int);
101 static void catch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value
*);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint
*);
109 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
111 struct breakpoint_ops
*);
112 /* This function is used in gdbtk sources and thus can not be made
114 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
115 struct symtab_and_line
,
116 enum bptype
, struct breakpoint_ops
*);
118 static struct breakpoint
*
119 momentary_breakpoint_from_master (struct breakpoint
*orig
,
121 struct breakpoint_ops
*ops
);
123 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
125 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
129 static void describe_other_breakpoints (struct gdbarch
*,
130 struct program_space
*, CORE_ADDR
,
131 struct obj_section
*, int);
133 static int breakpoint_address_match (struct address_space
*aspace1
,
135 struct address_space
*aspace2
,
138 static int watchpoint_locations_match (struct bp_location
*loc1
,
139 struct bp_location
*loc2
);
141 static int breakpoint_location_address_match (struct bp_location
*bl
,
142 struct address_space
*aspace
,
145 static void breakpoints_info (char *, int);
147 static void watchpoints_info (char *, int);
149 static int breakpoint_1 (char *, int,
150 int (*) (const struct breakpoint
*));
152 static int breakpoint_cond_eval (void *);
154 static void cleanup_executing_breakpoints (void *);
156 static void commands_command (char *, int);
158 static void condition_command (char *, int);
167 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
168 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
170 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
172 static int watchpoint_check (void *);
174 static void maintenance_info_breakpoints (char *, int);
176 static int hw_breakpoint_used_count (void);
178 static int hw_watchpoint_used_count (enum bptype
, int *);
180 static void hbreak_command (char *, int);
182 static void thbreak_command (char *, int);
184 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
);
186 static void stop_command (char *arg
, int from_tty
);
188 static void stopin_command (char *arg
, int from_tty
);
190 static void stopat_command (char *arg
, int from_tty
);
192 static char *ep_parse_optional_if_clause (char **arg
);
194 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
195 char *arg
, int tempflag
, int from_tty
);
197 static void tcatch_command (char *arg
, int from_tty
);
199 static void detach_single_step_breakpoints (void);
201 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
204 static void free_bp_location (struct bp_location
*loc
);
205 static void incref_bp_location (struct bp_location
*loc
);
206 static void decref_bp_location (struct bp_location
**loc
);
208 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
210 static void update_global_location_list (int);
212 static void update_global_location_list_nothrow (int);
214 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
216 static void insert_breakpoint_locations (void);
218 static int syscall_catchpoint_p (struct breakpoint
*b
);
220 static void tracepoints_info (char *, int);
222 static void delete_trace_command (char *, int);
224 static void enable_trace_command (char *, int);
226 static void disable_trace_command (char *, int);
228 static void trace_pass_command (char *, int);
230 static int is_masked_watchpoint (const struct breakpoint
*b
);
232 /* Assuming we're creating a static tracepoint, does S look like a
233 static tracepoint marker spec ("-m MARKER_ID")? */
234 #define is_marker_spec(s) \
235 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
237 /* The abstract base class all breakpoint_ops structures inherit
239 static struct breakpoint_ops base_breakpoint_ops
;
241 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
242 that are implemented on top of software or hardware breakpoints
243 (user breakpoints, internal and momentary breakpoints, etc.). */
244 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
246 /* Internal breakpoints class type. */
247 static struct breakpoint_ops internal_breakpoint_ops
;
249 /* Momentary breakpoints class type. */
250 static struct breakpoint_ops momentary_breakpoint_ops
;
252 /* The breakpoint_ops structure to be used in regular user created
254 struct breakpoint_ops bkpt_breakpoint_ops
;
256 /* A reference-counted struct command_line. This lets multiple
257 breakpoints share a single command list. */
258 struct counted_command_line
260 /* The reference count. */
263 /* The command list. */
264 struct command_line
*commands
;
267 struct command_line
*
268 breakpoint_commands (struct breakpoint
*b
)
270 return b
->commands
? b
->commands
->commands
: NULL
;
273 /* Flag indicating that a command has proceeded the inferior past the
274 current breakpoint. */
276 static int breakpoint_proceeded
;
279 bpdisp_text (enum bpdisp disp
)
281 /* NOTE: the following values are a part of MI protocol and
282 represent values of 'disp' field returned when inferior stops at
284 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
286 return bpdisps
[(int) disp
];
289 /* Prototypes for exported functions. */
290 /* If FALSE, gdb will not use hardware support for watchpoints, even
291 if such is available. */
292 static int can_use_hw_watchpoints
;
295 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
296 struct cmd_list_element
*c
,
299 fprintf_filtered (file
,
300 _("Debugger's willingness to use "
301 "watchpoint hardware is %s.\n"),
305 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
306 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
307 for unrecognized breakpoint locations.
308 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
309 static enum auto_boolean pending_break_support
;
311 show_pending_break_support (struct ui_file
*file
, int from_tty
,
312 struct cmd_list_element
*c
,
315 fprintf_filtered (file
,
316 _("Debugger's behavior regarding "
317 "pending breakpoints is %s.\n"),
321 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
322 set with "break" but falling in read-only memory.
323 If 0, gdb will warn about such breakpoints, but won't automatically
324 use hardware breakpoints. */
325 static int automatic_hardware_breakpoints
;
327 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
328 struct cmd_list_element
*c
,
331 fprintf_filtered (file
,
332 _("Automatic usage of hardware breakpoints is %s.\n"),
336 /* If on, gdb will keep breakpoints inserted even as inferior is
337 stopped, and immediately insert any new breakpoints. If off, gdb
338 will insert breakpoints into inferior only when resuming it, and
339 will remove breakpoints upon stop. If auto, GDB will behave as ON
340 if in non-stop mode, and as OFF if all-stop mode.*/
342 static const char always_inserted_auto
[] = "auto";
343 static const char always_inserted_on
[] = "on";
344 static const char always_inserted_off
[] = "off";
345 static const char *always_inserted_enums
[] = {
346 always_inserted_auto
,
351 static const char *always_inserted_mode
= always_inserted_auto
;
353 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
354 struct cmd_list_element
*c
, const char *value
)
356 if (always_inserted_mode
== always_inserted_auto
)
357 fprintf_filtered (file
,
358 _("Always inserted breakpoint "
359 "mode is %s (currently %s).\n"),
361 breakpoints_always_inserted_mode () ? "on" : "off");
363 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
368 breakpoints_always_inserted_mode (void)
370 return (always_inserted_mode
== always_inserted_on
371 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
374 void _initialize_breakpoint (void);
376 /* Are we executing breakpoint commands? */
377 static int executing_breakpoint_commands
;
379 /* Are overlay event breakpoints enabled? */
380 static int overlay_events_enabled
;
382 /* See description in breakpoint.h. */
383 int target_exact_watchpoints
= 0;
385 /* Walk the following statement or block through all breakpoints.
386 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
387 current breakpoint. */
389 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
391 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
392 for (B = breakpoint_chain; \
393 B ? (TMP=B->next, 1): 0; \
396 /* Similar iterator for the low-level breakpoints. SAFE variant is
397 not provided so update_global_location_list must not be called
398 while executing the block of ALL_BP_LOCATIONS. */
400 #define ALL_BP_LOCATIONS(B,BP_TMP) \
401 for (BP_TMP = bp_location; \
402 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
405 /* Iterator for tracepoints only. */
407 #define ALL_TRACEPOINTS(B) \
408 for (B = breakpoint_chain; B; B = B->next) \
409 if (is_tracepoint (B))
411 /* Chains of all breakpoints defined. */
413 struct breakpoint
*breakpoint_chain
;
415 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
417 static struct bp_location
**bp_location
;
419 /* Number of elements of BP_LOCATION. */
421 static unsigned bp_location_count
;
423 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
424 ADDRESS for the current elements of BP_LOCATION which get a valid
425 result from bp_location_has_shadow. You can use it for roughly
426 limiting the subrange of BP_LOCATION to scan for shadow bytes for
427 an address you need to read. */
429 static CORE_ADDR bp_location_placed_address_before_address_max
;
431 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
432 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
433 BP_LOCATION which get a valid result from bp_location_has_shadow.
434 You can use it for roughly limiting the subrange of BP_LOCATION to
435 scan for shadow bytes for an address you need to read. */
437 static CORE_ADDR bp_location_shadow_len_after_address_max
;
439 /* The locations that no longer correspond to any breakpoint, unlinked
440 from bp_location array, but for which a hit may still be reported
442 VEC(bp_location_p
) *moribund_locations
= NULL
;
444 /* Number of last breakpoint made. */
446 static int breakpoint_count
;
448 /* The value of `breakpoint_count' before the last command that
449 created breakpoints. If the last (break-like) command created more
450 than one breakpoint, then the difference between BREAKPOINT_COUNT
451 and PREV_BREAKPOINT_COUNT is more than one. */
452 static int prev_breakpoint_count
;
454 /* Number of last tracepoint made. */
456 static int tracepoint_count
;
458 static struct cmd_list_element
*breakpoint_set_cmdlist
;
459 static struct cmd_list_element
*breakpoint_show_cmdlist
;
460 struct cmd_list_element
*save_cmdlist
;
462 /* Return whether a breakpoint is an active enabled breakpoint. */
464 breakpoint_enabled (struct breakpoint
*b
)
466 return (b
->enable_state
== bp_enabled
);
469 /* Set breakpoint count to NUM. */
472 set_breakpoint_count (int num
)
474 prev_breakpoint_count
= breakpoint_count
;
475 breakpoint_count
= num
;
476 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
479 /* Used by `start_rbreak_breakpoints' below, to record the current
480 breakpoint count before "rbreak" creates any breakpoint. */
481 static int rbreak_start_breakpoint_count
;
483 /* Called at the start an "rbreak" command to record the first
487 start_rbreak_breakpoints (void)
489 rbreak_start_breakpoint_count
= breakpoint_count
;
492 /* Called at the end of an "rbreak" command to record the last
496 end_rbreak_breakpoints (void)
498 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
501 /* Used in run_command to zero the hit count when a new run starts. */
504 clear_breakpoint_hit_counts (void)
506 struct breakpoint
*b
;
512 /* Allocate a new counted_command_line with reference count of 1.
513 The new structure owns COMMANDS. */
515 static struct counted_command_line
*
516 alloc_counted_command_line (struct command_line
*commands
)
518 struct counted_command_line
*result
519 = xmalloc (sizeof (struct counted_command_line
));
522 result
->commands
= commands
;
526 /* Increment reference count. This does nothing if CMD is NULL. */
529 incref_counted_command_line (struct counted_command_line
*cmd
)
535 /* Decrement reference count. If the reference count reaches 0,
536 destroy the counted_command_line. Sets *CMDP to NULL. This does
537 nothing if *CMDP is NULL. */
540 decref_counted_command_line (struct counted_command_line
**cmdp
)
544 if (--(*cmdp
)->refc
== 0)
546 free_command_lines (&(*cmdp
)->commands
);
553 /* A cleanup function that calls decref_counted_command_line. */
556 do_cleanup_counted_command_line (void *arg
)
558 decref_counted_command_line (arg
);
561 /* Create a cleanup that calls decref_counted_command_line on the
564 static struct cleanup
*
565 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
567 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
570 /* Default address, symtab and line to put a breakpoint at
571 for "break" command with no arg.
572 If default_breakpoint_valid is zero, the other three are
573 not valid, and "break" with no arg is an error.
575 This set by print_stack_frame, which calls set_default_breakpoint. */
577 int default_breakpoint_valid
;
578 CORE_ADDR default_breakpoint_address
;
579 struct symtab
*default_breakpoint_symtab
;
580 int default_breakpoint_line
;
581 struct program_space
*default_breakpoint_pspace
;
584 /* Return the breakpoint with the specified number, or NULL
585 if the number does not refer to an existing breakpoint. */
588 get_breakpoint (int num
)
590 struct breakpoint
*b
;
593 if (b
->number
== num
)
602 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
605 xfree (b
->cond_string
);
606 b
->cond_string
= NULL
;
608 if (is_watchpoint (b
))
610 struct watchpoint
*w
= (struct watchpoint
*) b
;
617 struct bp_location
*loc
;
619 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
629 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
635 /* I don't know if it matters whether this is the string the user
636 typed in or the decompiled expression. */
637 b
->cond_string
= xstrdup (arg
);
638 b
->condition_not_parsed
= 0;
640 if (is_watchpoint (b
))
642 struct watchpoint
*w
= (struct watchpoint
*) b
;
644 innermost_block
= NULL
;
646 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
648 error (_("Junk at end of expression"));
649 w
->cond_exp_valid_block
= innermost_block
;
653 struct bp_location
*loc
;
655 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
659 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
661 error (_("Junk at end of expression"));
665 breakpoints_changed ();
666 observer_notify_breakpoint_modified (b
);
669 /* condition N EXP -- set break condition of breakpoint N to EXP. */
672 condition_command (char *arg
, int from_tty
)
674 struct breakpoint
*b
;
679 error_no_arg (_("breakpoint number"));
682 bnum
= get_number (&p
);
684 error (_("Bad breakpoint argument: '%s'"), arg
);
687 if (b
->number
== bnum
)
689 /* Check if this breakpoint has a Python object assigned to
690 it, and if it has a definition of the "stop"
691 method. This method and conditions entered into GDB from
692 the CLI are mutually exclusive. */
694 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
695 error (_("Cannot set a condition where a Python 'stop' "
696 "method has been defined in the breakpoint."));
697 set_breakpoint_condition (b
, p
, from_tty
);
701 error (_("No breakpoint number %d."), bnum
);
704 /* Check that COMMAND do not contain commands that are suitable
705 only for tracepoints and not suitable for ordinary breakpoints.
706 Throw if any such commands is found. */
709 check_no_tracepoint_commands (struct command_line
*commands
)
711 struct command_line
*c
;
713 for (c
= commands
; c
; c
= c
->next
)
717 if (c
->control_type
== while_stepping_control
)
718 error (_("The 'while-stepping' command can "
719 "only be used for tracepoints"));
721 for (i
= 0; i
< c
->body_count
; ++i
)
722 check_no_tracepoint_commands ((c
->body_list
)[i
]);
724 /* Not that command parsing removes leading whitespace and comment
725 lines and also empty lines. So, we only need to check for
727 if (strstr (c
->line
, "collect ") == c
->line
)
728 error (_("The 'collect' command can only be used for tracepoints"));
730 if (strstr (c
->line
, "teval ") == c
->line
)
731 error (_("The 'teval' command can only be used for tracepoints"));
735 /* Encapsulate tests for different types of tracepoints. */
738 is_tracepoint_type (enum bptype type
)
740 return (type
== bp_tracepoint
741 || type
== bp_fast_tracepoint
742 || type
== bp_static_tracepoint
);
746 is_tracepoint (const struct breakpoint
*b
)
748 return is_tracepoint_type (b
->type
);
751 /* A helper function that validates that COMMANDS are valid for a
752 breakpoint. This function will throw an exception if a problem is
756 validate_commands_for_breakpoint (struct breakpoint
*b
,
757 struct command_line
*commands
)
759 if (is_tracepoint (b
))
761 /* We need to verify that each top-level element of commands is
762 valid for tracepoints, that there's at most one
763 while-stepping element, and that while-stepping's body has
764 valid tracing commands excluding nested while-stepping. */
765 struct command_line
*c
;
766 struct command_line
*while_stepping
= 0;
767 for (c
= commands
; c
; c
= c
->next
)
769 if (c
->control_type
== while_stepping_control
)
771 if (b
->type
== bp_fast_tracepoint
)
772 error (_("The 'while-stepping' command "
773 "cannot be used for fast tracepoint"));
774 else if (b
->type
== bp_static_tracepoint
)
775 error (_("The 'while-stepping' command "
776 "cannot be used for static tracepoint"));
779 error (_("The 'while-stepping' command "
780 "can be used only once"));
787 struct command_line
*c2
;
789 gdb_assert (while_stepping
->body_count
== 1);
790 c2
= while_stepping
->body_list
[0];
791 for (; c2
; c2
= c2
->next
)
793 if (c2
->control_type
== while_stepping_control
)
794 error (_("The 'while-stepping' command cannot be nested"));
800 check_no_tracepoint_commands (commands
);
804 /* Return a vector of all the static tracepoints set at ADDR. The
805 caller is responsible for releasing the vector. */
808 static_tracepoints_here (CORE_ADDR addr
)
810 struct breakpoint
*b
;
811 VEC(breakpoint_p
) *found
= 0;
812 struct bp_location
*loc
;
815 if (b
->type
== bp_static_tracepoint
)
817 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
818 if (loc
->address
== addr
)
819 VEC_safe_push(breakpoint_p
, found
, b
);
825 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
826 validate that only allowed commands are included. */
829 breakpoint_set_commands (struct breakpoint
*b
,
830 struct command_line
*commands
)
832 validate_commands_for_breakpoint (b
, commands
);
834 decref_counted_command_line (&b
->commands
);
835 b
->commands
= alloc_counted_command_line (commands
);
836 breakpoints_changed ();
837 observer_notify_breakpoint_modified (b
);
840 /* Set the internal `silent' flag on the breakpoint. Note that this
841 is not the same as the "silent" that may appear in the breakpoint's
845 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
847 int old_silent
= b
->silent
;
850 if (old_silent
!= silent
)
851 observer_notify_breakpoint_modified (b
);
854 /* Set the thread for this breakpoint. If THREAD is -1, make the
855 breakpoint work for any thread. */
858 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
860 int old_thread
= b
->thread
;
863 if (old_thread
!= thread
)
864 observer_notify_breakpoint_modified (b
);
867 /* Set the task for this breakpoint. If TASK is 0, make the
868 breakpoint work for any task. */
871 breakpoint_set_task (struct breakpoint
*b
, int task
)
873 int old_task
= b
->task
;
876 if (old_task
!= task
)
877 observer_notify_breakpoint_modified (b
);
881 check_tracepoint_command (char *line
, void *closure
)
883 struct breakpoint
*b
= closure
;
885 validate_actionline (&line
, b
);
888 /* A structure used to pass information through
889 map_breakpoint_numbers. */
893 /* True if the command was typed at a tty. */
896 /* The breakpoint range spec. */
899 /* Non-NULL if the body of the commands are being read from this
900 already-parsed command. */
901 struct command_line
*control
;
903 /* The command lines read from the user, or NULL if they have not
905 struct counted_command_line
*cmd
;
908 /* A callback for map_breakpoint_numbers that sets the commands for
912 do_map_commands_command (struct breakpoint
*b
, void *data
)
914 struct commands_info
*info
= data
;
916 if (info
->cmd
== NULL
)
918 struct command_line
*l
;
920 if (info
->control
!= NULL
)
921 l
= copy_command_lines (info
->control
->body_list
[0]);
924 struct cleanup
*old_chain
;
927 str
= xstrprintf (_("Type commands for breakpoint(s) "
928 "%s, one per line."),
931 old_chain
= make_cleanup (xfree
, str
);
933 l
= read_command_lines (str
,
936 ? check_tracepoint_command
: 0),
939 do_cleanups (old_chain
);
942 info
->cmd
= alloc_counted_command_line (l
);
945 /* If a breakpoint was on the list more than once, we don't need to
947 if (b
->commands
!= info
->cmd
)
949 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
950 incref_counted_command_line (info
->cmd
);
951 decref_counted_command_line (&b
->commands
);
952 b
->commands
= info
->cmd
;
953 breakpoints_changed ();
954 observer_notify_breakpoint_modified (b
);
959 commands_command_1 (char *arg
, int from_tty
,
960 struct command_line
*control
)
962 struct cleanup
*cleanups
;
963 struct commands_info info
;
965 info
.from_tty
= from_tty
;
966 info
.control
= control
;
968 /* If we read command lines from the user, then `info' will hold an
969 extra reference to the commands that we must clean up. */
970 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
972 if (arg
== NULL
|| !*arg
)
974 if (breakpoint_count
- prev_breakpoint_count
> 1)
975 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
977 else if (breakpoint_count
> 0)
978 arg
= xstrprintf ("%d", breakpoint_count
);
981 /* So that we don't try to free the incoming non-NULL
982 argument in the cleanup below. Mapping breakpoint
983 numbers will fail in this case. */
988 /* The command loop has some static state, so we need to preserve
993 make_cleanup (xfree
, arg
);
997 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
999 if (info
.cmd
== NULL
)
1000 error (_("No breakpoints specified."));
1002 do_cleanups (cleanups
);
1006 commands_command (char *arg
, int from_tty
)
1008 commands_command_1 (arg
, from_tty
, NULL
);
1011 /* Like commands_command, but instead of reading the commands from
1012 input stream, takes them from an already parsed command structure.
1014 This is used by cli-script.c to DTRT with breakpoint commands
1015 that are part of if and while bodies. */
1016 enum command_control_type
1017 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1019 commands_command_1 (arg
, 0, cmd
);
1020 return simple_control
;
1023 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1026 bp_location_has_shadow (struct bp_location
*bl
)
1028 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1032 if (bl
->target_info
.shadow_len
== 0)
1033 /* BL isn't valid, or doesn't shadow memory. */
1038 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1039 by replacing any memory breakpoints with their shadowed contents.
1041 The range of shadowed area by each bp_location is:
1042 bl->address - bp_location_placed_address_before_address_max
1043 up to bl->address + bp_location_shadow_len_after_address_max
1044 The range we were requested to resolve shadows for is:
1045 memaddr ... memaddr + len
1046 Thus the safe cutoff boundaries for performance optimization are
1047 memaddr + len <= (bl->address
1048 - bp_location_placed_address_before_address_max)
1050 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1053 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1055 /* Left boundary, right boundary and median element of our binary
1057 unsigned bc_l
, bc_r
, bc
;
1059 /* Find BC_L which is a leftmost element which may affect BUF
1060 content. It is safe to report lower value but a failure to
1061 report higher one. */
1064 bc_r
= bp_location_count
;
1065 while (bc_l
+ 1 < bc_r
)
1067 struct bp_location
*bl
;
1069 bc
= (bc_l
+ bc_r
) / 2;
1070 bl
= bp_location
[bc
];
1072 /* Check first BL->ADDRESS will not overflow due to the added
1073 constant. Then advance the left boundary only if we are sure
1074 the BC element can in no way affect the BUF content (MEMADDR
1075 to MEMADDR + LEN range).
1077 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1078 offset so that we cannot miss a breakpoint with its shadow
1079 range tail still reaching MEMADDR. */
1081 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1083 && (bl
->address
+ bp_location_shadow_len_after_address_max
1090 /* Due to the binary search above, we need to make sure we pick the
1091 first location that's at BC_L's address. E.g., if there are
1092 multiple locations at the same address, BC_L may end up pointing
1093 at a duplicate location, and miss the "master"/"inserted"
1094 location. Say, given locations L1, L2 and L3 at addresses A and
1097 L1@A, L2@A, L3@B, ...
1099 BC_L could end up pointing at location L2, while the "master"
1100 location could be L1. Since the `loc->inserted' flag is only set
1101 on "master" locations, we'd forget to restore the shadow of L1
1104 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1107 /* Now do full processing of the found relevant range of elements. */
1109 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1111 struct bp_location
*bl
= bp_location
[bc
];
1112 CORE_ADDR bp_addr
= 0;
1116 /* bp_location array has BL->OWNER always non-NULL. */
1117 if (bl
->owner
->type
== bp_none
)
1118 warning (_("reading through apparently deleted breakpoint #%d?"),
1121 /* Performance optimization: any further element can no longer affect BUF
1124 if (bl
->address
>= bp_location_placed_address_before_address_max
1125 && memaddr
+ len
<= (bl
->address
1126 - bp_location_placed_address_before_address_max
))
1129 if (!bp_location_has_shadow (bl
))
1131 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1132 current_program_space
->aspace
, 0))
1135 /* Addresses and length of the part of the breakpoint that
1137 bp_addr
= bl
->target_info
.placed_address
;
1138 bp_size
= bl
->target_info
.shadow_len
;
1140 if (bp_addr
+ bp_size
<= memaddr
)
1141 /* The breakpoint is entirely before the chunk of memory we
1145 if (bp_addr
>= memaddr
+ len
)
1146 /* The breakpoint is entirely after the chunk of memory we are
1150 /* Offset within shadow_contents. */
1151 if (bp_addr
< memaddr
)
1153 /* Only copy the second part of the breakpoint. */
1154 bp_size
-= memaddr
- bp_addr
;
1155 bptoffset
= memaddr
- bp_addr
;
1159 if (bp_addr
+ bp_size
> memaddr
+ len
)
1161 /* Only copy the first part of the breakpoint. */
1162 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1165 memcpy (buf
+ bp_addr
- memaddr
,
1166 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1171 /* Return true if BPT is of any hardware watchpoint kind. */
1174 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1176 return (bpt
->type
== bp_hardware_watchpoint
1177 || bpt
->type
== bp_read_watchpoint
1178 || bpt
->type
== bp_access_watchpoint
);
1181 /* Return true if BPT is of any watchpoint kind, hardware or
1185 is_watchpoint (const struct breakpoint
*bpt
)
1187 return (is_hardware_watchpoint (bpt
)
1188 || bpt
->type
== bp_watchpoint
);
1191 /* Returns true if the current thread and its running state are safe
1192 to evaluate or update watchpoint B. Watchpoints on local
1193 expressions need to be evaluated in the context of the thread that
1194 was current when the watchpoint was created, and, that thread needs
1195 to be stopped to be able to select the correct frame context.
1196 Watchpoints on global expressions can be evaluated on any thread,
1197 and in any state. It is presently left to the target allowing
1198 memory accesses when threads are running. */
1201 watchpoint_in_thread_scope (struct watchpoint
*b
)
1203 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1204 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1205 && !is_executing (inferior_ptid
)));
1208 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1209 associated bp_watchpoint_scope breakpoint. */
1212 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1214 struct breakpoint
*b
= &w
->base
;
1216 if (b
->related_breakpoint
!= b
)
1218 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1219 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1220 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1221 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1222 b
->related_breakpoint
= b
;
1224 b
->disposition
= disp_del_at_next_stop
;
1227 /* Assuming that B is a watchpoint:
1228 - Reparse watchpoint expression, if REPARSE is non-zero
1229 - Evaluate expression and store the result in B->val
1230 - Evaluate the condition if there is one, and store the result
1232 - Update the list of values that must be watched in B->loc.
1234 If the watchpoint disposition is disp_del_at_next_stop, then do
1235 nothing. If this is local watchpoint that is out of scope, delete
1238 Even with `set breakpoint always-inserted on' the watchpoints are
1239 removed + inserted on each stop here. Normal breakpoints must
1240 never be removed because they might be missed by a running thread
1241 when debugging in non-stop mode. On the other hand, hardware
1242 watchpoints (is_hardware_watchpoint; processed here) are specific
1243 to each LWP since they are stored in each LWP's hardware debug
1244 registers. Therefore, such LWP must be stopped first in order to
1245 be able to modify its hardware watchpoints.
1247 Hardware watchpoints must be reset exactly once after being
1248 presented to the user. It cannot be done sooner, because it would
1249 reset the data used to present the watchpoint hit to the user. And
1250 it must not be done later because it could display the same single
1251 watchpoint hit during multiple GDB stops. Note that the latter is
1252 relevant only to the hardware watchpoint types bp_read_watchpoint
1253 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1254 not user-visible - its hit is suppressed if the memory content has
1257 The following constraints influence the location where we can reset
1258 hardware watchpoints:
1260 * target_stopped_by_watchpoint and target_stopped_data_address are
1261 called several times when GDB stops.
1264 * Multiple hardware watchpoints can be hit at the same time,
1265 causing GDB to stop. GDB only presents one hardware watchpoint
1266 hit at a time as the reason for stopping, and all the other hits
1267 are presented later, one after the other, each time the user
1268 requests the execution to be resumed. Execution is not resumed
1269 for the threads still having pending hit event stored in
1270 LWP_INFO->STATUS. While the watchpoint is already removed from
1271 the inferior on the first stop the thread hit event is kept being
1272 reported from its cached value by linux_nat_stopped_data_address
1273 until the real thread resume happens after the watchpoint gets
1274 presented and thus its LWP_INFO->STATUS gets reset.
1276 Therefore the hardware watchpoint hit can get safely reset on the
1277 watchpoint removal from inferior. */
1280 update_watchpoint (struct watchpoint
*b
, int reparse
)
1282 int within_current_scope
;
1283 struct frame_id saved_frame_id
;
1286 /* If this is a local watchpoint, we only want to check if the
1287 watchpoint frame is in scope if the current thread is the thread
1288 that was used to create the watchpoint. */
1289 if (!watchpoint_in_thread_scope (b
))
1292 if (b
->base
.disposition
== disp_del_at_next_stop
)
1297 /* Determine if the watchpoint is within scope. */
1298 if (b
->exp_valid_block
== NULL
)
1299 within_current_scope
= 1;
1302 struct frame_info
*fi
= get_current_frame ();
1303 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1304 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1306 /* If we're in a function epilogue, unwinding may not work
1307 properly, so do not attempt to recreate locations at this
1308 point. See similar comments in watchpoint_check. */
1309 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1312 /* Save the current frame's ID so we can restore it after
1313 evaluating the watchpoint expression on its own frame. */
1314 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1315 took a frame parameter, so that we didn't have to change the
1318 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1320 fi
= frame_find_by_id (b
->watchpoint_frame
);
1321 within_current_scope
= (fi
!= NULL
);
1322 if (within_current_scope
)
1326 /* We don't free locations. They are stored in the bp_location array
1327 and update_global_location_list will eventually delete them and
1328 remove breakpoints if needed. */
1331 if (within_current_scope
&& reparse
)
1340 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1341 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1342 /* If the meaning of expression itself changed, the old value is
1343 no longer relevant. We don't want to report a watchpoint hit
1344 to the user when the old value and the new value may actually
1345 be completely different objects. */
1346 value_free (b
->val
);
1350 /* Note that unlike with breakpoints, the watchpoint's condition
1351 expression is stored in the breakpoint object, not in the
1352 locations (re)created below. */
1353 if (b
->base
.cond_string
!= NULL
)
1355 if (b
->cond_exp
!= NULL
)
1357 xfree (b
->cond_exp
);
1361 s
= b
->base
.cond_string
;
1362 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1366 /* If we failed to parse the expression, for example because
1367 it refers to a global variable in a not-yet-loaded shared library,
1368 don't try to insert watchpoint. We don't automatically delete
1369 such watchpoint, though, since failure to parse expression
1370 is different from out-of-scope watchpoint. */
1371 if ( !target_has_execution
)
1373 /* Without execution, memory can't change. No use to try and
1374 set watchpoint locations. The watchpoint will be reset when
1375 the target gains execution, through breakpoint_re_set. */
1377 else if (within_current_scope
&& b
->exp
)
1380 struct value
*val_chain
, *v
, *result
, *next
;
1381 struct program_space
*frame_pspace
;
1383 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1385 /* Avoid setting b->val if it's already set. The meaning of
1386 b->val is 'the last value' user saw, and we should update
1387 it only if we reported that last value to user. As it
1388 happens, the code that reports it updates b->val directly.
1389 We don't keep track of the memory value for masked
1391 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1397 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1399 /* Look at each value on the value chain. */
1400 for (v
= val_chain
; v
; v
= value_next (v
))
1402 /* If it's a memory location, and GDB actually needed
1403 its contents to evaluate the expression, then we
1404 must watch it. If the first value returned is
1405 still lazy, that means an error occurred reading it;
1406 watch it anyway in case it becomes readable. */
1407 if (VALUE_LVAL (v
) == lval_memory
1408 && (v
== val_chain
|| ! value_lazy (v
)))
1410 struct type
*vtype
= check_typedef (value_type (v
));
1412 /* We only watch structs and arrays if user asked
1413 for it explicitly, never if they just happen to
1414 appear in the middle of some value chain. */
1416 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1417 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1421 struct bp_location
*loc
, **tmp
;
1423 addr
= value_address (v
);
1424 len
= TYPE_LENGTH (value_type (v
));
1426 if (b
->base
.type
== bp_read_watchpoint
)
1428 else if (b
->base
.type
== bp_access_watchpoint
)
1431 loc
= allocate_bp_location (&b
->base
);
1432 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1435 loc
->gdbarch
= get_type_arch (value_type (v
));
1437 loc
->pspace
= frame_pspace
;
1438 loc
->address
= addr
;
1440 loc
->watchpoint_type
= type
;
1445 /* Change the type of breakpoint between hardware assisted or
1446 an ordinary watchpoint depending on the hardware support
1447 and free hardware slots. REPARSE is set when the inferior
1452 enum bp_loc_type loc_type
;
1453 struct bp_location
*bl
;
1455 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1459 int i
, target_resources_ok
, other_type_used
;
1461 /* Use an exact watchpoint when there's only one memory region to be
1462 watched, and only one debug register is needed to watch it. */
1463 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1465 /* We need to determine how many resources are already
1466 used for all other hardware watchpoints plus this one
1467 to see if we still have enough resources to also fit
1468 this watchpoint in as well. To guarantee the
1469 hw_watchpoint_used_count call below counts this
1470 watchpoint, make sure that it is marked as a hardware
1472 if (b
->base
.type
== bp_watchpoint
)
1473 b
->base
.type
= bp_hardware_watchpoint
;
1475 i
= hw_watchpoint_used_count (b
->base
.type
, &other_type_used
);
1476 target_resources_ok
= target_can_use_hardware_watchpoint
1477 (b
->base
.type
, i
, other_type_used
);
1478 if (target_resources_ok
<= 0)
1480 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1482 if (target_resources_ok
== 0 && !sw_mode
)
1483 error (_("Target does not support this type of "
1484 "hardware watchpoint."));
1485 else if (target_resources_ok
< 0 && !sw_mode
)
1486 error (_("There are not enough available hardware "
1487 "resources for this watchpoint."));
1489 b
->base
.type
= bp_watchpoint
;
1492 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1493 error (_("Expression cannot be implemented with "
1494 "read/access watchpoint."));
1496 b
->base
.type
= bp_watchpoint
;
1498 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1499 : bp_loc_hardware_watchpoint
);
1500 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1501 bl
->loc_type
= loc_type
;
1504 for (v
= val_chain
; v
; v
= next
)
1506 next
= value_next (v
);
1511 /* If a software watchpoint is not watching any memory, then the
1512 above left it without any location set up. But,
1513 bpstat_stop_status requires a location to be able to report
1514 stops, so make sure there's at least a dummy one. */
1515 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1517 struct breakpoint
*base
= &b
->base
;
1518 base
->loc
= allocate_bp_location (base
);
1519 base
->loc
->pspace
= frame_pspace
;
1520 base
->loc
->address
= -1;
1521 base
->loc
->length
= -1;
1522 base
->loc
->watchpoint_type
= -1;
1525 else if (!within_current_scope
)
1527 printf_filtered (_("\
1528 Watchpoint %d deleted because the program has left the block\n\
1529 in which its expression is valid.\n"),
1531 watchpoint_del_at_next_stop (b
);
1534 /* Restore the selected frame. */
1536 select_frame (frame_find_by_id (saved_frame_id
));
1540 /* Returns 1 iff breakpoint location should be
1541 inserted in the inferior. */
1543 should_be_inserted (struct bp_location
*bl
)
1545 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1548 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1551 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1554 /* This is set for example, when we're attached to the parent of a
1555 vfork, and have detached from the child. The child is running
1556 free, and we expect it to do an exec or exit, at which point the
1557 OS makes the parent schedulable again (and the target reports
1558 that the vfork is done). Until the child is done with the shared
1559 memory region, do not insert breakpoints in the parent, otherwise
1560 the child could still trip on the parent's breakpoints. Since
1561 the parent is blocked anyway, it won't miss any breakpoint. */
1562 if (bl
->pspace
->breakpoints_not_allowed
)
1565 /* Tracepoints are inserted by the target at a time of its choosing,
1567 if (is_tracepoint (bl
->owner
))
1573 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1574 location. Any error messages are printed to TMP_ERROR_STREAM; and
1575 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1577 NOTE drow/2003-09-09: This routine could be broken down to an
1578 object-style method for each breakpoint or catchpoint type. */
1580 insert_bp_location (struct bp_location
*bl
,
1581 struct ui_file
*tmp_error_stream
,
1582 int *disabled_breaks
,
1583 int *hw_breakpoint_error
)
1587 if (!should_be_inserted (bl
) || bl
->inserted
)
1590 /* Initialize the target-specific information. */
1591 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1592 bl
->target_info
.placed_address
= bl
->address
;
1593 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1594 bl
->target_info
.length
= bl
->length
;
1596 if (bl
->loc_type
== bp_loc_software_breakpoint
1597 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1599 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1601 /* If the explicitly specified breakpoint type
1602 is not hardware breakpoint, check the memory map to see
1603 if the breakpoint address is in read only memory or not.
1605 Two important cases are:
1606 - location type is not hardware breakpoint, memory
1607 is readonly. We change the type of the location to
1608 hardware breakpoint.
1609 - location type is hardware breakpoint, memory is
1610 read-write. This means we've previously made the
1611 location hardware one, but then the memory map changed,
1614 When breakpoints are removed, remove_breakpoints will use
1615 location types we've just set here, the only possible
1616 problem is that memory map has changed during running
1617 program, but it's not going to work anyway with current
1619 struct mem_region
*mr
1620 = lookup_mem_region (bl
->target_info
.placed_address
);
1624 if (automatic_hardware_breakpoints
)
1626 enum bp_loc_type new_type
;
1628 if (mr
->attrib
.mode
!= MEM_RW
)
1629 new_type
= bp_loc_hardware_breakpoint
;
1631 new_type
= bp_loc_software_breakpoint
;
1633 if (new_type
!= bl
->loc_type
)
1635 static int said
= 0;
1637 bl
->loc_type
= new_type
;
1640 fprintf_filtered (gdb_stdout
,
1641 _("Note: automatically using "
1642 "hardware breakpoints for "
1643 "read-only addresses.\n"));
1648 else if (bl
->loc_type
== bp_loc_software_breakpoint
1649 && mr
->attrib
.mode
!= MEM_RW
)
1650 warning (_("cannot set software breakpoint "
1651 "at readonly address %s"),
1652 paddress (bl
->gdbarch
, bl
->address
));
1656 /* First check to see if we have to handle an overlay. */
1657 if (overlay_debugging
== ovly_off
1658 || bl
->section
== NULL
1659 || !(section_is_overlay (bl
->section
)))
1661 /* No overlay handling: just set the breakpoint. */
1663 val
= bl
->owner
->ops
->insert_location (bl
);
1667 /* This breakpoint is in an overlay section.
1668 Shall we set a breakpoint at the LMA? */
1669 if (!overlay_events_enabled
)
1671 /* Yes -- overlay event support is not active,
1672 so we must try to set a breakpoint at the LMA.
1673 This will not work for a hardware breakpoint. */
1674 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1675 warning (_("hardware breakpoint %d not supported in overlay!"),
1679 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1681 /* Set a software (trap) breakpoint at the LMA. */
1682 bl
->overlay_target_info
= bl
->target_info
;
1683 bl
->overlay_target_info
.placed_address
= addr
;
1684 val
= target_insert_breakpoint (bl
->gdbarch
,
1685 &bl
->overlay_target_info
);
1687 fprintf_unfiltered (tmp_error_stream
,
1688 "Overlay breakpoint %d "
1689 "failed: in ROM?\n",
1693 /* Shall we set a breakpoint at the VMA? */
1694 if (section_is_mapped (bl
->section
))
1696 /* Yes. This overlay section is mapped into memory. */
1697 val
= bl
->owner
->ops
->insert_location (bl
);
1701 /* No. This breakpoint will not be inserted.
1702 No error, but do not mark the bp as 'inserted'. */
1709 /* Can't set the breakpoint. */
1710 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1712 /* See also: disable_breakpoints_in_shlibs. */
1714 bl
->shlib_disabled
= 1;
1715 observer_notify_breakpoint_modified (bl
->owner
);
1716 if (!*disabled_breaks
)
1718 fprintf_unfiltered (tmp_error_stream
,
1719 "Cannot insert breakpoint %d.\n",
1721 fprintf_unfiltered (tmp_error_stream
,
1722 "Temporarily disabling shared "
1723 "library breakpoints:\n");
1725 *disabled_breaks
= 1;
1726 fprintf_unfiltered (tmp_error_stream
,
1727 "breakpoint #%d\n", bl
->owner
->number
);
1731 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1733 *hw_breakpoint_error
= 1;
1734 fprintf_unfiltered (tmp_error_stream
,
1735 "Cannot insert hardware "
1741 fprintf_unfiltered (tmp_error_stream
,
1742 "Cannot insert breakpoint %d.\n",
1744 fprintf_filtered (tmp_error_stream
,
1745 "Error accessing memory address ");
1746 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1748 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1749 safe_strerror (val
));
1760 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1761 /* NOTE drow/2003-09-08: This state only exists for removing
1762 watchpoints. It's not clear that it's necessary... */
1763 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1765 gdb_assert (bl
->owner
->ops
!= NULL
1766 && bl
->owner
->ops
->insert_location
!= NULL
);
1768 val
= bl
->owner
->ops
->insert_location (bl
);
1770 /* If trying to set a read-watchpoint, and it turns out it's not
1771 supported, try emulating one with an access watchpoint. */
1772 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1774 struct bp_location
*loc
, **loc_temp
;
1776 /* But don't try to insert it, if there's already another
1777 hw_access location that would be considered a duplicate
1779 ALL_BP_LOCATIONS (loc
, loc_temp
)
1781 && loc
->watchpoint_type
== hw_access
1782 && watchpoint_locations_match (bl
, loc
))
1786 bl
->target_info
= loc
->target_info
;
1787 bl
->watchpoint_type
= hw_access
;
1794 bl
->watchpoint_type
= hw_access
;
1795 val
= bl
->owner
->ops
->insert_location (bl
);
1798 /* Back to the original value. */
1799 bl
->watchpoint_type
= hw_read
;
1803 bl
->inserted
= (val
== 0);
1806 else if (bl
->owner
->type
== bp_catchpoint
)
1808 gdb_assert (bl
->owner
->ops
!= NULL
1809 && bl
->owner
->ops
->insert_location
!= NULL
);
1811 val
= bl
->owner
->ops
->insert_location (bl
);
1814 bl
->owner
->enable_state
= bp_disabled
;
1818 Error inserting catchpoint %d: Your system does not support this type\n\
1819 of catchpoint."), bl
->owner
->number
);
1821 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1824 bl
->inserted
= (val
== 0);
1826 /* We've already printed an error message if there was a problem
1827 inserting this catchpoint, and we've disabled the catchpoint,
1828 so just return success. */
1835 /* This function is called when program space PSPACE is about to be
1836 deleted. It takes care of updating breakpoints to not reference
1840 breakpoint_program_space_exit (struct program_space
*pspace
)
1842 struct breakpoint
*b
, *b_temp
;
1843 struct bp_location
*loc
, **loc_temp
;
1845 /* Remove any breakpoint that was set through this program space. */
1846 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1848 if (b
->pspace
== pspace
)
1849 delete_breakpoint (b
);
1852 /* Breakpoints set through other program spaces could have locations
1853 bound to PSPACE as well. Remove those. */
1854 ALL_BP_LOCATIONS (loc
, loc_temp
)
1856 struct bp_location
*tmp
;
1858 if (loc
->pspace
== pspace
)
1860 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1861 if (loc
->owner
->loc
== loc
)
1862 loc
->owner
->loc
= loc
->next
;
1864 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1865 if (tmp
->next
== loc
)
1867 tmp
->next
= loc
->next
;
1873 /* Now update the global location list to permanently delete the
1874 removed locations above. */
1875 update_global_location_list (0);
1878 /* Make sure all breakpoints are inserted in inferior.
1879 Throws exception on any error.
1880 A breakpoint that is already inserted won't be inserted
1881 again, so calling this function twice is safe. */
1883 insert_breakpoints (void)
1885 struct breakpoint
*bpt
;
1887 ALL_BREAKPOINTS (bpt
)
1888 if (is_hardware_watchpoint (bpt
))
1890 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1892 update_watchpoint (w
, 0 /* don't reparse. */);
1895 update_global_location_list (1);
1897 /* update_global_location_list does not insert breakpoints when
1898 always_inserted_mode is not enabled. Explicitly insert them
1900 if (!breakpoints_always_inserted_mode ())
1901 insert_breakpoint_locations ();
1904 /* insert_breakpoints is used when starting or continuing the program.
1905 remove_breakpoints is used when the program stops.
1906 Both return zero if successful,
1907 or an `errno' value if could not write the inferior. */
1910 insert_breakpoint_locations (void)
1912 struct breakpoint
*bpt
;
1913 struct bp_location
*bl
, **blp_tmp
;
1916 int disabled_breaks
= 0;
1917 int hw_breakpoint_error
= 0;
1919 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1920 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1922 /* Explicitly mark the warning -- this will only be printed if
1923 there was an error. */
1924 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1926 save_current_space_and_thread ();
1928 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1930 if (!should_be_inserted (bl
) || bl
->inserted
)
1933 /* There is no point inserting thread-specific breakpoints if
1934 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1935 has BL->OWNER always non-NULL. */
1936 if (bl
->owner
->thread
!= -1
1937 && !valid_thread_id (bl
->owner
->thread
))
1940 switch_to_program_space_and_thread (bl
->pspace
);
1942 /* For targets that support global breakpoints, there's no need
1943 to select an inferior to insert breakpoint to. In fact, even
1944 if we aren't attached to any process yet, we should still
1945 insert breakpoints. */
1946 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1947 && ptid_equal (inferior_ptid
, null_ptid
))
1950 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1951 &hw_breakpoint_error
);
1956 /* If we failed to insert all locations of a watchpoint, remove
1957 them, as half-inserted watchpoint is of limited use. */
1958 ALL_BREAKPOINTS (bpt
)
1960 int some_failed
= 0;
1961 struct bp_location
*loc
;
1963 if (!is_hardware_watchpoint (bpt
))
1966 if (!breakpoint_enabled (bpt
))
1969 if (bpt
->disposition
== disp_del_at_next_stop
)
1972 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1973 if (!loc
->inserted
&& should_be_inserted (loc
))
1980 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1982 remove_breakpoint (loc
, mark_uninserted
);
1984 hw_breakpoint_error
= 1;
1985 fprintf_unfiltered (tmp_error_stream
,
1986 "Could not insert hardware watchpoint %d.\n",
1994 /* If a hardware breakpoint or watchpoint was inserted, add a
1995 message about possibly exhausted resources. */
1996 if (hw_breakpoint_error
)
1998 fprintf_unfiltered (tmp_error_stream
,
1999 "Could not insert hardware breakpoints:\n\
2000 You may have requested too many hardware breakpoints/watchpoints.\n");
2002 target_terminal_ours_for_output ();
2003 error_stream (tmp_error_stream
);
2006 do_cleanups (cleanups
);
2010 remove_breakpoints (void)
2012 struct bp_location
*bl
, **blp_tmp
;
2015 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2018 val
|= remove_breakpoint (bl
, mark_uninserted
);
2023 /* Remove breakpoints of process PID. */
2026 remove_breakpoints_pid (int pid
)
2028 struct bp_location
*bl
, **blp_tmp
;
2030 struct inferior
*inf
= find_inferior_pid (pid
);
2032 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2034 if (bl
->pspace
!= inf
->pspace
)
2039 val
= remove_breakpoint (bl
, mark_uninserted
);
2048 reattach_breakpoints (int pid
)
2050 struct cleanup
*old_chain
;
2051 struct bp_location
*bl
, **blp_tmp
;
2053 struct ui_file
*tmp_error_stream
;
2054 int dummy1
= 0, dummy2
= 0;
2055 struct inferior
*inf
;
2056 struct thread_info
*tp
;
2058 tp
= any_live_thread_of_process (pid
);
2062 inf
= find_inferior_pid (pid
);
2063 old_chain
= save_inferior_ptid ();
2065 inferior_ptid
= tp
->ptid
;
2067 tmp_error_stream
= mem_fileopen ();
2068 make_cleanup_ui_file_delete (tmp_error_stream
);
2070 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2072 if (bl
->pspace
!= inf
->pspace
)
2078 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2081 do_cleanups (old_chain
);
2086 do_cleanups (old_chain
);
2090 static int internal_breakpoint_number
= -1;
2092 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2093 If INTERNAL is non-zero, the breakpoint number will be populated
2094 from internal_breakpoint_number and that variable decremented.
2095 Otherwise the breakpoint number will be populated from
2096 breakpoint_count and that value incremented. Internal breakpoints
2097 do not set the internal var bpnum. */
2099 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2102 b
->number
= internal_breakpoint_number
--;
2105 set_breakpoint_count (breakpoint_count
+ 1);
2106 b
->number
= breakpoint_count
;
2110 static struct breakpoint
*
2111 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2112 CORE_ADDR address
, enum bptype type
,
2113 struct breakpoint_ops
*ops
)
2115 struct symtab_and_line sal
;
2116 struct breakpoint
*b
;
2118 init_sal (&sal
); /* Initialize to zeroes. */
2121 sal
.section
= find_pc_overlay (sal
.pc
);
2122 sal
.pspace
= current_program_space
;
2124 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2125 b
->number
= internal_breakpoint_number
--;
2126 b
->disposition
= disp_donttouch
;
2131 static const char *const longjmp_names
[] =
2133 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2135 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2137 /* Per-objfile data private to breakpoint.c. */
2138 struct breakpoint_objfile_data
2140 /* Minimal symbol for "_ovly_debug_event" (if any). */
2141 struct minimal_symbol
*overlay_msym
;
2143 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2144 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2146 /* Minimal symbol for "std::terminate()" (if any). */
2147 struct minimal_symbol
*terminate_msym
;
2149 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2150 struct minimal_symbol
*exception_msym
;
2153 static const struct objfile_data
*breakpoint_objfile_key
;
2155 /* Minimal symbol not found sentinel. */
2156 static struct minimal_symbol msym_not_found
;
2158 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2161 msym_not_found_p (const struct minimal_symbol
*msym
)
2163 return msym
== &msym_not_found
;
2166 /* Return per-objfile data needed by breakpoint.c.
2167 Allocate the data if necessary. */
2169 static struct breakpoint_objfile_data
*
2170 get_breakpoint_objfile_data (struct objfile
*objfile
)
2172 struct breakpoint_objfile_data
*bp_objfile_data
;
2174 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2175 if (bp_objfile_data
== NULL
)
2177 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2178 sizeof (*bp_objfile_data
));
2180 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2181 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2183 return bp_objfile_data
;
2187 create_overlay_event_breakpoint (void)
2189 struct objfile
*objfile
;
2190 const char *const func_name
= "_ovly_debug_event";
2192 ALL_OBJFILES (objfile
)
2194 struct breakpoint
*b
;
2195 struct breakpoint_objfile_data
*bp_objfile_data
;
2198 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2200 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2203 if (bp_objfile_data
->overlay_msym
== NULL
)
2205 struct minimal_symbol
*m
;
2207 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2210 /* Avoid future lookups in this objfile. */
2211 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2214 bp_objfile_data
->overlay_msym
= m
;
2217 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2218 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2220 &internal_breakpoint_ops
);
2221 b
->addr_string
= xstrdup (func_name
);
2223 if (overlay_debugging
== ovly_auto
)
2225 b
->enable_state
= bp_enabled
;
2226 overlay_events_enabled
= 1;
2230 b
->enable_state
= bp_disabled
;
2231 overlay_events_enabled
= 0;
2234 update_global_location_list (1);
2238 create_longjmp_master_breakpoint (void)
2240 struct program_space
*pspace
;
2241 struct cleanup
*old_chain
;
2243 old_chain
= save_current_program_space ();
2245 ALL_PSPACES (pspace
)
2247 struct objfile
*objfile
;
2249 set_current_program_space (pspace
);
2251 ALL_OBJFILES (objfile
)
2254 struct gdbarch
*gdbarch
;
2255 struct breakpoint_objfile_data
*bp_objfile_data
;
2257 gdbarch
= get_objfile_arch (objfile
);
2258 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2261 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2263 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2265 struct breakpoint
*b
;
2266 const char *func_name
;
2269 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2272 func_name
= longjmp_names
[i
];
2273 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2275 struct minimal_symbol
*m
;
2277 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2280 /* Prevent future lookups in this objfile. */
2281 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2284 bp_objfile_data
->longjmp_msym
[i
] = m
;
2287 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2288 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2289 &internal_breakpoint_ops
);
2290 b
->addr_string
= xstrdup (func_name
);
2291 b
->enable_state
= bp_disabled
;
2295 update_global_location_list (1);
2297 do_cleanups (old_chain
);
2300 /* Create a master std::terminate breakpoint. */
2302 create_std_terminate_master_breakpoint (void)
2304 struct program_space
*pspace
;
2305 struct cleanup
*old_chain
;
2306 const char *const func_name
= "std::terminate()";
2308 old_chain
= save_current_program_space ();
2310 ALL_PSPACES (pspace
)
2312 struct objfile
*objfile
;
2315 set_current_program_space (pspace
);
2317 ALL_OBJFILES (objfile
)
2319 struct breakpoint
*b
;
2320 struct breakpoint_objfile_data
*bp_objfile_data
;
2322 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2324 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2327 if (bp_objfile_data
->terminate_msym
== NULL
)
2329 struct minimal_symbol
*m
;
2331 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2332 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2333 && MSYMBOL_TYPE (m
) != mst_file_text
))
2335 /* Prevent future lookups in this objfile. */
2336 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2339 bp_objfile_data
->terminate_msym
= m
;
2342 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2343 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2344 bp_std_terminate_master
,
2345 &internal_breakpoint_ops
);
2346 b
->addr_string
= xstrdup (func_name
);
2347 b
->enable_state
= bp_disabled
;
2351 update_global_location_list (1);
2353 do_cleanups (old_chain
);
2356 /* Install a master breakpoint on the unwinder's debug hook. */
2359 create_exception_master_breakpoint (void)
2361 struct objfile
*objfile
;
2362 const char *const func_name
= "_Unwind_DebugHook";
2364 ALL_OBJFILES (objfile
)
2366 struct breakpoint
*b
;
2367 struct gdbarch
*gdbarch
;
2368 struct breakpoint_objfile_data
*bp_objfile_data
;
2371 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2373 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2376 gdbarch
= get_objfile_arch (objfile
);
2378 if (bp_objfile_data
->exception_msym
== NULL
)
2380 struct minimal_symbol
*debug_hook
;
2382 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2383 if (debug_hook
== NULL
)
2385 bp_objfile_data
->exception_msym
= &msym_not_found
;
2389 bp_objfile_data
->exception_msym
= debug_hook
;
2392 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2393 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2395 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2396 &internal_breakpoint_ops
);
2397 b
->addr_string
= xstrdup (func_name
);
2398 b
->enable_state
= bp_disabled
;
2401 update_global_location_list (1);
2405 update_breakpoints_after_exec (void)
2407 struct breakpoint
*b
, *b_tmp
;
2408 struct bp_location
*bploc
, **bplocp_tmp
;
2410 /* We're about to delete breakpoints from GDB's lists. If the
2411 INSERTED flag is true, GDB will try to lift the breakpoints by
2412 writing the breakpoints' "shadow contents" back into memory. The
2413 "shadow contents" are NOT valid after an exec, so GDB should not
2414 do that. Instead, the target is responsible from marking
2415 breakpoints out as soon as it detects an exec. We don't do that
2416 here instead, because there may be other attempts to delete
2417 breakpoints after detecting an exec and before reaching here. */
2418 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2419 if (bploc
->pspace
== current_program_space
)
2420 gdb_assert (!bploc
->inserted
);
2422 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2424 if (b
->pspace
!= current_program_space
)
2427 /* Solib breakpoints must be explicitly reset after an exec(). */
2428 if (b
->type
== bp_shlib_event
)
2430 delete_breakpoint (b
);
2434 /* JIT breakpoints must be explicitly reset after an exec(). */
2435 if (b
->type
== bp_jit_event
)
2437 delete_breakpoint (b
);
2441 /* Thread event breakpoints must be set anew after an exec(),
2442 as must overlay event and longjmp master breakpoints. */
2443 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2444 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2445 || b
->type
== bp_exception_master
)
2447 delete_breakpoint (b
);
2451 /* Step-resume breakpoints are meaningless after an exec(). */
2452 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2454 delete_breakpoint (b
);
2458 /* Longjmp and longjmp-resume breakpoints are also meaningless
2460 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2461 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2463 delete_breakpoint (b
);
2467 if (b
->type
== bp_catchpoint
)
2469 /* For now, none of the bp_catchpoint breakpoints need to
2470 do anything at this point. In the future, if some of
2471 the catchpoints need to something, we will need to add
2472 a new method, and call this method from here. */
2476 /* bp_finish is a special case. The only way we ought to be able
2477 to see one of these when an exec() has happened, is if the user
2478 caught a vfork, and then said "finish". Ordinarily a finish just
2479 carries them to the call-site of the current callee, by setting
2480 a temporary bp there and resuming. But in this case, the finish
2481 will carry them entirely through the vfork & exec.
2483 We don't want to allow a bp_finish to remain inserted now. But
2484 we can't safely delete it, 'cause finish_command has a handle to
2485 the bp on a bpstat, and will later want to delete it. There's a
2486 chance (and I've seen it happen) that if we delete the bp_finish
2487 here, that its storage will get reused by the time finish_command
2488 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2489 We really must allow finish_command to delete a bp_finish.
2491 In the absence of a general solution for the "how do we know
2492 it's safe to delete something others may have handles to?"
2493 problem, what we'll do here is just uninsert the bp_finish, and
2494 let finish_command delete it.
2496 (We know the bp_finish is "doomed" in the sense that it's
2497 momentary, and will be deleted as soon as finish_command sees
2498 the inferior stopped. So it doesn't matter that the bp's
2499 address is probably bogus in the new a.out, unlike e.g., the
2500 solib breakpoints.) */
2502 if (b
->type
== bp_finish
)
2507 /* Without a symbolic address, we have little hope of the
2508 pre-exec() address meaning the same thing in the post-exec()
2510 if (b
->addr_string
== NULL
)
2512 delete_breakpoint (b
);
2516 /* FIXME what about longjmp breakpoints? Re-create them here? */
2517 create_overlay_event_breakpoint ();
2518 create_longjmp_master_breakpoint ();
2519 create_std_terminate_master_breakpoint ();
2520 create_exception_master_breakpoint ();
2524 detach_breakpoints (int pid
)
2526 struct bp_location
*bl
, **blp_tmp
;
2528 struct cleanup
*old_chain
= save_inferior_ptid ();
2529 struct inferior
*inf
= current_inferior ();
2531 if (pid
== PIDGET (inferior_ptid
))
2532 error (_("Cannot detach breakpoints of inferior_ptid"));
2534 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2535 inferior_ptid
= pid_to_ptid (pid
);
2536 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2538 if (bl
->pspace
!= inf
->pspace
)
2542 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2545 /* Detach single-step breakpoints as well. */
2546 detach_single_step_breakpoints ();
2548 do_cleanups (old_chain
);
2552 /* Remove the breakpoint location BL from the current address space.
2553 Note that this is used to detach breakpoints from a child fork.
2554 When we get here, the child isn't in the inferior list, and neither
2555 do we have objects to represent its address space --- we should
2556 *not* look at bl->pspace->aspace here. */
2559 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2563 /* BL is never in moribund_locations by our callers. */
2564 gdb_assert (bl
->owner
!= NULL
);
2566 if (bl
->owner
->enable_state
== bp_permanent
)
2567 /* Permanent breakpoints cannot be inserted or removed. */
2570 /* The type of none suggests that owner is actually deleted.
2571 This should not ever happen. */
2572 gdb_assert (bl
->owner
->type
!= bp_none
);
2574 if (bl
->loc_type
== bp_loc_software_breakpoint
2575 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2577 /* "Normal" instruction breakpoint: either the standard
2578 trap-instruction bp (bp_breakpoint), or a
2579 bp_hardware_breakpoint. */
2581 /* First check to see if we have to handle an overlay. */
2582 if (overlay_debugging
== ovly_off
2583 || bl
->section
== NULL
2584 || !(section_is_overlay (bl
->section
)))
2586 /* No overlay handling: just remove the breakpoint. */
2587 val
= bl
->owner
->ops
->remove_location (bl
);
2591 /* This breakpoint is in an overlay section.
2592 Did we set a breakpoint at the LMA? */
2593 if (!overlay_events_enabled
)
2595 /* Yes -- overlay event support is not active, so we
2596 should have set a breakpoint at the LMA. Remove it.
2598 /* Ignore any failures: if the LMA is in ROM, we will
2599 have already warned when we failed to insert it. */
2600 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2601 target_remove_hw_breakpoint (bl
->gdbarch
,
2602 &bl
->overlay_target_info
);
2604 target_remove_breakpoint (bl
->gdbarch
,
2605 &bl
->overlay_target_info
);
2607 /* Did we set a breakpoint at the VMA?
2608 If so, we will have marked the breakpoint 'inserted'. */
2611 /* Yes -- remove it. Previously we did not bother to
2612 remove the breakpoint if the section had been
2613 unmapped, but let's not rely on that being safe. We
2614 don't know what the overlay manager might do. */
2616 /* However, we should remove *software* breakpoints only
2617 if the section is still mapped, or else we overwrite
2618 wrong code with the saved shadow contents. */
2619 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2620 || section_is_mapped (bl
->section
))
2621 val
= bl
->owner
->ops
->remove_location (bl
);
2627 /* No -- not inserted, so no need to remove. No error. */
2632 /* In some cases, we might not be able to remove a breakpoint
2633 in a shared library that has already been removed, but we
2634 have not yet processed the shlib unload event. */
2635 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2640 bl
->inserted
= (is
== mark_inserted
);
2642 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2644 gdb_assert (bl
->owner
->ops
!= NULL
2645 && bl
->owner
->ops
->remove_location
!= NULL
);
2647 bl
->inserted
= (is
== mark_inserted
);
2648 bl
->owner
->ops
->remove_location (bl
);
2650 /* Failure to remove any of the hardware watchpoints comes here. */
2651 if ((is
== mark_uninserted
) && (bl
->inserted
))
2652 warning (_("Could not remove hardware watchpoint %d."),
2655 else if (bl
->owner
->type
== bp_catchpoint
2656 && breakpoint_enabled (bl
->owner
)
2659 gdb_assert (bl
->owner
->ops
!= NULL
2660 && bl
->owner
->ops
->remove_location
!= NULL
);
2662 val
= bl
->owner
->ops
->remove_location (bl
);
2666 bl
->inserted
= (is
== mark_inserted
);
2673 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2676 struct cleanup
*old_chain
;
2678 /* BL is never in moribund_locations by our callers. */
2679 gdb_assert (bl
->owner
!= NULL
);
2681 if (bl
->owner
->enable_state
== bp_permanent
)
2682 /* Permanent breakpoints cannot be inserted or removed. */
2685 /* The type of none suggests that owner is actually deleted.
2686 This should not ever happen. */
2687 gdb_assert (bl
->owner
->type
!= bp_none
);
2689 old_chain
= save_current_space_and_thread ();
2691 switch_to_program_space_and_thread (bl
->pspace
);
2693 ret
= remove_breakpoint_1 (bl
, is
);
2695 do_cleanups (old_chain
);
2699 /* Clear the "inserted" flag in all breakpoints. */
2702 mark_breakpoints_out (void)
2704 struct bp_location
*bl
, **blp_tmp
;
2706 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2707 if (bl
->pspace
== current_program_space
)
2711 /* Clear the "inserted" flag in all breakpoints and delete any
2712 breakpoints which should go away between runs of the program.
2714 Plus other such housekeeping that has to be done for breakpoints
2717 Note: this function gets called at the end of a run (by
2718 generic_mourn_inferior) and when a run begins (by
2719 init_wait_for_inferior). */
2724 breakpoint_init_inferior (enum inf_context context
)
2726 struct breakpoint
*b
, *b_tmp
;
2727 struct bp_location
*bl
, **blp_tmp
;
2729 struct program_space
*pspace
= current_program_space
;
2731 /* If breakpoint locations are shared across processes, then there's
2733 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2736 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2738 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2739 if (bl
->pspace
== pspace
2740 && bl
->owner
->enable_state
!= bp_permanent
)
2744 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2746 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2753 /* If the call dummy breakpoint is at the entry point it will
2754 cause problems when the inferior is rerun, so we better get
2757 case bp_watchpoint_scope
:
2759 /* Also get rid of scope breakpoints. */
2761 case bp_shlib_event
:
2763 /* Also remove solib event breakpoints. Their addresses may
2764 have changed since the last time we ran the program.
2765 Actually we may now be debugging against different target;
2766 and so the solib backend that installed this breakpoint may
2767 not be used in by the target. E.g.,
2769 (gdb) file prog-linux
2770 (gdb) run # native linux target
2773 (gdb) file prog-win.exe
2774 (gdb) tar rem :9999 # remote Windows gdbserver.
2777 delete_breakpoint (b
);
2781 case bp_hardware_watchpoint
:
2782 case bp_read_watchpoint
:
2783 case bp_access_watchpoint
:
2785 struct watchpoint
*w
= (struct watchpoint
*) b
;
2787 /* Likewise for watchpoints on local expressions. */
2788 if (w
->exp_valid_block
!= NULL
)
2789 delete_breakpoint (b
);
2790 else if (context
== inf_starting
)
2792 /* Reset val field to force reread of starting value in
2793 insert_breakpoints. */
2795 value_free (w
->val
);
2806 /* Get rid of the moribund locations. */
2807 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2808 decref_bp_location (&bl
);
2809 VEC_free (bp_location_p
, moribund_locations
);
2812 /* These functions concern about actual breakpoints inserted in the
2813 target --- to e.g. check if we need to do decr_pc adjustment or if
2814 we need to hop over the bkpt --- so we check for address space
2815 match, not program space. */
2817 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2818 exists at PC. It returns ordinary_breakpoint_here if it's an
2819 ordinary breakpoint, or permanent_breakpoint_here if it's a
2820 permanent breakpoint.
2821 - When continuing from a location with an ordinary breakpoint, we
2822 actually single step once before calling insert_breakpoints.
2823 - When continuing from a location with a permanent breakpoint, we
2824 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2825 the target, to advance the PC past the breakpoint. */
2827 enum breakpoint_here
2828 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2830 struct bp_location
*bl
, **blp_tmp
;
2831 int any_breakpoint_here
= 0;
2833 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2835 if (bl
->loc_type
!= bp_loc_software_breakpoint
2836 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2839 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2840 if ((breakpoint_enabled (bl
->owner
)
2841 || bl
->owner
->enable_state
== bp_permanent
)
2842 && breakpoint_location_address_match (bl
, aspace
, pc
))
2844 if (overlay_debugging
2845 && section_is_overlay (bl
->section
)
2846 && !section_is_mapped (bl
->section
))
2847 continue; /* unmapped overlay -- can't be a match */
2848 else if (bl
->owner
->enable_state
== bp_permanent
)
2849 return permanent_breakpoint_here
;
2851 any_breakpoint_here
= 1;
2855 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2858 /* Return true if there's a moribund breakpoint at PC. */
2861 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2863 struct bp_location
*loc
;
2866 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2867 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2873 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2874 inserted using regular breakpoint_chain / bp_location array
2875 mechanism. This does not check for single-step breakpoints, which
2876 are inserted and removed using direct target manipulation. */
2879 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2882 struct bp_location
*bl
, **blp_tmp
;
2884 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2886 if (bl
->loc_type
!= bp_loc_software_breakpoint
2887 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2891 && breakpoint_location_address_match (bl
, aspace
, pc
))
2893 if (overlay_debugging
2894 && section_is_overlay (bl
->section
)
2895 && !section_is_mapped (bl
->section
))
2896 continue; /* unmapped overlay -- can't be a match */
2904 /* Returns non-zero iff there's either regular breakpoint
2905 or a single step breakpoint inserted at PC. */
2908 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2910 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2913 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2919 /* This function returns non-zero iff there is a software breakpoint
2923 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2926 struct bp_location
*bl
, **blp_tmp
;
2928 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2930 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2934 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2937 if (overlay_debugging
2938 && section_is_overlay (bl
->section
)
2939 && !section_is_mapped (bl
->section
))
2940 continue; /* unmapped overlay -- can't be a match */
2946 /* Also check for software single-step breakpoints. */
2947 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2954 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2955 CORE_ADDR addr
, ULONGEST len
)
2957 struct breakpoint
*bpt
;
2959 ALL_BREAKPOINTS (bpt
)
2961 struct bp_location
*loc
;
2963 if (bpt
->type
!= bp_hardware_watchpoint
2964 && bpt
->type
!= bp_access_watchpoint
)
2967 if (!breakpoint_enabled (bpt
))
2970 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2971 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2975 /* Check for intersection. */
2976 l
= max (loc
->address
, addr
);
2977 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2985 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2986 PC is valid for process/thread PTID. */
2989 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2992 struct bp_location
*bl
, **blp_tmp
;
2993 /* The thread and task IDs associated to PTID, computed lazily. */
2997 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2999 if (bl
->loc_type
!= bp_loc_software_breakpoint
3000 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3003 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3004 if (!breakpoint_enabled (bl
->owner
)
3005 && bl
->owner
->enable_state
!= bp_permanent
)
3008 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3011 if (bl
->owner
->thread
!= -1)
3013 /* This is a thread-specific breakpoint. Check that ptid
3014 matches that thread. If thread hasn't been computed yet,
3015 it is now time to do so. */
3017 thread
= pid_to_thread_id (ptid
);
3018 if (bl
->owner
->thread
!= thread
)
3022 if (bl
->owner
->task
!= 0)
3024 /* This is a task-specific breakpoint. Check that ptid
3025 matches that task. If task hasn't been computed yet,
3026 it is now time to do so. */
3028 task
= ada_get_task_number (ptid
);
3029 if (bl
->owner
->task
!= task
)
3033 if (overlay_debugging
3034 && section_is_overlay (bl
->section
)
3035 && !section_is_mapped (bl
->section
))
3036 continue; /* unmapped overlay -- can't be a match */
3045 /* bpstat stuff. External routines' interfaces are documented
3049 ep_is_catchpoint (struct breakpoint
*ep
)
3051 return (ep
->type
== bp_catchpoint
);
3054 /* Frees any storage that is part of a bpstat. Does not walk the
3058 bpstat_free (bpstat bs
)
3060 if (bs
->old_val
!= NULL
)
3061 value_free (bs
->old_val
);
3062 decref_counted_command_line (&bs
->commands
);
3063 decref_bp_location (&bs
->bp_location_at
);
3067 /* Clear a bpstat so that it says we are not at any breakpoint.
3068 Also free any storage that is part of a bpstat. */
3071 bpstat_clear (bpstat
*bsp
)
3088 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3089 is part of the bpstat is copied as well. */
3092 bpstat_copy (bpstat bs
)
3096 bpstat retval
= NULL
;
3101 for (; bs
!= NULL
; bs
= bs
->next
)
3103 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3104 memcpy (tmp
, bs
, sizeof (*tmp
));
3105 incref_counted_command_line (tmp
->commands
);
3106 incref_bp_location (tmp
->bp_location_at
);
3107 if (bs
->old_val
!= NULL
)
3109 tmp
->old_val
= value_copy (bs
->old_val
);
3110 release_value (tmp
->old_val
);
3114 /* This is the first thing in the chain. */
3124 /* Find the bpstat associated with this breakpoint. */
3127 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3132 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3134 if (bsp
->breakpoint_at
== breakpoint
)
3140 /* Put in *NUM the breakpoint number of the first breakpoint we are
3141 stopped at. *BSP upon return is a bpstat which points to the
3142 remaining breakpoints stopped at (but which is not guaranteed to be
3143 good for anything but further calls to bpstat_num).
3145 Return 0 if passed a bpstat which does not indicate any breakpoints.
3146 Return -1 if stopped at a breakpoint that has been deleted since
3148 Return 1 otherwise. */
3151 bpstat_num (bpstat
*bsp
, int *num
)
3153 struct breakpoint
*b
;
3156 return 0; /* No more breakpoint values */
3158 /* We assume we'll never have several bpstats that correspond to a
3159 single breakpoint -- otherwise, this function might return the
3160 same number more than once and this will look ugly. */
3161 b
= (*bsp
)->breakpoint_at
;
3162 *bsp
= (*bsp
)->next
;
3164 return -1; /* breakpoint that's been deleted since */
3166 *num
= b
->number
; /* We have its number */
3170 /* Modify BS so that the actions will not be performed. */
3173 bpstat_clear_actions (bpstat bs
)
3175 for (; bs
!= NULL
; bs
= bs
->next
)
3177 decref_counted_command_line (&bs
->commands
);
3178 bs
->commands_left
= NULL
;
3179 if (bs
->old_val
!= NULL
)
3181 value_free (bs
->old_val
);
3187 /* Called when a command is about to proceed the inferior. */
3190 breakpoint_about_to_proceed (void)
3192 if (!ptid_equal (inferior_ptid
, null_ptid
))
3194 struct thread_info
*tp
= inferior_thread ();
3196 /* Allow inferior function calls in breakpoint commands to not
3197 interrupt the command list. When the call finishes
3198 successfully, the inferior will be standing at the same
3199 breakpoint as if nothing happened. */
3200 if (tp
->control
.in_infcall
)
3204 breakpoint_proceeded
= 1;
3207 /* Stub for cleaning up our state if we error-out of a breakpoint
3210 cleanup_executing_breakpoints (void *ignore
)
3212 executing_breakpoint_commands
= 0;
3215 /* Execute all the commands associated with all the breakpoints at
3216 this location. Any of these commands could cause the process to
3217 proceed beyond this point, etc. We look out for such changes by
3218 checking the global "breakpoint_proceeded" after each command.
3220 Returns true if a breakpoint command resumed the inferior. In that
3221 case, it is the caller's responsibility to recall it again with the
3222 bpstat of the current thread. */
3225 bpstat_do_actions_1 (bpstat
*bsp
)
3228 struct cleanup
*old_chain
;
3231 /* Avoid endless recursion if a `source' command is contained
3233 if (executing_breakpoint_commands
)
3236 executing_breakpoint_commands
= 1;
3237 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3239 prevent_dont_repeat ();
3241 /* This pointer will iterate over the list of bpstat's. */
3244 breakpoint_proceeded
= 0;
3245 for (; bs
!= NULL
; bs
= bs
->next
)
3247 struct counted_command_line
*ccmd
;
3248 struct command_line
*cmd
;
3249 struct cleanup
*this_cmd_tree_chain
;
3251 /* Take ownership of the BSP's command tree, if it has one.
3253 The command tree could legitimately contain commands like
3254 'step' and 'next', which call clear_proceed_status, which
3255 frees stop_bpstat's command tree. To make sure this doesn't
3256 free the tree we're executing out from under us, we need to
3257 take ownership of the tree ourselves. Since a given bpstat's
3258 commands are only executed once, we don't need to copy it; we
3259 can clear the pointer in the bpstat, and make sure we free
3260 the tree when we're done. */
3261 ccmd
= bs
->commands
;
3262 bs
->commands
= NULL
;
3264 = make_cleanup_decref_counted_command_line (&ccmd
);
3265 cmd
= bs
->commands_left
;
3266 bs
->commands_left
= NULL
;
3270 execute_control_command (cmd
);
3272 if (breakpoint_proceeded
)
3278 /* We can free this command tree now. */
3279 do_cleanups (this_cmd_tree_chain
);
3281 if (breakpoint_proceeded
)
3283 if (target_can_async_p ())
3284 /* If we are in async mode, then the target might be still
3285 running, not stopped at any breakpoint, so nothing for
3286 us to do here -- just return to the event loop. */
3289 /* In sync mode, when execute_control_command returns
3290 we're already standing on the next breakpoint.
3291 Breakpoint commands for that stop were not run, since
3292 execute_command does not run breakpoint commands --
3293 only command_line_handler does, but that one is not
3294 involved in execution of breakpoint commands. So, we
3295 can now execute breakpoint commands. It should be
3296 noted that making execute_command do bpstat actions is
3297 not an option -- in this case we'll have recursive
3298 invocation of bpstat for each breakpoint with a
3299 command, and can easily blow up GDB stack. Instead, we
3300 return true, which will trigger the caller to recall us
3301 with the new stop_bpstat. */
3306 do_cleanups (old_chain
);
3311 bpstat_do_actions (void)
3313 /* Do any commands attached to breakpoint we are stopped at. */
3314 while (!ptid_equal (inferior_ptid
, null_ptid
)
3315 && target_has_execution
3316 && !is_exited (inferior_ptid
)
3317 && !is_executing (inferior_ptid
))
3318 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3319 and only return when it is stopped at the next breakpoint, we
3320 keep doing breakpoint actions until it returns false to
3321 indicate the inferior was not resumed. */
3322 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3326 /* Print out the (old or new) value associated with a watchpoint. */
3329 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3332 fprintf_unfiltered (stream
, _("<unreadable>"));
3335 struct value_print_options opts
;
3336 get_user_print_options (&opts
);
3337 value_print (val
, stream
, &opts
);
3341 /* Generic routine for printing messages indicating why we
3342 stopped. The behavior of this function depends on the value
3343 'print_it' in the bpstat structure. Under some circumstances we
3344 may decide not to print anything here and delegate the task to
3347 static enum print_stop_action
3348 print_bp_stop_message (bpstat bs
)
3350 switch (bs
->print_it
)
3353 /* Nothing should be printed for this bpstat entry. */
3354 return PRINT_UNKNOWN
;
3358 /* We still want to print the frame, but we already printed the
3359 relevant messages. */
3360 return PRINT_SRC_AND_LOC
;
3363 case print_it_normal
:
3365 struct breakpoint
*b
= bs
->breakpoint_at
;
3367 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3368 which has since been deleted. */
3370 return PRINT_UNKNOWN
;
3372 /* Normal case. Call the breakpoint's print_it method. */
3373 return b
->ops
->print_it (bs
);
3378 internal_error (__FILE__
, __LINE__
,
3379 _("print_bp_stop_message: unrecognized enum value"));
3384 /* Print a message indicating what happened. This is called from
3385 normal_stop(). The input to this routine is the head of the bpstat
3386 list - a list of the eventpoints that caused this stop. This
3387 routine calls the generic print routine for printing a message
3388 about reasons for stopping. This will print (for example) the
3389 "Breakpoint n," part of the output. The return value of this
3392 PRINT_UNKNOWN: Means we printed nothing.
3393 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3394 code to print the location. An example is
3395 "Breakpoint 1, " which should be followed by
3397 PRINT_SRC_ONLY: Means we printed something, but there is no need
3398 to also print the location part of the message.
3399 An example is the catch/throw messages, which
3400 don't require a location appended to the end.
3401 PRINT_NOTHING: We have done some printing and we don't need any
3402 further info to be printed. */
3404 enum print_stop_action
3405 bpstat_print (bpstat bs
)
3409 /* Maybe another breakpoint in the chain caused us to stop.
3410 (Currently all watchpoints go on the bpstat whether hit or not.
3411 That probably could (should) be changed, provided care is taken
3412 with respect to bpstat_explains_signal). */
3413 for (; bs
; bs
= bs
->next
)
3415 val
= print_bp_stop_message (bs
);
3416 if (val
== PRINT_SRC_ONLY
3417 || val
== PRINT_SRC_AND_LOC
3418 || val
== PRINT_NOTHING
)
3422 /* We reached the end of the chain, or we got a null BS to start
3423 with and nothing was printed. */
3424 return PRINT_UNKNOWN
;
3427 /* Evaluate the expression EXP and return 1 if value is zero. This is
3428 used inside a catch_errors to evaluate the breakpoint condition.
3429 The argument is a "struct expression *" that has been cast to a
3430 "char *" to make it pass through catch_errors. */
3433 breakpoint_cond_eval (void *exp
)
3435 struct value
*mark
= value_mark ();
3436 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3438 value_free_to_mark (mark
);
3442 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3445 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3449 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3451 **bs_link_pointer
= bs
;
3452 *bs_link_pointer
= &bs
->next
;
3453 bs
->breakpoint_at
= bl
->owner
;
3454 bs
->bp_location_at
= bl
;
3455 incref_bp_location (bl
);
3456 /* If the condition is false, etc., don't do the commands. */
3457 bs
->commands
= NULL
;
3458 bs
->commands_left
= NULL
;
3460 bs
->print_it
= print_it_normal
;
3464 /* The target has stopped with waitstatus WS. Check if any hardware
3465 watchpoints have triggered, according to the target. */
3468 watchpoints_triggered (struct target_waitstatus
*ws
)
3470 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3472 struct breakpoint
*b
;
3474 if (!stopped_by_watchpoint
)
3476 /* We were not stopped by a watchpoint. Mark all watchpoints
3477 as not triggered. */
3479 if (is_hardware_watchpoint (b
))
3481 struct watchpoint
*w
= (struct watchpoint
*) b
;
3483 w
->watchpoint_triggered
= watch_triggered_no
;
3489 if (!target_stopped_data_address (¤t_target
, &addr
))
3491 /* We were stopped by a watchpoint, but we don't know where.
3492 Mark all watchpoints as unknown. */
3494 if (is_hardware_watchpoint (b
))
3496 struct watchpoint
*w
= (struct watchpoint
*) b
;
3498 w
->watchpoint_triggered
= watch_triggered_unknown
;
3501 return stopped_by_watchpoint
;
3504 /* The target could report the data address. Mark watchpoints
3505 affected by this data address as triggered, and all others as not
3509 if (is_hardware_watchpoint (b
))
3511 struct watchpoint
*w
= (struct watchpoint
*) b
;
3512 struct bp_location
*loc
;
3514 w
->watchpoint_triggered
= watch_triggered_no
;
3515 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3517 if (is_masked_watchpoint (b
))
3519 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3520 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3522 if (newaddr
== start
)
3524 w
->watchpoint_triggered
= watch_triggered_yes
;
3528 /* Exact match not required. Within range is sufficient. */
3529 else if (target_watchpoint_addr_within_range (¤t_target
,
3533 w
->watchpoint_triggered
= watch_triggered_yes
;
3542 /* Possible return values for watchpoint_check (this can't be an enum
3543 because of check_errors). */
3544 /* The watchpoint has been deleted. */
3545 #define WP_DELETED 1
3546 /* The value has changed. */
3547 #define WP_VALUE_CHANGED 2
3548 /* The value has not changed. */
3549 #define WP_VALUE_NOT_CHANGED 3
3550 /* Ignore this watchpoint, no matter if the value changed or not. */
3553 #define BP_TEMPFLAG 1
3554 #define BP_HARDWAREFLAG 2
3556 /* Evaluate watchpoint condition expression and check if its value
3559 P should be a pointer to struct bpstat, but is defined as a void *
3560 in order for this function to be usable with catch_errors. */
3563 watchpoint_check (void *p
)
3565 bpstat bs
= (bpstat
) p
;
3566 struct watchpoint
*b
;
3567 struct frame_info
*fr
;
3568 int within_current_scope
;
3570 /* BS is built from an existing struct breakpoint. */
3571 gdb_assert (bs
->breakpoint_at
!= NULL
);
3572 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3574 /* If this is a local watchpoint, we only want to check if the
3575 watchpoint frame is in scope if the current thread is the thread
3576 that was used to create the watchpoint. */
3577 if (!watchpoint_in_thread_scope (b
))
3580 if (b
->exp_valid_block
== NULL
)
3581 within_current_scope
= 1;
3584 struct frame_info
*frame
= get_current_frame ();
3585 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3586 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3588 /* in_function_epilogue_p() returns a non-zero value if we're
3589 still in the function but the stack frame has already been
3590 invalidated. Since we can't rely on the values of local
3591 variables after the stack has been destroyed, we are treating
3592 the watchpoint in that state as `not changed' without further
3593 checking. Don't mark watchpoints as changed if the current
3594 frame is in an epilogue - even if they are in some other
3595 frame, our view of the stack is likely to be wrong and
3596 frame_find_by_id could error out. */
3597 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3600 fr
= frame_find_by_id (b
->watchpoint_frame
);
3601 within_current_scope
= (fr
!= NULL
);
3603 /* If we've gotten confused in the unwinder, we might have
3604 returned a frame that can't describe this variable. */
3605 if (within_current_scope
)
3607 struct symbol
*function
;
3609 function
= get_frame_function (fr
);
3610 if (function
== NULL
3611 || !contained_in (b
->exp_valid_block
,
3612 SYMBOL_BLOCK_VALUE (function
)))
3613 within_current_scope
= 0;
3616 if (within_current_scope
)
3617 /* If we end up stopping, the current frame will get selected
3618 in normal_stop. So this call to select_frame won't affect
3623 if (within_current_scope
)
3625 /* We use value_{,free_to_}mark because it could be a *long*
3626 time before we return to the command level and call
3627 free_all_values. We can't call free_all_values because we
3628 might be in the middle of evaluating a function call. */
3632 struct value
*new_val
;
3634 if (is_masked_watchpoint (&b
->base
))
3635 /* Since we don't know the exact trigger address (from
3636 stopped_data_address), just tell the user we've triggered
3637 a mask watchpoint. */
3638 return WP_VALUE_CHANGED
;
3640 mark
= value_mark ();
3641 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3643 /* We use value_equal_contents instead of value_equal because
3644 the latter coerces an array to a pointer, thus comparing just
3645 the address of the array instead of its contents. This is
3646 not what we want. */
3647 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3648 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3650 if (new_val
!= NULL
)
3652 release_value (new_val
);
3653 value_free_to_mark (mark
);
3655 bs
->old_val
= b
->val
;
3658 return WP_VALUE_CHANGED
;
3662 /* Nothing changed. */
3663 value_free_to_mark (mark
);
3664 return WP_VALUE_NOT_CHANGED
;
3669 /* This seems like the only logical thing to do because
3670 if we temporarily ignored the watchpoint, then when
3671 we reenter the block in which it is valid it contains
3672 garbage (in the case of a function, it may have two
3673 garbage values, one before and one after the prologue).
3674 So we can't even detect the first assignment to it and
3675 watch after that (since the garbage may or may not equal
3676 the first value assigned). */
3677 /* We print all the stop information in
3678 breakpoint_ops->print_it, but in this case, by the time we
3679 call breakpoint_ops->print_it this bp will be deleted
3680 already. So we have no choice but print the information
3682 if (ui_out_is_mi_like_p (uiout
))
3684 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3685 ui_out_text (uiout
, "\nWatchpoint ");
3686 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3688 " deleted because the program has left the block in\n\
3689 which its expression is valid.\n");
3691 /* Make sure the watchpoint's commands aren't executed. */
3692 decref_counted_command_line (&b
->base
.commands
);
3693 watchpoint_del_at_next_stop (b
);
3699 /* Return true if it looks like target has stopped due to hitting
3700 breakpoint location BL. This function does not check if we should
3701 stop, only if BL explains the stop. */
3704 bpstat_check_location (const struct bp_location
*bl
,
3705 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3707 struct breakpoint
*b
= bl
->owner
;
3709 /* BL is from an existing breakpoint. */
3710 gdb_assert (b
!= NULL
);
3712 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3715 /* Determine if the watched values have actually changed, and we
3716 should stop. If not, set BS->stop to 0. */
3719 bpstat_check_watchpoint (bpstat bs
)
3721 const struct bp_location
*bl
;
3722 struct watchpoint
*b
;
3724 /* BS is built for existing struct breakpoint. */
3725 bl
= bs
->bp_location_at
;
3726 gdb_assert (bl
!= NULL
);
3727 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3728 gdb_assert (b
!= NULL
);
3731 int must_check_value
= 0;
3733 if (b
->base
.type
== bp_watchpoint
)
3734 /* For a software watchpoint, we must always check the
3736 must_check_value
= 1;
3737 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3738 /* We have a hardware watchpoint (read, write, or access)
3739 and the target earlier reported an address watched by
3741 must_check_value
= 1;
3742 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3743 && b
->base
.type
== bp_hardware_watchpoint
)
3744 /* We were stopped by a hardware watchpoint, but the target could
3745 not report the data address. We must check the watchpoint's
3746 value. Access and read watchpoints are out of luck; without
3747 a data address, we can't figure it out. */
3748 must_check_value
= 1;
3750 if (must_check_value
)
3753 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3755 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3756 int e
= catch_errors (watchpoint_check
, bs
, message
,
3758 do_cleanups (cleanups
);
3762 /* We've already printed what needs to be printed. */
3763 bs
->print_it
= print_it_done
;
3767 bs
->print_it
= print_it_noop
;
3770 case WP_VALUE_CHANGED
:
3771 if (b
->base
.type
== bp_read_watchpoint
)
3773 /* There are two cases to consider here:
3775 1. We're watching the triggered memory for reads.
3776 In that case, trust the target, and always report
3777 the watchpoint hit to the user. Even though
3778 reads don't cause value changes, the value may
3779 have changed since the last time it was read, and
3780 since we're not trapping writes, we will not see
3781 those, and as such we should ignore our notion of
3784 2. We're watching the triggered memory for both
3785 reads and writes. There are two ways this may
3788 2.1. This is a target that can't break on data
3789 reads only, but can break on accesses (reads or
3790 writes), such as e.g., x86. We detect this case
3791 at the time we try to insert read watchpoints.
3793 2.2. Otherwise, the target supports read
3794 watchpoints, but, the user set an access or write
3795 watchpoint watching the same memory as this read
3798 If we're watching memory writes as well as reads,
3799 ignore watchpoint hits when we find that the
3800 value hasn't changed, as reads don't cause
3801 changes. This still gives false positives when
3802 the program writes the same value to memory as
3803 what there was already in memory (we will confuse
3804 it for a read), but it's much better than
3807 int other_write_watchpoint
= 0;
3809 if (bl
->watchpoint_type
== hw_read
)
3811 struct breakpoint
*other_b
;
3813 ALL_BREAKPOINTS (other_b
)
3814 if (other_b
->type
== bp_hardware_watchpoint
3815 || other_b
->type
== bp_access_watchpoint
)
3817 struct watchpoint
*other_w
=
3818 (struct watchpoint
*) other_b
;
3820 if (other_w
->watchpoint_triggered
3821 == watch_triggered_yes
)
3823 other_write_watchpoint
= 1;
3829 if (other_write_watchpoint
3830 || bl
->watchpoint_type
== hw_access
)
3832 /* We're watching the same memory for writes,
3833 and the value changed since the last time we
3834 updated it, so this trap must be for a write.
3836 bs
->print_it
= print_it_noop
;
3841 case WP_VALUE_NOT_CHANGED
:
3842 if (b
->base
.type
== bp_hardware_watchpoint
3843 || b
->base
.type
== bp_watchpoint
)
3845 /* Don't stop: write watchpoints shouldn't fire if
3846 the value hasn't changed. */
3847 bs
->print_it
= print_it_noop
;
3855 /* Error from catch_errors. */
3856 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3857 watchpoint_del_at_next_stop (b
);
3858 /* We've already printed what needs to be printed. */
3859 bs
->print_it
= print_it_done
;
3863 else /* must_check_value == 0 */
3865 /* This is a case where some watchpoint(s) triggered, but
3866 not at the address of this watchpoint, or else no
3867 watchpoint triggered after all. So don't print
3868 anything for this watchpoint. */
3869 bs
->print_it
= print_it_noop
;
3876 /* Check conditions (condition proper, frame, thread and ignore count)
3877 of breakpoint referred to by BS. If we should not stop for this
3878 breakpoint, set BS->stop to 0. */
3881 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3883 int thread_id
= pid_to_thread_id (ptid
);
3884 const struct bp_location
*bl
;
3885 struct breakpoint
*b
;
3887 /* BS is built for existing struct breakpoint. */
3888 bl
= bs
->bp_location_at
;
3889 gdb_assert (bl
!= NULL
);
3890 b
= bs
->breakpoint_at
;
3891 gdb_assert (b
!= NULL
);
3893 if (frame_id_p (b
->frame_id
)
3894 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3898 int value_is_zero
= 0;
3899 struct expression
*cond
;
3901 /* Evaluate Python breakpoints that have a "stop"
3902 method implemented. */
3903 if (b
->py_bp_object
)
3904 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
3906 if (is_watchpoint (b
))
3908 struct watchpoint
*w
= (struct watchpoint
*) b
;
3915 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3917 int within_current_scope
= 1;
3918 struct watchpoint
* w
;
3920 /* We use value_mark and value_free_to_mark because it could
3921 be a long time before we return to the command level and
3922 call free_all_values. We can't call free_all_values
3923 because we might be in the middle of evaluating a
3925 struct value
*mark
= value_mark ();
3927 if (is_watchpoint (b
))
3928 w
= (struct watchpoint
*) b
;
3932 /* Need to select the frame, with all that implies so that
3933 the conditions will have the right context. Because we
3934 use the frame, we will not see an inlined function's
3935 variables when we arrive at a breakpoint at the start
3936 of the inlined function; the current frame will be the
3938 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
3939 select_frame (get_current_frame ());
3942 struct frame_info
*frame
;
3944 /* For local watchpoint expressions, which particular
3945 instance of a local is being watched matters, so we
3946 keep track of the frame to evaluate the expression
3947 in. To evaluate the condition however, it doesn't
3948 really matter which instantiation of the function
3949 where the condition makes sense triggers the
3950 watchpoint. This allows an expression like "watch
3951 global if q > 10" set in `func', catch writes to
3952 global on all threads that call `func', or catch
3953 writes on all recursive calls of `func' by a single
3954 thread. We simply always evaluate the condition in
3955 the innermost frame that's executing where it makes
3956 sense to evaluate the condition. It seems
3958 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
3960 select_frame (frame
);
3962 within_current_scope
= 0;
3964 if (within_current_scope
)
3966 = catch_errors (breakpoint_cond_eval
, cond
,
3967 "Error in testing breakpoint condition:\n",
3971 warning (_("Watchpoint condition cannot be tested "
3972 "in the current scope"));
3973 /* If we failed to set the right context for this
3974 watchpoint, unconditionally report it. */
3977 /* FIXME-someday, should give breakpoint #. */
3978 value_free_to_mark (mark
);
3981 if (cond
&& value_is_zero
)
3985 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3989 else if (b
->ignore_count
> 0)
3992 annotate_ignore_count_change ();
3994 /* Increase the hit count even though we don't stop. */
3996 observer_notify_breakpoint_modified (b
);
4002 /* Get a bpstat associated with having just stopped at address
4003 BP_ADDR in thread PTID.
4005 Determine whether we stopped at a breakpoint, etc, or whether we
4006 don't understand this stop. Result is a chain of bpstat's such
4009 if we don't understand the stop, the result is a null pointer.
4011 if we understand why we stopped, the result is not null.
4013 Each element of the chain refers to a particular breakpoint or
4014 watchpoint at which we have stopped. (We may have stopped for
4015 several reasons concurrently.)
4017 Each element of the chain has valid next, breakpoint_at,
4018 commands, FIXME??? fields. */
4021 bpstat_stop_status (struct address_space
*aspace
,
4022 CORE_ADDR bp_addr
, ptid_t ptid
)
4024 struct breakpoint
*b
= NULL
;
4025 struct bp_location
*bl
;
4026 struct bp_location
*loc
;
4027 /* First item of allocated bpstat's. */
4028 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4029 /* Pointer to the last thing in the chain currently. */
4032 int need_remove_insert
;
4035 /* First, build the bpstat chain with locations that explain a
4036 target stop, while being careful to not set the target running,
4037 as that may invalidate locations (in particular watchpoint
4038 locations are recreated). Resuming will happen here with
4039 breakpoint conditions or watchpoint expressions that include
4040 inferior function calls. */
4044 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4047 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4049 /* For hardware watchpoints, we look only at the first
4050 location. The watchpoint_check function will work on the
4051 entire expression, not the individual locations. For
4052 read watchpoints, the watchpoints_triggered function has
4053 checked all locations already. */
4054 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4057 if (bl
->shlib_disabled
)
4060 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4063 /* Come here if it's a watchpoint, or if the break address
4066 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4069 /* Assume we stop. Should we find a watchpoint that is not
4070 actually triggered, or if the condition of the breakpoint
4071 evaluates as false, we'll reset 'stop' to 0. */
4075 /* If this is a scope breakpoint, mark the associated
4076 watchpoint as triggered so that we will handle the
4077 out-of-scope event. We'll get to the watchpoint next
4079 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4081 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4083 w
->watchpoint_triggered
= watch_triggered_yes
;
4088 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4090 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4092 bs
= bpstat_alloc (loc
, &bs_link
);
4093 /* For hits of moribund locations, we should just proceed. */
4096 bs
->print_it
= print_it_noop
;
4100 /* Now go through the locations that caused the target to stop, and
4101 check whether we're interested in reporting this stop to higher
4102 layers, or whether we should resume the target transparently. */
4106 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4111 b
= bs
->breakpoint_at
;
4112 b
->ops
->check_status (bs
);
4115 bpstat_check_breakpoint_conditions (bs
, ptid
);
4120 observer_notify_breakpoint_modified (b
);
4122 /* We will stop here. */
4123 if (b
->disposition
== disp_disable
)
4125 if (b
->enable_state
!= bp_permanent
)
4126 b
->enable_state
= bp_disabled
;
4131 bs
->commands
= b
->commands
;
4132 incref_counted_command_line (bs
->commands
);
4133 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4134 if (bs
->commands_left
4135 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4138 bs
->commands_left
->line
) == 0)))
4140 bs
->commands_left
= bs
->commands_left
->next
;
4145 /* Print nothing for this entry if we don't stop or don't print. */
4146 if (bs
->stop
== 0 || bs
->print
== 0)
4147 bs
->print_it
= print_it_noop
;
4151 /* If we aren't stopping, the value of some hardware watchpoint may
4152 not have changed, but the intermediate memory locations we are
4153 watching may have. Don't bother if we're stopping; this will get
4155 need_remove_insert
= 0;
4156 if (! bpstat_causes_stop (bs_head
))
4157 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4159 && bs
->breakpoint_at
4160 && is_hardware_watchpoint (bs
->breakpoint_at
))
4162 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4164 update_watchpoint (w
, 0 /* don't reparse. */);
4165 need_remove_insert
= 1;
4168 if (need_remove_insert
)
4169 update_global_location_list (1);
4170 else if (removed_any
)
4171 update_global_location_list (0);
4177 handle_jit_event (void)
4179 struct frame_info
*frame
;
4180 struct gdbarch
*gdbarch
;
4182 /* Switch terminal for any messages produced by
4183 breakpoint_re_set. */
4184 target_terminal_ours_for_output ();
4186 frame
= get_current_frame ();
4187 gdbarch
= get_frame_arch (frame
);
4189 jit_event_handler (gdbarch
);
4191 target_terminal_inferior ();
4194 /* Prepare WHAT final decision for infrun. */
4196 /* Decide what infrun needs to do with this bpstat. */
4199 bpstat_what (bpstat bs_head
)
4201 struct bpstat_what retval
;
4202 /* We need to defer calling `solib_add', as adding new symbols
4203 resets breakpoints, which in turn deletes breakpoint locations,
4204 and hence may clear unprocessed entries in the BS chain. */
4205 int shlib_event
= 0;
4209 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4210 retval
.call_dummy
= STOP_NONE
;
4211 retval
.is_longjmp
= 0;
4213 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4215 /* Extract this BS's action. After processing each BS, we check
4216 if its action overrides all we've seem so far. */
4217 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4220 if (bs
->breakpoint_at
== NULL
)
4222 /* I suspect this can happen if it was a momentary
4223 breakpoint which has since been deleted. */
4227 bptype
= bs
->breakpoint_at
->type
;
4234 case bp_hardware_breakpoint
:
4240 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4242 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4245 this_action
= BPSTAT_WHAT_SINGLE
;
4248 case bp_hardware_watchpoint
:
4249 case bp_read_watchpoint
:
4250 case bp_access_watchpoint
:
4254 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4256 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4260 /* There was a watchpoint, but we're not stopping.
4261 This requires no further action. */
4266 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4267 retval
.is_longjmp
= bptype
== bp_longjmp
;
4269 case bp_longjmp_resume
:
4270 case bp_exception_resume
:
4271 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4272 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4274 case bp_step_resume
:
4276 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4279 /* It is for the wrong frame. */
4280 this_action
= BPSTAT_WHAT_SINGLE
;
4283 case bp_hp_step_resume
:
4285 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4288 /* It is for the wrong frame. */
4289 this_action
= BPSTAT_WHAT_SINGLE
;
4292 case bp_watchpoint_scope
:
4293 case bp_thread_event
:
4294 case bp_overlay_event
:
4295 case bp_longjmp_master
:
4296 case bp_std_terminate_master
:
4297 case bp_exception_master
:
4298 this_action
= BPSTAT_WHAT_SINGLE
;
4304 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4306 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4310 /* There was a catchpoint, but we're not stopping.
4311 This requires no further action. */
4314 case bp_shlib_event
:
4317 /* If requested, stop when the dynamic linker notifies GDB
4318 of events. This allows the user to get control and place
4319 breakpoints in initializer routines for dynamically
4320 loaded objects (among other things). */
4321 if (stop_on_solib_events
)
4322 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4324 this_action
= BPSTAT_WHAT_SINGLE
;
4328 this_action
= BPSTAT_WHAT_SINGLE
;
4331 /* Make sure the action is stop (silent or noisy),
4332 so infrun.c pops the dummy frame. */
4333 retval
.call_dummy
= STOP_STACK_DUMMY
;
4334 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4336 case bp_std_terminate
:
4337 /* Make sure the action is stop (silent or noisy),
4338 so infrun.c pops the dummy frame. */
4339 retval
.call_dummy
= STOP_STD_TERMINATE
;
4340 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4343 case bp_fast_tracepoint
:
4344 case bp_static_tracepoint
:
4345 /* Tracepoint hits should not be reported back to GDB, and
4346 if one got through somehow, it should have been filtered
4348 internal_error (__FILE__
, __LINE__
,
4349 _("bpstat_what: tracepoint encountered"));
4351 case bp_gnu_ifunc_resolver
:
4352 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4353 this_action
= BPSTAT_WHAT_SINGLE
;
4355 case bp_gnu_ifunc_resolver_return
:
4356 /* The breakpoint will be removed, execution will restart from the
4357 PC of the former breakpoint. */
4358 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4361 internal_error (__FILE__
, __LINE__
,
4362 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4365 retval
.main_action
= max (retval
.main_action
, this_action
);
4368 /* These operations may affect the bs->breakpoint_at state so they are
4369 delayed after MAIN_ACTION is decided above. */
4374 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4376 /* Check for any newly added shared libraries if we're supposed
4377 to be adding them automatically. */
4379 /* Switch terminal for any messages produced by
4380 breakpoint_re_set. */
4381 target_terminal_ours_for_output ();
4384 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4386 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4389 target_terminal_inferior ();
4395 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4397 handle_jit_event ();
4400 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4402 struct breakpoint
*b
= bs
->breakpoint_at
;
4408 case bp_gnu_ifunc_resolver
:
4409 gnu_ifunc_resolver_stop (b
);
4411 case bp_gnu_ifunc_resolver_return
:
4412 gnu_ifunc_resolver_return_stop (b
);
4420 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4421 without hardware support). This isn't related to a specific bpstat,
4422 just to things like whether watchpoints are set. */
4425 bpstat_should_step (void)
4427 struct breakpoint
*b
;
4430 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4436 bpstat_causes_stop (bpstat bs
)
4438 for (; bs
!= NULL
; bs
= bs
->next
)
4447 /* Compute a string of spaces suitable to indent the next line
4448 so it starts at the position corresponding to the table column
4449 named COL_NAME in the currently active table of UIOUT. */
4452 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4454 static char wrap_indent
[80];
4455 int i
, total_width
, width
, align
;
4459 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4461 if (strcmp (text
, col_name
) == 0)
4463 gdb_assert (total_width
< sizeof wrap_indent
);
4464 memset (wrap_indent
, ' ', total_width
);
4465 wrap_indent
[total_width
] = 0;
4470 total_width
+= width
+ 1;
4476 /* Print the LOC location out of the list of B->LOC locations. */
4479 print_breakpoint_location (struct breakpoint
*b
,
4480 struct bp_location
*loc
)
4482 struct cleanup
*old_chain
= save_current_program_space ();
4484 if (loc
!= NULL
&& loc
->shlib_disabled
)
4488 set_current_program_space (loc
->pspace
);
4490 if (b
->display_canonical
)
4491 ui_out_field_string (uiout
, "what", b
->addr_string
);
4492 else if (b
->source_file
&& loc
)
4495 = find_pc_sect_function (loc
->address
, loc
->section
);
4498 ui_out_text (uiout
, "in ");
4499 ui_out_field_string (uiout
, "func",
4500 SYMBOL_PRINT_NAME (sym
));
4501 ui_out_text (uiout
, " ");
4502 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4503 ui_out_text (uiout
, "at ");
4505 ui_out_field_string (uiout
, "file", b
->source_file
);
4506 ui_out_text (uiout
, ":");
4508 if (ui_out_is_mi_like_p (uiout
))
4510 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4511 char *fullname
= symtab_to_fullname (sal
.symtab
);
4514 ui_out_field_string (uiout
, "fullname", fullname
);
4517 ui_out_field_int (uiout
, "line", b
->line_number
);
4521 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4522 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4524 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4526 ui_out_field_stream (uiout
, "at", stb
);
4528 do_cleanups (stb_chain
);
4531 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4533 do_cleanups (old_chain
);
4537 bptype_string (enum bptype type
)
4539 struct ep_type_description
4544 static struct ep_type_description bptypes
[] =
4546 {bp_none
, "?deleted?"},
4547 {bp_breakpoint
, "breakpoint"},
4548 {bp_hardware_breakpoint
, "hw breakpoint"},
4549 {bp_until
, "until"},
4550 {bp_finish
, "finish"},
4551 {bp_watchpoint
, "watchpoint"},
4552 {bp_hardware_watchpoint
, "hw watchpoint"},
4553 {bp_read_watchpoint
, "read watchpoint"},
4554 {bp_access_watchpoint
, "acc watchpoint"},
4555 {bp_longjmp
, "longjmp"},
4556 {bp_longjmp_resume
, "longjmp resume"},
4557 {bp_exception
, "exception"},
4558 {bp_exception_resume
, "exception resume"},
4559 {bp_step_resume
, "step resume"},
4560 {bp_hp_step_resume
, "high-priority step resume"},
4561 {bp_watchpoint_scope
, "watchpoint scope"},
4562 {bp_call_dummy
, "call dummy"},
4563 {bp_std_terminate
, "std::terminate"},
4564 {bp_shlib_event
, "shlib events"},
4565 {bp_thread_event
, "thread events"},
4566 {bp_overlay_event
, "overlay events"},
4567 {bp_longjmp_master
, "longjmp master"},
4568 {bp_std_terminate_master
, "std::terminate master"},
4569 {bp_exception_master
, "exception master"},
4570 {bp_catchpoint
, "catchpoint"},
4571 {bp_tracepoint
, "tracepoint"},
4572 {bp_fast_tracepoint
, "fast tracepoint"},
4573 {bp_static_tracepoint
, "static tracepoint"},
4574 {bp_jit_event
, "jit events"},
4575 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4576 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4579 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4580 || ((int) type
!= bptypes
[(int) type
].type
))
4581 internal_error (__FILE__
, __LINE__
,
4582 _("bptypes table does not describe type #%d."),
4585 return bptypes
[(int) type
].description
;
4588 /* Print B to gdb_stdout. */
4591 print_one_breakpoint_location (struct breakpoint
*b
,
4592 struct bp_location
*loc
,
4594 struct bp_location
**last_loc
,
4597 struct command_line
*l
;
4598 static char bpenables
[] = "nynny";
4600 int header_of_multiple
= 0;
4601 int part_of_multiple
= (loc
!= NULL
);
4602 struct value_print_options opts
;
4604 get_user_print_options (&opts
);
4606 gdb_assert (!loc
|| loc_number
!= 0);
4607 /* See comment in print_one_breakpoint concerning treatment of
4608 breakpoints with single disabled location. */
4611 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4612 header_of_multiple
= 1;
4620 if (part_of_multiple
)
4623 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4624 ui_out_field_string (uiout
, "number", formatted
);
4629 ui_out_field_int (uiout
, "number", b
->number
);
4634 if (part_of_multiple
)
4635 ui_out_field_skip (uiout
, "type");
4637 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4641 if (part_of_multiple
)
4642 ui_out_field_skip (uiout
, "disp");
4644 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4649 if (part_of_multiple
)
4650 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4652 ui_out_field_fmt (uiout
, "enabled", "%c",
4653 bpenables
[(int) b
->enable_state
]);
4654 ui_out_spaces (uiout
, 2);
4658 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4660 /* Although the print_one can possibly print all locations,
4661 calling it here is not likely to get any nice result. So,
4662 make sure there's just one location. */
4663 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4664 b
->ops
->print_one (b
, last_loc
);
4670 internal_error (__FILE__
, __LINE__
,
4671 _("print_one_breakpoint: bp_none encountered\n"));
4675 case bp_hardware_watchpoint
:
4676 case bp_read_watchpoint
:
4677 case bp_access_watchpoint
:
4679 struct watchpoint
*w
= (struct watchpoint
*) b
;
4681 /* Field 4, the address, is omitted (which makes the columns
4682 not line up too nicely with the headers, but the effect
4683 is relatively readable). */
4684 if (opts
.addressprint
)
4685 ui_out_field_skip (uiout
, "addr");
4687 ui_out_field_string (uiout
, "what", w
->exp_string
);
4692 case bp_hardware_breakpoint
:
4696 case bp_longjmp_resume
:
4698 case bp_exception_resume
:
4699 case bp_step_resume
:
4700 case bp_hp_step_resume
:
4701 case bp_watchpoint_scope
:
4703 case bp_std_terminate
:
4704 case bp_shlib_event
:
4705 case bp_thread_event
:
4706 case bp_overlay_event
:
4707 case bp_longjmp_master
:
4708 case bp_std_terminate_master
:
4709 case bp_exception_master
:
4711 case bp_fast_tracepoint
:
4712 case bp_static_tracepoint
:
4714 case bp_gnu_ifunc_resolver
:
4715 case bp_gnu_ifunc_resolver_return
:
4716 if (opts
.addressprint
)
4719 if (header_of_multiple
)
4720 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4721 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4722 ui_out_field_string (uiout
, "addr", "<PENDING>");
4724 ui_out_field_core_addr (uiout
, "addr",
4725 loc
->gdbarch
, loc
->address
);
4728 if (!header_of_multiple
)
4729 print_breakpoint_location (b
, loc
);
4736 /* For backward compatibility, don't display inferiors unless there
4739 && !header_of_multiple
4741 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4742 && (number_of_program_spaces () > 1
4743 || number_of_inferiors () > 1)
4744 /* LOC is for existing B, it cannot be in
4745 moribund_locations and thus having NULL OWNER. */
4746 && loc
->owner
->type
!= bp_catchpoint
)))
4748 struct inferior
*inf
;
4751 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4753 if (inf
->pspace
== loc
->pspace
)
4758 ui_out_text (uiout
, " inf ");
4761 ui_out_text (uiout
, ", ");
4762 ui_out_text (uiout
, plongest (inf
->num
));
4767 if (!part_of_multiple
)
4769 if (b
->thread
!= -1)
4771 /* FIXME: This seems to be redundant and lost here; see the
4772 "stop only in" line a little further down. */
4773 ui_out_text (uiout
, " thread ");
4774 ui_out_field_int (uiout
, "thread", b
->thread
);
4776 else if (b
->task
!= 0)
4778 ui_out_text (uiout
, " task ");
4779 ui_out_field_int (uiout
, "task", b
->task
);
4783 ui_out_text (uiout
, "\n");
4785 if (!part_of_multiple
)
4786 b
->ops
->print_one_detail (b
, uiout
);
4788 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4791 ui_out_text (uiout
, "\tstop only in stack frame at ");
4792 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4794 ui_out_field_core_addr (uiout
, "frame",
4795 b
->gdbarch
, b
->frame_id
.stack_addr
);
4796 ui_out_text (uiout
, "\n");
4799 if (!part_of_multiple
&& b
->cond_string
)
4802 if (is_tracepoint (b
))
4803 ui_out_text (uiout
, "\ttrace only if ");
4805 ui_out_text (uiout
, "\tstop only if ");
4806 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4807 ui_out_text (uiout
, "\n");
4810 if (!part_of_multiple
&& b
->thread
!= -1)
4812 /* FIXME should make an annotation for this. */
4813 ui_out_text (uiout
, "\tstop only in thread ");
4814 ui_out_field_int (uiout
, "thread", b
->thread
);
4815 ui_out_text (uiout
, "\n");
4818 if (!part_of_multiple
&& b
->hit_count
)
4820 /* FIXME should make an annotation for this. */
4821 if (ep_is_catchpoint (b
))
4822 ui_out_text (uiout
, "\tcatchpoint");
4824 ui_out_text (uiout
, "\tbreakpoint");
4825 ui_out_text (uiout
, " already hit ");
4826 ui_out_field_int (uiout
, "times", b
->hit_count
);
4827 if (b
->hit_count
== 1)
4828 ui_out_text (uiout
, " time\n");
4830 ui_out_text (uiout
, " times\n");
4833 /* Output the count also if it is zero, but only if this is mi.
4834 FIXME: Should have a better test for this. */
4835 if (ui_out_is_mi_like_p (uiout
))
4836 if (!part_of_multiple
&& b
->hit_count
== 0)
4837 ui_out_field_int (uiout
, "times", b
->hit_count
);
4839 if (!part_of_multiple
&& b
->ignore_count
)
4842 ui_out_text (uiout
, "\tignore next ");
4843 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4844 ui_out_text (uiout
, " hits\n");
4847 l
= b
->commands
? b
->commands
->commands
: NULL
;
4848 if (!part_of_multiple
&& l
)
4850 struct cleanup
*script_chain
;
4853 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4854 print_command_lines (uiout
, l
, 4);
4855 do_cleanups (script_chain
);
4858 if (is_tracepoint (b
))
4860 struct tracepoint
*t
= (struct tracepoint
*) b
;
4862 if (!part_of_multiple
&& t
->pass_count
)
4864 annotate_field (10);
4865 ui_out_text (uiout
, "\tpass count ");
4866 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4867 ui_out_text (uiout
, " \n");
4871 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4873 if (is_watchpoint (b
))
4875 struct watchpoint
*w
= (struct watchpoint
*) b
;
4877 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
4879 else if (b
->addr_string
)
4880 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4885 print_one_breakpoint (struct breakpoint
*b
,
4886 struct bp_location
**last_loc
,
4889 struct cleanup
*bkpt_chain
;
4891 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4893 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
4894 do_cleanups (bkpt_chain
);
4896 /* If this breakpoint has custom print function,
4897 it's already printed. Otherwise, print individual
4898 locations, if any. */
4899 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4901 /* If breakpoint has a single location that is disabled, we
4902 print it as if it had several locations, since otherwise it's
4903 hard to represent "breakpoint enabled, location disabled"
4906 Note that while hardware watchpoints have several locations
4907 internally, that's not a property exposed to user. */
4909 && !is_hardware_watchpoint (b
)
4910 && (b
->loc
->next
|| !b
->loc
->enabled
))
4912 struct bp_location
*loc
;
4915 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4917 struct cleanup
*inner2
=
4918 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
4919 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
4920 do_cleanups (inner2
);
4927 breakpoint_address_bits (struct breakpoint
*b
)
4929 int print_address_bits
= 0;
4930 struct bp_location
*loc
;
4932 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4936 /* Software watchpoints that aren't watching memory don't have
4937 an address to print. */
4938 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4941 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4942 if (addr_bit
> print_address_bits
)
4943 print_address_bits
= addr_bit
;
4946 return print_address_bits
;
4949 struct captured_breakpoint_query_args
4955 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4957 struct captured_breakpoint_query_args
*args
= data
;
4958 struct breakpoint
*b
;
4959 struct bp_location
*dummy_loc
= NULL
;
4963 if (args
->bnum
== b
->number
)
4965 print_one_breakpoint (b
, &dummy_loc
, 0);
4973 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
4974 char **error_message
)
4976 struct captured_breakpoint_query_args args
;
4979 /* For the moment we don't trust print_one_breakpoint() to not throw
4981 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4982 error_message
, RETURN_MASK_ALL
) < 0)
4988 /* Return true if this breakpoint was set by the user, false if it is
4989 internal or momentary. */
4992 user_breakpoint_p (struct breakpoint
*b
)
4994 return b
->number
> 0;
4997 /* Print information on user settable breakpoint (watchpoint, etc)
4998 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4999 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5000 FILTER is non-NULL, call it on each breakpoint and only include the
5001 ones for which it returns non-zero. Return the total number of
5002 breakpoints listed. */
5005 breakpoint_1 (char *args
, int allflag
,
5006 int (*filter
) (const struct breakpoint
*))
5008 struct breakpoint
*b
;
5009 struct bp_location
*last_loc
= NULL
;
5010 int nr_printable_breakpoints
;
5011 struct cleanup
*bkpttbl_chain
;
5012 struct value_print_options opts
;
5013 int print_address_bits
= 0;
5014 int print_type_col_width
= 14;
5016 get_user_print_options (&opts
);
5018 /* Compute the number of rows in the table, as well as the size
5019 required for address fields. */
5020 nr_printable_breakpoints
= 0;
5023 /* If we have a filter, only list the breakpoints it accepts. */
5024 if (filter
&& !filter (b
))
5027 /* If we have an "args" string, it is a list of breakpoints to
5028 accept. Skip the others. */
5029 if (args
!= NULL
&& *args
!= '\0')
5031 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5033 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5037 if (allflag
|| user_breakpoint_p (b
))
5039 int addr_bit
, type_len
;
5041 addr_bit
= breakpoint_address_bits (b
);
5042 if (addr_bit
> print_address_bits
)
5043 print_address_bits
= addr_bit
;
5045 type_len
= strlen (bptype_string (b
->type
));
5046 if (type_len
> print_type_col_width
)
5047 print_type_col_width
= type_len
;
5049 nr_printable_breakpoints
++;
5053 if (opts
.addressprint
)
5055 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5056 nr_printable_breakpoints
,
5060 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5061 nr_printable_breakpoints
,
5064 if (nr_printable_breakpoints
> 0)
5065 annotate_breakpoints_headers ();
5066 if (nr_printable_breakpoints
> 0)
5068 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5069 if (nr_printable_breakpoints
> 0)
5071 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5072 "type", "Type"); /* 2 */
5073 if (nr_printable_breakpoints
> 0)
5075 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5076 if (nr_printable_breakpoints
> 0)
5078 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5079 if (opts
.addressprint
)
5081 if (nr_printable_breakpoints
> 0)
5083 if (print_address_bits
<= 32)
5084 ui_out_table_header (uiout
, 10, ui_left
,
5085 "addr", "Address"); /* 5 */
5087 ui_out_table_header (uiout
, 18, ui_left
,
5088 "addr", "Address"); /* 5 */
5090 if (nr_printable_breakpoints
> 0)
5092 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5093 ui_out_table_body (uiout
);
5094 if (nr_printable_breakpoints
> 0)
5095 annotate_breakpoints_table ();
5100 /* If we have a filter, only list the breakpoints it accepts. */
5101 if (filter
&& !filter (b
))
5104 /* If we have an "args" string, it is a list of breakpoints to
5105 accept. Skip the others. */
5107 if (args
!= NULL
&& *args
!= '\0')
5109 if (allflag
) /* maintenance info breakpoint */
5111 if (parse_and_eval_long (args
) != b
->number
)
5114 else /* all others */
5116 if (!number_is_in_list (args
, b
->number
))
5120 /* We only print out user settable breakpoints unless the
5122 if (allflag
|| user_breakpoint_p (b
))
5123 print_one_breakpoint (b
, &last_loc
, allflag
);
5126 do_cleanups (bkpttbl_chain
);
5128 if (nr_printable_breakpoints
== 0)
5130 /* If there's a filter, let the caller decide how to report
5134 if (args
== NULL
|| *args
== '\0')
5135 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5137 ui_out_message (uiout
, 0,
5138 "No breakpoint or watchpoint matching '%s'.\n",
5144 if (last_loc
&& !server_command
)
5145 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5148 /* FIXME? Should this be moved up so that it is only called when
5149 there have been breakpoints? */
5150 annotate_breakpoints_table_end ();
5152 return nr_printable_breakpoints
;
5155 /* Display the value of default-collect in a way that is generally
5156 compatible with the breakpoint list. */
5159 default_collect_info (void)
5161 /* If it has no value (which is frequently the case), say nothing; a
5162 message like "No default-collect." gets in user's face when it's
5164 if (!*default_collect
)
5167 /* The following phrase lines up nicely with per-tracepoint collect
5169 ui_out_text (uiout
, "default collect ");
5170 ui_out_field_string (uiout
, "default-collect", default_collect
);
5171 ui_out_text (uiout
, " \n");
5175 breakpoints_info (char *args
, int from_tty
)
5177 breakpoint_1 (args
, 0, NULL
);
5179 default_collect_info ();
5183 watchpoints_info (char *args
, int from_tty
)
5185 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5187 if (num_printed
== 0)
5189 if (args
== NULL
|| *args
== '\0')
5190 ui_out_message (uiout
, 0, "No watchpoints.\n");
5192 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5197 maintenance_info_breakpoints (char *args
, int from_tty
)
5199 breakpoint_1 (args
, 1, NULL
);
5201 default_collect_info ();
5205 breakpoint_has_pc (struct breakpoint
*b
,
5206 struct program_space
*pspace
,
5207 CORE_ADDR pc
, struct obj_section
*section
)
5209 struct bp_location
*bl
= b
->loc
;
5211 for (; bl
; bl
= bl
->next
)
5213 if (bl
->pspace
== pspace
5214 && bl
->address
== pc
5215 && (!overlay_debugging
|| bl
->section
== section
))
5221 /* Print a message describing any breakpoints set at PC. This
5222 concerns with logical breakpoints, so we match program spaces, not
5226 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5227 struct program_space
*pspace
, CORE_ADDR pc
,
5228 struct obj_section
*section
, int thread
)
5231 struct breakpoint
*b
;
5234 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5238 printf_filtered (_("Note: breakpoint "));
5239 else /* if (others == ???) */
5240 printf_filtered (_("Note: breakpoints "));
5242 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5245 printf_filtered ("%d", b
->number
);
5246 if (b
->thread
== -1 && thread
!= -1)
5247 printf_filtered (" (all threads)");
5248 else if (b
->thread
!= -1)
5249 printf_filtered (" (thread %d)", b
->thread
);
5250 printf_filtered ("%s%s ",
5251 ((b
->enable_state
== bp_disabled
5252 || b
->enable_state
== bp_call_disabled
5253 || b
->enable_state
== bp_startup_disabled
)
5255 : b
->enable_state
== bp_permanent
5259 : ((others
== 1) ? " and" : ""));
5261 printf_filtered (_("also set at pc "));
5262 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5263 printf_filtered (".\n");
5267 /* Set the default place to put a breakpoint
5268 for the `break' command with no arguments. */
5271 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5272 CORE_ADDR addr
, struct symtab
*symtab
,
5275 default_breakpoint_valid
= valid
;
5276 default_breakpoint_pspace
= pspace
;
5277 default_breakpoint_address
= addr
;
5278 default_breakpoint_symtab
= symtab
;
5279 default_breakpoint_line
= line
;
5282 /* Return true iff it is meaningful to use the address member of
5283 BPT. For some breakpoint types, the address member is irrelevant
5284 and it makes no sense to attempt to compare it to other addresses
5285 (or use it for any other purpose either).
5287 More specifically, each of the following breakpoint types will
5288 always have a zero valued address and we don't want to mark
5289 breakpoints of any of these types to be a duplicate of an actual
5290 breakpoint at address zero:
5298 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5300 enum bptype type
= bpt
->type
;
5302 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5305 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5306 true if LOC1 and LOC2 represent the same watchpoint location. */
5309 watchpoint_locations_match (struct bp_location
*loc1
,
5310 struct bp_location
*loc2
)
5312 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5313 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5315 /* Both of them must exist. */
5316 gdb_assert (w1
!= NULL
);
5317 gdb_assert (w2
!= NULL
);
5319 /* If the target can evaluate the condition expression in hardware,
5320 then we we need to insert both watchpoints even if they are at
5321 the same place. Otherwise the watchpoint will only trigger when
5322 the condition of whichever watchpoint was inserted evaluates to
5323 true, not giving a chance for GDB to check the condition of the
5324 other watchpoint. */
5326 && target_can_accel_watchpoint_condition (loc1
->address
,
5328 loc1
->watchpoint_type
,
5331 && target_can_accel_watchpoint_condition (loc2
->address
,
5333 loc2
->watchpoint_type
,
5337 /* Note that this checks the owner's type, not the location's. In
5338 case the target does not support read watchpoints, but does
5339 support access watchpoints, we'll have bp_read_watchpoint
5340 watchpoints with hw_access locations. Those should be considered
5341 duplicates of hw_read locations. The hw_read locations will
5342 become hw_access locations later. */
5343 return (loc1
->owner
->type
== loc2
->owner
->type
5344 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5345 && loc1
->address
== loc2
->address
5346 && loc1
->length
== loc2
->length
);
5349 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5350 same breakpoint location. In most targets, this can only be true
5351 if ASPACE1 matches ASPACE2. On targets that have global
5352 breakpoints, the address space doesn't really matter. */
5355 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5356 struct address_space
*aspace2
, CORE_ADDR addr2
)
5358 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5359 || aspace1
== aspace2
)
5363 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5364 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5365 matches ASPACE2. On targets that have global breakpoints, the address
5366 space doesn't really matter. */
5369 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5370 int len1
, struct address_space
*aspace2
,
5373 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5374 || aspace1
== aspace2
)
5375 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5378 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5379 a ranged breakpoint. In most targets, a match happens only if ASPACE
5380 matches the breakpoint's address space. On targets that have global
5381 breakpoints, the address space doesn't really matter. */
5384 breakpoint_location_address_match (struct bp_location
*bl
,
5385 struct address_space
*aspace
,
5388 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5391 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5392 bl
->address
, bl
->length
,
5396 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5397 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5398 represent the same location. */
5401 breakpoint_locations_match (struct bp_location
*loc1
,
5402 struct bp_location
*loc2
)
5404 int hw_point1
, hw_point2
;
5406 /* Both of them must not be in moribund_locations. */
5407 gdb_assert (loc1
->owner
!= NULL
);
5408 gdb_assert (loc2
->owner
!= NULL
);
5410 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5411 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5413 if (hw_point1
!= hw_point2
)
5416 return watchpoint_locations_match (loc1
, loc2
);
5418 /* We compare bp_location.length in order to cover ranged breakpoints. */
5419 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5420 loc2
->pspace
->aspace
, loc2
->address
)
5421 && loc1
->length
== loc2
->length
);
5425 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5426 int bnum
, int have_bnum
)
5428 /* The longest string possibly returned by hex_string_custom
5429 is 50 chars. These must be at least that big for safety. */
5433 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5434 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5436 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5437 bnum
, astr1
, astr2
);
5439 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5442 /* Adjust a breakpoint's address to account for architectural
5443 constraints on breakpoint placement. Return the adjusted address.
5444 Note: Very few targets require this kind of adjustment. For most
5445 targets, this function is simply the identity function. */
5448 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5449 CORE_ADDR bpaddr
, enum bptype bptype
)
5451 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5453 /* Very few targets need any kind of breakpoint adjustment. */
5456 else if (bptype
== bp_watchpoint
5457 || bptype
== bp_hardware_watchpoint
5458 || bptype
== bp_read_watchpoint
5459 || bptype
== bp_access_watchpoint
5460 || bptype
== bp_catchpoint
)
5462 /* Watchpoints and the various bp_catch_* eventpoints should not
5463 have their addresses modified. */
5468 CORE_ADDR adjusted_bpaddr
;
5470 /* Some targets have architectural constraints on the placement
5471 of breakpoint instructions. Obtain the adjusted address. */
5472 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5474 /* An adjusted breakpoint address can significantly alter
5475 a user's expectations. Print a warning if an adjustment
5477 if (adjusted_bpaddr
!= bpaddr
)
5478 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5480 return adjusted_bpaddr
;
5485 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5486 struct breakpoint
*owner
)
5488 memset (loc
, 0, sizeof (*loc
));
5490 gdb_assert (ops
!= NULL
);
5495 loc
->shlib_disabled
= 0;
5498 switch (owner
->type
)
5504 case bp_longjmp_resume
:
5506 case bp_exception_resume
:
5507 case bp_step_resume
:
5508 case bp_hp_step_resume
:
5509 case bp_watchpoint_scope
:
5511 case bp_std_terminate
:
5512 case bp_shlib_event
:
5513 case bp_thread_event
:
5514 case bp_overlay_event
:
5516 case bp_longjmp_master
:
5517 case bp_std_terminate_master
:
5518 case bp_exception_master
:
5519 case bp_gnu_ifunc_resolver
:
5520 case bp_gnu_ifunc_resolver_return
:
5521 loc
->loc_type
= bp_loc_software_breakpoint
;
5523 case bp_hardware_breakpoint
:
5524 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5526 case bp_hardware_watchpoint
:
5527 case bp_read_watchpoint
:
5528 case bp_access_watchpoint
:
5529 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5534 case bp_fast_tracepoint
:
5535 case bp_static_tracepoint
:
5536 loc
->loc_type
= bp_loc_other
;
5539 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5545 /* Allocate a struct bp_location. */
5547 static struct bp_location
*
5548 allocate_bp_location (struct breakpoint
*bpt
)
5550 return bpt
->ops
->allocate_location (bpt
);
5554 free_bp_location (struct bp_location
*loc
)
5556 loc
->ops
->dtor (loc
);
5560 /* Increment reference count. */
5563 incref_bp_location (struct bp_location
*bl
)
5568 /* Decrement reference count. If the reference count reaches 0,
5569 destroy the bp_location. Sets *BLP to NULL. */
5572 decref_bp_location (struct bp_location
**blp
)
5574 gdb_assert ((*blp
)->refc
> 0);
5576 if (--(*blp
)->refc
== 0)
5577 free_bp_location (*blp
);
5581 /* Add breakpoint B at the end of the global breakpoint chain. */
5584 add_to_breakpoint_chain (struct breakpoint
*b
)
5586 struct breakpoint
*b1
;
5588 /* Add this breakpoint to the end of the chain so that a list of
5589 breakpoints will come out in order of increasing numbers. */
5591 b1
= breakpoint_chain
;
5593 breakpoint_chain
= b
;
5602 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5605 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5606 struct gdbarch
*gdbarch
,
5608 struct breakpoint_ops
*ops
)
5610 memset (b
, 0, sizeof (*b
));
5612 gdb_assert (ops
!= NULL
);
5616 b
->gdbarch
= gdbarch
;
5617 b
->language
= current_language
->la_language
;
5618 b
->input_radix
= input_radix
;
5620 b
->enable_state
= bp_enabled
;
5623 b
->ignore_count
= 0;
5625 b
->frame_id
= null_frame_id
;
5626 b
->condition_not_parsed
= 0;
5627 b
->py_bp_object
= NULL
;
5628 b
->related_breakpoint
= b
;
5631 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5632 that has type BPTYPE and has no locations as yet. */
5634 static struct breakpoint
*
5635 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5637 struct breakpoint_ops
*ops
)
5639 struct breakpoint
*b
= XNEW (struct breakpoint
);
5641 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5642 add_to_breakpoint_chain (b
);
5646 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5647 resolutions should be made as the user specified the location explicitly
5651 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5653 gdb_assert (loc
->owner
!= NULL
);
5655 if (loc
->owner
->type
== bp_breakpoint
5656 || loc
->owner
->type
== bp_hardware_breakpoint
5657 || is_tracepoint (loc
->owner
))
5661 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5662 NULL
, NULL
, &is_gnu_ifunc
);
5664 if (is_gnu_ifunc
&& !explicit_loc
)
5666 struct breakpoint
*b
= loc
->owner
;
5668 gdb_assert (loc
->pspace
== current_program_space
);
5669 if (gnu_ifunc_resolve_name (loc
->function_name
,
5670 &loc
->requested_address
))
5672 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5673 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5674 loc
->requested_address
,
5677 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5678 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5680 /* Create only the whole new breakpoint of this type but do not
5681 mess more complicated breakpoints with multiple locations. */
5682 b
->type
= bp_gnu_ifunc_resolver
;
5686 if (loc
->function_name
)
5687 loc
->function_name
= xstrdup (loc
->function_name
);
5691 /* Attempt to determine architecture of location identified by SAL. */
5692 static struct gdbarch
*
5693 get_sal_arch (struct symtab_and_line sal
)
5696 return get_objfile_arch (sal
.section
->objfile
);
5698 return get_objfile_arch (sal
.symtab
->objfile
);
5703 /* Low level routine for partially initializing a breakpoint of type
5704 BPTYPE. The newly created breakpoint's address, section, source
5705 file name, and line number are provided by SAL.
5707 It is expected that the caller will complete the initialization of
5708 the newly created breakpoint struct as well as output any status
5709 information regarding the creation of a new breakpoint. */
5712 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5713 struct symtab_and_line sal
, enum bptype bptype
,
5714 struct breakpoint_ops
*ops
)
5716 CORE_ADDR adjusted_address
;
5717 struct gdbarch
*loc_gdbarch
;
5719 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5721 loc_gdbarch
= get_sal_arch (sal
);
5723 loc_gdbarch
= b
->gdbarch
;
5725 if (bptype
!= bp_catchpoint
)
5726 gdb_assert (sal
.pspace
!= NULL
);
5728 /* Adjust the breakpoint's address prior to allocating a location.
5729 Once we call allocate_bp_location(), that mostly uninitialized
5730 location will be placed on the location chain. Adjustment of the
5731 breakpoint may cause target_read_memory() to be called and we do
5732 not want its scan of the location chain to find a breakpoint and
5733 location that's only been partially initialized. */
5734 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5737 b
->loc
= allocate_bp_location (b
);
5738 b
->loc
->gdbarch
= loc_gdbarch
;
5739 b
->loc
->requested_address
= sal
.pc
;
5740 b
->loc
->address
= adjusted_address
;
5741 b
->loc
->pspace
= sal
.pspace
;
5743 /* Store the program space that was used to set the breakpoint, for
5744 breakpoint resetting. */
5745 b
->pspace
= sal
.pspace
;
5747 if (sal
.symtab
== NULL
)
5748 b
->source_file
= NULL
;
5750 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5751 b
->loc
->section
= sal
.section
;
5752 b
->line_number
= sal
.line
;
5754 set_breakpoint_location_function (b
->loc
,
5755 sal
.explicit_pc
|| sal
.explicit_line
);
5757 breakpoints_changed ();
5760 /* set_raw_breakpoint is a low level routine for allocating and
5761 partially initializing a breakpoint of type BPTYPE. The newly
5762 created breakpoint's address, section, source file name, and line
5763 number are provided by SAL. The newly created and partially
5764 initialized breakpoint is added to the breakpoint chain and
5765 is also returned as the value of this function.
5767 It is expected that the caller will complete the initialization of
5768 the newly created breakpoint struct as well as output any status
5769 information regarding the creation of a new breakpoint. In
5770 particular, set_raw_breakpoint does NOT set the breakpoint
5771 number! Care should be taken to not allow an error to occur
5772 prior to completing the initialization of the breakpoint. If this
5773 should happen, a bogus breakpoint will be left on the chain. */
5776 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5777 struct symtab_and_line sal
, enum bptype bptype
,
5778 struct breakpoint_ops
*ops
)
5780 struct breakpoint
*b
= XNEW (struct breakpoint
);
5782 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5783 add_to_breakpoint_chain (b
);
5788 /* Note that the breakpoint object B describes a permanent breakpoint
5789 instruction, hard-wired into the inferior's code. */
5791 make_breakpoint_permanent (struct breakpoint
*b
)
5793 struct bp_location
*bl
;
5795 b
->enable_state
= bp_permanent
;
5797 /* By definition, permanent breakpoints are already present in the
5798 code. Mark all locations as inserted. For now,
5799 make_breakpoint_permanent is called in just one place, so it's
5800 hard to say if it's reasonable to have permanent breakpoint with
5801 multiple locations or not, but it's easy to implement. */
5802 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5806 /* Call this routine when stepping and nexting to enable a breakpoint
5807 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5808 initiated the operation. */
5811 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5813 struct breakpoint
*b
, *b_tmp
;
5814 int thread
= tp
->num
;
5816 /* To avoid having to rescan all objfile symbols at every step,
5817 we maintain a list of continually-inserted but always disabled
5818 longjmp "master" breakpoints. Here, we simply create momentary
5819 clones of those and enable them for the requested thread. */
5820 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5821 if (b
->pspace
== current_program_space
5822 && (b
->type
== bp_longjmp_master
5823 || b
->type
== bp_exception_master
))
5825 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5826 struct breakpoint
*clone
;
5828 clone
= momentary_breakpoint_from_master (b
, type
,
5829 &momentary_breakpoint_ops
);
5830 clone
->thread
= thread
;
5833 tp
->initiating_frame
= frame
;
5836 /* Delete all longjmp breakpoints from THREAD. */
5838 delete_longjmp_breakpoint (int thread
)
5840 struct breakpoint
*b
, *b_tmp
;
5842 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5843 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5845 if (b
->thread
== thread
)
5846 delete_breakpoint (b
);
5851 enable_overlay_breakpoints (void)
5853 struct breakpoint
*b
;
5856 if (b
->type
== bp_overlay_event
)
5858 b
->enable_state
= bp_enabled
;
5859 update_global_location_list (1);
5860 overlay_events_enabled
= 1;
5865 disable_overlay_breakpoints (void)
5867 struct breakpoint
*b
;
5870 if (b
->type
== bp_overlay_event
)
5872 b
->enable_state
= bp_disabled
;
5873 update_global_location_list (0);
5874 overlay_events_enabled
= 0;
5878 /* Set an active std::terminate breakpoint for each std::terminate
5879 master breakpoint. */
5881 set_std_terminate_breakpoint (void)
5883 struct breakpoint
*b
, *b_tmp
;
5885 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5886 if (b
->pspace
== current_program_space
5887 && b
->type
== bp_std_terminate_master
)
5889 momentary_breakpoint_from_master (b
, bp_std_terminate
,
5890 &momentary_breakpoint_ops
);
5894 /* Delete all the std::terminate breakpoints. */
5896 delete_std_terminate_breakpoint (void)
5898 struct breakpoint
*b
, *b_tmp
;
5900 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5901 if (b
->type
== bp_std_terminate
)
5902 delete_breakpoint (b
);
5906 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5908 struct breakpoint
*b
;
5910 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
5911 &internal_breakpoint_ops
);
5913 b
->enable_state
= bp_enabled
;
5914 /* addr_string has to be used or breakpoint_re_set will delete me. */
5916 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5918 update_global_location_list_nothrow (1);
5924 remove_thread_event_breakpoints (void)
5926 struct breakpoint
*b
, *b_tmp
;
5928 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5929 if (b
->type
== bp_thread_event
5930 && b
->loc
->pspace
== current_program_space
)
5931 delete_breakpoint (b
);
5934 struct lang_and_radix
5940 /* Create a breakpoint for JIT code registration and unregistration. */
5943 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5945 struct breakpoint
*b
;
5947 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
5948 &internal_breakpoint_ops
);
5949 update_global_location_list_nothrow (1);
5953 /* Remove JIT code registration and unregistration breakpoint(s). */
5956 remove_jit_event_breakpoints (void)
5958 struct breakpoint
*b
, *b_tmp
;
5960 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5961 if (b
->type
== bp_jit_event
5962 && b
->loc
->pspace
== current_program_space
)
5963 delete_breakpoint (b
);
5967 remove_solib_event_breakpoints (void)
5969 struct breakpoint
*b
, *b_tmp
;
5971 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5972 if (b
->type
== bp_shlib_event
5973 && b
->loc
->pspace
== current_program_space
)
5974 delete_breakpoint (b
);
5978 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5980 struct breakpoint
*b
;
5982 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
5983 &internal_breakpoint_ops
);
5984 update_global_location_list_nothrow (1);
5988 /* Disable any breakpoints that are on code in shared libraries. Only
5989 apply to enabled breakpoints, disabled ones can just stay disabled. */
5992 disable_breakpoints_in_shlibs (void)
5994 struct bp_location
*loc
, **locp_tmp
;
5996 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5998 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5999 struct breakpoint
*b
= loc
->owner
;
6001 /* We apply the check to all breakpoints, including disabled for
6002 those with loc->duplicate set. This is so that when breakpoint
6003 becomes enabled, or the duplicate is removed, gdb will try to
6004 insert all breakpoints. If we don't set shlib_disabled here,
6005 we'll try to insert those breakpoints and fail. */
6006 if (((b
->type
== bp_breakpoint
)
6007 || (b
->type
== bp_jit_event
)
6008 || (b
->type
== bp_hardware_breakpoint
)
6009 || (is_tracepoint (b
)))
6010 && loc
->pspace
== current_program_space
6011 && !loc
->shlib_disabled
6013 && PC_SOLIB (loc
->address
)
6015 && solib_name_from_address (loc
->pspace
, loc
->address
)
6019 loc
->shlib_disabled
= 1;
6024 /* Disable any breakpoints that are in an unloaded shared library.
6025 Only apply to enabled breakpoints, disabled ones can just stay
6029 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6031 struct bp_location
*loc
, **locp_tmp
;
6032 int disabled_shlib_breaks
= 0;
6034 /* SunOS a.out shared libraries are always mapped, so do not
6035 disable breakpoints; they will only be reported as unloaded
6036 through clear_solib when GDB discards its shared library
6037 list. See clear_solib for more information. */
6038 if (exec_bfd
!= NULL
6039 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6042 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6044 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6045 struct breakpoint
*b
= loc
->owner
;
6047 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6048 || loc
->loc_type
== bp_loc_software_breakpoint
)
6049 && solib
->pspace
== loc
->pspace
6050 && !loc
->shlib_disabled
6051 && (b
->type
== bp_breakpoint
6052 || b
->type
== bp_jit_event
6053 || b
->type
== bp_hardware_breakpoint
)
6054 && solib_contains_address_p (solib
, loc
->address
))
6056 loc
->shlib_disabled
= 1;
6057 /* At this point, we cannot rely on remove_breakpoint
6058 succeeding so we must mark the breakpoint as not inserted
6059 to prevent future errors occurring in remove_breakpoints. */
6062 /* This may cause duplicate notifications for the same breakpoint. */
6063 observer_notify_breakpoint_modified (b
);
6065 if (!disabled_shlib_breaks
)
6067 target_terminal_ours_for_output ();
6068 warning (_("Temporarily disabling breakpoints "
6069 "for unloaded shared library \"%s\""),
6072 disabled_shlib_breaks
= 1;
6077 /* FORK & VFORK catchpoints. */
6079 /* An instance of this type is used to represent a fork or vfork
6080 catchpoint. It includes a "struct breakpoint" as a kind of base
6081 class; users downcast to "struct breakpoint *" when needed. A
6082 breakpoint is really of this type iff its ops pointer points to
6083 CATCH_FORK_BREAKPOINT_OPS. */
6085 struct fork_catchpoint
6087 /* The base class. */
6088 struct breakpoint base
;
6090 /* Process id of a child process whose forking triggered this
6091 catchpoint. This field is only valid immediately after this
6092 catchpoint has triggered. */
6093 ptid_t forked_inferior_pid
;
6096 /* Implement the "insert" breakpoint_ops method for fork
6100 insert_catch_fork (struct bp_location
*bl
)
6102 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6105 /* Implement the "remove" breakpoint_ops method for fork
6109 remove_catch_fork (struct bp_location
*bl
)
6111 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6114 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6118 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6119 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6121 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6123 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6126 /* Implement the "print_it" breakpoint_ops method for fork
6129 static enum print_stop_action
6130 print_it_catch_fork (bpstat bs
)
6132 struct breakpoint
*b
= bs
->breakpoint_at
;
6133 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6135 annotate_catchpoint (b
->number
);
6136 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6137 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6138 return PRINT_SRC_AND_LOC
;
6141 /* Implement the "print_one" breakpoint_ops method for fork
6145 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6147 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6148 struct value_print_options opts
;
6150 get_user_print_options (&opts
);
6152 /* Field 4, the address, is omitted (which makes the columns not
6153 line up too nicely with the headers, but the effect is relatively
6155 if (opts
.addressprint
)
6156 ui_out_field_skip (uiout
, "addr");
6158 ui_out_text (uiout
, "fork");
6159 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6161 ui_out_text (uiout
, ", process ");
6162 ui_out_field_int (uiout
, "what",
6163 ptid_get_pid (c
->forked_inferior_pid
));
6164 ui_out_spaces (uiout
, 1);
6168 /* Implement the "print_mention" breakpoint_ops method for fork
6172 print_mention_catch_fork (struct breakpoint
*b
)
6174 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6177 /* Implement the "print_recreate" breakpoint_ops method for fork
6181 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6183 fprintf_unfiltered (fp
, "catch fork");
6184 print_recreate_thread (b
, fp
);
6187 /* The breakpoint_ops structure to be used in fork catchpoints. */
6189 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6191 /* Implement the "insert" breakpoint_ops method for vfork
6195 insert_catch_vfork (struct bp_location
*bl
)
6197 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6200 /* Implement the "remove" breakpoint_ops method for vfork
6204 remove_catch_vfork (struct bp_location
*bl
)
6206 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6209 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6213 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6214 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6216 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6218 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6221 /* Implement the "print_it" breakpoint_ops method for vfork
6224 static enum print_stop_action
6225 print_it_catch_vfork (bpstat bs
)
6227 struct breakpoint
*b
= bs
->breakpoint_at
;
6228 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6230 annotate_catchpoint (b
->number
);
6231 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6232 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6233 return PRINT_SRC_AND_LOC
;
6236 /* Implement the "print_one" breakpoint_ops method for vfork
6240 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6242 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6243 struct value_print_options opts
;
6245 get_user_print_options (&opts
);
6246 /* Field 4, the address, is omitted (which makes the columns not
6247 line up too nicely with the headers, but the effect is relatively
6249 if (opts
.addressprint
)
6250 ui_out_field_skip (uiout
, "addr");
6252 ui_out_text (uiout
, "vfork");
6253 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6255 ui_out_text (uiout
, ", process ");
6256 ui_out_field_int (uiout
, "what",
6257 ptid_get_pid (c
->forked_inferior_pid
));
6258 ui_out_spaces (uiout
, 1);
6262 /* Implement the "print_mention" breakpoint_ops method for vfork
6266 print_mention_catch_vfork (struct breakpoint
*b
)
6268 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6271 /* Implement the "print_recreate" breakpoint_ops method for vfork
6275 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6277 fprintf_unfiltered (fp
, "catch vfork");
6278 print_recreate_thread (b
, fp
);
6281 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6283 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6285 /* An instance of this type is used to represent a syscall catchpoint.
6286 It includes a "struct breakpoint" as a kind of base class; users
6287 downcast to "struct breakpoint *" when needed. A breakpoint is
6288 really of this type iff its ops pointer points to
6289 CATCH_SYSCALL_BREAKPOINT_OPS. */
6291 struct syscall_catchpoint
6293 /* The base class. */
6294 struct breakpoint base
;
6296 /* Syscall numbers used for the 'catch syscall' feature. If no
6297 syscall has been specified for filtering, its value is NULL.
6298 Otherwise, it holds a list of all syscalls to be caught. The
6299 list elements are allocated with xmalloc. */
6300 VEC(int) *syscalls_to_be_caught
;
6303 /* Implement the "dtor" breakpoint_ops method for syscall
6307 dtor_catch_syscall (struct breakpoint
*b
)
6309 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6311 VEC_free (int, c
->syscalls_to_be_caught
);
6313 base_breakpoint_ops
.dtor (b
);
6316 /* Implement the "insert" breakpoint_ops method for syscall
6320 insert_catch_syscall (struct bp_location
*bl
)
6322 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6323 struct inferior
*inf
= current_inferior ();
6325 ++inf
->total_syscalls_count
;
6326 if (!c
->syscalls_to_be_caught
)
6327 ++inf
->any_syscall_count
;
6333 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6338 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6340 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6341 uintptr_t vec_addr_offset
6342 = old_size
* ((uintptr_t) sizeof (int));
6344 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6345 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6347 memset ((void *) vec_addr
, 0,
6348 (iter
+ 1 - old_size
) * sizeof (int));
6350 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6351 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6355 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6356 inf
->total_syscalls_count
!= 0,
6357 inf
->any_syscall_count
,
6358 VEC_length (int, inf
->syscalls_counts
),
6359 VEC_address (int, inf
->syscalls_counts
));
6362 /* Implement the "remove" breakpoint_ops method for syscall
6366 remove_catch_syscall (struct bp_location
*bl
)
6368 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6369 struct inferior
*inf
= current_inferior ();
6371 --inf
->total_syscalls_count
;
6372 if (!c
->syscalls_to_be_caught
)
6373 --inf
->any_syscall_count
;
6379 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6383 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6384 /* Shouldn't happen. */
6386 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6387 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6391 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6392 inf
->total_syscalls_count
!= 0,
6393 inf
->any_syscall_count
,
6394 VEC_length (int, inf
->syscalls_counts
),
6396 inf
->syscalls_counts
));
6399 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6403 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6404 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6406 /* We must check if we are catching specific syscalls in this
6407 breakpoint. If we are, then we must guarantee that the called
6408 syscall is the same syscall we are catching. */
6409 int syscall_number
= 0;
6410 const struct syscall_catchpoint
*c
6411 = (const struct syscall_catchpoint
*) bl
->owner
;
6413 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6416 /* Now, checking if the syscall is the same. */
6417 if (c
->syscalls_to_be_caught
)
6422 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6424 if (syscall_number
== iter
)
6434 /* Implement the "print_it" breakpoint_ops method for syscall
6437 static enum print_stop_action
6438 print_it_catch_syscall (bpstat bs
)
6440 struct breakpoint
*b
= bs
->breakpoint_at
;
6441 /* These are needed because we want to know in which state a
6442 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6443 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6444 must print "called syscall" or "returned from syscall". */
6446 struct target_waitstatus last
;
6448 struct cleanup
*old_chain
;
6451 get_last_target_status (&ptid
, &last
);
6453 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6455 annotate_catchpoint (b
->number
);
6458 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6460 syscall_id
= xstrprintf ("'%s'", s
.name
);
6462 old_chain
= make_cleanup (xfree
, syscall_id
);
6464 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6465 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6466 b
->number
, syscall_id
);
6467 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6468 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6469 b
->number
, syscall_id
);
6471 do_cleanups (old_chain
);
6473 return PRINT_SRC_AND_LOC
;
6476 /* Implement the "print_one" breakpoint_ops method for syscall
6480 print_one_catch_syscall (struct breakpoint
*b
,
6481 struct bp_location
**last_loc
)
6483 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6484 struct value_print_options opts
;
6486 get_user_print_options (&opts
);
6487 /* Field 4, the address, is omitted (which makes the columns not
6488 line up too nicely with the headers, but the effect is relatively
6490 if (opts
.addressprint
)
6491 ui_out_field_skip (uiout
, "addr");
6494 if (c
->syscalls_to_be_caught
6495 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6496 ui_out_text (uiout
, "syscalls \"");
6498 ui_out_text (uiout
, "syscall \"");
6500 if (c
->syscalls_to_be_caught
)
6503 char *text
= xstrprintf ("%s", "");
6506 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6511 get_syscall_by_number (iter
, &s
);
6514 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6516 text
= xstrprintf ("%s%d, ", text
, iter
);
6518 /* We have to xfree the last 'text' (now stored at 'x')
6519 because xstrprintf dynamically allocates new space for it
6523 /* Remove the last comma. */
6524 text
[strlen (text
) - 2] = '\0';
6525 ui_out_field_string (uiout
, "what", text
);
6528 ui_out_field_string (uiout
, "what", "<any syscall>");
6529 ui_out_text (uiout
, "\" ");
6532 /* Implement the "print_mention" breakpoint_ops method for syscall
6536 print_mention_catch_syscall (struct breakpoint
*b
)
6538 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6540 if (c
->syscalls_to_be_caught
)
6544 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6545 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6547 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6550 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6554 get_syscall_by_number (iter
, &s
);
6557 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6559 printf_filtered (" %d", s
.number
);
6561 printf_filtered (")");
6564 printf_filtered (_("Catchpoint %d (any syscall)"),
6568 /* Implement the "print_recreate" breakpoint_ops method for syscall
6572 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6574 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6576 fprintf_unfiltered (fp
, "catch syscall");
6578 if (c
->syscalls_to_be_caught
)
6583 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6588 get_syscall_by_number (iter
, &s
);
6590 fprintf_unfiltered (fp
, " %s", s
.name
);
6592 fprintf_unfiltered (fp
, " %d", s
.number
);
6595 print_recreate_thread (b
, fp
);
6598 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6600 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6602 /* Returns non-zero if 'b' is a syscall catchpoint. */
6605 syscall_catchpoint_p (struct breakpoint
*b
)
6607 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6610 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6611 is non-zero, then make the breakpoint temporary. If COND_STRING is
6612 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6613 the breakpoint_ops structure associated to the catchpoint. */
6616 init_catchpoint (struct breakpoint
*b
,
6617 struct gdbarch
*gdbarch
, int tempflag
,
6619 struct breakpoint_ops
*ops
)
6621 struct symtab_and_line sal
;
6624 sal
.pspace
= current_program_space
;
6626 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6628 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6629 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6633 install_breakpoint (int internal
, struct breakpoint
*b
)
6635 add_to_breakpoint_chain (b
);
6636 set_breakpoint_number (internal
, b
);
6639 observer_notify_breakpoint_created (b
);
6640 update_global_location_list (1);
6644 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6645 int tempflag
, char *cond_string
,
6646 struct breakpoint_ops
*ops
)
6648 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6650 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6652 c
->forked_inferior_pid
= null_ptid
;
6654 install_breakpoint (0, &c
->base
);
6657 /* Exec catchpoints. */
6659 /* An instance of this type is used to represent an exec catchpoint.
6660 It includes a "struct breakpoint" as a kind of base class; users
6661 downcast to "struct breakpoint *" when needed. A breakpoint is
6662 really of this type iff its ops pointer points to
6663 CATCH_EXEC_BREAKPOINT_OPS. */
6665 struct exec_catchpoint
6667 /* The base class. */
6668 struct breakpoint base
;
6670 /* Filename of a program whose exec triggered this catchpoint.
6671 This field is only valid immediately after this catchpoint has
6673 char *exec_pathname
;
6676 /* Implement the "dtor" breakpoint_ops method for exec
6680 dtor_catch_exec (struct breakpoint
*b
)
6682 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6684 xfree (c
->exec_pathname
);
6686 base_breakpoint_ops
.dtor (b
);
6690 insert_catch_exec (struct bp_location
*bl
)
6692 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6696 remove_catch_exec (struct bp_location
*bl
)
6698 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6702 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6703 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6705 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6707 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6710 static enum print_stop_action
6711 print_it_catch_exec (bpstat bs
)
6713 struct breakpoint
*b
= bs
->breakpoint_at
;
6714 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6716 annotate_catchpoint (b
->number
);
6717 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6719 return PRINT_SRC_AND_LOC
;
6723 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6725 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6726 struct value_print_options opts
;
6728 get_user_print_options (&opts
);
6730 /* Field 4, the address, is omitted (which makes the columns
6731 not line up too nicely with the headers, but the effect
6732 is relatively readable). */
6733 if (opts
.addressprint
)
6734 ui_out_field_skip (uiout
, "addr");
6736 ui_out_text (uiout
, "exec");
6737 if (c
->exec_pathname
!= NULL
)
6739 ui_out_text (uiout
, ", program \"");
6740 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6741 ui_out_text (uiout
, "\" ");
6746 print_mention_catch_exec (struct breakpoint
*b
)
6748 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6751 /* Implement the "print_recreate" breakpoint_ops method for exec
6755 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6757 fprintf_unfiltered (fp
, "catch exec");
6758 print_recreate_thread (b
, fp
);
6761 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6764 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6765 struct breakpoint_ops
*ops
)
6767 struct syscall_catchpoint
*c
;
6768 struct gdbarch
*gdbarch
= get_current_arch ();
6770 c
= XNEW (struct syscall_catchpoint
);
6771 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6772 c
->syscalls_to_be_caught
= filter
;
6774 install_breakpoint (0, &c
->base
);
6778 hw_breakpoint_used_count (void)
6781 struct breakpoint
*b
;
6782 struct bp_location
*bl
;
6786 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6787 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6789 /* Special types of hardware breakpoints may use more than
6791 i
+= b
->ops
->resources_needed (bl
);
6799 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6802 struct breakpoint
*b
;
6803 struct bp_location
*bl
;
6805 *other_type_used
= 0;
6808 if (!breakpoint_enabled (b
))
6811 if (b
->type
== type
)
6812 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6814 /* Special types of hardware watchpoints may use more than
6816 i
+= b
->ops
->resources_needed (bl
);
6818 else if (is_hardware_watchpoint (b
))
6819 *other_type_used
= 1;
6826 disable_watchpoints_before_interactive_call_start (void)
6828 struct breakpoint
*b
;
6832 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6834 b
->enable_state
= bp_call_disabled
;
6835 update_global_location_list (0);
6841 enable_watchpoints_after_interactive_call_stop (void)
6843 struct breakpoint
*b
;
6847 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6849 b
->enable_state
= bp_enabled
;
6850 update_global_location_list (1);
6856 disable_breakpoints_before_startup (void)
6858 struct breakpoint
*b
;
6863 if (b
->pspace
!= current_program_space
)
6866 if ((b
->type
== bp_breakpoint
6867 || b
->type
== bp_hardware_breakpoint
)
6868 && breakpoint_enabled (b
))
6870 b
->enable_state
= bp_startup_disabled
;
6876 update_global_location_list (0);
6878 current_program_space
->executing_startup
= 1;
6882 enable_breakpoints_after_startup (void)
6884 struct breakpoint
*b
;
6887 current_program_space
->executing_startup
= 0;
6891 if (b
->pspace
!= current_program_space
)
6894 if ((b
->type
== bp_breakpoint
6895 || b
->type
== bp_hardware_breakpoint
)
6896 && b
->enable_state
== bp_startup_disabled
)
6898 b
->enable_state
= bp_enabled
;
6904 breakpoint_re_set ();
6908 /* Set a breakpoint that will evaporate an end of command
6909 at address specified by SAL.
6910 Restrict it to frame FRAME if FRAME is nonzero. */
6913 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6914 struct frame_id frame_id
, enum bptype type
)
6916 struct breakpoint
*b
;
6918 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6920 gdb_assert (!frame_id_inlined_p (frame_id
));
6922 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
6923 b
->enable_state
= bp_enabled
;
6924 b
->disposition
= disp_donttouch
;
6925 b
->frame_id
= frame_id
;
6927 /* If we're debugging a multi-threaded program, then we want
6928 momentary breakpoints to be active in only a single thread of
6930 if (in_thread_list (inferior_ptid
))
6931 b
->thread
= pid_to_thread_id (inferior_ptid
);
6933 update_global_location_list_nothrow (1);
6938 /* Make a momentary breakpoint based on the master breakpoint ORIG.
6939 The new breakpoint will have type TYPE, and use OPS as it
6942 static struct breakpoint
*
6943 momentary_breakpoint_from_master (struct breakpoint
*orig
,
6945 struct breakpoint_ops
*ops
)
6947 struct breakpoint
*copy
;
6949 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
6950 copy
->loc
= allocate_bp_location (copy
);
6951 set_breakpoint_location_function (copy
->loc
, 1);
6953 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6954 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6955 copy
->loc
->address
= orig
->loc
->address
;
6956 copy
->loc
->section
= orig
->loc
->section
;
6957 copy
->loc
->pspace
= orig
->loc
->pspace
;
6959 if (orig
->source_file
== NULL
)
6960 copy
->source_file
= NULL
;
6962 copy
->source_file
= xstrdup (orig
->source_file
);
6964 copy
->line_number
= orig
->line_number
;
6965 copy
->frame_id
= orig
->frame_id
;
6966 copy
->thread
= orig
->thread
;
6967 copy
->pspace
= orig
->pspace
;
6969 copy
->enable_state
= bp_enabled
;
6970 copy
->disposition
= disp_donttouch
;
6971 copy
->number
= internal_breakpoint_number
--;
6973 update_global_location_list_nothrow (0);
6977 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6981 clone_momentary_breakpoint (struct breakpoint
*orig
)
6983 /* If there's nothing to clone, then return nothing. */
6987 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
6991 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6994 struct symtab_and_line sal
;
6996 sal
= find_pc_line (pc
, 0);
6998 sal
.section
= find_pc_overlay (pc
);
6999 sal
.explicit_pc
= 1;
7001 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7005 /* Tell the user we have just set a breakpoint B. */
7008 mention (struct breakpoint
*b
)
7010 b
->ops
->print_mention (b
);
7011 if (ui_out_is_mi_like_p (uiout
))
7013 printf_filtered ("\n");
7017 static struct bp_location
*
7018 add_location_to_breakpoint (struct breakpoint
*b
,
7019 const struct symtab_and_line
*sal
)
7021 struct bp_location
*loc
, **tmp
;
7023 loc
= allocate_bp_location (b
);
7024 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7027 loc
->gdbarch
= get_sal_arch (*sal
);
7029 loc
->gdbarch
= b
->gdbarch
;
7030 loc
->requested_address
= sal
->pc
;
7031 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7032 loc
->requested_address
, b
->type
);
7033 loc
->pspace
= sal
->pspace
;
7034 gdb_assert (loc
->pspace
!= NULL
);
7035 loc
->section
= sal
->section
;
7037 set_breakpoint_location_function (loc
,
7038 sal
->explicit_pc
|| sal
->explicit_line
);
7043 /* Return 1 if LOC is pointing to a permanent breakpoint,
7044 return 0 otherwise. */
7047 bp_loc_is_permanent (struct bp_location
*loc
)
7051 const gdb_byte
*brk
;
7052 gdb_byte
*target_mem
;
7053 struct cleanup
*cleanup
;
7056 gdb_assert (loc
!= NULL
);
7058 addr
= loc
->address
;
7059 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7061 /* Software breakpoints unsupported? */
7065 target_mem
= alloca (len
);
7067 /* Enable the automatic memory restoration from breakpoints while
7068 we read the memory. Otherwise we could say about our temporary
7069 breakpoints they are permanent. */
7070 cleanup
= save_current_space_and_thread ();
7072 switch_to_program_space_and_thread (loc
->pspace
);
7073 make_show_memory_breakpoints_cleanup (0);
7075 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7076 && memcmp (target_mem
, brk
, len
) == 0)
7079 do_cleanups (cleanup
);
7086 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7087 as textual description of the location, and COND_STRING
7088 as condition expression. */
7091 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7092 struct symtabs_and_lines sals
, char *addr_string
,
7094 enum bptype type
, enum bpdisp disposition
,
7095 int thread
, int task
, int ignore_count
,
7096 struct breakpoint_ops
*ops
, int from_tty
,
7097 int enabled
, int internal
, int display_canonical
)
7101 if (type
== bp_hardware_breakpoint
)
7103 int i
= hw_breakpoint_used_count ();
7104 int target_resources_ok
=
7105 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7107 if (target_resources_ok
== 0)
7108 error (_("No hardware breakpoint support in the target."));
7109 else if (target_resources_ok
< 0)
7110 error (_("Hardware breakpoints used exceeds limit."));
7113 gdb_assert (sals
.nelts
> 0);
7115 for (i
= 0; i
< sals
.nelts
; ++i
)
7117 struct symtab_and_line sal
= sals
.sals
[i
];
7118 struct bp_location
*loc
;
7122 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7124 loc_gdbarch
= gdbarch
;
7126 describe_other_breakpoints (loc_gdbarch
,
7127 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7132 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7136 b
->cond_string
= cond_string
;
7137 b
->ignore_count
= ignore_count
;
7138 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7139 b
->disposition
= disposition
;
7140 b
->pspace
= sals
.sals
[0].pspace
;
7142 if (type
== bp_static_tracepoint
)
7144 struct tracepoint
*t
= (struct tracepoint
*) b
;
7145 struct static_tracepoint_marker marker
;
7147 if (is_marker_spec (addr_string
))
7149 /* We already know the marker exists, otherwise, we
7150 wouldn't see a sal for it. */
7151 char *p
= &addr_string
[3];
7156 p
= skip_spaces (p
);
7158 endp
= skip_to_space (p
);
7160 marker_str
= savestring (p
, endp
- p
);
7161 t
->static_trace_marker_id
= marker_str
;
7163 printf_filtered (_("Probed static tracepoint "
7165 t
->static_trace_marker_id
);
7167 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7169 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7170 release_static_tracepoint_marker (&marker
);
7172 printf_filtered (_("Probed static tracepoint "
7174 t
->static_trace_marker_id
);
7177 warning (_("Couldn't determine the static "
7178 "tracepoint marker to probe"));
7181 if (enabled
&& b
->pspace
->executing_startup
7182 && (b
->type
== bp_breakpoint
7183 || b
->type
== bp_hardware_breakpoint
))
7184 b
->enable_state
= bp_startup_disabled
;
7190 loc
= add_location_to_breakpoint (b
, &sal
);
7193 if (bp_loc_is_permanent (loc
))
7194 make_breakpoint_permanent (b
);
7198 char *arg
= b
->cond_string
;
7199 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7201 error (_("Garbage %s follows condition"), arg
);
7205 b
->display_canonical
= display_canonical
;
7207 b
->addr_string
= addr_string
;
7209 /* addr_string has to be used or breakpoint_re_set will delete
7212 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7216 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7217 struct symtabs_and_lines sals
, char *addr_string
,
7219 enum bptype type
, enum bpdisp disposition
,
7220 int thread
, int task
, int ignore_count
,
7221 struct breakpoint_ops
*ops
, int from_tty
,
7222 int enabled
, int internal
, int display_canonical
)
7224 struct breakpoint
*b
;
7225 struct cleanup
*old_chain
;
7227 if (is_tracepoint_type (type
))
7229 struct tracepoint
*t
;
7231 t
= XCNEW (struct tracepoint
);
7235 b
= XNEW (struct breakpoint
);
7237 old_chain
= make_cleanup (xfree
, b
);
7239 init_breakpoint_sal (b
, gdbarch
,
7243 thread
, task
, ignore_count
,
7245 enabled
, internal
, display_canonical
);
7246 discard_cleanups (old_chain
);
7248 install_breakpoint (internal
, b
);
7251 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7252 elements to fill the void space. */
7254 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7256 int i
= index_to_remove
+1;
7257 int last_index
= sal
->nelts
-1;
7259 for (;i
<= last_index
; ++i
)
7260 sal
->sals
[i
-1] = sal
->sals
[i
];
7265 /* If appropriate, obtains all sals that correspond to the same file
7266 and line as SAL, in all program spaces. Users debugging with IDEs,
7267 will want to set a breakpoint at foo.c:line, and not really care
7268 about program spaces. This is done only if SAL does not have
7269 explicit PC and has line and file information. If we got just a
7270 single expanded sal, return the original.
7272 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7273 which the name of enclosing function is different from SAL. This
7274 makes sure that if we have breakpoint originally set in template
7275 instantiation, say foo<int>(), we won't expand SAL to locations at
7276 the same line in all existing instantiations of 'foo'. */
7278 static struct symtabs_and_lines
7279 expand_line_sal_maybe (struct symtab_and_line sal
)
7281 struct symtabs_and_lines expanded
;
7282 CORE_ADDR original_pc
= sal
.pc
;
7283 char *original_function
= NULL
;
7286 struct cleanup
*old_chain
;
7288 /* If we have explicit pc, don't expand.
7289 If we have no line number, we can't expand. */
7290 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7293 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7294 expanded
.sals
[0] = sal
;
7300 old_chain
= save_current_space_and_thread ();
7302 switch_to_program_space_and_thread (sal
.pspace
);
7304 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7306 /* Note that expand_line_sal visits *all* program spaces. */
7307 expanded
= expand_line_sal (sal
);
7309 if (expanded
.nelts
== 1)
7311 /* We had one sal, we got one sal. Return that sal, adjusting it
7312 past the function prologue if necessary. */
7313 xfree (expanded
.sals
);
7315 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7316 sal
.pc
= original_pc
;
7317 expanded
.sals
[0] = sal
;
7318 skip_prologue_sal (&expanded
.sals
[0]);
7319 do_cleanups (old_chain
);
7323 if (!sal
.explicit_line
)
7325 CORE_ADDR func_addr
, func_end
;
7326 for (i
= 0; i
< expanded
.nelts
; ++i
)
7328 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7329 char *this_function
;
7331 /* We need to switch threads as well since we're about to
7333 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7335 if (find_pc_partial_function (pc
, &this_function
,
7336 &func_addr
, &func_end
))
7339 && strcmp (this_function
, original_function
) != 0)
7341 remove_sal (&expanded
, i
);
7348 /* Skip the function prologue if necessary. */
7349 for (i
= 0; i
< expanded
.nelts
; ++i
)
7350 skip_prologue_sal (&expanded
.sals
[i
]);
7352 do_cleanups (old_chain
);
7354 if (expanded
.nelts
<= 1)
7356 /* This is an ugly workaround. If we get zero expanded sals
7357 then something is really wrong. Fix that by returning the
7360 xfree (expanded
.sals
);
7362 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7363 sal
.pc
= original_pc
;
7364 expanded
.sals
[0] = sal
;
7371 for (i
= 0; i
< expanded
.nelts
; ++i
)
7372 if (expanded
.sals
[i
].pc
== original_pc
)
7383 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7384 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7385 value. COND_STRING, if not NULL, specified the condition to be
7386 used for all breakpoints. Essentially the only case where
7387 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7388 function. In that case, it's still not possible to specify
7389 separate conditions for different overloaded functions, so
7390 we take just a single condition string.
7392 NOTE: If the function succeeds, the caller is expected to cleanup
7393 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7394 array contents). If the function fails (error() is called), the
7395 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7396 COND and SALS arrays and each of those arrays contents. */
7399 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7400 struct symtabs_and_lines sals
,
7401 struct linespec_result
*canonical
,
7403 enum bptype type
, enum bpdisp disposition
,
7404 int thread
, int task
, int ignore_count
,
7405 struct breakpoint_ops
*ops
, int from_tty
,
7406 int enabled
, int internal
)
7410 for (i
= 0; i
< sals
.nelts
; ++i
)
7412 struct symtabs_and_lines expanded
=
7413 expand_line_sal_maybe (sals
.sals
[i
]);
7415 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7416 cond_string
, type
, disposition
,
7417 thread
, task
, ignore_count
, ops
,
7418 from_tty
, enabled
, internal
,
7419 canonical
->special_display
);
7423 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7424 followed by conditionals. On return, SALS contains an array of SAL
7425 addresses found. ADDR_STRING contains a vector of (canonical)
7426 address strings. ADDRESS points to the end of the SAL.
7428 The array and the line spec strings are allocated on the heap, it is
7429 the caller's responsibility to free them. */
7432 parse_breakpoint_sals (char **address
,
7433 struct symtabs_and_lines
*sals
,
7434 struct linespec_result
*canonical
)
7436 char *addr_start
= *address
;
7438 /* If no arg given, or if first arg is 'if ', use the default
7440 if ((*address
) == NULL
7441 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7443 if (default_breakpoint_valid
)
7445 struct symtab_and_line sal
;
7447 init_sal (&sal
); /* Initialize to zeroes. */
7448 sals
->sals
= (struct symtab_and_line
*)
7449 xmalloc (sizeof (struct symtab_and_line
));
7450 sal
.pc
= default_breakpoint_address
;
7451 sal
.line
= default_breakpoint_line
;
7452 sal
.symtab
= default_breakpoint_symtab
;
7453 sal
.pspace
= default_breakpoint_pspace
;
7454 sal
.section
= find_pc_overlay (sal
.pc
);
7456 /* "break" without arguments is equivalent to "break *PC"
7457 where PC is the default_breakpoint_address. So make sure
7458 to set sal.explicit_pc to prevent GDB from trying to
7459 expand the list of sals to include all other instances
7460 with the same symtab and line. */
7461 sal
.explicit_pc
= 1;
7463 sals
->sals
[0] = sal
;
7467 error (_("No default breakpoint address now."));
7471 /* Force almost all breakpoints to be in terms of the
7472 current_source_symtab (which is decode_line_1's default).
7473 This should produce the results we want almost all of the
7474 time while leaving default_breakpoint_* alone.
7476 ObjC: However, don't match an Objective-C method name which
7477 may have a '+' or '-' succeeded by a '[' */
7479 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7481 if (default_breakpoint_valid
7483 || ((strchr ("+-", (*address
)[0]) != NULL
)
7484 && ((*address
)[1] != '['))))
7485 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7486 default_breakpoint_line
, canonical
);
7488 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7491 /* For any SAL that didn't have a canonical string, fill one in. */
7492 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7493 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7494 if (addr_start
!= (*address
))
7498 for (i
= 0; i
< sals
->nelts
; i
++)
7500 /* Add the string if not present. */
7501 if (canonical
->canonical
[i
] == NULL
)
7502 canonical
->canonical
[i
] = savestring (addr_start
,
7503 (*address
) - addr_start
);
7509 /* Convert each SAL into a real PC. Verify that the PC can be
7510 inserted as a breakpoint. If it can't throw an error. */
7513 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7517 for (i
= 0; i
< sals
->nelts
; i
++)
7518 resolve_sal_pc (&sals
->sals
[i
]);
7521 /* Fast tracepoints may have restrictions on valid locations. For
7522 instance, a fast tracepoint using a jump instead of a trap will
7523 likely have to overwrite more bytes than a trap would, and so can
7524 only be placed where the instruction is longer than the jump, or a
7525 multi-instruction sequence does not have a jump into the middle of
7529 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7530 struct symtabs_and_lines
*sals
)
7533 struct symtab_and_line
*sal
;
7535 struct cleanup
*old_chain
;
7537 for (i
= 0; i
< sals
->nelts
; i
++)
7539 sal
= &sals
->sals
[i
];
7541 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7543 old_chain
= make_cleanup (xfree
, msg
);
7546 error (_("May not have a fast tracepoint at 0x%s%s"),
7547 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7549 do_cleanups (old_chain
);
7553 /* Given TOK, a string specification of condition and thread, as
7554 accepted by the 'break' command, extract the condition
7555 string and thread number and set *COND_STRING and *THREAD.
7556 PC identifies the context at which the condition should be parsed.
7557 If no condition is found, *COND_STRING is set to NULL.
7558 If no thread is found, *THREAD is set to -1. */
7560 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7561 char **cond_string
, int *thread
, int *task
)
7563 *cond_string
= NULL
;
7569 char *cond_start
= NULL
;
7570 char *cond_end
= NULL
;
7572 tok
= skip_spaces (tok
);
7574 end_tok
= skip_to_space (tok
);
7576 toklen
= end_tok
- tok
;
7578 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7580 struct expression
*expr
;
7582 tok
= cond_start
= end_tok
+ 1;
7583 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7586 *cond_string
= savestring (cond_start
,
7587 cond_end
- cond_start
);
7589 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7595 *thread
= strtol (tok
, &tok
, 0);
7597 error (_("Junk after thread keyword."));
7598 if (!valid_thread_id (*thread
))
7599 error (_("Unknown thread %d."), *thread
);
7601 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7607 *task
= strtol (tok
, &tok
, 0);
7609 error (_("Junk after task keyword."));
7610 if (!valid_task_id (*task
))
7611 error (_("Unknown task %d."), *task
);
7614 error (_("Junk at end of arguments."));
7618 /* Decode a static tracepoint marker spec. */
7620 static struct symtabs_and_lines
7621 decode_static_tracepoint_spec (char **arg_p
)
7623 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7624 struct symtabs_and_lines sals
;
7625 struct symtab_and_line sal
;
7627 struct cleanup
*old_chain
;
7628 char *p
= &(*arg_p
)[3];
7633 p
= skip_spaces (p
);
7635 endp
= skip_to_space (p
);
7637 marker_str
= savestring (p
, endp
- p
);
7638 old_chain
= make_cleanup (xfree
, marker_str
);
7640 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7641 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7642 error (_("No known static tracepoint marker named %s"), marker_str
);
7644 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7645 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7647 for (i
= 0; i
< sals
.nelts
; i
++)
7649 struct static_tracepoint_marker
*marker
;
7651 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7653 init_sal (&sals
.sals
[i
]);
7655 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7656 sals
.sals
[i
].pc
= marker
->address
;
7658 release_static_tracepoint_marker (marker
);
7661 do_cleanups (old_chain
);
7667 /* Set a breakpoint. This function is shared between CLI and MI
7668 functions for setting a breakpoint. This function has two major
7669 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7670 parameter. If non-zero, the function will parse arg, extracting
7671 breakpoint location, address and thread. Otherwise, ARG is just
7672 the location of breakpoint, with condition and thread specified by
7673 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7674 the breakpoint number will be allocated from the internal
7675 breakpoint count. Returns true if any breakpoint was created;
7679 create_breakpoint (struct gdbarch
*gdbarch
,
7680 char *arg
, char *cond_string
, int thread
,
7681 int parse_condition_and_thread
,
7682 int tempflag
, enum bptype type_wanted
,
7684 enum auto_boolean pending_break_support
,
7685 struct breakpoint_ops
*ops
,
7686 int from_tty
, int enabled
, int internal
)
7688 volatile struct gdb_exception e
;
7689 struct symtabs_and_lines sals
;
7690 struct symtab_and_line pending_sal
;
7692 char *addr_start
= arg
;
7693 struct linespec_result canonical
;
7694 struct cleanup
*old_chain
;
7695 struct cleanup
*bkpt_chain
= NULL
;
7699 int prev_bkpt_count
= breakpoint_count
;
7701 gdb_assert (ops
!= NULL
);
7705 init_linespec_result (&canonical
);
7707 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7711 sals
= decode_static_tracepoint_spec (&arg
);
7713 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7714 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7715 for (i
= 0; i
< sals
.nelts
; i
++)
7716 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7720 TRY_CATCH (e
, RETURN_MASK_ALL
)
7722 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7725 /* If caller is interested in rc value from parse, set value. */
7729 throw_exception (e
);
7733 case NOT_FOUND_ERROR
:
7735 /* If pending breakpoint support is turned off, throw
7738 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7739 throw_exception (e
);
7741 exception_print (gdb_stderr
, e
);
7743 /* If pending breakpoint support is auto query and the user
7744 selects no, then simply return the error code. */
7745 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7746 && !nquery (_("Make breakpoint pending on "
7747 "future shared library load? ")))
7750 /* At this point, either the user was queried about setting
7751 a pending breakpoint and selected yes, or pending
7752 breakpoint behavior is on and thus a pending breakpoint
7753 is defaulted on behalf of the user. */
7754 copy_arg
= xstrdup (addr_start
);
7755 canonical
.canonical
= ©_arg
;
7757 sals
.sals
= &pending_sal
;
7762 throw_exception (e
);
7772 /* Create a chain of things that always need to be cleaned up. */
7773 old_chain
= make_cleanup (null_cleanup
, 0);
7777 /* Make sure that all storage allocated to SALS gets freed. */
7778 make_cleanup (xfree
, sals
.sals
);
7780 /* Cleanup the canonical array but not its contents. */
7781 make_cleanup (xfree
, canonical
.canonical
);
7784 /* ----------------------------- SNIP -----------------------------
7785 Anything added to the cleanup chain beyond this point is assumed
7786 to be part of a breakpoint. If the breakpoint create succeeds
7787 then the memory is not reclaimed. */
7788 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7790 /* Mark the contents of the canonical for cleanup. These go on
7791 the bkpt_chain and only occur if the breakpoint create fails. */
7792 for (i
= 0; i
< sals
.nelts
; i
++)
7794 if (canonical
.canonical
[i
] != NULL
)
7795 make_cleanup (xfree
, canonical
.canonical
[i
]);
7798 /* Resolve all line numbers to PC's and verify that the addresses
7799 are ok for the target. */
7801 breakpoint_sals_to_pc (&sals
);
7803 /* Fast tracepoints may have additional restrictions on location. */
7804 if (type_wanted
== bp_fast_tracepoint
)
7805 check_fast_tracepoint_sals (gdbarch
, &sals
);
7807 /* Verify that condition can be parsed, before setting any
7808 breakpoints. Allocate a separate condition expression for each
7812 if (parse_condition_and_thread
)
7814 /* Here we only parse 'arg' to separate condition
7815 from thread number, so parsing in context of first
7816 sal is OK. When setting the breakpoint we'll
7817 re-parse it in context of each sal. */
7820 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7823 make_cleanup (xfree
, cond_string
);
7827 /* Create a private copy of condition string. */
7830 cond_string
= xstrdup (cond_string
);
7831 make_cleanup (xfree
, cond_string
);
7835 /* If the user is creating a static tracepoint by marker id
7836 (strace -m MARKER_ID), then store the sals index, so that
7837 breakpoint_re_set can try to match up which of the newly
7838 found markers corresponds to this one, and, don't try to
7839 expand multiple locations for each sal, given than SALS
7840 already should contain all sals for MARKER_ID. */
7841 if (type_wanted
== bp_static_tracepoint
7842 && is_marker_spec (canonical
.canonical
[0]))
7846 for (i
= 0; i
< sals
.nelts
; ++i
)
7848 struct symtabs_and_lines expanded
;
7849 struct tracepoint
*tp
;
7850 struct cleanup
*old_chain
;
7853 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7854 expanded
.sals
[0] = sals
.sals
[i
];
7855 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7857 tp
= XCNEW (struct tracepoint
);
7858 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
7859 canonical
.canonical
[i
],
7860 cond_string
, type_wanted
,
7861 tempflag
? disp_del
: disp_donttouch
,
7862 thread
, task
, ignore_count
, ops
,
7863 from_tty
, enabled
, internal
,
7864 canonical
.special_display
);
7865 /* Given that its possible to have multiple markers with
7866 the same string id, if the user is creating a static
7867 tracepoint by marker id ("strace -m MARKER_ID"), then
7868 store the sals index, so that breakpoint_re_set can
7869 try to match up which of the newly found markers
7870 corresponds to this one */
7871 tp
->static_trace_marker_id_idx
= i
;
7873 install_breakpoint (internal
, &tp
->base
);
7875 do_cleanups (old_chain
);
7879 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
7881 tempflag
? disp_del
: disp_donttouch
,
7882 thread
, task
, ignore_count
, ops
, from_tty
,
7887 struct breakpoint
*b
;
7889 make_cleanup (xfree
, copy_arg
);
7891 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
, ops
);
7892 set_breakpoint_number (internal
, b
);
7894 b
->addr_string
= canonical
.canonical
[0];
7895 b
->cond_string
= NULL
;
7896 b
->ignore_count
= ignore_count
;
7897 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7898 b
->condition_not_parsed
= 1;
7899 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7900 b
->pspace
= current_program_space
;
7901 b
->py_bp_object
= NULL
;
7903 if (enabled
&& b
->pspace
->executing_startup
7904 && (b
->type
== bp_breakpoint
7905 || b
->type
== bp_hardware_breakpoint
))
7906 b
->enable_state
= bp_startup_disabled
;
7909 /* Do not mention breakpoints with a negative number,
7910 but do notify observers. */
7912 observer_notify_breakpoint_created (b
);
7917 warning (_("Multiple breakpoints were set.\nUse the "
7918 "\"delete\" command to delete unwanted breakpoints."));
7919 prev_breakpoint_count
= prev_bkpt_count
;
7922 /* That's it. Discard the cleanups for data inserted into the
7924 discard_cleanups (bkpt_chain
);
7925 /* But cleanup everything else. */
7926 do_cleanups (old_chain
);
7928 /* error call may happen here - have BKPT_CHAIN already discarded. */
7929 update_global_location_list (1);
7934 /* Set a breakpoint.
7935 ARG is a string describing breakpoint address,
7936 condition, and thread.
7937 FLAG specifies if a breakpoint is hardware on,
7938 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7942 break_command_1 (char *arg
, int flag
, int from_tty
)
7944 int tempflag
= flag
& BP_TEMPFLAG
;
7945 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7946 ? bp_hardware_breakpoint
7949 create_breakpoint (get_current_arch (),
7951 NULL
, 0, 1 /* parse arg */,
7952 tempflag
, type_wanted
,
7953 0 /* Ignore count */,
7954 pending_break_support
,
7955 &bkpt_breakpoint_ops
,
7961 /* Helper function for break_command_1 and disassemble_command. */
7964 resolve_sal_pc (struct symtab_and_line
*sal
)
7968 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7970 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7971 error (_("No line %d in file \"%s\"."),
7972 sal
->line
, sal
->symtab
->filename
);
7975 /* If this SAL corresponds to a breakpoint inserted using a line
7976 number, then skip the function prologue if necessary. */
7977 if (sal
->explicit_line
)
7978 skip_prologue_sal (sal
);
7981 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7983 struct blockvector
*bv
;
7987 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7990 sym
= block_linkage_function (b
);
7993 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7994 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7998 /* It really is worthwhile to have the section, so we'll
7999 just have to look harder. This case can be executed
8000 if we have line numbers but no functions (as can
8001 happen in assembly source). */
8003 struct minimal_symbol
*msym
;
8004 struct cleanup
*old_chain
= save_current_space_and_thread ();
8006 switch_to_program_space_and_thread (sal
->pspace
);
8008 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8010 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8012 do_cleanups (old_chain
);
8019 break_command (char *arg
, int from_tty
)
8021 break_command_1 (arg
, 0, from_tty
);
8025 tbreak_command (char *arg
, int from_tty
)
8027 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8031 hbreak_command (char *arg
, int from_tty
)
8033 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8037 thbreak_command (char *arg
, int from_tty
)
8039 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8043 stop_command (char *arg
, int from_tty
)
8045 printf_filtered (_("Specify the type of breakpoint to set.\n\
8046 Usage: stop in <function | address>\n\
8047 stop at <line>\n"));
8051 stopin_command (char *arg
, int from_tty
)
8055 if (arg
== (char *) NULL
)
8057 else if (*arg
!= '*')
8062 /* Look for a ':'. If this is a line number specification, then
8063 say it is bad, otherwise, it should be an address or
8064 function/method name. */
8065 while (*argptr
&& !hasColon
)
8067 hasColon
= (*argptr
== ':');
8072 badInput
= (*argptr
!= ':'); /* Not a class::method */
8074 badInput
= isdigit (*arg
); /* a simple line number */
8078 printf_filtered (_("Usage: stop in <function | address>\n"));
8080 break_command_1 (arg
, 0, from_tty
);
8084 stopat_command (char *arg
, int from_tty
)
8088 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8095 /* Look for a ':'. If there is a '::' then get out, otherwise
8096 it is probably a line number. */
8097 while (*argptr
&& !hasColon
)
8099 hasColon
= (*argptr
== ':');
8104 badInput
= (*argptr
== ':'); /* we have class::method */
8106 badInput
= !isdigit (*arg
); /* not a line number */
8110 printf_filtered (_("Usage: stop at <line>\n"));
8112 break_command_1 (arg
, 0, from_tty
);
8115 /* Implement the "breakpoint_hit" breakpoint_ops method for
8116 ranged breakpoints. */
8119 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8120 struct address_space
*aspace
,
8123 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8124 bl
->length
, aspace
, bp_addr
);
8127 /* Implement the "resources_needed" breakpoint_ops method for
8128 ranged breakpoints. */
8131 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8133 return target_ranged_break_num_registers ();
8136 /* Implement the "print_it" breakpoint_ops method for
8137 ranged breakpoints. */
8139 static enum print_stop_action
8140 print_it_ranged_breakpoint (bpstat bs
)
8142 struct breakpoint
*b
= bs
->breakpoint_at
;
8143 struct bp_location
*bl
= b
->loc
;
8145 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8147 /* Ranged breakpoints have only one location. */
8148 gdb_assert (bl
&& bl
->next
== NULL
);
8150 annotate_breakpoint (b
->number
);
8151 if (b
->disposition
== disp_del
)
8152 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8154 ui_out_text (uiout
, "\nRanged breakpoint ");
8155 if (ui_out_is_mi_like_p (uiout
))
8157 ui_out_field_string (uiout
, "reason",
8158 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8159 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8161 ui_out_field_int (uiout
, "bkptno", b
->number
);
8162 ui_out_text (uiout
, ", ");
8164 return PRINT_SRC_AND_LOC
;
8167 /* Implement the "print_one" breakpoint_ops method for
8168 ranged breakpoints. */
8171 print_one_ranged_breakpoint (struct breakpoint
*b
,
8172 struct bp_location
**last_loc
)
8174 struct bp_location
*bl
= b
->loc
;
8175 struct value_print_options opts
;
8177 /* Ranged breakpoints have only one location. */
8178 gdb_assert (bl
&& bl
->next
== NULL
);
8180 get_user_print_options (&opts
);
8182 if (opts
.addressprint
)
8183 /* We don't print the address range here, it will be printed later
8184 by print_one_detail_ranged_breakpoint. */
8185 ui_out_field_skip (uiout
, "addr");
8187 print_breakpoint_location (b
, bl
);
8191 /* Implement the "print_one_detail" breakpoint_ops method for
8192 ranged breakpoints. */
8195 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8196 struct ui_out
*uiout
)
8198 CORE_ADDR address_start
, address_end
;
8199 struct bp_location
*bl
= b
->loc
;
8200 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8201 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8205 address_start
= bl
->address
;
8206 address_end
= address_start
+ bl
->length
- 1;
8208 ui_out_text (uiout
, "\taddress range: ");
8209 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8210 print_core_address (bl
->gdbarch
, address_start
),
8211 print_core_address (bl
->gdbarch
, address_end
));
8212 ui_out_field_stream (uiout
, "addr", stb
);
8213 ui_out_text (uiout
, "\n");
8215 do_cleanups (cleanup
);
8218 /* Implement the "print_mention" breakpoint_ops method for
8219 ranged breakpoints. */
8222 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8224 struct bp_location
*bl
= b
->loc
;
8227 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8229 if (ui_out_is_mi_like_p (uiout
))
8232 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8233 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8234 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8237 /* Implement the "print_recreate" breakpoint_ops method for
8238 ranged breakpoints. */
8241 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8243 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8244 b
->addr_string_range_end
);
8245 print_recreate_thread (b
, fp
);
8248 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8250 static struct breakpoint_ops ranged_breakpoint_ops
;
8252 /* Find the address where the end of the breakpoint range should be
8253 placed, given the SAL of the end of the range. This is so that if
8254 the user provides a line number, the end of the range is set to the
8255 last instruction of the given line. */
8258 find_breakpoint_range_end (struct symtab_and_line sal
)
8262 /* If the user provided a PC value, use it. Otherwise,
8263 find the address of the end of the given location. */
8264 if (sal
.explicit_pc
)
8271 ret
= find_line_pc_range (sal
, &start
, &end
);
8273 error (_("Could not find location of the end of the range."));
8275 /* find_line_pc_range returns the start of the next line. */
8282 /* Implement the "break-range" CLI command. */
8285 break_range_command (char *arg
, int from_tty
)
8287 char *arg_start
, *addr_string_start
, *addr_string_end
;
8288 struct linespec_result canonical_start
, canonical_end
;
8289 int bp_count
, can_use_bp
, length
;
8291 struct breakpoint
*b
;
8292 struct symtab_and_line sal_start
, sal_end
;
8293 struct symtabs_and_lines sals_start
, sals_end
;
8294 struct cleanup
*cleanup_bkpt
;
8296 /* We don't support software ranged breakpoints. */
8297 if (target_ranged_break_num_registers () < 0)
8298 error (_("This target does not support hardware ranged breakpoints."));
8300 bp_count
= hw_breakpoint_used_count ();
8301 bp_count
+= target_ranged_break_num_registers ();
8302 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8305 error (_("Hardware breakpoints used exceeds limit."));
8307 if (arg
== NULL
|| arg
[0] == '\0')
8308 error(_("No address range specified."));
8310 sals_start
.sals
= NULL
;
8311 sals_start
.nelts
= 0;
8312 init_linespec_result (&canonical_start
);
8314 while (*arg
== ' ' || *arg
== '\t')
8317 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8319 sal_start
= sals_start
.sals
[0];
8320 addr_string_start
= canonical_start
.canonical
[0];
8321 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8322 xfree (sals_start
.sals
);
8323 xfree (canonical_start
.canonical
);
8326 error (_("Too few arguments."));
8327 else if (sals_start
.nelts
== 0)
8328 error (_("Could not find location of the beginning of the range."));
8329 else if (sals_start
.nelts
!= 1)
8330 error (_("Cannot create a ranged breakpoint with multiple locations."));
8332 resolve_sal_pc (&sal_start
);
8334 arg
++; /* Skip the comma. */
8335 while (*arg
== ' ' || *arg
== '\t')
8338 /* Parse the end location. */
8340 sals_end
.sals
= NULL
;
8342 init_linespec_result (&canonical_end
);
8345 /* We call decode_line_1 directly here instead of using
8346 parse_breakpoint_sals because we need to specify the start location's
8347 symtab and line as the default symtab and line for the end of the
8348 range. This makes it possible to have ranges like "foo.c:27, +14",
8349 where +14 means 14 lines from the start location. */
8350 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8353 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8354 if (canonical_end
.canonical
== NULL
)
8355 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8356 /* Add the string if not present. */
8357 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8358 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8360 sal_end
= sals_end
.sals
[0];
8361 addr_string_end
= canonical_end
.canonical
[0];
8362 make_cleanup (xfree
, addr_string_end
);
8363 xfree (sals_end
.sals
);
8364 xfree (canonical_end
.canonical
);
8366 if (sals_end
.nelts
== 0)
8367 error (_("Could not find location of the end of the range."));
8368 else if (sals_end
.nelts
!= 1)
8369 error (_("Cannot create a ranged breakpoint with multiple locations."));
8371 resolve_sal_pc (&sal_end
);
8373 end
= find_breakpoint_range_end (sal_end
);
8374 if (sal_start
.pc
> end
)
8375 error (_("Invalid address range, end precedes start."));
8377 length
= end
- sal_start
.pc
+ 1;
8379 /* Length overflowed. */
8380 error (_("Address range too large."));
8381 else if (length
== 1)
8383 /* This range is simple enough to be handled by
8384 the `hbreak' command. */
8385 hbreak_command (addr_string_start
, 1);
8387 do_cleanups (cleanup_bkpt
);
8392 /* Now set up the breakpoint. */
8393 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8394 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8395 set_breakpoint_count (breakpoint_count
+ 1);
8396 b
->number
= breakpoint_count
;
8397 b
->disposition
= disp_donttouch
;
8398 b
->addr_string
= addr_string_start
;
8399 b
->addr_string_range_end
= addr_string_end
;
8400 b
->loc
->length
= length
;
8402 discard_cleanups (cleanup_bkpt
);
8405 observer_notify_breakpoint_created (b
);
8406 update_global_location_list (1);
8409 /* Return non-zero if EXP is verified as constant. Returned zero
8410 means EXP is variable. Also the constant detection may fail for
8411 some constant expressions and in such case still falsely return
8414 watchpoint_exp_is_const (const struct expression
*exp
)
8422 /* We are only interested in the descriptor of each element. */
8423 operator_length (exp
, i
, &oplenp
, &argsp
);
8426 switch (exp
->elts
[i
].opcode
)
8436 case BINOP_LOGICAL_AND
:
8437 case BINOP_LOGICAL_OR
:
8438 case BINOP_BITWISE_AND
:
8439 case BINOP_BITWISE_IOR
:
8440 case BINOP_BITWISE_XOR
:
8442 case BINOP_NOTEQUAL
:
8458 case TERNOP_SLICE_COUNT
:
8470 case OP_OBJC_NSSTRING
:
8473 case UNOP_LOGICAL_NOT
:
8474 case UNOP_COMPLEMENT
:
8477 /* Unary, binary and ternary operators: We have to check
8478 their operands. If they are constant, then so is the
8479 result of that operation. For instance, if A and B are
8480 determined to be constants, then so is "A + B".
8482 UNOP_IND is one exception to the rule above, because the
8483 value of *ADDR is not necessarily a constant, even when
8488 /* Check whether the associated symbol is a constant.
8490 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8491 possible that a buggy compiler could mark a variable as
8492 constant even when it is not, and TYPE_CONST would return
8493 true in this case, while SYMBOL_CLASS wouldn't.
8495 We also have to check for function symbols because they
8496 are always constant. */
8498 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8500 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8501 && SYMBOL_CLASS (s
) != LOC_CONST
8502 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8507 /* The default action is to return 0 because we are using
8508 the optimistic approach here: If we don't know something,
8509 then it is not a constant. */
8518 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8521 dtor_watchpoint (struct breakpoint
*self
)
8523 struct watchpoint
*w
= (struct watchpoint
*) self
;
8525 xfree (w
->cond_exp
);
8527 xfree (w
->exp_string
);
8528 xfree (w
->exp_string_reparse
);
8529 value_free (w
->val
);
8531 base_breakpoint_ops
.dtor (self
);
8534 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8537 re_set_watchpoint (struct breakpoint
*b
)
8539 struct watchpoint
*w
= (struct watchpoint
*) b
;
8541 /* Watchpoint can be either on expression using entirely global
8542 variables, or it can be on local variables.
8544 Watchpoints of the first kind are never auto-deleted, and even
8545 persist across program restarts. Since they can use variables
8546 from shared libraries, we need to reparse expression as libraries
8547 are loaded and unloaded.
8549 Watchpoints on local variables can also change meaning as result
8550 of solib event. For example, if a watchpoint uses both a local
8551 and a global variables in expression, it's a local watchpoint,
8552 but unloading of a shared library will make the expression
8553 invalid. This is not a very common use case, but we still
8554 re-evaluate expression, to avoid surprises to the user.
8556 Note that for local watchpoints, we re-evaluate it only if
8557 watchpoints frame id is still valid. If it's not, it means the
8558 watchpoint is out of scope and will be deleted soon. In fact,
8559 I'm not sure we'll ever be called in this case.
8561 If a local watchpoint's frame id is still valid, then
8562 w->exp_valid_block is likewise valid, and we can safely use it.
8564 Don't do anything about disabled watchpoints, since they will be
8565 reevaluated again when enabled. */
8566 update_watchpoint (w
, 1 /* reparse */);
8569 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8572 insert_watchpoint (struct bp_location
*bl
)
8574 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8575 int length
= w
->exact
? 1 : bl
->length
;
8577 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8581 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8584 remove_watchpoint (struct bp_location
*bl
)
8586 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8587 int length
= w
->exact
? 1 : bl
->length
;
8589 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8594 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8595 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8597 struct breakpoint
*b
= bl
->owner
;
8598 struct watchpoint
*w
= (struct watchpoint
*) b
;
8600 /* Continuable hardware watchpoints are treated as non-existent if the
8601 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8602 some data address). Otherwise gdb won't stop on a break instruction
8603 in the code (not from a breakpoint) when a hardware watchpoint has
8604 been defined. Also skip watchpoints which we know did not trigger
8605 (did not match the data address). */
8606 if (is_hardware_watchpoint (b
)
8607 && w
->watchpoint_triggered
== watch_triggered_no
)
8614 check_status_watchpoint (bpstat bs
)
8616 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8618 bpstat_check_watchpoint (bs
);
8621 /* Implement the "resources_needed" breakpoint_ops method for
8622 hardware watchpoints. */
8625 resources_needed_watchpoint (const struct bp_location
*bl
)
8627 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8628 int length
= w
->exact
? 1 : bl
->length
;
8630 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8633 /* Implement the "works_in_software_mode" breakpoint_ops method for
8634 hardware watchpoints. */
8637 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8639 return b
->type
== bp_hardware_watchpoint
;
8642 static enum print_stop_action
8643 print_it_watchpoint (bpstat bs
)
8645 struct cleanup
*old_chain
;
8646 struct breakpoint
*b
;
8647 const struct bp_location
*bl
;
8648 struct ui_stream
*stb
;
8649 enum print_stop_action result
;
8650 struct watchpoint
*w
;
8652 gdb_assert (bs
->bp_location_at
!= NULL
);
8654 bl
= bs
->bp_location_at
;
8655 b
= bs
->breakpoint_at
;
8656 w
= (struct watchpoint
*) b
;
8658 stb
= ui_out_stream_new (uiout
);
8659 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8664 case bp_hardware_watchpoint
:
8665 annotate_watchpoint (b
->number
);
8666 if (ui_out_is_mi_like_p (uiout
))
8669 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8671 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8672 ui_out_text (uiout
, "\nOld value = ");
8673 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8674 ui_out_field_stream (uiout
, "old", stb
);
8675 ui_out_text (uiout
, "\nNew value = ");
8676 watchpoint_value_print (w
->val
, stb
->stream
);
8677 ui_out_field_stream (uiout
, "new", stb
);
8678 ui_out_text (uiout
, "\n");
8679 /* More than one watchpoint may have been triggered. */
8680 result
= PRINT_UNKNOWN
;
8683 case bp_read_watchpoint
:
8684 if (ui_out_is_mi_like_p (uiout
))
8687 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8689 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8690 ui_out_text (uiout
, "\nValue = ");
8691 watchpoint_value_print (w
->val
, stb
->stream
);
8692 ui_out_field_stream (uiout
, "value", stb
);
8693 ui_out_text (uiout
, "\n");
8694 result
= PRINT_UNKNOWN
;
8697 case bp_access_watchpoint
:
8698 if (bs
->old_val
!= NULL
)
8700 annotate_watchpoint (b
->number
);
8701 if (ui_out_is_mi_like_p (uiout
))
8704 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8706 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8707 ui_out_text (uiout
, "\nOld value = ");
8708 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8709 ui_out_field_stream (uiout
, "old", stb
);
8710 ui_out_text (uiout
, "\nNew value = ");
8715 if (ui_out_is_mi_like_p (uiout
))
8718 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8719 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8720 ui_out_text (uiout
, "\nValue = ");
8722 watchpoint_value_print (w
->val
, stb
->stream
);
8723 ui_out_field_stream (uiout
, "new", stb
);
8724 ui_out_text (uiout
, "\n");
8725 result
= PRINT_UNKNOWN
;
8728 result
= PRINT_UNKNOWN
;
8731 do_cleanups (old_chain
);
8735 /* Implement the "print_mention" breakpoint_ops method for hardware
8739 print_mention_watchpoint (struct breakpoint
*b
)
8741 struct cleanup
*ui_out_chain
;
8742 struct watchpoint
*w
= (struct watchpoint
*) b
;
8747 ui_out_text (uiout
, "Watchpoint ");
8748 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8750 case bp_hardware_watchpoint
:
8751 ui_out_text (uiout
, "Hardware watchpoint ");
8752 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8754 case bp_read_watchpoint
:
8755 ui_out_text (uiout
, "Hardware read watchpoint ");
8756 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8758 case bp_access_watchpoint
:
8759 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8760 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8763 internal_error (__FILE__
, __LINE__
,
8764 _("Invalid hardware watchpoint type."));
8767 ui_out_field_int (uiout
, "number", b
->number
);
8768 ui_out_text (uiout
, ": ");
8769 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8770 do_cleanups (ui_out_chain
);
8773 /* Implement the "print_recreate" breakpoint_ops method for
8777 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8779 struct watchpoint
*w
= (struct watchpoint
*) b
;
8784 case bp_hardware_watchpoint
:
8785 fprintf_unfiltered (fp
, "watch");
8787 case bp_read_watchpoint
:
8788 fprintf_unfiltered (fp
, "rwatch");
8790 case bp_access_watchpoint
:
8791 fprintf_unfiltered (fp
, "awatch");
8794 internal_error (__FILE__
, __LINE__
,
8795 _("Invalid watchpoint type."));
8798 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8799 print_recreate_thread (b
, fp
);
8802 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8804 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8806 /* Implement the "insert" breakpoint_ops method for
8807 masked hardware watchpoints. */
8810 insert_masked_watchpoint (struct bp_location
*bl
)
8812 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8814 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8815 bl
->watchpoint_type
);
8818 /* Implement the "remove" breakpoint_ops method for
8819 masked hardware watchpoints. */
8822 remove_masked_watchpoint (struct bp_location
*bl
)
8824 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8826 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8827 bl
->watchpoint_type
);
8830 /* Implement the "resources_needed" breakpoint_ops method for
8831 masked hardware watchpoints. */
8834 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8836 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8838 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
8841 /* Implement the "works_in_software_mode" breakpoint_ops method for
8842 masked hardware watchpoints. */
8845 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8850 /* Implement the "print_it" breakpoint_ops method for
8851 masked hardware watchpoints. */
8853 static enum print_stop_action
8854 print_it_masked_watchpoint (bpstat bs
)
8856 struct breakpoint
*b
= bs
->breakpoint_at
;
8858 /* Masked watchpoints have only one location. */
8859 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8863 case bp_hardware_watchpoint
:
8864 annotate_watchpoint (b
->number
);
8865 if (ui_out_is_mi_like_p (uiout
))
8868 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8871 case bp_read_watchpoint
:
8872 if (ui_out_is_mi_like_p (uiout
))
8875 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8878 case bp_access_watchpoint
:
8879 if (ui_out_is_mi_like_p (uiout
))
8882 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8885 internal_error (__FILE__
, __LINE__
,
8886 _("Invalid hardware watchpoint type."));
8890 ui_out_text (uiout
, _("\n\
8891 Check the underlying instruction at PC for the memory\n\
8892 address and value which triggered this watchpoint.\n"));
8893 ui_out_text (uiout
, "\n");
8895 /* More than one watchpoint may have been triggered. */
8896 return PRINT_UNKNOWN
;
8899 /* Implement the "print_one_detail" breakpoint_ops method for
8900 masked hardware watchpoints. */
8903 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8904 struct ui_out
*uiout
)
8906 struct watchpoint
*w
= (struct watchpoint
*) b
;
8908 /* Masked watchpoints have only one location. */
8909 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8911 ui_out_text (uiout
, "\tmask ");
8912 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
8913 ui_out_text (uiout
, "\n");
8916 /* Implement the "print_mention" breakpoint_ops method for
8917 masked hardware watchpoints. */
8920 print_mention_masked_watchpoint (struct breakpoint
*b
)
8922 struct watchpoint
*w
= (struct watchpoint
*) b
;
8923 struct cleanup
*ui_out_chain
;
8927 case bp_hardware_watchpoint
:
8928 ui_out_text (uiout
, "Masked hardware watchpoint ");
8929 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8931 case bp_read_watchpoint
:
8932 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8933 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8935 case bp_access_watchpoint
:
8936 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8937 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8940 internal_error (__FILE__
, __LINE__
,
8941 _("Invalid hardware watchpoint type."));
8944 ui_out_field_int (uiout
, "number", b
->number
);
8945 ui_out_text (uiout
, ": ");
8946 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8947 do_cleanups (ui_out_chain
);
8950 /* Implement the "print_recreate" breakpoint_ops method for
8951 masked hardware watchpoints. */
8954 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8956 struct watchpoint
*w
= (struct watchpoint
*) b
;
8961 case bp_hardware_watchpoint
:
8962 fprintf_unfiltered (fp
, "watch");
8964 case bp_read_watchpoint
:
8965 fprintf_unfiltered (fp
, "rwatch");
8967 case bp_access_watchpoint
:
8968 fprintf_unfiltered (fp
, "awatch");
8971 internal_error (__FILE__
, __LINE__
,
8972 _("Invalid hardware watchpoint type."));
8975 sprintf_vma (tmp
, w
->hw_wp_mask
);
8976 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
8977 print_recreate_thread (b
, fp
);
8980 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
8982 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
8984 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
8987 is_masked_watchpoint (const struct breakpoint
*b
)
8989 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
8992 /* accessflag: hw_write: watch write,
8993 hw_read: watch read,
8994 hw_access: watch access (read or write) */
8996 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8997 int just_location
, int internal
)
8999 volatile struct gdb_exception e
;
9000 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9001 struct expression
*exp
;
9002 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9003 struct value
*val
, *mark
, *result
;
9004 struct frame_info
*frame
;
9005 char *exp_start
= NULL
;
9006 char *exp_end
= NULL
;
9007 char *tok
, *end_tok
;
9009 char *cond_start
= NULL
;
9010 char *cond_end
= NULL
;
9011 enum bptype bp_type
;
9014 /* Flag to indicate whether we are going to use masks for
9015 the hardware watchpoint. */
9018 struct watchpoint
*w
;
9020 /* Make sure that we actually have parameters to parse. */
9021 if (arg
!= NULL
&& arg
[0] != '\0')
9025 /* Look for "parameter value" pairs at the end
9026 of the arguments string. */
9027 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9029 /* Skip whitespace at the end of the argument list. */
9030 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9033 /* Find the beginning of the last token.
9034 This is the value of the parameter. */
9035 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9037 value_start
= tok
+ 1;
9039 /* Skip whitespace. */
9040 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9045 /* Find the beginning of the second to last token.
9046 This is the parameter itself. */
9047 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9050 toklen
= end_tok
- tok
+ 1;
9052 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9054 /* At this point we've found a "thread" token, which means
9055 the user is trying to set a watchpoint that triggers
9056 only in a specific thread. */
9060 error(_("You can specify only one thread."));
9062 /* Extract the thread ID from the next token. */
9063 thread
= strtol (value_start
, &endp
, 0);
9065 /* Check if the user provided a valid numeric value for the
9067 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9068 error (_("Invalid thread ID specification %s."), value_start
);
9070 /* Check if the thread actually exists. */
9071 if (!valid_thread_id (thread
))
9072 error (_("Unknown thread %d."), thread
);
9074 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9076 /* We've found a "mask" token, which means the user wants to
9077 create a hardware watchpoint that is going to have the mask
9079 struct value
*mask_value
, *mark
;
9082 error(_("You can specify only one mask."));
9084 use_mask
= just_location
= 1;
9086 mark
= value_mark ();
9087 mask_value
= parse_to_comma_and_eval (&value_start
);
9088 mask
= value_as_address (mask_value
);
9089 value_free_to_mark (mark
);
9092 /* We didn't recognize what we found. We should stop here. */
9095 /* Truncate the string and get rid of the "parameter value" pair before
9096 the arguments string is parsed by the parse_exp_1 function. */
9101 /* Parse the rest of the arguments. */
9102 innermost_block
= NULL
;
9104 exp
= parse_exp_1 (&arg
, 0, 0);
9106 /* Remove trailing whitespace from the expression before saving it.
9107 This makes the eventual display of the expression string a bit
9109 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9112 /* Checking if the expression is not constant. */
9113 if (watchpoint_exp_is_const (exp
))
9117 len
= exp_end
- exp_start
;
9118 while (len
> 0 && isspace (exp_start
[len
- 1]))
9120 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9123 exp_valid_block
= innermost_block
;
9124 mark
= value_mark ();
9125 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9131 exp_valid_block
= NULL
;
9132 val
= value_addr (result
);
9133 release_value (val
);
9134 value_free_to_mark (mark
);
9138 ret
= target_masked_watch_num_registers (value_as_address (val
),
9141 error (_("This target does not support masked watchpoints."));
9143 error (_("Invalid mask or memory region."));
9146 else if (val
!= NULL
)
9147 release_value (val
);
9149 tok
= skip_spaces (arg
);
9150 end_tok
= skip_to_space (tok
);
9152 toklen
= end_tok
- tok
;
9153 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9155 struct expression
*cond
;
9157 innermost_block
= NULL
;
9158 tok
= cond_start
= end_tok
+ 1;
9159 cond
= parse_exp_1 (&tok
, 0, 0);
9161 /* The watchpoint expression may not be local, but the condition
9162 may still be. E.g.: `watch global if local > 0'. */
9163 cond_exp_valid_block
= innermost_block
;
9169 error (_("Junk at end of command."));
9171 if (accessflag
== hw_read
)
9172 bp_type
= bp_read_watchpoint
;
9173 else if (accessflag
== hw_access
)
9174 bp_type
= bp_access_watchpoint
;
9176 bp_type
= bp_hardware_watchpoint
;
9178 frame
= block_innermost_frame (exp_valid_block
);
9180 /* If the expression is "local", then set up a "watchpoint scope"
9181 breakpoint at the point where we've left the scope of the watchpoint
9182 expression. Create the scope breakpoint before the watchpoint, so
9183 that we will encounter it first in bpstat_stop_status. */
9184 if (exp_valid_block
&& frame
)
9186 if (frame_id_p (frame_unwind_caller_id (frame
)))
9189 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9190 frame_unwind_caller_pc (frame
),
9191 bp_watchpoint_scope
,
9192 &momentary_breakpoint_ops
);
9194 scope_breakpoint
->enable_state
= bp_enabled
;
9196 /* Automatically delete the breakpoint when it hits. */
9197 scope_breakpoint
->disposition
= disp_del
;
9199 /* Only break in the proper frame (help with recursion). */
9200 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9202 /* Set the address at which we will stop. */
9203 scope_breakpoint
->loc
->gdbarch
9204 = frame_unwind_caller_arch (frame
);
9205 scope_breakpoint
->loc
->requested_address
9206 = frame_unwind_caller_pc (frame
);
9207 scope_breakpoint
->loc
->address
9208 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9209 scope_breakpoint
->loc
->requested_address
,
9210 scope_breakpoint
->type
);
9214 /* Now set up the breakpoint. */
9216 w
= XCNEW (struct watchpoint
);
9219 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9220 &masked_watchpoint_breakpoint_ops
);
9222 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9223 &watchpoint_breakpoint_ops
);
9225 b
->disposition
= disp_donttouch
;
9226 b
->pspace
= current_program_space
;
9228 w
->exp_valid_block
= exp_valid_block
;
9229 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9232 struct type
*t
= value_type (val
);
9233 CORE_ADDR addr
= value_as_address (val
);
9236 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9237 name
= type_to_string (t
);
9239 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9240 core_addr_to_string (addr
));
9243 w
->exp_string
= xstrprintf ("-location %.*s",
9244 (int) (exp_end
- exp_start
), exp_start
);
9246 /* The above expression is in C. */
9247 b
->language
= language_c
;
9250 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9254 w
->hw_wp_mask
= mask
;
9263 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9269 w
->watchpoint_frame
= get_frame_id (frame
);
9270 w
->watchpoint_thread
= inferior_ptid
;
9274 w
->watchpoint_frame
= null_frame_id
;
9275 w
->watchpoint_thread
= null_ptid
;
9278 if (scope_breakpoint
!= NULL
)
9280 /* The scope breakpoint is related to the watchpoint. We will
9281 need to act on them together. */
9282 b
->related_breakpoint
= scope_breakpoint
;
9283 scope_breakpoint
->related_breakpoint
= b
;
9287 value_free_to_mark (mark
);
9289 TRY_CATCH (e
, RETURN_MASK_ALL
)
9291 /* Finally update the new watchpoint. This creates the locations
9292 that should be inserted. */
9293 update_watchpoint (w
, 1);
9297 delete_breakpoint (b
);
9298 throw_exception (e
);
9301 install_breakpoint (internal
, b
);
9304 /* Return count of debug registers needed to watch the given expression.
9305 If the watchpoint cannot be handled in hardware return zero. */
9308 can_use_hardware_watchpoint (struct value
*v
)
9310 int found_memory_cnt
= 0;
9311 struct value
*head
= v
;
9313 /* Did the user specifically forbid us to use hardware watchpoints? */
9314 if (!can_use_hw_watchpoints
)
9317 /* Make sure that the value of the expression depends only upon
9318 memory contents, and values computed from them within GDB. If we
9319 find any register references or function calls, we can't use a
9320 hardware watchpoint.
9322 The idea here is that evaluating an expression generates a series
9323 of values, one holding the value of every subexpression. (The
9324 expression a*b+c has five subexpressions: a, b, a*b, c, and
9325 a*b+c.) GDB's values hold almost enough information to establish
9326 the criteria given above --- they identify memory lvalues,
9327 register lvalues, computed values, etcetera. So we can evaluate
9328 the expression, and then scan the chain of values that leaves
9329 behind to decide whether we can detect any possible change to the
9330 expression's final value using only hardware watchpoints.
9332 However, I don't think that the values returned by inferior
9333 function calls are special in any way. So this function may not
9334 notice that an expression involving an inferior function call
9335 can't be watched with hardware watchpoints. FIXME. */
9336 for (; v
; v
= value_next (v
))
9338 if (VALUE_LVAL (v
) == lval_memory
)
9340 if (v
!= head
&& value_lazy (v
))
9341 /* A lazy memory lvalue in the chain is one that GDB never
9342 needed to fetch; we either just used its address (e.g.,
9343 `a' in `a.b') or we never needed it at all (e.g., `a'
9344 in `a,b'). This doesn't apply to HEAD; if that is
9345 lazy then it was not readable, but watch it anyway. */
9349 /* Ahh, memory we actually used! Check if we can cover
9350 it with hardware watchpoints. */
9351 struct type
*vtype
= check_typedef (value_type (v
));
9353 /* We only watch structs and arrays if user asked for it
9354 explicitly, never if they just happen to appear in a
9355 middle of some value chain. */
9357 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9358 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9360 CORE_ADDR vaddr
= value_address (v
);
9364 len
= (target_exact_watchpoints
9365 && is_scalar_type_recursive (vtype
))?
9366 1 : TYPE_LENGTH (value_type (v
));
9368 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9372 found_memory_cnt
+= num_regs
;
9376 else if (VALUE_LVAL (v
) != not_lval
9377 && deprecated_value_modifiable (v
) == 0)
9378 return 0; /* These are values from the history (e.g., $1). */
9379 else if (VALUE_LVAL (v
) == lval_register
)
9380 return 0; /* Cannot watch a register with a HW watchpoint. */
9383 /* The expression itself looks suitable for using a hardware
9384 watchpoint, but give the target machine a chance to reject it. */
9385 return found_memory_cnt
;
9389 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9391 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9394 /* A helper function that looks for an argument at the start of a
9395 string. The argument must also either be at the end of the string,
9396 or be followed by whitespace. Returns 1 if it finds the argument,
9397 0 otherwise. If the argument is found, it updates *STR. */
9400 check_for_argument (char **str
, char *arg
, int arg_len
)
9402 if (strncmp (*str
, arg
, arg_len
) == 0
9403 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9411 /* A helper function that looks for the "-location" argument and then
9412 calls watch_command_1. */
9415 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9417 int just_location
= 0;
9420 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9421 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9423 arg
= skip_spaces (arg
);
9427 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9431 watch_command (char *arg
, int from_tty
)
9433 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9437 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9439 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9443 rwatch_command (char *arg
, int from_tty
)
9445 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9449 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9451 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9455 awatch_command (char *arg
, int from_tty
)
9457 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9461 /* Helper routines for the until_command routine in infcmd.c. Here
9462 because it uses the mechanisms of breakpoints. */
9464 struct until_break_command_continuation_args
9466 struct breakpoint
*breakpoint
;
9467 struct breakpoint
*breakpoint2
;
9471 /* This function is called by fetch_inferior_event via the
9472 cmd_continuation pointer, to complete the until command. It takes
9473 care of cleaning up the temporary breakpoints set up by the until
9476 until_break_command_continuation (void *arg
, int err
)
9478 struct until_break_command_continuation_args
*a
= arg
;
9480 delete_breakpoint (a
->breakpoint
);
9482 delete_breakpoint (a
->breakpoint2
);
9483 delete_longjmp_breakpoint (a
->thread_num
);
9487 until_break_command (char *arg
, int from_tty
, int anywhere
)
9489 struct symtabs_and_lines sals
;
9490 struct symtab_and_line sal
;
9491 struct frame_info
*frame
= get_selected_frame (NULL
);
9492 struct breakpoint
*breakpoint
;
9493 struct breakpoint
*breakpoint2
= NULL
;
9494 struct cleanup
*old_chain
;
9496 struct thread_info
*tp
;
9498 clear_proceed_status ();
9500 /* Set a breakpoint where the user wants it and at return from
9503 if (default_breakpoint_valid
)
9504 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
9505 default_breakpoint_line
, NULL
);
9507 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9509 if (sals
.nelts
!= 1)
9510 error (_("Couldn't get information on specified line."));
9513 xfree (sals
.sals
); /* malloc'd, so freed. */
9516 error (_("Junk at end of arguments."));
9518 resolve_sal_pc (&sal
);
9521 /* If the user told us to continue until a specified location,
9522 we don't specify a frame at which we need to stop. */
9523 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9524 null_frame_id
, bp_until
);
9526 /* Otherwise, specify the selected frame, because we want to stop
9527 only at the very same frame. */
9528 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9529 get_stack_frame_id (frame
),
9532 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9534 tp
= inferior_thread ();
9537 /* Keep within the current frame, or in frames called by the current
9540 if (frame_id_p (frame_unwind_caller_id (frame
)))
9542 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9543 sal
.pc
= frame_unwind_caller_pc (frame
);
9544 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9546 frame_unwind_caller_id (frame
),
9548 make_cleanup_delete_breakpoint (breakpoint2
);
9550 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9551 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9554 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9556 /* If we are running asynchronously, and proceed call above has
9557 actually managed to start the target, arrange for breakpoints to
9558 be deleted when the target stops. Otherwise, we're already
9559 stopped and delete breakpoints via cleanup chain. */
9561 if (target_can_async_p () && is_running (inferior_ptid
))
9563 struct until_break_command_continuation_args
*args
;
9564 args
= xmalloc (sizeof (*args
));
9566 args
->breakpoint
= breakpoint
;
9567 args
->breakpoint2
= breakpoint2
;
9568 args
->thread_num
= thread
;
9570 discard_cleanups (old_chain
);
9571 add_continuation (inferior_thread (),
9572 until_break_command_continuation
, args
,
9576 do_cleanups (old_chain
);
9579 /* This function attempts to parse an optional "if <cond>" clause
9580 from the arg string. If one is not found, it returns NULL.
9582 Else, it returns a pointer to the condition string. (It does not
9583 attempt to evaluate the string against a particular block.) And,
9584 it updates arg to point to the first character following the parsed
9585 if clause in the arg string. */
9588 ep_parse_optional_if_clause (char **arg
)
9592 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9595 /* Skip the "if" keyword. */
9598 /* Skip any extra leading whitespace, and record the start of the
9599 condition string. */
9600 *arg
= skip_spaces (*arg
);
9603 /* Assume that the condition occupies the remainder of the arg
9605 (*arg
) += strlen (cond_string
);
9610 /* Commands to deal with catching events, such as signals, exceptions,
9611 process start/exit, etc. */
9615 catch_fork_temporary
, catch_vfork_temporary
,
9616 catch_fork_permanent
, catch_vfork_permanent
9621 catch_fork_command_1 (char *arg
, int from_tty
,
9622 struct cmd_list_element
*command
)
9624 struct gdbarch
*gdbarch
= get_current_arch ();
9625 char *cond_string
= NULL
;
9626 catch_fork_kind fork_kind
;
9629 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9630 tempflag
= (fork_kind
== catch_fork_temporary
9631 || fork_kind
== catch_vfork_temporary
);
9635 arg
= skip_spaces (arg
);
9637 /* The allowed syntax is:
9639 catch [v]fork if <cond>
9641 First, check if there's an if clause. */
9642 cond_string
= ep_parse_optional_if_clause (&arg
);
9644 if ((*arg
!= '\0') && !isspace (*arg
))
9645 error (_("Junk at end of arguments."));
9647 /* If this target supports it, create a fork or vfork catchpoint
9648 and enable reporting of such events. */
9651 case catch_fork_temporary
:
9652 case catch_fork_permanent
:
9653 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9654 &catch_fork_breakpoint_ops
);
9656 case catch_vfork_temporary
:
9657 case catch_vfork_permanent
:
9658 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9659 &catch_vfork_breakpoint_ops
);
9662 error (_("unsupported or unknown fork kind; cannot catch it"));
9668 catch_exec_command_1 (char *arg
, int from_tty
,
9669 struct cmd_list_element
*command
)
9671 struct exec_catchpoint
*c
;
9672 struct gdbarch
*gdbarch
= get_current_arch ();
9674 char *cond_string
= NULL
;
9676 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9680 arg
= skip_spaces (arg
);
9682 /* The allowed syntax is:
9684 catch exec if <cond>
9686 First, check if there's an if clause. */
9687 cond_string
= ep_parse_optional_if_clause (&arg
);
9689 if ((*arg
!= '\0') && !isspace (*arg
))
9690 error (_("Junk at end of arguments."));
9692 c
= XNEW (struct exec_catchpoint
);
9693 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9694 &catch_exec_breakpoint_ops
);
9695 c
->exec_pathname
= NULL
;
9697 install_breakpoint (0, &c
->base
);
9700 static enum print_stop_action
9701 print_it_exception_catchpoint (bpstat bs
)
9703 struct breakpoint
*b
= bs
->breakpoint_at
;
9704 int bp_temp
, bp_throw
;
9706 annotate_catchpoint (b
->number
);
9708 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9709 if (b
->loc
->address
!= b
->loc
->requested_address
)
9710 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9713 bp_temp
= b
->disposition
== disp_del
;
9715 bp_temp
? "Temporary catchpoint "
9717 if (!ui_out_is_mi_like_p (uiout
))
9718 ui_out_field_int (uiout
, "bkptno", b
->number
);
9720 bp_throw
? " (exception thrown), "
9721 : " (exception caught), ");
9722 if (ui_out_is_mi_like_p (uiout
))
9724 ui_out_field_string (uiout
, "reason",
9725 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9726 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9727 ui_out_field_int (uiout
, "bkptno", b
->number
);
9729 return PRINT_SRC_AND_LOC
;
9733 print_one_exception_catchpoint (struct breakpoint
*b
,
9734 struct bp_location
**last_loc
)
9736 struct value_print_options opts
;
9738 get_user_print_options (&opts
);
9739 if (opts
.addressprint
)
9742 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9743 ui_out_field_string (uiout
, "addr", "<PENDING>");
9745 ui_out_field_core_addr (uiout
, "addr",
9746 b
->loc
->gdbarch
, b
->loc
->address
);
9751 if (strstr (b
->addr_string
, "throw") != NULL
)
9752 ui_out_field_string (uiout
, "what", "exception throw");
9754 ui_out_field_string (uiout
, "what", "exception catch");
9758 print_mention_exception_catchpoint (struct breakpoint
*b
)
9763 bp_temp
= b
->disposition
== disp_del
;
9764 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9765 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9766 : _("Catchpoint "));
9767 ui_out_field_int (uiout
, "bkptno", b
->number
);
9768 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9772 /* Implement the "print_recreate" breakpoint_ops method for throw and
9773 catch catchpoints. */
9776 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9782 bp_temp
= b
->disposition
== disp_del
;
9783 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9784 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9785 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9786 print_recreate_thread (b
, fp
);
9789 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9792 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9793 enum exception_event_kind ex_event
, int from_tty
)
9795 char *trigger_func_name
;
9797 if (ex_event
== EX_EVENT_CATCH
)
9798 trigger_func_name
= "__cxa_begin_catch";
9800 trigger_func_name
= "__cxa_throw";
9802 create_breakpoint (get_current_arch (),
9803 trigger_func_name
, cond_string
, -1,
9804 0 /* condition and thread are valid. */,
9805 tempflag
, bp_breakpoint
,
9807 AUTO_BOOLEAN_TRUE
/* pending */,
9808 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9815 /* Deal with "catch catch" and "catch throw" commands. */
9818 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9819 int tempflag
, int from_tty
)
9821 char *cond_string
= NULL
;
9825 arg
= skip_spaces (arg
);
9827 cond_string
= ep_parse_optional_if_clause (&arg
);
9829 if ((*arg
!= '\0') && !isspace (*arg
))
9830 error (_("Junk at end of arguments."));
9832 if (ex_event
!= EX_EVENT_THROW
9833 && ex_event
!= EX_EVENT_CATCH
)
9834 error (_("Unsupported or unknown exception event; cannot catch it"));
9836 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9839 warning (_("Unsupported with this platform/compiler combination."));
9842 /* Implementation of "catch catch" command. */
9845 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9847 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9849 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9852 /* Implementation of "catch throw" command. */
9855 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9857 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9859 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9863 init_ada_exception_breakpoint (struct breakpoint
*b
,
9864 struct gdbarch
*gdbarch
,
9865 struct symtab_and_line sal
,
9867 struct breakpoint_ops
*ops
,
9873 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9875 loc_gdbarch
= gdbarch
;
9877 describe_other_breakpoints (loc_gdbarch
,
9878 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9879 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9880 version for exception catchpoints, because two catchpoints
9881 used for different exception names will use the same address.
9882 In this case, a "breakpoint ... also set at..." warning is
9883 unproductive. Besides, the warning phrasing is also a bit
9884 inappropriate, we should use the word catchpoint, and tell
9885 the user what type of catchpoint it is. The above is good
9886 enough for now, though. */
9889 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9891 b
->enable_state
= bp_enabled
;
9892 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9893 b
->addr_string
= addr_string
;
9894 b
->language
= language_ada
;
9897 /* Cleanup function for a syscall filter list. */
9899 clean_up_filters (void *arg
)
9901 VEC(int) *iter
= *(VEC(int) **) arg
;
9902 VEC_free (int, iter
);
9905 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9906 filter list, or NULL if no filtering is required. */
9908 catch_syscall_split_args (char *arg
)
9910 VEC(int) *result
= NULL
;
9911 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9913 while (*arg
!= '\0')
9915 int i
, syscall_number
;
9920 /* Skip whitespace. */
9921 while (isspace (*arg
))
9924 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9925 cur_name
[i
] = arg
[i
];
9929 /* Check if the user provided a syscall name or a number. */
9930 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9931 if (*endptr
== '\0')
9932 get_syscall_by_number (syscall_number
, &s
);
9935 /* We have a name. Let's check if it's valid and convert it
9937 get_syscall_by_name (cur_name
, &s
);
9939 if (s
.number
== UNKNOWN_SYSCALL
)
9940 /* Here we have to issue an error instead of a warning,
9941 because GDB cannot do anything useful if there's no
9942 syscall number to be caught. */
9943 error (_("Unknown syscall name '%s'."), cur_name
);
9946 /* Ok, it's valid. */
9947 VEC_safe_push (int, result
, s
.number
);
9950 discard_cleanups (cleanup
);
9954 /* Implement the "catch syscall" command. */
9957 catch_syscall_command_1 (char *arg
, int from_tty
,
9958 struct cmd_list_element
*command
)
9963 struct gdbarch
*gdbarch
= get_current_arch ();
9965 /* Checking if the feature if supported. */
9966 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9967 error (_("The feature 'catch syscall' is not supported on \
9968 this architecture yet."));
9970 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9972 arg
= skip_spaces (arg
);
9974 /* We need to do this first "dummy" translation in order
9975 to get the syscall XML file loaded or, most important,
9976 to display a warning to the user if there's no XML file
9977 for his/her architecture. */
9978 get_syscall_by_number (0, &s
);
9980 /* The allowed syntax is:
9982 catch syscall <name | number> [<name | number> ... <name | number>]
9984 Let's check if there's a syscall name. */
9987 filter
= catch_syscall_split_args (arg
);
9991 create_syscall_event_catchpoint (tempflag
, filter
,
9992 &catch_syscall_breakpoint_ops
);
9996 catch_command (char *arg
, int from_tty
)
9998 error (_("Catch requires an event name."));
10003 tcatch_command (char *arg
, int from_tty
)
10005 error (_("Catch requires an event name."));
10008 /* Delete breakpoints by address or line. */
10011 clear_command (char *arg
, int from_tty
)
10013 struct breakpoint
*b
;
10014 VEC(breakpoint_p
) *found
= 0;
10017 struct symtabs_and_lines sals
;
10018 struct symtab_and_line sal
;
10023 sals
= decode_line_spec (arg
, 1);
10028 sals
.sals
= (struct symtab_and_line
*)
10029 xmalloc (sizeof (struct symtab_and_line
));
10030 make_cleanup (xfree
, sals
.sals
);
10031 init_sal (&sal
); /* Initialize to zeroes. */
10032 sal
.line
= default_breakpoint_line
;
10033 sal
.symtab
= default_breakpoint_symtab
;
10034 sal
.pc
= default_breakpoint_address
;
10035 sal
.pspace
= default_breakpoint_pspace
;
10036 if (sal
.symtab
== 0)
10037 error (_("No source file specified."));
10039 sals
.sals
[0] = sal
;
10045 /* We don't call resolve_sal_pc here. That's not as bad as it
10046 seems, because all existing breakpoints typically have both
10047 file/line and pc set. So, if clear is given file/line, we can
10048 match this to existing breakpoint without obtaining pc at all.
10050 We only support clearing given the address explicitly
10051 present in breakpoint table. Say, we've set breakpoint
10052 at file:line. There were several PC values for that file:line,
10053 due to optimization, all in one block.
10055 We've picked one PC value. If "clear" is issued with another
10056 PC corresponding to the same file:line, the breakpoint won't
10057 be cleared. We probably can still clear the breakpoint, but
10058 since the other PC value is never presented to user, user
10059 can only find it by guessing, and it does not seem important
10060 to support that. */
10062 /* For each line spec given, delete bps which correspond to it. Do
10063 it in two passes, solely to preserve the current behavior that
10064 from_tty is forced true if we delete more than one
10068 for (i
= 0; i
< sals
.nelts
; i
++)
10070 /* If exact pc given, clear bpts at that pc.
10071 If line given (pc == 0), clear all bpts on specified line.
10072 If defaulting, clear all bpts on default line
10075 defaulting sal.pc != 0 tests to do
10080 1 0 <can't happen> */
10082 sal
= sals
.sals
[i
];
10084 /* Find all matching breakpoints and add them to 'found'. */
10085 ALL_BREAKPOINTS (b
)
10088 /* Are we going to delete b? */
10089 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10091 struct bp_location
*loc
= b
->loc
;
10092 for (; loc
; loc
= loc
->next
)
10094 int pc_match
= sal
.pc
10095 && (loc
->pspace
== sal
.pspace
)
10096 && (loc
->address
== sal
.pc
)
10097 && (!section_is_overlay (loc
->section
)
10098 || loc
->section
== sal
.section
);
10099 int line_match
= ((default_match
|| (0 == sal
.pc
))
10100 && b
->source_file
!= NULL
10101 && sal
.symtab
!= NULL
10102 && sal
.pspace
== loc
->pspace
10103 && filename_cmp (b
->source_file
,
10104 sal
.symtab
->filename
) == 0
10105 && b
->line_number
== sal
.line
);
10106 if (pc_match
|| line_match
)
10115 VEC_safe_push(breakpoint_p
, found
, b
);
10118 /* Now go thru the 'found' chain and delete them. */
10119 if (VEC_empty(breakpoint_p
, found
))
10122 error (_("No breakpoint at %s."), arg
);
10124 error (_("No breakpoint at this line."));
10127 if (VEC_length(breakpoint_p
, found
) > 1)
10128 from_tty
= 1; /* Always report if deleted more than one. */
10131 if (VEC_length(breakpoint_p
, found
) == 1)
10132 printf_unfiltered (_("Deleted breakpoint "));
10134 printf_unfiltered (_("Deleted breakpoints "));
10136 breakpoints_changed ();
10138 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10141 printf_unfiltered ("%d ", b
->number
);
10142 delete_breakpoint (b
);
10145 putchar_unfiltered ('\n');
10148 /* Delete breakpoint in BS if they are `delete' breakpoints and
10149 all breakpoints that are marked for deletion, whether hit or not.
10150 This is called after any breakpoint is hit, or after errors. */
10153 breakpoint_auto_delete (bpstat bs
)
10155 struct breakpoint
*b
, *b_tmp
;
10157 for (; bs
; bs
= bs
->next
)
10158 if (bs
->breakpoint_at
10159 && bs
->breakpoint_at
->disposition
== disp_del
10161 delete_breakpoint (bs
->breakpoint_at
);
10163 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10165 if (b
->disposition
== disp_del_at_next_stop
)
10166 delete_breakpoint (b
);
10170 /* A comparison function for bp_location AP and BP being interfaced to
10171 qsort. Sort elements primarily by their ADDRESS (no matter what
10172 does breakpoint_address_is_meaningful say for its OWNER),
10173 secondarily by ordering first bp_permanent OWNERed elements and
10174 terciarily just ensuring the array is sorted stable way despite
10175 qsort being an unstable algorithm. */
10178 bp_location_compare (const void *ap
, const void *bp
)
10180 struct bp_location
*a
= *(void **) ap
;
10181 struct bp_location
*b
= *(void **) bp
;
10182 /* A and B come from existing breakpoints having non-NULL OWNER. */
10183 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10184 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10186 if (a
->address
!= b
->address
)
10187 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10189 /* Sort permanent breakpoints first. */
10190 if (a_perm
!= b_perm
)
10191 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10193 /* Make the user-visible order stable across GDB runs. Locations of
10194 the same breakpoint can be sorted in arbitrary order. */
10196 if (a
->owner
->number
!= b
->owner
->number
)
10197 return (a
->owner
->number
> b
->owner
->number
)
10198 - (a
->owner
->number
< b
->owner
->number
);
10200 return (a
> b
) - (a
< b
);
10203 /* Set bp_location_placed_address_before_address_max and
10204 bp_location_shadow_len_after_address_max according to the current
10205 content of the bp_location array. */
10208 bp_location_target_extensions_update (void)
10210 struct bp_location
*bl
, **blp_tmp
;
10212 bp_location_placed_address_before_address_max
= 0;
10213 bp_location_shadow_len_after_address_max
= 0;
10215 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10217 CORE_ADDR start
, end
, addr
;
10219 if (!bp_location_has_shadow (bl
))
10222 start
= bl
->target_info
.placed_address
;
10223 end
= start
+ bl
->target_info
.shadow_len
;
10225 gdb_assert (bl
->address
>= start
);
10226 addr
= bl
->address
- start
;
10227 if (addr
> bp_location_placed_address_before_address_max
)
10228 bp_location_placed_address_before_address_max
= addr
;
10230 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10232 gdb_assert (bl
->address
< end
);
10233 addr
= end
- bl
->address
;
10234 if (addr
> bp_location_shadow_len_after_address_max
)
10235 bp_location_shadow_len_after_address_max
= addr
;
10239 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10240 into the inferior, only remove already-inserted locations that no
10241 longer should be inserted. Functions that delete a breakpoint or
10242 breakpoints should pass false, so that deleting a breakpoint
10243 doesn't have the side effect of inserting the locations of other
10244 breakpoints that are marked not-inserted, but should_be_inserted
10245 returns true on them.
10247 This behaviour is useful is situations close to tear-down -- e.g.,
10248 after an exec, while the target still has execution, but breakpoint
10249 shadows of the previous executable image should *NOT* be restored
10250 to the new image; or before detaching, where the target still has
10251 execution and wants to delete breakpoints from GDB's lists, and all
10252 breakpoints had already been removed from the inferior. */
10255 update_global_location_list (int should_insert
)
10257 struct breakpoint
*b
;
10258 struct bp_location
**locp
, *loc
;
10259 struct cleanup
*cleanups
;
10261 /* Used in the duplicates detection below. When iterating over all
10262 bp_locations, points to the first bp_location of a given address.
10263 Breakpoints and watchpoints of different types are never
10264 duplicates of each other. Keep one pointer for each type of
10265 breakpoint/watchpoint, so we only need to loop over all locations
10267 struct bp_location
*bp_loc_first
; /* breakpoint */
10268 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10269 struct bp_location
*awp_loc_first
; /* access watchpoint */
10270 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10272 /* Saved former bp_location array which we compare against the newly
10273 built bp_location from the current state of ALL_BREAKPOINTS. */
10274 struct bp_location
**old_location
, **old_locp
;
10275 unsigned old_location_count
;
10277 old_location
= bp_location
;
10278 old_location_count
= bp_location_count
;
10279 bp_location
= NULL
;
10280 bp_location_count
= 0;
10281 cleanups
= make_cleanup (xfree
, old_location
);
10283 ALL_BREAKPOINTS (b
)
10284 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10285 bp_location_count
++;
10287 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10288 locp
= bp_location
;
10289 ALL_BREAKPOINTS (b
)
10290 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10292 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10293 bp_location_compare
);
10295 bp_location_target_extensions_update ();
10297 /* Identify bp_location instances that are no longer present in the
10298 new list, and therefore should be freed. Note that it's not
10299 necessary that those locations should be removed from inferior --
10300 if there's another location at the same address (previously
10301 marked as duplicate), we don't need to remove/insert the
10304 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10305 and former bp_location array state respectively. */
10307 locp
= bp_location
;
10308 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10311 struct bp_location
*old_loc
= *old_locp
;
10312 struct bp_location
**loc2p
;
10314 /* Tells if 'old_loc' is found among the new locations. If
10315 not, we have to free it. */
10316 int found_object
= 0;
10317 /* Tells if the location should remain inserted in the target. */
10318 int keep_in_target
= 0;
10321 /* Skip LOCP entries which will definitely never be needed.
10322 Stop either at or being the one matching OLD_LOC. */
10323 while (locp
< bp_location
+ bp_location_count
10324 && (*locp
)->address
< old_loc
->address
)
10328 (loc2p
< bp_location
+ bp_location_count
10329 && (*loc2p
)->address
== old_loc
->address
);
10332 if (*loc2p
== old_loc
)
10339 /* If this location is no longer present, and inserted, look if
10340 there's maybe a new location at the same address. If so,
10341 mark that one inserted, and don't remove this one. This is
10342 needed so that we don't have a time window where a breakpoint
10343 at certain location is not inserted. */
10345 if (old_loc
->inserted
)
10347 /* If the location is inserted now, we might have to remove
10350 if (found_object
&& should_be_inserted (old_loc
))
10352 /* The location is still present in the location list,
10353 and still should be inserted. Don't do anything. */
10354 keep_in_target
= 1;
10358 /* The location is either no longer present, or got
10359 disabled. See if there's another location at the
10360 same address, in which case we don't need to remove
10361 this one from the target. */
10363 /* OLD_LOC comes from existing struct breakpoint. */
10364 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10367 (loc2p
< bp_location
+ bp_location_count
10368 && (*loc2p
)->address
== old_loc
->address
);
10371 struct bp_location
*loc2
= *loc2p
;
10373 if (breakpoint_locations_match (loc2
, old_loc
))
10375 /* For the sake of should_be_inserted.
10376 Duplicates check below will fix up this
10378 loc2
->duplicate
= 0;
10380 /* Read watchpoint locations are switched to
10381 access watchpoints, if the former are not
10382 supported, but the latter are. */
10383 if (is_hardware_watchpoint (old_loc
->owner
))
10385 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10386 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10389 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
10391 loc2
->inserted
= 1;
10392 loc2
->target_info
= old_loc
->target_info
;
10393 keep_in_target
= 1;
10401 if (!keep_in_target
)
10403 if (remove_breakpoint (old_loc
, mark_uninserted
))
10405 /* This is just about all we can do. We could keep
10406 this location on the global list, and try to
10407 remove it next time, but there's no particular
10408 reason why we will succeed next time.
10410 Note that at this point, old_loc->owner is still
10411 valid, as delete_breakpoint frees the breakpoint
10412 only after calling us. */
10413 printf_filtered (_("warning: Error removing "
10414 "breakpoint %d\n"),
10415 old_loc
->owner
->number
);
10423 if (removed
&& non_stop
10424 && breakpoint_address_is_meaningful (old_loc
->owner
)
10425 && !is_hardware_watchpoint (old_loc
->owner
))
10427 /* This location was removed from the target. In
10428 non-stop mode, a race condition is possible where
10429 we've removed a breakpoint, but stop events for that
10430 breakpoint are already queued and will arrive later.
10431 We apply an heuristic to be able to distinguish such
10432 SIGTRAPs from other random SIGTRAPs: we keep this
10433 breakpoint location for a bit, and will retire it
10434 after we see some number of events. The theory here
10435 is that reporting of events should, "on the average",
10436 be fair, so after a while we'll see events from all
10437 threads that have anything of interest, and no longer
10438 need to keep this breakpoint location around. We
10439 don't hold locations forever so to reduce chances of
10440 mistaking a non-breakpoint SIGTRAP for a breakpoint
10443 The heuristic failing can be disastrous on
10444 decr_pc_after_break targets.
10446 On decr_pc_after_break targets, like e.g., x86-linux,
10447 if we fail to recognize a late breakpoint SIGTRAP,
10448 because events_till_retirement has reached 0 too
10449 soon, we'll fail to do the PC adjustment, and report
10450 a random SIGTRAP to the user. When the user resumes
10451 the inferior, it will most likely immediately crash
10452 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10453 corrupted, because of being resumed e.g., in the
10454 middle of a multi-byte instruction, or skipped a
10455 one-byte instruction. This was actually seen happen
10456 on native x86-linux, and should be less rare on
10457 targets that do not support new thread events, like
10458 remote, due to the heuristic depending on
10461 Mistaking a random SIGTRAP for a breakpoint trap
10462 causes similar symptoms (PC adjustment applied when
10463 it shouldn't), but then again, playing with SIGTRAPs
10464 behind the debugger's back is asking for trouble.
10466 Since hardware watchpoint traps are always
10467 distinguishable from other traps, so we don't need to
10468 apply keep hardware watchpoint moribund locations
10469 around. We simply always ignore hardware watchpoint
10470 traps we can no longer explain. */
10472 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10473 old_loc
->owner
= NULL
;
10475 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10479 old_loc
->owner
= NULL
;
10480 decref_bp_location (&old_loc
);
10485 /* Rescan breakpoints at the same address and section, marking the
10486 first one as "first" and any others as "duplicates". This is so
10487 that the bpt instruction is only inserted once. If we have a
10488 permanent breakpoint at the same place as BPT, make that one the
10489 official one, and the rest as duplicates. Permanent breakpoints
10490 are sorted first for the same address.
10492 Do the same for hardware watchpoints, but also considering the
10493 watchpoint's type (regular/access/read) and length. */
10495 bp_loc_first
= NULL
;
10496 wp_loc_first
= NULL
;
10497 awp_loc_first
= NULL
;
10498 rwp_loc_first
= NULL
;
10499 ALL_BP_LOCATIONS (loc
, locp
)
10501 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10503 struct breakpoint
*b
= loc
->owner
;
10504 struct bp_location
**loc_first_p
;
10506 if (b
->enable_state
== bp_disabled
10507 || b
->enable_state
== bp_call_disabled
10508 || b
->enable_state
== bp_startup_disabled
10510 || loc
->shlib_disabled
10511 || !breakpoint_address_is_meaningful (b
)
10512 || is_tracepoint (b
))
10515 /* Permanent breakpoint should always be inserted. */
10516 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10517 internal_error (__FILE__
, __LINE__
,
10518 _("allegedly permanent breakpoint is not "
10519 "actually inserted"));
10521 if (b
->type
== bp_hardware_watchpoint
)
10522 loc_first_p
= &wp_loc_first
;
10523 else if (b
->type
== bp_read_watchpoint
)
10524 loc_first_p
= &rwp_loc_first
;
10525 else if (b
->type
== bp_access_watchpoint
)
10526 loc_first_p
= &awp_loc_first
;
10528 loc_first_p
= &bp_loc_first
;
10530 if (*loc_first_p
== NULL
10531 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10532 || !breakpoint_locations_match (loc
, *loc_first_p
))
10534 *loc_first_p
= loc
;
10535 loc
->duplicate
= 0;
10539 loc
->duplicate
= 1;
10541 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10542 && b
->enable_state
!= bp_permanent
)
10543 internal_error (__FILE__
, __LINE__
,
10544 _("another breakpoint was inserted on top of "
10545 "a permanent breakpoint"));
10548 if (breakpoints_always_inserted_mode () && should_insert
10549 && (have_live_inferiors ()
10550 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10551 insert_breakpoint_locations ();
10553 do_cleanups (cleanups
);
10557 breakpoint_retire_moribund (void)
10559 struct bp_location
*loc
;
10562 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10563 if (--(loc
->events_till_retirement
) == 0)
10565 decref_bp_location (&loc
);
10566 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10572 update_global_location_list_nothrow (int inserting
)
10574 struct gdb_exception e
;
10576 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10577 update_global_location_list (inserting
);
10580 /* Clear BKP from a BPS. */
10583 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10587 for (bs
= bps
; bs
; bs
= bs
->next
)
10588 if (bs
->breakpoint_at
== bpt
)
10590 bs
->breakpoint_at
= NULL
;
10591 bs
->old_val
= NULL
;
10592 /* bs->commands will be freed later. */
10596 /* Callback for iterate_over_threads. */
10598 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10600 struct breakpoint
*bpt
= data
;
10602 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10606 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10610 say_where (struct breakpoint
*b
)
10612 struct value_print_options opts
;
10614 get_user_print_options (&opts
);
10616 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10618 if (b
->loc
== NULL
)
10620 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10624 if (opts
.addressprint
|| b
->source_file
== NULL
)
10626 printf_filtered (" at ");
10627 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10630 if (b
->source_file
)
10631 printf_filtered (": file %s, line %d.",
10632 b
->source_file
, b
->line_number
);
10636 struct bp_location
*loc
= b
->loc
;
10638 for (; loc
; loc
= loc
->next
)
10640 printf_filtered (" (%d locations)", n
);
10645 /* Default bp_location_ops methods. */
10648 bp_location_dtor (struct bp_location
*self
)
10650 xfree (self
->cond
);
10651 xfree (self
->function_name
);
10654 static const struct bp_location_ops bp_location_ops
=
10659 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10663 base_breakpoint_dtor (struct breakpoint
*self
)
10665 decref_counted_command_line (&self
->commands
);
10666 xfree (self
->cond_string
);
10667 xfree (self
->addr_string
);
10668 xfree (self
->addr_string_range_end
);
10669 xfree (self
->source_file
);
10672 static struct bp_location
*
10673 base_breakpoint_allocate_location (struct breakpoint
*self
)
10675 struct bp_location
*loc
;
10677 loc
= XNEW (struct bp_location
);
10678 init_bp_location (loc
, &bp_location_ops
, self
);
10683 base_breakpoint_re_set (struct breakpoint
*b
)
10685 /* Nothing to re-set. */
10688 #define internal_error_pure_virtual_called() \
10689 gdb_assert_not_reached ("pure virtual function called")
10692 base_breakpoint_insert_location (struct bp_location
*bl
)
10694 internal_error_pure_virtual_called ();
10698 base_breakpoint_remove_location (struct bp_location
*bl
)
10700 internal_error_pure_virtual_called ();
10704 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10705 struct address_space
*aspace
,
10708 internal_error_pure_virtual_called ();
10712 base_breakpoint_check_status (bpstat bs
)
10717 /* A "works_in_software_mode" breakpoint_ops method that just internal
10721 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10723 internal_error_pure_virtual_called ();
10726 /* A "resources_needed" breakpoint_ops method that just internal
10730 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10732 internal_error_pure_virtual_called ();
10735 static enum print_stop_action
10736 base_breakpoint_print_it (bpstat bs
)
10738 internal_error_pure_virtual_called ();
10742 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10743 struct ui_out
*uiout
)
10749 base_breakpoint_print_mention (struct breakpoint
*b
)
10751 internal_error_pure_virtual_called ();
10755 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10757 internal_error_pure_virtual_called ();
10760 static struct breakpoint_ops base_breakpoint_ops
=
10762 base_breakpoint_dtor
,
10763 base_breakpoint_allocate_location
,
10764 base_breakpoint_re_set
,
10765 base_breakpoint_insert_location
,
10766 base_breakpoint_remove_location
,
10767 base_breakpoint_breakpoint_hit
,
10768 base_breakpoint_check_status
,
10769 base_breakpoint_resources_needed
,
10770 base_breakpoint_works_in_software_mode
,
10771 base_breakpoint_print_it
,
10773 base_breakpoint_print_one_detail
,
10774 base_breakpoint_print_mention
,
10775 base_breakpoint_print_recreate
10778 /* Default breakpoint_ops methods. */
10781 bkpt_re_set (struct breakpoint
*b
)
10783 /* Do not attempt to re-set breakpoints disabled during startup. */
10784 if (b
->enable_state
== bp_startup_disabled
)
10787 /* FIXME: is this still reachable? */
10788 if (b
->addr_string
== NULL
)
10790 /* Anything without a string can't be re-set. */
10791 delete_breakpoint (b
);
10795 breakpoint_re_set_default (b
);
10799 bkpt_insert_location (struct bp_location
*bl
)
10801 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10802 return target_insert_hw_breakpoint (bl
->gdbarch
,
10805 return target_insert_breakpoint (bl
->gdbarch
,
10810 bkpt_remove_location (struct bp_location
*bl
)
10812 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10813 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10815 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10819 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10820 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10822 struct breakpoint
*b
= bl
->owner
;
10824 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10828 if (overlay_debugging
/* unmapped overlay section */
10829 && section_is_overlay (bl
->section
)
10830 && !section_is_mapped (bl
->section
))
10837 bkpt_resources_needed (const struct bp_location
*bl
)
10839 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10844 static enum print_stop_action
10845 bkpt_print_it (bpstat bs
)
10847 struct breakpoint
*b
;
10848 const struct bp_location
*bl
;
10851 gdb_assert (bs
->bp_location_at
!= NULL
);
10853 bl
= bs
->bp_location_at
;
10854 b
= bs
->breakpoint_at
;
10856 bp_temp
= b
->disposition
== disp_del
;
10857 if (bl
->address
!= bl
->requested_address
)
10858 breakpoint_adjustment_warning (bl
->requested_address
,
10861 annotate_breakpoint (b
->number
);
10863 ui_out_text (uiout
, "\nTemporary breakpoint ");
10865 ui_out_text (uiout
, "\nBreakpoint ");
10866 if (ui_out_is_mi_like_p (uiout
))
10868 ui_out_field_string (uiout
, "reason",
10869 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10870 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10872 ui_out_field_int (uiout
, "bkptno", b
->number
);
10873 ui_out_text (uiout
, ", ");
10875 return PRINT_SRC_AND_LOC
;
10879 bkpt_print_mention (struct breakpoint
*b
)
10881 if (ui_out_is_mi_like_p (uiout
))
10886 case bp_breakpoint
:
10887 case bp_gnu_ifunc_resolver
:
10888 if (b
->disposition
== disp_del
)
10889 printf_filtered (_("Temporary breakpoint"));
10891 printf_filtered (_("Breakpoint"));
10892 printf_filtered (_(" %d"), b
->number
);
10893 if (b
->type
== bp_gnu_ifunc_resolver
)
10894 printf_filtered (_(" at gnu-indirect-function resolver"));
10896 case bp_hardware_breakpoint
:
10897 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
10905 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
10907 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10908 fprintf_unfiltered (fp
, "tbreak");
10909 else if (tp
->type
== bp_breakpoint
)
10910 fprintf_unfiltered (fp
, "break");
10911 else if (tp
->type
== bp_hardware_breakpoint
10912 && tp
->disposition
== disp_del
)
10913 fprintf_unfiltered (fp
, "thbreak");
10914 else if (tp
->type
== bp_hardware_breakpoint
)
10915 fprintf_unfiltered (fp
, "hbreak");
10917 internal_error (__FILE__
, __LINE__
,
10918 _("unhandled breakpoint type %d"), (int) tp
->type
);
10920 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10923 /* Virtual table for internal breakpoints. */
10926 internal_bkpt_re_set (struct breakpoint
*b
)
10930 /* Delete overlay event and longjmp master breakpoints; they
10931 will be reset later by breakpoint_re_set. */
10932 case bp_overlay_event
:
10933 case bp_longjmp_master
:
10934 case bp_std_terminate_master
:
10935 case bp_exception_master
:
10936 delete_breakpoint (b
);
10939 /* This breakpoint is special, it's set up when the inferior
10940 starts and we really don't want to touch it. */
10941 case bp_shlib_event
:
10943 /* Like bp_shlib_event, this breakpoint type is special. Once
10944 it is set up, we do not want to touch it. */
10945 case bp_thread_event
:
10951 internal_bkpt_check_status (bpstat bs
)
10953 /* We do not stop for these. */
10957 static enum print_stop_action
10958 internal_bkpt_print_it (bpstat bs
)
10960 struct breakpoint
*b
;
10962 b
= bs
->breakpoint_at
;
10966 case bp_shlib_event
:
10967 /* Did we stop because the user set the stop_on_solib_events
10968 variable? (If so, we report this as a generic, "Stopped due
10969 to shlib event" message.) */
10970 printf_filtered (_("Stopped due to shared library event\n"));
10973 case bp_thread_event
:
10974 /* Not sure how we will get here.
10975 GDB should not stop for these breakpoints. */
10976 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
10979 case bp_overlay_event
:
10980 /* By analogy with the thread event, GDB should not stop for these. */
10981 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
10984 case bp_longjmp_master
:
10985 /* These should never be enabled. */
10986 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
10989 case bp_std_terminate_master
:
10990 /* These should never be enabled. */
10991 printf_filtered (_("std::terminate Master Breakpoint: "
10992 "gdb should not stop!\n"));
10995 case bp_exception_master
:
10996 /* These should never be enabled. */
10997 printf_filtered (_("Exception Master Breakpoint: "
10998 "gdb should not stop!\n"));
11002 return PRINT_NOTHING
;
11006 internal_bkpt_print_mention (struct breakpoint
*b
)
11008 /* Nothing to mention. These breakpoints are internal. */
11011 /* Virtual table for momentary breakpoints */
11014 momentary_bkpt_re_set (struct breakpoint
*b
)
11016 /* Keep temporary breakpoints, which can be encountered when we step
11017 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11018 Otherwise these should have been blown away via the cleanup chain
11019 or by breakpoint_init_inferior when we rerun the executable. */
11023 momentary_bkpt_check_status (bpstat bs
)
11025 /* Nothing. The point of these breakpoints is causing a stop. */
11028 static enum print_stop_action
11029 momentary_bkpt_print_it (bpstat bs
)
11031 if (ui_out_is_mi_like_p (uiout
))
11033 struct breakpoint
*b
= bs
->breakpoint_at
;
11038 ui_out_field_string
11040 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11044 ui_out_field_string
11046 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11051 return PRINT_UNKNOWN
;
11055 momentary_bkpt_print_mention (struct breakpoint
*b
)
11057 /* Nothing to mention. These breakpoints are internal. */
11060 /* The breakpoint_ops structure to be used in tracepoints. */
11063 tracepoint_re_set (struct breakpoint
*b
)
11065 breakpoint_re_set_default (b
);
11069 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11070 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11072 /* By definition, the inferior does not report stops at
11078 tracepoint_print_one_detail (const struct breakpoint
*self
,
11079 struct ui_out
*uiout
)
11081 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11082 if (tp
->static_trace_marker_id
)
11084 gdb_assert (self
->type
== bp_static_tracepoint
);
11086 ui_out_text (uiout
, "\tmarker id is ");
11087 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11088 tp
->static_trace_marker_id
);
11089 ui_out_text (uiout
, "\n");
11094 tracepoint_print_mention (struct breakpoint
*b
)
11096 if (ui_out_is_mi_like_p (uiout
))
11101 case bp_tracepoint
:
11102 printf_filtered (_("Tracepoint"));
11103 printf_filtered (_(" %d"), b
->number
);
11105 case bp_fast_tracepoint
:
11106 printf_filtered (_("Fast tracepoint"));
11107 printf_filtered (_(" %d"), b
->number
);
11109 case bp_static_tracepoint
:
11110 printf_filtered (_("Static tracepoint"));
11111 printf_filtered (_(" %d"), b
->number
);
11114 internal_error (__FILE__
, __LINE__
,
11115 _("unhandled tracepoint type %d"), (int) b
->type
);
11122 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11124 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11126 if (self
->type
== bp_fast_tracepoint
)
11127 fprintf_unfiltered (fp
, "ftrace");
11128 if (self
->type
== bp_static_tracepoint
)
11129 fprintf_unfiltered (fp
, "strace");
11130 else if (self
->type
== bp_tracepoint
)
11131 fprintf_unfiltered (fp
, "trace");
11133 internal_error (__FILE__
, __LINE__
,
11134 _("unhandled tracepoint type %d"), (int) self
->type
);
11136 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11137 print_recreate_thread (self
, fp
);
11139 if (tp
->pass_count
)
11140 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11143 struct breakpoint_ops tracepoint_breakpoint_ops
;
11145 /* Delete a breakpoint and clean up all traces of it in the data
11149 delete_breakpoint (struct breakpoint
*bpt
)
11151 struct breakpoint
*b
;
11153 gdb_assert (bpt
!= NULL
);
11155 /* Has this bp already been deleted? This can happen because
11156 multiple lists can hold pointers to bp's. bpstat lists are
11159 One example of this happening is a watchpoint's scope bp. When
11160 the scope bp triggers, we notice that the watchpoint is out of
11161 scope, and delete it. We also delete its scope bp. But the
11162 scope bp is marked "auto-deleting", and is already on a bpstat.
11163 That bpstat is then checked for auto-deleting bp's, which are
11166 A real solution to this problem might involve reference counts in
11167 bp's, and/or giving them pointers back to their referencing
11168 bpstat's, and teaching delete_breakpoint to only free a bp's
11169 storage when no more references were extent. A cheaper bandaid
11171 if (bpt
->type
== bp_none
)
11174 /* At least avoid this stale reference until the reference counting
11175 of breakpoints gets resolved. */
11176 if (bpt
->related_breakpoint
!= bpt
)
11178 struct breakpoint
*related
;
11179 struct watchpoint
*w
;
11181 if (bpt
->type
== bp_watchpoint_scope
)
11182 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11183 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11184 w
= (struct watchpoint
*) bpt
;
11188 watchpoint_del_at_next_stop (w
);
11190 /* Unlink bpt from the bpt->related_breakpoint ring. */
11191 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11192 related
= related
->related_breakpoint
);
11193 related
->related_breakpoint
= bpt
->related_breakpoint
;
11194 bpt
->related_breakpoint
= bpt
;
11197 /* watch_command_1 creates a watchpoint but only sets its number if
11198 update_watchpoint succeeds in creating its bp_locations. If there's
11199 a problem in that process, we'll be asked to delete the half-created
11200 watchpoint. In that case, don't announce the deletion. */
11202 observer_notify_breakpoint_deleted (bpt
);
11204 if (breakpoint_chain
== bpt
)
11205 breakpoint_chain
= bpt
->next
;
11207 ALL_BREAKPOINTS (b
)
11208 if (b
->next
== bpt
)
11210 b
->next
= bpt
->next
;
11214 /* Be sure no bpstat's are pointing at the breakpoint after it's
11216 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11217 in all threads for now. Note that we cannot just remove bpstats
11218 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11219 commands are associated with the bpstat; if we remove it here,
11220 then the later call to bpstat_do_actions (&stop_bpstat); in
11221 event-top.c won't do anything, and temporary breakpoints with
11222 commands won't work. */
11224 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11226 /* Now that breakpoint is removed from breakpoint list, update the
11227 global location list. This will remove locations that used to
11228 belong to this breakpoint. Do this before freeing the breakpoint
11229 itself, since remove_breakpoint looks at location's owner. It
11230 might be better design to have location completely
11231 self-contained, but it's not the case now. */
11232 update_global_location_list (0);
11234 bpt
->ops
->dtor (bpt
);
11235 /* On the chance that someone will soon try again to delete this
11236 same bp, we mark it as deleted before freeing its storage. */
11237 bpt
->type
= bp_none
;
11242 do_delete_breakpoint_cleanup (void *b
)
11244 delete_breakpoint (b
);
11248 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11250 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11253 /* Iterator function to call a user-provided callback function once
11254 for each of B and its related breakpoints. */
11257 iterate_over_related_breakpoints (struct breakpoint
*b
,
11258 void (*function
) (struct breakpoint
*,
11262 struct breakpoint
*related
;
11267 struct breakpoint
*next
;
11269 /* FUNCTION may delete RELATED. */
11270 next
= related
->related_breakpoint
;
11272 if (next
== related
)
11274 /* RELATED is the last ring entry. */
11275 function (related
, data
);
11277 /* FUNCTION may have deleted it, so we'd never reach back to
11278 B. There's nothing left to do anyway, so just break
11283 function (related
, data
);
11287 while (related
!= b
);
11291 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11293 delete_breakpoint (b
);
11296 /* A callback for map_breakpoint_numbers that calls
11297 delete_breakpoint. */
11300 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11302 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11306 delete_command (char *arg
, int from_tty
)
11308 struct breakpoint
*b
, *b_tmp
;
11314 int breaks_to_delete
= 0;
11316 /* Delete all breakpoints if no argument. Do not delete
11317 internal breakpoints, these have to be deleted with an
11318 explicit breakpoint number argument. */
11319 ALL_BREAKPOINTS (b
)
11320 if (user_breakpoint_p (b
))
11322 breaks_to_delete
= 1;
11326 /* Ask user only if there are some breakpoints to delete. */
11328 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11330 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11331 if (user_breakpoint_p (b
))
11332 delete_breakpoint (b
);
11336 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11340 all_locations_are_pending (struct bp_location
*loc
)
11342 for (; loc
; loc
= loc
->next
)
11343 if (!loc
->shlib_disabled
)
11348 /* Subroutine of update_breakpoint_locations to simplify it.
11349 Return non-zero if multiple fns in list LOC have the same name.
11350 Null names are ignored. */
11353 ambiguous_names_p (struct bp_location
*loc
)
11355 struct bp_location
*l
;
11356 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11357 (int (*) (const void *,
11358 const void *)) streq
,
11359 NULL
, xcalloc
, xfree
);
11361 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11364 const char *name
= l
->function_name
;
11366 /* Allow for some names to be NULL, ignore them. */
11370 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11372 /* NOTE: We can assume slot != NULL here because xcalloc never
11376 htab_delete (htab
);
11382 htab_delete (htab
);
11386 /* When symbols change, it probably means the sources changed as well,
11387 and it might mean the static tracepoint markers are no longer at
11388 the same address or line numbers they used to be at last we
11389 checked. Losing your static tracepoints whenever you rebuild is
11390 undesirable. This function tries to resync/rematch gdb static
11391 tracepoints with the markers on the target, for static tracepoints
11392 that have not been set by marker id. Static tracepoint that have
11393 been set by marker id are reset by marker id in breakpoint_re_set.
11396 1) For a tracepoint set at a specific address, look for a marker at
11397 the old PC. If one is found there, assume to be the same marker.
11398 If the name / string id of the marker found is different from the
11399 previous known name, assume that means the user renamed the marker
11400 in the sources, and output a warning.
11402 2) For a tracepoint set at a given line number, look for a marker
11403 at the new address of the old line number. If one is found there,
11404 assume to be the same marker. If the name / string id of the
11405 marker found is different from the previous known name, assume that
11406 means the user renamed the marker in the sources, and output a
11409 3) If a marker is no longer found at the same address or line, it
11410 may mean the marker no longer exists. But it may also just mean
11411 the code changed a bit. Maybe the user added a few lines of code
11412 that made the marker move up or down (in line number terms). Ask
11413 the target for info about the marker with the string id as we knew
11414 it. If found, update line number and address in the matching
11415 static tracepoint. This will get confused if there's more than one
11416 marker with the same ID (possible in UST, although unadvised
11417 precisely because it confuses tools). */
11419 static struct symtab_and_line
11420 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11422 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11423 struct static_tracepoint_marker marker
;
11429 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11431 if (target_static_tracepoint_marker_at (pc
, &marker
))
11433 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11434 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11436 tp
->static_trace_marker_id
, marker
.str_id
);
11438 xfree (tp
->static_trace_marker_id
);
11439 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11440 release_static_tracepoint_marker (&marker
);
11445 /* Old marker wasn't found on target at lineno. Try looking it up
11447 if (!sal
.explicit_pc
11449 && sal
.symtab
!= NULL
11450 && tp
->static_trace_marker_id
!= NULL
)
11452 VEC(static_tracepoint_marker_p
) *markers
;
11455 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11457 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11459 struct symtab_and_line sal
;
11460 struct symbol
*sym
;
11461 struct static_tracepoint_marker
*marker
;
11463 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11465 xfree (tp
->static_trace_marker_id
);
11466 tp
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11468 warning (_("marker for static tracepoint %d (%s) not "
11469 "found at previous line number"),
11470 b
->number
, tp
->static_trace_marker_id
);
11474 sal
.pc
= marker
->address
;
11476 sal
= find_pc_line (marker
->address
, 0);
11477 sym
= find_pc_sect_function (marker
->address
, NULL
);
11478 ui_out_text (uiout
, "Now in ");
11481 ui_out_field_string (uiout
, "func",
11482 SYMBOL_PRINT_NAME (sym
));
11483 ui_out_text (uiout
, " at ");
11485 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11486 ui_out_text (uiout
, ":");
11488 if (ui_out_is_mi_like_p (uiout
))
11490 char *fullname
= symtab_to_fullname (sal
.symtab
);
11493 ui_out_field_string (uiout
, "fullname", fullname
);
11496 ui_out_field_int (uiout
, "line", sal
.line
);
11497 ui_out_text (uiout
, "\n");
11499 b
->line_number
= sal
.line
;
11501 xfree (b
->source_file
);
11503 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11505 b
->source_file
= NULL
;
11507 xfree (b
->addr_string
);
11508 b
->addr_string
= xstrprintf ("%s:%d",
11509 sal
.symtab
->filename
, b
->line_number
);
11511 /* Might be nice to check if function changed, and warn if
11514 release_static_tracepoint_marker (marker
);
11520 /* Returns 1 iff locations A and B are sufficiently same that
11521 we don't need to report breakpoint as changed. */
11524 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11528 if (a
->address
!= b
->address
)
11531 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11534 if (a
->enabled
!= b
->enabled
)
11541 if ((a
== NULL
) != (b
== NULL
))
11547 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11548 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11549 a ranged breakpoint. */
11552 update_breakpoint_locations (struct breakpoint
*b
,
11553 struct symtabs_and_lines sals
,
11554 struct symtabs_and_lines sals_end
)
11557 struct bp_location
*existing_locations
= b
->loc
;
11559 /* Ranged breakpoints have only one start location and one end location. */
11560 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11562 /* If there's no new locations, and all existing locations are
11563 pending, don't do anything. This optimizes the common case where
11564 all locations are in the same shared library, that was unloaded.
11565 We'd like to retain the location, so that when the library is
11566 loaded again, we don't loose the enabled/disabled status of the
11567 individual locations. */
11568 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11573 for (i
= 0; i
< sals
.nelts
; ++i
)
11575 struct bp_location
*new_loc
=
11576 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11578 /* Reparse conditions, they might contain references to the
11580 if (b
->cond_string
!= NULL
)
11583 struct gdb_exception e
;
11585 s
= b
->cond_string
;
11586 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11588 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11593 warning (_("failed to reevaluate condition "
11594 "for breakpoint %d: %s"),
11595 b
->number
, e
.message
);
11596 new_loc
->enabled
= 0;
11600 if (b
->source_file
!= NULL
)
11601 xfree (b
->source_file
);
11602 if (sals
.sals
[i
].symtab
== NULL
)
11603 b
->source_file
= NULL
;
11605 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11607 if (b
->line_number
== 0)
11608 b
->line_number
= sals
.sals
[i
].line
;
11610 if (sals_end
.nelts
)
11612 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11614 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11618 /* Update locations of permanent breakpoints. */
11619 if (b
->enable_state
== bp_permanent
)
11620 make_breakpoint_permanent (b
);
11622 /* If possible, carry over 'disable' status from existing
11625 struct bp_location
*e
= existing_locations
;
11626 /* If there are multiple breakpoints with the same function name,
11627 e.g. for inline functions, comparing function names won't work.
11628 Instead compare pc addresses; this is just a heuristic as things
11629 may have moved, but in practice it gives the correct answer
11630 often enough until a better solution is found. */
11631 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11633 for (; e
; e
= e
->next
)
11635 if (!e
->enabled
&& e
->function_name
)
11637 struct bp_location
*l
= b
->loc
;
11638 if (have_ambiguous_names
)
11640 for (; l
; l
= l
->next
)
11641 if (breakpoint_locations_match (e
, l
))
11649 for (; l
; l
= l
->next
)
11650 if (l
->function_name
11651 && strcmp (e
->function_name
, l
->function_name
) == 0)
11661 if (!locations_are_equal (existing_locations
, b
->loc
))
11662 observer_notify_breakpoint_modified (b
);
11664 update_global_location_list (1);
11667 /* Find the SaL locations corresponding to the given ADDR_STRING.
11668 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11670 static struct symtabs_and_lines
11671 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11675 struct symtabs_and_lines sals
= {0};
11676 struct gdb_exception e
;
11679 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11681 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11685 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11687 sals
= decode_static_tracepoint_spec (&s
);
11688 if (sals
.nelts
> tp
->static_trace_marker_id_idx
)
11690 sals
.sals
[0] = sals
.sals
[tp
->static_trace_marker_id_idx
];
11694 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11697 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11701 int not_found_and_ok
= 0;
11702 /* For pending breakpoints, it's expected that parsing will
11703 fail until the right shared library is loaded. User has
11704 already told to create pending breakpoints and don't need
11705 extra messages. If breakpoint is in bp_shlib_disabled
11706 state, then user already saw the message about that
11707 breakpoint being disabled, and don't want to see more
11709 if (e
.error
== NOT_FOUND_ERROR
11710 && (b
->condition_not_parsed
11711 || (b
->loc
&& b
->loc
->shlib_disabled
)
11712 || b
->enable_state
== bp_disabled
))
11713 not_found_and_ok
= 1;
11715 if (!not_found_and_ok
)
11717 /* We surely don't want to warn about the same breakpoint
11718 10 times. One solution, implemented here, is disable
11719 the breakpoint on error. Another solution would be to
11720 have separate 'warning emitted' flag. Since this
11721 happens only when a binary has changed, I don't know
11722 which approach is better. */
11723 b
->enable_state
= bp_disabled
;
11724 throw_exception (e
);
11728 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11730 gdb_assert (sals
.nelts
== 1);
11732 resolve_sal_pc (&sals
.sals
[0]);
11733 if (b
->condition_not_parsed
&& s
&& s
[0])
11735 char *cond_string
= 0;
11739 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11740 &cond_string
, &thread
, &task
);
11742 b
->cond_string
= cond_string
;
11743 b
->thread
= thread
;
11745 b
->condition_not_parsed
= 0;
11748 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11749 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11759 /* The default re_set method, for typical hardware or software
11760 breakpoints. Reevaluate the breakpoint and recreate its
11764 breakpoint_re_set_default (struct breakpoint
*b
)
11767 struct symtabs_and_lines sals
, sals_end
;
11768 struct symtabs_and_lines expanded
= {0};
11769 struct symtabs_and_lines expanded_end
= {0};
11771 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11774 make_cleanup (xfree
, sals
.sals
);
11775 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
11778 if (b
->addr_string_range_end
)
11780 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11783 make_cleanup (xfree
, sals_end
.sals
);
11784 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
11788 update_breakpoint_locations (b
, expanded
, expanded_end
);
11791 /* Prepare the global context for a re-set of breakpoint B. */
11793 static struct cleanup
*
11794 prepare_re_set_context (struct breakpoint
*b
)
11796 struct cleanup
*cleanups
;
11798 input_radix
= b
->input_radix
;
11799 cleanups
= save_current_space_and_thread ();
11800 switch_to_program_space_and_thread (b
->pspace
);
11801 set_language (b
->language
);
11806 /* Reset a breakpoint given it's struct breakpoint * BINT.
11807 The value we return ends up being the return value from catch_errors.
11808 Unused in this case. */
11811 breakpoint_re_set_one (void *bint
)
11813 /* Get past catch_errs. */
11814 struct breakpoint
*b
= (struct breakpoint
*) bint
;
11815 struct cleanup
*cleanups
;
11817 cleanups
= prepare_re_set_context (b
);
11818 b
->ops
->re_set (b
);
11819 do_cleanups (cleanups
);
11823 /* Re-set all breakpoints after symbols have been re-loaded. */
11825 breakpoint_re_set (void)
11827 struct breakpoint
*b
, *b_tmp
;
11828 enum language save_language
;
11829 int save_input_radix
;
11830 struct cleanup
*old_chain
;
11832 save_language
= current_language
->la_language
;
11833 save_input_radix
= input_radix
;
11834 old_chain
= save_current_program_space ();
11836 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11838 /* Format possible error msg. */
11839 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
11841 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
11842 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
11843 do_cleanups (cleanups
);
11845 set_language (save_language
);
11846 input_radix
= save_input_radix
;
11848 jit_breakpoint_re_set ();
11850 do_cleanups (old_chain
);
11852 create_overlay_event_breakpoint ();
11853 create_longjmp_master_breakpoint ();
11854 create_std_terminate_master_breakpoint ();
11855 create_exception_master_breakpoint ();
11858 /* Reset the thread number of this breakpoint:
11860 - If the breakpoint is for all threads, leave it as-is.
11861 - Else, reset it to the current thread for inferior_ptid. */
11863 breakpoint_re_set_thread (struct breakpoint
*b
)
11865 if (b
->thread
!= -1)
11867 if (in_thread_list (inferior_ptid
))
11868 b
->thread
= pid_to_thread_id (inferior_ptid
);
11870 /* We're being called after following a fork. The new fork is
11871 selected as current, and unless this was a vfork will have a
11872 different program space from the original thread. Reset that
11874 b
->loc
->pspace
= current_program_space
;
11878 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11879 If from_tty is nonzero, it prints a message to that effect,
11880 which ends with a period (no newline). */
11883 set_ignore_count (int bptnum
, int count
, int from_tty
)
11885 struct breakpoint
*b
;
11890 ALL_BREAKPOINTS (b
)
11891 if (b
->number
== bptnum
)
11893 if (is_tracepoint (b
))
11895 if (from_tty
&& count
!= 0)
11896 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11901 b
->ignore_count
= count
;
11905 printf_filtered (_("Will stop next time "
11906 "breakpoint %d is reached."),
11908 else if (count
== 1)
11909 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11912 printf_filtered (_("Will ignore next %d "
11913 "crossings of breakpoint %d."),
11916 breakpoints_changed ();
11917 observer_notify_breakpoint_modified (b
);
11921 error (_("No breakpoint number %d."), bptnum
);
11924 /* Command to set ignore-count of breakpoint N to COUNT. */
11927 ignore_command (char *args
, int from_tty
)
11933 error_no_arg (_("a breakpoint number"));
11935 num
= get_number (&p
);
11937 error (_("bad breakpoint number: '%s'"), args
);
11939 error (_("Second argument (specified ignore-count) is missing."));
11941 set_ignore_count (num
,
11942 longest_to_int (value_as_long (parse_and_eval (p
))),
11945 printf_filtered ("\n");
11948 /* Call FUNCTION on each of the breakpoints
11949 whose numbers are given in ARGS. */
11952 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
11957 struct breakpoint
*b
, *tmp
;
11959 struct get_number_or_range_state state
;
11962 error_no_arg (_("one or more breakpoint numbers"));
11964 init_number_or_range (&state
, args
);
11966 while (!state
.finished
)
11968 char *p
= state
.string
;
11972 num
= get_number_or_range (&state
);
11975 warning (_("bad breakpoint number at or near '%s'"), p
);
11979 ALL_BREAKPOINTS_SAFE (b
, tmp
)
11980 if (b
->number
== num
)
11983 function (b
, data
);
11987 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
11992 static struct bp_location
*
11993 find_location_by_number (char *number
)
11995 char *dot
= strchr (number
, '.');
11999 struct breakpoint
*b
;
12000 struct bp_location
*loc
;
12005 bp_num
= get_number (&p1
);
12007 error (_("Bad breakpoint number '%s'"), number
);
12009 ALL_BREAKPOINTS (b
)
12010 if (b
->number
== bp_num
)
12015 if (!b
|| b
->number
!= bp_num
)
12016 error (_("Bad breakpoint number '%s'"), number
);
12019 loc_num
= get_number (&p1
);
12021 error (_("Bad breakpoint location number '%s'"), number
);
12025 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12028 error (_("Bad breakpoint location number '%s'"), dot
+1);
12034 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12035 If from_tty is nonzero, it prints a message to that effect,
12036 which ends with a period (no newline). */
12039 disable_breakpoint (struct breakpoint
*bpt
)
12041 /* Never disable a watchpoint scope breakpoint; we want to
12042 hit them when we leave scope so we can delete both the
12043 watchpoint and its scope breakpoint at that time. */
12044 if (bpt
->type
== bp_watchpoint_scope
)
12047 /* You can't disable permanent breakpoints. */
12048 if (bpt
->enable_state
== bp_permanent
)
12051 bpt
->enable_state
= bp_disabled
;
12053 if (target_supports_enable_disable_tracepoint ()
12054 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12056 struct bp_location
*location
;
12058 for (location
= bpt
->loc
; location
; location
= location
->next
)
12059 target_disable_tracepoint (location
);
12062 update_global_location_list (0);
12064 observer_notify_breakpoint_modified (bpt
);
12067 /* A callback for iterate_over_related_breakpoints. */
12070 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12072 disable_breakpoint (b
);
12075 /* A callback for map_breakpoint_numbers that calls
12076 disable_breakpoint. */
12079 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12081 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12085 disable_command (char *args
, int from_tty
)
12089 struct breakpoint
*bpt
;
12091 ALL_BREAKPOINTS (bpt
)
12092 if (user_breakpoint_p (bpt
))
12093 disable_breakpoint (bpt
);
12095 else if (strchr (args
, '.'))
12097 struct bp_location
*loc
= find_location_by_number (args
);
12101 if (target_supports_enable_disable_tracepoint ()
12102 && current_trace_status ()->running
&& loc
->owner
12103 && is_tracepoint (loc
->owner
))
12104 target_disable_tracepoint (loc
);
12106 update_global_location_list (0);
12109 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12113 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12115 int target_resources_ok
;
12117 if (bpt
->type
== bp_hardware_breakpoint
)
12120 i
= hw_breakpoint_used_count ();
12121 target_resources_ok
=
12122 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12124 if (target_resources_ok
== 0)
12125 error (_("No hardware breakpoint support in the target."));
12126 else if (target_resources_ok
< 0)
12127 error (_("Hardware breakpoints used exceeds limit."));
12130 if (is_watchpoint (bpt
))
12132 /* Initialize it just to avoid a GCC false warning. */
12133 enum enable_state orig_enable_state
= 0;
12134 struct gdb_exception e
;
12136 TRY_CATCH (e
, RETURN_MASK_ALL
)
12138 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12140 orig_enable_state
= bpt
->enable_state
;
12141 bpt
->enable_state
= bp_enabled
;
12142 update_watchpoint (w
, 1 /* reparse */);
12146 bpt
->enable_state
= orig_enable_state
;
12147 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12153 if (bpt
->enable_state
!= bp_permanent
)
12154 bpt
->enable_state
= bp_enabled
;
12156 if (target_supports_enable_disable_tracepoint ()
12157 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12159 struct bp_location
*location
;
12161 for (location
= bpt
->loc
; location
; location
= location
->next
)
12162 target_enable_tracepoint (location
);
12165 bpt
->disposition
= disposition
;
12166 update_global_location_list (1);
12167 breakpoints_changed ();
12169 observer_notify_breakpoint_modified (bpt
);
12174 enable_breakpoint (struct breakpoint
*bpt
)
12176 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12180 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12182 enable_breakpoint (bpt
);
12185 /* A callback for map_breakpoint_numbers that calls
12186 enable_breakpoint. */
12189 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12191 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12194 /* The enable command enables the specified breakpoints (or all defined
12195 breakpoints) so they once again become (or continue to be) effective
12196 in stopping the inferior. */
12199 enable_command (char *args
, int from_tty
)
12203 struct breakpoint
*bpt
;
12205 ALL_BREAKPOINTS (bpt
)
12206 if (user_breakpoint_p (bpt
))
12207 enable_breakpoint (bpt
);
12209 else if (strchr (args
, '.'))
12211 struct bp_location
*loc
= find_location_by_number (args
);
12215 if (target_supports_enable_disable_tracepoint ()
12216 && current_trace_status ()->running
&& loc
->owner
12217 && is_tracepoint (loc
->owner
))
12218 target_enable_tracepoint (loc
);
12220 update_global_location_list (1);
12223 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12227 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12229 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12231 enable_breakpoint_disp (bpt
, disp
);
12235 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12237 enum bpdisp disp
= disp_disable
;
12239 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12243 enable_once_command (char *args
, int from_tty
)
12245 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12249 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12251 enum bpdisp disp
= disp_del
;
12253 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12257 enable_delete_command (char *args
, int from_tty
)
12259 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12263 set_breakpoint_cmd (char *args
, int from_tty
)
12268 show_breakpoint_cmd (char *args
, int from_tty
)
12272 /* Invalidate last known value of any hardware watchpoint if
12273 the memory which that value represents has been written to by
12277 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12278 const bfd_byte
*data
)
12280 struct breakpoint
*bp
;
12282 ALL_BREAKPOINTS (bp
)
12283 if (bp
->enable_state
== bp_enabled
12284 && bp
->type
== bp_hardware_watchpoint
)
12286 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12288 if (wp
->val_valid
&& wp
->val
)
12290 struct bp_location
*loc
;
12292 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12293 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12294 && loc
->address
+ loc
->length
> addr
12295 && addr
+ len
> loc
->address
)
12297 value_free (wp
->val
);
12305 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12307 struct symtabs_and_lines
12308 decode_line_spec_1 (char *string
, int funfirstline
)
12310 struct symtabs_and_lines sals
;
12313 error (_("Empty line specification."));
12314 if (default_breakpoint_valid
)
12315 sals
= decode_line_1 (&string
, funfirstline
,
12316 default_breakpoint_symtab
,
12317 default_breakpoint_line
,
12320 sals
= decode_line_1 (&string
, funfirstline
,
12321 (struct symtab
*) NULL
, 0, NULL
);
12323 error (_("Junk at end of line specification: %s"), string
);
12327 /* Create and insert a raw software breakpoint at PC. Return an
12328 identifier, which should be used to remove the breakpoint later.
12329 In general, places which call this should be using something on the
12330 breakpoint chain instead; this function should be eliminated
12334 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12335 struct address_space
*aspace
, CORE_ADDR pc
)
12337 struct bp_target_info
*bp_tgt
;
12339 bp_tgt
= XZALLOC (struct bp_target_info
);
12341 bp_tgt
->placed_address_space
= aspace
;
12342 bp_tgt
->placed_address
= pc
;
12344 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12346 /* Could not insert the breakpoint. */
12354 /* Remove a breakpoint BP inserted by
12355 deprecated_insert_raw_breakpoint. */
12358 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12360 struct bp_target_info
*bp_tgt
= bp
;
12363 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12369 /* One (or perhaps two) breakpoints used for software single
12372 static void *single_step_breakpoints
[2];
12373 static struct gdbarch
*single_step_gdbarch
[2];
12375 /* Create and insert a breakpoint for software single step. */
12378 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12379 struct address_space
*aspace
,
12384 if (single_step_breakpoints
[0] == NULL
)
12386 bpt_p
= &single_step_breakpoints
[0];
12387 single_step_gdbarch
[0] = gdbarch
;
12391 gdb_assert (single_step_breakpoints
[1] == NULL
);
12392 bpt_p
= &single_step_breakpoints
[1];
12393 single_step_gdbarch
[1] = gdbarch
;
12396 /* NOTE drow/2006-04-11: A future improvement to this function would
12397 be to only create the breakpoints once, and actually put them on
12398 the breakpoint chain. That would let us use set_raw_breakpoint.
12399 We could adjust the addresses each time they were needed. Doing
12400 this requires corresponding changes elsewhere where single step
12401 breakpoints are handled, however. So, for now, we use this. */
12403 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12404 if (*bpt_p
== NULL
)
12405 error (_("Could not insert single-step breakpoint at %s"),
12406 paddress (gdbarch
, next_pc
));
12409 /* Check if the breakpoints used for software single stepping
12410 were inserted or not. */
12413 single_step_breakpoints_inserted (void)
12415 return (single_step_breakpoints
[0] != NULL
12416 || single_step_breakpoints
[1] != NULL
);
12419 /* Remove and delete any breakpoints used for software single step. */
12422 remove_single_step_breakpoints (void)
12424 gdb_assert (single_step_breakpoints
[0] != NULL
);
12426 /* See insert_single_step_breakpoint for more about this deprecated
12428 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12429 single_step_breakpoints
[0]);
12430 single_step_gdbarch
[0] = NULL
;
12431 single_step_breakpoints
[0] = NULL
;
12433 if (single_step_breakpoints
[1] != NULL
)
12435 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12436 single_step_breakpoints
[1]);
12437 single_step_gdbarch
[1] = NULL
;
12438 single_step_breakpoints
[1] = NULL
;
12442 /* Delete software single step breakpoints without removing them from
12443 the inferior. This is intended to be used if the inferior's address
12444 space where they were inserted is already gone, e.g. after exit or
12448 cancel_single_step_breakpoints (void)
12452 for (i
= 0; i
< 2; i
++)
12453 if (single_step_breakpoints
[i
])
12455 xfree (single_step_breakpoints
[i
]);
12456 single_step_breakpoints
[i
] = NULL
;
12457 single_step_gdbarch
[i
] = NULL
;
12461 /* Detach software single-step breakpoints from INFERIOR_PTID without
12465 detach_single_step_breakpoints (void)
12469 for (i
= 0; i
< 2; i
++)
12470 if (single_step_breakpoints
[i
])
12471 target_remove_breakpoint (single_step_gdbarch
[i
],
12472 single_step_breakpoints
[i
]);
12475 /* Check whether a software single-step breakpoint is inserted at
12479 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12484 for (i
= 0; i
< 2; i
++)
12486 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12488 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12489 bp_tgt
->placed_address
,
12497 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12498 non-zero otherwise. */
12500 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12502 if (syscall_catchpoint_p (bp
)
12503 && bp
->enable_state
!= bp_disabled
12504 && bp
->enable_state
!= bp_call_disabled
)
12511 catch_syscall_enabled (void)
12513 struct inferior
*inf
= current_inferior ();
12515 return inf
->total_syscalls_count
!= 0;
12519 catching_syscall_number (int syscall_number
)
12521 struct breakpoint
*bp
;
12523 ALL_BREAKPOINTS (bp
)
12524 if (is_syscall_catchpoint_enabled (bp
))
12526 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12528 if (c
->syscalls_to_be_caught
)
12532 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12534 if (syscall_number
== iter
)
12544 /* Complete syscall names. Used by "catch syscall". */
12546 catch_syscall_completer (struct cmd_list_element
*cmd
,
12547 char *text
, char *word
)
12549 const char **list
= get_syscall_names ();
12551 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12557 /* Tracepoint-specific operations. */
12559 /* Set tracepoint count to NUM. */
12561 set_tracepoint_count (int num
)
12563 tracepoint_count
= num
;
12564 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12568 trace_command (char *arg
, int from_tty
)
12570 if (create_breakpoint (get_current_arch (),
12572 NULL
, 0, 1 /* parse arg */,
12574 bp_tracepoint
/* type_wanted */,
12575 0 /* Ignore count */,
12576 pending_break_support
,
12577 &tracepoint_breakpoint_ops
,
12581 set_tracepoint_count (breakpoint_count
);
12585 ftrace_command (char *arg
, int from_tty
)
12587 if (create_breakpoint (get_current_arch (),
12589 NULL
, 0, 1 /* parse arg */,
12591 bp_fast_tracepoint
/* type_wanted */,
12592 0 /* Ignore count */,
12593 pending_break_support
,
12594 &tracepoint_breakpoint_ops
,
12598 set_tracepoint_count (breakpoint_count
);
12601 /* strace command implementation. Creates a static tracepoint. */
12604 strace_command (char *arg
, int from_tty
)
12606 if (create_breakpoint (get_current_arch (),
12608 NULL
, 0, 1 /* parse arg */,
12610 bp_static_tracepoint
/* type_wanted */,
12611 0 /* Ignore count */,
12612 pending_break_support
,
12613 &tracepoint_breakpoint_ops
,
12617 set_tracepoint_count (breakpoint_count
);
12620 /* Set up a fake reader function that gets command lines from a linked
12621 list that was acquired during tracepoint uploading. */
12623 static struct uploaded_tp
*this_utp
;
12624 static int next_cmd
;
12627 read_uploaded_action (void)
12631 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12638 /* Given information about a tracepoint as recorded on a target (which
12639 can be either a live system or a trace file), attempt to create an
12640 equivalent GDB tracepoint. This is not a reliable process, since
12641 the target does not necessarily have all the information used when
12642 the tracepoint was originally defined. */
12644 struct tracepoint
*
12645 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12647 char *addr_str
, small_buf
[100];
12648 struct tracepoint
*tp
;
12650 if (utp
->at_string
)
12651 addr_str
= utp
->at_string
;
12654 /* In the absence of a source location, fall back to raw
12655 address. Since there is no way to confirm that the address
12656 means the same thing as when the trace was started, warn the
12658 warning (_("Uploaded tracepoint %d has no "
12659 "source location, using raw address"),
12661 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12662 addr_str
= small_buf
;
12665 /* There's not much we can do with a sequence of bytecodes. */
12666 if (utp
->cond
&& !utp
->cond_string
)
12667 warning (_("Uploaded tracepoint %d condition "
12668 "has no source form, ignoring it"),
12671 if (!create_breakpoint (get_current_arch (),
12673 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12675 utp
->type
/* type_wanted */,
12676 0 /* Ignore count */,
12677 pending_break_support
,
12678 &tracepoint_breakpoint_ops
,
12680 utp
->enabled
/* enabled */,
12684 set_tracepoint_count (breakpoint_count
);
12686 /* Get the tracepoint we just created. */
12687 tp
= get_tracepoint (tracepoint_count
);
12688 gdb_assert (tp
!= NULL
);
12692 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
12694 trace_pass_command (small_buf
, 0);
12697 /* If we have uploaded versions of the original commands, set up a
12698 special-purpose "reader" function and call the usual command line
12699 reader, then pass the result to the breakpoint command-setting
12701 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12703 struct command_line
*cmd_list
;
12708 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12710 breakpoint_set_commands (&tp
->base
, cmd_list
);
12712 else if (!VEC_empty (char_ptr
, utp
->actions
)
12713 || !VEC_empty (char_ptr
, utp
->step_actions
))
12714 warning (_("Uploaded tracepoint %d actions "
12715 "have no source form, ignoring them"),
12721 /* Print information on tracepoint number TPNUM_EXP, or all if
12725 tracepoints_info (char *args
, int from_tty
)
12729 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12731 if (num_printed
== 0)
12733 if (args
== NULL
|| *args
== '\0')
12734 ui_out_message (uiout
, 0, "No tracepoints.\n");
12736 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12739 default_collect_info ();
12742 /* The 'enable trace' command enables tracepoints.
12743 Not supported by all targets. */
12745 enable_trace_command (char *args
, int from_tty
)
12747 enable_command (args
, from_tty
);
12750 /* The 'disable trace' command disables tracepoints.
12751 Not supported by all targets. */
12753 disable_trace_command (char *args
, int from_tty
)
12755 disable_command (args
, from_tty
);
12758 /* Remove a tracepoint (or all if no argument). */
12760 delete_trace_command (char *arg
, int from_tty
)
12762 struct breakpoint
*b
, *b_tmp
;
12768 int breaks_to_delete
= 0;
12770 /* Delete all breakpoints if no argument.
12771 Do not delete internal or call-dummy breakpoints, these
12772 have to be deleted with an explicit breakpoint number
12774 ALL_TRACEPOINTS (b
)
12775 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12777 breaks_to_delete
= 1;
12781 /* Ask user only if there are some breakpoints to delete. */
12783 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12785 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12786 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12787 delete_breakpoint (b
);
12791 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12794 /* Helper function for trace_pass_command. */
12797 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
12799 tp
->pass_count
= count
;
12800 observer_notify_tracepoint_modified (tp
->base
.number
);
12802 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12803 tp
->base
.number
, count
);
12806 /* Set passcount for tracepoint.
12808 First command argument is passcount, second is tracepoint number.
12809 If tracepoint number omitted, apply to most recently defined.
12810 Also accepts special argument "all". */
12813 trace_pass_command (char *args
, int from_tty
)
12815 struct tracepoint
*t1
;
12816 unsigned int count
;
12818 if (args
== 0 || *args
== 0)
12819 error (_("passcount command requires an "
12820 "argument (count + optional TP num)"));
12822 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
12824 while (*args
&& isspace ((int) *args
))
12827 if (*args
&& strncasecmp (args
, "all", 3) == 0)
12829 struct breakpoint
*b
;
12831 args
+= 3; /* Skip special argument "all". */
12833 error (_("Junk at end of arguments."));
12835 ALL_TRACEPOINTS (b
)
12837 t1
= (struct tracepoint
*) b
;
12838 trace_pass_set_count (t1
, count
, from_tty
);
12841 else if (*args
== '\0')
12843 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
12845 trace_pass_set_count (t1
, count
, from_tty
);
12849 struct get_number_or_range_state state
;
12851 init_number_or_range (&state
, args
);
12852 while (!state
.finished
)
12854 t1
= get_tracepoint_by_number (&args
, &state
, 1);
12856 trace_pass_set_count (t1
, count
, from_tty
);
12861 struct tracepoint
*
12862 get_tracepoint (int num
)
12864 struct breakpoint
*t
;
12866 ALL_TRACEPOINTS (t
)
12867 if (t
->number
== num
)
12868 return (struct tracepoint
*) t
;
12873 /* Find the tracepoint with the given target-side number (which may be
12874 different from the tracepoint number after disconnecting and
12877 struct tracepoint
*
12878 get_tracepoint_by_number_on_target (int num
)
12880 struct breakpoint
*b
;
12882 ALL_TRACEPOINTS (b
)
12884 struct tracepoint
*t
= (struct tracepoint
*) b
;
12886 if (t
->number_on_target
== num
)
12893 /* Utility: parse a tracepoint number and look it up in the list.
12894 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12895 If OPTIONAL_P is true, then if the argument is missing, the most
12896 recent tracepoint (tracepoint_count) is returned. */
12897 struct tracepoint
*
12898 get_tracepoint_by_number (char **arg
,
12899 struct get_number_or_range_state
*state
,
12902 extern int tracepoint_count
;
12903 struct breakpoint
*t
;
12905 char *instring
= arg
== NULL
? NULL
: *arg
;
12909 gdb_assert (!state
->finished
);
12910 tpnum
= get_number_or_range (state
);
12912 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
12915 tpnum
= tracepoint_count
;
12917 error_no_arg (_("tracepoint number"));
12920 tpnum
= get_number (arg
);
12924 if (instring
&& *instring
)
12925 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12928 printf_filtered (_("Tracepoint argument missing "
12929 "and no previous tracepoint\n"));
12933 ALL_TRACEPOINTS (t
)
12934 if (t
->number
== tpnum
)
12936 return (struct tracepoint
*) t
;
12939 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
12944 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
12946 if (b
->thread
!= -1)
12947 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
12950 fprintf_unfiltered (fp
, " task %d", b
->task
);
12952 fprintf_unfiltered (fp
, "\n");
12955 /* Save information on user settable breakpoints (watchpoints, etc) to
12956 a new script file named FILENAME. If FILTER is non-NULL, call it
12957 on each breakpoint and only include the ones for which it returns
12961 save_breakpoints (char *filename
, int from_tty
,
12962 int (*filter
) (const struct breakpoint
*))
12964 struct breakpoint
*tp
;
12967 struct cleanup
*cleanup
;
12968 struct ui_file
*fp
;
12969 int extra_trace_bits
= 0;
12971 if (filename
== 0 || *filename
== 0)
12972 error (_("Argument required (file name in which to save)"));
12974 /* See if we have anything to save. */
12975 ALL_BREAKPOINTS (tp
)
12977 /* Skip internal and momentary breakpoints. */
12978 if (!user_breakpoint_p (tp
))
12981 /* If we have a filter, only save the breakpoints it accepts. */
12982 if (filter
&& !filter (tp
))
12987 if (is_tracepoint (tp
))
12989 extra_trace_bits
= 1;
12991 /* We can stop searching. */
12998 warning (_("Nothing to save."));
13002 pathname
= tilde_expand (filename
);
13003 cleanup
= make_cleanup (xfree
, pathname
);
13004 fp
= gdb_fopen (pathname
, "w");
13006 error (_("Unable to open file '%s' for saving (%s)"),
13007 filename
, safe_strerror (errno
));
13008 make_cleanup_ui_file_delete (fp
);
13010 if (extra_trace_bits
)
13011 save_trace_state_variables (fp
);
13013 ALL_BREAKPOINTS (tp
)
13015 /* Skip internal and momentary breakpoints. */
13016 if (!user_breakpoint_p (tp
))
13019 /* If we have a filter, only save the breakpoints it accepts. */
13020 if (filter
&& !filter (tp
))
13023 tp
->ops
->print_recreate (tp
, fp
);
13025 /* Note, we can't rely on tp->number for anything, as we can't
13026 assume the recreated breakpoint numbers will match. Use $bpnum
13029 if (tp
->cond_string
)
13030 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13032 if (tp
->ignore_count
)
13033 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13037 volatile struct gdb_exception ex
;
13039 fprintf_unfiltered (fp
, " commands\n");
13041 ui_out_redirect (uiout
, fp
);
13042 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13044 print_command_lines (uiout
, tp
->commands
->commands
, 2);
13046 ui_out_redirect (uiout
, NULL
);
13049 throw_exception (ex
);
13051 fprintf_unfiltered (fp
, " end\n");
13054 if (tp
->enable_state
== bp_disabled
)
13055 fprintf_unfiltered (fp
, "disable\n");
13057 /* If this is a multi-location breakpoint, check if the locations
13058 should be individually disabled. Watchpoint locations are
13059 special, and not user visible. */
13060 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13062 struct bp_location
*loc
;
13065 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13067 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13071 if (extra_trace_bits
&& *default_collect
)
13072 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13074 do_cleanups (cleanup
);
13076 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13079 /* The `save breakpoints' command. */
13082 save_breakpoints_command (char *args
, int from_tty
)
13084 save_breakpoints (args
, from_tty
, NULL
);
13087 /* The `save tracepoints' command. */
13090 save_tracepoints_command (char *args
, int from_tty
)
13092 save_breakpoints (args
, from_tty
, is_tracepoint
);
13095 /* Create a vector of all tracepoints. */
13097 VEC(breakpoint_p
) *
13098 all_tracepoints (void)
13100 VEC(breakpoint_p
) *tp_vec
= 0;
13101 struct breakpoint
*tp
;
13103 ALL_TRACEPOINTS (tp
)
13105 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13112 /* This help string is used for the break, hbreak, tbreak and thbreak
13113 commands. It is defined as a macro to prevent duplication.
13114 COMMAND should be a string constant containing the name of the
13116 #define BREAK_ARGS_HELP(command) \
13117 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13118 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13119 If a line number is specified, break at start of code for that line.\n\
13120 If a function is specified, break at start of code for that function.\n\
13121 If an address is specified, break at that exact address.\n\
13122 With no LOCATION, uses current execution address of the selected\n\
13123 stack frame. This is useful for breaking on return to a stack frame.\n\
13125 THREADNUM is the number from \"info threads\".\n\
13126 CONDITION is a boolean expression.\n\
13128 Multiple breakpoints at one place are permitted, and useful if their\n\
13129 conditions are different.\n\
13131 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13133 /* List of subcommands for "catch". */
13134 static struct cmd_list_element
*catch_cmdlist
;
13136 /* List of subcommands for "tcatch". */
13137 static struct cmd_list_element
*tcatch_cmdlist
;
13140 add_catch_command (char *name
, char *docstring
,
13141 void (*sfunc
) (char *args
, int from_tty
,
13142 struct cmd_list_element
*command
),
13143 char **(*completer
) (struct cmd_list_element
*cmd
,
13144 char *text
, char *word
),
13145 void *user_data_catch
,
13146 void *user_data_tcatch
)
13148 struct cmd_list_element
*command
;
13150 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13152 set_cmd_sfunc (command
, sfunc
);
13153 set_cmd_context (command
, user_data_catch
);
13154 set_cmd_completer (command
, completer
);
13156 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13158 set_cmd_sfunc (command
, sfunc
);
13159 set_cmd_context (command
, user_data_tcatch
);
13160 set_cmd_completer (command
, completer
);
13164 clear_syscall_counts (struct inferior
*inf
)
13166 inf
->total_syscalls_count
= 0;
13167 inf
->any_syscall_count
= 0;
13168 VEC_free (int, inf
->syscalls_counts
);
13172 save_command (char *arg
, int from_tty
)
13174 printf_unfiltered (_("\"save\" must be followed by "
13175 "the name of a save subcommand.\n"));
13176 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13179 struct breakpoint
*
13180 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13183 struct breakpoint
*b
, *b_tmp
;
13185 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13187 if ((*callback
) (b
, data
))
13195 initialize_breakpoint_ops (void)
13197 static int initialized
= 0;
13199 struct breakpoint_ops
*ops
;
13205 /* The breakpoint_ops structure to be inherit by all kinds of
13206 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13207 internal and momentary breakpoints, etc.). */
13208 ops
= &bkpt_base_breakpoint_ops
;
13209 *ops
= base_breakpoint_ops
;
13210 ops
->re_set
= bkpt_re_set
;
13211 ops
->insert_location
= bkpt_insert_location
;
13212 ops
->remove_location
= bkpt_remove_location
;
13213 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13215 /* The breakpoint_ops structure to be used in regular breakpoints. */
13216 ops
= &bkpt_breakpoint_ops
;
13217 *ops
= bkpt_base_breakpoint_ops
;
13218 ops
->re_set
= bkpt_re_set
;
13219 ops
->resources_needed
= bkpt_resources_needed
;
13220 ops
->print_it
= bkpt_print_it
;
13221 ops
->print_mention
= bkpt_print_mention
;
13222 ops
->print_recreate
= bkpt_print_recreate
;
13224 /* Ranged breakpoints. */
13225 ops
= &ranged_breakpoint_ops
;
13226 *ops
= bkpt_breakpoint_ops
;
13227 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13228 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13229 ops
->print_it
= print_it_ranged_breakpoint
;
13230 ops
->print_one
= print_one_ranged_breakpoint
;
13231 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13232 ops
->print_mention
= print_mention_ranged_breakpoint
;
13233 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13235 /* Internal breakpoints. */
13236 ops
= &internal_breakpoint_ops
;
13237 *ops
= bkpt_base_breakpoint_ops
;
13238 ops
->re_set
= internal_bkpt_re_set
;
13239 ops
->check_status
= internal_bkpt_check_status
;
13240 ops
->print_it
= internal_bkpt_print_it
;
13241 ops
->print_mention
= internal_bkpt_print_mention
;
13243 /* Momentary breakpoints. */
13244 ops
= &momentary_breakpoint_ops
;
13245 *ops
= bkpt_base_breakpoint_ops
;
13246 ops
->re_set
= momentary_bkpt_re_set
;
13247 ops
->check_status
= momentary_bkpt_check_status
;
13248 ops
->print_it
= momentary_bkpt_print_it
;
13249 ops
->print_mention
= momentary_bkpt_print_mention
;
13251 /* GNU v3 exception catchpoints. */
13252 ops
= &gnu_v3_exception_catchpoint_ops
;
13253 *ops
= bkpt_breakpoint_ops
;
13254 ops
->print_it
= print_it_exception_catchpoint
;
13255 ops
->print_one
= print_one_exception_catchpoint
;
13256 ops
->print_mention
= print_mention_exception_catchpoint
;
13257 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13260 ops
= &watchpoint_breakpoint_ops
;
13261 *ops
= base_breakpoint_ops
;
13262 ops
->dtor
= dtor_watchpoint
;
13263 ops
->re_set
= re_set_watchpoint
;
13264 ops
->insert_location
= insert_watchpoint
;
13265 ops
->remove_location
= remove_watchpoint
;
13266 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13267 ops
->check_status
= check_status_watchpoint
;
13268 ops
->resources_needed
= resources_needed_watchpoint
;
13269 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13270 ops
->print_it
= print_it_watchpoint
;
13271 ops
->print_mention
= print_mention_watchpoint
;
13272 ops
->print_recreate
= print_recreate_watchpoint
;
13274 /* Masked watchpoints. */
13275 ops
= &masked_watchpoint_breakpoint_ops
;
13276 *ops
= watchpoint_breakpoint_ops
;
13277 ops
->insert_location
= insert_masked_watchpoint
;
13278 ops
->remove_location
= remove_masked_watchpoint
;
13279 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13280 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13281 ops
->print_it
= print_it_masked_watchpoint
;
13282 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13283 ops
->print_mention
= print_mention_masked_watchpoint
;
13284 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13287 ops
= &tracepoint_breakpoint_ops
;
13288 *ops
= base_breakpoint_ops
;
13289 ops
->re_set
= tracepoint_re_set
;
13290 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13291 ops
->print_one_detail
= tracepoint_print_one_detail
;
13292 ops
->print_mention
= tracepoint_print_mention
;
13293 ops
->print_recreate
= tracepoint_print_recreate
;
13295 /* Fork catchpoints. */
13296 ops
= &catch_fork_breakpoint_ops
;
13297 *ops
= base_breakpoint_ops
;
13298 ops
->insert_location
= insert_catch_fork
;
13299 ops
->remove_location
= remove_catch_fork
;
13300 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13301 ops
->print_it
= print_it_catch_fork
;
13302 ops
->print_one
= print_one_catch_fork
;
13303 ops
->print_mention
= print_mention_catch_fork
;
13304 ops
->print_recreate
= print_recreate_catch_fork
;
13306 /* Vfork catchpoints. */
13307 ops
= &catch_vfork_breakpoint_ops
;
13308 *ops
= base_breakpoint_ops
;
13309 ops
->insert_location
= insert_catch_vfork
;
13310 ops
->remove_location
= remove_catch_vfork
;
13311 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13312 ops
->print_it
= print_it_catch_vfork
;
13313 ops
->print_one
= print_one_catch_vfork
;
13314 ops
->print_mention
= print_mention_catch_vfork
;
13315 ops
->print_recreate
= print_recreate_catch_vfork
;
13317 /* Exec catchpoints. */
13318 ops
= &catch_exec_breakpoint_ops
;
13319 *ops
= base_breakpoint_ops
;
13320 ops
->dtor
= dtor_catch_exec
;
13321 ops
->insert_location
= insert_catch_exec
;
13322 ops
->remove_location
= remove_catch_exec
;
13323 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13324 ops
->print_it
= print_it_catch_exec
;
13325 ops
->print_one
= print_one_catch_exec
;
13326 ops
->print_mention
= print_mention_catch_exec
;
13327 ops
->print_recreate
= print_recreate_catch_exec
;
13329 /* Syscall catchpoints. */
13330 ops
= &catch_syscall_breakpoint_ops
;
13331 *ops
= base_breakpoint_ops
;
13332 ops
->dtor
= dtor_catch_syscall
;
13333 ops
->insert_location
= insert_catch_syscall
;
13334 ops
->remove_location
= remove_catch_syscall
;
13335 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13336 ops
->print_it
= print_it_catch_syscall
;
13337 ops
->print_one
= print_one_catch_syscall
;
13338 ops
->print_mention
= print_mention_catch_syscall
;
13339 ops
->print_recreate
= print_recreate_catch_syscall
;
13343 _initialize_breakpoint (void)
13345 struct cmd_list_element
*c
;
13347 initialize_breakpoint_ops ();
13349 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13350 observer_attach_inferior_exit (clear_syscall_counts
);
13351 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13353 breakpoint_objfile_key
= register_objfile_data ();
13355 breakpoint_chain
= 0;
13356 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13357 before a breakpoint is set. */
13358 breakpoint_count
= 0;
13360 tracepoint_count
= 0;
13362 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13363 Set ignore-count of breakpoint number N to COUNT.\n\
13364 Usage is `ignore N COUNT'."));
13366 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13368 add_com ("commands", class_breakpoint
, commands_command
, _("\
13369 Set commands to be executed when a breakpoint is hit.\n\
13370 Give breakpoint number as argument after \"commands\".\n\
13371 With no argument, the targeted breakpoint is the last one set.\n\
13372 The commands themselves follow starting on the next line.\n\
13373 Type a line containing \"end\" to indicate the end of them.\n\
13374 Give \"silent\" as the first line to make the breakpoint silent;\n\
13375 then no output is printed when it is hit, except what the commands print."));
13377 add_com ("condition", class_breakpoint
, condition_command
, _("\
13378 Specify breakpoint number N to break only if COND is true.\n\
13379 Usage is `condition N COND', where N is an integer and COND is an\n\
13380 expression to be evaluated whenever breakpoint N is reached."));
13382 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13383 Set a temporary breakpoint.\n\
13384 Like \"break\" except the breakpoint is only temporary,\n\
13385 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13386 by using \"enable delete\" on the breakpoint number.\n\
13388 BREAK_ARGS_HELP ("tbreak")));
13389 set_cmd_completer (c
, location_completer
);
13391 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13392 Set a hardware assisted breakpoint.\n\
13393 Like \"break\" except the breakpoint requires hardware support,\n\
13394 some target hardware may not have this support.\n\
13396 BREAK_ARGS_HELP ("hbreak")));
13397 set_cmd_completer (c
, location_completer
);
13399 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13400 Set a temporary hardware assisted breakpoint.\n\
13401 Like \"hbreak\" except the breakpoint is only temporary,\n\
13402 so it will be deleted when hit.\n\
13404 BREAK_ARGS_HELP ("thbreak")));
13405 set_cmd_completer (c
, location_completer
);
13407 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13408 Enable some breakpoints.\n\
13409 Give breakpoint numbers (separated by spaces) as arguments.\n\
13410 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13411 This is used to cancel the effect of the \"disable\" command.\n\
13412 With a subcommand you can enable temporarily."),
13413 &enablelist
, "enable ", 1, &cmdlist
);
13415 add_com ("ab", class_breakpoint
, enable_command
, _("\
13416 Enable some breakpoints.\n\
13417 Give breakpoint numbers (separated by spaces) as arguments.\n\
13418 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13419 This is used to cancel the effect of the \"disable\" command.\n\
13420 With a subcommand you can enable temporarily."));
13422 add_com_alias ("en", "enable", class_breakpoint
, 1);
13424 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13425 Enable some breakpoints.\n\
13426 Give breakpoint numbers (separated by spaces) as arguments.\n\
13427 This is used to cancel the effect of the \"disable\" command.\n\
13428 May be abbreviated to simply \"enable\".\n"),
13429 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13431 add_cmd ("once", no_class
, enable_once_command
, _("\
13432 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13433 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13436 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13437 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13438 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13441 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13442 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13443 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13446 add_cmd ("once", no_class
, enable_once_command
, _("\
13447 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13448 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13451 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13452 Disable some breakpoints.\n\
13453 Arguments are breakpoint numbers with spaces in between.\n\
13454 To disable all breakpoints, give no argument.\n\
13455 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13456 &disablelist
, "disable ", 1, &cmdlist
);
13457 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13458 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13460 add_com ("sb", class_breakpoint
, disable_command
, _("\
13461 Disable some breakpoints.\n\
13462 Arguments are breakpoint numbers with spaces in between.\n\
13463 To disable all breakpoints, give no argument.\n\
13464 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13466 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13467 Disable some breakpoints.\n\
13468 Arguments are breakpoint numbers with spaces in between.\n\
13469 To disable all breakpoints, give no argument.\n\
13470 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13471 This command may be abbreviated \"disable\"."),
13474 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13475 Delete some breakpoints or auto-display expressions.\n\
13476 Arguments are breakpoint numbers with spaces in between.\n\
13477 To delete all breakpoints, give no argument.\n\
13479 Also a prefix command for deletion of other GDB objects.\n\
13480 The \"unset\" command is also an alias for \"delete\"."),
13481 &deletelist
, "delete ", 1, &cmdlist
);
13482 add_com_alias ("d", "delete", class_breakpoint
, 1);
13483 add_com_alias ("del", "delete", class_breakpoint
, 1);
13485 add_com ("db", class_breakpoint
, delete_command
, _("\
13486 Delete some breakpoints.\n\
13487 Arguments are breakpoint numbers with spaces in between.\n\
13488 To delete all breakpoints, give no argument.\n"));
13490 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13491 Delete some breakpoints or auto-display expressions.\n\
13492 Arguments are breakpoint numbers with spaces in between.\n\
13493 To delete all breakpoints, give no argument.\n\
13494 This command may be abbreviated \"delete\"."),
13497 add_com ("clear", class_breakpoint
, clear_command
, _("\
13498 Clear breakpoint at specified line or function.\n\
13499 Argument may be line number, function name, or \"*\" and an address.\n\
13500 If line number is specified, all breakpoints in that line are cleared.\n\
13501 If function is specified, breakpoints at beginning of function are cleared.\n\
13502 If an address is specified, breakpoints at that address are cleared.\n\
13504 With no argument, clears all breakpoints in the line that the selected frame\n\
13505 is executing in.\n\
13507 See also the \"delete\" command which clears breakpoints by number."));
13508 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13510 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13511 Set breakpoint at specified line or function.\n"
13512 BREAK_ARGS_HELP ("break")));
13513 set_cmd_completer (c
, location_completer
);
13515 add_com_alias ("b", "break", class_run
, 1);
13516 add_com_alias ("br", "break", class_run
, 1);
13517 add_com_alias ("bre", "break", class_run
, 1);
13518 add_com_alias ("brea", "break", class_run
, 1);
13521 add_com_alias ("ba", "break", class_breakpoint
, 1);
13525 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13526 Break in function/address or break at a line in the current file."),
13527 &stoplist
, "stop ", 1, &cmdlist
);
13528 add_cmd ("in", class_breakpoint
, stopin_command
,
13529 _("Break in function or address."), &stoplist
);
13530 add_cmd ("at", class_breakpoint
, stopat_command
,
13531 _("Break at a line in the current file."), &stoplist
);
13532 add_com ("status", class_info
, breakpoints_info
, _("\
13533 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13534 The \"Type\" column indicates one of:\n\
13535 \tbreakpoint - normal breakpoint\n\
13536 \twatchpoint - watchpoint\n\
13537 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13538 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13539 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13540 address and file/line number respectively.\n\
13542 Convenience variable \"$_\" and default examine address for \"x\"\n\
13543 are set to the address of the last breakpoint listed unless the command\n\
13544 is prefixed with \"server \".\n\n\
13545 Convenience variable \"$bpnum\" contains the number of the last\n\
13546 breakpoint set."));
13549 add_info ("breakpoints", breakpoints_info
, _("\
13550 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13551 The \"Type\" column indicates one of:\n\
13552 \tbreakpoint - normal breakpoint\n\
13553 \twatchpoint - watchpoint\n\
13554 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13555 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13556 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13557 address and file/line number respectively.\n\
13559 Convenience variable \"$_\" and default examine address for \"x\"\n\
13560 are set to the address of the last breakpoint listed unless the command\n\
13561 is prefixed with \"server \".\n\n\
13562 Convenience variable \"$bpnum\" contains the number of the last\n\
13563 breakpoint set."));
13565 add_info_alias ("b", "breakpoints", 1);
13568 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13569 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13570 The \"Type\" column indicates one of:\n\
13571 \tbreakpoint - normal breakpoint\n\
13572 \twatchpoint - watchpoint\n\
13573 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13574 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13575 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13576 address and file/line number respectively.\n\
13578 Convenience variable \"$_\" and default examine address for \"x\"\n\
13579 are set to the address of the last breakpoint listed unless the command\n\
13580 is prefixed with \"server \".\n\n\
13581 Convenience variable \"$bpnum\" contains the number of the last\n\
13582 breakpoint set."));
13584 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13585 Status of all breakpoints, or breakpoint number NUMBER.\n\
13586 The \"Type\" column indicates one of:\n\
13587 \tbreakpoint - normal breakpoint\n\
13588 \twatchpoint - watchpoint\n\
13589 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13590 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13591 \tuntil - internal breakpoint used by the \"until\" command\n\
13592 \tfinish - internal breakpoint used by the \"finish\" command\n\
13593 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13594 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13595 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13596 address and file/line number respectively.\n\
13598 Convenience variable \"$_\" and default examine address for \"x\"\n\
13599 are set to the address of the last breakpoint listed unless the command\n\
13600 is prefixed with \"server \".\n\n\
13601 Convenience variable \"$bpnum\" contains the number of the last\n\
13603 &maintenanceinfolist
);
13605 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13606 Set catchpoints to catch events."),
13607 &catch_cmdlist
, "catch ",
13608 0/*allow-unknown*/, &cmdlist
);
13610 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13611 Set temporary catchpoints to catch events."),
13612 &tcatch_cmdlist
, "tcatch ",
13613 0/*allow-unknown*/, &cmdlist
);
13615 /* Add catch and tcatch sub-commands. */
13616 add_catch_command ("catch", _("\
13617 Catch an exception, when caught.\n\
13618 With an argument, catch only exceptions with the given name."),
13619 catch_catch_command
,
13623 add_catch_command ("throw", _("\
13624 Catch an exception, when thrown.\n\
13625 With an argument, catch only exceptions with the given name."),
13626 catch_throw_command
,
13630 add_catch_command ("fork", _("Catch calls to fork."),
13631 catch_fork_command_1
,
13633 (void *) (uintptr_t) catch_fork_permanent
,
13634 (void *) (uintptr_t) catch_fork_temporary
);
13635 add_catch_command ("vfork", _("Catch calls to vfork."),
13636 catch_fork_command_1
,
13638 (void *) (uintptr_t) catch_vfork_permanent
,
13639 (void *) (uintptr_t) catch_vfork_temporary
);
13640 add_catch_command ("exec", _("Catch calls to exec."),
13641 catch_exec_command_1
,
13645 add_catch_command ("syscall", _("\
13646 Catch system calls by their names and/or numbers.\n\
13647 Arguments say which system calls to catch. If no arguments\n\
13648 are given, every system call will be caught.\n\
13649 Arguments, if given, should be one or more system call names\n\
13650 (if your system supports that), or system call numbers."),
13651 catch_syscall_command_1
,
13652 catch_syscall_completer
,
13656 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13657 Set a watchpoint for an expression.\n\
13658 Usage: watch [-l|-location] EXPRESSION\n\
13659 A watchpoint stops execution of your program whenever the value of\n\
13660 an expression changes.\n\
13661 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13662 the memory to which it refers."));
13663 set_cmd_completer (c
, expression_completer
);
13665 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13666 Set a read watchpoint for an expression.\n\
13667 Usage: rwatch [-l|-location] EXPRESSION\n\
13668 A watchpoint stops execution of your program whenever the value of\n\
13669 an expression is read.\n\
13670 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13671 the memory to which it refers."));
13672 set_cmd_completer (c
, expression_completer
);
13674 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13675 Set a watchpoint for an expression.\n\
13676 Usage: awatch [-l|-location] EXPRESSION\n\
13677 A watchpoint stops execution of your program whenever the value of\n\
13678 an expression is either read or written.\n\
13679 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13680 the memory to which it refers."));
13681 set_cmd_completer (c
, expression_completer
);
13683 add_info ("watchpoints", watchpoints_info
, _("\
13684 Status of specified watchpoints (all watchpoints if no argument)."));
13686 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13687 respond to changes - contrary to the description. */
13688 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13689 &can_use_hw_watchpoints
, _("\
13690 Set debugger's willingness to use watchpoint hardware."), _("\
13691 Show debugger's willingness to use watchpoint hardware."), _("\
13692 If zero, gdb will not use hardware for new watchpoints, even if\n\
13693 such is available. (However, any hardware watchpoints that were\n\
13694 created before setting this to nonzero, will continue to use watchpoint\n\
13697 show_can_use_hw_watchpoints
,
13698 &setlist
, &showlist
);
13700 can_use_hw_watchpoints
= 1;
13702 /* Tracepoint manipulation commands. */
13704 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13705 Set a tracepoint at specified line or function.\n\
13707 BREAK_ARGS_HELP ("trace") "\n\
13708 Do \"help tracepoints\" for info on other tracepoint commands."));
13709 set_cmd_completer (c
, location_completer
);
13711 add_com_alias ("tp", "trace", class_alias
, 0);
13712 add_com_alias ("tr", "trace", class_alias
, 1);
13713 add_com_alias ("tra", "trace", class_alias
, 1);
13714 add_com_alias ("trac", "trace", class_alias
, 1);
13716 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13717 Set a fast tracepoint at specified line or function.\n\
13719 BREAK_ARGS_HELP ("ftrace") "\n\
13720 Do \"help tracepoints\" for info on other tracepoint commands."));
13721 set_cmd_completer (c
, location_completer
);
13723 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13724 Set a static tracepoint at specified line, function or marker.\n\
13726 strace [LOCATION] [if CONDITION]\n\
13727 LOCATION may be a line number, function name, \"*\" and an address,\n\
13728 or -m MARKER_ID.\n\
13729 If a line number is specified, probe the marker at start of code\n\
13730 for that line. If a function is specified, probe the marker at start\n\
13731 of code for that function. If an address is specified, probe the marker\n\
13732 at that exact address. If a marker id is specified, probe the marker\n\
13733 with that name. With no LOCATION, uses current execution address of\n\
13734 the selected stack frame.\n\
13735 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13736 This collects arbitrary user data passed in the probe point call to the\n\
13737 tracing library. You can inspect it when analyzing the trace buffer,\n\
13738 by printing the $_sdata variable like any other convenience variable.\n\
13740 CONDITION is a boolean expression.\n\
13742 Multiple tracepoints at one place are permitted, and useful if their\n\
13743 conditions are different.\n\
13745 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13746 Do \"help tracepoints\" for info on other tracepoint commands."));
13747 set_cmd_completer (c
, location_completer
);
13749 add_info ("tracepoints", tracepoints_info
, _("\
13750 Status of specified tracepoints (all tracepoints if no argument).\n\
13751 Convenience variable \"$tpnum\" contains the number of the\n\
13752 last tracepoint set."));
13754 add_info_alias ("tp", "tracepoints", 1);
13756 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13757 Delete specified tracepoints.\n\
13758 Arguments are tracepoint numbers, separated by spaces.\n\
13759 No argument means delete all tracepoints."),
13762 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13763 Disable specified tracepoints.\n\
13764 Arguments are tracepoint numbers, separated by spaces.\n\
13765 No argument means disable all tracepoints."),
13767 deprecate_cmd (c
, "disable");
13769 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
13770 Enable specified tracepoints.\n\
13771 Arguments are tracepoint numbers, separated by spaces.\n\
13772 No argument means enable all tracepoints."),
13774 deprecate_cmd (c
, "enable");
13776 add_com ("passcount", class_trace
, trace_pass_command
, _("\
13777 Set the passcount for a tracepoint.\n\
13778 The trace will end when the tracepoint has been passed 'count' times.\n\
13779 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13780 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13782 add_prefix_cmd ("save", class_breakpoint
, save_command
,
13783 _("Save breakpoint definitions as a script."),
13784 &save_cmdlist
, "save ",
13785 0/*allow-unknown*/, &cmdlist
);
13787 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
13788 Save current breakpoint definitions as a script.\n\
13789 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13790 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13791 session to restore them."),
13793 set_cmd_completer (c
, filename_completer
);
13795 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
13796 Save current tracepoint definitions as a script.\n\
13797 Use the 'source' command in another debug session to restore them."),
13799 set_cmd_completer (c
, filename_completer
);
13801 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
13802 deprecate_cmd (c
, "save tracepoints");
13804 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
13805 Breakpoint specific settings\n\
13806 Configure various breakpoint-specific variables such as\n\
13807 pending breakpoint behavior"),
13808 &breakpoint_set_cmdlist
, "set breakpoint ",
13809 0/*allow-unknown*/, &setlist
);
13810 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
13811 Breakpoint specific settings\n\
13812 Configure various breakpoint-specific variables such as\n\
13813 pending breakpoint behavior"),
13814 &breakpoint_show_cmdlist
, "show breakpoint ",
13815 0/*allow-unknown*/, &showlist
);
13817 add_setshow_auto_boolean_cmd ("pending", no_class
,
13818 &pending_break_support
, _("\
13819 Set debugger's behavior regarding pending breakpoints."), _("\
13820 Show debugger's behavior regarding pending breakpoints."), _("\
13821 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13822 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13823 an error. If auto, an unrecognized breakpoint location results in a\n\
13824 user-query to see if a pending breakpoint should be created."),
13826 show_pending_break_support
,
13827 &breakpoint_set_cmdlist
,
13828 &breakpoint_show_cmdlist
);
13830 pending_break_support
= AUTO_BOOLEAN_AUTO
;
13832 add_setshow_boolean_cmd ("auto-hw", no_class
,
13833 &automatic_hardware_breakpoints
, _("\
13834 Set automatic usage of hardware breakpoints."), _("\
13835 Show automatic usage of hardware breakpoints."), _("\
13836 If set, the debugger will automatically use hardware breakpoints for\n\
13837 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13838 a warning will be emitted for such breakpoints."),
13840 show_automatic_hardware_breakpoints
,
13841 &breakpoint_set_cmdlist
,
13842 &breakpoint_show_cmdlist
);
13844 add_setshow_enum_cmd ("always-inserted", class_support
,
13845 always_inserted_enums
, &always_inserted_mode
, _("\
13846 Set mode for inserting breakpoints."), _("\
13847 Show mode for inserting breakpoints."), _("\
13848 When this mode is off, breakpoints are inserted in inferior when it is\n\
13849 resumed, and removed when execution stops. When this mode is on,\n\
13850 breakpoints are inserted immediately and removed only when the user\n\
13851 deletes the breakpoint. When this mode is auto (which is the default),\n\
13852 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13853 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13854 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13855 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13857 &show_always_inserted_mode
,
13858 &breakpoint_set_cmdlist
,
13859 &breakpoint_show_cmdlist
);
13861 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
13862 Set a breakpoint for an address range.\n\
13863 break-range START-LOCATION, END-LOCATION\n\
13864 where START-LOCATION and END-LOCATION can be one of the following:\n\
13865 LINENUM, for that line in the current file,\n\
13866 FILE:LINENUM, for that line in that file,\n\
13867 +OFFSET, for that number of lines after the current line\n\
13868 or the start of the range\n\
13869 FUNCTION, for the first line in that function,\n\
13870 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13871 *ADDRESS, for the instruction at that address.\n\
13873 The breakpoint will stop execution of the inferior whenever it executes\n\
13874 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13875 range (including START-LOCATION and END-LOCATION)."));
13877 automatic_hardware_breakpoints
= 1;
13879 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);