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 target_resources_ok
;
7270 i
= hw_breakpoint_used_count ();
7271 target_resources_ok
=
7272 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7274 if (target_resources_ok
== 0)
7275 error (_("No hardware breakpoint support in the target."));
7276 else if (target_resources_ok
< 0)
7277 error (_("Hardware breakpoints used exceeds limit."));
7280 gdb_assert (sals
.nelts
> 0);
7282 for (i
= 0; i
< sals
.nelts
; ++i
)
7284 struct symtab_and_line sal
= sals
.sals
[i
];
7285 struct bp_location
*loc
;
7289 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7291 loc_gdbarch
= gdbarch
;
7293 describe_other_breakpoints (loc_gdbarch
,
7294 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7299 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7303 b
->cond_string
= cond_string
;
7304 b
->ignore_count
= ignore_count
;
7305 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7306 b
->disposition
= disposition
;
7307 b
->pspace
= sals
.sals
[0].pspace
;
7309 if (type
== bp_static_tracepoint
)
7311 struct tracepoint
*t
= (struct tracepoint
*) b
;
7312 struct static_tracepoint_marker marker
;
7314 if (is_marker_spec (addr_string
))
7316 /* We already know the marker exists, otherwise, we
7317 wouldn't see a sal for it. */
7318 char *p
= &addr_string
[3];
7322 p
= skip_spaces (p
);
7324 endp
= skip_to_space (p
);
7326 marker_str
= savestring (p
, endp
- p
);
7327 t
->static_trace_marker_id
= marker_str
;
7329 printf_filtered (_("Probed static tracepoint "
7331 t
->static_trace_marker_id
);
7333 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7335 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7336 release_static_tracepoint_marker (&marker
);
7338 printf_filtered (_("Probed static tracepoint "
7340 t
->static_trace_marker_id
);
7343 warning (_("Couldn't determine the static "
7344 "tracepoint marker to probe"));
7347 if (enabled
&& b
->pspace
->executing_startup
7348 && (b
->type
== bp_breakpoint
7349 || b
->type
== bp_hardware_breakpoint
))
7350 b
->enable_state
= bp_startup_disabled
;
7356 loc
= add_location_to_breakpoint (b
, &sal
);
7359 if (bp_loc_is_permanent (loc
))
7360 make_breakpoint_permanent (b
);
7364 char *arg
= b
->cond_string
;
7365 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7367 error (_("Garbage %s follows condition"), arg
);
7371 b
->display_canonical
= display_canonical
;
7373 b
->addr_string
= addr_string
;
7375 /* addr_string has to be used or breakpoint_re_set will delete
7378 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7382 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7383 struct symtabs_and_lines sals
, char *addr_string
,
7385 enum bptype type
, enum bpdisp disposition
,
7386 int thread
, int task
, int ignore_count
,
7387 const struct breakpoint_ops
*ops
, int from_tty
,
7388 int enabled
, int internal
, int display_canonical
)
7390 struct breakpoint
*b
;
7391 struct cleanup
*old_chain
;
7393 if (is_tracepoint_type (type
))
7395 struct tracepoint
*t
;
7397 t
= XCNEW (struct tracepoint
);
7401 b
= XNEW (struct breakpoint
);
7403 old_chain
= make_cleanup (xfree
, b
);
7405 init_breakpoint_sal (b
, gdbarch
,
7409 thread
, task
, ignore_count
,
7411 enabled
, internal
, display_canonical
);
7412 discard_cleanups (old_chain
);
7414 install_breakpoint (internal
, b
, 0);
7417 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7418 elements to fill the void space. */
7420 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7422 int i
= index_to_remove
+1;
7423 int last_index
= sal
->nelts
-1;
7425 for (;i
<= last_index
; ++i
)
7426 sal
->sals
[i
-1] = sal
->sals
[i
];
7431 /* If appropriate, obtains all sals that correspond to the same file
7432 and line as SAL, in all program spaces. Users debugging with IDEs,
7433 will want to set a breakpoint at foo.c:line, and not really care
7434 about program spaces. This is done only if SAL does not have
7435 explicit PC and has line and file information. If we got just a
7436 single expanded sal, return the original.
7438 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7439 which the name of enclosing function is different from SAL. This
7440 makes sure that if we have breakpoint originally set in template
7441 instantiation, say foo<int>(), we won't expand SAL to locations at
7442 the same line in all existing instantiations of 'foo'. */
7444 static struct symtabs_and_lines
7445 expand_line_sal_maybe (struct symtab_and_line sal
)
7447 struct symtabs_and_lines expanded
;
7448 CORE_ADDR original_pc
= sal
.pc
;
7449 char *original_function
= NULL
;
7452 struct cleanup
*old_chain
;
7454 /* If we have explicit pc, don't expand.
7455 If we have no line number, we can't expand. */
7456 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7459 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7460 expanded
.sals
[0] = sal
;
7466 old_chain
= save_current_space_and_thread ();
7468 switch_to_program_space_and_thread (sal
.pspace
);
7470 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7472 /* Note that expand_line_sal visits *all* program spaces. */
7473 expanded
= expand_line_sal (sal
);
7475 if (expanded
.nelts
== 1)
7477 /* We had one sal, we got one sal. Return that sal, adjusting it
7478 past the function prologue if necessary. */
7479 xfree (expanded
.sals
);
7481 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7482 sal
.pc
= original_pc
;
7483 expanded
.sals
[0] = sal
;
7484 skip_prologue_sal (&expanded
.sals
[0]);
7485 do_cleanups (old_chain
);
7489 if (!sal
.explicit_line
)
7491 CORE_ADDR func_addr
, func_end
;
7492 for (i
= 0; i
< expanded
.nelts
; ++i
)
7494 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7495 char *this_function
;
7497 /* We need to switch threads as well since we're about to
7499 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7501 if (find_pc_partial_function (pc
, &this_function
,
7502 &func_addr
, &func_end
))
7505 && strcmp (this_function
, original_function
) != 0)
7507 remove_sal (&expanded
, i
);
7514 /* Skip the function prologue if necessary. */
7515 for (i
= 0; i
< expanded
.nelts
; ++i
)
7516 skip_prologue_sal (&expanded
.sals
[i
]);
7518 do_cleanups (old_chain
);
7520 if (expanded
.nelts
<= 1)
7522 /* This is an ugly workaround. If we get zero expanded sals
7523 then something is really wrong. Fix that by returning the
7526 xfree (expanded
.sals
);
7528 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7529 sal
.pc
= original_pc
;
7530 expanded
.sals
[0] = sal
;
7537 for (i
= 0; i
< expanded
.nelts
; ++i
)
7538 if (expanded
.sals
[i
].pc
== original_pc
)
7549 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7550 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7551 value. COND_STRING, if not NULL, specified the condition to be
7552 used for all breakpoints. Essentially the only case where
7553 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7554 function. In that case, it's still not possible to specify
7555 separate conditions for different overloaded functions, so
7556 we take just a single condition string.
7558 NOTE: If the function succeeds, the caller is expected to cleanup
7559 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7560 array contents). If the function fails (error() is called), the
7561 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7562 COND and SALS arrays and each of those arrays contents. */
7565 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7566 struct symtabs_and_lines sals
,
7567 struct linespec_result
*canonical
,
7569 enum bptype type
, enum bpdisp disposition
,
7570 int thread
, int task
, int ignore_count
,
7571 const struct breakpoint_ops
*ops
, int from_tty
,
7572 int enabled
, int internal
)
7576 for (i
= 0; i
< sals
.nelts
; ++i
)
7578 struct symtabs_and_lines expanded
=
7579 expand_line_sal_maybe (sals
.sals
[i
]);
7581 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7582 cond_string
, type
, disposition
,
7583 thread
, task
, ignore_count
, ops
,
7584 from_tty
, enabled
, internal
,
7585 canonical
->special_display
);
7589 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7590 followed by conditionals. On return, SALS contains an array of SAL
7591 addresses found. ADDR_STRING contains a vector of (canonical)
7592 address strings. ADDRESS points to the end of the SAL.
7594 The array and the line spec strings are allocated on the heap, it is
7595 the caller's responsibility to free them. */
7598 parse_breakpoint_sals (char **address
,
7599 struct symtabs_and_lines
*sals
,
7600 struct linespec_result
*canonical
)
7602 char *addr_start
= *address
;
7604 /* If no arg given, or if first arg is 'if ', use the default
7606 if ((*address
) == NULL
7607 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7609 /* The last displayed codepoint, if it's valid, is our default breakpoint
7611 if (last_displayed_sal_is_valid ())
7613 struct symtab_and_line sal
;
7615 init_sal (&sal
); /* Initialize to zeroes. */
7616 sals
->sals
= (struct symtab_and_line
*)
7617 xmalloc (sizeof (struct symtab_and_line
));
7619 /* Set sal's pspace, pc, symtab, and line to the values
7620 corresponding to the last call to print_frame_info. */
7621 get_last_displayed_sal (&sal
);
7622 sal
.section
= find_pc_overlay (sal
.pc
);
7624 /* "break" without arguments is equivalent to "break *PC"
7625 where PC is the last displayed codepoint's address. So
7626 make sure to set sal.explicit_pc to prevent GDB from
7627 trying to expand the list of sals to include all other
7628 instances with the same symtab and line. */
7629 sal
.explicit_pc
= 1;
7631 sals
->sals
[0] = sal
;
7635 error (_("No default breakpoint address now."));
7639 /* Force almost all breakpoints to be in terms of the
7640 current_source_symtab (which is decode_line_1's default).
7641 This should produce the results we want almost all of the
7642 time while leaving the last displayed codepoint pointers
7645 ObjC: However, don't match an Objective-C method name which
7646 may have a '+' or '-' succeeded by a '[' */
7648 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7650 if (last_displayed_sal_is_valid ()
7652 || ((strchr ("+-", (*address
)[0]) != NULL
)
7653 && ((*address
)[1] != '['))))
7654 *sals
= decode_line_1 (address
, 1,
7655 get_last_displayed_symtab (),
7656 get_last_displayed_line (),
7659 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7662 /* For any SAL that didn't have a canonical string, fill one in. */
7663 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7664 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7665 if (addr_start
!= (*address
))
7669 for (i
= 0; i
< sals
->nelts
; i
++)
7671 /* Add the string if not present. */
7672 if (canonical
->canonical
[i
] == NULL
)
7673 canonical
->canonical
[i
] = savestring (addr_start
,
7674 (*address
) - addr_start
);
7680 /* Convert each SAL into a real PC. Verify that the PC can be
7681 inserted as a breakpoint. If it can't throw an error. */
7684 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7688 for (i
= 0; i
< sals
->nelts
; i
++)
7689 resolve_sal_pc (&sals
->sals
[i
]);
7692 /* Fast tracepoints may have restrictions on valid locations. For
7693 instance, a fast tracepoint using a jump instead of a trap will
7694 likely have to overwrite more bytes than a trap would, and so can
7695 only be placed where the instruction is longer than the jump, or a
7696 multi-instruction sequence does not have a jump into the middle of
7700 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7701 struct symtabs_and_lines
*sals
)
7704 struct symtab_and_line
*sal
;
7706 struct cleanup
*old_chain
;
7708 for (i
= 0; i
< sals
->nelts
; i
++)
7710 sal
= &sals
->sals
[i
];
7712 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7714 old_chain
= make_cleanup (xfree
, msg
);
7717 error (_("May not have a fast tracepoint at 0x%s%s"),
7718 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7720 do_cleanups (old_chain
);
7724 /* Given TOK, a string specification of condition and thread, as
7725 accepted by the 'break' command, extract the condition
7726 string and thread number and set *COND_STRING and *THREAD.
7727 PC identifies the context at which the condition should be parsed.
7728 If no condition is found, *COND_STRING is set to NULL.
7729 If no thread is found, *THREAD is set to -1. */
7731 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7732 char **cond_string
, int *thread
, int *task
)
7734 *cond_string
= NULL
;
7740 char *cond_start
= NULL
;
7741 char *cond_end
= NULL
;
7743 tok
= skip_spaces (tok
);
7745 end_tok
= skip_to_space (tok
);
7747 toklen
= end_tok
- tok
;
7749 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7751 struct expression
*expr
;
7753 tok
= cond_start
= end_tok
+ 1;
7754 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7757 *cond_string
= savestring (cond_start
,
7758 cond_end
- cond_start
);
7760 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7766 *thread
= strtol (tok
, &tok
, 0);
7768 error (_("Junk after thread keyword."));
7769 if (!valid_thread_id (*thread
))
7770 error (_("Unknown thread %d."), *thread
);
7772 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7778 *task
= strtol (tok
, &tok
, 0);
7780 error (_("Junk after task keyword."));
7781 if (!valid_task_id (*task
))
7782 error (_("Unknown task %d."), *task
);
7785 error (_("Junk at end of arguments."));
7789 /* Decode a static tracepoint marker spec. */
7791 static struct symtabs_and_lines
7792 decode_static_tracepoint_spec (char **arg_p
)
7794 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7795 struct symtabs_and_lines sals
;
7796 struct symtab_and_line sal
;
7798 struct cleanup
*old_chain
;
7799 char *p
= &(*arg_p
)[3];
7804 p
= skip_spaces (p
);
7806 endp
= skip_to_space (p
);
7808 marker_str
= savestring (p
, endp
- p
);
7809 old_chain
= make_cleanup (xfree
, marker_str
);
7811 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7812 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7813 error (_("No known static tracepoint marker named %s"), marker_str
);
7815 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7816 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7818 for (i
= 0; i
< sals
.nelts
; i
++)
7820 struct static_tracepoint_marker
*marker
;
7822 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7824 init_sal (&sals
.sals
[i
]);
7826 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7827 sals
.sals
[i
].pc
= marker
->address
;
7829 release_static_tracepoint_marker (marker
);
7832 do_cleanups (old_chain
);
7838 /* Set a breakpoint. This function is shared between CLI and MI
7839 functions for setting a breakpoint. This function has two major
7840 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7841 parameter. If non-zero, the function will parse arg, extracting
7842 breakpoint location, address and thread. Otherwise, ARG is just
7843 the location of breakpoint, with condition and thread specified by
7844 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7845 the breakpoint number will be allocated from the internal
7846 breakpoint count. Returns true if any breakpoint was created;
7850 create_breakpoint (struct gdbarch
*gdbarch
,
7851 char *arg
, char *cond_string
, int thread
,
7852 int parse_condition_and_thread
,
7853 int tempflag
, enum bptype type_wanted
,
7855 enum auto_boolean pending_break_support
,
7856 const struct breakpoint_ops
*ops
,
7857 int from_tty
, int enabled
, int internal
)
7859 volatile struct gdb_exception e
;
7860 struct symtabs_and_lines sals
;
7861 struct symtab_and_line pending_sal
;
7863 char *addr_start
= arg
;
7864 struct linespec_result canonical
;
7865 struct cleanup
*old_chain
;
7866 struct cleanup
*bkpt_chain
= NULL
;
7870 int prev_bkpt_count
= breakpoint_count
;
7872 gdb_assert (ops
!= NULL
);
7876 init_linespec_result (&canonical
);
7878 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7882 sals
= decode_static_tracepoint_spec (&arg
);
7884 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7885 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7886 for (i
= 0; i
< sals
.nelts
; i
++)
7887 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7891 TRY_CATCH (e
, RETURN_MASK_ALL
)
7893 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7896 /* If caller is interested in rc value from parse, set value. */
7900 throw_exception (e
);
7904 case NOT_FOUND_ERROR
:
7906 /* If pending breakpoint support is turned off, throw
7909 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7910 throw_exception (e
);
7912 exception_print (gdb_stderr
, e
);
7914 /* If pending breakpoint support is auto query and the user
7915 selects no, then simply return the error code. */
7916 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7917 && !nquery (_("Make %s pending on future shared library load? "),
7918 bptype_string (type_wanted
)))
7921 /* At this point, either the user was queried about setting
7922 a pending breakpoint and selected yes, or pending
7923 breakpoint behavior is on and thus a pending breakpoint
7924 is defaulted on behalf of the user. */
7925 copy_arg
= xstrdup (addr_start
);
7926 canonical
.canonical
= ©_arg
;
7928 sals
.sals
= &pending_sal
;
7933 throw_exception (e
);
7943 /* Create a chain of things that always need to be cleaned up. */
7944 old_chain
= make_cleanup (null_cleanup
, 0);
7948 /* Make sure that all storage allocated to SALS gets freed. */
7949 make_cleanup (xfree
, sals
.sals
);
7951 /* Cleanup the canonical array but not its contents. */
7952 make_cleanup (xfree
, canonical
.canonical
);
7955 /* ----------------------------- SNIP -----------------------------
7956 Anything added to the cleanup chain beyond this point is assumed
7957 to be part of a breakpoint. If the breakpoint create succeeds
7958 then the memory is not reclaimed. */
7959 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7961 /* Mark the contents of the canonical for cleanup. These go on
7962 the bkpt_chain and only occur if the breakpoint create fails. */
7963 for (i
= 0; i
< sals
.nelts
; i
++)
7965 if (canonical
.canonical
[i
] != NULL
)
7966 make_cleanup (xfree
, canonical
.canonical
[i
]);
7969 /* Resolve all line numbers to PC's and verify that the addresses
7970 are ok for the target. */
7972 breakpoint_sals_to_pc (&sals
);
7974 /* Fast tracepoints may have additional restrictions on location. */
7975 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
7976 check_fast_tracepoint_sals (gdbarch
, &sals
);
7978 /* Verify that condition can be parsed, before setting any
7979 breakpoints. Allocate a separate condition expression for each
7983 if (parse_condition_and_thread
)
7985 /* Here we only parse 'arg' to separate condition
7986 from thread number, so parsing in context of first
7987 sal is OK. When setting the breakpoint we'll
7988 re-parse it in context of each sal. */
7991 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7994 make_cleanup (xfree
, cond_string
);
7998 /* Create a private copy of condition string. */
8001 cond_string
= xstrdup (cond_string
);
8002 make_cleanup (xfree
, cond_string
);
8006 /* If the user is creating a static tracepoint by marker id
8007 (strace -m MARKER_ID), then store the sals index, so that
8008 breakpoint_re_set can try to match up which of the newly
8009 found markers corresponds to this one, and, don't try to
8010 expand multiple locations for each sal, given than SALS
8011 already should contain all sals for MARKER_ID. */
8012 if (type_wanted
== bp_static_tracepoint
8013 && is_marker_spec (canonical
.canonical
[0]))
8017 for (i
= 0; i
< sals
.nelts
; ++i
)
8019 struct symtabs_and_lines expanded
;
8020 struct tracepoint
*tp
;
8021 struct cleanup
*old_chain
;
8024 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
8025 expanded
.sals
[0] = sals
.sals
[i
];
8026 old_chain
= make_cleanup (xfree
, expanded
.sals
);
8028 tp
= XCNEW (struct tracepoint
);
8029 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
8030 canonical
.canonical
[i
],
8031 cond_string
, type_wanted
,
8032 tempflag
? disp_del
: disp_donttouch
,
8033 thread
, task
, ignore_count
, ops
,
8034 from_tty
, enabled
, internal
,
8035 canonical
.special_display
);
8036 /* Given that its possible to have multiple markers with
8037 the same string id, if the user is creating a static
8038 tracepoint by marker id ("strace -m MARKER_ID"), then
8039 store the sals index, so that breakpoint_re_set can
8040 try to match up which of the newly found markers
8041 corresponds to this one */
8042 tp
->static_trace_marker_id_idx
= i
;
8044 install_breakpoint (internal
, &tp
->base
, 0);
8046 do_cleanups (old_chain
);
8050 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
8052 tempflag
? disp_del
: disp_donttouch
,
8053 thread
, task
, ignore_count
, ops
, from_tty
,
8058 struct breakpoint
*b
;
8060 make_cleanup (xfree
, copy_arg
);
8062 if (is_tracepoint_type (type_wanted
))
8064 struct tracepoint
*t
;
8066 t
= XCNEW (struct tracepoint
);
8070 b
= XNEW (struct breakpoint
);
8072 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
8074 b
->addr_string
= canonical
.canonical
[0];
8075 b
->cond_string
= NULL
;
8076 b
->ignore_count
= ignore_count
;
8077 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8078 b
->condition_not_parsed
= 1;
8079 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8080 b
->pspace
= current_program_space
;
8082 if (enabled
&& b
->pspace
->executing_startup
8083 && (b
->type
== bp_breakpoint
8084 || b
->type
== bp_hardware_breakpoint
))
8085 b
->enable_state
= bp_startup_disabled
;
8087 install_breakpoint (internal
, b
, 0);
8092 warning (_("Multiple breakpoints were set.\nUse the "
8093 "\"delete\" command to delete unwanted breakpoints."));
8094 prev_breakpoint_count
= prev_bkpt_count
;
8097 /* That's it. Discard the cleanups for data inserted into the
8099 discard_cleanups (bkpt_chain
);
8100 /* But cleanup everything else. */
8101 do_cleanups (old_chain
);
8103 /* error call may happen here - have BKPT_CHAIN already discarded. */
8104 update_global_location_list (1);
8109 /* Set a breakpoint.
8110 ARG is a string describing breakpoint address,
8111 condition, and thread.
8112 FLAG specifies if a breakpoint is hardware on,
8113 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8117 break_command_1 (char *arg
, int flag
, int from_tty
)
8119 int tempflag
= flag
& BP_TEMPFLAG
;
8120 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8121 ? bp_hardware_breakpoint
8124 create_breakpoint (get_current_arch (),
8126 NULL
, 0, 1 /* parse arg */,
8127 tempflag
, type_wanted
,
8128 0 /* Ignore count */,
8129 pending_break_support
,
8130 &bkpt_breakpoint_ops
,
8136 /* Helper function for break_command_1 and disassemble_command. */
8139 resolve_sal_pc (struct symtab_and_line
*sal
)
8143 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8145 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8146 error (_("No line %d in file \"%s\"."),
8147 sal
->line
, sal
->symtab
->filename
);
8150 /* If this SAL corresponds to a breakpoint inserted using a line
8151 number, then skip the function prologue if necessary. */
8152 if (sal
->explicit_line
)
8153 skip_prologue_sal (sal
);
8156 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8158 struct blockvector
*bv
;
8162 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8165 sym
= block_linkage_function (b
);
8168 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8169 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8173 /* It really is worthwhile to have the section, so we'll
8174 just have to look harder. This case can be executed
8175 if we have line numbers but no functions (as can
8176 happen in assembly source). */
8178 struct minimal_symbol
*msym
;
8179 struct cleanup
*old_chain
= save_current_space_and_thread ();
8181 switch_to_program_space_and_thread (sal
->pspace
);
8183 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8185 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8187 do_cleanups (old_chain
);
8194 break_command (char *arg
, int from_tty
)
8196 break_command_1 (arg
, 0, from_tty
);
8200 tbreak_command (char *arg
, int from_tty
)
8202 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8206 hbreak_command (char *arg
, int from_tty
)
8208 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8212 thbreak_command (char *arg
, int from_tty
)
8214 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8218 stop_command (char *arg
, int from_tty
)
8220 printf_filtered (_("Specify the type of breakpoint to set.\n\
8221 Usage: stop in <function | address>\n\
8222 stop at <line>\n"));
8226 stopin_command (char *arg
, int from_tty
)
8230 if (arg
== (char *) NULL
)
8232 else if (*arg
!= '*')
8237 /* Look for a ':'. If this is a line number specification, then
8238 say it is bad, otherwise, it should be an address or
8239 function/method name. */
8240 while (*argptr
&& !hasColon
)
8242 hasColon
= (*argptr
== ':');
8247 badInput
= (*argptr
!= ':'); /* Not a class::method */
8249 badInput
= isdigit (*arg
); /* a simple line number */
8253 printf_filtered (_("Usage: stop in <function | address>\n"));
8255 break_command_1 (arg
, 0, from_tty
);
8259 stopat_command (char *arg
, int from_tty
)
8263 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8270 /* Look for a ':'. If there is a '::' then get out, otherwise
8271 it is probably a line number. */
8272 while (*argptr
&& !hasColon
)
8274 hasColon
= (*argptr
== ':');
8279 badInput
= (*argptr
== ':'); /* we have class::method */
8281 badInput
= !isdigit (*arg
); /* not a line number */
8285 printf_filtered (_("Usage: stop at <line>\n"));
8287 break_command_1 (arg
, 0, from_tty
);
8290 /* Implement the "breakpoint_hit" breakpoint_ops method for
8291 ranged breakpoints. */
8294 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8295 struct address_space
*aspace
,
8298 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8299 bl
->length
, aspace
, bp_addr
);
8302 /* Implement the "resources_needed" breakpoint_ops method for
8303 ranged breakpoints. */
8306 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8308 return target_ranged_break_num_registers ();
8311 /* Implement the "print_it" breakpoint_ops method for
8312 ranged breakpoints. */
8314 static enum print_stop_action
8315 print_it_ranged_breakpoint (bpstat bs
)
8317 struct breakpoint
*b
= bs
->breakpoint_at
;
8318 struct bp_location
*bl
= b
->loc
;
8319 struct ui_out
*uiout
= current_uiout
;
8321 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8323 /* Ranged breakpoints have only one location. */
8324 gdb_assert (bl
&& bl
->next
== NULL
);
8326 annotate_breakpoint (b
->number
);
8327 if (b
->disposition
== disp_del
)
8328 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8330 ui_out_text (uiout
, "\nRanged breakpoint ");
8331 if (ui_out_is_mi_like_p (uiout
))
8333 ui_out_field_string (uiout
, "reason",
8334 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8335 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8337 ui_out_field_int (uiout
, "bkptno", b
->number
);
8338 ui_out_text (uiout
, ", ");
8340 return PRINT_SRC_AND_LOC
;
8343 /* Implement the "print_one" breakpoint_ops method for
8344 ranged breakpoints. */
8347 print_one_ranged_breakpoint (struct breakpoint
*b
,
8348 struct bp_location
**last_loc
)
8350 struct bp_location
*bl
= b
->loc
;
8351 struct value_print_options opts
;
8352 struct ui_out
*uiout
= current_uiout
;
8354 /* Ranged breakpoints have only one location. */
8355 gdb_assert (bl
&& bl
->next
== NULL
);
8357 get_user_print_options (&opts
);
8359 if (opts
.addressprint
)
8360 /* We don't print the address range here, it will be printed later
8361 by print_one_detail_ranged_breakpoint. */
8362 ui_out_field_skip (uiout
, "addr");
8364 print_breakpoint_location (b
, bl
);
8368 /* Implement the "print_one_detail" breakpoint_ops method for
8369 ranged breakpoints. */
8372 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8373 struct ui_out
*uiout
)
8375 CORE_ADDR address_start
, address_end
;
8376 struct bp_location
*bl
= b
->loc
;
8377 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8378 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8382 address_start
= bl
->address
;
8383 address_end
= address_start
+ bl
->length
- 1;
8385 ui_out_text (uiout
, "\taddress range: ");
8386 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8387 print_core_address (bl
->gdbarch
, address_start
),
8388 print_core_address (bl
->gdbarch
, address_end
));
8389 ui_out_field_stream (uiout
, "addr", stb
);
8390 ui_out_text (uiout
, "\n");
8392 do_cleanups (cleanup
);
8395 /* Implement the "print_mention" breakpoint_ops method for
8396 ranged breakpoints. */
8399 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8401 struct bp_location
*bl
= b
->loc
;
8402 struct ui_out
*uiout
= current_uiout
;
8405 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8407 if (ui_out_is_mi_like_p (uiout
))
8410 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8411 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8412 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8415 /* Implement the "print_recreate" breakpoint_ops method for
8416 ranged breakpoints. */
8419 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8421 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8422 b
->addr_string_range_end
);
8423 print_recreate_thread (b
, fp
);
8426 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8428 static struct breakpoint_ops ranged_breakpoint_ops
;
8430 /* Find the address where the end of the breakpoint range should be
8431 placed, given the SAL of the end of the range. This is so that if
8432 the user provides a line number, the end of the range is set to the
8433 last instruction of the given line. */
8436 find_breakpoint_range_end (struct symtab_and_line sal
)
8440 /* If the user provided a PC value, use it. Otherwise,
8441 find the address of the end of the given location. */
8442 if (sal
.explicit_pc
)
8449 ret
= find_line_pc_range (sal
, &start
, &end
);
8451 error (_("Could not find location of the end of the range."));
8453 /* find_line_pc_range returns the start of the next line. */
8460 /* Implement the "break-range" CLI command. */
8463 break_range_command (char *arg
, int from_tty
)
8465 char *arg_start
, *addr_string_start
, *addr_string_end
;
8466 struct linespec_result canonical_start
, canonical_end
;
8467 int bp_count
, can_use_bp
, length
;
8469 struct breakpoint
*b
;
8470 struct symtab_and_line sal_start
, sal_end
;
8471 struct symtabs_and_lines sals_start
, sals_end
;
8472 struct cleanup
*cleanup_bkpt
;
8474 /* We don't support software ranged breakpoints. */
8475 if (target_ranged_break_num_registers () < 0)
8476 error (_("This target does not support hardware ranged breakpoints."));
8478 bp_count
= hw_breakpoint_used_count ();
8479 bp_count
+= target_ranged_break_num_registers ();
8480 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8483 error (_("Hardware breakpoints used exceeds limit."));
8485 if (arg
== NULL
|| arg
[0] == '\0')
8486 error(_("No address range specified."));
8488 sals_start
.sals
= NULL
;
8489 sals_start
.nelts
= 0;
8490 init_linespec_result (&canonical_start
);
8492 while (*arg
== ' ' || *arg
== '\t')
8495 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8497 sal_start
= sals_start
.sals
[0];
8498 addr_string_start
= canonical_start
.canonical
[0];
8499 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8500 xfree (sals_start
.sals
);
8501 xfree (canonical_start
.canonical
);
8504 error (_("Too few arguments."));
8505 else if (sals_start
.nelts
== 0)
8506 error (_("Could not find location of the beginning of the range."));
8507 else if (sals_start
.nelts
!= 1)
8508 error (_("Cannot create a ranged breakpoint with multiple locations."));
8510 resolve_sal_pc (&sal_start
);
8512 arg
++; /* Skip the comma. */
8513 while (*arg
== ' ' || *arg
== '\t')
8516 /* Parse the end location. */
8518 sals_end
.sals
= NULL
;
8520 init_linespec_result (&canonical_end
);
8523 /* We call decode_line_1 directly here instead of using
8524 parse_breakpoint_sals because we need to specify the start location's
8525 symtab and line as the default symtab and line for the end of the
8526 range. This makes it possible to have ranges like "foo.c:27, +14",
8527 where +14 means 14 lines from the start location. */
8528 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8531 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8532 if (canonical_end
.canonical
== NULL
)
8533 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8534 /* Add the string if not present. */
8535 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8536 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8538 sal_end
= sals_end
.sals
[0];
8539 addr_string_end
= canonical_end
.canonical
[0];
8540 make_cleanup (xfree
, addr_string_end
);
8541 xfree (sals_end
.sals
);
8542 xfree (canonical_end
.canonical
);
8544 if (sals_end
.nelts
== 0)
8545 error (_("Could not find location of the end of the range."));
8546 else if (sals_end
.nelts
!= 1)
8547 error (_("Cannot create a ranged breakpoint with multiple locations."));
8549 resolve_sal_pc (&sal_end
);
8551 end
= find_breakpoint_range_end (sal_end
);
8552 if (sal_start
.pc
> end
)
8553 error (_("Invalid address range, end precedes start."));
8555 length
= end
- sal_start
.pc
+ 1;
8557 /* Length overflowed. */
8558 error (_("Address range too large."));
8559 else if (length
== 1)
8561 /* This range is simple enough to be handled by
8562 the `hbreak' command. */
8563 hbreak_command (addr_string_start
, 1);
8565 do_cleanups (cleanup_bkpt
);
8570 /* Now set up the breakpoint. */
8571 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8572 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8573 set_breakpoint_count (breakpoint_count
+ 1);
8574 b
->number
= breakpoint_count
;
8575 b
->disposition
= disp_donttouch
;
8576 b
->addr_string
= addr_string_start
;
8577 b
->addr_string_range_end
= addr_string_end
;
8578 b
->loc
->length
= length
;
8580 discard_cleanups (cleanup_bkpt
);
8583 observer_notify_breakpoint_created (b
);
8584 update_global_location_list (1);
8587 /* Return non-zero if EXP is verified as constant. Returned zero
8588 means EXP is variable. Also the constant detection may fail for
8589 some constant expressions and in such case still falsely return
8592 watchpoint_exp_is_const (const struct expression
*exp
)
8600 /* We are only interested in the descriptor of each element. */
8601 operator_length (exp
, i
, &oplenp
, &argsp
);
8604 switch (exp
->elts
[i
].opcode
)
8614 case BINOP_LOGICAL_AND
:
8615 case BINOP_LOGICAL_OR
:
8616 case BINOP_BITWISE_AND
:
8617 case BINOP_BITWISE_IOR
:
8618 case BINOP_BITWISE_XOR
:
8620 case BINOP_NOTEQUAL
:
8636 case TERNOP_SLICE_COUNT
:
8648 case OP_OBJC_NSSTRING
:
8651 case UNOP_LOGICAL_NOT
:
8652 case UNOP_COMPLEMENT
:
8655 /* Unary, binary and ternary operators: We have to check
8656 their operands. If they are constant, then so is the
8657 result of that operation. For instance, if A and B are
8658 determined to be constants, then so is "A + B".
8660 UNOP_IND is one exception to the rule above, because the
8661 value of *ADDR is not necessarily a constant, even when
8666 /* Check whether the associated symbol is a constant.
8668 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8669 possible that a buggy compiler could mark a variable as
8670 constant even when it is not, and TYPE_CONST would return
8671 true in this case, while SYMBOL_CLASS wouldn't.
8673 We also have to check for function symbols because they
8674 are always constant. */
8676 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8678 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8679 && SYMBOL_CLASS (s
) != LOC_CONST
8680 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8685 /* The default action is to return 0 because we are using
8686 the optimistic approach here: If we don't know something,
8687 then it is not a constant. */
8696 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8699 dtor_watchpoint (struct breakpoint
*self
)
8701 struct watchpoint
*w
= (struct watchpoint
*) self
;
8703 xfree (w
->cond_exp
);
8705 xfree (w
->exp_string
);
8706 xfree (w
->exp_string_reparse
);
8707 value_free (w
->val
);
8709 base_breakpoint_ops
.dtor (self
);
8712 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8715 re_set_watchpoint (struct breakpoint
*b
)
8717 struct watchpoint
*w
= (struct watchpoint
*) b
;
8719 /* Watchpoint can be either on expression using entirely global
8720 variables, or it can be on local variables.
8722 Watchpoints of the first kind are never auto-deleted, and even
8723 persist across program restarts. Since they can use variables
8724 from shared libraries, we need to reparse expression as libraries
8725 are loaded and unloaded.
8727 Watchpoints on local variables can also change meaning as result
8728 of solib event. For example, if a watchpoint uses both a local
8729 and a global variables in expression, it's a local watchpoint,
8730 but unloading of a shared library will make the expression
8731 invalid. This is not a very common use case, but we still
8732 re-evaluate expression, to avoid surprises to the user.
8734 Note that for local watchpoints, we re-evaluate it only if
8735 watchpoints frame id is still valid. If it's not, it means the
8736 watchpoint is out of scope and will be deleted soon. In fact,
8737 I'm not sure we'll ever be called in this case.
8739 If a local watchpoint's frame id is still valid, then
8740 w->exp_valid_block is likewise valid, and we can safely use it.
8742 Don't do anything about disabled watchpoints, since they will be
8743 reevaluated again when enabled. */
8744 update_watchpoint (w
, 1 /* reparse */);
8747 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8750 insert_watchpoint (struct bp_location
*bl
)
8752 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8753 int length
= w
->exact
? 1 : bl
->length
;
8755 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8759 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8762 remove_watchpoint (struct bp_location
*bl
)
8764 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8765 int length
= w
->exact
? 1 : bl
->length
;
8767 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8772 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8773 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8775 struct breakpoint
*b
= bl
->owner
;
8776 struct watchpoint
*w
= (struct watchpoint
*) b
;
8778 /* Continuable hardware watchpoints are treated as non-existent if the
8779 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8780 some data address). Otherwise gdb won't stop on a break instruction
8781 in the code (not from a breakpoint) when a hardware watchpoint has
8782 been defined. Also skip watchpoints which we know did not trigger
8783 (did not match the data address). */
8784 if (is_hardware_watchpoint (b
)
8785 && w
->watchpoint_triggered
== watch_triggered_no
)
8792 check_status_watchpoint (bpstat bs
)
8794 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8796 bpstat_check_watchpoint (bs
);
8799 /* Implement the "resources_needed" breakpoint_ops method for
8800 hardware watchpoints. */
8803 resources_needed_watchpoint (const struct bp_location
*bl
)
8805 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8806 int length
= w
->exact
? 1 : bl
->length
;
8808 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8811 /* Implement the "works_in_software_mode" breakpoint_ops method for
8812 hardware watchpoints. */
8815 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8817 /* Read and access watchpoints only work with hardware support. */
8818 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8821 static enum print_stop_action
8822 print_it_watchpoint (bpstat bs
)
8824 struct cleanup
*old_chain
;
8825 struct breakpoint
*b
;
8826 const struct bp_location
*bl
;
8827 struct ui_stream
*stb
;
8828 enum print_stop_action result
;
8829 struct watchpoint
*w
;
8830 struct ui_out
*uiout
= current_uiout
;
8832 gdb_assert (bs
->bp_location_at
!= NULL
);
8834 bl
= bs
->bp_location_at
;
8835 b
= bs
->breakpoint_at
;
8836 w
= (struct watchpoint
*) b
;
8838 stb
= ui_out_stream_new (uiout
);
8839 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8844 case bp_hardware_watchpoint
:
8845 annotate_watchpoint (b
->number
);
8846 if (ui_out_is_mi_like_p (uiout
))
8849 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8851 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8852 ui_out_text (uiout
, "\nOld value = ");
8853 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8854 ui_out_field_stream (uiout
, "old", stb
);
8855 ui_out_text (uiout
, "\nNew value = ");
8856 watchpoint_value_print (w
->val
, stb
->stream
);
8857 ui_out_field_stream (uiout
, "new", stb
);
8858 ui_out_text (uiout
, "\n");
8859 /* More than one watchpoint may have been triggered. */
8860 result
= PRINT_UNKNOWN
;
8863 case bp_read_watchpoint
:
8864 if (ui_out_is_mi_like_p (uiout
))
8867 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8869 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8870 ui_out_text (uiout
, "\nValue = ");
8871 watchpoint_value_print (w
->val
, stb
->stream
);
8872 ui_out_field_stream (uiout
, "value", stb
);
8873 ui_out_text (uiout
, "\n");
8874 result
= PRINT_UNKNOWN
;
8877 case bp_access_watchpoint
:
8878 if (bs
->old_val
!= NULL
)
8880 annotate_watchpoint (b
->number
);
8881 if (ui_out_is_mi_like_p (uiout
))
8884 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8886 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8887 ui_out_text (uiout
, "\nOld value = ");
8888 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8889 ui_out_field_stream (uiout
, "old", stb
);
8890 ui_out_text (uiout
, "\nNew value = ");
8895 if (ui_out_is_mi_like_p (uiout
))
8898 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8899 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8900 ui_out_text (uiout
, "\nValue = ");
8902 watchpoint_value_print (w
->val
, stb
->stream
);
8903 ui_out_field_stream (uiout
, "new", stb
);
8904 ui_out_text (uiout
, "\n");
8905 result
= PRINT_UNKNOWN
;
8908 result
= PRINT_UNKNOWN
;
8911 do_cleanups (old_chain
);
8915 /* Implement the "print_mention" breakpoint_ops method for hardware
8919 print_mention_watchpoint (struct breakpoint
*b
)
8921 struct cleanup
*ui_out_chain
;
8922 struct watchpoint
*w
= (struct watchpoint
*) b
;
8923 struct ui_out
*uiout
= current_uiout
;
8928 ui_out_text (uiout
, "Watchpoint ");
8929 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8931 case bp_hardware_watchpoint
:
8932 ui_out_text (uiout
, "Hardware watchpoint ");
8933 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8935 case bp_read_watchpoint
:
8936 ui_out_text (uiout
, "Hardware read watchpoint ");
8937 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8939 case bp_access_watchpoint
:
8940 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8941 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8944 internal_error (__FILE__
, __LINE__
,
8945 _("Invalid hardware watchpoint type."));
8948 ui_out_field_int (uiout
, "number", b
->number
);
8949 ui_out_text (uiout
, ": ");
8950 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8951 do_cleanups (ui_out_chain
);
8954 /* Implement the "print_recreate" breakpoint_ops method for
8958 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8960 struct watchpoint
*w
= (struct watchpoint
*) b
;
8965 case bp_hardware_watchpoint
:
8966 fprintf_unfiltered (fp
, "watch");
8968 case bp_read_watchpoint
:
8969 fprintf_unfiltered (fp
, "rwatch");
8971 case bp_access_watchpoint
:
8972 fprintf_unfiltered (fp
, "awatch");
8975 internal_error (__FILE__
, __LINE__
,
8976 _("Invalid watchpoint type."));
8979 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8980 print_recreate_thread (b
, fp
);
8983 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8985 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8987 /* Implement the "insert" breakpoint_ops method for
8988 masked hardware watchpoints. */
8991 insert_masked_watchpoint (struct bp_location
*bl
)
8993 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8995 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8996 bl
->watchpoint_type
);
8999 /* Implement the "remove" breakpoint_ops method for
9000 masked hardware watchpoints. */
9003 remove_masked_watchpoint (struct bp_location
*bl
)
9005 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9007 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9008 bl
->watchpoint_type
);
9011 /* Implement the "resources_needed" breakpoint_ops method for
9012 masked hardware watchpoints. */
9015 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
9017 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9019 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
9022 /* Implement the "works_in_software_mode" breakpoint_ops method for
9023 masked hardware watchpoints. */
9026 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
9031 /* Implement the "print_it" breakpoint_ops method for
9032 masked hardware watchpoints. */
9034 static enum print_stop_action
9035 print_it_masked_watchpoint (bpstat bs
)
9037 struct breakpoint
*b
= bs
->breakpoint_at
;
9038 struct ui_out
*uiout
= current_uiout
;
9040 /* Masked watchpoints have only one location. */
9041 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9045 case bp_hardware_watchpoint
:
9046 annotate_watchpoint (b
->number
);
9047 if (ui_out_is_mi_like_p (uiout
))
9050 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9053 case bp_read_watchpoint
:
9054 if (ui_out_is_mi_like_p (uiout
))
9057 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9060 case bp_access_watchpoint
:
9061 if (ui_out_is_mi_like_p (uiout
))
9064 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9067 internal_error (__FILE__
, __LINE__
,
9068 _("Invalid hardware watchpoint type."));
9072 ui_out_text (uiout
, _("\n\
9073 Check the underlying instruction at PC for the memory\n\
9074 address and value which triggered this watchpoint.\n"));
9075 ui_out_text (uiout
, "\n");
9077 /* More than one watchpoint may have been triggered. */
9078 return PRINT_UNKNOWN
;
9081 /* Implement the "print_one_detail" breakpoint_ops method for
9082 masked hardware watchpoints. */
9085 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
9086 struct ui_out
*uiout
)
9088 struct watchpoint
*w
= (struct watchpoint
*) b
;
9090 /* Masked watchpoints have only one location. */
9091 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9093 ui_out_text (uiout
, "\tmask ");
9094 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
9095 ui_out_text (uiout
, "\n");
9098 /* Implement the "print_mention" breakpoint_ops method for
9099 masked hardware watchpoints. */
9102 print_mention_masked_watchpoint (struct breakpoint
*b
)
9104 struct watchpoint
*w
= (struct watchpoint
*) b
;
9105 struct ui_out
*uiout
= current_uiout
;
9106 struct cleanup
*ui_out_chain
;
9110 case bp_hardware_watchpoint
:
9111 ui_out_text (uiout
, "Masked hardware watchpoint ");
9112 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9114 case bp_read_watchpoint
:
9115 ui_out_text (uiout
, "Masked hardware read watchpoint ");
9116 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9118 case bp_access_watchpoint
:
9119 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
9120 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9123 internal_error (__FILE__
, __LINE__
,
9124 _("Invalid hardware watchpoint type."));
9127 ui_out_field_int (uiout
, "number", b
->number
);
9128 ui_out_text (uiout
, ": ");
9129 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9130 do_cleanups (ui_out_chain
);
9133 /* Implement the "print_recreate" breakpoint_ops method for
9134 masked hardware watchpoints. */
9137 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9139 struct watchpoint
*w
= (struct watchpoint
*) b
;
9144 case bp_hardware_watchpoint
:
9145 fprintf_unfiltered (fp
, "watch");
9147 case bp_read_watchpoint
:
9148 fprintf_unfiltered (fp
, "rwatch");
9150 case bp_access_watchpoint
:
9151 fprintf_unfiltered (fp
, "awatch");
9154 internal_error (__FILE__
, __LINE__
,
9155 _("Invalid hardware watchpoint type."));
9158 sprintf_vma (tmp
, w
->hw_wp_mask
);
9159 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
9160 print_recreate_thread (b
, fp
);
9163 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9165 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
9167 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9170 is_masked_watchpoint (const struct breakpoint
*b
)
9172 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
9175 /* accessflag: hw_write: watch write,
9176 hw_read: watch read,
9177 hw_access: watch access (read or write) */
9179 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
9180 int just_location
, int internal
)
9182 volatile struct gdb_exception e
;
9183 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9184 struct expression
*exp
;
9185 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9186 struct value
*val
, *mark
, *result
;
9187 struct frame_info
*frame
;
9188 char *exp_start
= NULL
;
9189 char *exp_end
= NULL
;
9190 char *tok
, *end_tok
;
9192 char *cond_start
= NULL
;
9193 char *cond_end
= NULL
;
9194 enum bptype bp_type
;
9197 /* Flag to indicate whether we are going to use masks for
9198 the hardware watchpoint. */
9201 struct watchpoint
*w
;
9203 /* Make sure that we actually have parameters to parse. */
9204 if (arg
!= NULL
&& arg
[0] != '\0')
9208 /* Look for "parameter value" pairs at the end
9209 of the arguments string. */
9210 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9212 /* Skip whitespace at the end of the argument list. */
9213 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9216 /* Find the beginning of the last token.
9217 This is the value of the parameter. */
9218 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9220 value_start
= tok
+ 1;
9222 /* Skip whitespace. */
9223 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9228 /* Find the beginning of the second to last token.
9229 This is the parameter itself. */
9230 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9233 toklen
= end_tok
- tok
+ 1;
9235 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9237 /* At this point we've found a "thread" token, which means
9238 the user is trying to set a watchpoint that triggers
9239 only in a specific thread. */
9243 error(_("You can specify only one thread."));
9245 /* Extract the thread ID from the next token. */
9246 thread
= strtol (value_start
, &endp
, 0);
9248 /* Check if the user provided a valid numeric value for the
9250 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9251 error (_("Invalid thread ID specification %s."), value_start
);
9253 /* Check if the thread actually exists. */
9254 if (!valid_thread_id (thread
))
9255 error (_("Unknown thread %d."), thread
);
9257 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9259 /* We've found a "mask" token, which means the user wants to
9260 create a hardware watchpoint that is going to have the mask
9262 struct value
*mask_value
, *mark
;
9265 error(_("You can specify only one mask."));
9267 use_mask
= just_location
= 1;
9269 mark
= value_mark ();
9270 mask_value
= parse_to_comma_and_eval (&value_start
);
9271 mask
= value_as_address (mask_value
);
9272 value_free_to_mark (mark
);
9275 /* We didn't recognize what we found. We should stop here. */
9278 /* Truncate the string and get rid of the "parameter value" pair before
9279 the arguments string is parsed by the parse_exp_1 function. */
9284 /* Parse the rest of the arguments. */
9285 innermost_block
= NULL
;
9287 exp
= parse_exp_1 (&arg
, 0, 0);
9289 /* Remove trailing whitespace from the expression before saving it.
9290 This makes the eventual display of the expression string a bit
9292 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9295 /* Checking if the expression is not constant. */
9296 if (watchpoint_exp_is_const (exp
))
9300 len
= exp_end
- exp_start
;
9301 while (len
> 0 && isspace (exp_start
[len
- 1]))
9303 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9306 exp_valid_block
= innermost_block
;
9307 mark
= value_mark ();
9308 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9314 exp_valid_block
= NULL
;
9315 val
= value_addr (result
);
9316 release_value (val
);
9317 value_free_to_mark (mark
);
9321 ret
= target_masked_watch_num_registers (value_as_address (val
),
9324 error (_("This target does not support masked watchpoints."));
9326 error (_("Invalid mask or memory region."));
9329 else if (val
!= NULL
)
9330 release_value (val
);
9332 tok
= skip_spaces (arg
);
9333 end_tok
= skip_to_space (tok
);
9335 toklen
= end_tok
- tok
;
9336 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9338 struct expression
*cond
;
9340 innermost_block
= NULL
;
9341 tok
= cond_start
= end_tok
+ 1;
9342 cond
= parse_exp_1 (&tok
, 0, 0);
9344 /* The watchpoint expression may not be local, but the condition
9345 may still be. E.g.: `watch global if local > 0'. */
9346 cond_exp_valid_block
= innermost_block
;
9352 error (_("Junk at end of command."));
9354 if (accessflag
== hw_read
)
9355 bp_type
= bp_read_watchpoint
;
9356 else if (accessflag
== hw_access
)
9357 bp_type
= bp_access_watchpoint
;
9359 bp_type
= bp_hardware_watchpoint
;
9361 frame
= block_innermost_frame (exp_valid_block
);
9363 /* If the expression is "local", then set up a "watchpoint scope"
9364 breakpoint at the point where we've left the scope of the watchpoint
9365 expression. Create the scope breakpoint before the watchpoint, so
9366 that we will encounter it first in bpstat_stop_status. */
9367 if (exp_valid_block
&& frame
)
9369 if (frame_id_p (frame_unwind_caller_id (frame
)))
9372 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9373 frame_unwind_caller_pc (frame
),
9374 bp_watchpoint_scope
,
9375 &momentary_breakpoint_ops
);
9377 scope_breakpoint
->enable_state
= bp_enabled
;
9379 /* Automatically delete the breakpoint when it hits. */
9380 scope_breakpoint
->disposition
= disp_del
;
9382 /* Only break in the proper frame (help with recursion). */
9383 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9385 /* Set the address at which we will stop. */
9386 scope_breakpoint
->loc
->gdbarch
9387 = frame_unwind_caller_arch (frame
);
9388 scope_breakpoint
->loc
->requested_address
9389 = frame_unwind_caller_pc (frame
);
9390 scope_breakpoint
->loc
->address
9391 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9392 scope_breakpoint
->loc
->requested_address
,
9393 scope_breakpoint
->type
);
9397 /* Now set up the breakpoint. */
9399 w
= XCNEW (struct watchpoint
);
9402 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9403 &masked_watchpoint_breakpoint_ops
);
9405 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9406 &watchpoint_breakpoint_ops
);
9408 b
->disposition
= disp_donttouch
;
9409 b
->pspace
= current_program_space
;
9411 w
->exp_valid_block
= exp_valid_block
;
9412 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9415 struct type
*t
= value_type (val
);
9416 CORE_ADDR addr
= value_as_address (val
);
9419 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9420 name
= type_to_string (t
);
9422 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9423 core_addr_to_string (addr
));
9426 w
->exp_string
= xstrprintf ("-location %.*s",
9427 (int) (exp_end
- exp_start
), exp_start
);
9429 /* The above expression is in C. */
9430 b
->language
= language_c
;
9433 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9437 w
->hw_wp_mask
= mask
;
9446 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9452 w
->watchpoint_frame
= get_frame_id (frame
);
9453 w
->watchpoint_thread
= inferior_ptid
;
9457 w
->watchpoint_frame
= null_frame_id
;
9458 w
->watchpoint_thread
= null_ptid
;
9461 if (scope_breakpoint
!= NULL
)
9463 /* The scope breakpoint is related to the watchpoint. We will
9464 need to act on them together. */
9465 b
->related_breakpoint
= scope_breakpoint
;
9466 scope_breakpoint
->related_breakpoint
= b
;
9470 value_free_to_mark (mark
);
9472 TRY_CATCH (e
, RETURN_MASK_ALL
)
9474 /* Finally update the new watchpoint. This creates the locations
9475 that should be inserted. */
9476 update_watchpoint (w
, 1);
9480 delete_breakpoint (b
);
9481 throw_exception (e
);
9484 install_breakpoint (internal
, b
, 1);
9487 /* Return count of debug registers needed to watch the given expression.
9488 If the watchpoint cannot be handled in hardware return zero. */
9491 can_use_hardware_watchpoint (struct value
*v
)
9493 int found_memory_cnt
= 0;
9494 struct value
*head
= v
;
9496 /* Did the user specifically forbid us to use hardware watchpoints? */
9497 if (!can_use_hw_watchpoints
)
9500 /* Make sure that the value of the expression depends only upon
9501 memory contents, and values computed from them within GDB. If we
9502 find any register references or function calls, we can't use a
9503 hardware watchpoint.
9505 The idea here is that evaluating an expression generates a series
9506 of values, one holding the value of every subexpression. (The
9507 expression a*b+c has five subexpressions: a, b, a*b, c, and
9508 a*b+c.) GDB's values hold almost enough information to establish
9509 the criteria given above --- they identify memory lvalues,
9510 register lvalues, computed values, etcetera. So we can evaluate
9511 the expression, and then scan the chain of values that leaves
9512 behind to decide whether we can detect any possible change to the
9513 expression's final value using only hardware watchpoints.
9515 However, I don't think that the values returned by inferior
9516 function calls are special in any way. So this function may not
9517 notice that an expression involving an inferior function call
9518 can't be watched with hardware watchpoints. FIXME. */
9519 for (; v
; v
= value_next (v
))
9521 if (VALUE_LVAL (v
) == lval_memory
)
9523 if (v
!= head
&& value_lazy (v
))
9524 /* A lazy memory lvalue in the chain is one that GDB never
9525 needed to fetch; we either just used its address (e.g.,
9526 `a' in `a.b') or we never needed it at all (e.g., `a'
9527 in `a,b'). This doesn't apply to HEAD; if that is
9528 lazy then it was not readable, but watch it anyway. */
9532 /* Ahh, memory we actually used! Check if we can cover
9533 it with hardware watchpoints. */
9534 struct type
*vtype
= check_typedef (value_type (v
));
9536 /* We only watch structs and arrays if user asked for it
9537 explicitly, never if they just happen to appear in a
9538 middle of some value chain. */
9540 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9541 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9543 CORE_ADDR vaddr
= value_address (v
);
9547 len
= (target_exact_watchpoints
9548 && is_scalar_type_recursive (vtype
))?
9549 1 : TYPE_LENGTH (value_type (v
));
9551 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9555 found_memory_cnt
+= num_regs
;
9559 else if (VALUE_LVAL (v
) != not_lval
9560 && deprecated_value_modifiable (v
) == 0)
9561 return 0; /* These are values from the history (e.g., $1). */
9562 else if (VALUE_LVAL (v
) == lval_register
)
9563 return 0; /* Cannot watch a register with a HW watchpoint. */
9566 /* The expression itself looks suitable for using a hardware
9567 watchpoint, but give the target machine a chance to reject it. */
9568 return found_memory_cnt
;
9572 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9574 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9577 /* A helper function that looks for an argument at the start of a
9578 string. The argument must also either be at the end of the string,
9579 or be followed by whitespace. Returns 1 if it finds the argument,
9580 0 otherwise. If the argument is found, it updates *STR. */
9583 check_for_argument (char **str
, char *arg
, int arg_len
)
9585 if (strncmp (*str
, arg
, arg_len
) == 0
9586 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9594 /* A helper function that looks for the "-location" argument and then
9595 calls watch_command_1. */
9598 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9600 int just_location
= 0;
9603 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9604 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9606 arg
= skip_spaces (arg
);
9610 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9614 watch_command (char *arg
, int from_tty
)
9616 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9620 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9622 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9626 rwatch_command (char *arg
, int from_tty
)
9628 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9632 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9634 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9638 awatch_command (char *arg
, int from_tty
)
9640 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9644 /* Helper routines for the until_command routine in infcmd.c. Here
9645 because it uses the mechanisms of breakpoints. */
9647 struct until_break_command_continuation_args
9649 struct breakpoint
*breakpoint
;
9650 struct breakpoint
*breakpoint2
;
9654 /* This function is called by fetch_inferior_event via the
9655 cmd_continuation pointer, to complete the until command. It takes
9656 care of cleaning up the temporary breakpoints set up by the until
9659 until_break_command_continuation (void *arg
, int err
)
9661 struct until_break_command_continuation_args
*a
= arg
;
9663 delete_breakpoint (a
->breakpoint
);
9665 delete_breakpoint (a
->breakpoint2
);
9666 delete_longjmp_breakpoint (a
->thread_num
);
9670 until_break_command (char *arg
, int from_tty
, int anywhere
)
9672 struct symtabs_and_lines sals
;
9673 struct symtab_and_line sal
;
9674 struct frame_info
*frame
= get_selected_frame (NULL
);
9675 struct breakpoint
*breakpoint
;
9676 struct breakpoint
*breakpoint2
= NULL
;
9677 struct cleanup
*old_chain
;
9679 struct thread_info
*tp
;
9681 clear_proceed_status ();
9683 /* Set a breakpoint where the user wants it and at return from
9686 if (last_displayed_sal_is_valid ())
9687 sals
= decode_line_1 (&arg
, 1,
9688 get_last_displayed_symtab (),
9689 get_last_displayed_line (),
9692 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9694 if (sals
.nelts
!= 1)
9695 error (_("Couldn't get information on specified line."));
9698 xfree (sals
.sals
); /* malloc'd, so freed. */
9701 error (_("Junk at end of arguments."));
9703 resolve_sal_pc (&sal
);
9706 /* If the user told us to continue until a specified location,
9707 we don't specify a frame at which we need to stop. */
9708 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9709 null_frame_id
, bp_until
);
9711 /* Otherwise, specify the selected frame, because we want to stop
9712 only at the very same frame. */
9713 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9714 get_stack_frame_id (frame
),
9717 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9719 tp
= inferior_thread ();
9722 /* Keep within the current frame, or in frames called by the current
9725 if (frame_id_p (frame_unwind_caller_id (frame
)))
9727 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9728 sal
.pc
= frame_unwind_caller_pc (frame
);
9729 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9731 frame_unwind_caller_id (frame
),
9733 make_cleanup_delete_breakpoint (breakpoint2
);
9735 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9736 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9739 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9741 /* If we are running asynchronously, and proceed call above has
9742 actually managed to start the target, arrange for breakpoints to
9743 be deleted when the target stops. Otherwise, we're already
9744 stopped and delete breakpoints via cleanup chain. */
9746 if (target_can_async_p () && is_running (inferior_ptid
))
9748 struct until_break_command_continuation_args
*args
;
9749 args
= xmalloc (sizeof (*args
));
9751 args
->breakpoint
= breakpoint
;
9752 args
->breakpoint2
= breakpoint2
;
9753 args
->thread_num
= thread
;
9755 discard_cleanups (old_chain
);
9756 add_continuation (inferior_thread (),
9757 until_break_command_continuation
, args
,
9761 do_cleanups (old_chain
);
9764 /* This function attempts to parse an optional "if <cond>" clause
9765 from the arg string. If one is not found, it returns NULL.
9767 Else, it returns a pointer to the condition string. (It does not
9768 attempt to evaluate the string against a particular block.) And,
9769 it updates arg to point to the first character following the parsed
9770 if clause in the arg string. */
9773 ep_parse_optional_if_clause (char **arg
)
9777 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9780 /* Skip the "if" keyword. */
9783 /* Skip any extra leading whitespace, and record the start of the
9784 condition string. */
9785 *arg
= skip_spaces (*arg
);
9788 /* Assume that the condition occupies the remainder of the arg
9790 (*arg
) += strlen (cond_string
);
9795 /* Commands to deal with catching events, such as signals, exceptions,
9796 process start/exit, etc. */
9800 catch_fork_temporary
, catch_vfork_temporary
,
9801 catch_fork_permanent
, catch_vfork_permanent
9806 catch_fork_command_1 (char *arg
, int from_tty
,
9807 struct cmd_list_element
*command
)
9809 struct gdbarch
*gdbarch
= get_current_arch ();
9810 char *cond_string
= NULL
;
9811 catch_fork_kind fork_kind
;
9814 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9815 tempflag
= (fork_kind
== catch_fork_temporary
9816 || fork_kind
== catch_vfork_temporary
);
9820 arg
= skip_spaces (arg
);
9822 /* The allowed syntax is:
9824 catch [v]fork if <cond>
9826 First, check if there's an if clause. */
9827 cond_string
= ep_parse_optional_if_clause (&arg
);
9829 if ((*arg
!= '\0') && !isspace (*arg
))
9830 error (_("Junk at end of arguments."));
9832 /* If this target supports it, create a fork or vfork catchpoint
9833 and enable reporting of such events. */
9836 case catch_fork_temporary
:
9837 case catch_fork_permanent
:
9838 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9839 &catch_fork_breakpoint_ops
);
9841 case catch_vfork_temporary
:
9842 case catch_vfork_permanent
:
9843 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9844 &catch_vfork_breakpoint_ops
);
9847 error (_("unsupported or unknown fork kind; cannot catch it"));
9853 catch_exec_command_1 (char *arg
, int from_tty
,
9854 struct cmd_list_element
*command
)
9856 struct exec_catchpoint
*c
;
9857 struct gdbarch
*gdbarch
= get_current_arch ();
9859 char *cond_string
= NULL
;
9861 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9865 arg
= skip_spaces (arg
);
9867 /* The allowed syntax is:
9869 catch exec if <cond>
9871 First, check if there's an if clause. */
9872 cond_string
= ep_parse_optional_if_clause (&arg
);
9874 if ((*arg
!= '\0') && !isspace (*arg
))
9875 error (_("Junk at end of arguments."));
9877 c
= XNEW (struct exec_catchpoint
);
9878 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9879 &catch_exec_breakpoint_ops
);
9880 c
->exec_pathname
= NULL
;
9882 install_breakpoint (0, &c
->base
, 1);
9885 static enum print_stop_action
9886 print_it_exception_catchpoint (bpstat bs
)
9888 struct ui_out
*uiout
= current_uiout
;
9889 struct breakpoint
*b
= bs
->breakpoint_at
;
9890 int bp_temp
, bp_throw
;
9892 annotate_catchpoint (b
->number
);
9894 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9895 if (b
->loc
->address
!= b
->loc
->requested_address
)
9896 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9899 bp_temp
= b
->disposition
== disp_del
;
9901 bp_temp
? "Temporary catchpoint "
9903 if (!ui_out_is_mi_like_p (uiout
))
9904 ui_out_field_int (uiout
, "bkptno", b
->number
);
9906 bp_throw
? " (exception thrown), "
9907 : " (exception caught), ");
9908 if (ui_out_is_mi_like_p (uiout
))
9910 ui_out_field_string (uiout
, "reason",
9911 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9912 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9913 ui_out_field_int (uiout
, "bkptno", b
->number
);
9915 return PRINT_SRC_AND_LOC
;
9919 print_one_exception_catchpoint (struct breakpoint
*b
,
9920 struct bp_location
**last_loc
)
9922 struct value_print_options opts
;
9923 struct ui_out
*uiout
= current_uiout
;
9925 get_user_print_options (&opts
);
9926 if (opts
.addressprint
)
9929 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9930 ui_out_field_string (uiout
, "addr", "<PENDING>");
9932 ui_out_field_core_addr (uiout
, "addr",
9933 b
->loc
->gdbarch
, b
->loc
->address
);
9938 if (strstr (b
->addr_string
, "throw") != NULL
)
9939 ui_out_field_string (uiout
, "what", "exception throw");
9941 ui_out_field_string (uiout
, "what", "exception catch");
9945 print_mention_exception_catchpoint (struct breakpoint
*b
)
9947 struct ui_out
*uiout
= current_uiout
;
9951 bp_temp
= b
->disposition
== disp_del
;
9952 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9953 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9954 : _("Catchpoint "));
9955 ui_out_field_int (uiout
, "bkptno", b
->number
);
9956 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9960 /* Implement the "print_recreate" breakpoint_ops method for throw and
9961 catch catchpoints. */
9964 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9970 bp_temp
= b
->disposition
== disp_del
;
9971 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9972 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9973 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9974 print_recreate_thread (b
, fp
);
9977 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9980 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9981 enum exception_event_kind ex_event
, int from_tty
)
9983 char *trigger_func_name
;
9985 if (ex_event
== EX_EVENT_CATCH
)
9986 trigger_func_name
= "__cxa_begin_catch";
9988 trigger_func_name
= "__cxa_throw";
9990 create_breakpoint (get_current_arch (),
9991 trigger_func_name
, cond_string
, -1,
9992 0 /* condition and thread are valid. */,
9993 tempflag
, bp_breakpoint
,
9995 AUTO_BOOLEAN_TRUE
/* pending */,
9996 &gnu_v3_exception_catchpoint_ops
, from_tty
,
10003 /* Deal with "catch catch" and "catch throw" commands. */
10006 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
10007 int tempflag
, int from_tty
)
10009 char *cond_string
= NULL
;
10013 arg
= skip_spaces (arg
);
10015 cond_string
= ep_parse_optional_if_clause (&arg
);
10017 if ((*arg
!= '\0') && !isspace (*arg
))
10018 error (_("Junk at end of arguments."));
10020 if (ex_event
!= EX_EVENT_THROW
10021 && ex_event
!= EX_EVENT_CATCH
)
10022 error (_("Unsupported or unknown exception event; cannot catch it"));
10024 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
10027 warning (_("Unsupported with this platform/compiler combination."));
10030 /* Implementation of "catch catch" command. */
10033 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10035 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10037 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
10040 /* Implementation of "catch throw" command. */
10043 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10045 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10047 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
10051 init_ada_exception_breakpoint (struct breakpoint
*b
,
10052 struct gdbarch
*gdbarch
,
10053 struct symtab_and_line sal
,
10055 const struct breakpoint_ops
*ops
,
10061 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10063 loc_gdbarch
= gdbarch
;
10065 describe_other_breakpoints (loc_gdbarch
,
10066 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10067 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10068 version for exception catchpoints, because two catchpoints
10069 used for different exception names will use the same address.
10070 In this case, a "breakpoint ... also set at..." warning is
10071 unproductive. Besides, the warning phrasing is also a bit
10072 inappropriate, we should use the word catchpoint, and tell
10073 the user what type of catchpoint it is. The above is good
10074 enough for now, though. */
10077 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
10079 b
->enable_state
= bp_enabled
;
10080 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10081 b
->addr_string
= addr_string
;
10082 b
->language
= language_ada
;
10085 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10086 filter list, or NULL if no filtering is required. */
10088 catch_syscall_split_args (char *arg
)
10090 VEC(int) *result
= NULL
;
10091 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
10093 while (*arg
!= '\0')
10095 int i
, syscall_number
;
10097 char cur_name
[128];
10100 /* Skip whitespace. */
10101 while (isspace (*arg
))
10104 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
10105 cur_name
[i
] = arg
[i
];
10106 cur_name
[i
] = '\0';
10109 /* Check if the user provided a syscall name or a number. */
10110 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
10111 if (*endptr
== '\0')
10112 get_syscall_by_number (syscall_number
, &s
);
10115 /* We have a name. Let's check if it's valid and convert it
10117 get_syscall_by_name (cur_name
, &s
);
10119 if (s
.number
== UNKNOWN_SYSCALL
)
10120 /* Here we have to issue an error instead of a warning,
10121 because GDB cannot do anything useful if there's no
10122 syscall number to be caught. */
10123 error (_("Unknown syscall name '%s'."), cur_name
);
10126 /* Ok, it's valid. */
10127 VEC_safe_push (int, result
, s
.number
);
10130 discard_cleanups (cleanup
);
10134 /* Implement the "catch syscall" command. */
10137 catch_syscall_command_1 (char *arg
, int from_tty
,
10138 struct cmd_list_element
*command
)
10143 struct gdbarch
*gdbarch
= get_current_arch ();
10145 /* Checking if the feature if supported. */
10146 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
10147 error (_("The feature 'catch syscall' is not supported on \
10148 this architecture yet."));
10150 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10152 arg
= skip_spaces (arg
);
10154 /* We need to do this first "dummy" translation in order
10155 to get the syscall XML file loaded or, most important,
10156 to display a warning to the user if there's no XML file
10157 for his/her architecture. */
10158 get_syscall_by_number (0, &s
);
10160 /* The allowed syntax is:
10162 catch syscall <name | number> [<name | number> ... <name | number>]
10164 Let's check if there's a syscall name. */
10167 filter
= catch_syscall_split_args (arg
);
10171 create_syscall_event_catchpoint (tempflag
, filter
,
10172 &catch_syscall_breakpoint_ops
);
10176 catch_command (char *arg
, int from_tty
)
10178 error (_("Catch requires an event name."));
10183 tcatch_command (char *arg
, int from_tty
)
10185 error (_("Catch requires an event name."));
10188 /* Delete breakpoints by address or line. */
10191 clear_command (char *arg
, int from_tty
)
10193 struct breakpoint
*b
;
10194 VEC(breakpoint_p
) *found
= 0;
10197 struct symtabs_and_lines sals
;
10198 struct symtab_and_line sal
;
10203 sals
= decode_line_spec (arg
, 1);
10208 sals
.sals
= (struct symtab_and_line
*)
10209 xmalloc (sizeof (struct symtab_and_line
));
10210 make_cleanup (xfree
, sals
.sals
);
10211 init_sal (&sal
); /* Initialize to zeroes. */
10213 /* Set sal's line, symtab, pc, and pspace to the values
10214 corresponding to the last call to print_frame_info. If the
10215 codepoint is not valid, this will set all the fields to 0. */
10216 get_last_displayed_sal (&sal
);
10217 if (sal
.symtab
== 0)
10218 error (_("No source file specified."));
10220 sals
.sals
[0] = sal
;
10226 /* We don't call resolve_sal_pc here. That's not as bad as it
10227 seems, because all existing breakpoints typically have both
10228 file/line and pc set. So, if clear is given file/line, we can
10229 match this to existing breakpoint without obtaining pc at all.
10231 We only support clearing given the address explicitly
10232 present in breakpoint table. Say, we've set breakpoint
10233 at file:line. There were several PC values for that file:line,
10234 due to optimization, all in one block.
10236 We've picked one PC value. If "clear" is issued with another
10237 PC corresponding to the same file:line, the breakpoint won't
10238 be cleared. We probably can still clear the breakpoint, but
10239 since the other PC value is never presented to user, user
10240 can only find it by guessing, and it does not seem important
10241 to support that. */
10243 /* For each line spec given, delete bps which correspond to it. Do
10244 it in two passes, solely to preserve the current behavior that
10245 from_tty is forced true if we delete more than one
10249 for (i
= 0; i
< sals
.nelts
; i
++)
10251 /* If exact pc given, clear bpts at that pc.
10252 If line given (pc == 0), clear all bpts on specified line.
10253 If defaulting, clear all bpts on default line
10256 defaulting sal.pc != 0 tests to do
10261 1 0 <can't happen> */
10263 sal
= sals
.sals
[i
];
10265 /* Find all matching breakpoints and add them to 'found'. */
10266 ALL_BREAKPOINTS (b
)
10269 /* Are we going to delete b? */
10270 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10272 struct bp_location
*loc
= b
->loc
;
10273 for (; loc
; loc
= loc
->next
)
10275 int pc_match
= sal
.pc
10276 && (loc
->pspace
== sal
.pspace
)
10277 && (loc
->address
== sal
.pc
)
10278 && (!section_is_overlay (loc
->section
)
10279 || loc
->section
== sal
.section
);
10280 int line_match
= ((default_match
|| (0 == sal
.pc
))
10281 && b
->source_file
!= NULL
10282 && sal
.symtab
!= NULL
10283 && sal
.pspace
== loc
->pspace
10284 && filename_cmp (b
->source_file
,
10285 sal
.symtab
->filename
) == 0
10286 && b
->line_number
== sal
.line
);
10287 if (pc_match
|| line_match
)
10296 VEC_safe_push(breakpoint_p
, found
, b
);
10299 /* Now go thru the 'found' chain and delete them. */
10300 if (VEC_empty(breakpoint_p
, found
))
10303 error (_("No breakpoint at %s."), arg
);
10305 error (_("No breakpoint at this line."));
10308 if (VEC_length(breakpoint_p
, found
) > 1)
10309 from_tty
= 1; /* Always report if deleted more than one. */
10312 if (VEC_length(breakpoint_p
, found
) == 1)
10313 printf_unfiltered (_("Deleted breakpoint "));
10315 printf_unfiltered (_("Deleted breakpoints "));
10317 breakpoints_changed ();
10319 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10322 printf_unfiltered ("%d ", b
->number
);
10323 delete_breakpoint (b
);
10326 putchar_unfiltered ('\n');
10329 /* Delete breakpoint in BS if they are `delete' breakpoints and
10330 all breakpoints that are marked for deletion, whether hit or not.
10331 This is called after any breakpoint is hit, or after errors. */
10334 breakpoint_auto_delete (bpstat bs
)
10336 struct breakpoint
*b
, *b_tmp
;
10338 for (; bs
; bs
= bs
->next
)
10339 if (bs
->breakpoint_at
10340 && bs
->breakpoint_at
->disposition
== disp_del
10342 delete_breakpoint (bs
->breakpoint_at
);
10344 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10346 if (b
->disposition
== disp_del_at_next_stop
)
10347 delete_breakpoint (b
);
10351 /* A comparison function for bp_location AP and BP being interfaced to
10352 qsort. Sort elements primarily by their ADDRESS (no matter what
10353 does breakpoint_address_is_meaningful say for its OWNER),
10354 secondarily by ordering first bp_permanent OWNERed elements and
10355 terciarily just ensuring the array is sorted stable way despite
10356 qsort being an unstable algorithm. */
10359 bp_location_compare (const void *ap
, const void *bp
)
10361 struct bp_location
*a
= *(void **) ap
;
10362 struct bp_location
*b
= *(void **) bp
;
10363 /* A and B come from existing breakpoints having non-NULL OWNER. */
10364 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10365 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10367 if (a
->address
!= b
->address
)
10368 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10370 /* Sort permanent breakpoints first. */
10371 if (a_perm
!= b_perm
)
10372 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10374 /* Make the user-visible order stable across GDB runs. Locations of
10375 the same breakpoint can be sorted in arbitrary order. */
10377 if (a
->owner
->number
!= b
->owner
->number
)
10378 return (a
->owner
->number
> b
->owner
->number
)
10379 - (a
->owner
->number
< b
->owner
->number
);
10381 return (a
> b
) - (a
< b
);
10384 /* Set bp_location_placed_address_before_address_max and
10385 bp_location_shadow_len_after_address_max according to the current
10386 content of the bp_location array. */
10389 bp_location_target_extensions_update (void)
10391 struct bp_location
*bl
, **blp_tmp
;
10393 bp_location_placed_address_before_address_max
= 0;
10394 bp_location_shadow_len_after_address_max
= 0;
10396 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10398 CORE_ADDR start
, end
, addr
;
10400 if (!bp_location_has_shadow (bl
))
10403 start
= bl
->target_info
.placed_address
;
10404 end
= start
+ bl
->target_info
.shadow_len
;
10406 gdb_assert (bl
->address
>= start
);
10407 addr
= bl
->address
- start
;
10408 if (addr
> bp_location_placed_address_before_address_max
)
10409 bp_location_placed_address_before_address_max
= addr
;
10411 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10413 gdb_assert (bl
->address
< end
);
10414 addr
= end
- bl
->address
;
10415 if (addr
> bp_location_shadow_len_after_address_max
)
10416 bp_location_shadow_len_after_address_max
= addr
;
10420 /* Download tracepoint locations if they haven't been. */
10423 download_tracepoint_locations (void)
10425 struct bp_location
*bl
, **blp_tmp
;
10426 struct cleanup
*old_chain
;
10428 if (!target_can_download_tracepoint ())
10431 old_chain
= save_current_space_and_thread ();
10433 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10435 struct tracepoint
*t
;
10437 if (!is_tracepoint (bl
->owner
))
10440 if ((bl
->owner
->type
== bp_fast_tracepoint
10441 ? !may_insert_fast_tracepoints
10442 : !may_insert_tracepoints
))
10445 /* In tracepoint, locations are _never_ duplicated, so
10446 should_be_inserted is equivalent to
10447 unduplicated_should_be_inserted. */
10448 if (!should_be_inserted (bl
) || bl
->inserted
)
10451 switch_to_program_space_and_thread (bl
->pspace
);
10453 target_download_tracepoint (bl
);
10456 t
= (struct tracepoint
*) bl
->owner
;
10457 t
->number_on_target
= bl
->owner
->number
;
10460 do_cleanups (old_chain
);
10463 /* Swap the insertion/duplication state between two locations. */
10466 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10468 const int left_inserted
= left
->inserted
;
10469 const int left_duplicate
= left
->duplicate
;
10470 const struct bp_target_info left_target_info
= left
->target_info
;
10472 /* Locations of tracepoints can never be duplicated. */
10473 if (is_tracepoint (left
->owner
))
10474 gdb_assert (!left
->duplicate
);
10475 if (is_tracepoint (right
->owner
))
10476 gdb_assert (!right
->duplicate
);
10478 left
->inserted
= right
->inserted
;
10479 left
->duplicate
= right
->duplicate
;
10480 left
->target_info
= right
->target_info
;
10481 right
->inserted
= left_inserted
;
10482 right
->duplicate
= left_duplicate
;
10483 right
->target_info
= left_target_info
;
10486 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10487 into the inferior, only remove already-inserted locations that no
10488 longer should be inserted. Functions that delete a breakpoint or
10489 breakpoints should pass false, so that deleting a breakpoint
10490 doesn't have the side effect of inserting the locations of other
10491 breakpoints that are marked not-inserted, but should_be_inserted
10492 returns true on them.
10494 This behaviour is useful is situations close to tear-down -- e.g.,
10495 after an exec, while the target still has execution, but breakpoint
10496 shadows of the previous executable image should *NOT* be restored
10497 to the new image; or before detaching, where the target still has
10498 execution and wants to delete breakpoints from GDB's lists, and all
10499 breakpoints had already been removed from the inferior. */
10502 update_global_location_list (int should_insert
)
10504 struct breakpoint
*b
;
10505 struct bp_location
**locp
, *loc
;
10506 struct cleanup
*cleanups
;
10508 /* Used in the duplicates detection below. When iterating over all
10509 bp_locations, points to the first bp_location of a given address.
10510 Breakpoints and watchpoints of different types are never
10511 duplicates of each other. Keep one pointer for each type of
10512 breakpoint/watchpoint, so we only need to loop over all locations
10514 struct bp_location
*bp_loc_first
; /* breakpoint */
10515 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10516 struct bp_location
*awp_loc_first
; /* access watchpoint */
10517 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10519 /* Saved former bp_location array which we compare against the newly
10520 built bp_location from the current state of ALL_BREAKPOINTS. */
10521 struct bp_location
**old_location
, **old_locp
;
10522 unsigned old_location_count
;
10524 old_location
= bp_location
;
10525 old_location_count
= bp_location_count
;
10526 bp_location
= NULL
;
10527 bp_location_count
= 0;
10528 cleanups
= make_cleanup (xfree
, old_location
);
10530 ALL_BREAKPOINTS (b
)
10531 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10532 bp_location_count
++;
10534 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10535 locp
= bp_location
;
10536 ALL_BREAKPOINTS (b
)
10537 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10539 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10540 bp_location_compare
);
10542 bp_location_target_extensions_update ();
10544 /* Identify bp_location instances that are no longer present in the
10545 new list, and therefore should be freed. Note that it's not
10546 necessary that those locations should be removed from inferior --
10547 if there's another location at the same address (previously
10548 marked as duplicate), we don't need to remove/insert the
10551 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10552 and former bp_location array state respectively. */
10554 locp
= bp_location
;
10555 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10558 struct bp_location
*old_loc
= *old_locp
;
10559 struct bp_location
**loc2p
;
10561 /* Tells if 'old_loc' is found among the new locations. If
10562 not, we have to free it. */
10563 int found_object
= 0;
10564 /* Tells if the location should remain inserted in the target. */
10565 int keep_in_target
= 0;
10568 /* Skip LOCP entries which will definitely never be needed.
10569 Stop either at or being the one matching OLD_LOC. */
10570 while (locp
< bp_location
+ bp_location_count
10571 && (*locp
)->address
< old_loc
->address
)
10575 (loc2p
< bp_location
+ bp_location_count
10576 && (*loc2p
)->address
== old_loc
->address
);
10579 if (*loc2p
== old_loc
)
10586 /* If this location is no longer present, and inserted, look if
10587 there's maybe a new location at the same address. If so,
10588 mark that one inserted, and don't remove this one. This is
10589 needed so that we don't have a time window where a breakpoint
10590 at certain location is not inserted. */
10592 if (old_loc
->inserted
)
10594 /* If the location is inserted now, we might have to remove
10597 if (found_object
&& should_be_inserted (old_loc
))
10599 /* The location is still present in the location list,
10600 and still should be inserted. Don't do anything. */
10601 keep_in_target
= 1;
10605 /* The location is either no longer present, or got
10606 disabled. See if there's another location at the
10607 same address, in which case we don't need to remove
10608 this one from the target. */
10610 /* OLD_LOC comes from existing struct breakpoint. */
10611 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10614 (loc2p
< bp_location
+ bp_location_count
10615 && (*loc2p
)->address
== old_loc
->address
);
10618 struct bp_location
*loc2
= *loc2p
;
10620 if (breakpoint_locations_match (loc2
, old_loc
))
10622 /* Read watchpoint locations are switched to
10623 access watchpoints, if the former are not
10624 supported, but the latter are. */
10625 if (is_hardware_watchpoint (old_loc
->owner
))
10627 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10628 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10631 /* loc2 is a duplicated location. We need to check
10632 if it should be inserted in case it will be
10634 if (loc2
!= old_loc
10635 && unduplicated_should_be_inserted (loc2
))
10637 swap_insertion (old_loc
, loc2
);
10638 keep_in_target
= 1;
10646 if (!keep_in_target
)
10648 if (remove_breakpoint (old_loc
, mark_uninserted
))
10650 /* This is just about all we can do. We could keep
10651 this location on the global list, and try to
10652 remove it next time, but there's no particular
10653 reason why we will succeed next time.
10655 Note that at this point, old_loc->owner is still
10656 valid, as delete_breakpoint frees the breakpoint
10657 only after calling us. */
10658 printf_filtered (_("warning: Error removing "
10659 "breakpoint %d\n"),
10660 old_loc
->owner
->number
);
10668 if (removed
&& non_stop
10669 && breakpoint_address_is_meaningful (old_loc
->owner
)
10670 && !is_hardware_watchpoint (old_loc
->owner
))
10672 /* This location was removed from the target. In
10673 non-stop mode, a race condition is possible where
10674 we've removed a breakpoint, but stop events for that
10675 breakpoint are already queued and will arrive later.
10676 We apply an heuristic to be able to distinguish such
10677 SIGTRAPs from other random SIGTRAPs: we keep this
10678 breakpoint location for a bit, and will retire it
10679 after we see some number of events. The theory here
10680 is that reporting of events should, "on the average",
10681 be fair, so after a while we'll see events from all
10682 threads that have anything of interest, and no longer
10683 need to keep this breakpoint location around. We
10684 don't hold locations forever so to reduce chances of
10685 mistaking a non-breakpoint SIGTRAP for a breakpoint
10688 The heuristic failing can be disastrous on
10689 decr_pc_after_break targets.
10691 On decr_pc_after_break targets, like e.g., x86-linux,
10692 if we fail to recognize a late breakpoint SIGTRAP,
10693 because events_till_retirement has reached 0 too
10694 soon, we'll fail to do the PC adjustment, and report
10695 a random SIGTRAP to the user. When the user resumes
10696 the inferior, it will most likely immediately crash
10697 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10698 corrupted, because of being resumed e.g., in the
10699 middle of a multi-byte instruction, or skipped a
10700 one-byte instruction. This was actually seen happen
10701 on native x86-linux, and should be less rare on
10702 targets that do not support new thread events, like
10703 remote, due to the heuristic depending on
10706 Mistaking a random SIGTRAP for a breakpoint trap
10707 causes similar symptoms (PC adjustment applied when
10708 it shouldn't), but then again, playing with SIGTRAPs
10709 behind the debugger's back is asking for trouble.
10711 Since hardware watchpoint traps are always
10712 distinguishable from other traps, so we don't need to
10713 apply keep hardware watchpoint moribund locations
10714 around. We simply always ignore hardware watchpoint
10715 traps we can no longer explain. */
10717 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10718 old_loc
->owner
= NULL
;
10720 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10724 old_loc
->owner
= NULL
;
10725 decref_bp_location (&old_loc
);
10730 /* Rescan breakpoints at the same address and section, marking the
10731 first one as "first" and any others as "duplicates". This is so
10732 that the bpt instruction is only inserted once. If we have a
10733 permanent breakpoint at the same place as BPT, make that one the
10734 official one, and the rest as duplicates. Permanent breakpoints
10735 are sorted first for the same address.
10737 Do the same for hardware watchpoints, but also considering the
10738 watchpoint's type (regular/access/read) and length. */
10740 bp_loc_first
= NULL
;
10741 wp_loc_first
= NULL
;
10742 awp_loc_first
= NULL
;
10743 rwp_loc_first
= NULL
;
10744 ALL_BP_LOCATIONS (loc
, locp
)
10746 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10748 struct breakpoint
*b
= loc
->owner
;
10749 struct bp_location
**loc_first_p
;
10751 if (b
->enable_state
== bp_disabled
10752 || b
->enable_state
== bp_call_disabled
10753 || b
->enable_state
== bp_startup_disabled
10755 || loc
->shlib_disabled
10756 || !breakpoint_address_is_meaningful (b
)
10757 /* Don't detect duplicate for tracepoint locations because they are
10758 never duplicated. See the comments in field `duplicate' of
10759 `struct bp_location'. */
10760 || is_tracepoint (b
))
10763 /* Permanent breakpoint should always be inserted. */
10764 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10765 internal_error (__FILE__
, __LINE__
,
10766 _("allegedly permanent breakpoint is not "
10767 "actually inserted"));
10769 if (b
->type
== bp_hardware_watchpoint
)
10770 loc_first_p
= &wp_loc_first
;
10771 else if (b
->type
== bp_read_watchpoint
)
10772 loc_first_p
= &rwp_loc_first
;
10773 else if (b
->type
== bp_access_watchpoint
)
10774 loc_first_p
= &awp_loc_first
;
10776 loc_first_p
= &bp_loc_first
;
10778 if (*loc_first_p
== NULL
10779 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10780 || !breakpoint_locations_match (loc
, *loc_first_p
))
10782 *loc_first_p
= loc
;
10783 loc
->duplicate
= 0;
10788 /* This and the above ensure the invariant that the first location
10789 is not duplicated, and is the inserted one.
10790 All following are marked as duplicated, and are not inserted. */
10792 swap_insertion (loc
, *loc_first_p
);
10793 loc
->duplicate
= 1;
10795 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10796 && b
->enable_state
!= bp_permanent
)
10797 internal_error (__FILE__
, __LINE__
,
10798 _("another breakpoint was inserted on top of "
10799 "a permanent breakpoint"));
10802 if (breakpoints_always_inserted_mode () && should_insert
10803 && (have_live_inferiors ()
10804 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10805 insert_breakpoint_locations ();
10808 download_tracepoint_locations ();
10810 do_cleanups (cleanups
);
10814 breakpoint_retire_moribund (void)
10816 struct bp_location
*loc
;
10819 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10820 if (--(loc
->events_till_retirement
) == 0)
10822 decref_bp_location (&loc
);
10823 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10829 update_global_location_list_nothrow (int inserting
)
10831 struct gdb_exception e
;
10833 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10834 update_global_location_list (inserting
);
10837 /* Clear BKP from a BPS. */
10840 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10844 for (bs
= bps
; bs
; bs
= bs
->next
)
10845 if (bs
->breakpoint_at
== bpt
)
10847 bs
->breakpoint_at
= NULL
;
10848 bs
->old_val
= NULL
;
10849 /* bs->commands will be freed later. */
10853 /* Callback for iterate_over_threads. */
10855 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10857 struct breakpoint
*bpt
= data
;
10859 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10863 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10867 say_where (struct breakpoint
*b
)
10869 struct ui_out
*uiout
= current_uiout
;
10870 struct value_print_options opts
;
10872 get_user_print_options (&opts
);
10874 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10876 if (b
->loc
== NULL
)
10878 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10882 if (opts
.addressprint
|| b
->source_file
== NULL
)
10884 printf_filtered (" at ");
10885 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10888 if (b
->source_file
)
10889 printf_filtered (": file %s, line %d.",
10890 b
->source_file
, b
->line_number
);
10894 struct bp_location
*loc
= b
->loc
;
10896 for (; loc
; loc
= loc
->next
)
10898 printf_filtered (" (%d locations)", n
);
10903 /* Default bp_location_ops methods. */
10906 bp_location_dtor (struct bp_location
*self
)
10908 xfree (self
->cond
);
10909 xfree (self
->function_name
);
10912 static const struct bp_location_ops bp_location_ops
=
10917 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10921 base_breakpoint_dtor (struct breakpoint
*self
)
10923 decref_counted_command_line (&self
->commands
);
10924 xfree (self
->cond_string
);
10925 xfree (self
->addr_string
);
10926 xfree (self
->addr_string_range_end
);
10927 xfree (self
->source_file
);
10930 static struct bp_location
*
10931 base_breakpoint_allocate_location (struct breakpoint
*self
)
10933 struct bp_location
*loc
;
10935 loc
= XNEW (struct bp_location
);
10936 init_bp_location (loc
, &bp_location_ops
, self
);
10941 base_breakpoint_re_set (struct breakpoint
*b
)
10943 /* Nothing to re-set. */
10946 #define internal_error_pure_virtual_called() \
10947 gdb_assert_not_reached ("pure virtual function called")
10950 base_breakpoint_insert_location (struct bp_location
*bl
)
10952 internal_error_pure_virtual_called ();
10956 base_breakpoint_remove_location (struct bp_location
*bl
)
10958 internal_error_pure_virtual_called ();
10962 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10963 struct address_space
*aspace
,
10966 internal_error_pure_virtual_called ();
10970 base_breakpoint_check_status (bpstat bs
)
10975 /* A "works_in_software_mode" breakpoint_ops method that just internal
10979 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10981 internal_error_pure_virtual_called ();
10984 /* A "resources_needed" breakpoint_ops method that just internal
10988 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10990 internal_error_pure_virtual_called ();
10993 static enum print_stop_action
10994 base_breakpoint_print_it (bpstat bs
)
10996 internal_error_pure_virtual_called ();
11000 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
11001 struct ui_out
*uiout
)
11007 base_breakpoint_print_mention (struct breakpoint
*b
)
11009 internal_error_pure_virtual_called ();
11013 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
11015 internal_error_pure_virtual_called ();
11018 static struct breakpoint_ops base_breakpoint_ops
=
11020 base_breakpoint_dtor
,
11021 base_breakpoint_allocate_location
,
11022 base_breakpoint_re_set
,
11023 base_breakpoint_insert_location
,
11024 base_breakpoint_remove_location
,
11025 base_breakpoint_breakpoint_hit
,
11026 base_breakpoint_check_status
,
11027 base_breakpoint_resources_needed
,
11028 base_breakpoint_works_in_software_mode
,
11029 base_breakpoint_print_it
,
11031 base_breakpoint_print_one_detail
,
11032 base_breakpoint_print_mention
,
11033 base_breakpoint_print_recreate
11036 /* Default breakpoint_ops methods. */
11039 bkpt_re_set (struct breakpoint
*b
)
11041 /* Do not attempt to re-set breakpoints disabled during startup. */
11042 if (b
->enable_state
== bp_startup_disabled
)
11045 /* FIXME: is this still reachable? */
11046 if (b
->addr_string
== NULL
)
11048 /* Anything without a string can't be re-set. */
11049 delete_breakpoint (b
);
11053 breakpoint_re_set_default (b
);
11057 bkpt_insert_location (struct bp_location
*bl
)
11059 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11060 return target_insert_hw_breakpoint (bl
->gdbarch
,
11063 return target_insert_breakpoint (bl
->gdbarch
,
11068 bkpt_remove_location (struct bp_location
*bl
)
11070 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11071 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11073 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11077 bkpt_breakpoint_hit (const struct bp_location
*bl
,
11078 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11080 struct breakpoint
*b
= bl
->owner
;
11082 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11086 if (overlay_debugging
/* unmapped overlay section */
11087 && section_is_overlay (bl
->section
)
11088 && !section_is_mapped (bl
->section
))
11095 bkpt_resources_needed (const struct bp_location
*bl
)
11097 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
11102 static enum print_stop_action
11103 bkpt_print_it (bpstat bs
)
11105 struct breakpoint
*b
;
11106 const struct bp_location
*bl
;
11108 struct ui_out
*uiout
= current_uiout
;
11110 gdb_assert (bs
->bp_location_at
!= NULL
);
11112 bl
= bs
->bp_location_at
;
11113 b
= bs
->breakpoint_at
;
11115 bp_temp
= b
->disposition
== disp_del
;
11116 if (bl
->address
!= bl
->requested_address
)
11117 breakpoint_adjustment_warning (bl
->requested_address
,
11120 annotate_breakpoint (b
->number
);
11122 ui_out_text (uiout
, "\nTemporary breakpoint ");
11124 ui_out_text (uiout
, "\nBreakpoint ");
11125 if (ui_out_is_mi_like_p (uiout
))
11127 ui_out_field_string (uiout
, "reason",
11128 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11129 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11131 ui_out_field_int (uiout
, "bkptno", b
->number
);
11132 ui_out_text (uiout
, ", ");
11134 return PRINT_SRC_AND_LOC
;
11138 bkpt_print_mention (struct breakpoint
*b
)
11140 if (ui_out_is_mi_like_p (current_uiout
))
11145 case bp_breakpoint
:
11146 case bp_gnu_ifunc_resolver
:
11147 if (b
->disposition
== disp_del
)
11148 printf_filtered (_("Temporary breakpoint"));
11150 printf_filtered (_("Breakpoint"));
11151 printf_filtered (_(" %d"), b
->number
);
11152 if (b
->type
== bp_gnu_ifunc_resolver
)
11153 printf_filtered (_(" at gnu-indirect-function resolver"));
11155 case bp_hardware_breakpoint
:
11156 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
11164 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11166 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11167 fprintf_unfiltered (fp
, "tbreak");
11168 else if (tp
->type
== bp_breakpoint
)
11169 fprintf_unfiltered (fp
, "break");
11170 else if (tp
->type
== bp_hardware_breakpoint
11171 && tp
->disposition
== disp_del
)
11172 fprintf_unfiltered (fp
, "thbreak");
11173 else if (tp
->type
== bp_hardware_breakpoint
)
11174 fprintf_unfiltered (fp
, "hbreak");
11176 internal_error (__FILE__
, __LINE__
,
11177 _("unhandled breakpoint type %d"), (int) tp
->type
);
11179 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11180 print_recreate_thread (tp
, fp
);
11183 /* Virtual table for internal breakpoints. */
11186 internal_bkpt_re_set (struct breakpoint
*b
)
11190 /* Delete overlay event and longjmp master breakpoints; they
11191 will be reset later by breakpoint_re_set. */
11192 case bp_overlay_event
:
11193 case bp_longjmp_master
:
11194 case bp_std_terminate_master
:
11195 case bp_exception_master
:
11196 delete_breakpoint (b
);
11199 /* This breakpoint is special, it's set up when the inferior
11200 starts and we really don't want to touch it. */
11201 case bp_shlib_event
:
11203 /* Like bp_shlib_event, this breakpoint type is special. Once
11204 it is set up, we do not want to touch it. */
11205 case bp_thread_event
:
11211 internal_bkpt_check_status (bpstat bs
)
11213 /* We do not stop for these. */
11217 static enum print_stop_action
11218 internal_bkpt_print_it (bpstat bs
)
11220 struct ui_out
*uiout
= current_uiout
;
11221 struct breakpoint
*b
;
11223 b
= bs
->breakpoint_at
;
11227 case bp_shlib_event
:
11228 /* Did we stop because the user set the stop_on_solib_events
11229 variable? (If so, we report this as a generic, "Stopped due
11230 to shlib event" message.) */
11231 ui_out_text (uiout
, _("Stopped due to shared library event\n"));
11232 if (ui_out_is_mi_like_p (uiout
))
11233 ui_out_field_string (uiout
, "reason",
11234 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
11237 case bp_thread_event
:
11238 /* Not sure how we will get here.
11239 GDB should not stop for these breakpoints. */
11240 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11243 case bp_overlay_event
:
11244 /* By analogy with the thread event, GDB should not stop for these. */
11245 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11248 case bp_longjmp_master
:
11249 /* These should never be enabled. */
11250 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11253 case bp_std_terminate_master
:
11254 /* These should never be enabled. */
11255 printf_filtered (_("std::terminate Master Breakpoint: "
11256 "gdb should not stop!\n"));
11259 case bp_exception_master
:
11260 /* These should never be enabled. */
11261 printf_filtered (_("Exception Master Breakpoint: "
11262 "gdb should not stop!\n"));
11266 return PRINT_NOTHING
;
11270 internal_bkpt_print_mention (struct breakpoint
*b
)
11272 /* Nothing to mention. These breakpoints are internal. */
11275 /* Virtual table for momentary breakpoints */
11278 momentary_bkpt_re_set (struct breakpoint
*b
)
11280 /* Keep temporary breakpoints, which can be encountered when we step
11281 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11282 Otherwise these should have been blown away via the cleanup chain
11283 or by breakpoint_init_inferior when we rerun the executable. */
11287 momentary_bkpt_check_status (bpstat bs
)
11289 /* Nothing. The point of these breakpoints is causing a stop. */
11292 static enum print_stop_action
11293 momentary_bkpt_print_it (bpstat bs
)
11295 struct ui_out
*uiout
= current_uiout
;
11297 if (ui_out_is_mi_like_p (uiout
))
11299 struct breakpoint
*b
= bs
->breakpoint_at
;
11304 ui_out_field_string
11306 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11310 ui_out_field_string
11312 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11317 return PRINT_UNKNOWN
;
11321 momentary_bkpt_print_mention (struct breakpoint
*b
)
11323 /* Nothing to mention. These breakpoints are internal. */
11326 /* The breakpoint_ops structure to be used in tracepoints. */
11329 tracepoint_re_set (struct breakpoint
*b
)
11331 breakpoint_re_set_default (b
);
11335 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11336 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11338 /* By definition, the inferior does not report stops at
11344 tracepoint_print_one_detail (const struct breakpoint
*self
,
11345 struct ui_out
*uiout
)
11347 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11348 if (tp
->static_trace_marker_id
)
11350 gdb_assert (self
->type
== bp_static_tracepoint
);
11352 ui_out_text (uiout
, "\tmarker id is ");
11353 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11354 tp
->static_trace_marker_id
);
11355 ui_out_text (uiout
, "\n");
11360 tracepoint_print_mention (struct breakpoint
*b
)
11362 if (ui_out_is_mi_like_p (current_uiout
))
11367 case bp_tracepoint
:
11368 printf_filtered (_("Tracepoint"));
11369 printf_filtered (_(" %d"), b
->number
);
11371 case bp_fast_tracepoint
:
11372 printf_filtered (_("Fast tracepoint"));
11373 printf_filtered (_(" %d"), b
->number
);
11375 case bp_static_tracepoint
:
11376 printf_filtered (_("Static tracepoint"));
11377 printf_filtered (_(" %d"), b
->number
);
11380 internal_error (__FILE__
, __LINE__
,
11381 _("unhandled tracepoint type %d"), (int) b
->type
);
11388 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11390 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11392 if (self
->type
== bp_fast_tracepoint
)
11393 fprintf_unfiltered (fp
, "ftrace");
11394 if (self
->type
== bp_static_tracepoint
)
11395 fprintf_unfiltered (fp
, "strace");
11396 else if (self
->type
== bp_tracepoint
)
11397 fprintf_unfiltered (fp
, "trace");
11399 internal_error (__FILE__
, __LINE__
,
11400 _("unhandled tracepoint type %d"), (int) self
->type
);
11402 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11403 print_recreate_thread (self
, fp
);
11405 if (tp
->pass_count
)
11406 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11409 struct breakpoint_ops tracepoint_breakpoint_ops
;
11411 /* Delete a breakpoint and clean up all traces of it in the data
11415 delete_breakpoint (struct breakpoint
*bpt
)
11417 struct breakpoint
*b
;
11419 gdb_assert (bpt
!= NULL
);
11421 /* Has this bp already been deleted? This can happen because
11422 multiple lists can hold pointers to bp's. bpstat lists are
11425 One example of this happening is a watchpoint's scope bp. When
11426 the scope bp triggers, we notice that the watchpoint is out of
11427 scope, and delete it. We also delete its scope bp. But the
11428 scope bp is marked "auto-deleting", and is already on a bpstat.
11429 That bpstat is then checked for auto-deleting bp's, which are
11432 A real solution to this problem might involve reference counts in
11433 bp's, and/or giving them pointers back to their referencing
11434 bpstat's, and teaching delete_breakpoint to only free a bp's
11435 storage when no more references were extent. A cheaper bandaid
11437 if (bpt
->type
== bp_none
)
11440 /* At least avoid this stale reference until the reference counting
11441 of breakpoints gets resolved. */
11442 if (bpt
->related_breakpoint
!= bpt
)
11444 struct breakpoint
*related
;
11445 struct watchpoint
*w
;
11447 if (bpt
->type
== bp_watchpoint_scope
)
11448 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11449 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11450 w
= (struct watchpoint
*) bpt
;
11454 watchpoint_del_at_next_stop (w
);
11456 /* Unlink bpt from the bpt->related_breakpoint ring. */
11457 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11458 related
= related
->related_breakpoint
);
11459 related
->related_breakpoint
= bpt
->related_breakpoint
;
11460 bpt
->related_breakpoint
= bpt
;
11463 /* watch_command_1 creates a watchpoint but only sets its number if
11464 update_watchpoint succeeds in creating its bp_locations. If there's
11465 a problem in that process, we'll be asked to delete the half-created
11466 watchpoint. In that case, don't announce the deletion. */
11468 observer_notify_breakpoint_deleted (bpt
);
11470 if (breakpoint_chain
== bpt
)
11471 breakpoint_chain
= bpt
->next
;
11473 ALL_BREAKPOINTS (b
)
11474 if (b
->next
== bpt
)
11476 b
->next
= bpt
->next
;
11480 /* Be sure no bpstat's are pointing at the breakpoint after it's
11482 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11483 in all threads for now. Note that we cannot just remove bpstats
11484 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11485 commands are associated with the bpstat; if we remove it here,
11486 then the later call to bpstat_do_actions (&stop_bpstat); in
11487 event-top.c won't do anything, and temporary breakpoints with
11488 commands won't work. */
11490 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11492 /* Now that breakpoint is removed from breakpoint list, update the
11493 global location list. This will remove locations that used to
11494 belong to this breakpoint. Do this before freeing the breakpoint
11495 itself, since remove_breakpoint looks at location's owner. It
11496 might be better design to have location completely
11497 self-contained, but it's not the case now. */
11498 update_global_location_list (0);
11500 bpt
->ops
->dtor (bpt
);
11501 /* On the chance that someone will soon try again to delete this
11502 same bp, we mark it as deleted before freeing its storage. */
11503 bpt
->type
= bp_none
;
11508 do_delete_breakpoint_cleanup (void *b
)
11510 delete_breakpoint (b
);
11514 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11516 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11519 /* Iterator function to call a user-provided callback function once
11520 for each of B and its related breakpoints. */
11523 iterate_over_related_breakpoints (struct breakpoint
*b
,
11524 void (*function
) (struct breakpoint
*,
11528 struct breakpoint
*related
;
11533 struct breakpoint
*next
;
11535 /* FUNCTION may delete RELATED. */
11536 next
= related
->related_breakpoint
;
11538 if (next
== related
)
11540 /* RELATED is the last ring entry. */
11541 function (related
, data
);
11543 /* FUNCTION may have deleted it, so we'd never reach back to
11544 B. There's nothing left to do anyway, so just break
11549 function (related
, data
);
11553 while (related
!= b
);
11557 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11559 delete_breakpoint (b
);
11562 /* A callback for map_breakpoint_numbers that calls
11563 delete_breakpoint. */
11566 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11568 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11572 delete_command (char *arg
, int from_tty
)
11574 struct breakpoint
*b
, *b_tmp
;
11580 int breaks_to_delete
= 0;
11582 /* Delete all breakpoints if no argument. Do not delete
11583 internal breakpoints, these have to be deleted with an
11584 explicit breakpoint number argument. */
11585 ALL_BREAKPOINTS (b
)
11586 if (user_breakpoint_p (b
))
11588 breaks_to_delete
= 1;
11592 /* Ask user only if there are some breakpoints to delete. */
11594 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11596 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11597 if (user_breakpoint_p (b
))
11598 delete_breakpoint (b
);
11602 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11606 all_locations_are_pending (struct bp_location
*loc
)
11608 for (; loc
; loc
= loc
->next
)
11609 if (!loc
->shlib_disabled
)
11614 /* Subroutine of update_breakpoint_locations to simplify it.
11615 Return non-zero if multiple fns in list LOC have the same name.
11616 Null names are ignored. */
11619 ambiguous_names_p (struct bp_location
*loc
)
11621 struct bp_location
*l
;
11622 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11623 (int (*) (const void *,
11624 const void *)) streq
,
11625 NULL
, xcalloc
, xfree
);
11627 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11630 const char *name
= l
->function_name
;
11632 /* Allow for some names to be NULL, ignore them. */
11636 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11638 /* NOTE: We can assume slot != NULL here because xcalloc never
11642 htab_delete (htab
);
11648 htab_delete (htab
);
11652 /* When symbols change, it probably means the sources changed as well,
11653 and it might mean the static tracepoint markers are no longer at
11654 the same address or line numbers they used to be at last we
11655 checked. Losing your static tracepoints whenever you rebuild is
11656 undesirable. This function tries to resync/rematch gdb static
11657 tracepoints with the markers on the target, for static tracepoints
11658 that have not been set by marker id. Static tracepoint that have
11659 been set by marker id are reset by marker id in breakpoint_re_set.
11662 1) For a tracepoint set at a specific address, look for a marker at
11663 the old PC. If one is found there, assume to be the same marker.
11664 If the name / string id of the marker found is different from the
11665 previous known name, assume that means the user renamed the marker
11666 in the sources, and output a warning.
11668 2) For a tracepoint set at a given line number, look for a marker
11669 at the new address of the old line number. If one is found there,
11670 assume to be the same marker. If the name / string id of the
11671 marker found is different from the previous known name, assume that
11672 means the user renamed the marker in the sources, and output a
11675 3) If a marker is no longer found at the same address or line, it
11676 may mean the marker no longer exists. But it may also just mean
11677 the code changed a bit. Maybe the user added a few lines of code
11678 that made the marker move up or down (in line number terms). Ask
11679 the target for info about the marker with the string id as we knew
11680 it. If found, update line number and address in the matching
11681 static tracepoint. This will get confused if there's more than one
11682 marker with the same ID (possible in UST, although unadvised
11683 precisely because it confuses tools). */
11685 static struct symtab_and_line
11686 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11688 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11689 struct static_tracepoint_marker marker
;
11695 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11697 if (target_static_tracepoint_marker_at (pc
, &marker
))
11699 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11700 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11702 tp
->static_trace_marker_id
, marker
.str_id
);
11704 xfree (tp
->static_trace_marker_id
);
11705 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11706 release_static_tracepoint_marker (&marker
);
11711 /* Old marker wasn't found on target at lineno. Try looking it up
11713 if (!sal
.explicit_pc
11715 && sal
.symtab
!= NULL
11716 && tp
->static_trace_marker_id
!= NULL
)
11718 VEC(static_tracepoint_marker_p
) *markers
;
11721 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11723 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11725 struct symtab_and_line sal
;
11726 struct symbol
*sym
;
11727 struct static_tracepoint_marker
*marker
;
11728 struct ui_out
*uiout
= current_uiout
;
11730 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11732 xfree (tp
->static_trace_marker_id
);
11733 tp
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11735 warning (_("marker for static tracepoint %d (%s) not "
11736 "found at previous line number"),
11737 b
->number
, tp
->static_trace_marker_id
);
11741 sal
.pc
= marker
->address
;
11743 sal
= find_pc_line (marker
->address
, 0);
11744 sym
= find_pc_sect_function (marker
->address
, NULL
);
11745 ui_out_text (uiout
, "Now in ");
11748 ui_out_field_string (uiout
, "func",
11749 SYMBOL_PRINT_NAME (sym
));
11750 ui_out_text (uiout
, " at ");
11752 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11753 ui_out_text (uiout
, ":");
11755 if (ui_out_is_mi_like_p (uiout
))
11757 char *fullname
= symtab_to_fullname (sal
.symtab
);
11760 ui_out_field_string (uiout
, "fullname", fullname
);
11763 ui_out_field_int (uiout
, "line", sal
.line
);
11764 ui_out_text (uiout
, "\n");
11766 b
->line_number
= sal
.line
;
11768 xfree (b
->source_file
);
11770 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11772 b
->source_file
= NULL
;
11774 xfree (b
->addr_string
);
11775 b
->addr_string
= xstrprintf ("%s:%d",
11776 sal
.symtab
->filename
, b
->line_number
);
11778 /* Might be nice to check if function changed, and warn if
11781 release_static_tracepoint_marker (marker
);
11787 /* Returns 1 iff locations A and B are sufficiently same that
11788 we don't need to report breakpoint as changed. */
11791 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11795 if (a
->address
!= b
->address
)
11798 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11801 if (a
->enabled
!= b
->enabled
)
11808 if ((a
== NULL
) != (b
== NULL
))
11814 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11815 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11816 a ranged breakpoint. */
11819 update_breakpoint_locations (struct breakpoint
*b
,
11820 struct symtabs_and_lines sals
,
11821 struct symtabs_and_lines sals_end
)
11824 struct bp_location
*existing_locations
= b
->loc
;
11826 /* Ranged breakpoints have only one start location and one end location. */
11827 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11829 /* If there's no new locations, and all existing locations are
11830 pending, don't do anything. This optimizes the common case where
11831 all locations are in the same shared library, that was unloaded.
11832 We'd like to retain the location, so that when the library is
11833 loaded again, we don't loose the enabled/disabled status of the
11834 individual locations. */
11835 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11840 for (i
= 0; i
< sals
.nelts
; ++i
)
11842 struct bp_location
*new_loc
=
11843 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11845 /* Reparse conditions, they might contain references to the
11847 if (b
->cond_string
!= NULL
)
11850 struct gdb_exception e
;
11852 s
= b
->cond_string
;
11853 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11855 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11860 warning (_("failed to reevaluate condition "
11861 "for breakpoint %d: %s"),
11862 b
->number
, e
.message
);
11863 new_loc
->enabled
= 0;
11867 if (b
->source_file
!= NULL
)
11868 xfree (b
->source_file
);
11869 if (sals
.sals
[i
].symtab
== NULL
)
11870 b
->source_file
= NULL
;
11872 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11874 if (b
->line_number
== 0)
11875 b
->line_number
= sals
.sals
[i
].line
;
11877 if (sals_end
.nelts
)
11879 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11881 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11885 /* Update locations of permanent breakpoints. */
11886 if (b
->enable_state
== bp_permanent
)
11887 make_breakpoint_permanent (b
);
11889 /* If possible, carry over 'disable' status from existing
11892 struct bp_location
*e
= existing_locations
;
11893 /* If there are multiple breakpoints with the same function name,
11894 e.g. for inline functions, comparing function names won't work.
11895 Instead compare pc addresses; this is just a heuristic as things
11896 may have moved, but in practice it gives the correct answer
11897 often enough until a better solution is found. */
11898 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11900 for (; e
; e
= e
->next
)
11902 if (!e
->enabled
&& e
->function_name
)
11904 struct bp_location
*l
= b
->loc
;
11905 if (have_ambiguous_names
)
11907 for (; l
; l
= l
->next
)
11908 if (breakpoint_locations_match (e
, l
))
11916 for (; l
; l
= l
->next
)
11917 if (l
->function_name
11918 && strcmp (e
->function_name
, l
->function_name
) == 0)
11928 if (!locations_are_equal (existing_locations
, b
->loc
))
11929 observer_notify_breakpoint_modified (b
);
11931 update_global_location_list (1);
11934 /* Find the SaL locations corresponding to the given ADDR_STRING.
11935 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11937 static struct symtabs_and_lines
11938 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11942 struct symtabs_and_lines sals
= {0};
11943 struct gdb_exception e
;
11946 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11948 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11952 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11954 sals
= decode_static_tracepoint_spec (&s
);
11955 if (sals
.nelts
> tp
->static_trace_marker_id_idx
)
11957 sals
.sals
[0] = sals
.sals
[tp
->static_trace_marker_id_idx
];
11961 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11964 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11968 int not_found_and_ok
= 0;
11969 /* For pending breakpoints, it's expected that parsing will
11970 fail until the right shared library is loaded. User has
11971 already told to create pending breakpoints and don't need
11972 extra messages. If breakpoint is in bp_shlib_disabled
11973 state, then user already saw the message about that
11974 breakpoint being disabled, and don't want to see more
11976 if (e
.error
== NOT_FOUND_ERROR
11977 && (b
->condition_not_parsed
11978 || (b
->loc
&& b
->loc
->shlib_disabled
)
11979 || b
->enable_state
== bp_disabled
))
11980 not_found_and_ok
= 1;
11982 if (!not_found_and_ok
)
11984 /* We surely don't want to warn about the same breakpoint
11985 10 times. One solution, implemented here, is disable
11986 the breakpoint on error. Another solution would be to
11987 have separate 'warning emitted' flag. Since this
11988 happens only when a binary has changed, I don't know
11989 which approach is better. */
11990 b
->enable_state
= bp_disabled
;
11991 throw_exception (e
);
11995 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11997 gdb_assert (sals
.nelts
== 1);
11999 resolve_sal_pc (&sals
.sals
[0]);
12000 if (b
->condition_not_parsed
&& s
&& s
[0])
12002 char *cond_string
= 0;
12006 find_condition_and_thread (s
, sals
.sals
[0].pc
,
12007 &cond_string
, &thread
, &task
);
12009 b
->cond_string
= cond_string
;
12010 b
->thread
= thread
;
12012 b
->condition_not_parsed
= 0;
12015 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
12016 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
12026 /* The default re_set method, for typical hardware or software
12027 breakpoints. Reevaluate the breakpoint and recreate its
12031 breakpoint_re_set_default (struct breakpoint
*b
)
12034 struct symtabs_and_lines sals
, sals_end
;
12035 struct symtabs_and_lines expanded
= {0};
12036 struct symtabs_and_lines expanded_end
= {0};
12038 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
12041 make_cleanup (xfree
, sals
.sals
);
12042 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
12045 if (b
->addr_string_range_end
)
12047 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
12050 make_cleanup (xfree
, sals_end
.sals
);
12051 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
12055 update_breakpoint_locations (b
, expanded
, expanded_end
);
12058 /* Prepare the global context for a re-set of breakpoint B. */
12060 static struct cleanup
*
12061 prepare_re_set_context (struct breakpoint
*b
)
12063 struct cleanup
*cleanups
;
12065 input_radix
= b
->input_radix
;
12066 cleanups
= save_current_space_and_thread ();
12067 switch_to_program_space_and_thread (b
->pspace
);
12068 set_language (b
->language
);
12073 /* Reset a breakpoint given it's struct breakpoint * BINT.
12074 The value we return ends up being the return value from catch_errors.
12075 Unused in this case. */
12078 breakpoint_re_set_one (void *bint
)
12080 /* Get past catch_errs. */
12081 struct breakpoint
*b
= (struct breakpoint
*) bint
;
12082 struct cleanup
*cleanups
;
12084 cleanups
= prepare_re_set_context (b
);
12085 b
->ops
->re_set (b
);
12086 do_cleanups (cleanups
);
12090 /* Re-set all breakpoints after symbols have been re-loaded. */
12092 breakpoint_re_set (void)
12094 struct breakpoint
*b
, *b_tmp
;
12095 enum language save_language
;
12096 int save_input_radix
;
12097 struct cleanup
*old_chain
;
12099 save_language
= current_language
->la_language
;
12100 save_input_radix
= input_radix
;
12101 old_chain
= save_current_program_space ();
12103 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12105 /* Format possible error msg. */
12106 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
12108 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
12109 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
12110 do_cleanups (cleanups
);
12112 set_language (save_language
);
12113 input_radix
= save_input_radix
;
12115 jit_breakpoint_re_set ();
12117 do_cleanups (old_chain
);
12119 create_overlay_event_breakpoint ();
12120 create_longjmp_master_breakpoint ();
12121 create_std_terminate_master_breakpoint ();
12122 create_exception_master_breakpoint ();
12124 /* While we're at it, reset the skip list too. */
12128 /* Reset the thread number of this breakpoint:
12130 - If the breakpoint is for all threads, leave it as-is.
12131 - Else, reset it to the current thread for inferior_ptid. */
12133 breakpoint_re_set_thread (struct breakpoint
*b
)
12135 if (b
->thread
!= -1)
12137 if (in_thread_list (inferior_ptid
))
12138 b
->thread
= pid_to_thread_id (inferior_ptid
);
12140 /* We're being called after following a fork. The new fork is
12141 selected as current, and unless this was a vfork will have a
12142 different program space from the original thread. Reset that
12144 b
->loc
->pspace
= current_program_space
;
12148 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12149 If from_tty is nonzero, it prints a message to that effect,
12150 which ends with a period (no newline). */
12153 set_ignore_count (int bptnum
, int count
, int from_tty
)
12155 struct breakpoint
*b
;
12160 ALL_BREAKPOINTS (b
)
12161 if (b
->number
== bptnum
)
12163 if (is_tracepoint (b
))
12165 if (from_tty
&& count
!= 0)
12166 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12171 b
->ignore_count
= count
;
12175 printf_filtered (_("Will stop next time "
12176 "breakpoint %d is reached."),
12178 else if (count
== 1)
12179 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12182 printf_filtered (_("Will ignore next %d "
12183 "crossings of breakpoint %d."),
12186 breakpoints_changed ();
12187 observer_notify_breakpoint_modified (b
);
12191 error (_("No breakpoint number %d."), bptnum
);
12194 /* Command to set ignore-count of breakpoint N to COUNT. */
12197 ignore_command (char *args
, int from_tty
)
12203 error_no_arg (_("a breakpoint number"));
12205 num
= get_number (&p
);
12207 error (_("bad breakpoint number: '%s'"), args
);
12209 error (_("Second argument (specified ignore-count) is missing."));
12211 set_ignore_count (num
,
12212 longest_to_int (value_as_long (parse_and_eval (p
))),
12215 printf_filtered ("\n");
12218 /* Call FUNCTION on each of the breakpoints
12219 whose numbers are given in ARGS. */
12222 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
12227 struct breakpoint
*b
, *tmp
;
12229 struct get_number_or_range_state state
;
12232 error_no_arg (_("one or more breakpoint numbers"));
12234 init_number_or_range (&state
, args
);
12236 while (!state
.finished
)
12238 char *p
= state
.string
;
12242 num
= get_number_or_range (&state
);
12245 warning (_("bad breakpoint number at or near '%s'"), p
);
12249 ALL_BREAKPOINTS_SAFE (b
, tmp
)
12250 if (b
->number
== num
)
12253 function (b
, data
);
12257 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
12262 static struct bp_location
*
12263 find_location_by_number (char *number
)
12265 char *dot
= strchr (number
, '.');
12269 struct breakpoint
*b
;
12270 struct bp_location
*loc
;
12275 bp_num
= get_number (&p1
);
12277 error (_("Bad breakpoint number '%s'"), number
);
12279 ALL_BREAKPOINTS (b
)
12280 if (b
->number
== bp_num
)
12285 if (!b
|| b
->number
!= bp_num
)
12286 error (_("Bad breakpoint number '%s'"), number
);
12289 loc_num
= get_number (&p1
);
12291 error (_("Bad breakpoint location number '%s'"), number
);
12295 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12298 error (_("Bad breakpoint location number '%s'"), dot
+1);
12304 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12305 If from_tty is nonzero, it prints a message to that effect,
12306 which ends with a period (no newline). */
12309 disable_breakpoint (struct breakpoint
*bpt
)
12311 /* Never disable a watchpoint scope breakpoint; we want to
12312 hit them when we leave scope so we can delete both the
12313 watchpoint and its scope breakpoint at that time. */
12314 if (bpt
->type
== bp_watchpoint_scope
)
12317 /* You can't disable permanent breakpoints. */
12318 if (bpt
->enable_state
== bp_permanent
)
12321 bpt
->enable_state
= bp_disabled
;
12323 if (target_supports_enable_disable_tracepoint ()
12324 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12326 struct bp_location
*location
;
12328 for (location
= bpt
->loc
; location
; location
= location
->next
)
12329 target_disable_tracepoint (location
);
12332 update_global_location_list (0);
12334 observer_notify_breakpoint_modified (bpt
);
12337 /* A callback for iterate_over_related_breakpoints. */
12340 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12342 disable_breakpoint (b
);
12345 /* A callback for map_breakpoint_numbers that calls
12346 disable_breakpoint. */
12349 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12351 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12355 disable_command (char *args
, int from_tty
)
12359 struct breakpoint
*bpt
;
12361 ALL_BREAKPOINTS (bpt
)
12362 if (user_breakpoint_p (bpt
))
12363 disable_breakpoint (bpt
);
12365 else if (strchr (args
, '.'))
12367 struct bp_location
*loc
= find_location_by_number (args
);
12371 if (target_supports_enable_disable_tracepoint ()
12372 && current_trace_status ()->running
&& loc
->owner
12373 && is_tracepoint (loc
->owner
))
12374 target_disable_tracepoint (loc
);
12376 update_global_location_list (0);
12379 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12383 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12385 int target_resources_ok
;
12387 if (bpt
->type
== bp_hardware_breakpoint
)
12390 i
= hw_breakpoint_used_count ();
12391 target_resources_ok
=
12392 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12394 if (target_resources_ok
== 0)
12395 error (_("No hardware breakpoint support in the target."));
12396 else if (target_resources_ok
< 0)
12397 error (_("Hardware breakpoints used exceeds limit."));
12400 if (is_watchpoint (bpt
))
12402 /* Initialize it just to avoid a GCC false warning. */
12403 enum enable_state orig_enable_state
= 0;
12404 struct gdb_exception e
;
12406 TRY_CATCH (e
, RETURN_MASK_ALL
)
12408 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12410 orig_enable_state
= bpt
->enable_state
;
12411 bpt
->enable_state
= bp_enabled
;
12412 update_watchpoint (w
, 1 /* reparse */);
12416 bpt
->enable_state
= orig_enable_state
;
12417 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12423 if (bpt
->enable_state
!= bp_permanent
)
12424 bpt
->enable_state
= bp_enabled
;
12426 if (target_supports_enable_disable_tracepoint ()
12427 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12429 struct bp_location
*location
;
12431 for (location
= bpt
->loc
; location
; location
= location
->next
)
12432 target_enable_tracepoint (location
);
12435 bpt
->disposition
= disposition
;
12436 update_global_location_list (1);
12437 breakpoints_changed ();
12439 observer_notify_breakpoint_modified (bpt
);
12444 enable_breakpoint (struct breakpoint
*bpt
)
12446 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12450 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12452 enable_breakpoint (bpt
);
12455 /* A callback for map_breakpoint_numbers that calls
12456 enable_breakpoint. */
12459 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12461 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12464 /* The enable command enables the specified breakpoints (or all defined
12465 breakpoints) so they once again become (or continue to be) effective
12466 in stopping the inferior. */
12469 enable_command (char *args
, int from_tty
)
12473 struct breakpoint
*bpt
;
12475 ALL_BREAKPOINTS (bpt
)
12476 if (user_breakpoint_p (bpt
))
12477 enable_breakpoint (bpt
);
12479 else if (strchr (args
, '.'))
12481 struct bp_location
*loc
= find_location_by_number (args
);
12485 if (target_supports_enable_disable_tracepoint ()
12486 && current_trace_status ()->running
&& loc
->owner
12487 && is_tracepoint (loc
->owner
))
12488 target_enable_tracepoint (loc
);
12490 update_global_location_list (1);
12493 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12497 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12499 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12501 enable_breakpoint_disp (bpt
, disp
);
12505 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12507 enum bpdisp disp
= disp_disable
;
12509 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12513 enable_once_command (char *args
, int from_tty
)
12515 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12519 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12521 enum bpdisp disp
= disp_del
;
12523 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12527 enable_delete_command (char *args
, int from_tty
)
12529 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12533 set_breakpoint_cmd (char *args
, int from_tty
)
12538 show_breakpoint_cmd (char *args
, int from_tty
)
12542 /* Invalidate last known value of any hardware watchpoint if
12543 the memory which that value represents has been written to by
12547 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12548 const bfd_byte
*data
)
12550 struct breakpoint
*bp
;
12552 ALL_BREAKPOINTS (bp
)
12553 if (bp
->enable_state
== bp_enabled
12554 && bp
->type
== bp_hardware_watchpoint
)
12556 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12558 if (wp
->val_valid
&& wp
->val
)
12560 struct bp_location
*loc
;
12562 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12563 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12564 && loc
->address
+ loc
->length
> addr
12565 && addr
+ len
> loc
->address
)
12567 value_free (wp
->val
);
12575 /* Use the last displayed codepoint's values, or nothing
12576 if they aren't valid. */
12578 struct symtabs_and_lines
12579 decode_line_spec_1 (char *string
, int funfirstline
)
12581 struct symtabs_and_lines sals
;
12584 error (_("Empty line specification."));
12585 if (last_displayed_sal_is_valid ())
12586 sals
= decode_line_1 (&string
, funfirstline
,
12587 get_last_displayed_symtab (),
12588 get_last_displayed_line (),
12591 sals
= decode_line_1 (&string
, funfirstline
,
12592 (struct symtab
*) NULL
, 0, NULL
);
12594 error (_("Junk at end of line specification: %s"), string
);
12598 /* Create and insert a raw software breakpoint at PC. Return an
12599 identifier, which should be used to remove the breakpoint later.
12600 In general, places which call this should be using something on the
12601 breakpoint chain instead; this function should be eliminated
12605 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12606 struct address_space
*aspace
, CORE_ADDR pc
)
12608 struct bp_target_info
*bp_tgt
;
12610 bp_tgt
= XZALLOC (struct bp_target_info
);
12612 bp_tgt
->placed_address_space
= aspace
;
12613 bp_tgt
->placed_address
= pc
;
12615 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12617 /* Could not insert the breakpoint. */
12625 /* Remove a breakpoint BP inserted by
12626 deprecated_insert_raw_breakpoint. */
12629 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12631 struct bp_target_info
*bp_tgt
= bp
;
12634 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12640 /* One (or perhaps two) breakpoints used for software single
12643 static void *single_step_breakpoints
[2];
12644 static struct gdbarch
*single_step_gdbarch
[2];
12646 /* Create and insert a breakpoint for software single step. */
12649 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12650 struct address_space
*aspace
,
12655 if (single_step_breakpoints
[0] == NULL
)
12657 bpt_p
= &single_step_breakpoints
[0];
12658 single_step_gdbarch
[0] = gdbarch
;
12662 gdb_assert (single_step_breakpoints
[1] == NULL
);
12663 bpt_p
= &single_step_breakpoints
[1];
12664 single_step_gdbarch
[1] = gdbarch
;
12667 /* NOTE drow/2006-04-11: A future improvement to this function would
12668 be to only create the breakpoints once, and actually put them on
12669 the breakpoint chain. That would let us use set_raw_breakpoint.
12670 We could adjust the addresses each time they were needed. Doing
12671 this requires corresponding changes elsewhere where single step
12672 breakpoints are handled, however. So, for now, we use this. */
12674 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12675 if (*bpt_p
== NULL
)
12676 error (_("Could not insert single-step breakpoint at %s"),
12677 paddress (gdbarch
, next_pc
));
12680 /* Check if the breakpoints used for software single stepping
12681 were inserted or not. */
12684 single_step_breakpoints_inserted (void)
12686 return (single_step_breakpoints
[0] != NULL
12687 || single_step_breakpoints
[1] != NULL
);
12690 /* Remove and delete any breakpoints used for software single step. */
12693 remove_single_step_breakpoints (void)
12695 gdb_assert (single_step_breakpoints
[0] != NULL
);
12697 /* See insert_single_step_breakpoint for more about this deprecated
12699 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12700 single_step_breakpoints
[0]);
12701 single_step_gdbarch
[0] = NULL
;
12702 single_step_breakpoints
[0] = NULL
;
12704 if (single_step_breakpoints
[1] != NULL
)
12706 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12707 single_step_breakpoints
[1]);
12708 single_step_gdbarch
[1] = NULL
;
12709 single_step_breakpoints
[1] = NULL
;
12713 /* Delete software single step breakpoints without removing them from
12714 the inferior. This is intended to be used if the inferior's address
12715 space where they were inserted is already gone, e.g. after exit or
12719 cancel_single_step_breakpoints (void)
12723 for (i
= 0; i
< 2; i
++)
12724 if (single_step_breakpoints
[i
])
12726 xfree (single_step_breakpoints
[i
]);
12727 single_step_breakpoints
[i
] = NULL
;
12728 single_step_gdbarch
[i
] = NULL
;
12732 /* Detach software single-step breakpoints from INFERIOR_PTID without
12736 detach_single_step_breakpoints (void)
12740 for (i
= 0; i
< 2; i
++)
12741 if (single_step_breakpoints
[i
])
12742 target_remove_breakpoint (single_step_gdbarch
[i
],
12743 single_step_breakpoints
[i
]);
12746 /* Check whether a software single-step breakpoint is inserted at
12750 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12755 for (i
= 0; i
< 2; i
++)
12757 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12759 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12760 bp_tgt
->placed_address
,
12768 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12769 non-zero otherwise. */
12771 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12773 if (syscall_catchpoint_p (bp
)
12774 && bp
->enable_state
!= bp_disabled
12775 && bp
->enable_state
!= bp_call_disabled
)
12782 catch_syscall_enabled (void)
12784 struct inferior
*inf
= current_inferior ();
12786 return inf
->total_syscalls_count
!= 0;
12790 catching_syscall_number (int syscall_number
)
12792 struct breakpoint
*bp
;
12794 ALL_BREAKPOINTS (bp
)
12795 if (is_syscall_catchpoint_enabled (bp
))
12797 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12799 if (c
->syscalls_to_be_caught
)
12803 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12805 if (syscall_number
== iter
)
12815 /* Complete syscall names. Used by "catch syscall". */
12817 catch_syscall_completer (struct cmd_list_element
*cmd
,
12818 char *text
, char *word
)
12820 const char **list
= get_syscall_names ();
12822 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12828 /* Tracepoint-specific operations. */
12830 /* Set tracepoint count to NUM. */
12832 set_tracepoint_count (int num
)
12834 tracepoint_count
= num
;
12835 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12839 trace_command (char *arg
, int from_tty
)
12841 if (create_breakpoint (get_current_arch (),
12843 NULL
, 0, 1 /* parse arg */,
12845 bp_tracepoint
/* type_wanted */,
12846 0 /* Ignore count */,
12847 pending_break_support
,
12848 &tracepoint_breakpoint_ops
,
12852 set_tracepoint_count (breakpoint_count
);
12856 ftrace_command (char *arg
, int from_tty
)
12858 if (create_breakpoint (get_current_arch (),
12860 NULL
, 0, 1 /* parse arg */,
12862 bp_fast_tracepoint
/* type_wanted */,
12863 0 /* Ignore count */,
12864 pending_break_support
,
12865 &tracepoint_breakpoint_ops
,
12869 set_tracepoint_count (breakpoint_count
);
12872 /* strace command implementation. Creates a static tracepoint. */
12875 strace_command (char *arg
, int from_tty
)
12877 if (create_breakpoint (get_current_arch (),
12879 NULL
, 0, 1 /* parse arg */,
12881 bp_static_tracepoint
/* type_wanted */,
12882 0 /* Ignore count */,
12883 pending_break_support
,
12884 &tracepoint_breakpoint_ops
,
12888 set_tracepoint_count (breakpoint_count
);
12891 /* Set up a fake reader function that gets command lines from a linked
12892 list that was acquired during tracepoint uploading. */
12894 static struct uploaded_tp
*this_utp
;
12895 static int next_cmd
;
12898 read_uploaded_action (void)
12902 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12909 /* Given information about a tracepoint as recorded on a target (which
12910 can be either a live system or a trace file), attempt to create an
12911 equivalent GDB tracepoint. This is not a reliable process, since
12912 the target does not necessarily have all the information used when
12913 the tracepoint was originally defined. */
12915 struct tracepoint
*
12916 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12918 char *addr_str
, small_buf
[100];
12919 struct tracepoint
*tp
;
12921 if (utp
->at_string
)
12922 addr_str
= utp
->at_string
;
12925 /* In the absence of a source location, fall back to raw
12926 address. Since there is no way to confirm that the address
12927 means the same thing as when the trace was started, warn the
12929 warning (_("Uploaded tracepoint %d has no "
12930 "source location, using raw address"),
12932 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12933 addr_str
= small_buf
;
12936 /* There's not much we can do with a sequence of bytecodes. */
12937 if (utp
->cond
&& !utp
->cond_string
)
12938 warning (_("Uploaded tracepoint %d condition "
12939 "has no source form, ignoring it"),
12942 if (!create_breakpoint (get_current_arch (),
12944 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12946 utp
->type
/* type_wanted */,
12947 0 /* Ignore count */,
12948 pending_break_support
,
12949 &tracepoint_breakpoint_ops
,
12951 utp
->enabled
/* enabled */,
12955 set_tracepoint_count (breakpoint_count
);
12957 /* Get the tracepoint we just created. */
12958 tp
= get_tracepoint (tracepoint_count
);
12959 gdb_assert (tp
!= NULL
);
12963 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
12965 trace_pass_command (small_buf
, 0);
12968 /* If we have uploaded versions of the original commands, set up a
12969 special-purpose "reader" function and call the usual command line
12970 reader, then pass the result to the breakpoint command-setting
12972 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12974 struct command_line
*cmd_list
;
12979 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12981 breakpoint_set_commands (&tp
->base
, cmd_list
);
12983 else if (!VEC_empty (char_ptr
, utp
->actions
)
12984 || !VEC_empty (char_ptr
, utp
->step_actions
))
12985 warning (_("Uploaded tracepoint %d actions "
12986 "have no source form, ignoring them"),
12989 /* Copy any status information that might be available. */
12990 tp
->base
.hit_count
= utp
->hit_count
;
12991 tp
->traceframe_usage
= utp
->traceframe_usage
;
12996 /* Print information on tracepoint number TPNUM_EXP, or all if
13000 tracepoints_info (char *args
, int from_tty
)
13002 struct ui_out
*uiout
= current_uiout
;
13005 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
13007 if (num_printed
== 0)
13009 if (args
== NULL
|| *args
== '\0')
13010 ui_out_message (uiout
, 0, "No tracepoints.\n");
13012 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
13015 default_collect_info ();
13018 /* The 'enable trace' command enables tracepoints.
13019 Not supported by all targets. */
13021 enable_trace_command (char *args
, int from_tty
)
13023 enable_command (args
, from_tty
);
13026 /* The 'disable trace' command disables tracepoints.
13027 Not supported by all targets. */
13029 disable_trace_command (char *args
, int from_tty
)
13031 disable_command (args
, from_tty
);
13034 /* Remove a tracepoint (or all if no argument). */
13036 delete_trace_command (char *arg
, int from_tty
)
13038 struct breakpoint
*b
, *b_tmp
;
13044 int breaks_to_delete
= 0;
13046 /* Delete all breakpoints if no argument.
13047 Do not delete internal or call-dummy breakpoints, these
13048 have to be deleted with an explicit breakpoint number
13050 ALL_TRACEPOINTS (b
)
13051 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13053 breaks_to_delete
= 1;
13057 /* Ask user only if there are some breakpoints to delete. */
13059 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13061 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13062 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13063 delete_breakpoint (b
);
13067 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13070 /* Helper function for trace_pass_command. */
13073 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13075 tp
->pass_count
= count
;
13076 observer_notify_tracepoint_modified (tp
->base
.number
);
13078 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
13079 tp
->base
.number
, count
);
13082 /* Set passcount for tracepoint.
13084 First command argument is passcount, second is tracepoint number.
13085 If tracepoint number omitted, apply to most recently defined.
13086 Also accepts special argument "all". */
13089 trace_pass_command (char *args
, int from_tty
)
13091 struct tracepoint
*t1
;
13092 unsigned int count
;
13094 if (args
== 0 || *args
== 0)
13095 error (_("passcount command requires an "
13096 "argument (count + optional TP num)"));
13098 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
13100 while (*args
&& isspace ((int) *args
))
13103 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13105 struct breakpoint
*b
;
13107 args
+= 3; /* Skip special argument "all". */
13109 error (_("Junk at end of arguments."));
13111 ALL_TRACEPOINTS (b
)
13113 t1
= (struct tracepoint
*) b
;
13114 trace_pass_set_count (t1
, count
, from_tty
);
13117 else if (*args
== '\0')
13119 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
13121 trace_pass_set_count (t1
, count
, from_tty
);
13125 struct get_number_or_range_state state
;
13127 init_number_or_range (&state
, args
);
13128 while (!state
.finished
)
13130 t1
= get_tracepoint_by_number (&args
, &state
, 1);
13132 trace_pass_set_count (t1
, count
, from_tty
);
13137 struct tracepoint
*
13138 get_tracepoint (int num
)
13140 struct breakpoint
*t
;
13142 ALL_TRACEPOINTS (t
)
13143 if (t
->number
== num
)
13144 return (struct tracepoint
*) t
;
13149 /* Find the tracepoint with the given target-side number (which may be
13150 different from the tracepoint number after disconnecting and
13153 struct tracepoint
*
13154 get_tracepoint_by_number_on_target (int num
)
13156 struct breakpoint
*b
;
13158 ALL_TRACEPOINTS (b
)
13160 struct tracepoint
*t
= (struct tracepoint
*) b
;
13162 if (t
->number_on_target
== num
)
13169 /* Utility: parse a tracepoint number and look it up in the list.
13170 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13171 If OPTIONAL_P is true, then if the argument is missing, the most
13172 recent tracepoint (tracepoint_count) is returned. */
13173 struct tracepoint
*
13174 get_tracepoint_by_number (char **arg
,
13175 struct get_number_or_range_state
*state
,
13178 extern int tracepoint_count
;
13179 struct breakpoint
*t
;
13181 char *instring
= arg
== NULL
? NULL
: *arg
;
13185 gdb_assert (!state
->finished
);
13186 tpnum
= get_number_or_range (state
);
13188 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13191 tpnum
= tracepoint_count
;
13193 error_no_arg (_("tracepoint number"));
13196 tpnum
= get_number (arg
);
13200 if (instring
&& *instring
)
13201 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13204 printf_filtered (_("Tracepoint argument missing "
13205 "and no previous tracepoint\n"));
13209 ALL_TRACEPOINTS (t
)
13210 if (t
->number
== tpnum
)
13212 return (struct tracepoint
*) t
;
13215 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
13220 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
13222 if (b
->thread
!= -1)
13223 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
13226 fprintf_unfiltered (fp
, " task %d", b
->task
);
13228 fprintf_unfiltered (fp
, "\n");
13231 /* Save information on user settable breakpoints (watchpoints, etc) to
13232 a new script file named FILENAME. If FILTER is non-NULL, call it
13233 on each breakpoint and only include the ones for which it returns
13237 save_breakpoints (char *filename
, int from_tty
,
13238 int (*filter
) (const struct breakpoint
*))
13240 struct breakpoint
*tp
;
13243 struct cleanup
*cleanup
;
13244 struct ui_file
*fp
;
13245 int extra_trace_bits
= 0;
13247 if (filename
== 0 || *filename
== 0)
13248 error (_("Argument required (file name in which to save)"));
13250 /* See if we have anything to save. */
13251 ALL_BREAKPOINTS (tp
)
13253 /* Skip internal and momentary breakpoints. */
13254 if (!user_breakpoint_p (tp
))
13257 /* If we have a filter, only save the breakpoints it accepts. */
13258 if (filter
&& !filter (tp
))
13263 if (is_tracepoint (tp
))
13265 extra_trace_bits
= 1;
13267 /* We can stop searching. */
13274 warning (_("Nothing to save."));
13278 pathname
= tilde_expand (filename
);
13279 cleanup
= make_cleanup (xfree
, pathname
);
13280 fp
= gdb_fopen (pathname
, "w");
13282 error (_("Unable to open file '%s' for saving (%s)"),
13283 filename
, safe_strerror (errno
));
13284 make_cleanup_ui_file_delete (fp
);
13286 if (extra_trace_bits
)
13287 save_trace_state_variables (fp
);
13289 ALL_BREAKPOINTS (tp
)
13291 /* Skip internal and momentary breakpoints. */
13292 if (!user_breakpoint_p (tp
))
13295 /* If we have a filter, only save the breakpoints it accepts. */
13296 if (filter
&& !filter (tp
))
13299 tp
->ops
->print_recreate (tp
, fp
);
13301 /* Note, we can't rely on tp->number for anything, as we can't
13302 assume the recreated breakpoint numbers will match. Use $bpnum
13305 if (tp
->cond_string
)
13306 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13308 if (tp
->ignore_count
)
13309 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13313 volatile struct gdb_exception ex
;
13315 fprintf_unfiltered (fp
, " commands\n");
13317 ui_out_redirect (current_uiout
, fp
);
13318 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13320 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
13322 ui_out_redirect (current_uiout
, NULL
);
13325 throw_exception (ex
);
13327 fprintf_unfiltered (fp
, " end\n");
13330 if (tp
->enable_state
== bp_disabled
)
13331 fprintf_unfiltered (fp
, "disable\n");
13333 /* If this is a multi-location breakpoint, check if the locations
13334 should be individually disabled. Watchpoint locations are
13335 special, and not user visible. */
13336 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13338 struct bp_location
*loc
;
13341 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13343 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13347 if (extra_trace_bits
&& *default_collect
)
13348 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13350 do_cleanups (cleanup
);
13352 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13355 /* The `save breakpoints' command. */
13358 save_breakpoints_command (char *args
, int from_tty
)
13360 save_breakpoints (args
, from_tty
, NULL
);
13363 /* The `save tracepoints' command. */
13366 save_tracepoints_command (char *args
, int from_tty
)
13368 save_breakpoints (args
, from_tty
, is_tracepoint
);
13371 /* Create a vector of all tracepoints. */
13373 VEC(breakpoint_p
) *
13374 all_tracepoints (void)
13376 VEC(breakpoint_p
) *tp_vec
= 0;
13377 struct breakpoint
*tp
;
13379 ALL_TRACEPOINTS (tp
)
13381 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13388 /* This help string is used for the break, hbreak, tbreak and thbreak
13389 commands. It is defined as a macro to prevent duplication.
13390 COMMAND should be a string constant containing the name of the
13392 #define BREAK_ARGS_HELP(command) \
13393 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13394 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13395 If a line number is specified, break at start of code for that line.\n\
13396 If a function is specified, break at start of code for that function.\n\
13397 If an address is specified, break at that exact address.\n\
13398 With no LOCATION, uses current execution address of the selected\n\
13399 stack frame. This is useful for breaking on return to a stack frame.\n\
13401 THREADNUM is the number from \"info threads\".\n\
13402 CONDITION is a boolean expression.\n\
13404 Multiple breakpoints at one place are permitted, and useful if their\n\
13405 conditions are different.\n\
13407 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13409 /* List of subcommands for "catch". */
13410 static struct cmd_list_element
*catch_cmdlist
;
13412 /* List of subcommands for "tcatch". */
13413 static struct cmd_list_element
*tcatch_cmdlist
;
13416 add_catch_command (char *name
, char *docstring
,
13417 void (*sfunc
) (char *args
, int from_tty
,
13418 struct cmd_list_element
*command
),
13419 char **(*completer
) (struct cmd_list_element
*cmd
,
13420 char *text
, char *word
),
13421 void *user_data_catch
,
13422 void *user_data_tcatch
)
13424 struct cmd_list_element
*command
;
13426 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13428 set_cmd_sfunc (command
, sfunc
);
13429 set_cmd_context (command
, user_data_catch
);
13430 set_cmd_completer (command
, completer
);
13432 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13434 set_cmd_sfunc (command
, sfunc
);
13435 set_cmd_context (command
, user_data_tcatch
);
13436 set_cmd_completer (command
, completer
);
13440 clear_syscall_counts (struct inferior
*inf
)
13442 inf
->total_syscalls_count
= 0;
13443 inf
->any_syscall_count
= 0;
13444 VEC_free (int, inf
->syscalls_counts
);
13448 save_command (char *arg
, int from_tty
)
13450 printf_unfiltered (_("\"save\" must be followed by "
13451 "the name of a save subcommand.\n"));
13452 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13455 struct breakpoint
*
13456 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13459 struct breakpoint
*b
, *b_tmp
;
13461 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13463 if ((*callback
) (b
, data
))
13470 /* Zero if any of the breakpoint's locations could be a location where
13471 functions have been inlined, nonzero otherwise. */
13474 is_non_inline_function (struct breakpoint
*b
)
13476 /* The shared library event breakpoint is set on the address of a
13477 non-inline function. */
13478 if (b
->type
== bp_shlib_event
)
13484 /* Nonzero if the specified PC cannot be a location where functions
13485 have been inlined. */
13488 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
)
13490 struct breakpoint
*b
;
13491 struct bp_location
*bl
;
13493 ALL_BREAKPOINTS (b
)
13495 if (!is_non_inline_function (b
))
13498 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
13500 if (!bl
->shlib_disabled
13501 && bpstat_check_location (bl
, aspace
, pc
))
13510 initialize_breakpoint_ops (void)
13512 static int initialized
= 0;
13514 struct breakpoint_ops
*ops
;
13520 /* The breakpoint_ops structure to be inherit by all kinds of
13521 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13522 internal and momentary breakpoints, etc.). */
13523 ops
= &bkpt_base_breakpoint_ops
;
13524 *ops
= base_breakpoint_ops
;
13525 ops
->re_set
= bkpt_re_set
;
13526 ops
->insert_location
= bkpt_insert_location
;
13527 ops
->remove_location
= bkpt_remove_location
;
13528 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13530 /* The breakpoint_ops structure to be used in regular breakpoints. */
13531 ops
= &bkpt_breakpoint_ops
;
13532 *ops
= bkpt_base_breakpoint_ops
;
13533 ops
->re_set
= bkpt_re_set
;
13534 ops
->resources_needed
= bkpt_resources_needed
;
13535 ops
->print_it
= bkpt_print_it
;
13536 ops
->print_mention
= bkpt_print_mention
;
13537 ops
->print_recreate
= bkpt_print_recreate
;
13539 /* Ranged breakpoints. */
13540 ops
= &ranged_breakpoint_ops
;
13541 *ops
= bkpt_breakpoint_ops
;
13542 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13543 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13544 ops
->print_it
= print_it_ranged_breakpoint
;
13545 ops
->print_one
= print_one_ranged_breakpoint
;
13546 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13547 ops
->print_mention
= print_mention_ranged_breakpoint
;
13548 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13550 /* Internal breakpoints. */
13551 ops
= &internal_breakpoint_ops
;
13552 *ops
= bkpt_base_breakpoint_ops
;
13553 ops
->re_set
= internal_bkpt_re_set
;
13554 ops
->check_status
= internal_bkpt_check_status
;
13555 ops
->print_it
= internal_bkpt_print_it
;
13556 ops
->print_mention
= internal_bkpt_print_mention
;
13558 /* Momentary breakpoints. */
13559 ops
= &momentary_breakpoint_ops
;
13560 *ops
= bkpt_base_breakpoint_ops
;
13561 ops
->re_set
= momentary_bkpt_re_set
;
13562 ops
->check_status
= momentary_bkpt_check_status
;
13563 ops
->print_it
= momentary_bkpt_print_it
;
13564 ops
->print_mention
= momentary_bkpt_print_mention
;
13566 /* GNU v3 exception catchpoints. */
13567 ops
= &gnu_v3_exception_catchpoint_ops
;
13568 *ops
= bkpt_breakpoint_ops
;
13569 ops
->print_it
= print_it_exception_catchpoint
;
13570 ops
->print_one
= print_one_exception_catchpoint
;
13571 ops
->print_mention
= print_mention_exception_catchpoint
;
13572 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13575 ops
= &watchpoint_breakpoint_ops
;
13576 *ops
= base_breakpoint_ops
;
13577 ops
->dtor
= dtor_watchpoint
;
13578 ops
->re_set
= re_set_watchpoint
;
13579 ops
->insert_location
= insert_watchpoint
;
13580 ops
->remove_location
= remove_watchpoint
;
13581 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13582 ops
->check_status
= check_status_watchpoint
;
13583 ops
->resources_needed
= resources_needed_watchpoint
;
13584 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13585 ops
->print_it
= print_it_watchpoint
;
13586 ops
->print_mention
= print_mention_watchpoint
;
13587 ops
->print_recreate
= print_recreate_watchpoint
;
13589 /* Masked watchpoints. */
13590 ops
= &masked_watchpoint_breakpoint_ops
;
13591 *ops
= watchpoint_breakpoint_ops
;
13592 ops
->insert_location
= insert_masked_watchpoint
;
13593 ops
->remove_location
= remove_masked_watchpoint
;
13594 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13595 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13596 ops
->print_it
= print_it_masked_watchpoint
;
13597 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13598 ops
->print_mention
= print_mention_masked_watchpoint
;
13599 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13602 ops
= &tracepoint_breakpoint_ops
;
13603 *ops
= base_breakpoint_ops
;
13604 ops
->re_set
= tracepoint_re_set
;
13605 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13606 ops
->print_one_detail
= tracepoint_print_one_detail
;
13607 ops
->print_mention
= tracepoint_print_mention
;
13608 ops
->print_recreate
= tracepoint_print_recreate
;
13610 /* Fork catchpoints. */
13611 ops
= &catch_fork_breakpoint_ops
;
13612 *ops
= base_breakpoint_ops
;
13613 ops
->insert_location
= insert_catch_fork
;
13614 ops
->remove_location
= remove_catch_fork
;
13615 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13616 ops
->print_it
= print_it_catch_fork
;
13617 ops
->print_one
= print_one_catch_fork
;
13618 ops
->print_mention
= print_mention_catch_fork
;
13619 ops
->print_recreate
= print_recreate_catch_fork
;
13621 /* Vfork catchpoints. */
13622 ops
= &catch_vfork_breakpoint_ops
;
13623 *ops
= base_breakpoint_ops
;
13624 ops
->insert_location
= insert_catch_vfork
;
13625 ops
->remove_location
= remove_catch_vfork
;
13626 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13627 ops
->print_it
= print_it_catch_vfork
;
13628 ops
->print_one
= print_one_catch_vfork
;
13629 ops
->print_mention
= print_mention_catch_vfork
;
13630 ops
->print_recreate
= print_recreate_catch_vfork
;
13632 /* Exec catchpoints. */
13633 ops
= &catch_exec_breakpoint_ops
;
13634 *ops
= base_breakpoint_ops
;
13635 ops
->dtor
= dtor_catch_exec
;
13636 ops
->insert_location
= insert_catch_exec
;
13637 ops
->remove_location
= remove_catch_exec
;
13638 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13639 ops
->print_it
= print_it_catch_exec
;
13640 ops
->print_one
= print_one_catch_exec
;
13641 ops
->print_mention
= print_mention_catch_exec
;
13642 ops
->print_recreate
= print_recreate_catch_exec
;
13644 /* Syscall catchpoints. */
13645 ops
= &catch_syscall_breakpoint_ops
;
13646 *ops
= base_breakpoint_ops
;
13647 ops
->dtor
= dtor_catch_syscall
;
13648 ops
->insert_location
= insert_catch_syscall
;
13649 ops
->remove_location
= remove_catch_syscall
;
13650 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13651 ops
->print_it
= print_it_catch_syscall
;
13652 ops
->print_one
= print_one_catch_syscall
;
13653 ops
->print_mention
= print_mention_catch_syscall
;
13654 ops
->print_recreate
= print_recreate_catch_syscall
;
13658 _initialize_breakpoint (void)
13660 struct cmd_list_element
*c
;
13662 initialize_breakpoint_ops ();
13664 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13665 observer_attach_inferior_exit (clear_syscall_counts
);
13666 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13668 breakpoint_objfile_key
= register_objfile_data ();
13670 breakpoint_chain
= 0;
13671 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13672 before a breakpoint is set. */
13673 breakpoint_count
= 0;
13675 tracepoint_count
= 0;
13677 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13678 Set ignore-count of breakpoint number N to COUNT.\n\
13679 Usage is `ignore N COUNT'."));
13681 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13683 add_com ("commands", class_breakpoint
, commands_command
, _("\
13684 Set commands to be executed when a breakpoint is hit.\n\
13685 Give breakpoint number as argument after \"commands\".\n\
13686 With no argument, the targeted breakpoint is the last one set.\n\
13687 The commands themselves follow starting on the next line.\n\
13688 Type a line containing \"end\" to indicate the end of them.\n\
13689 Give \"silent\" as the first line to make the breakpoint silent;\n\
13690 then no output is printed when it is hit, except what the commands print."));
13692 add_com ("condition", class_breakpoint
, condition_command
, _("\
13693 Specify breakpoint number N to break only if COND is true.\n\
13694 Usage is `condition N COND', where N is an integer and COND is an\n\
13695 expression to be evaluated whenever breakpoint N is reached."));
13697 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13698 Set a temporary breakpoint.\n\
13699 Like \"break\" except the breakpoint is only temporary,\n\
13700 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13701 by using \"enable delete\" on the breakpoint number.\n\
13703 BREAK_ARGS_HELP ("tbreak")));
13704 set_cmd_completer (c
, location_completer
);
13706 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13707 Set a hardware assisted breakpoint.\n\
13708 Like \"break\" except the breakpoint requires hardware support,\n\
13709 some target hardware may not have this support.\n\
13711 BREAK_ARGS_HELP ("hbreak")));
13712 set_cmd_completer (c
, location_completer
);
13714 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13715 Set a temporary hardware assisted breakpoint.\n\
13716 Like \"hbreak\" except the breakpoint is only temporary,\n\
13717 so it will be deleted when hit.\n\
13719 BREAK_ARGS_HELP ("thbreak")));
13720 set_cmd_completer (c
, location_completer
);
13722 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13723 Enable some breakpoints.\n\
13724 Give breakpoint numbers (separated by spaces) as arguments.\n\
13725 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13726 This is used to cancel the effect of the \"disable\" command.\n\
13727 With a subcommand you can enable temporarily."),
13728 &enablelist
, "enable ", 1, &cmdlist
);
13730 add_com ("ab", class_breakpoint
, enable_command
, _("\
13731 Enable some breakpoints.\n\
13732 Give breakpoint numbers (separated by spaces) as arguments.\n\
13733 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13734 This is used to cancel the effect of the \"disable\" command.\n\
13735 With a subcommand you can enable temporarily."));
13737 add_com_alias ("en", "enable", class_breakpoint
, 1);
13739 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13740 Enable some breakpoints.\n\
13741 Give breakpoint numbers (separated by spaces) as arguments.\n\
13742 This is used to cancel the effect of the \"disable\" command.\n\
13743 May be abbreviated to simply \"enable\".\n"),
13744 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13746 add_cmd ("once", no_class
, enable_once_command
, _("\
13747 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13748 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13751 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13752 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13753 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13756 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13757 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13758 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13761 add_cmd ("once", no_class
, enable_once_command
, _("\
13762 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13763 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13766 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13767 Disable some breakpoints.\n\
13768 Arguments are breakpoint numbers with spaces in between.\n\
13769 To disable all breakpoints, give no argument.\n\
13770 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13771 &disablelist
, "disable ", 1, &cmdlist
);
13772 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13773 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13775 add_com ("sb", class_breakpoint
, disable_command
, _("\
13776 Disable some breakpoints.\n\
13777 Arguments are breakpoint numbers with spaces in between.\n\
13778 To disable all breakpoints, give no argument.\n\
13779 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13781 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13782 Disable some breakpoints.\n\
13783 Arguments are breakpoint numbers with spaces in between.\n\
13784 To disable all breakpoints, give no argument.\n\
13785 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13786 This command may be abbreviated \"disable\"."),
13789 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13790 Delete some breakpoints or auto-display expressions.\n\
13791 Arguments are breakpoint numbers with spaces in between.\n\
13792 To delete all breakpoints, give no argument.\n\
13794 Also a prefix command for deletion of other GDB objects.\n\
13795 The \"unset\" command is also an alias for \"delete\"."),
13796 &deletelist
, "delete ", 1, &cmdlist
);
13797 add_com_alias ("d", "delete", class_breakpoint
, 1);
13798 add_com_alias ("del", "delete", class_breakpoint
, 1);
13800 add_com ("db", class_breakpoint
, delete_command
, _("\
13801 Delete some breakpoints.\n\
13802 Arguments are breakpoint numbers with spaces in between.\n\
13803 To delete all breakpoints, give no argument.\n"));
13805 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13806 Delete some breakpoints or auto-display expressions.\n\
13807 Arguments are breakpoint numbers with spaces in between.\n\
13808 To delete all breakpoints, give no argument.\n\
13809 This command may be abbreviated \"delete\"."),
13812 add_com ("clear", class_breakpoint
, clear_command
, _("\
13813 Clear breakpoint at specified line or function.\n\
13814 Argument may be line number, function name, or \"*\" and an address.\n\
13815 If line number is specified, all breakpoints in that line are cleared.\n\
13816 If function is specified, breakpoints at beginning of function are cleared.\n\
13817 If an address is specified, breakpoints at that address are cleared.\n\
13819 With no argument, clears all breakpoints in the line that the selected frame\n\
13820 is executing in.\n\
13822 See also the \"delete\" command which clears breakpoints by number."));
13823 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13825 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13826 Set breakpoint at specified line or function.\n"
13827 BREAK_ARGS_HELP ("break")));
13828 set_cmd_completer (c
, location_completer
);
13830 add_com_alias ("b", "break", class_run
, 1);
13831 add_com_alias ("br", "break", class_run
, 1);
13832 add_com_alias ("bre", "break", class_run
, 1);
13833 add_com_alias ("brea", "break", class_run
, 1);
13836 add_com_alias ("ba", "break", class_breakpoint
, 1);
13840 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13841 Break in function/address or break at a line in the current file."),
13842 &stoplist
, "stop ", 1, &cmdlist
);
13843 add_cmd ("in", class_breakpoint
, stopin_command
,
13844 _("Break in function or address."), &stoplist
);
13845 add_cmd ("at", class_breakpoint
, stopat_command
,
13846 _("Break at a line in the current file."), &stoplist
);
13847 add_com ("status", class_info
, breakpoints_info
, _("\
13848 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13849 The \"Type\" column indicates one of:\n\
13850 \tbreakpoint - normal breakpoint\n\
13851 \twatchpoint - watchpoint\n\
13852 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13853 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13854 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13855 address and file/line number respectively.\n\
13857 Convenience variable \"$_\" and default examine address for \"x\"\n\
13858 are set to the address of the last breakpoint listed unless the command\n\
13859 is prefixed with \"server \".\n\n\
13860 Convenience variable \"$bpnum\" contains the number of the last\n\
13861 breakpoint set."));
13864 add_info ("breakpoints", breakpoints_info
, _("\
13865 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13866 The \"Type\" column indicates one of:\n\
13867 \tbreakpoint - normal breakpoint\n\
13868 \twatchpoint - watchpoint\n\
13869 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13870 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13871 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13872 address and file/line number respectively.\n\
13874 Convenience variable \"$_\" and default examine address for \"x\"\n\
13875 are set to the address of the last breakpoint listed unless the command\n\
13876 is prefixed with \"server \".\n\n\
13877 Convenience variable \"$bpnum\" contains the number of the last\n\
13878 breakpoint set."));
13880 add_info_alias ("b", "breakpoints", 1);
13883 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13884 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13885 The \"Type\" column indicates one of:\n\
13886 \tbreakpoint - normal breakpoint\n\
13887 \twatchpoint - watchpoint\n\
13888 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13889 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13890 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13891 address and file/line number respectively.\n\
13893 Convenience variable \"$_\" and default examine address for \"x\"\n\
13894 are set to the address of the last breakpoint listed unless the command\n\
13895 is prefixed with \"server \".\n\n\
13896 Convenience variable \"$bpnum\" contains the number of the last\n\
13897 breakpoint set."));
13899 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13900 Status of all breakpoints, or breakpoint number NUMBER.\n\
13901 The \"Type\" column indicates one of:\n\
13902 \tbreakpoint - normal breakpoint\n\
13903 \twatchpoint - watchpoint\n\
13904 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13905 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13906 \tuntil - internal breakpoint used by the \"until\" command\n\
13907 \tfinish - internal breakpoint used by the \"finish\" command\n\
13908 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13909 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13910 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13911 address and file/line number respectively.\n\
13913 Convenience variable \"$_\" and default examine address for \"x\"\n\
13914 are set to the address of the last breakpoint listed unless the command\n\
13915 is prefixed with \"server \".\n\n\
13916 Convenience variable \"$bpnum\" contains the number of the last\n\
13918 &maintenanceinfolist
);
13920 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13921 Set catchpoints to catch events."),
13922 &catch_cmdlist
, "catch ",
13923 0/*allow-unknown*/, &cmdlist
);
13925 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13926 Set temporary catchpoints to catch events."),
13927 &tcatch_cmdlist
, "tcatch ",
13928 0/*allow-unknown*/, &cmdlist
);
13930 /* Add catch and tcatch sub-commands. */
13931 add_catch_command ("catch", _("\
13932 Catch an exception, when caught.\n\
13933 With an argument, catch only exceptions with the given name."),
13934 catch_catch_command
,
13938 add_catch_command ("throw", _("\
13939 Catch an exception, when thrown.\n\
13940 With an argument, catch only exceptions with the given name."),
13941 catch_throw_command
,
13945 add_catch_command ("fork", _("Catch calls to fork."),
13946 catch_fork_command_1
,
13948 (void *) (uintptr_t) catch_fork_permanent
,
13949 (void *) (uintptr_t) catch_fork_temporary
);
13950 add_catch_command ("vfork", _("Catch calls to vfork."),
13951 catch_fork_command_1
,
13953 (void *) (uintptr_t) catch_vfork_permanent
,
13954 (void *) (uintptr_t) catch_vfork_temporary
);
13955 add_catch_command ("exec", _("Catch calls to exec."),
13956 catch_exec_command_1
,
13960 add_catch_command ("syscall", _("\
13961 Catch system calls by their names and/or numbers.\n\
13962 Arguments say which system calls to catch. If no arguments\n\
13963 are given, every system call will be caught.\n\
13964 Arguments, if given, should be one or more system call names\n\
13965 (if your system supports that), or system call numbers."),
13966 catch_syscall_command_1
,
13967 catch_syscall_completer
,
13971 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13972 Set a watchpoint for an expression.\n\
13973 Usage: watch [-l|-location] EXPRESSION\n\
13974 A watchpoint stops execution of your program whenever the value of\n\
13975 an expression changes.\n\
13976 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13977 the memory to which it refers."));
13978 set_cmd_completer (c
, expression_completer
);
13980 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13981 Set a read watchpoint for an expression.\n\
13982 Usage: rwatch [-l|-location] EXPRESSION\n\
13983 A watchpoint stops execution of your program whenever the value of\n\
13984 an expression is read.\n\
13985 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13986 the memory to which it refers."));
13987 set_cmd_completer (c
, expression_completer
);
13989 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13990 Set a watchpoint for an expression.\n\
13991 Usage: awatch [-l|-location] EXPRESSION\n\
13992 A watchpoint stops execution of your program whenever the value of\n\
13993 an expression is either read or written.\n\
13994 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13995 the memory to which it refers."));
13996 set_cmd_completer (c
, expression_completer
);
13998 add_info ("watchpoints", watchpoints_info
, _("\
13999 Status of specified watchpoints (all watchpoints if no argument)."));
14001 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14002 respond to changes - contrary to the description. */
14003 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14004 &can_use_hw_watchpoints
, _("\
14005 Set debugger's willingness to use watchpoint hardware."), _("\
14006 Show debugger's willingness to use watchpoint hardware."), _("\
14007 If zero, gdb will not use hardware for new watchpoints, even if\n\
14008 such is available. (However, any hardware watchpoints that were\n\
14009 created before setting this to nonzero, will continue to use watchpoint\n\
14012 show_can_use_hw_watchpoints
,
14013 &setlist
, &showlist
);
14015 can_use_hw_watchpoints
= 1;
14017 /* Tracepoint manipulation commands. */
14019 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
14020 Set a tracepoint at specified line or function.\n\
14022 BREAK_ARGS_HELP ("trace") "\n\
14023 Do \"help tracepoints\" for info on other tracepoint commands."));
14024 set_cmd_completer (c
, location_completer
);
14026 add_com_alias ("tp", "trace", class_alias
, 0);
14027 add_com_alias ("tr", "trace", class_alias
, 1);
14028 add_com_alias ("tra", "trace", class_alias
, 1);
14029 add_com_alias ("trac", "trace", class_alias
, 1);
14031 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14032 Set a fast tracepoint at specified line or function.\n\
14034 BREAK_ARGS_HELP ("ftrace") "\n\
14035 Do \"help tracepoints\" for info on other tracepoint commands."));
14036 set_cmd_completer (c
, location_completer
);
14038 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14039 Set a static tracepoint at specified line, function or marker.\n\
14041 strace [LOCATION] [if CONDITION]\n\
14042 LOCATION may be a line number, function name, \"*\" and an address,\n\
14043 or -m MARKER_ID.\n\
14044 If a line number is specified, probe the marker at start of code\n\
14045 for that line. If a function is specified, probe the marker at start\n\
14046 of code for that function. If an address is specified, probe the marker\n\
14047 at that exact address. If a marker id is specified, probe the marker\n\
14048 with that name. With no LOCATION, uses current execution address of\n\
14049 the selected stack frame.\n\
14050 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14051 This collects arbitrary user data passed in the probe point call to the\n\
14052 tracing library. You can inspect it when analyzing the trace buffer,\n\
14053 by printing the $_sdata variable like any other convenience variable.\n\
14055 CONDITION is a boolean expression.\n\
14057 Multiple tracepoints at one place are permitted, and useful if their\n\
14058 conditions are different.\n\
14060 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14061 Do \"help tracepoints\" for info on other tracepoint commands."));
14062 set_cmd_completer (c
, location_completer
);
14064 add_info ("tracepoints", tracepoints_info
, _("\
14065 Status of specified tracepoints (all tracepoints if no argument).\n\
14066 Convenience variable \"$tpnum\" contains the number of the\n\
14067 last tracepoint set."));
14069 add_info_alias ("tp", "tracepoints", 1);
14071 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14072 Delete specified tracepoints.\n\
14073 Arguments are tracepoint numbers, separated by spaces.\n\
14074 No argument means delete all tracepoints."),
14077 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14078 Disable specified tracepoints.\n\
14079 Arguments are tracepoint numbers, separated by spaces.\n\
14080 No argument means disable all tracepoints."),
14082 deprecate_cmd (c
, "disable");
14084 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14085 Enable specified tracepoints.\n\
14086 Arguments are tracepoint numbers, separated by spaces.\n\
14087 No argument means enable all tracepoints."),
14089 deprecate_cmd (c
, "enable");
14091 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14092 Set the passcount for a tracepoint.\n\
14093 The trace will end when the tracepoint has been passed 'count' times.\n\
14094 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14095 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14097 add_prefix_cmd ("save", class_breakpoint
, save_command
,
14098 _("Save breakpoint definitions as a script."),
14099 &save_cmdlist
, "save ",
14100 0/*allow-unknown*/, &cmdlist
);
14102 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14103 Save current breakpoint definitions as a script.\n\
14104 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14105 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14106 session to restore them."),
14108 set_cmd_completer (c
, filename_completer
);
14110 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14111 Save current tracepoint definitions as a script.\n\
14112 Use the 'source' command in another debug session to restore them."),
14114 set_cmd_completer (c
, filename_completer
);
14116 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
14117 deprecate_cmd (c
, "save tracepoints");
14119 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
14120 Breakpoint specific settings\n\
14121 Configure various breakpoint-specific variables such as\n\
14122 pending breakpoint behavior"),
14123 &breakpoint_set_cmdlist
, "set breakpoint ",
14124 0/*allow-unknown*/, &setlist
);
14125 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
14126 Breakpoint specific settings\n\
14127 Configure various breakpoint-specific variables such as\n\
14128 pending breakpoint behavior"),
14129 &breakpoint_show_cmdlist
, "show breakpoint ",
14130 0/*allow-unknown*/, &showlist
);
14132 add_setshow_auto_boolean_cmd ("pending", no_class
,
14133 &pending_break_support
, _("\
14134 Set debugger's behavior regarding pending breakpoints."), _("\
14135 Show debugger's behavior regarding pending breakpoints."), _("\
14136 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14137 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14138 an error. If auto, an unrecognized breakpoint location results in a\n\
14139 user-query to see if a pending breakpoint should be created."),
14141 show_pending_break_support
,
14142 &breakpoint_set_cmdlist
,
14143 &breakpoint_show_cmdlist
);
14145 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14147 add_setshow_boolean_cmd ("auto-hw", no_class
,
14148 &automatic_hardware_breakpoints
, _("\
14149 Set automatic usage of hardware breakpoints."), _("\
14150 Show automatic usage of hardware breakpoints."), _("\
14151 If set, the debugger will automatically use hardware breakpoints for\n\
14152 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14153 a warning will be emitted for such breakpoints."),
14155 show_automatic_hardware_breakpoints
,
14156 &breakpoint_set_cmdlist
,
14157 &breakpoint_show_cmdlist
);
14159 add_setshow_enum_cmd ("always-inserted", class_support
,
14160 always_inserted_enums
, &always_inserted_mode
, _("\
14161 Set mode for inserting breakpoints."), _("\
14162 Show mode for inserting breakpoints."), _("\
14163 When this mode is off, breakpoints are inserted in inferior when it is\n\
14164 resumed, and removed when execution stops. When this mode is on,\n\
14165 breakpoints are inserted immediately and removed only when the user\n\
14166 deletes the breakpoint. When this mode is auto (which is the default),\n\
14167 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14168 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14169 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14170 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14172 &show_always_inserted_mode
,
14173 &breakpoint_set_cmdlist
,
14174 &breakpoint_show_cmdlist
);
14176 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14177 Set a breakpoint for an address range.\n\
14178 break-range START-LOCATION, END-LOCATION\n\
14179 where START-LOCATION and END-LOCATION can be one of the following:\n\
14180 LINENUM, for that line in the current file,\n\
14181 FILE:LINENUM, for that line in that file,\n\
14182 +OFFSET, for that number of lines after the current line\n\
14183 or the start of the range\n\
14184 FUNCTION, for the first line in that function,\n\
14185 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14186 *ADDRESS, for the instruction at that address.\n\
14188 The breakpoint will stop execution of the inferior whenever it executes\n\
14189 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14190 range (including START-LOCATION and END-LOCATION)."));
14192 automatic_hardware_breakpoints
= 1;
14194 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);