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 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1575 location. Any error messages are printed to TMP_ERROR_STREAM; and
1576 HW_BREAKPOINT_ERROR is used to report problems.
1577 Returns 0 for success, 1 if the bp_location type is not supported or
1580 NOTE drow/2003-09-09: This routine could be broken down to an
1581 object-style method for each breakpoint or catchpoint type. */
1583 insert_bp_location (struct bp_location
*bl
,
1584 struct ui_file
*tmp_error_stream
,
1585 int *hw_breakpoint_error
)
1589 if (!should_be_inserted (bl
) || bl
->inserted
)
1592 /* Initialize the target-specific information. */
1593 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1594 bl
->target_info
.placed_address
= bl
->address
;
1595 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1596 bl
->target_info
.length
= bl
->length
;
1598 if (bl
->loc_type
== bp_loc_software_breakpoint
1599 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1601 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1603 /* If the explicitly specified breakpoint type
1604 is not hardware breakpoint, check the memory map to see
1605 if the breakpoint address is in read only memory or not.
1607 Two important cases are:
1608 - location type is not hardware breakpoint, memory
1609 is readonly. We change the type of the location to
1610 hardware breakpoint.
1611 - location type is hardware breakpoint, memory is
1612 read-write. This means we've previously made the
1613 location hardware one, but then the memory map changed,
1616 When breakpoints are removed, remove_breakpoints will use
1617 location types we've just set here, the only possible
1618 problem is that memory map has changed during running
1619 program, but it's not going to work anyway with current
1621 struct mem_region
*mr
1622 = lookup_mem_region (bl
->target_info
.placed_address
);
1626 if (automatic_hardware_breakpoints
)
1628 enum bp_loc_type new_type
;
1630 if (mr
->attrib
.mode
!= MEM_RW
)
1631 new_type
= bp_loc_hardware_breakpoint
;
1633 new_type
= bp_loc_software_breakpoint
;
1635 if (new_type
!= bl
->loc_type
)
1637 static int said
= 0;
1639 bl
->loc_type
= new_type
;
1642 fprintf_filtered (gdb_stdout
,
1643 _("Note: automatically using "
1644 "hardware breakpoints for "
1645 "read-only addresses.\n"));
1650 else if (bl
->loc_type
== bp_loc_software_breakpoint
1651 && mr
->attrib
.mode
!= MEM_RW
)
1652 warning (_("cannot set software breakpoint "
1653 "at readonly address %s"),
1654 paddress (bl
->gdbarch
, bl
->address
));
1658 /* First check to see if we have to handle an overlay. */
1659 if (overlay_debugging
== ovly_off
1660 || bl
->section
== NULL
1661 || !(section_is_overlay (bl
->section
)))
1663 /* No overlay handling: just set the breakpoint. */
1665 val
= bl
->owner
->ops
->insert_location (bl
);
1669 /* This breakpoint is in an overlay section.
1670 Shall we set a breakpoint at the LMA? */
1671 if (!overlay_events_enabled
)
1673 /* Yes -- overlay event support is not active,
1674 so we must try to set a breakpoint at the LMA.
1675 This will not work for a hardware breakpoint. */
1676 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1677 warning (_("hardware breakpoint %d not supported in overlay!"),
1681 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1683 /* Set a software (trap) breakpoint at the LMA. */
1684 bl
->overlay_target_info
= bl
->target_info
;
1685 bl
->overlay_target_info
.placed_address
= addr
;
1686 val
= target_insert_breakpoint (bl
->gdbarch
,
1687 &bl
->overlay_target_info
);
1689 fprintf_unfiltered (tmp_error_stream
,
1690 "Overlay breakpoint %d "
1691 "failed: in ROM?\n",
1695 /* Shall we set a breakpoint at the VMA? */
1696 if (section_is_mapped (bl
->section
))
1698 /* Yes. This overlay section is mapped into memory. */
1699 val
= bl
->owner
->ops
->insert_location (bl
);
1703 /* No. This breakpoint will not be inserted.
1704 No error, but do not mark the bp as 'inserted'. */
1711 /* Can't set the breakpoint. */
1712 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1714 /* See also: disable_breakpoints_in_shlibs. */
1716 bl
->shlib_disabled
= 1;
1717 observer_notify_breakpoint_modified (bl
->owner
);
1718 fprintf_unfiltered (tmp_error_stream
,
1719 "Cannot insert breakpoint %d.\n",
1721 fprintf_unfiltered (tmp_error_stream
,
1722 "Temporarily disabling shared "
1723 "library breakpoints:\n");
1724 fprintf_unfiltered (tmp_error_stream
,
1725 "breakpoint #%d\n", bl
->owner
->number
);
1729 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1731 *hw_breakpoint_error
= 1;
1732 fprintf_unfiltered (tmp_error_stream
,
1733 "Cannot insert hardware "
1739 fprintf_unfiltered (tmp_error_stream
,
1740 "Cannot insert breakpoint %d.\n",
1742 fprintf_filtered (tmp_error_stream
,
1743 "Error accessing memory address ");
1744 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1746 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1747 safe_strerror (val
));
1758 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1759 /* NOTE drow/2003-09-08: This state only exists for removing
1760 watchpoints. It's not clear that it's necessary... */
1761 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1763 gdb_assert (bl
->owner
->ops
!= NULL
1764 && bl
->owner
->ops
->insert_location
!= NULL
);
1766 val
= bl
->owner
->ops
->insert_location (bl
);
1768 /* If trying to set a read-watchpoint, and it turns out it's not
1769 supported, try emulating one with an access watchpoint. */
1770 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1772 struct bp_location
*loc
, **loc_temp
;
1774 /* But don't try to insert it, if there's already another
1775 hw_access location that would be considered a duplicate
1777 ALL_BP_LOCATIONS (loc
, loc_temp
)
1779 && loc
->watchpoint_type
== hw_access
1780 && watchpoint_locations_match (bl
, loc
))
1784 bl
->target_info
= loc
->target_info
;
1785 bl
->watchpoint_type
= hw_access
;
1792 bl
->watchpoint_type
= hw_access
;
1793 val
= bl
->owner
->ops
->insert_location (bl
);
1796 /* Back to the original value. */
1797 bl
->watchpoint_type
= hw_read
;
1801 bl
->inserted
= (val
== 0);
1804 else if (bl
->owner
->type
== bp_catchpoint
)
1806 gdb_assert (bl
->owner
->ops
!= NULL
1807 && bl
->owner
->ops
->insert_location
!= NULL
);
1809 val
= bl
->owner
->ops
->insert_location (bl
);
1812 bl
->owner
->enable_state
= bp_disabled
;
1816 Error inserting catchpoint %d: Your system does not support this type\n\
1817 of catchpoint."), bl
->owner
->number
);
1819 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1822 bl
->inserted
= (val
== 0);
1824 /* We've already printed an error message if there was a problem
1825 inserting this catchpoint, and we've disabled the catchpoint,
1826 so just return success. */
1833 /* This function is called when program space PSPACE is about to be
1834 deleted. It takes care of updating breakpoints to not reference
1838 breakpoint_program_space_exit (struct program_space
*pspace
)
1840 struct breakpoint
*b
, *b_temp
;
1841 struct bp_location
*loc
, **loc_temp
;
1843 /* Remove any breakpoint that was set through this program space. */
1844 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1846 if (b
->pspace
== pspace
)
1847 delete_breakpoint (b
);
1850 /* Breakpoints set through other program spaces could have locations
1851 bound to PSPACE as well. Remove those. */
1852 ALL_BP_LOCATIONS (loc
, loc_temp
)
1854 struct bp_location
*tmp
;
1856 if (loc
->pspace
== pspace
)
1858 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1859 if (loc
->owner
->loc
== loc
)
1860 loc
->owner
->loc
= loc
->next
;
1862 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1863 if (tmp
->next
== loc
)
1865 tmp
->next
= loc
->next
;
1871 /* Now update the global location list to permanently delete the
1872 removed locations above. */
1873 update_global_location_list (0);
1876 /* Make sure all breakpoints are inserted in inferior.
1877 Throws exception on any error.
1878 A breakpoint that is already inserted won't be inserted
1879 again, so calling this function twice is safe. */
1881 insert_breakpoints (void)
1883 struct breakpoint
*bpt
;
1885 ALL_BREAKPOINTS (bpt
)
1886 if (is_hardware_watchpoint (bpt
))
1888 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1890 update_watchpoint (w
, 0 /* don't reparse. */);
1893 update_global_location_list (1);
1895 /* update_global_location_list does not insert breakpoints when
1896 always_inserted_mode is not enabled. Explicitly insert them
1898 if (!breakpoints_always_inserted_mode ())
1899 insert_breakpoint_locations ();
1902 /* Used when starting or continuing the program. */
1905 insert_breakpoint_locations (void)
1907 struct breakpoint
*bpt
;
1908 struct bp_location
*bl
, **blp_tmp
;
1911 int hw_breakpoint_error
= 0;
1913 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1914 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1916 /* Explicitly mark the warning -- this will only be printed if
1917 there was an error. */
1918 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1920 save_current_space_and_thread ();
1922 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1924 if (!should_be_inserted (bl
) || bl
->inserted
)
1927 /* There is no point inserting thread-specific breakpoints if
1928 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1929 has BL->OWNER always non-NULL. */
1930 if (bl
->owner
->thread
!= -1
1931 && !valid_thread_id (bl
->owner
->thread
))
1934 switch_to_program_space_and_thread (bl
->pspace
);
1936 /* For targets that support global breakpoints, there's no need
1937 to select an inferior to insert breakpoint to. In fact, even
1938 if we aren't attached to any process yet, we should still
1939 insert breakpoints. */
1940 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1941 && ptid_equal (inferior_ptid
, null_ptid
))
1944 val
= insert_bp_location (bl
, tmp_error_stream
,
1945 &hw_breakpoint_error
);
1950 /* If we failed to insert all locations of a watchpoint, remove
1951 them, as half-inserted watchpoint is of limited use. */
1952 ALL_BREAKPOINTS (bpt
)
1954 int some_failed
= 0;
1955 struct bp_location
*loc
;
1957 if (!is_hardware_watchpoint (bpt
))
1960 if (!breakpoint_enabled (bpt
))
1963 if (bpt
->disposition
== disp_del_at_next_stop
)
1966 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1967 if (!loc
->inserted
&& should_be_inserted (loc
))
1974 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1976 remove_breakpoint (loc
, mark_uninserted
);
1978 hw_breakpoint_error
= 1;
1979 fprintf_unfiltered (tmp_error_stream
,
1980 "Could not insert hardware watchpoint %d.\n",
1988 /* If a hardware breakpoint or watchpoint was inserted, add a
1989 message about possibly exhausted resources. */
1990 if (hw_breakpoint_error
)
1992 fprintf_unfiltered (tmp_error_stream
,
1993 "Could not insert hardware breakpoints:\n\
1994 You may have requested too many hardware breakpoints/watchpoints.\n");
1996 target_terminal_ours_for_output ();
1997 error_stream (tmp_error_stream
);
2000 do_cleanups (cleanups
);
2003 /* Used when the program stops.
2004 Returns zero if successful, or non-zero if there was a problem
2005 removing a breakpoint location. */
2008 remove_breakpoints (void)
2010 struct bp_location
*bl
, **blp_tmp
;
2013 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2016 val
|= remove_breakpoint (bl
, mark_uninserted
);
2021 /* Remove breakpoints of process PID. */
2024 remove_breakpoints_pid (int pid
)
2026 struct bp_location
*bl
, **blp_tmp
;
2028 struct inferior
*inf
= find_inferior_pid (pid
);
2030 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2032 if (bl
->pspace
!= inf
->pspace
)
2037 val
= remove_breakpoint (bl
, mark_uninserted
);
2046 reattach_breakpoints (int pid
)
2048 struct cleanup
*old_chain
;
2049 struct bp_location
*bl
, **blp_tmp
;
2051 struct ui_file
*tmp_error_stream
;
2053 struct inferior
*inf
;
2054 struct thread_info
*tp
;
2056 tp
= any_live_thread_of_process (pid
);
2060 inf
= find_inferior_pid (pid
);
2061 old_chain
= save_inferior_ptid ();
2063 inferior_ptid
= tp
->ptid
;
2065 tmp_error_stream
= mem_fileopen ();
2066 make_cleanup_ui_file_delete (tmp_error_stream
);
2068 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2070 if (bl
->pspace
!= inf
->pspace
)
2076 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy
);
2079 do_cleanups (old_chain
);
2084 do_cleanups (old_chain
);
2088 static int internal_breakpoint_number
= -1;
2090 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2091 If INTERNAL is non-zero, the breakpoint number will be populated
2092 from internal_breakpoint_number and that variable decremented.
2093 Otherwise the breakpoint number will be populated from
2094 breakpoint_count and that value incremented. Internal breakpoints
2095 do not set the internal var bpnum. */
2097 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2100 b
->number
= internal_breakpoint_number
--;
2103 set_breakpoint_count (breakpoint_count
+ 1);
2104 b
->number
= breakpoint_count
;
2108 static struct breakpoint
*
2109 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2110 CORE_ADDR address
, enum bptype type
,
2111 const struct breakpoint_ops
*ops
)
2113 struct symtab_and_line sal
;
2114 struct breakpoint
*b
;
2116 init_sal (&sal
); /* Initialize to zeroes. */
2119 sal
.section
= find_pc_overlay (sal
.pc
);
2120 sal
.pspace
= current_program_space
;
2122 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2123 b
->number
= internal_breakpoint_number
--;
2124 b
->disposition
= disp_donttouch
;
2129 static const char *const longjmp_names
[] =
2131 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2133 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2135 /* Per-objfile data private to breakpoint.c. */
2136 struct breakpoint_objfile_data
2138 /* Minimal symbol for "_ovly_debug_event" (if any). */
2139 struct minimal_symbol
*overlay_msym
;
2141 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2142 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2144 /* Minimal symbol for "std::terminate()" (if any). */
2145 struct minimal_symbol
*terminate_msym
;
2147 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2148 struct minimal_symbol
*exception_msym
;
2151 static const struct objfile_data
*breakpoint_objfile_key
;
2153 /* Minimal symbol not found sentinel. */
2154 static struct minimal_symbol msym_not_found
;
2156 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2159 msym_not_found_p (const struct minimal_symbol
*msym
)
2161 return msym
== &msym_not_found
;
2164 /* Return per-objfile data needed by breakpoint.c.
2165 Allocate the data if necessary. */
2167 static struct breakpoint_objfile_data
*
2168 get_breakpoint_objfile_data (struct objfile
*objfile
)
2170 struct breakpoint_objfile_data
*bp_objfile_data
;
2172 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2173 if (bp_objfile_data
== NULL
)
2175 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2176 sizeof (*bp_objfile_data
));
2178 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2179 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2181 return bp_objfile_data
;
2185 create_overlay_event_breakpoint (void)
2187 struct objfile
*objfile
;
2188 const char *const func_name
= "_ovly_debug_event";
2190 ALL_OBJFILES (objfile
)
2192 struct breakpoint
*b
;
2193 struct breakpoint_objfile_data
*bp_objfile_data
;
2196 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2198 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2201 if (bp_objfile_data
->overlay_msym
== NULL
)
2203 struct minimal_symbol
*m
;
2205 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2208 /* Avoid future lookups in this objfile. */
2209 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2212 bp_objfile_data
->overlay_msym
= m
;
2215 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2216 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2218 &internal_breakpoint_ops
);
2219 b
->addr_string
= xstrdup (func_name
);
2221 if (overlay_debugging
== ovly_auto
)
2223 b
->enable_state
= bp_enabled
;
2224 overlay_events_enabled
= 1;
2228 b
->enable_state
= bp_disabled
;
2229 overlay_events_enabled
= 0;
2232 update_global_location_list (1);
2236 create_longjmp_master_breakpoint (void)
2238 struct program_space
*pspace
;
2239 struct cleanup
*old_chain
;
2241 old_chain
= save_current_program_space ();
2243 ALL_PSPACES (pspace
)
2245 struct objfile
*objfile
;
2247 set_current_program_space (pspace
);
2249 ALL_OBJFILES (objfile
)
2252 struct gdbarch
*gdbarch
;
2253 struct breakpoint_objfile_data
*bp_objfile_data
;
2255 gdbarch
= get_objfile_arch (objfile
);
2256 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2259 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2261 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2263 struct breakpoint
*b
;
2264 const char *func_name
;
2267 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2270 func_name
= longjmp_names
[i
];
2271 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2273 struct minimal_symbol
*m
;
2275 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2278 /* Prevent future lookups in this objfile. */
2279 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2282 bp_objfile_data
->longjmp_msym
[i
] = m
;
2285 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2286 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2287 &internal_breakpoint_ops
);
2288 b
->addr_string
= xstrdup (func_name
);
2289 b
->enable_state
= bp_disabled
;
2293 update_global_location_list (1);
2295 do_cleanups (old_chain
);
2298 /* Create a master std::terminate breakpoint. */
2300 create_std_terminate_master_breakpoint (void)
2302 struct program_space
*pspace
;
2303 struct cleanup
*old_chain
;
2304 const char *const func_name
= "std::terminate()";
2306 old_chain
= save_current_program_space ();
2308 ALL_PSPACES (pspace
)
2310 struct objfile
*objfile
;
2313 set_current_program_space (pspace
);
2315 ALL_OBJFILES (objfile
)
2317 struct breakpoint
*b
;
2318 struct breakpoint_objfile_data
*bp_objfile_data
;
2320 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2322 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2325 if (bp_objfile_data
->terminate_msym
== NULL
)
2327 struct minimal_symbol
*m
;
2329 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2330 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2331 && MSYMBOL_TYPE (m
) != mst_file_text
))
2333 /* Prevent future lookups in this objfile. */
2334 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2337 bp_objfile_data
->terminate_msym
= m
;
2340 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2341 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2342 bp_std_terminate_master
,
2343 &internal_breakpoint_ops
);
2344 b
->addr_string
= xstrdup (func_name
);
2345 b
->enable_state
= bp_disabled
;
2349 update_global_location_list (1);
2351 do_cleanups (old_chain
);
2354 /* Install a master breakpoint on the unwinder's debug hook. */
2357 create_exception_master_breakpoint (void)
2359 struct objfile
*objfile
;
2360 const char *const func_name
= "_Unwind_DebugHook";
2362 ALL_OBJFILES (objfile
)
2364 struct breakpoint
*b
;
2365 struct gdbarch
*gdbarch
;
2366 struct breakpoint_objfile_data
*bp_objfile_data
;
2369 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2371 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2374 gdbarch
= get_objfile_arch (objfile
);
2376 if (bp_objfile_data
->exception_msym
== NULL
)
2378 struct minimal_symbol
*debug_hook
;
2380 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2381 if (debug_hook
== NULL
)
2383 bp_objfile_data
->exception_msym
= &msym_not_found
;
2387 bp_objfile_data
->exception_msym
= debug_hook
;
2390 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2391 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2393 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2394 &internal_breakpoint_ops
);
2395 b
->addr_string
= xstrdup (func_name
);
2396 b
->enable_state
= bp_disabled
;
2399 update_global_location_list (1);
2403 update_breakpoints_after_exec (void)
2405 struct breakpoint
*b
, *b_tmp
;
2406 struct bp_location
*bploc
, **bplocp_tmp
;
2408 /* We're about to delete breakpoints from GDB's lists. If the
2409 INSERTED flag is true, GDB will try to lift the breakpoints by
2410 writing the breakpoints' "shadow contents" back into memory. The
2411 "shadow contents" are NOT valid after an exec, so GDB should not
2412 do that. Instead, the target is responsible from marking
2413 breakpoints out as soon as it detects an exec. We don't do that
2414 here instead, because there may be other attempts to delete
2415 breakpoints after detecting an exec and before reaching here. */
2416 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2417 if (bploc
->pspace
== current_program_space
)
2418 gdb_assert (!bploc
->inserted
);
2420 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2422 if (b
->pspace
!= current_program_space
)
2425 /* Solib breakpoints must be explicitly reset after an exec(). */
2426 if (b
->type
== bp_shlib_event
)
2428 delete_breakpoint (b
);
2432 /* JIT breakpoints must be explicitly reset after an exec(). */
2433 if (b
->type
== bp_jit_event
)
2435 delete_breakpoint (b
);
2439 /* Thread event breakpoints must be set anew after an exec(),
2440 as must overlay event and longjmp master breakpoints. */
2441 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2442 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2443 || b
->type
== bp_exception_master
)
2445 delete_breakpoint (b
);
2449 /* Step-resume breakpoints are meaningless after an exec(). */
2450 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2452 delete_breakpoint (b
);
2456 /* Longjmp and longjmp-resume breakpoints are also meaningless
2458 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2459 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2461 delete_breakpoint (b
);
2465 if (b
->type
== bp_catchpoint
)
2467 /* For now, none of the bp_catchpoint breakpoints need to
2468 do anything at this point. In the future, if some of
2469 the catchpoints need to something, we will need to add
2470 a new method, and call this method from here. */
2474 /* bp_finish is a special case. The only way we ought to be able
2475 to see one of these when an exec() has happened, is if the user
2476 caught a vfork, and then said "finish". Ordinarily a finish just
2477 carries them to the call-site of the current callee, by setting
2478 a temporary bp there and resuming. But in this case, the finish
2479 will carry them entirely through the vfork & exec.
2481 We don't want to allow a bp_finish to remain inserted now. But
2482 we can't safely delete it, 'cause finish_command has a handle to
2483 the bp on a bpstat, and will later want to delete it. There's a
2484 chance (and I've seen it happen) that if we delete the bp_finish
2485 here, that its storage will get reused by the time finish_command
2486 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2487 We really must allow finish_command to delete a bp_finish.
2489 In the absence of a general solution for the "how do we know
2490 it's safe to delete something others may have handles to?"
2491 problem, what we'll do here is just uninsert the bp_finish, and
2492 let finish_command delete it.
2494 (We know the bp_finish is "doomed" in the sense that it's
2495 momentary, and will be deleted as soon as finish_command sees
2496 the inferior stopped. So it doesn't matter that the bp's
2497 address is probably bogus in the new a.out, unlike e.g., the
2498 solib breakpoints.) */
2500 if (b
->type
== bp_finish
)
2505 /* Without a symbolic address, we have little hope of the
2506 pre-exec() address meaning the same thing in the post-exec()
2508 if (b
->addr_string
== NULL
)
2510 delete_breakpoint (b
);
2514 /* FIXME what about longjmp breakpoints? Re-create them here? */
2515 create_overlay_event_breakpoint ();
2516 create_longjmp_master_breakpoint ();
2517 create_std_terminate_master_breakpoint ();
2518 create_exception_master_breakpoint ();
2522 detach_breakpoints (int pid
)
2524 struct bp_location
*bl
, **blp_tmp
;
2526 struct cleanup
*old_chain
= save_inferior_ptid ();
2527 struct inferior
*inf
= current_inferior ();
2529 if (pid
== PIDGET (inferior_ptid
))
2530 error (_("Cannot detach breakpoints of inferior_ptid"));
2532 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2533 inferior_ptid
= pid_to_ptid (pid
);
2534 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2536 if (bl
->pspace
!= inf
->pspace
)
2540 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2543 /* Detach single-step breakpoints as well. */
2544 detach_single_step_breakpoints ();
2546 do_cleanups (old_chain
);
2550 /* Remove the breakpoint location BL from the current address space.
2551 Note that this is used to detach breakpoints from a child fork.
2552 When we get here, the child isn't in the inferior list, and neither
2553 do we have objects to represent its address space --- we should
2554 *not* look at bl->pspace->aspace here. */
2557 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2561 /* BL is never in moribund_locations by our callers. */
2562 gdb_assert (bl
->owner
!= NULL
);
2564 if (bl
->owner
->enable_state
== bp_permanent
)
2565 /* Permanent breakpoints cannot be inserted or removed. */
2568 /* The type of none suggests that owner is actually deleted.
2569 This should not ever happen. */
2570 gdb_assert (bl
->owner
->type
!= bp_none
);
2572 if (bl
->loc_type
== bp_loc_software_breakpoint
2573 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2575 /* "Normal" instruction breakpoint: either the standard
2576 trap-instruction bp (bp_breakpoint), or a
2577 bp_hardware_breakpoint. */
2579 /* First check to see if we have to handle an overlay. */
2580 if (overlay_debugging
== ovly_off
2581 || bl
->section
== NULL
2582 || !(section_is_overlay (bl
->section
)))
2584 /* No overlay handling: just remove the breakpoint. */
2585 val
= bl
->owner
->ops
->remove_location (bl
);
2589 /* This breakpoint is in an overlay section.
2590 Did we set a breakpoint at the LMA? */
2591 if (!overlay_events_enabled
)
2593 /* Yes -- overlay event support is not active, so we
2594 should have set a breakpoint at the LMA. Remove it.
2596 /* Ignore any failures: if the LMA is in ROM, we will
2597 have already warned when we failed to insert it. */
2598 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2599 target_remove_hw_breakpoint (bl
->gdbarch
,
2600 &bl
->overlay_target_info
);
2602 target_remove_breakpoint (bl
->gdbarch
,
2603 &bl
->overlay_target_info
);
2605 /* Did we set a breakpoint at the VMA?
2606 If so, we will have marked the breakpoint 'inserted'. */
2609 /* Yes -- remove it. Previously we did not bother to
2610 remove the breakpoint if the section had been
2611 unmapped, but let's not rely on that being safe. We
2612 don't know what the overlay manager might do. */
2614 /* However, we should remove *software* breakpoints only
2615 if the section is still mapped, or else we overwrite
2616 wrong code with the saved shadow contents. */
2617 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2618 || section_is_mapped (bl
->section
))
2619 val
= bl
->owner
->ops
->remove_location (bl
);
2625 /* No -- not inserted, so no need to remove. No error. */
2630 /* In some cases, we might not be able to remove a breakpoint
2631 in a shared library that has already been removed, but we
2632 have not yet processed the shlib unload event. */
2633 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2638 bl
->inserted
= (is
== mark_inserted
);
2640 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2642 gdb_assert (bl
->owner
->ops
!= NULL
2643 && bl
->owner
->ops
->remove_location
!= NULL
);
2645 bl
->inserted
= (is
== mark_inserted
);
2646 bl
->owner
->ops
->remove_location (bl
);
2648 /* Failure to remove any of the hardware watchpoints comes here. */
2649 if ((is
== mark_uninserted
) && (bl
->inserted
))
2650 warning (_("Could not remove hardware watchpoint %d."),
2653 else if (bl
->owner
->type
== bp_catchpoint
2654 && breakpoint_enabled (bl
->owner
)
2657 gdb_assert (bl
->owner
->ops
!= NULL
2658 && bl
->owner
->ops
->remove_location
!= NULL
);
2660 val
= bl
->owner
->ops
->remove_location (bl
);
2664 bl
->inserted
= (is
== mark_inserted
);
2671 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2674 struct cleanup
*old_chain
;
2676 /* BL is never in moribund_locations by our callers. */
2677 gdb_assert (bl
->owner
!= NULL
);
2679 if (bl
->owner
->enable_state
== bp_permanent
)
2680 /* Permanent breakpoints cannot be inserted or removed. */
2683 /* The type of none suggests that owner is actually deleted.
2684 This should not ever happen. */
2685 gdb_assert (bl
->owner
->type
!= bp_none
);
2687 old_chain
= save_current_space_and_thread ();
2689 switch_to_program_space_and_thread (bl
->pspace
);
2691 ret
= remove_breakpoint_1 (bl
, is
);
2693 do_cleanups (old_chain
);
2697 /* Clear the "inserted" flag in all breakpoints. */
2700 mark_breakpoints_out (void)
2702 struct bp_location
*bl
, **blp_tmp
;
2704 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2705 if (bl
->pspace
== current_program_space
)
2709 /* Clear the "inserted" flag in all breakpoints and delete any
2710 breakpoints which should go away between runs of the program.
2712 Plus other such housekeeping that has to be done for breakpoints
2715 Note: this function gets called at the end of a run (by
2716 generic_mourn_inferior) and when a run begins (by
2717 init_wait_for_inferior). */
2722 breakpoint_init_inferior (enum inf_context context
)
2724 struct breakpoint
*b
, *b_tmp
;
2725 struct bp_location
*bl
, **blp_tmp
;
2727 struct program_space
*pspace
= current_program_space
;
2729 /* If breakpoint locations are shared across processes, then there's
2731 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2734 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2736 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2737 if (bl
->pspace
== pspace
2738 && bl
->owner
->enable_state
!= bp_permanent
)
2742 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2744 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2751 /* If the call dummy breakpoint is at the entry point it will
2752 cause problems when the inferior is rerun, so we better get
2755 case bp_watchpoint_scope
:
2757 /* Also get rid of scope breakpoints. */
2759 case bp_shlib_event
:
2761 /* Also remove solib event breakpoints. Their addresses may
2762 have changed since the last time we ran the program.
2763 Actually we may now be debugging against different target;
2764 and so the solib backend that installed this breakpoint may
2765 not be used in by the target. E.g.,
2767 (gdb) file prog-linux
2768 (gdb) run # native linux target
2771 (gdb) file prog-win.exe
2772 (gdb) tar rem :9999 # remote Windows gdbserver.
2775 delete_breakpoint (b
);
2779 case bp_hardware_watchpoint
:
2780 case bp_read_watchpoint
:
2781 case bp_access_watchpoint
:
2783 struct watchpoint
*w
= (struct watchpoint
*) b
;
2785 /* Likewise for watchpoints on local expressions. */
2786 if (w
->exp_valid_block
!= NULL
)
2787 delete_breakpoint (b
);
2788 else if (context
== inf_starting
)
2790 /* Reset val field to force reread of starting value in
2791 insert_breakpoints. */
2793 value_free (w
->val
);
2804 /* Get rid of the moribund locations. */
2805 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2806 decref_bp_location (&bl
);
2807 VEC_free (bp_location_p
, moribund_locations
);
2810 /* These functions concern about actual breakpoints inserted in the
2811 target --- to e.g. check if we need to do decr_pc adjustment or if
2812 we need to hop over the bkpt --- so we check for address space
2813 match, not program space. */
2815 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2816 exists at PC. It returns ordinary_breakpoint_here if it's an
2817 ordinary breakpoint, or permanent_breakpoint_here if it's a
2818 permanent breakpoint.
2819 - When continuing from a location with an ordinary breakpoint, we
2820 actually single step once before calling insert_breakpoints.
2821 - When continuing from a location with a permanent breakpoint, we
2822 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2823 the target, to advance the PC past the breakpoint. */
2825 enum breakpoint_here
2826 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2828 struct bp_location
*bl
, **blp_tmp
;
2829 int any_breakpoint_here
= 0;
2831 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2833 if (bl
->loc_type
!= bp_loc_software_breakpoint
2834 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2837 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2838 if ((breakpoint_enabled (bl
->owner
)
2839 || bl
->owner
->enable_state
== bp_permanent
)
2840 && breakpoint_location_address_match (bl
, aspace
, pc
))
2842 if (overlay_debugging
2843 && section_is_overlay (bl
->section
)
2844 && !section_is_mapped (bl
->section
))
2845 continue; /* unmapped overlay -- can't be a match */
2846 else if (bl
->owner
->enable_state
== bp_permanent
)
2847 return permanent_breakpoint_here
;
2849 any_breakpoint_here
= 1;
2853 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2856 /* Return true if there's a moribund breakpoint at PC. */
2859 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2861 struct bp_location
*loc
;
2864 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2865 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2871 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2872 inserted using regular breakpoint_chain / bp_location array
2873 mechanism. This does not check for single-step breakpoints, which
2874 are inserted and removed using direct target manipulation. */
2877 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2880 struct bp_location
*bl
, **blp_tmp
;
2882 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2884 if (bl
->loc_type
!= bp_loc_software_breakpoint
2885 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2889 && breakpoint_location_address_match (bl
, aspace
, pc
))
2891 if (overlay_debugging
2892 && section_is_overlay (bl
->section
)
2893 && !section_is_mapped (bl
->section
))
2894 continue; /* unmapped overlay -- can't be a match */
2902 /* Returns non-zero iff there's either regular breakpoint
2903 or a single step breakpoint inserted at PC. */
2906 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2908 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2911 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2917 /* This function returns non-zero iff there is a software breakpoint
2921 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2924 struct bp_location
*bl
, **blp_tmp
;
2926 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2928 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2932 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2935 if (overlay_debugging
2936 && section_is_overlay (bl
->section
)
2937 && !section_is_mapped (bl
->section
))
2938 continue; /* unmapped overlay -- can't be a match */
2944 /* Also check for software single-step breakpoints. */
2945 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2952 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2953 CORE_ADDR addr
, ULONGEST len
)
2955 struct breakpoint
*bpt
;
2957 ALL_BREAKPOINTS (bpt
)
2959 struct bp_location
*loc
;
2961 if (bpt
->type
!= bp_hardware_watchpoint
2962 && bpt
->type
!= bp_access_watchpoint
)
2965 if (!breakpoint_enabled (bpt
))
2968 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2969 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2973 /* Check for intersection. */
2974 l
= max (loc
->address
, addr
);
2975 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2983 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2984 PC is valid for process/thread PTID. */
2987 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2990 struct bp_location
*bl
, **blp_tmp
;
2991 /* The thread and task IDs associated to PTID, computed lazily. */
2995 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2997 if (bl
->loc_type
!= bp_loc_software_breakpoint
2998 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3001 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3002 if (!breakpoint_enabled (bl
->owner
)
3003 && bl
->owner
->enable_state
!= bp_permanent
)
3006 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3009 if (bl
->owner
->thread
!= -1)
3011 /* This is a thread-specific breakpoint. Check that ptid
3012 matches that thread. If thread hasn't been computed yet,
3013 it is now time to do so. */
3015 thread
= pid_to_thread_id (ptid
);
3016 if (bl
->owner
->thread
!= thread
)
3020 if (bl
->owner
->task
!= 0)
3022 /* This is a task-specific breakpoint. Check that ptid
3023 matches that task. If task hasn't been computed yet,
3024 it is now time to do so. */
3026 task
= ada_get_task_number (ptid
);
3027 if (bl
->owner
->task
!= task
)
3031 if (overlay_debugging
3032 && section_is_overlay (bl
->section
)
3033 && !section_is_mapped (bl
->section
))
3034 continue; /* unmapped overlay -- can't be a match */
3043 /* bpstat stuff. External routines' interfaces are documented
3047 ep_is_catchpoint (struct breakpoint
*ep
)
3049 return (ep
->type
== bp_catchpoint
);
3052 /* Frees any storage that is part of a bpstat. Does not walk the
3056 bpstat_free (bpstat bs
)
3058 if (bs
->old_val
!= NULL
)
3059 value_free (bs
->old_val
);
3060 decref_counted_command_line (&bs
->commands
);
3061 decref_bp_location (&bs
->bp_location_at
);
3065 /* Clear a bpstat so that it says we are not at any breakpoint.
3066 Also free any storage that is part of a bpstat. */
3069 bpstat_clear (bpstat
*bsp
)
3086 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3087 is part of the bpstat is copied as well. */
3090 bpstat_copy (bpstat bs
)
3094 bpstat retval
= NULL
;
3099 for (; bs
!= NULL
; bs
= bs
->next
)
3101 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3102 memcpy (tmp
, bs
, sizeof (*tmp
));
3103 incref_counted_command_line (tmp
->commands
);
3104 incref_bp_location (tmp
->bp_location_at
);
3105 if (bs
->old_val
!= NULL
)
3107 tmp
->old_val
= value_copy (bs
->old_val
);
3108 release_value (tmp
->old_val
);
3112 /* This is the first thing in the chain. */
3122 /* Find the bpstat associated with this breakpoint. */
3125 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3130 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3132 if (bsp
->breakpoint_at
== breakpoint
)
3138 /* Put in *NUM the breakpoint number of the first breakpoint we are
3139 stopped at. *BSP upon return is a bpstat which points to the
3140 remaining breakpoints stopped at (but which is not guaranteed to be
3141 good for anything but further calls to bpstat_num).
3143 Return 0 if passed a bpstat which does not indicate any breakpoints.
3144 Return -1 if stopped at a breakpoint that has been deleted since
3146 Return 1 otherwise. */
3149 bpstat_num (bpstat
*bsp
, int *num
)
3151 struct breakpoint
*b
;
3154 return 0; /* No more breakpoint values */
3156 /* We assume we'll never have several bpstats that correspond to a
3157 single breakpoint -- otherwise, this function might return the
3158 same number more than once and this will look ugly. */
3159 b
= (*bsp
)->breakpoint_at
;
3160 *bsp
= (*bsp
)->next
;
3162 return -1; /* breakpoint that's been deleted since */
3164 *num
= b
->number
; /* We have its number */
3168 /* Modify BS so that the actions will not be performed. */
3171 bpstat_clear_actions (bpstat bs
)
3173 for (; bs
!= NULL
; bs
= bs
->next
)
3175 decref_counted_command_line (&bs
->commands
);
3176 bs
->commands_left
= NULL
;
3177 if (bs
->old_val
!= NULL
)
3179 value_free (bs
->old_val
);
3185 /* Called when a command is about to proceed the inferior. */
3188 breakpoint_about_to_proceed (void)
3190 if (!ptid_equal (inferior_ptid
, null_ptid
))
3192 struct thread_info
*tp
= inferior_thread ();
3194 /* Allow inferior function calls in breakpoint commands to not
3195 interrupt the command list. When the call finishes
3196 successfully, the inferior will be standing at the same
3197 breakpoint as if nothing happened. */
3198 if (tp
->control
.in_infcall
)
3202 breakpoint_proceeded
= 1;
3205 /* Stub for cleaning up our state if we error-out of a breakpoint
3208 cleanup_executing_breakpoints (void *ignore
)
3210 executing_breakpoint_commands
= 0;
3213 /* Execute all the commands associated with all the breakpoints at
3214 this location. Any of these commands could cause the process to
3215 proceed beyond this point, etc. We look out for such changes by
3216 checking the global "breakpoint_proceeded" after each command.
3218 Returns true if a breakpoint command resumed the inferior. In that
3219 case, it is the caller's responsibility to recall it again with the
3220 bpstat of the current thread. */
3223 bpstat_do_actions_1 (bpstat
*bsp
)
3226 struct cleanup
*old_chain
;
3229 /* Avoid endless recursion if a `source' command is contained
3231 if (executing_breakpoint_commands
)
3234 executing_breakpoint_commands
= 1;
3235 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3237 prevent_dont_repeat ();
3239 /* This pointer will iterate over the list of bpstat's. */
3242 breakpoint_proceeded
= 0;
3243 for (; bs
!= NULL
; bs
= bs
->next
)
3245 struct counted_command_line
*ccmd
;
3246 struct command_line
*cmd
;
3247 struct cleanup
*this_cmd_tree_chain
;
3249 /* Take ownership of the BSP's command tree, if it has one.
3251 The command tree could legitimately contain commands like
3252 'step' and 'next', which call clear_proceed_status, which
3253 frees stop_bpstat's command tree. To make sure this doesn't
3254 free the tree we're executing out from under us, we need to
3255 take ownership of the tree ourselves. Since a given bpstat's
3256 commands are only executed once, we don't need to copy it; we
3257 can clear the pointer in the bpstat, and make sure we free
3258 the tree when we're done. */
3259 ccmd
= bs
->commands
;
3260 bs
->commands
= NULL
;
3262 = make_cleanup_decref_counted_command_line (&ccmd
);
3263 cmd
= bs
->commands_left
;
3264 bs
->commands_left
= NULL
;
3268 execute_control_command (cmd
);
3270 if (breakpoint_proceeded
)
3276 /* We can free this command tree now. */
3277 do_cleanups (this_cmd_tree_chain
);
3279 if (breakpoint_proceeded
)
3281 if (target_can_async_p ())
3282 /* If we are in async mode, then the target might be still
3283 running, not stopped at any breakpoint, so nothing for
3284 us to do here -- just return to the event loop. */
3287 /* In sync mode, when execute_control_command returns
3288 we're already standing on the next breakpoint.
3289 Breakpoint commands for that stop were not run, since
3290 execute_command does not run breakpoint commands --
3291 only command_line_handler does, but that one is not
3292 involved in execution of breakpoint commands. So, we
3293 can now execute breakpoint commands. It should be
3294 noted that making execute_command do bpstat actions is
3295 not an option -- in this case we'll have recursive
3296 invocation of bpstat for each breakpoint with a
3297 command, and can easily blow up GDB stack. Instead, we
3298 return true, which will trigger the caller to recall us
3299 with the new stop_bpstat. */
3304 do_cleanups (old_chain
);
3309 bpstat_do_actions (void)
3311 /* Do any commands attached to breakpoint we are stopped at. */
3312 while (!ptid_equal (inferior_ptid
, null_ptid
)
3313 && target_has_execution
3314 && !is_exited (inferior_ptid
)
3315 && !is_executing (inferior_ptid
))
3316 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3317 and only return when it is stopped at the next breakpoint, we
3318 keep doing breakpoint actions until it returns false to
3319 indicate the inferior was not resumed. */
3320 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3324 /* Print out the (old or new) value associated with a watchpoint. */
3327 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3330 fprintf_unfiltered (stream
, _("<unreadable>"));
3333 struct value_print_options opts
;
3334 get_user_print_options (&opts
);
3335 value_print (val
, stream
, &opts
);
3339 /* Generic routine for printing messages indicating why we
3340 stopped. The behavior of this function depends on the value
3341 'print_it' in the bpstat structure. Under some circumstances we
3342 may decide not to print anything here and delegate the task to
3345 static enum print_stop_action
3346 print_bp_stop_message (bpstat bs
)
3348 switch (bs
->print_it
)
3351 /* Nothing should be printed for this bpstat entry. */
3352 return PRINT_UNKNOWN
;
3356 /* We still want to print the frame, but we already printed the
3357 relevant messages. */
3358 return PRINT_SRC_AND_LOC
;
3361 case print_it_normal
:
3363 struct breakpoint
*b
= bs
->breakpoint_at
;
3365 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3366 which has since been deleted. */
3368 return PRINT_UNKNOWN
;
3370 /* Normal case. Call the breakpoint's print_it method. */
3371 return b
->ops
->print_it (bs
);
3376 internal_error (__FILE__
, __LINE__
,
3377 _("print_bp_stop_message: unrecognized enum value"));
3382 /* Print a message indicating what happened. This is called from
3383 normal_stop(). The input to this routine is the head of the bpstat
3384 list - a list of the eventpoints that caused this stop. This
3385 routine calls the generic print routine for printing a message
3386 about reasons for stopping. This will print (for example) the
3387 "Breakpoint n," part of the output. The return value of this
3390 PRINT_UNKNOWN: Means we printed nothing.
3391 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3392 code to print the location. An example is
3393 "Breakpoint 1, " which should be followed by
3395 PRINT_SRC_ONLY: Means we printed something, but there is no need
3396 to also print the location part of the message.
3397 An example is the catch/throw messages, which
3398 don't require a location appended to the end.
3399 PRINT_NOTHING: We have done some printing and we don't need any
3400 further info to be printed. */
3402 enum print_stop_action
3403 bpstat_print (bpstat bs
)
3407 /* Maybe another breakpoint in the chain caused us to stop.
3408 (Currently all watchpoints go on the bpstat whether hit or not.
3409 That probably could (should) be changed, provided care is taken
3410 with respect to bpstat_explains_signal). */
3411 for (; bs
; bs
= bs
->next
)
3413 val
= print_bp_stop_message (bs
);
3414 if (val
== PRINT_SRC_ONLY
3415 || val
== PRINT_SRC_AND_LOC
3416 || val
== PRINT_NOTHING
)
3420 /* We reached the end of the chain, or we got a null BS to start
3421 with and nothing was printed. */
3422 return PRINT_UNKNOWN
;
3425 /* Evaluate the expression EXP and return 1 if value is zero. This is
3426 used inside a catch_errors to evaluate the breakpoint condition.
3427 The argument is a "struct expression *" that has been cast to a
3428 "char *" to make it pass through catch_errors. */
3431 breakpoint_cond_eval (void *exp
)
3433 struct value
*mark
= value_mark ();
3434 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3436 value_free_to_mark (mark
);
3440 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3443 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3447 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3449 **bs_link_pointer
= bs
;
3450 *bs_link_pointer
= &bs
->next
;
3451 bs
->breakpoint_at
= bl
->owner
;
3452 bs
->bp_location_at
= bl
;
3453 incref_bp_location (bl
);
3454 /* If the condition is false, etc., don't do the commands. */
3455 bs
->commands
= NULL
;
3456 bs
->commands_left
= NULL
;
3458 bs
->print_it
= print_it_normal
;
3462 /* The target has stopped with waitstatus WS. Check if any hardware
3463 watchpoints have triggered, according to the target. */
3466 watchpoints_triggered (struct target_waitstatus
*ws
)
3468 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3470 struct breakpoint
*b
;
3472 if (!stopped_by_watchpoint
)
3474 /* We were not stopped by a watchpoint. Mark all watchpoints
3475 as not triggered. */
3477 if (is_hardware_watchpoint (b
))
3479 struct watchpoint
*w
= (struct watchpoint
*) b
;
3481 w
->watchpoint_triggered
= watch_triggered_no
;
3487 if (!target_stopped_data_address (¤t_target
, &addr
))
3489 /* We were stopped by a watchpoint, but we don't know where.
3490 Mark all watchpoints as unknown. */
3492 if (is_hardware_watchpoint (b
))
3494 struct watchpoint
*w
= (struct watchpoint
*) b
;
3496 w
->watchpoint_triggered
= watch_triggered_unknown
;
3499 return stopped_by_watchpoint
;
3502 /* The target could report the data address. Mark watchpoints
3503 affected by this data address as triggered, and all others as not
3507 if (is_hardware_watchpoint (b
))
3509 struct watchpoint
*w
= (struct watchpoint
*) b
;
3510 struct bp_location
*loc
;
3512 w
->watchpoint_triggered
= watch_triggered_no
;
3513 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3515 if (is_masked_watchpoint (b
))
3517 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3518 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3520 if (newaddr
== start
)
3522 w
->watchpoint_triggered
= watch_triggered_yes
;
3526 /* Exact match not required. Within range is sufficient. */
3527 else if (target_watchpoint_addr_within_range (¤t_target
,
3531 w
->watchpoint_triggered
= watch_triggered_yes
;
3540 /* Possible return values for watchpoint_check (this can't be an enum
3541 because of check_errors). */
3542 /* The watchpoint has been deleted. */
3543 #define WP_DELETED 1
3544 /* The value has changed. */
3545 #define WP_VALUE_CHANGED 2
3546 /* The value has not changed. */
3547 #define WP_VALUE_NOT_CHANGED 3
3548 /* Ignore this watchpoint, no matter if the value changed or not. */
3551 #define BP_TEMPFLAG 1
3552 #define BP_HARDWAREFLAG 2
3554 /* Evaluate watchpoint condition expression and check if its value
3557 P should be a pointer to struct bpstat, but is defined as a void *
3558 in order for this function to be usable with catch_errors. */
3561 watchpoint_check (void *p
)
3563 bpstat bs
= (bpstat
) p
;
3564 struct watchpoint
*b
;
3565 struct frame_info
*fr
;
3566 int within_current_scope
;
3568 /* BS is built from an existing struct breakpoint. */
3569 gdb_assert (bs
->breakpoint_at
!= NULL
);
3570 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3572 /* If this is a local watchpoint, we only want to check if the
3573 watchpoint frame is in scope if the current thread is the thread
3574 that was used to create the watchpoint. */
3575 if (!watchpoint_in_thread_scope (b
))
3578 if (b
->exp_valid_block
== NULL
)
3579 within_current_scope
= 1;
3582 struct frame_info
*frame
= get_current_frame ();
3583 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3584 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3586 /* in_function_epilogue_p() returns a non-zero value if we're
3587 still in the function but the stack frame has already been
3588 invalidated. Since we can't rely on the values of local
3589 variables after the stack has been destroyed, we are treating
3590 the watchpoint in that state as `not changed' without further
3591 checking. Don't mark watchpoints as changed if the current
3592 frame is in an epilogue - even if they are in some other
3593 frame, our view of the stack is likely to be wrong and
3594 frame_find_by_id could error out. */
3595 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3598 fr
= frame_find_by_id (b
->watchpoint_frame
);
3599 within_current_scope
= (fr
!= NULL
);
3601 /* If we've gotten confused in the unwinder, we might have
3602 returned a frame that can't describe this variable. */
3603 if (within_current_scope
)
3605 struct symbol
*function
;
3607 function
= get_frame_function (fr
);
3608 if (function
== NULL
3609 || !contained_in (b
->exp_valid_block
,
3610 SYMBOL_BLOCK_VALUE (function
)))
3611 within_current_scope
= 0;
3614 if (within_current_scope
)
3615 /* If we end up stopping, the current frame will get selected
3616 in normal_stop. So this call to select_frame won't affect
3621 if (within_current_scope
)
3623 /* We use value_{,free_to_}mark because it could be a *long*
3624 time before we return to the command level and call
3625 free_all_values. We can't call free_all_values because we
3626 might be in the middle of evaluating a function call. */
3630 struct value
*new_val
;
3632 if (is_masked_watchpoint (&b
->base
))
3633 /* Since we don't know the exact trigger address (from
3634 stopped_data_address), just tell the user we've triggered
3635 a mask watchpoint. */
3636 return WP_VALUE_CHANGED
;
3638 mark
= value_mark ();
3639 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3641 /* We use value_equal_contents instead of value_equal because
3642 the latter coerces an array to a pointer, thus comparing just
3643 the address of the array instead of its contents. This is
3644 not what we want. */
3645 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3646 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3648 if (new_val
!= NULL
)
3650 release_value (new_val
);
3651 value_free_to_mark (mark
);
3653 bs
->old_val
= b
->val
;
3656 return WP_VALUE_CHANGED
;
3660 /* Nothing changed. */
3661 value_free_to_mark (mark
);
3662 return WP_VALUE_NOT_CHANGED
;
3667 /* This seems like the only logical thing to do because
3668 if we temporarily ignored the watchpoint, then when
3669 we reenter the block in which it is valid it contains
3670 garbage (in the case of a function, it may have two
3671 garbage values, one before and one after the prologue).
3672 So we can't even detect the first assignment to it and
3673 watch after that (since the garbage may or may not equal
3674 the first value assigned). */
3675 /* We print all the stop information in
3676 breakpoint_ops->print_it, but in this case, by the time we
3677 call breakpoint_ops->print_it this bp will be deleted
3678 already. So we have no choice but print the information
3680 if (ui_out_is_mi_like_p (uiout
))
3682 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3683 ui_out_text (uiout
, "\nWatchpoint ");
3684 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3686 " deleted because the program has left the block in\n\
3687 which its expression is valid.\n");
3689 /* Make sure the watchpoint's commands aren't executed. */
3690 decref_counted_command_line (&b
->base
.commands
);
3691 watchpoint_del_at_next_stop (b
);
3697 /* Return true if it looks like target has stopped due to hitting
3698 breakpoint location BL. This function does not check if we should
3699 stop, only if BL explains the stop. */
3702 bpstat_check_location (const struct bp_location
*bl
,
3703 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3705 struct breakpoint
*b
= bl
->owner
;
3707 /* BL is from an existing breakpoint. */
3708 gdb_assert (b
!= NULL
);
3710 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3713 /* Determine if the watched values have actually changed, and we
3714 should stop. If not, set BS->stop to 0. */
3717 bpstat_check_watchpoint (bpstat bs
)
3719 const struct bp_location
*bl
;
3720 struct watchpoint
*b
;
3722 /* BS is built for existing struct breakpoint. */
3723 bl
= bs
->bp_location_at
;
3724 gdb_assert (bl
!= NULL
);
3725 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3726 gdb_assert (b
!= NULL
);
3729 int must_check_value
= 0;
3731 if (b
->base
.type
== bp_watchpoint
)
3732 /* For a software watchpoint, we must always check the
3734 must_check_value
= 1;
3735 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3736 /* We have a hardware watchpoint (read, write, or access)
3737 and the target earlier reported an address watched by
3739 must_check_value
= 1;
3740 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3741 && b
->base
.type
== bp_hardware_watchpoint
)
3742 /* We were stopped by a hardware watchpoint, but the target could
3743 not report the data address. We must check the watchpoint's
3744 value. Access and read watchpoints are out of luck; without
3745 a data address, we can't figure it out. */
3746 must_check_value
= 1;
3748 if (must_check_value
)
3751 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3753 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3754 int e
= catch_errors (watchpoint_check
, bs
, message
,
3756 do_cleanups (cleanups
);
3760 /* We've already printed what needs to be printed. */
3761 bs
->print_it
= print_it_done
;
3765 bs
->print_it
= print_it_noop
;
3768 case WP_VALUE_CHANGED
:
3769 if (b
->base
.type
== bp_read_watchpoint
)
3771 /* There are two cases to consider here:
3773 1. We're watching the triggered memory for reads.
3774 In that case, trust the target, and always report
3775 the watchpoint hit to the user. Even though
3776 reads don't cause value changes, the value may
3777 have changed since the last time it was read, and
3778 since we're not trapping writes, we will not see
3779 those, and as such we should ignore our notion of
3782 2. We're watching the triggered memory for both
3783 reads and writes. There are two ways this may
3786 2.1. This is a target that can't break on data
3787 reads only, but can break on accesses (reads or
3788 writes), such as e.g., x86. We detect this case
3789 at the time we try to insert read watchpoints.
3791 2.2. Otherwise, the target supports read
3792 watchpoints, but, the user set an access or write
3793 watchpoint watching the same memory as this read
3796 If we're watching memory writes as well as reads,
3797 ignore watchpoint hits when we find that the
3798 value hasn't changed, as reads don't cause
3799 changes. This still gives false positives when
3800 the program writes the same value to memory as
3801 what there was already in memory (we will confuse
3802 it for a read), but it's much better than
3805 int other_write_watchpoint
= 0;
3807 if (bl
->watchpoint_type
== hw_read
)
3809 struct breakpoint
*other_b
;
3811 ALL_BREAKPOINTS (other_b
)
3812 if (other_b
->type
== bp_hardware_watchpoint
3813 || other_b
->type
== bp_access_watchpoint
)
3815 struct watchpoint
*other_w
=
3816 (struct watchpoint
*) other_b
;
3818 if (other_w
->watchpoint_triggered
3819 == watch_triggered_yes
)
3821 other_write_watchpoint
= 1;
3827 if (other_write_watchpoint
3828 || bl
->watchpoint_type
== hw_access
)
3830 /* We're watching the same memory for writes,
3831 and the value changed since the last time we
3832 updated it, so this trap must be for a write.
3834 bs
->print_it
= print_it_noop
;
3839 case WP_VALUE_NOT_CHANGED
:
3840 if (b
->base
.type
== bp_hardware_watchpoint
3841 || b
->base
.type
== bp_watchpoint
)
3843 /* Don't stop: write watchpoints shouldn't fire if
3844 the value hasn't changed. */
3845 bs
->print_it
= print_it_noop
;
3853 /* Error from catch_errors. */
3854 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3855 watchpoint_del_at_next_stop (b
);
3856 /* We've already printed what needs to be printed. */
3857 bs
->print_it
= print_it_done
;
3861 else /* must_check_value == 0 */
3863 /* This is a case where some watchpoint(s) triggered, but
3864 not at the address of this watchpoint, or else no
3865 watchpoint triggered after all. So don't print
3866 anything for this watchpoint. */
3867 bs
->print_it
= print_it_noop
;
3874 /* Check conditions (condition proper, frame, thread and ignore count)
3875 of breakpoint referred to by BS. If we should not stop for this
3876 breakpoint, set BS->stop to 0. */
3879 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3881 int thread_id
= pid_to_thread_id (ptid
);
3882 const struct bp_location
*bl
;
3883 struct breakpoint
*b
;
3885 /* BS is built for existing struct breakpoint. */
3886 bl
= bs
->bp_location_at
;
3887 gdb_assert (bl
!= NULL
);
3888 b
= bs
->breakpoint_at
;
3889 gdb_assert (b
!= NULL
);
3891 if (frame_id_p (b
->frame_id
)
3892 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3896 int value_is_zero
= 0;
3897 struct expression
*cond
;
3899 /* Evaluate Python breakpoints that have a "stop"
3900 method implemented. */
3901 if (b
->py_bp_object
)
3902 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
3904 if (is_watchpoint (b
))
3906 struct watchpoint
*w
= (struct watchpoint
*) b
;
3913 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3915 int within_current_scope
= 1;
3916 struct watchpoint
* w
;
3918 /* We use value_mark and value_free_to_mark because it could
3919 be a long time before we return to the command level and
3920 call free_all_values. We can't call free_all_values
3921 because we might be in the middle of evaluating a
3923 struct value
*mark
= value_mark ();
3925 if (is_watchpoint (b
))
3926 w
= (struct watchpoint
*) b
;
3930 /* Need to select the frame, with all that implies so that
3931 the conditions will have the right context. Because we
3932 use the frame, we will not see an inlined function's
3933 variables when we arrive at a breakpoint at the start
3934 of the inlined function; the current frame will be the
3936 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
3937 select_frame (get_current_frame ());
3940 struct frame_info
*frame
;
3942 /* For local watchpoint expressions, which particular
3943 instance of a local is being watched matters, so we
3944 keep track of the frame to evaluate the expression
3945 in. To evaluate the condition however, it doesn't
3946 really matter which instantiation of the function
3947 where the condition makes sense triggers the
3948 watchpoint. This allows an expression like "watch
3949 global if q > 10" set in `func', catch writes to
3950 global on all threads that call `func', or catch
3951 writes on all recursive calls of `func' by a single
3952 thread. We simply always evaluate the condition in
3953 the innermost frame that's executing where it makes
3954 sense to evaluate the condition. It seems
3956 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
3958 select_frame (frame
);
3960 within_current_scope
= 0;
3962 if (within_current_scope
)
3964 = catch_errors (breakpoint_cond_eval
, cond
,
3965 "Error in testing breakpoint condition:\n",
3969 warning (_("Watchpoint condition cannot be tested "
3970 "in the current scope"));
3971 /* If we failed to set the right context for this
3972 watchpoint, unconditionally report it. */
3975 /* FIXME-someday, should give breakpoint #. */
3976 value_free_to_mark (mark
);
3979 if (cond
&& value_is_zero
)
3983 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3987 else if (b
->ignore_count
> 0)
3990 annotate_ignore_count_change ();
3992 /* Increase the hit count even though we don't stop. */
3994 observer_notify_breakpoint_modified (b
);
4000 /* Get a bpstat associated with having just stopped at address
4001 BP_ADDR in thread PTID.
4003 Determine whether we stopped at a breakpoint, etc, or whether we
4004 don't understand this stop. Result is a chain of bpstat's such
4007 if we don't understand the stop, the result is a null pointer.
4009 if we understand why we stopped, the result is not null.
4011 Each element of the chain refers to a particular breakpoint or
4012 watchpoint at which we have stopped. (We may have stopped for
4013 several reasons concurrently.)
4015 Each element of the chain has valid next, breakpoint_at,
4016 commands, FIXME??? fields. */
4019 bpstat_stop_status (struct address_space
*aspace
,
4020 CORE_ADDR bp_addr
, ptid_t ptid
)
4022 struct breakpoint
*b
= NULL
;
4023 struct bp_location
*bl
;
4024 struct bp_location
*loc
;
4025 /* First item of allocated bpstat's. */
4026 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4027 /* Pointer to the last thing in the chain currently. */
4030 int need_remove_insert
;
4033 /* First, build the bpstat chain with locations that explain a
4034 target stop, while being careful to not set the target running,
4035 as that may invalidate locations (in particular watchpoint
4036 locations are recreated). Resuming will happen here with
4037 breakpoint conditions or watchpoint expressions that include
4038 inferior function calls. */
4042 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4045 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4047 /* For hardware watchpoints, we look only at the first
4048 location. The watchpoint_check function will work on the
4049 entire expression, not the individual locations. For
4050 read watchpoints, the watchpoints_triggered function has
4051 checked all locations already. */
4052 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4055 if (bl
->shlib_disabled
)
4058 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4061 /* Come here if it's a watchpoint, or if the break address
4064 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4067 /* Assume we stop. Should we find a watchpoint that is not
4068 actually triggered, or if the condition of the breakpoint
4069 evaluates as false, we'll reset 'stop' to 0. */
4073 /* If this is a scope breakpoint, mark the associated
4074 watchpoint as triggered so that we will handle the
4075 out-of-scope event. We'll get to the watchpoint next
4077 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4079 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4081 w
->watchpoint_triggered
= watch_triggered_yes
;
4086 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4088 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4090 bs
= bpstat_alloc (loc
, &bs_link
);
4091 /* For hits of moribund locations, we should just proceed. */
4094 bs
->print_it
= print_it_noop
;
4098 /* Now go through the locations that caused the target to stop, and
4099 check whether we're interested in reporting this stop to higher
4100 layers, or whether we should resume the target transparently. */
4104 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4109 b
= bs
->breakpoint_at
;
4110 b
->ops
->check_status (bs
);
4113 bpstat_check_breakpoint_conditions (bs
, ptid
);
4118 observer_notify_breakpoint_modified (b
);
4120 /* We will stop here. */
4121 if (b
->disposition
== disp_disable
)
4123 if (b
->enable_state
!= bp_permanent
)
4124 b
->enable_state
= bp_disabled
;
4129 bs
->commands
= b
->commands
;
4130 incref_counted_command_line (bs
->commands
);
4131 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4132 if (bs
->commands_left
4133 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4136 bs
->commands_left
->line
) == 0)))
4138 bs
->commands_left
= bs
->commands_left
->next
;
4143 /* Print nothing for this entry if we don't stop or don't print. */
4144 if (bs
->stop
== 0 || bs
->print
== 0)
4145 bs
->print_it
= print_it_noop
;
4149 /* If we aren't stopping, the value of some hardware watchpoint may
4150 not have changed, but the intermediate memory locations we are
4151 watching may have. Don't bother if we're stopping; this will get
4153 need_remove_insert
= 0;
4154 if (! bpstat_causes_stop (bs_head
))
4155 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4157 && bs
->breakpoint_at
4158 && is_hardware_watchpoint (bs
->breakpoint_at
))
4160 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4162 update_watchpoint (w
, 0 /* don't reparse. */);
4163 need_remove_insert
= 1;
4166 if (need_remove_insert
)
4167 update_global_location_list (1);
4168 else if (removed_any
)
4169 update_global_location_list (0);
4175 handle_jit_event (void)
4177 struct frame_info
*frame
;
4178 struct gdbarch
*gdbarch
;
4180 /* Switch terminal for any messages produced by
4181 breakpoint_re_set. */
4182 target_terminal_ours_for_output ();
4184 frame
= get_current_frame ();
4185 gdbarch
= get_frame_arch (frame
);
4187 jit_event_handler (gdbarch
);
4189 target_terminal_inferior ();
4192 /* Prepare WHAT final decision for infrun. */
4194 /* Decide what infrun needs to do with this bpstat. */
4197 bpstat_what (bpstat bs_head
)
4199 struct bpstat_what retval
;
4200 /* We need to defer calling `solib_add', as adding new symbols
4201 resets breakpoints, which in turn deletes breakpoint locations,
4202 and hence may clear unprocessed entries in the BS chain. */
4203 int shlib_event
= 0;
4207 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4208 retval
.call_dummy
= STOP_NONE
;
4209 retval
.is_longjmp
= 0;
4211 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4213 /* Extract this BS's action. After processing each BS, we check
4214 if its action overrides all we've seem so far. */
4215 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4218 if (bs
->breakpoint_at
== NULL
)
4220 /* I suspect this can happen if it was a momentary
4221 breakpoint which has since been deleted. */
4225 bptype
= bs
->breakpoint_at
->type
;
4232 case bp_hardware_breakpoint
:
4238 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4240 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4243 this_action
= BPSTAT_WHAT_SINGLE
;
4246 case bp_hardware_watchpoint
:
4247 case bp_read_watchpoint
:
4248 case bp_access_watchpoint
:
4252 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4254 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4258 /* There was a watchpoint, but we're not stopping.
4259 This requires no further action. */
4264 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4265 retval
.is_longjmp
= bptype
== bp_longjmp
;
4267 case bp_longjmp_resume
:
4268 case bp_exception_resume
:
4269 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4270 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4272 case bp_step_resume
:
4274 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4277 /* It is for the wrong frame. */
4278 this_action
= BPSTAT_WHAT_SINGLE
;
4281 case bp_hp_step_resume
:
4283 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4286 /* It is for the wrong frame. */
4287 this_action
= BPSTAT_WHAT_SINGLE
;
4290 case bp_watchpoint_scope
:
4291 case bp_thread_event
:
4292 case bp_overlay_event
:
4293 case bp_longjmp_master
:
4294 case bp_std_terminate_master
:
4295 case bp_exception_master
:
4296 this_action
= BPSTAT_WHAT_SINGLE
;
4302 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4304 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4308 /* There was a catchpoint, but we're not stopping.
4309 This requires no further action. */
4312 case bp_shlib_event
:
4315 /* If requested, stop when the dynamic linker notifies GDB
4316 of events. This allows the user to get control and place
4317 breakpoints in initializer routines for dynamically
4318 loaded objects (among other things). */
4319 if (stop_on_solib_events
)
4320 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4322 this_action
= BPSTAT_WHAT_SINGLE
;
4326 this_action
= BPSTAT_WHAT_SINGLE
;
4329 /* Make sure the action is stop (silent or noisy),
4330 so infrun.c pops the dummy frame. */
4331 retval
.call_dummy
= STOP_STACK_DUMMY
;
4332 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4334 case bp_std_terminate
:
4335 /* Make sure the action is stop (silent or noisy),
4336 so infrun.c pops the dummy frame. */
4337 retval
.call_dummy
= STOP_STD_TERMINATE
;
4338 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4341 case bp_fast_tracepoint
:
4342 case bp_static_tracepoint
:
4343 /* Tracepoint hits should not be reported back to GDB, and
4344 if one got through somehow, it should have been filtered
4346 internal_error (__FILE__
, __LINE__
,
4347 _("bpstat_what: tracepoint encountered"));
4349 case bp_gnu_ifunc_resolver
:
4350 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4351 this_action
= BPSTAT_WHAT_SINGLE
;
4353 case bp_gnu_ifunc_resolver_return
:
4354 /* The breakpoint will be removed, execution will restart from the
4355 PC of the former breakpoint. */
4356 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4359 internal_error (__FILE__
, __LINE__
,
4360 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4363 retval
.main_action
= max (retval
.main_action
, this_action
);
4366 /* These operations may affect the bs->breakpoint_at state so they are
4367 delayed after MAIN_ACTION is decided above. */
4372 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4374 /* Check for any newly added shared libraries if we're supposed
4375 to be adding them automatically. */
4377 /* Switch terminal for any messages produced by
4378 breakpoint_re_set. */
4379 target_terminal_ours_for_output ();
4382 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4384 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4387 target_terminal_inferior ();
4393 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4395 handle_jit_event ();
4398 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4400 struct breakpoint
*b
= bs
->breakpoint_at
;
4406 case bp_gnu_ifunc_resolver
:
4407 gnu_ifunc_resolver_stop (b
);
4409 case bp_gnu_ifunc_resolver_return
:
4410 gnu_ifunc_resolver_return_stop (b
);
4418 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4419 without hardware support). This isn't related to a specific bpstat,
4420 just to things like whether watchpoints are set. */
4423 bpstat_should_step (void)
4425 struct breakpoint
*b
;
4428 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4434 bpstat_causes_stop (bpstat bs
)
4436 for (; bs
!= NULL
; bs
= bs
->next
)
4445 /* Compute a string of spaces suitable to indent the next line
4446 so it starts at the position corresponding to the table column
4447 named COL_NAME in the currently active table of UIOUT. */
4450 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4452 static char wrap_indent
[80];
4453 int i
, total_width
, width
, align
;
4457 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4459 if (strcmp (text
, col_name
) == 0)
4461 gdb_assert (total_width
< sizeof wrap_indent
);
4462 memset (wrap_indent
, ' ', total_width
);
4463 wrap_indent
[total_width
] = 0;
4468 total_width
+= width
+ 1;
4474 /* Print the LOC location out of the list of B->LOC locations. */
4477 print_breakpoint_location (struct breakpoint
*b
,
4478 struct bp_location
*loc
)
4480 struct cleanup
*old_chain
= save_current_program_space ();
4482 if (loc
!= NULL
&& loc
->shlib_disabled
)
4486 set_current_program_space (loc
->pspace
);
4488 if (b
->display_canonical
)
4489 ui_out_field_string (uiout
, "what", b
->addr_string
);
4490 else if (b
->source_file
&& loc
)
4493 = find_pc_sect_function (loc
->address
, loc
->section
);
4496 ui_out_text (uiout
, "in ");
4497 ui_out_field_string (uiout
, "func",
4498 SYMBOL_PRINT_NAME (sym
));
4499 ui_out_text (uiout
, " ");
4500 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4501 ui_out_text (uiout
, "at ");
4503 ui_out_field_string (uiout
, "file", b
->source_file
);
4504 ui_out_text (uiout
, ":");
4506 if (ui_out_is_mi_like_p (uiout
))
4508 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4509 char *fullname
= symtab_to_fullname (sal
.symtab
);
4512 ui_out_field_string (uiout
, "fullname", fullname
);
4515 ui_out_field_int (uiout
, "line", b
->line_number
);
4519 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4520 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4522 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4524 ui_out_field_stream (uiout
, "at", stb
);
4526 do_cleanups (stb_chain
);
4529 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4531 do_cleanups (old_chain
);
4535 bptype_string (enum bptype type
)
4537 struct ep_type_description
4542 static struct ep_type_description bptypes
[] =
4544 {bp_none
, "?deleted?"},
4545 {bp_breakpoint
, "breakpoint"},
4546 {bp_hardware_breakpoint
, "hw breakpoint"},
4547 {bp_until
, "until"},
4548 {bp_finish
, "finish"},
4549 {bp_watchpoint
, "watchpoint"},
4550 {bp_hardware_watchpoint
, "hw watchpoint"},
4551 {bp_read_watchpoint
, "read watchpoint"},
4552 {bp_access_watchpoint
, "acc watchpoint"},
4553 {bp_longjmp
, "longjmp"},
4554 {bp_longjmp_resume
, "longjmp resume"},
4555 {bp_exception
, "exception"},
4556 {bp_exception_resume
, "exception resume"},
4557 {bp_step_resume
, "step resume"},
4558 {bp_hp_step_resume
, "high-priority step resume"},
4559 {bp_watchpoint_scope
, "watchpoint scope"},
4560 {bp_call_dummy
, "call dummy"},
4561 {bp_std_terminate
, "std::terminate"},
4562 {bp_shlib_event
, "shlib events"},
4563 {bp_thread_event
, "thread events"},
4564 {bp_overlay_event
, "overlay events"},
4565 {bp_longjmp_master
, "longjmp master"},
4566 {bp_std_terminate_master
, "std::terminate master"},
4567 {bp_exception_master
, "exception master"},
4568 {bp_catchpoint
, "catchpoint"},
4569 {bp_tracepoint
, "tracepoint"},
4570 {bp_fast_tracepoint
, "fast tracepoint"},
4571 {bp_static_tracepoint
, "static tracepoint"},
4572 {bp_jit_event
, "jit events"},
4573 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4574 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4577 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4578 || ((int) type
!= bptypes
[(int) type
].type
))
4579 internal_error (__FILE__
, __LINE__
,
4580 _("bptypes table does not describe type #%d."),
4583 return bptypes
[(int) type
].description
;
4586 /* Print B to gdb_stdout. */
4589 print_one_breakpoint_location (struct breakpoint
*b
,
4590 struct bp_location
*loc
,
4592 struct bp_location
**last_loc
,
4595 struct command_line
*l
;
4596 static char bpenables
[] = "nynny";
4598 int header_of_multiple
= 0;
4599 int part_of_multiple
= (loc
!= NULL
);
4600 struct value_print_options opts
;
4602 get_user_print_options (&opts
);
4604 gdb_assert (!loc
|| loc_number
!= 0);
4605 /* See comment in print_one_breakpoint concerning treatment of
4606 breakpoints with single disabled location. */
4609 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4610 header_of_multiple
= 1;
4618 if (part_of_multiple
)
4621 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4622 ui_out_field_string (uiout
, "number", formatted
);
4627 ui_out_field_int (uiout
, "number", b
->number
);
4632 if (part_of_multiple
)
4633 ui_out_field_skip (uiout
, "type");
4635 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4639 if (part_of_multiple
)
4640 ui_out_field_skip (uiout
, "disp");
4642 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4647 if (part_of_multiple
)
4648 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4650 ui_out_field_fmt (uiout
, "enabled", "%c",
4651 bpenables
[(int) b
->enable_state
]);
4652 ui_out_spaces (uiout
, 2);
4656 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4658 /* Although the print_one can possibly print all locations,
4659 calling it here is not likely to get any nice result. So,
4660 make sure there's just one location. */
4661 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4662 b
->ops
->print_one (b
, last_loc
);
4668 internal_error (__FILE__
, __LINE__
,
4669 _("print_one_breakpoint: bp_none encountered\n"));
4673 case bp_hardware_watchpoint
:
4674 case bp_read_watchpoint
:
4675 case bp_access_watchpoint
:
4677 struct watchpoint
*w
= (struct watchpoint
*) b
;
4679 /* Field 4, the address, is omitted (which makes the columns
4680 not line up too nicely with the headers, but the effect
4681 is relatively readable). */
4682 if (opts
.addressprint
)
4683 ui_out_field_skip (uiout
, "addr");
4685 ui_out_field_string (uiout
, "what", w
->exp_string
);
4690 case bp_hardware_breakpoint
:
4694 case bp_longjmp_resume
:
4696 case bp_exception_resume
:
4697 case bp_step_resume
:
4698 case bp_hp_step_resume
:
4699 case bp_watchpoint_scope
:
4701 case bp_std_terminate
:
4702 case bp_shlib_event
:
4703 case bp_thread_event
:
4704 case bp_overlay_event
:
4705 case bp_longjmp_master
:
4706 case bp_std_terminate_master
:
4707 case bp_exception_master
:
4709 case bp_fast_tracepoint
:
4710 case bp_static_tracepoint
:
4712 case bp_gnu_ifunc_resolver
:
4713 case bp_gnu_ifunc_resolver_return
:
4714 if (opts
.addressprint
)
4717 if (header_of_multiple
)
4718 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4719 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4720 ui_out_field_string (uiout
, "addr", "<PENDING>");
4722 ui_out_field_core_addr (uiout
, "addr",
4723 loc
->gdbarch
, loc
->address
);
4726 if (!header_of_multiple
)
4727 print_breakpoint_location (b
, loc
);
4734 /* For backward compatibility, don't display inferiors unless there
4737 && !header_of_multiple
4739 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4740 && (number_of_program_spaces () > 1
4741 || number_of_inferiors () > 1)
4742 /* LOC is for existing B, it cannot be in
4743 moribund_locations and thus having NULL OWNER. */
4744 && loc
->owner
->type
!= bp_catchpoint
)))
4746 struct inferior
*inf
;
4749 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4751 if (inf
->pspace
== loc
->pspace
)
4756 ui_out_text (uiout
, " inf ");
4759 ui_out_text (uiout
, ", ");
4760 ui_out_text (uiout
, plongest (inf
->num
));
4765 if (!part_of_multiple
)
4767 if (b
->thread
!= -1)
4769 /* FIXME: This seems to be redundant and lost here; see the
4770 "stop only in" line a little further down. */
4771 ui_out_text (uiout
, " thread ");
4772 ui_out_field_int (uiout
, "thread", b
->thread
);
4774 else if (b
->task
!= 0)
4776 ui_out_text (uiout
, " task ");
4777 ui_out_field_int (uiout
, "task", b
->task
);
4781 ui_out_text (uiout
, "\n");
4783 if (!part_of_multiple
)
4784 b
->ops
->print_one_detail (b
, uiout
);
4786 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4789 ui_out_text (uiout
, "\tstop only in stack frame at ");
4790 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4792 ui_out_field_core_addr (uiout
, "frame",
4793 b
->gdbarch
, b
->frame_id
.stack_addr
);
4794 ui_out_text (uiout
, "\n");
4797 if (!part_of_multiple
&& b
->cond_string
)
4800 if (is_tracepoint (b
))
4801 ui_out_text (uiout
, "\ttrace only if ");
4803 ui_out_text (uiout
, "\tstop only if ");
4804 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4805 ui_out_text (uiout
, "\n");
4808 if (!part_of_multiple
&& b
->thread
!= -1)
4810 /* FIXME should make an annotation for this. */
4811 ui_out_text (uiout
, "\tstop only in thread ");
4812 ui_out_field_int (uiout
, "thread", b
->thread
);
4813 ui_out_text (uiout
, "\n");
4816 if (!part_of_multiple
&& b
->hit_count
)
4818 /* FIXME should make an annotation for this. */
4819 if (ep_is_catchpoint (b
))
4820 ui_out_text (uiout
, "\tcatchpoint");
4822 ui_out_text (uiout
, "\tbreakpoint");
4823 ui_out_text (uiout
, " already hit ");
4824 ui_out_field_int (uiout
, "times", b
->hit_count
);
4825 if (b
->hit_count
== 1)
4826 ui_out_text (uiout
, " time\n");
4828 ui_out_text (uiout
, " times\n");
4831 /* Output the count also if it is zero, but only if this is mi.
4832 FIXME: Should have a better test for this. */
4833 if (ui_out_is_mi_like_p (uiout
))
4834 if (!part_of_multiple
&& b
->hit_count
== 0)
4835 ui_out_field_int (uiout
, "times", b
->hit_count
);
4837 if (!part_of_multiple
&& b
->ignore_count
)
4840 ui_out_text (uiout
, "\tignore next ");
4841 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4842 ui_out_text (uiout
, " hits\n");
4845 l
= b
->commands
? b
->commands
->commands
: NULL
;
4846 if (!part_of_multiple
&& l
)
4848 struct cleanup
*script_chain
;
4851 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4852 print_command_lines (uiout
, l
, 4);
4853 do_cleanups (script_chain
);
4856 if (is_tracepoint (b
))
4858 struct tracepoint
*t
= (struct tracepoint
*) b
;
4860 if (!part_of_multiple
&& t
->pass_count
)
4862 annotate_field (10);
4863 ui_out_text (uiout
, "\tpass count ");
4864 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4865 ui_out_text (uiout
, " \n");
4869 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4871 if (is_watchpoint (b
))
4873 struct watchpoint
*w
= (struct watchpoint
*) b
;
4875 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
4877 else if (b
->addr_string
)
4878 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4883 print_one_breakpoint (struct breakpoint
*b
,
4884 struct bp_location
**last_loc
,
4887 struct cleanup
*bkpt_chain
;
4889 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4891 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
4892 do_cleanups (bkpt_chain
);
4894 /* If this breakpoint has custom print function,
4895 it's already printed. Otherwise, print individual
4896 locations, if any. */
4897 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4899 /* If breakpoint has a single location that is disabled, we
4900 print it as if it had several locations, since otherwise it's
4901 hard to represent "breakpoint enabled, location disabled"
4904 Note that while hardware watchpoints have several locations
4905 internally, that's not a property exposed to user. */
4907 && !is_hardware_watchpoint (b
)
4908 && (b
->loc
->next
|| !b
->loc
->enabled
))
4910 struct bp_location
*loc
;
4913 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4915 struct cleanup
*inner2
=
4916 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
4917 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
4918 do_cleanups (inner2
);
4925 breakpoint_address_bits (struct breakpoint
*b
)
4927 int print_address_bits
= 0;
4928 struct bp_location
*loc
;
4930 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4934 /* Software watchpoints that aren't watching memory don't have
4935 an address to print. */
4936 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4939 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4940 if (addr_bit
> print_address_bits
)
4941 print_address_bits
= addr_bit
;
4944 return print_address_bits
;
4947 struct captured_breakpoint_query_args
4953 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4955 struct captured_breakpoint_query_args
*args
= data
;
4956 struct breakpoint
*b
;
4957 struct bp_location
*dummy_loc
= NULL
;
4961 if (args
->bnum
== b
->number
)
4963 print_one_breakpoint (b
, &dummy_loc
, 0);
4971 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
4972 char **error_message
)
4974 struct captured_breakpoint_query_args args
;
4977 /* For the moment we don't trust print_one_breakpoint() to not throw
4979 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4980 error_message
, RETURN_MASK_ALL
) < 0)
4986 /* Return true if this breakpoint was set by the user, false if it is
4987 internal or momentary. */
4990 user_breakpoint_p (struct breakpoint
*b
)
4992 return b
->number
> 0;
4995 /* Print information on user settable breakpoint (watchpoint, etc)
4996 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4997 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4998 FILTER is non-NULL, call it on each breakpoint and only include the
4999 ones for which it returns non-zero. Return the total number of
5000 breakpoints listed. */
5003 breakpoint_1 (char *args
, int allflag
,
5004 int (*filter
) (const struct breakpoint
*))
5006 struct breakpoint
*b
;
5007 struct bp_location
*last_loc
= NULL
;
5008 int nr_printable_breakpoints
;
5009 struct cleanup
*bkpttbl_chain
;
5010 struct value_print_options opts
;
5011 int print_address_bits
= 0;
5012 int print_type_col_width
= 14;
5014 get_user_print_options (&opts
);
5016 /* Compute the number of rows in the table, as well as the size
5017 required for address fields. */
5018 nr_printable_breakpoints
= 0;
5021 /* If we have a filter, only list the breakpoints it accepts. */
5022 if (filter
&& !filter (b
))
5025 /* If we have an "args" string, it is a list of breakpoints to
5026 accept. Skip the others. */
5027 if (args
!= NULL
&& *args
!= '\0')
5029 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5031 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5035 if (allflag
|| user_breakpoint_p (b
))
5037 int addr_bit
, type_len
;
5039 addr_bit
= breakpoint_address_bits (b
);
5040 if (addr_bit
> print_address_bits
)
5041 print_address_bits
= addr_bit
;
5043 type_len
= strlen (bptype_string (b
->type
));
5044 if (type_len
> print_type_col_width
)
5045 print_type_col_width
= type_len
;
5047 nr_printable_breakpoints
++;
5051 if (opts
.addressprint
)
5053 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5054 nr_printable_breakpoints
,
5058 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5059 nr_printable_breakpoints
,
5062 if (nr_printable_breakpoints
> 0)
5063 annotate_breakpoints_headers ();
5064 if (nr_printable_breakpoints
> 0)
5066 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5067 if (nr_printable_breakpoints
> 0)
5069 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5070 "type", "Type"); /* 2 */
5071 if (nr_printable_breakpoints
> 0)
5073 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5074 if (nr_printable_breakpoints
> 0)
5076 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5077 if (opts
.addressprint
)
5079 if (nr_printable_breakpoints
> 0)
5081 if (print_address_bits
<= 32)
5082 ui_out_table_header (uiout
, 10, ui_left
,
5083 "addr", "Address"); /* 5 */
5085 ui_out_table_header (uiout
, 18, ui_left
,
5086 "addr", "Address"); /* 5 */
5088 if (nr_printable_breakpoints
> 0)
5090 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5091 ui_out_table_body (uiout
);
5092 if (nr_printable_breakpoints
> 0)
5093 annotate_breakpoints_table ();
5098 /* If we have a filter, only list the breakpoints it accepts. */
5099 if (filter
&& !filter (b
))
5102 /* If we have an "args" string, it is a list of breakpoints to
5103 accept. Skip the others. */
5105 if (args
!= NULL
&& *args
!= '\0')
5107 if (allflag
) /* maintenance info breakpoint */
5109 if (parse_and_eval_long (args
) != b
->number
)
5112 else /* all others */
5114 if (!number_is_in_list (args
, b
->number
))
5118 /* We only print out user settable breakpoints unless the
5120 if (allflag
|| user_breakpoint_p (b
))
5121 print_one_breakpoint (b
, &last_loc
, allflag
);
5124 do_cleanups (bkpttbl_chain
);
5126 if (nr_printable_breakpoints
== 0)
5128 /* If there's a filter, let the caller decide how to report
5132 if (args
== NULL
|| *args
== '\0')
5133 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5135 ui_out_message (uiout
, 0,
5136 "No breakpoint or watchpoint matching '%s'.\n",
5142 if (last_loc
&& !server_command
)
5143 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5146 /* FIXME? Should this be moved up so that it is only called when
5147 there have been breakpoints? */
5148 annotate_breakpoints_table_end ();
5150 return nr_printable_breakpoints
;
5153 /* Display the value of default-collect in a way that is generally
5154 compatible with the breakpoint list. */
5157 default_collect_info (void)
5159 /* If it has no value (which is frequently the case), say nothing; a
5160 message like "No default-collect." gets in user's face when it's
5162 if (!*default_collect
)
5165 /* The following phrase lines up nicely with per-tracepoint collect
5167 ui_out_text (uiout
, "default collect ");
5168 ui_out_field_string (uiout
, "default-collect", default_collect
);
5169 ui_out_text (uiout
, " \n");
5173 breakpoints_info (char *args
, int from_tty
)
5175 breakpoint_1 (args
, 0, NULL
);
5177 default_collect_info ();
5181 watchpoints_info (char *args
, int from_tty
)
5183 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5185 if (num_printed
== 0)
5187 if (args
== NULL
|| *args
== '\0')
5188 ui_out_message (uiout
, 0, "No watchpoints.\n");
5190 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5195 maintenance_info_breakpoints (char *args
, int from_tty
)
5197 breakpoint_1 (args
, 1, NULL
);
5199 default_collect_info ();
5203 breakpoint_has_pc (struct breakpoint
*b
,
5204 struct program_space
*pspace
,
5205 CORE_ADDR pc
, struct obj_section
*section
)
5207 struct bp_location
*bl
= b
->loc
;
5209 for (; bl
; bl
= bl
->next
)
5211 if (bl
->pspace
== pspace
5212 && bl
->address
== pc
5213 && (!overlay_debugging
|| bl
->section
== section
))
5219 /* Print a message describing any breakpoints set at PC. This
5220 concerns with logical breakpoints, so we match program spaces, not
5224 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5225 struct program_space
*pspace
, CORE_ADDR pc
,
5226 struct obj_section
*section
, int thread
)
5229 struct breakpoint
*b
;
5232 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5236 printf_filtered (_("Note: breakpoint "));
5237 else /* if (others == ???) */
5238 printf_filtered (_("Note: breakpoints "));
5240 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5243 printf_filtered ("%d", b
->number
);
5244 if (b
->thread
== -1 && thread
!= -1)
5245 printf_filtered (" (all threads)");
5246 else if (b
->thread
!= -1)
5247 printf_filtered (" (thread %d)", b
->thread
);
5248 printf_filtered ("%s%s ",
5249 ((b
->enable_state
== bp_disabled
5250 || b
->enable_state
== bp_call_disabled
5251 || b
->enable_state
== bp_startup_disabled
)
5253 : b
->enable_state
== bp_permanent
5257 : ((others
== 1) ? " and" : ""));
5259 printf_filtered (_("also set at pc "));
5260 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5261 printf_filtered (".\n");
5265 /* Set the default place to put a breakpoint
5266 for the `break' command with no arguments. */
5269 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5270 CORE_ADDR addr
, struct symtab
*symtab
,
5273 default_breakpoint_valid
= valid
;
5274 default_breakpoint_pspace
= pspace
;
5275 default_breakpoint_address
= addr
;
5276 default_breakpoint_symtab
= symtab
;
5277 default_breakpoint_line
= line
;
5280 /* Return true iff it is meaningful to use the address member of
5281 BPT. For some breakpoint types, the address member is irrelevant
5282 and it makes no sense to attempt to compare it to other addresses
5283 (or use it for any other purpose either).
5285 More specifically, each of the following breakpoint types will
5286 always have a zero valued address and we don't want to mark
5287 breakpoints of any of these types to be a duplicate of an actual
5288 breakpoint at address zero:
5296 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5298 enum bptype type
= bpt
->type
;
5300 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5303 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5304 true if LOC1 and LOC2 represent the same watchpoint location. */
5307 watchpoint_locations_match (struct bp_location
*loc1
,
5308 struct bp_location
*loc2
)
5310 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5311 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5313 /* Both of them must exist. */
5314 gdb_assert (w1
!= NULL
);
5315 gdb_assert (w2
!= NULL
);
5317 /* If the target can evaluate the condition expression in hardware,
5318 then we we need to insert both watchpoints even if they are at
5319 the same place. Otherwise the watchpoint will only trigger when
5320 the condition of whichever watchpoint was inserted evaluates to
5321 true, not giving a chance for GDB to check the condition of the
5322 other watchpoint. */
5324 && target_can_accel_watchpoint_condition (loc1
->address
,
5326 loc1
->watchpoint_type
,
5329 && target_can_accel_watchpoint_condition (loc2
->address
,
5331 loc2
->watchpoint_type
,
5335 /* Note that this checks the owner's type, not the location's. In
5336 case the target does not support read watchpoints, but does
5337 support access watchpoints, we'll have bp_read_watchpoint
5338 watchpoints with hw_access locations. Those should be considered
5339 duplicates of hw_read locations. The hw_read locations will
5340 become hw_access locations later. */
5341 return (loc1
->owner
->type
== loc2
->owner
->type
5342 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5343 && loc1
->address
== loc2
->address
5344 && loc1
->length
== loc2
->length
);
5347 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5348 same breakpoint location. In most targets, this can only be true
5349 if ASPACE1 matches ASPACE2. On targets that have global
5350 breakpoints, the address space doesn't really matter. */
5353 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5354 struct address_space
*aspace2
, CORE_ADDR addr2
)
5356 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5357 || aspace1
== aspace2
)
5361 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5362 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5363 matches ASPACE2. On targets that have global breakpoints, the address
5364 space doesn't really matter. */
5367 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5368 int len1
, struct address_space
*aspace2
,
5371 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5372 || aspace1
== aspace2
)
5373 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5376 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5377 a ranged breakpoint. In most targets, a match happens only if ASPACE
5378 matches the breakpoint's address space. On targets that have global
5379 breakpoints, the address space doesn't really matter. */
5382 breakpoint_location_address_match (struct bp_location
*bl
,
5383 struct address_space
*aspace
,
5386 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5389 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5390 bl
->address
, bl
->length
,
5394 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5395 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5396 represent the same location. */
5399 breakpoint_locations_match (struct bp_location
*loc1
,
5400 struct bp_location
*loc2
)
5402 int hw_point1
, hw_point2
;
5404 /* Both of them must not be in moribund_locations. */
5405 gdb_assert (loc1
->owner
!= NULL
);
5406 gdb_assert (loc2
->owner
!= NULL
);
5408 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5409 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5411 if (hw_point1
!= hw_point2
)
5414 return watchpoint_locations_match (loc1
, loc2
);
5416 /* We compare bp_location.length in order to cover ranged breakpoints. */
5417 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5418 loc2
->pspace
->aspace
, loc2
->address
)
5419 && loc1
->length
== loc2
->length
);
5423 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5424 int bnum
, int have_bnum
)
5426 /* The longest string possibly returned by hex_string_custom
5427 is 50 chars. These must be at least that big for safety. */
5431 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5432 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5434 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5435 bnum
, astr1
, astr2
);
5437 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5440 /* Adjust a breakpoint's address to account for architectural
5441 constraints on breakpoint placement. Return the adjusted address.
5442 Note: Very few targets require this kind of adjustment. For most
5443 targets, this function is simply the identity function. */
5446 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5447 CORE_ADDR bpaddr
, enum bptype bptype
)
5449 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5451 /* Very few targets need any kind of breakpoint adjustment. */
5454 else if (bptype
== bp_watchpoint
5455 || bptype
== bp_hardware_watchpoint
5456 || bptype
== bp_read_watchpoint
5457 || bptype
== bp_access_watchpoint
5458 || bptype
== bp_catchpoint
)
5460 /* Watchpoints and the various bp_catch_* eventpoints should not
5461 have their addresses modified. */
5466 CORE_ADDR adjusted_bpaddr
;
5468 /* Some targets have architectural constraints on the placement
5469 of breakpoint instructions. Obtain the adjusted address. */
5470 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5472 /* An adjusted breakpoint address can significantly alter
5473 a user's expectations. Print a warning if an adjustment
5475 if (adjusted_bpaddr
!= bpaddr
)
5476 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5478 return adjusted_bpaddr
;
5483 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5484 struct breakpoint
*owner
)
5486 memset (loc
, 0, sizeof (*loc
));
5488 gdb_assert (ops
!= NULL
);
5493 loc
->shlib_disabled
= 0;
5496 switch (owner
->type
)
5502 case bp_longjmp_resume
:
5504 case bp_exception_resume
:
5505 case bp_step_resume
:
5506 case bp_hp_step_resume
:
5507 case bp_watchpoint_scope
:
5509 case bp_std_terminate
:
5510 case bp_shlib_event
:
5511 case bp_thread_event
:
5512 case bp_overlay_event
:
5514 case bp_longjmp_master
:
5515 case bp_std_terminate_master
:
5516 case bp_exception_master
:
5517 case bp_gnu_ifunc_resolver
:
5518 case bp_gnu_ifunc_resolver_return
:
5519 loc
->loc_type
= bp_loc_software_breakpoint
;
5521 case bp_hardware_breakpoint
:
5522 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5524 case bp_hardware_watchpoint
:
5525 case bp_read_watchpoint
:
5526 case bp_access_watchpoint
:
5527 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5532 case bp_fast_tracepoint
:
5533 case bp_static_tracepoint
:
5534 loc
->loc_type
= bp_loc_other
;
5537 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5543 /* Allocate a struct bp_location. */
5545 static struct bp_location
*
5546 allocate_bp_location (struct breakpoint
*bpt
)
5548 return bpt
->ops
->allocate_location (bpt
);
5552 free_bp_location (struct bp_location
*loc
)
5554 loc
->ops
->dtor (loc
);
5558 /* Increment reference count. */
5561 incref_bp_location (struct bp_location
*bl
)
5566 /* Decrement reference count. If the reference count reaches 0,
5567 destroy the bp_location. Sets *BLP to NULL. */
5570 decref_bp_location (struct bp_location
**blp
)
5572 gdb_assert ((*blp
)->refc
> 0);
5574 if (--(*blp
)->refc
== 0)
5575 free_bp_location (*blp
);
5579 /* Add breakpoint B at the end of the global breakpoint chain. */
5582 add_to_breakpoint_chain (struct breakpoint
*b
)
5584 struct breakpoint
*b1
;
5586 /* Add this breakpoint to the end of the chain so that a list of
5587 breakpoints will come out in order of increasing numbers. */
5589 b1
= breakpoint_chain
;
5591 breakpoint_chain
= b
;
5600 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5603 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5604 struct gdbarch
*gdbarch
,
5606 const struct breakpoint_ops
*ops
)
5608 memset (b
, 0, sizeof (*b
));
5610 gdb_assert (ops
!= NULL
);
5614 b
->gdbarch
= gdbarch
;
5615 b
->language
= current_language
->la_language
;
5616 b
->input_radix
= input_radix
;
5618 b
->enable_state
= bp_enabled
;
5621 b
->ignore_count
= 0;
5623 b
->frame_id
= null_frame_id
;
5624 b
->condition_not_parsed
= 0;
5625 b
->py_bp_object
= NULL
;
5626 b
->related_breakpoint
= b
;
5629 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5630 that has type BPTYPE and has no locations as yet. */
5632 static struct breakpoint
*
5633 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5635 const struct breakpoint_ops
*ops
)
5637 struct breakpoint
*b
= XNEW (struct breakpoint
);
5639 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5640 add_to_breakpoint_chain (b
);
5644 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5645 resolutions should be made as the user specified the location explicitly
5649 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5651 gdb_assert (loc
->owner
!= NULL
);
5653 if (loc
->owner
->type
== bp_breakpoint
5654 || loc
->owner
->type
== bp_hardware_breakpoint
5655 || is_tracepoint (loc
->owner
))
5659 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5660 NULL
, NULL
, &is_gnu_ifunc
);
5662 if (is_gnu_ifunc
&& !explicit_loc
)
5664 struct breakpoint
*b
= loc
->owner
;
5666 gdb_assert (loc
->pspace
== current_program_space
);
5667 if (gnu_ifunc_resolve_name (loc
->function_name
,
5668 &loc
->requested_address
))
5670 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5671 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5672 loc
->requested_address
,
5675 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5676 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5678 /* Create only the whole new breakpoint of this type but do not
5679 mess more complicated breakpoints with multiple locations. */
5680 b
->type
= bp_gnu_ifunc_resolver
;
5684 if (loc
->function_name
)
5685 loc
->function_name
= xstrdup (loc
->function_name
);
5689 /* Attempt to determine architecture of location identified by SAL. */
5690 static struct gdbarch
*
5691 get_sal_arch (struct symtab_and_line sal
)
5694 return get_objfile_arch (sal
.section
->objfile
);
5696 return get_objfile_arch (sal
.symtab
->objfile
);
5701 /* Low level routine for partially initializing a breakpoint of type
5702 BPTYPE. The newly created breakpoint's address, section, source
5703 file name, and line number are provided by SAL.
5705 It is expected that the caller will complete the initialization of
5706 the newly created breakpoint struct as well as output any status
5707 information regarding the creation of a new breakpoint. */
5710 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5711 struct symtab_and_line sal
, enum bptype bptype
,
5712 const struct breakpoint_ops
*ops
)
5714 CORE_ADDR adjusted_address
;
5715 struct gdbarch
*loc_gdbarch
;
5717 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5719 loc_gdbarch
= get_sal_arch (sal
);
5721 loc_gdbarch
= b
->gdbarch
;
5723 if (bptype
!= bp_catchpoint
)
5724 gdb_assert (sal
.pspace
!= NULL
);
5726 /* Adjust the breakpoint's address prior to allocating a location.
5727 Once we call allocate_bp_location(), that mostly uninitialized
5728 location will be placed on the location chain. Adjustment of the
5729 breakpoint may cause target_read_memory() to be called and we do
5730 not want its scan of the location chain to find a breakpoint and
5731 location that's only been partially initialized. */
5732 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5735 b
->loc
= allocate_bp_location (b
);
5736 b
->loc
->gdbarch
= loc_gdbarch
;
5737 b
->loc
->requested_address
= sal
.pc
;
5738 b
->loc
->address
= adjusted_address
;
5739 b
->loc
->pspace
= sal
.pspace
;
5741 /* Store the program space that was used to set the breakpoint, for
5742 breakpoint resetting. */
5743 b
->pspace
= sal
.pspace
;
5745 if (sal
.symtab
== NULL
)
5746 b
->source_file
= NULL
;
5748 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5749 b
->loc
->section
= sal
.section
;
5750 b
->line_number
= sal
.line
;
5752 set_breakpoint_location_function (b
->loc
,
5753 sal
.explicit_pc
|| sal
.explicit_line
);
5755 breakpoints_changed ();
5758 /* set_raw_breakpoint is a low level routine for allocating and
5759 partially initializing a breakpoint of type BPTYPE. The newly
5760 created breakpoint's address, section, source file name, and line
5761 number are provided by SAL. The newly created and partially
5762 initialized breakpoint is added to the breakpoint chain and
5763 is also returned as the value of this function.
5765 It is expected that the caller will complete the initialization of
5766 the newly created breakpoint struct as well as output any status
5767 information regarding the creation of a new breakpoint. In
5768 particular, set_raw_breakpoint does NOT set the breakpoint
5769 number! Care should be taken to not allow an error to occur
5770 prior to completing the initialization of the breakpoint. If this
5771 should happen, a bogus breakpoint will be left on the chain. */
5774 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5775 struct symtab_and_line sal
, enum bptype bptype
,
5776 const struct breakpoint_ops
*ops
)
5778 struct breakpoint
*b
= XNEW (struct breakpoint
);
5780 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5781 add_to_breakpoint_chain (b
);
5786 /* Note that the breakpoint object B describes a permanent breakpoint
5787 instruction, hard-wired into the inferior's code. */
5789 make_breakpoint_permanent (struct breakpoint
*b
)
5791 struct bp_location
*bl
;
5793 b
->enable_state
= bp_permanent
;
5795 /* By definition, permanent breakpoints are already present in the
5796 code. Mark all locations as inserted. For now,
5797 make_breakpoint_permanent is called in just one place, so it's
5798 hard to say if it's reasonable to have permanent breakpoint with
5799 multiple locations or not, but it's easy to implement. */
5800 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5804 /* Call this routine when stepping and nexting to enable a breakpoint
5805 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5806 initiated the operation. */
5809 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5811 struct breakpoint
*b
, *b_tmp
;
5812 int thread
= tp
->num
;
5814 /* To avoid having to rescan all objfile symbols at every step,
5815 we maintain a list of continually-inserted but always disabled
5816 longjmp "master" breakpoints. Here, we simply create momentary
5817 clones of those and enable them for the requested thread. */
5818 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5819 if (b
->pspace
== current_program_space
5820 && (b
->type
== bp_longjmp_master
5821 || b
->type
== bp_exception_master
))
5823 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5824 struct breakpoint
*clone
;
5826 clone
= momentary_breakpoint_from_master (b
, type
,
5827 &momentary_breakpoint_ops
);
5828 clone
->thread
= thread
;
5831 tp
->initiating_frame
= frame
;
5834 /* Delete all longjmp breakpoints from THREAD. */
5836 delete_longjmp_breakpoint (int thread
)
5838 struct breakpoint
*b
, *b_tmp
;
5840 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5841 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5843 if (b
->thread
== thread
)
5844 delete_breakpoint (b
);
5849 enable_overlay_breakpoints (void)
5851 struct breakpoint
*b
;
5854 if (b
->type
== bp_overlay_event
)
5856 b
->enable_state
= bp_enabled
;
5857 update_global_location_list (1);
5858 overlay_events_enabled
= 1;
5863 disable_overlay_breakpoints (void)
5865 struct breakpoint
*b
;
5868 if (b
->type
== bp_overlay_event
)
5870 b
->enable_state
= bp_disabled
;
5871 update_global_location_list (0);
5872 overlay_events_enabled
= 0;
5876 /* Set an active std::terminate breakpoint for each std::terminate
5877 master breakpoint. */
5879 set_std_terminate_breakpoint (void)
5881 struct breakpoint
*b
, *b_tmp
;
5883 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5884 if (b
->pspace
== current_program_space
5885 && b
->type
== bp_std_terminate_master
)
5887 momentary_breakpoint_from_master (b
, bp_std_terminate
,
5888 &momentary_breakpoint_ops
);
5892 /* Delete all the std::terminate breakpoints. */
5894 delete_std_terminate_breakpoint (void)
5896 struct breakpoint
*b
, *b_tmp
;
5898 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5899 if (b
->type
== bp_std_terminate
)
5900 delete_breakpoint (b
);
5904 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5906 struct breakpoint
*b
;
5908 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
5909 &internal_breakpoint_ops
);
5911 b
->enable_state
= bp_enabled
;
5912 /* addr_string has to be used or breakpoint_re_set will delete me. */
5914 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5916 update_global_location_list_nothrow (1);
5922 remove_thread_event_breakpoints (void)
5924 struct breakpoint
*b
, *b_tmp
;
5926 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5927 if (b
->type
== bp_thread_event
5928 && b
->loc
->pspace
== current_program_space
)
5929 delete_breakpoint (b
);
5932 struct lang_and_radix
5938 /* Create a breakpoint for JIT code registration and unregistration. */
5941 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5943 struct breakpoint
*b
;
5945 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
5946 &internal_breakpoint_ops
);
5947 update_global_location_list_nothrow (1);
5951 /* Remove JIT code registration and unregistration breakpoint(s). */
5954 remove_jit_event_breakpoints (void)
5956 struct breakpoint
*b
, *b_tmp
;
5958 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5959 if (b
->type
== bp_jit_event
5960 && b
->loc
->pspace
== current_program_space
)
5961 delete_breakpoint (b
);
5965 remove_solib_event_breakpoints (void)
5967 struct breakpoint
*b
, *b_tmp
;
5969 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5970 if (b
->type
== bp_shlib_event
5971 && b
->loc
->pspace
== current_program_space
)
5972 delete_breakpoint (b
);
5976 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5978 struct breakpoint
*b
;
5980 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
5981 &internal_breakpoint_ops
);
5982 update_global_location_list_nothrow (1);
5986 /* Disable any breakpoints that are on code in shared libraries. Only
5987 apply to enabled breakpoints, disabled ones can just stay disabled. */
5990 disable_breakpoints_in_shlibs (void)
5992 struct bp_location
*loc
, **locp_tmp
;
5994 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5996 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5997 struct breakpoint
*b
= loc
->owner
;
5999 /* We apply the check to all breakpoints, including disabled for
6000 those with loc->duplicate set. This is so that when breakpoint
6001 becomes enabled, or the duplicate is removed, gdb will try to
6002 insert all breakpoints. If we don't set shlib_disabled here,
6003 we'll try to insert those breakpoints and fail. */
6004 if (((b
->type
== bp_breakpoint
)
6005 || (b
->type
== bp_jit_event
)
6006 || (b
->type
== bp_hardware_breakpoint
)
6007 || (is_tracepoint (b
)))
6008 && loc
->pspace
== current_program_space
6009 && !loc
->shlib_disabled
6011 && PC_SOLIB (loc
->address
)
6013 && solib_name_from_address (loc
->pspace
, loc
->address
)
6017 loc
->shlib_disabled
= 1;
6022 /* Disable any breakpoints that are in an unloaded shared library.
6023 Only apply to enabled breakpoints, disabled ones can just stay
6027 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6029 struct bp_location
*loc
, **locp_tmp
;
6030 int disabled_shlib_breaks
= 0;
6032 /* SunOS a.out shared libraries are always mapped, so do not
6033 disable breakpoints; they will only be reported as unloaded
6034 through clear_solib when GDB discards its shared library
6035 list. See clear_solib for more information. */
6036 if (exec_bfd
!= NULL
6037 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6040 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6042 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6043 struct breakpoint
*b
= loc
->owner
;
6045 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6046 || loc
->loc_type
== bp_loc_software_breakpoint
)
6047 && solib
->pspace
== loc
->pspace
6048 && !loc
->shlib_disabled
6049 && (b
->type
== bp_breakpoint
6050 || b
->type
== bp_jit_event
6051 || b
->type
== bp_hardware_breakpoint
)
6052 && solib_contains_address_p (solib
, loc
->address
))
6054 loc
->shlib_disabled
= 1;
6055 /* At this point, we cannot rely on remove_breakpoint
6056 succeeding so we must mark the breakpoint as not inserted
6057 to prevent future errors occurring in remove_breakpoints. */
6060 /* This may cause duplicate notifications for the same breakpoint. */
6061 observer_notify_breakpoint_modified (b
);
6063 if (!disabled_shlib_breaks
)
6065 target_terminal_ours_for_output ();
6066 warning (_("Temporarily disabling breakpoints "
6067 "for unloaded shared library \"%s\""),
6070 disabled_shlib_breaks
= 1;
6075 /* FORK & VFORK catchpoints. */
6077 /* An instance of this type is used to represent a fork or vfork
6078 catchpoint. It includes a "struct breakpoint" as a kind of base
6079 class; users downcast to "struct breakpoint *" when needed. A
6080 breakpoint is really of this type iff its ops pointer points to
6081 CATCH_FORK_BREAKPOINT_OPS. */
6083 struct fork_catchpoint
6085 /* The base class. */
6086 struct breakpoint base
;
6088 /* Process id of a child process whose forking triggered this
6089 catchpoint. This field is only valid immediately after this
6090 catchpoint has triggered. */
6091 ptid_t forked_inferior_pid
;
6094 /* Implement the "insert" breakpoint_ops method for fork
6098 insert_catch_fork (struct bp_location
*bl
)
6100 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6103 /* Implement the "remove" breakpoint_ops method for fork
6107 remove_catch_fork (struct bp_location
*bl
)
6109 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6112 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6116 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6117 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6119 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6121 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6124 /* Implement the "print_it" breakpoint_ops method for fork
6127 static enum print_stop_action
6128 print_it_catch_fork (bpstat bs
)
6130 struct breakpoint
*b
= bs
->breakpoint_at
;
6131 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6133 annotate_catchpoint (b
->number
);
6134 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6135 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6136 return PRINT_SRC_AND_LOC
;
6139 /* Implement the "print_one" breakpoint_ops method for fork
6143 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6145 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6146 struct value_print_options opts
;
6148 get_user_print_options (&opts
);
6150 /* Field 4, the address, is omitted (which makes the columns not
6151 line up too nicely with the headers, but the effect is relatively
6153 if (opts
.addressprint
)
6154 ui_out_field_skip (uiout
, "addr");
6156 ui_out_text (uiout
, "fork");
6157 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6159 ui_out_text (uiout
, ", process ");
6160 ui_out_field_int (uiout
, "what",
6161 ptid_get_pid (c
->forked_inferior_pid
));
6162 ui_out_spaces (uiout
, 1);
6166 /* Implement the "print_mention" breakpoint_ops method for fork
6170 print_mention_catch_fork (struct breakpoint
*b
)
6172 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6175 /* Implement the "print_recreate" breakpoint_ops method for fork
6179 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6181 fprintf_unfiltered (fp
, "catch fork");
6182 print_recreate_thread (b
, fp
);
6185 /* The breakpoint_ops structure to be used in fork catchpoints. */
6187 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6189 /* Implement the "insert" breakpoint_ops method for vfork
6193 insert_catch_vfork (struct bp_location
*bl
)
6195 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6198 /* Implement the "remove" breakpoint_ops method for vfork
6202 remove_catch_vfork (struct bp_location
*bl
)
6204 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6207 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6211 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6212 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6214 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6216 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6219 /* Implement the "print_it" breakpoint_ops method for vfork
6222 static enum print_stop_action
6223 print_it_catch_vfork (bpstat bs
)
6225 struct breakpoint
*b
= bs
->breakpoint_at
;
6226 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6228 annotate_catchpoint (b
->number
);
6229 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6230 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6231 return PRINT_SRC_AND_LOC
;
6234 /* Implement the "print_one" breakpoint_ops method for vfork
6238 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6240 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6241 struct value_print_options opts
;
6243 get_user_print_options (&opts
);
6244 /* Field 4, the address, is omitted (which makes the columns not
6245 line up too nicely with the headers, but the effect is relatively
6247 if (opts
.addressprint
)
6248 ui_out_field_skip (uiout
, "addr");
6250 ui_out_text (uiout
, "vfork");
6251 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6253 ui_out_text (uiout
, ", process ");
6254 ui_out_field_int (uiout
, "what",
6255 ptid_get_pid (c
->forked_inferior_pid
));
6256 ui_out_spaces (uiout
, 1);
6260 /* Implement the "print_mention" breakpoint_ops method for vfork
6264 print_mention_catch_vfork (struct breakpoint
*b
)
6266 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6269 /* Implement the "print_recreate" breakpoint_ops method for vfork
6273 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6275 fprintf_unfiltered (fp
, "catch vfork");
6276 print_recreate_thread (b
, fp
);
6279 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6281 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6283 /* An instance of this type is used to represent a syscall catchpoint.
6284 It includes a "struct breakpoint" as a kind of base class; users
6285 downcast to "struct breakpoint *" when needed. A breakpoint is
6286 really of this type iff its ops pointer points to
6287 CATCH_SYSCALL_BREAKPOINT_OPS. */
6289 struct syscall_catchpoint
6291 /* The base class. */
6292 struct breakpoint base
;
6294 /* Syscall numbers used for the 'catch syscall' feature. If no
6295 syscall has been specified for filtering, its value is NULL.
6296 Otherwise, it holds a list of all syscalls to be caught. The
6297 list elements are allocated with xmalloc. */
6298 VEC(int) *syscalls_to_be_caught
;
6301 /* Implement the "dtor" breakpoint_ops method for syscall
6305 dtor_catch_syscall (struct breakpoint
*b
)
6307 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6309 VEC_free (int, c
->syscalls_to_be_caught
);
6311 base_breakpoint_ops
.dtor (b
);
6314 /* Implement the "insert" breakpoint_ops method for syscall
6318 insert_catch_syscall (struct bp_location
*bl
)
6320 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6321 struct inferior
*inf
= current_inferior ();
6323 ++inf
->total_syscalls_count
;
6324 if (!c
->syscalls_to_be_caught
)
6325 ++inf
->any_syscall_count
;
6331 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6336 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6338 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6339 uintptr_t vec_addr_offset
6340 = old_size
* ((uintptr_t) sizeof (int));
6342 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6343 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6345 memset ((void *) vec_addr
, 0,
6346 (iter
+ 1 - old_size
) * sizeof (int));
6348 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6349 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6353 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6354 inf
->total_syscalls_count
!= 0,
6355 inf
->any_syscall_count
,
6356 VEC_length (int, inf
->syscalls_counts
),
6357 VEC_address (int, inf
->syscalls_counts
));
6360 /* Implement the "remove" breakpoint_ops method for syscall
6364 remove_catch_syscall (struct bp_location
*bl
)
6366 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6367 struct inferior
*inf
= current_inferior ();
6369 --inf
->total_syscalls_count
;
6370 if (!c
->syscalls_to_be_caught
)
6371 --inf
->any_syscall_count
;
6377 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6381 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6382 /* Shouldn't happen. */
6384 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6385 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6389 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6390 inf
->total_syscalls_count
!= 0,
6391 inf
->any_syscall_count
,
6392 VEC_length (int, inf
->syscalls_counts
),
6394 inf
->syscalls_counts
));
6397 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6401 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6402 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6404 /* We must check if we are catching specific syscalls in this
6405 breakpoint. If we are, then we must guarantee that the called
6406 syscall is the same syscall we are catching. */
6407 int syscall_number
= 0;
6408 const struct syscall_catchpoint
*c
6409 = (const struct syscall_catchpoint
*) bl
->owner
;
6411 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6414 /* Now, checking if the syscall is the same. */
6415 if (c
->syscalls_to_be_caught
)
6420 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6422 if (syscall_number
== iter
)
6432 /* Implement the "print_it" breakpoint_ops method for syscall
6435 static enum print_stop_action
6436 print_it_catch_syscall (bpstat bs
)
6438 struct breakpoint
*b
= bs
->breakpoint_at
;
6439 /* These are needed because we want to know in which state a
6440 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6441 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6442 must print "called syscall" or "returned from syscall". */
6444 struct target_waitstatus last
;
6446 struct cleanup
*old_chain
;
6449 get_last_target_status (&ptid
, &last
);
6451 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6453 annotate_catchpoint (b
->number
);
6456 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6458 syscall_id
= xstrprintf ("'%s'", s
.name
);
6460 old_chain
= make_cleanup (xfree
, syscall_id
);
6462 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6463 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6464 b
->number
, syscall_id
);
6465 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6466 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6467 b
->number
, syscall_id
);
6469 do_cleanups (old_chain
);
6471 return PRINT_SRC_AND_LOC
;
6474 /* Implement the "print_one" breakpoint_ops method for syscall
6478 print_one_catch_syscall (struct breakpoint
*b
,
6479 struct bp_location
**last_loc
)
6481 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6482 struct value_print_options opts
;
6484 get_user_print_options (&opts
);
6485 /* Field 4, the address, is omitted (which makes the columns not
6486 line up too nicely with the headers, but the effect is relatively
6488 if (opts
.addressprint
)
6489 ui_out_field_skip (uiout
, "addr");
6492 if (c
->syscalls_to_be_caught
6493 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6494 ui_out_text (uiout
, "syscalls \"");
6496 ui_out_text (uiout
, "syscall \"");
6498 if (c
->syscalls_to_be_caught
)
6501 char *text
= xstrprintf ("%s", "");
6504 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6509 get_syscall_by_number (iter
, &s
);
6512 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6514 text
= xstrprintf ("%s%d, ", text
, iter
);
6516 /* We have to xfree the last 'text' (now stored at 'x')
6517 because xstrprintf dynamically allocates new space for it
6521 /* Remove the last comma. */
6522 text
[strlen (text
) - 2] = '\0';
6523 ui_out_field_string (uiout
, "what", text
);
6526 ui_out_field_string (uiout
, "what", "<any syscall>");
6527 ui_out_text (uiout
, "\" ");
6530 /* Implement the "print_mention" breakpoint_ops method for syscall
6534 print_mention_catch_syscall (struct breakpoint
*b
)
6536 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6538 if (c
->syscalls_to_be_caught
)
6542 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6543 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6545 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6548 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6552 get_syscall_by_number (iter
, &s
);
6555 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6557 printf_filtered (" %d", s
.number
);
6559 printf_filtered (")");
6562 printf_filtered (_("Catchpoint %d (any syscall)"),
6566 /* Implement the "print_recreate" breakpoint_ops method for syscall
6570 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6572 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6574 fprintf_unfiltered (fp
, "catch syscall");
6576 if (c
->syscalls_to_be_caught
)
6581 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6586 get_syscall_by_number (iter
, &s
);
6588 fprintf_unfiltered (fp
, " %s", s
.name
);
6590 fprintf_unfiltered (fp
, " %d", s
.number
);
6593 print_recreate_thread (b
, fp
);
6596 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6598 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6600 /* Returns non-zero if 'b' is a syscall catchpoint. */
6603 syscall_catchpoint_p (struct breakpoint
*b
)
6605 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6608 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6609 is non-zero, then make the breakpoint temporary. If COND_STRING is
6610 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6611 the breakpoint_ops structure associated to the catchpoint. */
6614 init_catchpoint (struct breakpoint
*b
,
6615 struct gdbarch
*gdbarch
, int tempflag
,
6617 const struct breakpoint_ops
*ops
)
6619 struct symtab_and_line sal
;
6622 sal
.pspace
= current_program_space
;
6624 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6626 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6627 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6631 install_breakpoint (int internal
, struct breakpoint
*b
)
6633 add_to_breakpoint_chain (b
);
6634 set_breakpoint_number (internal
, b
);
6637 observer_notify_breakpoint_created (b
);
6638 update_global_location_list (1);
6642 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6643 int tempflag
, char *cond_string
,
6644 const struct breakpoint_ops
*ops
)
6646 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6648 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6650 c
->forked_inferior_pid
= null_ptid
;
6652 install_breakpoint (0, &c
->base
);
6655 /* Exec catchpoints. */
6657 /* An instance of this type is used to represent an exec catchpoint.
6658 It includes a "struct breakpoint" as a kind of base class; users
6659 downcast to "struct breakpoint *" when needed. A breakpoint is
6660 really of this type iff its ops pointer points to
6661 CATCH_EXEC_BREAKPOINT_OPS. */
6663 struct exec_catchpoint
6665 /* The base class. */
6666 struct breakpoint base
;
6668 /* Filename of a program whose exec triggered this catchpoint.
6669 This field is only valid immediately after this catchpoint has
6671 char *exec_pathname
;
6674 /* Implement the "dtor" breakpoint_ops method for exec
6678 dtor_catch_exec (struct breakpoint
*b
)
6680 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6682 xfree (c
->exec_pathname
);
6684 base_breakpoint_ops
.dtor (b
);
6688 insert_catch_exec (struct bp_location
*bl
)
6690 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6694 remove_catch_exec (struct bp_location
*bl
)
6696 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6700 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6701 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6703 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6705 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6708 static enum print_stop_action
6709 print_it_catch_exec (bpstat bs
)
6711 struct breakpoint
*b
= bs
->breakpoint_at
;
6712 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6714 annotate_catchpoint (b
->number
);
6715 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6717 return PRINT_SRC_AND_LOC
;
6721 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6723 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6724 struct value_print_options opts
;
6726 get_user_print_options (&opts
);
6728 /* Field 4, the address, is omitted (which makes the columns
6729 not line up too nicely with the headers, but the effect
6730 is relatively readable). */
6731 if (opts
.addressprint
)
6732 ui_out_field_skip (uiout
, "addr");
6734 ui_out_text (uiout
, "exec");
6735 if (c
->exec_pathname
!= NULL
)
6737 ui_out_text (uiout
, ", program \"");
6738 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6739 ui_out_text (uiout
, "\" ");
6744 print_mention_catch_exec (struct breakpoint
*b
)
6746 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6749 /* Implement the "print_recreate" breakpoint_ops method for exec
6753 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6755 fprintf_unfiltered (fp
, "catch exec");
6756 print_recreate_thread (b
, fp
);
6759 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6762 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6763 const struct breakpoint_ops
*ops
)
6765 struct syscall_catchpoint
*c
;
6766 struct gdbarch
*gdbarch
= get_current_arch ();
6768 c
= XNEW (struct syscall_catchpoint
);
6769 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6770 c
->syscalls_to_be_caught
= filter
;
6772 install_breakpoint (0, &c
->base
);
6776 hw_breakpoint_used_count (void)
6779 struct breakpoint
*b
;
6780 struct bp_location
*bl
;
6784 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6785 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6787 /* Special types of hardware breakpoints may use more than
6789 i
+= b
->ops
->resources_needed (bl
);
6797 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6800 struct breakpoint
*b
;
6801 struct bp_location
*bl
;
6803 *other_type_used
= 0;
6806 if (!breakpoint_enabled (b
))
6809 if (b
->type
== type
)
6810 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6812 /* Special types of hardware watchpoints may use more than
6814 i
+= b
->ops
->resources_needed (bl
);
6816 else if (is_hardware_watchpoint (b
))
6817 *other_type_used
= 1;
6824 disable_watchpoints_before_interactive_call_start (void)
6826 struct breakpoint
*b
;
6830 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6832 b
->enable_state
= bp_call_disabled
;
6833 update_global_location_list (0);
6839 enable_watchpoints_after_interactive_call_stop (void)
6841 struct breakpoint
*b
;
6845 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6847 b
->enable_state
= bp_enabled
;
6848 update_global_location_list (1);
6854 disable_breakpoints_before_startup (void)
6856 struct breakpoint
*b
;
6861 if (b
->pspace
!= current_program_space
)
6864 if ((b
->type
== bp_breakpoint
6865 || b
->type
== bp_hardware_breakpoint
)
6866 && breakpoint_enabled (b
))
6868 b
->enable_state
= bp_startup_disabled
;
6874 update_global_location_list (0);
6876 current_program_space
->executing_startup
= 1;
6880 enable_breakpoints_after_startup (void)
6882 struct breakpoint
*b
;
6885 current_program_space
->executing_startup
= 0;
6889 if (b
->pspace
!= current_program_space
)
6892 if ((b
->type
== bp_breakpoint
6893 || b
->type
== bp_hardware_breakpoint
)
6894 && b
->enable_state
== bp_startup_disabled
)
6896 b
->enable_state
= bp_enabled
;
6902 breakpoint_re_set ();
6906 /* Set a breakpoint that will evaporate an end of command
6907 at address specified by SAL.
6908 Restrict it to frame FRAME if FRAME is nonzero. */
6911 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6912 struct frame_id frame_id
, enum bptype type
)
6914 struct breakpoint
*b
;
6916 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6918 gdb_assert (!frame_id_inlined_p (frame_id
));
6920 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
6921 b
->enable_state
= bp_enabled
;
6922 b
->disposition
= disp_donttouch
;
6923 b
->frame_id
= frame_id
;
6925 /* If we're debugging a multi-threaded program, then we want
6926 momentary breakpoints to be active in only a single thread of
6928 if (in_thread_list (inferior_ptid
))
6929 b
->thread
= pid_to_thread_id (inferior_ptid
);
6931 update_global_location_list_nothrow (1);
6936 /* Make a momentary breakpoint based on the master breakpoint ORIG.
6937 The new breakpoint will have type TYPE, and use OPS as it
6940 static struct breakpoint
*
6941 momentary_breakpoint_from_master (struct breakpoint
*orig
,
6943 const struct breakpoint_ops
*ops
)
6945 struct breakpoint
*copy
;
6947 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
6948 copy
->loc
= allocate_bp_location (copy
);
6949 set_breakpoint_location_function (copy
->loc
, 1);
6951 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6952 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6953 copy
->loc
->address
= orig
->loc
->address
;
6954 copy
->loc
->section
= orig
->loc
->section
;
6955 copy
->loc
->pspace
= orig
->loc
->pspace
;
6957 if (orig
->source_file
== NULL
)
6958 copy
->source_file
= NULL
;
6960 copy
->source_file
= xstrdup (orig
->source_file
);
6962 copy
->line_number
= orig
->line_number
;
6963 copy
->frame_id
= orig
->frame_id
;
6964 copy
->thread
= orig
->thread
;
6965 copy
->pspace
= orig
->pspace
;
6967 copy
->enable_state
= bp_enabled
;
6968 copy
->disposition
= disp_donttouch
;
6969 copy
->number
= internal_breakpoint_number
--;
6971 update_global_location_list_nothrow (0);
6975 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6979 clone_momentary_breakpoint (struct breakpoint
*orig
)
6981 /* If there's nothing to clone, then return nothing. */
6985 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
6989 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6992 struct symtab_and_line sal
;
6994 sal
= find_pc_line (pc
, 0);
6996 sal
.section
= find_pc_overlay (pc
);
6997 sal
.explicit_pc
= 1;
6999 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7003 /* Tell the user we have just set a breakpoint B. */
7006 mention (struct breakpoint
*b
)
7008 b
->ops
->print_mention (b
);
7009 if (ui_out_is_mi_like_p (uiout
))
7011 printf_filtered ("\n");
7015 static struct bp_location
*
7016 add_location_to_breakpoint (struct breakpoint
*b
,
7017 const struct symtab_and_line
*sal
)
7019 struct bp_location
*loc
, **tmp
;
7021 loc
= allocate_bp_location (b
);
7022 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7025 loc
->gdbarch
= get_sal_arch (*sal
);
7027 loc
->gdbarch
= b
->gdbarch
;
7028 loc
->requested_address
= sal
->pc
;
7029 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7030 loc
->requested_address
, b
->type
);
7031 loc
->pspace
= sal
->pspace
;
7032 gdb_assert (loc
->pspace
!= NULL
);
7033 loc
->section
= sal
->section
;
7035 set_breakpoint_location_function (loc
,
7036 sal
->explicit_pc
|| sal
->explicit_line
);
7041 /* Return 1 if LOC is pointing to a permanent breakpoint,
7042 return 0 otherwise. */
7045 bp_loc_is_permanent (struct bp_location
*loc
)
7049 const gdb_byte
*brk
;
7050 gdb_byte
*target_mem
;
7051 struct cleanup
*cleanup
;
7054 gdb_assert (loc
!= NULL
);
7056 addr
= loc
->address
;
7057 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7059 /* Software breakpoints unsupported? */
7063 target_mem
= alloca (len
);
7065 /* Enable the automatic memory restoration from breakpoints while
7066 we read the memory. Otherwise we could say about our temporary
7067 breakpoints they are permanent. */
7068 cleanup
= save_current_space_and_thread ();
7070 switch_to_program_space_and_thread (loc
->pspace
);
7071 make_show_memory_breakpoints_cleanup (0);
7073 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7074 && memcmp (target_mem
, brk
, len
) == 0)
7077 do_cleanups (cleanup
);
7084 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7085 as textual description of the location, and COND_STRING
7086 as condition expression. */
7089 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7090 struct symtabs_and_lines sals
, char *addr_string
,
7092 enum bptype type
, enum bpdisp disposition
,
7093 int thread
, int task
, int ignore_count
,
7094 const struct breakpoint_ops
*ops
, int from_tty
,
7095 int enabled
, int internal
, int display_canonical
)
7099 if (type
== bp_hardware_breakpoint
)
7101 int i
= hw_breakpoint_used_count ();
7102 int target_resources_ok
=
7103 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7105 if (target_resources_ok
== 0)
7106 error (_("No hardware breakpoint support in the target."));
7107 else if (target_resources_ok
< 0)
7108 error (_("Hardware breakpoints used exceeds limit."));
7111 gdb_assert (sals
.nelts
> 0);
7113 for (i
= 0; i
< sals
.nelts
; ++i
)
7115 struct symtab_and_line sal
= sals
.sals
[i
];
7116 struct bp_location
*loc
;
7120 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7122 loc_gdbarch
= gdbarch
;
7124 describe_other_breakpoints (loc_gdbarch
,
7125 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7130 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7134 b
->cond_string
= cond_string
;
7135 b
->ignore_count
= ignore_count
;
7136 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7137 b
->disposition
= disposition
;
7138 b
->pspace
= sals
.sals
[0].pspace
;
7140 if (type
== bp_static_tracepoint
)
7142 struct tracepoint
*t
= (struct tracepoint
*) b
;
7143 struct static_tracepoint_marker marker
;
7145 if (is_marker_spec (addr_string
))
7147 /* We already know the marker exists, otherwise, we
7148 wouldn't see a sal for it. */
7149 char *p
= &addr_string
[3];
7154 p
= skip_spaces (p
);
7156 endp
= skip_to_space (p
);
7158 marker_str
= savestring (p
, endp
- p
);
7159 t
->static_trace_marker_id
= marker_str
;
7161 printf_filtered (_("Probed static tracepoint "
7163 t
->static_trace_marker_id
);
7165 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7167 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7168 release_static_tracepoint_marker (&marker
);
7170 printf_filtered (_("Probed static tracepoint "
7172 t
->static_trace_marker_id
);
7175 warning (_("Couldn't determine the static "
7176 "tracepoint marker to probe"));
7179 if (enabled
&& b
->pspace
->executing_startup
7180 && (b
->type
== bp_breakpoint
7181 || b
->type
== bp_hardware_breakpoint
))
7182 b
->enable_state
= bp_startup_disabled
;
7188 loc
= add_location_to_breakpoint (b
, &sal
);
7191 if (bp_loc_is_permanent (loc
))
7192 make_breakpoint_permanent (b
);
7196 char *arg
= b
->cond_string
;
7197 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7199 error (_("Garbage %s follows condition"), arg
);
7203 b
->display_canonical
= display_canonical
;
7205 b
->addr_string
= addr_string
;
7207 /* addr_string has to be used or breakpoint_re_set will delete
7210 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7214 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7215 struct symtabs_and_lines sals
, char *addr_string
,
7217 enum bptype type
, enum bpdisp disposition
,
7218 int thread
, int task
, int ignore_count
,
7219 const struct breakpoint_ops
*ops
, int from_tty
,
7220 int enabled
, int internal
, int display_canonical
)
7222 struct breakpoint
*b
;
7223 struct cleanup
*old_chain
;
7225 if (is_tracepoint_type (type
))
7227 struct tracepoint
*t
;
7229 t
= XCNEW (struct tracepoint
);
7233 b
= XNEW (struct breakpoint
);
7235 old_chain
= make_cleanup (xfree
, b
);
7237 init_breakpoint_sal (b
, gdbarch
,
7241 thread
, task
, ignore_count
,
7243 enabled
, internal
, display_canonical
);
7244 discard_cleanups (old_chain
);
7246 install_breakpoint (internal
, b
);
7249 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7250 elements to fill the void space. */
7252 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7254 int i
= index_to_remove
+1;
7255 int last_index
= sal
->nelts
-1;
7257 for (;i
<= last_index
; ++i
)
7258 sal
->sals
[i
-1] = sal
->sals
[i
];
7263 /* If appropriate, obtains all sals that correspond to the same file
7264 and line as SAL, in all program spaces. Users debugging with IDEs,
7265 will want to set a breakpoint at foo.c:line, and not really care
7266 about program spaces. This is done only if SAL does not have
7267 explicit PC and has line and file information. If we got just a
7268 single expanded sal, return the original.
7270 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7271 which the name of enclosing function is different from SAL. This
7272 makes sure that if we have breakpoint originally set in template
7273 instantiation, say foo<int>(), we won't expand SAL to locations at
7274 the same line in all existing instantiations of 'foo'. */
7276 static struct symtabs_and_lines
7277 expand_line_sal_maybe (struct symtab_and_line sal
)
7279 struct symtabs_and_lines expanded
;
7280 CORE_ADDR original_pc
= sal
.pc
;
7281 char *original_function
= NULL
;
7284 struct cleanup
*old_chain
;
7286 /* If we have explicit pc, don't expand.
7287 If we have no line number, we can't expand. */
7288 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7291 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7292 expanded
.sals
[0] = sal
;
7298 old_chain
= save_current_space_and_thread ();
7300 switch_to_program_space_and_thread (sal
.pspace
);
7302 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7304 /* Note that expand_line_sal visits *all* program spaces. */
7305 expanded
= expand_line_sal (sal
);
7307 if (expanded
.nelts
== 1)
7309 /* We had one sal, we got one sal. Return that sal, adjusting it
7310 past the function prologue if necessary. */
7311 xfree (expanded
.sals
);
7313 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7314 sal
.pc
= original_pc
;
7315 expanded
.sals
[0] = sal
;
7316 skip_prologue_sal (&expanded
.sals
[0]);
7317 do_cleanups (old_chain
);
7321 if (!sal
.explicit_line
)
7323 CORE_ADDR func_addr
, func_end
;
7324 for (i
= 0; i
< expanded
.nelts
; ++i
)
7326 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7327 char *this_function
;
7329 /* We need to switch threads as well since we're about to
7331 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7333 if (find_pc_partial_function (pc
, &this_function
,
7334 &func_addr
, &func_end
))
7337 && strcmp (this_function
, original_function
) != 0)
7339 remove_sal (&expanded
, i
);
7346 /* Skip the function prologue if necessary. */
7347 for (i
= 0; i
< expanded
.nelts
; ++i
)
7348 skip_prologue_sal (&expanded
.sals
[i
]);
7350 do_cleanups (old_chain
);
7352 if (expanded
.nelts
<= 1)
7354 /* This is an ugly workaround. If we get zero expanded sals
7355 then something is really wrong. Fix that by returning the
7358 xfree (expanded
.sals
);
7360 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7361 sal
.pc
= original_pc
;
7362 expanded
.sals
[0] = sal
;
7369 for (i
= 0; i
< expanded
.nelts
; ++i
)
7370 if (expanded
.sals
[i
].pc
== original_pc
)
7381 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7382 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7383 value. COND_STRING, if not NULL, specified the condition to be
7384 used for all breakpoints. Essentially the only case where
7385 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7386 function. In that case, it's still not possible to specify
7387 separate conditions for different overloaded functions, so
7388 we take just a single condition string.
7390 NOTE: If the function succeeds, the caller is expected to cleanup
7391 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7392 array contents). If the function fails (error() is called), the
7393 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7394 COND and SALS arrays and each of those arrays contents. */
7397 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7398 struct symtabs_and_lines sals
,
7399 struct linespec_result
*canonical
,
7401 enum bptype type
, enum bpdisp disposition
,
7402 int thread
, int task
, int ignore_count
,
7403 const struct breakpoint_ops
*ops
, int from_tty
,
7404 int enabled
, int internal
)
7408 for (i
= 0; i
< sals
.nelts
; ++i
)
7410 struct symtabs_and_lines expanded
=
7411 expand_line_sal_maybe (sals
.sals
[i
]);
7413 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7414 cond_string
, type
, disposition
,
7415 thread
, task
, ignore_count
, ops
,
7416 from_tty
, enabled
, internal
,
7417 canonical
->special_display
);
7421 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7422 followed by conditionals. On return, SALS contains an array of SAL
7423 addresses found. ADDR_STRING contains a vector of (canonical)
7424 address strings. ADDRESS points to the end of the SAL.
7426 The array and the line spec strings are allocated on the heap, it is
7427 the caller's responsibility to free them. */
7430 parse_breakpoint_sals (char **address
,
7431 struct symtabs_and_lines
*sals
,
7432 struct linespec_result
*canonical
)
7434 char *addr_start
= *address
;
7436 /* If no arg given, or if first arg is 'if ', use the default
7438 if ((*address
) == NULL
7439 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7441 if (default_breakpoint_valid
)
7443 struct symtab_and_line sal
;
7445 init_sal (&sal
); /* Initialize to zeroes. */
7446 sals
->sals
= (struct symtab_and_line
*)
7447 xmalloc (sizeof (struct symtab_and_line
));
7448 sal
.pc
= default_breakpoint_address
;
7449 sal
.line
= default_breakpoint_line
;
7450 sal
.symtab
= default_breakpoint_symtab
;
7451 sal
.pspace
= default_breakpoint_pspace
;
7452 sal
.section
= find_pc_overlay (sal
.pc
);
7454 /* "break" without arguments is equivalent to "break *PC"
7455 where PC is the default_breakpoint_address. So make sure
7456 to set sal.explicit_pc to prevent GDB from trying to
7457 expand the list of sals to include all other instances
7458 with the same symtab and line. */
7459 sal
.explicit_pc
= 1;
7461 sals
->sals
[0] = sal
;
7465 error (_("No default breakpoint address now."));
7469 /* Force almost all breakpoints to be in terms of the
7470 current_source_symtab (which is decode_line_1's default).
7471 This should produce the results we want almost all of the
7472 time while leaving default_breakpoint_* alone.
7474 ObjC: However, don't match an Objective-C method name which
7475 may have a '+' or '-' succeeded by a '[' */
7477 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7479 if (default_breakpoint_valid
7481 || ((strchr ("+-", (*address
)[0]) != NULL
)
7482 && ((*address
)[1] != '['))))
7483 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7484 default_breakpoint_line
, canonical
);
7486 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7489 /* For any SAL that didn't have a canonical string, fill one in. */
7490 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7491 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7492 if (addr_start
!= (*address
))
7496 for (i
= 0; i
< sals
->nelts
; i
++)
7498 /* Add the string if not present. */
7499 if (canonical
->canonical
[i
] == NULL
)
7500 canonical
->canonical
[i
] = savestring (addr_start
,
7501 (*address
) - addr_start
);
7507 /* Convert each SAL into a real PC. Verify that the PC can be
7508 inserted as a breakpoint. If it can't throw an error. */
7511 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7515 for (i
= 0; i
< sals
->nelts
; i
++)
7516 resolve_sal_pc (&sals
->sals
[i
]);
7519 /* Fast tracepoints may have restrictions on valid locations. For
7520 instance, a fast tracepoint using a jump instead of a trap will
7521 likely have to overwrite more bytes than a trap would, and so can
7522 only be placed where the instruction is longer than the jump, or a
7523 multi-instruction sequence does not have a jump into the middle of
7527 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7528 struct symtabs_and_lines
*sals
)
7531 struct symtab_and_line
*sal
;
7533 struct cleanup
*old_chain
;
7535 for (i
= 0; i
< sals
->nelts
; i
++)
7537 sal
= &sals
->sals
[i
];
7539 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7541 old_chain
= make_cleanup (xfree
, msg
);
7544 error (_("May not have a fast tracepoint at 0x%s%s"),
7545 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7547 do_cleanups (old_chain
);
7551 /* Given TOK, a string specification of condition and thread, as
7552 accepted by the 'break' command, extract the condition
7553 string and thread number and set *COND_STRING and *THREAD.
7554 PC identifies the context at which the condition should be parsed.
7555 If no condition is found, *COND_STRING is set to NULL.
7556 If no thread is found, *THREAD is set to -1. */
7558 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7559 char **cond_string
, int *thread
, int *task
)
7561 *cond_string
= NULL
;
7567 char *cond_start
= NULL
;
7568 char *cond_end
= NULL
;
7570 tok
= skip_spaces (tok
);
7572 end_tok
= skip_to_space (tok
);
7574 toklen
= end_tok
- tok
;
7576 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7578 struct expression
*expr
;
7580 tok
= cond_start
= end_tok
+ 1;
7581 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7584 *cond_string
= savestring (cond_start
,
7585 cond_end
- cond_start
);
7587 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7593 *thread
= strtol (tok
, &tok
, 0);
7595 error (_("Junk after thread keyword."));
7596 if (!valid_thread_id (*thread
))
7597 error (_("Unknown thread %d."), *thread
);
7599 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7605 *task
= strtol (tok
, &tok
, 0);
7607 error (_("Junk after task keyword."));
7608 if (!valid_task_id (*task
))
7609 error (_("Unknown task %d."), *task
);
7612 error (_("Junk at end of arguments."));
7616 /* Decode a static tracepoint marker spec. */
7618 static struct symtabs_and_lines
7619 decode_static_tracepoint_spec (char **arg_p
)
7621 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7622 struct symtabs_and_lines sals
;
7623 struct symtab_and_line sal
;
7625 struct cleanup
*old_chain
;
7626 char *p
= &(*arg_p
)[3];
7631 p
= skip_spaces (p
);
7633 endp
= skip_to_space (p
);
7635 marker_str
= savestring (p
, endp
- p
);
7636 old_chain
= make_cleanup (xfree
, marker_str
);
7638 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7639 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7640 error (_("No known static tracepoint marker named %s"), marker_str
);
7642 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7643 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7645 for (i
= 0; i
< sals
.nelts
; i
++)
7647 struct static_tracepoint_marker
*marker
;
7649 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7651 init_sal (&sals
.sals
[i
]);
7653 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7654 sals
.sals
[i
].pc
= marker
->address
;
7656 release_static_tracepoint_marker (marker
);
7659 do_cleanups (old_chain
);
7665 /* Set a breakpoint. This function is shared between CLI and MI
7666 functions for setting a breakpoint. This function has two major
7667 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7668 parameter. If non-zero, the function will parse arg, extracting
7669 breakpoint location, address and thread. Otherwise, ARG is just
7670 the location of breakpoint, with condition and thread specified by
7671 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7672 the breakpoint number will be allocated from the internal
7673 breakpoint count. Returns true if any breakpoint was created;
7677 create_breakpoint (struct gdbarch
*gdbarch
,
7678 char *arg
, char *cond_string
, int thread
,
7679 int parse_condition_and_thread
,
7680 int tempflag
, enum bptype type_wanted
,
7682 enum auto_boolean pending_break_support
,
7683 const struct breakpoint_ops
*ops
,
7684 int from_tty
, int enabled
, int internal
)
7686 volatile struct gdb_exception e
;
7687 struct symtabs_and_lines sals
;
7688 struct symtab_and_line pending_sal
;
7690 char *addr_start
= arg
;
7691 struct linespec_result canonical
;
7692 struct cleanup
*old_chain
;
7693 struct cleanup
*bkpt_chain
= NULL
;
7697 int prev_bkpt_count
= breakpoint_count
;
7699 gdb_assert (ops
!= NULL
);
7703 init_linespec_result (&canonical
);
7705 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7709 sals
= decode_static_tracepoint_spec (&arg
);
7711 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7712 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7713 for (i
= 0; i
< sals
.nelts
; i
++)
7714 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7718 TRY_CATCH (e
, RETURN_MASK_ALL
)
7720 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7723 /* If caller is interested in rc value from parse, set value. */
7727 throw_exception (e
);
7731 case NOT_FOUND_ERROR
:
7733 /* If pending breakpoint support is turned off, throw
7736 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7737 throw_exception (e
);
7739 exception_print (gdb_stderr
, e
);
7741 /* If pending breakpoint support is auto query and the user
7742 selects no, then simply return the error code. */
7743 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7744 && !nquery (_("Make breakpoint pending on "
7745 "future shared library load? ")))
7748 /* At this point, either the user was queried about setting
7749 a pending breakpoint and selected yes, or pending
7750 breakpoint behavior is on and thus a pending breakpoint
7751 is defaulted on behalf of the user. */
7752 copy_arg
= xstrdup (addr_start
);
7753 canonical
.canonical
= ©_arg
;
7755 sals
.sals
= &pending_sal
;
7760 throw_exception (e
);
7770 /* Create a chain of things that always need to be cleaned up. */
7771 old_chain
= make_cleanup (null_cleanup
, 0);
7775 /* Make sure that all storage allocated to SALS gets freed. */
7776 make_cleanup (xfree
, sals
.sals
);
7778 /* Cleanup the canonical array but not its contents. */
7779 make_cleanup (xfree
, canonical
.canonical
);
7782 /* ----------------------------- SNIP -----------------------------
7783 Anything added to the cleanup chain beyond this point is assumed
7784 to be part of a breakpoint. If the breakpoint create succeeds
7785 then the memory is not reclaimed. */
7786 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7788 /* Mark the contents of the canonical for cleanup. These go on
7789 the bkpt_chain and only occur if the breakpoint create fails. */
7790 for (i
= 0; i
< sals
.nelts
; i
++)
7792 if (canonical
.canonical
[i
] != NULL
)
7793 make_cleanup (xfree
, canonical
.canonical
[i
]);
7796 /* Resolve all line numbers to PC's and verify that the addresses
7797 are ok for the target. */
7799 breakpoint_sals_to_pc (&sals
);
7801 /* Fast tracepoints may have additional restrictions on location. */
7802 if (type_wanted
== bp_fast_tracepoint
)
7803 check_fast_tracepoint_sals (gdbarch
, &sals
);
7805 /* Verify that condition can be parsed, before setting any
7806 breakpoints. Allocate a separate condition expression for each
7810 if (parse_condition_and_thread
)
7812 /* Here we only parse 'arg' to separate condition
7813 from thread number, so parsing in context of first
7814 sal is OK. When setting the breakpoint we'll
7815 re-parse it in context of each sal. */
7818 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7821 make_cleanup (xfree
, cond_string
);
7825 /* Create a private copy of condition string. */
7828 cond_string
= xstrdup (cond_string
);
7829 make_cleanup (xfree
, cond_string
);
7833 /* If the user is creating a static tracepoint by marker id
7834 (strace -m MARKER_ID), then store the sals index, so that
7835 breakpoint_re_set can try to match up which of the newly
7836 found markers corresponds to this one, and, don't try to
7837 expand multiple locations for each sal, given than SALS
7838 already should contain all sals for MARKER_ID. */
7839 if (type_wanted
== bp_static_tracepoint
7840 && is_marker_spec (canonical
.canonical
[0]))
7844 for (i
= 0; i
< sals
.nelts
; ++i
)
7846 struct symtabs_and_lines expanded
;
7847 struct tracepoint
*tp
;
7848 struct cleanup
*old_chain
;
7851 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7852 expanded
.sals
[0] = sals
.sals
[i
];
7853 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7855 tp
= XCNEW (struct tracepoint
);
7856 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
7857 canonical
.canonical
[i
],
7858 cond_string
, type_wanted
,
7859 tempflag
? disp_del
: disp_donttouch
,
7860 thread
, task
, ignore_count
, ops
,
7861 from_tty
, enabled
, internal
,
7862 canonical
.special_display
);
7863 /* Given that its possible to have multiple markers with
7864 the same string id, if the user is creating a static
7865 tracepoint by marker id ("strace -m MARKER_ID"), then
7866 store the sals index, so that breakpoint_re_set can
7867 try to match up which of the newly found markers
7868 corresponds to this one */
7869 tp
->static_trace_marker_id_idx
= i
;
7871 install_breakpoint (internal
, &tp
->base
);
7873 do_cleanups (old_chain
);
7877 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
7879 tempflag
? disp_del
: disp_donttouch
,
7880 thread
, task
, ignore_count
, ops
, from_tty
,
7885 struct breakpoint
*b
;
7887 make_cleanup (xfree
, copy_arg
);
7889 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
, ops
);
7890 set_breakpoint_number (internal
, b
);
7892 b
->addr_string
= canonical
.canonical
[0];
7893 b
->cond_string
= NULL
;
7894 b
->ignore_count
= ignore_count
;
7895 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7896 b
->condition_not_parsed
= 1;
7897 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7898 b
->pspace
= current_program_space
;
7899 b
->py_bp_object
= NULL
;
7901 if (enabled
&& b
->pspace
->executing_startup
7902 && (b
->type
== bp_breakpoint
7903 || b
->type
== bp_hardware_breakpoint
))
7904 b
->enable_state
= bp_startup_disabled
;
7907 /* Do not mention breakpoints with a negative number,
7908 but do notify observers. */
7910 observer_notify_breakpoint_created (b
);
7915 warning (_("Multiple breakpoints were set.\nUse the "
7916 "\"delete\" command to delete unwanted breakpoints."));
7917 prev_breakpoint_count
= prev_bkpt_count
;
7920 /* That's it. Discard the cleanups for data inserted into the
7922 discard_cleanups (bkpt_chain
);
7923 /* But cleanup everything else. */
7924 do_cleanups (old_chain
);
7926 /* error call may happen here - have BKPT_CHAIN already discarded. */
7927 update_global_location_list (1);
7932 /* Set a breakpoint.
7933 ARG is a string describing breakpoint address,
7934 condition, and thread.
7935 FLAG specifies if a breakpoint is hardware on,
7936 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7940 break_command_1 (char *arg
, int flag
, int from_tty
)
7942 int tempflag
= flag
& BP_TEMPFLAG
;
7943 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7944 ? bp_hardware_breakpoint
7947 create_breakpoint (get_current_arch (),
7949 NULL
, 0, 1 /* parse arg */,
7950 tempflag
, type_wanted
,
7951 0 /* Ignore count */,
7952 pending_break_support
,
7953 &bkpt_breakpoint_ops
,
7959 /* Helper function for break_command_1 and disassemble_command. */
7962 resolve_sal_pc (struct symtab_and_line
*sal
)
7966 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7968 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7969 error (_("No line %d in file \"%s\"."),
7970 sal
->line
, sal
->symtab
->filename
);
7973 /* If this SAL corresponds to a breakpoint inserted using a line
7974 number, then skip the function prologue if necessary. */
7975 if (sal
->explicit_line
)
7976 skip_prologue_sal (sal
);
7979 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7981 struct blockvector
*bv
;
7985 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7988 sym
= block_linkage_function (b
);
7991 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7992 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7996 /* It really is worthwhile to have the section, so we'll
7997 just have to look harder. This case can be executed
7998 if we have line numbers but no functions (as can
7999 happen in assembly source). */
8001 struct minimal_symbol
*msym
;
8002 struct cleanup
*old_chain
= save_current_space_and_thread ();
8004 switch_to_program_space_and_thread (sal
->pspace
);
8006 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8008 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8010 do_cleanups (old_chain
);
8017 break_command (char *arg
, int from_tty
)
8019 break_command_1 (arg
, 0, from_tty
);
8023 tbreak_command (char *arg
, int from_tty
)
8025 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8029 hbreak_command (char *arg
, int from_tty
)
8031 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8035 thbreak_command (char *arg
, int from_tty
)
8037 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8041 stop_command (char *arg
, int from_tty
)
8043 printf_filtered (_("Specify the type of breakpoint to set.\n\
8044 Usage: stop in <function | address>\n\
8045 stop at <line>\n"));
8049 stopin_command (char *arg
, int from_tty
)
8053 if (arg
== (char *) NULL
)
8055 else if (*arg
!= '*')
8060 /* Look for a ':'. If this is a line number specification, then
8061 say it is bad, otherwise, it should be an address or
8062 function/method name. */
8063 while (*argptr
&& !hasColon
)
8065 hasColon
= (*argptr
== ':');
8070 badInput
= (*argptr
!= ':'); /* Not a class::method */
8072 badInput
= isdigit (*arg
); /* a simple line number */
8076 printf_filtered (_("Usage: stop in <function | address>\n"));
8078 break_command_1 (arg
, 0, from_tty
);
8082 stopat_command (char *arg
, int from_tty
)
8086 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8093 /* Look for a ':'. If there is a '::' then get out, otherwise
8094 it is probably a line number. */
8095 while (*argptr
&& !hasColon
)
8097 hasColon
= (*argptr
== ':');
8102 badInput
= (*argptr
== ':'); /* we have class::method */
8104 badInput
= !isdigit (*arg
); /* not a line number */
8108 printf_filtered (_("Usage: stop at <line>\n"));
8110 break_command_1 (arg
, 0, from_tty
);
8113 /* Implement the "breakpoint_hit" breakpoint_ops method for
8114 ranged breakpoints. */
8117 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8118 struct address_space
*aspace
,
8121 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8122 bl
->length
, aspace
, bp_addr
);
8125 /* Implement the "resources_needed" breakpoint_ops method for
8126 ranged breakpoints. */
8129 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8131 return target_ranged_break_num_registers ();
8134 /* Implement the "print_it" breakpoint_ops method for
8135 ranged breakpoints. */
8137 static enum print_stop_action
8138 print_it_ranged_breakpoint (bpstat bs
)
8140 struct breakpoint
*b
= bs
->breakpoint_at
;
8141 struct bp_location
*bl
= b
->loc
;
8143 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8145 /* Ranged breakpoints have only one location. */
8146 gdb_assert (bl
&& bl
->next
== NULL
);
8148 annotate_breakpoint (b
->number
);
8149 if (b
->disposition
== disp_del
)
8150 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8152 ui_out_text (uiout
, "\nRanged breakpoint ");
8153 if (ui_out_is_mi_like_p (uiout
))
8155 ui_out_field_string (uiout
, "reason",
8156 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8157 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8159 ui_out_field_int (uiout
, "bkptno", b
->number
);
8160 ui_out_text (uiout
, ", ");
8162 return PRINT_SRC_AND_LOC
;
8165 /* Implement the "print_one" breakpoint_ops method for
8166 ranged breakpoints. */
8169 print_one_ranged_breakpoint (struct breakpoint
*b
,
8170 struct bp_location
**last_loc
)
8172 struct bp_location
*bl
= b
->loc
;
8173 struct value_print_options opts
;
8175 /* Ranged breakpoints have only one location. */
8176 gdb_assert (bl
&& bl
->next
== NULL
);
8178 get_user_print_options (&opts
);
8180 if (opts
.addressprint
)
8181 /* We don't print the address range here, it will be printed later
8182 by print_one_detail_ranged_breakpoint. */
8183 ui_out_field_skip (uiout
, "addr");
8185 print_breakpoint_location (b
, bl
);
8189 /* Implement the "print_one_detail" breakpoint_ops method for
8190 ranged breakpoints. */
8193 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8194 struct ui_out
*uiout
)
8196 CORE_ADDR address_start
, address_end
;
8197 struct bp_location
*bl
= b
->loc
;
8198 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8199 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8203 address_start
= bl
->address
;
8204 address_end
= address_start
+ bl
->length
- 1;
8206 ui_out_text (uiout
, "\taddress range: ");
8207 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8208 print_core_address (bl
->gdbarch
, address_start
),
8209 print_core_address (bl
->gdbarch
, address_end
));
8210 ui_out_field_stream (uiout
, "addr", stb
);
8211 ui_out_text (uiout
, "\n");
8213 do_cleanups (cleanup
);
8216 /* Implement the "print_mention" breakpoint_ops method for
8217 ranged breakpoints. */
8220 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8222 struct bp_location
*bl
= b
->loc
;
8225 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8227 if (ui_out_is_mi_like_p (uiout
))
8230 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8231 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8232 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8235 /* Implement the "print_recreate" breakpoint_ops method for
8236 ranged breakpoints. */
8239 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8241 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8242 b
->addr_string_range_end
);
8243 print_recreate_thread (b
, fp
);
8246 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8248 static struct breakpoint_ops ranged_breakpoint_ops
;
8250 /* Find the address where the end of the breakpoint range should be
8251 placed, given the SAL of the end of the range. This is so that if
8252 the user provides a line number, the end of the range is set to the
8253 last instruction of the given line. */
8256 find_breakpoint_range_end (struct symtab_and_line sal
)
8260 /* If the user provided a PC value, use it. Otherwise,
8261 find the address of the end of the given location. */
8262 if (sal
.explicit_pc
)
8269 ret
= find_line_pc_range (sal
, &start
, &end
);
8271 error (_("Could not find location of the end of the range."));
8273 /* find_line_pc_range returns the start of the next line. */
8280 /* Implement the "break-range" CLI command. */
8283 break_range_command (char *arg
, int from_tty
)
8285 char *arg_start
, *addr_string_start
, *addr_string_end
;
8286 struct linespec_result canonical_start
, canonical_end
;
8287 int bp_count
, can_use_bp
, length
;
8289 struct breakpoint
*b
;
8290 struct symtab_and_line sal_start
, sal_end
;
8291 struct symtabs_and_lines sals_start
, sals_end
;
8292 struct cleanup
*cleanup_bkpt
;
8294 /* We don't support software ranged breakpoints. */
8295 if (target_ranged_break_num_registers () < 0)
8296 error (_("This target does not support hardware ranged breakpoints."));
8298 bp_count
= hw_breakpoint_used_count ();
8299 bp_count
+= target_ranged_break_num_registers ();
8300 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8303 error (_("Hardware breakpoints used exceeds limit."));
8305 if (arg
== NULL
|| arg
[0] == '\0')
8306 error(_("No address range specified."));
8308 sals_start
.sals
= NULL
;
8309 sals_start
.nelts
= 0;
8310 init_linespec_result (&canonical_start
);
8312 while (*arg
== ' ' || *arg
== '\t')
8315 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8317 sal_start
= sals_start
.sals
[0];
8318 addr_string_start
= canonical_start
.canonical
[0];
8319 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8320 xfree (sals_start
.sals
);
8321 xfree (canonical_start
.canonical
);
8324 error (_("Too few arguments."));
8325 else if (sals_start
.nelts
== 0)
8326 error (_("Could not find location of the beginning of the range."));
8327 else if (sals_start
.nelts
!= 1)
8328 error (_("Cannot create a ranged breakpoint with multiple locations."));
8330 resolve_sal_pc (&sal_start
);
8332 arg
++; /* Skip the comma. */
8333 while (*arg
== ' ' || *arg
== '\t')
8336 /* Parse the end location. */
8338 sals_end
.sals
= NULL
;
8340 init_linespec_result (&canonical_end
);
8343 /* We call decode_line_1 directly here instead of using
8344 parse_breakpoint_sals because we need to specify the start location's
8345 symtab and line as the default symtab and line for the end of the
8346 range. This makes it possible to have ranges like "foo.c:27, +14",
8347 where +14 means 14 lines from the start location. */
8348 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8351 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8352 if (canonical_end
.canonical
== NULL
)
8353 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8354 /* Add the string if not present. */
8355 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8356 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8358 sal_end
= sals_end
.sals
[0];
8359 addr_string_end
= canonical_end
.canonical
[0];
8360 make_cleanup (xfree
, addr_string_end
);
8361 xfree (sals_end
.sals
);
8362 xfree (canonical_end
.canonical
);
8364 if (sals_end
.nelts
== 0)
8365 error (_("Could not find location of the end of the range."));
8366 else if (sals_end
.nelts
!= 1)
8367 error (_("Cannot create a ranged breakpoint with multiple locations."));
8369 resolve_sal_pc (&sal_end
);
8371 end
= find_breakpoint_range_end (sal_end
);
8372 if (sal_start
.pc
> end
)
8373 error (_("Invalid address range, end precedes start."));
8375 length
= end
- sal_start
.pc
+ 1;
8377 /* Length overflowed. */
8378 error (_("Address range too large."));
8379 else if (length
== 1)
8381 /* This range is simple enough to be handled by
8382 the `hbreak' command. */
8383 hbreak_command (addr_string_start
, 1);
8385 do_cleanups (cleanup_bkpt
);
8390 /* Now set up the breakpoint. */
8391 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8392 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8393 set_breakpoint_count (breakpoint_count
+ 1);
8394 b
->number
= breakpoint_count
;
8395 b
->disposition
= disp_donttouch
;
8396 b
->addr_string
= addr_string_start
;
8397 b
->addr_string_range_end
= addr_string_end
;
8398 b
->loc
->length
= length
;
8400 discard_cleanups (cleanup_bkpt
);
8403 observer_notify_breakpoint_created (b
);
8404 update_global_location_list (1);
8407 /* Return non-zero if EXP is verified as constant. Returned zero
8408 means EXP is variable. Also the constant detection may fail for
8409 some constant expressions and in such case still falsely return
8412 watchpoint_exp_is_const (const struct expression
*exp
)
8420 /* We are only interested in the descriptor of each element. */
8421 operator_length (exp
, i
, &oplenp
, &argsp
);
8424 switch (exp
->elts
[i
].opcode
)
8434 case BINOP_LOGICAL_AND
:
8435 case BINOP_LOGICAL_OR
:
8436 case BINOP_BITWISE_AND
:
8437 case BINOP_BITWISE_IOR
:
8438 case BINOP_BITWISE_XOR
:
8440 case BINOP_NOTEQUAL
:
8456 case TERNOP_SLICE_COUNT
:
8468 case OP_OBJC_NSSTRING
:
8471 case UNOP_LOGICAL_NOT
:
8472 case UNOP_COMPLEMENT
:
8475 /* Unary, binary and ternary operators: We have to check
8476 their operands. If they are constant, then so is the
8477 result of that operation. For instance, if A and B are
8478 determined to be constants, then so is "A + B".
8480 UNOP_IND is one exception to the rule above, because the
8481 value of *ADDR is not necessarily a constant, even when
8486 /* Check whether the associated symbol is a constant.
8488 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8489 possible that a buggy compiler could mark a variable as
8490 constant even when it is not, and TYPE_CONST would return
8491 true in this case, while SYMBOL_CLASS wouldn't.
8493 We also have to check for function symbols because they
8494 are always constant. */
8496 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8498 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8499 && SYMBOL_CLASS (s
) != LOC_CONST
8500 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8505 /* The default action is to return 0 because we are using
8506 the optimistic approach here: If we don't know something,
8507 then it is not a constant. */
8516 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8519 dtor_watchpoint (struct breakpoint
*self
)
8521 struct watchpoint
*w
= (struct watchpoint
*) self
;
8523 xfree (w
->cond_exp
);
8525 xfree (w
->exp_string
);
8526 xfree (w
->exp_string_reparse
);
8527 value_free (w
->val
);
8529 base_breakpoint_ops
.dtor (self
);
8532 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8535 re_set_watchpoint (struct breakpoint
*b
)
8537 struct watchpoint
*w
= (struct watchpoint
*) b
;
8539 /* Watchpoint can be either on expression using entirely global
8540 variables, or it can be on local variables.
8542 Watchpoints of the first kind are never auto-deleted, and even
8543 persist across program restarts. Since they can use variables
8544 from shared libraries, we need to reparse expression as libraries
8545 are loaded and unloaded.
8547 Watchpoints on local variables can also change meaning as result
8548 of solib event. For example, if a watchpoint uses both a local
8549 and a global variables in expression, it's a local watchpoint,
8550 but unloading of a shared library will make the expression
8551 invalid. This is not a very common use case, but we still
8552 re-evaluate expression, to avoid surprises to the user.
8554 Note that for local watchpoints, we re-evaluate it only if
8555 watchpoints frame id is still valid. If it's not, it means the
8556 watchpoint is out of scope and will be deleted soon. In fact,
8557 I'm not sure we'll ever be called in this case.
8559 If a local watchpoint's frame id is still valid, then
8560 w->exp_valid_block is likewise valid, and we can safely use it.
8562 Don't do anything about disabled watchpoints, since they will be
8563 reevaluated again when enabled. */
8564 update_watchpoint (w
, 1 /* reparse */);
8567 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8570 insert_watchpoint (struct bp_location
*bl
)
8572 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8573 int length
= w
->exact
? 1 : bl
->length
;
8575 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8579 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8582 remove_watchpoint (struct bp_location
*bl
)
8584 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8585 int length
= w
->exact
? 1 : bl
->length
;
8587 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8592 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8593 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8595 struct breakpoint
*b
= bl
->owner
;
8596 struct watchpoint
*w
= (struct watchpoint
*) b
;
8598 /* Continuable hardware watchpoints are treated as non-existent if the
8599 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8600 some data address). Otherwise gdb won't stop on a break instruction
8601 in the code (not from a breakpoint) when a hardware watchpoint has
8602 been defined. Also skip watchpoints which we know did not trigger
8603 (did not match the data address). */
8604 if (is_hardware_watchpoint (b
)
8605 && w
->watchpoint_triggered
== watch_triggered_no
)
8612 check_status_watchpoint (bpstat bs
)
8614 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8616 bpstat_check_watchpoint (bs
);
8619 /* Implement the "resources_needed" breakpoint_ops method for
8620 hardware watchpoints. */
8623 resources_needed_watchpoint (const struct bp_location
*bl
)
8625 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8626 int length
= w
->exact
? 1 : bl
->length
;
8628 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8631 /* Implement the "works_in_software_mode" breakpoint_ops method for
8632 hardware watchpoints. */
8635 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8637 /* Read and access watchpoints only work with hardware support. */
8638 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8641 static enum print_stop_action
8642 print_it_watchpoint (bpstat bs
)
8644 struct cleanup
*old_chain
;
8645 struct breakpoint
*b
;
8646 const struct bp_location
*bl
;
8647 struct ui_stream
*stb
;
8648 enum print_stop_action result
;
8649 struct watchpoint
*w
;
8651 gdb_assert (bs
->bp_location_at
!= NULL
);
8653 bl
= bs
->bp_location_at
;
8654 b
= bs
->breakpoint_at
;
8655 w
= (struct watchpoint
*) b
;
8657 stb
= ui_out_stream_new (uiout
);
8658 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8663 case bp_hardware_watchpoint
:
8664 annotate_watchpoint (b
->number
);
8665 if (ui_out_is_mi_like_p (uiout
))
8668 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8670 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8671 ui_out_text (uiout
, "\nOld value = ");
8672 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8673 ui_out_field_stream (uiout
, "old", stb
);
8674 ui_out_text (uiout
, "\nNew value = ");
8675 watchpoint_value_print (w
->val
, stb
->stream
);
8676 ui_out_field_stream (uiout
, "new", stb
);
8677 ui_out_text (uiout
, "\n");
8678 /* More than one watchpoint may have been triggered. */
8679 result
= PRINT_UNKNOWN
;
8682 case bp_read_watchpoint
:
8683 if (ui_out_is_mi_like_p (uiout
))
8686 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8688 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8689 ui_out_text (uiout
, "\nValue = ");
8690 watchpoint_value_print (w
->val
, stb
->stream
);
8691 ui_out_field_stream (uiout
, "value", stb
);
8692 ui_out_text (uiout
, "\n");
8693 result
= PRINT_UNKNOWN
;
8696 case bp_access_watchpoint
:
8697 if (bs
->old_val
!= NULL
)
8699 annotate_watchpoint (b
->number
);
8700 if (ui_out_is_mi_like_p (uiout
))
8703 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8705 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8706 ui_out_text (uiout
, "\nOld value = ");
8707 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8708 ui_out_field_stream (uiout
, "old", stb
);
8709 ui_out_text (uiout
, "\nNew value = ");
8714 if (ui_out_is_mi_like_p (uiout
))
8717 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8718 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8719 ui_out_text (uiout
, "\nValue = ");
8721 watchpoint_value_print (w
->val
, stb
->stream
);
8722 ui_out_field_stream (uiout
, "new", stb
);
8723 ui_out_text (uiout
, "\n");
8724 result
= PRINT_UNKNOWN
;
8727 result
= PRINT_UNKNOWN
;
8730 do_cleanups (old_chain
);
8734 /* Implement the "print_mention" breakpoint_ops method for hardware
8738 print_mention_watchpoint (struct breakpoint
*b
)
8740 struct cleanup
*ui_out_chain
;
8741 struct watchpoint
*w
= (struct watchpoint
*) b
;
8746 ui_out_text (uiout
, "Watchpoint ");
8747 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8749 case bp_hardware_watchpoint
:
8750 ui_out_text (uiout
, "Hardware watchpoint ");
8751 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8753 case bp_read_watchpoint
:
8754 ui_out_text (uiout
, "Hardware read watchpoint ");
8755 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8757 case bp_access_watchpoint
:
8758 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8759 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8762 internal_error (__FILE__
, __LINE__
,
8763 _("Invalid hardware watchpoint type."));
8766 ui_out_field_int (uiout
, "number", b
->number
);
8767 ui_out_text (uiout
, ": ");
8768 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8769 do_cleanups (ui_out_chain
);
8772 /* Implement the "print_recreate" breakpoint_ops method for
8776 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8778 struct watchpoint
*w
= (struct watchpoint
*) b
;
8783 case bp_hardware_watchpoint
:
8784 fprintf_unfiltered (fp
, "watch");
8786 case bp_read_watchpoint
:
8787 fprintf_unfiltered (fp
, "rwatch");
8789 case bp_access_watchpoint
:
8790 fprintf_unfiltered (fp
, "awatch");
8793 internal_error (__FILE__
, __LINE__
,
8794 _("Invalid watchpoint type."));
8797 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8798 print_recreate_thread (b
, fp
);
8801 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8803 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8805 /* Implement the "insert" breakpoint_ops method for
8806 masked hardware watchpoints. */
8809 insert_masked_watchpoint (struct bp_location
*bl
)
8811 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8813 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8814 bl
->watchpoint_type
);
8817 /* Implement the "remove" breakpoint_ops method for
8818 masked hardware watchpoints. */
8821 remove_masked_watchpoint (struct bp_location
*bl
)
8823 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8825 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8826 bl
->watchpoint_type
);
8829 /* Implement the "resources_needed" breakpoint_ops method for
8830 masked hardware watchpoints. */
8833 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8835 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8837 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
8840 /* Implement the "works_in_software_mode" breakpoint_ops method for
8841 masked hardware watchpoints. */
8844 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8849 /* Implement the "print_it" breakpoint_ops method for
8850 masked hardware watchpoints. */
8852 static enum print_stop_action
8853 print_it_masked_watchpoint (bpstat bs
)
8855 struct breakpoint
*b
= bs
->breakpoint_at
;
8857 /* Masked watchpoints have only one location. */
8858 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8862 case bp_hardware_watchpoint
:
8863 annotate_watchpoint (b
->number
);
8864 if (ui_out_is_mi_like_p (uiout
))
8867 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8870 case bp_read_watchpoint
:
8871 if (ui_out_is_mi_like_p (uiout
))
8874 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8877 case bp_access_watchpoint
:
8878 if (ui_out_is_mi_like_p (uiout
))
8881 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8884 internal_error (__FILE__
, __LINE__
,
8885 _("Invalid hardware watchpoint type."));
8889 ui_out_text (uiout
, _("\n\
8890 Check the underlying instruction at PC for the memory\n\
8891 address and value which triggered this watchpoint.\n"));
8892 ui_out_text (uiout
, "\n");
8894 /* More than one watchpoint may have been triggered. */
8895 return PRINT_UNKNOWN
;
8898 /* Implement the "print_one_detail" breakpoint_ops method for
8899 masked hardware watchpoints. */
8902 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8903 struct ui_out
*uiout
)
8905 struct watchpoint
*w
= (struct watchpoint
*) b
;
8907 /* Masked watchpoints have only one location. */
8908 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8910 ui_out_text (uiout
, "\tmask ");
8911 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
8912 ui_out_text (uiout
, "\n");
8915 /* Implement the "print_mention" breakpoint_ops method for
8916 masked hardware watchpoints. */
8919 print_mention_masked_watchpoint (struct breakpoint
*b
)
8921 struct watchpoint
*w
= (struct watchpoint
*) b
;
8922 struct cleanup
*ui_out_chain
;
8926 case bp_hardware_watchpoint
:
8927 ui_out_text (uiout
, "Masked hardware watchpoint ");
8928 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8930 case bp_read_watchpoint
:
8931 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8932 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8934 case bp_access_watchpoint
:
8935 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8936 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8939 internal_error (__FILE__
, __LINE__
,
8940 _("Invalid hardware watchpoint type."));
8943 ui_out_field_int (uiout
, "number", b
->number
);
8944 ui_out_text (uiout
, ": ");
8945 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8946 do_cleanups (ui_out_chain
);
8949 /* Implement the "print_recreate" breakpoint_ops method for
8950 masked hardware watchpoints. */
8953 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8955 struct watchpoint
*w
= (struct watchpoint
*) b
;
8960 case bp_hardware_watchpoint
:
8961 fprintf_unfiltered (fp
, "watch");
8963 case bp_read_watchpoint
:
8964 fprintf_unfiltered (fp
, "rwatch");
8966 case bp_access_watchpoint
:
8967 fprintf_unfiltered (fp
, "awatch");
8970 internal_error (__FILE__
, __LINE__
,
8971 _("Invalid hardware watchpoint type."));
8974 sprintf_vma (tmp
, w
->hw_wp_mask
);
8975 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
8976 print_recreate_thread (b
, fp
);
8979 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
8981 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
8983 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
8986 is_masked_watchpoint (const struct breakpoint
*b
)
8988 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
8991 /* accessflag: hw_write: watch write,
8992 hw_read: watch read,
8993 hw_access: watch access (read or write) */
8995 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8996 int just_location
, int internal
)
8998 volatile struct gdb_exception e
;
8999 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9000 struct expression
*exp
;
9001 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9002 struct value
*val
, *mark
, *result
;
9003 struct frame_info
*frame
;
9004 char *exp_start
= NULL
;
9005 char *exp_end
= NULL
;
9006 char *tok
, *end_tok
;
9008 char *cond_start
= NULL
;
9009 char *cond_end
= NULL
;
9010 enum bptype bp_type
;
9013 /* Flag to indicate whether we are going to use masks for
9014 the hardware watchpoint. */
9017 struct watchpoint
*w
;
9019 /* Make sure that we actually have parameters to parse. */
9020 if (arg
!= NULL
&& arg
[0] != '\0')
9024 /* Look for "parameter value" pairs at the end
9025 of the arguments string. */
9026 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9028 /* Skip whitespace at the end of the argument list. */
9029 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9032 /* Find the beginning of the last token.
9033 This is the value of the parameter. */
9034 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9036 value_start
= tok
+ 1;
9038 /* Skip whitespace. */
9039 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9044 /* Find the beginning of the second to last token.
9045 This is the parameter itself. */
9046 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9049 toklen
= end_tok
- tok
+ 1;
9051 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9053 /* At this point we've found a "thread" token, which means
9054 the user is trying to set a watchpoint that triggers
9055 only in a specific thread. */
9059 error(_("You can specify only one thread."));
9061 /* Extract the thread ID from the next token. */
9062 thread
= strtol (value_start
, &endp
, 0);
9064 /* Check if the user provided a valid numeric value for the
9066 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9067 error (_("Invalid thread ID specification %s."), value_start
);
9069 /* Check if the thread actually exists. */
9070 if (!valid_thread_id (thread
))
9071 error (_("Unknown thread %d."), thread
);
9073 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9075 /* We've found a "mask" token, which means the user wants to
9076 create a hardware watchpoint that is going to have the mask
9078 struct value
*mask_value
, *mark
;
9081 error(_("You can specify only one mask."));
9083 use_mask
= just_location
= 1;
9085 mark
= value_mark ();
9086 mask_value
= parse_to_comma_and_eval (&value_start
);
9087 mask
= value_as_address (mask_value
);
9088 value_free_to_mark (mark
);
9091 /* We didn't recognize what we found. We should stop here. */
9094 /* Truncate the string and get rid of the "parameter value" pair before
9095 the arguments string is parsed by the parse_exp_1 function. */
9100 /* Parse the rest of the arguments. */
9101 innermost_block
= NULL
;
9103 exp
= parse_exp_1 (&arg
, 0, 0);
9105 /* Remove trailing whitespace from the expression before saving it.
9106 This makes the eventual display of the expression string a bit
9108 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9111 /* Checking if the expression is not constant. */
9112 if (watchpoint_exp_is_const (exp
))
9116 len
= exp_end
- exp_start
;
9117 while (len
> 0 && isspace (exp_start
[len
- 1]))
9119 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9122 exp_valid_block
= innermost_block
;
9123 mark
= value_mark ();
9124 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9130 exp_valid_block
= NULL
;
9131 val
= value_addr (result
);
9132 release_value (val
);
9133 value_free_to_mark (mark
);
9137 ret
= target_masked_watch_num_registers (value_as_address (val
),
9140 error (_("This target does not support masked watchpoints."));
9142 error (_("Invalid mask or memory region."));
9145 else if (val
!= NULL
)
9146 release_value (val
);
9148 tok
= skip_spaces (arg
);
9149 end_tok
= skip_to_space (tok
);
9151 toklen
= end_tok
- tok
;
9152 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9154 struct expression
*cond
;
9156 innermost_block
= NULL
;
9157 tok
= cond_start
= end_tok
+ 1;
9158 cond
= parse_exp_1 (&tok
, 0, 0);
9160 /* The watchpoint expression may not be local, but the condition
9161 may still be. E.g.: `watch global if local > 0'. */
9162 cond_exp_valid_block
= innermost_block
;
9168 error (_("Junk at end of command."));
9170 if (accessflag
== hw_read
)
9171 bp_type
= bp_read_watchpoint
;
9172 else if (accessflag
== hw_access
)
9173 bp_type
= bp_access_watchpoint
;
9175 bp_type
= bp_hardware_watchpoint
;
9177 frame
= block_innermost_frame (exp_valid_block
);
9179 /* If the expression is "local", then set up a "watchpoint scope"
9180 breakpoint at the point where we've left the scope of the watchpoint
9181 expression. Create the scope breakpoint before the watchpoint, so
9182 that we will encounter it first in bpstat_stop_status. */
9183 if (exp_valid_block
&& frame
)
9185 if (frame_id_p (frame_unwind_caller_id (frame
)))
9188 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9189 frame_unwind_caller_pc (frame
),
9190 bp_watchpoint_scope
,
9191 &momentary_breakpoint_ops
);
9193 scope_breakpoint
->enable_state
= bp_enabled
;
9195 /* Automatically delete the breakpoint when it hits. */
9196 scope_breakpoint
->disposition
= disp_del
;
9198 /* Only break in the proper frame (help with recursion). */
9199 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9201 /* Set the address at which we will stop. */
9202 scope_breakpoint
->loc
->gdbarch
9203 = frame_unwind_caller_arch (frame
);
9204 scope_breakpoint
->loc
->requested_address
9205 = frame_unwind_caller_pc (frame
);
9206 scope_breakpoint
->loc
->address
9207 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9208 scope_breakpoint
->loc
->requested_address
,
9209 scope_breakpoint
->type
);
9213 /* Now set up the breakpoint. */
9215 w
= XCNEW (struct watchpoint
);
9218 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9219 &masked_watchpoint_breakpoint_ops
);
9221 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9222 &watchpoint_breakpoint_ops
);
9224 b
->disposition
= disp_donttouch
;
9225 b
->pspace
= current_program_space
;
9227 w
->exp_valid_block
= exp_valid_block
;
9228 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9231 struct type
*t
= value_type (val
);
9232 CORE_ADDR addr
= value_as_address (val
);
9235 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9236 name
= type_to_string (t
);
9238 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9239 core_addr_to_string (addr
));
9242 w
->exp_string
= xstrprintf ("-location %.*s",
9243 (int) (exp_end
- exp_start
), exp_start
);
9245 /* The above expression is in C. */
9246 b
->language
= language_c
;
9249 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9253 w
->hw_wp_mask
= mask
;
9262 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9268 w
->watchpoint_frame
= get_frame_id (frame
);
9269 w
->watchpoint_thread
= inferior_ptid
;
9273 w
->watchpoint_frame
= null_frame_id
;
9274 w
->watchpoint_thread
= null_ptid
;
9277 if (scope_breakpoint
!= NULL
)
9279 /* The scope breakpoint is related to the watchpoint. We will
9280 need to act on them together. */
9281 b
->related_breakpoint
= scope_breakpoint
;
9282 scope_breakpoint
->related_breakpoint
= b
;
9286 value_free_to_mark (mark
);
9288 TRY_CATCH (e
, RETURN_MASK_ALL
)
9290 /* Finally update the new watchpoint. This creates the locations
9291 that should be inserted. */
9292 update_watchpoint (w
, 1);
9296 delete_breakpoint (b
);
9297 throw_exception (e
);
9300 install_breakpoint (internal
, b
);
9303 /* Return count of debug registers needed to watch the given expression.
9304 If the watchpoint cannot be handled in hardware return zero. */
9307 can_use_hardware_watchpoint (struct value
*v
)
9309 int found_memory_cnt
= 0;
9310 struct value
*head
= v
;
9312 /* Did the user specifically forbid us to use hardware watchpoints? */
9313 if (!can_use_hw_watchpoints
)
9316 /* Make sure that the value of the expression depends only upon
9317 memory contents, and values computed from them within GDB. If we
9318 find any register references or function calls, we can't use a
9319 hardware watchpoint.
9321 The idea here is that evaluating an expression generates a series
9322 of values, one holding the value of every subexpression. (The
9323 expression a*b+c has five subexpressions: a, b, a*b, c, and
9324 a*b+c.) GDB's values hold almost enough information to establish
9325 the criteria given above --- they identify memory lvalues,
9326 register lvalues, computed values, etcetera. So we can evaluate
9327 the expression, and then scan the chain of values that leaves
9328 behind to decide whether we can detect any possible change to the
9329 expression's final value using only hardware watchpoints.
9331 However, I don't think that the values returned by inferior
9332 function calls are special in any way. So this function may not
9333 notice that an expression involving an inferior function call
9334 can't be watched with hardware watchpoints. FIXME. */
9335 for (; v
; v
= value_next (v
))
9337 if (VALUE_LVAL (v
) == lval_memory
)
9339 if (v
!= head
&& value_lazy (v
))
9340 /* A lazy memory lvalue in the chain is one that GDB never
9341 needed to fetch; we either just used its address (e.g.,
9342 `a' in `a.b') or we never needed it at all (e.g., `a'
9343 in `a,b'). This doesn't apply to HEAD; if that is
9344 lazy then it was not readable, but watch it anyway. */
9348 /* Ahh, memory we actually used! Check if we can cover
9349 it with hardware watchpoints. */
9350 struct type
*vtype
= check_typedef (value_type (v
));
9352 /* We only watch structs and arrays if user asked for it
9353 explicitly, never if they just happen to appear in a
9354 middle of some value chain. */
9356 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9357 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9359 CORE_ADDR vaddr
= value_address (v
);
9363 len
= (target_exact_watchpoints
9364 && is_scalar_type_recursive (vtype
))?
9365 1 : TYPE_LENGTH (value_type (v
));
9367 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9371 found_memory_cnt
+= num_regs
;
9375 else if (VALUE_LVAL (v
) != not_lval
9376 && deprecated_value_modifiable (v
) == 0)
9377 return 0; /* These are values from the history (e.g., $1). */
9378 else if (VALUE_LVAL (v
) == lval_register
)
9379 return 0; /* Cannot watch a register with a HW watchpoint. */
9382 /* The expression itself looks suitable for using a hardware
9383 watchpoint, but give the target machine a chance to reject it. */
9384 return found_memory_cnt
;
9388 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9390 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9393 /* A helper function that looks for an argument at the start of a
9394 string. The argument must also either be at the end of the string,
9395 or be followed by whitespace. Returns 1 if it finds the argument,
9396 0 otherwise. If the argument is found, it updates *STR. */
9399 check_for_argument (char **str
, char *arg
, int arg_len
)
9401 if (strncmp (*str
, arg
, arg_len
) == 0
9402 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9410 /* A helper function that looks for the "-location" argument and then
9411 calls watch_command_1. */
9414 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9416 int just_location
= 0;
9419 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9420 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9422 arg
= skip_spaces (arg
);
9426 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9430 watch_command (char *arg
, int from_tty
)
9432 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9436 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9438 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9442 rwatch_command (char *arg
, int from_tty
)
9444 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9448 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9450 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9454 awatch_command (char *arg
, int from_tty
)
9456 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9460 /* Helper routines for the until_command routine in infcmd.c. Here
9461 because it uses the mechanisms of breakpoints. */
9463 struct until_break_command_continuation_args
9465 struct breakpoint
*breakpoint
;
9466 struct breakpoint
*breakpoint2
;
9470 /* This function is called by fetch_inferior_event via the
9471 cmd_continuation pointer, to complete the until command. It takes
9472 care of cleaning up the temporary breakpoints set up by the until
9475 until_break_command_continuation (void *arg
, int err
)
9477 struct until_break_command_continuation_args
*a
= arg
;
9479 delete_breakpoint (a
->breakpoint
);
9481 delete_breakpoint (a
->breakpoint2
);
9482 delete_longjmp_breakpoint (a
->thread_num
);
9486 until_break_command (char *arg
, int from_tty
, int anywhere
)
9488 struct symtabs_and_lines sals
;
9489 struct symtab_and_line sal
;
9490 struct frame_info
*frame
= get_selected_frame (NULL
);
9491 struct breakpoint
*breakpoint
;
9492 struct breakpoint
*breakpoint2
= NULL
;
9493 struct cleanup
*old_chain
;
9495 struct thread_info
*tp
;
9497 clear_proceed_status ();
9499 /* Set a breakpoint where the user wants it and at return from
9502 if (default_breakpoint_valid
)
9503 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
9504 default_breakpoint_line
, NULL
);
9506 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9508 if (sals
.nelts
!= 1)
9509 error (_("Couldn't get information on specified line."));
9512 xfree (sals
.sals
); /* malloc'd, so freed. */
9515 error (_("Junk at end of arguments."));
9517 resolve_sal_pc (&sal
);
9520 /* If the user told us to continue until a specified location,
9521 we don't specify a frame at which we need to stop. */
9522 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9523 null_frame_id
, bp_until
);
9525 /* Otherwise, specify the selected frame, because we want to stop
9526 only at the very same frame. */
9527 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9528 get_stack_frame_id (frame
),
9531 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9533 tp
= inferior_thread ();
9536 /* Keep within the current frame, or in frames called by the current
9539 if (frame_id_p (frame_unwind_caller_id (frame
)))
9541 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9542 sal
.pc
= frame_unwind_caller_pc (frame
);
9543 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9545 frame_unwind_caller_id (frame
),
9547 make_cleanup_delete_breakpoint (breakpoint2
);
9549 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9550 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9553 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9555 /* If we are running asynchronously, and proceed call above has
9556 actually managed to start the target, arrange for breakpoints to
9557 be deleted when the target stops. Otherwise, we're already
9558 stopped and delete breakpoints via cleanup chain. */
9560 if (target_can_async_p () && is_running (inferior_ptid
))
9562 struct until_break_command_continuation_args
*args
;
9563 args
= xmalloc (sizeof (*args
));
9565 args
->breakpoint
= breakpoint
;
9566 args
->breakpoint2
= breakpoint2
;
9567 args
->thread_num
= thread
;
9569 discard_cleanups (old_chain
);
9570 add_continuation (inferior_thread (),
9571 until_break_command_continuation
, args
,
9575 do_cleanups (old_chain
);
9578 /* This function attempts to parse an optional "if <cond>" clause
9579 from the arg string. If one is not found, it returns NULL.
9581 Else, it returns a pointer to the condition string. (It does not
9582 attempt to evaluate the string against a particular block.) And,
9583 it updates arg to point to the first character following the parsed
9584 if clause in the arg string. */
9587 ep_parse_optional_if_clause (char **arg
)
9591 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9594 /* Skip the "if" keyword. */
9597 /* Skip any extra leading whitespace, and record the start of the
9598 condition string. */
9599 *arg
= skip_spaces (*arg
);
9602 /* Assume that the condition occupies the remainder of the arg
9604 (*arg
) += strlen (cond_string
);
9609 /* Commands to deal with catching events, such as signals, exceptions,
9610 process start/exit, etc. */
9614 catch_fork_temporary
, catch_vfork_temporary
,
9615 catch_fork_permanent
, catch_vfork_permanent
9620 catch_fork_command_1 (char *arg
, int from_tty
,
9621 struct cmd_list_element
*command
)
9623 struct gdbarch
*gdbarch
= get_current_arch ();
9624 char *cond_string
= NULL
;
9625 catch_fork_kind fork_kind
;
9628 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9629 tempflag
= (fork_kind
== catch_fork_temporary
9630 || fork_kind
== catch_vfork_temporary
);
9634 arg
= skip_spaces (arg
);
9636 /* The allowed syntax is:
9638 catch [v]fork if <cond>
9640 First, check if there's an if clause. */
9641 cond_string
= ep_parse_optional_if_clause (&arg
);
9643 if ((*arg
!= '\0') && !isspace (*arg
))
9644 error (_("Junk at end of arguments."));
9646 /* If this target supports it, create a fork or vfork catchpoint
9647 and enable reporting of such events. */
9650 case catch_fork_temporary
:
9651 case catch_fork_permanent
:
9652 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9653 &catch_fork_breakpoint_ops
);
9655 case catch_vfork_temporary
:
9656 case catch_vfork_permanent
:
9657 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9658 &catch_vfork_breakpoint_ops
);
9661 error (_("unsupported or unknown fork kind; cannot catch it"));
9667 catch_exec_command_1 (char *arg
, int from_tty
,
9668 struct cmd_list_element
*command
)
9670 struct exec_catchpoint
*c
;
9671 struct gdbarch
*gdbarch
= get_current_arch ();
9673 char *cond_string
= NULL
;
9675 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9679 arg
= skip_spaces (arg
);
9681 /* The allowed syntax is:
9683 catch exec if <cond>
9685 First, check if there's an if clause. */
9686 cond_string
= ep_parse_optional_if_clause (&arg
);
9688 if ((*arg
!= '\0') && !isspace (*arg
))
9689 error (_("Junk at end of arguments."));
9691 c
= XNEW (struct exec_catchpoint
);
9692 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9693 &catch_exec_breakpoint_ops
);
9694 c
->exec_pathname
= NULL
;
9696 install_breakpoint (0, &c
->base
);
9699 static enum print_stop_action
9700 print_it_exception_catchpoint (bpstat bs
)
9702 struct breakpoint
*b
= bs
->breakpoint_at
;
9703 int bp_temp
, bp_throw
;
9705 annotate_catchpoint (b
->number
);
9707 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9708 if (b
->loc
->address
!= b
->loc
->requested_address
)
9709 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9712 bp_temp
= b
->disposition
== disp_del
;
9714 bp_temp
? "Temporary catchpoint "
9716 if (!ui_out_is_mi_like_p (uiout
))
9717 ui_out_field_int (uiout
, "bkptno", b
->number
);
9719 bp_throw
? " (exception thrown), "
9720 : " (exception caught), ");
9721 if (ui_out_is_mi_like_p (uiout
))
9723 ui_out_field_string (uiout
, "reason",
9724 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9725 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9726 ui_out_field_int (uiout
, "bkptno", b
->number
);
9728 return PRINT_SRC_AND_LOC
;
9732 print_one_exception_catchpoint (struct breakpoint
*b
,
9733 struct bp_location
**last_loc
)
9735 struct value_print_options opts
;
9737 get_user_print_options (&opts
);
9738 if (opts
.addressprint
)
9741 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9742 ui_out_field_string (uiout
, "addr", "<PENDING>");
9744 ui_out_field_core_addr (uiout
, "addr",
9745 b
->loc
->gdbarch
, b
->loc
->address
);
9750 if (strstr (b
->addr_string
, "throw") != NULL
)
9751 ui_out_field_string (uiout
, "what", "exception throw");
9753 ui_out_field_string (uiout
, "what", "exception catch");
9757 print_mention_exception_catchpoint (struct breakpoint
*b
)
9762 bp_temp
= b
->disposition
== disp_del
;
9763 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9764 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9765 : _("Catchpoint "));
9766 ui_out_field_int (uiout
, "bkptno", b
->number
);
9767 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9771 /* Implement the "print_recreate" breakpoint_ops method for throw and
9772 catch catchpoints. */
9775 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9781 bp_temp
= b
->disposition
== disp_del
;
9782 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9783 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9784 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9785 print_recreate_thread (b
, fp
);
9788 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9791 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9792 enum exception_event_kind ex_event
, int from_tty
)
9794 char *trigger_func_name
;
9796 if (ex_event
== EX_EVENT_CATCH
)
9797 trigger_func_name
= "__cxa_begin_catch";
9799 trigger_func_name
= "__cxa_throw";
9801 create_breakpoint (get_current_arch (),
9802 trigger_func_name
, cond_string
, -1,
9803 0 /* condition and thread are valid. */,
9804 tempflag
, bp_breakpoint
,
9806 AUTO_BOOLEAN_TRUE
/* pending */,
9807 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9814 /* Deal with "catch catch" and "catch throw" commands. */
9817 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9818 int tempflag
, int from_tty
)
9820 char *cond_string
= NULL
;
9824 arg
= skip_spaces (arg
);
9826 cond_string
= ep_parse_optional_if_clause (&arg
);
9828 if ((*arg
!= '\0') && !isspace (*arg
))
9829 error (_("Junk at end of arguments."));
9831 if (ex_event
!= EX_EVENT_THROW
9832 && ex_event
!= EX_EVENT_CATCH
)
9833 error (_("Unsupported or unknown exception event; cannot catch it"));
9835 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9838 warning (_("Unsupported with this platform/compiler combination."));
9841 /* Implementation of "catch catch" command. */
9844 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9846 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9848 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9851 /* Implementation of "catch throw" command. */
9854 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9856 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9858 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9862 init_ada_exception_breakpoint (struct breakpoint
*b
,
9863 struct gdbarch
*gdbarch
,
9864 struct symtab_and_line sal
,
9866 const struct breakpoint_ops
*ops
,
9872 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9874 loc_gdbarch
= gdbarch
;
9876 describe_other_breakpoints (loc_gdbarch
,
9877 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9878 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9879 version for exception catchpoints, because two catchpoints
9880 used for different exception names will use the same address.
9881 In this case, a "breakpoint ... also set at..." warning is
9882 unproductive. Besides, the warning phrasing is also a bit
9883 inappropriate, we should use the word catchpoint, and tell
9884 the user what type of catchpoint it is. The above is good
9885 enough for now, though. */
9888 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9890 b
->enable_state
= bp_enabled
;
9891 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9892 b
->addr_string
= addr_string
;
9893 b
->language
= language_ada
;
9896 /* Cleanup function for a syscall filter list. */
9898 clean_up_filters (void *arg
)
9900 VEC(int) *iter
= *(VEC(int) **) arg
;
9901 VEC_free (int, iter
);
9904 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9905 filter list, or NULL if no filtering is required. */
9907 catch_syscall_split_args (char *arg
)
9909 VEC(int) *result
= NULL
;
9910 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9912 while (*arg
!= '\0')
9914 int i
, syscall_number
;
9919 /* Skip whitespace. */
9920 while (isspace (*arg
))
9923 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9924 cur_name
[i
] = arg
[i
];
9928 /* Check if the user provided a syscall name or a number. */
9929 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9930 if (*endptr
== '\0')
9931 get_syscall_by_number (syscall_number
, &s
);
9934 /* We have a name. Let's check if it's valid and convert it
9936 get_syscall_by_name (cur_name
, &s
);
9938 if (s
.number
== UNKNOWN_SYSCALL
)
9939 /* Here we have to issue an error instead of a warning,
9940 because GDB cannot do anything useful if there's no
9941 syscall number to be caught. */
9942 error (_("Unknown syscall name '%s'."), cur_name
);
9945 /* Ok, it's valid. */
9946 VEC_safe_push (int, result
, s
.number
);
9949 discard_cleanups (cleanup
);
9953 /* Implement the "catch syscall" command. */
9956 catch_syscall_command_1 (char *arg
, int from_tty
,
9957 struct cmd_list_element
*command
)
9962 struct gdbarch
*gdbarch
= get_current_arch ();
9964 /* Checking if the feature if supported. */
9965 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9966 error (_("The feature 'catch syscall' is not supported on \
9967 this architecture yet."));
9969 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9971 arg
= skip_spaces (arg
);
9973 /* We need to do this first "dummy" translation in order
9974 to get the syscall XML file loaded or, most important,
9975 to display a warning to the user if there's no XML file
9976 for his/her architecture. */
9977 get_syscall_by_number (0, &s
);
9979 /* The allowed syntax is:
9981 catch syscall <name | number> [<name | number> ... <name | number>]
9983 Let's check if there's a syscall name. */
9986 filter
= catch_syscall_split_args (arg
);
9990 create_syscall_event_catchpoint (tempflag
, filter
,
9991 &catch_syscall_breakpoint_ops
);
9995 catch_command (char *arg
, int from_tty
)
9997 error (_("Catch requires an event name."));
10002 tcatch_command (char *arg
, int from_tty
)
10004 error (_("Catch requires an event name."));
10007 /* Delete breakpoints by address or line. */
10010 clear_command (char *arg
, int from_tty
)
10012 struct breakpoint
*b
;
10013 VEC(breakpoint_p
) *found
= 0;
10016 struct symtabs_and_lines sals
;
10017 struct symtab_and_line sal
;
10022 sals
= decode_line_spec (arg
, 1);
10027 sals
.sals
= (struct symtab_and_line
*)
10028 xmalloc (sizeof (struct symtab_and_line
));
10029 make_cleanup (xfree
, sals
.sals
);
10030 init_sal (&sal
); /* Initialize to zeroes. */
10031 sal
.line
= default_breakpoint_line
;
10032 sal
.symtab
= default_breakpoint_symtab
;
10033 sal
.pc
= default_breakpoint_address
;
10034 sal
.pspace
= default_breakpoint_pspace
;
10035 if (sal
.symtab
== 0)
10036 error (_("No source file specified."));
10038 sals
.sals
[0] = sal
;
10044 /* We don't call resolve_sal_pc here. That's not as bad as it
10045 seems, because all existing breakpoints typically have both
10046 file/line and pc set. So, if clear is given file/line, we can
10047 match this to existing breakpoint without obtaining pc at all.
10049 We only support clearing given the address explicitly
10050 present in breakpoint table. Say, we've set breakpoint
10051 at file:line. There were several PC values for that file:line,
10052 due to optimization, all in one block.
10054 We've picked one PC value. If "clear" is issued with another
10055 PC corresponding to the same file:line, the breakpoint won't
10056 be cleared. We probably can still clear the breakpoint, but
10057 since the other PC value is never presented to user, user
10058 can only find it by guessing, and it does not seem important
10059 to support that. */
10061 /* For each line spec given, delete bps which correspond to it. Do
10062 it in two passes, solely to preserve the current behavior that
10063 from_tty is forced true if we delete more than one
10067 for (i
= 0; i
< sals
.nelts
; i
++)
10069 /* If exact pc given, clear bpts at that pc.
10070 If line given (pc == 0), clear all bpts on specified line.
10071 If defaulting, clear all bpts on default line
10074 defaulting sal.pc != 0 tests to do
10079 1 0 <can't happen> */
10081 sal
= sals
.sals
[i
];
10083 /* Find all matching breakpoints and add them to 'found'. */
10084 ALL_BREAKPOINTS (b
)
10087 /* Are we going to delete b? */
10088 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10090 struct bp_location
*loc
= b
->loc
;
10091 for (; loc
; loc
= loc
->next
)
10093 int pc_match
= sal
.pc
10094 && (loc
->pspace
== sal
.pspace
)
10095 && (loc
->address
== sal
.pc
)
10096 && (!section_is_overlay (loc
->section
)
10097 || loc
->section
== sal
.section
);
10098 int line_match
= ((default_match
|| (0 == sal
.pc
))
10099 && b
->source_file
!= NULL
10100 && sal
.symtab
!= NULL
10101 && sal
.pspace
== loc
->pspace
10102 && filename_cmp (b
->source_file
,
10103 sal
.symtab
->filename
) == 0
10104 && b
->line_number
== sal
.line
);
10105 if (pc_match
|| line_match
)
10114 VEC_safe_push(breakpoint_p
, found
, b
);
10117 /* Now go thru the 'found' chain and delete them. */
10118 if (VEC_empty(breakpoint_p
, found
))
10121 error (_("No breakpoint at %s."), arg
);
10123 error (_("No breakpoint at this line."));
10126 if (VEC_length(breakpoint_p
, found
) > 1)
10127 from_tty
= 1; /* Always report if deleted more than one. */
10130 if (VEC_length(breakpoint_p
, found
) == 1)
10131 printf_unfiltered (_("Deleted breakpoint "));
10133 printf_unfiltered (_("Deleted breakpoints "));
10135 breakpoints_changed ();
10137 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10140 printf_unfiltered ("%d ", b
->number
);
10141 delete_breakpoint (b
);
10144 putchar_unfiltered ('\n');
10147 /* Delete breakpoint in BS if they are `delete' breakpoints and
10148 all breakpoints that are marked for deletion, whether hit or not.
10149 This is called after any breakpoint is hit, or after errors. */
10152 breakpoint_auto_delete (bpstat bs
)
10154 struct breakpoint
*b
, *b_tmp
;
10156 for (; bs
; bs
= bs
->next
)
10157 if (bs
->breakpoint_at
10158 && bs
->breakpoint_at
->disposition
== disp_del
10160 delete_breakpoint (bs
->breakpoint_at
);
10162 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10164 if (b
->disposition
== disp_del_at_next_stop
)
10165 delete_breakpoint (b
);
10169 /* A comparison function for bp_location AP and BP being interfaced to
10170 qsort. Sort elements primarily by their ADDRESS (no matter what
10171 does breakpoint_address_is_meaningful say for its OWNER),
10172 secondarily by ordering first bp_permanent OWNERed elements and
10173 terciarily just ensuring the array is sorted stable way despite
10174 qsort being an unstable algorithm. */
10177 bp_location_compare (const void *ap
, const void *bp
)
10179 struct bp_location
*a
= *(void **) ap
;
10180 struct bp_location
*b
= *(void **) bp
;
10181 /* A and B come from existing breakpoints having non-NULL OWNER. */
10182 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10183 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10185 if (a
->address
!= b
->address
)
10186 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10188 /* Sort permanent breakpoints first. */
10189 if (a_perm
!= b_perm
)
10190 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10192 /* Make the user-visible order stable across GDB runs. Locations of
10193 the same breakpoint can be sorted in arbitrary order. */
10195 if (a
->owner
->number
!= b
->owner
->number
)
10196 return (a
->owner
->number
> b
->owner
->number
)
10197 - (a
->owner
->number
< b
->owner
->number
);
10199 return (a
> b
) - (a
< b
);
10202 /* Set bp_location_placed_address_before_address_max and
10203 bp_location_shadow_len_after_address_max according to the current
10204 content of the bp_location array. */
10207 bp_location_target_extensions_update (void)
10209 struct bp_location
*bl
, **blp_tmp
;
10211 bp_location_placed_address_before_address_max
= 0;
10212 bp_location_shadow_len_after_address_max
= 0;
10214 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10216 CORE_ADDR start
, end
, addr
;
10218 if (!bp_location_has_shadow (bl
))
10221 start
= bl
->target_info
.placed_address
;
10222 end
= start
+ bl
->target_info
.shadow_len
;
10224 gdb_assert (bl
->address
>= start
);
10225 addr
= bl
->address
- start
;
10226 if (addr
> bp_location_placed_address_before_address_max
)
10227 bp_location_placed_address_before_address_max
= addr
;
10229 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10231 gdb_assert (bl
->address
< end
);
10232 addr
= end
- bl
->address
;
10233 if (addr
> bp_location_shadow_len_after_address_max
)
10234 bp_location_shadow_len_after_address_max
= addr
;
10238 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10239 into the inferior, only remove already-inserted locations that no
10240 longer should be inserted. Functions that delete a breakpoint or
10241 breakpoints should pass false, so that deleting a breakpoint
10242 doesn't have the side effect of inserting the locations of other
10243 breakpoints that are marked not-inserted, but should_be_inserted
10244 returns true on them.
10246 This behaviour is useful is situations close to tear-down -- e.g.,
10247 after an exec, while the target still has execution, but breakpoint
10248 shadows of the previous executable image should *NOT* be restored
10249 to the new image; or before detaching, where the target still has
10250 execution and wants to delete breakpoints from GDB's lists, and all
10251 breakpoints had already been removed from the inferior. */
10254 update_global_location_list (int should_insert
)
10256 struct breakpoint
*b
;
10257 struct bp_location
**locp
, *loc
;
10258 struct cleanup
*cleanups
;
10260 /* Used in the duplicates detection below. When iterating over all
10261 bp_locations, points to the first bp_location of a given address.
10262 Breakpoints and watchpoints of different types are never
10263 duplicates of each other. Keep one pointer for each type of
10264 breakpoint/watchpoint, so we only need to loop over all locations
10266 struct bp_location
*bp_loc_first
; /* breakpoint */
10267 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10268 struct bp_location
*awp_loc_first
; /* access watchpoint */
10269 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10271 /* Saved former bp_location array which we compare against the newly
10272 built bp_location from the current state of ALL_BREAKPOINTS. */
10273 struct bp_location
**old_location
, **old_locp
;
10274 unsigned old_location_count
;
10276 old_location
= bp_location
;
10277 old_location_count
= bp_location_count
;
10278 bp_location
= NULL
;
10279 bp_location_count
= 0;
10280 cleanups
= make_cleanup (xfree
, old_location
);
10282 ALL_BREAKPOINTS (b
)
10283 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10284 bp_location_count
++;
10286 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10287 locp
= bp_location
;
10288 ALL_BREAKPOINTS (b
)
10289 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10291 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10292 bp_location_compare
);
10294 bp_location_target_extensions_update ();
10296 /* Identify bp_location instances that are no longer present in the
10297 new list, and therefore should be freed. Note that it's not
10298 necessary that those locations should be removed from inferior --
10299 if there's another location at the same address (previously
10300 marked as duplicate), we don't need to remove/insert the
10303 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10304 and former bp_location array state respectively. */
10306 locp
= bp_location
;
10307 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10310 struct bp_location
*old_loc
= *old_locp
;
10311 struct bp_location
**loc2p
;
10313 /* Tells if 'old_loc' is found among the new locations. If
10314 not, we have to free it. */
10315 int found_object
= 0;
10316 /* Tells if the location should remain inserted in the target. */
10317 int keep_in_target
= 0;
10320 /* Skip LOCP entries which will definitely never be needed.
10321 Stop either at or being the one matching OLD_LOC. */
10322 while (locp
< bp_location
+ bp_location_count
10323 && (*locp
)->address
< old_loc
->address
)
10327 (loc2p
< bp_location
+ bp_location_count
10328 && (*loc2p
)->address
== old_loc
->address
);
10331 if (*loc2p
== old_loc
)
10338 /* If this location is no longer present, and inserted, look if
10339 there's maybe a new location at the same address. If so,
10340 mark that one inserted, and don't remove this one. This is
10341 needed so that we don't have a time window where a breakpoint
10342 at certain location is not inserted. */
10344 if (old_loc
->inserted
)
10346 /* If the location is inserted now, we might have to remove
10349 if (found_object
&& should_be_inserted (old_loc
))
10351 /* The location is still present in the location list,
10352 and still should be inserted. Don't do anything. */
10353 keep_in_target
= 1;
10357 /* The location is either no longer present, or got
10358 disabled. See if there's another location at the
10359 same address, in which case we don't need to remove
10360 this one from the target. */
10362 /* OLD_LOC comes from existing struct breakpoint. */
10363 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10366 (loc2p
< bp_location
+ bp_location_count
10367 && (*loc2p
)->address
== old_loc
->address
);
10370 struct bp_location
*loc2
= *loc2p
;
10372 if (breakpoint_locations_match (loc2
, old_loc
))
10374 /* For the sake of should_be_inserted.
10375 Duplicates check below will fix up this
10377 loc2
->duplicate
= 0;
10379 /* Read watchpoint locations are switched to
10380 access watchpoints, if the former are not
10381 supported, but the latter are. */
10382 if (is_hardware_watchpoint (old_loc
->owner
))
10384 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10385 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10388 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
10390 loc2
->inserted
= 1;
10391 loc2
->target_info
= old_loc
->target_info
;
10392 keep_in_target
= 1;
10400 if (!keep_in_target
)
10402 if (remove_breakpoint (old_loc
, mark_uninserted
))
10404 /* This is just about all we can do. We could keep
10405 this location on the global list, and try to
10406 remove it next time, but there's no particular
10407 reason why we will succeed next time.
10409 Note that at this point, old_loc->owner is still
10410 valid, as delete_breakpoint frees the breakpoint
10411 only after calling us. */
10412 printf_filtered (_("warning: Error removing "
10413 "breakpoint %d\n"),
10414 old_loc
->owner
->number
);
10422 if (removed
&& non_stop
10423 && breakpoint_address_is_meaningful (old_loc
->owner
)
10424 && !is_hardware_watchpoint (old_loc
->owner
))
10426 /* This location was removed from the target. In
10427 non-stop mode, a race condition is possible where
10428 we've removed a breakpoint, but stop events for that
10429 breakpoint are already queued and will arrive later.
10430 We apply an heuristic to be able to distinguish such
10431 SIGTRAPs from other random SIGTRAPs: we keep this
10432 breakpoint location for a bit, and will retire it
10433 after we see some number of events. The theory here
10434 is that reporting of events should, "on the average",
10435 be fair, so after a while we'll see events from all
10436 threads that have anything of interest, and no longer
10437 need to keep this breakpoint location around. We
10438 don't hold locations forever so to reduce chances of
10439 mistaking a non-breakpoint SIGTRAP for a breakpoint
10442 The heuristic failing can be disastrous on
10443 decr_pc_after_break targets.
10445 On decr_pc_after_break targets, like e.g., x86-linux,
10446 if we fail to recognize a late breakpoint SIGTRAP,
10447 because events_till_retirement has reached 0 too
10448 soon, we'll fail to do the PC adjustment, and report
10449 a random SIGTRAP to the user. When the user resumes
10450 the inferior, it will most likely immediately crash
10451 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10452 corrupted, because of being resumed e.g., in the
10453 middle of a multi-byte instruction, or skipped a
10454 one-byte instruction. This was actually seen happen
10455 on native x86-linux, and should be less rare on
10456 targets that do not support new thread events, like
10457 remote, due to the heuristic depending on
10460 Mistaking a random SIGTRAP for a breakpoint trap
10461 causes similar symptoms (PC adjustment applied when
10462 it shouldn't), but then again, playing with SIGTRAPs
10463 behind the debugger's back is asking for trouble.
10465 Since hardware watchpoint traps are always
10466 distinguishable from other traps, so we don't need to
10467 apply keep hardware watchpoint moribund locations
10468 around. We simply always ignore hardware watchpoint
10469 traps we can no longer explain. */
10471 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10472 old_loc
->owner
= NULL
;
10474 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10478 old_loc
->owner
= NULL
;
10479 decref_bp_location (&old_loc
);
10484 /* Rescan breakpoints at the same address and section, marking the
10485 first one as "first" and any others as "duplicates". This is so
10486 that the bpt instruction is only inserted once. If we have a
10487 permanent breakpoint at the same place as BPT, make that one the
10488 official one, and the rest as duplicates. Permanent breakpoints
10489 are sorted first for the same address.
10491 Do the same for hardware watchpoints, but also considering the
10492 watchpoint's type (regular/access/read) and length. */
10494 bp_loc_first
= NULL
;
10495 wp_loc_first
= NULL
;
10496 awp_loc_first
= NULL
;
10497 rwp_loc_first
= NULL
;
10498 ALL_BP_LOCATIONS (loc
, locp
)
10500 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10502 struct breakpoint
*b
= loc
->owner
;
10503 struct bp_location
**loc_first_p
;
10505 if (b
->enable_state
== bp_disabled
10506 || b
->enable_state
== bp_call_disabled
10507 || b
->enable_state
== bp_startup_disabled
10509 || loc
->shlib_disabled
10510 || !breakpoint_address_is_meaningful (b
)
10511 || is_tracepoint (b
))
10514 /* Permanent breakpoint should always be inserted. */
10515 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10516 internal_error (__FILE__
, __LINE__
,
10517 _("allegedly permanent breakpoint is not "
10518 "actually inserted"));
10520 if (b
->type
== bp_hardware_watchpoint
)
10521 loc_first_p
= &wp_loc_first
;
10522 else if (b
->type
== bp_read_watchpoint
)
10523 loc_first_p
= &rwp_loc_first
;
10524 else if (b
->type
== bp_access_watchpoint
)
10525 loc_first_p
= &awp_loc_first
;
10527 loc_first_p
= &bp_loc_first
;
10529 if (*loc_first_p
== NULL
10530 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10531 || !breakpoint_locations_match (loc
, *loc_first_p
))
10533 *loc_first_p
= loc
;
10534 loc
->duplicate
= 0;
10538 loc
->duplicate
= 1;
10540 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10541 && b
->enable_state
!= bp_permanent
)
10542 internal_error (__FILE__
, __LINE__
,
10543 _("another breakpoint was inserted on top of "
10544 "a permanent breakpoint"));
10547 if (breakpoints_always_inserted_mode () && should_insert
10548 && (have_live_inferiors ()
10549 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10550 insert_breakpoint_locations ();
10552 do_cleanups (cleanups
);
10556 breakpoint_retire_moribund (void)
10558 struct bp_location
*loc
;
10561 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10562 if (--(loc
->events_till_retirement
) == 0)
10564 decref_bp_location (&loc
);
10565 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10571 update_global_location_list_nothrow (int inserting
)
10573 struct gdb_exception e
;
10575 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10576 update_global_location_list (inserting
);
10579 /* Clear BKP from a BPS. */
10582 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10586 for (bs
= bps
; bs
; bs
= bs
->next
)
10587 if (bs
->breakpoint_at
== bpt
)
10589 bs
->breakpoint_at
= NULL
;
10590 bs
->old_val
= NULL
;
10591 /* bs->commands will be freed later. */
10595 /* Callback for iterate_over_threads. */
10597 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10599 struct breakpoint
*bpt
= data
;
10601 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10605 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10609 say_where (struct breakpoint
*b
)
10611 struct value_print_options opts
;
10613 get_user_print_options (&opts
);
10615 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10617 if (b
->loc
== NULL
)
10619 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10623 if (opts
.addressprint
|| b
->source_file
== NULL
)
10625 printf_filtered (" at ");
10626 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10629 if (b
->source_file
)
10630 printf_filtered (": file %s, line %d.",
10631 b
->source_file
, b
->line_number
);
10635 struct bp_location
*loc
= b
->loc
;
10637 for (; loc
; loc
= loc
->next
)
10639 printf_filtered (" (%d locations)", n
);
10644 /* Default bp_location_ops methods. */
10647 bp_location_dtor (struct bp_location
*self
)
10649 xfree (self
->cond
);
10650 xfree (self
->function_name
);
10653 static const struct bp_location_ops bp_location_ops
=
10658 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10662 base_breakpoint_dtor (struct breakpoint
*self
)
10664 decref_counted_command_line (&self
->commands
);
10665 xfree (self
->cond_string
);
10666 xfree (self
->addr_string
);
10667 xfree (self
->addr_string_range_end
);
10668 xfree (self
->source_file
);
10671 static struct bp_location
*
10672 base_breakpoint_allocate_location (struct breakpoint
*self
)
10674 struct bp_location
*loc
;
10676 loc
= XNEW (struct bp_location
);
10677 init_bp_location (loc
, &bp_location_ops
, self
);
10682 base_breakpoint_re_set (struct breakpoint
*b
)
10684 /* Nothing to re-set. */
10687 #define internal_error_pure_virtual_called() \
10688 gdb_assert_not_reached ("pure virtual function called")
10691 base_breakpoint_insert_location (struct bp_location
*bl
)
10693 internal_error_pure_virtual_called ();
10697 base_breakpoint_remove_location (struct bp_location
*bl
)
10699 internal_error_pure_virtual_called ();
10703 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10704 struct address_space
*aspace
,
10707 internal_error_pure_virtual_called ();
10711 base_breakpoint_check_status (bpstat bs
)
10716 /* A "works_in_software_mode" breakpoint_ops method that just internal
10720 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10722 internal_error_pure_virtual_called ();
10725 /* A "resources_needed" breakpoint_ops method that just internal
10729 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10731 internal_error_pure_virtual_called ();
10734 static enum print_stop_action
10735 base_breakpoint_print_it (bpstat bs
)
10737 internal_error_pure_virtual_called ();
10741 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10742 struct ui_out
*uiout
)
10748 base_breakpoint_print_mention (struct breakpoint
*b
)
10750 internal_error_pure_virtual_called ();
10754 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10756 internal_error_pure_virtual_called ();
10759 static struct breakpoint_ops base_breakpoint_ops
=
10761 base_breakpoint_dtor
,
10762 base_breakpoint_allocate_location
,
10763 base_breakpoint_re_set
,
10764 base_breakpoint_insert_location
,
10765 base_breakpoint_remove_location
,
10766 base_breakpoint_breakpoint_hit
,
10767 base_breakpoint_check_status
,
10768 base_breakpoint_resources_needed
,
10769 base_breakpoint_works_in_software_mode
,
10770 base_breakpoint_print_it
,
10772 base_breakpoint_print_one_detail
,
10773 base_breakpoint_print_mention
,
10774 base_breakpoint_print_recreate
10777 /* Default breakpoint_ops methods. */
10780 bkpt_re_set (struct breakpoint
*b
)
10782 /* Do not attempt to re-set breakpoints disabled during startup. */
10783 if (b
->enable_state
== bp_startup_disabled
)
10786 /* FIXME: is this still reachable? */
10787 if (b
->addr_string
== NULL
)
10789 /* Anything without a string can't be re-set. */
10790 delete_breakpoint (b
);
10794 breakpoint_re_set_default (b
);
10798 bkpt_insert_location (struct bp_location
*bl
)
10800 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10801 return target_insert_hw_breakpoint (bl
->gdbarch
,
10804 return target_insert_breakpoint (bl
->gdbarch
,
10809 bkpt_remove_location (struct bp_location
*bl
)
10811 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10812 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10814 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10818 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10819 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10821 struct breakpoint
*b
= bl
->owner
;
10823 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10827 if (overlay_debugging
/* unmapped overlay section */
10828 && section_is_overlay (bl
->section
)
10829 && !section_is_mapped (bl
->section
))
10836 bkpt_resources_needed (const struct bp_location
*bl
)
10838 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10843 static enum print_stop_action
10844 bkpt_print_it (bpstat bs
)
10846 struct breakpoint
*b
;
10847 const struct bp_location
*bl
;
10850 gdb_assert (bs
->bp_location_at
!= NULL
);
10852 bl
= bs
->bp_location_at
;
10853 b
= bs
->breakpoint_at
;
10855 bp_temp
= b
->disposition
== disp_del
;
10856 if (bl
->address
!= bl
->requested_address
)
10857 breakpoint_adjustment_warning (bl
->requested_address
,
10860 annotate_breakpoint (b
->number
);
10862 ui_out_text (uiout
, "\nTemporary breakpoint ");
10864 ui_out_text (uiout
, "\nBreakpoint ");
10865 if (ui_out_is_mi_like_p (uiout
))
10867 ui_out_field_string (uiout
, "reason",
10868 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10869 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10871 ui_out_field_int (uiout
, "bkptno", b
->number
);
10872 ui_out_text (uiout
, ", ");
10874 return PRINT_SRC_AND_LOC
;
10878 bkpt_print_mention (struct breakpoint
*b
)
10880 if (ui_out_is_mi_like_p (uiout
))
10885 case bp_breakpoint
:
10886 case bp_gnu_ifunc_resolver
:
10887 if (b
->disposition
== disp_del
)
10888 printf_filtered (_("Temporary breakpoint"));
10890 printf_filtered (_("Breakpoint"));
10891 printf_filtered (_(" %d"), b
->number
);
10892 if (b
->type
== bp_gnu_ifunc_resolver
)
10893 printf_filtered (_(" at gnu-indirect-function resolver"));
10895 case bp_hardware_breakpoint
:
10896 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
10904 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
10906 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10907 fprintf_unfiltered (fp
, "tbreak");
10908 else if (tp
->type
== bp_breakpoint
)
10909 fprintf_unfiltered (fp
, "break");
10910 else if (tp
->type
== bp_hardware_breakpoint
10911 && tp
->disposition
== disp_del
)
10912 fprintf_unfiltered (fp
, "thbreak");
10913 else if (tp
->type
== bp_hardware_breakpoint
)
10914 fprintf_unfiltered (fp
, "hbreak");
10916 internal_error (__FILE__
, __LINE__
,
10917 _("unhandled breakpoint type %d"), (int) tp
->type
);
10919 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10922 /* Virtual table for internal breakpoints. */
10925 internal_bkpt_re_set (struct breakpoint
*b
)
10929 /* Delete overlay event and longjmp master breakpoints; they
10930 will be reset later by breakpoint_re_set. */
10931 case bp_overlay_event
:
10932 case bp_longjmp_master
:
10933 case bp_std_terminate_master
:
10934 case bp_exception_master
:
10935 delete_breakpoint (b
);
10938 /* This breakpoint is special, it's set up when the inferior
10939 starts and we really don't want to touch it. */
10940 case bp_shlib_event
:
10942 /* Like bp_shlib_event, this breakpoint type is special. Once
10943 it is set up, we do not want to touch it. */
10944 case bp_thread_event
:
10950 internal_bkpt_check_status (bpstat bs
)
10952 /* We do not stop for these. */
10956 static enum print_stop_action
10957 internal_bkpt_print_it (bpstat bs
)
10959 struct breakpoint
*b
;
10961 b
= bs
->breakpoint_at
;
10965 case bp_shlib_event
:
10966 /* Did we stop because the user set the stop_on_solib_events
10967 variable? (If so, we report this as a generic, "Stopped due
10968 to shlib event" message.) */
10969 printf_filtered (_("Stopped due to shared library event\n"));
10972 case bp_thread_event
:
10973 /* Not sure how we will get here.
10974 GDB should not stop for these breakpoints. */
10975 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
10978 case bp_overlay_event
:
10979 /* By analogy with the thread event, GDB should not stop for these. */
10980 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
10983 case bp_longjmp_master
:
10984 /* These should never be enabled. */
10985 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
10988 case bp_std_terminate_master
:
10989 /* These should never be enabled. */
10990 printf_filtered (_("std::terminate Master Breakpoint: "
10991 "gdb should not stop!\n"));
10994 case bp_exception_master
:
10995 /* These should never be enabled. */
10996 printf_filtered (_("Exception Master Breakpoint: "
10997 "gdb should not stop!\n"));
11001 return PRINT_NOTHING
;
11005 internal_bkpt_print_mention (struct breakpoint
*b
)
11007 /* Nothing to mention. These breakpoints are internal. */
11010 /* Virtual table for momentary breakpoints */
11013 momentary_bkpt_re_set (struct breakpoint
*b
)
11015 /* Keep temporary breakpoints, which can be encountered when we step
11016 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11017 Otherwise these should have been blown away via the cleanup chain
11018 or by breakpoint_init_inferior when we rerun the executable. */
11022 momentary_bkpt_check_status (bpstat bs
)
11024 /* Nothing. The point of these breakpoints is causing a stop. */
11027 static enum print_stop_action
11028 momentary_bkpt_print_it (bpstat bs
)
11030 if (ui_out_is_mi_like_p (uiout
))
11032 struct breakpoint
*b
= bs
->breakpoint_at
;
11037 ui_out_field_string
11039 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11043 ui_out_field_string
11045 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11050 return PRINT_UNKNOWN
;
11054 momentary_bkpt_print_mention (struct breakpoint
*b
)
11056 /* Nothing to mention. These breakpoints are internal. */
11059 /* The breakpoint_ops structure to be used in tracepoints. */
11062 tracepoint_re_set (struct breakpoint
*b
)
11064 breakpoint_re_set_default (b
);
11068 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11069 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11071 /* By definition, the inferior does not report stops at
11077 tracepoint_print_one_detail (const struct breakpoint
*self
,
11078 struct ui_out
*uiout
)
11080 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11081 if (tp
->static_trace_marker_id
)
11083 gdb_assert (self
->type
== bp_static_tracepoint
);
11085 ui_out_text (uiout
, "\tmarker id is ");
11086 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11087 tp
->static_trace_marker_id
);
11088 ui_out_text (uiout
, "\n");
11093 tracepoint_print_mention (struct breakpoint
*b
)
11095 if (ui_out_is_mi_like_p (uiout
))
11100 case bp_tracepoint
:
11101 printf_filtered (_("Tracepoint"));
11102 printf_filtered (_(" %d"), b
->number
);
11104 case bp_fast_tracepoint
:
11105 printf_filtered (_("Fast tracepoint"));
11106 printf_filtered (_(" %d"), b
->number
);
11108 case bp_static_tracepoint
:
11109 printf_filtered (_("Static tracepoint"));
11110 printf_filtered (_(" %d"), b
->number
);
11113 internal_error (__FILE__
, __LINE__
,
11114 _("unhandled tracepoint type %d"), (int) b
->type
);
11121 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11123 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11125 if (self
->type
== bp_fast_tracepoint
)
11126 fprintf_unfiltered (fp
, "ftrace");
11127 if (self
->type
== bp_static_tracepoint
)
11128 fprintf_unfiltered (fp
, "strace");
11129 else if (self
->type
== bp_tracepoint
)
11130 fprintf_unfiltered (fp
, "trace");
11132 internal_error (__FILE__
, __LINE__
,
11133 _("unhandled tracepoint type %d"), (int) self
->type
);
11135 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11136 print_recreate_thread (self
, fp
);
11138 if (tp
->pass_count
)
11139 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11142 struct breakpoint_ops tracepoint_breakpoint_ops
;
11144 /* Delete a breakpoint and clean up all traces of it in the data
11148 delete_breakpoint (struct breakpoint
*bpt
)
11150 struct breakpoint
*b
;
11152 gdb_assert (bpt
!= NULL
);
11154 /* Has this bp already been deleted? This can happen because
11155 multiple lists can hold pointers to bp's. bpstat lists are
11158 One example of this happening is a watchpoint's scope bp. When
11159 the scope bp triggers, we notice that the watchpoint is out of
11160 scope, and delete it. We also delete its scope bp. But the
11161 scope bp is marked "auto-deleting", and is already on a bpstat.
11162 That bpstat is then checked for auto-deleting bp's, which are
11165 A real solution to this problem might involve reference counts in
11166 bp's, and/or giving them pointers back to their referencing
11167 bpstat's, and teaching delete_breakpoint to only free a bp's
11168 storage when no more references were extent. A cheaper bandaid
11170 if (bpt
->type
== bp_none
)
11173 /* At least avoid this stale reference until the reference counting
11174 of breakpoints gets resolved. */
11175 if (bpt
->related_breakpoint
!= bpt
)
11177 struct breakpoint
*related
;
11178 struct watchpoint
*w
;
11180 if (bpt
->type
== bp_watchpoint_scope
)
11181 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11182 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11183 w
= (struct watchpoint
*) bpt
;
11187 watchpoint_del_at_next_stop (w
);
11189 /* Unlink bpt from the bpt->related_breakpoint ring. */
11190 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11191 related
= related
->related_breakpoint
);
11192 related
->related_breakpoint
= bpt
->related_breakpoint
;
11193 bpt
->related_breakpoint
= bpt
;
11196 /* watch_command_1 creates a watchpoint but only sets its number if
11197 update_watchpoint succeeds in creating its bp_locations. If there's
11198 a problem in that process, we'll be asked to delete the half-created
11199 watchpoint. In that case, don't announce the deletion. */
11201 observer_notify_breakpoint_deleted (bpt
);
11203 if (breakpoint_chain
== bpt
)
11204 breakpoint_chain
= bpt
->next
;
11206 ALL_BREAKPOINTS (b
)
11207 if (b
->next
== bpt
)
11209 b
->next
= bpt
->next
;
11213 /* Be sure no bpstat's are pointing at the breakpoint after it's
11215 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11216 in all threads for now. Note that we cannot just remove bpstats
11217 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11218 commands are associated with the bpstat; if we remove it here,
11219 then the later call to bpstat_do_actions (&stop_bpstat); in
11220 event-top.c won't do anything, and temporary breakpoints with
11221 commands won't work. */
11223 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11225 /* Now that breakpoint is removed from breakpoint list, update the
11226 global location list. This will remove locations that used to
11227 belong to this breakpoint. Do this before freeing the breakpoint
11228 itself, since remove_breakpoint looks at location's owner. It
11229 might be better design to have location completely
11230 self-contained, but it's not the case now. */
11231 update_global_location_list (0);
11233 bpt
->ops
->dtor (bpt
);
11234 /* On the chance that someone will soon try again to delete this
11235 same bp, we mark it as deleted before freeing its storage. */
11236 bpt
->type
= bp_none
;
11241 do_delete_breakpoint_cleanup (void *b
)
11243 delete_breakpoint (b
);
11247 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11249 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11252 /* Iterator function to call a user-provided callback function once
11253 for each of B and its related breakpoints. */
11256 iterate_over_related_breakpoints (struct breakpoint
*b
,
11257 void (*function
) (struct breakpoint
*,
11261 struct breakpoint
*related
;
11266 struct breakpoint
*next
;
11268 /* FUNCTION may delete RELATED. */
11269 next
= related
->related_breakpoint
;
11271 if (next
== related
)
11273 /* RELATED is the last ring entry. */
11274 function (related
, data
);
11276 /* FUNCTION may have deleted it, so we'd never reach back to
11277 B. There's nothing left to do anyway, so just break
11282 function (related
, data
);
11286 while (related
!= b
);
11290 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11292 delete_breakpoint (b
);
11295 /* A callback for map_breakpoint_numbers that calls
11296 delete_breakpoint. */
11299 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11301 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11305 delete_command (char *arg
, int from_tty
)
11307 struct breakpoint
*b
, *b_tmp
;
11313 int breaks_to_delete
= 0;
11315 /* Delete all breakpoints if no argument. Do not delete
11316 internal breakpoints, these have to be deleted with an
11317 explicit breakpoint number argument. */
11318 ALL_BREAKPOINTS (b
)
11319 if (user_breakpoint_p (b
))
11321 breaks_to_delete
= 1;
11325 /* Ask user only if there are some breakpoints to delete. */
11327 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11329 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11330 if (user_breakpoint_p (b
))
11331 delete_breakpoint (b
);
11335 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11339 all_locations_are_pending (struct bp_location
*loc
)
11341 for (; loc
; loc
= loc
->next
)
11342 if (!loc
->shlib_disabled
)
11347 /* Subroutine of update_breakpoint_locations to simplify it.
11348 Return non-zero if multiple fns in list LOC have the same name.
11349 Null names are ignored. */
11352 ambiguous_names_p (struct bp_location
*loc
)
11354 struct bp_location
*l
;
11355 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11356 (int (*) (const void *,
11357 const void *)) streq
,
11358 NULL
, xcalloc
, xfree
);
11360 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11363 const char *name
= l
->function_name
;
11365 /* Allow for some names to be NULL, ignore them. */
11369 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11371 /* NOTE: We can assume slot != NULL here because xcalloc never
11375 htab_delete (htab
);
11381 htab_delete (htab
);
11385 /* When symbols change, it probably means the sources changed as well,
11386 and it might mean the static tracepoint markers are no longer at
11387 the same address or line numbers they used to be at last we
11388 checked. Losing your static tracepoints whenever you rebuild is
11389 undesirable. This function tries to resync/rematch gdb static
11390 tracepoints with the markers on the target, for static tracepoints
11391 that have not been set by marker id. Static tracepoint that have
11392 been set by marker id are reset by marker id in breakpoint_re_set.
11395 1) For a tracepoint set at a specific address, look for a marker at
11396 the old PC. If one is found there, assume to be the same marker.
11397 If the name / string id of the marker found is different from the
11398 previous known name, assume that means the user renamed the marker
11399 in the sources, and output a warning.
11401 2) For a tracepoint set at a given line number, look for a marker
11402 at the new address of the old line number. If one is found there,
11403 assume to be the same marker. If the name / string id of the
11404 marker found is different from the previous known name, assume that
11405 means the user renamed the marker in the sources, and output a
11408 3) If a marker is no longer found at the same address or line, it
11409 may mean the marker no longer exists. But it may also just mean
11410 the code changed a bit. Maybe the user added a few lines of code
11411 that made the marker move up or down (in line number terms). Ask
11412 the target for info about the marker with the string id as we knew
11413 it. If found, update line number and address in the matching
11414 static tracepoint. This will get confused if there's more than one
11415 marker with the same ID (possible in UST, although unadvised
11416 precisely because it confuses tools). */
11418 static struct symtab_and_line
11419 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11421 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11422 struct static_tracepoint_marker marker
;
11428 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11430 if (target_static_tracepoint_marker_at (pc
, &marker
))
11432 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11433 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11435 tp
->static_trace_marker_id
, marker
.str_id
);
11437 xfree (tp
->static_trace_marker_id
);
11438 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11439 release_static_tracepoint_marker (&marker
);
11444 /* Old marker wasn't found on target at lineno. Try looking it up
11446 if (!sal
.explicit_pc
11448 && sal
.symtab
!= NULL
11449 && tp
->static_trace_marker_id
!= NULL
)
11451 VEC(static_tracepoint_marker_p
) *markers
;
11454 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11456 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11458 struct symtab_and_line sal
;
11459 struct symbol
*sym
;
11460 struct static_tracepoint_marker
*marker
;
11462 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11464 xfree (tp
->static_trace_marker_id
);
11465 tp
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11467 warning (_("marker for static tracepoint %d (%s) not "
11468 "found at previous line number"),
11469 b
->number
, tp
->static_trace_marker_id
);
11473 sal
.pc
= marker
->address
;
11475 sal
= find_pc_line (marker
->address
, 0);
11476 sym
= find_pc_sect_function (marker
->address
, NULL
);
11477 ui_out_text (uiout
, "Now in ");
11480 ui_out_field_string (uiout
, "func",
11481 SYMBOL_PRINT_NAME (sym
));
11482 ui_out_text (uiout
, " at ");
11484 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11485 ui_out_text (uiout
, ":");
11487 if (ui_out_is_mi_like_p (uiout
))
11489 char *fullname
= symtab_to_fullname (sal
.symtab
);
11492 ui_out_field_string (uiout
, "fullname", fullname
);
11495 ui_out_field_int (uiout
, "line", sal
.line
);
11496 ui_out_text (uiout
, "\n");
11498 b
->line_number
= sal
.line
;
11500 xfree (b
->source_file
);
11502 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11504 b
->source_file
= NULL
;
11506 xfree (b
->addr_string
);
11507 b
->addr_string
= xstrprintf ("%s:%d",
11508 sal
.symtab
->filename
, b
->line_number
);
11510 /* Might be nice to check if function changed, and warn if
11513 release_static_tracepoint_marker (marker
);
11519 /* Returns 1 iff locations A and B are sufficiently same that
11520 we don't need to report breakpoint as changed. */
11523 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11527 if (a
->address
!= b
->address
)
11530 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11533 if (a
->enabled
!= b
->enabled
)
11540 if ((a
== NULL
) != (b
== NULL
))
11546 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11547 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11548 a ranged breakpoint. */
11551 update_breakpoint_locations (struct breakpoint
*b
,
11552 struct symtabs_and_lines sals
,
11553 struct symtabs_and_lines sals_end
)
11556 struct bp_location
*existing_locations
= b
->loc
;
11558 /* Ranged breakpoints have only one start location and one end location. */
11559 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11561 /* If there's no new locations, and all existing locations are
11562 pending, don't do anything. This optimizes the common case where
11563 all locations are in the same shared library, that was unloaded.
11564 We'd like to retain the location, so that when the library is
11565 loaded again, we don't loose the enabled/disabled status of the
11566 individual locations. */
11567 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11572 for (i
= 0; i
< sals
.nelts
; ++i
)
11574 struct bp_location
*new_loc
=
11575 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11577 /* Reparse conditions, they might contain references to the
11579 if (b
->cond_string
!= NULL
)
11582 struct gdb_exception e
;
11584 s
= b
->cond_string
;
11585 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11587 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11592 warning (_("failed to reevaluate condition "
11593 "for breakpoint %d: %s"),
11594 b
->number
, e
.message
);
11595 new_loc
->enabled
= 0;
11599 if (b
->source_file
!= NULL
)
11600 xfree (b
->source_file
);
11601 if (sals
.sals
[i
].symtab
== NULL
)
11602 b
->source_file
= NULL
;
11604 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11606 if (b
->line_number
== 0)
11607 b
->line_number
= sals
.sals
[i
].line
;
11609 if (sals_end
.nelts
)
11611 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11613 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11617 /* Update locations of permanent breakpoints. */
11618 if (b
->enable_state
== bp_permanent
)
11619 make_breakpoint_permanent (b
);
11621 /* If possible, carry over 'disable' status from existing
11624 struct bp_location
*e
= existing_locations
;
11625 /* If there are multiple breakpoints with the same function name,
11626 e.g. for inline functions, comparing function names won't work.
11627 Instead compare pc addresses; this is just a heuristic as things
11628 may have moved, but in practice it gives the correct answer
11629 often enough until a better solution is found. */
11630 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11632 for (; e
; e
= e
->next
)
11634 if (!e
->enabled
&& e
->function_name
)
11636 struct bp_location
*l
= b
->loc
;
11637 if (have_ambiguous_names
)
11639 for (; l
; l
= l
->next
)
11640 if (breakpoint_locations_match (e
, l
))
11648 for (; l
; l
= l
->next
)
11649 if (l
->function_name
11650 && strcmp (e
->function_name
, l
->function_name
) == 0)
11660 if (!locations_are_equal (existing_locations
, b
->loc
))
11661 observer_notify_breakpoint_modified (b
);
11663 update_global_location_list (1);
11666 /* Find the SaL locations corresponding to the given ADDR_STRING.
11667 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11669 static struct symtabs_and_lines
11670 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11674 struct symtabs_and_lines sals
= {0};
11675 struct gdb_exception e
;
11678 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11680 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11684 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11686 sals
= decode_static_tracepoint_spec (&s
);
11687 if (sals
.nelts
> tp
->static_trace_marker_id_idx
)
11689 sals
.sals
[0] = sals
.sals
[tp
->static_trace_marker_id_idx
];
11693 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11696 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11700 int not_found_and_ok
= 0;
11701 /* For pending breakpoints, it's expected that parsing will
11702 fail until the right shared library is loaded. User has
11703 already told to create pending breakpoints and don't need
11704 extra messages. If breakpoint is in bp_shlib_disabled
11705 state, then user already saw the message about that
11706 breakpoint being disabled, and don't want to see more
11708 if (e
.error
== NOT_FOUND_ERROR
11709 && (b
->condition_not_parsed
11710 || (b
->loc
&& b
->loc
->shlib_disabled
)
11711 || b
->enable_state
== bp_disabled
))
11712 not_found_and_ok
= 1;
11714 if (!not_found_and_ok
)
11716 /* We surely don't want to warn about the same breakpoint
11717 10 times. One solution, implemented here, is disable
11718 the breakpoint on error. Another solution would be to
11719 have separate 'warning emitted' flag. Since this
11720 happens only when a binary has changed, I don't know
11721 which approach is better. */
11722 b
->enable_state
= bp_disabled
;
11723 throw_exception (e
);
11727 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11729 gdb_assert (sals
.nelts
== 1);
11731 resolve_sal_pc (&sals
.sals
[0]);
11732 if (b
->condition_not_parsed
&& s
&& s
[0])
11734 char *cond_string
= 0;
11738 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11739 &cond_string
, &thread
, &task
);
11741 b
->cond_string
= cond_string
;
11742 b
->thread
= thread
;
11744 b
->condition_not_parsed
= 0;
11747 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11748 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11758 /* The default re_set method, for typical hardware or software
11759 breakpoints. Reevaluate the breakpoint and recreate its
11763 breakpoint_re_set_default (struct breakpoint
*b
)
11766 struct symtabs_and_lines sals
, sals_end
;
11767 struct symtabs_and_lines expanded
= {0};
11768 struct symtabs_and_lines expanded_end
= {0};
11770 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11773 make_cleanup (xfree
, sals
.sals
);
11774 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
11777 if (b
->addr_string_range_end
)
11779 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11782 make_cleanup (xfree
, sals_end
.sals
);
11783 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
11787 update_breakpoint_locations (b
, expanded
, expanded_end
);
11790 /* Prepare the global context for a re-set of breakpoint B. */
11792 static struct cleanup
*
11793 prepare_re_set_context (struct breakpoint
*b
)
11795 struct cleanup
*cleanups
;
11797 input_radix
= b
->input_radix
;
11798 cleanups
= save_current_space_and_thread ();
11799 switch_to_program_space_and_thread (b
->pspace
);
11800 set_language (b
->language
);
11805 /* Reset a breakpoint given it's struct breakpoint * BINT.
11806 The value we return ends up being the return value from catch_errors.
11807 Unused in this case. */
11810 breakpoint_re_set_one (void *bint
)
11812 /* Get past catch_errs. */
11813 struct breakpoint
*b
= (struct breakpoint
*) bint
;
11814 struct cleanup
*cleanups
;
11816 cleanups
= prepare_re_set_context (b
);
11817 b
->ops
->re_set (b
);
11818 do_cleanups (cleanups
);
11822 /* Re-set all breakpoints after symbols have been re-loaded. */
11824 breakpoint_re_set (void)
11826 struct breakpoint
*b
, *b_tmp
;
11827 enum language save_language
;
11828 int save_input_radix
;
11829 struct cleanup
*old_chain
;
11831 save_language
= current_language
->la_language
;
11832 save_input_radix
= input_radix
;
11833 old_chain
= save_current_program_space ();
11835 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11837 /* Format possible error msg. */
11838 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
11840 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
11841 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
11842 do_cleanups (cleanups
);
11844 set_language (save_language
);
11845 input_radix
= save_input_radix
;
11847 jit_breakpoint_re_set ();
11849 do_cleanups (old_chain
);
11851 create_overlay_event_breakpoint ();
11852 create_longjmp_master_breakpoint ();
11853 create_std_terminate_master_breakpoint ();
11854 create_exception_master_breakpoint ();
11857 /* Reset the thread number of this breakpoint:
11859 - If the breakpoint is for all threads, leave it as-is.
11860 - Else, reset it to the current thread for inferior_ptid. */
11862 breakpoint_re_set_thread (struct breakpoint
*b
)
11864 if (b
->thread
!= -1)
11866 if (in_thread_list (inferior_ptid
))
11867 b
->thread
= pid_to_thread_id (inferior_ptid
);
11869 /* We're being called after following a fork. The new fork is
11870 selected as current, and unless this was a vfork will have a
11871 different program space from the original thread. Reset that
11873 b
->loc
->pspace
= current_program_space
;
11877 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11878 If from_tty is nonzero, it prints a message to that effect,
11879 which ends with a period (no newline). */
11882 set_ignore_count (int bptnum
, int count
, int from_tty
)
11884 struct breakpoint
*b
;
11889 ALL_BREAKPOINTS (b
)
11890 if (b
->number
== bptnum
)
11892 if (is_tracepoint (b
))
11894 if (from_tty
&& count
!= 0)
11895 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11900 b
->ignore_count
= count
;
11904 printf_filtered (_("Will stop next time "
11905 "breakpoint %d is reached."),
11907 else if (count
== 1)
11908 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11911 printf_filtered (_("Will ignore next %d "
11912 "crossings of breakpoint %d."),
11915 breakpoints_changed ();
11916 observer_notify_breakpoint_modified (b
);
11920 error (_("No breakpoint number %d."), bptnum
);
11923 /* Command to set ignore-count of breakpoint N to COUNT. */
11926 ignore_command (char *args
, int from_tty
)
11932 error_no_arg (_("a breakpoint number"));
11934 num
= get_number (&p
);
11936 error (_("bad breakpoint number: '%s'"), args
);
11938 error (_("Second argument (specified ignore-count) is missing."));
11940 set_ignore_count (num
,
11941 longest_to_int (value_as_long (parse_and_eval (p
))),
11944 printf_filtered ("\n");
11947 /* Call FUNCTION on each of the breakpoints
11948 whose numbers are given in ARGS. */
11951 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
11956 struct breakpoint
*b
, *tmp
;
11958 struct get_number_or_range_state state
;
11961 error_no_arg (_("one or more breakpoint numbers"));
11963 init_number_or_range (&state
, args
);
11965 while (!state
.finished
)
11967 char *p
= state
.string
;
11971 num
= get_number_or_range (&state
);
11974 warning (_("bad breakpoint number at or near '%s'"), p
);
11978 ALL_BREAKPOINTS_SAFE (b
, tmp
)
11979 if (b
->number
== num
)
11982 function (b
, data
);
11986 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
11991 static struct bp_location
*
11992 find_location_by_number (char *number
)
11994 char *dot
= strchr (number
, '.');
11998 struct breakpoint
*b
;
11999 struct bp_location
*loc
;
12004 bp_num
= get_number (&p1
);
12006 error (_("Bad breakpoint number '%s'"), number
);
12008 ALL_BREAKPOINTS (b
)
12009 if (b
->number
== bp_num
)
12014 if (!b
|| b
->number
!= bp_num
)
12015 error (_("Bad breakpoint number '%s'"), number
);
12018 loc_num
= get_number (&p1
);
12020 error (_("Bad breakpoint location number '%s'"), number
);
12024 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12027 error (_("Bad breakpoint location number '%s'"), dot
+1);
12033 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12034 If from_tty is nonzero, it prints a message to that effect,
12035 which ends with a period (no newline). */
12038 disable_breakpoint (struct breakpoint
*bpt
)
12040 /* Never disable a watchpoint scope breakpoint; we want to
12041 hit them when we leave scope so we can delete both the
12042 watchpoint and its scope breakpoint at that time. */
12043 if (bpt
->type
== bp_watchpoint_scope
)
12046 /* You can't disable permanent breakpoints. */
12047 if (bpt
->enable_state
== bp_permanent
)
12050 bpt
->enable_state
= bp_disabled
;
12052 if (target_supports_enable_disable_tracepoint ()
12053 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12055 struct bp_location
*location
;
12057 for (location
= bpt
->loc
; location
; location
= location
->next
)
12058 target_disable_tracepoint (location
);
12061 update_global_location_list (0);
12063 observer_notify_breakpoint_modified (bpt
);
12066 /* A callback for iterate_over_related_breakpoints. */
12069 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12071 disable_breakpoint (b
);
12074 /* A callback for map_breakpoint_numbers that calls
12075 disable_breakpoint. */
12078 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12080 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12084 disable_command (char *args
, int from_tty
)
12088 struct breakpoint
*bpt
;
12090 ALL_BREAKPOINTS (bpt
)
12091 if (user_breakpoint_p (bpt
))
12092 disable_breakpoint (bpt
);
12094 else if (strchr (args
, '.'))
12096 struct bp_location
*loc
= find_location_by_number (args
);
12100 if (target_supports_enable_disable_tracepoint ()
12101 && current_trace_status ()->running
&& loc
->owner
12102 && is_tracepoint (loc
->owner
))
12103 target_disable_tracepoint (loc
);
12105 update_global_location_list (0);
12108 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12112 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12114 int target_resources_ok
;
12116 if (bpt
->type
== bp_hardware_breakpoint
)
12119 i
= hw_breakpoint_used_count ();
12120 target_resources_ok
=
12121 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12123 if (target_resources_ok
== 0)
12124 error (_("No hardware breakpoint support in the target."));
12125 else if (target_resources_ok
< 0)
12126 error (_("Hardware breakpoints used exceeds limit."));
12129 if (is_watchpoint (bpt
))
12131 /* Initialize it just to avoid a GCC false warning. */
12132 enum enable_state orig_enable_state
= 0;
12133 struct gdb_exception e
;
12135 TRY_CATCH (e
, RETURN_MASK_ALL
)
12137 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12139 orig_enable_state
= bpt
->enable_state
;
12140 bpt
->enable_state
= bp_enabled
;
12141 update_watchpoint (w
, 1 /* reparse */);
12145 bpt
->enable_state
= orig_enable_state
;
12146 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12152 if (bpt
->enable_state
!= bp_permanent
)
12153 bpt
->enable_state
= bp_enabled
;
12155 if (target_supports_enable_disable_tracepoint ()
12156 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12158 struct bp_location
*location
;
12160 for (location
= bpt
->loc
; location
; location
= location
->next
)
12161 target_enable_tracepoint (location
);
12164 bpt
->disposition
= disposition
;
12165 update_global_location_list (1);
12166 breakpoints_changed ();
12168 observer_notify_breakpoint_modified (bpt
);
12173 enable_breakpoint (struct breakpoint
*bpt
)
12175 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12179 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12181 enable_breakpoint (bpt
);
12184 /* A callback for map_breakpoint_numbers that calls
12185 enable_breakpoint. */
12188 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12190 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12193 /* The enable command enables the specified breakpoints (or all defined
12194 breakpoints) so they once again become (or continue to be) effective
12195 in stopping the inferior. */
12198 enable_command (char *args
, int from_tty
)
12202 struct breakpoint
*bpt
;
12204 ALL_BREAKPOINTS (bpt
)
12205 if (user_breakpoint_p (bpt
))
12206 enable_breakpoint (bpt
);
12208 else if (strchr (args
, '.'))
12210 struct bp_location
*loc
= find_location_by_number (args
);
12214 if (target_supports_enable_disable_tracepoint ()
12215 && current_trace_status ()->running
&& loc
->owner
12216 && is_tracepoint (loc
->owner
))
12217 target_enable_tracepoint (loc
);
12219 update_global_location_list (1);
12222 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12226 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12228 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12230 enable_breakpoint_disp (bpt
, disp
);
12234 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12236 enum bpdisp disp
= disp_disable
;
12238 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12242 enable_once_command (char *args
, int from_tty
)
12244 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12248 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12250 enum bpdisp disp
= disp_del
;
12252 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12256 enable_delete_command (char *args
, int from_tty
)
12258 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12262 set_breakpoint_cmd (char *args
, int from_tty
)
12267 show_breakpoint_cmd (char *args
, int from_tty
)
12271 /* Invalidate last known value of any hardware watchpoint if
12272 the memory which that value represents has been written to by
12276 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12277 const bfd_byte
*data
)
12279 struct breakpoint
*bp
;
12281 ALL_BREAKPOINTS (bp
)
12282 if (bp
->enable_state
== bp_enabled
12283 && bp
->type
== bp_hardware_watchpoint
)
12285 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12287 if (wp
->val_valid
&& wp
->val
)
12289 struct bp_location
*loc
;
12291 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12292 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12293 && loc
->address
+ loc
->length
> addr
12294 && addr
+ len
> loc
->address
)
12296 value_free (wp
->val
);
12304 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12306 struct symtabs_and_lines
12307 decode_line_spec_1 (char *string
, int funfirstline
)
12309 struct symtabs_and_lines sals
;
12312 error (_("Empty line specification."));
12313 if (default_breakpoint_valid
)
12314 sals
= decode_line_1 (&string
, funfirstline
,
12315 default_breakpoint_symtab
,
12316 default_breakpoint_line
,
12319 sals
= decode_line_1 (&string
, funfirstline
,
12320 (struct symtab
*) NULL
, 0, NULL
);
12322 error (_("Junk at end of line specification: %s"), string
);
12326 /* Create and insert a raw software breakpoint at PC. Return an
12327 identifier, which should be used to remove the breakpoint later.
12328 In general, places which call this should be using something on the
12329 breakpoint chain instead; this function should be eliminated
12333 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12334 struct address_space
*aspace
, CORE_ADDR pc
)
12336 struct bp_target_info
*bp_tgt
;
12338 bp_tgt
= XZALLOC (struct bp_target_info
);
12340 bp_tgt
->placed_address_space
= aspace
;
12341 bp_tgt
->placed_address
= pc
;
12343 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12345 /* Could not insert the breakpoint. */
12353 /* Remove a breakpoint BP inserted by
12354 deprecated_insert_raw_breakpoint. */
12357 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12359 struct bp_target_info
*bp_tgt
= bp
;
12362 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12368 /* One (or perhaps two) breakpoints used for software single
12371 static void *single_step_breakpoints
[2];
12372 static struct gdbarch
*single_step_gdbarch
[2];
12374 /* Create and insert a breakpoint for software single step. */
12377 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12378 struct address_space
*aspace
,
12383 if (single_step_breakpoints
[0] == NULL
)
12385 bpt_p
= &single_step_breakpoints
[0];
12386 single_step_gdbarch
[0] = gdbarch
;
12390 gdb_assert (single_step_breakpoints
[1] == NULL
);
12391 bpt_p
= &single_step_breakpoints
[1];
12392 single_step_gdbarch
[1] = gdbarch
;
12395 /* NOTE drow/2006-04-11: A future improvement to this function would
12396 be to only create the breakpoints once, and actually put them on
12397 the breakpoint chain. That would let us use set_raw_breakpoint.
12398 We could adjust the addresses each time they were needed. Doing
12399 this requires corresponding changes elsewhere where single step
12400 breakpoints are handled, however. So, for now, we use this. */
12402 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12403 if (*bpt_p
== NULL
)
12404 error (_("Could not insert single-step breakpoint at %s"),
12405 paddress (gdbarch
, next_pc
));
12408 /* Check if the breakpoints used for software single stepping
12409 were inserted or not. */
12412 single_step_breakpoints_inserted (void)
12414 return (single_step_breakpoints
[0] != NULL
12415 || single_step_breakpoints
[1] != NULL
);
12418 /* Remove and delete any breakpoints used for software single step. */
12421 remove_single_step_breakpoints (void)
12423 gdb_assert (single_step_breakpoints
[0] != NULL
);
12425 /* See insert_single_step_breakpoint for more about this deprecated
12427 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12428 single_step_breakpoints
[0]);
12429 single_step_gdbarch
[0] = NULL
;
12430 single_step_breakpoints
[0] = NULL
;
12432 if (single_step_breakpoints
[1] != NULL
)
12434 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12435 single_step_breakpoints
[1]);
12436 single_step_gdbarch
[1] = NULL
;
12437 single_step_breakpoints
[1] = NULL
;
12441 /* Delete software single step breakpoints without removing them from
12442 the inferior. This is intended to be used if the inferior's address
12443 space where they were inserted is already gone, e.g. after exit or
12447 cancel_single_step_breakpoints (void)
12451 for (i
= 0; i
< 2; i
++)
12452 if (single_step_breakpoints
[i
])
12454 xfree (single_step_breakpoints
[i
]);
12455 single_step_breakpoints
[i
] = NULL
;
12456 single_step_gdbarch
[i
] = NULL
;
12460 /* Detach software single-step breakpoints from INFERIOR_PTID without
12464 detach_single_step_breakpoints (void)
12468 for (i
= 0; i
< 2; i
++)
12469 if (single_step_breakpoints
[i
])
12470 target_remove_breakpoint (single_step_gdbarch
[i
],
12471 single_step_breakpoints
[i
]);
12474 /* Check whether a software single-step breakpoint is inserted at
12478 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12483 for (i
= 0; i
< 2; i
++)
12485 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12487 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12488 bp_tgt
->placed_address
,
12496 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12497 non-zero otherwise. */
12499 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12501 if (syscall_catchpoint_p (bp
)
12502 && bp
->enable_state
!= bp_disabled
12503 && bp
->enable_state
!= bp_call_disabled
)
12510 catch_syscall_enabled (void)
12512 struct inferior
*inf
= current_inferior ();
12514 return inf
->total_syscalls_count
!= 0;
12518 catching_syscall_number (int syscall_number
)
12520 struct breakpoint
*bp
;
12522 ALL_BREAKPOINTS (bp
)
12523 if (is_syscall_catchpoint_enabled (bp
))
12525 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12527 if (c
->syscalls_to_be_caught
)
12531 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12533 if (syscall_number
== iter
)
12543 /* Complete syscall names. Used by "catch syscall". */
12545 catch_syscall_completer (struct cmd_list_element
*cmd
,
12546 char *text
, char *word
)
12548 const char **list
= get_syscall_names ();
12550 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12556 /* Tracepoint-specific operations. */
12558 /* Set tracepoint count to NUM. */
12560 set_tracepoint_count (int num
)
12562 tracepoint_count
= num
;
12563 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12567 trace_command (char *arg
, int from_tty
)
12569 if (create_breakpoint (get_current_arch (),
12571 NULL
, 0, 1 /* parse arg */,
12573 bp_tracepoint
/* type_wanted */,
12574 0 /* Ignore count */,
12575 pending_break_support
,
12576 &tracepoint_breakpoint_ops
,
12580 set_tracepoint_count (breakpoint_count
);
12584 ftrace_command (char *arg
, int from_tty
)
12586 if (create_breakpoint (get_current_arch (),
12588 NULL
, 0, 1 /* parse arg */,
12590 bp_fast_tracepoint
/* type_wanted */,
12591 0 /* Ignore count */,
12592 pending_break_support
,
12593 &tracepoint_breakpoint_ops
,
12597 set_tracepoint_count (breakpoint_count
);
12600 /* strace command implementation. Creates a static tracepoint. */
12603 strace_command (char *arg
, int from_tty
)
12605 if (create_breakpoint (get_current_arch (),
12607 NULL
, 0, 1 /* parse arg */,
12609 bp_static_tracepoint
/* type_wanted */,
12610 0 /* Ignore count */,
12611 pending_break_support
,
12612 &tracepoint_breakpoint_ops
,
12616 set_tracepoint_count (breakpoint_count
);
12619 /* Set up a fake reader function that gets command lines from a linked
12620 list that was acquired during tracepoint uploading. */
12622 static struct uploaded_tp
*this_utp
;
12623 static int next_cmd
;
12626 read_uploaded_action (void)
12630 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12637 /* Given information about a tracepoint as recorded on a target (which
12638 can be either a live system or a trace file), attempt to create an
12639 equivalent GDB tracepoint. This is not a reliable process, since
12640 the target does not necessarily have all the information used when
12641 the tracepoint was originally defined. */
12643 struct tracepoint
*
12644 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12646 char *addr_str
, small_buf
[100];
12647 struct tracepoint
*tp
;
12649 if (utp
->at_string
)
12650 addr_str
= utp
->at_string
;
12653 /* In the absence of a source location, fall back to raw
12654 address. Since there is no way to confirm that the address
12655 means the same thing as when the trace was started, warn the
12657 warning (_("Uploaded tracepoint %d has no "
12658 "source location, using raw address"),
12660 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12661 addr_str
= small_buf
;
12664 /* There's not much we can do with a sequence of bytecodes. */
12665 if (utp
->cond
&& !utp
->cond_string
)
12666 warning (_("Uploaded tracepoint %d condition "
12667 "has no source form, ignoring it"),
12670 if (!create_breakpoint (get_current_arch (),
12672 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12674 utp
->type
/* type_wanted */,
12675 0 /* Ignore count */,
12676 pending_break_support
,
12677 &tracepoint_breakpoint_ops
,
12679 utp
->enabled
/* enabled */,
12683 set_tracepoint_count (breakpoint_count
);
12685 /* Get the tracepoint we just created. */
12686 tp
= get_tracepoint (tracepoint_count
);
12687 gdb_assert (tp
!= NULL
);
12691 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
12693 trace_pass_command (small_buf
, 0);
12696 /* If we have uploaded versions of the original commands, set up a
12697 special-purpose "reader" function and call the usual command line
12698 reader, then pass the result to the breakpoint command-setting
12700 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12702 struct command_line
*cmd_list
;
12707 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12709 breakpoint_set_commands (&tp
->base
, cmd_list
);
12711 else if (!VEC_empty (char_ptr
, utp
->actions
)
12712 || !VEC_empty (char_ptr
, utp
->step_actions
))
12713 warning (_("Uploaded tracepoint %d actions "
12714 "have no source form, ignoring them"),
12720 /* Print information on tracepoint number TPNUM_EXP, or all if
12724 tracepoints_info (char *args
, int from_tty
)
12728 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12730 if (num_printed
== 0)
12732 if (args
== NULL
|| *args
== '\0')
12733 ui_out_message (uiout
, 0, "No tracepoints.\n");
12735 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12738 default_collect_info ();
12741 /* The 'enable trace' command enables tracepoints.
12742 Not supported by all targets. */
12744 enable_trace_command (char *args
, int from_tty
)
12746 enable_command (args
, from_tty
);
12749 /* The 'disable trace' command disables tracepoints.
12750 Not supported by all targets. */
12752 disable_trace_command (char *args
, int from_tty
)
12754 disable_command (args
, from_tty
);
12757 /* Remove a tracepoint (or all if no argument). */
12759 delete_trace_command (char *arg
, int from_tty
)
12761 struct breakpoint
*b
, *b_tmp
;
12767 int breaks_to_delete
= 0;
12769 /* Delete all breakpoints if no argument.
12770 Do not delete internal or call-dummy breakpoints, these
12771 have to be deleted with an explicit breakpoint number
12773 ALL_TRACEPOINTS (b
)
12774 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12776 breaks_to_delete
= 1;
12780 /* Ask user only if there are some breakpoints to delete. */
12782 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12784 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12785 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12786 delete_breakpoint (b
);
12790 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12793 /* Helper function for trace_pass_command. */
12796 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
12798 tp
->pass_count
= count
;
12799 observer_notify_tracepoint_modified (tp
->base
.number
);
12801 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12802 tp
->base
.number
, count
);
12805 /* Set passcount for tracepoint.
12807 First command argument is passcount, second is tracepoint number.
12808 If tracepoint number omitted, apply to most recently defined.
12809 Also accepts special argument "all". */
12812 trace_pass_command (char *args
, int from_tty
)
12814 struct tracepoint
*t1
;
12815 unsigned int count
;
12817 if (args
== 0 || *args
== 0)
12818 error (_("passcount command requires an "
12819 "argument (count + optional TP num)"));
12821 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
12823 while (*args
&& isspace ((int) *args
))
12826 if (*args
&& strncasecmp (args
, "all", 3) == 0)
12828 struct breakpoint
*b
;
12830 args
+= 3; /* Skip special argument "all". */
12832 error (_("Junk at end of arguments."));
12834 ALL_TRACEPOINTS (b
)
12836 t1
= (struct tracepoint
*) b
;
12837 trace_pass_set_count (t1
, count
, from_tty
);
12840 else if (*args
== '\0')
12842 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
12844 trace_pass_set_count (t1
, count
, from_tty
);
12848 struct get_number_or_range_state state
;
12850 init_number_or_range (&state
, args
);
12851 while (!state
.finished
)
12853 t1
= get_tracepoint_by_number (&args
, &state
, 1);
12855 trace_pass_set_count (t1
, count
, from_tty
);
12860 struct tracepoint
*
12861 get_tracepoint (int num
)
12863 struct breakpoint
*t
;
12865 ALL_TRACEPOINTS (t
)
12866 if (t
->number
== num
)
12867 return (struct tracepoint
*) t
;
12872 /* Find the tracepoint with the given target-side number (which may be
12873 different from the tracepoint number after disconnecting and
12876 struct tracepoint
*
12877 get_tracepoint_by_number_on_target (int num
)
12879 struct breakpoint
*b
;
12881 ALL_TRACEPOINTS (b
)
12883 struct tracepoint
*t
= (struct tracepoint
*) b
;
12885 if (t
->number_on_target
== num
)
12892 /* Utility: parse a tracepoint number and look it up in the list.
12893 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12894 If OPTIONAL_P is true, then if the argument is missing, the most
12895 recent tracepoint (tracepoint_count) is returned. */
12896 struct tracepoint
*
12897 get_tracepoint_by_number (char **arg
,
12898 struct get_number_or_range_state
*state
,
12901 extern int tracepoint_count
;
12902 struct breakpoint
*t
;
12904 char *instring
= arg
== NULL
? NULL
: *arg
;
12908 gdb_assert (!state
->finished
);
12909 tpnum
= get_number_or_range (state
);
12911 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
12914 tpnum
= tracepoint_count
;
12916 error_no_arg (_("tracepoint number"));
12919 tpnum
= get_number (arg
);
12923 if (instring
&& *instring
)
12924 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12927 printf_filtered (_("Tracepoint argument missing "
12928 "and no previous tracepoint\n"));
12932 ALL_TRACEPOINTS (t
)
12933 if (t
->number
== tpnum
)
12935 return (struct tracepoint
*) t
;
12938 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
12943 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
12945 if (b
->thread
!= -1)
12946 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
12949 fprintf_unfiltered (fp
, " task %d", b
->task
);
12951 fprintf_unfiltered (fp
, "\n");
12954 /* Save information on user settable breakpoints (watchpoints, etc) to
12955 a new script file named FILENAME. If FILTER is non-NULL, call it
12956 on each breakpoint and only include the ones for which it returns
12960 save_breakpoints (char *filename
, int from_tty
,
12961 int (*filter
) (const struct breakpoint
*))
12963 struct breakpoint
*tp
;
12966 struct cleanup
*cleanup
;
12967 struct ui_file
*fp
;
12968 int extra_trace_bits
= 0;
12970 if (filename
== 0 || *filename
== 0)
12971 error (_("Argument required (file name in which to save)"));
12973 /* See if we have anything to save. */
12974 ALL_BREAKPOINTS (tp
)
12976 /* Skip internal and momentary breakpoints. */
12977 if (!user_breakpoint_p (tp
))
12980 /* If we have a filter, only save the breakpoints it accepts. */
12981 if (filter
&& !filter (tp
))
12986 if (is_tracepoint (tp
))
12988 extra_trace_bits
= 1;
12990 /* We can stop searching. */
12997 warning (_("Nothing to save."));
13001 pathname
= tilde_expand (filename
);
13002 cleanup
= make_cleanup (xfree
, pathname
);
13003 fp
= gdb_fopen (pathname
, "w");
13005 error (_("Unable to open file '%s' for saving (%s)"),
13006 filename
, safe_strerror (errno
));
13007 make_cleanup_ui_file_delete (fp
);
13009 if (extra_trace_bits
)
13010 save_trace_state_variables (fp
);
13012 ALL_BREAKPOINTS (tp
)
13014 /* Skip internal and momentary breakpoints. */
13015 if (!user_breakpoint_p (tp
))
13018 /* If we have a filter, only save the breakpoints it accepts. */
13019 if (filter
&& !filter (tp
))
13022 tp
->ops
->print_recreate (tp
, fp
);
13024 /* Note, we can't rely on tp->number for anything, as we can't
13025 assume the recreated breakpoint numbers will match. Use $bpnum
13028 if (tp
->cond_string
)
13029 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13031 if (tp
->ignore_count
)
13032 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13036 volatile struct gdb_exception ex
;
13038 fprintf_unfiltered (fp
, " commands\n");
13040 ui_out_redirect (uiout
, fp
);
13041 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13043 print_command_lines (uiout
, tp
->commands
->commands
, 2);
13045 ui_out_redirect (uiout
, NULL
);
13048 throw_exception (ex
);
13050 fprintf_unfiltered (fp
, " end\n");
13053 if (tp
->enable_state
== bp_disabled
)
13054 fprintf_unfiltered (fp
, "disable\n");
13056 /* If this is a multi-location breakpoint, check if the locations
13057 should be individually disabled. Watchpoint locations are
13058 special, and not user visible. */
13059 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13061 struct bp_location
*loc
;
13064 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13066 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13070 if (extra_trace_bits
&& *default_collect
)
13071 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13073 do_cleanups (cleanup
);
13075 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13078 /* The `save breakpoints' command. */
13081 save_breakpoints_command (char *args
, int from_tty
)
13083 save_breakpoints (args
, from_tty
, NULL
);
13086 /* The `save tracepoints' command. */
13089 save_tracepoints_command (char *args
, int from_tty
)
13091 save_breakpoints (args
, from_tty
, is_tracepoint
);
13094 /* Create a vector of all tracepoints. */
13096 VEC(breakpoint_p
) *
13097 all_tracepoints (void)
13099 VEC(breakpoint_p
) *tp_vec
= 0;
13100 struct breakpoint
*tp
;
13102 ALL_TRACEPOINTS (tp
)
13104 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13111 /* This help string is used for the break, hbreak, tbreak and thbreak
13112 commands. It is defined as a macro to prevent duplication.
13113 COMMAND should be a string constant containing the name of the
13115 #define BREAK_ARGS_HELP(command) \
13116 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13117 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13118 If a line number is specified, break at start of code for that line.\n\
13119 If a function is specified, break at start of code for that function.\n\
13120 If an address is specified, break at that exact address.\n\
13121 With no LOCATION, uses current execution address of the selected\n\
13122 stack frame. This is useful for breaking on return to a stack frame.\n\
13124 THREADNUM is the number from \"info threads\".\n\
13125 CONDITION is a boolean expression.\n\
13127 Multiple breakpoints at one place are permitted, and useful if their\n\
13128 conditions are different.\n\
13130 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13132 /* List of subcommands for "catch". */
13133 static struct cmd_list_element
*catch_cmdlist
;
13135 /* List of subcommands for "tcatch". */
13136 static struct cmd_list_element
*tcatch_cmdlist
;
13139 add_catch_command (char *name
, char *docstring
,
13140 void (*sfunc
) (char *args
, int from_tty
,
13141 struct cmd_list_element
*command
),
13142 char **(*completer
) (struct cmd_list_element
*cmd
,
13143 char *text
, char *word
),
13144 void *user_data_catch
,
13145 void *user_data_tcatch
)
13147 struct cmd_list_element
*command
;
13149 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13151 set_cmd_sfunc (command
, sfunc
);
13152 set_cmd_context (command
, user_data_catch
);
13153 set_cmd_completer (command
, completer
);
13155 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13157 set_cmd_sfunc (command
, sfunc
);
13158 set_cmd_context (command
, user_data_tcatch
);
13159 set_cmd_completer (command
, completer
);
13163 clear_syscall_counts (struct inferior
*inf
)
13165 inf
->total_syscalls_count
= 0;
13166 inf
->any_syscall_count
= 0;
13167 VEC_free (int, inf
->syscalls_counts
);
13171 save_command (char *arg
, int from_tty
)
13173 printf_unfiltered (_("\"save\" must be followed by "
13174 "the name of a save subcommand.\n"));
13175 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13178 struct breakpoint
*
13179 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13182 struct breakpoint
*b
, *b_tmp
;
13184 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13186 if ((*callback
) (b
, data
))
13194 initialize_breakpoint_ops (void)
13196 static int initialized
= 0;
13198 struct breakpoint_ops
*ops
;
13204 /* The breakpoint_ops structure to be inherit by all kinds of
13205 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13206 internal and momentary breakpoints, etc.). */
13207 ops
= &bkpt_base_breakpoint_ops
;
13208 *ops
= base_breakpoint_ops
;
13209 ops
->re_set
= bkpt_re_set
;
13210 ops
->insert_location
= bkpt_insert_location
;
13211 ops
->remove_location
= bkpt_remove_location
;
13212 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13214 /* The breakpoint_ops structure to be used in regular breakpoints. */
13215 ops
= &bkpt_breakpoint_ops
;
13216 *ops
= bkpt_base_breakpoint_ops
;
13217 ops
->re_set
= bkpt_re_set
;
13218 ops
->resources_needed
= bkpt_resources_needed
;
13219 ops
->print_it
= bkpt_print_it
;
13220 ops
->print_mention
= bkpt_print_mention
;
13221 ops
->print_recreate
= bkpt_print_recreate
;
13223 /* Ranged breakpoints. */
13224 ops
= &ranged_breakpoint_ops
;
13225 *ops
= bkpt_breakpoint_ops
;
13226 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13227 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13228 ops
->print_it
= print_it_ranged_breakpoint
;
13229 ops
->print_one
= print_one_ranged_breakpoint
;
13230 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13231 ops
->print_mention
= print_mention_ranged_breakpoint
;
13232 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13234 /* Internal breakpoints. */
13235 ops
= &internal_breakpoint_ops
;
13236 *ops
= bkpt_base_breakpoint_ops
;
13237 ops
->re_set
= internal_bkpt_re_set
;
13238 ops
->check_status
= internal_bkpt_check_status
;
13239 ops
->print_it
= internal_bkpt_print_it
;
13240 ops
->print_mention
= internal_bkpt_print_mention
;
13242 /* Momentary breakpoints. */
13243 ops
= &momentary_breakpoint_ops
;
13244 *ops
= bkpt_base_breakpoint_ops
;
13245 ops
->re_set
= momentary_bkpt_re_set
;
13246 ops
->check_status
= momentary_bkpt_check_status
;
13247 ops
->print_it
= momentary_bkpt_print_it
;
13248 ops
->print_mention
= momentary_bkpt_print_mention
;
13250 /* GNU v3 exception catchpoints. */
13251 ops
= &gnu_v3_exception_catchpoint_ops
;
13252 *ops
= bkpt_breakpoint_ops
;
13253 ops
->print_it
= print_it_exception_catchpoint
;
13254 ops
->print_one
= print_one_exception_catchpoint
;
13255 ops
->print_mention
= print_mention_exception_catchpoint
;
13256 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13259 ops
= &watchpoint_breakpoint_ops
;
13260 *ops
= base_breakpoint_ops
;
13261 ops
->dtor
= dtor_watchpoint
;
13262 ops
->re_set
= re_set_watchpoint
;
13263 ops
->insert_location
= insert_watchpoint
;
13264 ops
->remove_location
= remove_watchpoint
;
13265 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13266 ops
->check_status
= check_status_watchpoint
;
13267 ops
->resources_needed
= resources_needed_watchpoint
;
13268 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13269 ops
->print_it
= print_it_watchpoint
;
13270 ops
->print_mention
= print_mention_watchpoint
;
13271 ops
->print_recreate
= print_recreate_watchpoint
;
13273 /* Masked watchpoints. */
13274 ops
= &masked_watchpoint_breakpoint_ops
;
13275 *ops
= watchpoint_breakpoint_ops
;
13276 ops
->insert_location
= insert_masked_watchpoint
;
13277 ops
->remove_location
= remove_masked_watchpoint
;
13278 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13279 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13280 ops
->print_it
= print_it_masked_watchpoint
;
13281 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13282 ops
->print_mention
= print_mention_masked_watchpoint
;
13283 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13286 ops
= &tracepoint_breakpoint_ops
;
13287 *ops
= base_breakpoint_ops
;
13288 ops
->re_set
= tracepoint_re_set
;
13289 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13290 ops
->print_one_detail
= tracepoint_print_one_detail
;
13291 ops
->print_mention
= tracepoint_print_mention
;
13292 ops
->print_recreate
= tracepoint_print_recreate
;
13294 /* Fork catchpoints. */
13295 ops
= &catch_fork_breakpoint_ops
;
13296 *ops
= base_breakpoint_ops
;
13297 ops
->insert_location
= insert_catch_fork
;
13298 ops
->remove_location
= remove_catch_fork
;
13299 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13300 ops
->print_it
= print_it_catch_fork
;
13301 ops
->print_one
= print_one_catch_fork
;
13302 ops
->print_mention
= print_mention_catch_fork
;
13303 ops
->print_recreate
= print_recreate_catch_fork
;
13305 /* Vfork catchpoints. */
13306 ops
= &catch_vfork_breakpoint_ops
;
13307 *ops
= base_breakpoint_ops
;
13308 ops
->insert_location
= insert_catch_vfork
;
13309 ops
->remove_location
= remove_catch_vfork
;
13310 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13311 ops
->print_it
= print_it_catch_vfork
;
13312 ops
->print_one
= print_one_catch_vfork
;
13313 ops
->print_mention
= print_mention_catch_vfork
;
13314 ops
->print_recreate
= print_recreate_catch_vfork
;
13316 /* Exec catchpoints. */
13317 ops
= &catch_exec_breakpoint_ops
;
13318 *ops
= base_breakpoint_ops
;
13319 ops
->dtor
= dtor_catch_exec
;
13320 ops
->insert_location
= insert_catch_exec
;
13321 ops
->remove_location
= remove_catch_exec
;
13322 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13323 ops
->print_it
= print_it_catch_exec
;
13324 ops
->print_one
= print_one_catch_exec
;
13325 ops
->print_mention
= print_mention_catch_exec
;
13326 ops
->print_recreate
= print_recreate_catch_exec
;
13328 /* Syscall catchpoints. */
13329 ops
= &catch_syscall_breakpoint_ops
;
13330 *ops
= base_breakpoint_ops
;
13331 ops
->dtor
= dtor_catch_syscall
;
13332 ops
->insert_location
= insert_catch_syscall
;
13333 ops
->remove_location
= remove_catch_syscall
;
13334 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13335 ops
->print_it
= print_it_catch_syscall
;
13336 ops
->print_one
= print_one_catch_syscall
;
13337 ops
->print_mention
= print_mention_catch_syscall
;
13338 ops
->print_recreate
= print_recreate_catch_syscall
;
13342 _initialize_breakpoint (void)
13344 struct cmd_list_element
*c
;
13346 initialize_breakpoint_ops ();
13348 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13349 observer_attach_inferior_exit (clear_syscall_counts
);
13350 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13352 breakpoint_objfile_key
= register_objfile_data ();
13354 breakpoint_chain
= 0;
13355 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13356 before a breakpoint is set. */
13357 breakpoint_count
= 0;
13359 tracepoint_count
= 0;
13361 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13362 Set ignore-count of breakpoint number N to COUNT.\n\
13363 Usage is `ignore N COUNT'."));
13365 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13367 add_com ("commands", class_breakpoint
, commands_command
, _("\
13368 Set commands to be executed when a breakpoint is hit.\n\
13369 Give breakpoint number as argument after \"commands\".\n\
13370 With no argument, the targeted breakpoint is the last one set.\n\
13371 The commands themselves follow starting on the next line.\n\
13372 Type a line containing \"end\" to indicate the end of them.\n\
13373 Give \"silent\" as the first line to make the breakpoint silent;\n\
13374 then no output is printed when it is hit, except what the commands print."));
13376 add_com ("condition", class_breakpoint
, condition_command
, _("\
13377 Specify breakpoint number N to break only if COND is true.\n\
13378 Usage is `condition N COND', where N is an integer and COND is an\n\
13379 expression to be evaluated whenever breakpoint N is reached."));
13381 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13382 Set a temporary breakpoint.\n\
13383 Like \"break\" except the breakpoint is only temporary,\n\
13384 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13385 by using \"enable delete\" on the breakpoint number.\n\
13387 BREAK_ARGS_HELP ("tbreak")));
13388 set_cmd_completer (c
, location_completer
);
13390 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13391 Set a hardware assisted breakpoint.\n\
13392 Like \"break\" except the breakpoint requires hardware support,\n\
13393 some target hardware may not have this support.\n\
13395 BREAK_ARGS_HELP ("hbreak")));
13396 set_cmd_completer (c
, location_completer
);
13398 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13399 Set a temporary hardware assisted breakpoint.\n\
13400 Like \"hbreak\" except the breakpoint is only temporary,\n\
13401 so it will be deleted when hit.\n\
13403 BREAK_ARGS_HELP ("thbreak")));
13404 set_cmd_completer (c
, location_completer
);
13406 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13407 Enable some breakpoints.\n\
13408 Give breakpoint numbers (separated by spaces) as arguments.\n\
13409 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13410 This is used to cancel the effect of the \"disable\" command.\n\
13411 With a subcommand you can enable temporarily."),
13412 &enablelist
, "enable ", 1, &cmdlist
);
13414 add_com ("ab", class_breakpoint
, enable_command
, _("\
13415 Enable some breakpoints.\n\
13416 Give breakpoint numbers (separated by spaces) as arguments.\n\
13417 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13418 This is used to cancel the effect of the \"disable\" command.\n\
13419 With a subcommand you can enable temporarily."));
13421 add_com_alias ("en", "enable", class_breakpoint
, 1);
13423 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13424 Enable some breakpoints.\n\
13425 Give breakpoint numbers (separated by spaces) as arguments.\n\
13426 This is used to cancel the effect of the \"disable\" command.\n\
13427 May be abbreviated to simply \"enable\".\n"),
13428 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13430 add_cmd ("once", no_class
, enable_once_command
, _("\
13431 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13432 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13435 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13436 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13437 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13440 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13441 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13442 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13445 add_cmd ("once", no_class
, enable_once_command
, _("\
13446 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13447 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13450 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13451 Disable some breakpoints.\n\
13452 Arguments are breakpoint numbers with spaces in between.\n\
13453 To disable all breakpoints, give no argument.\n\
13454 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13455 &disablelist
, "disable ", 1, &cmdlist
);
13456 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13457 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13459 add_com ("sb", class_breakpoint
, disable_command
, _("\
13460 Disable some breakpoints.\n\
13461 Arguments are breakpoint numbers with spaces in between.\n\
13462 To disable all breakpoints, give no argument.\n\
13463 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13465 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13466 Disable some breakpoints.\n\
13467 Arguments are breakpoint numbers with spaces in between.\n\
13468 To disable all breakpoints, give no argument.\n\
13469 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13470 This command may be abbreviated \"disable\"."),
13473 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13474 Delete some breakpoints or auto-display expressions.\n\
13475 Arguments are breakpoint numbers with spaces in between.\n\
13476 To delete all breakpoints, give no argument.\n\
13478 Also a prefix command for deletion of other GDB objects.\n\
13479 The \"unset\" command is also an alias for \"delete\"."),
13480 &deletelist
, "delete ", 1, &cmdlist
);
13481 add_com_alias ("d", "delete", class_breakpoint
, 1);
13482 add_com_alias ("del", "delete", class_breakpoint
, 1);
13484 add_com ("db", class_breakpoint
, delete_command
, _("\
13485 Delete some breakpoints.\n\
13486 Arguments are breakpoint numbers with spaces in between.\n\
13487 To delete all breakpoints, give no argument.\n"));
13489 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13490 Delete some breakpoints or auto-display expressions.\n\
13491 Arguments are breakpoint numbers with spaces in between.\n\
13492 To delete all breakpoints, give no argument.\n\
13493 This command may be abbreviated \"delete\"."),
13496 add_com ("clear", class_breakpoint
, clear_command
, _("\
13497 Clear breakpoint at specified line or function.\n\
13498 Argument may be line number, function name, or \"*\" and an address.\n\
13499 If line number is specified, all breakpoints in that line are cleared.\n\
13500 If function is specified, breakpoints at beginning of function are cleared.\n\
13501 If an address is specified, breakpoints at that address are cleared.\n\
13503 With no argument, clears all breakpoints in the line that the selected frame\n\
13504 is executing in.\n\
13506 See also the \"delete\" command which clears breakpoints by number."));
13507 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13509 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13510 Set breakpoint at specified line or function.\n"
13511 BREAK_ARGS_HELP ("break")));
13512 set_cmd_completer (c
, location_completer
);
13514 add_com_alias ("b", "break", class_run
, 1);
13515 add_com_alias ("br", "break", class_run
, 1);
13516 add_com_alias ("bre", "break", class_run
, 1);
13517 add_com_alias ("brea", "break", class_run
, 1);
13520 add_com_alias ("ba", "break", class_breakpoint
, 1);
13524 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13525 Break in function/address or break at a line in the current file."),
13526 &stoplist
, "stop ", 1, &cmdlist
);
13527 add_cmd ("in", class_breakpoint
, stopin_command
,
13528 _("Break in function or address."), &stoplist
);
13529 add_cmd ("at", class_breakpoint
, stopat_command
,
13530 _("Break at a line in the current file."), &stoplist
);
13531 add_com ("status", class_info
, breakpoints_info
, _("\
13532 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13533 The \"Type\" column indicates one of:\n\
13534 \tbreakpoint - normal breakpoint\n\
13535 \twatchpoint - watchpoint\n\
13536 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13537 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13538 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13539 address and file/line number respectively.\n\
13541 Convenience variable \"$_\" and default examine address for \"x\"\n\
13542 are set to the address of the last breakpoint listed unless the command\n\
13543 is prefixed with \"server \".\n\n\
13544 Convenience variable \"$bpnum\" contains the number of the last\n\
13545 breakpoint set."));
13548 add_info ("breakpoints", breakpoints_info
, _("\
13549 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13550 The \"Type\" column indicates one of:\n\
13551 \tbreakpoint - normal breakpoint\n\
13552 \twatchpoint - watchpoint\n\
13553 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13554 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13555 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13556 address and file/line number respectively.\n\
13558 Convenience variable \"$_\" and default examine address for \"x\"\n\
13559 are set to the address of the last breakpoint listed unless the command\n\
13560 is prefixed with \"server \".\n\n\
13561 Convenience variable \"$bpnum\" contains the number of the last\n\
13562 breakpoint set."));
13564 add_info_alias ("b", "breakpoints", 1);
13567 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13568 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13569 The \"Type\" column indicates one of:\n\
13570 \tbreakpoint - normal breakpoint\n\
13571 \twatchpoint - watchpoint\n\
13572 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13573 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13574 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13575 address and file/line number respectively.\n\
13577 Convenience variable \"$_\" and default examine address for \"x\"\n\
13578 are set to the address of the last breakpoint listed unless the command\n\
13579 is prefixed with \"server \".\n\n\
13580 Convenience variable \"$bpnum\" contains the number of the last\n\
13581 breakpoint set."));
13583 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13584 Status of all breakpoints, or breakpoint number NUMBER.\n\
13585 The \"Type\" column indicates one of:\n\
13586 \tbreakpoint - normal breakpoint\n\
13587 \twatchpoint - watchpoint\n\
13588 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13589 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13590 \tuntil - internal breakpoint used by the \"until\" command\n\
13591 \tfinish - internal breakpoint used by the \"finish\" command\n\
13592 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13593 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13594 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13595 address and file/line number respectively.\n\
13597 Convenience variable \"$_\" and default examine address for \"x\"\n\
13598 are set to the address of the last breakpoint listed unless the command\n\
13599 is prefixed with \"server \".\n\n\
13600 Convenience variable \"$bpnum\" contains the number of the last\n\
13602 &maintenanceinfolist
);
13604 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13605 Set catchpoints to catch events."),
13606 &catch_cmdlist
, "catch ",
13607 0/*allow-unknown*/, &cmdlist
);
13609 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13610 Set temporary catchpoints to catch events."),
13611 &tcatch_cmdlist
, "tcatch ",
13612 0/*allow-unknown*/, &cmdlist
);
13614 /* Add catch and tcatch sub-commands. */
13615 add_catch_command ("catch", _("\
13616 Catch an exception, when caught.\n\
13617 With an argument, catch only exceptions with the given name."),
13618 catch_catch_command
,
13622 add_catch_command ("throw", _("\
13623 Catch an exception, when thrown.\n\
13624 With an argument, catch only exceptions with the given name."),
13625 catch_throw_command
,
13629 add_catch_command ("fork", _("Catch calls to fork."),
13630 catch_fork_command_1
,
13632 (void *) (uintptr_t) catch_fork_permanent
,
13633 (void *) (uintptr_t) catch_fork_temporary
);
13634 add_catch_command ("vfork", _("Catch calls to vfork."),
13635 catch_fork_command_1
,
13637 (void *) (uintptr_t) catch_vfork_permanent
,
13638 (void *) (uintptr_t) catch_vfork_temporary
);
13639 add_catch_command ("exec", _("Catch calls to exec."),
13640 catch_exec_command_1
,
13644 add_catch_command ("syscall", _("\
13645 Catch system calls by their names and/or numbers.\n\
13646 Arguments say which system calls to catch. If no arguments\n\
13647 are given, every system call will be caught.\n\
13648 Arguments, if given, should be one or more system call names\n\
13649 (if your system supports that), or system call numbers."),
13650 catch_syscall_command_1
,
13651 catch_syscall_completer
,
13655 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13656 Set a watchpoint for an expression.\n\
13657 Usage: watch [-l|-location] EXPRESSION\n\
13658 A watchpoint stops execution of your program whenever the value of\n\
13659 an expression changes.\n\
13660 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13661 the memory to which it refers."));
13662 set_cmd_completer (c
, expression_completer
);
13664 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13665 Set a read watchpoint for an expression.\n\
13666 Usage: rwatch [-l|-location] EXPRESSION\n\
13667 A watchpoint stops execution of your program whenever the value of\n\
13668 an expression is read.\n\
13669 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13670 the memory to which it refers."));
13671 set_cmd_completer (c
, expression_completer
);
13673 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13674 Set a watchpoint for an expression.\n\
13675 Usage: awatch [-l|-location] EXPRESSION\n\
13676 A watchpoint stops execution of your program whenever the value of\n\
13677 an expression is either read or written.\n\
13678 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13679 the memory to which it refers."));
13680 set_cmd_completer (c
, expression_completer
);
13682 add_info ("watchpoints", watchpoints_info
, _("\
13683 Status of specified watchpoints (all watchpoints if no argument)."));
13685 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13686 respond to changes - contrary to the description. */
13687 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13688 &can_use_hw_watchpoints
, _("\
13689 Set debugger's willingness to use watchpoint hardware."), _("\
13690 Show debugger's willingness to use watchpoint hardware."), _("\
13691 If zero, gdb will not use hardware for new watchpoints, even if\n\
13692 such is available. (However, any hardware watchpoints that were\n\
13693 created before setting this to nonzero, will continue to use watchpoint\n\
13696 show_can_use_hw_watchpoints
,
13697 &setlist
, &showlist
);
13699 can_use_hw_watchpoints
= 1;
13701 /* Tracepoint manipulation commands. */
13703 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13704 Set a tracepoint at specified line or function.\n\
13706 BREAK_ARGS_HELP ("trace") "\n\
13707 Do \"help tracepoints\" for info on other tracepoint commands."));
13708 set_cmd_completer (c
, location_completer
);
13710 add_com_alias ("tp", "trace", class_alias
, 0);
13711 add_com_alias ("tr", "trace", class_alias
, 1);
13712 add_com_alias ("tra", "trace", class_alias
, 1);
13713 add_com_alias ("trac", "trace", class_alias
, 1);
13715 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13716 Set a fast tracepoint at specified line or function.\n\
13718 BREAK_ARGS_HELP ("ftrace") "\n\
13719 Do \"help tracepoints\" for info on other tracepoint commands."));
13720 set_cmd_completer (c
, location_completer
);
13722 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13723 Set a static tracepoint at specified line, function or marker.\n\
13725 strace [LOCATION] [if CONDITION]\n\
13726 LOCATION may be a line number, function name, \"*\" and an address,\n\
13727 or -m MARKER_ID.\n\
13728 If a line number is specified, probe the marker at start of code\n\
13729 for that line. If a function is specified, probe the marker at start\n\
13730 of code for that function. If an address is specified, probe the marker\n\
13731 at that exact address. If a marker id is specified, probe the marker\n\
13732 with that name. With no LOCATION, uses current execution address of\n\
13733 the selected stack frame.\n\
13734 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13735 This collects arbitrary user data passed in the probe point call to the\n\
13736 tracing library. You can inspect it when analyzing the trace buffer,\n\
13737 by printing the $_sdata variable like any other convenience variable.\n\
13739 CONDITION is a boolean expression.\n\
13741 Multiple tracepoints at one place are permitted, and useful if their\n\
13742 conditions are different.\n\
13744 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13745 Do \"help tracepoints\" for info on other tracepoint commands."));
13746 set_cmd_completer (c
, location_completer
);
13748 add_info ("tracepoints", tracepoints_info
, _("\
13749 Status of specified tracepoints (all tracepoints if no argument).\n\
13750 Convenience variable \"$tpnum\" contains the number of the\n\
13751 last tracepoint set."));
13753 add_info_alias ("tp", "tracepoints", 1);
13755 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13756 Delete specified tracepoints.\n\
13757 Arguments are tracepoint numbers, separated by spaces.\n\
13758 No argument means delete all tracepoints."),
13761 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13762 Disable specified tracepoints.\n\
13763 Arguments are tracepoint numbers, separated by spaces.\n\
13764 No argument means disable all tracepoints."),
13766 deprecate_cmd (c
, "disable");
13768 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
13769 Enable specified tracepoints.\n\
13770 Arguments are tracepoint numbers, separated by spaces.\n\
13771 No argument means enable all tracepoints."),
13773 deprecate_cmd (c
, "enable");
13775 add_com ("passcount", class_trace
, trace_pass_command
, _("\
13776 Set the passcount for a tracepoint.\n\
13777 The trace will end when the tracepoint has been passed 'count' times.\n\
13778 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13779 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13781 add_prefix_cmd ("save", class_breakpoint
, save_command
,
13782 _("Save breakpoint definitions as a script."),
13783 &save_cmdlist
, "save ",
13784 0/*allow-unknown*/, &cmdlist
);
13786 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
13787 Save current breakpoint definitions as a script.\n\
13788 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13789 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13790 session to restore them."),
13792 set_cmd_completer (c
, filename_completer
);
13794 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
13795 Save current tracepoint definitions as a script.\n\
13796 Use the 'source' command in another debug session to restore them."),
13798 set_cmd_completer (c
, filename_completer
);
13800 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
13801 deprecate_cmd (c
, "save tracepoints");
13803 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
13804 Breakpoint specific settings\n\
13805 Configure various breakpoint-specific variables such as\n\
13806 pending breakpoint behavior"),
13807 &breakpoint_set_cmdlist
, "set breakpoint ",
13808 0/*allow-unknown*/, &setlist
);
13809 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
13810 Breakpoint specific settings\n\
13811 Configure various breakpoint-specific variables such as\n\
13812 pending breakpoint behavior"),
13813 &breakpoint_show_cmdlist
, "show breakpoint ",
13814 0/*allow-unknown*/, &showlist
);
13816 add_setshow_auto_boolean_cmd ("pending", no_class
,
13817 &pending_break_support
, _("\
13818 Set debugger's behavior regarding pending breakpoints."), _("\
13819 Show debugger's behavior regarding pending breakpoints."), _("\
13820 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13821 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13822 an error. If auto, an unrecognized breakpoint location results in a\n\
13823 user-query to see if a pending breakpoint should be created."),
13825 show_pending_break_support
,
13826 &breakpoint_set_cmdlist
,
13827 &breakpoint_show_cmdlist
);
13829 pending_break_support
= AUTO_BOOLEAN_AUTO
;
13831 add_setshow_boolean_cmd ("auto-hw", no_class
,
13832 &automatic_hardware_breakpoints
, _("\
13833 Set automatic usage of hardware breakpoints."), _("\
13834 Show automatic usage of hardware breakpoints."), _("\
13835 If set, the debugger will automatically use hardware breakpoints for\n\
13836 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13837 a warning will be emitted for such breakpoints."),
13839 show_automatic_hardware_breakpoints
,
13840 &breakpoint_set_cmdlist
,
13841 &breakpoint_show_cmdlist
);
13843 add_setshow_enum_cmd ("always-inserted", class_support
,
13844 always_inserted_enums
, &always_inserted_mode
, _("\
13845 Set mode for inserting breakpoints."), _("\
13846 Show mode for inserting breakpoints."), _("\
13847 When this mode is off, breakpoints are inserted in inferior when it is\n\
13848 resumed, and removed when execution stops. When this mode is on,\n\
13849 breakpoints are inserted immediately and removed only when the user\n\
13850 deletes the breakpoint. When this mode is auto (which is the default),\n\
13851 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13852 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13853 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13854 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13856 &show_always_inserted_mode
,
13857 &breakpoint_set_cmdlist
,
13858 &breakpoint_show_cmdlist
);
13860 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
13861 Set a breakpoint for an address range.\n\
13862 break-range START-LOCATION, END-LOCATION\n\
13863 where START-LOCATION and END-LOCATION can be one of the following:\n\
13864 LINENUM, for that line in the current file,\n\
13865 FILE:LINENUM, for that line in that file,\n\
13866 +OFFSET, for that number of lines after the current line\n\
13867 or the start of the range\n\
13868 FUNCTION, for the first line in that function,\n\
13869 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13870 *ADDRESS, for the instruction at that address.\n\
13872 The breakpoint will stop execution of the inferior whenever it executes\n\
13873 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13874 range (including START-LOCATION and END-LOCATION)."));
13876 automatic_hardware_breakpoints
= 1;
13878 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);