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"
41 #include "gdb-demangle.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"
71 /* readline include files */
72 #include "readline/readline.h"
73 #include "readline/history.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "python/python.h"
81 /* Prototypes for local functions. */
83 static void enable_delete_command (char *, int);
85 static void enable_once_command (char *, int);
87 static void disable_command (char *, int);
89 static void enable_command (char *, int);
91 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
95 static void ignore_command (char *, int);
97 static int breakpoint_re_set_one (void *);
99 static void breakpoint_re_set_default (struct breakpoint
*);
101 static void clear_command (char *, int);
103 static void catch_command (char *, int);
105 static int can_use_hardware_watchpoint (struct value
*);
107 static void break_command_1 (char *, int, int);
109 static void mention (struct breakpoint
*);
111 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
113 const struct breakpoint_ops
*);
114 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
115 const struct symtab_and_line
*);
117 /* This function is used in gdbtk sources and thus can not be made
119 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
120 struct symtab_and_line
,
122 const struct breakpoint_ops
*);
124 static struct breakpoint
*
125 momentary_breakpoint_from_master (struct breakpoint
*orig
,
127 const struct breakpoint_ops
*ops
);
129 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
131 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
135 static void describe_other_breakpoints (struct gdbarch
*,
136 struct program_space
*, CORE_ADDR
,
137 struct obj_section
*, int);
139 static int breakpoint_address_match (struct address_space
*aspace1
,
141 struct address_space
*aspace2
,
144 static int watchpoint_locations_match (struct bp_location
*loc1
,
145 struct bp_location
*loc2
);
147 static int breakpoint_location_address_match (struct bp_location
*bl
,
148 struct address_space
*aspace
,
151 static void breakpoints_info (char *, int);
153 static void watchpoints_info (char *, int);
155 static int breakpoint_1 (char *, int,
156 int (*) (const struct breakpoint
*));
158 static int breakpoint_cond_eval (void *);
160 static void cleanup_executing_breakpoints (void *);
162 static void commands_command (char *, int);
164 static void condition_command (char *, int);
173 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
174 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
176 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
178 static int watchpoint_check (void *);
180 static void maintenance_info_breakpoints (char *, int);
182 static int hw_breakpoint_used_count (void);
184 static int hw_watchpoint_use_count (struct breakpoint
*);
186 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
188 int *other_type_used
);
190 static void hbreak_command (char *, int);
192 static void thbreak_command (char *, int);
194 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
);
196 static void stop_command (char *arg
, int from_tty
);
198 static void stopin_command (char *arg
, int from_tty
);
200 static void stopat_command (char *arg
, int from_tty
);
202 static char *ep_parse_optional_if_clause (char **arg
);
204 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
205 char *arg
, int tempflag
, int from_tty
);
207 static void tcatch_command (char *arg
, int from_tty
);
209 static void detach_single_step_breakpoints (void);
211 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
214 static void free_bp_location (struct bp_location
*loc
);
215 static void incref_bp_location (struct bp_location
*loc
);
216 static void decref_bp_location (struct bp_location
**loc
);
218 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
220 static void update_global_location_list (int);
222 static void update_global_location_list_nothrow (int);
224 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
226 static void insert_breakpoint_locations (void);
228 static int syscall_catchpoint_p (struct breakpoint
*b
);
230 static void tracepoints_info (char *, int);
232 static void delete_trace_command (char *, int);
234 static void enable_trace_command (char *, int);
236 static void disable_trace_command (char *, int);
238 static void trace_pass_command (char *, int);
240 static int is_masked_watchpoint (const struct breakpoint
*b
);
242 /* Assuming we're creating a static tracepoint, does S look like a
243 static tracepoint marker spec ("-m MARKER_ID")? */
244 #define is_marker_spec(s) \
245 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
247 /* The abstract base class all breakpoint_ops structures inherit
249 static struct breakpoint_ops base_breakpoint_ops
;
251 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
252 that are implemented on top of software or hardware breakpoints
253 (user breakpoints, internal and momentary breakpoints, etc.). */
254 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
256 /* Internal breakpoints class type. */
257 static struct breakpoint_ops internal_breakpoint_ops
;
259 /* Momentary breakpoints class type. */
260 static struct breakpoint_ops momentary_breakpoint_ops
;
262 /* The breakpoint_ops structure to be used in regular user created
264 struct breakpoint_ops bkpt_breakpoint_ops
;
266 /* A reference-counted struct command_line. This lets multiple
267 breakpoints share a single command list. */
268 struct counted_command_line
270 /* The reference count. */
273 /* The command list. */
274 struct command_line
*commands
;
277 struct command_line
*
278 breakpoint_commands (struct breakpoint
*b
)
280 return b
->commands
? b
->commands
->commands
: NULL
;
283 /* Flag indicating that a command has proceeded the inferior past the
284 current breakpoint. */
286 static int breakpoint_proceeded
;
289 bpdisp_text (enum bpdisp disp
)
291 /* NOTE: the following values are a part of MI protocol and
292 represent values of 'disp' field returned when inferior stops at
294 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
296 return bpdisps
[(int) disp
];
299 /* Prototypes for exported functions. */
300 /* If FALSE, gdb will not use hardware support for watchpoints, even
301 if such is available. */
302 static int can_use_hw_watchpoints
;
305 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
306 struct cmd_list_element
*c
,
309 fprintf_filtered (file
,
310 _("Debugger's willingness to use "
311 "watchpoint hardware is %s.\n"),
315 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
316 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
317 for unrecognized breakpoint locations.
318 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
319 static enum auto_boolean pending_break_support
;
321 show_pending_break_support (struct ui_file
*file
, int from_tty
,
322 struct cmd_list_element
*c
,
325 fprintf_filtered (file
,
326 _("Debugger's behavior regarding "
327 "pending breakpoints is %s.\n"),
331 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
332 set with "break" but falling in read-only memory.
333 If 0, gdb will warn about such breakpoints, but won't automatically
334 use hardware breakpoints. */
335 static int automatic_hardware_breakpoints
;
337 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
338 struct cmd_list_element
*c
,
341 fprintf_filtered (file
,
342 _("Automatic usage of hardware breakpoints is %s.\n"),
346 /* If on, gdb will keep breakpoints inserted even as inferior is
347 stopped, and immediately insert any new breakpoints. If off, gdb
348 will insert breakpoints into inferior only when resuming it, and
349 will remove breakpoints upon stop. If auto, GDB will behave as ON
350 if in non-stop mode, and as OFF if all-stop mode.*/
352 static const char always_inserted_auto
[] = "auto";
353 static const char always_inserted_on
[] = "on";
354 static const char always_inserted_off
[] = "off";
355 static const char *always_inserted_enums
[] = {
356 always_inserted_auto
,
361 static const char *always_inserted_mode
= always_inserted_auto
;
363 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
364 struct cmd_list_element
*c
, const char *value
)
366 if (always_inserted_mode
== always_inserted_auto
)
367 fprintf_filtered (file
,
368 _("Always inserted breakpoint "
369 "mode is %s (currently %s).\n"),
371 breakpoints_always_inserted_mode () ? "on" : "off");
373 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
378 breakpoints_always_inserted_mode (void)
380 return (always_inserted_mode
== always_inserted_on
381 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
384 void _initialize_breakpoint (void);
386 /* Are we executing breakpoint commands? */
387 static int executing_breakpoint_commands
;
389 /* Are overlay event breakpoints enabled? */
390 static int overlay_events_enabled
;
392 /* See description in breakpoint.h. */
393 int target_exact_watchpoints
= 0;
395 /* Walk the following statement or block through all breakpoints.
396 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
397 current breakpoint. */
399 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
401 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
402 for (B = breakpoint_chain; \
403 B ? (TMP=B->next, 1): 0; \
406 /* Similar iterator for the low-level breakpoints. SAFE variant is
407 not provided so update_global_location_list must not be called
408 while executing the block of ALL_BP_LOCATIONS. */
410 #define ALL_BP_LOCATIONS(B,BP_TMP) \
411 for (BP_TMP = bp_location; \
412 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
415 /* Iterator for tracepoints only. */
417 #define ALL_TRACEPOINTS(B) \
418 for (B = breakpoint_chain; B; B = B->next) \
419 if (is_tracepoint (B))
421 /* Chains of all breakpoints defined. */
423 struct breakpoint
*breakpoint_chain
;
425 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
427 static struct bp_location
**bp_location
;
429 /* Number of elements of BP_LOCATION. */
431 static unsigned bp_location_count
;
433 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
434 ADDRESS for the current elements of BP_LOCATION which get a valid
435 result from bp_location_has_shadow. You can use it for roughly
436 limiting the subrange of BP_LOCATION to scan for shadow bytes for
437 an address you need to read. */
439 static CORE_ADDR bp_location_placed_address_before_address_max
;
441 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
442 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
443 BP_LOCATION which get a valid result from bp_location_has_shadow.
444 You can use it for roughly limiting the subrange of BP_LOCATION to
445 scan for shadow bytes for an address you need to read. */
447 static CORE_ADDR bp_location_shadow_len_after_address_max
;
449 /* The locations that no longer correspond to any breakpoint, unlinked
450 from bp_location array, but for which a hit may still be reported
452 VEC(bp_location_p
) *moribund_locations
= NULL
;
454 /* Number of last breakpoint made. */
456 static int breakpoint_count
;
458 /* The value of `breakpoint_count' before the last command that
459 created breakpoints. If the last (break-like) command created more
460 than one breakpoint, then the difference between BREAKPOINT_COUNT
461 and PREV_BREAKPOINT_COUNT is more than one. */
462 static int prev_breakpoint_count
;
464 /* Number of last tracepoint made. */
466 static int tracepoint_count
;
468 static struct cmd_list_element
*breakpoint_set_cmdlist
;
469 static struct cmd_list_element
*breakpoint_show_cmdlist
;
470 struct cmd_list_element
*save_cmdlist
;
472 /* Return whether a breakpoint is an active enabled breakpoint. */
474 breakpoint_enabled (struct breakpoint
*b
)
476 return (b
->enable_state
== bp_enabled
);
479 /* Set breakpoint count to NUM. */
482 set_breakpoint_count (int num
)
484 prev_breakpoint_count
= breakpoint_count
;
485 breakpoint_count
= num
;
486 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
489 /* Used by `start_rbreak_breakpoints' below, to record the current
490 breakpoint count before "rbreak" creates any breakpoint. */
491 static int rbreak_start_breakpoint_count
;
493 /* Called at the start an "rbreak" command to record the first
497 start_rbreak_breakpoints (void)
499 rbreak_start_breakpoint_count
= breakpoint_count
;
502 /* Called at the end of an "rbreak" command to record the last
506 end_rbreak_breakpoints (void)
508 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
511 /* Used in run_command to zero the hit count when a new run starts. */
514 clear_breakpoint_hit_counts (void)
516 struct breakpoint
*b
;
522 /* Allocate a new counted_command_line with reference count of 1.
523 The new structure owns COMMANDS. */
525 static struct counted_command_line
*
526 alloc_counted_command_line (struct command_line
*commands
)
528 struct counted_command_line
*result
529 = xmalloc (sizeof (struct counted_command_line
));
532 result
->commands
= commands
;
536 /* Increment reference count. This does nothing if CMD is NULL. */
539 incref_counted_command_line (struct counted_command_line
*cmd
)
545 /* Decrement reference count. If the reference count reaches 0,
546 destroy the counted_command_line. Sets *CMDP to NULL. This does
547 nothing if *CMDP is NULL. */
550 decref_counted_command_line (struct counted_command_line
**cmdp
)
554 if (--(*cmdp
)->refc
== 0)
556 free_command_lines (&(*cmdp
)->commands
);
563 /* A cleanup function that calls decref_counted_command_line. */
566 do_cleanup_counted_command_line (void *arg
)
568 decref_counted_command_line (arg
);
571 /* Create a cleanup that calls decref_counted_command_line on the
574 static struct cleanup
*
575 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
577 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
581 /* Return the breakpoint with the specified number, or NULL
582 if the number does not refer to an existing breakpoint. */
585 get_breakpoint (int num
)
587 struct breakpoint
*b
;
590 if (b
->number
== num
)
599 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
602 xfree (b
->cond_string
);
603 b
->cond_string
= NULL
;
605 if (is_watchpoint (b
))
607 struct watchpoint
*w
= (struct watchpoint
*) b
;
614 struct bp_location
*loc
;
616 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
626 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
632 /* I don't know if it matters whether this is the string the user
633 typed in or the decompiled expression. */
634 b
->cond_string
= xstrdup (arg
);
635 b
->condition_not_parsed
= 0;
637 if (is_watchpoint (b
))
639 struct watchpoint
*w
= (struct watchpoint
*) b
;
641 innermost_block
= NULL
;
643 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
645 error (_("Junk at end of expression"));
646 w
->cond_exp_valid_block
= innermost_block
;
650 struct bp_location
*loc
;
652 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
656 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
658 error (_("Junk at end of expression"));
662 breakpoints_changed ();
663 observer_notify_breakpoint_modified (b
);
666 /* condition N EXP -- set break condition of breakpoint N to EXP. */
669 condition_command (char *arg
, int from_tty
)
671 struct breakpoint
*b
;
676 error_no_arg (_("breakpoint number"));
679 bnum
= get_number (&p
);
681 error (_("Bad breakpoint argument: '%s'"), arg
);
684 if (b
->number
== bnum
)
686 /* Check if this breakpoint has a Python object assigned to
687 it, and if it has a definition of the "stop"
688 method. This method and conditions entered into GDB from
689 the CLI are mutually exclusive. */
691 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
692 error (_("Cannot set a condition where a Python 'stop' "
693 "method has been defined in the breakpoint."));
694 set_breakpoint_condition (b
, p
, from_tty
);
698 error (_("No breakpoint number %d."), bnum
);
701 /* Check that COMMAND do not contain commands that are suitable
702 only for tracepoints and not suitable for ordinary breakpoints.
703 Throw if any such commands is found. */
706 check_no_tracepoint_commands (struct command_line
*commands
)
708 struct command_line
*c
;
710 for (c
= commands
; c
; c
= c
->next
)
714 if (c
->control_type
== while_stepping_control
)
715 error (_("The 'while-stepping' command can "
716 "only be used for tracepoints"));
718 for (i
= 0; i
< c
->body_count
; ++i
)
719 check_no_tracepoint_commands ((c
->body_list
)[i
]);
721 /* Not that command parsing removes leading whitespace and comment
722 lines and also empty lines. So, we only need to check for
724 if (strstr (c
->line
, "collect ") == c
->line
)
725 error (_("The 'collect' command can only be used for tracepoints"));
727 if (strstr (c
->line
, "teval ") == c
->line
)
728 error (_("The 'teval' command can only be used for tracepoints"));
732 /* Encapsulate tests for different types of tracepoints. */
735 is_tracepoint_type (enum bptype type
)
737 return (type
== bp_tracepoint
738 || type
== bp_fast_tracepoint
739 || type
== bp_static_tracepoint
);
743 is_tracepoint (const struct breakpoint
*b
)
745 return is_tracepoint_type (b
->type
);
748 /* A helper function that validates that COMMANDS are valid for a
749 breakpoint. This function will throw an exception if a problem is
753 validate_commands_for_breakpoint (struct breakpoint
*b
,
754 struct command_line
*commands
)
756 if (is_tracepoint (b
))
758 /* We need to verify that each top-level element of commands is
759 valid for tracepoints, that there's at most one
760 while-stepping element, and that while-stepping's body has
761 valid tracing commands excluding nested while-stepping. */
762 struct command_line
*c
;
763 struct command_line
*while_stepping
= 0;
764 for (c
= commands
; c
; c
= c
->next
)
766 if (c
->control_type
== while_stepping_control
)
768 if (b
->type
== bp_fast_tracepoint
)
769 error (_("The 'while-stepping' command "
770 "cannot be used for fast tracepoint"));
771 else if (b
->type
== bp_static_tracepoint
)
772 error (_("The 'while-stepping' command "
773 "cannot be used for static tracepoint"));
776 error (_("The 'while-stepping' command "
777 "can be used only once"));
784 struct command_line
*c2
;
786 gdb_assert (while_stepping
->body_count
== 1);
787 c2
= while_stepping
->body_list
[0];
788 for (; c2
; c2
= c2
->next
)
790 if (c2
->control_type
== while_stepping_control
)
791 error (_("The 'while-stepping' command cannot be nested"));
797 check_no_tracepoint_commands (commands
);
801 /* Return a vector of all the static tracepoints set at ADDR. The
802 caller is responsible for releasing the vector. */
805 static_tracepoints_here (CORE_ADDR addr
)
807 struct breakpoint
*b
;
808 VEC(breakpoint_p
) *found
= 0;
809 struct bp_location
*loc
;
812 if (b
->type
== bp_static_tracepoint
)
814 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
815 if (loc
->address
== addr
)
816 VEC_safe_push(breakpoint_p
, found
, b
);
822 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
823 validate that only allowed commands are included. */
826 breakpoint_set_commands (struct breakpoint
*b
,
827 struct command_line
*commands
)
829 validate_commands_for_breakpoint (b
, commands
);
831 decref_counted_command_line (&b
->commands
);
832 b
->commands
= alloc_counted_command_line (commands
);
833 breakpoints_changed ();
834 observer_notify_breakpoint_modified (b
);
837 /* Set the internal `silent' flag on the breakpoint. Note that this
838 is not the same as the "silent" that may appear in the breakpoint's
842 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
844 int old_silent
= b
->silent
;
847 if (old_silent
!= silent
)
848 observer_notify_breakpoint_modified (b
);
851 /* Set the thread for this breakpoint. If THREAD is -1, make the
852 breakpoint work for any thread. */
855 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
857 int old_thread
= b
->thread
;
860 if (old_thread
!= thread
)
861 observer_notify_breakpoint_modified (b
);
864 /* Set the task for this breakpoint. If TASK is 0, make the
865 breakpoint work for any task. */
868 breakpoint_set_task (struct breakpoint
*b
, int task
)
870 int old_task
= b
->task
;
873 if (old_task
!= task
)
874 observer_notify_breakpoint_modified (b
);
878 check_tracepoint_command (char *line
, void *closure
)
880 struct breakpoint
*b
= closure
;
882 validate_actionline (&line
, b
);
885 /* A structure used to pass information through
886 map_breakpoint_numbers. */
890 /* True if the command was typed at a tty. */
893 /* The breakpoint range spec. */
896 /* Non-NULL if the body of the commands are being read from this
897 already-parsed command. */
898 struct command_line
*control
;
900 /* The command lines read from the user, or NULL if they have not
902 struct counted_command_line
*cmd
;
905 /* A callback for map_breakpoint_numbers that sets the commands for
909 do_map_commands_command (struct breakpoint
*b
, void *data
)
911 struct commands_info
*info
= data
;
913 if (info
->cmd
== NULL
)
915 struct command_line
*l
;
917 if (info
->control
!= NULL
)
918 l
= copy_command_lines (info
->control
->body_list
[0]);
921 struct cleanup
*old_chain
;
924 str
= xstrprintf (_("Type commands for breakpoint(s) "
925 "%s, one per line."),
928 old_chain
= make_cleanup (xfree
, str
);
930 l
= read_command_lines (str
,
933 ? check_tracepoint_command
: 0),
936 do_cleanups (old_chain
);
939 info
->cmd
= alloc_counted_command_line (l
);
942 /* If a breakpoint was on the list more than once, we don't need to
944 if (b
->commands
!= info
->cmd
)
946 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
947 incref_counted_command_line (info
->cmd
);
948 decref_counted_command_line (&b
->commands
);
949 b
->commands
= info
->cmd
;
950 breakpoints_changed ();
951 observer_notify_breakpoint_modified (b
);
956 commands_command_1 (char *arg
, int from_tty
,
957 struct command_line
*control
)
959 struct cleanup
*cleanups
;
960 struct commands_info info
;
962 info
.from_tty
= from_tty
;
963 info
.control
= control
;
965 /* If we read command lines from the user, then `info' will hold an
966 extra reference to the commands that we must clean up. */
967 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
969 if (arg
== NULL
|| !*arg
)
971 if (breakpoint_count
- prev_breakpoint_count
> 1)
972 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
974 else if (breakpoint_count
> 0)
975 arg
= xstrprintf ("%d", breakpoint_count
);
978 /* So that we don't try to free the incoming non-NULL
979 argument in the cleanup below. Mapping breakpoint
980 numbers will fail in this case. */
985 /* The command loop has some static state, so we need to preserve
990 make_cleanup (xfree
, arg
);
994 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
996 if (info
.cmd
== NULL
)
997 error (_("No breakpoints specified."));
999 do_cleanups (cleanups
);
1003 commands_command (char *arg
, int from_tty
)
1005 commands_command_1 (arg
, from_tty
, NULL
);
1008 /* Like commands_command, but instead of reading the commands from
1009 input stream, takes them from an already parsed command structure.
1011 This is used by cli-script.c to DTRT with breakpoint commands
1012 that are part of if and while bodies. */
1013 enum command_control_type
1014 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1016 commands_command_1 (arg
, 0, cmd
);
1017 return simple_control
;
1020 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1023 bp_location_has_shadow (struct bp_location
*bl
)
1025 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1029 if (bl
->target_info
.shadow_len
== 0)
1030 /* BL isn't valid, or doesn't shadow memory. */
1035 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1036 by replacing any memory breakpoints with their shadowed contents.
1038 The range of shadowed area by each bp_location is:
1039 bl->address - bp_location_placed_address_before_address_max
1040 up to bl->address + bp_location_shadow_len_after_address_max
1041 The range we were requested to resolve shadows for is:
1042 memaddr ... memaddr + len
1043 Thus the safe cutoff boundaries for performance optimization are
1044 memaddr + len <= (bl->address
1045 - bp_location_placed_address_before_address_max)
1047 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1050 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1052 /* Left boundary, right boundary and median element of our binary
1054 unsigned bc_l
, bc_r
, bc
;
1056 /* Find BC_L which is a leftmost element which may affect BUF
1057 content. It is safe to report lower value but a failure to
1058 report higher one. */
1061 bc_r
= bp_location_count
;
1062 while (bc_l
+ 1 < bc_r
)
1064 struct bp_location
*bl
;
1066 bc
= (bc_l
+ bc_r
) / 2;
1067 bl
= bp_location
[bc
];
1069 /* Check first BL->ADDRESS will not overflow due to the added
1070 constant. Then advance the left boundary only if we are sure
1071 the BC element can in no way affect the BUF content (MEMADDR
1072 to MEMADDR + LEN range).
1074 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1075 offset so that we cannot miss a breakpoint with its shadow
1076 range tail still reaching MEMADDR. */
1078 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1080 && (bl
->address
+ bp_location_shadow_len_after_address_max
1087 /* Due to the binary search above, we need to make sure we pick the
1088 first location that's at BC_L's address. E.g., if there are
1089 multiple locations at the same address, BC_L may end up pointing
1090 at a duplicate location, and miss the "master"/"inserted"
1091 location. Say, given locations L1, L2 and L3 at addresses A and
1094 L1@A, L2@A, L3@B, ...
1096 BC_L could end up pointing at location L2, while the "master"
1097 location could be L1. Since the `loc->inserted' flag is only set
1098 on "master" locations, we'd forget to restore the shadow of L1
1101 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1104 /* Now do full processing of the found relevant range of elements. */
1106 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1108 struct bp_location
*bl
= bp_location
[bc
];
1109 CORE_ADDR bp_addr
= 0;
1113 /* bp_location array has BL->OWNER always non-NULL. */
1114 if (bl
->owner
->type
== bp_none
)
1115 warning (_("reading through apparently deleted breakpoint #%d?"),
1118 /* Performance optimization: any further element can no longer affect BUF
1121 if (bl
->address
>= bp_location_placed_address_before_address_max
1122 && memaddr
+ len
<= (bl
->address
1123 - bp_location_placed_address_before_address_max
))
1126 if (!bp_location_has_shadow (bl
))
1128 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1129 current_program_space
->aspace
, 0))
1132 /* Addresses and length of the part of the breakpoint that
1134 bp_addr
= bl
->target_info
.placed_address
;
1135 bp_size
= bl
->target_info
.shadow_len
;
1137 if (bp_addr
+ bp_size
<= memaddr
)
1138 /* The breakpoint is entirely before the chunk of memory we
1142 if (bp_addr
>= memaddr
+ len
)
1143 /* The breakpoint is entirely after the chunk of memory we are
1147 /* Offset within shadow_contents. */
1148 if (bp_addr
< memaddr
)
1150 /* Only copy the second part of the breakpoint. */
1151 bp_size
-= memaddr
- bp_addr
;
1152 bptoffset
= memaddr
- bp_addr
;
1156 if (bp_addr
+ bp_size
> memaddr
+ len
)
1158 /* Only copy the first part of the breakpoint. */
1159 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1162 memcpy (buf
+ bp_addr
- memaddr
,
1163 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1168 /* Return true if BPT is of any hardware watchpoint kind. */
1171 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1173 return (bpt
->type
== bp_hardware_watchpoint
1174 || bpt
->type
== bp_read_watchpoint
1175 || bpt
->type
== bp_access_watchpoint
);
1178 /* Return true if BPT is of any watchpoint kind, hardware or
1182 is_watchpoint (const struct breakpoint
*bpt
)
1184 return (is_hardware_watchpoint (bpt
)
1185 || bpt
->type
== bp_watchpoint
);
1188 /* Returns true if the current thread and its running state are safe
1189 to evaluate or update watchpoint B. Watchpoints on local
1190 expressions need to be evaluated in the context of the thread that
1191 was current when the watchpoint was created, and, that thread needs
1192 to be stopped to be able to select the correct frame context.
1193 Watchpoints on global expressions can be evaluated on any thread,
1194 and in any state. It is presently left to the target allowing
1195 memory accesses when threads are running. */
1198 watchpoint_in_thread_scope (struct watchpoint
*b
)
1200 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1201 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1202 && !is_executing (inferior_ptid
)));
1205 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1206 associated bp_watchpoint_scope breakpoint. */
1209 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1211 struct breakpoint
*b
= &w
->base
;
1213 if (b
->related_breakpoint
!= b
)
1215 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1216 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1217 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1218 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1219 b
->related_breakpoint
= b
;
1221 b
->disposition
= disp_del_at_next_stop
;
1224 /* Assuming that B is a watchpoint:
1225 - Reparse watchpoint expression, if REPARSE is non-zero
1226 - Evaluate expression and store the result in B->val
1227 - Evaluate the condition if there is one, and store the result
1229 - Update the list of values that must be watched in B->loc.
1231 If the watchpoint disposition is disp_del_at_next_stop, then do
1232 nothing. If this is local watchpoint that is out of scope, delete
1235 Even with `set breakpoint always-inserted on' the watchpoints are
1236 removed + inserted on each stop here. Normal breakpoints must
1237 never be removed because they might be missed by a running thread
1238 when debugging in non-stop mode. On the other hand, hardware
1239 watchpoints (is_hardware_watchpoint; processed here) are specific
1240 to each LWP since they are stored in each LWP's hardware debug
1241 registers. Therefore, such LWP must be stopped first in order to
1242 be able to modify its hardware watchpoints.
1244 Hardware watchpoints must be reset exactly once after being
1245 presented to the user. It cannot be done sooner, because it would
1246 reset the data used to present the watchpoint hit to the user. And
1247 it must not be done later because it could display the same single
1248 watchpoint hit during multiple GDB stops. Note that the latter is
1249 relevant only to the hardware watchpoint types bp_read_watchpoint
1250 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1251 not user-visible - its hit is suppressed if the memory content has
1254 The following constraints influence the location where we can reset
1255 hardware watchpoints:
1257 * target_stopped_by_watchpoint and target_stopped_data_address are
1258 called several times when GDB stops.
1261 * Multiple hardware watchpoints can be hit at the same time,
1262 causing GDB to stop. GDB only presents one hardware watchpoint
1263 hit at a time as the reason for stopping, and all the other hits
1264 are presented later, one after the other, each time the user
1265 requests the execution to be resumed. Execution is not resumed
1266 for the threads still having pending hit event stored in
1267 LWP_INFO->STATUS. While the watchpoint is already removed from
1268 the inferior on the first stop the thread hit event is kept being
1269 reported from its cached value by linux_nat_stopped_data_address
1270 until the real thread resume happens after the watchpoint gets
1271 presented and thus its LWP_INFO->STATUS gets reset.
1273 Therefore the hardware watchpoint hit can get safely reset on the
1274 watchpoint removal from inferior. */
1277 update_watchpoint (struct watchpoint
*b
, int reparse
)
1279 int within_current_scope
;
1280 struct frame_id saved_frame_id
;
1283 /* If this is a local watchpoint, we only want to check if the
1284 watchpoint frame is in scope if the current thread is the thread
1285 that was used to create the watchpoint. */
1286 if (!watchpoint_in_thread_scope (b
))
1289 if (b
->base
.disposition
== disp_del_at_next_stop
)
1294 /* Determine if the watchpoint is within scope. */
1295 if (b
->exp_valid_block
== NULL
)
1296 within_current_scope
= 1;
1299 struct frame_info
*fi
= get_current_frame ();
1300 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1301 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1303 /* If we're in a function epilogue, unwinding may not work
1304 properly, so do not attempt to recreate locations at this
1305 point. See similar comments in watchpoint_check. */
1306 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1309 /* Save the current frame's ID so we can restore it after
1310 evaluating the watchpoint expression on its own frame. */
1311 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1312 took a frame parameter, so that we didn't have to change the
1315 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1317 fi
= frame_find_by_id (b
->watchpoint_frame
);
1318 within_current_scope
= (fi
!= NULL
);
1319 if (within_current_scope
)
1323 /* We don't free locations. They are stored in the bp_location array
1324 and update_global_location_list will eventually delete them and
1325 remove breakpoints if needed. */
1328 if (within_current_scope
&& reparse
)
1337 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1338 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1339 /* If the meaning of expression itself changed, the old value is
1340 no longer relevant. We don't want to report a watchpoint hit
1341 to the user when the old value and the new value may actually
1342 be completely different objects. */
1343 value_free (b
->val
);
1347 /* Note that unlike with breakpoints, the watchpoint's condition
1348 expression is stored in the breakpoint object, not in the
1349 locations (re)created below. */
1350 if (b
->base
.cond_string
!= NULL
)
1352 if (b
->cond_exp
!= NULL
)
1354 xfree (b
->cond_exp
);
1358 s
= b
->base
.cond_string
;
1359 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1363 /* If we failed to parse the expression, for example because
1364 it refers to a global variable in a not-yet-loaded shared library,
1365 don't try to insert watchpoint. We don't automatically delete
1366 such watchpoint, though, since failure to parse expression
1367 is different from out-of-scope watchpoint. */
1368 if ( !target_has_execution
)
1370 /* Without execution, memory can't change. No use to try and
1371 set watchpoint locations. The watchpoint will be reset when
1372 the target gains execution, through breakpoint_re_set. */
1374 else if (within_current_scope
&& b
->exp
)
1377 struct value
*val_chain
, *v
, *result
, *next
;
1378 struct program_space
*frame_pspace
;
1380 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1382 /* Avoid setting b->val if it's already set. The meaning of
1383 b->val is 'the last value' user saw, and we should update
1384 it only if we reported that last value to user. As it
1385 happens, the code that reports it updates b->val directly.
1386 We don't keep track of the memory value for masked
1388 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1394 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1396 /* Look at each value on the value chain. */
1397 for (v
= val_chain
; v
; v
= value_next (v
))
1399 /* If it's a memory location, and GDB actually needed
1400 its contents to evaluate the expression, then we
1401 must watch it. If the first value returned is
1402 still lazy, that means an error occurred reading it;
1403 watch it anyway in case it becomes readable. */
1404 if (VALUE_LVAL (v
) == lval_memory
1405 && (v
== val_chain
|| ! value_lazy (v
)))
1407 struct type
*vtype
= check_typedef (value_type (v
));
1409 /* We only watch structs and arrays if user asked
1410 for it explicitly, never if they just happen to
1411 appear in the middle of some value chain. */
1413 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1414 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1418 struct bp_location
*loc
, **tmp
;
1420 addr
= value_address (v
);
1421 len
= TYPE_LENGTH (value_type (v
));
1423 if (b
->base
.type
== bp_read_watchpoint
)
1425 else if (b
->base
.type
== bp_access_watchpoint
)
1428 loc
= allocate_bp_location (&b
->base
);
1429 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1432 loc
->gdbarch
= get_type_arch (value_type (v
));
1434 loc
->pspace
= frame_pspace
;
1435 loc
->address
= addr
;
1437 loc
->watchpoint_type
= type
;
1442 /* Change the type of breakpoint between hardware assisted or
1443 an ordinary watchpoint depending on the hardware support
1444 and free hardware slots. REPARSE is set when the inferior
1449 enum bp_loc_type loc_type
;
1450 struct bp_location
*bl
;
1452 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1456 int i
, target_resources_ok
, other_type_used
;
1459 /* Use an exact watchpoint when there's only one memory region to be
1460 watched, and only one debug register is needed to watch it. */
1461 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1463 /* We need to determine how many resources are already
1464 used for all other hardware watchpoints plus this one
1465 to see if we still have enough resources to also fit
1466 this watchpoint in as well. */
1468 /* If this is a software watchpoint, we try to turn it
1469 to a hardware one -- count resources as if B was of
1470 hardware watchpoint type. */
1471 type
= b
->base
.type
;
1472 if (type
== bp_watchpoint
)
1473 type
= bp_hardware_watchpoint
;
1475 /* This watchpoint may or may not have been placed on
1476 the list yet at this point (it won't be in the list
1477 if we're trying to create it for the first time,
1478 through watch_command), so always account for it
1481 /* Count resources used by all watchpoints except B. */
1482 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1484 /* Add in the resources needed for B. */
1485 i
+= hw_watchpoint_use_count (&b
->base
);
1488 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1489 if (target_resources_ok
<= 0)
1491 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1493 if (target_resources_ok
== 0 && !sw_mode
)
1494 error (_("Target does not support this type of "
1495 "hardware watchpoint."));
1496 else if (target_resources_ok
< 0 && !sw_mode
)
1497 error (_("There are not enough available hardware "
1498 "resources for this watchpoint."));
1500 /* Downgrade to software watchpoint. */
1501 b
->base
.type
= bp_watchpoint
;
1505 /* If this was a software watchpoint, we've just
1506 found we have enough resources to turn it to a
1507 hardware watchpoint. Otherwise, this is a
1509 b
->base
.type
= type
;
1512 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1513 error (_("Expression cannot be implemented with "
1514 "read/access watchpoint."));
1516 b
->base
.type
= bp_watchpoint
;
1518 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1519 : bp_loc_hardware_watchpoint
);
1520 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1521 bl
->loc_type
= loc_type
;
1524 for (v
= val_chain
; v
; v
= next
)
1526 next
= value_next (v
);
1531 /* If a software watchpoint is not watching any memory, then the
1532 above left it without any location set up. But,
1533 bpstat_stop_status requires a location to be able to report
1534 stops, so make sure there's at least a dummy one. */
1535 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1537 struct breakpoint
*base
= &b
->base
;
1538 base
->loc
= allocate_bp_location (base
);
1539 base
->loc
->pspace
= frame_pspace
;
1540 base
->loc
->address
= -1;
1541 base
->loc
->length
= -1;
1542 base
->loc
->watchpoint_type
= -1;
1545 else if (!within_current_scope
)
1547 printf_filtered (_("\
1548 Watchpoint %d deleted because the program has left the block\n\
1549 in which its expression is valid.\n"),
1551 watchpoint_del_at_next_stop (b
);
1554 /* Restore the selected frame. */
1556 select_frame (frame_find_by_id (saved_frame_id
));
1560 /* Returns 1 iff breakpoint location should be
1561 inserted in the inferior. We don't differentiate the type of BL's owner
1562 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1563 breakpoint_ops is not defined, because in insert_bp_location,
1564 tracepoint's insert_location will not be called. */
1566 should_be_inserted (struct bp_location
*bl
)
1568 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1571 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1574 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1577 /* This is set for example, when we're attached to the parent of a
1578 vfork, and have detached from the child. The child is running
1579 free, and we expect it to do an exec or exit, at which point the
1580 OS makes the parent schedulable again (and the target reports
1581 that the vfork is done). Until the child is done with the shared
1582 memory region, do not insert breakpoints in the parent, otherwise
1583 the child could still trip on the parent's breakpoints. Since
1584 the parent is blocked anyway, it won't miss any breakpoint. */
1585 if (bl
->pspace
->breakpoints_not_allowed
)
1591 /* Same as should_be_inserted but does the check assuming
1592 that the location is not duplicated. */
1595 unduplicated_should_be_inserted (struct bp_location
*bl
)
1598 const int save_duplicate
= bl
->duplicate
;
1601 result
= should_be_inserted (bl
);
1602 bl
->duplicate
= save_duplicate
;
1606 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1607 location. Any error messages are printed to TMP_ERROR_STREAM; and
1608 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1609 Returns 0 for success, 1 if the bp_location type is not supported or
1612 NOTE drow/2003-09-09: This routine could be broken down to an
1613 object-style method for each breakpoint or catchpoint type. */
1615 insert_bp_location (struct bp_location
*bl
,
1616 struct ui_file
*tmp_error_stream
,
1617 int *disabled_breaks
,
1618 int *hw_breakpoint_error
)
1622 if (!should_be_inserted (bl
) || bl
->inserted
)
1625 /* Initialize the target-specific information. */
1626 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1627 bl
->target_info
.placed_address
= bl
->address
;
1628 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1629 bl
->target_info
.length
= bl
->length
;
1631 if (bl
->loc_type
== bp_loc_software_breakpoint
1632 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1634 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1636 /* If the explicitly specified breakpoint type
1637 is not hardware breakpoint, check the memory map to see
1638 if the breakpoint address is in read only memory or not.
1640 Two important cases are:
1641 - location type is not hardware breakpoint, memory
1642 is readonly. We change the type of the location to
1643 hardware breakpoint.
1644 - location type is hardware breakpoint, memory is
1645 read-write. This means we've previously made the
1646 location hardware one, but then the memory map changed,
1649 When breakpoints are removed, remove_breakpoints will use
1650 location types we've just set here, the only possible
1651 problem is that memory map has changed during running
1652 program, but it's not going to work anyway with current
1654 struct mem_region
*mr
1655 = lookup_mem_region (bl
->target_info
.placed_address
);
1659 if (automatic_hardware_breakpoints
)
1661 enum bp_loc_type new_type
;
1663 if (mr
->attrib
.mode
!= MEM_RW
)
1664 new_type
= bp_loc_hardware_breakpoint
;
1666 new_type
= bp_loc_software_breakpoint
;
1668 if (new_type
!= bl
->loc_type
)
1670 static int said
= 0;
1672 bl
->loc_type
= new_type
;
1675 fprintf_filtered (gdb_stdout
,
1676 _("Note: automatically using "
1677 "hardware breakpoints for "
1678 "read-only addresses.\n"));
1683 else if (bl
->loc_type
== bp_loc_software_breakpoint
1684 && mr
->attrib
.mode
!= MEM_RW
)
1685 warning (_("cannot set software breakpoint "
1686 "at readonly address %s"),
1687 paddress (bl
->gdbarch
, bl
->address
));
1691 /* First check to see if we have to handle an overlay. */
1692 if (overlay_debugging
== ovly_off
1693 || bl
->section
== NULL
1694 || !(section_is_overlay (bl
->section
)))
1696 /* No overlay handling: just set the breakpoint. */
1698 val
= bl
->owner
->ops
->insert_location (bl
);
1702 /* This breakpoint is in an overlay section.
1703 Shall we set a breakpoint at the LMA? */
1704 if (!overlay_events_enabled
)
1706 /* Yes -- overlay event support is not active,
1707 so we must try to set a breakpoint at the LMA.
1708 This will not work for a hardware breakpoint. */
1709 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1710 warning (_("hardware breakpoint %d not supported in overlay!"),
1714 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1716 /* Set a software (trap) breakpoint at the LMA. */
1717 bl
->overlay_target_info
= bl
->target_info
;
1718 bl
->overlay_target_info
.placed_address
= addr
;
1719 val
= target_insert_breakpoint (bl
->gdbarch
,
1720 &bl
->overlay_target_info
);
1722 fprintf_unfiltered (tmp_error_stream
,
1723 "Overlay breakpoint %d "
1724 "failed: in ROM?\n",
1728 /* Shall we set a breakpoint at the VMA? */
1729 if (section_is_mapped (bl
->section
))
1731 /* Yes. This overlay section is mapped into memory. */
1732 val
= bl
->owner
->ops
->insert_location (bl
);
1736 /* No. This breakpoint will not be inserted.
1737 No error, but do not mark the bp as 'inserted'. */
1744 /* Can't set the breakpoint. */
1745 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1747 /* See also: disable_breakpoints_in_shlibs. */
1749 bl
->shlib_disabled
= 1;
1750 observer_notify_breakpoint_modified (bl
->owner
);
1751 if (!*disabled_breaks
)
1753 fprintf_unfiltered (tmp_error_stream
,
1754 "Cannot insert breakpoint %d.\n",
1756 fprintf_unfiltered (tmp_error_stream
,
1757 "Temporarily disabling shared "
1758 "library breakpoints:\n");
1760 *disabled_breaks
= 1;
1761 fprintf_unfiltered (tmp_error_stream
,
1762 "breakpoint #%d\n", bl
->owner
->number
);
1766 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1768 *hw_breakpoint_error
= 1;
1769 fprintf_unfiltered (tmp_error_stream
,
1770 "Cannot insert hardware "
1776 fprintf_unfiltered (tmp_error_stream
,
1777 "Cannot insert breakpoint %d.\n",
1779 fprintf_filtered (tmp_error_stream
,
1780 "Error accessing memory address ");
1781 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1783 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1784 safe_strerror (val
));
1795 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1796 /* NOTE drow/2003-09-08: This state only exists for removing
1797 watchpoints. It's not clear that it's necessary... */
1798 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1800 gdb_assert (bl
->owner
->ops
!= NULL
1801 && bl
->owner
->ops
->insert_location
!= NULL
);
1803 val
= bl
->owner
->ops
->insert_location (bl
);
1805 /* If trying to set a read-watchpoint, and it turns out it's not
1806 supported, try emulating one with an access watchpoint. */
1807 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1809 struct bp_location
*loc
, **loc_temp
;
1811 /* But don't try to insert it, if there's already another
1812 hw_access location that would be considered a duplicate
1814 ALL_BP_LOCATIONS (loc
, loc_temp
)
1816 && loc
->watchpoint_type
== hw_access
1817 && watchpoint_locations_match (bl
, loc
))
1821 bl
->target_info
= loc
->target_info
;
1822 bl
->watchpoint_type
= hw_access
;
1829 bl
->watchpoint_type
= hw_access
;
1830 val
= bl
->owner
->ops
->insert_location (bl
);
1833 /* Back to the original value. */
1834 bl
->watchpoint_type
= hw_read
;
1838 bl
->inserted
= (val
== 0);
1841 else if (bl
->owner
->type
== bp_catchpoint
)
1843 gdb_assert (bl
->owner
->ops
!= NULL
1844 && bl
->owner
->ops
->insert_location
!= NULL
);
1846 val
= bl
->owner
->ops
->insert_location (bl
);
1849 bl
->owner
->enable_state
= bp_disabled
;
1853 Error inserting catchpoint %d: Your system does not support this type\n\
1854 of catchpoint."), bl
->owner
->number
);
1856 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1859 bl
->inserted
= (val
== 0);
1861 /* We've already printed an error message if there was a problem
1862 inserting this catchpoint, and we've disabled the catchpoint,
1863 so just return success. */
1870 /* This function is called when program space PSPACE is about to be
1871 deleted. It takes care of updating breakpoints to not reference
1875 breakpoint_program_space_exit (struct program_space
*pspace
)
1877 struct breakpoint
*b
, *b_temp
;
1878 struct bp_location
*loc
, **loc_temp
;
1880 /* Remove any breakpoint that was set through this program space. */
1881 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1883 if (b
->pspace
== pspace
)
1884 delete_breakpoint (b
);
1887 /* Breakpoints set through other program spaces could have locations
1888 bound to PSPACE as well. Remove those. */
1889 ALL_BP_LOCATIONS (loc
, loc_temp
)
1891 struct bp_location
*tmp
;
1893 if (loc
->pspace
== pspace
)
1895 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1896 if (loc
->owner
->loc
== loc
)
1897 loc
->owner
->loc
= loc
->next
;
1899 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1900 if (tmp
->next
== loc
)
1902 tmp
->next
= loc
->next
;
1908 /* Now update the global location list to permanently delete the
1909 removed locations above. */
1910 update_global_location_list (0);
1913 /* Make sure all breakpoints are inserted in inferior.
1914 Throws exception on any error.
1915 A breakpoint that is already inserted won't be inserted
1916 again, so calling this function twice is safe. */
1918 insert_breakpoints (void)
1920 struct breakpoint
*bpt
;
1922 ALL_BREAKPOINTS (bpt
)
1923 if (is_hardware_watchpoint (bpt
))
1925 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1927 update_watchpoint (w
, 0 /* don't reparse. */);
1930 update_global_location_list (1);
1932 /* update_global_location_list does not insert breakpoints when
1933 always_inserted_mode is not enabled. Explicitly insert them
1935 if (!breakpoints_always_inserted_mode ())
1936 insert_breakpoint_locations ();
1939 /* Used when starting or continuing the program. */
1942 insert_breakpoint_locations (void)
1944 struct breakpoint
*bpt
;
1945 struct bp_location
*bl
, **blp_tmp
;
1948 int disabled_breaks
= 0;
1949 int hw_breakpoint_error
= 0;
1951 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1952 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1954 /* Explicitly mark the warning -- this will only be printed if
1955 there was an error. */
1956 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1958 save_current_space_and_thread ();
1960 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1962 if (!should_be_inserted (bl
) || bl
->inserted
)
1965 /* There is no point inserting thread-specific breakpoints if
1966 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1967 has BL->OWNER always non-NULL. */
1968 if (bl
->owner
->thread
!= -1
1969 && !valid_thread_id (bl
->owner
->thread
))
1972 switch_to_program_space_and_thread (bl
->pspace
);
1974 /* For targets that support global breakpoints, there's no need
1975 to select an inferior to insert breakpoint to. In fact, even
1976 if we aren't attached to any process yet, we should still
1977 insert breakpoints. */
1978 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1979 && ptid_equal (inferior_ptid
, null_ptid
))
1982 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1983 &hw_breakpoint_error
);
1988 /* If we failed to insert all locations of a watchpoint, remove
1989 them, as half-inserted watchpoint is of limited use. */
1990 ALL_BREAKPOINTS (bpt
)
1992 int some_failed
= 0;
1993 struct bp_location
*loc
;
1995 if (!is_hardware_watchpoint (bpt
))
1998 if (!breakpoint_enabled (bpt
))
2001 if (bpt
->disposition
== disp_del_at_next_stop
)
2004 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2005 if (!loc
->inserted
&& should_be_inserted (loc
))
2012 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2014 remove_breakpoint (loc
, mark_uninserted
);
2016 hw_breakpoint_error
= 1;
2017 fprintf_unfiltered (tmp_error_stream
,
2018 "Could not insert hardware watchpoint %d.\n",
2026 /* If a hardware breakpoint or watchpoint was inserted, add a
2027 message about possibly exhausted resources. */
2028 if (hw_breakpoint_error
)
2030 fprintf_unfiltered (tmp_error_stream
,
2031 "Could not insert hardware breakpoints:\n\
2032 You may have requested too many hardware breakpoints/watchpoints.\n");
2034 target_terminal_ours_for_output ();
2035 error_stream (tmp_error_stream
);
2038 do_cleanups (cleanups
);
2041 /* Used when the program stops.
2042 Returns zero if successful, or non-zero if there was a problem
2043 removing a breakpoint location. */
2046 remove_breakpoints (void)
2048 struct bp_location
*bl
, **blp_tmp
;
2051 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2053 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2054 val
|= remove_breakpoint (bl
, mark_uninserted
);
2059 /* Remove breakpoints of process PID. */
2062 remove_breakpoints_pid (int pid
)
2064 struct bp_location
*bl
, **blp_tmp
;
2066 struct inferior
*inf
= find_inferior_pid (pid
);
2068 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2070 if (bl
->pspace
!= inf
->pspace
)
2075 val
= remove_breakpoint (bl
, mark_uninserted
);
2084 reattach_breakpoints (int pid
)
2086 struct cleanup
*old_chain
;
2087 struct bp_location
*bl
, **blp_tmp
;
2089 struct ui_file
*tmp_error_stream
;
2090 int dummy1
= 0, dummy2
= 0;
2091 struct inferior
*inf
;
2092 struct thread_info
*tp
;
2094 tp
= any_live_thread_of_process (pid
);
2098 inf
= find_inferior_pid (pid
);
2099 old_chain
= save_inferior_ptid ();
2101 inferior_ptid
= tp
->ptid
;
2103 tmp_error_stream
= mem_fileopen ();
2104 make_cleanup_ui_file_delete (tmp_error_stream
);
2106 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2108 if (bl
->pspace
!= inf
->pspace
)
2114 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2117 do_cleanups (old_chain
);
2122 do_cleanups (old_chain
);
2126 static int internal_breakpoint_number
= -1;
2128 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2129 If INTERNAL is non-zero, the breakpoint number will be populated
2130 from internal_breakpoint_number and that variable decremented.
2131 Otherwise the breakpoint number will be populated from
2132 breakpoint_count and that value incremented. Internal breakpoints
2133 do not set the internal var bpnum. */
2135 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2138 b
->number
= internal_breakpoint_number
--;
2141 set_breakpoint_count (breakpoint_count
+ 1);
2142 b
->number
= breakpoint_count
;
2146 static struct breakpoint
*
2147 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2148 CORE_ADDR address
, enum bptype type
,
2149 const struct breakpoint_ops
*ops
)
2151 struct symtab_and_line sal
;
2152 struct breakpoint
*b
;
2154 init_sal (&sal
); /* Initialize to zeroes. */
2157 sal
.section
= find_pc_overlay (sal
.pc
);
2158 sal
.pspace
= current_program_space
;
2160 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2161 b
->number
= internal_breakpoint_number
--;
2162 b
->disposition
= disp_donttouch
;
2167 static const char *const longjmp_names
[] =
2169 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2171 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2173 /* Per-objfile data private to breakpoint.c. */
2174 struct breakpoint_objfile_data
2176 /* Minimal symbol for "_ovly_debug_event" (if any). */
2177 struct minimal_symbol
*overlay_msym
;
2179 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2180 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2182 /* Minimal symbol for "std::terminate()" (if any). */
2183 struct minimal_symbol
*terminate_msym
;
2185 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2186 struct minimal_symbol
*exception_msym
;
2189 static const struct objfile_data
*breakpoint_objfile_key
;
2191 /* Minimal symbol not found sentinel. */
2192 static struct minimal_symbol msym_not_found
;
2194 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2197 msym_not_found_p (const struct minimal_symbol
*msym
)
2199 return msym
== &msym_not_found
;
2202 /* Return per-objfile data needed by breakpoint.c.
2203 Allocate the data if necessary. */
2205 static struct breakpoint_objfile_data
*
2206 get_breakpoint_objfile_data (struct objfile
*objfile
)
2208 struct breakpoint_objfile_data
*bp_objfile_data
;
2210 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2211 if (bp_objfile_data
== NULL
)
2213 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2214 sizeof (*bp_objfile_data
));
2216 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2217 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2219 return bp_objfile_data
;
2223 create_overlay_event_breakpoint (void)
2225 struct objfile
*objfile
;
2226 const char *const func_name
= "_ovly_debug_event";
2228 ALL_OBJFILES (objfile
)
2230 struct breakpoint
*b
;
2231 struct breakpoint_objfile_data
*bp_objfile_data
;
2234 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2236 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2239 if (bp_objfile_data
->overlay_msym
== NULL
)
2241 struct minimal_symbol
*m
;
2243 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2246 /* Avoid future lookups in this objfile. */
2247 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2250 bp_objfile_data
->overlay_msym
= m
;
2253 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2254 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2256 &internal_breakpoint_ops
);
2257 b
->addr_string
= xstrdup (func_name
);
2259 if (overlay_debugging
== ovly_auto
)
2261 b
->enable_state
= bp_enabled
;
2262 overlay_events_enabled
= 1;
2266 b
->enable_state
= bp_disabled
;
2267 overlay_events_enabled
= 0;
2270 update_global_location_list (1);
2274 create_longjmp_master_breakpoint (void)
2276 struct program_space
*pspace
;
2277 struct cleanup
*old_chain
;
2279 old_chain
= save_current_program_space ();
2281 ALL_PSPACES (pspace
)
2283 struct objfile
*objfile
;
2285 set_current_program_space (pspace
);
2287 ALL_OBJFILES (objfile
)
2290 struct gdbarch
*gdbarch
;
2291 struct breakpoint_objfile_data
*bp_objfile_data
;
2293 gdbarch
= get_objfile_arch (objfile
);
2294 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2297 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2299 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2301 struct breakpoint
*b
;
2302 const char *func_name
;
2305 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2308 func_name
= longjmp_names
[i
];
2309 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2311 struct minimal_symbol
*m
;
2313 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2316 /* Prevent future lookups in this objfile. */
2317 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2320 bp_objfile_data
->longjmp_msym
[i
] = m
;
2323 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2324 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2325 &internal_breakpoint_ops
);
2326 b
->addr_string
= xstrdup (func_name
);
2327 b
->enable_state
= bp_disabled
;
2331 update_global_location_list (1);
2333 do_cleanups (old_chain
);
2336 /* Create a master std::terminate breakpoint. */
2338 create_std_terminate_master_breakpoint (void)
2340 struct program_space
*pspace
;
2341 struct cleanup
*old_chain
;
2342 const char *const func_name
= "std::terminate()";
2344 old_chain
= save_current_program_space ();
2346 ALL_PSPACES (pspace
)
2348 struct objfile
*objfile
;
2351 set_current_program_space (pspace
);
2353 ALL_OBJFILES (objfile
)
2355 struct breakpoint
*b
;
2356 struct breakpoint_objfile_data
*bp_objfile_data
;
2358 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2360 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2363 if (bp_objfile_data
->terminate_msym
== NULL
)
2365 struct minimal_symbol
*m
;
2367 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2368 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2369 && MSYMBOL_TYPE (m
) != mst_file_text
))
2371 /* Prevent future lookups in this objfile. */
2372 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2375 bp_objfile_data
->terminate_msym
= m
;
2378 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2379 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2380 bp_std_terminate_master
,
2381 &internal_breakpoint_ops
);
2382 b
->addr_string
= xstrdup (func_name
);
2383 b
->enable_state
= bp_disabled
;
2387 update_global_location_list (1);
2389 do_cleanups (old_chain
);
2392 /* Install a master breakpoint on the unwinder's debug hook. */
2395 create_exception_master_breakpoint (void)
2397 struct objfile
*objfile
;
2398 const char *const func_name
= "_Unwind_DebugHook";
2400 ALL_OBJFILES (objfile
)
2402 struct breakpoint
*b
;
2403 struct gdbarch
*gdbarch
;
2404 struct breakpoint_objfile_data
*bp_objfile_data
;
2407 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2409 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2412 gdbarch
= get_objfile_arch (objfile
);
2414 if (bp_objfile_data
->exception_msym
== NULL
)
2416 struct minimal_symbol
*debug_hook
;
2418 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2419 if (debug_hook
== NULL
)
2421 bp_objfile_data
->exception_msym
= &msym_not_found
;
2425 bp_objfile_data
->exception_msym
= debug_hook
;
2428 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2429 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2431 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2432 &internal_breakpoint_ops
);
2433 b
->addr_string
= xstrdup (func_name
);
2434 b
->enable_state
= bp_disabled
;
2437 update_global_location_list (1);
2441 update_breakpoints_after_exec (void)
2443 struct breakpoint
*b
, *b_tmp
;
2444 struct bp_location
*bploc
, **bplocp_tmp
;
2446 /* We're about to delete breakpoints from GDB's lists. If the
2447 INSERTED flag is true, GDB will try to lift the breakpoints by
2448 writing the breakpoints' "shadow contents" back into memory. The
2449 "shadow contents" are NOT valid after an exec, so GDB should not
2450 do that. Instead, the target is responsible from marking
2451 breakpoints out as soon as it detects an exec. We don't do that
2452 here instead, because there may be other attempts to delete
2453 breakpoints after detecting an exec and before reaching here. */
2454 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2455 if (bploc
->pspace
== current_program_space
)
2456 gdb_assert (!bploc
->inserted
);
2458 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2460 if (b
->pspace
!= current_program_space
)
2463 /* Solib breakpoints must be explicitly reset after an exec(). */
2464 if (b
->type
== bp_shlib_event
)
2466 delete_breakpoint (b
);
2470 /* JIT breakpoints must be explicitly reset after an exec(). */
2471 if (b
->type
== bp_jit_event
)
2473 delete_breakpoint (b
);
2477 /* Thread event breakpoints must be set anew after an exec(),
2478 as must overlay event and longjmp master breakpoints. */
2479 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2480 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2481 || b
->type
== bp_exception_master
)
2483 delete_breakpoint (b
);
2487 /* Step-resume breakpoints are meaningless after an exec(). */
2488 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2490 delete_breakpoint (b
);
2494 /* Longjmp and longjmp-resume breakpoints are also meaningless
2496 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2497 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2499 delete_breakpoint (b
);
2503 if (b
->type
== bp_catchpoint
)
2505 /* For now, none of the bp_catchpoint breakpoints need to
2506 do anything at this point. In the future, if some of
2507 the catchpoints need to something, we will need to add
2508 a new method, and call this method from here. */
2512 /* bp_finish is a special case. The only way we ought to be able
2513 to see one of these when an exec() has happened, is if the user
2514 caught a vfork, and then said "finish". Ordinarily a finish just
2515 carries them to the call-site of the current callee, by setting
2516 a temporary bp there and resuming. But in this case, the finish
2517 will carry them entirely through the vfork & exec.
2519 We don't want to allow a bp_finish to remain inserted now. But
2520 we can't safely delete it, 'cause finish_command has a handle to
2521 the bp on a bpstat, and will later want to delete it. There's a
2522 chance (and I've seen it happen) that if we delete the bp_finish
2523 here, that its storage will get reused by the time finish_command
2524 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2525 We really must allow finish_command to delete a bp_finish.
2527 In the absence of a general solution for the "how do we know
2528 it's safe to delete something others may have handles to?"
2529 problem, what we'll do here is just uninsert the bp_finish, and
2530 let finish_command delete it.
2532 (We know the bp_finish is "doomed" in the sense that it's
2533 momentary, and will be deleted as soon as finish_command sees
2534 the inferior stopped. So it doesn't matter that the bp's
2535 address is probably bogus in the new a.out, unlike e.g., the
2536 solib breakpoints.) */
2538 if (b
->type
== bp_finish
)
2543 /* Without a symbolic address, we have little hope of the
2544 pre-exec() address meaning the same thing in the post-exec()
2546 if (b
->addr_string
== NULL
)
2548 delete_breakpoint (b
);
2552 /* FIXME what about longjmp breakpoints? Re-create them here? */
2553 create_overlay_event_breakpoint ();
2554 create_longjmp_master_breakpoint ();
2555 create_std_terminate_master_breakpoint ();
2556 create_exception_master_breakpoint ();
2560 detach_breakpoints (int pid
)
2562 struct bp_location
*bl
, **blp_tmp
;
2564 struct cleanup
*old_chain
= save_inferior_ptid ();
2565 struct inferior
*inf
= current_inferior ();
2567 if (pid
== PIDGET (inferior_ptid
))
2568 error (_("Cannot detach breakpoints of inferior_ptid"));
2570 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2571 inferior_ptid
= pid_to_ptid (pid
);
2572 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2574 if (bl
->pspace
!= inf
->pspace
)
2578 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2581 /* Detach single-step breakpoints as well. */
2582 detach_single_step_breakpoints ();
2584 do_cleanups (old_chain
);
2588 /* Remove the breakpoint location BL from the current address space.
2589 Note that this is used to detach breakpoints from a child fork.
2590 When we get here, the child isn't in the inferior list, and neither
2591 do we have objects to represent its address space --- we should
2592 *not* look at bl->pspace->aspace here. */
2595 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2599 /* BL is never in moribund_locations by our callers. */
2600 gdb_assert (bl
->owner
!= NULL
);
2602 if (bl
->owner
->enable_state
== bp_permanent
)
2603 /* Permanent breakpoints cannot be inserted or removed. */
2606 /* The type of none suggests that owner is actually deleted.
2607 This should not ever happen. */
2608 gdb_assert (bl
->owner
->type
!= bp_none
);
2610 if (bl
->loc_type
== bp_loc_software_breakpoint
2611 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2613 /* "Normal" instruction breakpoint: either the standard
2614 trap-instruction bp (bp_breakpoint), or a
2615 bp_hardware_breakpoint. */
2617 /* First check to see if we have to handle an overlay. */
2618 if (overlay_debugging
== ovly_off
2619 || bl
->section
== NULL
2620 || !(section_is_overlay (bl
->section
)))
2622 /* No overlay handling: just remove the breakpoint. */
2623 val
= bl
->owner
->ops
->remove_location (bl
);
2627 /* This breakpoint is in an overlay section.
2628 Did we set a breakpoint at the LMA? */
2629 if (!overlay_events_enabled
)
2631 /* Yes -- overlay event support is not active, so we
2632 should have set a breakpoint at the LMA. Remove it.
2634 /* Ignore any failures: if the LMA is in ROM, we will
2635 have already warned when we failed to insert it. */
2636 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2637 target_remove_hw_breakpoint (bl
->gdbarch
,
2638 &bl
->overlay_target_info
);
2640 target_remove_breakpoint (bl
->gdbarch
,
2641 &bl
->overlay_target_info
);
2643 /* Did we set a breakpoint at the VMA?
2644 If so, we will have marked the breakpoint 'inserted'. */
2647 /* Yes -- remove it. Previously we did not bother to
2648 remove the breakpoint if the section had been
2649 unmapped, but let's not rely on that being safe. We
2650 don't know what the overlay manager might do. */
2652 /* However, we should remove *software* breakpoints only
2653 if the section is still mapped, or else we overwrite
2654 wrong code with the saved shadow contents. */
2655 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2656 || section_is_mapped (bl
->section
))
2657 val
= bl
->owner
->ops
->remove_location (bl
);
2663 /* No -- not inserted, so no need to remove. No error. */
2668 /* In some cases, we might not be able to remove a breakpoint
2669 in a shared library that has already been removed, but we
2670 have not yet processed the shlib unload event. */
2671 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2676 bl
->inserted
= (is
== mark_inserted
);
2678 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2680 gdb_assert (bl
->owner
->ops
!= NULL
2681 && bl
->owner
->ops
->remove_location
!= NULL
);
2683 bl
->inserted
= (is
== mark_inserted
);
2684 bl
->owner
->ops
->remove_location (bl
);
2686 /* Failure to remove any of the hardware watchpoints comes here. */
2687 if ((is
== mark_uninserted
) && (bl
->inserted
))
2688 warning (_("Could not remove hardware watchpoint %d."),
2691 else if (bl
->owner
->type
== bp_catchpoint
2692 && breakpoint_enabled (bl
->owner
)
2695 gdb_assert (bl
->owner
->ops
!= NULL
2696 && bl
->owner
->ops
->remove_location
!= NULL
);
2698 val
= bl
->owner
->ops
->remove_location (bl
);
2702 bl
->inserted
= (is
== mark_inserted
);
2709 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2712 struct cleanup
*old_chain
;
2714 /* BL is never in moribund_locations by our callers. */
2715 gdb_assert (bl
->owner
!= NULL
);
2717 if (bl
->owner
->enable_state
== bp_permanent
)
2718 /* Permanent breakpoints cannot be inserted or removed. */
2721 /* The type of none suggests that owner is actually deleted.
2722 This should not ever happen. */
2723 gdb_assert (bl
->owner
->type
!= bp_none
);
2725 old_chain
= save_current_space_and_thread ();
2727 switch_to_program_space_and_thread (bl
->pspace
);
2729 ret
= remove_breakpoint_1 (bl
, is
);
2731 do_cleanups (old_chain
);
2735 /* Clear the "inserted" flag in all breakpoints. */
2738 mark_breakpoints_out (void)
2740 struct bp_location
*bl
, **blp_tmp
;
2742 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2743 if (bl
->pspace
== current_program_space
)
2747 /* Clear the "inserted" flag in all breakpoints and delete any
2748 breakpoints which should go away between runs of the program.
2750 Plus other such housekeeping that has to be done for breakpoints
2753 Note: this function gets called at the end of a run (by
2754 generic_mourn_inferior) and when a run begins (by
2755 init_wait_for_inferior). */
2760 breakpoint_init_inferior (enum inf_context context
)
2762 struct breakpoint
*b
, *b_tmp
;
2763 struct bp_location
*bl
, **blp_tmp
;
2765 struct program_space
*pspace
= current_program_space
;
2767 /* If breakpoint locations are shared across processes, then there's
2769 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2772 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2774 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2775 if (bl
->pspace
== pspace
2776 && bl
->owner
->enable_state
!= bp_permanent
)
2780 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2782 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2789 /* If the call dummy breakpoint is at the entry point it will
2790 cause problems when the inferior is rerun, so we better get
2793 case bp_watchpoint_scope
:
2795 /* Also get rid of scope breakpoints. */
2797 case bp_shlib_event
:
2799 /* Also remove solib event breakpoints. Their addresses may
2800 have changed since the last time we ran the program.
2801 Actually we may now be debugging against different target;
2802 and so the solib backend that installed this breakpoint may
2803 not be used in by the target. E.g.,
2805 (gdb) file prog-linux
2806 (gdb) run # native linux target
2809 (gdb) file prog-win.exe
2810 (gdb) tar rem :9999 # remote Windows gdbserver.
2813 delete_breakpoint (b
);
2817 case bp_hardware_watchpoint
:
2818 case bp_read_watchpoint
:
2819 case bp_access_watchpoint
:
2821 struct watchpoint
*w
= (struct watchpoint
*) b
;
2823 /* Likewise for watchpoints on local expressions. */
2824 if (w
->exp_valid_block
!= NULL
)
2825 delete_breakpoint (b
);
2826 else if (context
== inf_starting
)
2828 /* Reset val field to force reread of starting value in
2829 insert_breakpoints. */
2831 value_free (w
->val
);
2842 /* Get rid of the moribund locations. */
2843 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2844 decref_bp_location (&bl
);
2845 VEC_free (bp_location_p
, moribund_locations
);
2848 /* These functions concern about actual breakpoints inserted in the
2849 target --- to e.g. check if we need to do decr_pc adjustment or if
2850 we need to hop over the bkpt --- so we check for address space
2851 match, not program space. */
2853 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2854 exists at PC. It returns ordinary_breakpoint_here if it's an
2855 ordinary breakpoint, or permanent_breakpoint_here if it's a
2856 permanent breakpoint.
2857 - When continuing from a location with an ordinary breakpoint, we
2858 actually single step once before calling insert_breakpoints.
2859 - When continuing from a location with a permanent breakpoint, we
2860 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2861 the target, to advance the PC past the breakpoint. */
2863 enum breakpoint_here
2864 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2866 struct bp_location
*bl
, **blp_tmp
;
2867 int any_breakpoint_here
= 0;
2869 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2871 if (bl
->loc_type
!= bp_loc_software_breakpoint
2872 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2875 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2876 if ((breakpoint_enabled (bl
->owner
)
2877 || bl
->owner
->enable_state
== bp_permanent
)
2878 && breakpoint_location_address_match (bl
, aspace
, pc
))
2880 if (overlay_debugging
2881 && section_is_overlay (bl
->section
)
2882 && !section_is_mapped (bl
->section
))
2883 continue; /* unmapped overlay -- can't be a match */
2884 else if (bl
->owner
->enable_state
== bp_permanent
)
2885 return permanent_breakpoint_here
;
2887 any_breakpoint_here
= 1;
2891 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2894 /* Return true if there's a moribund breakpoint at PC. */
2897 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2899 struct bp_location
*loc
;
2902 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2903 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2909 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2910 inserted using regular breakpoint_chain / bp_location array
2911 mechanism. This does not check for single-step breakpoints, which
2912 are inserted and removed using direct target manipulation. */
2915 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2918 struct bp_location
*bl
, **blp_tmp
;
2920 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2922 if (bl
->loc_type
!= bp_loc_software_breakpoint
2923 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2927 && breakpoint_location_address_match (bl
, aspace
, pc
))
2929 if (overlay_debugging
2930 && section_is_overlay (bl
->section
)
2931 && !section_is_mapped (bl
->section
))
2932 continue; /* unmapped overlay -- can't be a match */
2940 /* Returns non-zero iff there's either regular breakpoint
2941 or a single step breakpoint inserted at PC. */
2944 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2946 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2949 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2955 /* This function returns non-zero iff there is a software breakpoint
2959 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2962 struct bp_location
*bl
, **blp_tmp
;
2964 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2966 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2970 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2973 if (overlay_debugging
2974 && section_is_overlay (bl
->section
)
2975 && !section_is_mapped (bl
->section
))
2976 continue; /* unmapped overlay -- can't be a match */
2982 /* Also check for software single-step breakpoints. */
2983 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2990 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2991 CORE_ADDR addr
, ULONGEST len
)
2993 struct breakpoint
*bpt
;
2995 ALL_BREAKPOINTS (bpt
)
2997 struct bp_location
*loc
;
2999 if (bpt
->type
!= bp_hardware_watchpoint
3000 && bpt
->type
!= bp_access_watchpoint
)
3003 if (!breakpoint_enabled (bpt
))
3006 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3007 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3011 /* Check for intersection. */
3012 l
= max (loc
->address
, addr
);
3013 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3021 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3022 PC is valid for process/thread PTID. */
3025 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3028 struct bp_location
*bl
, **blp_tmp
;
3029 /* The thread and task IDs associated to PTID, computed lazily. */
3033 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3035 if (bl
->loc_type
!= bp_loc_software_breakpoint
3036 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3039 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3040 if (!breakpoint_enabled (bl
->owner
)
3041 && bl
->owner
->enable_state
!= bp_permanent
)
3044 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3047 if (bl
->owner
->thread
!= -1)
3049 /* This is a thread-specific breakpoint. Check that ptid
3050 matches that thread. If thread hasn't been computed yet,
3051 it is now time to do so. */
3053 thread
= pid_to_thread_id (ptid
);
3054 if (bl
->owner
->thread
!= thread
)
3058 if (bl
->owner
->task
!= 0)
3060 /* This is a task-specific breakpoint. Check that ptid
3061 matches that task. If task hasn't been computed yet,
3062 it is now time to do so. */
3064 task
= ada_get_task_number (ptid
);
3065 if (bl
->owner
->task
!= task
)
3069 if (overlay_debugging
3070 && section_is_overlay (bl
->section
)
3071 && !section_is_mapped (bl
->section
))
3072 continue; /* unmapped overlay -- can't be a match */
3081 /* bpstat stuff. External routines' interfaces are documented
3085 ep_is_catchpoint (struct breakpoint
*ep
)
3087 return (ep
->type
== bp_catchpoint
);
3090 /* Frees any storage that is part of a bpstat. Does not walk the
3094 bpstat_free (bpstat bs
)
3096 if (bs
->old_val
!= NULL
)
3097 value_free (bs
->old_val
);
3098 decref_counted_command_line (&bs
->commands
);
3099 decref_bp_location (&bs
->bp_location_at
);
3103 /* Clear a bpstat so that it says we are not at any breakpoint.
3104 Also free any storage that is part of a bpstat. */
3107 bpstat_clear (bpstat
*bsp
)
3124 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3125 is part of the bpstat is copied as well. */
3128 bpstat_copy (bpstat bs
)
3132 bpstat retval
= NULL
;
3137 for (; bs
!= NULL
; bs
= bs
->next
)
3139 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3140 memcpy (tmp
, bs
, sizeof (*tmp
));
3141 incref_counted_command_line (tmp
->commands
);
3142 incref_bp_location (tmp
->bp_location_at
);
3143 if (bs
->old_val
!= NULL
)
3145 tmp
->old_val
= value_copy (bs
->old_val
);
3146 release_value (tmp
->old_val
);
3150 /* This is the first thing in the chain. */
3160 /* Find the bpstat associated with this breakpoint. */
3163 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3168 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3170 if (bsp
->breakpoint_at
== breakpoint
)
3176 /* Put in *NUM the breakpoint number of the first breakpoint we are
3177 stopped at. *BSP upon return is a bpstat which points to the
3178 remaining breakpoints stopped at (but which is not guaranteed to be
3179 good for anything but further calls to bpstat_num).
3181 Return 0 if passed a bpstat which does not indicate any breakpoints.
3182 Return -1 if stopped at a breakpoint that has been deleted since
3184 Return 1 otherwise. */
3187 bpstat_num (bpstat
*bsp
, int *num
)
3189 struct breakpoint
*b
;
3192 return 0; /* No more breakpoint values */
3194 /* We assume we'll never have several bpstats that correspond to a
3195 single breakpoint -- otherwise, this function might return the
3196 same number more than once and this will look ugly. */
3197 b
= (*bsp
)->breakpoint_at
;
3198 *bsp
= (*bsp
)->next
;
3200 return -1; /* breakpoint that's been deleted since */
3202 *num
= b
->number
; /* We have its number */
3206 /* See breakpoint.h. */
3209 bpstat_clear_actions (void)
3211 struct thread_info
*tp
;
3214 if (ptid_equal (inferior_ptid
, null_ptid
))
3217 tp
= find_thread_ptid (inferior_ptid
);
3221 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3223 decref_counted_command_line (&bs
->commands
);
3225 if (bs
->old_val
!= NULL
)
3227 value_free (bs
->old_val
);
3233 /* Called when a command is about to proceed the inferior. */
3236 breakpoint_about_to_proceed (void)
3238 if (!ptid_equal (inferior_ptid
, null_ptid
))
3240 struct thread_info
*tp
= inferior_thread ();
3242 /* Allow inferior function calls in breakpoint commands to not
3243 interrupt the command list. When the call finishes
3244 successfully, the inferior will be standing at the same
3245 breakpoint as if nothing happened. */
3246 if (tp
->control
.in_infcall
)
3250 breakpoint_proceeded
= 1;
3253 /* Stub for cleaning up our state if we error-out of a breakpoint
3256 cleanup_executing_breakpoints (void *ignore
)
3258 executing_breakpoint_commands
= 0;
3261 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3262 or its equivalent. */
3265 command_line_is_silent (struct command_line
*cmd
)
3267 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3268 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3271 /* Execute all the commands associated with all the breakpoints at
3272 this location. Any of these commands could cause the process to
3273 proceed beyond this point, etc. We look out for such changes by
3274 checking the global "breakpoint_proceeded" after each command.
3276 Returns true if a breakpoint command resumed the inferior. In that
3277 case, it is the caller's responsibility to recall it again with the
3278 bpstat of the current thread. */
3281 bpstat_do_actions_1 (bpstat
*bsp
)
3284 struct cleanup
*old_chain
;
3287 /* Avoid endless recursion if a `source' command is contained
3289 if (executing_breakpoint_commands
)
3292 executing_breakpoint_commands
= 1;
3293 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3295 prevent_dont_repeat ();
3297 /* This pointer will iterate over the list of bpstat's. */
3300 breakpoint_proceeded
= 0;
3301 for (; bs
!= NULL
; bs
= bs
->next
)
3303 struct counted_command_line
*ccmd
;
3304 struct command_line
*cmd
;
3305 struct cleanup
*this_cmd_tree_chain
;
3307 /* Take ownership of the BSP's command tree, if it has one.
3309 The command tree could legitimately contain commands like
3310 'step' and 'next', which call clear_proceed_status, which
3311 frees stop_bpstat's command tree. To make sure this doesn't
3312 free the tree we're executing out from under us, we need to
3313 take ownership of the tree ourselves. Since a given bpstat's
3314 commands are only executed once, we don't need to copy it; we
3315 can clear the pointer in the bpstat, and make sure we free
3316 the tree when we're done. */
3317 ccmd
= bs
->commands
;
3318 bs
->commands
= NULL
;
3319 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3320 cmd
= ccmd
? ccmd
->commands
: NULL
;
3321 if (command_line_is_silent (cmd
))
3323 /* The action has been already done by bpstat_stop_status. */
3329 execute_control_command (cmd
);
3331 if (breakpoint_proceeded
)
3337 /* We can free this command tree now. */
3338 do_cleanups (this_cmd_tree_chain
);
3340 if (breakpoint_proceeded
)
3342 if (target_can_async_p ())
3343 /* If we are in async mode, then the target might be still
3344 running, not stopped at any breakpoint, so nothing for
3345 us to do here -- just return to the event loop. */
3348 /* In sync mode, when execute_control_command returns
3349 we're already standing on the next breakpoint.
3350 Breakpoint commands for that stop were not run, since
3351 execute_command does not run breakpoint commands --
3352 only command_line_handler does, but that one is not
3353 involved in execution of breakpoint commands. So, we
3354 can now execute breakpoint commands. It should be
3355 noted that making execute_command do bpstat actions is
3356 not an option -- in this case we'll have recursive
3357 invocation of bpstat for each breakpoint with a
3358 command, and can easily blow up GDB stack. Instead, we
3359 return true, which will trigger the caller to recall us
3360 with the new stop_bpstat. */
3365 do_cleanups (old_chain
);
3370 bpstat_do_actions (void)
3372 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
3374 /* Do any commands attached to breakpoint we are stopped at. */
3375 while (!ptid_equal (inferior_ptid
, null_ptid
)
3376 && target_has_execution
3377 && !is_exited (inferior_ptid
)
3378 && !is_executing (inferior_ptid
))
3379 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3380 and only return when it is stopped at the next breakpoint, we
3381 keep doing breakpoint actions until it returns false to
3382 indicate the inferior was not resumed. */
3383 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3386 discard_cleanups (cleanup_if_error
);
3389 /* Print out the (old or new) value associated with a watchpoint. */
3392 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3395 fprintf_unfiltered (stream
, _("<unreadable>"));
3398 struct value_print_options opts
;
3399 get_user_print_options (&opts
);
3400 value_print (val
, stream
, &opts
);
3404 /* Generic routine for printing messages indicating why we
3405 stopped. The behavior of this function depends on the value
3406 'print_it' in the bpstat structure. Under some circumstances we
3407 may decide not to print anything here and delegate the task to
3410 static enum print_stop_action
3411 print_bp_stop_message (bpstat bs
)
3413 switch (bs
->print_it
)
3416 /* Nothing should be printed for this bpstat entry. */
3417 return PRINT_UNKNOWN
;
3421 /* We still want to print the frame, but we already printed the
3422 relevant messages. */
3423 return PRINT_SRC_AND_LOC
;
3426 case print_it_normal
:
3428 struct breakpoint
*b
= bs
->breakpoint_at
;
3430 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3431 which has since been deleted. */
3433 return PRINT_UNKNOWN
;
3435 /* Normal case. Call the breakpoint's print_it method. */
3436 return b
->ops
->print_it (bs
);
3441 internal_error (__FILE__
, __LINE__
,
3442 _("print_bp_stop_message: unrecognized enum value"));
3447 /* Print a message indicating what happened. This is called from
3448 normal_stop(). The input to this routine is the head of the bpstat
3449 list - a list of the eventpoints that caused this stop. KIND is
3450 the target_waitkind for the stopping event. This
3451 routine calls the generic print routine for printing a message
3452 about reasons for stopping. This will print (for example) the
3453 "Breakpoint n," part of the output. The return value of this
3456 PRINT_UNKNOWN: Means we printed nothing.
3457 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3458 code to print the location. An example is
3459 "Breakpoint 1, " which should be followed by
3461 PRINT_SRC_ONLY: Means we printed something, but there is no need
3462 to also print the location part of the message.
3463 An example is the catch/throw messages, which
3464 don't require a location appended to the end.
3465 PRINT_NOTHING: We have done some printing and we don't need any
3466 further info to be printed. */
3468 enum print_stop_action
3469 bpstat_print (bpstat bs
, int kind
)
3473 /* Maybe another breakpoint in the chain caused us to stop.
3474 (Currently all watchpoints go on the bpstat whether hit or not.
3475 That probably could (should) be changed, provided care is taken
3476 with respect to bpstat_explains_signal). */
3477 for (; bs
; bs
= bs
->next
)
3479 val
= print_bp_stop_message (bs
);
3480 if (val
== PRINT_SRC_ONLY
3481 || val
== PRINT_SRC_AND_LOC
3482 || val
== PRINT_NOTHING
)
3486 /* If we had hit a shared library event breakpoint,
3487 print_bp_stop_message would print out this message. If we hit an
3488 OS-level shared library event, do the same thing. */
3489 if (kind
== TARGET_WAITKIND_LOADED
)
3491 ui_out_text (current_uiout
, _("Stopped due to shared library event\n"));
3492 if (ui_out_is_mi_like_p (current_uiout
))
3493 ui_out_field_string (current_uiout
, "reason",
3494 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
3495 return PRINT_NOTHING
;
3498 /* We reached the end of the chain, or we got a null BS to start
3499 with and nothing was printed. */
3500 return PRINT_UNKNOWN
;
3503 /* Evaluate the expression EXP and return 1 if value is zero. This is
3504 used inside a catch_errors to evaluate the breakpoint condition.
3505 The argument is a "struct expression *" that has been cast to a
3506 "char *" to make it pass through catch_errors. */
3509 breakpoint_cond_eval (void *exp
)
3511 struct value
*mark
= value_mark ();
3512 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3514 value_free_to_mark (mark
);
3518 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3521 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3525 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3527 **bs_link_pointer
= bs
;
3528 *bs_link_pointer
= &bs
->next
;
3529 bs
->breakpoint_at
= bl
->owner
;
3530 bs
->bp_location_at
= bl
;
3531 incref_bp_location (bl
);
3532 /* If the condition is false, etc., don't do the commands. */
3533 bs
->commands
= NULL
;
3535 bs
->print_it
= print_it_normal
;
3539 /* The target has stopped with waitstatus WS. Check if any hardware
3540 watchpoints have triggered, according to the target. */
3543 watchpoints_triggered (struct target_waitstatus
*ws
)
3545 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3547 struct breakpoint
*b
;
3549 if (!stopped_by_watchpoint
)
3551 /* We were not stopped by a watchpoint. Mark all watchpoints
3552 as not triggered. */
3554 if (is_hardware_watchpoint (b
))
3556 struct watchpoint
*w
= (struct watchpoint
*) b
;
3558 w
->watchpoint_triggered
= watch_triggered_no
;
3564 if (!target_stopped_data_address (¤t_target
, &addr
))
3566 /* We were stopped by a watchpoint, but we don't know where.
3567 Mark all watchpoints as unknown. */
3569 if (is_hardware_watchpoint (b
))
3571 struct watchpoint
*w
= (struct watchpoint
*) b
;
3573 w
->watchpoint_triggered
= watch_triggered_unknown
;
3576 return stopped_by_watchpoint
;
3579 /* The target could report the data address. Mark watchpoints
3580 affected by this data address as triggered, and all others as not
3584 if (is_hardware_watchpoint (b
))
3586 struct watchpoint
*w
= (struct watchpoint
*) b
;
3587 struct bp_location
*loc
;
3589 w
->watchpoint_triggered
= watch_triggered_no
;
3590 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3592 if (is_masked_watchpoint (b
))
3594 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3595 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3597 if (newaddr
== start
)
3599 w
->watchpoint_triggered
= watch_triggered_yes
;
3603 /* Exact match not required. Within range is sufficient. */
3604 else if (target_watchpoint_addr_within_range (¤t_target
,
3608 w
->watchpoint_triggered
= watch_triggered_yes
;
3617 /* Possible return values for watchpoint_check (this can't be an enum
3618 because of check_errors). */
3619 /* The watchpoint has been deleted. */
3620 #define WP_DELETED 1
3621 /* The value has changed. */
3622 #define WP_VALUE_CHANGED 2
3623 /* The value has not changed. */
3624 #define WP_VALUE_NOT_CHANGED 3
3625 /* Ignore this watchpoint, no matter if the value changed or not. */
3628 #define BP_TEMPFLAG 1
3629 #define BP_HARDWAREFLAG 2
3631 /* Evaluate watchpoint condition expression and check if its value
3634 P should be a pointer to struct bpstat, but is defined as a void *
3635 in order for this function to be usable with catch_errors. */
3638 watchpoint_check (void *p
)
3640 bpstat bs
= (bpstat
) p
;
3641 struct watchpoint
*b
;
3642 struct frame_info
*fr
;
3643 int within_current_scope
;
3645 /* BS is built from an existing struct breakpoint. */
3646 gdb_assert (bs
->breakpoint_at
!= NULL
);
3647 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3649 /* If this is a local watchpoint, we only want to check if the
3650 watchpoint frame is in scope if the current thread is the thread
3651 that was used to create the watchpoint. */
3652 if (!watchpoint_in_thread_scope (b
))
3655 if (b
->exp_valid_block
== NULL
)
3656 within_current_scope
= 1;
3659 struct frame_info
*frame
= get_current_frame ();
3660 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3661 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3663 /* in_function_epilogue_p() returns a non-zero value if we're
3664 still in the function but the stack frame has already been
3665 invalidated. Since we can't rely on the values of local
3666 variables after the stack has been destroyed, we are treating
3667 the watchpoint in that state as `not changed' without further
3668 checking. Don't mark watchpoints as changed if the current
3669 frame is in an epilogue - even if they are in some other
3670 frame, our view of the stack is likely to be wrong and
3671 frame_find_by_id could error out. */
3672 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3675 fr
= frame_find_by_id (b
->watchpoint_frame
);
3676 within_current_scope
= (fr
!= NULL
);
3678 /* If we've gotten confused in the unwinder, we might have
3679 returned a frame that can't describe this variable. */
3680 if (within_current_scope
)
3682 struct symbol
*function
;
3684 function
= get_frame_function (fr
);
3685 if (function
== NULL
3686 || !contained_in (b
->exp_valid_block
,
3687 SYMBOL_BLOCK_VALUE (function
)))
3688 within_current_scope
= 0;
3691 if (within_current_scope
)
3692 /* If we end up stopping, the current frame will get selected
3693 in normal_stop. So this call to select_frame won't affect
3698 if (within_current_scope
)
3700 /* We use value_{,free_to_}mark because it could be a *long*
3701 time before we return to the command level and call
3702 free_all_values. We can't call free_all_values because we
3703 might be in the middle of evaluating a function call. */
3707 struct value
*new_val
;
3709 if (is_masked_watchpoint (&b
->base
))
3710 /* Since we don't know the exact trigger address (from
3711 stopped_data_address), just tell the user we've triggered
3712 a mask watchpoint. */
3713 return WP_VALUE_CHANGED
;
3715 mark
= value_mark ();
3716 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3718 /* We use value_equal_contents instead of value_equal because
3719 the latter coerces an array to a pointer, thus comparing just
3720 the address of the array instead of its contents. This is
3721 not what we want. */
3722 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3723 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3725 if (new_val
!= NULL
)
3727 release_value (new_val
);
3728 value_free_to_mark (mark
);
3730 bs
->old_val
= b
->val
;
3733 return WP_VALUE_CHANGED
;
3737 /* Nothing changed. */
3738 value_free_to_mark (mark
);
3739 return WP_VALUE_NOT_CHANGED
;
3744 struct ui_out
*uiout
= current_uiout
;
3746 /* This seems like the only logical thing to do because
3747 if we temporarily ignored the watchpoint, then when
3748 we reenter the block in which it is valid it contains
3749 garbage (in the case of a function, it may have two
3750 garbage values, one before and one after the prologue).
3751 So we can't even detect the first assignment to it and
3752 watch after that (since the garbage may or may not equal
3753 the first value assigned). */
3754 /* We print all the stop information in
3755 breakpoint_ops->print_it, but in this case, by the time we
3756 call breakpoint_ops->print_it this bp will be deleted
3757 already. So we have no choice but print the information
3759 if (ui_out_is_mi_like_p (uiout
))
3761 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3762 ui_out_text (uiout
, "\nWatchpoint ");
3763 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3765 " deleted because the program has left the block in\n\
3766 which its expression is valid.\n");
3768 /* Make sure the watchpoint's commands aren't executed. */
3769 decref_counted_command_line (&b
->base
.commands
);
3770 watchpoint_del_at_next_stop (b
);
3776 /* Return true if it looks like target has stopped due to hitting
3777 breakpoint location BL. This function does not check if we should
3778 stop, only if BL explains the stop. */
3781 bpstat_check_location (const struct bp_location
*bl
,
3782 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3784 struct breakpoint
*b
= bl
->owner
;
3786 /* BL is from an existing breakpoint. */
3787 gdb_assert (b
!= NULL
);
3789 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3792 /* Determine if the watched values have actually changed, and we
3793 should stop. If not, set BS->stop to 0. */
3796 bpstat_check_watchpoint (bpstat bs
)
3798 const struct bp_location
*bl
;
3799 struct watchpoint
*b
;
3801 /* BS is built for existing struct breakpoint. */
3802 bl
= bs
->bp_location_at
;
3803 gdb_assert (bl
!= NULL
);
3804 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3805 gdb_assert (b
!= NULL
);
3808 int must_check_value
= 0;
3810 if (b
->base
.type
== bp_watchpoint
)
3811 /* For a software watchpoint, we must always check the
3813 must_check_value
= 1;
3814 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3815 /* We have a hardware watchpoint (read, write, or access)
3816 and the target earlier reported an address watched by
3818 must_check_value
= 1;
3819 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3820 && b
->base
.type
== bp_hardware_watchpoint
)
3821 /* We were stopped by a hardware watchpoint, but the target could
3822 not report the data address. We must check the watchpoint's
3823 value. Access and read watchpoints are out of luck; without
3824 a data address, we can't figure it out. */
3825 must_check_value
= 1;
3827 if (must_check_value
)
3830 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3832 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3833 int e
= catch_errors (watchpoint_check
, bs
, message
,
3835 do_cleanups (cleanups
);
3839 /* We've already printed what needs to be printed. */
3840 bs
->print_it
= print_it_done
;
3844 bs
->print_it
= print_it_noop
;
3847 case WP_VALUE_CHANGED
:
3848 if (b
->base
.type
== bp_read_watchpoint
)
3850 /* There are two cases to consider here:
3852 1. We're watching the triggered memory for reads.
3853 In that case, trust the target, and always report
3854 the watchpoint hit to the user. Even though
3855 reads don't cause value changes, the value may
3856 have changed since the last time it was read, and
3857 since we're not trapping writes, we will not see
3858 those, and as such we should ignore our notion of
3861 2. We're watching the triggered memory for both
3862 reads and writes. There are two ways this may
3865 2.1. This is a target that can't break on data
3866 reads only, but can break on accesses (reads or
3867 writes), such as e.g., x86. We detect this case
3868 at the time we try to insert read watchpoints.
3870 2.2. Otherwise, the target supports read
3871 watchpoints, but, the user set an access or write
3872 watchpoint watching the same memory as this read
3875 If we're watching memory writes as well as reads,
3876 ignore watchpoint hits when we find that the
3877 value hasn't changed, as reads don't cause
3878 changes. This still gives false positives when
3879 the program writes the same value to memory as
3880 what there was already in memory (we will confuse
3881 it for a read), but it's much better than
3884 int other_write_watchpoint
= 0;
3886 if (bl
->watchpoint_type
== hw_read
)
3888 struct breakpoint
*other_b
;
3890 ALL_BREAKPOINTS (other_b
)
3891 if (other_b
->type
== bp_hardware_watchpoint
3892 || other_b
->type
== bp_access_watchpoint
)
3894 struct watchpoint
*other_w
=
3895 (struct watchpoint
*) other_b
;
3897 if (other_w
->watchpoint_triggered
3898 == watch_triggered_yes
)
3900 other_write_watchpoint
= 1;
3906 if (other_write_watchpoint
3907 || bl
->watchpoint_type
== hw_access
)
3909 /* We're watching the same memory for writes,
3910 and the value changed since the last time we
3911 updated it, so this trap must be for a write.
3913 bs
->print_it
= print_it_noop
;
3918 case WP_VALUE_NOT_CHANGED
:
3919 if (b
->base
.type
== bp_hardware_watchpoint
3920 || b
->base
.type
== bp_watchpoint
)
3922 /* Don't stop: write watchpoints shouldn't fire if
3923 the value hasn't changed. */
3924 bs
->print_it
= print_it_noop
;
3932 /* Error from catch_errors. */
3933 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3934 watchpoint_del_at_next_stop (b
);
3935 /* We've already printed what needs to be printed. */
3936 bs
->print_it
= print_it_done
;
3940 else /* must_check_value == 0 */
3942 /* This is a case where some watchpoint(s) triggered, but
3943 not at the address of this watchpoint, or else no
3944 watchpoint triggered after all. So don't print
3945 anything for this watchpoint. */
3946 bs
->print_it
= print_it_noop
;
3953 /* Check conditions (condition proper, frame, thread and ignore count)
3954 of breakpoint referred to by BS. If we should not stop for this
3955 breakpoint, set BS->stop to 0. */
3958 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3960 int thread_id
= pid_to_thread_id (ptid
);
3961 const struct bp_location
*bl
;
3962 struct breakpoint
*b
;
3964 /* BS is built for existing struct breakpoint. */
3965 bl
= bs
->bp_location_at
;
3966 gdb_assert (bl
!= NULL
);
3967 b
= bs
->breakpoint_at
;
3968 gdb_assert (b
!= NULL
);
3970 if (frame_id_p (b
->frame_id
)
3971 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3975 int value_is_zero
= 0;
3976 struct expression
*cond
;
3978 /* Evaluate Python breakpoints that have a "stop"
3979 method implemented. */
3980 if (b
->py_bp_object
)
3981 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
3983 if (is_watchpoint (b
))
3985 struct watchpoint
*w
= (struct watchpoint
*) b
;
3992 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3994 int within_current_scope
= 1;
3995 struct watchpoint
* w
;
3997 /* We use value_mark and value_free_to_mark because it could
3998 be a long time before we return to the command level and
3999 call free_all_values. We can't call free_all_values
4000 because we might be in the middle of evaluating a
4002 struct value
*mark
= value_mark ();
4004 if (is_watchpoint (b
))
4005 w
= (struct watchpoint
*) b
;
4009 /* Need to select the frame, with all that implies so that
4010 the conditions will have the right context. Because we
4011 use the frame, we will not see an inlined function's
4012 variables when we arrive at a breakpoint at the start
4013 of the inlined function; the current frame will be the
4015 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4016 select_frame (get_current_frame ());
4019 struct frame_info
*frame
;
4021 /* For local watchpoint expressions, which particular
4022 instance of a local is being watched matters, so we
4023 keep track of the frame to evaluate the expression
4024 in. To evaluate the condition however, it doesn't
4025 really matter which instantiation of the function
4026 where the condition makes sense triggers the
4027 watchpoint. This allows an expression like "watch
4028 global if q > 10" set in `func', catch writes to
4029 global on all threads that call `func', or catch
4030 writes on all recursive calls of `func' by a single
4031 thread. We simply always evaluate the condition in
4032 the innermost frame that's executing where it makes
4033 sense to evaluate the condition. It seems
4035 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4037 select_frame (frame
);
4039 within_current_scope
= 0;
4041 if (within_current_scope
)
4043 = catch_errors (breakpoint_cond_eval
, cond
,
4044 "Error in testing breakpoint condition:\n",
4048 warning (_("Watchpoint condition cannot be tested "
4049 "in the current scope"));
4050 /* If we failed to set the right context for this
4051 watchpoint, unconditionally report it. */
4054 /* FIXME-someday, should give breakpoint #. */
4055 value_free_to_mark (mark
);
4058 if (cond
&& value_is_zero
)
4062 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4066 else if (b
->ignore_count
> 0)
4069 annotate_ignore_count_change ();
4071 /* Increase the hit count even though we don't stop. */
4073 observer_notify_breakpoint_modified (b
);
4079 /* Get a bpstat associated with having just stopped at address
4080 BP_ADDR in thread PTID.
4082 Determine whether we stopped at a breakpoint, etc, or whether we
4083 don't understand this stop. Result is a chain of bpstat's such
4086 if we don't understand the stop, the result is a null pointer.
4088 if we understand why we stopped, the result is not null.
4090 Each element of the chain refers to a particular breakpoint or
4091 watchpoint at which we have stopped. (We may have stopped for
4092 several reasons concurrently.)
4094 Each element of the chain has valid next, breakpoint_at,
4095 commands, FIXME??? fields. */
4098 bpstat_stop_status (struct address_space
*aspace
,
4099 CORE_ADDR bp_addr
, ptid_t ptid
)
4101 struct breakpoint
*b
= NULL
;
4102 struct bp_location
*bl
;
4103 struct bp_location
*loc
;
4104 /* First item of allocated bpstat's. */
4105 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4106 /* Pointer to the last thing in the chain currently. */
4109 int need_remove_insert
;
4112 /* First, build the bpstat chain with locations that explain a
4113 target stop, while being careful to not set the target running,
4114 as that may invalidate locations (in particular watchpoint
4115 locations are recreated). Resuming will happen here with
4116 breakpoint conditions or watchpoint expressions that include
4117 inferior function calls. */
4121 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4124 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4126 /* For hardware watchpoints, we look only at the first
4127 location. The watchpoint_check function will work on the
4128 entire expression, not the individual locations. For
4129 read watchpoints, the watchpoints_triggered function has
4130 checked all locations already. */
4131 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4134 if (bl
->shlib_disabled
)
4137 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4140 /* Come here if it's a watchpoint, or if the break address
4143 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4146 /* Assume we stop. Should we find a watchpoint that is not
4147 actually triggered, or if the condition of the breakpoint
4148 evaluates as false, we'll reset 'stop' to 0. */
4152 /* If this is a scope breakpoint, mark the associated
4153 watchpoint as triggered so that we will handle the
4154 out-of-scope event. We'll get to the watchpoint next
4156 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4158 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4160 w
->watchpoint_triggered
= watch_triggered_yes
;
4165 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4167 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4169 bs
= bpstat_alloc (loc
, &bs_link
);
4170 /* For hits of moribund locations, we should just proceed. */
4173 bs
->print_it
= print_it_noop
;
4177 /* Now go through the locations that caused the target to stop, and
4178 check whether we're interested in reporting this stop to higher
4179 layers, or whether we should resume the target transparently. */
4183 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4188 b
= bs
->breakpoint_at
;
4189 b
->ops
->check_status (bs
);
4192 bpstat_check_breakpoint_conditions (bs
, ptid
);
4197 observer_notify_breakpoint_modified (b
);
4199 /* We will stop here. */
4200 if (b
->disposition
== disp_disable
)
4202 if (b
->enable_state
!= bp_permanent
)
4203 b
->enable_state
= bp_disabled
;
4208 bs
->commands
= b
->commands
;
4209 incref_counted_command_line (bs
->commands
);
4210 if (command_line_is_silent (bs
->commands
4211 ? bs
->commands
->commands
: NULL
))
4215 /* Print nothing for this entry if we don't stop or don't print. */
4216 if (bs
->stop
== 0 || bs
->print
== 0)
4217 bs
->print_it
= print_it_noop
;
4221 /* If we aren't stopping, the value of some hardware watchpoint may
4222 not have changed, but the intermediate memory locations we are
4223 watching may have. Don't bother if we're stopping; this will get
4225 need_remove_insert
= 0;
4226 if (! bpstat_causes_stop (bs_head
))
4227 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4229 && bs
->breakpoint_at
4230 && is_hardware_watchpoint (bs
->breakpoint_at
))
4232 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4234 update_watchpoint (w
, 0 /* don't reparse. */);
4235 need_remove_insert
= 1;
4238 if (need_remove_insert
)
4239 update_global_location_list (1);
4240 else if (removed_any
)
4241 update_global_location_list (0);
4247 handle_jit_event (void)
4249 struct frame_info
*frame
;
4250 struct gdbarch
*gdbarch
;
4252 /* Switch terminal for any messages produced by
4253 breakpoint_re_set. */
4254 target_terminal_ours_for_output ();
4256 frame
= get_current_frame ();
4257 gdbarch
= get_frame_arch (frame
);
4259 jit_event_handler (gdbarch
);
4261 target_terminal_inferior ();
4264 /* Prepare WHAT final decision for infrun. */
4266 /* Decide what infrun needs to do with this bpstat. */
4269 bpstat_what (bpstat bs_head
)
4271 struct bpstat_what retval
;
4272 /* We need to defer calling `solib_add', as adding new symbols
4273 resets breakpoints, which in turn deletes breakpoint locations,
4274 and hence may clear unprocessed entries in the BS chain. */
4275 int shlib_event
= 0;
4279 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4280 retval
.call_dummy
= STOP_NONE
;
4281 retval
.is_longjmp
= 0;
4283 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4285 /* Extract this BS's action. After processing each BS, we check
4286 if its action overrides all we've seem so far. */
4287 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4290 if (bs
->breakpoint_at
== NULL
)
4292 /* I suspect this can happen if it was a momentary
4293 breakpoint which has since been deleted. */
4297 bptype
= bs
->breakpoint_at
->type
;
4304 case bp_hardware_breakpoint
:
4310 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4312 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4315 this_action
= BPSTAT_WHAT_SINGLE
;
4318 case bp_hardware_watchpoint
:
4319 case bp_read_watchpoint
:
4320 case bp_access_watchpoint
:
4324 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4326 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4330 /* There was a watchpoint, but we're not stopping.
4331 This requires no further action. */
4336 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4337 retval
.is_longjmp
= bptype
== bp_longjmp
;
4339 case bp_longjmp_resume
:
4340 case bp_exception_resume
:
4341 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4342 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4344 case bp_step_resume
:
4346 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4349 /* It is for the wrong frame. */
4350 this_action
= BPSTAT_WHAT_SINGLE
;
4353 case bp_hp_step_resume
:
4355 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4358 /* It is for the wrong frame. */
4359 this_action
= BPSTAT_WHAT_SINGLE
;
4362 case bp_watchpoint_scope
:
4363 case bp_thread_event
:
4364 case bp_overlay_event
:
4365 case bp_longjmp_master
:
4366 case bp_std_terminate_master
:
4367 case bp_exception_master
:
4368 this_action
= BPSTAT_WHAT_SINGLE
;
4374 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4376 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4380 /* There was a catchpoint, but we're not stopping.
4381 This requires no further action. */
4384 case bp_shlib_event
:
4387 /* If requested, stop when the dynamic linker notifies GDB
4388 of events. This allows the user to get control and place
4389 breakpoints in initializer routines for dynamically
4390 loaded objects (among other things). */
4391 if (stop_on_solib_events
)
4392 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4394 this_action
= BPSTAT_WHAT_SINGLE
;
4398 this_action
= BPSTAT_WHAT_SINGLE
;
4401 /* Make sure the action is stop (silent or noisy),
4402 so infrun.c pops the dummy frame. */
4403 retval
.call_dummy
= STOP_STACK_DUMMY
;
4404 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4406 case bp_std_terminate
:
4407 /* Make sure the action is stop (silent or noisy),
4408 so infrun.c pops the dummy frame. */
4409 retval
.call_dummy
= STOP_STD_TERMINATE
;
4410 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4413 case bp_fast_tracepoint
:
4414 case bp_static_tracepoint
:
4415 /* Tracepoint hits should not be reported back to GDB, and
4416 if one got through somehow, it should have been filtered
4418 internal_error (__FILE__
, __LINE__
,
4419 _("bpstat_what: tracepoint encountered"));
4421 case bp_gnu_ifunc_resolver
:
4422 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4423 this_action
= BPSTAT_WHAT_SINGLE
;
4425 case bp_gnu_ifunc_resolver_return
:
4426 /* The breakpoint will be removed, execution will restart from the
4427 PC of the former breakpoint. */
4428 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4431 internal_error (__FILE__
, __LINE__
,
4432 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4435 retval
.main_action
= max (retval
.main_action
, this_action
);
4438 /* These operations may affect the bs->breakpoint_at state so they are
4439 delayed after MAIN_ACTION is decided above. */
4444 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4446 /* Check for any newly added shared libraries if we're supposed
4447 to be adding them automatically. */
4449 /* Switch terminal for any messages produced by
4450 breakpoint_re_set. */
4451 target_terminal_ours_for_output ();
4454 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4456 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4459 target_terminal_inferior ();
4465 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4467 handle_jit_event ();
4470 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4472 struct breakpoint
*b
= bs
->breakpoint_at
;
4478 case bp_gnu_ifunc_resolver
:
4479 gnu_ifunc_resolver_stop (b
);
4481 case bp_gnu_ifunc_resolver_return
:
4482 gnu_ifunc_resolver_return_stop (b
);
4490 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4491 without hardware support). This isn't related to a specific bpstat,
4492 just to things like whether watchpoints are set. */
4495 bpstat_should_step (void)
4497 struct breakpoint
*b
;
4500 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4506 bpstat_causes_stop (bpstat bs
)
4508 for (; bs
!= NULL
; bs
= bs
->next
)
4517 /* Compute a string of spaces suitable to indent the next line
4518 so it starts at the position corresponding to the table column
4519 named COL_NAME in the currently active table of UIOUT. */
4522 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4524 static char wrap_indent
[80];
4525 int i
, total_width
, width
, align
;
4529 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4531 if (strcmp (text
, col_name
) == 0)
4533 gdb_assert (total_width
< sizeof wrap_indent
);
4534 memset (wrap_indent
, ' ', total_width
);
4535 wrap_indent
[total_width
] = 0;
4540 total_width
+= width
+ 1;
4546 /* Print the LOC location out of the list of B->LOC locations. */
4549 print_breakpoint_location (struct breakpoint
*b
,
4550 struct bp_location
*loc
)
4552 struct ui_out
*uiout
= current_uiout
;
4553 struct cleanup
*old_chain
= save_current_program_space ();
4555 if (loc
!= NULL
&& loc
->shlib_disabled
)
4559 set_current_program_space (loc
->pspace
);
4561 if (b
->display_canonical
)
4562 ui_out_field_string (uiout
, "what", b
->addr_string
);
4563 else if (b
->source_file
&& loc
)
4566 = find_pc_sect_function (loc
->address
, loc
->section
);
4569 ui_out_text (uiout
, "in ");
4570 ui_out_field_string (uiout
, "func",
4571 SYMBOL_PRINT_NAME (sym
));
4572 ui_out_text (uiout
, " ");
4573 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4574 ui_out_text (uiout
, "at ");
4576 ui_out_field_string (uiout
, "file", b
->source_file
);
4577 ui_out_text (uiout
, ":");
4579 if (ui_out_is_mi_like_p (uiout
))
4581 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4582 char *fullname
= symtab_to_fullname (sal
.symtab
);
4585 ui_out_field_string (uiout
, "fullname", fullname
);
4588 ui_out_field_int (uiout
, "line", b
->line_number
);
4592 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4593 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4595 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4597 ui_out_field_stream (uiout
, "at", stb
);
4599 do_cleanups (stb_chain
);
4602 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4604 do_cleanups (old_chain
);
4608 bptype_string (enum bptype type
)
4610 struct ep_type_description
4615 static struct ep_type_description bptypes
[] =
4617 {bp_none
, "?deleted?"},
4618 {bp_breakpoint
, "breakpoint"},
4619 {bp_hardware_breakpoint
, "hw breakpoint"},
4620 {bp_until
, "until"},
4621 {bp_finish
, "finish"},
4622 {bp_watchpoint
, "watchpoint"},
4623 {bp_hardware_watchpoint
, "hw watchpoint"},
4624 {bp_read_watchpoint
, "read watchpoint"},
4625 {bp_access_watchpoint
, "acc watchpoint"},
4626 {bp_longjmp
, "longjmp"},
4627 {bp_longjmp_resume
, "longjmp resume"},
4628 {bp_exception
, "exception"},
4629 {bp_exception_resume
, "exception resume"},
4630 {bp_step_resume
, "step resume"},
4631 {bp_hp_step_resume
, "high-priority step resume"},
4632 {bp_watchpoint_scope
, "watchpoint scope"},
4633 {bp_call_dummy
, "call dummy"},
4634 {bp_std_terminate
, "std::terminate"},
4635 {bp_shlib_event
, "shlib events"},
4636 {bp_thread_event
, "thread events"},
4637 {bp_overlay_event
, "overlay events"},
4638 {bp_longjmp_master
, "longjmp master"},
4639 {bp_std_terminate_master
, "std::terminate master"},
4640 {bp_exception_master
, "exception master"},
4641 {bp_catchpoint
, "catchpoint"},
4642 {bp_tracepoint
, "tracepoint"},
4643 {bp_fast_tracepoint
, "fast tracepoint"},
4644 {bp_static_tracepoint
, "static tracepoint"},
4645 {bp_jit_event
, "jit events"},
4646 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4647 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4650 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4651 || ((int) type
!= bptypes
[(int) type
].type
))
4652 internal_error (__FILE__
, __LINE__
,
4653 _("bptypes table does not describe type #%d."),
4656 return bptypes
[(int) type
].description
;
4659 /* Print B to gdb_stdout. */
4662 print_one_breakpoint_location (struct breakpoint
*b
,
4663 struct bp_location
*loc
,
4665 struct bp_location
**last_loc
,
4668 struct command_line
*l
;
4669 static char bpenables
[] = "nynny";
4671 struct ui_out
*uiout
= current_uiout
;
4672 int header_of_multiple
= 0;
4673 int part_of_multiple
= (loc
!= NULL
);
4674 struct value_print_options opts
;
4676 get_user_print_options (&opts
);
4678 gdb_assert (!loc
|| loc_number
!= 0);
4679 /* See comment in print_one_breakpoint concerning treatment of
4680 breakpoints with single disabled location. */
4683 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4684 header_of_multiple
= 1;
4692 if (part_of_multiple
)
4695 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4696 ui_out_field_string (uiout
, "number", formatted
);
4701 ui_out_field_int (uiout
, "number", b
->number
);
4706 if (part_of_multiple
)
4707 ui_out_field_skip (uiout
, "type");
4709 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4713 if (part_of_multiple
)
4714 ui_out_field_skip (uiout
, "disp");
4716 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4721 if (part_of_multiple
)
4722 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4724 ui_out_field_fmt (uiout
, "enabled", "%c",
4725 bpenables
[(int) b
->enable_state
]);
4726 ui_out_spaces (uiout
, 2);
4730 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4732 /* Although the print_one can possibly print all locations,
4733 calling it here is not likely to get any nice result. So,
4734 make sure there's just one location. */
4735 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4736 b
->ops
->print_one (b
, last_loc
);
4742 internal_error (__FILE__
, __LINE__
,
4743 _("print_one_breakpoint: bp_none encountered\n"));
4747 case bp_hardware_watchpoint
:
4748 case bp_read_watchpoint
:
4749 case bp_access_watchpoint
:
4751 struct watchpoint
*w
= (struct watchpoint
*) b
;
4753 /* Field 4, the address, is omitted (which makes the columns
4754 not line up too nicely with the headers, but the effect
4755 is relatively readable). */
4756 if (opts
.addressprint
)
4757 ui_out_field_skip (uiout
, "addr");
4759 ui_out_field_string (uiout
, "what", w
->exp_string
);
4764 case bp_hardware_breakpoint
:
4768 case bp_longjmp_resume
:
4770 case bp_exception_resume
:
4771 case bp_step_resume
:
4772 case bp_hp_step_resume
:
4773 case bp_watchpoint_scope
:
4775 case bp_std_terminate
:
4776 case bp_shlib_event
:
4777 case bp_thread_event
:
4778 case bp_overlay_event
:
4779 case bp_longjmp_master
:
4780 case bp_std_terminate_master
:
4781 case bp_exception_master
:
4783 case bp_fast_tracepoint
:
4784 case bp_static_tracepoint
:
4786 case bp_gnu_ifunc_resolver
:
4787 case bp_gnu_ifunc_resolver_return
:
4788 if (opts
.addressprint
)
4791 if (header_of_multiple
)
4792 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4793 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4794 ui_out_field_string (uiout
, "addr", "<PENDING>");
4796 ui_out_field_core_addr (uiout
, "addr",
4797 loc
->gdbarch
, loc
->address
);
4800 if (!header_of_multiple
)
4801 print_breakpoint_location (b
, loc
);
4808 /* For backward compatibility, don't display inferiors unless there
4811 && !header_of_multiple
4813 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4814 && (number_of_program_spaces () > 1
4815 || number_of_inferiors () > 1)
4816 /* LOC is for existing B, it cannot be in
4817 moribund_locations and thus having NULL OWNER. */
4818 && loc
->owner
->type
!= bp_catchpoint
)))
4820 struct inferior
*inf
;
4823 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4825 if (inf
->pspace
== loc
->pspace
)
4830 ui_out_text (uiout
, " inf ");
4833 ui_out_text (uiout
, ", ");
4834 ui_out_text (uiout
, plongest (inf
->num
));
4839 if (!part_of_multiple
)
4841 if (b
->thread
!= -1)
4843 /* FIXME: This seems to be redundant and lost here; see the
4844 "stop only in" line a little further down. */
4845 ui_out_text (uiout
, " thread ");
4846 ui_out_field_int (uiout
, "thread", b
->thread
);
4848 else if (b
->task
!= 0)
4850 ui_out_text (uiout
, " task ");
4851 ui_out_field_int (uiout
, "task", b
->task
);
4855 ui_out_text (uiout
, "\n");
4857 if (!part_of_multiple
)
4858 b
->ops
->print_one_detail (b
, uiout
);
4860 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4863 ui_out_text (uiout
, "\tstop only in stack frame at ");
4864 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4866 ui_out_field_core_addr (uiout
, "frame",
4867 b
->gdbarch
, b
->frame_id
.stack_addr
);
4868 ui_out_text (uiout
, "\n");
4871 if (!part_of_multiple
&& b
->cond_string
)
4874 if (is_tracepoint (b
))
4875 ui_out_text (uiout
, "\ttrace only if ");
4877 ui_out_text (uiout
, "\tstop only if ");
4878 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4879 ui_out_text (uiout
, "\n");
4882 if (!part_of_multiple
&& b
->thread
!= -1)
4884 /* FIXME should make an annotation for this. */
4885 ui_out_text (uiout
, "\tstop only in thread ");
4886 ui_out_field_int (uiout
, "thread", b
->thread
);
4887 ui_out_text (uiout
, "\n");
4890 if (!part_of_multiple
&& b
->hit_count
)
4892 /* FIXME should make an annotation for this. */
4893 if (ep_is_catchpoint (b
))
4894 ui_out_text (uiout
, "\tcatchpoint");
4895 else if (is_tracepoint (b
))
4896 ui_out_text (uiout
, "\ttracepoint");
4898 ui_out_text (uiout
, "\tbreakpoint");
4899 ui_out_text (uiout
, " already hit ");
4900 ui_out_field_int (uiout
, "times", b
->hit_count
);
4901 if (b
->hit_count
== 1)
4902 ui_out_text (uiout
, " time\n");
4904 ui_out_text (uiout
, " times\n");
4907 /* Output the count also if it is zero, but only if this is mi.
4908 FIXME: Should have a better test for this. */
4909 if (ui_out_is_mi_like_p (uiout
))
4910 if (!part_of_multiple
&& b
->hit_count
== 0)
4911 ui_out_field_int (uiout
, "times", b
->hit_count
);
4913 if (!part_of_multiple
&& b
->ignore_count
)
4916 ui_out_text (uiout
, "\tignore next ");
4917 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4918 ui_out_text (uiout
, " hits\n");
4921 if (!part_of_multiple
&& is_tracepoint (b
))
4923 struct tracepoint
*tp
= (struct tracepoint
*) b
;
4925 if (tp
->traceframe_usage
)
4927 ui_out_text (uiout
, "\ttrace buffer usage ");
4928 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
4929 ui_out_text (uiout
, " bytes\n");
4933 l
= b
->commands
? b
->commands
->commands
: NULL
;
4934 if (!part_of_multiple
&& l
)
4936 struct cleanup
*script_chain
;
4939 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4940 print_command_lines (uiout
, l
, 4);
4941 do_cleanups (script_chain
);
4944 if (is_tracepoint (b
))
4946 struct tracepoint
*t
= (struct tracepoint
*) b
;
4948 if (!part_of_multiple
&& t
->pass_count
)
4950 annotate_field (10);
4951 ui_out_text (uiout
, "\tpass count ");
4952 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4953 ui_out_text (uiout
, " \n");
4957 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4959 if (is_watchpoint (b
))
4961 struct watchpoint
*w
= (struct watchpoint
*) b
;
4963 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
4965 else if (b
->addr_string
)
4966 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4971 print_one_breakpoint (struct breakpoint
*b
,
4972 struct bp_location
**last_loc
,
4975 struct cleanup
*bkpt_chain
;
4976 struct ui_out
*uiout
= current_uiout
;
4978 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4980 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
4981 do_cleanups (bkpt_chain
);
4983 /* If this breakpoint has custom print function,
4984 it's already printed. Otherwise, print individual
4985 locations, if any. */
4986 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4988 /* If breakpoint has a single location that is disabled, we
4989 print it as if it had several locations, since otherwise it's
4990 hard to represent "breakpoint enabled, location disabled"
4993 Note that while hardware watchpoints have several locations
4994 internally, that's not a property exposed to user. */
4996 && !is_hardware_watchpoint (b
)
4997 && (b
->loc
->next
|| !b
->loc
->enabled
))
4999 struct bp_location
*loc
;
5002 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5004 struct cleanup
*inner2
=
5005 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5006 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5007 do_cleanups (inner2
);
5014 breakpoint_address_bits (struct breakpoint
*b
)
5016 int print_address_bits
= 0;
5017 struct bp_location
*loc
;
5019 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5023 /* Software watchpoints that aren't watching memory don't have
5024 an address to print. */
5025 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5028 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5029 if (addr_bit
> print_address_bits
)
5030 print_address_bits
= addr_bit
;
5033 return print_address_bits
;
5036 struct captured_breakpoint_query_args
5042 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5044 struct captured_breakpoint_query_args
*args
= data
;
5045 struct breakpoint
*b
;
5046 struct bp_location
*dummy_loc
= NULL
;
5050 if (args
->bnum
== b
->number
)
5052 print_one_breakpoint (b
, &dummy_loc
, 0);
5060 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5061 char **error_message
)
5063 struct captured_breakpoint_query_args args
;
5066 /* For the moment we don't trust print_one_breakpoint() to not throw
5068 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5069 error_message
, RETURN_MASK_ALL
) < 0)
5075 /* Return true if this breakpoint was set by the user, false if it is
5076 internal or momentary. */
5079 user_breakpoint_p (struct breakpoint
*b
)
5081 return b
->number
> 0;
5084 /* Print information on user settable breakpoint (watchpoint, etc)
5085 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5086 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5087 FILTER is non-NULL, call it on each breakpoint and only include the
5088 ones for which it returns non-zero. Return the total number of
5089 breakpoints listed. */
5092 breakpoint_1 (char *args
, int allflag
,
5093 int (*filter
) (const struct breakpoint
*))
5095 struct breakpoint
*b
;
5096 struct bp_location
*last_loc
= NULL
;
5097 int nr_printable_breakpoints
;
5098 struct cleanup
*bkpttbl_chain
;
5099 struct value_print_options opts
;
5100 int print_address_bits
= 0;
5101 int print_type_col_width
= 14;
5102 struct ui_out
*uiout
= current_uiout
;
5104 get_user_print_options (&opts
);
5106 /* Compute the number of rows in the table, as well as the size
5107 required for address fields. */
5108 nr_printable_breakpoints
= 0;
5111 /* If we have a filter, only list the breakpoints it accepts. */
5112 if (filter
&& !filter (b
))
5115 /* If we have an "args" string, it is a list of breakpoints to
5116 accept. Skip the others. */
5117 if (args
!= NULL
&& *args
!= '\0')
5119 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5121 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5125 if (allflag
|| user_breakpoint_p (b
))
5127 int addr_bit
, type_len
;
5129 addr_bit
= breakpoint_address_bits (b
);
5130 if (addr_bit
> print_address_bits
)
5131 print_address_bits
= addr_bit
;
5133 type_len
= strlen (bptype_string (b
->type
));
5134 if (type_len
> print_type_col_width
)
5135 print_type_col_width
= type_len
;
5137 nr_printable_breakpoints
++;
5141 if (opts
.addressprint
)
5143 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5144 nr_printable_breakpoints
,
5148 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5149 nr_printable_breakpoints
,
5152 if (nr_printable_breakpoints
> 0)
5153 annotate_breakpoints_headers ();
5154 if (nr_printable_breakpoints
> 0)
5156 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5157 if (nr_printable_breakpoints
> 0)
5159 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5160 "type", "Type"); /* 2 */
5161 if (nr_printable_breakpoints
> 0)
5163 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5164 if (nr_printable_breakpoints
> 0)
5166 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5167 if (opts
.addressprint
)
5169 if (nr_printable_breakpoints
> 0)
5171 if (print_address_bits
<= 32)
5172 ui_out_table_header (uiout
, 10, ui_left
,
5173 "addr", "Address"); /* 5 */
5175 ui_out_table_header (uiout
, 18, ui_left
,
5176 "addr", "Address"); /* 5 */
5178 if (nr_printable_breakpoints
> 0)
5180 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5181 ui_out_table_body (uiout
);
5182 if (nr_printable_breakpoints
> 0)
5183 annotate_breakpoints_table ();
5188 /* If we have a filter, only list the breakpoints it accepts. */
5189 if (filter
&& !filter (b
))
5192 /* If we have an "args" string, it is a list of breakpoints to
5193 accept. Skip the others. */
5195 if (args
!= NULL
&& *args
!= '\0')
5197 if (allflag
) /* maintenance info breakpoint */
5199 if (parse_and_eval_long (args
) != b
->number
)
5202 else /* all others */
5204 if (!number_is_in_list (args
, b
->number
))
5208 /* We only print out user settable breakpoints unless the
5210 if (allflag
|| user_breakpoint_p (b
))
5211 print_one_breakpoint (b
, &last_loc
, allflag
);
5214 do_cleanups (bkpttbl_chain
);
5216 if (nr_printable_breakpoints
== 0)
5218 /* If there's a filter, let the caller decide how to report
5222 if (args
== NULL
|| *args
== '\0')
5223 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5225 ui_out_message (uiout
, 0,
5226 "No breakpoint or watchpoint matching '%s'.\n",
5232 if (last_loc
&& !server_command
)
5233 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5236 /* FIXME? Should this be moved up so that it is only called when
5237 there have been breakpoints? */
5238 annotate_breakpoints_table_end ();
5240 return nr_printable_breakpoints
;
5243 /* Display the value of default-collect in a way that is generally
5244 compatible with the breakpoint list. */
5247 default_collect_info (void)
5249 struct ui_out
*uiout
= current_uiout
;
5251 /* If it has no value (which is frequently the case), say nothing; a
5252 message like "No default-collect." gets in user's face when it's
5254 if (!*default_collect
)
5257 /* The following phrase lines up nicely with per-tracepoint collect
5259 ui_out_text (uiout
, "default collect ");
5260 ui_out_field_string (uiout
, "default-collect", default_collect
);
5261 ui_out_text (uiout
, " \n");
5265 breakpoints_info (char *args
, int from_tty
)
5267 breakpoint_1 (args
, 0, NULL
);
5269 default_collect_info ();
5273 watchpoints_info (char *args
, int from_tty
)
5275 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5276 struct ui_out
*uiout
= current_uiout
;
5278 if (num_printed
== 0)
5280 if (args
== NULL
|| *args
== '\0')
5281 ui_out_message (uiout
, 0, "No watchpoints.\n");
5283 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5288 maintenance_info_breakpoints (char *args
, int from_tty
)
5290 breakpoint_1 (args
, 1, NULL
);
5292 default_collect_info ();
5296 breakpoint_has_pc (struct breakpoint
*b
,
5297 struct program_space
*pspace
,
5298 CORE_ADDR pc
, struct obj_section
*section
)
5300 struct bp_location
*bl
= b
->loc
;
5302 for (; bl
; bl
= bl
->next
)
5304 if (bl
->pspace
== pspace
5305 && bl
->address
== pc
5306 && (!overlay_debugging
|| bl
->section
== section
))
5312 /* Print a message describing any user-breakpoints set at PC. This
5313 concerns with logical breakpoints, so we match program spaces, not
5317 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5318 struct program_space
*pspace
, CORE_ADDR pc
,
5319 struct obj_section
*section
, int thread
)
5322 struct breakpoint
*b
;
5325 others
+= (user_breakpoint_p (b
)
5326 && breakpoint_has_pc (b
, pspace
, pc
, section
));
5330 printf_filtered (_("Note: breakpoint "));
5331 else /* if (others == ???) */
5332 printf_filtered (_("Note: breakpoints "));
5334 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
5337 printf_filtered ("%d", b
->number
);
5338 if (b
->thread
== -1 && thread
!= -1)
5339 printf_filtered (" (all threads)");
5340 else if (b
->thread
!= -1)
5341 printf_filtered (" (thread %d)", b
->thread
);
5342 printf_filtered ("%s%s ",
5343 ((b
->enable_state
== bp_disabled
5344 || b
->enable_state
== bp_call_disabled
5345 || b
->enable_state
== bp_startup_disabled
)
5347 : b
->enable_state
== bp_permanent
5351 : ((others
== 1) ? " and" : ""));
5353 printf_filtered (_("also set at pc "));
5354 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5355 printf_filtered (".\n");
5360 /* Return true iff it is meaningful to use the address member of
5361 BPT. For some breakpoint types, the address member is irrelevant
5362 and it makes no sense to attempt to compare it to other addresses
5363 (or use it for any other purpose either).
5365 More specifically, each of the following breakpoint types will
5366 always have a zero valued address and we don't want to mark
5367 breakpoints of any of these types to be a duplicate of an actual
5368 breakpoint at address zero:
5376 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5378 enum bptype type
= bpt
->type
;
5380 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5383 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5384 true if LOC1 and LOC2 represent the same watchpoint location. */
5387 watchpoint_locations_match (struct bp_location
*loc1
,
5388 struct bp_location
*loc2
)
5390 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5391 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5393 /* Both of them must exist. */
5394 gdb_assert (w1
!= NULL
);
5395 gdb_assert (w2
!= NULL
);
5397 /* If the target can evaluate the condition expression in hardware,
5398 then we we need to insert both watchpoints even if they are at
5399 the same place. Otherwise the watchpoint will only trigger when
5400 the condition of whichever watchpoint was inserted evaluates to
5401 true, not giving a chance for GDB to check the condition of the
5402 other watchpoint. */
5404 && target_can_accel_watchpoint_condition (loc1
->address
,
5406 loc1
->watchpoint_type
,
5409 && target_can_accel_watchpoint_condition (loc2
->address
,
5411 loc2
->watchpoint_type
,
5415 /* Note that this checks the owner's type, not the location's. In
5416 case the target does not support read watchpoints, but does
5417 support access watchpoints, we'll have bp_read_watchpoint
5418 watchpoints with hw_access locations. Those should be considered
5419 duplicates of hw_read locations. The hw_read locations will
5420 become hw_access locations later. */
5421 return (loc1
->owner
->type
== loc2
->owner
->type
5422 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5423 && loc1
->address
== loc2
->address
5424 && loc1
->length
== loc2
->length
);
5427 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5428 same breakpoint location. In most targets, this can only be true
5429 if ASPACE1 matches ASPACE2. On targets that have global
5430 breakpoints, the address space doesn't really matter. */
5433 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5434 struct address_space
*aspace2
, CORE_ADDR addr2
)
5436 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5437 || aspace1
== aspace2
)
5441 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5442 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5443 matches ASPACE2. On targets that have global breakpoints, the address
5444 space doesn't really matter. */
5447 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5448 int len1
, struct address_space
*aspace2
,
5451 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5452 || aspace1
== aspace2
)
5453 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5456 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5457 a ranged breakpoint. In most targets, a match happens only if ASPACE
5458 matches the breakpoint's address space. On targets that have global
5459 breakpoints, the address space doesn't really matter. */
5462 breakpoint_location_address_match (struct bp_location
*bl
,
5463 struct address_space
*aspace
,
5466 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5469 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5470 bl
->address
, bl
->length
,
5474 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
5475 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
5476 true, otherwise returns false. */
5479 tracepoint_locations_match (struct bp_location
*loc1
,
5480 struct bp_location
*loc2
)
5482 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
5483 /* Since tracepoint locations are never duplicated with others', tracepoint
5484 locations at the same address of different tracepoints are regarded as
5485 different locations. */
5486 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
5491 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5492 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5493 represent the same location. */
5496 breakpoint_locations_match (struct bp_location
*loc1
,
5497 struct bp_location
*loc2
)
5499 int hw_point1
, hw_point2
;
5501 /* Both of them must not be in moribund_locations. */
5502 gdb_assert (loc1
->owner
!= NULL
);
5503 gdb_assert (loc2
->owner
!= NULL
);
5505 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5506 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5508 if (hw_point1
!= hw_point2
)
5511 return watchpoint_locations_match (loc1
, loc2
);
5512 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
5513 return tracepoint_locations_match (loc1
, loc2
);
5515 /* We compare bp_location.length in order to cover ranged breakpoints. */
5516 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5517 loc2
->pspace
->aspace
, loc2
->address
)
5518 && loc1
->length
== loc2
->length
);
5522 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5523 int bnum
, int have_bnum
)
5525 /* The longest string possibly returned by hex_string_custom
5526 is 50 chars. These must be at least that big for safety. */
5530 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5531 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5533 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5534 bnum
, astr1
, astr2
);
5536 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5539 /* Adjust a breakpoint's address to account for architectural
5540 constraints on breakpoint placement. Return the adjusted address.
5541 Note: Very few targets require this kind of adjustment. For most
5542 targets, this function is simply the identity function. */
5545 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5546 CORE_ADDR bpaddr
, enum bptype bptype
)
5548 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5550 /* Very few targets need any kind of breakpoint adjustment. */
5553 else if (bptype
== bp_watchpoint
5554 || bptype
== bp_hardware_watchpoint
5555 || bptype
== bp_read_watchpoint
5556 || bptype
== bp_access_watchpoint
5557 || bptype
== bp_catchpoint
)
5559 /* Watchpoints and the various bp_catch_* eventpoints should not
5560 have their addresses modified. */
5565 CORE_ADDR adjusted_bpaddr
;
5567 /* Some targets have architectural constraints on the placement
5568 of breakpoint instructions. Obtain the adjusted address. */
5569 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5571 /* An adjusted breakpoint address can significantly alter
5572 a user's expectations. Print a warning if an adjustment
5574 if (adjusted_bpaddr
!= bpaddr
)
5575 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5577 return adjusted_bpaddr
;
5582 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5583 struct breakpoint
*owner
)
5585 memset (loc
, 0, sizeof (*loc
));
5587 gdb_assert (ops
!= NULL
);
5592 loc
->shlib_disabled
= 0;
5595 switch (owner
->type
)
5601 case bp_longjmp_resume
:
5603 case bp_exception_resume
:
5604 case bp_step_resume
:
5605 case bp_hp_step_resume
:
5606 case bp_watchpoint_scope
:
5608 case bp_std_terminate
:
5609 case bp_shlib_event
:
5610 case bp_thread_event
:
5611 case bp_overlay_event
:
5613 case bp_longjmp_master
:
5614 case bp_std_terminate_master
:
5615 case bp_exception_master
:
5616 case bp_gnu_ifunc_resolver
:
5617 case bp_gnu_ifunc_resolver_return
:
5618 loc
->loc_type
= bp_loc_software_breakpoint
;
5620 case bp_hardware_breakpoint
:
5621 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5623 case bp_hardware_watchpoint
:
5624 case bp_read_watchpoint
:
5625 case bp_access_watchpoint
:
5626 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5631 case bp_fast_tracepoint
:
5632 case bp_static_tracepoint
:
5633 loc
->loc_type
= bp_loc_other
;
5636 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5642 /* Allocate a struct bp_location. */
5644 static struct bp_location
*
5645 allocate_bp_location (struct breakpoint
*bpt
)
5647 return bpt
->ops
->allocate_location (bpt
);
5651 free_bp_location (struct bp_location
*loc
)
5653 loc
->ops
->dtor (loc
);
5657 /* Increment reference count. */
5660 incref_bp_location (struct bp_location
*bl
)
5665 /* Decrement reference count. If the reference count reaches 0,
5666 destroy the bp_location. Sets *BLP to NULL. */
5669 decref_bp_location (struct bp_location
**blp
)
5671 gdb_assert ((*blp
)->refc
> 0);
5673 if (--(*blp
)->refc
== 0)
5674 free_bp_location (*blp
);
5678 /* Add breakpoint B at the end of the global breakpoint chain. */
5681 add_to_breakpoint_chain (struct breakpoint
*b
)
5683 struct breakpoint
*b1
;
5685 /* Add this breakpoint to the end of the chain so that a list of
5686 breakpoints will come out in order of increasing numbers. */
5688 b1
= breakpoint_chain
;
5690 breakpoint_chain
= b
;
5699 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5702 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5703 struct gdbarch
*gdbarch
,
5705 const struct breakpoint_ops
*ops
)
5707 memset (b
, 0, sizeof (*b
));
5709 gdb_assert (ops
!= NULL
);
5713 b
->gdbarch
= gdbarch
;
5714 b
->language
= current_language
->la_language
;
5715 b
->input_radix
= input_radix
;
5717 b
->enable_state
= bp_enabled
;
5720 b
->ignore_count
= 0;
5722 b
->frame_id
= null_frame_id
;
5723 b
->condition_not_parsed
= 0;
5724 b
->py_bp_object
= NULL
;
5725 b
->related_breakpoint
= b
;
5728 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5729 that has type BPTYPE and has no locations as yet. */
5731 static struct breakpoint
*
5732 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5734 const struct breakpoint_ops
*ops
)
5736 struct breakpoint
*b
= XNEW (struct breakpoint
);
5738 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5739 add_to_breakpoint_chain (b
);
5743 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5744 resolutions should be made as the user specified the location explicitly
5748 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5750 gdb_assert (loc
->owner
!= NULL
);
5752 if (loc
->owner
->type
== bp_breakpoint
5753 || loc
->owner
->type
== bp_hardware_breakpoint
5754 || is_tracepoint (loc
->owner
))
5758 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5759 NULL
, NULL
, &is_gnu_ifunc
);
5761 if (is_gnu_ifunc
&& !explicit_loc
)
5763 struct breakpoint
*b
= loc
->owner
;
5765 gdb_assert (loc
->pspace
== current_program_space
);
5766 if (gnu_ifunc_resolve_name (loc
->function_name
,
5767 &loc
->requested_address
))
5769 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5770 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5771 loc
->requested_address
,
5774 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5775 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5777 /* Create only the whole new breakpoint of this type but do not
5778 mess more complicated breakpoints with multiple locations. */
5779 b
->type
= bp_gnu_ifunc_resolver
;
5783 if (loc
->function_name
)
5784 loc
->function_name
= xstrdup (loc
->function_name
);
5788 /* Attempt to determine architecture of location identified by SAL. */
5790 get_sal_arch (struct symtab_and_line sal
)
5793 return get_objfile_arch (sal
.section
->objfile
);
5795 return get_objfile_arch (sal
.symtab
->objfile
);
5800 /* Low level routine for partially initializing a breakpoint of type
5801 BPTYPE. The newly created breakpoint's address, section, source
5802 file name, and line number are provided by SAL.
5804 It is expected that the caller will complete the initialization of
5805 the newly created breakpoint struct as well as output any status
5806 information regarding the creation of a new breakpoint. */
5809 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5810 struct symtab_and_line sal
, enum bptype bptype
,
5811 const struct breakpoint_ops
*ops
)
5813 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5815 add_location_to_breakpoint (b
, &sal
);
5817 if (bptype
!= bp_catchpoint
)
5818 gdb_assert (sal
.pspace
!= NULL
);
5820 /* Store the program space that was used to set the breakpoint, for
5821 breakpoint resetting. */
5822 b
->pspace
= sal
.pspace
;
5824 if (sal
.symtab
== NULL
)
5825 b
->source_file
= NULL
;
5827 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5828 b
->line_number
= sal
.line
;
5830 breakpoints_changed ();
5833 /* set_raw_breakpoint is a low level routine for allocating and
5834 partially initializing a breakpoint of type BPTYPE. The newly
5835 created breakpoint's address, section, source file name, and line
5836 number are provided by SAL. The newly created and partially
5837 initialized breakpoint is added to the breakpoint chain and
5838 is also returned as the value of this function.
5840 It is expected that the caller will complete the initialization of
5841 the newly created breakpoint struct as well as output any status
5842 information regarding the creation of a new breakpoint. In
5843 particular, set_raw_breakpoint does NOT set the breakpoint
5844 number! Care should be taken to not allow an error to occur
5845 prior to completing the initialization of the breakpoint. If this
5846 should happen, a bogus breakpoint will be left on the chain. */
5849 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5850 struct symtab_and_line sal
, enum bptype bptype
,
5851 const struct breakpoint_ops
*ops
)
5853 struct breakpoint
*b
= XNEW (struct breakpoint
);
5855 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5856 add_to_breakpoint_chain (b
);
5861 /* Note that the breakpoint object B describes a permanent breakpoint
5862 instruction, hard-wired into the inferior's code. */
5864 make_breakpoint_permanent (struct breakpoint
*b
)
5866 struct bp_location
*bl
;
5868 b
->enable_state
= bp_permanent
;
5870 /* By definition, permanent breakpoints are already present in the
5871 code. Mark all locations as inserted. For now,
5872 make_breakpoint_permanent is called in just one place, so it's
5873 hard to say if it's reasonable to have permanent breakpoint with
5874 multiple locations or not, but it's easy to implement. */
5875 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5879 /* Call this routine when stepping and nexting to enable a breakpoint
5880 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5881 initiated the operation. */
5884 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5886 struct breakpoint
*b
, *b_tmp
;
5887 int thread
= tp
->num
;
5889 /* To avoid having to rescan all objfile symbols at every step,
5890 we maintain a list of continually-inserted but always disabled
5891 longjmp "master" breakpoints. Here, we simply create momentary
5892 clones of those and enable them for the requested thread. */
5893 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5894 if (b
->pspace
== current_program_space
5895 && (b
->type
== bp_longjmp_master
5896 || b
->type
== bp_exception_master
))
5898 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5899 struct breakpoint
*clone
;
5901 clone
= momentary_breakpoint_from_master (b
, type
,
5902 &momentary_breakpoint_ops
);
5903 clone
->thread
= thread
;
5906 tp
->initiating_frame
= frame
;
5909 /* Delete all longjmp breakpoints from THREAD. */
5911 delete_longjmp_breakpoint (int thread
)
5913 struct breakpoint
*b
, *b_tmp
;
5915 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5916 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5918 if (b
->thread
== thread
)
5919 delete_breakpoint (b
);
5924 enable_overlay_breakpoints (void)
5926 struct breakpoint
*b
;
5929 if (b
->type
== bp_overlay_event
)
5931 b
->enable_state
= bp_enabled
;
5932 update_global_location_list (1);
5933 overlay_events_enabled
= 1;
5938 disable_overlay_breakpoints (void)
5940 struct breakpoint
*b
;
5943 if (b
->type
== bp_overlay_event
)
5945 b
->enable_state
= bp_disabled
;
5946 update_global_location_list (0);
5947 overlay_events_enabled
= 0;
5951 /* Set an active std::terminate breakpoint for each std::terminate
5952 master breakpoint. */
5954 set_std_terminate_breakpoint (void)
5956 struct breakpoint
*b
, *b_tmp
;
5958 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5959 if (b
->pspace
== current_program_space
5960 && b
->type
== bp_std_terminate_master
)
5962 momentary_breakpoint_from_master (b
, bp_std_terminate
,
5963 &momentary_breakpoint_ops
);
5967 /* Delete all the std::terminate breakpoints. */
5969 delete_std_terminate_breakpoint (void)
5971 struct breakpoint
*b
, *b_tmp
;
5973 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5974 if (b
->type
== bp_std_terminate
)
5975 delete_breakpoint (b
);
5979 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5981 struct breakpoint
*b
;
5983 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
5984 &internal_breakpoint_ops
);
5986 b
->enable_state
= bp_enabled
;
5987 /* addr_string has to be used or breakpoint_re_set will delete me. */
5989 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5991 update_global_location_list_nothrow (1);
5997 remove_thread_event_breakpoints (void)
5999 struct breakpoint
*b
, *b_tmp
;
6001 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6002 if (b
->type
== bp_thread_event
6003 && b
->loc
->pspace
== current_program_space
)
6004 delete_breakpoint (b
);
6007 struct lang_and_radix
6013 /* Create a breakpoint for JIT code registration and unregistration. */
6016 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6018 struct breakpoint
*b
;
6020 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6021 &internal_breakpoint_ops
);
6022 update_global_location_list_nothrow (1);
6026 /* Remove JIT code registration and unregistration breakpoint(s). */
6029 remove_jit_event_breakpoints (void)
6031 struct breakpoint
*b
, *b_tmp
;
6033 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6034 if (b
->type
== bp_jit_event
6035 && b
->loc
->pspace
== current_program_space
)
6036 delete_breakpoint (b
);
6040 remove_solib_event_breakpoints (void)
6042 struct breakpoint
*b
, *b_tmp
;
6044 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6045 if (b
->type
== bp_shlib_event
6046 && b
->loc
->pspace
== current_program_space
)
6047 delete_breakpoint (b
);
6051 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6053 struct breakpoint
*b
;
6055 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6056 &internal_breakpoint_ops
);
6057 update_global_location_list_nothrow (1);
6061 /* Disable any breakpoints that are on code in shared libraries. Only
6062 apply to enabled breakpoints, disabled ones can just stay disabled. */
6065 disable_breakpoints_in_shlibs (void)
6067 struct bp_location
*loc
, **locp_tmp
;
6069 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6071 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6072 struct breakpoint
*b
= loc
->owner
;
6074 /* We apply the check to all breakpoints, including disabled for
6075 those with loc->duplicate set. This is so that when breakpoint
6076 becomes enabled, or the duplicate is removed, gdb will try to
6077 insert all breakpoints. If we don't set shlib_disabled here,
6078 we'll try to insert those breakpoints and fail. */
6079 if (((b
->type
== bp_breakpoint
)
6080 || (b
->type
== bp_jit_event
)
6081 || (b
->type
== bp_hardware_breakpoint
)
6082 || (is_tracepoint (b
)))
6083 && loc
->pspace
== current_program_space
6084 && !loc
->shlib_disabled
6086 && PC_SOLIB (loc
->address
)
6088 && solib_name_from_address (loc
->pspace
, loc
->address
)
6092 loc
->shlib_disabled
= 1;
6097 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6098 library. Only apply to enabled breakpoints, disabled ones can just stay
6102 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6104 struct bp_location
*loc
, **locp_tmp
;
6105 int disabled_shlib_breaks
= 0;
6107 /* SunOS a.out shared libraries are always mapped, so do not
6108 disable breakpoints; they will only be reported as unloaded
6109 through clear_solib when GDB discards its shared library
6110 list. See clear_solib for more information. */
6111 if (exec_bfd
!= NULL
6112 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6115 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6117 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6118 struct breakpoint
*b
= loc
->owner
;
6120 if (solib
->pspace
== loc
->pspace
6121 && !loc
->shlib_disabled
6122 && (((b
->type
== bp_breakpoint
6123 || b
->type
== bp_jit_event
6124 || b
->type
== bp_hardware_breakpoint
)
6125 && (loc
->loc_type
== bp_loc_hardware_breakpoint
6126 || loc
->loc_type
== bp_loc_software_breakpoint
))
6127 || is_tracepoint (b
))
6128 && solib_contains_address_p (solib
, loc
->address
))
6130 loc
->shlib_disabled
= 1;
6131 /* At this point, we cannot rely on remove_breakpoint
6132 succeeding so we must mark the breakpoint as not inserted
6133 to prevent future errors occurring in remove_breakpoints. */
6136 /* This may cause duplicate notifications for the same breakpoint. */
6137 observer_notify_breakpoint_modified (b
);
6139 if (!disabled_shlib_breaks
)
6141 target_terminal_ours_for_output ();
6142 warning (_("Temporarily disabling breakpoints "
6143 "for unloaded shared library \"%s\""),
6146 disabled_shlib_breaks
= 1;
6151 /* FORK & VFORK catchpoints. */
6153 /* An instance of this type is used to represent a fork or vfork
6154 catchpoint. It includes a "struct breakpoint" as a kind of base
6155 class; users downcast to "struct breakpoint *" when needed. A
6156 breakpoint is really of this type iff its ops pointer points to
6157 CATCH_FORK_BREAKPOINT_OPS. */
6159 struct fork_catchpoint
6161 /* The base class. */
6162 struct breakpoint base
;
6164 /* Process id of a child process whose forking triggered this
6165 catchpoint. This field is only valid immediately after this
6166 catchpoint has triggered. */
6167 ptid_t forked_inferior_pid
;
6170 /* Implement the "insert" breakpoint_ops method for fork
6174 insert_catch_fork (struct bp_location
*bl
)
6176 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6179 /* Implement the "remove" breakpoint_ops method for fork
6183 remove_catch_fork (struct bp_location
*bl
)
6185 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6188 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6192 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6193 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6195 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6197 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6200 /* Implement the "print_it" breakpoint_ops method for fork
6203 static enum print_stop_action
6204 print_it_catch_fork (bpstat bs
)
6206 struct ui_out
*uiout
= current_uiout
;
6207 struct breakpoint
*b
= bs
->breakpoint_at
;
6208 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6210 annotate_catchpoint (b
->number
);
6211 if (b
->disposition
== disp_del
)
6212 ui_out_text (uiout
, "\nTemporary catchpoint ");
6214 ui_out_text (uiout
, "\nCatchpoint ");
6215 if (ui_out_is_mi_like_p (uiout
))
6217 ui_out_field_string (uiout
, "reason",
6218 async_reason_lookup (EXEC_ASYNC_FORK
));
6219 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6221 ui_out_field_int (uiout
, "bkptno", b
->number
);
6222 ui_out_text (uiout
, " (forked process ");
6223 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6224 ui_out_text (uiout
, "), ");
6225 return PRINT_SRC_AND_LOC
;
6228 /* Implement the "print_one" breakpoint_ops method for fork
6232 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6234 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6235 struct value_print_options opts
;
6236 struct ui_out
*uiout
= current_uiout
;
6238 get_user_print_options (&opts
);
6240 /* Field 4, the address, is omitted (which makes the columns not
6241 line up too nicely with the headers, but the effect is relatively
6243 if (opts
.addressprint
)
6244 ui_out_field_skip (uiout
, "addr");
6246 ui_out_text (uiout
, "fork");
6247 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6249 ui_out_text (uiout
, ", process ");
6250 ui_out_field_int (uiout
, "what",
6251 ptid_get_pid (c
->forked_inferior_pid
));
6252 ui_out_spaces (uiout
, 1);
6256 /* Implement the "print_mention" breakpoint_ops method for fork
6260 print_mention_catch_fork (struct breakpoint
*b
)
6262 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6265 /* Implement the "print_recreate" breakpoint_ops method for fork
6269 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6271 fprintf_unfiltered (fp
, "catch fork");
6272 print_recreate_thread (b
, fp
);
6275 /* The breakpoint_ops structure to be used in fork catchpoints. */
6277 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6279 /* Implement the "insert" breakpoint_ops method for vfork
6283 insert_catch_vfork (struct bp_location
*bl
)
6285 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6288 /* Implement the "remove" breakpoint_ops method for vfork
6292 remove_catch_vfork (struct bp_location
*bl
)
6294 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6297 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6301 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6302 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6304 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6306 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6309 /* Implement the "print_it" breakpoint_ops method for vfork
6312 static enum print_stop_action
6313 print_it_catch_vfork (bpstat bs
)
6315 struct ui_out
*uiout
= current_uiout
;
6316 struct breakpoint
*b
= bs
->breakpoint_at
;
6317 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6319 annotate_catchpoint (b
->number
);
6320 if (b
->disposition
== disp_del
)
6321 ui_out_text (uiout
, "\nTemporary catchpoint ");
6323 ui_out_text (uiout
, "\nCatchpoint ");
6324 if (ui_out_is_mi_like_p (uiout
))
6326 ui_out_field_string (uiout
, "reason",
6327 async_reason_lookup (EXEC_ASYNC_VFORK
));
6328 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6330 ui_out_field_int (uiout
, "bkptno", b
->number
);
6331 ui_out_text (uiout
, " (vforked process ");
6332 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6333 ui_out_text (uiout
, "), ");
6334 return PRINT_SRC_AND_LOC
;
6337 /* Implement the "print_one" breakpoint_ops method for vfork
6341 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6343 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6344 struct value_print_options opts
;
6345 struct ui_out
*uiout
= current_uiout
;
6347 get_user_print_options (&opts
);
6348 /* Field 4, the address, is omitted (which makes the columns not
6349 line up too nicely with the headers, but the effect is relatively
6351 if (opts
.addressprint
)
6352 ui_out_field_skip (uiout
, "addr");
6354 ui_out_text (uiout
, "vfork");
6355 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6357 ui_out_text (uiout
, ", process ");
6358 ui_out_field_int (uiout
, "what",
6359 ptid_get_pid (c
->forked_inferior_pid
));
6360 ui_out_spaces (uiout
, 1);
6364 /* Implement the "print_mention" breakpoint_ops method for vfork
6368 print_mention_catch_vfork (struct breakpoint
*b
)
6370 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6373 /* Implement the "print_recreate" breakpoint_ops method for vfork
6377 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6379 fprintf_unfiltered (fp
, "catch vfork");
6380 print_recreate_thread (b
, fp
);
6383 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6385 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6387 /* An instance of this type is used to represent a syscall catchpoint.
6388 It includes a "struct breakpoint" as a kind of base class; users
6389 downcast to "struct breakpoint *" when needed. A breakpoint is
6390 really of this type iff its ops pointer points to
6391 CATCH_SYSCALL_BREAKPOINT_OPS. */
6393 struct syscall_catchpoint
6395 /* The base class. */
6396 struct breakpoint base
;
6398 /* Syscall numbers used for the 'catch syscall' feature. If no
6399 syscall has been specified for filtering, its value is NULL.
6400 Otherwise, it holds a list of all syscalls to be caught. The
6401 list elements are allocated with xmalloc. */
6402 VEC(int) *syscalls_to_be_caught
;
6405 /* Implement the "dtor" breakpoint_ops method for syscall
6409 dtor_catch_syscall (struct breakpoint
*b
)
6411 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6413 VEC_free (int, c
->syscalls_to_be_caught
);
6415 base_breakpoint_ops
.dtor (b
);
6418 /* Implement the "insert" breakpoint_ops method for syscall
6422 insert_catch_syscall (struct bp_location
*bl
)
6424 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6425 struct inferior
*inf
= current_inferior ();
6427 ++inf
->total_syscalls_count
;
6428 if (!c
->syscalls_to_be_caught
)
6429 ++inf
->any_syscall_count
;
6435 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6440 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6442 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6443 uintptr_t vec_addr_offset
6444 = old_size
* ((uintptr_t) sizeof (int));
6446 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6447 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6449 memset ((void *) vec_addr
, 0,
6450 (iter
+ 1 - old_size
) * sizeof (int));
6452 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6453 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6457 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6458 inf
->total_syscalls_count
!= 0,
6459 inf
->any_syscall_count
,
6460 VEC_length (int, inf
->syscalls_counts
),
6461 VEC_address (int, inf
->syscalls_counts
));
6464 /* Implement the "remove" breakpoint_ops method for syscall
6468 remove_catch_syscall (struct bp_location
*bl
)
6470 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6471 struct inferior
*inf
= current_inferior ();
6473 --inf
->total_syscalls_count
;
6474 if (!c
->syscalls_to_be_caught
)
6475 --inf
->any_syscall_count
;
6481 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6485 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6486 /* Shouldn't happen. */
6488 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6489 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6493 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6494 inf
->total_syscalls_count
!= 0,
6495 inf
->any_syscall_count
,
6496 VEC_length (int, inf
->syscalls_counts
),
6498 inf
->syscalls_counts
));
6501 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6505 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6506 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6508 /* We must check if we are catching specific syscalls in this
6509 breakpoint. If we are, then we must guarantee that the called
6510 syscall is the same syscall we are catching. */
6511 int syscall_number
= 0;
6512 const struct syscall_catchpoint
*c
6513 = (const struct syscall_catchpoint
*) bl
->owner
;
6515 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6518 /* Now, checking if the syscall is the same. */
6519 if (c
->syscalls_to_be_caught
)
6524 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6526 if (syscall_number
== iter
)
6536 /* Implement the "print_it" breakpoint_ops method for syscall
6539 static enum print_stop_action
6540 print_it_catch_syscall (bpstat bs
)
6542 struct ui_out
*uiout
= current_uiout
;
6543 struct breakpoint
*b
= bs
->breakpoint_at
;
6544 /* These are needed because we want to know in which state a
6545 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6546 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6547 must print "called syscall" or "returned from syscall". */
6549 struct target_waitstatus last
;
6553 get_last_target_status (&ptid
, &last
);
6555 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6557 annotate_catchpoint (b
->number
);
6559 if (b
->disposition
== disp_del
)
6560 ui_out_text (uiout
, "\nTemporary catchpoint ");
6562 ui_out_text (uiout
, "\nCatchpoint ");
6563 if (ui_out_is_mi_like_p (uiout
))
6565 ui_out_field_string (uiout
, "reason",
6566 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
6567 ? EXEC_ASYNC_SYSCALL_ENTRY
6568 : EXEC_ASYNC_SYSCALL_RETURN
));
6569 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6571 ui_out_field_int (uiout
, "bkptno", b
->number
);
6573 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6574 ui_out_text (uiout
, " (call to syscall ");
6576 ui_out_text (uiout
, " (returned from syscall ");
6578 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
6579 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
6581 ui_out_field_string (uiout
, "syscall-name", s
.name
);
6583 ui_out_text (uiout
, "), ");
6585 return PRINT_SRC_AND_LOC
;
6588 /* Implement the "print_one" breakpoint_ops method for syscall
6592 print_one_catch_syscall (struct breakpoint
*b
,
6593 struct bp_location
**last_loc
)
6595 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6596 struct value_print_options opts
;
6597 struct ui_out
*uiout
= current_uiout
;
6599 get_user_print_options (&opts
);
6600 /* Field 4, the address, is omitted (which makes the columns not
6601 line up too nicely with the headers, but the effect is relatively
6603 if (opts
.addressprint
)
6604 ui_out_field_skip (uiout
, "addr");
6607 if (c
->syscalls_to_be_caught
6608 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6609 ui_out_text (uiout
, "syscalls \"");
6611 ui_out_text (uiout
, "syscall \"");
6613 if (c
->syscalls_to_be_caught
)
6616 char *text
= xstrprintf ("%s", "");
6619 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6624 get_syscall_by_number (iter
, &s
);
6627 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6629 text
= xstrprintf ("%s%d, ", text
, iter
);
6631 /* We have to xfree the last 'text' (now stored at 'x')
6632 because xstrprintf dynamically allocates new space for it
6636 /* Remove the last comma. */
6637 text
[strlen (text
) - 2] = '\0';
6638 ui_out_field_string (uiout
, "what", text
);
6641 ui_out_field_string (uiout
, "what", "<any syscall>");
6642 ui_out_text (uiout
, "\" ");
6645 /* Implement the "print_mention" breakpoint_ops method for syscall
6649 print_mention_catch_syscall (struct breakpoint
*b
)
6651 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6653 if (c
->syscalls_to_be_caught
)
6657 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6658 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6660 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6663 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6667 get_syscall_by_number (iter
, &s
);
6670 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6672 printf_filtered (" %d", s
.number
);
6674 printf_filtered (")");
6677 printf_filtered (_("Catchpoint %d (any syscall)"),
6681 /* Implement the "print_recreate" breakpoint_ops method for syscall
6685 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6687 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6689 fprintf_unfiltered (fp
, "catch syscall");
6691 if (c
->syscalls_to_be_caught
)
6696 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6701 get_syscall_by_number (iter
, &s
);
6703 fprintf_unfiltered (fp
, " %s", s
.name
);
6705 fprintf_unfiltered (fp
, " %d", s
.number
);
6708 print_recreate_thread (b
, fp
);
6711 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6713 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6715 /* Returns non-zero if 'b' is a syscall catchpoint. */
6718 syscall_catchpoint_p (struct breakpoint
*b
)
6720 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6723 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6724 is non-zero, then make the breakpoint temporary. If COND_STRING is
6725 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6726 the breakpoint_ops structure associated to the catchpoint. */
6729 init_catchpoint (struct breakpoint
*b
,
6730 struct gdbarch
*gdbarch
, int tempflag
,
6732 const struct breakpoint_ops
*ops
)
6734 struct symtab_and_line sal
;
6737 sal
.pspace
= current_program_space
;
6739 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6741 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6742 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6746 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
6748 add_to_breakpoint_chain (b
);
6749 set_breakpoint_number (internal
, b
);
6752 observer_notify_breakpoint_created (b
);
6755 update_global_location_list (1);
6759 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6760 int tempflag
, char *cond_string
,
6761 const struct breakpoint_ops
*ops
)
6763 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6765 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6767 c
->forked_inferior_pid
= null_ptid
;
6769 install_breakpoint (0, &c
->base
, 1);
6772 /* Exec catchpoints. */
6774 /* An instance of this type is used to represent an exec catchpoint.
6775 It includes a "struct breakpoint" as a kind of base class; users
6776 downcast to "struct breakpoint *" when needed. A breakpoint is
6777 really of this type iff its ops pointer points to
6778 CATCH_EXEC_BREAKPOINT_OPS. */
6780 struct exec_catchpoint
6782 /* The base class. */
6783 struct breakpoint base
;
6785 /* Filename of a program whose exec triggered this catchpoint.
6786 This field is only valid immediately after this catchpoint has
6788 char *exec_pathname
;
6791 /* Implement the "dtor" breakpoint_ops method for exec
6795 dtor_catch_exec (struct breakpoint
*b
)
6797 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6799 xfree (c
->exec_pathname
);
6801 base_breakpoint_ops
.dtor (b
);
6805 insert_catch_exec (struct bp_location
*bl
)
6807 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6811 remove_catch_exec (struct bp_location
*bl
)
6813 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6817 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6818 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6820 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6822 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6825 static enum print_stop_action
6826 print_it_catch_exec (bpstat bs
)
6828 struct ui_out
*uiout
= current_uiout
;
6829 struct breakpoint
*b
= bs
->breakpoint_at
;
6830 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6832 annotate_catchpoint (b
->number
);
6833 if (b
->disposition
== disp_del
)
6834 ui_out_text (uiout
, "\nTemporary catchpoint ");
6836 ui_out_text (uiout
, "\nCatchpoint ");
6837 if (ui_out_is_mi_like_p (uiout
))
6839 ui_out_field_string (uiout
, "reason",
6840 async_reason_lookup (EXEC_ASYNC_EXEC
));
6841 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6843 ui_out_field_int (uiout
, "bkptno", b
->number
);
6844 ui_out_text (uiout
, " (exec'd ");
6845 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
6846 ui_out_text (uiout
, "), ");
6848 return PRINT_SRC_AND_LOC
;
6852 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6854 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6855 struct value_print_options opts
;
6856 struct ui_out
*uiout
= current_uiout
;
6858 get_user_print_options (&opts
);
6860 /* Field 4, the address, is omitted (which makes the columns
6861 not line up too nicely with the headers, but the effect
6862 is relatively readable). */
6863 if (opts
.addressprint
)
6864 ui_out_field_skip (uiout
, "addr");
6866 ui_out_text (uiout
, "exec");
6867 if (c
->exec_pathname
!= NULL
)
6869 ui_out_text (uiout
, ", program \"");
6870 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6871 ui_out_text (uiout
, "\" ");
6876 print_mention_catch_exec (struct breakpoint
*b
)
6878 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6881 /* Implement the "print_recreate" breakpoint_ops method for exec
6885 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6887 fprintf_unfiltered (fp
, "catch exec");
6888 print_recreate_thread (b
, fp
);
6891 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6894 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6895 const struct breakpoint_ops
*ops
)
6897 struct syscall_catchpoint
*c
;
6898 struct gdbarch
*gdbarch
= get_current_arch ();
6900 c
= XNEW (struct syscall_catchpoint
);
6901 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6902 c
->syscalls_to_be_caught
= filter
;
6904 install_breakpoint (0, &c
->base
, 1);
6908 hw_breakpoint_used_count (void)
6911 struct breakpoint
*b
;
6912 struct bp_location
*bl
;
6916 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6917 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6919 /* Special types of hardware breakpoints may use more than
6921 i
+= b
->ops
->resources_needed (bl
);
6928 /* Returns the resources B would use if it were a hardware
6932 hw_watchpoint_use_count (struct breakpoint
*b
)
6935 struct bp_location
*bl
;
6937 if (!breakpoint_enabled (b
))
6940 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6942 /* Special types of hardware watchpoints may use more than
6944 i
+= b
->ops
->resources_needed (bl
);
6950 /* Returns the sum the used resources of all hardware watchpoints of
6951 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
6952 the sum of the used resources of all hardware watchpoints of other
6953 types _not_ TYPE. */
6956 hw_watchpoint_used_count_others (struct breakpoint
*except
,
6957 enum bptype type
, int *other_type_used
)
6960 struct breakpoint
*b
;
6962 *other_type_used
= 0;
6967 if (!breakpoint_enabled (b
))
6970 if (b
->type
== type
)
6971 i
+= hw_watchpoint_use_count (b
);
6972 else if (is_hardware_watchpoint (b
))
6973 *other_type_used
= 1;
6980 disable_watchpoints_before_interactive_call_start (void)
6982 struct breakpoint
*b
;
6986 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6988 b
->enable_state
= bp_call_disabled
;
6989 update_global_location_list (0);
6995 enable_watchpoints_after_interactive_call_stop (void)
6997 struct breakpoint
*b
;
7001 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7003 b
->enable_state
= bp_enabled
;
7004 update_global_location_list (1);
7010 disable_breakpoints_before_startup (void)
7012 struct breakpoint
*b
;
7017 if (b
->pspace
!= current_program_space
)
7020 if ((b
->type
== bp_breakpoint
7021 || b
->type
== bp_hardware_breakpoint
)
7022 && breakpoint_enabled (b
))
7024 b
->enable_state
= bp_startup_disabled
;
7030 update_global_location_list (0);
7032 current_program_space
->executing_startup
= 1;
7036 enable_breakpoints_after_startup (void)
7038 struct breakpoint
*b
;
7041 current_program_space
->executing_startup
= 0;
7045 if (b
->pspace
!= current_program_space
)
7048 if ((b
->type
== bp_breakpoint
7049 || b
->type
== bp_hardware_breakpoint
)
7050 && b
->enable_state
== bp_startup_disabled
)
7052 b
->enable_state
= bp_enabled
;
7058 breakpoint_re_set ();
7062 /* Set a breakpoint that will evaporate an end of command
7063 at address specified by SAL.
7064 Restrict it to frame FRAME if FRAME is nonzero. */
7067 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7068 struct frame_id frame_id
, enum bptype type
)
7070 struct breakpoint
*b
;
7072 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7074 gdb_assert (!frame_id_inlined_p (frame_id
));
7076 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
7077 b
->enable_state
= bp_enabled
;
7078 b
->disposition
= disp_donttouch
;
7079 b
->frame_id
= frame_id
;
7081 /* If we're debugging a multi-threaded program, then we want
7082 momentary breakpoints to be active in only a single thread of
7084 if (in_thread_list (inferior_ptid
))
7085 b
->thread
= pid_to_thread_id (inferior_ptid
);
7087 update_global_location_list_nothrow (1);
7092 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7093 The new breakpoint will have type TYPE, and use OPS as it
7096 static struct breakpoint
*
7097 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7099 const struct breakpoint_ops
*ops
)
7101 struct breakpoint
*copy
;
7103 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
7104 copy
->loc
= allocate_bp_location (copy
);
7105 set_breakpoint_location_function (copy
->loc
, 1);
7107 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7108 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7109 copy
->loc
->address
= orig
->loc
->address
;
7110 copy
->loc
->section
= orig
->loc
->section
;
7111 copy
->loc
->pspace
= orig
->loc
->pspace
;
7113 if (orig
->source_file
== NULL
)
7114 copy
->source_file
= NULL
;
7116 copy
->source_file
= xstrdup (orig
->source_file
);
7118 copy
->line_number
= orig
->line_number
;
7119 copy
->frame_id
= orig
->frame_id
;
7120 copy
->thread
= orig
->thread
;
7121 copy
->pspace
= orig
->pspace
;
7123 copy
->enable_state
= bp_enabled
;
7124 copy
->disposition
= disp_donttouch
;
7125 copy
->number
= internal_breakpoint_number
--;
7127 update_global_location_list_nothrow (0);
7131 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7135 clone_momentary_breakpoint (struct breakpoint
*orig
)
7137 /* If there's nothing to clone, then return nothing. */
7141 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
7145 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7148 struct symtab_and_line sal
;
7150 sal
= find_pc_line (pc
, 0);
7152 sal
.section
= find_pc_overlay (pc
);
7153 sal
.explicit_pc
= 1;
7155 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7159 /* Tell the user we have just set a breakpoint B. */
7162 mention (struct breakpoint
*b
)
7164 b
->ops
->print_mention (b
);
7165 if (ui_out_is_mi_like_p (current_uiout
))
7167 printf_filtered ("\n");
7171 static struct bp_location
*
7172 add_location_to_breakpoint (struct breakpoint
*b
,
7173 const struct symtab_and_line
*sal
)
7175 struct bp_location
*loc
, **tmp
;
7176 CORE_ADDR adjusted_address
;
7177 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
7179 if (loc_gdbarch
== NULL
)
7180 loc_gdbarch
= b
->gdbarch
;
7182 /* Adjust the breakpoint's address prior to allocating a location.
7183 Once we call allocate_bp_location(), that mostly uninitialized
7184 location will be placed on the location chain. Adjustment of the
7185 breakpoint may cause target_read_memory() to be called and we do
7186 not want its scan of the location chain to find a breakpoint and
7187 location that's only been partially initialized. */
7188 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
7191 loc
= allocate_bp_location (b
);
7192 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7196 loc
->requested_address
= sal
->pc
;
7197 loc
->address
= adjusted_address
;
7198 loc
->pspace
= sal
->pspace
;
7199 gdb_assert (loc
->pspace
!= NULL
);
7200 loc
->section
= sal
->section
;
7201 loc
->gdbarch
= loc_gdbarch
;
7202 set_breakpoint_location_function (loc
,
7203 sal
->explicit_pc
|| sal
->explicit_line
);
7208 /* Return 1 if LOC is pointing to a permanent breakpoint,
7209 return 0 otherwise. */
7212 bp_loc_is_permanent (struct bp_location
*loc
)
7216 const gdb_byte
*brk
;
7217 gdb_byte
*target_mem
;
7218 struct cleanup
*cleanup
;
7221 gdb_assert (loc
!= NULL
);
7223 addr
= loc
->address
;
7224 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7226 /* Software breakpoints unsupported? */
7230 target_mem
= alloca (len
);
7232 /* Enable the automatic memory restoration from breakpoints while
7233 we read the memory. Otherwise we could say about our temporary
7234 breakpoints they are permanent. */
7235 cleanup
= save_current_space_and_thread ();
7237 switch_to_program_space_and_thread (loc
->pspace
);
7238 make_show_memory_breakpoints_cleanup (0);
7240 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7241 && memcmp (target_mem
, brk
, len
) == 0)
7244 do_cleanups (cleanup
);
7251 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7252 as textual description of the location, and COND_STRING
7253 as condition expression. */
7256 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7257 struct symtabs_and_lines sals
, char *addr_string
,
7259 enum bptype type
, enum bpdisp disposition
,
7260 int thread
, int task
, int ignore_count
,
7261 const struct breakpoint_ops
*ops
, int from_tty
,
7262 int enabled
, int internal
, int display_canonical
)
7266 if (type
== bp_hardware_breakpoint
)
7268 int i
= hw_breakpoint_used_count ();
7269 int target_resources_ok
=
7270 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7272 if (target_resources_ok
== 0)
7273 error (_("No hardware breakpoint support in the target."));
7274 else if (target_resources_ok
< 0)
7275 error (_("Hardware breakpoints used exceeds limit."));
7278 gdb_assert (sals
.nelts
> 0);
7280 for (i
= 0; i
< sals
.nelts
; ++i
)
7282 struct symtab_and_line sal
= sals
.sals
[i
];
7283 struct bp_location
*loc
;
7287 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7289 loc_gdbarch
= gdbarch
;
7291 describe_other_breakpoints (loc_gdbarch
,
7292 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7297 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7301 b
->cond_string
= cond_string
;
7302 b
->ignore_count
= ignore_count
;
7303 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7304 b
->disposition
= disposition
;
7305 b
->pspace
= sals
.sals
[0].pspace
;
7307 if (type
== bp_static_tracepoint
)
7309 struct tracepoint
*t
= (struct tracepoint
*) b
;
7310 struct static_tracepoint_marker marker
;
7312 if (is_marker_spec (addr_string
))
7314 /* We already know the marker exists, otherwise, we
7315 wouldn't see a sal for it. */
7316 char *p
= &addr_string
[3];
7321 p
= skip_spaces (p
);
7323 endp
= skip_to_space (p
);
7325 marker_str
= savestring (p
, endp
- p
);
7326 t
->static_trace_marker_id
= marker_str
;
7328 printf_filtered (_("Probed static tracepoint "
7330 t
->static_trace_marker_id
);
7332 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7334 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7335 release_static_tracepoint_marker (&marker
);
7337 printf_filtered (_("Probed static tracepoint "
7339 t
->static_trace_marker_id
);
7342 warning (_("Couldn't determine the static "
7343 "tracepoint marker to probe"));
7346 if (enabled
&& b
->pspace
->executing_startup
7347 && (b
->type
== bp_breakpoint
7348 || b
->type
== bp_hardware_breakpoint
))
7349 b
->enable_state
= bp_startup_disabled
;
7355 loc
= add_location_to_breakpoint (b
, &sal
);
7358 if (bp_loc_is_permanent (loc
))
7359 make_breakpoint_permanent (b
);
7363 char *arg
= b
->cond_string
;
7364 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7366 error (_("Garbage %s follows condition"), arg
);
7370 b
->display_canonical
= display_canonical
;
7372 b
->addr_string
= addr_string
;
7374 /* addr_string has to be used or breakpoint_re_set will delete
7377 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7381 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7382 struct symtabs_and_lines sals
, char *addr_string
,
7384 enum bptype type
, enum bpdisp disposition
,
7385 int thread
, int task
, int ignore_count
,
7386 const struct breakpoint_ops
*ops
, int from_tty
,
7387 int enabled
, int internal
, int display_canonical
)
7389 struct breakpoint
*b
;
7390 struct cleanup
*old_chain
;
7392 if (is_tracepoint_type (type
))
7394 struct tracepoint
*t
;
7396 t
= XCNEW (struct tracepoint
);
7400 b
= XNEW (struct breakpoint
);
7402 old_chain
= make_cleanup (xfree
, b
);
7404 init_breakpoint_sal (b
, gdbarch
,
7408 thread
, task
, ignore_count
,
7410 enabled
, internal
, display_canonical
);
7411 discard_cleanups (old_chain
);
7413 install_breakpoint (internal
, b
, 0);
7416 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7417 elements to fill the void space. */
7419 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7421 int i
= index_to_remove
+1;
7422 int last_index
= sal
->nelts
-1;
7424 for (;i
<= last_index
; ++i
)
7425 sal
->sals
[i
-1] = sal
->sals
[i
];
7430 /* If appropriate, obtains all sals that correspond to the same file
7431 and line as SAL, in all program spaces. Users debugging with IDEs,
7432 will want to set a breakpoint at foo.c:line, and not really care
7433 about program spaces. This is done only if SAL does not have
7434 explicit PC and has line and file information. If we got just a
7435 single expanded sal, return the original.
7437 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7438 which the name of enclosing function is different from SAL. This
7439 makes sure that if we have breakpoint originally set in template
7440 instantiation, say foo<int>(), we won't expand SAL to locations at
7441 the same line in all existing instantiations of 'foo'. */
7443 static struct symtabs_and_lines
7444 expand_line_sal_maybe (struct symtab_and_line sal
)
7446 struct symtabs_and_lines expanded
;
7447 CORE_ADDR original_pc
= sal
.pc
;
7448 char *original_function
= NULL
;
7451 struct cleanup
*old_chain
;
7453 /* If we have explicit pc, don't expand.
7454 If we have no line number, we can't expand. */
7455 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7458 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7459 expanded
.sals
[0] = sal
;
7465 old_chain
= save_current_space_and_thread ();
7467 switch_to_program_space_and_thread (sal
.pspace
);
7469 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7471 /* Note that expand_line_sal visits *all* program spaces. */
7472 expanded
= expand_line_sal (sal
);
7474 if (expanded
.nelts
== 1)
7476 /* We had one sal, we got one sal. Return that sal, adjusting it
7477 past the function prologue if necessary. */
7478 xfree (expanded
.sals
);
7480 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7481 sal
.pc
= original_pc
;
7482 expanded
.sals
[0] = sal
;
7483 skip_prologue_sal (&expanded
.sals
[0]);
7484 do_cleanups (old_chain
);
7488 if (!sal
.explicit_line
)
7490 CORE_ADDR func_addr
, func_end
;
7491 for (i
= 0; i
< expanded
.nelts
; ++i
)
7493 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7494 char *this_function
;
7496 /* We need to switch threads as well since we're about to
7498 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7500 if (find_pc_partial_function (pc
, &this_function
,
7501 &func_addr
, &func_end
))
7504 && strcmp (this_function
, original_function
) != 0)
7506 remove_sal (&expanded
, i
);
7513 /* Skip the function prologue if necessary. */
7514 for (i
= 0; i
< expanded
.nelts
; ++i
)
7515 skip_prologue_sal (&expanded
.sals
[i
]);
7517 do_cleanups (old_chain
);
7519 if (expanded
.nelts
<= 1)
7521 /* This is an ugly workaround. If we get zero expanded sals
7522 then something is really wrong. Fix that by returning the
7525 xfree (expanded
.sals
);
7527 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7528 sal
.pc
= original_pc
;
7529 expanded
.sals
[0] = sal
;
7536 for (i
= 0; i
< expanded
.nelts
; ++i
)
7537 if (expanded
.sals
[i
].pc
== original_pc
)
7548 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7549 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7550 value. COND_STRING, if not NULL, specified the condition to be
7551 used for all breakpoints. Essentially the only case where
7552 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7553 function. In that case, it's still not possible to specify
7554 separate conditions for different overloaded functions, so
7555 we take just a single condition string.
7557 NOTE: If the function succeeds, the caller is expected to cleanup
7558 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7559 array contents). If the function fails (error() is called), the
7560 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7561 COND and SALS arrays and each of those arrays contents. */
7564 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7565 struct symtabs_and_lines sals
,
7566 struct linespec_result
*canonical
,
7568 enum bptype type
, enum bpdisp disposition
,
7569 int thread
, int task
, int ignore_count
,
7570 const struct breakpoint_ops
*ops
, int from_tty
,
7571 int enabled
, int internal
)
7575 for (i
= 0; i
< sals
.nelts
; ++i
)
7577 struct symtabs_and_lines expanded
=
7578 expand_line_sal_maybe (sals
.sals
[i
]);
7580 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7581 cond_string
, type
, disposition
,
7582 thread
, task
, ignore_count
, ops
,
7583 from_tty
, enabled
, internal
,
7584 canonical
->special_display
);
7588 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7589 followed by conditionals. On return, SALS contains an array of SAL
7590 addresses found. ADDR_STRING contains a vector of (canonical)
7591 address strings. ADDRESS points to the end of the SAL.
7593 The array and the line spec strings are allocated on the heap, it is
7594 the caller's responsibility to free them. */
7597 parse_breakpoint_sals (char **address
,
7598 struct symtabs_and_lines
*sals
,
7599 struct linespec_result
*canonical
)
7601 char *addr_start
= *address
;
7603 /* If no arg given, or if first arg is 'if ', use the default
7605 if ((*address
) == NULL
7606 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7608 /* The last displayed codepoint, if it's valid, is our default breakpoint
7610 if (last_displayed_sal_is_valid ())
7612 struct symtab_and_line sal
;
7614 init_sal (&sal
); /* Initialize to zeroes. */
7615 sals
->sals
= (struct symtab_and_line
*)
7616 xmalloc (sizeof (struct symtab_and_line
));
7618 /* Set sal's pspace, pc, symtab, and line to the values
7619 corresponding to the last call to print_frame_info. */
7620 get_last_displayed_sal (&sal
);
7621 sal
.section
= find_pc_overlay (sal
.pc
);
7623 /* "break" without arguments is equivalent to "break *PC"
7624 where PC is the last displayed codepoint's address. So
7625 make sure to set sal.explicit_pc to prevent GDB from
7626 trying to expand the list of sals to include all other
7627 instances with the same symtab and line. */
7628 sal
.explicit_pc
= 1;
7630 sals
->sals
[0] = sal
;
7634 error (_("No default breakpoint address now."));
7638 /* Force almost all breakpoints to be in terms of the
7639 current_source_symtab (which is decode_line_1's default).
7640 This should produce the results we want almost all of the
7641 time while leaving the last displayed codepoint pointers
7644 ObjC: However, don't match an Objective-C method name which
7645 may have a '+' or '-' succeeded by a '[' */
7647 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7649 if (last_displayed_sal_is_valid ()
7651 || ((strchr ("+-", (*address
)[0]) != NULL
)
7652 && ((*address
)[1] != '['))))
7653 *sals
= decode_line_1 (address
, 1,
7654 get_last_displayed_symtab (),
7655 get_last_displayed_line (),
7658 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7661 /* For any SAL that didn't have a canonical string, fill one in. */
7662 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7663 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7664 if (addr_start
!= (*address
))
7668 for (i
= 0; i
< sals
->nelts
; i
++)
7670 /* Add the string if not present. */
7671 if (canonical
->canonical
[i
] == NULL
)
7672 canonical
->canonical
[i
] = savestring (addr_start
,
7673 (*address
) - addr_start
);
7679 /* Convert each SAL into a real PC. Verify that the PC can be
7680 inserted as a breakpoint. If it can't throw an error. */
7683 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7687 for (i
= 0; i
< sals
->nelts
; i
++)
7688 resolve_sal_pc (&sals
->sals
[i
]);
7691 /* Fast tracepoints may have restrictions on valid locations. For
7692 instance, a fast tracepoint using a jump instead of a trap will
7693 likely have to overwrite more bytes than a trap would, and so can
7694 only be placed where the instruction is longer than the jump, or a
7695 multi-instruction sequence does not have a jump into the middle of
7699 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7700 struct symtabs_and_lines
*sals
)
7703 struct symtab_and_line
*sal
;
7705 struct cleanup
*old_chain
;
7707 for (i
= 0; i
< sals
->nelts
; i
++)
7709 sal
= &sals
->sals
[i
];
7711 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7713 old_chain
= make_cleanup (xfree
, msg
);
7716 error (_("May not have a fast tracepoint at 0x%s%s"),
7717 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7719 do_cleanups (old_chain
);
7723 /* Given TOK, a string specification of condition and thread, as
7724 accepted by the 'break' command, extract the condition
7725 string and thread number and set *COND_STRING and *THREAD.
7726 PC identifies the context at which the condition should be parsed.
7727 If no condition is found, *COND_STRING is set to NULL.
7728 If no thread is found, *THREAD is set to -1. */
7730 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7731 char **cond_string
, int *thread
, int *task
)
7733 *cond_string
= NULL
;
7739 char *cond_start
= NULL
;
7740 char *cond_end
= NULL
;
7742 tok
= skip_spaces (tok
);
7744 end_tok
= skip_to_space (tok
);
7746 toklen
= end_tok
- tok
;
7748 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7750 struct expression
*expr
;
7752 tok
= cond_start
= end_tok
+ 1;
7753 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7756 *cond_string
= savestring (cond_start
,
7757 cond_end
- cond_start
);
7759 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7765 *thread
= strtol (tok
, &tok
, 0);
7767 error (_("Junk after thread keyword."));
7768 if (!valid_thread_id (*thread
))
7769 error (_("Unknown thread %d."), *thread
);
7771 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7777 *task
= strtol (tok
, &tok
, 0);
7779 error (_("Junk after task keyword."));
7780 if (!valid_task_id (*task
))
7781 error (_("Unknown task %d."), *task
);
7784 error (_("Junk at end of arguments."));
7788 /* Decode a static tracepoint marker spec. */
7790 static struct symtabs_and_lines
7791 decode_static_tracepoint_spec (char **arg_p
)
7793 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7794 struct symtabs_and_lines sals
;
7795 struct symtab_and_line sal
;
7797 struct cleanup
*old_chain
;
7798 char *p
= &(*arg_p
)[3];
7803 p
= skip_spaces (p
);
7805 endp
= skip_to_space (p
);
7807 marker_str
= savestring (p
, endp
- p
);
7808 old_chain
= make_cleanup (xfree
, marker_str
);
7810 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7811 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7812 error (_("No known static tracepoint marker named %s"), marker_str
);
7814 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7815 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7817 for (i
= 0; i
< sals
.nelts
; i
++)
7819 struct static_tracepoint_marker
*marker
;
7821 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7823 init_sal (&sals
.sals
[i
]);
7825 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7826 sals
.sals
[i
].pc
= marker
->address
;
7828 release_static_tracepoint_marker (marker
);
7831 do_cleanups (old_chain
);
7837 /* Set a breakpoint. This function is shared between CLI and MI
7838 functions for setting a breakpoint. This function has two major
7839 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7840 parameter. If non-zero, the function will parse arg, extracting
7841 breakpoint location, address and thread. Otherwise, ARG is just
7842 the location of breakpoint, with condition and thread specified by
7843 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7844 the breakpoint number will be allocated from the internal
7845 breakpoint count. Returns true if any breakpoint was created;
7849 create_breakpoint (struct gdbarch
*gdbarch
,
7850 char *arg
, char *cond_string
, int thread
,
7851 int parse_condition_and_thread
,
7852 int tempflag
, enum bptype type_wanted
,
7854 enum auto_boolean pending_break_support
,
7855 const struct breakpoint_ops
*ops
,
7856 int from_tty
, int enabled
, int internal
)
7858 volatile struct gdb_exception e
;
7859 struct symtabs_and_lines sals
;
7860 struct symtab_and_line pending_sal
;
7862 char *addr_start
= arg
;
7863 struct linespec_result canonical
;
7864 struct cleanup
*old_chain
;
7865 struct cleanup
*bkpt_chain
= NULL
;
7869 int prev_bkpt_count
= breakpoint_count
;
7871 gdb_assert (ops
!= NULL
);
7875 init_linespec_result (&canonical
);
7877 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7881 sals
= decode_static_tracepoint_spec (&arg
);
7883 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7884 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7885 for (i
= 0; i
< sals
.nelts
; i
++)
7886 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7890 TRY_CATCH (e
, RETURN_MASK_ALL
)
7892 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7895 /* If caller is interested in rc value from parse, set value. */
7899 throw_exception (e
);
7903 case NOT_FOUND_ERROR
:
7905 /* If pending breakpoint support is turned off, throw
7908 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7909 throw_exception (e
);
7911 exception_print (gdb_stderr
, e
);
7913 /* If pending breakpoint support is auto query and the user
7914 selects no, then simply return the error code. */
7915 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7916 && !nquery (_("Make %s pending on future shared library load? "),
7917 bptype_string (type_wanted
)))
7920 /* At this point, either the user was queried about setting
7921 a pending breakpoint and selected yes, or pending
7922 breakpoint behavior is on and thus a pending breakpoint
7923 is defaulted on behalf of the user. */
7924 copy_arg
= xstrdup (addr_start
);
7925 canonical
.canonical
= ©_arg
;
7927 sals
.sals
= &pending_sal
;
7932 throw_exception (e
);
7942 /* Create a chain of things that always need to be cleaned up. */
7943 old_chain
= make_cleanup (null_cleanup
, 0);
7947 /* Make sure that all storage allocated to SALS gets freed. */
7948 make_cleanup (xfree
, sals
.sals
);
7950 /* Cleanup the canonical array but not its contents. */
7951 make_cleanup (xfree
, canonical
.canonical
);
7954 /* ----------------------------- SNIP -----------------------------
7955 Anything added to the cleanup chain beyond this point is assumed
7956 to be part of a breakpoint. If the breakpoint create succeeds
7957 then the memory is not reclaimed. */
7958 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7960 /* Mark the contents of the canonical for cleanup. These go on
7961 the bkpt_chain and only occur if the breakpoint create fails. */
7962 for (i
= 0; i
< sals
.nelts
; i
++)
7964 if (canonical
.canonical
[i
] != NULL
)
7965 make_cleanup (xfree
, canonical
.canonical
[i
]);
7968 /* Resolve all line numbers to PC's and verify that the addresses
7969 are ok for the target. */
7971 breakpoint_sals_to_pc (&sals
);
7973 /* Fast tracepoints may have additional restrictions on location. */
7974 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
7975 check_fast_tracepoint_sals (gdbarch
, &sals
);
7977 /* Verify that condition can be parsed, before setting any
7978 breakpoints. Allocate a separate condition expression for each
7982 if (parse_condition_and_thread
)
7984 /* Here we only parse 'arg' to separate condition
7985 from thread number, so parsing in context of first
7986 sal is OK. When setting the breakpoint we'll
7987 re-parse it in context of each sal. */
7990 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7993 make_cleanup (xfree
, cond_string
);
7997 /* Create a private copy of condition string. */
8000 cond_string
= xstrdup (cond_string
);
8001 make_cleanup (xfree
, cond_string
);
8005 /* If the user is creating a static tracepoint by marker id
8006 (strace -m MARKER_ID), then store the sals index, so that
8007 breakpoint_re_set can try to match up which of the newly
8008 found markers corresponds to this one, and, don't try to
8009 expand multiple locations for each sal, given than SALS
8010 already should contain all sals for MARKER_ID. */
8011 if (type_wanted
== bp_static_tracepoint
8012 && is_marker_spec (canonical
.canonical
[0]))
8016 for (i
= 0; i
< sals
.nelts
; ++i
)
8018 struct symtabs_and_lines expanded
;
8019 struct tracepoint
*tp
;
8020 struct cleanup
*old_chain
;
8023 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
8024 expanded
.sals
[0] = sals
.sals
[i
];
8025 old_chain
= make_cleanup (xfree
, expanded
.sals
);
8027 tp
= XCNEW (struct tracepoint
);
8028 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
8029 canonical
.canonical
[i
],
8030 cond_string
, type_wanted
,
8031 tempflag
? disp_del
: disp_donttouch
,
8032 thread
, task
, ignore_count
, ops
,
8033 from_tty
, enabled
, internal
,
8034 canonical
.special_display
);
8035 /* Given that its possible to have multiple markers with
8036 the same string id, if the user is creating a static
8037 tracepoint by marker id ("strace -m MARKER_ID"), then
8038 store the sals index, so that breakpoint_re_set can
8039 try to match up which of the newly found markers
8040 corresponds to this one */
8041 tp
->static_trace_marker_id_idx
= i
;
8043 install_breakpoint (internal
, &tp
->base
, 0);
8045 do_cleanups (old_chain
);
8049 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
8051 tempflag
? disp_del
: disp_donttouch
,
8052 thread
, task
, ignore_count
, ops
, from_tty
,
8057 struct breakpoint
*b
;
8059 make_cleanup (xfree
, copy_arg
);
8061 if (is_tracepoint_type (type_wanted
))
8063 struct tracepoint
*t
;
8065 t
= XCNEW (struct tracepoint
);
8069 b
= XNEW (struct breakpoint
);
8071 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
8073 b
->addr_string
= canonical
.canonical
[0];
8074 b
->cond_string
= NULL
;
8075 b
->ignore_count
= ignore_count
;
8076 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8077 b
->condition_not_parsed
= 1;
8078 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8079 b
->pspace
= current_program_space
;
8081 if (enabled
&& b
->pspace
->executing_startup
8082 && (b
->type
== bp_breakpoint
8083 || b
->type
== bp_hardware_breakpoint
))
8084 b
->enable_state
= bp_startup_disabled
;
8086 install_breakpoint (internal
, b
, 0);
8091 warning (_("Multiple breakpoints were set.\nUse the "
8092 "\"delete\" command to delete unwanted breakpoints."));
8093 prev_breakpoint_count
= prev_bkpt_count
;
8096 /* That's it. Discard the cleanups for data inserted into the
8098 discard_cleanups (bkpt_chain
);
8099 /* But cleanup everything else. */
8100 do_cleanups (old_chain
);
8102 /* error call may happen here - have BKPT_CHAIN already discarded. */
8103 update_global_location_list (1);
8108 /* Set a breakpoint.
8109 ARG is a string describing breakpoint address,
8110 condition, and thread.
8111 FLAG specifies if a breakpoint is hardware on,
8112 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8116 break_command_1 (char *arg
, int flag
, int from_tty
)
8118 int tempflag
= flag
& BP_TEMPFLAG
;
8119 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8120 ? bp_hardware_breakpoint
8123 create_breakpoint (get_current_arch (),
8125 NULL
, 0, 1 /* parse arg */,
8126 tempflag
, type_wanted
,
8127 0 /* Ignore count */,
8128 pending_break_support
,
8129 &bkpt_breakpoint_ops
,
8135 /* Helper function for break_command_1 and disassemble_command. */
8138 resolve_sal_pc (struct symtab_and_line
*sal
)
8142 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8144 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8145 error (_("No line %d in file \"%s\"."),
8146 sal
->line
, sal
->symtab
->filename
);
8149 /* If this SAL corresponds to a breakpoint inserted using a line
8150 number, then skip the function prologue if necessary. */
8151 if (sal
->explicit_line
)
8152 skip_prologue_sal (sal
);
8155 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8157 struct blockvector
*bv
;
8161 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8164 sym
= block_linkage_function (b
);
8167 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8168 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8172 /* It really is worthwhile to have the section, so we'll
8173 just have to look harder. This case can be executed
8174 if we have line numbers but no functions (as can
8175 happen in assembly source). */
8177 struct minimal_symbol
*msym
;
8178 struct cleanup
*old_chain
= save_current_space_and_thread ();
8180 switch_to_program_space_and_thread (sal
->pspace
);
8182 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8184 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8186 do_cleanups (old_chain
);
8193 break_command (char *arg
, int from_tty
)
8195 break_command_1 (arg
, 0, from_tty
);
8199 tbreak_command (char *arg
, int from_tty
)
8201 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8205 hbreak_command (char *arg
, int from_tty
)
8207 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8211 thbreak_command (char *arg
, int from_tty
)
8213 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8217 stop_command (char *arg
, int from_tty
)
8219 printf_filtered (_("Specify the type of breakpoint to set.\n\
8220 Usage: stop in <function | address>\n\
8221 stop at <line>\n"));
8225 stopin_command (char *arg
, int from_tty
)
8229 if (arg
== (char *) NULL
)
8231 else if (*arg
!= '*')
8236 /* Look for a ':'. If this is a line number specification, then
8237 say it is bad, otherwise, it should be an address or
8238 function/method name. */
8239 while (*argptr
&& !hasColon
)
8241 hasColon
= (*argptr
== ':');
8246 badInput
= (*argptr
!= ':'); /* Not a class::method */
8248 badInput
= isdigit (*arg
); /* a simple line number */
8252 printf_filtered (_("Usage: stop in <function | address>\n"));
8254 break_command_1 (arg
, 0, from_tty
);
8258 stopat_command (char *arg
, int from_tty
)
8262 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8269 /* Look for a ':'. If there is a '::' then get out, otherwise
8270 it is probably a line number. */
8271 while (*argptr
&& !hasColon
)
8273 hasColon
= (*argptr
== ':');
8278 badInput
= (*argptr
== ':'); /* we have class::method */
8280 badInput
= !isdigit (*arg
); /* not a line number */
8284 printf_filtered (_("Usage: stop at <line>\n"));
8286 break_command_1 (arg
, 0, from_tty
);
8289 /* Implement the "breakpoint_hit" breakpoint_ops method for
8290 ranged breakpoints. */
8293 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8294 struct address_space
*aspace
,
8297 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8298 bl
->length
, aspace
, bp_addr
);
8301 /* Implement the "resources_needed" breakpoint_ops method for
8302 ranged breakpoints. */
8305 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8307 return target_ranged_break_num_registers ();
8310 /* Implement the "print_it" breakpoint_ops method for
8311 ranged breakpoints. */
8313 static enum print_stop_action
8314 print_it_ranged_breakpoint (bpstat bs
)
8316 struct breakpoint
*b
= bs
->breakpoint_at
;
8317 struct bp_location
*bl
= b
->loc
;
8318 struct ui_out
*uiout
= current_uiout
;
8320 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8322 /* Ranged breakpoints have only one location. */
8323 gdb_assert (bl
&& bl
->next
== NULL
);
8325 annotate_breakpoint (b
->number
);
8326 if (b
->disposition
== disp_del
)
8327 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8329 ui_out_text (uiout
, "\nRanged breakpoint ");
8330 if (ui_out_is_mi_like_p (uiout
))
8332 ui_out_field_string (uiout
, "reason",
8333 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8334 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8336 ui_out_field_int (uiout
, "bkptno", b
->number
);
8337 ui_out_text (uiout
, ", ");
8339 return PRINT_SRC_AND_LOC
;
8342 /* Implement the "print_one" breakpoint_ops method for
8343 ranged breakpoints. */
8346 print_one_ranged_breakpoint (struct breakpoint
*b
,
8347 struct bp_location
**last_loc
)
8349 struct bp_location
*bl
= b
->loc
;
8350 struct value_print_options opts
;
8351 struct ui_out
*uiout
= current_uiout
;
8353 /* Ranged breakpoints have only one location. */
8354 gdb_assert (bl
&& bl
->next
== NULL
);
8356 get_user_print_options (&opts
);
8358 if (opts
.addressprint
)
8359 /* We don't print the address range here, it will be printed later
8360 by print_one_detail_ranged_breakpoint. */
8361 ui_out_field_skip (uiout
, "addr");
8363 print_breakpoint_location (b
, bl
);
8367 /* Implement the "print_one_detail" breakpoint_ops method for
8368 ranged breakpoints. */
8371 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8372 struct ui_out
*uiout
)
8374 CORE_ADDR address_start
, address_end
;
8375 struct bp_location
*bl
= b
->loc
;
8376 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8377 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8381 address_start
= bl
->address
;
8382 address_end
= address_start
+ bl
->length
- 1;
8384 ui_out_text (uiout
, "\taddress range: ");
8385 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8386 print_core_address (bl
->gdbarch
, address_start
),
8387 print_core_address (bl
->gdbarch
, address_end
));
8388 ui_out_field_stream (uiout
, "addr", stb
);
8389 ui_out_text (uiout
, "\n");
8391 do_cleanups (cleanup
);
8394 /* Implement the "print_mention" breakpoint_ops method for
8395 ranged breakpoints. */
8398 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8400 struct bp_location
*bl
= b
->loc
;
8401 struct ui_out
*uiout
= current_uiout
;
8404 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8406 if (ui_out_is_mi_like_p (uiout
))
8409 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8410 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8411 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8414 /* Implement the "print_recreate" breakpoint_ops method for
8415 ranged breakpoints. */
8418 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8420 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8421 b
->addr_string_range_end
);
8422 print_recreate_thread (b
, fp
);
8425 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8427 static struct breakpoint_ops ranged_breakpoint_ops
;
8429 /* Find the address where the end of the breakpoint range should be
8430 placed, given the SAL of the end of the range. This is so that if
8431 the user provides a line number, the end of the range is set to the
8432 last instruction of the given line. */
8435 find_breakpoint_range_end (struct symtab_and_line sal
)
8439 /* If the user provided a PC value, use it. Otherwise,
8440 find the address of the end of the given location. */
8441 if (sal
.explicit_pc
)
8448 ret
= find_line_pc_range (sal
, &start
, &end
);
8450 error (_("Could not find location of the end of the range."));
8452 /* find_line_pc_range returns the start of the next line. */
8459 /* Implement the "break-range" CLI command. */
8462 break_range_command (char *arg
, int from_tty
)
8464 char *arg_start
, *addr_string_start
, *addr_string_end
;
8465 struct linespec_result canonical_start
, canonical_end
;
8466 int bp_count
, can_use_bp
, length
;
8468 struct breakpoint
*b
;
8469 struct symtab_and_line sal_start
, sal_end
;
8470 struct symtabs_and_lines sals_start
, sals_end
;
8471 struct cleanup
*cleanup_bkpt
;
8473 /* We don't support software ranged breakpoints. */
8474 if (target_ranged_break_num_registers () < 0)
8475 error (_("This target does not support hardware ranged breakpoints."));
8477 bp_count
= hw_breakpoint_used_count ();
8478 bp_count
+= target_ranged_break_num_registers ();
8479 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8482 error (_("Hardware breakpoints used exceeds limit."));
8484 if (arg
== NULL
|| arg
[0] == '\0')
8485 error(_("No address range specified."));
8487 sals_start
.sals
= NULL
;
8488 sals_start
.nelts
= 0;
8489 init_linespec_result (&canonical_start
);
8491 while (*arg
== ' ' || *arg
== '\t')
8494 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8496 sal_start
= sals_start
.sals
[0];
8497 addr_string_start
= canonical_start
.canonical
[0];
8498 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8499 xfree (sals_start
.sals
);
8500 xfree (canonical_start
.canonical
);
8503 error (_("Too few arguments."));
8504 else if (sals_start
.nelts
== 0)
8505 error (_("Could not find location of the beginning of the range."));
8506 else if (sals_start
.nelts
!= 1)
8507 error (_("Cannot create a ranged breakpoint with multiple locations."));
8509 resolve_sal_pc (&sal_start
);
8511 arg
++; /* Skip the comma. */
8512 while (*arg
== ' ' || *arg
== '\t')
8515 /* Parse the end location. */
8517 sals_end
.sals
= NULL
;
8519 init_linespec_result (&canonical_end
);
8522 /* We call decode_line_1 directly here instead of using
8523 parse_breakpoint_sals because we need to specify the start location's
8524 symtab and line as the default symtab and line for the end of the
8525 range. This makes it possible to have ranges like "foo.c:27, +14",
8526 where +14 means 14 lines from the start location. */
8527 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8530 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8531 if (canonical_end
.canonical
== NULL
)
8532 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8533 /* Add the string if not present. */
8534 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8535 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8537 sal_end
= sals_end
.sals
[0];
8538 addr_string_end
= canonical_end
.canonical
[0];
8539 make_cleanup (xfree
, addr_string_end
);
8540 xfree (sals_end
.sals
);
8541 xfree (canonical_end
.canonical
);
8543 if (sals_end
.nelts
== 0)
8544 error (_("Could not find location of the end of the range."));
8545 else if (sals_end
.nelts
!= 1)
8546 error (_("Cannot create a ranged breakpoint with multiple locations."));
8548 resolve_sal_pc (&sal_end
);
8550 end
= find_breakpoint_range_end (sal_end
);
8551 if (sal_start
.pc
> end
)
8552 error (_("Invalid address range, end precedes start."));
8554 length
= end
- sal_start
.pc
+ 1;
8556 /* Length overflowed. */
8557 error (_("Address range too large."));
8558 else if (length
== 1)
8560 /* This range is simple enough to be handled by
8561 the `hbreak' command. */
8562 hbreak_command (addr_string_start
, 1);
8564 do_cleanups (cleanup_bkpt
);
8569 /* Now set up the breakpoint. */
8570 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8571 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8572 set_breakpoint_count (breakpoint_count
+ 1);
8573 b
->number
= breakpoint_count
;
8574 b
->disposition
= disp_donttouch
;
8575 b
->addr_string
= addr_string_start
;
8576 b
->addr_string_range_end
= addr_string_end
;
8577 b
->loc
->length
= length
;
8579 discard_cleanups (cleanup_bkpt
);
8582 observer_notify_breakpoint_created (b
);
8583 update_global_location_list (1);
8586 /* Return non-zero if EXP is verified as constant. Returned zero
8587 means EXP is variable. Also the constant detection may fail for
8588 some constant expressions and in such case still falsely return
8591 watchpoint_exp_is_const (const struct expression
*exp
)
8599 /* We are only interested in the descriptor of each element. */
8600 operator_length (exp
, i
, &oplenp
, &argsp
);
8603 switch (exp
->elts
[i
].opcode
)
8613 case BINOP_LOGICAL_AND
:
8614 case BINOP_LOGICAL_OR
:
8615 case BINOP_BITWISE_AND
:
8616 case BINOP_BITWISE_IOR
:
8617 case BINOP_BITWISE_XOR
:
8619 case BINOP_NOTEQUAL
:
8635 case TERNOP_SLICE_COUNT
:
8647 case OP_OBJC_NSSTRING
:
8650 case UNOP_LOGICAL_NOT
:
8651 case UNOP_COMPLEMENT
:
8654 /* Unary, binary and ternary operators: We have to check
8655 their operands. If they are constant, then so is the
8656 result of that operation. For instance, if A and B are
8657 determined to be constants, then so is "A + B".
8659 UNOP_IND is one exception to the rule above, because the
8660 value of *ADDR is not necessarily a constant, even when
8665 /* Check whether the associated symbol is a constant.
8667 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8668 possible that a buggy compiler could mark a variable as
8669 constant even when it is not, and TYPE_CONST would return
8670 true in this case, while SYMBOL_CLASS wouldn't.
8672 We also have to check for function symbols because they
8673 are always constant. */
8675 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8677 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8678 && SYMBOL_CLASS (s
) != LOC_CONST
8679 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8684 /* The default action is to return 0 because we are using
8685 the optimistic approach here: If we don't know something,
8686 then it is not a constant. */
8695 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8698 dtor_watchpoint (struct breakpoint
*self
)
8700 struct watchpoint
*w
= (struct watchpoint
*) self
;
8702 xfree (w
->cond_exp
);
8704 xfree (w
->exp_string
);
8705 xfree (w
->exp_string_reparse
);
8706 value_free (w
->val
);
8708 base_breakpoint_ops
.dtor (self
);
8711 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8714 re_set_watchpoint (struct breakpoint
*b
)
8716 struct watchpoint
*w
= (struct watchpoint
*) b
;
8718 /* Watchpoint can be either on expression using entirely global
8719 variables, or it can be on local variables.
8721 Watchpoints of the first kind are never auto-deleted, and even
8722 persist across program restarts. Since they can use variables
8723 from shared libraries, we need to reparse expression as libraries
8724 are loaded and unloaded.
8726 Watchpoints on local variables can also change meaning as result
8727 of solib event. For example, if a watchpoint uses both a local
8728 and a global variables in expression, it's a local watchpoint,
8729 but unloading of a shared library will make the expression
8730 invalid. This is not a very common use case, but we still
8731 re-evaluate expression, to avoid surprises to the user.
8733 Note that for local watchpoints, we re-evaluate it only if
8734 watchpoints frame id is still valid. If it's not, it means the
8735 watchpoint is out of scope and will be deleted soon. In fact,
8736 I'm not sure we'll ever be called in this case.
8738 If a local watchpoint's frame id is still valid, then
8739 w->exp_valid_block is likewise valid, and we can safely use it.
8741 Don't do anything about disabled watchpoints, since they will be
8742 reevaluated again when enabled. */
8743 update_watchpoint (w
, 1 /* reparse */);
8746 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8749 insert_watchpoint (struct bp_location
*bl
)
8751 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8752 int length
= w
->exact
? 1 : bl
->length
;
8754 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8758 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8761 remove_watchpoint (struct bp_location
*bl
)
8763 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8764 int length
= w
->exact
? 1 : bl
->length
;
8766 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8771 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8772 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8774 struct breakpoint
*b
= bl
->owner
;
8775 struct watchpoint
*w
= (struct watchpoint
*) b
;
8777 /* Continuable hardware watchpoints are treated as non-existent if the
8778 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8779 some data address). Otherwise gdb won't stop on a break instruction
8780 in the code (not from a breakpoint) when a hardware watchpoint has
8781 been defined. Also skip watchpoints which we know did not trigger
8782 (did not match the data address). */
8783 if (is_hardware_watchpoint (b
)
8784 && w
->watchpoint_triggered
== watch_triggered_no
)
8791 check_status_watchpoint (bpstat bs
)
8793 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8795 bpstat_check_watchpoint (bs
);
8798 /* Implement the "resources_needed" breakpoint_ops method for
8799 hardware watchpoints. */
8802 resources_needed_watchpoint (const struct bp_location
*bl
)
8804 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8805 int length
= w
->exact
? 1 : bl
->length
;
8807 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8810 /* Implement the "works_in_software_mode" breakpoint_ops method for
8811 hardware watchpoints. */
8814 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8816 /* Read and access watchpoints only work with hardware support. */
8817 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8820 static enum print_stop_action
8821 print_it_watchpoint (bpstat bs
)
8823 struct cleanup
*old_chain
;
8824 struct breakpoint
*b
;
8825 const struct bp_location
*bl
;
8826 struct ui_stream
*stb
;
8827 enum print_stop_action result
;
8828 struct watchpoint
*w
;
8829 struct ui_out
*uiout
= current_uiout
;
8831 gdb_assert (bs
->bp_location_at
!= NULL
);
8833 bl
= bs
->bp_location_at
;
8834 b
= bs
->breakpoint_at
;
8835 w
= (struct watchpoint
*) b
;
8837 stb
= ui_out_stream_new (uiout
);
8838 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8843 case bp_hardware_watchpoint
:
8844 annotate_watchpoint (b
->number
);
8845 if (ui_out_is_mi_like_p (uiout
))
8848 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8850 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8851 ui_out_text (uiout
, "\nOld value = ");
8852 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8853 ui_out_field_stream (uiout
, "old", stb
);
8854 ui_out_text (uiout
, "\nNew value = ");
8855 watchpoint_value_print (w
->val
, stb
->stream
);
8856 ui_out_field_stream (uiout
, "new", stb
);
8857 ui_out_text (uiout
, "\n");
8858 /* More than one watchpoint may have been triggered. */
8859 result
= PRINT_UNKNOWN
;
8862 case bp_read_watchpoint
:
8863 if (ui_out_is_mi_like_p (uiout
))
8866 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8868 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8869 ui_out_text (uiout
, "\nValue = ");
8870 watchpoint_value_print (w
->val
, stb
->stream
);
8871 ui_out_field_stream (uiout
, "value", stb
);
8872 ui_out_text (uiout
, "\n");
8873 result
= PRINT_UNKNOWN
;
8876 case bp_access_watchpoint
:
8877 if (bs
->old_val
!= NULL
)
8879 annotate_watchpoint (b
->number
);
8880 if (ui_out_is_mi_like_p (uiout
))
8883 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8885 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8886 ui_out_text (uiout
, "\nOld value = ");
8887 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8888 ui_out_field_stream (uiout
, "old", stb
);
8889 ui_out_text (uiout
, "\nNew value = ");
8894 if (ui_out_is_mi_like_p (uiout
))
8897 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8898 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8899 ui_out_text (uiout
, "\nValue = ");
8901 watchpoint_value_print (w
->val
, stb
->stream
);
8902 ui_out_field_stream (uiout
, "new", stb
);
8903 ui_out_text (uiout
, "\n");
8904 result
= PRINT_UNKNOWN
;
8907 result
= PRINT_UNKNOWN
;
8910 do_cleanups (old_chain
);
8914 /* Implement the "print_mention" breakpoint_ops method for hardware
8918 print_mention_watchpoint (struct breakpoint
*b
)
8920 struct cleanup
*ui_out_chain
;
8921 struct watchpoint
*w
= (struct watchpoint
*) b
;
8922 struct ui_out
*uiout
= current_uiout
;
8927 ui_out_text (uiout
, "Watchpoint ");
8928 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8930 case bp_hardware_watchpoint
:
8931 ui_out_text (uiout
, "Hardware watchpoint ");
8932 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8934 case bp_read_watchpoint
:
8935 ui_out_text (uiout
, "Hardware read watchpoint ");
8936 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8938 case bp_access_watchpoint
:
8939 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8940 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8943 internal_error (__FILE__
, __LINE__
,
8944 _("Invalid hardware watchpoint type."));
8947 ui_out_field_int (uiout
, "number", b
->number
);
8948 ui_out_text (uiout
, ": ");
8949 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8950 do_cleanups (ui_out_chain
);
8953 /* Implement the "print_recreate" breakpoint_ops method for
8957 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8959 struct watchpoint
*w
= (struct watchpoint
*) b
;
8964 case bp_hardware_watchpoint
:
8965 fprintf_unfiltered (fp
, "watch");
8967 case bp_read_watchpoint
:
8968 fprintf_unfiltered (fp
, "rwatch");
8970 case bp_access_watchpoint
:
8971 fprintf_unfiltered (fp
, "awatch");
8974 internal_error (__FILE__
, __LINE__
,
8975 _("Invalid watchpoint type."));
8978 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8979 print_recreate_thread (b
, fp
);
8982 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8984 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8986 /* Implement the "insert" breakpoint_ops method for
8987 masked hardware watchpoints. */
8990 insert_masked_watchpoint (struct bp_location
*bl
)
8992 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8994 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8995 bl
->watchpoint_type
);
8998 /* Implement the "remove" breakpoint_ops method for
8999 masked hardware watchpoints. */
9002 remove_masked_watchpoint (struct bp_location
*bl
)
9004 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9006 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9007 bl
->watchpoint_type
);
9010 /* Implement the "resources_needed" breakpoint_ops method for
9011 masked hardware watchpoints. */
9014 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
9016 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9018 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
9021 /* Implement the "works_in_software_mode" breakpoint_ops method for
9022 masked hardware watchpoints. */
9025 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
9030 /* Implement the "print_it" breakpoint_ops method for
9031 masked hardware watchpoints. */
9033 static enum print_stop_action
9034 print_it_masked_watchpoint (bpstat bs
)
9036 struct breakpoint
*b
= bs
->breakpoint_at
;
9037 struct ui_out
*uiout
= current_uiout
;
9039 /* Masked watchpoints have only one location. */
9040 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9044 case bp_hardware_watchpoint
:
9045 annotate_watchpoint (b
->number
);
9046 if (ui_out_is_mi_like_p (uiout
))
9049 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9052 case bp_read_watchpoint
:
9053 if (ui_out_is_mi_like_p (uiout
))
9056 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9059 case bp_access_watchpoint
:
9060 if (ui_out_is_mi_like_p (uiout
))
9063 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9066 internal_error (__FILE__
, __LINE__
,
9067 _("Invalid hardware watchpoint type."));
9071 ui_out_text (uiout
, _("\n\
9072 Check the underlying instruction at PC for the memory\n\
9073 address and value which triggered this watchpoint.\n"));
9074 ui_out_text (uiout
, "\n");
9076 /* More than one watchpoint may have been triggered. */
9077 return PRINT_UNKNOWN
;
9080 /* Implement the "print_one_detail" breakpoint_ops method for
9081 masked hardware watchpoints. */
9084 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
9085 struct ui_out
*uiout
)
9087 struct watchpoint
*w
= (struct watchpoint
*) b
;
9089 /* Masked watchpoints have only one location. */
9090 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9092 ui_out_text (uiout
, "\tmask ");
9093 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
9094 ui_out_text (uiout
, "\n");
9097 /* Implement the "print_mention" breakpoint_ops method for
9098 masked hardware watchpoints. */
9101 print_mention_masked_watchpoint (struct breakpoint
*b
)
9103 struct watchpoint
*w
= (struct watchpoint
*) b
;
9104 struct ui_out
*uiout
= current_uiout
;
9105 struct cleanup
*ui_out_chain
;
9109 case bp_hardware_watchpoint
:
9110 ui_out_text (uiout
, "Masked hardware watchpoint ");
9111 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9113 case bp_read_watchpoint
:
9114 ui_out_text (uiout
, "Masked hardware read watchpoint ");
9115 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9117 case bp_access_watchpoint
:
9118 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
9119 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9122 internal_error (__FILE__
, __LINE__
,
9123 _("Invalid hardware watchpoint type."));
9126 ui_out_field_int (uiout
, "number", b
->number
);
9127 ui_out_text (uiout
, ": ");
9128 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9129 do_cleanups (ui_out_chain
);
9132 /* Implement the "print_recreate" breakpoint_ops method for
9133 masked hardware watchpoints. */
9136 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9138 struct watchpoint
*w
= (struct watchpoint
*) b
;
9143 case bp_hardware_watchpoint
:
9144 fprintf_unfiltered (fp
, "watch");
9146 case bp_read_watchpoint
:
9147 fprintf_unfiltered (fp
, "rwatch");
9149 case bp_access_watchpoint
:
9150 fprintf_unfiltered (fp
, "awatch");
9153 internal_error (__FILE__
, __LINE__
,
9154 _("Invalid hardware watchpoint type."));
9157 sprintf_vma (tmp
, w
->hw_wp_mask
);
9158 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
9159 print_recreate_thread (b
, fp
);
9162 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9164 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
9166 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9169 is_masked_watchpoint (const struct breakpoint
*b
)
9171 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
9174 /* accessflag: hw_write: watch write,
9175 hw_read: watch read,
9176 hw_access: watch access (read or write) */
9178 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
9179 int just_location
, int internal
)
9181 volatile struct gdb_exception e
;
9182 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9183 struct expression
*exp
;
9184 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9185 struct value
*val
, *mark
, *result
;
9186 struct frame_info
*frame
;
9187 char *exp_start
= NULL
;
9188 char *exp_end
= NULL
;
9189 char *tok
, *end_tok
;
9191 char *cond_start
= NULL
;
9192 char *cond_end
= NULL
;
9193 enum bptype bp_type
;
9196 /* Flag to indicate whether we are going to use masks for
9197 the hardware watchpoint. */
9200 struct watchpoint
*w
;
9202 /* Make sure that we actually have parameters to parse. */
9203 if (arg
!= NULL
&& arg
[0] != '\0')
9207 /* Look for "parameter value" pairs at the end
9208 of the arguments string. */
9209 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9211 /* Skip whitespace at the end of the argument list. */
9212 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9215 /* Find the beginning of the last token.
9216 This is the value of the parameter. */
9217 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9219 value_start
= tok
+ 1;
9221 /* Skip whitespace. */
9222 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9227 /* Find the beginning of the second to last token.
9228 This is the parameter itself. */
9229 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9232 toklen
= end_tok
- tok
+ 1;
9234 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9236 /* At this point we've found a "thread" token, which means
9237 the user is trying to set a watchpoint that triggers
9238 only in a specific thread. */
9242 error(_("You can specify only one thread."));
9244 /* Extract the thread ID from the next token. */
9245 thread
= strtol (value_start
, &endp
, 0);
9247 /* Check if the user provided a valid numeric value for the
9249 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9250 error (_("Invalid thread ID specification %s."), value_start
);
9252 /* Check if the thread actually exists. */
9253 if (!valid_thread_id (thread
))
9254 error (_("Unknown thread %d."), thread
);
9256 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9258 /* We've found a "mask" token, which means the user wants to
9259 create a hardware watchpoint that is going to have the mask
9261 struct value
*mask_value
, *mark
;
9264 error(_("You can specify only one mask."));
9266 use_mask
= just_location
= 1;
9268 mark
= value_mark ();
9269 mask_value
= parse_to_comma_and_eval (&value_start
);
9270 mask
= value_as_address (mask_value
);
9271 value_free_to_mark (mark
);
9274 /* We didn't recognize what we found. We should stop here. */
9277 /* Truncate the string and get rid of the "parameter value" pair before
9278 the arguments string is parsed by the parse_exp_1 function. */
9283 /* Parse the rest of the arguments. */
9284 innermost_block
= NULL
;
9286 exp
= parse_exp_1 (&arg
, 0, 0);
9288 /* Remove trailing whitespace from the expression before saving it.
9289 This makes the eventual display of the expression string a bit
9291 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9294 /* Checking if the expression is not constant. */
9295 if (watchpoint_exp_is_const (exp
))
9299 len
= exp_end
- exp_start
;
9300 while (len
> 0 && isspace (exp_start
[len
- 1]))
9302 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9305 exp_valid_block
= innermost_block
;
9306 mark
= value_mark ();
9307 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9313 exp_valid_block
= NULL
;
9314 val
= value_addr (result
);
9315 release_value (val
);
9316 value_free_to_mark (mark
);
9320 ret
= target_masked_watch_num_registers (value_as_address (val
),
9323 error (_("This target does not support masked watchpoints."));
9325 error (_("Invalid mask or memory region."));
9328 else if (val
!= NULL
)
9329 release_value (val
);
9331 tok
= skip_spaces (arg
);
9332 end_tok
= skip_to_space (tok
);
9334 toklen
= end_tok
- tok
;
9335 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9337 struct expression
*cond
;
9339 innermost_block
= NULL
;
9340 tok
= cond_start
= end_tok
+ 1;
9341 cond
= parse_exp_1 (&tok
, 0, 0);
9343 /* The watchpoint expression may not be local, but the condition
9344 may still be. E.g.: `watch global if local > 0'. */
9345 cond_exp_valid_block
= innermost_block
;
9351 error (_("Junk at end of command."));
9353 if (accessflag
== hw_read
)
9354 bp_type
= bp_read_watchpoint
;
9355 else if (accessflag
== hw_access
)
9356 bp_type
= bp_access_watchpoint
;
9358 bp_type
= bp_hardware_watchpoint
;
9360 frame
= block_innermost_frame (exp_valid_block
);
9362 /* If the expression is "local", then set up a "watchpoint scope"
9363 breakpoint at the point where we've left the scope of the watchpoint
9364 expression. Create the scope breakpoint before the watchpoint, so
9365 that we will encounter it first in bpstat_stop_status. */
9366 if (exp_valid_block
&& frame
)
9368 if (frame_id_p (frame_unwind_caller_id (frame
)))
9371 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9372 frame_unwind_caller_pc (frame
),
9373 bp_watchpoint_scope
,
9374 &momentary_breakpoint_ops
);
9376 scope_breakpoint
->enable_state
= bp_enabled
;
9378 /* Automatically delete the breakpoint when it hits. */
9379 scope_breakpoint
->disposition
= disp_del
;
9381 /* Only break in the proper frame (help with recursion). */
9382 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9384 /* Set the address at which we will stop. */
9385 scope_breakpoint
->loc
->gdbarch
9386 = frame_unwind_caller_arch (frame
);
9387 scope_breakpoint
->loc
->requested_address
9388 = frame_unwind_caller_pc (frame
);
9389 scope_breakpoint
->loc
->address
9390 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9391 scope_breakpoint
->loc
->requested_address
,
9392 scope_breakpoint
->type
);
9396 /* Now set up the breakpoint. */
9398 w
= XCNEW (struct watchpoint
);
9401 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9402 &masked_watchpoint_breakpoint_ops
);
9404 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9405 &watchpoint_breakpoint_ops
);
9407 b
->disposition
= disp_donttouch
;
9408 b
->pspace
= current_program_space
;
9410 w
->exp_valid_block
= exp_valid_block
;
9411 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9414 struct type
*t
= value_type (val
);
9415 CORE_ADDR addr
= value_as_address (val
);
9418 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9419 name
= type_to_string (t
);
9421 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9422 core_addr_to_string (addr
));
9425 w
->exp_string
= xstrprintf ("-location %.*s",
9426 (int) (exp_end
- exp_start
), exp_start
);
9428 /* The above expression is in C. */
9429 b
->language
= language_c
;
9432 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9436 w
->hw_wp_mask
= mask
;
9445 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9451 w
->watchpoint_frame
= get_frame_id (frame
);
9452 w
->watchpoint_thread
= inferior_ptid
;
9456 w
->watchpoint_frame
= null_frame_id
;
9457 w
->watchpoint_thread
= null_ptid
;
9460 if (scope_breakpoint
!= NULL
)
9462 /* The scope breakpoint is related to the watchpoint. We will
9463 need to act on them together. */
9464 b
->related_breakpoint
= scope_breakpoint
;
9465 scope_breakpoint
->related_breakpoint
= b
;
9469 value_free_to_mark (mark
);
9471 TRY_CATCH (e
, RETURN_MASK_ALL
)
9473 /* Finally update the new watchpoint. This creates the locations
9474 that should be inserted. */
9475 update_watchpoint (w
, 1);
9479 delete_breakpoint (b
);
9480 throw_exception (e
);
9483 install_breakpoint (internal
, b
, 1);
9486 /* Return count of debug registers needed to watch the given expression.
9487 If the watchpoint cannot be handled in hardware return zero. */
9490 can_use_hardware_watchpoint (struct value
*v
)
9492 int found_memory_cnt
= 0;
9493 struct value
*head
= v
;
9495 /* Did the user specifically forbid us to use hardware watchpoints? */
9496 if (!can_use_hw_watchpoints
)
9499 /* Make sure that the value of the expression depends only upon
9500 memory contents, and values computed from them within GDB. If we
9501 find any register references or function calls, we can't use a
9502 hardware watchpoint.
9504 The idea here is that evaluating an expression generates a series
9505 of values, one holding the value of every subexpression. (The
9506 expression a*b+c has five subexpressions: a, b, a*b, c, and
9507 a*b+c.) GDB's values hold almost enough information to establish
9508 the criteria given above --- they identify memory lvalues,
9509 register lvalues, computed values, etcetera. So we can evaluate
9510 the expression, and then scan the chain of values that leaves
9511 behind to decide whether we can detect any possible change to the
9512 expression's final value using only hardware watchpoints.
9514 However, I don't think that the values returned by inferior
9515 function calls are special in any way. So this function may not
9516 notice that an expression involving an inferior function call
9517 can't be watched with hardware watchpoints. FIXME. */
9518 for (; v
; v
= value_next (v
))
9520 if (VALUE_LVAL (v
) == lval_memory
)
9522 if (v
!= head
&& value_lazy (v
))
9523 /* A lazy memory lvalue in the chain is one that GDB never
9524 needed to fetch; we either just used its address (e.g.,
9525 `a' in `a.b') or we never needed it at all (e.g., `a'
9526 in `a,b'). This doesn't apply to HEAD; if that is
9527 lazy then it was not readable, but watch it anyway. */
9531 /* Ahh, memory we actually used! Check if we can cover
9532 it with hardware watchpoints. */
9533 struct type
*vtype
= check_typedef (value_type (v
));
9535 /* We only watch structs and arrays if user asked for it
9536 explicitly, never if they just happen to appear in a
9537 middle of some value chain. */
9539 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9540 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9542 CORE_ADDR vaddr
= value_address (v
);
9546 len
= (target_exact_watchpoints
9547 && is_scalar_type_recursive (vtype
))?
9548 1 : TYPE_LENGTH (value_type (v
));
9550 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9554 found_memory_cnt
+= num_regs
;
9558 else if (VALUE_LVAL (v
) != not_lval
9559 && deprecated_value_modifiable (v
) == 0)
9560 return 0; /* These are values from the history (e.g., $1). */
9561 else if (VALUE_LVAL (v
) == lval_register
)
9562 return 0; /* Cannot watch a register with a HW watchpoint. */
9565 /* The expression itself looks suitable for using a hardware
9566 watchpoint, but give the target machine a chance to reject it. */
9567 return found_memory_cnt
;
9571 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9573 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9576 /* A helper function that looks for an argument at the start of a
9577 string. The argument must also either be at the end of the string,
9578 or be followed by whitespace. Returns 1 if it finds the argument,
9579 0 otherwise. If the argument is found, it updates *STR. */
9582 check_for_argument (char **str
, char *arg
, int arg_len
)
9584 if (strncmp (*str
, arg
, arg_len
) == 0
9585 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9593 /* A helper function that looks for the "-location" argument and then
9594 calls watch_command_1. */
9597 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9599 int just_location
= 0;
9602 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9603 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9605 arg
= skip_spaces (arg
);
9609 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9613 watch_command (char *arg
, int from_tty
)
9615 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9619 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9621 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9625 rwatch_command (char *arg
, int from_tty
)
9627 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9631 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9633 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9637 awatch_command (char *arg
, int from_tty
)
9639 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9643 /* Helper routines for the until_command routine in infcmd.c. Here
9644 because it uses the mechanisms of breakpoints. */
9646 struct until_break_command_continuation_args
9648 struct breakpoint
*breakpoint
;
9649 struct breakpoint
*breakpoint2
;
9653 /* This function is called by fetch_inferior_event via the
9654 cmd_continuation pointer, to complete the until command. It takes
9655 care of cleaning up the temporary breakpoints set up by the until
9658 until_break_command_continuation (void *arg
, int err
)
9660 struct until_break_command_continuation_args
*a
= arg
;
9662 delete_breakpoint (a
->breakpoint
);
9664 delete_breakpoint (a
->breakpoint2
);
9665 delete_longjmp_breakpoint (a
->thread_num
);
9669 until_break_command (char *arg
, int from_tty
, int anywhere
)
9671 struct symtabs_and_lines sals
;
9672 struct symtab_and_line sal
;
9673 struct frame_info
*frame
= get_selected_frame (NULL
);
9674 struct breakpoint
*breakpoint
;
9675 struct breakpoint
*breakpoint2
= NULL
;
9676 struct cleanup
*old_chain
;
9678 struct thread_info
*tp
;
9680 clear_proceed_status ();
9682 /* Set a breakpoint where the user wants it and at return from
9685 if (last_displayed_sal_is_valid ())
9686 sals
= decode_line_1 (&arg
, 1,
9687 get_last_displayed_symtab (),
9688 get_last_displayed_line (),
9691 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9693 if (sals
.nelts
!= 1)
9694 error (_("Couldn't get information on specified line."));
9697 xfree (sals
.sals
); /* malloc'd, so freed. */
9700 error (_("Junk at end of arguments."));
9702 resolve_sal_pc (&sal
);
9705 /* If the user told us to continue until a specified location,
9706 we don't specify a frame at which we need to stop. */
9707 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9708 null_frame_id
, bp_until
);
9710 /* Otherwise, specify the selected frame, because we want to stop
9711 only at the very same frame. */
9712 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9713 get_stack_frame_id (frame
),
9716 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9718 tp
= inferior_thread ();
9721 /* Keep within the current frame, or in frames called by the current
9724 if (frame_id_p (frame_unwind_caller_id (frame
)))
9726 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9727 sal
.pc
= frame_unwind_caller_pc (frame
);
9728 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9730 frame_unwind_caller_id (frame
),
9732 make_cleanup_delete_breakpoint (breakpoint2
);
9734 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9735 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9738 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9740 /* If we are running asynchronously, and proceed call above has
9741 actually managed to start the target, arrange for breakpoints to
9742 be deleted when the target stops. Otherwise, we're already
9743 stopped and delete breakpoints via cleanup chain. */
9745 if (target_can_async_p () && is_running (inferior_ptid
))
9747 struct until_break_command_continuation_args
*args
;
9748 args
= xmalloc (sizeof (*args
));
9750 args
->breakpoint
= breakpoint
;
9751 args
->breakpoint2
= breakpoint2
;
9752 args
->thread_num
= thread
;
9754 discard_cleanups (old_chain
);
9755 add_continuation (inferior_thread (),
9756 until_break_command_continuation
, args
,
9760 do_cleanups (old_chain
);
9763 /* This function attempts to parse an optional "if <cond>" clause
9764 from the arg string. If one is not found, it returns NULL.
9766 Else, it returns a pointer to the condition string. (It does not
9767 attempt to evaluate the string against a particular block.) And,
9768 it updates arg to point to the first character following the parsed
9769 if clause in the arg string. */
9772 ep_parse_optional_if_clause (char **arg
)
9776 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9779 /* Skip the "if" keyword. */
9782 /* Skip any extra leading whitespace, and record the start of the
9783 condition string. */
9784 *arg
= skip_spaces (*arg
);
9787 /* Assume that the condition occupies the remainder of the arg
9789 (*arg
) += strlen (cond_string
);
9794 /* Commands to deal with catching events, such as signals, exceptions,
9795 process start/exit, etc. */
9799 catch_fork_temporary
, catch_vfork_temporary
,
9800 catch_fork_permanent
, catch_vfork_permanent
9805 catch_fork_command_1 (char *arg
, int from_tty
,
9806 struct cmd_list_element
*command
)
9808 struct gdbarch
*gdbarch
= get_current_arch ();
9809 char *cond_string
= NULL
;
9810 catch_fork_kind fork_kind
;
9813 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9814 tempflag
= (fork_kind
== catch_fork_temporary
9815 || fork_kind
== catch_vfork_temporary
);
9819 arg
= skip_spaces (arg
);
9821 /* The allowed syntax is:
9823 catch [v]fork if <cond>
9825 First, check if there's an if clause. */
9826 cond_string
= ep_parse_optional_if_clause (&arg
);
9828 if ((*arg
!= '\0') && !isspace (*arg
))
9829 error (_("Junk at end of arguments."));
9831 /* If this target supports it, create a fork or vfork catchpoint
9832 and enable reporting of such events. */
9835 case catch_fork_temporary
:
9836 case catch_fork_permanent
:
9837 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9838 &catch_fork_breakpoint_ops
);
9840 case catch_vfork_temporary
:
9841 case catch_vfork_permanent
:
9842 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9843 &catch_vfork_breakpoint_ops
);
9846 error (_("unsupported or unknown fork kind; cannot catch it"));
9852 catch_exec_command_1 (char *arg
, int from_tty
,
9853 struct cmd_list_element
*command
)
9855 struct exec_catchpoint
*c
;
9856 struct gdbarch
*gdbarch
= get_current_arch ();
9858 char *cond_string
= NULL
;
9860 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9864 arg
= skip_spaces (arg
);
9866 /* The allowed syntax is:
9868 catch exec if <cond>
9870 First, check if there's an if clause. */
9871 cond_string
= ep_parse_optional_if_clause (&arg
);
9873 if ((*arg
!= '\0') && !isspace (*arg
))
9874 error (_("Junk at end of arguments."));
9876 c
= XNEW (struct exec_catchpoint
);
9877 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9878 &catch_exec_breakpoint_ops
);
9879 c
->exec_pathname
= NULL
;
9881 install_breakpoint (0, &c
->base
, 1);
9884 static enum print_stop_action
9885 print_it_exception_catchpoint (bpstat bs
)
9887 struct ui_out
*uiout
= current_uiout
;
9888 struct breakpoint
*b
= bs
->breakpoint_at
;
9889 int bp_temp
, bp_throw
;
9891 annotate_catchpoint (b
->number
);
9893 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9894 if (b
->loc
->address
!= b
->loc
->requested_address
)
9895 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9898 bp_temp
= b
->disposition
== disp_del
;
9900 bp_temp
? "Temporary catchpoint "
9902 if (!ui_out_is_mi_like_p (uiout
))
9903 ui_out_field_int (uiout
, "bkptno", b
->number
);
9905 bp_throw
? " (exception thrown), "
9906 : " (exception caught), ");
9907 if (ui_out_is_mi_like_p (uiout
))
9909 ui_out_field_string (uiout
, "reason",
9910 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9911 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9912 ui_out_field_int (uiout
, "bkptno", b
->number
);
9914 return PRINT_SRC_AND_LOC
;
9918 print_one_exception_catchpoint (struct breakpoint
*b
,
9919 struct bp_location
**last_loc
)
9921 struct value_print_options opts
;
9922 struct ui_out
*uiout
= current_uiout
;
9924 get_user_print_options (&opts
);
9925 if (opts
.addressprint
)
9928 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9929 ui_out_field_string (uiout
, "addr", "<PENDING>");
9931 ui_out_field_core_addr (uiout
, "addr",
9932 b
->loc
->gdbarch
, b
->loc
->address
);
9937 if (strstr (b
->addr_string
, "throw") != NULL
)
9938 ui_out_field_string (uiout
, "what", "exception throw");
9940 ui_out_field_string (uiout
, "what", "exception catch");
9944 print_mention_exception_catchpoint (struct breakpoint
*b
)
9946 struct ui_out
*uiout
= current_uiout
;
9950 bp_temp
= b
->disposition
== disp_del
;
9951 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9952 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9953 : _("Catchpoint "));
9954 ui_out_field_int (uiout
, "bkptno", b
->number
);
9955 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9959 /* Implement the "print_recreate" breakpoint_ops method for throw and
9960 catch catchpoints. */
9963 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9969 bp_temp
= b
->disposition
== disp_del
;
9970 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9971 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9972 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9973 print_recreate_thread (b
, fp
);
9976 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9979 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9980 enum exception_event_kind ex_event
, int from_tty
)
9982 char *trigger_func_name
;
9984 if (ex_event
== EX_EVENT_CATCH
)
9985 trigger_func_name
= "__cxa_begin_catch";
9987 trigger_func_name
= "__cxa_throw";
9989 create_breakpoint (get_current_arch (),
9990 trigger_func_name
, cond_string
, -1,
9991 0 /* condition and thread are valid. */,
9992 tempflag
, bp_breakpoint
,
9994 AUTO_BOOLEAN_TRUE
/* pending */,
9995 &gnu_v3_exception_catchpoint_ops
, from_tty
,
10002 /* Deal with "catch catch" and "catch throw" commands. */
10005 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
10006 int tempflag
, int from_tty
)
10008 char *cond_string
= NULL
;
10012 arg
= skip_spaces (arg
);
10014 cond_string
= ep_parse_optional_if_clause (&arg
);
10016 if ((*arg
!= '\0') && !isspace (*arg
))
10017 error (_("Junk at end of arguments."));
10019 if (ex_event
!= EX_EVENT_THROW
10020 && ex_event
!= EX_EVENT_CATCH
)
10021 error (_("Unsupported or unknown exception event; cannot catch it"));
10023 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
10026 warning (_("Unsupported with this platform/compiler combination."));
10029 /* Implementation of "catch catch" command. */
10032 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10034 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10036 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
10039 /* Implementation of "catch throw" command. */
10042 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10044 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10046 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
10050 init_ada_exception_breakpoint (struct breakpoint
*b
,
10051 struct gdbarch
*gdbarch
,
10052 struct symtab_and_line sal
,
10054 const struct breakpoint_ops
*ops
,
10060 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10062 loc_gdbarch
= gdbarch
;
10064 describe_other_breakpoints (loc_gdbarch
,
10065 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10066 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10067 version for exception catchpoints, because two catchpoints
10068 used for different exception names will use the same address.
10069 In this case, a "breakpoint ... also set at..." warning is
10070 unproductive. Besides, the warning phrasing is also a bit
10071 inappropriate, we should use the word catchpoint, and tell
10072 the user what type of catchpoint it is. The above is good
10073 enough for now, though. */
10076 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
10078 b
->enable_state
= bp_enabled
;
10079 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10080 b
->addr_string
= addr_string
;
10081 b
->language
= language_ada
;
10084 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10085 filter list, or NULL if no filtering is required. */
10087 catch_syscall_split_args (char *arg
)
10089 VEC(int) *result
= NULL
;
10090 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
10092 while (*arg
!= '\0')
10094 int i
, syscall_number
;
10096 char cur_name
[128];
10099 /* Skip whitespace. */
10100 while (isspace (*arg
))
10103 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
10104 cur_name
[i
] = arg
[i
];
10105 cur_name
[i
] = '\0';
10108 /* Check if the user provided a syscall name or a number. */
10109 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
10110 if (*endptr
== '\0')
10111 get_syscall_by_number (syscall_number
, &s
);
10114 /* We have a name. Let's check if it's valid and convert it
10116 get_syscall_by_name (cur_name
, &s
);
10118 if (s
.number
== UNKNOWN_SYSCALL
)
10119 /* Here we have to issue an error instead of a warning,
10120 because GDB cannot do anything useful if there's no
10121 syscall number to be caught. */
10122 error (_("Unknown syscall name '%s'."), cur_name
);
10125 /* Ok, it's valid. */
10126 VEC_safe_push (int, result
, s
.number
);
10129 discard_cleanups (cleanup
);
10133 /* Implement the "catch syscall" command. */
10136 catch_syscall_command_1 (char *arg
, int from_tty
,
10137 struct cmd_list_element
*command
)
10142 struct gdbarch
*gdbarch
= get_current_arch ();
10144 /* Checking if the feature if supported. */
10145 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
10146 error (_("The feature 'catch syscall' is not supported on \
10147 this architecture yet."));
10149 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10151 arg
= skip_spaces (arg
);
10153 /* We need to do this first "dummy" translation in order
10154 to get the syscall XML file loaded or, most important,
10155 to display a warning to the user if there's no XML file
10156 for his/her architecture. */
10157 get_syscall_by_number (0, &s
);
10159 /* The allowed syntax is:
10161 catch syscall <name | number> [<name | number> ... <name | number>]
10163 Let's check if there's a syscall name. */
10166 filter
= catch_syscall_split_args (arg
);
10170 create_syscall_event_catchpoint (tempflag
, filter
,
10171 &catch_syscall_breakpoint_ops
);
10175 catch_command (char *arg
, int from_tty
)
10177 error (_("Catch requires an event name."));
10182 tcatch_command (char *arg
, int from_tty
)
10184 error (_("Catch requires an event name."));
10187 /* Delete breakpoints by address or line. */
10190 clear_command (char *arg
, int from_tty
)
10192 struct breakpoint
*b
;
10193 VEC(breakpoint_p
) *found
= 0;
10196 struct symtabs_and_lines sals
;
10197 struct symtab_and_line sal
;
10202 sals
= decode_line_spec (arg
, 1);
10207 sals
.sals
= (struct symtab_and_line
*)
10208 xmalloc (sizeof (struct symtab_and_line
));
10209 make_cleanup (xfree
, sals
.sals
);
10210 init_sal (&sal
); /* Initialize to zeroes. */
10212 /* Set sal's line, symtab, pc, and pspace to the values
10213 corresponding to the last call to print_frame_info. If the
10214 codepoint is not valid, this will set all the fields to 0. */
10215 get_last_displayed_sal (&sal
);
10216 if (sal
.symtab
== 0)
10217 error (_("No source file specified."));
10219 sals
.sals
[0] = sal
;
10225 /* We don't call resolve_sal_pc here. That's not as bad as it
10226 seems, because all existing breakpoints typically have both
10227 file/line and pc set. So, if clear is given file/line, we can
10228 match this to existing breakpoint without obtaining pc at all.
10230 We only support clearing given the address explicitly
10231 present in breakpoint table. Say, we've set breakpoint
10232 at file:line. There were several PC values for that file:line,
10233 due to optimization, all in one block.
10235 We've picked one PC value. If "clear" is issued with another
10236 PC corresponding to the same file:line, the breakpoint won't
10237 be cleared. We probably can still clear the breakpoint, but
10238 since the other PC value is never presented to user, user
10239 can only find it by guessing, and it does not seem important
10240 to support that. */
10242 /* For each line spec given, delete bps which correspond to it. Do
10243 it in two passes, solely to preserve the current behavior that
10244 from_tty is forced true if we delete more than one
10248 for (i
= 0; i
< sals
.nelts
; i
++)
10250 /* If exact pc given, clear bpts at that pc.
10251 If line given (pc == 0), clear all bpts on specified line.
10252 If defaulting, clear all bpts on default line
10255 defaulting sal.pc != 0 tests to do
10260 1 0 <can't happen> */
10262 sal
= sals
.sals
[i
];
10264 /* Find all matching breakpoints and add them to 'found'. */
10265 ALL_BREAKPOINTS (b
)
10268 /* Are we going to delete b? */
10269 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10271 struct bp_location
*loc
= b
->loc
;
10272 for (; loc
; loc
= loc
->next
)
10274 int pc_match
= sal
.pc
10275 && (loc
->pspace
== sal
.pspace
)
10276 && (loc
->address
== sal
.pc
)
10277 && (!section_is_overlay (loc
->section
)
10278 || loc
->section
== sal
.section
);
10279 int line_match
= ((default_match
|| (0 == sal
.pc
))
10280 && b
->source_file
!= NULL
10281 && sal
.symtab
!= NULL
10282 && sal
.pspace
== loc
->pspace
10283 && filename_cmp (b
->source_file
,
10284 sal
.symtab
->filename
) == 0
10285 && b
->line_number
== sal
.line
);
10286 if (pc_match
|| line_match
)
10295 VEC_safe_push(breakpoint_p
, found
, b
);
10298 /* Now go thru the 'found' chain and delete them. */
10299 if (VEC_empty(breakpoint_p
, found
))
10302 error (_("No breakpoint at %s."), arg
);
10304 error (_("No breakpoint at this line."));
10307 if (VEC_length(breakpoint_p
, found
) > 1)
10308 from_tty
= 1; /* Always report if deleted more than one. */
10311 if (VEC_length(breakpoint_p
, found
) == 1)
10312 printf_unfiltered (_("Deleted breakpoint "));
10314 printf_unfiltered (_("Deleted breakpoints "));
10316 breakpoints_changed ();
10318 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10321 printf_unfiltered ("%d ", b
->number
);
10322 delete_breakpoint (b
);
10325 putchar_unfiltered ('\n');
10328 /* Delete breakpoint in BS if they are `delete' breakpoints and
10329 all breakpoints that are marked for deletion, whether hit or not.
10330 This is called after any breakpoint is hit, or after errors. */
10333 breakpoint_auto_delete (bpstat bs
)
10335 struct breakpoint
*b
, *b_tmp
;
10337 for (; bs
; bs
= bs
->next
)
10338 if (bs
->breakpoint_at
10339 && bs
->breakpoint_at
->disposition
== disp_del
10341 delete_breakpoint (bs
->breakpoint_at
);
10343 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10345 if (b
->disposition
== disp_del_at_next_stop
)
10346 delete_breakpoint (b
);
10350 /* A comparison function for bp_location AP and BP being interfaced to
10351 qsort. Sort elements primarily by their ADDRESS (no matter what
10352 does breakpoint_address_is_meaningful say for its OWNER),
10353 secondarily by ordering first bp_permanent OWNERed elements and
10354 terciarily just ensuring the array is sorted stable way despite
10355 qsort being an unstable algorithm. */
10358 bp_location_compare (const void *ap
, const void *bp
)
10360 struct bp_location
*a
= *(void **) ap
;
10361 struct bp_location
*b
= *(void **) bp
;
10362 /* A and B come from existing breakpoints having non-NULL OWNER. */
10363 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10364 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10366 if (a
->address
!= b
->address
)
10367 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10369 /* Sort permanent breakpoints first. */
10370 if (a_perm
!= b_perm
)
10371 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10373 /* Make the user-visible order stable across GDB runs. Locations of
10374 the same breakpoint can be sorted in arbitrary order. */
10376 if (a
->owner
->number
!= b
->owner
->number
)
10377 return (a
->owner
->number
> b
->owner
->number
)
10378 - (a
->owner
->number
< b
->owner
->number
);
10380 return (a
> b
) - (a
< b
);
10383 /* Set bp_location_placed_address_before_address_max and
10384 bp_location_shadow_len_after_address_max according to the current
10385 content of the bp_location array. */
10388 bp_location_target_extensions_update (void)
10390 struct bp_location
*bl
, **blp_tmp
;
10392 bp_location_placed_address_before_address_max
= 0;
10393 bp_location_shadow_len_after_address_max
= 0;
10395 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10397 CORE_ADDR start
, end
, addr
;
10399 if (!bp_location_has_shadow (bl
))
10402 start
= bl
->target_info
.placed_address
;
10403 end
= start
+ bl
->target_info
.shadow_len
;
10405 gdb_assert (bl
->address
>= start
);
10406 addr
= bl
->address
- start
;
10407 if (addr
> bp_location_placed_address_before_address_max
)
10408 bp_location_placed_address_before_address_max
= addr
;
10410 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10412 gdb_assert (bl
->address
< end
);
10413 addr
= end
- bl
->address
;
10414 if (addr
> bp_location_shadow_len_after_address_max
)
10415 bp_location_shadow_len_after_address_max
= addr
;
10419 /* Download tracepoint locations if they haven't been. */
10422 download_tracepoint_locations (void)
10424 struct bp_location
*bl
, **blp_tmp
;
10425 struct cleanup
*old_chain
;
10427 if (!target_can_download_tracepoint ())
10430 old_chain
= save_current_space_and_thread ();
10432 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10434 struct tracepoint
*t
;
10436 if (!is_tracepoint (bl
->owner
))
10439 if ((bl
->owner
->type
== bp_fast_tracepoint
10440 ? !may_insert_fast_tracepoints
10441 : !may_insert_tracepoints
))
10444 /* In tracepoint, locations are _never_ duplicated, so
10445 should_be_inserted is equivalent to
10446 unduplicated_should_be_inserted. */
10447 if (!should_be_inserted (bl
) || bl
->inserted
)
10450 switch_to_program_space_and_thread (bl
->pspace
);
10452 target_download_tracepoint (bl
);
10455 t
= (struct tracepoint
*) bl
->owner
;
10456 t
->number_on_target
= bl
->owner
->number
;
10459 do_cleanups (old_chain
);
10462 /* Swap the insertion/duplication state between two locations. */
10465 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10467 const int left_inserted
= left
->inserted
;
10468 const int left_duplicate
= left
->duplicate
;
10469 const struct bp_target_info left_target_info
= left
->target_info
;
10471 /* Locations of tracepoints can never be duplicated. */
10472 if (is_tracepoint (left
->owner
))
10473 gdb_assert (!left
->duplicate
);
10474 if (is_tracepoint (right
->owner
))
10475 gdb_assert (!right
->duplicate
);
10477 left
->inserted
= right
->inserted
;
10478 left
->duplicate
= right
->duplicate
;
10479 left
->target_info
= right
->target_info
;
10480 right
->inserted
= left_inserted
;
10481 right
->duplicate
= left_duplicate
;
10482 right
->target_info
= left_target_info
;
10485 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10486 into the inferior, only remove already-inserted locations that no
10487 longer should be inserted. Functions that delete a breakpoint or
10488 breakpoints should pass false, so that deleting a breakpoint
10489 doesn't have the side effect of inserting the locations of other
10490 breakpoints that are marked not-inserted, but should_be_inserted
10491 returns true on them.
10493 This behaviour is useful is situations close to tear-down -- e.g.,
10494 after an exec, while the target still has execution, but breakpoint
10495 shadows of the previous executable image should *NOT* be restored
10496 to the new image; or before detaching, where the target still has
10497 execution and wants to delete breakpoints from GDB's lists, and all
10498 breakpoints had already been removed from the inferior. */
10501 update_global_location_list (int should_insert
)
10503 struct breakpoint
*b
;
10504 struct bp_location
**locp
, *loc
;
10505 struct cleanup
*cleanups
;
10507 /* Used in the duplicates detection below. When iterating over all
10508 bp_locations, points to the first bp_location of a given address.
10509 Breakpoints and watchpoints of different types are never
10510 duplicates of each other. Keep one pointer for each type of
10511 breakpoint/watchpoint, so we only need to loop over all locations
10513 struct bp_location
*bp_loc_first
; /* breakpoint */
10514 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10515 struct bp_location
*awp_loc_first
; /* access watchpoint */
10516 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10518 /* Saved former bp_location array which we compare against the newly
10519 built bp_location from the current state of ALL_BREAKPOINTS. */
10520 struct bp_location
**old_location
, **old_locp
;
10521 unsigned old_location_count
;
10523 old_location
= bp_location
;
10524 old_location_count
= bp_location_count
;
10525 bp_location
= NULL
;
10526 bp_location_count
= 0;
10527 cleanups
= make_cleanup (xfree
, old_location
);
10529 ALL_BREAKPOINTS (b
)
10530 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10531 bp_location_count
++;
10533 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10534 locp
= bp_location
;
10535 ALL_BREAKPOINTS (b
)
10536 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10538 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10539 bp_location_compare
);
10541 bp_location_target_extensions_update ();
10543 /* Identify bp_location instances that are no longer present in the
10544 new list, and therefore should be freed. Note that it's not
10545 necessary that those locations should be removed from inferior --
10546 if there's another location at the same address (previously
10547 marked as duplicate), we don't need to remove/insert the
10550 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10551 and former bp_location array state respectively. */
10553 locp
= bp_location
;
10554 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10557 struct bp_location
*old_loc
= *old_locp
;
10558 struct bp_location
**loc2p
;
10560 /* Tells if 'old_loc' is found among the new locations. If
10561 not, we have to free it. */
10562 int found_object
= 0;
10563 /* Tells if the location should remain inserted in the target. */
10564 int keep_in_target
= 0;
10567 /* Skip LOCP entries which will definitely never be needed.
10568 Stop either at or being the one matching OLD_LOC. */
10569 while (locp
< bp_location
+ bp_location_count
10570 && (*locp
)->address
< old_loc
->address
)
10574 (loc2p
< bp_location
+ bp_location_count
10575 && (*loc2p
)->address
== old_loc
->address
);
10578 if (*loc2p
== old_loc
)
10585 /* If this location is no longer present, and inserted, look if
10586 there's maybe a new location at the same address. If so,
10587 mark that one inserted, and don't remove this one. This is
10588 needed so that we don't have a time window where a breakpoint
10589 at certain location is not inserted. */
10591 if (old_loc
->inserted
)
10593 /* If the location is inserted now, we might have to remove
10596 if (found_object
&& should_be_inserted (old_loc
))
10598 /* The location is still present in the location list,
10599 and still should be inserted. Don't do anything. */
10600 keep_in_target
= 1;
10604 /* The location is either no longer present, or got
10605 disabled. See if there's another location at the
10606 same address, in which case we don't need to remove
10607 this one from the target. */
10609 /* OLD_LOC comes from existing struct breakpoint. */
10610 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10613 (loc2p
< bp_location
+ bp_location_count
10614 && (*loc2p
)->address
== old_loc
->address
);
10617 struct bp_location
*loc2
= *loc2p
;
10619 if (breakpoint_locations_match (loc2
, old_loc
))
10621 /* Read watchpoint locations are switched to
10622 access watchpoints, if the former are not
10623 supported, but the latter are. */
10624 if (is_hardware_watchpoint (old_loc
->owner
))
10626 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10627 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10630 /* loc2 is a duplicated location. We need to check
10631 if it should be inserted in case it will be
10633 if (loc2
!= old_loc
10634 && unduplicated_should_be_inserted (loc2
))
10636 swap_insertion (old_loc
, loc2
);
10637 keep_in_target
= 1;
10645 if (!keep_in_target
)
10647 if (remove_breakpoint (old_loc
, mark_uninserted
))
10649 /* This is just about all we can do. We could keep
10650 this location on the global list, and try to
10651 remove it next time, but there's no particular
10652 reason why we will succeed next time.
10654 Note that at this point, old_loc->owner is still
10655 valid, as delete_breakpoint frees the breakpoint
10656 only after calling us. */
10657 printf_filtered (_("warning: Error removing "
10658 "breakpoint %d\n"),
10659 old_loc
->owner
->number
);
10667 if (removed
&& non_stop
10668 && breakpoint_address_is_meaningful (old_loc
->owner
)
10669 && !is_hardware_watchpoint (old_loc
->owner
))
10671 /* This location was removed from the target. In
10672 non-stop mode, a race condition is possible where
10673 we've removed a breakpoint, but stop events for that
10674 breakpoint are already queued and will arrive later.
10675 We apply an heuristic to be able to distinguish such
10676 SIGTRAPs from other random SIGTRAPs: we keep this
10677 breakpoint location for a bit, and will retire it
10678 after we see some number of events. The theory here
10679 is that reporting of events should, "on the average",
10680 be fair, so after a while we'll see events from all
10681 threads that have anything of interest, and no longer
10682 need to keep this breakpoint location around. We
10683 don't hold locations forever so to reduce chances of
10684 mistaking a non-breakpoint SIGTRAP for a breakpoint
10687 The heuristic failing can be disastrous on
10688 decr_pc_after_break targets.
10690 On decr_pc_after_break targets, like e.g., x86-linux,
10691 if we fail to recognize a late breakpoint SIGTRAP,
10692 because events_till_retirement has reached 0 too
10693 soon, we'll fail to do the PC adjustment, and report
10694 a random SIGTRAP to the user. When the user resumes
10695 the inferior, it will most likely immediately crash
10696 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10697 corrupted, because of being resumed e.g., in the
10698 middle of a multi-byte instruction, or skipped a
10699 one-byte instruction. This was actually seen happen
10700 on native x86-linux, and should be less rare on
10701 targets that do not support new thread events, like
10702 remote, due to the heuristic depending on
10705 Mistaking a random SIGTRAP for a breakpoint trap
10706 causes similar symptoms (PC adjustment applied when
10707 it shouldn't), but then again, playing with SIGTRAPs
10708 behind the debugger's back is asking for trouble.
10710 Since hardware watchpoint traps are always
10711 distinguishable from other traps, so we don't need to
10712 apply keep hardware watchpoint moribund locations
10713 around. We simply always ignore hardware watchpoint
10714 traps we can no longer explain. */
10716 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10717 old_loc
->owner
= NULL
;
10719 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10723 old_loc
->owner
= NULL
;
10724 decref_bp_location (&old_loc
);
10729 /* Rescan breakpoints at the same address and section, marking the
10730 first one as "first" and any others as "duplicates". This is so
10731 that the bpt instruction is only inserted once. If we have a
10732 permanent breakpoint at the same place as BPT, make that one the
10733 official one, and the rest as duplicates. Permanent breakpoints
10734 are sorted first for the same address.
10736 Do the same for hardware watchpoints, but also considering the
10737 watchpoint's type (regular/access/read) and length. */
10739 bp_loc_first
= NULL
;
10740 wp_loc_first
= NULL
;
10741 awp_loc_first
= NULL
;
10742 rwp_loc_first
= NULL
;
10743 ALL_BP_LOCATIONS (loc
, locp
)
10745 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10747 struct breakpoint
*b
= loc
->owner
;
10748 struct bp_location
**loc_first_p
;
10750 if (b
->enable_state
== bp_disabled
10751 || b
->enable_state
== bp_call_disabled
10752 || b
->enable_state
== bp_startup_disabled
10754 || loc
->shlib_disabled
10755 || !breakpoint_address_is_meaningful (b
)
10756 /* Don't detect duplicate for tracepoint locations because they are
10757 never duplicated. See the comments in field `duplicate' of
10758 `struct bp_location'. */
10759 || is_tracepoint (b
))
10762 /* Permanent breakpoint should always be inserted. */
10763 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10764 internal_error (__FILE__
, __LINE__
,
10765 _("allegedly permanent breakpoint is not "
10766 "actually inserted"));
10768 if (b
->type
== bp_hardware_watchpoint
)
10769 loc_first_p
= &wp_loc_first
;
10770 else if (b
->type
== bp_read_watchpoint
)
10771 loc_first_p
= &rwp_loc_first
;
10772 else if (b
->type
== bp_access_watchpoint
)
10773 loc_first_p
= &awp_loc_first
;
10775 loc_first_p
= &bp_loc_first
;
10777 if (*loc_first_p
== NULL
10778 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10779 || !breakpoint_locations_match (loc
, *loc_first_p
))
10781 *loc_first_p
= loc
;
10782 loc
->duplicate
= 0;
10787 /* This and the above ensure the invariant that the first location
10788 is not duplicated, and is the inserted one.
10789 All following are marked as duplicated, and are not inserted. */
10791 swap_insertion (loc
, *loc_first_p
);
10792 loc
->duplicate
= 1;
10794 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10795 && b
->enable_state
!= bp_permanent
)
10796 internal_error (__FILE__
, __LINE__
,
10797 _("another breakpoint was inserted on top of "
10798 "a permanent breakpoint"));
10801 if (breakpoints_always_inserted_mode () && should_insert
10802 && (have_live_inferiors ()
10803 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10804 insert_breakpoint_locations ();
10807 download_tracepoint_locations ();
10809 do_cleanups (cleanups
);
10813 breakpoint_retire_moribund (void)
10815 struct bp_location
*loc
;
10818 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10819 if (--(loc
->events_till_retirement
) == 0)
10821 decref_bp_location (&loc
);
10822 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10828 update_global_location_list_nothrow (int inserting
)
10830 struct gdb_exception e
;
10832 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10833 update_global_location_list (inserting
);
10836 /* Clear BKP from a BPS. */
10839 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10843 for (bs
= bps
; bs
; bs
= bs
->next
)
10844 if (bs
->breakpoint_at
== bpt
)
10846 bs
->breakpoint_at
= NULL
;
10847 bs
->old_val
= NULL
;
10848 /* bs->commands will be freed later. */
10852 /* Callback for iterate_over_threads. */
10854 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10856 struct breakpoint
*bpt
= data
;
10858 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10862 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10866 say_where (struct breakpoint
*b
)
10868 struct ui_out
*uiout
= current_uiout
;
10869 struct value_print_options opts
;
10871 get_user_print_options (&opts
);
10873 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10875 if (b
->loc
== NULL
)
10877 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10881 if (opts
.addressprint
|| b
->source_file
== NULL
)
10883 printf_filtered (" at ");
10884 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10887 if (b
->source_file
)
10888 printf_filtered (": file %s, line %d.",
10889 b
->source_file
, b
->line_number
);
10893 struct bp_location
*loc
= b
->loc
;
10895 for (; loc
; loc
= loc
->next
)
10897 printf_filtered (" (%d locations)", n
);
10902 /* Default bp_location_ops methods. */
10905 bp_location_dtor (struct bp_location
*self
)
10907 xfree (self
->cond
);
10908 xfree (self
->function_name
);
10911 static const struct bp_location_ops bp_location_ops
=
10916 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10920 base_breakpoint_dtor (struct breakpoint
*self
)
10922 decref_counted_command_line (&self
->commands
);
10923 xfree (self
->cond_string
);
10924 xfree (self
->addr_string
);
10925 xfree (self
->addr_string_range_end
);
10926 xfree (self
->source_file
);
10929 static struct bp_location
*
10930 base_breakpoint_allocate_location (struct breakpoint
*self
)
10932 struct bp_location
*loc
;
10934 loc
= XNEW (struct bp_location
);
10935 init_bp_location (loc
, &bp_location_ops
, self
);
10940 base_breakpoint_re_set (struct breakpoint
*b
)
10942 /* Nothing to re-set. */
10945 #define internal_error_pure_virtual_called() \
10946 gdb_assert_not_reached ("pure virtual function called")
10949 base_breakpoint_insert_location (struct bp_location
*bl
)
10951 internal_error_pure_virtual_called ();
10955 base_breakpoint_remove_location (struct bp_location
*bl
)
10957 internal_error_pure_virtual_called ();
10961 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10962 struct address_space
*aspace
,
10965 internal_error_pure_virtual_called ();
10969 base_breakpoint_check_status (bpstat bs
)
10974 /* A "works_in_software_mode" breakpoint_ops method that just internal
10978 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10980 internal_error_pure_virtual_called ();
10983 /* A "resources_needed" breakpoint_ops method that just internal
10987 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10989 internal_error_pure_virtual_called ();
10992 static enum print_stop_action
10993 base_breakpoint_print_it (bpstat bs
)
10995 internal_error_pure_virtual_called ();
10999 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
11000 struct ui_out
*uiout
)
11006 base_breakpoint_print_mention (struct breakpoint
*b
)
11008 internal_error_pure_virtual_called ();
11012 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
11014 internal_error_pure_virtual_called ();
11017 static struct breakpoint_ops base_breakpoint_ops
=
11019 base_breakpoint_dtor
,
11020 base_breakpoint_allocate_location
,
11021 base_breakpoint_re_set
,
11022 base_breakpoint_insert_location
,
11023 base_breakpoint_remove_location
,
11024 base_breakpoint_breakpoint_hit
,
11025 base_breakpoint_check_status
,
11026 base_breakpoint_resources_needed
,
11027 base_breakpoint_works_in_software_mode
,
11028 base_breakpoint_print_it
,
11030 base_breakpoint_print_one_detail
,
11031 base_breakpoint_print_mention
,
11032 base_breakpoint_print_recreate
11035 /* Default breakpoint_ops methods. */
11038 bkpt_re_set (struct breakpoint
*b
)
11040 /* Do not attempt to re-set breakpoints disabled during startup. */
11041 if (b
->enable_state
== bp_startup_disabled
)
11044 /* FIXME: is this still reachable? */
11045 if (b
->addr_string
== NULL
)
11047 /* Anything without a string can't be re-set. */
11048 delete_breakpoint (b
);
11052 breakpoint_re_set_default (b
);
11056 bkpt_insert_location (struct bp_location
*bl
)
11058 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11059 return target_insert_hw_breakpoint (bl
->gdbarch
,
11062 return target_insert_breakpoint (bl
->gdbarch
,
11067 bkpt_remove_location (struct bp_location
*bl
)
11069 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11070 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11072 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11076 bkpt_breakpoint_hit (const struct bp_location
*bl
,
11077 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11079 struct breakpoint
*b
= bl
->owner
;
11081 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11085 if (overlay_debugging
/* unmapped overlay section */
11086 && section_is_overlay (bl
->section
)
11087 && !section_is_mapped (bl
->section
))
11094 bkpt_resources_needed (const struct bp_location
*bl
)
11096 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
11101 static enum print_stop_action
11102 bkpt_print_it (bpstat bs
)
11104 struct breakpoint
*b
;
11105 const struct bp_location
*bl
;
11107 struct ui_out
*uiout
= current_uiout
;
11109 gdb_assert (bs
->bp_location_at
!= NULL
);
11111 bl
= bs
->bp_location_at
;
11112 b
= bs
->breakpoint_at
;
11114 bp_temp
= b
->disposition
== disp_del
;
11115 if (bl
->address
!= bl
->requested_address
)
11116 breakpoint_adjustment_warning (bl
->requested_address
,
11119 annotate_breakpoint (b
->number
);
11121 ui_out_text (uiout
, "\nTemporary breakpoint ");
11123 ui_out_text (uiout
, "\nBreakpoint ");
11124 if (ui_out_is_mi_like_p (uiout
))
11126 ui_out_field_string (uiout
, "reason",
11127 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11128 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11130 ui_out_field_int (uiout
, "bkptno", b
->number
);
11131 ui_out_text (uiout
, ", ");
11133 return PRINT_SRC_AND_LOC
;
11137 bkpt_print_mention (struct breakpoint
*b
)
11139 if (ui_out_is_mi_like_p (current_uiout
))
11144 case bp_breakpoint
:
11145 case bp_gnu_ifunc_resolver
:
11146 if (b
->disposition
== disp_del
)
11147 printf_filtered (_("Temporary breakpoint"));
11149 printf_filtered (_("Breakpoint"));
11150 printf_filtered (_(" %d"), b
->number
);
11151 if (b
->type
== bp_gnu_ifunc_resolver
)
11152 printf_filtered (_(" at gnu-indirect-function resolver"));
11154 case bp_hardware_breakpoint
:
11155 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
11163 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11165 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11166 fprintf_unfiltered (fp
, "tbreak");
11167 else if (tp
->type
== bp_breakpoint
)
11168 fprintf_unfiltered (fp
, "break");
11169 else if (tp
->type
== bp_hardware_breakpoint
11170 && tp
->disposition
== disp_del
)
11171 fprintf_unfiltered (fp
, "thbreak");
11172 else if (tp
->type
== bp_hardware_breakpoint
)
11173 fprintf_unfiltered (fp
, "hbreak");
11175 internal_error (__FILE__
, __LINE__
,
11176 _("unhandled breakpoint type %d"), (int) tp
->type
);
11178 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11179 print_recreate_thread (tp
, fp
);
11182 /* Virtual table for internal breakpoints. */
11185 internal_bkpt_re_set (struct breakpoint
*b
)
11189 /* Delete overlay event and longjmp master breakpoints; they
11190 will be reset later by breakpoint_re_set. */
11191 case bp_overlay_event
:
11192 case bp_longjmp_master
:
11193 case bp_std_terminate_master
:
11194 case bp_exception_master
:
11195 delete_breakpoint (b
);
11198 /* This breakpoint is special, it's set up when the inferior
11199 starts and we really don't want to touch it. */
11200 case bp_shlib_event
:
11202 /* Like bp_shlib_event, this breakpoint type is special. Once
11203 it is set up, we do not want to touch it. */
11204 case bp_thread_event
:
11210 internal_bkpt_check_status (bpstat bs
)
11212 /* We do not stop for these. */
11216 static enum print_stop_action
11217 internal_bkpt_print_it (bpstat bs
)
11219 struct ui_out
*uiout
= current_uiout
;
11220 struct breakpoint
*b
;
11222 b
= bs
->breakpoint_at
;
11226 case bp_shlib_event
:
11227 /* Did we stop because the user set the stop_on_solib_events
11228 variable? (If so, we report this as a generic, "Stopped due
11229 to shlib event" message.) */
11230 ui_out_text (uiout
, _("Stopped due to shared library event\n"));
11231 if (ui_out_is_mi_like_p (uiout
))
11232 ui_out_field_string (uiout
, "reason",
11233 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
11236 case bp_thread_event
:
11237 /* Not sure how we will get here.
11238 GDB should not stop for these breakpoints. */
11239 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11242 case bp_overlay_event
:
11243 /* By analogy with the thread event, GDB should not stop for these. */
11244 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11247 case bp_longjmp_master
:
11248 /* These should never be enabled. */
11249 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11252 case bp_std_terminate_master
:
11253 /* These should never be enabled. */
11254 printf_filtered (_("std::terminate Master Breakpoint: "
11255 "gdb should not stop!\n"));
11258 case bp_exception_master
:
11259 /* These should never be enabled. */
11260 printf_filtered (_("Exception Master Breakpoint: "
11261 "gdb should not stop!\n"));
11265 return PRINT_NOTHING
;
11269 internal_bkpt_print_mention (struct breakpoint
*b
)
11271 /* Nothing to mention. These breakpoints are internal. */
11274 /* Virtual table for momentary breakpoints */
11277 momentary_bkpt_re_set (struct breakpoint
*b
)
11279 /* Keep temporary breakpoints, which can be encountered when we step
11280 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11281 Otherwise these should have been blown away via the cleanup chain
11282 or by breakpoint_init_inferior when we rerun the executable. */
11286 momentary_bkpt_check_status (bpstat bs
)
11288 /* Nothing. The point of these breakpoints is causing a stop. */
11291 static enum print_stop_action
11292 momentary_bkpt_print_it (bpstat bs
)
11294 struct ui_out
*uiout
= current_uiout
;
11296 if (ui_out_is_mi_like_p (uiout
))
11298 struct breakpoint
*b
= bs
->breakpoint_at
;
11303 ui_out_field_string
11305 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11309 ui_out_field_string
11311 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11316 return PRINT_UNKNOWN
;
11320 momentary_bkpt_print_mention (struct breakpoint
*b
)
11322 /* Nothing to mention. These breakpoints are internal. */
11325 /* The breakpoint_ops structure to be used in tracepoints. */
11328 tracepoint_re_set (struct breakpoint
*b
)
11330 breakpoint_re_set_default (b
);
11334 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11335 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11337 /* By definition, the inferior does not report stops at
11343 tracepoint_print_one_detail (const struct breakpoint
*self
,
11344 struct ui_out
*uiout
)
11346 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11347 if (tp
->static_trace_marker_id
)
11349 gdb_assert (self
->type
== bp_static_tracepoint
);
11351 ui_out_text (uiout
, "\tmarker id is ");
11352 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11353 tp
->static_trace_marker_id
);
11354 ui_out_text (uiout
, "\n");
11359 tracepoint_print_mention (struct breakpoint
*b
)
11361 if (ui_out_is_mi_like_p (current_uiout
))
11366 case bp_tracepoint
:
11367 printf_filtered (_("Tracepoint"));
11368 printf_filtered (_(" %d"), b
->number
);
11370 case bp_fast_tracepoint
:
11371 printf_filtered (_("Fast tracepoint"));
11372 printf_filtered (_(" %d"), b
->number
);
11374 case bp_static_tracepoint
:
11375 printf_filtered (_("Static tracepoint"));
11376 printf_filtered (_(" %d"), b
->number
);
11379 internal_error (__FILE__
, __LINE__
,
11380 _("unhandled tracepoint type %d"), (int) b
->type
);
11387 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11389 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11391 if (self
->type
== bp_fast_tracepoint
)
11392 fprintf_unfiltered (fp
, "ftrace");
11393 if (self
->type
== bp_static_tracepoint
)
11394 fprintf_unfiltered (fp
, "strace");
11395 else if (self
->type
== bp_tracepoint
)
11396 fprintf_unfiltered (fp
, "trace");
11398 internal_error (__FILE__
, __LINE__
,
11399 _("unhandled tracepoint type %d"), (int) self
->type
);
11401 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11402 print_recreate_thread (self
, fp
);
11404 if (tp
->pass_count
)
11405 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11408 struct breakpoint_ops tracepoint_breakpoint_ops
;
11410 /* Delete a breakpoint and clean up all traces of it in the data
11414 delete_breakpoint (struct breakpoint
*bpt
)
11416 struct breakpoint
*b
;
11418 gdb_assert (bpt
!= NULL
);
11420 /* Has this bp already been deleted? This can happen because
11421 multiple lists can hold pointers to bp's. bpstat lists are
11424 One example of this happening is a watchpoint's scope bp. When
11425 the scope bp triggers, we notice that the watchpoint is out of
11426 scope, and delete it. We also delete its scope bp. But the
11427 scope bp is marked "auto-deleting", and is already on a bpstat.
11428 That bpstat is then checked for auto-deleting bp's, which are
11431 A real solution to this problem might involve reference counts in
11432 bp's, and/or giving them pointers back to their referencing
11433 bpstat's, and teaching delete_breakpoint to only free a bp's
11434 storage when no more references were extent. A cheaper bandaid
11436 if (bpt
->type
== bp_none
)
11439 /* At least avoid this stale reference until the reference counting
11440 of breakpoints gets resolved. */
11441 if (bpt
->related_breakpoint
!= bpt
)
11443 struct breakpoint
*related
;
11444 struct watchpoint
*w
;
11446 if (bpt
->type
== bp_watchpoint_scope
)
11447 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11448 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11449 w
= (struct watchpoint
*) bpt
;
11453 watchpoint_del_at_next_stop (w
);
11455 /* Unlink bpt from the bpt->related_breakpoint ring. */
11456 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11457 related
= related
->related_breakpoint
);
11458 related
->related_breakpoint
= bpt
->related_breakpoint
;
11459 bpt
->related_breakpoint
= bpt
;
11462 /* watch_command_1 creates a watchpoint but only sets its number if
11463 update_watchpoint succeeds in creating its bp_locations. If there's
11464 a problem in that process, we'll be asked to delete the half-created
11465 watchpoint. In that case, don't announce the deletion. */
11467 observer_notify_breakpoint_deleted (bpt
);
11469 if (breakpoint_chain
== bpt
)
11470 breakpoint_chain
= bpt
->next
;
11472 ALL_BREAKPOINTS (b
)
11473 if (b
->next
== bpt
)
11475 b
->next
= bpt
->next
;
11479 /* Be sure no bpstat's are pointing at the breakpoint after it's
11481 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11482 in all threads for now. Note that we cannot just remove bpstats
11483 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11484 commands are associated with the bpstat; if we remove it here,
11485 then the later call to bpstat_do_actions (&stop_bpstat); in
11486 event-top.c won't do anything, and temporary breakpoints with
11487 commands won't work. */
11489 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11491 /* Now that breakpoint is removed from breakpoint list, update the
11492 global location list. This will remove locations that used to
11493 belong to this breakpoint. Do this before freeing the breakpoint
11494 itself, since remove_breakpoint looks at location's owner. It
11495 might be better design to have location completely
11496 self-contained, but it's not the case now. */
11497 update_global_location_list (0);
11499 bpt
->ops
->dtor (bpt
);
11500 /* On the chance that someone will soon try again to delete this
11501 same bp, we mark it as deleted before freeing its storage. */
11502 bpt
->type
= bp_none
;
11507 do_delete_breakpoint_cleanup (void *b
)
11509 delete_breakpoint (b
);
11513 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11515 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11518 /* Iterator function to call a user-provided callback function once
11519 for each of B and its related breakpoints. */
11522 iterate_over_related_breakpoints (struct breakpoint
*b
,
11523 void (*function
) (struct breakpoint
*,
11527 struct breakpoint
*related
;
11532 struct breakpoint
*next
;
11534 /* FUNCTION may delete RELATED. */
11535 next
= related
->related_breakpoint
;
11537 if (next
== related
)
11539 /* RELATED is the last ring entry. */
11540 function (related
, data
);
11542 /* FUNCTION may have deleted it, so we'd never reach back to
11543 B. There's nothing left to do anyway, so just break
11548 function (related
, data
);
11552 while (related
!= b
);
11556 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11558 delete_breakpoint (b
);
11561 /* A callback for map_breakpoint_numbers that calls
11562 delete_breakpoint. */
11565 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11567 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11571 delete_command (char *arg
, int from_tty
)
11573 struct breakpoint
*b
, *b_tmp
;
11579 int breaks_to_delete
= 0;
11581 /* Delete all breakpoints if no argument. Do not delete
11582 internal breakpoints, these have to be deleted with an
11583 explicit breakpoint number argument. */
11584 ALL_BREAKPOINTS (b
)
11585 if (user_breakpoint_p (b
))
11587 breaks_to_delete
= 1;
11591 /* Ask user only if there are some breakpoints to delete. */
11593 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11595 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11596 if (user_breakpoint_p (b
))
11597 delete_breakpoint (b
);
11601 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11605 all_locations_are_pending (struct bp_location
*loc
)
11607 for (; loc
; loc
= loc
->next
)
11608 if (!loc
->shlib_disabled
)
11613 /* Subroutine of update_breakpoint_locations to simplify it.
11614 Return non-zero if multiple fns in list LOC have the same name.
11615 Null names are ignored. */
11618 ambiguous_names_p (struct bp_location
*loc
)
11620 struct bp_location
*l
;
11621 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11622 (int (*) (const void *,
11623 const void *)) streq
,
11624 NULL
, xcalloc
, xfree
);
11626 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11629 const char *name
= l
->function_name
;
11631 /* Allow for some names to be NULL, ignore them. */
11635 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11637 /* NOTE: We can assume slot != NULL here because xcalloc never
11641 htab_delete (htab
);
11647 htab_delete (htab
);
11651 /* When symbols change, it probably means the sources changed as well,
11652 and it might mean the static tracepoint markers are no longer at
11653 the same address or line numbers they used to be at last we
11654 checked. Losing your static tracepoints whenever you rebuild is
11655 undesirable. This function tries to resync/rematch gdb static
11656 tracepoints with the markers on the target, for static tracepoints
11657 that have not been set by marker id. Static tracepoint that have
11658 been set by marker id are reset by marker id in breakpoint_re_set.
11661 1) For a tracepoint set at a specific address, look for a marker at
11662 the old PC. If one is found there, assume to be the same marker.
11663 If the name / string id of the marker found is different from the
11664 previous known name, assume that means the user renamed the marker
11665 in the sources, and output a warning.
11667 2) For a tracepoint set at a given line number, look for a marker
11668 at the new address of the old line number. If one is found there,
11669 assume to be the same marker. If the name / string id of the
11670 marker found is different from the previous known name, assume that
11671 means the user renamed the marker in the sources, and output a
11674 3) If a marker is no longer found at the same address or line, it
11675 may mean the marker no longer exists. But it may also just mean
11676 the code changed a bit. Maybe the user added a few lines of code
11677 that made the marker move up or down (in line number terms). Ask
11678 the target for info about the marker with the string id as we knew
11679 it. If found, update line number and address in the matching
11680 static tracepoint. This will get confused if there's more than one
11681 marker with the same ID (possible in UST, although unadvised
11682 precisely because it confuses tools). */
11684 static struct symtab_and_line
11685 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11687 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11688 struct static_tracepoint_marker marker
;
11694 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11696 if (target_static_tracepoint_marker_at (pc
, &marker
))
11698 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11699 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11701 tp
->static_trace_marker_id
, marker
.str_id
);
11703 xfree (tp
->static_trace_marker_id
);
11704 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11705 release_static_tracepoint_marker (&marker
);
11710 /* Old marker wasn't found on target at lineno. Try looking it up
11712 if (!sal
.explicit_pc
11714 && sal
.symtab
!= NULL
11715 && tp
->static_trace_marker_id
!= NULL
)
11717 VEC(static_tracepoint_marker_p
) *markers
;
11720 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11722 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11724 struct symtab_and_line sal
;
11725 struct symbol
*sym
;
11726 struct static_tracepoint_marker
*marker
;
11727 struct ui_out
*uiout
= current_uiout
;
11729 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11731 xfree (tp
->static_trace_marker_id
);
11732 tp
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11734 warning (_("marker for static tracepoint %d (%s) not "
11735 "found at previous line number"),
11736 b
->number
, tp
->static_trace_marker_id
);
11740 sal
.pc
= marker
->address
;
11742 sal
= find_pc_line (marker
->address
, 0);
11743 sym
= find_pc_sect_function (marker
->address
, NULL
);
11744 ui_out_text (uiout
, "Now in ");
11747 ui_out_field_string (uiout
, "func",
11748 SYMBOL_PRINT_NAME (sym
));
11749 ui_out_text (uiout
, " at ");
11751 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11752 ui_out_text (uiout
, ":");
11754 if (ui_out_is_mi_like_p (uiout
))
11756 char *fullname
= symtab_to_fullname (sal
.symtab
);
11759 ui_out_field_string (uiout
, "fullname", fullname
);
11762 ui_out_field_int (uiout
, "line", sal
.line
);
11763 ui_out_text (uiout
, "\n");
11765 b
->line_number
= sal
.line
;
11767 xfree (b
->source_file
);
11769 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11771 b
->source_file
= NULL
;
11773 xfree (b
->addr_string
);
11774 b
->addr_string
= xstrprintf ("%s:%d",
11775 sal
.symtab
->filename
, b
->line_number
);
11777 /* Might be nice to check if function changed, and warn if
11780 release_static_tracepoint_marker (marker
);
11786 /* Returns 1 iff locations A and B are sufficiently same that
11787 we don't need to report breakpoint as changed. */
11790 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11794 if (a
->address
!= b
->address
)
11797 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11800 if (a
->enabled
!= b
->enabled
)
11807 if ((a
== NULL
) != (b
== NULL
))
11813 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11814 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11815 a ranged breakpoint. */
11818 update_breakpoint_locations (struct breakpoint
*b
,
11819 struct symtabs_and_lines sals
,
11820 struct symtabs_and_lines sals_end
)
11823 struct bp_location
*existing_locations
= b
->loc
;
11825 /* Ranged breakpoints have only one start location and one end location. */
11826 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11828 /* If there's no new locations, and all existing locations are
11829 pending, don't do anything. This optimizes the common case where
11830 all locations are in the same shared library, that was unloaded.
11831 We'd like to retain the location, so that when the library is
11832 loaded again, we don't loose the enabled/disabled status of the
11833 individual locations. */
11834 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11839 for (i
= 0; i
< sals
.nelts
; ++i
)
11841 struct bp_location
*new_loc
=
11842 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11844 /* Reparse conditions, they might contain references to the
11846 if (b
->cond_string
!= NULL
)
11849 struct gdb_exception e
;
11851 s
= b
->cond_string
;
11852 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11854 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11859 warning (_("failed to reevaluate condition "
11860 "for breakpoint %d: %s"),
11861 b
->number
, e
.message
);
11862 new_loc
->enabled
= 0;
11866 if (b
->source_file
!= NULL
)
11867 xfree (b
->source_file
);
11868 if (sals
.sals
[i
].symtab
== NULL
)
11869 b
->source_file
= NULL
;
11871 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11873 if (b
->line_number
== 0)
11874 b
->line_number
= sals
.sals
[i
].line
;
11876 if (sals_end
.nelts
)
11878 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11880 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11884 /* Update locations of permanent breakpoints. */
11885 if (b
->enable_state
== bp_permanent
)
11886 make_breakpoint_permanent (b
);
11888 /* If possible, carry over 'disable' status from existing
11891 struct bp_location
*e
= existing_locations
;
11892 /* If there are multiple breakpoints with the same function name,
11893 e.g. for inline functions, comparing function names won't work.
11894 Instead compare pc addresses; this is just a heuristic as things
11895 may have moved, but in practice it gives the correct answer
11896 often enough until a better solution is found. */
11897 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11899 for (; e
; e
= e
->next
)
11901 if (!e
->enabled
&& e
->function_name
)
11903 struct bp_location
*l
= b
->loc
;
11904 if (have_ambiguous_names
)
11906 for (; l
; l
= l
->next
)
11907 if (breakpoint_locations_match (e
, l
))
11915 for (; l
; l
= l
->next
)
11916 if (l
->function_name
11917 && strcmp (e
->function_name
, l
->function_name
) == 0)
11927 if (!locations_are_equal (existing_locations
, b
->loc
))
11928 observer_notify_breakpoint_modified (b
);
11930 update_global_location_list (1);
11933 /* Find the SaL locations corresponding to the given ADDR_STRING.
11934 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11936 static struct symtabs_and_lines
11937 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11941 struct symtabs_and_lines sals
= {0};
11942 struct gdb_exception e
;
11945 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11947 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11951 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11953 sals
= decode_static_tracepoint_spec (&s
);
11954 if (sals
.nelts
> tp
->static_trace_marker_id_idx
)
11956 sals
.sals
[0] = sals
.sals
[tp
->static_trace_marker_id_idx
];
11960 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11963 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11967 int not_found_and_ok
= 0;
11968 /* For pending breakpoints, it's expected that parsing will
11969 fail until the right shared library is loaded. User has
11970 already told to create pending breakpoints and don't need
11971 extra messages. If breakpoint is in bp_shlib_disabled
11972 state, then user already saw the message about that
11973 breakpoint being disabled, and don't want to see more
11975 if (e
.error
== NOT_FOUND_ERROR
11976 && (b
->condition_not_parsed
11977 || (b
->loc
&& b
->loc
->shlib_disabled
)
11978 || b
->enable_state
== bp_disabled
))
11979 not_found_and_ok
= 1;
11981 if (!not_found_and_ok
)
11983 /* We surely don't want to warn about the same breakpoint
11984 10 times. One solution, implemented here, is disable
11985 the breakpoint on error. Another solution would be to
11986 have separate 'warning emitted' flag. Since this
11987 happens only when a binary has changed, I don't know
11988 which approach is better. */
11989 b
->enable_state
= bp_disabled
;
11990 throw_exception (e
);
11994 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11996 gdb_assert (sals
.nelts
== 1);
11998 resolve_sal_pc (&sals
.sals
[0]);
11999 if (b
->condition_not_parsed
&& s
&& s
[0])
12001 char *cond_string
= 0;
12005 find_condition_and_thread (s
, sals
.sals
[0].pc
,
12006 &cond_string
, &thread
, &task
);
12008 b
->cond_string
= cond_string
;
12009 b
->thread
= thread
;
12011 b
->condition_not_parsed
= 0;
12014 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
12015 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
12025 /* The default re_set method, for typical hardware or software
12026 breakpoints. Reevaluate the breakpoint and recreate its
12030 breakpoint_re_set_default (struct breakpoint
*b
)
12033 struct symtabs_and_lines sals
, sals_end
;
12034 struct symtabs_and_lines expanded
= {0};
12035 struct symtabs_and_lines expanded_end
= {0};
12037 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
12040 make_cleanup (xfree
, sals
.sals
);
12041 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
12044 if (b
->addr_string_range_end
)
12046 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
12049 make_cleanup (xfree
, sals_end
.sals
);
12050 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
12054 update_breakpoint_locations (b
, expanded
, expanded_end
);
12057 /* Prepare the global context for a re-set of breakpoint B. */
12059 static struct cleanup
*
12060 prepare_re_set_context (struct breakpoint
*b
)
12062 struct cleanup
*cleanups
;
12064 input_radix
= b
->input_radix
;
12065 cleanups
= save_current_space_and_thread ();
12066 switch_to_program_space_and_thread (b
->pspace
);
12067 set_language (b
->language
);
12072 /* Reset a breakpoint given it's struct breakpoint * BINT.
12073 The value we return ends up being the return value from catch_errors.
12074 Unused in this case. */
12077 breakpoint_re_set_one (void *bint
)
12079 /* Get past catch_errs. */
12080 struct breakpoint
*b
= (struct breakpoint
*) bint
;
12081 struct cleanup
*cleanups
;
12083 cleanups
= prepare_re_set_context (b
);
12084 b
->ops
->re_set (b
);
12085 do_cleanups (cleanups
);
12089 /* Re-set all breakpoints after symbols have been re-loaded. */
12091 breakpoint_re_set (void)
12093 struct breakpoint
*b
, *b_tmp
;
12094 enum language save_language
;
12095 int save_input_radix
;
12096 struct cleanup
*old_chain
;
12098 save_language
= current_language
->la_language
;
12099 save_input_radix
= input_radix
;
12100 old_chain
= save_current_program_space ();
12102 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12104 /* Format possible error msg. */
12105 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
12107 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
12108 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
12109 do_cleanups (cleanups
);
12111 set_language (save_language
);
12112 input_radix
= save_input_radix
;
12114 jit_breakpoint_re_set ();
12116 do_cleanups (old_chain
);
12118 create_overlay_event_breakpoint ();
12119 create_longjmp_master_breakpoint ();
12120 create_std_terminate_master_breakpoint ();
12121 create_exception_master_breakpoint ();
12123 /* While we're at it, reset the skip list too. */
12127 /* Reset the thread number of this breakpoint:
12129 - If the breakpoint is for all threads, leave it as-is.
12130 - Else, reset it to the current thread for inferior_ptid. */
12132 breakpoint_re_set_thread (struct breakpoint
*b
)
12134 if (b
->thread
!= -1)
12136 if (in_thread_list (inferior_ptid
))
12137 b
->thread
= pid_to_thread_id (inferior_ptid
);
12139 /* We're being called after following a fork. The new fork is
12140 selected as current, and unless this was a vfork will have a
12141 different program space from the original thread. Reset that
12143 b
->loc
->pspace
= current_program_space
;
12147 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12148 If from_tty is nonzero, it prints a message to that effect,
12149 which ends with a period (no newline). */
12152 set_ignore_count (int bptnum
, int count
, int from_tty
)
12154 struct breakpoint
*b
;
12159 ALL_BREAKPOINTS (b
)
12160 if (b
->number
== bptnum
)
12162 if (is_tracepoint (b
))
12164 if (from_tty
&& count
!= 0)
12165 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12170 b
->ignore_count
= count
;
12174 printf_filtered (_("Will stop next time "
12175 "breakpoint %d is reached."),
12177 else if (count
== 1)
12178 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12181 printf_filtered (_("Will ignore next %d "
12182 "crossings of breakpoint %d."),
12185 breakpoints_changed ();
12186 observer_notify_breakpoint_modified (b
);
12190 error (_("No breakpoint number %d."), bptnum
);
12193 /* Command to set ignore-count of breakpoint N to COUNT. */
12196 ignore_command (char *args
, int from_tty
)
12202 error_no_arg (_("a breakpoint number"));
12204 num
= get_number (&p
);
12206 error (_("bad breakpoint number: '%s'"), args
);
12208 error (_("Second argument (specified ignore-count) is missing."));
12210 set_ignore_count (num
,
12211 longest_to_int (value_as_long (parse_and_eval (p
))),
12214 printf_filtered ("\n");
12217 /* Call FUNCTION on each of the breakpoints
12218 whose numbers are given in ARGS. */
12221 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
12226 struct breakpoint
*b
, *tmp
;
12228 struct get_number_or_range_state state
;
12231 error_no_arg (_("one or more breakpoint numbers"));
12233 init_number_or_range (&state
, args
);
12235 while (!state
.finished
)
12237 char *p
= state
.string
;
12241 num
= get_number_or_range (&state
);
12244 warning (_("bad breakpoint number at or near '%s'"), p
);
12248 ALL_BREAKPOINTS_SAFE (b
, tmp
)
12249 if (b
->number
== num
)
12252 function (b
, data
);
12256 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
12261 static struct bp_location
*
12262 find_location_by_number (char *number
)
12264 char *dot
= strchr (number
, '.');
12268 struct breakpoint
*b
;
12269 struct bp_location
*loc
;
12274 bp_num
= get_number (&p1
);
12276 error (_("Bad breakpoint number '%s'"), number
);
12278 ALL_BREAKPOINTS (b
)
12279 if (b
->number
== bp_num
)
12284 if (!b
|| b
->number
!= bp_num
)
12285 error (_("Bad breakpoint number '%s'"), number
);
12288 loc_num
= get_number (&p1
);
12290 error (_("Bad breakpoint location number '%s'"), number
);
12294 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12297 error (_("Bad breakpoint location number '%s'"), dot
+1);
12303 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12304 If from_tty is nonzero, it prints a message to that effect,
12305 which ends with a period (no newline). */
12308 disable_breakpoint (struct breakpoint
*bpt
)
12310 /* Never disable a watchpoint scope breakpoint; we want to
12311 hit them when we leave scope so we can delete both the
12312 watchpoint and its scope breakpoint at that time. */
12313 if (bpt
->type
== bp_watchpoint_scope
)
12316 /* You can't disable permanent breakpoints. */
12317 if (bpt
->enable_state
== bp_permanent
)
12320 bpt
->enable_state
= bp_disabled
;
12322 if (target_supports_enable_disable_tracepoint ()
12323 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12325 struct bp_location
*location
;
12327 for (location
= bpt
->loc
; location
; location
= location
->next
)
12328 target_disable_tracepoint (location
);
12331 update_global_location_list (0);
12333 observer_notify_breakpoint_modified (bpt
);
12336 /* A callback for iterate_over_related_breakpoints. */
12339 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12341 disable_breakpoint (b
);
12344 /* A callback for map_breakpoint_numbers that calls
12345 disable_breakpoint. */
12348 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12350 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12354 disable_command (char *args
, int from_tty
)
12358 struct breakpoint
*bpt
;
12360 ALL_BREAKPOINTS (bpt
)
12361 if (user_breakpoint_p (bpt
))
12362 disable_breakpoint (bpt
);
12364 else if (strchr (args
, '.'))
12366 struct bp_location
*loc
= find_location_by_number (args
);
12370 if (target_supports_enable_disable_tracepoint ()
12371 && current_trace_status ()->running
&& loc
->owner
12372 && is_tracepoint (loc
->owner
))
12373 target_disable_tracepoint (loc
);
12375 update_global_location_list (0);
12378 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12382 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12384 int target_resources_ok
;
12386 if (bpt
->type
== bp_hardware_breakpoint
)
12389 i
= hw_breakpoint_used_count ();
12390 target_resources_ok
=
12391 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12393 if (target_resources_ok
== 0)
12394 error (_("No hardware breakpoint support in the target."));
12395 else if (target_resources_ok
< 0)
12396 error (_("Hardware breakpoints used exceeds limit."));
12399 if (is_watchpoint (bpt
))
12401 /* Initialize it just to avoid a GCC false warning. */
12402 enum enable_state orig_enable_state
= 0;
12403 struct gdb_exception e
;
12405 TRY_CATCH (e
, RETURN_MASK_ALL
)
12407 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12409 orig_enable_state
= bpt
->enable_state
;
12410 bpt
->enable_state
= bp_enabled
;
12411 update_watchpoint (w
, 1 /* reparse */);
12415 bpt
->enable_state
= orig_enable_state
;
12416 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12422 if (bpt
->enable_state
!= bp_permanent
)
12423 bpt
->enable_state
= bp_enabled
;
12425 if (target_supports_enable_disable_tracepoint ()
12426 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12428 struct bp_location
*location
;
12430 for (location
= bpt
->loc
; location
; location
= location
->next
)
12431 target_enable_tracepoint (location
);
12434 bpt
->disposition
= disposition
;
12435 update_global_location_list (1);
12436 breakpoints_changed ();
12438 observer_notify_breakpoint_modified (bpt
);
12443 enable_breakpoint (struct breakpoint
*bpt
)
12445 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12449 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12451 enable_breakpoint (bpt
);
12454 /* A callback for map_breakpoint_numbers that calls
12455 enable_breakpoint. */
12458 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12460 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12463 /* The enable command enables the specified breakpoints (or all defined
12464 breakpoints) so they once again become (or continue to be) effective
12465 in stopping the inferior. */
12468 enable_command (char *args
, int from_tty
)
12472 struct breakpoint
*bpt
;
12474 ALL_BREAKPOINTS (bpt
)
12475 if (user_breakpoint_p (bpt
))
12476 enable_breakpoint (bpt
);
12478 else if (strchr (args
, '.'))
12480 struct bp_location
*loc
= find_location_by_number (args
);
12484 if (target_supports_enable_disable_tracepoint ()
12485 && current_trace_status ()->running
&& loc
->owner
12486 && is_tracepoint (loc
->owner
))
12487 target_enable_tracepoint (loc
);
12489 update_global_location_list (1);
12492 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12496 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12498 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12500 enable_breakpoint_disp (bpt
, disp
);
12504 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12506 enum bpdisp disp
= disp_disable
;
12508 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12512 enable_once_command (char *args
, int from_tty
)
12514 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12518 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12520 enum bpdisp disp
= disp_del
;
12522 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12526 enable_delete_command (char *args
, int from_tty
)
12528 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12532 set_breakpoint_cmd (char *args
, int from_tty
)
12537 show_breakpoint_cmd (char *args
, int from_tty
)
12541 /* Invalidate last known value of any hardware watchpoint if
12542 the memory which that value represents has been written to by
12546 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12547 const bfd_byte
*data
)
12549 struct breakpoint
*bp
;
12551 ALL_BREAKPOINTS (bp
)
12552 if (bp
->enable_state
== bp_enabled
12553 && bp
->type
== bp_hardware_watchpoint
)
12555 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12557 if (wp
->val_valid
&& wp
->val
)
12559 struct bp_location
*loc
;
12561 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12562 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12563 && loc
->address
+ loc
->length
> addr
12564 && addr
+ len
> loc
->address
)
12566 value_free (wp
->val
);
12574 /* Use the last displayed codepoint's values, or nothing
12575 if they aren't valid. */
12577 struct symtabs_and_lines
12578 decode_line_spec_1 (char *string
, int funfirstline
)
12580 struct symtabs_and_lines sals
;
12583 error (_("Empty line specification."));
12584 if (last_displayed_sal_is_valid ())
12585 sals
= decode_line_1 (&string
, funfirstline
,
12586 get_last_displayed_symtab (),
12587 get_last_displayed_line (),
12590 sals
= decode_line_1 (&string
, funfirstline
,
12591 (struct symtab
*) NULL
, 0, NULL
);
12593 error (_("Junk at end of line specification: %s"), string
);
12597 /* Create and insert a raw software breakpoint at PC. Return an
12598 identifier, which should be used to remove the breakpoint later.
12599 In general, places which call this should be using something on the
12600 breakpoint chain instead; this function should be eliminated
12604 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12605 struct address_space
*aspace
, CORE_ADDR pc
)
12607 struct bp_target_info
*bp_tgt
;
12609 bp_tgt
= XZALLOC (struct bp_target_info
);
12611 bp_tgt
->placed_address_space
= aspace
;
12612 bp_tgt
->placed_address
= pc
;
12614 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12616 /* Could not insert the breakpoint. */
12624 /* Remove a breakpoint BP inserted by
12625 deprecated_insert_raw_breakpoint. */
12628 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12630 struct bp_target_info
*bp_tgt
= bp
;
12633 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12639 /* One (or perhaps two) breakpoints used for software single
12642 static void *single_step_breakpoints
[2];
12643 static struct gdbarch
*single_step_gdbarch
[2];
12645 /* Create and insert a breakpoint for software single step. */
12648 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12649 struct address_space
*aspace
,
12654 if (single_step_breakpoints
[0] == NULL
)
12656 bpt_p
= &single_step_breakpoints
[0];
12657 single_step_gdbarch
[0] = gdbarch
;
12661 gdb_assert (single_step_breakpoints
[1] == NULL
);
12662 bpt_p
= &single_step_breakpoints
[1];
12663 single_step_gdbarch
[1] = gdbarch
;
12666 /* NOTE drow/2006-04-11: A future improvement to this function would
12667 be to only create the breakpoints once, and actually put them on
12668 the breakpoint chain. That would let us use set_raw_breakpoint.
12669 We could adjust the addresses each time they were needed. Doing
12670 this requires corresponding changes elsewhere where single step
12671 breakpoints are handled, however. So, for now, we use this. */
12673 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12674 if (*bpt_p
== NULL
)
12675 error (_("Could not insert single-step breakpoint at %s"),
12676 paddress (gdbarch
, next_pc
));
12679 /* Check if the breakpoints used for software single stepping
12680 were inserted or not. */
12683 single_step_breakpoints_inserted (void)
12685 return (single_step_breakpoints
[0] != NULL
12686 || single_step_breakpoints
[1] != NULL
);
12689 /* Remove and delete any breakpoints used for software single step. */
12692 remove_single_step_breakpoints (void)
12694 gdb_assert (single_step_breakpoints
[0] != NULL
);
12696 /* See insert_single_step_breakpoint for more about this deprecated
12698 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12699 single_step_breakpoints
[0]);
12700 single_step_gdbarch
[0] = NULL
;
12701 single_step_breakpoints
[0] = NULL
;
12703 if (single_step_breakpoints
[1] != NULL
)
12705 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12706 single_step_breakpoints
[1]);
12707 single_step_gdbarch
[1] = NULL
;
12708 single_step_breakpoints
[1] = NULL
;
12712 /* Delete software single step breakpoints without removing them from
12713 the inferior. This is intended to be used if the inferior's address
12714 space where they were inserted is already gone, e.g. after exit or
12718 cancel_single_step_breakpoints (void)
12722 for (i
= 0; i
< 2; i
++)
12723 if (single_step_breakpoints
[i
])
12725 xfree (single_step_breakpoints
[i
]);
12726 single_step_breakpoints
[i
] = NULL
;
12727 single_step_gdbarch
[i
] = NULL
;
12731 /* Detach software single-step breakpoints from INFERIOR_PTID without
12735 detach_single_step_breakpoints (void)
12739 for (i
= 0; i
< 2; i
++)
12740 if (single_step_breakpoints
[i
])
12741 target_remove_breakpoint (single_step_gdbarch
[i
],
12742 single_step_breakpoints
[i
]);
12745 /* Check whether a software single-step breakpoint is inserted at
12749 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12754 for (i
= 0; i
< 2; i
++)
12756 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12758 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12759 bp_tgt
->placed_address
,
12767 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12768 non-zero otherwise. */
12770 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12772 if (syscall_catchpoint_p (bp
)
12773 && bp
->enable_state
!= bp_disabled
12774 && bp
->enable_state
!= bp_call_disabled
)
12781 catch_syscall_enabled (void)
12783 struct inferior
*inf
= current_inferior ();
12785 return inf
->total_syscalls_count
!= 0;
12789 catching_syscall_number (int syscall_number
)
12791 struct breakpoint
*bp
;
12793 ALL_BREAKPOINTS (bp
)
12794 if (is_syscall_catchpoint_enabled (bp
))
12796 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12798 if (c
->syscalls_to_be_caught
)
12802 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12804 if (syscall_number
== iter
)
12814 /* Complete syscall names. Used by "catch syscall". */
12816 catch_syscall_completer (struct cmd_list_element
*cmd
,
12817 char *text
, char *word
)
12819 const char **list
= get_syscall_names ();
12821 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12827 /* Tracepoint-specific operations. */
12829 /* Set tracepoint count to NUM. */
12831 set_tracepoint_count (int num
)
12833 tracepoint_count
= num
;
12834 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12838 trace_command (char *arg
, int from_tty
)
12840 if (create_breakpoint (get_current_arch (),
12842 NULL
, 0, 1 /* parse arg */,
12844 bp_tracepoint
/* type_wanted */,
12845 0 /* Ignore count */,
12846 pending_break_support
,
12847 &tracepoint_breakpoint_ops
,
12851 set_tracepoint_count (breakpoint_count
);
12855 ftrace_command (char *arg
, int from_tty
)
12857 if (create_breakpoint (get_current_arch (),
12859 NULL
, 0, 1 /* parse arg */,
12861 bp_fast_tracepoint
/* type_wanted */,
12862 0 /* Ignore count */,
12863 pending_break_support
,
12864 &tracepoint_breakpoint_ops
,
12868 set_tracepoint_count (breakpoint_count
);
12871 /* strace command implementation. Creates a static tracepoint. */
12874 strace_command (char *arg
, int from_tty
)
12876 if (create_breakpoint (get_current_arch (),
12878 NULL
, 0, 1 /* parse arg */,
12880 bp_static_tracepoint
/* type_wanted */,
12881 0 /* Ignore count */,
12882 pending_break_support
,
12883 &tracepoint_breakpoint_ops
,
12887 set_tracepoint_count (breakpoint_count
);
12890 /* Set up a fake reader function that gets command lines from a linked
12891 list that was acquired during tracepoint uploading. */
12893 static struct uploaded_tp
*this_utp
;
12894 static int next_cmd
;
12897 read_uploaded_action (void)
12901 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12908 /* Given information about a tracepoint as recorded on a target (which
12909 can be either a live system or a trace file), attempt to create an
12910 equivalent GDB tracepoint. This is not a reliable process, since
12911 the target does not necessarily have all the information used when
12912 the tracepoint was originally defined. */
12914 struct tracepoint
*
12915 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12917 char *addr_str
, small_buf
[100];
12918 struct tracepoint
*tp
;
12920 if (utp
->at_string
)
12921 addr_str
= utp
->at_string
;
12924 /* In the absence of a source location, fall back to raw
12925 address. Since there is no way to confirm that the address
12926 means the same thing as when the trace was started, warn the
12928 warning (_("Uploaded tracepoint %d has no "
12929 "source location, using raw address"),
12931 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12932 addr_str
= small_buf
;
12935 /* There's not much we can do with a sequence of bytecodes. */
12936 if (utp
->cond
&& !utp
->cond_string
)
12937 warning (_("Uploaded tracepoint %d condition "
12938 "has no source form, ignoring it"),
12941 if (!create_breakpoint (get_current_arch (),
12943 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12945 utp
->type
/* type_wanted */,
12946 0 /* Ignore count */,
12947 pending_break_support
,
12948 &tracepoint_breakpoint_ops
,
12950 utp
->enabled
/* enabled */,
12954 set_tracepoint_count (breakpoint_count
);
12956 /* Get the tracepoint we just created. */
12957 tp
= get_tracepoint (tracepoint_count
);
12958 gdb_assert (tp
!= NULL
);
12962 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
12964 trace_pass_command (small_buf
, 0);
12967 /* If we have uploaded versions of the original commands, set up a
12968 special-purpose "reader" function and call the usual command line
12969 reader, then pass the result to the breakpoint command-setting
12971 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12973 struct command_line
*cmd_list
;
12978 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12980 breakpoint_set_commands (&tp
->base
, cmd_list
);
12982 else if (!VEC_empty (char_ptr
, utp
->actions
)
12983 || !VEC_empty (char_ptr
, utp
->step_actions
))
12984 warning (_("Uploaded tracepoint %d actions "
12985 "have no source form, ignoring them"),
12988 /* Copy any status information that might be available. */
12989 tp
->base
.hit_count
= utp
->hit_count
;
12990 tp
->traceframe_usage
= utp
->traceframe_usage
;
12995 /* Print information on tracepoint number TPNUM_EXP, or all if
12999 tracepoints_info (char *args
, int from_tty
)
13001 struct ui_out
*uiout
= current_uiout
;
13004 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
13006 if (num_printed
== 0)
13008 if (args
== NULL
|| *args
== '\0')
13009 ui_out_message (uiout
, 0, "No tracepoints.\n");
13011 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
13014 default_collect_info ();
13017 /* The 'enable trace' command enables tracepoints.
13018 Not supported by all targets. */
13020 enable_trace_command (char *args
, int from_tty
)
13022 enable_command (args
, from_tty
);
13025 /* The 'disable trace' command disables tracepoints.
13026 Not supported by all targets. */
13028 disable_trace_command (char *args
, int from_tty
)
13030 disable_command (args
, from_tty
);
13033 /* Remove a tracepoint (or all if no argument). */
13035 delete_trace_command (char *arg
, int from_tty
)
13037 struct breakpoint
*b
, *b_tmp
;
13043 int breaks_to_delete
= 0;
13045 /* Delete all breakpoints if no argument.
13046 Do not delete internal or call-dummy breakpoints, these
13047 have to be deleted with an explicit breakpoint number
13049 ALL_TRACEPOINTS (b
)
13050 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13052 breaks_to_delete
= 1;
13056 /* Ask user only if there are some breakpoints to delete. */
13058 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13060 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13061 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13062 delete_breakpoint (b
);
13066 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13069 /* Helper function for trace_pass_command. */
13072 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13074 tp
->pass_count
= count
;
13075 observer_notify_tracepoint_modified (tp
->base
.number
);
13077 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
13078 tp
->base
.number
, count
);
13081 /* Set passcount for tracepoint.
13083 First command argument is passcount, second is tracepoint number.
13084 If tracepoint number omitted, apply to most recently defined.
13085 Also accepts special argument "all". */
13088 trace_pass_command (char *args
, int from_tty
)
13090 struct tracepoint
*t1
;
13091 unsigned int count
;
13093 if (args
== 0 || *args
== 0)
13094 error (_("passcount command requires an "
13095 "argument (count + optional TP num)"));
13097 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
13099 while (*args
&& isspace ((int) *args
))
13102 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13104 struct breakpoint
*b
;
13106 args
+= 3; /* Skip special argument "all". */
13108 error (_("Junk at end of arguments."));
13110 ALL_TRACEPOINTS (b
)
13112 t1
= (struct tracepoint
*) b
;
13113 trace_pass_set_count (t1
, count
, from_tty
);
13116 else if (*args
== '\0')
13118 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
13120 trace_pass_set_count (t1
, count
, from_tty
);
13124 struct get_number_or_range_state state
;
13126 init_number_or_range (&state
, args
);
13127 while (!state
.finished
)
13129 t1
= get_tracepoint_by_number (&args
, &state
, 1);
13131 trace_pass_set_count (t1
, count
, from_tty
);
13136 struct tracepoint
*
13137 get_tracepoint (int num
)
13139 struct breakpoint
*t
;
13141 ALL_TRACEPOINTS (t
)
13142 if (t
->number
== num
)
13143 return (struct tracepoint
*) t
;
13148 /* Find the tracepoint with the given target-side number (which may be
13149 different from the tracepoint number after disconnecting and
13152 struct tracepoint
*
13153 get_tracepoint_by_number_on_target (int num
)
13155 struct breakpoint
*b
;
13157 ALL_TRACEPOINTS (b
)
13159 struct tracepoint
*t
= (struct tracepoint
*) b
;
13161 if (t
->number_on_target
== num
)
13168 /* Utility: parse a tracepoint number and look it up in the list.
13169 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13170 If OPTIONAL_P is true, then if the argument is missing, the most
13171 recent tracepoint (tracepoint_count) is returned. */
13172 struct tracepoint
*
13173 get_tracepoint_by_number (char **arg
,
13174 struct get_number_or_range_state
*state
,
13177 extern int tracepoint_count
;
13178 struct breakpoint
*t
;
13180 char *instring
= arg
== NULL
? NULL
: *arg
;
13184 gdb_assert (!state
->finished
);
13185 tpnum
= get_number_or_range (state
);
13187 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13190 tpnum
= tracepoint_count
;
13192 error_no_arg (_("tracepoint number"));
13195 tpnum
= get_number (arg
);
13199 if (instring
&& *instring
)
13200 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13203 printf_filtered (_("Tracepoint argument missing "
13204 "and no previous tracepoint\n"));
13208 ALL_TRACEPOINTS (t
)
13209 if (t
->number
== tpnum
)
13211 return (struct tracepoint
*) t
;
13214 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
13219 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
13221 if (b
->thread
!= -1)
13222 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
13225 fprintf_unfiltered (fp
, " task %d", b
->task
);
13227 fprintf_unfiltered (fp
, "\n");
13230 /* Save information on user settable breakpoints (watchpoints, etc) to
13231 a new script file named FILENAME. If FILTER is non-NULL, call it
13232 on each breakpoint and only include the ones for which it returns
13236 save_breakpoints (char *filename
, int from_tty
,
13237 int (*filter
) (const struct breakpoint
*))
13239 struct breakpoint
*tp
;
13242 struct cleanup
*cleanup
;
13243 struct ui_file
*fp
;
13244 int extra_trace_bits
= 0;
13246 if (filename
== 0 || *filename
== 0)
13247 error (_("Argument required (file name in which to save)"));
13249 /* See if we have anything to save. */
13250 ALL_BREAKPOINTS (tp
)
13252 /* Skip internal and momentary breakpoints. */
13253 if (!user_breakpoint_p (tp
))
13256 /* If we have a filter, only save the breakpoints it accepts. */
13257 if (filter
&& !filter (tp
))
13262 if (is_tracepoint (tp
))
13264 extra_trace_bits
= 1;
13266 /* We can stop searching. */
13273 warning (_("Nothing to save."));
13277 pathname
= tilde_expand (filename
);
13278 cleanup
= make_cleanup (xfree
, pathname
);
13279 fp
= gdb_fopen (pathname
, "w");
13281 error (_("Unable to open file '%s' for saving (%s)"),
13282 filename
, safe_strerror (errno
));
13283 make_cleanup_ui_file_delete (fp
);
13285 if (extra_trace_bits
)
13286 save_trace_state_variables (fp
);
13288 ALL_BREAKPOINTS (tp
)
13290 /* Skip internal and momentary breakpoints. */
13291 if (!user_breakpoint_p (tp
))
13294 /* If we have a filter, only save the breakpoints it accepts. */
13295 if (filter
&& !filter (tp
))
13298 tp
->ops
->print_recreate (tp
, fp
);
13300 /* Note, we can't rely on tp->number for anything, as we can't
13301 assume the recreated breakpoint numbers will match. Use $bpnum
13304 if (tp
->cond_string
)
13305 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13307 if (tp
->ignore_count
)
13308 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13312 volatile struct gdb_exception ex
;
13314 fprintf_unfiltered (fp
, " commands\n");
13316 ui_out_redirect (current_uiout
, fp
);
13317 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13319 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
13321 ui_out_redirect (current_uiout
, NULL
);
13324 throw_exception (ex
);
13326 fprintf_unfiltered (fp
, " end\n");
13329 if (tp
->enable_state
== bp_disabled
)
13330 fprintf_unfiltered (fp
, "disable\n");
13332 /* If this is a multi-location breakpoint, check if the locations
13333 should be individually disabled. Watchpoint locations are
13334 special, and not user visible. */
13335 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13337 struct bp_location
*loc
;
13340 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13342 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13346 if (extra_trace_bits
&& *default_collect
)
13347 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13349 do_cleanups (cleanup
);
13351 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13354 /* The `save breakpoints' command. */
13357 save_breakpoints_command (char *args
, int from_tty
)
13359 save_breakpoints (args
, from_tty
, NULL
);
13362 /* The `save tracepoints' command. */
13365 save_tracepoints_command (char *args
, int from_tty
)
13367 save_breakpoints (args
, from_tty
, is_tracepoint
);
13370 /* Create a vector of all tracepoints. */
13372 VEC(breakpoint_p
) *
13373 all_tracepoints (void)
13375 VEC(breakpoint_p
) *tp_vec
= 0;
13376 struct breakpoint
*tp
;
13378 ALL_TRACEPOINTS (tp
)
13380 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13387 /* This help string is used for the break, hbreak, tbreak and thbreak
13388 commands. It is defined as a macro to prevent duplication.
13389 COMMAND should be a string constant containing the name of the
13391 #define BREAK_ARGS_HELP(command) \
13392 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13393 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13394 If a line number is specified, break at start of code for that line.\n\
13395 If a function is specified, break at start of code for that function.\n\
13396 If an address is specified, break at that exact address.\n\
13397 With no LOCATION, uses current execution address of the selected\n\
13398 stack frame. This is useful for breaking on return to a stack frame.\n\
13400 THREADNUM is the number from \"info threads\".\n\
13401 CONDITION is a boolean expression.\n\
13403 Multiple breakpoints at one place are permitted, and useful if their\n\
13404 conditions are different.\n\
13406 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13408 /* List of subcommands for "catch". */
13409 static struct cmd_list_element
*catch_cmdlist
;
13411 /* List of subcommands for "tcatch". */
13412 static struct cmd_list_element
*tcatch_cmdlist
;
13415 add_catch_command (char *name
, char *docstring
,
13416 void (*sfunc
) (char *args
, int from_tty
,
13417 struct cmd_list_element
*command
),
13418 char **(*completer
) (struct cmd_list_element
*cmd
,
13419 char *text
, char *word
),
13420 void *user_data_catch
,
13421 void *user_data_tcatch
)
13423 struct cmd_list_element
*command
;
13425 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13427 set_cmd_sfunc (command
, sfunc
);
13428 set_cmd_context (command
, user_data_catch
);
13429 set_cmd_completer (command
, completer
);
13431 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13433 set_cmd_sfunc (command
, sfunc
);
13434 set_cmd_context (command
, user_data_tcatch
);
13435 set_cmd_completer (command
, completer
);
13439 clear_syscall_counts (struct inferior
*inf
)
13441 inf
->total_syscalls_count
= 0;
13442 inf
->any_syscall_count
= 0;
13443 VEC_free (int, inf
->syscalls_counts
);
13447 save_command (char *arg
, int from_tty
)
13449 printf_unfiltered (_("\"save\" must be followed by "
13450 "the name of a save subcommand.\n"));
13451 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13454 struct breakpoint
*
13455 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13458 struct breakpoint
*b
, *b_tmp
;
13460 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13462 if ((*callback
) (b
, data
))
13469 /* Zero if any of the breakpoint's locations could be a location where
13470 functions have been inlined, nonzero otherwise. */
13473 is_non_inline_function (struct breakpoint
*b
)
13475 /* The shared library event breakpoint is set on the address of a
13476 non-inline function. */
13477 if (b
->type
== bp_shlib_event
)
13483 /* Nonzero if the specified PC cannot be a location where functions
13484 have been inlined. */
13487 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
)
13489 struct breakpoint
*b
;
13490 struct bp_location
*bl
;
13492 ALL_BREAKPOINTS (b
)
13494 if (!is_non_inline_function (b
))
13497 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
13499 if (!bl
->shlib_disabled
13500 && bpstat_check_location (bl
, aspace
, pc
))
13509 initialize_breakpoint_ops (void)
13511 static int initialized
= 0;
13513 struct breakpoint_ops
*ops
;
13519 /* The breakpoint_ops structure to be inherit by all kinds of
13520 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13521 internal and momentary breakpoints, etc.). */
13522 ops
= &bkpt_base_breakpoint_ops
;
13523 *ops
= base_breakpoint_ops
;
13524 ops
->re_set
= bkpt_re_set
;
13525 ops
->insert_location
= bkpt_insert_location
;
13526 ops
->remove_location
= bkpt_remove_location
;
13527 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13529 /* The breakpoint_ops structure to be used in regular breakpoints. */
13530 ops
= &bkpt_breakpoint_ops
;
13531 *ops
= bkpt_base_breakpoint_ops
;
13532 ops
->re_set
= bkpt_re_set
;
13533 ops
->resources_needed
= bkpt_resources_needed
;
13534 ops
->print_it
= bkpt_print_it
;
13535 ops
->print_mention
= bkpt_print_mention
;
13536 ops
->print_recreate
= bkpt_print_recreate
;
13538 /* Ranged breakpoints. */
13539 ops
= &ranged_breakpoint_ops
;
13540 *ops
= bkpt_breakpoint_ops
;
13541 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13542 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13543 ops
->print_it
= print_it_ranged_breakpoint
;
13544 ops
->print_one
= print_one_ranged_breakpoint
;
13545 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13546 ops
->print_mention
= print_mention_ranged_breakpoint
;
13547 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13549 /* Internal breakpoints. */
13550 ops
= &internal_breakpoint_ops
;
13551 *ops
= bkpt_base_breakpoint_ops
;
13552 ops
->re_set
= internal_bkpt_re_set
;
13553 ops
->check_status
= internal_bkpt_check_status
;
13554 ops
->print_it
= internal_bkpt_print_it
;
13555 ops
->print_mention
= internal_bkpt_print_mention
;
13557 /* Momentary breakpoints. */
13558 ops
= &momentary_breakpoint_ops
;
13559 *ops
= bkpt_base_breakpoint_ops
;
13560 ops
->re_set
= momentary_bkpt_re_set
;
13561 ops
->check_status
= momentary_bkpt_check_status
;
13562 ops
->print_it
= momentary_bkpt_print_it
;
13563 ops
->print_mention
= momentary_bkpt_print_mention
;
13565 /* GNU v3 exception catchpoints. */
13566 ops
= &gnu_v3_exception_catchpoint_ops
;
13567 *ops
= bkpt_breakpoint_ops
;
13568 ops
->print_it
= print_it_exception_catchpoint
;
13569 ops
->print_one
= print_one_exception_catchpoint
;
13570 ops
->print_mention
= print_mention_exception_catchpoint
;
13571 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13574 ops
= &watchpoint_breakpoint_ops
;
13575 *ops
= base_breakpoint_ops
;
13576 ops
->dtor
= dtor_watchpoint
;
13577 ops
->re_set
= re_set_watchpoint
;
13578 ops
->insert_location
= insert_watchpoint
;
13579 ops
->remove_location
= remove_watchpoint
;
13580 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13581 ops
->check_status
= check_status_watchpoint
;
13582 ops
->resources_needed
= resources_needed_watchpoint
;
13583 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13584 ops
->print_it
= print_it_watchpoint
;
13585 ops
->print_mention
= print_mention_watchpoint
;
13586 ops
->print_recreate
= print_recreate_watchpoint
;
13588 /* Masked watchpoints. */
13589 ops
= &masked_watchpoint_breakpoint_ops
;
13590 *ops
= watchpoint_breakpoint_ops
;
13591 ops
->insert_location
= insert_masked_watchpoint
;
13592 ops
->remove_location
= remove_masked_watchpoint
;
13593 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13594 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13595 ops
->print_it
= print_it_masked_watchpoint
;
13596 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13597 ops
->print_mention
= print_mention_masked_watchpoint
;
13598 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13601 ops
= &tracepoint_breakpoint_ops
;
13602 *ops
= base_breakpoint_ops
;
13603 ops
->re_set
= tracepoint_re_set
;
13604 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13605 ops
->print_one_detail
= tracepoint_print_one_detail
;
13606 ops
->print_mention
= tracepoint_print_mention
;
13607 ops
->print_recreate
= tracepoint_print_recreate
;
13609 /* Fork catchpoints. */
13610 ops
= &catch_fork_breakpoint_ops
;
13611 *ops
= base_breakpoint_ops
;
13612 ops
->insert_location
= insert_catch_fork
;
13613 ops
->remove_location
= remove_catch_fork
;
13614 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13615 ops
->print_it
= print_it_catch_fork
;
13616 ops
->print_one
= print_one_catch_fork
;
13617 ops
->print_mention
= print_mention_catch_fork
;
13618 ops
->print_recreate
= print_recreate_catch_fork
;
13620 /* Vfork catchpoints. */
13621 ops
= &catch_vfork_breakpoint_ops
;
13622 *ops
= base_breakpoint_ops
;
13623 ops
->insert_location
= insert_catch_vfork
;
13624 ops
->remove_location
= remove_catch_vfork
;
13625 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13626 ops
->print_it
= print_it_catch_vfork
;
13627 ops
->print_one
= print_one_catch_vfork
;
13628 ops
->print_mention
= print_mention_catch_vfork
;
13629 ops
->print_recreate
= print_recreate_catch_vfork
;
13631 /* Exec catchpoints. */
13632 ops
= &catch_exec_breakpoint_ops
;
13633 *ops
= base_breakpoint_ops
;
13634 ops
->dtor
= dtor_catch_exec
;
13635 ops
->insert_location
= insert_catch_exec
;
13636 ops
->remove_location
= remove_catch_exec
;
13637 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13638 ops
->print_it
= print_it_catch_exec
;
13639 ops
->print_one
= print_one_catch_exec
;
13640 ops
->print_mention
= print_mention_catch_exec
;
13641 ops
->print_recreate
= print_recreate_catch_exec
;
13643 /* Syscall catchpoints. */
13644 ops
= &catch_syscall_breakpoint_ops
;
13645 *ops
= base_breakpoint_ops
;
13646 ops
->dtor
= dtor_catch_syscall
;
13647 ops
->insert_location
= insert_catch_syscall
;
13648 ops
->remove_location
= remove_catch_syscall
;
13649 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13650 ops
->print_it
= print_it_catch_syscall
;
13651 ops
->print_one
= print_one_catch_syscall
;
13652 ops
->print_mention
= print_mention_catch_syscall
;
13653 ops
->print_recreate
= print_recreate_catch_syscall
;
13657 _initialize_breakpoint (void)
13659 struct cmd_list_element
*c
;
13661 initialize_breakpoint_ops ();
13663 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13664 observer_attach_inferior_exit (clear_syscall_counts
);
13665 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13667 breakpoint_objfile_key
= register_objfile_data ();
13669 breakpoint_chain
= 0;
13670 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13671 before a breakpoint is set. */
13672 breakpoint_count
= 0;
13674 tracepoint_count
= 0;
13676 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13677 Set ignore-count of breakpoint number N to COUNT.\n\
13678 Usage is `ignore N COUNT'."));
13680 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13682 add_com ("commands", class_breakpoint
, commands_command
, _("\
13683 Set commands to be executed when a breakpoint is hit.\n\
13684 Give breakpoint number as argument after \"commands\".\n\
13685 With no argument, the targeted breakpoint is the last one set.\n\
13686 The commands themselves follow starting on the next line.\n\
13687 Type a line containing \"end\" to indicate the end of them.\n\
13688 Give \"silent\" as the first line to make the breakpoint silent;\n\
13689 then no output is printed when it is hit, except what the commands print."));
13691 add_com ("condition", class_breakpoint
, condition_command
, _("\
13692 Specify breakpoint number N to break only if COND is true.\n\
13693 Usage is `condition N COND', where N is an integer and COND is an\n\
13694 expression to be evaluated whenever breakpoint N is reached."));
13696 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13697 Set a temporary breakpoint.\n\
13698 Like \"break\" except the breakpoint is only temporary,\n\
13699 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13700 by using \"enable delete\" on the breakpoint number.\n\
13702 BREAK_ARGS_HELP ("tbreak")));
13703 set_cmd_completer (c
, location_completer
);
13705 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13706 Set a hardware assisted breakpoint.\n\
13707 Like \"break\" except the breakpoint requires hardware support,\n\
13708 some target hardware may not have this support.\n\
13710 BREAK_ARGS_HELP ("hbreak")));
13711 set_cmd_completer (c
, location_completer
);
13713 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13714 Set a temporary hardware assisted breakpoint.\n\
13715 Like \"hbreak\" except the breakpoint is only temporary,\n\
13716 so it will be deleted when hit.\n\
13718 BREAK_ARGS_HELP ("thbreak")));
13719 set_cmd_completer (c
, location_completer
);
13721 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13722 Enable some breakpoints.\n\
13723 Give breakpoint numbers (separated by spaces) as arguments.\n\
13724 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13725 This is used to cancel the effect of the \"disable\" command.\n\
13726 With a subcommand you can enable temporarily."),
13727 &enablelist
, "enable ", 1, &cmdlist
);
13729 add_com ("ab", class_breakpoint
, enable_command
, _("\
13730 Enable some breakpoints.\n\
13731 Give breakpoint numbers (separated by spaces) as arguments.\n\
13732 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13733 This is used to cancel the effect of the \"disable\" command.\n\
13734 With a subcommand you can enable temporarily."));
13736 add_com_alias ("en", "enable", class_breakpoint
, 1);
13738 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13739 Enable some breakpoints.\n\
13740 Give breakpoint numbers (separated by spaces) as arguments.\n\
13741 This is used to cancel the effect of the \"disable\" command.\n\
13742 May be abbreviated to simply \"enable\".\n"),
13743 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13745 add_cmd ("once", no_class
, enable_once_command
, _("\
13746 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13747 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13750 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13751 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13752 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13755 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13756 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13757 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13760 add_cmd ("once", no_class
, enable_once_command
, _("\
13761 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13762 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13765 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13766 Disable some breakpoints.\n\
13767 Arguments are breakpoint numbers with spaces in between.\n\
13768 To disable all breakpoints, give no argument.\n\
13769 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13770 &disablelist
, "disable ", 1, &cmdlist
);
13771 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13772 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13774 add_com ("sb", class_breakpoint
, disable_command
, _("\
13775 Disable some breakpoints.\n\
13776 Arguments are breakpoint numbers with spaces in between.\n\
13777 To disable all breakpoints, give no argument.\n\
13778 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13780 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13781 Disable some breakpoints.\n\
13782 Arguments are breakpoint numbers with spaces in between.\n\
13783 To disable all breakpoints, give no argument.\n\
13784 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13785 This command may be abbreviated \"disable\"."),
13788 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13789 Delete some breakpoints or auto-display expressions.\n\
13790 Arguments are breakpoint numbers with spaces in between.\n\
13791 To delete all breakpoints, give no argument.\n\
13793 Also a prefix command for deletion of other GDB objects.\n\
13794 The \"unset\" command is also an alias for \"delete\"."),
13795 &deletelist
, "delete ", 1, &cmdlist
);
13796 add_com_alias ("d", "delete", class_breakpoint
, 1);
13797 add_com_alias ("del", "delete", class_breakpoint
, 1);
13799 add_com ("db", class_breakpoint
, delete_command
, _("\
13800 Delete some breakpoints.\n\
13801 Arguments are breakpoint numbers with spaces in between.\n\
13802 To delete all breakpoints, give no argument.\n"));
13804 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13805 Delete some breakpoints or auto-display expressions.\n\
13806 Arguments are breakpoint numbers with spaces in between.\n\
13807 To delete all breakpoints, give no argument.\n\
13808 This command may be abbreviated \"delete\"."),
13811 add_com ("clear", class_breakpoint
, clear_command
, _("\
13812 Clear breakpoint at specified line or function.\n\
13813 Argument may be line number, function name, or \"*\" and an address.\n\
13814 If line number is specified, all breakpoints in that line are cleared.\n\
13815 If function is specified, breakpoints at beginning of function are cleared.\n\
13816 If an address is specified, breakpoints at that address are cleared.\n\
13818 With no argument, clears all breakpoints in the line that the selected frame\n\
13819 is executing in.\n\
13821 See also the \"delete\" command which clears breakpoints by number."));
13822 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13824 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13825 Set breakpoint at specified line or function.\n"
13826 BREAK_ARGS_HELP ("break")));
13827 set_cmd_completer (c
, location_completer
);
13829 add_com_alias ("b", "break", class_run
, 1);
13830 add_com_alias ("br", "break", class_run
, 1);
13831 add_com_alias ("bre", "break", class_run
, 1);
13832 add_com_alias ("brea", "break", class_run
, 1);
13835 add_com_alias ("ba", "break", class_breakpoint
, 1);
13839 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13840 Break in function/address or break at a line in the current file."),
13841 &stoplist
, "stop ", 1, &cmdlist
);
13842 add_cmd ("in", class_breakpoint
, stopin_command
,
13843 _("Break in function or address."), &stoplist
);
13844 add_cmd ("at", class_breakpoint
, stopat_command
,
13845 _("Break at a line in the current file."), &stoplist
);
13846 add_com ("status", class_info
, breakpoints_info
, _("\
13847 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13848 The \"Type\" column indicates one of:\n\
13849 \tbreakpoint - normal breakpoint\n\
13850 \twatchpoint - watchpoint\n\
13851 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13852 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13853 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13854 address and file/line number respectively.\n\
13856 Convenience variable \"$_\" and default examine address for \"x\"\n\
13857 are set to the address of the last breakpoint listed unless the command\n\
13858 is prefixed with \"server \".\n\n\
13859 Convenience variable \"$bpnum\" contains the number of the last\n\
13860 breakpoint set."));
13863 add_info ("breakpoints", breakpoints_info
, _("\
13864 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13865 The \"Type\" column indicates one of:\n\
13866 \tbreakpoint - normal breakpoint\n\
13867 \twatchpoint - watchpoint\n\
13868 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13869 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13870 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13871 address and file/line number respectively.\n\
13873 Convenience variable \"$_\" and default examine address for \"x\"\n\
13874 are set to the address of the last breakpoint listed unless the command\n\
13875 is prefixed with \"server \".\n\n\
13876 Convenience variable \"$bpnum\" contains the number of the last\n\
13877 breakpoint set."));
13879 add_info_alias ("b", "breakpoints", 1);
13882 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13883 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13884 The \"Type\" column indicates one of:\n\
13885 \tbreakpoint - normal breakpoint\n\
13886 \twatchpoint - watchpoint\n\
13887 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13888 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13889 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13890 address and file/line number respectively.\n\
13892 Convenience variable \"$_\" and default examine address for \"x\"\n\
13893 are set to the address of the last breakpoint listed unless the command\n\
13894 is prefixed with \"server \".\n\n\
13895 Convenience variable \"$bpnum\" contains the number of the last\n\
13896 breakpoint set."));
13898 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13899 Status of all breakpoints, or breakpoint number NUMBER.\n\
13900 The \"Type\" column indicates one of:\n\
13901 \tbreakpoint - normal breakpoint\n\
13902 \twatchpoint - watchpoint\n\
13903 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13904 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13905 \tuntil - internal breakpoint used by the \"until\" command\n\
13906 \tfinish - internal breakpoint used by the \"finish\" command\n\
13907 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13908 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13909 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13910 address and file/line number respectively.\n\
13912 Convenience variable \"$_\" and default examine address for \"x\"\n\
13913 are set to the address of the last breakpoint listed unless the command\n\
13914 is prefixed with \"server \".\n\n\
13915 Convenience variable \"$bpnum\" contains the number of the last\n\
13917 &maintenanceinfolist
);
13919 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13920 Set catchpoints to catch events."),
13921 &catch_cmdlist
, "catch ",
13922 0/*allow-unknown*/, &cmdlist
);
13924 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13925 Set temporary catchpoints to catch events."),
13926 &tcatch_cmdlist
, "tcatch ",
13927 0/*allow-unknown*/, &cmdlist
);
13929 /* Add catch and tcatch sub-commands. */
13930 add_catch_command ("catch", _("\
13931 Catch an exception, when caught.\n\
13932 With an argument, catch only exceptions with the given name."),
13933 catch_catch_command
,
13937 add_catch_command ("throw", _("\
13938 Catch an exception, when thrown.\n\
13939 With an argument, catch only exceptions with the given name."),
13940 catch_throw_command
,
13944 add_catch_command ("fork", _("Catch calls to fork."),
13945 catch_fork_command_1
,
13947 (void *) (uintptr_t) catch_fork_permanent
,
13948 (void *) (uintptr_t) catch_fork_temporary
);
13949 add_catch_command ("vfork", _("Catch calls to vfork."),
13950 catch_fork_command_1
,
13952 (void *) (uintptr_t) catch_vfork_permanent
,
13953 (void *) (uintptr_t) catch_vfork_temporary
);
13954 add_catch_command ("exec", _("Catch calls to exec."),
13955 catch_exec_command_1
,
13959 add_catch_command ("syscall", _("\
13960 Catch system calls by their names and/or numbers.\n\
13961 Arguments say which system calls to catch. If no arguments\n\
13962 are given, every system call will be caught.\n\
13963 Arguments, if given, should be one or more system call names\n\
13964 (if your system supports that), or system call numbers."),
13965 catch_syscall_command_1
,
13966 catch_syscall_completer
,
13970 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13971 Set a watchpoint for an expression.\n\
13972 Usage: watch [-l|-location] EXPRESSION\n\
13973 A watchpoint stops execution of your program whenever the value of\n\
13974 an expression changes.\n\
13975 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13976 the memory to which it refers."));
13977 set_cmd_completer (c
, expression_completer
);
13979 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13980 Set a read watchpoint for an expression.\n\
13981 Usage: rwatch [-l|-location] EXPRESSION\n\
13982 A watchpoint stops execution of your program whenever the value of\n\
13983 an expression is read.\n\
13984 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13985 the memory to which it refers."));
13986 set_cmd_completer (c
, expression_completer
);
13988 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13989 Set a watchpoint for an expression.\n\
13990 Usage: awatch [-l|-location] EXPRESSION\n\
13991 A watchpoint stops execution of your program whenever the value of\n\
13992 an expression is either read or written.\n\
13993 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13994 the memory to which it refers."));
13995 set_cmd_completer (c
, expression_completer
);
13997 add_info ("watchpoints", watchpoints_info
, _("\
13998 Status of specified watchpoints (all watchpoints if no argument)."));
14000 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14001 respond to changes - contrary to the description. */
14002 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14003 &can_use_hw_watchpoints
, _("\
14004 Set debugger's willingness to use watchpoint hardware."), _("\
14005 Show debugger's willingness to use watchpoint hardware."), _("\
14006 If zero, gdb will not use hardware for new watchpoints, even if\n\
14007 such is available. (However, any hardware watchpoints that were\n\
14008 created before setting this to nonzero, will continue to use watchpoint\n\
14011 show_can_use_hw_watchpoints
,
14012 &setlist
, &showlist
);
14014 can_use_hw_watchpoints
= 1;
14016 /* Tracepoint manipulation commands. */
14018 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
14019 Set a tracepoint at specified line or function.\n\
14021 BREAK_ARGS_HELP ("trace") "\n\
14022 Do \"help tracepoints\" for info on other tracepoint commands."));
14023 set_cmd_completer (c
, location_completer
);
14025 add_com_alias ("tp", "trace", class_alias
, 0);
14026 add_com_alias ("tr", "trace", class_alias
, 1);
14027 add_com_alias ("tra", "trace", class_alias
, 1);
14028 add_com_alias ("trac", "trace", class_alias
, 1);
14030 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14031 Set a fast tracepoint at specified line or function.\n\
14033 BREAK_ARGS_HELP ("ftrace") "\n\
14034 Do \"help tracepoints\" for info on other tracepoint commands."));
14035 set_cmd_completer (c
, location_completer
);
14037 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14038 Set a static tracepoint at specified line, function or marker.\n\
14040 strace [LOCATION] [if CONDITION]\n\
14041 LOCATION may be a line number, function name, \"*\" and an address,\n\
14042 or -m MARKER_ID.\n\
14043 If a line number is specified, probe the marker at start of code\n\
14044 for that line. If a function is specified, probe the marker at start\n\
14045 of code for that function. If an address is specified, probe the marker\n\
14046 at that exact address. If a marker id is specified, probe the marker\n\
14047 with that name. With no LOCATION, uses current execution address of\n\
14048 the selected stack frame.\n\
14049 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14050 This collects arbitrary user data passed in the probe point call to the\n\
14051 tracing library. You can inspect it when analyzing the trace buffer,\n\
14052 by printing the $_sdata variable like any other convenience variable.\n\
14054 CONDITION is a boolean expression.\n\
14056 Multiple tracepoints at one place are permitted, and useful if their\n\
14057 conditions are different.\n\
14059 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14060 Do \"help tracepoints\" for info on other tracepoint commands."));
14061 set_cmd_completer (c
, location_completer
);
14063 add_info ("tracepoints", tracepoints_info
, _("\
14064 Status of specified tracepoints (all tracepoints if no argument).\n\
14065 Convenience variable \"$tpnum\" contains the number of the\n\
14066 last tracepoint set."));
14068 add_info_alias ("tp", "tracepoints", 1);
14070 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14071 Delete specified tracepoints.\n\
14072 Arguments are tracepoint numbers, separated by spaces.\n\
14073 No argument means delete all tracepoints."),
14076 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14077 Disable specified tracepoints.\n\
14078 Arguments are tracepoint numbers, separated by spaces.\n\
14079 No argument means disable all tracepoints."),
14081 deprecate_cmd (c
, "disable");
14083 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14084 Enable specified tracepoints.\n\
14085 Arguments are tracepoint numbers, separated by spaces.\n\
14086 No argument means enable all tracepoints."),
14088 deprecate_cmd (c
, "enable");
14090 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14091 Set the passcount for a tracepoint.\n\
14092 The trace will end when the tracepoint has been passed 'count' times.\n\
14093 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14094 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14096 add_prefix_cmd ("save", class_breakpoint
, save_command
,
14097 _("Save breakpoint definitions as a script."),
14098 &save_cmdlist
, "save ",
14099 0/*allow-unknown*/, &cmdlist
);
14101 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14102 Save current breakpoint definitions as a script.\n\
14103 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14104 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14105 session to restore them."),
14107 set_cmd_completer (c
, filename_completer
);
14109 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14110 Save current tracepoint definitions as a script.\n\
14111 Use the 'source' command in another debug session to restore them."),
14113 set_cmd_completer (c
, filename_completer
);
14115 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
14116 deprecate_cmd (c
, "save tracepoints");
14118 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
14119 Breakpoint specific settings\n\
14120 Configure various breakpoint-specific variables such as\n\
14121 pending breakpoint behavior"),
14122 &breakpoint_set_cmdlist
, "set breakpoint ",
14123 0/*allow-unknown*/, &setlist
);
14124 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
14125 Breakpoint specific settings\n\
14126 Configure various breakpoint-specific variables such as\n\
14127 pending breakpoint behavior"),
14128 &breakpoint_show_cmdlist
, "show breakpoint ",
14129 0/*allow-unknown*/, &showlist
);
14131 add_setshow_auto_boolean_cmd ("pending", no_class
,
14132 &pending_break_support
, _("\
14133 Set debugger's behavior regarding pending breakpoints."), _("\
14134 Show debugger's behavior regarding pending breakpoints."), _("\
14135 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14136 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14137 an error. If auto, an unrecognized breakpoint location results in a\n\
14138 user-query to see if a pending breakpoint should be created."),
14140 show_pending_break_support
,
14141 &breakpoint_set_cmdlist
,
14142 &breakpoint_show_cmdlist
);
14144 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14146 add_setshow_boolean_cmd ("auto-hw", no_class
,
14147 &automatic_hardware_breakpoints
, _("\
14148 Set automatic usage of hardware breakpoints."), _("\
14149 Show automatic usage of hardware breakpoints."), _("\
14150 If set, the debugger will automatically use hardware breakpoints for\n\
14151 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14152 a warning will be emitted for such breakpoints."),
14154 show_automatic_hardware_breakpoints
,
14155 &breakpoint_set_cmdlist
,
14156 &breakpoint_show_cmdlist
);
14158 add_setshow_enum_cmd ("always-inserted", class_support
,
14159 always_inserted_enums
, &always_inserted_mode
, _("\
14160 Set mode for inserting breakpoints."), _("\
14161 Show mode for inserting breakpoints."), _("\
14162 When this mode is off, breakpoints are inserted in inferior when it is\n\
14163 resumed, and removed when execution stops. When this mode is on,\n\
14164 breakpoints are inserted immediately and removed only when the user\n\
14165 deletes the breakpoint. When this mode is auto (which is the default),\n\
14166 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14167 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14168 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14169 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14171 &show_always_inserted_mode
,
14172 &breakpoint_set_cmdlist
,
14173 &breakpoint_show_cmdlist
);
14175 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14176 Set a breakpoint for an address range.\n\
14177 break-range START-LOCATION, END-LOCATION\n\
14178 where START-LOCATION and END-LOCATION can be one of the following:\n\
14179 LINENUM, for that line in the current file,\n\
14180 FILE:LINENUM, for that line in that file,\n\
14181 +OFFSET, for that number of lines after the current line\n\
14182 or the start of the range\n\
14183 FUNCTION, for the first line in that function,\n\
14184 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14185 *ADDRESS, for the instruction at that address.\n\
14187 The breakpoint will stop execution of the inferior whenever it executes\n\
14188 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14189 range (including START-LOCATION and END-LOCATION)."));
14191 automatic_hardware_breakpoints
= 1;
14193 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);