1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
42 #include "filenames.h"
48 #include "completer.h"
51 #include "cli/cli-script.h"
52 #include "gdb_assert.h"
57 #include "exceptions.h"
64 #include "xml-syscall.h"
65 #include "parser-defs.h"
66 #include "cli/cli-utils.h"
67 #include "continuations.h"
69 /* readline include files */
70 #include "readline/readline.h"
71 #include "readline/history.h"
73 /* readline defines this. */
76 #include "mi/mi-common.h"
77 #include "python/python.h"
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void breakpoint_re_set_default (struct breakpoint
*);
99 static void clear_command (char *, int);
101 static void catch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value
*);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint
*);
109 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
111 const struct breakpoint_ops
*);
112 /* This function is used in gdbtk sources and thus can not be made
114 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
115 struct symtab_and_line
,
117 const struct breakpoint_ops
*);
119 static struct breakpoint
*
120 momentary_breakpoint_from_master (struct breakpoint
*orig
,
122 const struct breakpoint_ops
*ops
);
124 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
126 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
130 static void describe_other_breakpoints (struct gdbarch
*,
131 struct program_space
*, CORE_ADDR
,
132 struct obj_section
*, int);
134 static int breakpoint_address_match (struct address_space
*aspace1
,
136 struct address_space
*aspace2
,
139 static int watchpoint_locations_match (struct bp_location
*loc1
,
140 struct bp_location
*loc2
);
142 static int breakpoint_location_address_match (struct bp_location
*bl
,
143 struct address_space
*aspace
,
146 static void breakpoints_info (char *, int);
148 static void watchpoints_info (char *, int);
150 static int breakpoint_1 (char *, int,
151 int (*) (const struct breakpoint
*));
153 static int breakpoint_cond_eval (void *);
155 static void cleanup_executing_breakpoints (void *);
157 static void commands_command (char *, int);
159 static void condition_command (char *, int);
168 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
169 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
171 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
173 static int watchpoint_check (void *);
175 static void maintenance_info_breakpoints (char *, int);
177 static int hw_breakpoint_used_count (void);
179 static int hw_watchpoint_used_count (enum bptype
, int *);
181 static void hbreak_command (char *, int);
183 static void thbreak_command (char *, int);
185 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
);
187 static void stop_command (char *arg
, int from_tty
);
189 static void stopin_command (char *arg
, int from_tty
);
191 static void stopat_command (char *arg
, int from_tty
);
193 static char *ep_parse_optional_if_clause (char **arg
);
195 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
196 char *arg
, int tempflag
, int from_tty
);
198 static void tcatch_command (char *arg
, int from_tty
);
200 static void detach_single_step_breakpoints (void);
202 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
205 static void free_bp_location (struct bp_location
*loc
);
206 static void incref_bp_location (struct bp_location
*loc
);
207 static void decref_bp_location (struct bp_location
**loc
);
209 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
211 static void update_global_location_list (int);
213 static void update_global_location_list_nothrow (int);
215 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
217 static void insert_breakpoint_locations (void);
219 static int syscall_catchpoint_p (struct breakpoint
*b
);
221 static void tracepoints_info (char *, int);
223 static void delete_trace_command (char *, int);
225 static void enable_trace_command (char *, int);
227 static void disable_trace_command (char *, int);
229 static void trace_pass_command (char *, int);
231 static int is_masked_watchpoint (const struct breakpoint
*b
);
233 /* Assuming we're creating a static tracepoint, does S look like a
234 static tracepoint marker spec ("-m MARKER_ID")? */
235 #define is_marker_spec(s) \
236 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
238 /* The abstract base class all breakpoint_ops structures inherit
240 static struct breakpoint_ops base_breakpoint_ops
;
242 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
243 that are implemented on top of software or hardware breakpoints
244 (user breakpoints, internal and momentary breakpoints, etc.). */
245 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
247 /* Internal breakpoints class type. */
248 static struct breakpoint_ops internal_breakpoint_ops
;
250 /* Momentary breakpoints class type. */
251 static struct breakpoint_ops momentary_breakpoint_ops
;
253 /* The breakpoint_ops structure to be used in regular user created
255 struct breakpoint_ops bkpt_breakpoint_ops
;
257 /* A reference-counted struct command_line. This lets multiple
258 breakpoints share a single command list. */
259 struct counted_command_line
261 /* The reference count. */
264 /* The command list. */
265 struct command_line
*commands
;
268 struct command_line
*
269 breakpoint_commands (struct breakpoint
*b
)
271 return b
->commands
? b
->commands
->commands
: NULL
;
274 /* Flag indicating that a command has proceeded the inferior past the
275 current breakpoint. */
277 static int breakpoint_proceeded
;
280 bpdisp_text (enum bpdisp disp
)
282 /* NOTE: the following values are a part of MI protocol and
283 represent values of 'disp' field returned when inferior stops at
285 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
287 return bpdisps
[(int) disp
];
290 /* Prototypes for exported functions. */
291 /* If FALSE, gdb will not use hardware support for watchpoints, even
292 if such is available. */
293 static int can_use_hw_watchpoints
;
296 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
297 struct cmd_list_element
*c
,
300 fprintf_filtered (file
,
301 _("Debugger's willingness to use "
302 "watchpoint hardware is %s.\n"),
306 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
307 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
308 for unrecognized breakpoint locations.
309 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
310 static enum auto_boolean pending_break_support
;
312 show_pending_break_support (struct ui_file
*file
, int from_tty
,
313 struct cmd_list_element
*c
,
316 fprintf_filtered (file
,
317 _("Debugger's behavior regarding "
318 "pending breakpoints is %s.\n"),
322 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
323 set with "break" but falling in read-only memory.
324 If 0, gdb will warn about such breakpoints, but won't automatically
325 use hardware breakpoints. */
326 static int automatic_hardware_breakpoints
;
328 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
329 struct cmd_list_element
*c
,
332 fprintf_filtered (file
,
333 _("Automatic usage of hardware breakpoints is %s.\n"),
337 /* If on, gdb will keep breakpoints inserted even as inferior is
338 stopped, and immediately insert any new breakpoints. If off, gdb
339 will insert breakpoints into inferior only when resuming it, and
340 will remove breakpoints upon stop. If auto, GDB will behave as ON
341 if in non-stop mode, and as OFF if all-stop mode.*/
343 static const char always_inserted_auto
[] = "auto";
344 static const char always_inserted_on
[] = "on";
345 static const char always_inserted_off
[] = "off";
346 static const char *always_inserted_enums
[] = {
347 always_inserted_auto
,
352 static const char *always_inserted_mode
= always_inserted_auto
;
354 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
355 struct cmd_list_element
*c
, const char *value
)
357 if (always_inserted_mode
== always_inserted_auto
)
358 fprintf_filtered (file
,
359 _("Always inserted breakpoint "
360 "mode is %s (currently %s).\n"),
362 breakpoints_always_inserted_mode () ? "on" : "off");
364 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
369 breakpoints_always_inserted_mode (void)
371 return (always_inserted_mode
== always_inserted_on
372 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
375 void _initialize_breakpoint (void);
377 /* Are we executing breakpoint commands? */
378 static int executing_breakpoint_commands
;
380 /* Are overlay event breakpoints enabled? */
381 static int overlay_events_enabled
;
383 /* See description in breakpoint.h. */
384 int target_exact_watchpoints
= 0;
386 /* Walk the following statement or block through all breakpoints.
387 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
388 current breakpoint. */
390 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
392 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
393 for (B = breakpoint_chain; \
394 B ? (TMP=B->next, 1): 0; \
397 /* Similar iterator for the low-level breakpoints. SAFE variant is
398 not provided so update_global_location_list must not be called
399 while executing the block of ALL_BP_LOCATIONS. */
401 #define ALL_BP_LOCATIONS(B,BP_TMP) \
402 for (BP_TMP = bp_location; \
403 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
406 /* Iterator for tracepoints only. */
408 #define ALL_TRACEPOINTS(B) \
409 for (B = breakpoint_chain; B; B = B->next) \
410 if (is_tracepoint (B))
412 /* Chains of all breakpoints defined. */
414 struct breakpoint
*breakpoint_chain
;
416 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
418 static struct bp_location
**bp_location
;
420 /* Number of elements of BP_LOCATION. */
422 static unsigned bp_location_count
;
424 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
425 ADDRESS for the current elements of BP_LOCATION which get a valid
426 result from bp_location_has_shadow. You can use it for roughly
427 limiting the subrange of BP_LOCATION to scan for shadow bytes for
428 an address you need to read. */
430 static CORE_ADDR bp_location_placed_address_before_address_max
;
432 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
433 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
434 BP_LOCATION which get a valid result from bp_location_has_shadow.
435 You can use it for roughly limiting the subrange of BP_LOCATION to
436 scan for shadow bytes for an address you need to read. */
438 static CORE_ADDR bp_location_shadow_len_after_address_max
;
440 /* The locations that no longer correspond to any breakpoint, unlinked
441 from bp_location array, but for which a hit may still be reported
443 VEC(bp_location_p
) *moribund_locations
= NULL
;
445 /* Number of last breakpoint made. */
447 static int breakpoint_count
;
449 /* The value of `breakpoint_count' before the last command that
450 created breakpoints. If the last (break-like) command created more
451 than one breakpoint, then the difference between BREAKPOINT_COUNT
452 and PREV_BREAKPOINT_COUNT is more than one. */
453 static int prev_breakpoint_count
;
455 /* Number of last tracepoint made. */
457 static int tracepoint_count
;
459 static struct cmd_list_element
*breakpoint_set_cmdlist
;
460 static struct cmd_list_element
*breakpoint_show_cmdlist
;
461 struct cmd_list_element
*save_cmdlist
;
463 /* Return whether a breakpoint is an active enabled breakpoint. */
465 breakpoint_enabled (struct breakpoint
*b
)
467 return (b
->enable_state
== bp_enabled
);
470 /* Set breakpoint count to NUM. */
473 set_breakpoint_count (int num
)
475 prev_breakpoint_count
= breakpoint_count
;
476 breakpoint_count
= num
;
477 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
480 /* Used by `start_rbreak_breakpoints' below, to record the current
481 breakpoint count before "rbreak" creates any breakpoint. */
482 static int rbreak_start_breakpoint_count
;
484 /* Called at the start an "rbreak" command to record the first
488 start_rbreak_breakpoints (void)
490 rbreak_start_breakpoint_count
= breakpoint_count
;
493 /* Called at the end of an "rbreak" command to record the last
497 end_rbreak_breakpoints (void)
499 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
502 /* Used in run_command to zero the hit count when a new run starts. */
505 clear_breakpoint_hit_counts (void)
507 struct breakpoint
*b
;
513 /* Allocate a new counted_command_line with reference count of 1.
514 The new structure owns COMMANDS. */
516 static struct counted_command_line
*
517 alloc_counted_command_line (struct command_line
*commands
)
519 struct counted_command_line
*result
520 = xmalloc (sizeof (struct counted_command_line
));
523 result
->commands
= commands
;
527 /* Increment reference count. This does nothing if CMD is NULL. */
530 incref_counted_command_line (struct counted_command_line
*cmd
)
536 /* Decrement reference count. If the reference count reaches 0,
537 destroy the counted_command_line. Sets *CMDP to NULL. This does
538 nothing if *CMDP is NULL. */
541 decref_counted_command_line (struct counted_command_line
**cmdp
)
545 if (--(*cmdp
)->refc
== 0)
547 free_command_lines (&(*cmdp
)->commands
);
554 /* A cleanup function that calls decref_counted_command_line. */
557 do_cleanup_counted_command_line (void *arg
)
559 decref_counted_command_line (arg
);
562 /* Create a cleanup that calls decref_counted_command_line on the
565 static struct cleanup
*
566 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
568 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
571 /* Default address, symtab and line to put a breakpoint at
572 for "break" command with no arg.
573 If default_breakpoint_valid is zero, the other three are
574 not valid, and "break" with no arg is an error.
576 This set by print_stack_frame, which calls set_default_breakpoint. */
578 int default_breakpoint_valid
;
579 CORE_ADDR default_breakpoint_address
;
580 struct symtab
*default_breakpoint_symtab
;
581 int default_breakpoint_line
;
582 struct program_space
*default_breakpoint_pspace
;
585 /* Return the breakpoint with the specified number, or NULL
586 if the number does not refer to an existing breakpoint. */
589 get_breakpoint (int num
)
591 struct breakpoint
*b
;
594 if (b
->number
== num
)
603 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
606 xfree (b
->cond_string
);
607 b
->cond_string
= NULL
;
609 if (is_watchpoint (b
))
611 struct watchpoint
*w
= (struct watchpoint
*) b
;
618 struct bp_location
*loc
;
620 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
630 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
636 /* I don't know if it matters whether this is the string the user
637 typed in or the decompiled expression. */
638 b
->cond_string
= xstrdup (arg
);
639 b
->condition_not_parsed
= 0;
641 if (is_watchpoint (b
))
643 struct watchpoint
*w
= (struct watchpoint
*) b
;
645 innermost_block
= NULL
;
647 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
649 error (_("Junk at end of expression"));
650 w
->cond_exp_valid_block
= innermost_block
;
654 struct bp_location
*loc
;
656 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
660 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
662 error (_("Junk at end of expression"));
666 breakpoints_changed ();
667 observer_notify_breakpoint_modified (b
);
670 /* condition N EXP -- set break condition of breakpoint N to EXP. */
673 condition_command (char *arg
, int from_tty
)
675 struct breakpoint
*b
;
680 error_no_arg (_("breakpoint number"));
683 bnum
= get_number (&p
);
685 error (_("Bad breakpoint argument: '%s'"), arg
);
688 if (b
->number
== bnum
)
690 /* Check if this breakpoint has a Python object assigned to
691 it, and if it has a definition of the "stop"
692 method. This method and conditions entered into GDB from
693 the CLI are mutually exclusive. */
695 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
696 error (_("Cannot set a condition where a Python 'stop' "
697 "method has been defined in the breakpoint."));
698 set_breakpoint_condition (b
, p
, from_tty
);
702 error (_("No breakpoint number %d."), bnum
);
705 /* Check that COMMAND do not contain commands that are suitable
706 only for tracepoints and not suitable for ordinary breakpoints.
707 Throw if any such commands is found. */
710 check_no_tracepoint_commands (struct command_line
*commands
)
712 struct command_line
*c
;
714 for (c
= commands
; c
; c
= c
->next
)
718 if (c
->control_type
== while_stepping_control
)
719 error (_("The 'while-stepping' command can "
720 "only be used for tracepoints"));
722 for (i
= 0; i
< c
->body_count
; ++i
)
723 check_no_tracepoint_commands ((c
->body_list
)[i
]);
725 /* Not that command parsing removes leading whitespace and comment
726 lines and also empty lines. So, we only need to check for
728 if (strstr (c
->line
, "collect ") == c
->line
)
729 error (_("The 'collect' command can only be used for tracepoints"));
731 if (strstr (c
->line
, "teval ") == c
->line
)
732 error (_("The 'teval' command can only be used for tracepoints"));
736 /* Encapsulate tests for different types of tracepoints. */
739 is_tracepoint_type (enum bptype type
)
741 return (type
== bp_tracepoint
742 || type
== bp_fast_tracepoint
743 || type
== bp_static_tracepoint
);
747 is_tracepoint (const struct breakpoint
*b
)
749 return is_tracepoint_type (b
->type
);
752 /* A helper function that validates that COMMANDS are valid for a
753 breakpoint. This function will throw an exception if a problem is
757 validate_commands_for_breakpoint (struct breakpoint
*b
,
758 struct command_line
*commands
)
760 if (is_tracepoint (b
))
762 /* We need to verify that each top-level element of commands is
763 valid for tracepoints, that there's at most one
764 while-stepping element, and that while-stepping's body has
765 valid tracing commands excluding nested while-stepping. */
766 struct command_line
*c
;
767 struct command_line
*while_stepping
= 0;
768 for (c
= commands
; c
; c
= c
->next
)
770 if (c
->control_type
== while_stepping_control
)
772 if (b
->type
== bp_fast_tracepoint
)
773 error (_("The 'while-stepping' command "
774 "cannot be used for fast tracepoint"));
775 else if (b
->type
== bp_static_tracepoint
)
776 error (_("The 'while-stepping' command "
777 "cannot be used for static tracepoint"));
780 error (_("The 'while-stepping' command "
781 "can be used only once"));
788 struct command_line
*c2
;
790 gdb_assert (while_stepping
->body_count
== 1);
791 c2
= while_stepping
->body_list
[0];
792 for (; c2
; c2
= c2
->next
)
794 if (c2
->control_type
== while_stepping_control
)
795 error (_("The 'while-stepping' command cannot be nested"));
801 check_no_tracepoint_commands (commands
);
805 /* Return a vector of all the static tracepoints set at ADDR. The
806 caller is responsible for releasing the vector. */
809 static_tracepoints_here (CORE_ADDR addr
)
811 struct breakpoint
*b
;
812 VEC(breakpoint_p
) *found
= 0;
813 struct bp_location
*loc
;
816 if (b
->type
== bp_static_tracepoint
)
818 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
819 if (loc
->address
== addr
)
820 VEC_safe_push(breakpoint_p
, found
, b
);
826 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
827 validate that only allowed commands are included. */
830 breakpoint_set_commands (struct breakpoint
*b
,
831 struct command_line
*commands
)
833 validate_commands_for_breakpoint (b
, commands
);
835 decref_counted_command_line (&b
->commands
);
836 b
->commands
= alloc_counted_command_line (commands
);
837 breakpoints_changed ();
838 observer_notify_breakpoint_modified (b
);
841 /* Set the internal `silent' flag on the breakpoint. Note that this
842 is not the same as the "silent" that may appear in the breakpoint's
846 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
848 int old_silent
= b
->silent
;
851 if (old_silent
!= silent
)
852 observer_notify_breakpoint_modified (b
);
855 /* Set the thread for this breakpoint. If THREAD is -1, make the
856 breakpoint work for any thread. */
859 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
861 int old_thread
= b
->thread
;
864 if (old_thread
!= thread
)
865 observer_notify_breakpoint_modified (b
);
868 /* Set the task for this breakpoint. If TASK is 0, make the
869 breakpoint work for any task. */
872 breakpoint_set_task (struct breakpoint
*b
, int task
)
874 int old_task
= b
->task
;
877 if (old_task
!= task
)
878 observer_notify_breakpoint_modified (b
);
882 check_tracepoint_command (char *line
, void *closure
)
884 struct breakpoint
*b
= closure
;
886 validate_actionline (&line
, b
);
889 /* A structure used to pass information through
890 map_breakpoint_numbers. */
894 /* True if the command was typed at a tty. */
897 /* The breakpoint range spec. */
900 /* Non-NULL if the body of the commands are being read from this
901 already-parsed command. */
902 struct command_line
*control
;
904 /* The command lines read from the user, or NULL if they have not
906 struct counted_command_line
*cmd
;
909 /* A callback for map_breakpoint_numbers that sets the commands for
913 do_map_commands_command (struct breakpoint
*b
, void *data
)
915 struct commands_info
*info
= data
;
917 if (info
->cmd
== NULL
)
919 struct command_line
*l
;
921 if (info
->control
!= NULL
)
922 l
= copy_command_lines (info
->control
->body_list
[0]);
925 struct cleanup
*old_chain
;
928 str
= xstrprintf (_("Type commands for breakpoint(s) "
929 "%s, one per line."),
932 old_chain
= make_cleanup (xfree
, str
);
934 l
= read_command_lines (str
,
937 ? check_tracepoint_command
: 0),
940 do_cleanups (old_chain
);
943 info
->cmd
= alloc_counted_command_line (l
);
946 /* If a breakpoint was on the list more than once, we don't need to
948 if (b
->commands
!= info
->cmd
)
950 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
951 incref_counted_command_line (info
->cmd
);
952 decref_counted_command_line (&b
->commands
);
953 b
->commands
= info
->cmd
;
954 breakpoints_changed ();
955 observer_notify_breakpoint_modified (b
);
960 commands_command_1 (char *arg
, int from_tty
,
961 struct command_line
*control
)
963 struct cleanup
*cleanups
;
964 struct commands_info info
;
966 info
.from_tty
= from_tty
;
967 info
.control
= control
;
969 /* If we read command lines from the user, then `info' will hold an
970 extra reference to the commands that we must clean up. */
971 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
973 if (arg
== NULL
|| !*arg
)
975 if (breakpoint_count
- prev_breakpoint_count
> 1)
976 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
978 else if (breakpoint_count
> 0)
979 arg
= xstrprintf ("%d", breakpoint_count
);
982 /* So that we don't try to free the incoming non-NULL
983 argument in the cleanup below. Mapping breakpoint
984 numbers will fail in this case. */
989 /* The command loop has some static state, so we need to preserve
994 make_cleanup (xfree
, arg
);
998 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1000 if (info
.cmd
== NULL
)
1001 error (_("No breakpoints specified."));
1003 do_cleanups (cleanups
);
1007 commands_command (char *arg
, int from_tty
)
1009 commands_command_1 (arg
, from_tty
, NULL
);
1012 /* Like commands_command, but instead of reading the commands from
1013 input stream, takes them from an already parsed command structure.
1015 This is used by cli-script.c to DTRT with breakpoint commands
1016 that are part of if and while bodies. */
1017 enum command_control_type
1018 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1020 commands_command_1 (arg
, 0, cmd
);
1021 return simple_control
;
1024 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1027 bp_location_has_shadow (struct bp_location
*bl
)
1029 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1033 if (bl
->target_info
.shadow_len
== 0)
1034 /* BL isn't valid, or doesn't shadow memory. */
1039 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1040 by replacing any memory breakpoints with their shadowed contents.
1042 The range of shadowed area by each bp_location is:
1043 bl->address - bp_location_placed_address_before_address_max
1044 up to bl->address + bp_location_shadow_len_after_address_max
1045 The range we were requested to resolve shadows for is:
1046 memaddr ... memaddr + len
1047 Thus the safe cutoff boundaries for performance optimization are
1048 memaddr + len <= (bl->address
1049 - bp_location_placed_address_before_address_max)
1051 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1054 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1056 /* Left boundary, right boundary and median element of our binary
1058 unsigned bc_l
, bc_r
, bc
;
1060 /* Find BC_L which is a leftmost element which may affect BUF
1061 content. It is safe to report lower value but a failure to
1062 report higher one. */
1065 bc_r
= bp_location_count
;
1066 while (bc_l
+ 1 < bc_r
)
1068 struct bp_location
*bl
;
1070 bc
= (bc_l
+ bc_r
) / 2;
1071 bl
= bp_location
[bc
];
1073 /* Check first BL->ADDRESS will not overflow due to the added
1074 constant. Then advance the left boundary only if we are sure
1075 the BC element can in no way affect the BUF content (MEMADDR
1076 to MEMADDR + LEN range).
1078 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1079 offset so that we cannot miss a breakpoint with its shadow
1080 range tail still reaching MEMADDR. */
1082 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1084 && (bl
->address
+ bp_location_shadow_len_after_address_max
1091 /* Due to the binary search above, we need to make sure we pick the
1092 first location that's at BC_L's address. E.g., if there are
1093 multiple locations at the same address, BC_L may end up pointing
1094 at a duplicate location, and miss the "master"/"inserted"
1095 location. Say, given locations L1, L2 and L3 at addresses A and
1098 L1@A, L2@A, L3@B, ...
1100 BC_L could end up pointing at location L2, while the "master"
1101 location could be L1. Since the `loc->inserted' flag is only set
1102 on "master" locations, we'd forget to restore the shadow of L1
1105 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1108 /* Now do full processing of the found relevant range of elements. */
1110 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1112 struct bp_location
*bl
= bp_location
[bc
];
1113 CORE_ADDR bp_addr
= 0;
1117 /* bp_location array has BL->OWNER always non-NULL. */
1118 if (bl
->owner
->type
== bp_none
)
1119 warning (_("reading through apparently deleted breakpoint #%d?"),
1122 /* Performance optimization: any further element can no longer affect BUF
1125 if (bl
->address
>= bp_location_placed_address_before_address_max
1126 && memaddr
+ len
<= (bl
->address
1127 - bp_location_placed_address_before_address_max
))
1130 if (!bp_location_has_shadow (bl
))
1132 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1133 current_program_space
->aspace
, 0))
1136 /* Addresses and length of the part of the breakpoint that
1138 bp_addr
= bl
->target_info
.placed_address
;
1139 bp_size
= bl
->target_info
.shadow_len
;
1141 if (bp_addr
+ bp_size
<= memaddr
)
1142 /* The breakpoint is entirely before the chunk of memory we
1146 if (bp_addr
>= memaddr
+ len
)
1147 /* The breakpoint is entirely after the chunk of memory we are
1151 /* Offset within shadow_contents. */
1152 if (bp_addr
< memaddr
)
1154 /* Only copy the second part of the breakpoint. */
1155 bp_size
-= memaddr
- bp_addr
;
1156 bptoffset
= memaddr
- bp_addr
;
1160 if (bp_addr
+ bp_size
> memaddr
+ len
)
1162 /* Only copy the first part of the breakpoint. */
1163 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1166 memcpy (buf
+ bp_addr
- memaddr
,
1167 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1172 /* Return true if BPT is of any hardware watchpoint kind. */
1175 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1177 return (bpt
->type
== bp_hardware_watchpoint
1178 || bpt
->type
== bp_read_watchpoint
1179 || bpt
->type
== bp_access_watchpoint
);
1182 /* Return true if BPT is of any watchpoint kind, hardware or
1186 is_watchpoint (const struct breakpoint
*bpt
)
1188 return (is_hardware_watchpoint (bpt
)
1189 || bpt
->type
== bp_watchpoint
);
1192 /* Returns true if the current thread and its running state are safe
1193 to evaluate or update watchpoint B. Watchpoints on local
1194 expressions need to be evaluated in the context of the thread that
1195 was current when the watchpoint was created, and, that thread needs
1196 to be stopped to be able to select the correct frame context.
1197 Watchpoints on global expressions can be evaluated on any thread,
1198 and in any state. It is presently left to the target allowing
1199 memory accesses when threads are running. */
1202 watchpoint_in_thread_scope (struct watchpoint
*b
)
1204 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1205 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1206 && !is_executing (inferior_ptid
)));
1209 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1210 associated bp_watchpoint_scope breakpoint. */
1213 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1215 struct breakpoint
*b
= &w
->base
;
1217 if (b
->related_breakpoint
!= b
)
1219 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1220 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1221 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1222 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1223 b
->related_breakpoint
= b
;
1225 b
->disposition
= disp_del_at_next_stop
;
1228 /* Assuming that B is a watchpoint:
1229 - Reparse watchpoint expression, if REPARSE is non-zero
1230 - Evaluate expression and store the result in B->val
1231 - Evaluate the condition if there is one, and store the result
1233 - Update the list of values that must be watched in B->loc.
1235 If the watchpoint disposition is disp_del_at_next_stop, then do
1236 nothing. If this is local watchpoint that is out of scope, delete
1239 Even with `set breakpoint always-inserted on' the watchpoints are
1240 removed + inserted on each stop here. Normal breakpoints must
1241 never be removed because they might be missed by a running thread
1242 when debugging in non-stop mode. On the other hand, hardware
1243 watchpoints (is_hardware_watchpoint; processed here) are specific
1244 to each LWP since they are stored in each LWP's hardware debug
1245 registers. Therefore, such LWP must be stopped first in order to
1246 be able to modify its hardware watchpoints.
1248 Hardware watchpoints must be reset exactly once after being
1249 presented to the user. It cannot be done sooner, because it would
1250 reset the data used to present the watchpoint hit to the user. And
1251 it must not be done later because it could display the same single
1252 watchpoint hit during multiple GDB stops. Note that the latter is
1253 relevant only to the hardware watchpoint types bp_read_watchpoint
1254 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1255 not user-visible - its hit is suppressed if the memory content has
1258 The following constraints influence the location where we can reset
1259 hardware watchpoints:
1261 * target_stopped_by_watchpoint and target_stopped_data_address are
1262 called several times when GDB stops.
1265 * Multiple hardware watchpoints can be hit at the same time,
1266 causing GDB to stop. GDB only presents one hardware watchpoint
1267 hit at a time as the reason for stopping, and all the other hits
1268 are presented later, one after the other, each time the user
1269 requests the execution to be resumed. Execution is not resumed
1270 for the threads still having pending hit event stored in
1271 LWP_INFO->STATUS. While the watchpoint is already removed from
1272 the inferior on the first stop the thread hit event is kept being
1273 reported from its cached value by linux_nat_stopped_data_address
1274 until the real thread resume happens after the watchpoint gets
1275 presented and thus its LWP_INFO->STATUS gets reset.
1277 Therefore the hardware watchpoint hit can get safely reset on the
1278 watchpoint removal from inferior. */
1281 update_watchpoint (struct watchpoint
*b
, int reparse
)
1283 int within_current_scope
;
1284 struct frame_id saved_frame_id
;
1287 /* If this is a local watchpoint, we only want to check if the
1288 watchpoint frame is in scope if the current thread is the thread
1289 that was used to create the watchpoint. */
1290 if (!watchpoint_in_thread_scope (b
))
1293 if (b
->base
.disposition
== disp_del_at_next_stop
)
1298 /* Determine if the watchpoint is within scope. */
1299 if (b
->exp_valid_block
== NULL
)
1300 within_current_scope
= 1;
1303 struct frame_info
*fi
= get_current_frame ();
1304 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1305 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1307 /* If we're in a function epilogue, unwinding may not work
1308 properly, so do not attempt to recreate locations at this
1309 point. See similar comments in watchpoint_check. */
1310 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1313 /* Save the current frame's ID so we can restore it after
1314 evaluating the watchpoint expression on its own frame. */
1315 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1316 took a frame parameter, so that we didn't have to change the
1319 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1321 fi
= frame_find_by_id (b
->watchpoint_frame
);
1322 within_current_scope
= (fi
!= NULL
);
1323 if (within_current_scope
)
1327 /* We don't free locations. They are stored in the bp_location array
1328 and update_global_location_list will eventually delete them and
1329 remove breakpoints if needed. */
1332 if (within_current_scope
&& reparse
)
1341 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1342 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1343 /* If the meaning of expression itself changed, the old value is
1344 no longer relevant. We don't want to report a watchpoint hit
1345 to the user when the old value and the new value may actually
1346 be completely different objects. */
1347 value_free (b
->val
);
1351 /* Note that unlike with breakpoints, the watchpoint's condition
1352 expression is stored in the breakpoint object, not in the
1353 locations (re)created below. */
1354 if (b
->base
.cond_string
!= NULL
)
1356 if (b
->cond_exp
!= NULL
)
1358 xfree (b
->cond_exp
);
1362 s
= b
->base
.cond_string
;
1363 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1367 /* If we failed to parse the expression, for example because
1368 it refers to a global variable in a not-yet-loaded shared library,
1369 don't try to insert watchpoint. We don't automatically delete
1370 such watchpoint, though, since failure to parse expression
1371 is different from out-of-scope watchpoint. */
1372 if ( !target_has_execution
)
1374 /* Without execution, memory can't change. No use to try and
1375 set watchpoint locations. The watchpoint will be reset when
1376 the target gains execution, through breakpoint_re_set. */
1378 else if (within_current_scope
&& b
->exp
)
1381 struct value
*val_chain
, *v
, *result
, *next
;
1382 struct program_space
*frame_pspace
;
1384 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1386 /* Avoid setting b->val if it's already set. The meaning of
1387 b->val is 'the last value' user saw, and we should update
1388 it only if we reported that last value to user. As it
1389 happens, the code that reports it updates b->val directly.
1390 We don't keep track of the memory value for masked
1392 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1398 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1400 /* Look at each value on the value chain. */
1401 for (v
= val_chain
; v
; v
= value_next (v
))
1403 /* If it's a memory location, and GDB actually needed
1404 its contents to evaluate the expression, then we
1405 must watch it. If the first value returned is
1406 still lazy, that means an error occurred reading it;
1407 watch it anyway in case it becomes readable. */
1408 if (VALUE_LVAL (v
) == lval_memory
1409 && (v
== val_chain
|| ! value_lazy (v
)))
1411 struct type
*vtype
= check_typedef (value_type (v
));
1413 /* We only watch structs and arrays if user asked
1414 for it explicitly, never if they just happen to
1415 appear in the middle of some value chain. */
1417 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1418 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1422 struct bp_location
*loc
, **tmp
;
1424 addr
= value_address (v
);
1425 len
= TYPE_LENGTH (value_type (v
));
1427 if (b
->base
.type
== bp_read_watchpoint
)
1429 else if (b
->base
.type
== bp_access_watchpoint
)
1432 loc
= allocate_bp_location (&b
->base
);
1433 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1436 loc
->gdbarch
= get_type_arch (value_type (v
));
1438 loc
->pspace
= frame_pspace
;
1439 loc
->address
= addr
;
1441 loc
->watchpoint_type
= type
;
1446 /* Change the type of breakpoint between hardware assisted or
1447 an ordinary watchpoint depending on the hardware support
1448 and free hardware slots. REPARSE is set when the inferior
1453 enum bp_loc_type loc_type
;
1454 struct bp_location
*bl
;
1456 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1460 int i
, target_resources_ok
, other_type_used
;
1462 /* Use an exact watchpoint when there's only one memory region to be
1463 watched, and only one debug register is needed to watch it. */
1464 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1466 /* We need to determine how many resources are already
1467 used for all other hardware watchpoints plus this one
1468 to see if we still have enough resources to also fit
1469 this watchpoint in as well. To guarantee the
1470 hw_watchpoint_used_count call below counts this
1471 watchpoint, make sure that it is marked as a hardware
1473 if (b
->base
.type
== bp_watchpoint
)
1474 b
->base
.type
= bp_hardware_watchpoint
;
1476 i
= hw_watchpoint_used_count (b
->base
.type
, &other_type_used
);
1477 target_resources_ok
= target_can_use_hardware_watchpoint
1478 (b
->base
.type
, i
, other_type_used
);
1479 if (target_resources_ok
<= 0)
1481 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1483 if (target_resources_ok
== 0 && !sw_mode
)
1484 error (_("Target does not support this type of "
1485 "hardware watchpoint."));
1486 else if (target_resources_ok
< 0 && !sw_mode
)
1487 error (_("There are not enough available hardware "
1488 "resources for this watchpoint."));
1490 b
->base
.type
= bp_watchpoint
;
1493 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1494 error (_("Expression cannot be implemented with "
1495 "read/access watchpoint."));
1497 b
->base
.type
= bp_watchpoint
;
1499 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1500 : bp_loc_hardware_watchpoint
);
1501 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1502 bl
->loc_type
= loc_type
;
1505 for (v
= val_chain
; v
; v
= next
)
1507 next
= value_next (v
);
1512 /* If a software watchpoint is not watching any memory, then the
1513 above left it without any location set up. But,
1514 bpstat_stop_status requires a location to be able to report
1515 stops, so make sure there's at least a dummy one. */
1516 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1518 struct breakpoint
*base
= &b
->base
;
1519 base
->loc
= allocate_bp_location (base
);
1520 base
->loc
->pspace
= frame_pspace
;
1521 base
->loc
->address
= -1;
1522 base
->loc
->length
= -1;
1523 base
->loc
->watchpoint_type
= -1;
1526 else if (!within_current_scope
)
1528 printf_filtered (_("\
1529 Watchpoint %d deleted because the program has left the block\n\
1530 in which its expression is valid.\n"),
1532 watchpoint_del_at_next_stop (b
);
1535 /* Restore the selected frame. */
1537 select_frame (frame_find_by_id (saved_frame_id
));
1541 /* Returns 1 iff breakpoint location should be
1542 inserted in the inferior. */
1544 should_be_inserted (struct bp_location
*bl
)
1546 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1549 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1552 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1555 /* This is set for example, when we're attached to the parent of a
1556 vfork, and have detached from the child. The child is running
1557 free, and we expect it to do an exec or exit, at which point the
1558 OS makes the parent schedulable again (and the target reports
1559 that the vfork is done). Until the child is done with the shared
1560 memory region, do not insert breakpoints in the parent, otherwise
1561 the child could still trip on the parent's breakpoints. Since
1562 the parent is blocked anyway, it won't miss any breakpoint. */
1563 if (bl
->pspace
->breakpoints_not_allowed
)
1566 /* Tracepoints are inserted by the target at a time of its choosing,
1568 if (is_tracepoint (bl
->owner
))
1574 /* Same as should_be_inserted but does the check assuming
1575 that the location is not duplicated. */
1578 unduplicated_should_be_inserted (struct bp_location
*bl
)
1581 const int save_duplicate
= bl
->duplicate
;
1584 result
= should_be_inserted (bl
);
1585 bl
->duplicate
= save_duplicate
;
1589 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1590 location. Any error messages are printed to TMP_ERROR_STREAM; and
1591 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1592 Returns 0 for success, 1 if the bp_location type is not supported or
1595 NOTE drow/2003-09-09: This routine could be broken down to an
1596 object-style method for each breakpoint or catchpoint type. */
1598 insert_bp_location (struct bp_location
*bl
,
1599 struct ui_file
*tmp_error_stream
,
1600 int *disabled_breaks
,
1601 int *hw_breakpoint_error
)
1605 if (!should_be_inserted (bl
) || bl
->inserted
)
1608 /* Initialize the target-specific information. */
1609 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1610 bl
->target_info
.placed_address
= bl
->address
;
1611 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1612 bl
->target_info
.length
= bl
->length
;
1614 if (bl
->loc_type
== bp_loc_software_breakpoint
1615 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1617 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1619 /* If the explicitly specified breakpoint type
1620 is not hardware breakpoint, check the memory map to see
1621 if the breakpoint address is in read only memory or not.
1623 Two important cases are:
1624 - location type is not hardware breakpoint, memory
1625 is readonly. We change the type of the location to
1626 hardware breakpoint.
1627 - location type is hardware breakpoint, memory is
1628 read-write. This means we've previously made the
1629 location hardware one, but then the memory map changed,
1632 When breakpoints are removed, remove_breakpoints will use
1633 location types we've just set here, the only possible
1634 problem is that memory map has changed during running
1635 program, but it's not going to work anyway with current
1637 struct mem_region
*mr
1638 = lookup_mem_region (bl
->target_info
.placed_address
);
1642 if (automatic_hardware_breakpoints
)
1644 enum bp_loc_type new_type
;
1646 if (mr
->attrib
.mode
!= MEM_RW
)
1647 new_type
= bp_loc_hardware_breakpoint
;
1649 new_type
= bp_loc_software_breakpoint
;
1651 if (new_type
!= bl
->loc_type
)
1653 static int said
= 0;
1655 bl
->loc_type
= new_type
;
1658 fprintf_filtered (gdb_stdout
,
1659 _("Note: automatically using "
1660 "hardware breakpoints for "
1661 "read-only addresses.\n"));
1666 else if (bl
->loc_type
== bp_loc_software_breakpoint
1667 && mr
->attrib
.mode
!= MEM_RW
)
1668 warning (_("cannot set software breakpoint "
1669 "at readonly address %s"),
1670 paddress (bl
->gdbarch
, bl
->address
));
1674 /* First check to see if we have to handle an overlay. */
1675 if (overlay_debugging
== ovly_off
1676 || bl
->section
== NULL
1677 || !(section_is_overlay (bl
->section
)))
1679 /* No overlay handling: just set the breakpoint. */
1681 val
= bl
->owner
->ops
->insert_location (bl
);
1685 /* This breakpoint is in an overlay section.
1686 Shall we set a breakpoint at the LMA? */
1687 if (!overlay_events_enabled
)
1689 /* Yes -- overlay event support is not active,
1690 so we must try to set a breakpoint at the LMA.
1691 This will not work for a hardware breakpoint. */
1692 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1693 warning (_("hardware breakpoint %d not supported in overlay!"),
1697 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1699 /* Set a software (trap) breakpoint at the LMA. */
1700 bl
->overlay_target_info
= bl
->target_info
;
1701 bl
->overlay_target_info
.placed_address
= addr
;
1702 val
= target_insert_breakpoint (bl
->gdbarch
,
1703 &bl
->overlay_target_info
);
1705 fprintf_unfiltered (tmp_error_stream
,
1706 "Overlay breakpoint %d "
1707 "failed: in ROM?\n",
1711 /* Shall we set a breakpoint at the VMA? */
1712 if (section_is_mapped (bl
->section
))
1714 /* Yes. This overlay section is mapped into memory. */
1715 val
= bl
->owner
->ops
->insert_location (bl
);
1719 /* No. This breakpoint will not be inserted.
1720 No error, but do not mark the bp as 'inserted'. */
1727 /* Can't set the breakpoint. */
1728 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1730 /* See also: disable_breakpoints_in_shlibs. */
1732 bl
->shlib_disabled
= 1;
1733 observer_notify_breakpoint_modified (bl
->owner
);
1734 if (!*disabled_breaks
)
1736 fprintf_unfiltered (tmp_error_stream
,
1737 "Cannot insert breakpoint %d.\n",
1739 fprintf_unfiltered (tmp_error_stream
,
1740 "Temporarily disabling shared "
1741 "library breakpoints:\n");
1743 *disabled_breaks
= 1;
1744 fprintf_unfiltered (tmp_error_stream
,
1745 "breakpoint #%d\n", bl
->owner
->number
);
1749 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1751 *hw_breakpoint_error
= 1;
1752 fprintf_unfiltered (tmp_error_stream
,
1753 "Cannot insert hardware "
1759 fprintf_unfiltered (tmp_error_stream
,
1760 "Cannot insert breakpoint %d.\n",
1762 fprintf_filtered (tmp_error_stream
,
1763 "Error accessing memory address ");
1764 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1766 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1767 safe_strerror (val
));
1778 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1779 /* NOTE drow/2003-09-08: This state only exists for removing
1780 watchpoints. It's not clear that it's necessary... */
1781 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1783 gdb_assert (bl
->owner
->ops
!= NULL
1784 && bl
->owner
->ops
->insert_location
!= NULL
);
1786 val
= bl
->owner
->ops
->insert_location (bl
);
1788 /* If trying to set a read-watchpoint, and it turns out it's not
1789 supported, try emulating one with an access watchpoint. */
1790 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1792 struct bp_location
*loc
, **loc_temp
;
1794 /* But don't try to insert it, if there's already another
1795 hw_access location that would be considered a duplicate
1797 ALL_BP_LOCATIONS (loc
, loc_temp
)
1799 && loc
->watchpoint_type
== hw_access
1800 && watchpoint_locations_match (bl
, loc
))
1804 bl
->target_info
= loc
->target_info
;
1805 bl
->watchpoint_type
= hw_access
;
1812 bl
->watchpoint_type
= hw_access
;
1813 val
= bl
->owner
->ops
->insert_location (bl
);
1816 /* Back to the original value. */
1817 bl
->watchpoint_type
= hw_read
;
1821 bl
->inserted
= (val
== 0);
1824 else if (bl
->owner
->type
== bp_catchpoint
)
1826 gdb_assert (bl
->owner
->ops
!= NULL
1827 && bl
->owner
->ops
->insert_location
!= NULL
);
1829 val
= bl
->owner
->ops
->insert_location (bl
);
1832 bl
->owner
->enable_state
= bp_disabled
;
1836 Error inserting catchpoint %d: Your system does not support this type\n\
1837 of catchpoint."), bl
->owner
->number
);
1839 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1842 bl
->inserted
= (val
== 0);
1844 /* We've already printed an error message if there was a problem
1845 inserting this catchpoint, and we've disabled the catchpoint,
1846 so just return success. */
1853 /* This function is called when program space PSPACE is about to be
1854 deleted. It takes care of updating breakpoints to not reference
1858 breakpoint_program_space_exit (struct program_space
*pspace
)
1860 struct breakpoint
*b
, *b_temp
;
1861 struct bp_location
*loc
, **loc_temp
;
1863 /* Remove any breakpoint that was set through this program space. */
1864 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1866 if (b
->pspace
== pspace
)
1867 delete_breakpoint (b
);
1870 /* Breakpoints set through other program spaces could have locations
1871 bound to PSPACE as well. Remove those. */
1872 ALL_BP_LOCATIONS (loc
, loc_temp
)
1874 struct bp_location
*tmp
;
1876 if (loc
->pspace
== pspace
)
1878 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1879 if (loc
->owner
->loc
== loc
)
1880 loc
->owner
->loc
= loc
->next
;
1882 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1883 if (tmp
->next
== loc
)
1885 tmp
->next
= loc
->next
;
1891 /* Now update the global location list to permanently delete the
1892 removed locations above. */
1893 update_global_location_list (0);
1896 /* Make sure all breakpoints are inserted in inferior.
1897 Throws exception on any error.
1898 A breakpoint that is already inserted won't be inserted
1899 again, so calling this function twice is safe. */
1901 insert_breakpoints (void)
1903 struct breakpoint
*bpt
;
1905 ALL_BREAKPOINTS (bpt
)
1906 if (is_hardware_watchpoint (bpt
))
1908 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1910 update_watchpoint (w
, 0 /* don't reparse. */);
1913 update_global_location_list (1);
1915 /* update_global_location_list does not insert breakpoints when
1916 always_inserted_mode is not enabled. Explicitly insert them
1918 if (!breakpoints_always_inserted_mode ())
1919 insert_breakpoint_locations ();
1922 /* Used when starting or continuing the program. */
1925 insert_breakpoint_locations (void)
1927 struct breakpoint
*bpt
;
1928 struct bp_location
*bl
, **blp_tmp
;
1931 int disabled_breaks
= 0;
1932 int hw_breakpoint_error
= 0;
1934 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1935 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1937 /* Explicitly mark the warning -- this will only be printed if
1938 there was an error. */
1939 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1941 save_current_space_and_thread ();
1943 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1945 if (!should_be_inserted (bl
) || bl
->inserted
)
1948 /* There is no point inserting thread-specific breakpoints if
1949 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1950 has BL->OWNER always non-NULL. */
1951 if (bl
->owner
->thread
!= -1
1952 && !valid_thread_id (bl
->owner
->thread
))
1955 switch_to_program_space_and_thread (bl
->pspace
);
1957 /* For targets that support global breakpoints, there's no need
1958 to select an inferior to insert breakpoint to. In fact, even
1959 if we aren't attached to any process yet, we should still
1960 insert breakpoints. */
1961 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1962 && ptid_equal (inferior_ptid
, null_ptid
))
1965 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1966 &hw_breakpoint_error
);
1971 /* If we failed to insert all locations of a watchpoint, remove
1972 them, as half-inserted watchpoint is of limited use. */
1973 ALL_BREAKPOINTS (bpt
)
1975 int some_failed
= 0;
1976 struct bp_location
*loc
;
1978 if (!is_hardware_watchpoint (bpt
))
1981 if (!breakpoint_enabled (bpt
))
1984 if (bpt
->disposition
== disp_del_at_next_stop
)
1987 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1988 if (!loc
->inserted
&& should_be_inserted (loc
))
1995 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1997 remove_breakpoint (loc
, mark_uninserted
);
1999 hw_breakpoint_error
= 1;
2000 fprintf_unfiltered (tmp_error_stream
,
2001 "Could not insert hardware watchpoint %d.\n",
2009 /* If a hardware breakpoint or watchpoint was inserted, add a
2010 message about possibly exhausted resources. */
2011 if (hw_breakpoint_error
)
2013 fprintf_unfiltered (tmp_error_stream
,
2014 "Could not insert hardware breakpoints:\n\
2015 You may have requested too many hardware breakpoints/watchpoints.\n");
2017 target_terminal_ours_for_output ();
2018 error_stream (tmp_error_stream
);
2021 do_cleanups (cleanups
);
2024 /* Used when the program stops.
2025 Returns zero if successful, or non-zero if there was a problem
2026 removing a breakpoint location. */
2029 remove_breakpoints (void)
2031 struct bp_location
*bl
, **blp_tmp
;
2034 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2037 val
|= remove_breakpoint (bl
, mark_uninserted
);
2042 /* Remove breakpoints of process PID. */
2045 remove_breakpoints_pid (int pid
)
2047 struct bp_location
*bl
, **blp_tmp
;
2049 struct inferior
*inf
= find_inferior_pid (pid
);
2051 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2053 if (bl
->pspace
!= inf
->pspace
)
2058 val
= remove_breakpoint (bl
, mark_uninserted
);
2067 reattach_breakpoints (int pid
)
2069 struct cleanup
*old_chain
;
2070 struct bp_location
*bl
, **blp_tmp
;
2072 struct ui_file
*tmp_error_stream
;
2073 int dummy1
= 0, dummy2
= 0;
2074 struct inferior
*inf
;
2075 struct thread_info
*tp
;
2077 tp
= any_live_thread_of_process (pid
);
2081 inf
= find_inferior_pid (pid
);
2082 old_chain
= save_inferior_ptid ();
2084 inferior_ptid
= tp
->ptid
;
2086 tmp_error_stream
= mem_fileopen ();
2087 make_cleanup_ui_file_delete (tmp_error_stream
);
2089 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2091 if (bl
->pspace
!= inf
->pspace
)
2097 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2100 do_cleanups (old_chain
);
2105 do_cleanups (old_chain
);
2109 static int internal_breakpoint_number
= -1;
2111 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2112 If INTERNAL is non-zero, the breakpoint number will be populated
2113 from internal_breakpoint_number and that variable decremented.
2114 Otherwise the breakpoint number will be populated from
2115 breakpoint_count and that value incremented. Internal breakpoints
2116 do not set the internal var bpnum. */
2118 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2121 b
->number
= internal_breakpoint_number
--;
2124 set_breakpoint_count (breakpoint_count
+ 1);
2125 b
->number
= breakpoint_count
;
2129 static struct breakpoint
*
2130 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2131 CORE_ADDR address
, enum bptype type
,
2132 const struct breakpoint_ops
*ops
)
2134 struct symtab_and_line sal
;
2135 struct breakpoint
*b
;
2137 init_sal (&sal
); /* Initialize to zeroes. */
2140 sal
.section
= find_pc_overlay (sal
.pc
);
2141 sal
.pspace
= current_program_space
;
2143 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2144 b
->number
= internal_breakpoint_number
--;
2145 b
->disposition
= disp_donttouch
;
2150 static const char *const longjmp_names
[] =
2152 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2154 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2156 /* Per-objfile data private to breakpoint.c. */
2157 struct breakpoint_objfile_data
2159 /* Minimal symbol for "_ovly_debug_event" (if any). */
2160 struct minimal_symbol
*overlay_msym
;
2162 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2163 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2165 /* Minimal symbol for "std::terminate()" (if any). */
2166 struct minimal_symbol
*terminate_msym
;
2168 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2169 struct minimal_symbol
*exception_msym
;
2172 static const struct objfile_data
*breakpoint_objfile_key
;
2174 /* Minimal symbol not found sentinel. */
2175 static struct minimal_symbol msym_not_found
;
2177 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2180 msym_not_found_p (const struct minimal_symbol
*msym
)
2182 return msym
== &msym_not_found
;
2185 /* Return per-objfile data needed by breakpoint.c.
2186 Allocate the data if necessary. */
2188 static struct breakpoint_objfile_data
*
2189 get_breakpoint_objfile_data (struct objfile
*objfile
)
2191 struct breakpoint_objfile_data
*bp_objfile_data
;
2193 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2194 if (bp_objfile_data
== NULL
)
2196 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2197 sizeof (*bp_objfile_data
));
2199 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2200 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2202 return bp_objfile_data
;
2206 create_overlay_event_breakpoint (void)
2208 struct objfile
*objfile
;
2209 const char *const func_name
= "_ovly_debug_event";
2211 ALL_OBJFILES (objfile
)
2213 struct breakpoint
*b
;
2214 struct breakpoint_objfile_data
*bp_objfile_data
;
2217 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2219 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2222 if (bp_objfile_data
->overlay_msym
== NULL
)
2224 struct minimal_symbol
*m
;
2226 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2229 /* Avoid future lookups in this objfile. */
2230 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2233 bp_objfile_data
->overlay_msym
= m
;
2236 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2237 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2239 &internal_breakpoint_ops
);
2240 b
->addr_string
= xstrdup (func_name
);
2242 if (overlay_debugging
== ovly_auto
)
2244 b
->enable_state
= bp_enabled
;
2245 overlay_events_enabled
= 1;
2249 b
->enable_state
= bp_disabled
;
2250 overlay_events_enabled
= 0;
2253 update_global_location_list (1);
2257 create_longjmp_master_breakpoint (void)
2259 struct program_space
*pspace
;
2260 struct cleanup
*old_chain
;
2262 old_chain
= save_current_program_space ();
2264 ALL_PSPACES (pspace
)
2266 struct objfile
*objfile
;
2268 set_current_program_space (pspace
);
2270 ALL_OBJFILES (objfile
)
2273 struct gdbarch
*gdbarch
;
2274 struct breakpoint_objfile_data
*bp_objfile_data
;
2276 gdbarch
= get_objfile_arch (objfile
);
2277 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2280 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2282 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2284 struct breakpoint
*b
;
2285 const char *func_name
;
2288 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2291 func_name
= longjmp_names
[i
];
2292 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2294 struct minimal_symbol
*m
;
2296 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2299 /* Prevent future lookups in this objfile. */
2300 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2303 bp_objfile_data
->longjmp_msym
[i
] = m
;
2306 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2307 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2308 &internal_breakpoint_ops
);
2309 b
->addr_string
= xstrdup (func_name
);
2310 b
->enable_state
= bp_disabled
;
2314 update_global_location_list (1);
2316 do_cleanups (old_chain
);
2319 /* Create a master std::terminate breakpoint. */
2321 create_std_terminate_master_breakpoint (void)
2323 struct program_space
*pspace
;
2324 struct cleanup
*old_chain
;
2325 const char *const func_name
= "std::terminate()";
2327 old_chain
= save_current_program_space ();
2329 ALL_PSPACES (pspace
)
2331 struct objfile
*objfile
;
2334 set_current_program_space (pspace
);
2336 ALL_OBJFILES (objfile
)
2338 struct breakpoint
*b
;
2339 struct breakpoint_objfile_data
*bp_objfile_data
;
2341 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2343 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2346 if (bp_objfile_data
->terminate_msym
== NULL
)
2348 struct minimal_symbol
*m
;
2350 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2351 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2352 && MSYMBOL_TYPE (m
) != mst_file_text
))
2354 /* Prevent future lookups in this objfile. */
2355 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2358 bp_objfile_data
->terminate_msym
= m
;
2361 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2362 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2363 bp_std_terminate_master
,
2364 &internal_breakpoint_ops
);
2365 b
->addr_string
= xstrdup (func_name
);
2366 b
->enable_state
= bp_disabled
;
2370 update_global_location_list (1);
2372 do_cleanups (old_chain
);
2375 /* Install a master breakpoint on the unwinder's debug hook. */
2378 create_exception_master_breakpoint (void)
2380 struct objfile
*objfile
;
2381 const char *const func_name
= "_Unwind_DebugHook";
2383 ALL_OBJFILES (objfile
)
2385 struct breakpoint
*b
;
2386 struct gdbarch
*gdbarch
;
2387 struct breakpoint_objfile_data
*bp_objfile_data
;
2390 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2392 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2395 gdbarch
= get_objfile_arch (objfile
);
2397 if (bp_objfile_data
->exception_msym
== NULL
)
2399 struct minimal_symbol
*debug_hook
;
2401 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2402 if (debug_hook
== NULL
)
2404 bp_objfile_data
->exception_msym
= &msym_not_found
;
2408 bp_objfile_data
->exception_msym
= debug_hook
;
2411 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2412 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2414 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2415 &internal_breakpoint_ops
);
2416 b
->addr_string
= xstrdup (func_name
);
2417 b
->enable_state
= bp_disabled
;
2420 update_global_location_list (1);
2424 update_breakpoints_after_exec (void)
2426 struct breakpoint
*b
, *b_tmp
;
2427 struct bp_location
*bploc
, **bplocp_tmp
;
2429 /* We're about to delete breakpoints from GDB's lists. If the
2430 INSERTED flag is true, GDB will try to lift the breakpoints by
2431 writing the breakpoints' "shadow contents" back into memory. The
2432 "shadow contents" are NOT valid after an exec, so GDB should not
2433 do that. Instead, the target is responsible from marking
2434 breakpoints out as soon as it detects an exec. We don't do that
2435 here instead, because there may be other attempts to delete
2436 breakpoints after detecting an exec and before reaching here. */
2437 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2438 if (bploc
->pspace
== current_program_space
)
2439 gdb_assert (!bploc
->inserted
);
2441 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2443 if (b
->pspace
!= current_program_space
)
2446 /* Solib breakpoints must be explicitly reset after an exec(). */
2447 if (b
->type
== bp_shlib_event
)
2449 delete_breakpoint (b
);
2453 /* JIT breakpoints must be explicitly reset after an exec(). */
2454 if (b
->type
== bp_jit_event
)
2456 delete_breakpoint (b
);
2460 /* Thread event breakpoints must be set anew after an exec(),
2461 as must overlay event and longjmp master breakpoints. */
2462 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2463 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2464 || b
->type
== bp_exception_master
)
2466 delete_breakpoint (b
);
2470 /* Step-resume breakpoints are meaningless after an exec(). */
2471 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2473 delete_breakpoint (b
);
2477 /* Longjmp and longjmp-resume breakpoints are also meaningless
2479 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2480 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2482 delete_breakpoint (b
);
2486 if (b
->type
== bp_catchpoint
)
2488 /* For now, none of the bp_catchpoint breakpoints need to
2489 do anything at this point. In the future, if some of
2490 the catchpoints need to something, we will need to add
2491 a new method, and call this method from here. */
2495 /* bp_finish is a special case. The only way we ought to be able
2496 to see one of these when an exec() has happened, is if the user
2497 caught a vfork, and then said "finish". Ordinarily a finish just
2498 carries them to the call-site of the current callee, by setting
2499 a temporary bp there and resuming. But in this case, the finish
2500 will carry them entirely through the vfork & exec.
2502 We don't want to allow a bp_finish to remain inserted now. But
2503 we can't safely delete it, 'cause finish_command has a handle to
2504 the bp on a bpstat, and will later want to delete it. There's a
2505 chance (and I've seen it happen) that if we delete the bp_finish
2506 here, that its storage will get reused by the time finish_command
2507 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2508 We really must allow finish_command to delete a bp_finish.
2510 In the absence of a general solution for the "how do we know
2511 it's safe to delete something others may have handles to?"
2512 problem, what we'll do here is just uninsert the bp_finish, and
2513 let finish_command delete it.
2515 (We know the bp_finish is "doomed" in the sense that it's
2516 momentary, and will be deleted as soon as finish_command sees
2517 the inferior stopped. So it doesn't matter that the bp's
2518 address is probably bogus in the new a.out, unlike e.g., the
2519 solib breakpoints.) */
2521 if (b
->type
== bp_finish
)
2526 /* Without a symbolic address, we have little hope of the
2527 pre-exec() address meaning the same thing in the post-exec()
2529 if (b
->addr_string
== NULL
)
2531 delete_breakpoint (b
);
2535 /* FIXME what about longjmp breakpoints? Re-create them here? */
2536 create_overlay_event_breakpoint ();
2537 create_longjmp_master_breakpoint ();
2538 create_std_terminate_master_breakpoint ();
2539 create_exception_master_breakpoint ();
2543 detach_breakpoints (int pid
)
2545 struct bp_location
*bl
, **blp_tmp
;
2547 struct cleanup
*old_chain
= save_inferior_ptid ();
2548 struct inferior
*inf
= current_inferior ();
2550 if (pid
== PIDGET (inferior_ptid
))
2551 error (_("Cannot detach breakpoints of inferior_ptid"));
2553 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2554 inferior_ptid
= pid_to_ptid (pid
);
2555 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2557 if (bl
->pspace
!= inf
->pspace
)
2561 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2564 /* Detach single-step breakpoints as well. */
2565 detach_single_step_breakpoints ();
2567 do_cleanups (old_chain
);
2571 /* Remove the breakpoint location BL from the current address space.
2572 Note that this is used to detach breakpoints from a child fork.
2573 When we get here, the child isn't in the inferior list, and neither
2574 do we have objects to represent its address space --- we should
2575 *not* look at bl->pspace->aspace here. */
2578 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2582 /* BL is never in moribund_locations by our callers. */
2583 gdb_assert (bl
->owner
!= NULL
);
2585 if (bl
->owner
->enable_state
== bp_permanent
)
2586 /* Permanent breakpoints cannot be inserted or removed. */
2589 /* The type of none suggests that owner is actually deleted.
2590 This should not ever happen. */
2591 gdb_assert (bl
->owner
->type
!= bp_none
);
2593 if (bl
->loc_type
== bp_loc_software_breakpoint
2594 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2596 /* "Normal" instruction breakpoint: either the standard
2597 trap-instruction bp (bp_breakpoint), or a
2598 bp_hardware_breakpoint. */
2600 /* First check to see if we have to handle an overlay. */
2601 if (overlay_debugging
== ovly_off
2602 || bl
->section
== NULL
2603 || !(section_is_overlay (bl
->section
)))
2605 /* No overlay handling: just remove the breakpoint. */
2606 val
= bl
->owner
->ops
->remove_location (bl
);
2610 /* This breakpoint is in an overlay section.
2611 Did we set a breakpoint at the LMA? */
2612 if (!overlay_events_enabled
)
2614 /* Yes -- overlay event support is not active, so we
2615 should have set a breakpoint at the LMA. Remove it.
2617 /* Ignore any failures: if the LMA is in ROM, we will
2618 have already warned when we failed to insert it. */
2619 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2620 target_remove_hw_breakpoint (bl
->gdbarch
,
2621 &bl
->overlay_target_info
);
2623 target_remove_breakpoint (bl
->gdbarch
,
2624 &bl
->overlay_target_info
);
2626 /* Did we set a breakpoint at the VMA?
2627 If so, we will have marked the breakpoint 'inserted'. */
2630 /* Yes -- remove it. Previously we did not bother to
2631 remove the breakpoint if the section had been
2632 unmapped, but let's not rely on that being safe. We
2633 don't know what the overlay manager might do. */
2635 /* However, we should remove *software* breakpoints only
2636 if the section is still mapped, or else we overwrite
2637 wrong code with the saved shadow contents. */
2638 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2639 || section_is_mapped (bl
->section
))
2640 val
= bl
->owner
->ops
->remove_location (bl
);
2646 /* No -- not inserted, so no need to remove. No error. */
2651 /* In some cases, we might not be able to remove a breakpoint
2652 in a shared library that has already been removed, but we
2653 have not yet processed the shlib unload event. */
2654 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2659 bl
->inserted
= (is
== mark_inserted
);
2661 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2663 gdb_assert (bl
->owner
->ops
!= NULL
2664 && bl
->owner
->ops
->remove_location
!= NULL
);
2666 bl
->inserted
= (is
== mark_inserted
);
2667 bl
->owner
->ops
->remove_location (bl
);
2669 /* Failure to remove any of the hardware watchpoints comes here. */
2670 if ((is
== mark_uninserted
) && (bl
->inserted
))
2671 warning (_("Could not remove hardware watchpoint %d."),
2674 else if (bl
->owner
->type
== bp_catchpoint
2675 && breakpoint_enabled (bl
->owner
)
2678 gdb_assert (bl
->owner
->ops
!= NULL
2679 && bl
->owner
->ops
->remove_location
!= NULL
);
2681 val
= bl
->owner
->ops
->remove_location (bl
);
2685 bl
->inserted
= (is
== mark_inserted
);
2692 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2695 struct cleanup
*old_chain
;
2697 /* BL is never in moribund_locations by our callers. */
2698 gdb_assert (bl
->owner
!= NULL
);
2700 if (bl
->owner
->enable_state
== bp_permanent
)
2701 /* Permanent breakpoints cannot be inserted or removed. */
2704 /* The type of none suggests that owner is actually deleted.
2705 This should not ever happen. */
2706 gdb_assert (bl
->owner
->type
!= bp_none
);
2708 old_chain
= save_current_space_and_thread ();
2710 switch_to_program_space_and_thread (bl
->pspace
);
2712 ret
= remove_breakpoint_1 (bl
, is
);
2714 do_cleanups (old_chain
);
2718 /* Clear the "inserted" flag in all breakpoints. */
2721 mark_breakpoints_out (void)
2723 struct bp_location
*bl
, **blp_tmp
;
2725 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2726 if (bl
->pspace
== current_program_space
)
2730 /* Clear the "inserted" flag in all breakpoints and delete any
2731 breakpoints which should go away between runs of the program.
2733 Plus other such housekeeping that has to be done for breakpoints
2736 Note: this function gets called at the end of a run (by
2737 generic_mourn_inferior) and when a run begins (by
2738 init_wait_for_inferior). */
2743 breakpoint_init_inferior (enum inf_context context
)
2745 struct breakpoint
*b
, *b_tmp
;
2746 struct bp_location
*bl
, **blp_tmp
;
2748 struct program_space
*pspace
= current_program_space
;
2750 /* If breakpoint locations are shared across processes, then there's
2752 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2755 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2757 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2758 if (bl
->pspace
== pspace
2759 && bl
->owner
->enable_state
!= bp_permanent
)
2763 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2765 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2772 /* If the call dummy breakpoint is at the entry point it will
2773 cause problems when the inferior is rerun, so we better get
2776 case bp_watchpoint_scope
:
2778 /* Also get rid of scope breakpoints. */
2780 case bp_shlib_event
:
2782 /* Also remove solib event breakpoints. Their addresses may
2783 have changed since the last time we ran the program.
2784 Actually we may now be debugging against different target;
2785 and so the solib backend that installed this breakpoint may
2786 not be used in by the target. E.g.,
2788 (gdb) file prog-linux
2789 (gdb) run # native linux target
2792 (gdb) file prog-win.exe
2793 (gdb) tar rem :9999 # remote Windows gdbserver.
2796 delete_breakpoint (b
);
2800 case bp_hardware_watchpoint
:
2801 case bp_read_watchpoint
:
2802 case bp_access_watchpoint
:
2804 struct watchpoint
*w
= (struct watchpoint
*) b
;
2806 /* Likewise for watchpoints on local expressions. */
2807 if (w
->exp_valid_block
!= NULL
)
2808 delete_breakpoint (b
);
2809 else if (context
== inf_starting
)
2811 /* Reset val field to force reread of starting value in
2812 insert_breakpoints. */
2814 value_free (w
->val
);
2825 /* Get rid of the moribund locations. */
2826 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2827 decref_bp_location (&bl
);
2828 VEC_free (bp_location_p
, moribund_locations
);
2831 /* These functions concern about actual breakpoints inserted in the
2832 target --- to e.g. check if we need to do decr_pc adjustment or if
2833 we need to hop over the bkpt --- so we check for address space
2834 match, not program space. */
2836 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2837 exists at PC. It returns ordinary_breakpoint_here if it's an
2838 ordinary breakpoint, or permanent_breakpoint_here if it's a
2839 permanent breakpoint.
2840 - When continuing from a location with an ordinary breakpoint, we
2841 actually single step once before calling insert_breakpoints.
2842 - When continuing from a location with a permanent breakpoint, we
2843 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2844 the target, to advance the PC past the breakpoint. */
2846 enum breakpoint_here
2847 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2849 struct bp_location
*bl
, **blp_tmp
;
2850 int any_breakpoint_here
= 0;
2852 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2854 if (bl
->loc_type
!= bp_loc_software_breakpoint
2855 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2858 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2859 if ((breakpoint_enabled (bl
->owner
)
2860 || bl
->owner
->enable_state
== bp_permanent
)
2861 && breakpoint_location_address_match (bl
, aspace
, pc
))
2863 if (overlay_debugging
2864 && section_is_overlay (bl
->section
)
2865 && !section_is_mapped (bl
->section
))
2866 continue; /* unmapped overlay -- can't be a match */
2867 else if (bl
->owner
->enable_state
== bp_permanent
)
2868 return permanent_breakpoint_here
;
2870 any_breakpoint_here
= 1;
2874 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2877 /* Return true if there's a moribund breakpoint at PC. */
2880 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2882 struct bp_location
*loc
;
2885 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2886 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2892 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2893 inserted using regular breakpoint_chain / bp_location array
2894 mechanism. This does not check for single-step breakpoints, which
2895 are inserted and removed using direct target manipulation. */
2898 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2901 struct bp_location
*bl
, **blp_tmp
;
2903 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2905 if (bl
->loc_type
!= bp_loc_software_breakpoint
2906 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2910 && breakpoint_location_address_match (bl
, aspace
, pc
))
2912 if (overlay_debugging
2913 && section_is_overlay (bl
->section
)
2914 && !section_is_mapped (bl
->section
))
2915 continue; /* unmapped overlay -- can't be a match */
2923 /* Returns non-zero iff there's either regular breakpoint
2924 or a single step breakpoint inserted at PC. */
2927 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2929 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2932 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2938 /* This function returns non-zero iff there is a software breakpoint
2942 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2945 struct bp_location
*bl
, **blp_tmp
;
2947 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2949 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2953 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2956 if (overlay_debugging
2957 && section_is_overlay (bl
->section
)
2958 && !section_is_mapped (bl
->section
))
2959 continue; /* unmapped overlay -- can't be a match */
2965 /* Also check for software single-step breakpoints. */
2966 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2973 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2974 CORE_ADDR addr
, ULONGEST len
)
2976 struct breakpoint
*bpt
;
2978 ALL_BREAKPOINTS (bpt
)
2980 struct bp_location
*loc
;
2982 if (bpt
->type
!= bp_hardware_watchpoint
2983 && bpt
->type
!= bp_access_watchpoint
)
2986 if (!breakpoint_enabled (bpt
))
2989 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2990 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2994 /* Check for intersection. */
2995 l
= max (loc
->address
, addr
);
2996 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3004 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3005 PC is valid for process/thread PTID. */
3008 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3011 struct bp_location
*bl
, **blp_tmp
;
3012 /* The thread and task IDs associated to PTID, computed lazily. */
3016 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3018 if (bl
->loc_type
!= bp_loc_software_breakpoint
3019 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3022 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3023 if (!breakpoint_enabled (bl
->owner
)
3024 && bl
->owner
->enable_state
!= bp_permanent
)
3027 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3030 if (bl
->owner
->thread
!= -1)
3032 /* This is a thread-specific breakpoint. Check that ptid
3033 matches that thread. If thread hasn't been computed yet,
3034 it is now time to do so. */
3036 thread
= pid_to_thread_id (ptid
);
3037 if (bl
->owner
->thread
!= thread
)
3041 if (bl
->owner
->task
!= 0)
3043 /* This is a task-specific breakpoint. Check that ptid
3044 matches that task. If task hasn't been computed yet,
3045 it is now time to do so. */
3047 task
= ada_get_task_number (ptid
);
3048 if (bl
->owner
->task
!= task
)
3052 if (overlay_debugging
3053 && section_is_overlay (bl
->section
)
3054 && !section_is_mapped (bl
->section
))
3055 continue; /* unmapped overlay -- can't be a match */
3064 /* bpstat stuff. External routines' interfaces are documented
3068 ep_is_catchpoint (struct breakpoint
*ep
)
3070 return (ep
->type
== bp_catchpoint
);
3073 /* Frees any storage that is part of a bpstat. Does not walk the
3077 bpstat_free (bpstat bs
)
3079 if (bs
->old_val
!= NULL
)
3080 value_free (bs
->old_val
);
3081 decref_counted_command_line (&bs
->commands
);
3082 decref_bp_location (&bs
->bp_location_at
);
3086 /* Clear a bpstat so that it says we are not at any breakpoint.
3087 Also free any storage that is part of a bpstat. */
3090 bpstat_clear (bpstat
*bsp
)
3107 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3108 is part of the bpstat is copied as well. */
3111 bpstat_copy (bpstat bs
)
3115 bpstat retval
= NULL
;
3120 for (; bs
!= NULL
; bs
= bs
->next
)
3122 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3123 memcpy (tmp
, bs
, sizeof (*tmp
));
3124 incref_counted_command_line (tmp
->commands
);
3125 incref_bp_location (tmp
->bp_location_at
);
3126 if (bs
->old_val
!= NULL
)
3128 tmp
->old_val
= value_copy (bs
->old_val
);
3129 release_value (tmp
->old_val
);
3133 /* This is the first thing in the chain. */
3143 /* Find the bpstat associated with this breakpoint. */
3146 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3151 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3153 if (bsp
->breakpoint_at
== breakpoint
)
3159 /* Put in *NUM the breakpoint number of the first breakpoint we are
3160 stopped at. *BSP upon return is a bpstat which points to the
3161 remaining breakpoints stopped at (but which is not guaranteed to be
3162 good for anything but further calls to bpstat_num).
3164 Return 0 if passed a bpstat which does not indicate any breakpoints.
3165 Return -1 if stopped at a breakpoint that has been deleted since
3167 Return 1 otherwise. */
3170 bpstat_num (bpstat
*bsp
, int *num
)
3172 struct breakpoint
*b
;
3175 return 0; /* No more breakpoint values */
3177 /* We assume we'll never have several bpstats that correspond to a
3178 single breakpoint -- otherwise, this function might return the
3179 same number more than once and this will look ugly. */
3180 b
= (*bsp
)->breakpoint_at
;
3181 *bsp
= (*bsp
)->next
;
3183 return -1; /* breakpoint that's been deleted since */
3185 *num
= b
->number
; /* We have its number */
3189 /* Modify BS so that the actions will not be performed. */
3192 bpstat_clear_actions (bpstat bs
)
3194 for (; bs
!= NULL
; bs
= bs
->next
)
3196 decref_counted_command_line (&bs
->commands
);
3197 bs
->commands_left
= NULL
;
3198 if (bs
->old_val
!= NULL
)
3200 value_free (bs
->old_val
);
3206 /* Called when a command is about to proceed the inferior. */
3209 breakpoint_about_to_proceed (void)
3211 if (!ptid_equal (inferior_ptid
, null_ptid
))
3213 struct thread_info
*tp
= inferior_thread ();
3215 /* Allow inferior function calls in breakpoint commands to not
3216 interrupt the command list. When the call finishes
3217 successfully, the inferior will be standing at the same
3218 breakpoint as if nothing happened. */
3219 if (tp
->control
.in_infcall
)
3223 breakpoint_proceeded
= 1;
3226 /* Stub for cleaning up our state if we error-out of a breakpoint
3229 cleanup_executing_breakpoints (void *ignore
)
3231 executing_breakpoint_commands
= 0;
3234 /* Execute all the commands associated with all the breakpoints at
3235 this location. Any of these commands could cause the process to
3236 proceed beyond this point, etc. We look out for such changes by
3237 checking the global "breakpoint_proceeded" after each command.
3239 Returns true if a breakpoint command resumed the inferior. In that
3240 case, it is the caller's responsibility to recall it again with the
3241 bpstat of the current thread. */
3244 bpstat_do_actions_1 (bpstat
*bsp
)
3247 struct cleanup
*old_chain
;
3250 /* Avoid endless recursion if a `source' command is contained
3252 if (executing_breakpoint_commands
)
3255 executing_breakpoint_commands
= 1;
3256 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3258 prevent_dont_repeat ();
3260 /* This pointer will iterate over the list of bpstat's. */
3263 breakpoint_proceeded
= 0;
3264 for (; bs
!= NULL
; bs
= bs
->next
)
3266 struct counted_command_line
*ccmd
;
3267 struct command_line
*cmd
;
3268 struct cleanup
*this_cmd_tree_chain
;
3270 /* Take ownership of the BSP's command tree, if it has one.
3272 The command tree could legitimately contain commands like
3273 'step' and 'next', which call clear_proceed_status, which
3274 frees stop_bpstat's command tree. To make sure this doesn't
3275 free the tree we're executing out from under us, we need to
3276 take ownership of the tree ourselves. Since a given bpstat's
3277 commands are only executed once, we don't need to copy it; we
3278 can clear the pointer in the bpstat, and make sure we free
3279 the tree when we're done. */
3280 ccmd
= bs
->commands
;
3281 bs
->commands
= NULL
;
3283 = make_cleanup_decref_counted_command_line (&ccmd
);
3284 cmd
= bs
->commands_left
;
3285 bs
->commands_left
= NULL
;
3289 execute_control_command (cmd
);
3291 if (breakpoint_proceeded
)
3297 /* We can free this command tree now. */
3298 do_cleanups (this_cmd_tree_chain
);
3300 if (breakpoint_proceeded
)
3302 if (target_can_async_p ())
3303 /* If we are in async mode, then the target might be still
3304 running, not stopped at any breakpoint, so nothing for
3305 us to do here -- just return to the event loop. */
3308 /* In sync mode, when execute_control_command returns
3309 we're already standing on the next breakpoint.
3310 Breakpoint commands for that stop were not run, since
3311 execute_command does not run breakpoint commands --
3312 only command_line_handler does, but that one is not
3313 involved in execution of breakpoint commands. So, we
3314 can now execute breakpoint commands. It should be
3315 noted that making execute_command do bpstat actions is
3316 not an option -- in this case we'll have recursive
3317 invocation of bpstat for each breakpoint with a
3318 command, and can easily blow up GDB stack. Instead, we
3319 return true, which will trigger the caller to recall us
3320 with the new stop_bpstat. */
3325 do_cleanups (old_chain
);
3330 bpstat_do_actions (void)
3332 /* Do any commands attached to breakpoint we are stopped at. */
3333 while (!ptid_equal (inferior_ptid
, null_ptid
)
3334 && target_has_execution
3335 && !is_exited (inferior_ptid
)
3336 && !is_executing (inferior_ptid
))
3337 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3338 and only return when it is stopped at the next breakpoint, we
3339 keep doing breakpoint actions until it returns false to
3340 indicate the inferior was not resumed. */
3341 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3345 /* Print out the (old or new) value associated with a watchpoint. */
3348 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3351 fprintf_unfiltered (stream
, _("<unreadable>"));
3354 struct value_print_options opts
;
3355 get_user_print_options (&opts
);
3356 value_print (val
, stream
, &opts
);
3360 /* Generic routine for printing messages indicating why we
3361 stopped. The behavior of this function depends on the value
3362 'print_it' in the bpstat structure. Under some circumstances we
3363 may decide not to print anything here and delegate the task to
3366 static enum print_stop_action
3367 print_bp_stop_message (bpstat bs
)
3369 switch (bs
->print_it
)
3372 /* Nothing should be printed for this bpstat entry. */
3373 return PRINT_UNKNOWN
;
3377 /* We still want to print the frame, but we already printed the
3378 relevant messages. */
3379 return PRINT_SRC_AND_LOC
;
3382 case print_it_normal
:
3384 struct breakpoint
*b
= bs
->breakpoint_at
;
3386 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3387 which has since been deleted. */
3389 return PRINT_UNKNOWN
;
3391 /* Normal case. Call the breakpoint's print_it method. */
3392 return b
->ops
->print_it (bs
);
3397 internal_error (__FILE__
, __LINE__
,
3398 _("print_bp_stop_message: unrecognized enum value"));
3403 /* Print a message indicating what happened. This is called from
3404 normal_stop(). The input to this routine is the head of the bpstat
3405 list - a list of the eventpoints that caused this stop. This
3406 routine calls the generic print routine for printing a message
3407 about reasons for stopping. This will print (for example) the
3408 "Breakpoint n," part of the output. The return value of this
3411 PRINT_UNKNOWN: Means we printed nothing.
3412 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3413 code to print the location. An example is
3414 "Breakpoint 1, " which should be followed by
3416 PRINT_SRC_ONLY: Means we printed something, but there is no need
3417 to also print the location part of the message.
3418 An example is the catch/throw messages, which
3419 don't require a location appended to the end.
3420 PRINT_NOTHING: We have done some printing and we don't need any
3421 further info to be printed. */
3423 enum print_stop_action
3424 bpstat_print (bpstat bs
)
3428 /* Maybe another breakpoint in the chain caused us to stop.
3429 (Currently all watchpoints go on the bpstat whether hit or not.
3430 That probably could (should) be changed, provided care is taken
3431 with respect to bpstat_explains_signal). */
3432 for (; bs
; bs
= bs
->next
)
3434 val
= print_bp_stop_message (bs
);
3435 if (val
== PRINT_SRC_ONLY
3436 || val
== PRINT_SRC_AND_LOC
3437 || val
== PRINT_NOTHING
)
3441 /* We reached the end of the chain, or we got a null BS to start
3442 with and nothing was printed. */
3443 return PRINT_UNKNOWN
;
3446 /* Evaluate the expression EXP and return 1 if value is zero. This is
3447 used inside a catch_errors to evaluate the breakpoint condition.
3448 The argument is a "struct expression *" that has been cast to a
3449 "char *" to make it pass through catch_errors. */
3452 breakpoint_cond_eval (void *exp
)
3454 struct value
*mark
= value_mark ();
3455 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3457 value_free_to_mark (mark
);
3461 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3464 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3468 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3470 **bs_link_pointer
= bs
;
3471 *bs_link_pointer
= &bs
->next
;
3472 bs
->breakpoint_at
= bl
->owner
;
3473 bs
->bp_location_at
= bl
;
3474 incref_bp_location (bl
);
3475 /* If the condition is false, etc., don't do the commands. */
3476 bs
->commands
= NULL
;
3477 bs
->commands_left
= NULL
;
3479 bs
->print_it
= print_it_normal
;
3483 /* The target has stopped with waitstatus WS. Check if any hardware
3484 watchpoints have triggered, according to the target. */
3487 watchpoints_triggered (struct target_waitstatus
*ws
)
3489 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3491 struct breakpoint
*b
;
3493 if (!stopped_by_watchpoint
)
3495 /* We were not stopped by a watchpoint. Mark all watchpoints
3496 as not triggered. */
3498 if (is_hardware_watchpoint (b
))
3500 struct watchpoint
*w
= (struct watchpoint
*) b
;
3502 w
->watchpoint_triggered
= watch_triggered_no
;
3508 if (!target_stopped_data_address (¤t_target
, &addr
))
3510 /* We were stopped by a watchpoint, but we don't know where.
3511 Mark all watchpoints as unknown. */
3513 if (is_hardware_watchpoint (b
))
3515 struct watchpoint
*w
= (struct watchpoint
*) b
;
3517 w
->watchpoint_triggered
= watch_triggered_unknown
;
3520 return stopped_by_watchpoint
;
3523 /* The target could report the data address. Mark watchpoints
3524 affected by this data address as triggered, and all others as not
3528 if (is_hardware_watchpoint (b
))
3530 struct watchpoint
*w
= (struct watchpoint
*) b
;
3531 struct bp_location
*loc
;
3533 w
->watchpoint_triggered
= watch_triggered_no
;
3534 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3536 if (is_masked_watchpoint (b
))
3538 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3539 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3541 if (newaddr
== start
)
3543 w
->watchpoint_triggered
= watch_triggered_yes
;
3547 /* Exact match not required. Within range is sufficient. */
3548 else if (target_watchpoint_addr_within_range (¤t_target
,
3552 w
->watchpoint_triggered
= watch_triggered_yes
;
3561 /* Possible return values for watchpoint_check (this can't be an enum
3562 because of check_errors). */
3563 /* The watchpoint has been deleted. */
3564 #define WP_DELETED 1
3565 /* The value has changed. */
3566 #define WP_VALUE_CHANGED 2
3567 /* The value has not changed. */
3568 #define WP_VALUE_NOT_CHANGED 3
3569 /* Ignore this watchpoint, no matter if the value changed or not. */
3572 #define BP_TEMPFLAG 1
3573 #define BP_HARDWAREFLAG 2
3575 /* Evaluate watchpoint condition expression and check if its value
3578 P should be a pointer to struct bpstat, but is defined as a void *
3579 in order for this function to be usable with catch_errors. */
3582 watchpoint_check (void *p
)
3584 bpstat bs
= (bpstat
) p
;
3585 struct watchpoint
*b
;
3586 struct frame_info
*fr
;
3587 int within_current_scope
;
3589 /* BS is built from an existing struct breakpoint. */
3590 gdb_assert (bs
->breakpoint_at
!= NULL
);
3591 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3593 /* If this is a local watchpoint, we only want to check if the
3594 watchpoint frame is in scope if the current thread is the thread
3595 that was used to create the watchpoint. */
3596 if (!watchpoint_in_thread_scope (b
))
3599 if (b
->exp_valid_block
== NULL
)
3600 within_current_scope
= 1;
3603 struct frame_info
*frame
= get_current_frame ();
3604 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3605 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3607 /* in_function_epilogue_p() returns a non-zero value if we're
3608 still in the function but the stack frame has already been
3609 invalidated. Since we can't rely on the values of local
3610 variables after the stack has been destroyed, we are treating
3611 the watchpoint in that state as `not changed' without further
3612 checking. Don't mark watchpoints as changed if the current
3613 frame is in an epilogue - even if they are in some other
3614 frame, our view of the stack is likely to be wrong and
3615 frame_find_by_id could error out. */
3616 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3619 fr
= frame_find_by_id (b
->watchpoint_frame
);
3620 within_current_scope
= (fr
!= NULL
);
3622 /* If we've gotten confused in the unwinder, we might have
3623 returned a frame that can't describe this variable. */
3624 if (within_current_scope
)
3626 struct symbol
*function
;
3628 function
= get_frame_function (fr
);
3629 if (function
== NULL
3630 || !contained_in (b
->exp_valid_block
,
3631 SYMBOL_BLOCK_VALUE (function
)))
3632 within_current_scope
= 0;
3635 if (within_current_scope
)
3636 /* If we end up stopping, the current frame will get selected
3637 in normal_stop. So this call to select_frame won't affect
3642 if (within_current_scope
)
3644 /* We use value_{,free_to_}mark because it could be a *long*
3645 time before we return to the command level and call
3646 free_all_values. We can't call free_all_values because we
3647 might be in the middle of evaluating a function call. */
3651 struct value
*new_val
;
3653 if (is_masked_watchpoint (&b
->base
))
3654 /* Since we don't know the exact trigger address (from
3655 stopped_data_address), just tell the user we've triggered
3656 a mask watchpoint. */
3657 return WP_VALUE_CHANGED
;
3659 mark
= value_mark ();
3660 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3662 /* We use value_equal_contents instead of value_equal because
3663 the latter coerces an array to a pointer, thus comparing just
3664 the address of the array instead of its contents. This is
3665 not what we want. */
3666 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3667 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3669 if (new_val
!= NULL
)
3671 release_value (new_val
);
3672 value_free_to_mark (mark
);
3674 bs
->old_val
= b
->val
;
3677 return WP_VALUE_CHANGED
;
3681 /* Nothing changed. */
3682 value_free_to_mark (mark
);
3683 return WP_VALUE_NOT_CHANGED
;
3688 struct ui_out
*uiout
= current_uiout
;
3690 /* This seems like the only logical thing to do because
3691 if we temporarily ignored the watchpoint, then when
3692 we reenter the block in which it is valid it contains
3693 garbage (in the case of a function, it may have two
3694 garbage values, one before and one after the prologue).
3695 So we can't even detect the first assignment to it and
3696 watch after that (since the garbage may or may not equal
3697 the first value assigned). */
3698 /* We print all the stop information in
3699 breakpoint_ops->print_it, but in this case, by the time we
3700 call breakpoint_ops->print_it this bp will be deleted
3701 already. So we have no choice but print the information
3703 if (ui_out_is_mi_like_p (uiout
))
3705 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3706 ui_out_text (uiout
, "\nWatchpoint ");
3707 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3709 " deleted because the program has left the block in\n\
3710 which its expression is valid.\n");
3712 /* Make sure the watchpoint's commands aren't executed. */
3713 decref_counted_command_line (&b
->base
.commands
);
3714 watchpoint_del_at_next_stop (b
);
3720 /* Return true if it looks like target has stopped due to hitting
3721 breakpoint location BL. This function does not check if we should
3722 stop, only if BL explains the stop. */
3725 bpstat_check_location (const struct bp_location
*bl
,
3726 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3728 struct breakpoint
*b
= bl
->owner
;
3730 /* BL is from an existing breakpoint. */
3731 gdb_assert (b
!= NULL
);
3733 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3736 /* Determine if the watched values have actually changed, and we
3737 should stop. If not, set BS->stop to 0. */
3740 bpstat_check_watchpoint (bpstat bs
)
3742 const struct bp_location
*bl
;
3743 struct watchpoint
*b
;
3745 /* BS is built for existing struct breakpoint. */
3746 bl
= bs
->bp_location_at
;
3747 gdb_assert (bl
!= NULL
);
3748 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3749 gdb_assert (b
!= NULL
);
3752 int must_check_value
= 0;
3754 if (b
->base
.type
== bp_watchpoint
)
3755 /* For a software watchpoint, we must always check the
3757 must_check_value
= 1;
3758 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3759 /* We have a hardware watchpoint (read, write, or access)
3760 and the target earlier reported an address watched by
3762 must_check_value
= 1;
3763 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3764 && b
->base
.type
== bp_hardware_watchpoint
)
3765 /* We were stopped by a hardware watchpoint, but the target could
3766 not report the data address. We must check the watchpoint's
3767 value. Access and read watchpoints are out of luck; without
3768 a data address, we can't figure it out. */
3769 must_check_value
= 1;
3771 if (must_check_value
)
3774 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3776 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3777 int e
= catch_errors (watchpoint_check
, bs
, message
,
3779 do_cleanups (cleanups
);
3783 /* We've already printed what needs to be printed. */
3784 bs
->print_it
= print_it_done
;
3788 bs
->print_it
= print_it_noop
;
3791 case WP_VALUE_CHANGED
:
3792 if (b
->base
.type
== bp_read_watchpoint
)
3794 /* There are two cases to consider here:
3796 1. We're watching the triggered memory for reads.
3797 In that case, trust the target, and always report
3798 the watchpoint hit to the user. Even though
3799 reads don't cause value changes, the value may
3800 have changed since the last time it was read, and
3801 since we're not trapping writes, we will not see
3802 those, and as such we should ignore our notion of
3805 2. We're watching the triggered memory for both
3806 reads and writes. There are two ways this may
3809 2.1. This is a target that can't break on data
3810 reads only, but can break on accesses (reads or
3811 writes), such as e.g., x86. We detect this case
3812 at the time we try to insert read watchpoints.
3814 2.2. Otherwise, the target supports read
3815 watchpoints, but, the user set an access or write
3816 watchpoint watching the same memory as this read
3819 If we're watching memory writes as well as reads,
3820 ignore watchpoint hits when we find that the
3821 value hasn't changed, as reads don't cause
3822 changes. This still gives false positives when
3823 the program writes the same value to memory as
3824 what there was already in memory (we will confuse
3825 it for a read), but it's much better than
3828 int other_write_watchpoint
= 0;
3830 if (bl
->watchpoint_type
== hw_read
)
3832 struct breakpoint
*other_b
;
3834 ALL_BREAKPOINTS (other_b
)
3835 if (other_b
->type
== bp_hardware_watchpoint
3836 || other_b
->type
== bp_access_watchpoint
)
3838 struct watchpoint
*other_w
=
3839 (struct watchpoint
*) other_b
;
3841 if (other_w
->watchpoint_triggered
3842 == watch_triggered_yes
)
3844 other_write_watchpoint
= 1;
3850 if (other_write_watchpoint
3851 || bl
->watchpoint_type
== hw_access
)
3853 /* We're watching the same memory for writes,
3854 and the value changed since the last time we
3855 updated it, so this trap must be for a write.
3857 bs
->print_it
= print_it_noop
;
3862 case WP_VALUE_NOT_CHANGED
:
3863 if (b
->base
.type
== bp_hardware_watchpoint
3864 || b
->base
.type
== bp_watchpoint
)
3866 /* Don't stop: write watchpoints shouldn't fire if
3867 the value hasn't changed. */
3868 bs
->print_it
= print_it_noop
;
3876 /* Error from catch_errors. */
3877 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3878 watchpoint_del_at_next_stop (b
);
3879 /* We've already printed what needs to be printed. */
3880 bs
->print_it
= print_it_done
;
3884 else /* must_check_value == 0 */
3886 /* This is a case where some watchpoint(s) triggered, but
3887 not at the address of this watchpoint, or else no
3888 watchpoint triggered after all. So don't print
3889 anything for this watchpoint. */
3890 bs
->print_it
= print_it_noop
;
3897 /* Check conditions (condition proper, frame, thread and ignore count)
3898 of breakpoint referred to by BS. If we should not stop for this
3899 breakpoint, set BS->stop to 0. */
3902 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3904 int thread_id
= pid_to_thread_id (ptid
);
3905 const struct bp_location
*bl
;
3906 struct breakpoint
*b
;
3908 /* BS is built for existing struct breakpoint. */
3909 bl
= bs
->bp_location_at
;
3910 gdb_assert (bl
!= NULL
);
3911 b
= bs
->breakpoint_at
;
3912 gdb_assert (b
!= NULL
);
3914 if (frame_id_p (b
->frame_id
)
3915 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3919 int value_is_zero
= 0;
3920 struct expression
*cond
;
3922 /* Evaluate Python breakpoints that have a "stop"
3923 method implemented. */
3924 if (b
->py_bp_object
)
3925 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
3927 if (is_watchpoint (b
))
3929 struct watchpoint
*w
= (struct watchpoint
*) b
;
3936 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3938 int within_current_scope
= 1;
3939 struct watchpoint
* w
;
3941 /* We use value_mark and value_free_to_mark because it could
3942 be a long time before we return to the command level and
3943 call free_all_values. We can't call free_all_values
3944 because we might be in the middle of evaluating a
3946 struct value
*mark
= value_mark ();
3948 if (is_watchpoint (b
))
3949 w
= (struct watchpoint
*) b
;
3953 /* Need to select the frame, with all that implies so that
3954 the conditions will have the right context. Because we
3955 use the frame, we will not see an inlined function's
3956 variables when we arrive at a breakpoint at the start
3957 of the inlined function; the current frame will be the
3959 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
3960 select_frame (get_current_frame ());
3963 struct frame_info
*frame
;
3965 /* For local watchpoint expressions, which particular
3966 instance of a local is being watched matters, so we
3967 keep track of the frame to evaluate the expression
3968 in. To evaluate the condition however, it doesn't
3969 really matter which instantiation of the function
3970 where the condition makes sense triggers the
3971 watchpoint. This allows an expression like "watch
3972 global if q > 10" set in `func', catch writes to
3973 global on all threads that call `func', or catch
3974 writes on all recursive calls of `func' by a single
3975 thread. We simply always evaluate the condition in
3976 the innermost frame that's executing where it makes
3977 sense to evaluate the condition. It seems
3979 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
3981 select_frame (frame
);
3983 within_current_scope
= 0;
3985 if (within_current_scope
)
3987 = catch_errors (breakpoint_cond_eval
, cond
,
3988 "Error in testing breakpoint condition:\n",
3992 warning (_("Watchpoint condition cannot be tested "
3993 "in the current scope"));
3994 /* If we failed to set the right context for this
3995 watchpoint, unconditionally report it. */
3998 /* FIXME-someday, should give breakpoint #. */
3999 value_free_to_mark (mark
);
4002 if (cond
&& value_is_zero
)
4006 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4010 else if (b
->ignore_count
> 0)
4013 annotate_ignore_count_change ();
4015 /* Increase the hit count even though we don't stop. */
4017 observer_notify_breakpoint_modified (b
);
4023 /* Get a bpstat associated with having just stopped at address
4024 BP_ADDR in thread PTID.
4026 Determine whether we stopped at a breakpoint, etc, or whether we
4027 don't understand this stop. Result is a chain of bpstat's such
4030 if we don't understand the stop, the result is a null pointer.
4032 if we understand why we stopped, the result is not null.
4034 Each element of the chain refers to a particular breakpoint or
4035 watchpoint at which we have stopped. (We may have stopped for
4036 several reasons concurrently.)
4038 Each element of the chain has valid next, breakpoint_at,
4039 commands, FIXME??? fields. */
4042 bpstat_stop_status (struct address_space
*aspace
,
4043 CORE_ADDR bp_addr
, ptid_t ptid
)
4045 struct breakpoint
*b
= NULL
;
4046 struct bp_location
*bl
;
4047 struct bp_location
*loc
;
4048 /* First item of allocated bpstat's. */
4049 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4050 /* Pointer to the last thing in the chain currently. */
4053 int need_remove_insert
;
4056 /* First, build the bpstat chain with locations that explain a
4057 target stop, while being careful to not set the target running,
4058 as that may invalidate locations (in particular watchpoint
4059 locations are recreated). Resuming will happen here with
4060 breakpoint conditions or watchpoint expressions that include
4061 inferior function calls. */
4065 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4068 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4070 /* For hardware watchpoints, we look only at the first
4071 location. The watchpoint_check function will work on the
4072 entire expression, not the individual locations. For
4073 read watchpoints, the watchpoints_triggered function has
4074 checked all locations already. */
4075 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4078 if (bl
->shlib_disabled
)
4081 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4084 /* Come here if it's a watchpoint, or if the break address
4087 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4090 /* Assume we stop. Should we find a watchpoint that is not
4091 actually triggered, or if the condition of the breakpoint
4092 evaluates as false, we'll reset 'stop' to 0. */
4096 /* If this is a scope breakpoint, mark the associated
4097 watchpoint as triggered so that we will handle the
4098 out-of-scope event. We'll get to the watchpoint next
4100 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4102 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4104 w
->watchpoint_triggered
= watch_triggered_yes
;
4109 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4111 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4113 bs
= bpstat_alloc (loc
, &bs_link
);
4114 /* For hits of moribund locations, we should just proceed. */
4117 bs
->print_it
= print_it_noop
;
4121 /* Now go through the locations that caused the target to stop, and
4122 check whether we're interested in reporting this stop to higher
4123 layers, or whether we should resume the target transparently. */
4127 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4132 b
= bs
->breakpoint_at
;
4133 b
->ops
->check_status (bs
);
4136 bpstat_check_breakpoint_conditions (bs
, ptid
);
4141 observer_notify_breakpoint_modified (b
);
4143 /* We will stop here. */
4144 if (b
->disposition
== disp_disable
)
4146 if (b
->enable_state
!= bp_permanent
)
4147 b
->enable_state
= bp_disabled
;
4152 bs
->commands
= b
->commands
;
4153 incref_counted_command_line (bs
->commands
);
4154 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4155 if (bs
->commands_left
4156 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4159 bs
->commands_left
->line
) == 0)))
4161 bs
->commands_left
= bs
->commands_left
->next
;
4166 /* Print nothing for this entry if we don't stop or don't print. */
4167 if (bs
->stop
== 0 || bs
->print
== 0)
4168 bs
->print_it
= print_it_noop
;
4172 /* If we aren't stopping, the value of some hardware watchpoint may
4173 not have changed, but the intermediate memory locations we are
4174 watching may have. Don't bother if we're stopping; this will get
4176 need_remove_insert
= 0;
4177 if (! bpstat_causes_stop (bs_head
))
4178 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4180 && bs
->breakpoint_at
4181 && is_hardware_watchpoint (bs
->breakpoint_at
))
4183 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4185 update_watchpoint (w
, 0 /* don't reparse. */);
4186 need_remove_insert
= 1;
4189 if (need_remove_insert
)
4190 update_global_location_list (1);
4191 else if (removed_any
)
4192 update_global_location_list (0);
4198 handle_jit_event (void)
4200 struct frame_info
*frame
;
4201 struct gdbarch
*gdbarch
;
4203 /* Switch terminal for any messages produced by
4204 breakpoint_re_set. */
4205 target_terminal_ours_for_output ();
4207 frame
= get_current_frame ();
4208 gdbarch
= get_frame_arch (frame
);
4210 jit_event_handler (gdbarch
);
4212 target_terminal_inferior ();
4215 /* Prepare WHAT final decision for infrun. */
4217 /* Decide what infrun needs to do with this bpstat. */
4220 bpstat_what (bpstat bs_head
)
4222 struct bpstat_what retval
;
4223 /* We need to defer calling `solib_add', as adding new symbols
4224 resets breakpoints, which in turn deletes breakpoint locations,
4225 and hence may clear unprocessed entries in the BS chain. */
4226 int shlib_event
= 0;
4230 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4231 retval
.call_dummy
= STOP_NONE
;
4232 retval
.is_longjmp
= 0;
4234 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4236 /* Extract this BS's action. After processing each BS, we check
4237 if its action overrides all we've seem so far. */
4238 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4241 if (bs
->breakpoint_at
== NULL
)
4243 /* I suspect this can happen if it was a momentary
4244 breakpoint which has since been deleted. */
4248 bptype
= bs
->breakpoint_at
->type
;
4255 case bp_hardware_breakpoint
:
4261 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4263 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4266 this_action
= BPSTAT_WHAT_SINGLE
;
4269 case bp_hardware_watchpoint
:
4270 case bp_read_watchpoint
:
4271 case bp_access_watchpoint
:
4275 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4277 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4281 /* There was a watchpoint, but we're not stopping.
4282 This requires no further action. */
4287 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4288 retval
.is_longjmp
= bptype
== bp_longjmp
;
4290 case bp_longjmp_resume
:
4291 case bp_exception_resume
:
4292 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4293 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4295 case bp_step_resume
:
4297 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4300 /* It is for the wrong frame. */
4301 this_action
= BPSTAT_WHAT_SINGLE
;
4304 case bp_hp_step_resume
:
4306 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4309 /* It is for the wrong frame. */
4310 this_action
= BPSTAT_WHAT_SINGLE
;
4313 case bp_watchpoint_scope
:
4314 case bp_thread_event
:
4315 case bp_overlay_event
:
4316 case bp_longjmp_master
:
4317 case bp_std_terminate_master
:
4318 case bp_exception_master
:
4319 this_action
= BPSTAT_WHAT_SINGLE
;
4325 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4327 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4331 /* There was a catchpoint, but we're not stopping.
4332 This requires no further action. */
4335 case bp_shlib_event
:
4338 /* If requested, stop when the dynamic linker notifies GDB
4339 of events. This allows the user to get control and place
4340 breakpoints in initializer routines for dynamically
4341 loaded objects (among other things). */
4342 if (stop_on_solib_events
)
4343 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4345 this_action
= BPSTAT_WHAT_SINGLE
;
4349 this_action
= BPSTAT_WHAT_SINGLE
;
4352 /* Make sure the action is stop (silent or noisy),
4353 so infrun.c pops the dummy frame. */
4354 retval
.call_dummy
= STOP_STACK_DUMMY
;
4355 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4357 case bp_std_terminate
:
4358 /* Make sure the action is stop (silent or noisy),
4359 so infrun.c pops the dummy frame. */
4360 retval
.call_dummy
= STOP_STD_TERMINATE
;
4361 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4364 case bp_fast_tracepoint
:
4365 case bp_static_tracepoint
:
4366 /* Tracepoint hits should not be reported back to GDB, and
4367 if one got through somehow, it should have been filtered
4369 internal_error (__FILE__
, __LINE__
,
4370 _("bpstat_what: tracepoint encountered"));
4372 case bp_gnu_ifunc_resolver
:
4373 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4374 this_action
= BPSTAT_WHAT_SINGLE
;
4376 case bp_gnu_ifunc_resolver_return
:
4377 /* The breakpoint will be removed, execution will restart from the
4378 PC of the former breakpoint. */
4379 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4382 internal_error (__FILE__
, __LINE__
,
4383 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4386 retval
.main_action
= max (retval
.main_action
, this_action
);
4389 /* These operations may affect the bs->breakpoint_at state so they are
4390 delayed after MAIN_ACTION is decided above. */
4395 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4397 /* Check for any newly added shared libraries if we're supposed
4398 to be adding them automatically. */
4400 /* Switch terminal for any messages produced by
4401 breakpoint_re_set. */
4402 target_terminal_ours_for_output ();
4405 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4407 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4410 target_terminal_inferior ();
4416 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4418 handle_jit_event ();
4421 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4423 struct breakpoint
*b
= bs
->breakpoint_at
;
4429 case bp_gnu_ifunc_resolver
:
4430 gnu_ifunc_resolver_stop (b
);
4432 case bp_gnu_ifunc_resolver_return
:
4433 gnu_ifunc_resolver_return_stop (b
);
4441 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4442 without hardware support). This isn't related to a specific bpstat,
4443 just to things like whether watchpoints are set. */
4446 bpstat_should_step (void)
4448 struct breakpoint
*b
;
4451 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4457 bpstat_causes_stop (bpstat bs
)
4459 for (; bs
!= NULL
; bs
= bs
->next
)
4468 /* Compute a string of spaces suitable to indent the next line
4469 so it starts at the position corresponding to the table column
4470 named COL_NAME in the currently active table of UIOUT. */
4473 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4475 static char wrap_indent
[80];
4476 int i
, total_width
, width
, align
;
4480 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4482 if (strcmp (text
, col_name
) == 0)
4484 gdb_assert (total_width
< sizeof wrap_indent
);
4485 memset (wrap_indent
, ' ', total_width
);
4486 wrap_indent
[total_width
] = 0;
4491 total_width
+= width
+ 1;
4497 /* Print the LOC location out of the list of B->LOC locations. */
4500 print_breakpoint_location (struct breakpoint
*b
,
4501 struct bp_location
*loc
)
4503 struct ui_out
*uiout
= current_uiout
;
4504 struct cleanup
*old_chain
= save_current_program_space ();
4506 if (loc
!= NULL
&& loc
->shlib_disabled
)
4510 set_current_program_space (loc
->pspace
);
4512 if (b
->display_canonical
)
4513 ui_out_field_string (uiout
, "what", b
->addr_string
);
4514 else if (b
->source_file
&& loc
)
4517 = find_pc_sect_function (loc
->address
, loc
->section
);
4520 ui_out_text (uiout
, "in ");
4521 ui_out_field_string (uiout
, "func",
4522 SYMBOL_PRINT_NAME (sym
));
4523 ui_out_text (uiout
, " ");
4524 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4525 ui_out_text (uiout
, "at ");
4527 ui_out_field_string (uiout
, "file", b
->source_file
);
4528 ui_out_text (uiout
, ":");
4530 if (ui_out_is_mi_like_p (uiout
))
4532 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4533 char *fullname
= symtab_to_fullname (sal
.symtab
);
4536 ui_out_field_string (uiout
, "fullname", fullname
);
4539 ui_out_field_int (uiout
, "line", b
->line_number
);
4543 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4544 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4546 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4548 ui_out_field_stream (uiout
, "at", stb
);
4550 do_cleanups (stb_chain
);
4553 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4555 do_cleanups (old_chain
);
4559 bptype_string (enum bptype type
)
4561 struct ep_type_description
4566 static struct ep_type_description bptypes
[] =
4568 {bp_none
, "?deleted?"},
4569 {bp_breakpoint
, "breakpoint"},
4570 {bp_hardware_breakpoint
, "hw breakpoint"},
4571 {bp_until
, "until"},
4572 {bp_finish
, "finish"},
4573 {bp_watchpoint
, "watchpoint"},
4574 {bp_hardware_watchpoint
, "hw watchpoint"},
4575 {bp_read_watchpoint
, "read watchpoint"},
4576 {bp_access_watchpoint
, "acc watchpoint"},
4577 {bp_longjmp
, "longjmp"},
4578 {bp_longjmp_resume
, "longjmp resume"},
4579 {bp_exception
, "exception"},
4580 {bp_exception_resume
, "exception resume"},
4581 {bp_step_resume
, "step resume"},
4582 {bp_hp_step_resume
, "high-priority step resume"},
4583 {bp_watchpoint_scope
, "watchpoint scope"},
4584 {bp_call_dummy
, "call dummy"},
4585 {bp_std_terminate
, "std::terminate"},
4586 {bp_shlib_event
, "shlib events"},
4587 {bp_thread_event
, "thread events"},
4588 {bp_overlay_event
, "overlay events"},
4589 {bp_longjmp_master
, "longjmp master"},
4590 {bp_std_terminate_master
, "std::terminate master"},
4591 {bp_exception_master
, "exception master"},
4592 {bp_catchpoint
, "catchpoint"},
4593 {bp_tracepoint
, "tracepoint"},
4594 {bp_fast_tracepoint
, "fast tracepoint"},
4595 {bp_static_tracepoint
, "static tracepoint"},
4596 {bp_jit_event
, "jit events"},
4597 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4598 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4601 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4602 || ((int) type
!= bptypes
[(int) type
].type
))
4603 internal_error (__FILE__
, __LINE__
,
4604 _("bptypes table does not describe type #%d."),
4607 return bptypes
[(int) type
].description
;
4610 /* Print B to gdb_stdout. */
4613 print_one_breakpoint_location (struct breakpoint
*b
,
4614 struct bp_location
*loc
,
4616 struct bp_location
**last_loc
,
4619 struct command_line
*l
;
4620 static char bpenables
[] = "nynny";
4622 struct ui_out
*uiout
= current_uiout
;
4623 int header_of_multiple
= 0;
4624 int part_of_multiple
= (loc
!= NULL
);
4625 struct value_print_options opts
;
4627 get_user_print_options (&opts
);
4629 gdb_assert (!loc
|| loc_number
!= 0);
4630 /* See comment in print_one_breakpoint concerning treatment of
4631 breakpoints with single disabled location. */
4634 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4635 header_of_multiple
= 1;
4643 if (part_of_multiple
)
4646 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4647 ui_out_field_string (uiout
, "number", formatted
);
4652 ui_out_field_int (uiout
, "number", b
->number
);
4657 if (part_of_multiple
)
4658 ui_out_field_skip (uiout
, "type");
4660 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4664 if (part_of_multiple
)
4665 ui_out_field_skip (uiout
, "disp");
4667 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4672 if (part_of_multiple
)
4673 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4675 ui_out_field_fmt (uiout
, "enabled", "%c",
4676 bpenables
[(int) b
->enable_state
]);
4677 ui_out_spaces (uiout
, 2);
4681 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4683 /* Although the print_one can possibly print all locations,
4684 calling it here is not likely to get any nice result. So,
4685 make sure there's just one location. */
4686 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4687 b
->ops
->print_one (b
, last_loc
);
4693 internal_error (__FILE__
, __LINE__
,
4694 _("print_one_breakpoint: bp_none encountered\n"));
4698 case bp_hardware_watchpoint
:
4699 case bp_read_watchpoint
:
4700 case bp_access_watchpoint
:
4702 struct watchpoint
*w
= (struct watchpoint
*) b
;
4704 /* Field 4, the address, is omitted (which makes the columns
4705 not line up too nicely with the headers, but the effect
4706 is relatively readable). */
4707 if (opts
.addressprint
)
4708 ui_out_field_skip (uiout
, "addr");
4710 ui_out_field_string (uiout
, "what", w
->exp_string
);
4715 case bp_hardware_breakpoint
:
4719 case bp_longjmp_resume
:
4721 case bp_exception_resume
:
4722 case bp_step_resume
:
4723 case bp_hp_step_resume
:
4724 case bp_watchpoint_scope
:
4726 case bp_std_terminate
:
4727 case bp_shlib_event
:
4728 case bp_thread_event
:
4729 case bp_overlay_event
:
4730 case bp_longjmp_master
:
4731 case bp_std_terminate_master
:
4732 case bp_exception_master
:
4734 case bp_fast_tracepoint
:
4735 case bp_static_tracepoint
:
4737 case bp_gnu_ifunc_resolver
:
4738 case bp_gnu_ifunc_resolver_return
:
4739 if (opts
.addressprint
)
4742 if (header_of_multiple
)
4743 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4744 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4745 ui_out_field_string (uiout
, "addr", "<PENDING>");
4747 ui_out_field_core_addr (uiout
, "addr",
4748 loc
->gdbarch
, loc
->address
);
4751 if (!header_of_multiple
)
4752 print_breakpoint_location (b
, loc
);
4759 /* For backward compatibility, don't display inferiors unless there
4762 && !header_of_multiple
4764 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4765 && (number_of_program_spaces () > 1
4766 || number_of_inferiors () > 1)
4767 /* LOC is for existing B, it cannot be in
4768 moribund_locations and thus having NULL OWNER. */
4769 && loc
->owner
->type
!= bp_catchpoint
)))
4771 struct inferior
*inf
;
4774 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4776 if (inf
->pspace
== loc
->pspace
)
4781 ui_out_text (uiout
, " inf ");
4784 ui_out_text (uiout
, ", ");
4785 ui_out_text (uiout
, plongest (inf
->num
));
4790 if (!part_of_multiple
)
4792 if (b
->thread
!= -1)
4794 /* FIXME: This seems to be redundant and lost here; see the
4795 "stop only in" line a little further down. */
4796 ui_out_text (uiout
, " thread ");
4797 ui_out_field_int (uiout
, "thread", b
->thread
);
4799 else if (b
->task
!= 0)
4801 ui_out_text (uiout
, " task ");
4802 ui_out_field_int (uiout
, "task", b
->task
);
4806 ui_out_text (uiout
, "\n");
4808 if (!part_of_multiple
)
4809 b
->ops
->print_one_detail (b
, uiout
);
4811 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4814 ui_out_text (uiout
, "\tstop only in stack frame at ");
4815 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4817 ui_out_field_core_addr (uiout
, "frame",
4818 b
->gdbarch
, b
->frame_id
.stack_addr
);
4819 ui_out_text (uiout
, "\n");
4822 if (!part_of_multiple
&& b
->cond_string
)
4825 if (is_tracepoint (b
))
4826 ui_out_text (uiout
, "\ttrace only if ");
4828 ui_out_text (uiout
, "\tstop only if ");
4829 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4830 ui_out_text (uiout
, "\n");
4833 if (!part_of_multiple
&& b
->thread
!= -1)
4835 /* FIXME should make an annotation for this. */
4836 ui_out_text (uiout
, "\tstop only in thread ");
4837 ui_out_field_int (uiout
, "thread", b
->thread
);
4838 ui_out_text (uiout
, "\n");
4841 if (!part_of_multiple
&& b
->hit_count
)
4843 /* FIXME should make an annotation for this. */
4844 if (ep_is_catchpoint (b
))
4845 ui_out_text (uiout
, "\tcatchpoint");
4847 ui_out_text (uiout
, "\tbreakpoint");
4848 ui_out_text (uiout
, " already hit ");
4849 ui_out_field_int (uiout
, "times", b
->hit_count
);
4850 if (b
->hit_count
== 1)
4851 ui_out_text (uiout
, " time\n");
4853 ui_out_text (uiout
, " times\n");
4856 /* Output the count also if it is zero, but only if this is mi.
4857 FIXME: Should have a better test for this. */
4858 if (ui_out_is_mi_like_p (uiout
))
4859 if (!part_of_multiple
&& b
->hit_count
== 0)
4860 ui_out_field_int (uiout
, "times", b
->hit_count
);
4862 if (!part_of_multiple
&& b
->ignore_count
)
4865 ui_out_text (uiout
, "\tignore next ");
4866 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4867 ui_out_text (uiout
, " hits\n");
4870 l
= b
->commands
? b
->commands
->commands
: NULL
;
4871 if (!part_of_multiple
&& l
)
4873 struct cleanup
*script_chain
;
4876 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4877 print_command_lines (uiout
, l
, 4);
4878 do_cleanups (script_chain
);
4881 if (is_tracepoint (b
))
4883 struct tracepoint
*t
= (struct tracepoint
*) b
;
4885 if (!part_of_multiple
&& t
->pass_count
)
4887 annotate_field (10);
4888 ui_out_text (uiout
, "\tpass count ");
4889 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4890 ui_out_text (uiout
, " \n");
4894 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4896 if (is_watchpoint (b
))
4898 struct watchpoint
*w
= (struct watchpoint
*) b
;
4900 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
4902 else if (b
->addr_string
)
4903 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4908 print_one_breakpoint (struct breakpoint
*b
,
4909 struct bp_location
**last_loc
,
4912 struct cleanup
*bkpt_chain
;
4913 struct ui_out
*uiout
= current_uiout
;
4915 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4917 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
4918 do_cleanups (bkpt_chain
);
4920 /* If this breakpoint has custom print function,
4921 it's already printed. Otherwise, print individual
4922 locations, if any. */
4923 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4925 /* If breakpoint has a single location that is disabled, we
4926 print it as if it had several locations, since otherwise it's
4927 hard to represent "breakpoint enabled, location disabled"
4930 Note that while hardware watchpoints have several locations
4931 internally, that's not a property exposed to user. */
4933 && !is_hardware_watchpoint (b
)
4934 && (b
->loc
->next
|| !b
->loc
->enabled
))
4936 struct bp_location
*loc
;
4939 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4941 struct cleanup
*inner2
=
4942 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
4943 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
4944 do_cleanups (inner2
);
4951 breakpoint_address_bits (struct breakpoint
*b
)
4953 int print_address_bits
= 0;
4954 struct bp_location
*loc
;
4956 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4960 /* Software watchpoints that aren't watching memory don't have
4961 an address to print. */
4962 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4965 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4966 if (addr_bit
> print_address_bits
)
4967 print_address_bits
= addr_bit
;
4970 return print_address_bits
;
4973 struct captured_breakpoint_query_args
4979 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4981 struct captured_breakpoint_query_args
*args
= data
;
4982 struct breakpoint
*b
;
4983 struct bp_location
*dummy_loc
= NULL
;
4987 if (args
->bnum
== b
->number
)
4989 print_one_breakpoint (b
, &dummy_loc
, 0);
4997 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
4998 char **error_message
)
5000 struct captured_breakpoint_query_args args
;
5003 /* For the moment we don't trust print_one_breakpoint() to not throw
5005 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5006 error_message
, RETURN_MASK_ALL
) < 0)
5012 /* Return true if this breakpoint was set by the user, false if it is
5013 internal or momentary. */
5016 user_breakpoint_p (struct breakpoint
*b
)
5018 return b
->number
> 0;
5021 /* Print information on user settable breakpoint (watchpoint, etc)
5022 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5023 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5024 FILTER is non-NULL, call it on each breakpoint and only include the
5025 ones for which it returns non-zero. Return the total number of
5026 breakpoints listed. */
5029 breakpoint_1 (char *args
, int allflag
,
5030 int (*filter
) (const struct breakpoint
*))
5032 struct breakpoint
*b
;
5033 struct bp_location
*last_loc
= NULL
;
5034 int nr_printable_breakpoints
;
5035 struct cleanup
*bkpttbl_chain
;
5036 struct value_print_options opts
;
5037 int print_address_bits
= 0;
5038 int print_type_col_width
= 14;
5039 struct ui_out
*uiout
= current_uiout
;
5041 get_user_print_options (&opts
);
5043 /* Compute the number of rows in the table, as well as the size
5044 required for address fields. */
5045 nr_printable_breakpoints
= 0;
5048 /* If we have a filter, only list the breakpoints it accepts. */
5049 if (filter
&& !filter (b
))
5052 /* If we have an "args" string, it is a list of breakpoints to
5053 accept. Skip the others. */
5054 if (args
!= NULL
&& *args
!= '\0')
5056 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5058 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5062 if (allflag
|| user_breakpoint_p (b
))
5064 int addr_bit
, type_len
;
5066 addr_bit
= breakpoint_address_bits (b
);
5067 if (addr_bit
> print_address_bits
)
5068 print_address_bits
= addr_bit
;
5070 type_len
= strlen (bptype_string (b
->type
));
5071 if (type_len
> print_type_col_width
)
5072 print_type_col_width
= type_len
;
5074 nr_printable_breakpoints
++;
5078 if (opts
.addressprint
)
5080 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5081 nr_printable_breakpoints
,
5085 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5086 nr_printable_breakpoints
,
5089 if (nr_printable_breakpoints
> 0)
5090 annotate_breakpoints_headers ();
5091 if (nr_printable_breakpoints
> 0)
5093 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5094 if (nr_printable_breakpoints
> 0)
5096 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5097 "type", "Type"); /* 2 */
5098 if (nr_printable_breakpoints
> 0)
5100 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5101 if (nr_printable_breakpoints
> 0)
5103 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5104 if (opts
.addressprint
)
5106 if (nr_printable_breakpoints
> 0)
5108 if (print_address_bits
<= 32)
5109 ui_out_table_header (uiout
, 10, ui_left
,
5110 "addr", "Address"); /* 5 */
5112 ui_out_table_header (uiout
, 18, ui_left
,
5113 "addr", "Address"); /* 5 */
5115 if (nr_printable_breakpoints
> 0)
5117 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5118 ui_out_table_body (uiout
);
5119 if (nr_printable_breakpoints
> 0)
5120 annotate_breakpoints_table ();
5125 /* If we have a filter, only list the breakpoints it accepts. */
5126 if (filter
&& !filter (b
))
5129 /* If we have an "args" string, it is a list of breakpoints to
5130 accept. Skip the others. */
5132 if (args
!= NULL
&& *args
!= '\0')
5134 if (allflag
) /* maintenance info breakpoint */
5136 if (parse_and_eval_long (args
) != b
->number
)
5139 else /* all others */
5141 if (!number_is_in_list (args
, b
->number
))
5145 /* We only print out user settable breakpoints unless the
5147 if (allflag
|| user_breakpoint_p (b
))
5148 print_one_breakpoint (b
, &last_loc
, allflag
);
5151 do_cleanups (bkpttbl_chain
);
5153 if (nr_printable_breakpoints
== 0)
5155 /* If there's a filter, let the caller decide how to report
5159 if (args
== NULL
|| *args
== '\0')
5160 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5162 ui_out_message (uiout
, 0,
5163 "No breakpoint or watchpoint matching '%s'.\n",
5169 if (last_loc
&& !server_command
)
5170 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5173 /* FIXME? Should this be moved up so that it is only called when
5174 there have been breakpoints? */
5175 annotate_breakpoints_table_end ();
5177 return nr_printable_breakpoints
;
5180 /* Display the value of default-collect in a way that is generally
5181 compatible with the breakpoint list. */
5184 default_collect_info (void)
5186 struct ui_out
*uiout
= current_uiout
;
5188 /* If it has no value (which is frequently the case), say nothing; a
5189 message like "No default-collect." gets in user's face when it's
5191 if (!*default_collect
)
5194 /* The following phrase lines up nicely with per-tracepoint collect
5196 ui_out_text (uiout
, "default collect ");
5197 ui_out_field_string (uiout
, "default-collect", default_collect
);
5198 ui_out_text (uiout
, " \n");
5202 breakpoints_info (char *args
, int from_tty
)
5204 breakpoint_1 (args
, 0, NULL
);
5206 default_collect_info ();
5210 watchpoints_info (char *args
, int from_tty
)
5212 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5213 struct ui_out
*uiout
= current_uiout
;
5215 if (num_printed
== 0)
5217 if (args
== NULL
|| *args
== '\0')
5218 ui_out_message (uiout
, 0, "No watchpoints.\n");
5220 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5225 maintenance_info_breakpoints (char *args
, int from_tty
)
5227 breakpoint_1 (args
, 1, NULL
);
5229 default_collect_info ();
5233 breakpoint_has_pc (struct breakpoint
*b
,
5234 struct program_space
*pspace
,
5235 CORE_ADDR pc
, struct obj_section
*section
)
5237 struct bp_location
*bl
= b
->loc
;
5239 for (; bl
; bl
= bl
->next
)
5241 if (bl
->pspace
== pspace
5242 && bl
->address
== pc
5243 && (!overlay_debugging
|| bl
->section
== section
))
5249 /* Print a message describing any breakpoints set at PC. This
5250 concerns with logical breakpoints, so we match program spaces, not
5254 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5255 struct program_space
*pspace
, CORE_ADDR pc
,
5256 struct obj_section
*section
, int thread
)
5259 struct breakpoint
*b
;
5262 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5266 printf_filtered (_("Note: breakpoint "));
5267 else /* if (others == ???) */
5268 printf_filtered (_("Note: breakpoints "));
5270 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5273 printf_filtered ("%d", b
->number
);
5274 if (b
->thread
== -1 && thread
!= -1)
5275 printf_filtered (" (all threads)");
5276 else if (b
->thread
!= -1)
5277 printf_filtered (" (thread %d)", b
->thread
);
5278 printf_filtered ("%s%s ",
5279 ((b
->enable_state
== bp_disabled
5280 || b
->enable_state
== bp_call_disabled
5281 || b
->enable_state
== bp_startup_disabled
)
5283 : b
->enable_state
== bp_permanent
5287 : ((others
== 1) ? " and" : ""));
5289 printf_filtered (_("also set at pc "));
5290 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5291 printf_filtered (".\n");
5295 /* Set the default place to put a breakpoint
5296 for the `break' command with no arguments. */
5299 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5300 CORE_ADDR addr
, struct symtab
*symtab
,
5303 default_breakpoint_valid
= valid
;
5304 default_breakpoint_pspace
= pspace
;
5305 default_breakpoint_address
= addr
;
5306 default_breakpoint_symtab
= symtab
;
5307 default_breakpoint_line
= line
;
5310 /* Return true iff it is meaningful to use the address member of
5311 BPT. For some breakpoint types, the address member is irrelevant
5312 and it makes no sense to attempt to compare it to other addresses
5313 (or use it for any other purpose either).
5315 More specifically, each of the following breakpoint types will
5316 always have a zero valued address and we don't want to mark
5317 breakpoints of any of these types to be a duplicate of an actual
5318 breakpoint at address zero:
5326 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5328 enum bptype type
= bpt
->type
;
5330 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5333 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5334 true if LOC1 and LOC2 represent the same watchpoint location. */
5337 watchpoint_locations_match (struct bp_location
*loc1
,
5338 struct bp_location
*loc2
)
5340 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5341 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5343 /* Both of them must exist. */
5344 gdb_assert (w1
!= NULL
);
5345 gdb_assert (w2
!= NULL
);
5347 /* If the target can evaluate the condition expression in hardware,
5348 then we we need to insert both watchpoints even if they are at
5349 the same place. Otherwise the watchpoint will only trigger when
5350 the condition of whichever watchpoint was inserted evaluates to
5351 true, not giving a chance for GDB to check the condition of the
5352 other watchpoint. */
5354 && target_can_accel_watchpoint_condition (loc1
->address
,
5356 loc1
->watchpoint_type
,
5359 && target_can_accel_watchpoint_condition (loc2
->address
,
5361 loc2
->watchpoint_type
,
5365 /* Note that this checks the owner's type, not the location's. In
5366 case the target does not support read watchpoints, but does
5367 support access watchpoints, we'll have bp_read_watchpoint
5368 watchpoints with hw_access locations. Those should be considered
5369 duplicates of hw_read locations. The hw_read locations will
5370 become hw_access locations later. */
5371 return (loc1
->owner
->type
== loc2
->owner
->type
5372 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5373 && loc1
->address
== loc2
->address
5374 && loc1
->length
== loc2
->length
);
5377 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5378 same breakpoint location. In most targets, this can only be true
5379 if ASPACE1 matches ASPACE2. On targets that have global
5380 breakpoints, the address space doesn't really matter. */
5383 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5384 struct address_space
*aspace2
, CORE_ADDR addr2
)
5386 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5387 || aspace1
== aspace2
)
5391 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5392 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5393 matches ASPACE2. On targets that have global breakpoints, the address
5394 space doesn't really matter. */
5397 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5398 int len1
, struct address_space
*aspace2
,
5401 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5402 || aspace1
== aspace2
)
5403 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5406 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5407 a ranged breakpoint. In most targets, a match happens only if ASPACE
5408 matches the breakpoint's address space. On targets that have global
5409 breakpoints, the address space doesn't really matter. */
5412 breakpoint_location_address_match (struct bp_location
*bl
,
5413 struct address_space
*aspace
,
5416 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5419 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5420 bl
->address
, bl
->length
,
5424 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5425 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5426 represent the same location. */
5429 breakpoint_locations_match (struct bp_location
*loc1
,
5430 struct bp_location
*loc2
)
5432 int hw_point1
, hw_point2
;
5434 /* Both of them must not be in moribund_locations. */
5435 gdb_assert (loc1
->owner
!= NULL
);
5436 gdb_assert (loc2
->owner
!= NULL
);
5438 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5439 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5441 if (hw_point1
!= hw_point2
)
5444 return watchpoint_locations_match (loc1
, loc2
);
5446 /* We compare bp_location.length in order to cover ranged breakpoints. */
5447 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5448 loc2
->pspace
->aspace
, loc2
->address
)
5449 && loc1
->length
== loc2
->length
);
5453 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5454 int bnum
, int have_bnum
)
5456 /* The longest string possibly returned by hex_string_custom
5457 is 50 chars. These must be at least that big for safety. */
5461 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5462 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5464 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5465 bnum
, astr1
, astr2
);
5467 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5470 /* Adjust a breakpoint's address to account for architectural
5471 constraints on breakpoint placement. Return the adjusted address.
5472 Note: Very few targets require this kind of adjustment. For most
5473 targets, this function is simply the identity function. */
5476 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5477 CORE_ADDR bpaddr
, enum bptype bptype
)
5479 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5481 /* Very few targets need any kind of breakpoint adjustment. */
5484 else if (bptype
== bp_watchpoint
5485 || bptype
== bp_hardware_watchpoint
5486 || bptype
== bp_read_watchpoint
5487 || bptype
== bp_access_watchpoint
5488 || bptype
== bp_catchpoint
)
5490 /* Watchpoints and the various bp_catch_* eventpoints should not
5491 have their addresses modified. */
5496 CORE_ADDR adjusted_bpaddr
;
5498 /* Some targets have architectural constraints on the placement
5499 of breakpoint instructions. Obtain the adjusted address. */
5500 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5502 /* An adjusted breakpoint address can significantly alter
5503 a user's expectations. Print a warning if an adjustment
5505 if (adjusted_bpaddr
!= bpaddr
)
5506 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5508 return adjusted_bpaddr
;
5513 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5514 struct breakpoint
*owner
)
5516 memset (loc
, 0, sizeof (*loc
));
5518 gdb_assert (ops
!= NULL
);
5523 loc
->shlib_disabled
= 0;
5526 switch (owner
->type
)
5532 case bp_longjmp_resume
:
5534 case bp_exception_resume
:
5535 case bp_step_resume
:
5536 case bp_hp_step_resume
:
5537 case bp_watchpoint_scope
:
5539 case bp_std_terminate
:
5540 case bp_shlib_event
:
5541 case bp_thread_event
:
5542 case bp_overlay_event
:
5544 case bp_longjmp_master
:
5545 case bp_std_terminate_master
:
5546 case bp_exception_master
:
5547 case bp_gnu_ifunc_resolver
:
5548 case bp_gnu_ifunc_resolver_return
:
5549 loc
->loc_type
= bp_loc_software_breakpoint
;
5551 case bp_hardware_breakpoint
:
5552 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5554 case bp_hardware_watchpoint
:
5555 case bp_read_watchpoint
:
5556 case bp_access_watchpoint
:
5557 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5562 case bp_fast_tracepoint
:
5563 case bp_static_tracepoint
:
5564 loc
->loc_type
= bp_loc_other
;
5567 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5573 /* Allocate a struct bp_location. */
5575 static struct bp_location
*
5576 allocate_bp_location (struct breakpoint
*bpt
)
5578 return bpt
->ops
->allocate_location (bpt
);
5582 free_bp_location (struct bp_location
*loc
)
5584 loc
->ops
->dtor (loc
);
5588 /* Increment reference count. */
5591 incref_bp_location (struct bp_location
*bl
)
5596 /* Decrement reference count. If the reference count reaches 0,
5597 destroy the bp_location. Sets *BLP to NULL. */
5600 decref_bp_location (struct bp_location
**blp
)
5602 gdb_assert ((*blp
)->refc
> 0);
5604 if (--(*blp
)->refc
== 0)
5605 free_bp_location (*blp
);
5609 /* Add breakpoint B at the end of the global breakpoint chain. */
5612 add_to_breakpoint_chain (struct breakpoint
*b
)
5614 struct breakpoint
*b1
;
5616 /* Add this breakpoint to the end of the chain so that a list of
5617 breakpoints will come out in order of increasing numbers. */
5619 b1
= breakpoint_chain
;
5621 breakpoint_chain
= b
;
5630 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5633 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5634 struct gdbarch
*gdbarch
,
5636 const struct breakpoint_ops
*ops
)
5638 memset (b
, 0, sizeof (*b
));
5640 gdb_assert (ops
!= NULL
);
5644 b
->gdbarch
= gdbarch
;
5645 b
->language
= current_language
->la_language
;
5646 b
->input_radix
= input_radix
;
5648 b
->enable_state
= bp_enabled
;
5651 b
->ignore_count
= 0;
5653 b
->frame_id
= null_frame_id
;
5654 b
->condition_not_parsed
= 0;
5655 b
->py_bp_object
= NULL
;
5656 b
->related_breakpoint
= b
;
5659 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5660 that has type BPTYPE and has no locations as yet. */
5662 static struct breakpoint
*
5663 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5665 const struct breakpoint_ops
*ops
)
5667 struct breakpoint
*b
= XNEW (struct breakpoint
);
5669 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5670 add_to_breakpoint_chain (b
);
5674 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5675 resolutions should be made as the user specified the location explicitly
5679 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5681 gdb_assert (loc
->owner
!= NULL
);
5683 if (loc
->owner
->type
== bp_breakpoint
5684 || loc
->owner
->type
== bp_hardware_breakpoint
5685 || is_tracepoint (loc
->owner
))
5689 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5690 NULL
, NULL
, &is_gnu_ifunc
);
5692 if (is_gnu_ifunc
&& !explicit_loc
)
5694 struct breakpoint
*b
= loc
->owner
;
5696 gdb_assert (loc
->pspace
== current_program_space
);
5697 if (gnu_ifunc_resolve_name (loc
->function_name
,
5698 &loc
->requested_address
))
5700 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5701 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5702 loc
->requested_address
,
5705 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5706 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5708 /* Create only the whole new breakpoint of this type but do not
5709 mess more complicated breakpoints with multiple locations. */
5710 b
->type
= bp_gnu_ifunc_resolver
;
5714 if (loc
->function_name
)
5715 loc
->function_name
= xstrdup (loc
->function_name
);
5719 /* Attempt to determine architecture of location identified by SAL. */
5720 static struct gdbarch
*
5721 get_sal_arch (struct symtab_and_line sal
)
5724 return get_objfile_arch (sal
.section
->objfile
);
5726 return get_objfile_arch (sal
.symtab
->objfile
);
5731 /* Low level routine for partially initializing a breakpoint of type
5732 BPTYPE. The newly created breakpoint's address, section, source
5733 file name, and line number are provided by SAL.
5735 It is expected that the caller will complete the initialization of
5736 the newly created breakpoint struct as well as output any status
5737 information regarding the creation of a new breakpoint. */
5740 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5741 struct symtab_and_line sal
, enum bptype bptype
,
5742 const struct breakpoint_ops
*ops
)
5744 CORE_ADDR adjusted_address
;
5745 struct gdbarch
*loc_gdbarch
;
5747 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5749 loc_gdbarch
= get_sal_arch (sal
);
5751 loc_gdbarch
= b
->gdbarch
;
5753 if (bptype
!= bp_catchpoint
)
5754 gdb_assert (sal
.pspace
!= NULL
);
5756 /* Adjust the breakpoint's address prior to allocating a location.
5757 Once we call allocate_bp_location(), that mostly uninitialized
5758 location will be placed on the location chain. Adjustment of the
5759 breakpoint may cause target_read_memory() to be called and we do
5760 not want its scan of the location chain to find a breakpoint and
5761 location that's only been partially initialized. */
5762 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5765 b
->loc
= allocate_bp_location (b
);
5766 b
->loc
->gdbarch
= loc_gdbarch
;
5767 b
->loc
->requested_address
= sal
.pc
;
5768 b
->loc
->address
= adjusted_address
;
5769 b
->loc
->pspace
= sal
.pspace
;
5771 /* Store the program space that was used to set the breakpoint, for
5772 breakpoint resetting. */
5773 b
->pspace
= sal
.pspace
;
5775 if (sal
.symtab
== NULL
)
5776 b
->source_file
= NULL
;
5778 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5779 b
->loc
->section
= sal
.section
;
5780 b
->line_number
= sal
.line
;
5782 set_breakpoint_location_function (b
->loc
,
5783 sal
.explicit_pc
|| sal
.explicit_line
);
5785 breakpoints_changed ();
5788 /* set_raw_breakpoint is a low level routine for allocating and
5789 partially initializing a breakpoint of type BPTYPE. The newly
5790 created breakpoint's address, section, source file name, and line
5791 number are provided by SAL. The newly created and partially
5792 initialized breakpoint is added to the breakpoint chain and
5793 is also returned as the value of this function.
5795 It is expected that the caller will complete the initialization of
5796 the newly created breakpoint struct as well as output any status
5797 information regarding the creation of a new breakpoint. In
5798 particular, set_raw_breakpoint does NOT set the breakpoint
5799 number! Care should be taken to not allow an error to occur
5800 prior to completing the initialization of the breakpoint. If this
5801 should happen, a bogus breakpoint will be left on the chain. */
5804 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5805 struct symtab_and_line sal
, enum bptype bptype
,
5806 const struct breakpoint_ops
*ops
)
5808 struct breakpoint
*b
= XNEW (struct breakpoint
);
5810 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5811 add_to_breakpoint_chain (b
);
5816 /* Note that the breakpoint object B describes a permanent breakpoint
5817 instruction, hard-wired into the inferior's code. */
5819 make_breakpoint_permanent (struct breakpoint
*b
)
5821 struct bp_location
*bl
;
5823 b
->enable_state
= bp_permanent
;
5825 /* By definition, permanent breakpoints are already present in the
5826 code. Mark all locations as inserted. For now,
5827 make_breakpoint_permanent is called in just one place, so it's
5828 hard to say if it's reasonable to have permanent breakpoint with
5829 multiple locations or not, but it's easy to implement. */
5830 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5834 /* Call this routine when stepping and nexting to enable a breakpoint
5835 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5836 initiated the operation. */
5839 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5841 struct breakpoint
*b
, *b_tmp
;
5842 int thread
= tp
->num
;
5844 /* To avoid having to rescan all objfile symbols at every step,
5845 we maintain a list of continually-inserted but always disabled
5846 longjmp "master" breakpoints. Here, we simply create momentary
5847 clones of those and enable them for the requested thread. */
5848 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5849 if (b
->pspace
== current_program_space
5850 && (b
->type
== bp_longjmp_master
5851 || b
->type
== bp_exception_master
))
5853 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5854 struct breakpoint
*clone
;
5856 clone
= momentary_breakpoint_from_master (b
, type
,
5857 &momentary_breakpoint_ops
);
5858 clone
->thread
= thread
;
5861 tp
->initiating_frame
= frame
;
5864 /* Delete all longjmp breakpoints from THREAD. */
5866 delete_longjmp_breakpoint (int thread
)
5868 struct breakpoint
*b
, *b_tmp
;
5870 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5871 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5873 if (b
->thread
== thread
)
5874 delete_breakpoint (b
);
5879 enable_overlay_breakpoints (void)
5881 struct breakpoint
*b
;
5884 if (b
->type
== bp_overlay_event
)
5886 b
->enable_state
= bp_enabled
;
5887 update_global_location_list (1);
5888 overlay_events_enabled
= 1;
5893 disable_overlay_breakpoints (void)
5895 struct breakpoint
*b
;
5898 if (b
->type
== bp_overlay_event
)
5900 b
->enable_state
= bp_disabled
;
5901 update_global_location_list (0);
5902 overlay_events_enabled
= 0;
5906 /* Set an active std::terminate breakpoint for each std::terminate
5907 master breakpoint. */
5909 set_std_terminate_breakpoint (void)
5911 struct breakpoint
*b
, *b_tmp
;
5913 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5914 if (b
->pspace
== current_program_space
5915 && b
->type
== bp_std_terminate_master
)
5917 momentary_breakpoint_from_master (b
, bp_std_terminate
,
5918 &momentary_breakpoint_ops
);
5922 /* Delete all the std::terminate breakpoints. */
5924 delete_std_terminate_breakpoint (void)
5926 struct breakpoint
*b
, *b_tmp
;
5928 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5929 if (b
->type
== bp_std_terminate
)
5930 delete_breakpoint (b
);
5934 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5936 struct breakpoint
*b
;
5938 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
5939 &internal_breakpoint_ops
);
5941 b
->enable_state
= bp_enabled
;
5942 /* addr_string has to be used or breakpoint_re_set will delete me. */
5944 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5946 update_global_location_list_nothrow (1);
5952 remove_thread_event_breakpoints (void)
5954 struct breakpoint
*b
, *b_tmp
;
5956 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5957 if (b
->type
== bp_thread_event
5958 && b
->loc
->pspace
== current_program_space
)
5959 delete_breakpoint (b
);
5962 struct lang_and_radix
5968 /* Create a breakpoint for JIT code registration and unregistration. */
5971 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5973 struct breakpoint
*b
;
5975 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
5976 &internal_breakpoint_ops
);
5977 update_global_location_list_nothrow (1);
5981 /* Remove JIT code registration and unregistration breakpoint(s). */
5984 remove_jit_event_breakpoints (void)
5986 struct breakpoint
*b
, *b_tmp
;
5988 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5989 if (b
->type
== bp_jit_event
5990 && b
->loc
->pspace
== current_program_space
)
5991 delete_breakpoint (b
);
5995 remove_solib_event_breakpoints (void)
5997 struct breakpoint
*b
, *b_tmp
;
5999 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6000 if (b
->type
== bp_shlib_event
6001 && b
->loc
->pspace
== current_program_space
)
6002 delete_breakpoint (b
);
6006 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6008 struct breakpoint
*b
;
6010 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6011 &internal_breakpoint_ops
);
6012 update_global_location_list_nothrow (1);
6016 /* Disable any breakpoints that are on code in shared libraries. Only
6017 apply to enabled breakpoints, disabled ones can just stay disabled. */
6020 disable_breakpoints_in_shlibs (void)
6022 struct bp_location
*loc
, **locp_tmp
;
6024 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6026 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6027 struct breakpoint
*b
= loc
->owner
;
6029 /* We apply the check to all breakpoints, including disabled for
6030 those with loc->duplicate set. This is so that when breakpoint
6031 becomes enabled, or the duplicate is removed, gdb will try to
6032 insert all breakpoints. If we don't set shlib_disabled here,
6033 we'll try to insert those breakpoints and fail. */
6034 if (((b
->type
== bp_breakpoint
)
6035 || (b
->type
== bp_jit_event
)
6036 || (b
->type
== bp_hardware_breakpoint
)
6037 || (is_tracepoint (b
)))
6038 && loc
->pspace
== current_program_space
6039 && !loc
->shlib_disabled
6041 && PC_SOLIB (loc
->address
)
6043 && solib_name_from_address (loc
->pspace
, loc
->address
)
6047 loc
->shlib_disabled
= 1;
6052 /* Disable any breakpoints that are in an unloaded shared library.
6053 Only apply to enabled breakpoints, disabled ones can just stay
6057 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6059 struct bp_location
*loc
, **locp_tmp
;
6060 int disabled_shlib_breaks
= 0;
6062 /* SunOS a.out shared libraries are always mapped, so do not
6063 disable breakpoints; they will only be reported as unloaded
6064 through clear_solib when GDB discards its shared library
6065 list. See clear_solib for more information. */
6066 if (exec_bfd
!= NULL
6067 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6070 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6072 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6073 struct breakpoint
*b
= loc
->owner
;
6075 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6076 || loc
->loc_type
== bp_loc_software_breakpoint
)
6077 && solib
->pspace
== loc
->pspace
6078 && !loc
->shlib_disabled
6079 && (b
->type
== bp_breakpoint
6080 || b
->type
== bp_jit_event
6081 || b
->type
== bp_hardware_breakpoint
)
6082 && solib_contains_address_p (solib
, loc
->address
))
6084 loc
->shlib_disabled
= 1;
6085 /* At this point, we cannot rely on remove_breakpoint
6086 succeeding so we must mark the breakpoint as not inserted
6087 to prevent future errors occurring in remove_breakpoints. */
6090 /* This may cause duplicate notifications for the same breakpoint. */
6091 observer_notify_breakpoint_modified (b
);
6093 if (!disabled_shlib_breaks
)
6095 target_terminal_ours_for_output ();
6096 warning (_("Temporarily disabling breakpoints "
6097 "for unloaded shared library \"%s\""),
6100 disabled_shlib_breaks
= 1;
6105 /* FORK & VFORK catchpoints. */
6107 /* An instance of this type is used to represent a fork or vfork
6108 catchpoint. It includes a "struct breakpoint" as a kind of base
6109 class; users downcast to "struct breakpoint *" when needed. A
6110 breakpoint is really of this type iff its ops pointer points to
6111 CATCH_FORK_BREAKPOINT_OPS. */
6113 struct fork_catchpoint
6115 /* The base class. */
6116 struct breakpoint base
;
6118 /* Process id of a child process whose forking triggered this
6119 catchpoint. This field is only valid immediately after this
6120 catchpoint has triggered. */
6121 ptid_t forked_inferior_pid
;
6124 /* Implement the "insert" breakpoint_ops method for fork
6128 insert_catch_fork (struct bp_location
*bl
)
6130 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6133 /* Implement the "remove" breakpoint_ops method for fork
6137 remove_catch_fork (struct bp_location
*bl
)
6139 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6142 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6146 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6147 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6149 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6151 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6154 /* Implement the "print_it" breakpoint_ops method for fork
6157 static enum print_stop_action
6158 print_it_catch_fork (bpstat bs
)
6160 struct breakpoint
*b
= bs
->breakpoint_at
;
6161 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6163 annotate_catchpoint (b
->number
);
6164 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6165 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6166 return PRINT_SRC_AND_LOC
;
6169 /* Implement the "print_one" breakpoint_ops method for fork
6173 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6175 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6176 struct value_print_options opts
;
6177 struct ui_out
*uiout
= current_uiout
;
6179 get_user_print_options (&opts
);
6181 /* Field 4, the address, is omitted (which makes the columns not
6182 line up too nicely with the headers, but the effect is relatively
6184 if (opts
.addressprint
)
6185 ui_out_field_skip (uiout
, "addr");
6187 ui_out_text (uiout
, "fork");
6188 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6190 ui_out_text (uiout
, ", process ");
6191 ui_out_field_int (uiout
, "what",
6192 ptid_get_pid (c
->forked_inferior_pid
));
6193 ui_out_spaces (uiout
, 1);
6197 /* Implement the "print_mention" breakpoint_ops method for fork
6201 print_mention_catch_fork (struct breakpoint
*b
)
6203 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6206 /* Implement the "print_recreate" breakpoint_ops method for fork
6210 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6212 fprintf_unfiltered (fp
, "catch fork");
6213 print_recreate_thread (b
, fp
);
6216 /* The breakpoint_ops structure to be used in fork catchpoints. */
6218 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6220 /* Implement the "insert" breakpoint_ops method for vfork
6224 insert_catch_vfork (struct bp_location
*bl
)
6226 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6229 /* Implement the "remove" breakpoint_ops method for vfork
6233 remove_catch_vfork (struct bp_location
*bl
)
6235 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6238 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6242 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6243 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6245 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6247 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6250 /* Implement the "print_it" breakpoint_ops method for vfork
6253 static enum print_stop_action
6254 print_it_catch_vfork (bpstat bs
)
6256 struct breakpoint
*b
= bs
->breakpoint_at
;
6257 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6259 annotate_catchpoint (b
->number
);
6260 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6261 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6262 return PRINT_SRC_AND_LOC
;
6265 /* Implement the "print_one" breakpoint_ops method for vfork
6269 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6271 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6272 struct value_print_options opts
;
6273 struct ui_out
*uiout
= current_uiout
;
6275 get_user_print_options (&opts
);
6276 /* Field 4, the address, is omitted (which makes the columns not
6277 line up too nicely with the headers, but the effect is relatively
6279 if (opts
.addressprint
)
6280 ui_out_field_skip (uiout
, "addr");
6282 ui_out_text (uiout
, "vfork");
6283 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6285 ui_out_text (uiout
, ", process ");
6286 ui_out_field_int (uiout
, "what",
6287 ptid_get_pid (c
->forked_inferior_pid
));
6288 ui_out_spaces (uiout
, 1);
6292 /* Implement the "print_mention" breakpoint_ops method for vfork
6296 print_mention_catch_vfork (struct breakpoint
*b
)
6298 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6301 /* Implement the "print_recreate" breakpoint_ops method for vfork
6305 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6307 fprintf_unfiltered (fp
, "catch vfork");
6308 print_recreate_thread (b
, fp
);
6311 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6313 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6315 /* An instance of this type is used to represent a syscall catchpoint.
6316 It includes a "struct breakpoint" as a kind of base class; users
6317 downcast to "struct breakpoint *" when needed. A breakpoint is
6318 really of this type iff its ops pointer points to
6319 CATCH_SYSCALL_BREAKPOINT_OPS. */
6321 struct syscall_catchpoint
6323 /* The base class. */
6324 struct breakpoint base
;
6326 /* Syscall numbers used for the 'catch syscall' feature. If no
6327 syscall has been specified for filtering, its value is NULL.
6328 Otherwise, it holds a list of all syscalls to be caught. The
6329 list elements are allocated with xmalloc. */
6330 VEC(int) *syscalls_to_be_caught
;
6333 /* Implement the "dtor" breakpoint_ops method for syscall
6337 dtor_catch_syscall (struct breakpoint
*b
)
6339 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6341 VEC_free (int, c
->syscalls_to_be_caught
);
6343 base_breakpoint_ops
.dtor (b
);
6346 /* Implement the "insert" breakpoint_ops method for syscall
6350 insert_catch_syscall (struct bp_location
*bl
)
6352 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6353 struct inferior
*inf
= current_inferior ();
6355 ++inf
->total_syscalls_count
;
6356 if (!c
->syscalls_to_be_caught
)
6357 ++inf
->any_syscall_count
;
6363 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6368 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6370 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6371 uintptr_t vec_addr_offset
6372 = old_size
* ((uintptr_t) sizeof (int));
6374 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6375 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6377 memset ((void *) vec_addr
, 0,
6378 (iter
+ 1 - old_size
) * sizeof (int));
6380 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6381 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6385 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6386 inf
->total_syscalls_count
!= 0,
6387 inf
->any_syscall_count
,
6388 VEC_length (int, inf
->syscalls_counts
),
6389 VEC_address (int, inf
->syscalls_counts
));
6392 /* Implement the "remove" breakpoint_ops method for syscall
6396 remove_catch_syscall (struct bp_location
*bl
)
6398 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6399 struct inferior
*inf
= current_inferior ();
6401 --inf
->total_syscalls_count
;
6402 if (!c
->syscalls_to_be_caught
)
6403 --inf
->any_syscall_count
;
6409 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6413 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6414 /* Shouldn't happen. */
6416 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6417 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6421 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6422 inf
->total_syscalls_count
!= 0,
6423 inf
->any_syscall_count
,
6424 VEC_length (int, inf
->syscalls_counts
),
6426 inf
->syscalls_counts
));
6429 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6433 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6434 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6436 /* We must check if we are catching specific syscalls in this
6437 breakpoint. If we are, then we must guarantee that the called
6438 syscall is the same syscall we are catching. */
6439 int syscall_number
= 0;
6440 const struct syscall_catchpoint
*c
6441 = (const struct syscall_catchpoint
*) bl
->owner
;
6443 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6446 /* Now, checking if the syscall is the same. */
6447 if (c
->syscalls_to_be_caught
)
6452 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6454 if (syscall_number
== iter
)
6464 /* Implement the "print_it" breakpoint_ops method for syscall
6467 static enum print_stop_action
6468 print_it_catch_syscall (bpstat bs
)
6470 struct breakpoint
*b
= bs
->breakpoint_at
;
6471 /* These are needed because we want to know in which state a
6472 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6473 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6474 must print "called syscall" or "returned from syscall". */
6476 struct target_waitstatus last
;
6478 struct cleanup
*old_chain
;
6481 get_last_target_status (&ptid
, &last
);
6483 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6485 annotate_catchpoint (b
->number
);
6488 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6490 syscall_id
= xstrprintf ("'%s'", s
.name
);
6492 old_chain
= make_cleanup (xfree
, syscall_id
);
6494 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6495 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6496 b
->number
, syscall_id
);
6497 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6498 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6499 b
->number
, syscall_id
);
6501 do_cleanups (old_chain
);
6503 return PRINT_SRC_AND_LOC
;
6506 /* Implement the "print_one" breakpoint_ops method for syscall
6510 print_one_catch_syscall (struct breakpoint
*b
,
6511 struct bp_location
**last_loc
)
6513 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6514 struct value_print_options opts
;
6515 struct ui_out
*uiout
= current_uiout
;
6517 get_user_print_options (&opts
);
6518 /* Field 4, the address, is omitted (which makes the columns not
6519 line up too nicely with the headers, but the effect is relatively
6521 if (opts
.addressprint
)
6522 ui_out_field_skip (uiout
, "addr");
6525 if (c
->syscalls_to_be_caught
6526 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6527 ui_out_text (uiout
, "syscalls \"");
6529 ui_out_text (uiout
, "syscall \"");
6531 if (c
->syscalls_to_be_caught
)
6534 char *text
= xstrprintf ("%s", "");
6537 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6542 get_syscall_by_number (iter
, &s
);
6545 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6547 text
= xstrprintf ("%s%d, ", text
, iter
);
6549 /* We have to xfree the last 'text' (now stored at 'x')
6550 because xstrprintf dynamically allocates new space for it
6554 /* Remove the last comma. */
6555 text
[strlen (text
) - 2] = '\0';
6556 ui_out_field_string (uiout
, "what", text
);
6559 ui_out_field_string (uiout
, "what", "<any syscall>");
6560 ui_out_text (uiout
, "\" ");
6563 /* Implement the "print_mention" breakpoint_ops method for syscall
6567 print_mention_catch_syscall (struct breakpoint
*b
)
6569 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6571 if (c
->syscalls_to_be_caught
)
6575 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6576 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6578 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6581 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6585 get_syscall_by_number (iter
, &s
);
6588 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6590 printf_filtered (" %d", s
.number
);
6592 printf_filtered (")");
6595 printf_filtered (_("Catchpoint %d (any syscall)"),
6599 /* Implement the "print_recreate" breakpoint_ops method for syscall
6603 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6605 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6607 fprintf_unfiltered (fp
, "catch syscall");
6609 if (c
->syscalls_to_be_caught
)
6614 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6619 get_syscall_by_number (iter
, &s
);
6621 fprintf_unfiltered (fp
, " %s", s
.name
);
6623 fprintf_unfiltered (fp
, " %d", s
.number
);
6626 print_recreate_thread (b
, fp
);
6629 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6631 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6633 /* Returns non-zero if 'b' is a syscall catchpoint. */
6636 syscall_catchpoint_p (struct breakpoint
*b
)
6638 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6641 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6642 is non-zero, then make the breakpoint temporary. If COND_STRING is
6643 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6644 the breakpoint_ops structure associated to the catchpoint. */
6647 init_catchpoint (struct breakpoint
*b
,
6648 struct gdbarch
*gdbarch
, int tempflag
,
6650 const struct breakpoint_ops
*ops
)
6652 struct symtab_and_line sal
;
6655 sal
.pspace
= current_program_space
;
6657 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6659 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6660 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6664 install_breakpoint (int internal
, struct breakpoint
*b
)
6666 add_to_breakpoint_chain (b
);
6667 set_breakpoint_number (internal
, b
);
6670 observer_notify_breakpoint_created (b
);
6671 update_global_location_list (1);
6675 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6676 int tempflag
, char *cond_string
,
6677 const struct breakpoint_ops
*ops
)
6679 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6681 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6683 c
->forked_inferior_pid
= null_ptid
;
6685 install_breakpoint (0, &c
->base
);
6688 /* Exec catchpoints. */
6690 /* An instance of this type is used to represent an exec catchpoint.
6691 It includes a "struct breakpoint" as a kind of base class; users
6692 downcast to "struct breakpoint *" when needed. A breakpoint is
6693 really of this type iff its ops pointer points to
6694 CATCH_EXEC_BREAKPOINT_OPS. */
6696 struct exec_catchpoint
6698 /* The base class. */
6699 struct breakpoint base
;
6701 /* Filename of a program whose exec triggered this catchpoint.
6702 This field is only valid immediately after this catchpoint has
6704 char *exec_pathname
;
6707 /* Implement the "dtor" breakpoint_ops method for exec
6711 dtor_catch_exec (struct breakpoint
*b
)
6713 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6715 xfree (c
->exec_pathname
);
6717 base_breakpoint_ops
.dtor (b
);
6721 insert_catch_exec (struct bp_location
*bl
)
6723 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6727 remove_catch_exec (struct bp_location
*bl
)
6729 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6733 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6734 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6736 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6738 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6741 static enum print_stop_action
6742 print_it_catch_exec (bpstat bs
)
6744 struct breakpoint
*b
= bs
->breakpoint_at
;
6745 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6747 annotate_catchpoint (b
->number
);
6748 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6750 return PRINT_SRC_AND_LOC
;
6754 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6756 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6757 struct value_print_options opts
;
6758 struct ui_out
*uiout
= current_uiout
;
6760 get_user_print_options (&opts
);
6762 /* Field 4, the address, is omitted (which makes the columns
6763 not line up too nicely with the headers, but the effect
6764 is relatively readable). */
6765 if (opts
.addressprint
)
6766 ui_out_field_skip (uiout
, "addr");
6768 ui_out_text (uiout
, "exec");
6769 if (c
->exec_pathname
!= NULL
)
6771 ui_out_text (uiout
, ", program \"");
6772 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6773 ui_out_text (uiout
, "\" ");
6778 print_mention_catch_exec (struct breakpoint
*b
)
6780 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6783 /* Implement the "print_recreate" breakpoint_ops method for exec
6787 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6789 fprintf_unfiltered (fp
, "catch exec");
6790 print_recreate_thread (b
, fp
);
6793 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6796 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6797 const struct breakpoint_ops
*ops
)
6799 struct syscall_catchpoint
*c
;
6800 struct gdbarch
*gdbarch
= get_current_arch ();
6802 c
= XNEW (struct syscall_catchpoint
);
6803 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6804 c
->syscalls_to_be_caught
= filter
;
6806 install_breakpoint (0, &c
->base
);
6810 hw_breakpoint_used_count (void)
6813 struct breakpoint
*b
;
6814 struct bp_location
*bl
;
6818 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6819 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6821 /* Special types of hardware breakpoints may use more than
6823 i
+= b
->ops
->resources_needed (bl
);
6831 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6834 struct breakpoint
*b
;
6835 struct bp_location
*bl
;
6837 *other_type_used
= 0;
6840 if (!breakpoint_enabled (b
))
6843 if (b
->type
== type
)
6844 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6846 /* Special types of hardware watchpoints may use more than
6848 i
+= b
->ops
->resources_needed (bl
);
6850 else if (is_hardware_watchpoint (b
))
6851 *other_type_used
= 1;
6858 disable_watchpoints_before_interactive_call_start (void)
6860 struct breakpoint
*b
;
6864 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6866 b
->enable_state
= bp_call_disabled
;
6867 update_global_location_list (0);
6873 enable_watchpoints_after_interactive_call_stop (void)
6875 struct breakpoint
*b
;
6879 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6881 b
->enable_state
= bp_enabled
;
6882 update_global_location_list (1);
6888 disable_breakpoints_before_startup (void)
6890 struct breakpoint
*b
;
6895 if (b
->pspace
!= current_program_space
)
6898 if ((b
->type
== bp_breakpoint
6899 || b
->type
== bp_hardware_breakpoint
)
6900 && breakpoint_enabled (b
))
6902 b
->enable_state
= bp_startup_disabled
;
6908 update_global_location_list (0);
6910 current_program_space
->executing_startup
= 1;
6914 enable_breakpoints_after_startup (void)
6916 struct breakpoint
*b
;
6919 current_program_space
->executing_startup
= 0;
6923 if (b
->pspace
!= current_program_space
)
6926 if ((b
->type
== bp_breakpoint
6927 || b
->type
== bp_hardware_breakpoint
)
6928 && b
->enable_state
== bp_startup_disabled
)
6930 b
->enable_state
= bp_enabled
;
6936 breakpoint_re_set ();
6940 /* Set a breakpoint that will evaporate an end of command
6941 at address specified by SAL.
6942 Restrict it to frame FRAME if FRAME is nonzero. */
6945 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6946 struct frame_id frame_id
, enum bptype type
)
6948 struct breakpoint
*b
;
6950 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6952 gdb_assert (!frame_id_inlined_p (frame_id
));
6954 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
6955 b
->enable_state
= bp_enabled
;
6956 b
->disposition
= disp_donttouch
;
6957 b
->frame_id
= frame_id
;
6959 /* If we're debugging a multi-threaded program, then we want
6960 momentary breakpoints to be active in only a single thread of
6962 if (in_thread_list (inferior_ptid
))
6963 b
->thread
= pid_to_thread_id (inferior_ptid
);
6965 update_global_location_list_nothrow (1);
6970 /* Make a momentary breakpoint based on the master breakpoint ORIG.
6971 The new breakpoint will have type TYPE, and use OPS as it
6974 static struct breakpoint
*
6975 momentary_breakpoint_from_master (struct breakpoint
*orig
,
6977 const struct breakpoint_ops
*ops
)
6979 struct breakpoint
*copy
;
6981 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
6982 copy
->loc
= allocate_bp_location (copy
);
6983 set_breakpoint_location_function (copy
->loc
, 1);
6985 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6986 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6987 copy
->loc
->address
= orig
->loc
->address
;
6988 copy
->loc
->section
= orig
->loc
->section
;
6989 copy
->loc
->pspace
= orig
->loc
->pspace
;
6991 if (orig
->source_file
== NULL
)
6992 copy
->source_file
= NULL
;
6994 copy
->source_file
= xstrdup (orig
->source_file
);
6996 copy
->line_number
= orig
->line_number
;
6997 copy
->frame_id
= orig
->frame_id
;
6998 copy
->thread
= orig
->thread
;
6999 copy
->pspace
= orig
->pspace
;
7001 copy
->enable_state
= bp_enabled
;
7002 copy
->disposition
= disp_donttouch
;
7003 copy
->number
= internal_breakpoint_number
--;
7005 update_global_location_list_nothrow (0);
7009 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7013 clone_momentary_breakpoint (struct breakpoint
*orig
)
7015 /* If there's nothing to clone, then return nothing. */
7019 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
7023 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7026 struct symtab_and_line sal
;
7028 sal
= find_pc_line (pc
, 0);
7030 sal
.section
= find_pc_overlay (pc
);
7031 sal
.explicit_pc
= 1;
7033 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7037 /* Tell the user we have just set a breakpoint B. */
7040 mention (struct breakpoint
*b
)
7042 b
->ops
->print_mention (b
);
7043 if (ui_out_is_mi_like_p (current_uiout
))
7045 printf_filtered ("\n");
7049 static struct bp_location
*
7050 add_location_to_breakpoint (struct breakpoint
*b
,
7051 const struct symtab_and_line
*sal
)
7053 struct bp_location
*loc
, **tmp
;
7055 loc
= allocate_bp_location (b
);
7056 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7059 loc
->gdbarch
= get_sal_arch (*sal
);
7061 loc
->gdbarch
= b
->gdbarch
;
7062 loc
->requested_address
= sal
->pc
;
7063 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7064 loc
->requested_address
, b
->type
);
7065 loc
->pspace
= sal
->pspace
;
7066 gdb_assert (loc
->pspace
!= NULL
);
7067 loc
->section
= sal
->section
;
7069 set_breakpoint_location_function (loc
,
7070 sal
->explicit_pc
|| sal
->explicit_line
);
7075 /* Return 1 if LOC is pointing to a permanent breakpoint,
7076 return 0 otherwise. */
7079 bp_loc_is_permanent (struct bp_location
*loc
)
7083 const gdb_byte
*brk
;
7084 gdb_byte
*target_mem
;
7085 struct cleanup
*cleanup
;
7088 gdb_assert (loc
!= NULL
);
7090 addr
= loc
->address
;
7091 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7093 /* Software breakpoints unsupported? */
7097 target_mem
= alloca (len
);
7099 /* Enable the automatic memory restoration from breakpoints while
7100 we read the memory. Otherwise we could say about our temporary
7101 breakpoints they are permanent. */
7102 cleanup
= save_current_space_and_thread ();
7104 switch_to_program_space_and_thread (loc
->pspace
);
7105 make_show_memory_breakpoints_cleanup (0);
7107 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7108 && memcmp (target_mem
, brk
, len
) == 0)
7111 do_cleanups (cleanup
);
7118 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7119 as textual description of the location, and COND_STRING
7120 as condition expression. */
7123 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7124 struct symtabs_and_lines sals
, char *addr_string
,
7126 enum bptype type
, enum bpdisp disposition
,
7127 int thread
, int task
, int ignore_count
,
7128 const struct breakpoint_ops
*ops
, int from_tty
,
7129 int enabled
, int internal
, int display_canonical
)
7133 if (type
== bp_hardware_breakpoint
)
7135 int i
= hw_breakpoint_used_count ();
7136 int target_resources_ok
=
7137 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7139 if (target_resources_ok
== 0)
7140 error (_("No hardware breakpoint support in the target."));
7141 else if (target_resources_ok
< 0)
7142 error (_("Hardware breakpoints used exceeds limit."));
7145 gdb_assert (sals
.nelts
> 0);
7147 for (i
= 0; i
< sals
.nelts
; ++i
)
7149 struct symtab_and_line sal
= sals
.sals
[i
];
7150 struct bp_location
*loc
;
7154 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7156 loc_gdbarch
= gdbarch
;
7158 describe_other_breakpoints (loc_gdbarch
,
7159 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7164 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7168 b
->cond_string
= cond_string
;
7169 b
->ignore_count
= ignore_count
;
7170 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7171 b
->disposition
= disposition
;
7172 b
->pspace
= sals
.sals
[0].pspace
;
7174 if (type
== bp_static_tracepoint
)
7176 struct tracepoint
*t
= (struct tracepoint
*) b
;
7177 struct static_tracepoint_marker marker
;
7179 if (is_marker_spec (addr_string
))
7181 /* We already know the marker exists, otherwise, we
7182 wouldn't see a sal for it. */
7183 char *p
= &addr_string
[3];
7188 p
= skip_spaces (p
);
7190 endp
= skip_to_space (p
);
7192 marker_str
= savestring (p
, endp
- p
);
7193 t
->static_trace_marker_id
= marker_str
;
7195 printf_filtered (_("Probed static tracepoint "
7197 t
->static_trace_marker_id
);
7199 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7201 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7202 release_static_tracepoint_marker (&marker
);
7204 printf_filtered (_("Probed static tracepoint "
7206 t
->static_trace_marker_id
);
7209 warning (_("Couldn't determine the static "
7210 "tracepoint marker to probe"));
7213 if (enabled
&& b
->pspace
->executing_startup
7214 && (b
->type
== bp_breakpoint
7215 || b
->type
== bp_hardware_breakpoint
))
7216 b
->enable_state
= bp_startup_disabled
;
7222 loc
= add_location_to_breakpoint (b
, &sal
);
7225 if (bp_loc_is_permanent (loc
))
7226 make_breakpoint_permanent (b
);
7230 char *arg
= b
->cond_string
;
7231 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7233 error (_("Garbage %s follows condition"), arg
);
7237 b
->display_canonical
= display_canonical
;
7239 b
->addr_string
= addr_string
;
7241 /* addr_string has to be used or breakpoint_re_set will delete
7244 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7248 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7249 struct symtabs_and_lines sals
, char *addr_string
,
7251 enum bptype type
, enum bpdisp disposition
,
7252 int thread
, int task
, int ignore_count
,
7253 const struct breakpoint_ops
*ops
, int from_tty
,
7254 int enabled
, int internal
, int display_canonical
)
7256 struct breakpoint
*b
;
7257 struct cleanup
*old_chain
;
7259 if (is_tracepoint_type (type
))
7261 struct tracepoint
*t
;
7263 t
= XCNEW (struct tracepoint
);
7267 b
= XNEW (struct breakpoint
);
7269 old_chain
= make_cleanup (xfree
, b
);
7271 init_breakpoint_sal (b
, gdbarch
,
7275 thread
, task
, ignore_count
,
7277 enabled
, internal
, display_canonical
);
7278 discard_cleanups (old_chain
);
7280 install_breakpoint (internal
, b
);
7283 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7284 elements to fill the void space. */
7286 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7288 int i
= index_to_remove
+1;
7289 int last_index
= sal
->nelts
-1;
7291 for (;i
<= last_index
; ++i
)
7292 sal
->sals
[i
-1] = sal
->sals
[i
];
7297 /* If appropriate, obtains all sals that correspond to the same file
7298 and line as SAL, in all program spaces. Users debugging with IDEs,
7299 will want to set a breakpoint at foo.c:line, and not really care
7300 about program spaces. This is done only if SAL does not have
7301 explicit PC and has line and file information. If we got just a
7302 single expanded sal, return the original.
7304 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7305 which the name of enclosing function is different from SAL. This
7306 makes sure that if we have breakpoint originally set in template
7307 instantiation, say foo<int>(), we won't expand SAL to locations at
7308 the same line in all existing instantiations of 'foo'. */
7310 static struct symtabs_and_lines
7311 expand_line_sal_maybe (struct symtab_and_line sal
)
7313 struct symtabs_and_lines expanded
;
7314 CORE_ADDR original_pc
= sal
.pc
;
7315 char *original_function
= NULL
;
7318 struct cleanup
*old_chain
;
7320 /* If we have explicit pc, don't expand.
7321 If we have no line number, we can't expand. */
7322 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7325 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7326 expanded
.sals
[0] = sal
;
7332 old_chain
= save_current_space_and_thread ();
7334 switch_to_program_space_and_thread (sal
.pspace
);
7336 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7338 /* Note that expand_line_sal visits *all* program spaces. */
7339 expanded
= expand_line_sal (sal
);
7341 if (expanded
.nelts
== 1)
7343 /* We had one sal, we got one sal. Return that sal, adjusting it
7344 past the function prologue if necessary. */
7345 xfree (expanded
.sals
);
7347 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7348 sal
.pc
= original_pc
;
7349 expanded
.sals
[0] = sal
;
7350 skip_prologue_sal (&expanded
.sals
[0]);
7351 do_cleanups (old_chain
);
7355 if (!sal
.explicit_line
)
7357 CORE_ADDR func_addr
, func_end
;
7358 for (i
= 0; i
< expanded
.nelts
; ++i
)
7360 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7361 char *this_function
;
7363 /* We need to switch threads as well since we're about to
7365 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7367 if (find_pc_partial_function (pc
, &this_function
,
7368 &func_addr
, &func_end
))
7371 && strcmp (this_function
, original_function
) != 0)
7373 remove_sal (&expanded
, i
);
7380 /* Skip the function prologue if necessary. */
7381 for (i
= 0; i
< expanded
.nelts
; ++i
)
7382 skip_prologue_sal (&expanded
.sals
[i
]);
7384 do_cleanups (old_chain
);
7386 if (expanded
.nelts
<= 1)
7388 /* This is an ugly workaround. If we get zero expanded sals
7389 then something is really wrong. Fix that by returning the
7392 xfree (expanded
.sals
);
7394 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7395 sal
.pc
= original_pc
;
7396 expanded
.sals
[0] = sal
;
7403 for (i
= 0; i
< expanded
.nelts
; ++i
)
7404 if (expanded
.sals
[i
].pc
== original_pc
)
7415 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7416 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7417 value. COND_STRING, if not NULL, specified the condition to be
7418 used for all breakpoints. Essentially the only case where
7419 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7420 function. In that case, it's still not possible to specify
7421 separate conditions for different overloaded functions, so
7422 we take just a single condition string.
7424 NOTE: If the function succeeds, the caller is expected to cleanup
7425 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7426 array contents). If the function fails (error() is called), the
7427 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7428 COND and SALS arrays and each of those arrays contents. */
7431 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7432 struct symtabs_and_lines sals
,
7433 struct linespec_result
*canonical
,
7435 enum bptype type
, enum bpdisp disposition
,
7436 int thread
, int task
, int ignore_count
,
7437 const struct breakpoint_ops
*ops
, int from_tty
,
7438 int enabled
, int internal
)
7442 for (i
= 0; i
< sals
.nelts
; ++i
)
7444 struct symtabs_and_lines expanded
=
7445 expand_line_sal_maybe (sals
.sals
[i
]);
7447 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7448 cond_string
, type
, disposition
,
7449 thread
, task
, ignore_count
, ops
,
7450 from_tty
, enabled
, internal
,
7451 canonical
->special_display
);
7455 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7456 followed by conditionals. On return, SALS contains an array of SAL
7457 addresses found. ADDR_STRING contains a vector of (canonical)
7458 address strings. ADDRESS points to the end of the SAL.
7460 The array and the line spec strings are allocated on the heap, it is
7461 the caller's responsibility to free them. */
7464 parse_breakpoint_sals (char **address
,
7465 struct symtabs_and_lines
*sals
,
7466 struct linespec_result
*canonical
)
7468 char *addr_start
= *address
;
7470 /* If no arg given, or if first arg is 'if ', use the default
7472 if ((*address
) == NULL
7473 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7475 if (default_breakpoint_valid
)
7477 struct symtab_and_line sal
;
7479 init_sal (&sal
); /* Initialize to zeroes. */
7480 sals
->sals
= (struct symtab_and_line
*)
7481 xmalloc (sizeof (struct symtab_and_line
));
7482 sal
.pc
= default_breakpoint_address
;
7483 sal
.line
= default_breakpoint_line
;
7484 sal
.symtab
= default_breakpoint_symtab
;
7485 sal
.pspace
= default_breakpoint_pspace
;
7486 sal
.section
= find_pc_overlay (sal
.pc
);
7488 /* "break" without arguments is equivalent to "break *PC"
7489 where PC is the default_breakpoint_address. So make sure
7490 to set sal.explicit_pc to prevent GDB from trying to
7491 expand the list of sals to include all other instances
7492 with the same symtab and line. */
7493 sal
.explicit_pc
= 1;
7495 sals
->sals
[0] = sal
;
7499 error (_("No default breakpoint address now."));
7503 /* Force almost all breakpoints to be in terms of the
7504 current_source_symtab (which is decode_line_1's default).
7505 This should produce the results we want almost all of the
7506 time while leaving default_breakpoint_* alone.
7508 ObjC: However, don't match an Objective-C method name which
7509 may have a '+' or '-' succeeded by a '[' */
7511 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7513 if (default_breakpoint_valid
7515 || ((strchr ("+-", (*address
)[0]) != NULL
)
7516 && ((*address
)[1] != '['))))
7517 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7518 default_breakpoint_line
, canonical
);
7520 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7523 /* For any SAL that didn't have a canonical string, fill one in. */
7524 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7525 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7526 if (addr_start
!= (*address
))
7530 for (i
= 0; i
< sals
->nelts
; i
++)
7532 /* Add the string if not present. */
7533 if (canonical
->canonical
[i
] == NULL
)
7534 canonical
->canonical
[i
] = savestring (addr_start
,
7535 (*address
) - addr_start
);
7541 /* Convert each SAL into a real PC. Verify that the PC can be
7542 inserted as a breakpoint. If it can't throw an error. */
7545 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7549 for (i
= 0; i
< sals
->nelts
; i
++)
7550 resolve_sal_pc (&sals
->sals
[i
]);
7553 /* Fast tracepoints may have restrictions on valid locations. For
7554 instance, a fast tracepoint using a jump instead of a trap will
7555 likely have to overwrite more bytes than a trap would, and so can
7556 only be placed where the instruction is longer than the jump, or a
7557 multi-instruction sequence does not have a jump into the middle of
7561 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7562 struct symtabs_and_lines
*sals
)
7565 struct symtab_and_line
*sal
;
7567 struct cleanup
*old_chain
;
7569 for (i
= 0; i
< sals
->nelts
; i
++)
7571 sal
= &sals
->sals
[i
];
7573 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7575 old_chain
= make_cleanup (xfree
, msg
);
7578 error (_("May not have a fast tracepoint at 0x%s%s"),
7579 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7581 do_cleanups (old_chain
);
7585 /* Given TOK, a string specification of condition and thread, as
7586 accepted by the 'break' command, extract the condition
7587 string and thread number and set *COND_STRING and *THREAD.
7588 PC identifies the context at which the condition should be parsed.
7589 If no condition is found, *COND_STRING is set to NULL.
7590 If no thread is found, *THREAD is set to -1. */
7592 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7593 char **cond_string
, int *thread
, int *task
)
7595 *cond_string
= NULL
;
7601 char *cond_start
= NULL
;
7602 char *cond_end
= NULL
;
7604 tok
= skip_spaces (tok
);
7606 end_tok
= skip_to_space (tok
);
7608 toklen
= end_tok
- tok
;
7610 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7612 struct expression
*expr
;
7614 tok
= cond_start
= end_tok
+ 1;
7615 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7618 *cond_string
= savestring (cond_start
,
7619 cond_end
- cond_start
);
7621 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7627 *thread
= strtol (tok
, &tok
, 0);
7629 error (_("Junk after thread keyword."));
7630 if (!valid_thread_id (*thread
))
7631 error (_("Unknown thread %d."), *thread
);
7633 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7639 *task
= strtol (tok
, &tok
, 0);
7641 error (_("Junk after task keyword."));
7642 if (!valid_task_id (*task
))
7643 error (_("Unknown task %d."), *task
);
7646 error (_("Junk at end of arguments."));
7650 /* Decode a static tracepoint marker spec. */
7652 static struct symtabs_and_lines
7653 decode_static_tracepoint_spec (char **arg_p
)
7655 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7656 struct symtabs_and_lines sals
;
7657 struct symtab_and_line sal
;
7659 struct cleanup
*old_chain
;
7660 char *p
= &(*arg_p
)[3];
7665 p
= skip_spaces (p
);
7667 endp
= skip_to_space (p
);
7669 marker_str
= savestring (p
, endp
- p
);
7670 old_chain
= make_cleanup (xfree
, marker_str
);
7672 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7673 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7674 error (_("No known static tracepoint marker named %s"), marker_str
);
7676 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7677 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7679 for (i
= 0; i
< sals
.nelts
; i
++)
7681 struct static_tracepoint_marker
*marker
;
7683 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7685 init_sal (&sals
.sals
[i
]);
7687 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7688 sals
.sals
[i
].pc
= marker
->address
;
7690 release_static_tracepoint_marker (marker
);
7693 do_cleanups (old_chain
);
7699 /* Set a breakpoint. This function is shared between CLI and MI
7700 functions for setting a breakpoint. This function has two major
7701 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7702 parameter. If non-zero, the function will parse arg, extracting
7703 breakpoint location, address and thread. Otherwise, ARG is just
7704 the location of breakpoint, with condition and thread specified by
7705 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7706 the breakpoint number will be allocated from the internal
7707 breakpoint count. Returns true if any breakpoint was created;
7711 create_breakpoint (struct gdbarch
*gdbarch
,
7712 char *arg
, char *cond_string
, int thread
,
7713 int parse_condition_and_thread
,
7714 int tempflag
, enum bptype type_wanted
,
7716 enum auto_boolean pending_break_support
,
7717 const struct breakpoint_ops
*ops
,
7718 int from_tty
, int enabled
, int internal
)
7720 volatile struct gdb_exception e
;
7721 struct symtabs_and_lines sals
;
7722 struct symtab_and_line pending_sal
;
7724 char *addr_start
= arg
;
7725 struct linespec_result canonical
;
7726 struct cleanup
*old_chain
;
7727 struct cleanup
*bkpt_chain
= NULL
;
7731 int prev_bkpt_count
= breakpoint_count
;
7733 gdb_assert (ops
!= NULL
);
7737 init_linespec_result (&canonical
);
7739 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7743 sals
= decode_static_tracepoint_spec (&arg
);
7745 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7746 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7747 for (i
= 0; i
< sals
.nelts
; i
++)
7748 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7752 TRY_CATCH (e
, RETURN_MASK_ALL
)
7754 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7757 /* If caller is interested in rc value from parse, set value. */
7761 throw_exception (e
);
7765 case NOT_FOUND_ERROR
:
7767 /* If pending breakpoint support is turned off, throw
7770 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7771 throw_exception (e
);
7773 exception_print (gdb_stderr
, e
);
7775 /* If pending breakpoint support is auto query and the user
7776 selects no, then simply return the error code. */
7777 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7778 && !nquery (_("Make breakpoint pending on "
7779 "future shared library load? ")))
7782 /* At this point, either the user was queried about setting
7783 a pending breakpoint and selected yes, or pending
7784 breakpoint behavior is on and thus a pending breakpoint
7785 is defaulted on behalf of the user. */
7786 copy_arg
= xstrdup (addr_start
);
7787 canonical
.canonical
= ©_arg
;
7789 sals
.sals
= &pending_sal
;
7794 throw_exception (e
);
7804 /* Create a chain of things that always need to be cleaned up. */
7805 old_chain
= make_cleanup (null_cleanup
, 0);
7809 /* Make sure that all storage allocated to SALS gets freed. */
7810 make_cleanup (xfree
, sals
.sals
);
7812 /* Cleanup the canonical array but not its contents. */
7813 make_cleanup (xfree
, canonical
.canonical
);
7816 /* ----------------------------- SNIP -----------------------------
7817 Anything added to the cleanup chain beyond this point is assumed
7818 to be part of a breakpoint. If the breakpoint create succeeds
7819 then the memory is not reclaimed. */
7820 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7822 /* Mark the contents of the canonical for cleanup. These go on
7823 the bkpt_chain and only occur if the breakpoint create fails. */
7824 for (i
= 0; i
< sals
.nelts
; i
++)
7826 if (canonical
.canonical
[i
] != NULL
)
7827 make_cleanup (xfree
, canonical
.canonical
[i
]);
7830 /* Resolve all line numbers to PC's and verify that the addresses
7831 are ok for the target. */
7833 breakpoint_sals_to_pc (&sals
);
7835 /* Fast tracepoints may have additional restrictions on location. */
7836 if (type_wanted
== bp_fast_tracepoint
)
7837 check_fast_tracepoint_sals (gdbarch
, &sals
);
7839 /* Verify that condition can be parsed, before setting any
7840 breakpoints. Allocate a separate condition expression for each
7844 if (parse_condition_and_thread
)
7846 /* Here we only parse 'arg' to separate condition
7847 from thread number, so parsing in context of first
7848 sal is OK. When setting the breakpoint we'll
7849 re-parse it in context of each sal. */
7852 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7855 make_cleanup (xfree
, cond_string
);
7859 /* Create a private copy of condition string. */
7862 cond_string
= xstrdup (cond_string
);
7863 make_cleanup (xfree
, cond_string
);
7867 /* If the user is creating a static tracepoint by marker id
7868 (strace -m MARKER_ID), then store the sals index, so that
7869 breakpoint_re_set can try to match up which of the newly
7870 found markers corresponds to this one, and, don't try to
7871 expand multiple locations for each sal, given than SALS
7872 already should contain all sals for MARKER_ID. */
7873 if (type_wanted
== bp_static_tracepoint
7874 && is_marker_spec (canonical
.canonical
[0]))
7878 for (i
= 0; i
< sals
.nelts
; ++i
)
7880 struct symtabs_and_lines expanded
;
7881 struct tracepoint
*tp
;
7882 struct cleanup
*old_chain
;
7885 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7886 expanded
.sals
[0] = sals
.sals
[i
];
7887 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7889 tp
= XCNEW (struct tracepoint
);
7890 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
7891 canonical
.canonical
[i
],
7892 cond_string
, type_wanted
,
7893 tempflag
? disp_del
: disp_donttouch
,
7894 thread
, task
, ignore_count
, ops
,
7895 from_tty
, enabled
, internal
,
7896 canonical
.special_display
);
7897 /* Given that its possible to have multiple markers with
7898 the same string id, if the user is creating a static
7899 tracepoint by marker id ("strace -m MARKER_ID"), then
7900 store the sals index, so that breakpoint_re_set can
7901 try to match up which of the newly found markers
7902 corresponds to this one */
7903 tp
->static_trace_marker_id_idx
= i
;
7905 install_breakpoint (internal
, &tp
->base
);
7907 do_cleanups (old_chain
);
7911 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
7913 tempflag
? disp_del
: disp_donttouch
,
7914 thread
, task
, ignore_count
, ops
, from_tty
,
7919 struct breakpoint
*b
;
7921 make_cleanup (xfree
, copy_arg
);
7923 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
, ops
);
7924 set_breakpoint_number (internal
, b
);
7926 b
->addr_string
= canonical
.canonical
[0];
7927 b
->cond_string
= NULL
;
7928 b
->ignore_count
= ignore_count
;
7929 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7930 b
->condition_not_parsed
= 1;
7931 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7932 b
->pspace
= current_program_space
;
7933 b
->py_bp_object
= NULL
;
7935 if (enabled
&& b
->pspace
->executing_startup
7936 && (b
->type
== bp_breakpoint
7937 || b
->type
== bp_hardware_breakpoint
))
7938 b
->enable_state
= bp_startup_disabled
;
7941 /* Do not mention breakpoints with a negative number,
7942 but do notify observers. */
7944 observer_notify_breakpoint_created (b
);
7949 warning (_("Multiple breakpoints were set.\nUse the "
7950 "\"delete\" command to delete unwanted breakpoints."));
7951 prev_breakpoint_count
= prev_bkpt_count
;
7954 /* That's it. Discard the cleanups for data inserted into the
7956 discard_cleanups (bkpt_chain
);
7957 /* But cleanup everything else. */
7958 do_cleanups (old_chain
);
7960 /* error call may happen here - have BKPT_CHAIN already discarded. */
7961 update_global_location_list (1);
7966 /* Set a breakpoint.
7967 ARG is a string describing breakpoint address,
7968 condition, and thread.
7969 FLAG specifies if a breakpoint is hardware on,
7970 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7974 break_command_1 (char *arg
, int flag
, int from_tty
)
7976 int tempflag
= flag
& BP_TEMPFLAG
;
7977 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7978 ? bp_hardware_breakpoint
7981 create_breakpoint (get_current_arch (),
7983 NULL
, 0, 1 /* parse arg */,
7984 tempflag
, type_wanted
,
7985 0 /* Ignore count */,
7986 pending_break_support
,
7987 &bkpt_breakpoint_ops
,
7993 /* Helper function for break_command_1 and disassemble_command. */
7996 resolve_sal_pc (struct symtab_and_line
*sal
)
8000 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8002 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8003 error (_("No line %d in file \"%s\"."),
8004 sal
->line
, sal
->symtab
->filename
);
8007 /* If this SAL corresponds to a breakpoint inserted using a line
8008 number, then skip the function prologue if necessary. */
8009 if (sal
->explicit_line
)
8010 skip_prologue_sal (sal
);
8013 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8015 struct blockvector
*bv
;
8019 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8022 sym
= block_linkage_function (b
);
8025 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8026 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8030 /* It really is worthwhile to have the section, so we'll
8031 just have to look harder. This case can be executed
8032 if we have line numbers but no functions (as can
8033 happen in assembly source). */
8035 struct minimal_symbol
*msym
;
8036 struct cleanup
*old_chain
= save_current_space_and_thread ();
8038 switch_to_program_space_and_thread (sal
->pspace
);
8040 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8042 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8044 do_cleanups (old_chain
);
8051 break_command (char *arg
, int from_tty
)
8053 break_command_1 (arg
, 0, from_tty
);
8057 tbreak_command (char *arg
, int from_tty
)
8059 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8063 hbreak_command (char *arg
, int from_tty
)
8065 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8069 thbreak_command (char *arg
, int from_tty
)
8071 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8075 stop_command (char *arg
, int from_tty
)
8077 printf_filtered (_("Specify the type of breakpoint to set.\n\
8078 Usage: stop in <function | address>\n\
8079 stop at <line>\n"));
8083 stopin_command (char *arg
, int from_tty
)
8087 if (arg
== (char *) NULL
)
8089 else if (*arg
!= '*')
8094 /* Look for a ':'. If this is a line number specification, then
8095 say it is bad, otherwise, it should be an address or
8096 function/method name. */
8097 while (*argptr
&& !hasColon
)
8099 hasColon
= (*argptr
== ':');
8104 badInput
= (*argptr
!= ':'); /* Not a class::method */
8106 badInput
= isdigit (*arg
); /* a simple line number */
8110 printf_filtered (_("Usage: stop in <function | address>\n"));
8112 break_command_1 (arg
, 0, from_tty
);
8116 stopat_command (char *arg
, int from_tty
)
8120 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8127 /* Look for a ':'. If there is a '::' then get out, otherwise
8128 it is probably a line number. */
8129 while (*argptr
&& !hasColon
)
8131 hasColon
= (*argptr
== ':');
8136 badInput
= (*argptr
== ':'); /* we have class::method */
8138 badInput
= !isdigit (*arg
); /* not a line number */
8142 printf_filtered (_("Usage: stop at <line>\n"));
8144 break_command_1 (arg
, 0, from_tty
);
8147 /* Implement the "breakpoint_hit" breakpoint_ops method for
8148 ranged breakpoints. */
8151 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8152 struct address_space
*aspace
,
8155 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8156 bl
->length
, aspace
, bp_addr
);
8159 /* Implement the "resources_needed" breakpoint_ops method for
8160 ranged breakpoints. */
8163 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8165 return target_ranged_break_num_registers ();
8168 /* Implement the "print_it" breakpoint_ops method for
8169 ranged breakpoints. */
8171 static enum print_stop_action
8172 print_it_ranged_breakpoint (bpstat bs
)
8174 struct breakpoint
*b
= bs
->breakpoint_at
;
8175 struct bp_location
*bl
= b
->loc
;
8176 struct ui_out
*uiout
= current_uiout
;
8178 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8180 /* Ranged breakpoints have only one location. */
8181 gdb_assert (bl
&& bl
->next
== NULL
);
8183 annotate_breakpoint (b
->number
);
8184 if (b
->disposition
== disp_del
)
8185 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8187 ui_out_text (uiout
, "\nRanged breakpoint ");
8188 if (ui_out_is_mi_like_p (uiout
))
8190 ui_out_field_string (uiout
, "reason",
8191 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8192 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8194 ui_out_field_int (uiout
, "bkptno", b
->number
);
8195 ui_out_text (uiout
, ", ");
8197 return PRINT_SRC_AND_LOC
;
8200 /* Implement the "print_one" breakpoint_ops method for
8201 ranged breakpoints. */
8204 print_one_ranged_breakpoint (struct breakpoint
*b
,
8205 struct bp_location
**last_loc
)
8207 struct bp_location
*bl
= b
->loc
;
8208 struct value_print_options opts
;
8209 struct ui_out
*uiout
= current_uiout
;
8211 /* Ranged breakpoints have only one location. */
8212 gdb_assert (bl
&& bl
->next
== NULL
);
8214 get_user_print_options (&opts
);
8216 if (opts
.addressprint
)
8217 /* We don't print the address range here, it will be printed later
8218 by print_one_detail_ranged_breakpoint. */
8219 ui_out_field_skip (uiout
, "addr");
8221 print_breakpoint_location (b
, bl
);
8225 /* Implement the "print_one_detail" breakpoint_ops method for
8226 ranged breakpoints. */
8229 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8230 struct ui_out
*uiout
)
8232 CORE_ADDR address_start
, address_end
;
8233 struct bp_location
*bl
= b
->loc
;
8234 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8235 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8239 address_start
= bl
->address
;
8240 address_end
= address_start
+ bl
->length
- 1;
8242 ui_out_text (uiout
, "\taddress range: ");
8243 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8244 print_core_address (bl
->gdbarch
, address_start
),
8245 print_core_address (bl
->gdbarch
, address_end
));
8246 ui_out_field_stream (uiout
, "addr", stb
);
8247 ui_out_text (uiout
, "\n");
8249 do_cleanups (cleanup
);
8252 /* Implement the "print_mention" breakpoint_ops method for
8253 ranged breakpoints. */
8256 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8258 struct bp_location
*bl
= b
->loc
;
8259 struct ui_out
*uiout
= current_uiout
;
8262 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8264 if (ui_out_is_mi_like_p (uiout
))
8267 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8268 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8269 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8272 /* Implement the "print_recreate" breakpoint_ops method for
8273 ranged breakpoints. */
8276 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8278 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8279 b
->addr_string_range_end
);
8280 print_recreate_thread (b
, fp
);
8283 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8285 static struct breakpoint_ops ranged_breakpoint_ops
;
8287 /* Find the address where the end of the breakpoint range should be
8288 placed, given the SAL of the end of the range. This is so that if
8289 the user provides a line number, the end of the range is set to the
8290 last instruction of the given line. */
8293 find_breakpoint_range_end (struct symtab_and_line sal
)
8297 /* If the user provided a PC value, use it. Otherwise,
8298 find the address of the end of the given location. */
8299 if (sal
.explicit_pc
)
8306 ret
= find_line_pc_range (sal
, &start
, &end
);
8308 error (_("Could not find location of the end of the range."));
8310 /* find_line_pc_range returns the start of the next line. */
8317 /* Implement the "break-range" CLI command. */
8320 break_range_command (char *arg
, int from_tty
)
8322 char *arg_start
, *addr_string_start
, *addr_string_end
;
8323 struct linespec_result canonical_start
, canonical_end
;
8324 int bp_count
, can_use_bp
, length
;
8326 struct breakpoint
*b
;
8327 struct symtab_and_line sal_start
, sal_end
;
8328 struct symtabs_and_lines sals_start
, sals_end
;
8329 struct cleanup
*cleanup_bkpt
;
8331 /* We don't support software ranged breakpoints. */
8332 if (target_ranged_break_num_registers () < 0)
8333 error (_("This target does not support hardware ranged breakpoints."));
8335 bp_count
= hw_breakpoint_used_count ();
8336 bp_count
+= target_ranged_break_num_registers ();
8337 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8340 error (_("Hardware breakpoints used exceeds limit."));
8342 if (arg
== NULL
|| arg
[0] == '\0')
8343 error(_("No address range specified."));
8345 sals_start
.sals
= NULL
;
8346 sals_start
.nelts
= 0;
8347 init_linespec_result (&canonical_start
);
8349 while (*arg
== ' ' || *arg
== '\t')
8352 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8354 sal_start
= sals_start
.sals
[0];
8355 addr_string_start
= canonical_start
.canonical
[0];
8356 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8357 xfree (sals_start
.sals
);
8358 xfree (canonical_start
.canonical
);
8361 error (_("Too few arguments."));
8362 else if (sals_start
.nelts
== 0)
8363 error (_("Could not find location of the beginning of the range."));
8364 else if (sals_start
.nelts
!= 1)
8365 error (_("Cannot create a ranged breakpoint with multiple locations."));
8367 resolve_sal_pc (&sal_start
);
8369 arg
++; /* Skip the comma. */
8370 while (*arg
== ' ' || *arg
== '\t')
8373 /* Parse the end location. */
8375 sals_end
.sals
= NULL
;
8377 init_linespec_result (&canonical_end
);
8380 /* We call decode_line_1 directly here instead of using
8381 parse_breakpoint_sals because we need to specify the start location's
8382 symtab and line as the default symtab and line for the end of the
8383 range. This makes it possible to have ranges like "foo.c:27, +14",
8384 where +14 means 14 lines from the start location. */
8385 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8388 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8389 if (canonical_end
.canonical
== NULL
)
8390 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8391 /* Add the string if not present. */
8392 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8393 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8395 sal_end
= sals_end
.sals
[0];
8396 addr_string_end
= canonical_end
.canonical
[0];
8397 make_cleanup (xfree
, addr_string_end
);
8398 xfree (sals_end
.sals
);
8399 xfree (canonical_end
.canonical
);
8401 if (sals_end
.nelts
== 0)
8402 error (_("Could not find location of the end of the range."));
8403 else if (sals_end
.nelts
!= 1)
8404 error (_("Cannot create a ranged breakpoint with multiple locations."));
8406 resolve_sal_pc (&sal_end
);
8408 end
= find_breakpoint_range_end (sal_end
);
8409 if (sal_start
.pc
> end
)
8410 error (_("Invalid address range, end precedes start."));
8412 length
= end
- sal_start
.pc
+ 1;
8414 /* Length overflowed. */
8415 error (_("Address range too large."));
8416 else if (length
== 1)
8418 /* This range is simple enough to be handled by
8419 the `hbreak' command. */
8420 hbreak_command (addr_string_start
, 1);
8422 do_cleanups (cleanup_bkpt
);
8427 /* Now set up the breakpoint. */
8428 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8429 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8430 set_breakpoint_count (breakpoint_count
+ 1);
8431 b
->number
= breakpoint_count
;
8432 b
->disposition
= disp_donttouch
;
8433 b
->addr_string
= addr_string_start
;
8434 b
->addr_string_range_end
= addr_string_end
;
8435 b
->loc
->length
= length
;
8437 discard_cleanups (cleanup_bkpt
);
8440 observer_notify_breakpoint_created (b
);
8441 update_global_location_list (1);
8444 /* Return non-zero if EXP is verified as constant. Returned zero
8445 means EXP is variable. Also the constant detection may fail for
8446 some constant expressions and in such case still falsely return
8449 watchpoint_exp_is_const (const struct expression
*exp
)
8457 /* We are only interested in the descriptor of each element. */
8458 operator_length (exp
, i
, &oplenp
, &argsp
);
8461 switch (exp
->elts
[i
].opcode
)
8471 case BINOP_LOGICAL_AND
:
8472 case BINOP_LOGICAL_OR
:
8473 case BINOP_BITWISE_AND
:
8474 case BINOP_BITWISE_IOR
:
8475 case BINOP_BITWISE_XOR
:
8477 case BINOP_NOTEQUAL
:
8493 case TERNOP_SLICE_COUNT
:
8505 case OP_OBJC_NSSTRING
:
8508 case UNOP_LOGICAL_NOT
:
8509 case UNOP_COMPLEMENT
:
8512 /* Unary, binary and ternary operators: We have to check
8513 their operands. If they are constant, then so is the
8514 result of that operation. For instance, if A and B are
8515 determined to be constants, then so is "A + B".
8517 UNOP_IND is one exception to the rule above, because the
8518 value of *ADDR is not necessarily a constant, even when
8523 /* Check whether the associated symbol is a constant.
8525 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8526 possible that a buggy compiler could mark a variable as
8527 constant even when it is not, and TYPE_CONST would return
8528 true in this case, while SYMBOL_CLASS wouldn't.
8530 We also have to check for function symbols because they
8531 are always constant. */
8533 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8535 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8536 && SYMBOL_CLASS (s
) != LOC_CONST
8537 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8542 /* The default action is to return 0 because we are using
8543 the optimistic approach here: If we don't know something,
8544 then it is not a constant. */
8553 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8556 dtor_watchpoint (struct breakpoint
*self
)
8558 struct watchpoint
*w
= (struct watchpoint
*) self
;
8560 xfree (w
->cond_exp
);
8562 xfree (w
->exp_string
);
8563 xfree (w
->exp_string_reparse
);
8564 value_free (w
->val
);
8566 base_breakpoint_ops
.dtor (self
);
8569 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8572 re_set_watchpoint (struct breakpoint
*b
)
8574 struct watchpoint
*w
= (struct watchpoint
*) b
;
8576 /* Watchpoint can be either on expression using entirely global
8577 variables, or it can be on local variables.
8579 Watchpoints of the first kind are never auto-deleted, and even
8580 persist across program restarts. Since they can use variables
8581 from shared libraries, we need to reparse expression as libraries
8582 are loaded and unloaded.
8584 Watchpoints on local variables can also change meaning as result
8585 of solib event. For example, if a watchpoint uses both a local
8586 and a global variables in expression, it's a local watchpoint,
8587 but unloading of a shared library will make the expression
8588 invalid. This is not a very common use case, but we still
8589 re-evaluate expression, to avoid surprises to the user.
8591 Note that for local watchpoints, we re-evaluate it only if
8592 watchpoints frame id is still valid. If it's not, it means the
8593 watchpoint is out of scope and will be deleted soon. In fact,
8594 I'm not sure we'll ever be called in this case.
8596 If a local watchpoint's frame id is still valid, then
8597 w->exp_valid_block is likewise valid, and we can safely use it.
8599 Don't do anything about disabled watchpoints, since they will be
8600 reevaluated again when enabled. */
8601 update_watchpoint (w
, 1 /* reparse */);
8604 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8607 insert_watchpoint (struct bp_location
*bl
)
8609 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8610 int length
= w
->exact
? 1 : bl
->length
;
8612 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8616 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8619 remove_watchpoint (struct bp_location
*bl
)
8621 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8622 int length
= w
->exact
? 1 : bl
->length
;
8624 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8629 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8630 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8632 struct breakpoint
*b
= bl
->owner
;
8633 struct watchpoint
*w
= (struct watchpoint
*) b
;
8635 /* Continuable hardware watchpoints are treated as non-existent if the
8636 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8637 some data address). Otherwise gdb won't stop on a break instruction
8638 in the code (not from a breakpoint) when a hardware watchpoint has
8639 been defined. Also skip watchpoints which we know did not trigger
8640 (did not match the data address). */
8641 if (is_hardware_watchpoint (b
)
8642 && w
->watchpoint_triggered
== watch_triggered_no
)
8649 check_status_watchpoint (bpstat bs
)
8651 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8653 bpstat_check_watchpoint (bs
);
8656 /* Implement the "resources_needed" breakpoint_ops method for
8657 hardware watchpoints. */
8660 resources_needed_watchpoint (const struct bp_location
*bl
)
8662 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8663 int length
= w
->exact
? 1 : bl
->length
;
8665 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8668 /* Implement the "works_in_software_mode" breakpoint_ops method for
8669 hardware watchpoints. */
8672 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8674 /* Read and access watchpoints only work with hardware support. */
8675 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8678 static enum print_stop_action
8679 print_it_watchpoint (bpstat bs
)
8681 struct cleanup
*old_chain
;
8682 struct breakpoint
*b
;
8683 const struct bp_location
*bl
;
8684 struct ui_stream
*stb
;
8685 enum print_stop_action result
;
8686 struct watchpoint
*w
;
8687 struct ui_out
*uiout
= current_uiout
;
8689 gdb_assert (bs
->bp_location_at
!= NULL
);
8691 bl
= bs
->bp_location_at
;
8692 b
= bs
->breakpoint_at
;
8693 w
= (struct watchpoint
*) b
;
8695 stb
= ui_out_stream_new (uiout
);
8696 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8701 case bp_hardware_watchpoint
:
8702 annotate_watchpoint (b
->number
);
8703 if (ui_out_is_mi_like_p (uiout
))
8706 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8708 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8709 ui_out_text (uiout
, "\nOld value = ");
8710 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8711 ui_out_field_stream (uiout
, "old", stb
);
8712 ui_out_text (uiout
, "\nNew value = ");
8713 watchpoint_value_print (w
->val
, stb
->stream
);
8714 ui_out_field_stream (uiout
, "new", stb
);
8715 ui_out_text (uiout
, "\n");
8716 /* More than one watchpoint may have been triggered. */
8717 result
= PRINT_UNKNOWN
;
8720 case bp_read_watchpoint
:
8721 if (ui_out_is_mi_like_p (uiout
))
8724 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8726 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8727 ui_out_text (uiout
, "\nValue = ");
8728 watchpoint_value_print (w
->val
, stb
->stream
);
8729 ui_out_field_stream (uiout
, "value", stb
);
8730 ui_out_text (uiout
, "\n");
8731 result
= PRINT_UNKNOWN
;
8734 case bp_access_watchpoint
:
8735 if (bs
->old_val
!= NULL
)
8737 annotate_watchpoint (b
->number
);
8738 if (ui_out_is_mi_like_p (uiout
))
8741 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8743 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8744 ui_out_text (uiout
, "\nOld value = ");
8745 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8746 ui_out_field_stream (uiout
, "old", stb
);
8747 ui_out_text (uiout
, "\nNew value = ");
8752 if (ui_out_is_mi_like_p (uiout
))
8755 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8756 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8757 ui_out_text (uiout
, "\nValue = ");
8759 watchpoint_value_print (w
->val
, stb
->stream
);
8760 ui_out_field_stream (uiout
, "new", stb
);
8761 ui_out_text (uiout
, "\n");
8762 result
= PRINT_UNKNOWN
;
8765 result
= PRINT_UNKNOWN
;
8768 do_cleanups (old_chain
);
8772 /* Implement the "print_mention" breakpoint_ops method for hardware
8776 print_mention_watchpoint (struct breakpoint
*b
)
8778 struct cleanup
*ui_out_chain
;
8779 struct watchpoint
*w
= (struct watchpoint
*) b
;
8780 struct ui_out
*uiout
= current_uiout
;
8785 ui_out_text (uiout
, "Watchpoint ");
8786 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8788 case bp_hardware_watchpoint
:
8789 ui_out_text (uiout
, "Hardware watchpoint ");
8790 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8792 case bp_read_watchpoint
:
8793 ui_out_text (uiout
, "Hardware read watchpoint ");
8794 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8796 case bp_access_watchpoint
:
8797 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8798 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8801 internal_error (__FILE__
, __LINE__
,
8802 _("Invalid hardware watchpoint type."));
8805 ui_out_field_int (uiout
, "number", b
->number
);
8806 ui_out_text (uiout
, ": ");
8807 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8808 do_cleanups (ui_out_chain
);
8811 /* Implement the "print_recreate" breakpoint_ops method for
8815 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8817 struct watchpoint
*w
= (struct watchpoint
*) b
;
8822 case bp_hardware_watchpoint
:
8823 fprintf_unfiltered (fp
, "watch");
8825 case bp_read_watchpoint
:
8826 fprintf_unfiltered (fp
, "rwatch");
8828 case bp_access_watchpoint
:
8829 fprintf_unfiltered (fp
, "awatch");
8832 internal_error (__FILE__
, __LINE__
,
8833 _("Invalid watchpoint type."));
8836 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8837 print_recreate_thread (b
, fp
);
8840 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8842 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8844 /* Implement the "insert" breakpoint_ops method for
8845 masked hardware watchpoints. */
8848 insert_masked_watchpoint (struct bp_location
*bl
)
8850 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8852 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8853 bl
->watchpoint_type
);
8856 /* Implement the "remove" breakpoint_ops method for
8857 masked hardware watchpoints. */
8860 remove_masked_watchpoint (struct bp_location
*bl
)
8862 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8864 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8865 bl
->watchpoint_type
);
8868 /* Implement the "resources_needed" breakpoint_ops method for
8869 masked hardware watchpoints. */
8872 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8874 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8876 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
8879 /* Implement the "works_in_software_mode" breakpoint_ops method for
8880 masked hardware watchpoints. */
8883 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8888 /* Implement the "print_it" breakpoint_ops method for
8889 masked hardware watchpoints. */
8891 static enum print_stop_action
8892 print_it_masked_watchpoint (bpstat bs
)
8894 struct breakpoint
*b
= bs
->breakpoint_at
;
8895 struct ui_out
*uiout
= current_uiout
;
8897 /* Masked watchpoints have only one location. */
8898 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8902 case bp_hardware_watchpoint
:
8903 annotate_watchpoint (b
->number
);
8904 if (ui_out_is_mi_like_p (uiout
))
8907 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8910 case bp_read_watchpoint
:
8911 if (ui_out_is_mi_like_p (uiout
))
8914 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8917 case bp_access_watchpoint
:
8918 if (ui_out_is_mi_like_p (uiout
))
8921 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8924 internal_error (__FILE__
, __LINE__
,
8925 _("Invalid hardware watchpoint type."));
8929 ui_out_text (uiout
, _("\n\
8930 Check the underlying instruction at PC for the memory\n\
8931 address and value which triggered this watchpoint.\n"));
8932 ui_out_text (uiout
, "\n");
8934 /* More than one watchpoint may have been triggered. */
8935 return PRINT_UNKNOWN
;
8938 /* Implement the "print_one_detail" breakpoint_ops method for
8939 masked hardware watchpoints. */
8942 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8943 struct ui_out
*uiout
)
8945 struct watchpoint
*w
= (struct watchpoint
*) b
;
8947 /* Masked watchpoints have only one location. */
8948 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8950 ui_out_text (uiout
, "\tmask ");
8951 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
8952 ui_out_text (uiout
, "\n");
8955 /* Implement the "print_mention" breakpoint_ops method for
8956 masked hardware watchpoints. */
8959 print_mention_masked_watchpoint (struct breakpoint
*b
)
8961 struct watchpoint
*w
= (struct watchpoint
*) b
;
8962 struct ui_out
*uiout
= current_uiout
;
8963 struct cleanup
*ui_out_chain
;
8967 case bp_hardware_watchpoint
:
8968 ui_out_text (uiout
, "Masked hardware watchpoint ");
8969 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8971 case bp_read_watchpoint
:
8972 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8973 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8975 case bp_access_watchpoint
:
8976 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8977 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8980 internal_error (__FILE__
, __LINE__
,
8981 _("Invalid hardware watchpoint type."));
8984 ui_out_field_int (uiout
, "number", b
->number
);
8985 ui_out_text (uiout
, ": ");
8986 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8987 do_cleanups (ui_out_chain
);
8990 /* Implement the "print_recreate" breakpoint_ops method for
8991 masked hardware watchpoints. */
8994 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8996 struct watchpoint
*w
= (struct watchpoint
*) b
;
9001 case bp_hardware_watchpoint
:
9002 fprintf_unfiltered (fp
, "watch");
9004 case bp_read_watchpoint
:
9005 fprintf_unfiltered (fp
, "rwatch");
9007 case bp_access_watchpoint
:
9008 fprintf_unfiltered (fp
, "awatch");
9011 internal_error (__FILE__
, __LINE__
,
9012 _("Invalid hardware watchpoint type."));
9015 sprintf_vma (tmp
, w
->hw_wp_mask
);
9016 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
9017 print_recreate_thread (b
, fp
);
9020 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9022 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
9024 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9027 is_masked_watchpoint (const struct breakpoint
*b
)
9029 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
9032 /* accessflag: hw_write: watch write,
9033 hw_read: watch read,
9034 hw_access: watch access (read or write) */
9036 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
9037 int just_location
, int internal
)
9039 volatile struct gdb_exception e
;
9040 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9041 struct expression
*exp
;
9042 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9043 struct value
*val
, *mark
, *result
;
9044 struct frame_info
*frame
;
9045 char *exp_start
= NULL
;
9046 char *exp_end
= NULL
;
9047 char *tok
, *end_tok
;
9049 char *cond_start
= NULL
;
9050 char *cond_end
= NULL
;
9051 enum bptype bp_type
;
9054 /* Flag to indicate whether we are going to use masks for
9055 the hardware watchpoint. */
9058 struct watchpoint
*w
;
9060 /* Make sure that we actually have parameters to parse. */
9061 if (arg
!= NULL
&& arg
[0] != '\0')
9065 /* Look for "parameter value" pairs at the end
9066 of the arguments string. */
9067 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9069 /* Skip whitespace at the end of the argument list. */
9070 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9073 /* Find the beginning of the last token.
9074 This is the value of the parameter. */
9075 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9077 value_start
= tok
+ 1;
9079 /* Skip whitespace. */
9080 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9085 /* Find the beginning of the second to last token.
9086 This is the parameter itself. */
9087 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9090 toklen
= end_tok
- tok
+ 1;
9092 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9094 /* At this point we've found a "thread" token, which means
9095 the user is trying to set a watchpoint that triggers
9096 only in a specific thread. */
9100 error(_("You can specify only one thread."));
9102 /* Extract the thread ID from the next token. */
9103 thread
= strtol (value_start
, &endp
, 0);
9105 /* Check if the user provided a valid numeric value for the
9107 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9108 error (_("Invalid thread ID specification %s."), value_start
);
9110 /* Check if the thread actually exists. */
9111 if (!valid_thread_id (thread
))
9112 error (_("Unknown thread %d."), thread
);
9114 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9116 /* We've found a "mask" token, which means the user wants to
9117 create a hardware watchpoint that is going to have the mask
9119 struct value
*mask_value
, *mark
;
9122 error(_("You can specify only one mask."));
9124 use_mask
= just_location
= 1;
9126 mark
= value_mark ();
9127 mask_value
= parse_to_comma_and_eval (&value_start
);
9128 mask
= value_as_address (mask_value
);
9129 value_free_to_mark (mark
);
9132 /* We didn't recognize what we found. We should stop here. */
9135 /* Truncate the string and get rid of the "parameter value" pair before
9136 the arguments string is parsed by the parse_exp_1 function. */
9141 /* Parse the rest of the arguments. */
9142 innermost_block
= NULL
;
9144 exp
= parse_exp_1 (&arg
, 0, 0);
9146 /* Remove trailing whitespace from the expression before saving it.
9147 This makes the eventual display of the expression string a bit
9149 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9152 /* Checking if the expression is not constant. */
9153 if (watchpoint_exp_is_const (exp
))
9157 len
= exp_end
- exp_start
;
9158 while (len
> 0 && isspace (exp_start
[len
- 1]))
9160 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9163 exp_valid_block
= innermost_block
;
9164 mark
= value_mark ();
9165 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9171 exp_valid_block
= NULL
;
9172 val
= value_addr (result
);
9173 release_value (val
);
9174 value_free_to_mark (mark
);
9178 ret
= target_masked_watch_num_registers (value_as_address (val
),
9181 error (_("This target does not support masked watchpoints."));
9183 error (_("Invalid mask or memory region."));
9186 else if (val
!= NULL
)
9187 release_value (val
);
9189 tok
= skip_spaces (arg
);
9190 end_tok
= skip_to_space (tok
);
9192 toklen
= end_tok
- tok
;
9193 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9195 struct expression
*cond
;
9197 innermost_block
= NULL
;
9198 tok
= cond_start
= end_tok
+ 1;
9199 cond
= parse_exp_1 (&tok
, 0, 0);
9201 /* The watchpoint expression may not be local, but the condition
9202 may still be. E.g.: `watch global if local > 0'. */
9203 cond_exp_valid_block
= innermost_block
;
9209 error (_("Junk at end of command."));
9211 if (accessflag
== hw_read
)
9212 bp_type
= bp_read_watchpoint
;
9213 else if (accessflag
== hw_access
)
9214 bp_type
= bp_access_watchpoint
;
9216 bp_type
= bp_hardware_watchpoint
;
9218 frame
= block_innermost_frame (exp_valid_block
);
9220 /* If the expression is "local", then set up a "watchpoint scope"
9221 breakpoint at the point where we've left the scope of the watchpoint
9222 expression. Create the scope breakpoint before the watchpoint, so
9223 that we will encounter it first in bpstat_stop_status. */
9224 if (exp_valid_block
&& frame
)
9226 if (frame_id_p (frame_unwind_caller_id (frame
)))
9229 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9230 frame_unwind_caller_pc (frame
),
9231 bp_watchpoint_scope
,
9232 &momentary_breakpoint_ops
);
9234 scope_breakpoint
->enable_state
= bp_enabled
;
9236 /* Automatically delete the breakpoint when it hits. */
9237 scope_breakpoint
->disposition
= disp_del
;
9239 /* Only break in the proper frame (help with recursion). */
9240 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9242 /* Set the address at which we will stop. */
9243 scope_breakpoint
->loc
->gdbarch
9244 = frame_unwind_caller_arch (frame
);
9245 scope_breakpoint
->loc
->requested_address
9246 = frame_unwind_caller_pc (frame
);
9247 scope_breakpoint
->loc
->address
9248 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9249 scope_breakpoint
->loc
->requested_address
,
9250 scope_breakpoint
->type
);
9254 /* Now set up the breakpoint. */
9256 w
= XCNEW (struct watchpoint
);
9259 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9260 &masked_watchpoint_breakpoint_ops
);
9262 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9263 &watchpoint_breakpoint_ops
);
9265 b
->disposition
= disp_donttouch
;
9266 b
->pspace
= current_program_space
;
9268 w
->exp_valid_block
= exp_valid_block
;
9269 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9272 struct type
*t
= value_type (val
);
9273 CORE_ADDR addr
= value_as_address (val
);
9276 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9277 name
= type_to_string (t
);
9279 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9280 core_addr_to_string (addr
));
9283 w
->exp_string
= xstrprintf ("-location %.*s",
9284 (int) (exp_end
- exp_start
), exp_start
);
9286 /* The above expression is in C. */
9287 b
->language
= language_c
;
9290 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9294 w
->hw_wp_mask
= mask
;
9303 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9309 w
->watchpoint_frame
= get_frame_id (frame
);
9310 w
->watchpoint_thread
= inferior_ptid
;
9314 w
->watchpoint_frame
= null_frame_id
;
9315 w
->watchpoint_thread
= null_ptid
;
9318 if (scope_breakpoint
!= NULL
)
9320 /* The scope breakpoint is related to the watchpoint. We will
9321 need to act on them together. */
9322 b
->related_breakpoint
= scope_breakpoint
;
9323 scope_breakpoint
->related_breakpoint
= b
;
9327 value_free_to_mark (mark
);
9329 TRY_CATCH (e
, RETURN_MASK_ALL
)
9331 /* Finally update the new watchpoint. This creates the locations
9332 that should be inserted. */
9333 update_watchpoint (w
, 1);
9337 delete_breakpoint (b
);
9338 throw_exception (e
);
9341 install_breakpoint (internal
, b
);
9344 /* Return count of debug registers needed to watch the given expression.
9345 If the watchpoint cannot be handled in hardware return zero. */
9348 can_use_hardware_watchpoint (struct value
*v
)
9350 int found_memory_cnt
= 0;
9351 struct value
*head
= v
;
9353 /* Did the user specifically forbid us to use hardware watchpoints? */
9354 if (!can_use_hw_watchpoints
)
9357 /* Make sure that the value of the expression depends only upon
9358 memory contents, and values computed from them within GDB. If we
9359 find any register references or function calls, we can't use a
9360 hardware watchpoint.
9362 The idea here is that evaluating an expression generates a series
9363 of values, one holding the value of every subexpression. (The
9364 expression a*b+c has five subexpressions: a, b, a*b, c, and
9365 a*b+c.) GDB's values hold almost enough information to establish
9366 the criteria given above --- they identify memory lvalues,
9367 register lvalues, computed values, etcetera. So we can evaluate
9368 the expression, and then scan the chain of values that leaves
9369 behind to decide whether we can detect any possible change to the
9370 expression's final value using only hardware watchpoints.
9372 However, I don't think that the values returned by inferior
9373 function calls are special in any way. So this function may not
9374 notice that an expression involving an inferior function call
9375 can't be watched with hardware watchpoints. FIXME. */
9376 for (; v
; v
= value_next (v
))
9378 if (VALUE_LVAL (v
) == lval_memory
)
9380 if (v
!= head
&& value_lazy (v
))
9381 /* A lazy memory lvalue in the chain is one that GDB never
9382 needed to fetch; we either just used its address (e.g.,
9383 `a' in `a.b') or we never needed it at all (e.g., `a'
9384 in `a,b'). This doesn't apply to HEAD; if that is
9385 lazy then it was not readable, but watch it anyway. */
9389 /* Ahh, memory we actually used! Check if we can cover
9390 it with hardware watchpoints. */
9391 struct type
*vtype
= check_typedef (value_type (v
));
9393 /* We only watch structs and arrays if user asked for it
9394 explicitly, never if they just happen to appear in a
9395 middle of some value chain. */
9397 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9398 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9400 CORE_ADDR vaddr
= value_address (v
);
9404 len
= (target_exact_watchpoints
9405 && is_scalar_type_recursive (vtype
))?
9406 1 : TYPE_LENGTH (value_type (v
));
9408 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9412 found_memory_cnt
+= num_regs
;
9416 else if (VALUE_LVAL (v
) != not_lval
9417 && deprecated_value_modifiable (v
) == 0)
9418 return 0; /* These are values from the history (e.g., $1). */
9419 else if (VALUE_LVAL (v
) == lval_register
)
9420 return 0; /* Cannot watch a register with a HW watchpoint. */
9423 /* The expression itself looks suitable for using a hardware
9424 watchpoint, but give the target machine a chance to reject it. */
9425 return found_memory_cnt
;
9429 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9431 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9434 /* A helper function that looks for an argument at the start of a
9435 string. The argument must also either be at the end of the string,
9436 or be followed by whitespace. Returns 1 if it finds the argument,
9437 0 otherwise. If the argument is found, it updates *STR. */
9440 check_for_argument (char **str
, char *arg
, int arg_len
)
9442 if (strncmp (*str
, arg
, arg_len
) == 0
9443 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9451 /* A helper function that looks for the "-location" argument and then
9452 calls watch_command_1. */
9455 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9457 int just_location
= 0;
9460 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9461 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9463 arg
= skip_spaces (arg
);
9467 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9471 watch_command (char *arg
, int from_tty
)
9473 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9477 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9479 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9483 rwatch_command (char *arg
, int from_tty
)
9485 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9489 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9491 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9495 awatch_command (char *arg
, int from_tty
)
9497 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9501 /* Helper routines for the until_command routine in infcmd.c. Here
9502 because it uses the mechanisms of breakpoints. */
9504 struct until_break_command_continuation_args
9506 struct breakpoint
*breakpoint
;
9507 struct breakpoint
*breakpoint2
;
9511 /* This function is called by fetch_inferior_event via the
9512 cmd_continuation pointer, to complete the until command. It takes
9513 care of cleaning up the temporary breakpoints set up by the until
9516 until_break_command_continuation (void *arg
, int err
)
9518 struct until_break_command_continuation_args
*a
= arg
;
9520 delete_breakpoint (a
->breakpoint
);
9522 delete_breakpoint (a
->breakpoint2
);
9523 delete_longjmp_breakpoint (a
->thread_num
);
9527 until_break_command (char *arg
, int from_tty
, int anywhere
)
9529 struct symtabs_and_lines sals
;
9530 struct symtab_and_line sal
;
9531 struct frame_info
*frame
= get_selected_frame (NULL
);
9532 struct breakpoint
*breakpoint
;
9533 struct breakpoint
*breakpoint2
= NULL
;
9534 struct cleanup
*old_chain
;
9536 struct thread_info
*tp
;
9538 clear_proceed_status ();
9540 /* Set a breakpoint where the user wants it and at return from
9543 if (default_breakpoint_valid
)
9544 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
9545 default_breakpoint_line
, NULL
);
9547 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9549 if (sals
.nelts
!= 1)
9550 error (_("Couldn't get information on specified line."));
9553 xfree (sals
.sals
); /* malloc'd, so freed. */
9556 error (_("Junk at end of arguments."));
9558 resolve_sal_pc (&sal
);
9561 /* If the user told us to continue until a specified location,
9562 we don't specify a frame at which we need to stop. */
9563 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9564 null_frame_id
, bp_until
);
9566 /* Otherwise, specify the selected frame, because we want to stop
9567 only at the very same frame. */
9568 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9569 get_stack_frame_id (frame
),
9572 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9574 tp
= inferior_thread ();
9577 /* Keep within the current frame, or in frames called by the current
9580 if (frame_id_p (frame_unwind_caller_id (frame
)))
9582 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9583 sal
.pc
= frame_unwind_caller_pc (frame
);
9584 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9586 frame_unwind_caller_id (frame
),
9588 make_cleanup_delete_breakpoint (breakpoint2
);
9590 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9591 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9594 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9596 /* If we are running asynchronously, and proceed call above has
9597 actually managed to start the target, arrange for breakpoints to
9598 be deleted when the target stops. Otherwise, we're already
9599 stopped and delete breakpoints via cleanup chain. */
9601 if (target_can_async_p () && is_running (inferior_ptid
))
9603 struct until_break_command_continuation_args
*args
;
9604 args
= xmalloc (sizeof (*args
));
9606 args
->breakpoint
= breakpoint
;
9607 args
->breakpoint2
= breakpoint2
;
9608 args
->thread_num
= thread
;
9610 discard_cleanups (old_chain
);
9611 add_continuation (inferior_thread (),
9612 until_break_command_continuation
, args
,
9616 do_cleanups (old_chain
);
9619 /* This function attempts to parse an optional "if <cond>" clause
9620 from the arg string. If one is not found, it returns NULL.
9622 Else, it returns a pointer to the condition string. (It does not
9623 attempt to evaluate the string against a particular block.) And,
9624 it updates arg to point to the first character following the parsed
9625 if clause in the arg string. */
9628 ep_parse_optional_if_clause (char **arg
)
9632 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9635 /* Skip the "if" keyword. */
9638 /* Skip any extra leading whitespace, and record the start of the
9639 condition string. */
9640 *arg
= skip_spaces (*arg
);
9643 /* Assume that the condition occupies the remainder of the arg
9645 (*arg
) += strlen (cond_string
);
9650 /* Commands to deal with catching events, such as signals, exceptions,
9651 process start/exit, etc. */
9655 catch_fork_temporary
, catch_vfork_temporary
,
9656 catch_fork_permanent
, catch_vfork_permanent
9661 catch_fork_command_1 (char *arg
, int from_tty
,
9662 struct cmd_list_element
*command
)
9664 struct gdbarch
*gdbarch
= get_current_arch ();
9665 char *cond_string
= NULL
;
9666 catch_fork_kind fork_kind
;
9669 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9670 tempflag
= (fork_kind
== catch_fork_temporary
9671 || fork_kind
== catch_vfork_temporary
);
9675 arg
= skip_spaces (arg
);
9677 /* The allowed syntax is:
9679 catch [v]fork if <cond>
9681 First, check if there's an if clause. */
9682 cond_string
= ep_parse_optional_if_clause (&arg
);
9684 if ((*arg
!= '\0') && !isspace (*arg
))
9685 error (_("Junk at end of arguments."));
9687 /* If this target supports it, create a fork or vfork catchpoint
9688 and enable reporting of such events. */
9691 case catch_fork_temporary
:
9692 case catch_fork_permanent
:
9693 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9694 &catch_fork_breakpoint_ops
);
9696 case catch_vfork_temporary
:
9697 case catch_vfork_permanent
:
9698 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9699 &catch_vfork_breakpoint_ops
);
9702 error (_("unsupported or unknown fork kind; cannot catch it"));
9708 catch_exec_command_1 (char *arg
, int from_tty
,
9709 struct cmd_list_element
*command
)
9711 struct exec_catchpoint
*c
;
9712 struct gdbarch
*gdbarch
= get_current_arch ();
9714 char *cond_string
= NULL
;
9716 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9720 arg
= skip_spaces (arg
);
9722 /* The allowed syntax is:
9724 catch exec if <cond>
9726 First, check if there's an if clause. */
9727 cond_string
= ep_parse_optional_if_clause (&arg
);
9729 if ((*arg
!= '\0') && !isspace (*arg
))
9730 error (_("Junk at end of arguments."));
9732 c
= XNEW (struct exec_catchpoint
);
9733 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9734 &catch_exec_breakpoint_ops
);
9735 c
->exec_pathname
= NULL
;
9737 install_breakpoint (0, &c
->base
);
9740 static enum print_stop_action
9741 print_it_exception_catchpoint (bpstat bs
)
9743 struct ui_out
*uiout
= current_uiout
;
9744 struct breakpoint
*b
= bs
->breakpoint_at
;
9745 int bp_temp
, bp_throw
;
9747 annotate_catchpoint (b
->number
);
9749 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9750 if (b
->loc
->address
!= b
->loc
->requested_address
)
9751 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9754 bp_temp
= b
->disposition
== disp_del
;
9756 bp_temp
? "Temporary catchpoint "
9758 if (!ui_out_is_mi_like_p (uiout
))
9759 ui_out_field_int (uiout
, "bkptno", b
->number
);
9761 bp_throw
? " (exception thrown), "
9762 : " (exception caught), ");
9763 if (ui_out_is_mi_like_p (uiout
))
9765 ui_out_field_string (uiout
, "reason",
9766 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9767 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9768 ui_out_field_int (uiout
, "bkptno", b
->number
);
9770 return PRINT_SRC_AND_LOC
;
9774 print_one_exception_catchpoint (struct breakpoint
*b
,
9775 struct bp_location
**last_loc
)
9777 struct value_print_options opts
;
9778 struct ui_out
*uiout
= current_uiout
;
9780 get_user_print_options (&opts
);
9781 if (opts
.addressprint
)
9784 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9785 ui_out_field_string (uiout
, "addr", "<PENDING>");
9787 ui_out_field_core_addr (uiout
, "addr",
9788 b
->loc
->gdbarch
, b
->loc
->address
);
9793 if (strstr (b
->addr_string
, "throw") != NULL
)
9794 ui_out_field_string (uiout
, "what", "exception throw");
9796 ui_out_field_string (uiout
, "what", "exception catch");
9800 print_mention_exception_catchpoint (struct breakpoint
*b
)
9802 struct ui_out
*uiout
= current_uiout
;
9806 bp_temp
= b
->disposition
== disp_del
;
9807 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9808 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9809 : _("Catchpoint "));
9810 ui_out_field_int (uiout
, "bkptno", b
->number
);
9811 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9815 /* Implement the "print_recreate" breakpoint_ops method for throw and
9816 catch catchpoints. */
9819 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9825 bp_temp
= b
->disposition
== disp_del
;
9826 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9827 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9828 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9829 print_recreate_thread (b
, fp
);
9832 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9835 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9836 enum exception_event_kind ex_event
, int from_tty
)
9838 char *trigger_func_name
;
9840 if (ex_event
== EX_EVENT_CATCH
)
9841 trigger_func_name
= "__cxa_begin_catch";
9843 trigger_func_name
= "__cxa_throw";
9845 create_breakpoint (get_current_arch (),
9846 trigger_func_name
, cond_string
, -1,
9847 0 /* condition and thread are valid. */,
9848 tempflag
, bp_breakpoint
,
9850 AUTO_BOOLEAN_TRUE
/* pending */,
9851 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9858 /* Deal with "catch catch" and "catch throw" commands. */
9861 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9862 int tempflag
, int from_tty
)
9864 char *cond_string
= NULL
;
9868 arg
= skip_spaces (arg
);
9870 cond_string
= ep_parse_optional_if_clause (&arg
);
9872 if ((*arg
!= '\0') && !isspace (*arg
))
9873 error (_("Junk at end of arguments."));
9875 if (ex_event
!= EX_EVENT_THROW
9876 && ex_event
!= EX_EVENT_CATCH
)
9877 error (_("Unsupported or unknown exception event; cannot catch it"));
9879 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9882 warning (_("Unsupported with this platform/compiler combination."));
9885 /* Implementation of "catch catch" command. */
9888 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9890 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9892 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9895 /* Implementation of "catch throw" command. */
9898 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9900 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9902 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9906 init_ada_exception_breakpoint (struct breakpoint
*b
,
9907 struct gdbarch
*gdbarch
,
9908 struct symtab_and_line sal
,
9910 const struct breakpoint_ops
*ops
,
9916 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9918 loc_gdbarch
= gdbarch
;
9920 describe_other_breakpoints (loc_gdbarch
,
9921 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9922 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9923 version for exception catchpoints, because two catchpoints
9924 used for different exception names will use the same address.
9925 In this case, a "breakpoint ... also set at..." warning is
9926 unproductive. Besides, the warning phrasing is also a bit
9927 inappropriate, we should use the word catchpoint, and tell
9928 the user what type of catchpoint it is. The above is good
9929 enough for now, though. */
9932 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9934 b
->enable_state
= bp_enabled
;
9935 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9936 b
->addr_string
= addr_string
;
9937 b
->language
= language_ada
;
9940 /* Cleanup function for a syscall filter list. */
9942 clean_up_filters (void *arg
)
9944 VEC(int) *iter
= *(VEC(int) **) arg
;
9945 VEC_free (int, iter
);
9948 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9949 filter list, or NULL if no filtering is required. */
9951 catch_syscall_split_args (char *arg
)
9953 VEC(int) *result
= NULL
;
9954 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9956 while (*arg
!= '\0')
9958 int i
, syscall_number
;
9963 /* Skip whitespace. */
9964 while (isspace (*arg
))
9967 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9968 cur_name
[i
] = arg
[i
];
9972 /* Check if the user provided a syscall name or a number. */
9973 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9974 if (*endptr
== '\0')
9975 get_syscall_by_number (syscall_number
, &s
);
9978 /* We have a name. Let's check if it's valid and convert it
9980 get_syscall_by_name (cur_name
, &s
);
9982 if (s
.number
== UNKNOWN_SYSCALL
)
9983 /* Here we have to issue an error instead of a warning,
9984 because GDB cannot do anything useful if there's no
9985 syscall number to be caught. */
9986 error (_("Unknown syscall name '%s'."), cur_name
);
9989 /* Ok, it's valid. */
9990 VEC_safe_push (int, result
, s
.number
);
9993 discard_cleanups (cleanup
);
9997 /* Implement the "catch syscall" command. */
10000 catch_syscall_command_1 (char *arg
, int from_tty
,
10001 struct cmd_list_element
*command
)
10006 struct gdbarch
*gdbarch
= get_current_arch ();
10008 /* Checking if the feature if supported. */
10009 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
10010 error (_("The feature 'catch syscall' is not supported on \
10011 this architecture yet."));
10013 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10015 arg
= skip_spaces (arg
);
10017 /* We need to do this first "dummy" translation in order
10018 to get the syscall XML file loaded or, most important,
10019 to display a warning to the user if there's no XML file
10020 for his/her architecture. */
10021 get_syscall_by_number (0, &s
);
10023 /* The allowed syntax is:
10025 catch syscall <name | number> [<name | number> ... <name | number>]
10027 Let's check if there's a syscall name. */
10030 filter
= catch_syscall_split_args (arg
);
10034 create_syscall_event_catchpoint (tempflag
, filter
,
10035 &catch_syscall_breakpoint_ops
);
10039 catch_command (char *arg
, int from_tty
)
10041 error (_("Catch requires an event name."));
10046 tcatch_command (char *arg
, int from_tty
)
10048 error (_("Catch requires an event name."));
10051 /* Delete breakpoints by address or line. */
10054 clear_command (char *arg
, int from_tty
)
10056 struct breakpoint
*b
;
10057 VEC(breakpoint_p
) *found
= 0;
10060 struct symtabs_and_lines sals
;
10061 struct symtab_and_line sal
;
10066 sals
= decode_line_spec (arg
, 1);
10071 sals
.sals
= (struct symtab_and_line
*)
10072 xmalloc (sizeof (struct symtab_and_line
));
10073 make_cleanup (xfree
, sals
.sals
);
10074 init_sal (&sal
); /* Initialize to zeroes. */
10075 sal
.line
= default_breakpoint_line
;
10076 sal
.symtab
= default_breakpoint_symtab
;
10077 sal
.pc
= default_breakpoint_address
;
10078 sal
.pspace
= default_breakpoint_pspace
;
10079 if (sal
.symtab
== 0)
10080 error (_("No source file specified."));
10082 sals
.sals
[0] = sal
;
10088 /* We don't call resolve_sal_pc here. That's not as bad as it
10089 seems, because all existing breakpoints typically have both
10090 file/line and pc set. So, if clear is given file/line, we can
10091 match this to existing breakpoint without obtaining pc at all.
10093 We only support clearing given the address explicitly
10094 present in breakpoint table. Say, we've set breakpoint
10095 at file:line. There were several PC values for that file:line,
10096 due to optimization, all in one block.
10098 We've picked one PC value. If "clear" is issued with another
10099 PC corresponding to the same file:line, the breakpoint won't
10100 be cleared. We probably can still clear the breakpoint, but
10101 since the other PC value is never presented to user, user
10102 can only find it by guessing, and it does not seem important
10103 to support that. */
10105 /* For each line spec given, delete bps which correspond to it. Do
10106 it in two passes, solely to preserve the current behavior that
10107 from_tty is forced true if we delete more than one
10111 for (i
= 0; i
< sals
.nelts
; i
++)
10113 /* If exact pc given, clear bpts at that pc.
10114 If line given (pc == 0), clear all bpts on specified line.
10115 If defaulting, clear all bpts on default line
10118 defaulting sal.pc != 0 tests to do
10123 1 0 <can't happen> */
10125 sal
= sals
.sals
[i
];
10127 /* Find all matching breakpoints and add them to 'found'. */
10128 ALL_BREAKPOINTS (b
)
10131 /* Are we going to delete b? */
10132 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10134 struct bp_location
*loc
= b
->loc
;
10135 for (; loc
; loc
= loc
->next
)
10137 int pc_match
= sal
.pc
10138 && (loc
->pspace
== sal
.pspace
)
10139 && (loc
->address
== sal
.pc
)
10140 && (!section_is_overlay (loc
->section
)
10141 || loc
->section
== sal
.section
);
10142 int line_match
= ((default_match
|| (0 == sal
.pc
))
10143 && b
->source_file
!= NULL
10144 && sal
.symtab
!= NULL
10145 && sal
.pspace
== loc
->pspace
10146 && filename_cmp (b
->source_file
,
10147 sal
.symtab
->filename
) == 0
10148 && b
->line_number
== sal
.line
);
10149 if (pc_match
|| line_match
)
10158 VEC_safe_push(breakpoint_p
, found
, b
);
10161 /* Now go thru the 'found' chain and delete them. */
10162 if (VEC_empty(breakpoint_p
, found
))
10165 error (_("No breakpoint at %s."), arg
);
10167 error (_("No breakpoint at this line."));
10170 if (VEC_length(breakpoint_p
, found
) > 1)
10171 from_tty
= 1; /* Always report if deleted more than one. */
10174 if (VEC_length(breakpoint_p
, found
) == 1)
10175 printf_unfiltered (_("Deleted breakpoint "));
10177 printf_unfiltered (_("Deleted breakpoints "));
10179 breakpoints_changed ();
10181 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10184 printf_unfiltered ("%d ", b
->number
);
10185 delete_breakpoint (b
);
10188 putchar_unfiltered ('\n');
10191 /* Delete breakpoint in BS if they are `delete' breakpoints and
10192 all breakpoints that are marked for deletion, whether hit or not.
10193 This is called after any breakpoint is hit, or after errors. */
10196 breakpoint_auto_delete (bpstat bs
)
10198 struct breakpoint
*b
, *b_tmp
;
10200 for (; bs
; bs
= bs
->next
)
10201 if (bs
->breakpoint_at
10202 && bs
->breakpoint_at
->disposition
== disp_del
10204 delete_breakpoint (bs
->breakpoint_at
);
10206 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10208 if (b
->disposition
== disp_del_at_next_stop
)
10209 delete_breakpoint (b
);
10213 /* A comparison function for bp_location AP and BP being interfaced to
10214 qsort. Sort elements primarily by their ADDRESS (no matter what
10215 does breakpoint_address_is_meaningful say for its OWNER),
10216 secondarily by ordering first bp_permanent OWNERed elements and
10217 terciarily just ensuring the array is sorted stable way despite
10218 qsort being an unstable algorithm. */
10221 bp_location_compare (const void *ap
, const void *bp
)
10223 struct bp_location
*a
= *(void **) ap
;
10224 struct bp_location
*b
= *(void **) bp
;
10225 /* A and B come from existing breakpoints having non-NULL OWNER. */
10226 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10227 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10229 if (a
->address
!= b
->address
)
10230 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10232 /* Sort permanent breakpoints first. */
10233 if (a_perm
!= b_perm
)
10234 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10236 /* Make the user-visible order stable across GDB runs. Locations of
10237 the same breakpoint can be sorted in arbitrary order. */
10239 if (a
->owner
->number
!= b
->owner
->number
)
10240 return (a
->owner
->number
> b
->owner
->number
)
10241 - (a
->owner
->number
< b
->owner
->number
);
10243 return (a
> b
) - (a
< b
);
10246 /* Set bp_location_placed_address_before_address_max and
10247 bp_location_shadow_len_after_address_max according to the current
10248 content of the bp_location array. */
10251 bp_location_target_extensions_update (void)
10253 struct bp_location
*bl
, **blp_tmp
;
10255 bp_location_placed_address_before_address_max
= 0;
10256 bp_location_shadow_len_after_address_max
= 0;
10258 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10260 CORE_ADDR start
, end
, addr
;
10262 if (!bp_location_has_shadow (bl
))
10265 start
= bl
->target_info
.placed_address
;
10266 end
= start
+ bl
->target_info
.shadow_len
;
10268 gdb_assert (bl
->address
>= start
);
10269 addr
= bl
->address
- start
;
10270 if (addr
> bp_location_placed_address_before_address_max
)
10271 bp_location_placed_address_before_address_max
= addr
;
10273 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10275 gdb_assert (bl
->address
< end
);
10276 addr
= end
- bl
->address
;
10277 if (addr
> bp_location_shadow_len_after_address_max
)
10278 bp_location_shadow_len_after_address_max
= addr
;
10282 /* Swap the insertion/duplication state between two locations. */
10285 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10287 const int left_inserted
= left
->inserted
;
10288 const int left_duplicate
= left
->duplicate
;
10289 const struct bp_target_info left_target_info
= left
->target_info
;
10291 left
->inserted
= right
->inserted
;
10292 left
->duplicate
= right
->duplicate
;
10293 left
->target_info
= right
->target_info
;
10294 right
->inserted
= left_inserted
;
10295 right
->duplicate
= left_duplicate
;
10296 right
->target_info
= left_target_info
;
10299 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10300 into the inferior, only remove already-inserted locations that no
10301 longer should be inserted. Functions that delete a breakpoint or
10302 breakpoints should pass false, so that deleting a breakpoint
10303 doesn't have the side effect of inserting the locations of other
10304 breakpoints that are marked not-inserted, but should_be_inserted
10305 returns true on them.
10307 This behaviour is useful is situations close to tear-down -- e.g.,
10308 after an exec, while the target still has execution, but breakpoint
10309 shadows of the previous executable image should *NOT* be restored
10310 to the new image; or before detaching, where the target still has
10311 execution and wants to delete breakpoints from GDB's lists, and all
10312 breakpoints had already been removed from the inferior. */
10315 update_global_location_list (int should_insert
)
10317 struct breakpoint
*b
;
10318 struct bp_location
**locp
, *loc
;
10319 struct cleanup
*cleanups
;
10321 /* Used in the duplicates detection below. When iterating over all
10322 bp_locations, points to the first bp_location of a given address.
10323 Breakpoints and watchpoints of different types are never
10324 duplicates of each other. Keep one pointer for each type of
10325 breakpoint/watchpoint, so we only need to loop over all locations
10327 struct bp_location
*bp_loc_first
; /* breakpoint */
10328 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10329 struct bp_location
*awp_loc_first
; /* access watchpoint */
10330 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10332 /* Saved former bp_location array which we compare against the newly
10333 built bp_location from the current state of ALL_BREAKPOINTS. */
10334 struct bp_location
**old_location
, **old_locp
;
10335 unsigned old_location_count
;
10337 old_location
= bp_location
;
10338 old_location_count
= bp_location_count
;
10339 bp_location
= NULL
;
10340 bp_location_count
= 0;
10341 cleanups
= make_cleanup (xfree
, old_location
);
10343 ALL_BREAKPOINTS (b
)
10344 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10345 bp_location_count
++;
10347 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10348 locp
= bp_location
;
10349 ALL_BREAKPOINTS (b
)
10350 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10352 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10353 bp_location_compare
);
10355 bp_location_target_extensions_update ();
10357 /* Identify bp_location instances that are no longer present in the
10358 new list, and therefore should be freed. Note that it's not
10359 necessary that those locations should be removed from inferior --
10360 if there's another location at the same address (previously
10361 marked as duplicate), we don't need to remove/insert the
10364 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10365 and former bp_location array state respectively. */
10367 locp
= bp_location
;
10368 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10371 struct bp_location
*old_loc
= *old_locp
;
10372 struct bp_location
**loc2p
;
10374 /* Tells if 'old_loc' is found among the new locations. If
10375 not, we have to free it. */
10376 int found_object
= 0;
10377 /* Tells if the location should remain inserted in the target. */
10378 int keep_in_target
= 0;
10381 /* Skip LOCP entries which will definitely never be needed.
10382 Stop either at or being the one matching OLD_LOC. */
10383 while (locp
< bp_location
+ bp_location_count
10384 && (*locp
)->address
< old_loc
->address
)
10388 (loc2p
< bp_location
+ bp_location_count
10389 && (*loc2p
)->address
== old_loc
->address
);
10392 if (*loc2p
== old_loc
)
10399 /* If this location is no longer present, and inserted, look if
10400 there's maybe a new location at the same address. If so,
10401 mark that one inserted, and don't remove this one. This is
10402 needed so that we don't have a time window where a breakpoint
10403 at certain location is not inserted. */
10405 if (old_loc
->inserted
)
10407 /* If the location is inserted now, we might have to remove
10410 if (found_object
&& should_be_inserted (old_loc
))
10412 /* The location is still present in the location list,
10413 and still should be inserted. Don't do anything. */
10414 keep_in_target
= 1;
10418 /* The location is either no longer present, or got
10419 disabled. See if there's another location at the
10420 same address, in which case we don't need to remove
10421 this one from the target. */
10423 /* OLD_LOC comes from existing struct breakpoint. */
10424 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10427 (loc2p
< bp_location
+ bp_location_count
10428 && (*loc2p
)->address
== old_loc
->address
);
10431 struct bp_location
*loc2
= *loc2p
;
10433 if (breakpoint_locations_match (loc2
, old_loc
))
10435 /* Read watchpoint locations are switched to
10436 access watchpoints, if the former are not
10437 supported, but the latter are. */
10438 if (is_hardware_watchpoint (old_loc
->owner
))
10440 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10441 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10444 /* loc2 is a duplicated location. We need to check
10445 if it should be inserted in case it will be
10447 if (loc2
!= old_loc
10448 && unduplicated_should_be_inserted (loc2
))
10450 swap_insertion (old_loc
, loc2
);
10451 keep_in_target
= 1;
10459 if (!keep_in_target
)
10461 if (remove_breakpoint (old_loc
, mark_uninserted
))
10463 /* This is just about all we can do. We could keep
10464 this location on the global list, and try to
10465 remove it next time, but there's no particular
10466 reason why we will succeed next time.
10468 Note that at this point, old_loc->owner is still
10469 valid, as delete_breakpoint frees the breakpoint
10470 only after calling us. */
10471 printf_filtered (_("warning: Error removing "
10472 "breakpoint %d\n"),
10473 old_loc
->owner
->number
);
10481 if (removed
&& non_stop
10482 && breakpoint_address_is_meaningful (old_loc
->owner
)
10483 && !is_hardware_watchpoint (old_loc
->owner
))
10485 /* This location was removed from the target. In
10486 non-stop mode, a race condition is possible where
10487 we've removed a breakpoint, but stop events for that
10488 breakpoint are already queued and will arrive later.
10489 We apply an heuristic to be able to distinguish such
10490 SIGTRAPs from other random SIGTRAPs: we keep this
10491 breakpoint location for a bit, and will retire it
10492 after we see some number of events. The theory here
10493 is that reporting of events should, "on the average",
10494 be fair, so after a while we'll see events from all
10495 threads that have anything of interest, and no longer
10496 need to keep this breakpoint location around. We
10497 don't hold locations forever so to reduce chances of
10498 mistaking a non-breakpoint SIGTRAP for a breakpoint
10501 The heuristic failing can be disastrous on
10502 decr_pc_after_break targets.
10504 On decr_pc_after_break targets, like e.g., x86-linux,
10505 if we fail to recognize a late breakpoint SIGTRAP,
10506 because events_till_retirement has reached 0 too
10507 soon, we'll fail to do the PC adjustment, and report
10508 a random SIGTRAP to the user. When the user resumes
10509 the inferior, it will most likely immediately crash
10510 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10511 corrupted, because of being resumed e.g., in the
10512 middle of a multi-byte instruction, or skipped a
10513 one-byte instruction. This was actually seen happen
10514 on native x86-linux, and should be less rare on
10515 targets that do not support new thread events, like
10516 remote, due to the heuristic depending on
10519 Mistaking a random SIGTRAP for a breakpoint trap
10520 causes similar symptoms (PC adjustment applied when
10521 it shouldn't), but then again, playing with SIGTRAPs
10522 behind the debugger's back is asking for trouble.
10524 Since hardware watchpoint traps are always
10525 distinguishable from other traps, so we don't need to
10526 apply keep hardware watchpoint moribund locations
10527 around. We simply always ignore hardware watchpoint
10528 traps we can no longer explain. */
10530 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10531 old_loc
->owner
= NULL
;
10533 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10537 old_loc
->owner
= NULL
;
10538 decref_bp_location (&old_loc
);
10543 /* Rescan breakpoints at the same address and section, marking the
10544 first one as "first" and any others as "duplicates". This is so
10545 that the bpt instruction is only inserted once. If we have a
10546 permanent breakpoint at the same place as BPT, make that one the
10547 official one, and the rest as duplicates. Permanent breakpoints
10548 are sorted first for the same address.
10550 Do the same for hardware watchpoints, but also considering the
10551 watchpoint's type (regular/access/read) and length. */
10553 bp_loc_first
= NULL
;
10554 wp_loc_first
= NULL
;
10555 awp_loc_first
= NULL
;
10556 rwp_loc_first
= NULL
;
10557 ALL_BP_LOCATIONS (loc
, locp
)
10559 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10561 struct breakpoint
*b
= loc
->owner
;
10562 struct bp_location
**loc_first_p
;
10564 if (b
->enable_state
== bp_disabled
10565 || b
->enable_state
== bp_call_disabled
10566 || b
->enable_state
== bp_startup_disabled
10568 || loc
->shlib_disabled
10569 || !breakpoint_address_is_meaningful (b
)
10570 || is_tracepoint (b
))
10573 /* Permanent breakpoint should always be inserted. */
10574 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10575 internal_error (__FILE__
, __LINE__
,
10576 _("allegedly permanent breakpoint is not "
10577 "actually inserted"));
10579 if (b
->type
== bp_hardware_watchpoint
)
10580 loc_first_p
= &wp_loc_first
;
10581 else if (b
->type
== bp_read_watchpoint
)
10582 loc_first_p
= &rwp_loc_first
;
10583 else if (b
->type
== bp_access_watchpoint
)
10584 loc_first_p
= &awp_loc_first
;
10586 loc_first_p
= &bp_loc_first
;
10588 if (*loc_first_p
== NULL
10589 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10590 || !breakpoint_locations_match (loc
, *loc_first_p
))
10592 *loc_first_p
= loc
;
10593 loc
->duplicate
= 0;
10598 /* This and the above ensure the invariant that the first location
10599 is not duplicated, and is the inserted one.
10600 All following are marked as duplicated, and are not inserted. */
10602 swap_insertion (loc
, *loc_first_p
);
10603 loc
->duplicate
= 1;
10605 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10606 && b
->enable_state
!= bp_permanent
)
10607 internal_error (__FILE__
, __LINE__
,
10608 _("another breakpoint was inserted on top of "
10609 "a permanent breakpoint"));
10612 if (breakpoints_always_inserted_mode () && should_insert
10613 && (have_live_inferiors ()
10614 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10615 insert_breakpoint_locations ();
10617 do_cleanups (cleanups
);
10621 breakpoint_retire_moribund (void)
10623 struct bp_location
*loc
;
10626 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10627 if (--(loc
->events_till_retirement
) == 0)
10629 decref_bp_location (&loc
);
10630 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10636 update_global_location_list_nothrow (int inserting
)
10638 struct gdb_exception e
;
10640 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10641 update_global_location_list (inserting
);
10644 /* Clear BKP from a BPS. */
10647 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10651 for (bs
= bps
; bs
; bs
= bs
->next
)
10652 if (bs
->breakpoint_at
== bpt
)
10654 bs
->breakpoint_at
= NULL
;
10655 bs
->old_val
= NULL
;
10656 /* bs->commands will be freed later. */
10660 /* Callback for iterate_over_threads. */
10662 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10664 struct breakpoint
*bpt
= data
;
10666 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10670 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10674 say_where (struct breakpoint
*b
)
10676 struct ui_out
*uiout
= current_uiout
;
10677 struct value_print_options opts
;
10679 get_user_print_options (&opts
);
10681 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10683 if (b
->loc
== NULL
)
10685 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10689 if (opts
.addressprint
|| b
->source_file
== NULL
)
10691 printf_filtered (" at ");
10692 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10695 if (b
->source_file
)
10696 printf_filtered (": file %s, line %d.",
10697 b
->source_file
, b
->line_number
);
10701 struct bp_location
*loc
= b
->loc
;
10703 for (; loc
; loc
= loc
->next
)
10705 printf_filtered (" (%d locations)", n
);
10710 /* Default bp_location_ops methods. */
10713 bp_location_dtor (struct bp_location
*self
)
10715 xfree (self
->cond
);
10716 xfree (self
->function_name
);
10719 static const struct bp_location_ops bp_location_ops
=
10724 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10728 base_breakpoint_dtor (struct breakpoint
*self
)
10730 decref_counted_command_line (&self
->commands
);
10731 xfree (self
->cond_string
);
10732 xfree (self
->addr_string
);
10733 xfree (self
->addr_string_range_end
);
10734 xfree (self
->source_file
);
10737 static struct bp_location
*
10738 base_breakpoint_allocate_location (struct breakpoint
*self
)
10740 struct bp_location
*loc
;
10742 loc
= XNEW (struct bp_location
);
10743 init_bp_location (loc
, &bp_location_ops
, self
);
10748 base_breakpoint_re_set (struct breakpoint
*b
)
10750 /* Nothing to re-set. */
10753 #define internal_error_pure_virtual_called() \
10754 gdb_assert_not_reached ("pure virtual function called")
10757 base_breakpoint_insert_location (struct bp_location
*bl
)
10759 internal_error_pure_virtual_called ();
10763 base_breakpoint_remove_location (struct bp_location
*bl
)
10765 internal_error_pure_virtual_called ();
10769 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10770 struct address_space
*aspace
,
10773 internal_error_pure_virtual_called ();
10777 base_breakpoint_check_status (bpstat bs
)
10782 /* A "works_in_software_mode" breakpoint_ops method that just internal
10786 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10788 internal_error_pure_virtual_called ();
10791 /* A "resources_needed" breakpoint_ops method that just internal
10795 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10797 internal_error_pure_virtual_called ();
10800 static enum print_stop_action
10801 base_breakpoint_print_it (bpstat bs
)
10803 internal_error_pure_virtual_called ();
10807 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10808 struct ui_out
*uiout
)
10814 base_breakpoint_print_mention (struct breakpoint
*b
)
10816 internal_error_pure_virtual_called ();
10820 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10822 internal_error_pure_virtual_called ();
10825 static struct breakpoint_ops base_breakpoint_ops
=
10827 base_breakpoint_dtor
,
10828 base_breakpoint_allocate_location
,
10829 base_breakpoint_re_set
,
10830 base_breakpoint_insert_location
,
10831 base_breakpoint_remove_location
,
10832 base_breakpoint_breakpoint_hit
,
10833 base_breakpoint_check_status
,
10834 base_breakpoint_resources_needed
,
10835 base_breakpoint_works_in_software_mode
,
10836 base_breakpoint_print_it
,
10838 base_breakpoint_print_one_detail
,
10839 base_breakpoint_print_mention
,
10840 base_breakpoint_print_recreate
10843 /* Default breakpoint_ops methods. */
10846 bkpt_re_set (struct breakpoint
*b
)
10848 /* Do not attempt to re-set breakpoints disabled during startup. */
10849 if (b
->enable_state
== bp_startup_disabled
)
10852 /* FIXME: is this still reachable? */
10853 if (b
->addr_string
== NULL
)
10855 /* Anything without a string can't be re-set. */
10856 delete_breakpoint (b
);
10860 breakpoint_re_set_default (b
);
10864 bkpt_insert_location (struct bp_location
*bl
)
10866 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10867 return target_insert_hw_breakpoint (bl
->gdbarch
,
10870 return target_insert_breakpoint (bl
->gdbarch
,
10875 bkpt_remove_location (struct bp_location
*bl
)
10877 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10878 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10880 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10884 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10885 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10887 struct breakpoint
*b
= bl
->owner
;
10889 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10893 if (overlay_debugging
/* unmapped overlay section */
10894 && section_is_overlay (bl
->section
)
10895 && !section_is_mapped (bl
->section
))
10902 bkpt_resources_needed (const struct bp_location
*bl
)
10904 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10909 static enum print_stop_action
10910 bkpt_print_it (bpstat bs
)
10912 struct breakpoint
*b
;
10913 const struct bp_location
*bl
;
10915 struct ui_out
*uiout
= current_uiout
;
10917 gdb_assert (bs
->bp_location_at
!= NULL
);
10919 bl
= bs
->bp_location_at
;
10920 b
= bs
->breakpoint_at
;
10922 bp_temp
= b
->disposition
== disp_del
;
10923 if (bl
->address
!= bl
->requested_address
)
10924 breakpoint_adjustment_warning (bl
->requested_address
,
10927 annotate_breakpoint (b
->number
);
10929 ui_out_text (uiout
, "\nTemporary breakpoint ");
10931 ui_out_text (uiout
, "\nBreakpoint ");
10932 if (ui_out_is_mi_like_p (uiout
))
10934 ui_out_field_string (uiout
, "reason",
10935 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10936 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10938 ui_out_field_int (uiout
, "bkptno", b
->number
);
10939 ui_out_text (uiout
, ", ");
10941 return PRINT_SRC_AND_LOC
;
10945 bkpt_print_mention (struct breakpoint
*b
)
10947 if (ui_out_is_mi_like_p (current_uiout
))
10952 case bp_breakpoint
:
10953 case bp_gnu_ifunc_resolver
:
10954 if (b
->disposition
== disp_del
)
10955 printf_filtered (_("Temporary breakpoint"));
10957 printf_filtered (_("Breakpoint"));
10958 printf_filtered (_(" %d"), b
->number
);
10959 if (b
->type
== bp_gnu_ifunc_resolver
)
10960 printf_filtered (_(" at gnu-indirect-function resolver"));
10962 case bp_hardware_breakpoint
:
10963 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
10971 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
10973 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10974 fprintf_unfiltered (fp
, "tbreak");
10975 else if (tp
->type
== bp_breakpoint
)
10976 fprintf_unfiltered (fp
, "break");
10977 else if (tp
->type
== bp_hardware_breakpoint
10978 && tp
->disposition
== disp_del
)
10979 fprintf_unfiltered (fp
, "thbreak");
10980 else if (tp
->type
== bp_hardware_breakpoint
)
10981 fprintf_unfiltered (fp
, "hbreak");
10983 internal_error (__FILE__
, __LINE__
,
10984 _("unhandled breakpoint type %d"), (int) tp
->type
);
10986 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10989 /* Virtual table for internal breakpoints. */
10992 internal_bkpt_re_set (struct breakpoint
*b
)
10996 /* Delete overlay event and longjmp master breakpoints; they
10997 will be reset later by breakpoint_re_set. */
10998 case bp_overlay_event
:
10999 case bp_longjmp_master
:
11000 case bp_std_terminate_master
:
11001 case bp_exception_master
:
11002 delete_breakpoint (b
);
11005 /* This breakpoint is special, it's set up when the inferior
11006 starts and we really don't want to touch it. */
11007 case bp_shlib_event
:
11009 /* Like bp_shlib_event, this breakpoint type is special. Once
11010 it is set up, we do not want to touch it. */
11011 case bp_thread_event
:
11017 internal_bkpt_check_status (bpstat bs
)
11019 /* We do not stop for these. */
11023 static enum print_stop_action
11024 internal_bkpt_print_it (bpstat bs
)
11026 struct breakpoint
*b
;
11028 b
= bs
->breakpoint_at
;
11032 case bp_shlib_event
:
11033 /* Did we stop because the user set the stop_on_solib_events
11034 variable? (If so, we report this as a generic, "Stopped due
11035 to shlib event" message.) */
11036 printf_filtered (_("Stopped due to shared library event\n"));
11039 case bp_thread_event
:
11040 /* Not sure how we will get here.
11041 GDB should not stop for these breakpoints. */
11042 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11045 case bp_overlay_event
:
11046 /* By analogy with the thread event, GDB should not stop for these. */
11047 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11050 case bp_longjmp_master
:
11051 /* These should never be enabled. */
11052 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11055 case bp_std_terminate_master
:
11056 /* These should never be enabled. */
11057 printf_filtered (_("std::terminate Master Breakpoint: "
11058 "gdb should not stop!\n"));
11061 case bp_exception_master
:
11062 /* These should never be enabled. */
11063 printf_filtered (_("Exception Master Breakpoint: "
11064 "gdb should not stop!\n"));
11068 return PRINT_NOTHING
;
11072 internal_bkpt_print_mention (struct breakpoint
*b
)
11074 /* Nothing to mention. These breakpoints are internal. */
11077 /* Virtual table for momentary breakpoints */
11080 momentary_bkpt_re_set (struct breakpoint
*b
)
11082 /* Keep temporary breakpoints, which can be encountered when we step
11083 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11084 Otherwise these should have been blown away via the cleanup chain
11085 or by breakpoint_init_inferior when we rerun the executable. */
11089 momentary_bkpt_check_status (bpstat bs
)
11091 /* Nothing. The point of these breakpoints is causing a stop. */
11094 static enum print_stop_action
11095 momentary_bkpt_print_it (bpstat bs
)
11097 struct ui_out
*uiout
= current_uiout
;
11099 if (ui_out_is_mi_like_p (uiout
))
11101 struct breakpoint
*b
= bs
->breakpoint_at
;
11106 ui_out_field_string
11108 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11112 ui_out_field_string
11114 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11119 return PRINT_UNKNOWN
;
11123 momentary_bkpt_print_mention (struct breakpoint
*b
)
11125 /* Nothing to mention. These breakpoints are internal. */
11128 /* The breakpoint_ops structure to be used in tracepoints. */
11131 tracepoint_re_set (struct breakpoint
*b
)
11133 breakpoint_re_set_default (b
);
11137 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11138 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11140 /* By definition, the inferior does not report stops at
11146 tracepoint_print_one_detail (const struct breakpoint
*self
,
11147 struct ui_out
*uiout
)
11149 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11150 if (tp
->static_trace_marker_id
)
11152 gdb_assert (self
->type
== bp_static_tracepoint
);
11154 ui_out_text (uiout
, "\tmarker id is ");
11155 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11156 tp
->static_trace_marker_id
);
11157 ui_out_text (uiout
, "\n");
11162 tracepoint_print_mention (struct breakpoint
*b
)
11164 if (ui_out_is_mi_like_p (current_uiout
))
11169 case bp_tracepoint
:
11170 printf_filtered (_("Tracepoint"));
11171 printf_filtered (_(" %d"), b
->number
);
11173 case bp_fast_tracepoint
:
11174 printf_filtered (_("Fast tracepoint"));
11175 printf_filtered (_(" %d"), b
->number
);
11177 case bp_static_tracepoint
:
11178 printf_filtered (_("Static tracepoint"));
11179 printf_filtered (_(" %d"), b
->number
);
11182 internal_error (__FILE__
, __LINE__
,
11183 _("unhandled tracepoint type %d"), (int) b
->type
);
11190 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11192 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11194 if (self
->type
== bp_fast_tracepoint
)
11195 fprintf_unfiltered (fp
, "ftrace");
11196 if (self
->type
== bp_static_tracepoint
)
11197 fprintf_unfiltered (fp
, "strace");
11198 else if (self
->type
== bp_tracepoint
)
11199 fprintf_unfiltered (fp
, "trace");
11201 internal_error (__FILE__
, __LINE__
,
11202 _("unhandled tracepoint type %d"), (int) self
->type
);
11204 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11205 print_recreate_thread (self
, fp
);
11207 if (tp
->pass_count
)
11208 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11211 struct breakpoint_ops tracepoint_breakpoint_ops
;
11213 /* Delete a breakpoint and clean up all traces of it in the data
11217 delete_breakpoint (struct breakpoint
*bpt
)
11219 struct breakpoint
*b
;
11221 gdb_assert (bpt
!= NULL
);
11223 /* Has this bp already been deleted? This can happen because
11224 multiple lists can hold pointers to bp's. bpstat lists are
11227 One example of this happening is a watchpoint's scope bp. When
11228 the scope bp triggers, we notice that the watchpoint is out of
11229 scope, and delete it. We also delete its scope bp. But the
11230 scope bp is marked "auto-deleting", and is already on a bpstat.
11231 That bpstat is then checked for auto-deleting bp's, which are
11234 A real solution to this problem might involve reference counts in
11235 bp's, and/or giving them pointers back to their referencing
11236 bpstat's, and teaching delete_breakpoint to only free a bp's
11237 storage when no more references were extent. A cheaper bandaid
11239 if (bpt
->type
== bp_none
)
11242 /* At least avoid this stale reference until the reference counting
11243 of breakpoints gets resolved. */
11244 if (bpt
->related_breakpoint
!= bpt
)
11246 struct breakpoint
*related
;
11247 struct watchpoint
*w
;
11249 if (bpt
->type
== bp_watchpoint_scope
)
11250 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11251 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11252 w
= (struct watchpoint
*) bpt
;
11256 watchpoint_del_at_next_stop (w
);
11258 /* Unlink bpt from the bpt->related_breakpoint ring. */
11259 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11260 related
= related
->related_breakpoint
);
11261 related
->related_breakpoint
= bpt
->related_breakpoint
;
11262 bpt
->related_breakpoint
= bpt
;
11265 /* watch_command_1 creates a watchpoint but only sets its number if
11266 update_watchpoint succeeds in creating its bp_locations. If there's
11267 a problem in that process, we'll be asked to delete the half-created
11268 watchpoint. In that case, don't announce the deletion. */
11270 observer_notify_breakpoint_deleted (bpt
);
11272 if (breakpoint_chain
== bpt
)
11273 breakpoint_chain
= bpt
->next
;
11275 ALL_BREAKPOINTS (b
)
11276 if (b
->next
== bpt
)
11278 b
->next
= bpt
->next
;
11282 /* Be sure no bpstat's are pointing at the breakpoint after it's
11284 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11285 in all threads for now. Note that we cannot just remove bpstats
11286 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11287 commands are associated with the bpstat; if we remove it here,
11288 then the later call to bpstat_do_actions (&stop_bpstat); in
11289 event-top.c won't do anything, and temporary breakpoints with
11290 commands won't work. */
11292 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11294 /* Now that breakpoint is removed from breakpoint list, update the
11295 global location list. This will remove locations that used to
11296 belong to this breakpoint. Do this before freeing the breakpoint
11297 itself, since remove_breakpoint looks at location's owner. It
11298 might be better design to have location completely
11299 self-contained, but it's not the case now. */
11300 update_global_location_list (0);
11302 bpt
->ops
->dtor (bpt
);
11303 /* On the chance that someone will soon try again to delete this
11304 same bp, we mark it as deleted before freeing its storage. */
11305 bpt
->type
= bp_none
;
11310 do_delete_breakpoint_cleanup (void *b
)
11312 delete_breakpoint (b
);
11316 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11318 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11321 /* Iterator function to call a user-provided callback function once
11322 for each of B and its related breakpoints. */
11325 iterate_over_related_breakpoints (struct breakpoint
*b
,
11326 void (*function
) (struct breakpoint
*,
11330 struct breakpoint
*related
;
11335 struct breakpoint
*next
;
11337 /* FUNCTION may delete RELATED. */
11338 next
= related
->related_breakpoint
;
11340 if (next
== related
)
11342 /* RELATED is the last ring entry. */
11343 function (related
, data
);
11345 /* FUNCTION may have deleted it, so we'd never reach back to
11346 B. There's nothing left to do anyway, so just break
11351 function (related
, data
);
11355 while (related
!= b
);
11359 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11361 delete_breakpoint (b
);
11364 /* A callback for map_breakpoint_numbers that calls
11365 delete_breakpoint. */
11368 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11370 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11374 delete_command (char *arg
, int from_tty
)
11376 struct breakpoint
*b
, *b_tmp
;
11382 int breaks_to_delete
= 0;
11384 /* Delete all breakpoints if no argument. Do not delete
11385 internal breakpoints, these have to be deleted with an
11386 explicit breakpoint number argument. */
11387 ALL_BREAKPOINTS (b
)
11388 if (user_breakpoint_p (b
))
11390 breaks_to_delete
= 1;
11394 /* Ask user only if there are some breakpoints to delete. */
11396 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11398 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11399 if (user_breakpoint_p (b
))
11400 delete_breakpoint (b
);
11404 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11408 all_locations_are_pending (struct bp_location
*loc
)
11410 for (; loc
; loc
= loc
->next
)
11411 if (!loc
->shlib_disabled
)
11416 /* Subroutine of update_breakpoint_locations to simplify it.
11417 Return non-zero if multiple fns in list LOC have the same name.
11418 Null names are ignored. */
11421 ambiguous_names_p (struct bp_location
*loc
)
11423 struct bp_location
*l
;
11424 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11425 (int (*) (const void *,
11426 const void *)) streq
,
11427 NULL
, xcalloc
, xfree
);
11429 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11432 const char *name
= l
->function_name
;
11434 /* Allow for some names to be NULL, ignore them. */
11438 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11440 /* NOTE: We can assume slot != NULL here because xcalloc never
11444 htab_delete (htab
);
11450 htab_delete (htab
);
11454 /* When symbols change, it probably means the sources changed as well,
11455 and it might mean the static tracepoint markers are no longer at
11456 the same address or line numbers they used to be at last we
11457 checked. Losing your static tracepoints whenever you rebuild is
11458 undesirable. This function tries to resync/rematch gdb static
11459 tracepoints with the markers on the target, for static tracepoints
11460 that have not been set by marker id. Static tracepoint that have
11461 been set by marker id are reset by marker id in breakpoint_re_set.
11464 1) For a tracepoint set at a specific address, look for a marker at
11465 the old PC. If one is found there, assume to be the same marker.
11466 If the name / string id of the marker found is different from the
11467 previous known name, assume that means the user renamed the marker
11468 in the sources, and output a warning.
11470 2) For a tracepoint set at a given line number, look for a marker
11471 at the new address of the old line number. If one is found there,
11472 assume to be the same marker. If the name / string id of the
11473 marker found is different from the previous known name, assume that
11474 means the user renamed the marker in the sources, and output a
11477 3) If a marker is no longer found at the same address or line, it
11478 may mean the marker no longer exists. But it may also just mean
11479 the code changed a bit. Maybe the user added a few lines of code
11480 that made the marker move up or down (in line number terms). Ask
11481 the target for info about the marker with the string id as we knew
11482 it. If found, update line number and address in the matching
11483 static tracepoint. This will get confused if there's more than one
11484 marker with the same ID (possible in UST, although unadvised
11485 precisely because it confuses tools). */
11487 static struct symtab_and_line
11488 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11490 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11491 struct static_tracepoint_marker marker
;
11497 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11499 if (target_static_tracepoint_marker_at (pc
, &marker
))
11501 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11502 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11504 tp
->static_trace_marker_id
, marker
.str_id
);
11506 xfree (tp
->static_trace_marker_id
);
11507 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11508 release_static_tracepoint_marker (&marker
);
11513 /* Old marker wasn't found on target at lineno. Try looking it up
11515 if (!sal
.explicit_pc
11517 && sal
.symtab
!= NULL
11518 && tp
->static_trace_marker_id
!= NULL
)
11520 VEC(static_tracepoint_marker_p
) *markers
;
11523 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11525 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11527 struct symtab_and_line sal
;
11528 struct symbol
*sym
;
11529 struct static_tracepoint_marker
*marker
;
11530 struct ui_out
*uiout
= current_uiout
;
11532 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11534 xfree (tp
->static_trace_marker_id
);
11535 tp
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11537 warning (_("marker for static tracepoint %d (%s) not "
11538 "found at previous line number"),
11539 b
->number
, tp
->static_trace_marker_id
);
11543 sal
.pc
= marker
->address
;
11545 sal
= find_pc_line (marker
->address
, 0);
11546 sym
= find_pc_sect_function (marker
->address
, NULL
);
11547 ui_out_text (uiout
, "Now in ");
11550 ui_out_field_string (uiout
, "func",
11551 SYMBOL_PRINT_NAME (sym
));
11552 ui_out_text (uiout
, " at ");
11554 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11555 ui_out_text (uiout
, ":");
11557 if (ui_out_is_mi_like_p (uiout
))
11559 char *fullname
= symtab_to_fullname (sal
.symtab
);
11562 ui_out_field_string (uiout
, "fullname", fullname
);
11565 ui_out_field_int (uiout
, "line", sal
.line
);
11566 ui_out_text (uiout
, "\n");
11568 b
->line_number
= sal
.line
;
11570 xfree (b
->source_file
);
11572 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11574 b
->source_file
= NULL
;
11576 xfree (b
->addr_string
);
11577 b
->addr_string
= xstrprintf ("%s:%d",
11578 sal
.symtab
->filename
, b
->line_number
);
11580 /* Might be nice to check if function changed, and warn if
11583 release_static_tracepoint_marker (marker
);
11589 /* Returns 1 iff locations A and B are sufficiently same that
11590 we don't need to report breakpoint as changed. */
11593 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11597 if (a
->address
!= b
->address
)
11600 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11603 if (a
->enabled
!= b
->enabled
)
11610 if ((a
== NULL
) != (b
== NULL
))
11616 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11617 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11618 a ranged breakpoint. */
11621 update_breakpoint_locations (struct breakpoint
*b
,
11622 struct symtabs_and_lines sals
,
11623 struct symtabs_and_lines sals_end
)
11626 struct bp_location
*existing_locations
= b
->loc
;
11628 /* Ranged breakpoints have only one start location and one end location. */
11629 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11631 /* If there's no new locations, and all existing locations are
11632 pending, don't do anything. This optimizes the common case where
11633 all locations are in the same shared library, that was unloaded.
11634 We'd like to retain the location, so that when the library is
11635 loaded again, we don't loose the enabled/disabled status of the
11636 individual locations. */
11637 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11642 for (i
= 0; i
< sals
.nelts
; ++i
)
11644 struct bp_location
*new_loc
=
11645 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11647 /* Reparse conditions, they might contain references to the
11649 if (b
->cond_string
!= NULL
)
11652 struct gdb_exception e
;
11654 s
= b
->cond_string
;
11655 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11657 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11662 warning (_("failed to reevaluate condition "
11663 "for breakpoint %d: %s"),
11664 b
->number
, e
.message
);
11665 new_loc
->enabled
= 0;
11669 if (b
->source_file
!= NULL
)
11670 xfree (b
->source_file
);
11671 if (sals
.sals
[i
].symtab
== NULL
)
11672 b
->source_file
= NULL
;
11674 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11676 if (b
->line_number
== 0)
11677 b
->line_number
= sals
.sals
[i
].line
;
11679 if (sals_end
.nelts
)
11681 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11683 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11687 /* Update locations of permanent breakpoints. */
11688 if (b
->enable_state
== bp_permanent
)
11689 make_breakpoint_permanent (b
);
11691 /* If possible, carry over 'disable' status from existing
11694 struct bp_location
*e
= existing_locations
;
11695 /* If there are multiple breakpoints with the same function name,
11696 e.g. for inline functions, comparing function names won't work.
11697 Instead compare pc addresses; this is just a heuristic as things
11698 may have moved, but in practice it gives the correct answer
11699 often enough until a better solution is found. */
11700 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11702 for (; e
; e
= e
->next
)
11704 if (!e
->enabled
&& e
->function_name
)
11706 struct bp_location
*l
= b
->loc
;
11707 if (have_ambiguous_names
)
11709 for (; l
; l
= l
->next
)
11710 if (breakpoint_locations_match (e
, l
))
11718 for (; l
; l
= l
->next
)
11719 if (l
->function_name
11720 && strcmp (e
->function_name
, l
->function_name
) == 0)
11730 if (!locations_are_equal (existing_locations
, b
->loc
))
11731 observer_notify_breakpoint_modified (b
);
11733 update_global_location_list (1);
11736 /* Find the SaL locations corresponding to the given ADDR_STRING.
11737 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11739 static struct symtabs_and_lines
11740 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11744 struct symtabs_and_lines sals
= {0};
11745 struct gdb_exception e
;
11748 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11750 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11754 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11756 sals
= decode_static_tracepoint_spec (&s
);
11757 if (sals
.nelts
> tp
->static_trace_marker_id_idx
)
11759 sals
.sals
[0] = sals
.sals
[tp
->static_trace_marker_id_idx
];
11763 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11766 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11770 int not_found_and_ok
= 0;
11771 /* For pending breakpoints, it's expected that parsing will
11772 fail until the right shared library is loaded. User has
11773 already told to create pending breakpoints and don't need
11774 extra messages. If breakpoint is in bp_shlib_disabled
11775 state, then user already saw the message about that
11776 breakpoint being disabled, and don't want to see more
11778 if (e
.error
== NOT_FOUND_ERROR
11779 && (b
->condition_not_parsed
11780 || (b
->loc
&& b
->loc
->shlib_disabled
)
11781 || b
->enable_state
== bp_disabled
))
11782 not_found_and_ok
= 1;
11784 if (!not_found_and_ok
)
11786 /* We surely don't want to warn about the same breakpoint
11787 10 times. One solution, implemented here, is disable
11788 the breakpoint on error. Another solution would be to
11789 have separate 'warning emitted' flag. Since this
11790 happens only when a binary has changed, I don't know
11791 which approach is better. */
11792 b
->enable_state
= bp_disabled
;
11793 throw_exception (e
);
11797 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11799 gdb_assert (sals
.nelts
== 1);
11801 resolve_sal_pc (&sals
.sals
[0]);
11802 if (b
->condition_not_parsed
&& s
&& s
[0])
11804 char *cond_string
= 0;
11808 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11809 &cond_string
, &thread
, &task
);
11811 b
->cond_string
= cond_string
;
11812 b
->thread
= thread
;
11814 b
->condition_not_parsed
= 0;
11817 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11818 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11828 /* The default re_set method, for typical hardware or software
11829 breakpoints. Reevaluate the breakpoint and recreate its
11833 breakpoint_re_set_default (struct breakpoint
*b
)
11836 struct symtabs_and_lines sals
, sals_end
;
11837 struct symtabs_and_lines expanded
= {0};
11838 struct symtabs_and_lines expanded_end
= {0};
11840 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11843 make_cleanup (xfree
, sals
.sals
);
11844 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
11847 if (b
->addr_string_range_end
)
11849 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11852 make_cleanup (xfree
, sals_end
.sals
);
11853 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
11857 update_breakpoint_locations (b
, expanded
, expanded_end
);
11860 /* Prepare the global context for a re-set of breakpoint B. */
11862 static struct cleanup
*
11863 prepare_re_set_context (struct breakpoint
*b
)
11865 struct cleanup
*cleanups
;
11867 input_radix
= b
->input_radix
;
11868 cleanups
= save_current_space_and_thread ();
11869 switch_to_program_space_and_thread (b
->pspace
);
11870 set_language (b
->language
);
11875 /* Reset a breakpoint given it's struct breakpoint * BINT.
11876 The value we return ends up being the return value from catch_errors.
11877 Unused in this case. */
11880 breakpoint_re_set_one (void *bint
)
11882 /* Get past catch_errs. */
11883 struct breakpoint
*b
= (struct breakpoint
*) bint
;
11884 struct cleanup
*cleanups
;
11886 cleanups
= prepare_re_set_context (b
);
11887 b
->ops
->re_set (b
);
11888 do_cleanups (cleanups
);
11892 /* Re-set all breakpoints after symbols have been re-loaded. */
11894 breakpoint_re_set (void)
11896 struct breakpoint
*b
, *b_tmp
;
11897 enum language save_language
;
11898 int save_input_radix
;
11899 struct cleanup
*old_chain
;
11901 save_language
= current_language
->la_language
;
11902 save_input_radix
= input_radix
;
11903 old_chain
= save_current_program_space ();
11905 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11907 /* Format possible error msg. */
11908 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
11910 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
11911 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
11912 do_cleanups (cleanups
);
11914 set_language (save_language
);
11915 input_radix
= save_input_radix
;
11917 jit_breakpoint_re_set ();
11919 do_cleanups (old_chain
);
11921 create_overlay_event_breakpoint ();
11922 create_longjmp_master_breakpoint ();
11923 create_std_terminate_master_breakpoint ();
11924 create_exception_master_breakpoint ();
11927 /* Reset the thread number of this breakpoint:
11929 - If the breakpoint is for all threads, leave it as-is.
11930 - Else, reset it to the current thread for inferior_ptid. */
11932 breakpoint_re_set_thread (struct breakpoint
*b
)
11934 if (b
->thread
!= -1)
11936 if (in_thread_list (inferior_ptid
))
11937 b
->thread
= pid_to_thread_id (inferior_ptid
);
11939 /* We're being called after following a fork. The new fork is
11940 selected as current, and unless this was a vfork will have a
11941 different program space from the original thread. Reset that
11943 b
->loc
->pspace
= current_program_space
;
11947 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11948 If from_tty is nonzero, it prints a message to that effect,
11949 which ends with a period (no newline). */
11952 set_ignore_count (int bptnum
, int count
, int from_tty
)
11954 struct breakpoint
*b
;
11959 ALL_BREAKPOINTS (b
)
11960 if (b
->number
== bptnum
)
11962 if (is_tracepoint (b
))
11964 if (from_tty
&& count
!= 0)
11965 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11970 b
->ignore_count
= count
;
11974 printf_filtered (_("Will stop next time "
11975 "breakpoint %d is reached."),
11977 else if (count
== 1)
11978 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11981 printf_filtered (_("Will ignore next %d "
11982 "crossings of breakpoint %d."),
11985 breakpoints_changed ();
11986 observer_notify_breakpoint_modified (b
);
11990 error (_("No breakpoint number %d."), bptnum
);
11993 /* Command to set ignore-count of breakpoint N to COUNT. */
11996 ignore_command (char *args
, int from_tty
)
12002 error_no_arg (_("a breakpoint number"));
12004 num
= get_number (&p
);
12006 error (_("bad breakpoint number: '%s'"), args
);
12008 error (_("Second argument (specified ignore-count) is missing."));
12010 set_ignore_count (num
,
12011 longest_to_int (value_as_long (parse_and_eval (p
))),
12014 printf_filtered ("\n");
12017 /* Call FUNCTION on each of the breakpoints
12018 whose numbers are given in ARGS. */
12021 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
12026 struct breakpoint
*b
, *tmp
;
12028 struct get_number_or_range_state state
;
12031 error_no_arg (_("one or more breakpoint numbers"));
12033 init_number_or_range (&state
, args
);
12035 while (!state
.finished
)
12037 char *p
= state
.string
;
12041 num
= get_number_or_range (&state
);
12044 warning (_("bad breakpoint number at or near '%s'"), p
);
12048 ALL_BREAKPOINTS_SAFE (b
, tmp
)
12049 if (b
->number
== num
)
12052 function (b
, data
);
12056 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
12061 static struct bp_location
*
12062 find_location_by_number (char *number
)
12064 char *dot
= strchr (number
, '.');
12068 struct breakpoint
*b
;
12069 struct bp_location
*loc
;
12074 bp_num
= get_number (&p1
);
12076 error (_("Bad breakpoint number '%s'"), number
);
12078 ALL_BREAKPOINTS (b
)
12079 if (b
->number
== bp_num
)
12084 if (!b
|| b
->number
!= bp_num
)
12085 error (_("Bad breakpoint number '%s'"), number
);
12088 loc_num
= get_number (&p1
);
12090 error (_("Bad breakpoint location number '%s'"), number
);
12094 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12097 error (_("Bad breakpoint location number '%s'"), dot
+1);
12103 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12104 If from_tty is nonzero, it prints a message to that effect,
12105 which ends with a period (no newline). */
12108 disable_breakpoint (struct breakpoint
*bpt
)
12110 /* Never disable a watchpoint scope breakpoint; we want to
12111 hit them when we leave scope so we can delete both the
12112 watchpoint and its scope breakpoint at that time. */
12113 if (bpt
->type
== bp_watchpoint_scope
)
12116 /* You can't disable permanent breakpoints. */
12117 if (bpt
->enable_state
== bp_permanent
)
12120 bpt
->enable_state
= bp_disabled
;
12122 if (target_supports_enable_disable_tracepoint ()
12123 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12125 struct bp_location
*location
;
12127 for (location
= bpt
->loc
; location
; location
= location
->next
)
12128 target_disable_tracepoint (location
);
12131 update_global_location_list (0);
12133 observer_notify_breakpoint_modified (bpt
);
12136 /* A callback for iterate_over_related_breakpoints. */
12139 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12141 disable_breakpoint (b
);
12144 /* A callback for map_breakpoint_numbers that calls
12145 disable_breakpoint. */
12148 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12150 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12154 disable_command (char *args
, int from_tty
)
12158 struct breakpoint
*bpt
;
12160 ALL_BREAKPOINTS (bpt
)
12161 if (user_breakpoint_p (bpt
))
12162 disable_breakpoint (bpt
);
12164 else if (strchr (args
, '.'))
12166 struct bp_location
*loc
= find_location_by_number (args
);
12170 if (target_supports_enable_disable_tracepoint ()
12171 && current_trace_status ()->running
&& loc
->owner
12172 && is_tracepoint (loc
->owner
))
12173 target_disable_tracepoint (loc
);
12175 update_global_location_list (0);
12178 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12182 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12184 int target_resources_ok
;
12186 if (bpt
->type
== bp_hardware_breakpoint
)
12189 i
= hw_breakpoint_used_count ();
12190 target_resources_ok
=
12191 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12193 if (target_resources_ok
== 0)
12194 error (_("No hardware breakpoint support in the target."));
12195 else if (target_resources_ok
< 0)
12196 error (_("Hardware breakpoints used exceeds limit."));
12199 if (is_watchpoint (bpt
))
12201 /* Initialize it just to avoid a GCC false warning. */
12202 enum enable_state orig_enable_state
= 0;
12203 struct gdb_exception e
;
12205 TRY_CATCH (e
, RETURN_MASK_ALL
)
12207 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12209 orig_enable_state
= bpt
->enable_state
;
12210 bpt
->enable_state
= bp_enabled
;
12211 update_watchpoint (w
, 1 /* reparse */);
12215 bpt
->enable_state
= orig_enable_state
;
12216 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12222 if (bpt
->enable_state
!= bp_permanent
)
12223 bpt
->enable_state
= bp_enabled
;
12225 if (target_supports_enable_disable_tracepoint ()
12226 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12228 struct bp_location
*location
;
12230 for (location
= bpt
->loc
; location
; location
= location
->next
)
12231 target_enable_tracepoint (location
);
12234 bpt
->disposition
= disposition
;
12235 update_global_location_list (1);
12236 breakpoints_changed ();
12238 observer_notify_breakpoint_modified (bpt
);
12243 enable_breakpoint (struct breakpoint
*bpt
)
12245 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12249 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12251 enable_breakpoint (bpt
);
12254 /* A callback for map_breakpoint_numbers that calls
12255 enable_breakpoint. */
12258 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12260 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12263 /* The enable command enables the specified breakpoints (or all defined
12264 breakpoints) so they once again become (or continue to be) effective
12265 in stopping the inferior. */
12268 enable_command (char *args
, int from_tty
)
12272 struct breakpoint
*bpt
;
12274 ALL_BREAKPOINTS (bpt
)
12275 if (user_breakpoint_p (bpt
))
12276 enable_breakpoint (bpt
);
12278 else if (strchr (args
, '.'))
12280 struct bp_location
*loc
= find_location_by_number (args
);
12284 if (target_supports_enable_disable_tracepoint ()
12285 && current_trace_status ()->running
&& loc
->owner
12286 && is_tracepoint (loc
->owner
))
12287 target_enable_tracepoint (loc
);
12289 update_global_location_list (1);
12292 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12296 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12298 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12300 enable_breakpoint_disp (bpt
, disp
);
12304 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12306 enum bpdisp disp
= disp_disable
;
12308 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12312 enable_once_command (char *args
, int from_tty
)
12314 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12318 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12320 enum bpdisp disp
= disp_del
;
12322 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12326 enable_delete_command (char *args
, int from_tty
)
12328 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12332 set_breakpoint_cmd (char *args
, int from_tty
)
12337 show_breakpoint_cmd (char *args
, int from_tty
)
12341 /* Invalidate last known value of any hardware watchpoint if
12342 the memory which that value represents has been written to by
12346 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12347 const bfd_byte
*data
)
12349 struct breakpoint
*bp
;
12351 ALL_BREAKPOINTS (bp
)
12352 if (bp
->enable_state
== bp_enabled
12353 && bp
->type
== bp_hardware_watchpoint
)
12355 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12357 if (wp
->val_valid
&& wp
->val
)
12359 struct bp_location
*loc
;
12361 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12362 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12363 && loc
->address
+ loc
->length
> addr
12364 && addr
+ len
> loc
->address
)
12366 value_free (wp
->val
);
12374 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12376 struct symtabs_and_lines
12377 decode_line_spec_1 (char *string
, int funfirstline
)
12379 struct symtabs_and_lines sals
;
12382 error (_("Empty line specification."));
12383 if (default_breakpoint_valid
)
12384 sals
= decode_line_1 (&string
, funfirstline
,
12385 default_breakpoint_symtab
,
12386 default_breakpoint_line
,
12389 sals
= decode_line_1 (&string
, funfirstline
,
12390 (struct symtab
*) NULL
, 0, NULL
);
12392 error (_("Junk at end of line specification: %s"), string
);
12396 /* Create and insert a raw software breakpoint at PC. Return an
12397 identifier, which should be used to remove the breakpoint later.
12398 In general, places which call this should be using something on the
12399 breakpoint chain instead; this function should be eliminated
12403 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12404 struct address_space
*aspace
, CORE_ADDR pc
)
12406 struct bp_target_info
*bp_tgt
;
12408 bp_tgt
= XZALLOC (struct bp_target_info
);
12410 bp_tgt
->placed_address_space
= aspace
;
12411 bp_tgt
->placed_address
= pc
;
12413 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12415 /* Could not insert the breakpoint. */
12423 /* Remove a breakpoint BP inserted by
12424 deprecated_insert_raw_breakpoint. */
12427 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12429 struct bp_target_info
*bp_tgt
= bp
;
12432 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12438 /* One (or perhaps two) breakpoints used for software single
12441 static void *single_step_breakpoints
[2];
12442 static struct gdbarch
*single_step_gdbarch
[2];
12444 /* Create and insert a breakpoint for software single step. */
12447 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12448 struct address_space
*aspace
,
12453 if (single_step_breakpoints
[0] == NULL
)
12455 bpt_p
= &single_step_breakpoints
[0];
12456 single_step_gdbarch
[0] = gdbarch
;
12460 gdb_assert (single_step_breakpoints
[1] == NULL
);
12461 bpt_p
= &single_step_breakpoints
[1];
12462 single_step_gdbarch
[1] = gdbarch
;
12465 /* NOTE drow/2006-04-11: A future improvement to this function would
12466 be to only create the breakpoints once, and actually put them on
12467 the breakpoint chain. That would let us use set_raw_breakpoint.
12468 We could adjust the addresses each time they were needed. Doing
12469 this requires corresponding changes elsewhere where single step
12470 breakpoints are handled, however. So, for now, we use this. */
12472 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12473 if (*bpt_p
== NULL
)
12474 error (_("Could not insert single-step breakpoint at %s"),
12475 paddress (gdbarch
, next_pc
));
12478 /* Check if the breakpoints used for software single stepping
12479 were inserted or not. */
12482 single_step_breakpoints_inserted (void)
12484 return (single_step_breakpoints
[0] != NULL
12485 || single_step_breakpoints
[1] != NULL
);
12488 /* Remove and delete any breakpoints used for software single step. */
12491 remove_single_step_breakpoints (void)
12493 gdb_assert (single_step_breakpoints
[0] != NULL
);
12495 /* See insert_single_step_breakpoint for more about this deprecated
12497 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12498 single_step_breakpoints
[0]);
12499 single_step_gdbarch
[0] = NULL
;
12500 single_step_breakpoints
[0] = NULL
;
12502 if (single_step_breakpoints
[1] != NULL
)
12504 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12505 single_step_breakpoints
[1]);
12506 single_step_gdbarch
[1] = NULL
;
12507 single_step_breakpoints
[1] = NULL
;
12511 /* Delete software single step breakpoints without removing them from
12512 the inferior. This is intended to be used if the inferior's address
12513 space where they were inserted is already gone, e.g. after exit or
12517 cancel_single_step_breakpoints (void)
12521 for (i
= 0; i
< 2; i
++)
12522 if (single_step_breakpoints
[i
])
12524 xfree (single_step_breakpoints
[i
]);
12525 single_step_breakpoints
[i
] = NULL
;
12526 single_step_gdbarch
[i
] = NULL
;
12530 /* Detach software single-step breakpoints from INFERIOR_PTID without
12534 detach_single_step_breakpoints (void)
12538 for (i
= 0; i
< 2; i
++)
12539 if (single_step_breakpoints
[i
])
12540 target_remove_breakpoint (single_step_gdbarch
[i
],
12541 single_step_breakpoints
[i
]);
12544 /* Check whether a software single-step breakpoint is inserted at
12548 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12553 for (i
= 0; i
< 2; i
++)
12555 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12557 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12558 bp_tgt
->placed_address
,
12566 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12567 non-zero otherwise. */
12569 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12571 if (syscall_catchpoint_p (bp
)
12572 && bp
->enable_state
!= bp_disabled
12573 && bp
->enable_state
!= bp_call_disabled
)
12580 catch_syscall_enabled (void)
12582 struct inferior
*inf
= current_inferior ();
12584 return inf
->total_syscalls_count
!= 0;
12588 catching_syscall_number (int syscall_number
)
12590 struct breakpoint
*bp
;
12592 ALL_BREAKPOINTS (bp
)
12593 if (is_syscall_catchpoint_enabled (bp
))
12595 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12597 if (c
->syscalls_to_be_caught
)
12601 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12603 if (syscall_number
== iter
)
12613 /* Complete syscall names. Used by "catch syscall". */
12615 catch_syscall_completer (struct cmd_list_element
*cmd
,
12616 char *text
, char *word
)
12618 const char **list
= get_syscall_names ();
12620 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12626 /* Tracepoint-specific operations. */
12628 /* Set tracepoint count to NUM. */
12630 set_tracepoint_count (int num
)
12632 tracepoint_count
= num
;
12633 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12637 trace_command (char *arg
, int from_tty
)
12639 if (create_breakpoint (get_current_arch (),
12641 NULL
, 0, 1 /* parse arg */,
12643 bp_tracepoint
/* type_wanted */,
12644 0 /* Ignore count */,
12645 pending_break_support
,
12646 &tracepoint_breakpoint_ops
,
12650 set_tracepoint_count (breakpoint_count
);
12654 ftrace_command (char *arg
, int from_tty
)
12656 if (create_breakpoint (get_current_arch (),
12658 NULL
, 0, 1 /* parse arg */,
12660 bp_fast_tracepoint
/* type_wanted */,
12661 0 /* Ignore count */,
12662 pending_break_support
,
12663 &tracepoint_breakpoint_ops
,
12667 set_tracepoint_count (breakpoint_count
);
12670 /* strace command implementation. Creates a static tracepoint. */
12673 strace_command (char *arg
, int from_tty
)
12675 if (create_breakpoint (get_current_arch (),
12677 NULL
, 0, 1 /* parse arg */,
12679 bp_static_tracepoint
/* type_wanted */,
12680 0 /* Ignore count */,
12681 pending_break_support
,
12682 &tracepoint_breakpoint_ops
,
12686 set_tracepoint_count (breakpoint_count
);
12689 /* Set up a fake reader function that gets command lines from a linked
12690 list that was acquired during tracepoint uploading. */
12692 static struct uploaded_tp
*this_utp
;
12693 static int next_cmd
;
12696 read_uploaded_action (void)
12700 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12707 /* Given information about a tracepoint as recorded on a target (which
12708 can be either a live system or a trace file), attempt to create an
12709 equivalent GDB tracepoint. This is not a reliable process, since
12710 the target does not necessarily have all the information used when
12711 the tracepoint was originally defined. */
12713 struct tracepoint
*
12714 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12716 char *addr_str
, small_buf
[100];
12717 struct tracepoint
*tp
;
12719 if (utp
->at_string
)
12720 addr_str
= utp
->at_string
;
12723 /* In the absence of a source location, fall back to raw
12724 address. Since there is no way to confirm that the address
12725 means the same thing as when the trace was started, warn the
12727 warning (_("Uploaded tracepoint %d has no "
12728 "source location, using raw address"),
12730 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12731 addr_str
= small_buf
;
12734 /* There's not much we can do with a sequence of bytecodes. */
12735 if (utp
->cond
&& !utp
->cond_string
)
12736 warning (_("Uploaded tracepoint %d condition "
12737 "has no source form, ignoring it"),
12740 if (!create_breakpoint (get_current_arch (),
12742 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12744 utp
->type
/* type_wanted */,
12745 0 /* Ignore count */,
12746 pending_break_support
,
12747 &tracepoint_breakpoint_ops
,
12749 utp
->enabled
/* enabled */,
12753 set_tracepoint_count (breakpoint_count
);
12755 /* Get the tracepoint we just created. */
12756 tp
= get_tracepoint (tracepoint_count
);
12757 gdb_assert (tp
!= NULL
);
12761 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
12763 trace_pass_command (small_buf
, 0);
12766 /* If we have uploaded versions of the original commands, set up a
12767 special-purpose "reader" function and call the usual command line
12768 reader, then pass the result to the breakpoint command-setting
12770 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12772 struct command_line
*cmd_list
;
12777 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12779 breakpoint_set_commands (&tp
->base
, cmd_list
);
12781 else if (!VEC_empty (char_ptr
, utp
->actions
)
12782 || !VEC_empty (char_ptr
, utp
->step_actions
))
12783 warning (_("Uploaded tracepoint %d actions "
12784 "have no source form, ignoring them"),
12790 /* Print information on tracepoint number TPNUM_EXP, or all if
12794 tracepoints_info (char *args
, int from_tty
)
12796 struct ui_out
*uiout
= current_uiout
;
12799 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12801 if (num_printed
== 0)
12803 if (args
== NULL
|| *args
== '\0')
12804 ui_out_message (uiout
, 0, "No tracepoints.\n");
12806 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12809 default_collect_info ();
12812 /* The 'enable trace' command enables tracepoints.
12813 Not supported by all targets. */
12815 enable_trace_command (char *args
, int from_tty
)
12817 enable_command (args
, from_tty
);
12820 /* The 'disable trace' command disables tracepoints.
12821 Not supported by all targets. */
12823 disable_trace_command (char *args
, int from_tty
)
12825 disable_command (args
, from_tty
);
12828 /* Remove a tracepoint (or all if no argument). */
12830 delete_trace_command (char *arg
, int from_tty
)
12832 struct breakpoint
*b
, *b_tmp
;
12838 int breaks_to_delete
= 0;
12840 /* Delete all breakpoints if no argument.
12841 Do not delete internal or call-dummy breakpoints, these
12842 have to be deleted with an explicit breakpoint number
12844 ALL_TRACEPOINTS (b
)
12845 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12847 breaks_to_delete
= 1;
12851 /* Ask user only if there are some breakpoints to delete. */
12853 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12855 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12856 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12857 delete_breakpoint (b
);
12861 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12864 /* Helper function for trace_pass_command. */
12867 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
12869 tp
->pass_count
= count
;
12870 observer_notify_tracepoint_modified (tp
->base
.number
);
12872 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12873 tp
->base
.number
, count
);
12876 /* Set passcount for tracepoint.
12878 First command argument is passcount, second is tracepoint number.
12879 If tracepoint number omitted, apply to most recently defined.
12880 Also accepts special argument "all". */
12883 trace_pass_command (char *args
, int from_tty
)
12885 struct tracepoint
*t1
;
12886 unsigned int count
;
12888 if (args
== 0 || *args
== 0)
12889 error (_("passcount command requires an "
12890 "argument (count + optional TP num)"));
12892 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
12894 while (*args
&& isspace ((int) *args
))
12897 if (*args
&& strncasecmp (args
, "all", 3) == 0)
12899 struct breakpoint
*b
;
12901 args
+= 3; /* Skip special argument "all". */
12903 error (_("Junk at end of arguments."));
12905 ALL_TRACEPOINTS (b
)
12907 t1
= (struct tracepoint
*) b
;
12908 trace_pass_set_count (t1
, count
, from_tty
);
12911 else if (*args
== '\0')
12913 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
12915 trace_pass_set_count (t1
, count
, from_tty
);
12919 struct get_number_or_range_state state
;
12921 init_number_or_range (&state
, args
);
12922 while (!state
.finished
)
12924 t1
= get_tracepoint_by_number (&args
, &state
, 1);
12926 trace_pass_set_count (t1
, count
, from_tty
);
12931 struct tracepoint
*
12932 get_tracepoint (int num
)
12934 struct breakpoint
*t
;
12936 ALL_TRACEPOINTS (t
)
12937 if (t
->number
== num
)
12938 return (struct tracepoint
*) t
;
12943 /* Find the tracepoint with the given target-side number (which may be
12944 different from the tracepoint number after disconnecting and
12947 struct tracepoint
*
12948 get_tracepoint_by_number_on_target (int num
)
12950 struct breakpoint
*b
;
12952 ALL_TRACEPOINTS (b
)
12954 struct tracepoint
*t
= (struct tracepoint
*) b
;
12956 if (t
->number_on_target
== num
)
12963 /* Utility: parse a tracepoint number and look it up in the list.
12964 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12965 If OPTIONAL_P is true, then if the argument is missing, the most
12966 recent tracepoint (tracepoint_count) is returned. */
12967 struct tracepoint
*
12968 get_tracepoint_by_number (char **arg
,
12969 struct get_number_or_range_state
*state
,
12972 extern int tracepoint_count
;
12973 struct breakpoint
*t
;
12975 char *instring
= arg
== NULL
? NULL
: *arg
;
12979 gdb_assert (!state
->finished
);
12980 tpnum
= get_number_or_range (state
);
12982 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
12985 tpnum
= tracepoint_count
;
12987 error_no_arg (_("tracepoint number"));
12990 tpnum
= get_number (arg
);
12994 if (instring
&& *instring
)
12995 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12998 printf_filtered (_("Tracepoint argument missing "
12999 "and no previous tracepoint\n"));
13003 ALL_TRACEPOINTS (t
)
13004 if (t
->number
== tpnum
)
13006 return (struct tracepoint
*) t
;
13009 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
13014 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
13016 if (b
->thread
!= -1)
13017 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
13020 fprintf_unfiltered (fp
, " task %d", b
->task
);
13022 fprintf_unfiltered (fp
, "\n");
13025 /* Save information on user settable breakpoints (watchpoints, etc) to
13026 a new script file named FILENAME. If FILTER is non-NULL, call it
13027 on each breakpoint and only include the ones for which it returns
13031 save_breakpoints (char *filename
, int from_tty
,
13032 int (*filter
) (const struct breakpoint
*))
13034 struct breakpoint
*tp
;
13037 struct cleanup
*cleanup
;
13038 struct ui_file
*fp
;
13039 int extra_trace_bits
= 0;
13041 if (filename
== 0 || *filename
== 0)
13042 error (_("Argument required (file name in which to save)"));
13044 /* See if we have anything to save. */
13045 ALL_BREAKPOINTS (tp
)
13047 /* Skip internal and momentary breakpoints. */
13048 if (!user_breakpoint_p (tp
))
13051 /* If we have a filter, only save the breakpoints it accepts. */
13052 if (filter
&& !filter (tp
))
13057 if (is_tracepoint (tp
))
13059 extra_trace_bits
= 1;
13061 /* We can stop searching. */
13068 warning (_("Nothing to save."));
13072 pathname
= tilde_expand (filename
);
13073 cleanup
= make_cleanup (xfree
, pathname
);
13074 fp
= gdb_fopen (pathname
, "w");
13076 error (_("Unable to open file '%s' for saving (%s)"),
13077 filename
, safe_strerror (errno
));
13078 make_cleanup_ui_file_delete (fp
);
13080 if (extra_trace_bits
)
13081 save_trace_state_variables (fp
);
13083 ALL_BREAKPOINTS (tp
)
13085 /* Skip internal and momentary breakpoints. */
13086 if (!user_breakpoint_p (tp
))
13089 /* If we have a filter, only save the breakpoints it accepts. */
13090 if (filter
&& !filter (tp
))
13093 tp
->ops
->print_recreate (tp
, fp
);
13095 /* Note, we can't rely on tp->number for anything, as we can't
13096 assume the recreated breakpoint numbers will match. Use $bpnum
13099 if (tp
->cond_string
)
13100 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13102 if (tp
->ignore_count
)
13103 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13107 volatile struct gdb_exception ex
;
13109 fprintf_unfiltered (fp
, " commands\n");
13111 ui_out_redirect (current_uiout
, fp
);
13112 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13114 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
13116 ui_out_redirect (current_uiout
, NULL
);
13119 throw_exception (ex
);
13121 fprintf_unfiltered (fp
, " end\n");
13124 if (tp
->enable_state
== bp_disabled
)
13125 fprintf_unfiltered (fp
, "disable\n");
13127 /* If this is a multi-location breakpoint, check if the locations
13128 should be individually disabled. Watchpoint locations are
13129 special, and not user visible. */
13130 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13132 struct bp_location
*loc
;
13135 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13137 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13141 if (extra_trace_bits
&& *default_collect
)
13142 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13144 do_cleanups (cleanup
);
13146 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13149 /* The `save breakpoints' command. */
13152 save_breakpoints_command (char *args
, int from_tty
)
13154 save_breakpoints (args
, from_tty
, NULL
);
13157 /* The `save tracepoints' command. */
13160 save_tracepoints_command (char *args
, int from_tty
)
13162 save_breakpoints (args
, from_tty
, is_tracepoint
);
13165 /* Create a vector of all tracepoints. */
13167 VEC(breakpoint_p
) *
13168 all_tracepoints (void)
13170 VEC(breakpoint_p
) *tp_vec
= 0;
13171 struct breakpoint
*tp
;
13173 ALL_TRACEPOINTS (tp
)
13175 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13182 /* This help string is used for the break, hbreak, tbreak and thbreak
13183 commands. It is defined as a macro to prevent duplication.
13184 COMMAND should be a string constant containing the name of the
13186 #define BREAK_ARGS_HELP(command) \
13187 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13188 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13189 If a line number is specified, break at start of code for that line.\n\
13190 If a function is specified, break at start of code for that function.\n\
13191 If an address is specified, break at that exact address.\n\
13192 With no LOCATION, uses current execution address of the selected\n\
13193 stack frame. This is useful for breaking on return to a stack frame.\n\
13195 THREADNUM is the number from \"info threads\".\n\
13196 CONDITION is a boolean expression.\n\
13198 Multiple breakpoints at one place are permitted, and useful if their\n\
13199 conditions are different.\n\
13201 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13203 /* List of subcommands for "catch". */
13204 static struct cmd_list_element
*catch_cmdlist
;
13206 /* List of subcommands for "tcatch". */
13207 static struct cmd_list_element
*tcatch_cmdlist
;
13210 add_catch_command (char *name
, char *docstring
,
13211 void (*sfunc
) (char *args
, int from_tty
,
13212 struct cmd_list_element
*command
),
13213 char **(*completer
) (struct cmd_list_element
*cmd
,
13214 char *text
, char *word
),
13215 void *user_data_catch
,
13216 void *user_data_tcatch
)
13218 struct cmd_list_element
*command
;
13220 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13222 set_cmd_sfunc (command
, sfunc
);
13223 set_cmd_context (command
, user_data_catch
);
13224 set_cmd_completer (command
, completer
);
13226 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13228 set_cmd_sfunc (command
, sfunc
);
13229 set_cmd_context (command
, user_data_tcatch
);
13230 set_cmd_completer (command
, completer
);
13234 clear_syscall_counts (struct inferior
*inf
)
13236 inf
->total_syscalls_count
= 0;
13237 inf
->any_syscall_count
= 0;
13238 VEC_free (int, inf
->syscalls_counts
);
13242 save_command (char *arg
, int from_tty
)
13244 printf_unfiltered (_("\"save\" must be followed by "
13245 "the name of a save subcommand.\n"));
13246 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13249 struct breakpoint
*
13250 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13253 struct breakpoint
*b
, *b_tmp
;
13255 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13257 if ((*callback
) (b
, data
))
13265 initialize_breakpoint_ops (void)
13267 static int initialized
= 0;
13269 struct breakpoint_ops
*ops
;
13275 /* The breakpoint_ops structure to be inherit by all kinds of
13276 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13277 internal and momentary breakpoints, etc.). */
13278 ops
= &bkpt_base_breakpoint_ops
;
13279 *ops
= base_breakpoint_ops
;
13280 ops
->re_set
= bkpt_re_set
;
13281 ops
->insert_location
= bkpt_insert_location
;
13282 ops
->remove_location
= bkpt_remove_location
;
13283 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13285 /* The breakpoint_ops structure to be used in regular breakpoints. */
13286 ops
= &bkpt_breakpoint_ops
;
13287 *ops
= bkpt_base_breakpoint_ops
;
13288 ops
->re_set
= bkpt_re_set
;
13289 ops
->resources_needed
= bkpt_resources_needed
;
13290 ops
->print_it
= bkpt_print_it
;
13291 ops
->print_mention
= bkpt_print_mention
;
13292 ops
->print_recreate
= bkpt_print_recreate
;
13294 /* Ranged breakpoints. */
13295 ops
= &ranged_breakpoint_ops
;
13296 *ops
= bkpt_breakpoint_ops
;
13297 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13298 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13299 ops
->print_it
= print_it_ranged_breakpoint
;
13300 ops
->print_one
= print_one_ranged_breakpoint
;
13301 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13302 ops
->print_mention
= print_mention_ranged_breakpoint
;
13303 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13305 /* Internal breakpoints. */
13306 ops
= &internal_breakpoint_ops
;
13307 *ops
= bkpt_base_breakpoint_ops
;
13308 ops
->re_set
= internal_bkpt_re_set
;
13309 ops
->check_status
= internal_bkpt_check_status
;
13310 ops
->print_it
= internal_bkpt_print_it
;
13311 ops
->print_mention
= internal_bkpt_print_mention
;
13313 /* Momentary breakpoints. */
13314 ops
= &momentary_breakpoint_ops
;
13315 *ops
= bkpt_base_breakpoint_ops
;
13316 ops
->re_set
= momentary_bkpt_re_set
;
13317 ops
->check_status
= momentary_bkpt_check_status
;
13318 ops
->print_it
= momentary_bkpt_print_it
;
13319 ops
->print_mention
= momentary_bkpt_print_mention
;
13321 /* GNU v3 exception catchpoints. */
13322 ops
= &gnu_v3_exception_catchpoint_ops
;
13323 *ops
= bkpt_breakpoint_ops
;
13324 ops
->print_it
= print_it_exception_catchpoint
;
13325 ops
->print_one
= print_one_exception_catchpoint
;
13326 ops
->print_mention
= print_mention_exception_catchpoint
;
13327 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13330 ops
= &watchpoint_breakpoint_ops
;
13331 *ops
= base_breakpoint_ops
;
13332 ops
->dtor
= dtor_watchpoint
;
13333 ops
->re_set
= re_set_watchpoint
;
13334 ops
->insert_location
= insert_watchpoint
;
13335 ops
->remove_location
= remove_watchpoint
;
13336 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13337 ops
->check_status
= check_status_watchpoint
;
13338 ops
->resources_needed
= resources_needed_watchpoint
;
13339 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13340 ops
->print_it
= print_it_watchpoint
;
13341 ops
->print_mention
= print_mention_watchpoint
;
13342 ops
->print_recreate
= print_recreate_watchpoint
;
13344 /* Masked watchpoints. */
13345 ops
= &masked_watchpoint_breakpoint_ops
;
13346 *ops
= watchpoint_breakpoint_ops
;
13347 ops
->insert_location
= insert_masked_watchpoint
;
13348 ops
->remove_location
= remove_masked_watchpoint
;
13349 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13350 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13351 ops
->print_it
= print_it_masked_watchpoint
;
13352 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13353 ops
->print_mention
= print_mention_masked_watchpoint
;
13354 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13357 ops
= &tracepoint_breakpoint_ops
;
13358 *ops
= base_breakpoint_ops
;
13359 ops
->re_set
= tracepoint_re_set
;
13360 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13361 ops
->print_one_detail
= tracepoint_print_one_detail
;
13362 ops
->print_mention
= tracepoint_print_mention
;
13363 ops
->print_recreate
= tracepoint_print_recreate
;
13365 /* Fork catchpoints. */
13366 ops
= &catch_fork_breakpoint_ops
;
13367 *ops
= base_breakpoint_ops
;
13368 ops
->insert_location
= insert_catch_fork
;
13369 ops
->remove_location
= remove_catch_fork
;
13370 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13371 ops
->print_it
= print_it_catch_fork
;
13372 ops
->print_one
= print_one_catch_fork
;
13373 ops
->print_mention
= print_mention_catch_fork
;
13374 ops
->print_recreate
= print_recreate_catch_fork
;
13376 /* Vfork catchpoints. */
13377 ops
= &catch_vfork_breakpoint_ops
;
13378 *ops
= base_breakpoint_ops
;
13379 ops
->insert_location
= insert_catch_vfork
;
13380 ops
->remove_location
= remove_catch_vfork
;
13381 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13382 ops
->print_it
= print_it_catch_vfork
;
13383 ops
->print_one
= print_one_catch_vfork
;
13384 ops
->print_mention
= print_mention_catch_vfork
;
13385 ops
->print_recreate
= print_recreate_catch_vfork
;
13387 /* Exec catchpoints. */
13388 ops
= &catch_exec_breakpoint_ops
;
13389 *ops
= base_breakpoint_ops
;
13390 ops
->dtor
= dtor_catch_exec
;
13391 ops
->insert_location
= insert_catch_exec
;
13392 ops
->remove_location
= remove_catch_exec
;
13393 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13394 ops
->print_it
= print_it_catch_exec
;
13395 ops
->print_one
= print_one_catch_exec
;
13396 ops
->print_mention
= print_mention_catch_exec
;
13397 ops
->print_recreate
= print_recreate_catch_exec
;
13399 /* Syscall catchpoints. */
13400 ops
= &catch_syscall_breakpoint_ops
;
13401 *ops
= base_breakpoint_ops
;
13402 ops
->dtor
= dtor_catch_syscall
;
13403 ops
->insert_location
= insert_catch_syscall
;
13404 ops
->remove_location
= remove_catch_syscall
;
13405 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13406 ops
->print_it
= print_it_catch_syscall
;
13407 ops
->print_one
= print_one_catch_syscall
;
13408 ops
->print_mention
= print_mention_catch_syscall
;
13409 ops
->print_recreate
= print_recreate_catch_syscall
;
13413 _initialize_breakpoint (void)
13415 struct cmd_list_element
*c
;
13417 initialize_breakpoint_ops ();
13419 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13420 observer_attach_inferior_exit (clear_syscall_counts
);
13421 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13423 breakpoint_objfile_key
= register_objfile_data ();
13425 breakpoint_chain
= 0;
13426 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13427 before a breakpoint is set. */
13428 breakpoint_count
= 0;
13430 tracepoint_count
= 0;
13432 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13433 Set ignore-count of breakpoint number N to COUNT.\n\
13434 Usage is `ignore N COUNT'."));
13436 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13438 add_com ("commands", class_breakpoint
, commands_command
, _("\
13439 Set commands to be executed when a breakpoint is hit.\n\
13440 Give breakpoint number as argument after \"commands\".\n\
13441 With no argument, the targeted breakpoint is the last one set.\n\
13442 The commands themselves follow starting on the next line.\n\
13443 Type a line containing \"end\" to indicate the end of them.\n\
13444 Give \"silent\" as the first line to make the breakpoint silent;\n\
13445 then no output is printed when it is hit, except what the commands print."));
13447 add_com ("condition", class_breakpoint
, condition_command
, _("\
13448 Specify breakpoint number N to break only if COND is true.\n\
13449 Usage is `condition N COND', where N is an integer and COND is an\n\
13450 expression to be evaluated whenever breakpoint N is reached."));
13452 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13453 Set a temporary breakpoint.\n\
13454 Like \"break\" except the breakpoint is only temporary,\n\
13455 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13456 by using \"enable delete\" on the breakpoint number.\n\
13458 BREAK_ARGS_HELP ("tbreak")));
13459 set_cmd_completer (c
, location_completer
);
13461 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13462 Set a hardware assisted breakpoint.\n\
13463 Like \"break\" except the breakpoint requires hardware support,\n\
13464 some target hardware may not have this support.\n\
13466 BREAK_ARGS_HELP ("hbreak")));
13467 set_cmd_completer (c
, location_completer
);
13469 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13470 Set a temporary hardware assisted breakpoint.\n\
13471 Like \"hbreak\" except the breakpoint is only temporary,\n\
13472 so it will be deleted when hit.\n\
13474 BREAK_ARGS_HELP ("thbreak")));
13475 set_cmd_completer (c
, location_completer
);
13477 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13478 Enable some breakpoints.\n\
13479 Give breakpoint numbers (separated by spaces) as arguments.\n\
13480 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13481 This is used to cancel the effect of the \"disable\" command.\n\
13482 With a subcommand you can enable temporarily."),
13483 &enablelist
, "enable ", 1, &cmdlist
);
13485 add_com ("ab", class_breakpoint
, enable_command
, _("\
13486 Enable some breakpoints.\n\
13487 Give breakpoint numbers (separated by spaces) as arguments.\n\
13488 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13489 This is used to cancel the effect of the \"disable\" command.\n\
13490 With a subcommand you can enable temporarily."));
13492 add_com_alias ("en", "enable", class_breakpoint
, 1);
13494 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13495 Enable some breakpoints.\n\
13496 Give breakpoint numbers (separated by spaces) as arguments.\n\
13497 This is used to cancel the effect of the \"disable\" command.\n\
13498 May be abbreviated to simply \"enable\".\n"),
13499 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13501 add_cmd ("once", no_class
, enable_once_command
, _("\
13502 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13503 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13506 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13507 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13508 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13511 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13512 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13513 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13516 add_cmd ("once", no_class
, enable_once_command
, _("\
13517 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13518 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13521 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13522 Disable some breakpoints.\n\
13523 Arguments are breakpoint numbers with spaces in between.\n\
13524 To disable all breakpoints, give no argument.\n\
13525 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13526 &disablelist
, "disable ", 1, &cmdlist
);
13527 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13528 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13530 add_com ("sb", class_breakpoint
, disable_command
, _("\
13531 Disable some breakpoints.\n\
13532 Arguments are breakpoint numbers with spaces in between.\n\
13533 To disable all breakpoints, give no argument.\n\
13534 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13536 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13537 Disable some breakpoints.\n\
13538 Arguments are breakpoint numbers with spaces in between.\n\
13539 To disable all breakpoints, give no argument.\n\
13540 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13541 This command may be abbreviated \"disable\"."),
13544 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13545 Delete some breakpoints or auto-display expressions.\n\
13546 Arguments are breakpoint numbers with spaces in between.\n\
13547 To delete all breakpoints, give no argument.\n\
13549 Also a prefix command for deletion of other GDB objects.\n\
13550 The \"unset\" command is also an alias for \"delete\"."),
13551 &deletelist
, "delete ", 1, &cmdlist
);
13552 add_com_alias ("d", "delete", class_breakpoint
, 1);
13553 add_com_alias ("del", "delete", class_breakpoint
, 1);
13555 add_com ("db", class_breakpoint
, delete_command
, _("\
13556 Delete some breakpoints.\n\
13557 Arguments are breakpoint numbers with spaces in between.\n\
13558 To delete all breakpoints, give no argument.\n"));
13560 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13561 Delete some breakpoints or auto-display expressions.\n\
13562 Arguments are breakpoint numbers with spaces in between.\n\
13563 To delete all breakpoints, give no argument.\n\
13564 This command may be abbreviated \"delete\"."),
13567 add_com ("clear", class_breakpoint
, clear_command
, _("\
13568 Clear breakpoint at specified line or function.\n\
13569 Argument may be line number, function name, or \"*\" and an address.\n\
13570 If line number is specified, all breakpoints in that line are cleared.\n\
13571 If function is specified, breakpoints at beginning of function are cleared.\n\
13572 If an address is specified, breakpoints at that address are cleared.\n\
13574 With no argument, clears all breakpoints in the line that the selected frame\n\
13575 is executing in.\n\
13577 See also the \"delete\" command which clears breakpoints by number."));
13578 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13580 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13581 Set breakpoint at specified line or function.\n"
13582 BREAK_ARGS_HELP ("break")));
13583 set_cmd_completer (c
, location_completer
);
13585 add_com_alias ("b", "break", class_run
, 1);
13586 add_com_alias ("br", "break", class_run
, 1);
13587 add_com_alias ("bre", "break", class_run
, 1);
13588 add_com_alias ("brea", "break", class_run
, 1);
13591 add_com_alias ("ba", "break", class_breakpoint
, 1);
13595 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13596 Break in function/address or break at a line in the current file."),
13597 &stoplist
, "stop ", 1, &cmdlist
);
13598 add_cmd ("in", class_breakpoint
, stopin_command
,
13599 _("Break in function or address."), &stoplist
);
13600 add_cmd ("at", class_breakpoint
, stopat_command
,
13601 _("Break at a line in the current file."), &stoplist
);
13602 add_com ("status", class_info
, breakpoints_info
, _("\
13603 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13604 The \"Type\" column indicates one of:\n\
13605 \tbreakpoint - normal breakpoint\n\
13606 \twatchpoint - watchpoint\n\
13607 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13608 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13609 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13610 address and file/line number respectively.\n\
13612 Convenience variable \"$_\" and default examine address for \"x\"\n\
13613 are set to the address of the last breakpoint listed unless the command\n\
13614 is prefixed with \"server \".\n\n\
13615 Convenience variable \"$bpnum\" contains the number of the last\n\
13616 breakpoint set."));
13619 add_info ("breakpoints", breakpoints_info
, _("\
13620 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13621 The \"Type\" column indicates one of:\n\
13622 \tbreakpoint - normal breakpoint\n\
13623 \twatchpoint - watchpoint\n\
13624 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13625 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13626 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13627 address and file/line number respectively.\n\
13629 Convenience variable \"$_\" and default examine address for \"x\"\n\
13630 are set to the address of the last breakpoint listed unless the command\n\
13631 is prefixed with \"server \".\n\n\
13632 Convenience variable \"$bpnum\" contains the number of the last\n\
13633 breakpoint set."));
13635 add_info_alias ("b", "breakpoints", 1);
13638 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13639 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13640 The \"Type\" column indicates one of:\n\
13641 \tbreakpoint - normal breakpoint\n\
13642 \twatchpoint - watchpoint\n\
13643 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13644 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13645 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13646 address and file/line number respectively.\n\
13648 Convenience variable \"$_\" and default examine address for \"x\"\n\
13649 are set to the address of the last breakpoint listed unless the command\n\
13650 is prefixed with \"server \".\n\n\
13651 Convenience variable \"$bpnum\" contains the number of the last\n\
13652 breakpoint set."));
13654 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13655 Status of all breakpoints, or breakpoint number NUMBER.\n\
13656 The \"Type\" column indicates one of:\n\
13657 \tbreakpoint - normal breakpoint\n\
13658 \twatchpoint - watchpoint\n\
13659 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13660 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13661 \tuntil - internal breakpoint used by the \"until\" command\n\
13662 \tfinish - internal breakpoint used by the \"finish\" command\n\
13663 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13664 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13665 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13666 address and file/line number respectively.\n\
13668 Convenience variable \"$_\" and default examine address for \"x\"\n\
13669 are set to the address of the last breakpoint listed unless the command\n\
13670 is prefixed with \"server \".\n\n\
13671 Convenience variable \"$bpnum\" contains the number of the last\n\
13673 &maintenanceinfolist
);
13675 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13676 Set catchpoints to catch events."),
13677 &catch_cmdlist
, "catch ",
13678 0/*allow-unknown*/, &cmdlist
);
13680 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13681 Set temporary catchpoints to catch events."),
13682 &tcatch_cmdlist
, "tcatch ",
13683 0/*allow-unknown*/, &cmdlist
);
13685 /* Add catch and tcatch sub-commands. */
13686 add_catch_command ("catch", _("\
13687 Catch an exception, when caught.\n\
13688 With an argument, catch only exceptions with the given name."),
13689 catch_catch_command
,
13693 add_catch_command ("throw", _("\
13694 Catch an exception, when thrown.\n\
13695 With an argument, catch only exceptions with the given name."),
13696 catch_throw_command
,
13700 add_catch_command ("fork", _("Catch calls to fork."),
13701 catch_fork_command_1
,
13703 (void *) (uintptr_t) catch_fork_permanent
,
13704 (void *) (uintptr_t) catch_fork_temporary
);
13705 add_catch_command ("vfork", _("Catch calls to vfork."),
13706 catch_fork_command_1
,
13708 (void *) (uintptr_t) catch_vfork_permanent
,
13709 (void *) (uintptr_t) catch_vfork_temporary
);
13710 add_catch_command ("exec", _("Catch calls to exec."),
13711 catch_exec_command_1
,
13715 add_catch_command ("syscall", _("\
13716 Catch system calls by their names and/or numbers.\n\
13717 Arguments say which system calls to catch. If no arguments\n\
13718 are given, every system call will be caught.\n\
13719 Arguments, if given, should be one or more system call names\n\
13720 (if your system supports that), or system call numbers."),
13721 catch_syscall_command_1
,
13722 catch_syscall_completer
,
13726 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13727 Set a watchpoint for an expression.\n\
13728 Usage: watch [-l|-location] EXPRESSION\n\
13729 A watchpoint stops execution of your program whenever the value of\n\
13730 an expression changes.\n\
13731 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13732 the memory to which it refers."));
13733 set_cmd_completer (c
, expression_completer
);
13735 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13736 Set a read watchpoint for an expression.\n\
13737 Usage: rwatch [-l|-location] EXPRESSION\n\
13738 A watchpoint stops execution of your program whenever the value of\n\
13739 an expression is read.\n\
13740 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13741 the memory to which it refers."));
13742 set_cmd_completer (c
, expression_completer
);
13744 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13745 Set a watchpoint for an expression.\n\
13746 Usage: awatch [-l|-location] EXPRESSION\n\
13747 A watchpoint stops execution of your program whenever the value of\n\
13748 an expression is either read or written.\n\
13749 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13750 the memory to which it refers."));
13751 set_cmd_completer (c
, expression_completer
);
13753 add_info ("watchpoints", watchpoints_info
, _("\
13754 Status of specified watchpoints (all watchpoints if no argument)."));
13756 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13757 respond to changes - contrary to the description. */
13758 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13759 &can_use_hw_watchpoints
, _("\
13760 Set debugger's willingness to use watchpoint hardware."), _("\
13761 Show debugger's willingness to use watchpoint hardware."), _("\
13762 If zero, gdb will not use hardware for new watchpoints, even if\n\
13763 such is available. (However, any hardware watchpoints that were\n\
13764 created before setting this to nonzero, will continue to use watchpoint\n\
13767 show_can_use_hw_watchpoints
,
13768 &setlist
, &showlist
);
13770 can_use_hw_watchpoints
= 1;
13772 /* Tracepoint manipulation commands. */
13774 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13775 Set a tracepoint at specified line or function.\n\
13777 BREAK_ARGS_HELP ("trace") "\n\
13778 Do \"help tracepoints\" for info on other tracepoint commands."));
13779 set_cmd_completer (c
, location_completer
);
13781 add_com_alias ("tp", "trace", class_alias
, 0);
13782 add_com_alias ("tr", "trace", class_alias
, 1);
13783 add_com_alias ("tra", "trace", class_alias
, 1);
13784 add_com_alias ("trac", "trace", class_alias
, 1);
13786 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13787 Set a fast tracepoint at specified line or function.\n\
13789 BREAK_ARGS_HELP ("ftrace") "\n\
13790 Do \"help tracepoints\" for info on other tracepoint commands."));
13791 set_cmd_completer (c
, location_completer
);
13793 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13794 Set a static tracepoint at specified line, function or marker.\n\
13796 strace [LOCATION] [if CONDITION]\n\
13797 LOCATION may be a line number, function name, \"*\" and an address,\n\
13798 or -m MARKER_ID.\n\
13799 If a line number is specified, probe the marker at start of code\n\
13800 for that line. If a function is specified, probe the marker at start\n\
13801 of code for that function. If an address is specified, probe the marker\n\
13802 at that exact address. If a marker id is specified, probe the marker\n\
13803 with that name. With no LOCATION, uses current execution address of\n\
13804 the selected stack frame.\n\
13805 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13806 This collects arbitrary user data passed in the probe point call to the\n\
13807 tracing library. You can inspect it when analyzing the trace buffer,\n\
13808 by printing the $_sdata variable like any other convenience variable.\n\
13810 CONDITION is a boolean expression.\n\
13812 Multiple tracepoints at one place are permitted, and useful if their\n\
13813 conditions are different.\n\
13815 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13816 Do \"help tracepoints\" for info on other tracepoint commands."));
13817 set_cmd_completer (c
, location_completer
);
13819 add_info ("tracepoints", tracepoints_info
, _("\
13820 Status of specified tracepoints (all tracepoints if no argument).\n\
13821 Convenience variable \"$tpnum\" contains the number of the\n\
13822 last tracepoint set."));
13824 add_info_alias ("tp", "tracepoints", 1);
13826 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13827 Delete specified tracepoints.\n\
13828 Arguments are tracepoint numbers, separated by spaces.\n\
13829 No argument means delete all tracepoints."),
13832 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13833 Disable specified tracepoints.\n\
13834 Arguments are tracepoint numbers, separated by spaces.\n\
13835 No argument means disable all tracepoints."),
13837 deprecate_cmd (c
, "disable");
13839 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
13840 Enable specified tracepoints.\n\
13841 Arguments are tracepoint numbers, separated by spaces.\n\
13842 No argument means enable all tracepoints."),
13844 deprecate_cmd (c
, "enable");
13846 add_com ("passcount", class_trace
, trace_pass_command
, _("\
13847 Set the passcount for a tracepoint.\n\
13848 The trace will end when the tracepoint has been passed 'count' times.\n\
13849 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13850 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13852 add_prefix_cmd ("save", class_breakpoint
, save_command
,
13853 _("Save breakpoint definitions as a script."),
13854 &save_cmdlist
, "save ",
13855 0/*allow-unknown*/, &cmdlist
);
13857 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
13858 Save current breakpoint definitions as a script.\n\
13859 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13860 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13861 session to restore them."),
13863 set_cmd_completer (c
, filename_completer
);
13865 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
13866 Save current tracepoint definitions as a script.\n\
13867 Use the 'source' command in another debug session to restore them."),
13869 set_cmd_completer (c
, filename_completer
);
13871 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
13872 deprecate_cmd (c
, "save tracepoints");
13874 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
13875 Breakpoint specific settings\n\
13876 Configure various breakpoint-specific variables such as\n\
13877 pending breakpoint behavior"),
13878 &breakpoint_set_cmdlist
, "set breakpoint ",
13879 0/*allow-unknown*/, &setlist
);
13880 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
13881 Breakpoint specific settings\n\
13882 Configure various breakpoint-specific variables such as\n\
13883 pending breakpoint behavior"),
13884 &breakpoint_show_cmdlist
, "show breakpoint ",
13885 0/*allow-unknown*/, &showlist
);
13887 add_setshow_auto_boolean_cmd ("pending", no_class
,
13888 &pending_break_support
, _("\
13889 Set debugger's behavior regarding pending breakpoints."), _("\
13890 Show debugger's behavior regarding pending breakpoints."), _("\
13891 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13892 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13893 an error. If auto, an unrecognized breakpoint location results in a\n\
13894 user-query to see if a pending breakpoint should be created."),
13896 show_pending_break_support
,
13897 &breakpoint_set_cmdlist
,
13898 &breakpoint_show_cmdlist
);
13900 pending_break_support
= AUTO_BOOLEAN_AUTO
;
13902 add_setshow_boolean_cmd ("auto-hw", no_class
,
13903 &automatic_hardware_breakpoints
, _("\
13904 Set automatic usage of hardware breakpoints."), _("\
13905 Show automatic usage of hardware breakpoints."), _("\
13906 If set, the debugger will automatically use hardware breakpoints for\n\
13907 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13908 a warning will be emitted for such breakpoints."),
13910 show_automatic_hardware_breakpoints
,
13911 &breakpoint_set_cmdlist
,
13912 &breakpoint_show_cmdlist
);
13914 add_setshow_enum_cmd ("always-inserted", class_support
,
13915 always_inserted_enums
, &always_inserted_mode
, _("\
13916 Set mode for inserting breakpoints."), _("\
13917 Show mode for inserting breakpoints."), _("\
13918 When this mode is off, breakpoints are inserted in inferior when it is\n\
13919 resumed, and removed when execution stops. When this mode is on,\n\
13920 breakpoints are inserted immediately and removed only when the user\n\
13921 deletes the breakpoint. When this mode is auto (which is the default),\n\
13922 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13923 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13924 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13925 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13927 &show_always_inserted_mode
,
13928 &breakpoint_set_cmdlist
,
13929 &breakpoint_show_cmdlist
);
13931 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
13932 Set a breakpoint for an address range.\n\
13933 break-range START-LOCATION, END-LOCATION\n\
13934 where START-LOCATION and END-LOCATION can be one of the following:\n\
13935 LINENUM, for that line in the current file,\n\
13936 FILE:LINENUM, for that line in that file,\n\
13937 +OFFSET, for that number of lines after the current line\n\
13938 or the start of the range\n\
13939 FUNCTION, for the first line in that function,\n\
13940 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13941 *ADDRESS, for the instruction at that address.\n\
13943 The breakpoint will stop execution of the inferior whenever it executes\n\
13944 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13945 range (including START-LOCATION and END-LOCATION)."));
13947 automatic_hardware_breakpoints
= 1;
13949 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);