1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
42 #include "filenames.h"
48 #include "completer.h"
51 #include "cli/cli-script.h"
52 #include "gdb_assert.h"
57 #include "exceptions.h"
64 #include "xml-syscall.h"
65 #include "parser-defs.h"
66 #include "cli/cli-utils.h"
67 #include "continuations.h"
69 /* readline include files */
70 #include "readline/readline.h"
71 #include "readline/history.h"
73 /* readline defines this. */
76 #include "mi/mi-common.h"
77 #include "python/python.h"
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void breakpoint_re_set_default (struct breakpoint
*);
99 static void clear_command (char *, int);
101 static void catch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value
*);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint
*);
109 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
111 struct breakpoint_ops
*);
112 /* This function is used in gdbtk sources and thus can not be made
114 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
115 struct symtab_and_line
,
116 enum bptype
, struct breakpoint_ops
*);
118 static struct breakpoint
*
119 momentary_breakpoint_from_master (struct breakpoint
*orig
,
121 struct breakpoint_ops
*ops
);
123 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
125 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
129 static void describe_other_breakpoints (struct gdbarch
*,
130 struct program_space
*, CORE_ADDR
,
131 struct obj_section
*, int);
133 static int breakpoint_address_match (struct address_space
*aspace1
,
135 struct address_space
*aspace2
,
138 static int watchpoint_locations_match (struct bp_location
*loc1
,
139 struct bp_location
*loc2
);
141 static int breakpoint_location_address_match (struct bp_location
*bl
,
142 struct address_space
*aspace
,
145 static void breakpoints_info (char *, int);
147 static void watchpoints_info (char *, int);
149 static int breakpoint_1 (char *, int,
150 int (*) (const struct breakpoint
*));
152 static int breakpoint_cond_eval (void *);
154 static void cleanup_executing_breakpoints (void *);
156 static void commands_command (char *, int);
158 static void condition_command (char *, int);
167 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
168 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
170 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
172 static int watchpoint_check (void *);
174 static void maintenance_info_breakpoints (char *, int);
176 static int hw_breakpoint_used_count (void);
178 static int hw_watchpoint_used_count (enum bptype
, int *);
180 static void hbreak_command (char *, int);
182 static void thbreak_command (char *, int);
184 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
);
186 static void stop_command (char *arg
, int from_tty
);
188 static void stopin_command (char *arg
, int from_tty
);
190 static void stopat_command (char *arg
, int from_tty
);
192 static char *ep_parse_optional_if_clause (char **arg
);
194 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
195 char *arg
, int tempflag
, int from_tty
);
197 static void tcatch_command (char *arg
, int from_tty
);
199 static void detach_single_step_breakpoints (void);
201 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
204 static void free_bp_location (struct bp_location
*loc
);
205 static void incref_bp_location (struct bp_location
*loc
);
206 static void decref_bp_location (struct bp_location
**loc
);
208 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
210 static void update_global_location_list (int);
212 static void update_global_location_list_nothrow (int);
214 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
216 static int is_watchpoint (const struct breakpoint
*bpt
);
218 static void insert_breakpoint_locations (void);
220 static int syscall_catchpoint_p (struct breakpoint
*b
);
222 static void tracepoints_info (char *, int);
224 static void delete_trace_command (char *, int);
226 static void enable_trace_command (char *, int);
228 static void disable_trace_command (char *, int);
230 static void trace_pass_command (char *, int);
232 static int is_masked_watchpoint (const struct breakpoint
*b
);
234 /* Assuming we're creating a static tracepoint, does S look like a
235 static tracepoint marker spec ("-m MARKER_ID")? */
236 #define is_marker_spec(s) \
237 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
239 /* The abstract base class all breakpoint_ops structures inherit
241 static struct breakpoint_ops base_breakpoint_ops
;
243 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
244 that are implemented on top of software or hardware breakpoints
245 (user breakpoints, internal and momentary breakpoints, etc.). */
246 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
248 /* Internal breakpoints class type. */
249 static struct breakpoint_ops internal_breakpoint_ops
;
251 /* Momentary breakpoints class type. */
252 static struct breakpoint_ops momentary_breakpoint_ops
;
254 /* The breakpoint_ops structure to be used in regular user created
256 struct breakpoint_ops bkpt_breakpoint_ops
;
258 /* A reference-counted struct command_line. This lets multiple
259 breakpoints share a single command list. */
260 struct counted_command_line
262 /* The reference count. */
265 /* The command list. */
266 struct command_line
*commands
;
269 struct command_line
*
270 breakpoint_commands (struct breakpoint
*b
)
272 return b
->commands
? b
->commands
->commands
: NULL
;
275 /* Flag indicating that a command has proceeded the inferior past the
276 current breakpoint. */
278 static int breakpoint_proceeded
;
281 bpdisp_text (enum bpdisp disp
)
283 /* NOTE: the following values are a part of MI protocol and
284 represent values of 'disp' field returned when inferior stops at
286 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
288 return bpdisps
[(int) disp
];
291 /* Prototypes for exported functions. */
292 /* If FALSE, gdb will not use hardware support for watchpoints, even
293 if such is available. */
294 static int can_use_hw_watchpoints
;
297 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
298 struct cmd_list_element
*c
,
301 fprintf_filtered (file
,
302 _("Debugger's willingness to use "
303 "watchpoint hardware is %s.\n"),
307 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
308 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
309 for unrecognized breakpoint locations.
310 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
311 static enum auto_boolean pending_break_support
;
313 show_pending_break_support (struct ui_file
*file
, int from_tty
,
314 struct cmd_list_element
*c
,
317 fprintf_filtered (file
,
318 _("Debugger's behavior regarding "
319 "pending breakpoints is %s.\n"),
323 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
324 set with "break" but falling in read-only memory.
325 If 0, gdb will warn about such breakpoints, but won't automatically
326 use hardware breakpoints. */
327 static int automatic_hardware_breakpoints
;
329 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
330 struct cmd_list_element
*c
,
333 fprintf_filtered (file
,
334 _("Automatic usage of hardware breakpoints is %s.\n"),
338 /* If on, gdb will keep breakpoints inserted even as inferior is
339 stopped, and immediately insert any new breakpoints. If off, gdb
340 will insert breakpoints into inferior only when resuming it, and
341 will remove breakpoints upon stop. If auto, GDB will behave as ON
342 if in non-stop mode, and as OFF if all-stop mode.*/
344 static const char always_inserted_auto
[] = "auto";
345 static const char always_inserted_on
[] = "on";
346 static const char always_inserted_off
[] = "off";
347 static const char *always_inserted_enums
[] = {
348 always_inserted_auto
,
353 static const char *always_inserted_mode
= always_inserted_auto
;
355 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
356 struct cmd_list_element
*c
, const char *value
)
358 if (always_inserted_mode
== always_inserted_auto
)
359 fprintf_filtered (file
,
360 _("Always inserted breakpoint "
361 "mode is %s (currently %s).\n"),
363 breakpoints_always_inserted_mode () ? "on" : "off");
365 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
370 breakpoints_always_inserted_mode (void)
372 return (always_inserted_mode
== always_inserted_on
373 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
376 void _initialize_breakpoint (void);
378 /* Are we executing breakpoint commands? */
379 static int executing_breakpoint_commands
;
381 /* Are overlay event breakpoints enabled? */
382 static int overlay_events_enabled
;
384 /* See description in breakpoint.h. */
385 int target_exact_watchpoints
= 0;
387 /* Walk the following statement or block through all breakpoints.
388 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
389 current breakpoint. */
391 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
393 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
394 for (B = breakpoint_chain; \
395 B ? (TMP=B->next, 1): 0; \
398 /* Similar iterator for the low-level breakpoints. SAFE variant is
399 not provided so update_global_location_list must not be called
400 while executing the block of ALL_BP_LOCATIONS. */
402 #define ALL_BP_LOCATIONS(B,BP_TMP) \
403 for (BP_TMP = bp_location; \
404 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
407 /* Iterator for tracepoints only. */
409 #define ALL_TRACEPOINTS(B) \
410 for (B = breakpoint_chain; B; B = B->next) \
411 if (is_tracepoint (B))
413 /* Chains of all breakpoints defined. */
415 struct breakpoint
*breakpoint_chain
;
417 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
419 static struct bp_location
**bp_location
;
421 /* Number of elements of BP_LOCATION. */
423 static unsigned bp_location_count
;
425 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
426 ADDRESS for the current elements of BP_LOCATION which get a valid
427 result from bp_location_has_shadow. You can use it for roughly
428 limiting the subrange of BP_LOCATION to scan for shadow bytes for
429 an address you need to read. */
431 static CORE_ADDR bp_location_placed_address_before_address_max
;
433 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
434 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
435 BP_LOCATION which get a valid result from bp_location_has_shadow.
436 You can use it for roughly limiting the subrange of BP_LOCATION to
437 scan for shadow bytes for an address you need to read. */
439 static CORE_ADDR bp_location_shadow_len_after_address_max
;
441 /* The locations that no longer correspond to any breakpoint, unlinked
442 from bp_location array, but for which a hit may still be reported
444 VEC(bp_location_p
) *moribund_locations
= NULL
;
446 /* Number of last breakpoint made. */
448 static int breakpoint_count
;
450 /* The value of `breakpoint_count' before the last command that
451 created breakpoints. If the last (break-like) command created more
452 than one breakpoint, then the difference between BREAKPOINT_COUNT
453 and PREV_BREAKPOINT_COUNT is more than one. */
454 static int prev_breakpoint_count
;
456 /* Number of last tracepoint made. */
458 static int tracepoint_count
;
460 static struct cmd_list_element
*breakpoint_set_cmdlist
;
461 static struct cmd_list_element
*breakpoint_show_cmdlist
;
462 struct cmd_list_element
*save_cmdlist
;
464 /* Return whether a breakpoint is an active enabled breakpoint. */
466 breakpoint_enabled (struct breakpoint
*b
)
468 return (b
->enable_state
== bp_enabled
);
471 /* Set breakpoint count to NUM. */
474 set_breakpoint_count (int num
)
476 prev_breakpoint_count
= breakpoint_count
;
477 breakpoint_count
= num
;
478 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
481 /* Used by `start_rbreak_breakpoints' below, to record the current
482 breakpoint count before "rbreak" creates any breakpoint. */
483 static int rbreak_start_breakpoint_count
;
485 /* Called at the start an "rbreak" command to record the first
489 start_rbreak_breakpoints (void)
491 rbreak_start_breakpoint_count
= breakpoint_count
;
494 /* Called at the end of an "rbreak" command to record the last
498 end_rbreak_breakpoints (void)
500 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
503 /* Used in run_command to zero the hit count when a new run starts. */
506 clear_breakpoint_hit_counts (void)
508 struct breakpoint
*b
;
514 /* Allocate a new counted_command_line with reference count of 1.
515 The new structure owns COMMANDS. */
517 static struct counted_command_line
*
518 alloc_counted_command_line (struct command_line
*commands
)
520 struct counted_command_line
*result
521 = xmalloc (sizeof (struct counted_command_line
));
524 result
->commands
= commands
;
528 /* Increment reference count. This does nothing if CMD is NULL. */
531 incref_counted_command_line (struct counted_command_line
*cmd
)
537 /* Decrement reference count. If the reference count reaches 0,
538 destroy the counted_command_line. Sets *CMDP to NULL. This does
539 nothing if *CMDP is NULL. */
542 decref_counted_command_line (struct counted_command_line
**cmdp
)
546 if (--(*cmdp
)->refc
== 0)
548 free_command_lines (&(*cmdp
)->commands
);
555 /* A cleanup function that calls decref_counted_command_line. */
558 do_cleanup_counted_command_line (void *arg
)
560 decref_counted_command_line (arg
);
563 /* Create a cleanup that calls decref_counted_command_line on the
566 static struct cleanup
*
567 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
569 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
572 /* Default address, symtab and line to put a breakpoint at
573 for "break" command with no arg.
574 If default_breakpoint_valid is zero, the other three are
575 not valid, and "break" with no arg is an error.
577 This set by print_stack_frame, which calls set_default_breakpoint. */
579 int default_breakpoint_valid
;
580 CORE_ADDR default_breakpoint_address
;
581 struct symtab
*default_breakpoint_symtab
;
582 int default_breakpoint_line
;
583 struct program_space
*default_breakpoint_pspace
;
586 /* Return the breakpoint with the specified number, or NULL
587 if the number does not refer to an existing breakpoint. */
590 get_breakpoint (int num
)
592 struct breakpoint
*b
;
595 if (b
->number
== num
)
604 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
607 struct bp_location
*loc
= b
->loc
;
609 for (; loc
; loc
= loc
->next
)
614 xfree (b
->cond_string
);
615 b
->cond_string
= NULL
;
622 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
628 /* I don't know if it matters whether this is the string the user
629 typed in or the decompiled expression. */
630 b
->cond_string
= xstrdup (arg
);
631 b
->condition_not_parsed
= 0;
633 if (is_watchpoint (b
))
635 innermost_block
= NULL
;
637 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
639 error (_("Junk at end of expression"));
640 b
->cond_exp_valid_block
= innermost_block
;
644 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
648 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
650 error (_("Junk at end of expression"));
654 breakpoints_changed ();
655 observer_notify_breakpoint_modified (b
);
658 /* condition N EXP -- set break condition of breakpoint N to EXP. */
661 condition_command (char *arg
, int from_tty
)
663 struct breakpoint
*b
;
668 error_no_arg (_("breakpoint number"));
671 bnum
= get_number (&p
);
673 error (_("Bad breakpoint argument: '%s'"), arg
);
676 if (b
->number
== bnum
)
678 /* Check if this breakpoint has a Python object assigned to
679 it, and if it has a definition of the "stop"
680 method. This method and conditions entered into GDB from
681 the CLI are mutually exclusive. */
683 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
684 error (_("Cannot set a condition where a Python 'stop' "
685 "method has been defined in the breakpoint."));
686 set_breakpoint_condition (b
, p
, from_tty
);
690 error (_("No breakpoint number %d."), bnum
);
693 /* Check that COMMAND do not contain commands that are suitable
694 only for tracepoints and not suitable for ordinary breakpoints.
695 Throw if any such commands is found. */
698 check_no_tracepoint_commands (struct command_line
*commands
)
700 struct command_line
*c
;
702 for (c
= commands
; c
; c
= c
->next
)
706 if (c
->control_type
== while_stepping_control
)
707 error (_("The 'while-stepping' command can "
708 "only be used for tracepoints"));
710 for (i
= 0; i
< c
->body_count
; ++i
)
711 check_no_tracepoint_commands ((c
->body_list
)[i
]);
713 /* Not that command parsing removes leading whitespace and comment
714 lines and also empty lines. So, we only need to check for
716 if (strstr (c
->line
, "collect ") == c
->line
)
717 error (_("The 'collect' command can only be used for tracepoints"));
719 if (strstr (c
->line
, "teval ") == c
->line
)
720 error (_("The 'teval' command can only be used for tracepoints"));
724 /* Encapsulate tests for different types of tracepoints. */
727 is_tracepoint (const struct breakpoint
*b
)
729 return (b
->type
== bp_tracepoint
730 || b
->type
== bp_fast_tracepoint
731 || b
->type
== bp_static_tracepoint
);
734 /* A helper function that validates that COMMANDS are valid for a
735 breakpoint. This function will throw an exception if a problem is
739 validate_commands_for_breakpoint (struct breakpoint
*b
,
740 struct command_line
*commands
)
742 if (is_tracepoint (b
))
744 /* We need to verify that each top-level element of commands is
745 valid for tracepoints, that there's at most one
746 while-stepping element, and that while-stepping's body has
747 valid tracing commands excluding nested while-stepping. */
748 struct command_line
*c
;
749 struct command_line
*while_stepping
= 0;
750 for (c
= commands
; c
; c
= c
->next
)
752 if (c
->control_type
== while_stepping_control
)
754 if (b
->type
== bp_fast_tracepoint
)
755 error (_("The 'while-stepping' command "
756 "cannot be used for fast tracepoint"));
757 else if (b
->type
== bp_static_tracepoint
)
758 error (_("The 'while-stepping' command "
759 "cannot be used for static tracepoint"));
762 error (_("The 'while-stepping' command "
763 "can be used only once"));
770 struct command_line
*c2
;
772 gdb_assert (while_stepping
->body_count
== 1);
773 c2
= while_stepping
->body_list
[0];
774 for (; c2
; c2
= c2
->next
)
776 if (c2
->control_type
== while_stepping_control
)
777 error (_("The 'while-stepping' command cannot be nested"));
783 check_no_tracepoint_commands (commands
);
787 /* Return a vector of all the static tracepoints set at ADDR. The
788 caller is responsible for releasing the vector. */
791 static_tracepoints_here (CORE_ADDR addr
)
793 struct breakpoint
*b
;
794 VEC(breakpoint_p
) *found
= 0;
795 struct bp_location
*loc
;
798 if (b
->type
== bp_static_tracepoint
)
800 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
801 if (loc
->address
== addr
)
802 VEC_safe_push(breakpoint_p
, found
, b
);
808 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
809 validate that only allowed commands are included. */
812 breakpoint_set_commands (struct breakpoint
*b
,
813 struct command_line
*commands
)
815 validate_commands_for_breakpoint (b
, commands
);
817 decref_counted_command_line (&b
->commands
);
818 b
->commands
= alloc_counted_command_line (commands
);
819 breakpoints_changed ();
820 observer_notify_breakpoint_modified (b
);
823 /* Set the internal `silent' flag on the breakpoint. Note that this
824 is not the same as the "silent" that may appear in the breakpoint's
828 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
830 int old_silent
= b
->silent
;
833 if (old_silent
!= silent
)
834 observer_notify_breakpoint_modified (b
);
837 /* Set the thread for this breakpoint. If THREAD is -1, make the
838 breakpoint work for any thread. */
841 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
843 int old_thread
= b
->thread
;
846 if (old_thread
!= thread
)
847 observer_notify_breakpoint_modified (b
);
850 /* Set the task for this breakpoint. If TASK is 0, make the
851 breakpoint work for any task. */
854 breakpoint_set_task (struct breakpoint
*b
, int task
)
856 int old_task
= b
->task
;
859 if (old_task
!= task
)
860 observer_notify_breakpoint_modified (b
);
864 check_tracepoint_command (char *line
, void *closure
)
866 struct breakpoint
*b
= closure
;
868 validate_actionline (&line
, b
);
871 /* A structure used to pass information through
872 map_breakpoint_numbers. */
876 /* True if the command was typed at a tty. */
879 /* The breakpoint range spec. */
882 /* Non-NULL if the body of the commands are being read from this
883 already-parsed command. */
884 struct command_line
*control
;
886 /* The command lines read from the user, or NULL if they have not
888 struct counted_command_line
*cmd
;
891 /* A callback for map_breakpoint_numbers that sets the commands for
895 do_map_commands_command (struct breakpoint
*b
, void *data
)
897 struct commands_info
*info
= data
;
899 if (info
->cmd
== NULL
)
901 struct command_line
*l
;
903 if (info
->control
!= NULL
)
904 l
= copy_command_lines (info
->control
->body_list
[0]);
907 struct cleanup
*old_chain
;
910 str
= xstrprintf (_("Type commands for breakpoint(s) "
911 "%s, one per line."),
914 old_chain
= make_cleanup (xfree
, str
);
916 l
= read_command_lines (str
,
919 ? check_tracepoint_command
: 0),
922 do_cleanups (old_chain
);
925 info
->cmd
= alloc_counted_command_line (l
);
928 /* If a breakpoint was on the list more than once, we don't need to
930 if (b
->commands
!= info
->cmd
)
932 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
933 incref_counted_command_line (info
->cmd
);
934 decref_counted_command_line (&b
->commands
);
935 b
->commands
= info
->cmd
;
936 breakpoints_changed ();
937 observer_notify_breakpoint_modified (b
);
942 commands_command_1 (char *arg
, int from_tty
,
943 struct command_line
*control
)
945 struct cleanup
*cleanups
;
946 struct commands_info info
;
948 info
.from_tty
= from_tty
;
949 info
.control
= control
;
951 /* If we read command lines from the user, then `info' will hold an
952 extra reference to the commands that we must clean up. */
953 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
955 if (arg
== NULL
|| !*arg
)
957 if (breakpoint_count
- prev_breakpoint_count
> 1)
958 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
960 else if (breakpoint_count
> 0)
961 arg
= xstrprintf ("%d", breakpoint_count
);
964 /* So that we don't try to free the incoming non-NULL
965 argument in the cleanup below. Mapping breakpoint
966 numbers will fail in this case. */
971 /* The command loop has some static state, so we need to preserve
976 make_cleanup (xfree
, arg
);
980 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
982 if (info
.cmd
== NULL
)
983 error (_("No breakpoints specified."));
985 do_cleanups (cleanups
);
989 commands_command (char *arg
, int from_tty
)
991 commands_command_1 (arg
, from_tty
, NULL
);
994 /* Like commands_command, but instead of reading the commands from
995 input stream, takes them from an already parsed command structure.
997 This is used by cli-script.c to DTRT with breakpoint commands
998 that are part of if and while bodies. */
999 enum command_control_type
1000 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1002 commands_command_1 (arg
, 0, cmd
);
1003 return simple_control
;
1006 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1009 bp_location_has_shadow (struct bp_location
*bl
)
1011 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1015 if (bl
->target_info
.shadow_len
== 0)
1016 /* BL isn't valid, or doesn't shadow memory. */
1021 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1022 by replacing any memory breakpoints with their shadowed contents.
1024 The range of shadowed area by each bp_location is:
1025 bl->address - bp_location_placed_address_before_address_max
1026 up to bl->address + bp_location_shadow_len_after_address_max
1027 The range we were requested to resolve shadows for is:
1028 memaddr ... memaddr + len
1029 Thus the safe cutoff boundaries for performance optimization are
1030 memaddr + len <= (bl->address
1031 - bp_location_placed_address_before_address_max)
1033 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1036 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1038 /* Left boundary, right boundary and median element of our binary
1040 unsigned bc_l
, bc_r
, bc
;
1042 /* Find BC_L which is a leftmost element which may affect BUF
1043 content. It is safe to report lower value but a failure to
1044 report higher one. */
1047 bc_r
= bp_location_count
;
1048 while (bc_l
+ 1 < bc_r
)
1050 struct bp_location
*bl
;
1052 bc
= (bc_l
+ bc_r
) / 2;
1053 bl
= bp_location
[bc
];
1055 /* Check first BL->ADDRESS will not overflow due to the added
1056 constant. Then advance the left boundary only if we are sure
1057 the BC element can in no way affect the BUF content (MEMADDR
1058 to MEMADDR + LEN range).
1060 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1061 offset so that we cannot miss a breakpoint with its shadow
1062 range tail still reaching MEMADDR. */
1064 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1066 && (bl
->address
+ bp_location_shadow_len_after_address_max
1073 /* Due to the binary search above, we need to make sure we pick the
1074 first location that's at BC_L's address. E.g., if there are
1075 multiple locations at the same address, BC_L may end up pointing
1076 at a duplicate location, and miss the "master"/"inserted"
1077 location. Say, given locations L1, L2 and L3 at addresses A and
1080 L1@A, L2@A, L3@B, ...
1082 BC_L could end up pointing at location L2, while the "master"
1083 location could be L1. Since the `loc->inserted' flag is only set
1084 on "master" locations, we'd forget to restore the shadow of L1
1087 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1090 /* Now do full processing of the found relevant range of elements. */
1092 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1094 struct bp_location
*bl
= bp_location
[bc
];
1095 CORE_ADDR bp_addr
= 0;
1099 /* bp_location array has BL->OWNER always non-NULL. */
1100 if (bl
->owner
->type
== bp_none
)
1101 warning (_("reading through apparently deleted breakpoint #%d?"),
1104 /* Performance optimization: any further element can no longer affect BUF
1107 if (bl
->address
>= bp_location_placed_address_before_address_max
1108 && memaddr
+ len
<= (bl
->address
1109 - bp_location_placed_address_before_address_max
))
1112 if (!bp_location_has_shadow (bl
))
1114 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1115 current_program_space
->aspace
, 0))
1118 /* Addresses and length of the part of the breakpoint that
1120 bp_addr
= bl
->target_info
.placed_address
;
1121 bp_size
= bl
->target_info
.shadow_len
;
1123 if (bp_addr
+ bp_size
<= memaddr
)
1124 /* The breakpoint is entirely before the chunk of memory we
1128 if (bp_addr
>= memaddr
+ len
)
1129 /* The breakpoint is entirely after the chunk of memory we are
1133 /* Offset within shadow_contents. */
1134 if (bp_addr
< memaddr
)
1136 /* Only copy the second part of the breakpoint. */
1137 bp_size
-= memaddr
- bp_addr
;
1138 bptoffset
= memaddr
- bp_addr
;
1142 if (bp_addr
+ bp_size
> memaddr
+ len
)
1144 /* Only copy the first part of the breakpoint. */
1145 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1148 memcpy (buf
+ bp_addr
- memaddr
,
1149 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1154 /* Return true if BPT is of any hardware watchpoint kind. */
1157 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1159 return (bpt
->type
== bp_hardware_watchpoint
1160 || bpt
->type
== bp_read_watchpoint
1161 || bpt
->type
== bp_access_watchpoint
);
1164 /* Return true if BPT is of any watchpoint kind, hardware or
1168 is_watchpoint (const struct breakpoint
*bpt
)
1170 return (is_hardware_watchpoint (bpt
)
1171 || bpt
->type
== bp_watchpoint
);
1174 /* Assuming that B is a watchpoint: returns true if the current thread
1175 and its running state are safe to evaluate or update watchpoint B.
1176 Watchpoints on local expressions need to be evaluated in the
1177 context of the thread that was current when the watchpoint was
1178 created, and, that thread needs to be stopped to be able to select
1179 the correct frame context. Watchpoints on global expressions can
1180 be evaluated on any thread, and in any state. It is presently left
1181 to the target allowing memory accesses when threads are
1185 watchpoint_in_thread_scope (struct breakpoint
*b
)
1187 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1188 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1189 && !is_executing (inferior_ptid
)));
1192 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1193 associated bp_watchpoint_scope breakpoint. */
1196 watchpoint_del_at_next_stop (struct breakpoint
*b
)
1198 gdb_assert (is_watchpoint (b
));
1200 if (b
->related_breakpoint
!= b
)
1202 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1203 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1204 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1205 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1206 b
->related_breakpoint
= b
;
1208 b
->disposition
= disp_del_at_next_stop
;
1211 /* Assuming that B is a watchpoint:
1212 - Reparse watchpoint expression, if REPARSE is non-zero
1213 - Evaluate expression and store the result in B->val
1214 - Evaluate the condition if there is one, and store the result
1216 - Update the list of values that must be watched in B->loc.
1218 If the watchpoint disposition is disp_del_at_next_stop, then do
1219 nothing. If this is local watchpoint that is out of scope, delete
1222 Even with `set breakpoint always-inserted on' the watchpoints are
1223 removed + inserted on each stop here. Normal breakpoints must
1224 never be removed because they might be missed by a running thread
1225 when debugging in non-stop mode. On the other hand, hardware
1226 watchpoints (is_hardware_watchpoint; processed here) are specific
1227 to each LWP since they are stored in each LWP's hardware debug
1228 registers. Therefore, such LWP must be stopped first in order to
1229 be able to modify its hardware watchpoints.
1231 Hardware watchpoints must be reset exactly once after being
1232 presented to the user. It cannot be done sooner, because it would
1233 reset the data used to present the watchpoint hit to the user. And
1234 it must not be done later because it could display the same single
1235 watchpoint hit during multiple GDB stops. Note that the latter is
1236 relevant only to the hardware watchpoint types bp_read_watchpoint
1237 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1238 not user-visible - its hit is suppressed if the memory content has
1241 The following constraints influence the location where we can reset
1242 hardware watchpoints:
1244 * target_stopped_by_watchpoint and target_stopped_data_address are
1245 called several times when GDB stops.
1248 * Multiple hardware watchpoints can be hit at the same time,
1249 causing GDB to stop. GDB only presents one hardware watchpoint
1250 hit at a time as the reason for stopping, and all the other hits
1251 are presented later, one after the other, each time the user
1252 requests the execution to be resumed. Execution is not resumed
1253 for the threads still having pending hit event stored in
1254 LWP_INFO->STATUS. While the watchpoint is already removed from
1255 the inferior on the first stop the thread hit event is kept being
1256 reported from its cached value by linux_nat_stopped_data_address
1257 until the real thread resume happens after the watchpoint gets
1258 presented and thus its LWP_INFO->STATUS gets reset.
1260 Therefore the hardware watchpoint hit can get safely reset on the
1261 watchpoint removal from inferior. */
1264 update_watchpoint (struct breakpoint
*b
, int reparse
)
1266 int within_current_scope
;
1267 struct frame_id saved_frame_id
;
1270 gdb_assert (is_watchpoint (b
));
1272 /* If this is a local watchpoint, we only want to check if the
1273 watchpoint frame is in scope if the current thread is the thread
1274 that was used to create the watchpoint. */
1275 if (!watchpoint_in_thread_scope (b
))
1278 if (b
->disposition
== disp_del_at_next_stop
)
1283 /* Determine if the watchpoint is within scope. */
1284 if (b
->exp_valid_block
== NULL
)
1285 within_current_scope
= 1;
1288 struct frame_info
*fi
= get_current_frame ();
1289 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1290 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1292 /* If we're in a function epilogue, unwinding may not work
1293 properly, so do not attempt to recreate locations at this
1294 point. See similar comments in watchpoint_check. */
1295 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1298 /* Save the current frame's ID so we can restore it after
1299 evaluating the watchpoint expression on its own frame. */
1300 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1301 took a frame parameter, so that we didn't have to change the
1304 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1306 fi
= frame_find_by_id (b
->watchpoint_frame
);
1307 within_current_scope
= (fi
!= NULL
);
1308 if (within_current_scope
)
1312 /* We don't free locations. They are stored in the bp_location array
1313 and update_global_location_list will eventually delete them and
1314 remove breakpoints if needed. */
1317 if (within_current_scope
&& reparse
)
1326 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1327 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1328 /* If the meaning of expression itself changed, the old value is
1329 no longer relevant. We don't want to report a watchpoint hit
1330 to the user when the old value and the new value may actually
1331 be completely different objects. */
1332 value_free (b
->val
);
1336 /* Note that unlike with breakpoints, the watchpoint's condition
1337 expression is stored in the breakpoint object, not in the
1338 locations (re)created below. */
1339 if (b
->cond_string
!= NULL
)
1341 if (b
->cond_exp
!= NULL
)
1343 xfree (b
->cond_exp
);
1348 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1352 /* If we failed to parse the expression, for example because
1353 it refers to a global variable in a not-yet-loaded shared library,
1354 don't try to insert watchpoint. We don't automatically delete
1355 such watchpoint, though, since failure to parse expression
1356 is different from out-of-scope watchpoint. */
1357 if ( !target_has_execution
)
1359 /* Without execution, memory can't change. No use to try and
1360 set watchpoint locations. The watchpoint will be reset when
1361 the target gains execution, through breakpoint_re_set. */
1363 else if (within_current_scope
&& b
->exp
)
1366 struct value
*val_chain
, *v
, *result
, *next
;
1367 struct program_space
*frame_pspace
;
1369 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1371 /* Avoid setting b->val if it's already set. The meaning of
1372 b->val is 'the last value' user saw, and we should update
1373 it only if we reported that last value to user. As it
1374 happens, the code that reports it updates b->val directly.
1375 We don't keep track of the memory value for masked
1377 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1383 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1385 /* Look at each value on the value chain. */
1386 for (v
= val_chain
; v
; v
= value_next (v
))
1388 /* If it's a memory location, and GDB actually needed
1389 its contents to evaluate the expression, then we
1390 must watch it. If the first value returned is
1391 still lazy, that means an error occurred reading it;
1392 watch it anyway in case it becomes readable. */
1393 if (VALUE_LVAL (v
) == lval_memory
1394 && (v
== val_chain
|| ! value_lazy (v
)))
1396 struct type
*vtype
= check_typedef (value_type (v
));
1398 /* We only watch structs and arrays if user asked
1399 for it explicitly, never if they just happen to
1400 appear in the middle of some value chain. */
1402 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1403 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1407 struct bp_location
*loc
, **tmp
;
1409 addr
= value_address (v
);
1410 len
= TYPE_LENGTH (value_type (v
));
1412 if (b
->type
== bp_read_watchpoint
)
1414 else if (b
->type
== bp_access_watchpoint
)
1417 loc
= allocate_bp_location (b
);
1418 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1421 loc
->gdbarch
= get_type_arch (value_type (v
));
1423 loc
->pspace
= frame_pspace
;
1424 loc
->address
= addr
;
1426 loc
->watchpoint_type
= type
;
1431 /* Change the type of breakpoint between hardware assisted or
1432 an ordinary watchpoint depending on the hardware support
1433 and free hardware slots. REPARSE is set when the inferior
1438 enum bp_loc_type loc_type
;
1439 struct bp_location
*bl
;
1441 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1445 int i
, target_resources_ok
, other_type_used
;
1447 /* Use an exact watchpoint when there's only one memory region to be
1448 watched, and only one debug register is needed to watch it. */
1449 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1451 /* We need to determine how many resources are already
1452 used for all other hardware watchpoints plus this one
1453 to see if we still have enough resources to also fit
1454 this watchpoint in as well. To guarantee the
1455 hw_watchpoint_used_count call below counts this
1456 watchpoint, make sure that it is marked as a hardware
1458 if (b
->type
== bp_watchpoint
)
1459 b
->type
= bp_hardware_watchpoint
;
1461 i
= hw_watchpoint_used_count (b
->type
, &other_type_used
);
1462 target_resources_ok
= target_can_use_hardware_watchpoint
1463 (b
->type
, i
, other_type_used
);
1464 if (target_resources_ok
<= 0)
1466 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1468 if (target_resources_ok
== 0 && !sw_mode
)
1469 error (_("Target does not support this type of "
1470 "hardware watchpoint."));
1471 else if (target_resources_ok
< 0 && !sw_mode
)
1472 error (_("There are not enough available hardware "
1473 "resources for this watchpoint."));
1475 b
->type
= bp_watchpoint
;
1478 else if (!b
->ops
->works_in_software_mode (b
))
1479 error (_("Expression cannot be implemented with "
1480 "read/access watchpoint."));
1482 b
->type
= bp_watchpoint
;
1484 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1485 : bp_loc_hardware_watchpoint
);
1486 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1487 bl
->loc_type
= loc_type
;
1490 for (v
= val_chain
; v
; v
= next
)
1492 next
= value_next (v
);
1497 /* If a software watchpoint is not watching any memory, then the
1498 above left it without any location set up. But,
1499 bpstat_stop_status requires a location to be able to report
1500 stops, so make sure there's at least a dummy one. */
1501 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1503 b
->loc
= allocate_bp_location (b
);
1504 b
->loc
->pspace
= frame_pspace
;
1505 b
->loc
->address
= -1;
1506 b
->loc
->length
= -1;
1507 b
->loc
->watchpoint_type
= -1;
1510 else if (!within_current_scope
)
1512 printf_filtered (_("\
1513 Watchpoint %d deleted because the program has left the block\n\
1514 in which its expression is valid.\n"),
1516 watchpoint_del_at_next_stop (b
);
1519 /* Restore the selected frame. */
1521 select_frame (frame_find_by_id (saved_frame_id
));
1525 /* Returns 1 iff breakpoint location should be
1526 inserted in the inferior. */
1528 should_be_inserted (struct bp_location
*bl
)
1530 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1533 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1536 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1539 /* This is set for example, when we're attached to the parent of a
1540 vfork, and have detached from the child. The child is running
1541 free, and we expect it to do an exec or exit, at which point the
1542 OS makes the parent schedulable again (and the target reports
1543 that the vfork is done). Until the child is done with the shared
1544 memory region, do not insert breakpoints in the parent, otherwise
1545 the child could still trip on the parent's breakpoints. Since
1546 the parent is blocked anyway, it won't miss any breakpoint. */
1547 if (bl
->pspace
->breakpoints_not_allowed
)
1550 /* Tracepoints are inserted by the target at a time of its choosing,
1552 if (is_tracepoint (bl
->owner
))
1558 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1559 location. Any error messages are printed to TMP_ERROR_STREAM; and
1560 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1562 NOTE drow/2003-09-09: This routine could be broken down to an
1563 object-style method for each breakpoint or catchpoint type. */
1565 insert_bp_location (struct bp_location
*bl
,
1566 struct ui_file
*tmp_error_stream
,
1567 int *disabled_breaks
,
1568 int *hw_breakpoint_error
)
1572 if (!should_be_inserted (bl
) || bl
->inserted
)
1575 /* Initialize the target-specific information. */
1576 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1577 bl
->target_info
.placed_address
= bl
->address
;
1578 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1579 bl
->target_info
.length
= bl
->length
;
1581 if (bl
->loc_type
== bp_loc_software_breakpoint
1582 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1584 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1586 /* If the explicitly specified breakpoint type
1587 is not hardware breakpoint, check the memory map to see
1588 if the breakpoint address is in read only memory or not.
1590 Two important cases are:
1591 - location type is not hardware breakpoint, memory
1592 is readonly. We change the type of the location to
1593 hardware breakpoint.
1594 - location type is hardware breakpoint, memory is
1595 read-write. This means we've previously made the
1596 location hardware one, but then the memory map changed,
1599 When breakpoints are removed, remove_breakpoints will use
1600 location types we've just set here, the only possible
1601 problem is that memory map has changed during running
1602 program, but it's not going to work anyway with current
1604 struct mem_region
*mr
1605 = lookup_mem_region (bl
->target_info
.placed_address
);
1609 if (automatic_hardware_breakpoints
)
1611 enum bp_loc_type new_type
;
1613 if (mr
->attrib
.mode
!= MEM_RW
)
1614 new_type
= bp_loc_hardware_breakpoint
;
1616 new_type
= bp_loc_software_breakpoint
;
1618 if (new_type
!= bl
->loc_type
)
1620 static int said
= 0;
1622 bl
->loc_type
= new_type
;
1625 fprintf_filtered (gdb_stdout
,
1626 _("Note: automatically using "
1627 "hardware breakpoints for "
1628 "read-only addresses.\n"));
1633 else if (bl
->loc_type
== bp_loc_software_breakpoint
1634 && mr
->attrib
.mode
!= MEM_RW
)
1635 warning (_("cannot set software breakpoint "
1636 "at readonly address %s"),
1637 paddress (bl
->gdbarch
, bl
->address
));
1641 /* First check to see if we have to handle an overlay. */
1642 if (overlay_debugging
== ovly_off
1643 || bl
->section
== NULL
1644 || !(section_is_overlay (bl
->section
)))
1646 /* No overlay handling: just set the breakpoint. */
1648 val
= bl
->owner
->ops
->insert_location (bl
);
1652 /* This breakpoint is in an overlay section.
1653 Shall we set a breakpoint at the LMA? */
1654 if (!overlay_events_enabled
)
1656 /* Yes -- overlay event support is not active,
1657 so we must try to set a breakpoint at the LMA.
1658 This will not work for a hardware breakpoint. */
1659 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1660 warning (_("hardware breakpoint %d not supported in overlay!"),
1664 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1666 /* Set a software (trap) breakpoint at the LMA. */
1667 bl
->overlay_target_info
= bl
->target_info
;
1668 bl
->overlay_target_info
.placed_address
= addr
;
1669 val
= target_insert_breakpoint (bl
->gdbarch
,
1670 &bl
->overlay_target_info
);
1672 fprintf_unfiltered (tmp_error_stream
,
1673 "Overlay breakpoint %d "
1674 "failed: in ROM?\n",
1678 /* Shall we set a breakpoint at the VMA? */
1679 if (section_is_mapped (bl
->section
))
1681 /* Yes. This overlay section is mapped into memory. */
1682 val
= bl
->owner
->ops
->insert_location (bl
);
1686 /* No. This breakpoint will not be inserted.
1687 No error, but do not mark the bp as 'inserted'. */
1694 /* Can't set the breakpoint. */
1695 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1697 /* See also: disable_breakpoints_in_shlibs. */
1699 bl
->shlib_disabled
= 1;
1700 observer_notify_breakpoint_modified (bl
->owner
);
1701 if (!*disabled_breaks
)
1703 fprintf_unfiltered (tmp_error_stream
,
1704 "Cannot insert breakpoint %d.\n",
1706 fprintf_unfiltered (tmp_error_stream
,
1707 "Temporarily disabling shared "
1708 "library breakpoints:\n");
1710 *disabled_breaks
= 1;
1711 fprintf_unfiltered (tmp_error_stream
,
1712 "breakpoint #%d\n", bl
->owner
->number
);
1716 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1718 *hw_breakpoint_error
= 1;
1719 fprintf_unfiltered (tmp_error_stream
,
1720 "Cannot insert hardware "
1726 fprintf_unfiltered (tmp_error_stream
,
1727 "Cannot insert breakpoint %d.\n",
1729 fprintf_filtered (tmp_error_stream
,
1730 "Error accessing memory address ");
1731 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1733 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1734 safe_strerror (val
));
1745 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1746 /* NOTE drow/2003-09-08: This state only exists for removing
1747 watchpoints. It's not clear that it's necessary... */
1748 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1750 gdb_assert (bl
->owner
->ops
!= NULL
1751 && bl
->owner
->ops
->insert_location
!= NULL
);
1753 val
= bl
->owner
->ops
->insert_location (bl
);
1755 /* If trying to set a read-watchpoint, and it turns out it's not
1756 supported, try emulating one with an access watchpoint. */
1757 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1759 struct bp_location
*loc
, **loc_temp
;
1761 /* But don't try to insert it, if there's already another
1762 hw_access location that would be considered a duplicate
1764 ALL_BP_LOCATIONS (loc
, loc_temp
)
1766 && loc
->watchpoint_type
== hw_access
1767 && watchpoint_locations_match (bl
, loc
))
1771 bl
->target_info
= loc
->target_info
;
1772 bl
->watchpoint_type
= hw_access
;
1779 bl
->watchpoint_type
= hw_access
;
1780 val
= bl
->owner
->ops
->insert_location (bl
);
1783 /* Back to the original value. */
1784 bl
->watchpoint_type
= hw_read
;
1788 bl
->inserted
= (val
== 0);
1791 else if (bl
->owner
->type
== bp_catchpoint
)
1793 gdb_assert (bl
->owner
->ops
!= NULL
1794 && bl
->owner
->ops
->insert_location
!= NULL
);
1796 val
= bl
->owner
->ops
->insert_location (bl
);
1799 bl
->owner
->enable_state
= bp_disabled
;
1803 Error inserting catchpoint %d: Your system does not support this type\n\
1804 of catchpoint."), bl
->owner
->number
);
1806 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1809 bl
->inserted
= (val
== 0);
1811 /* We've already printed an error message if there was a problem
1812 inserting this catchpoint, and we've disabled the catchpoint,
1813 so just return success. */
1820 /* This function is called when program space PSPACE is about to be
1821 deleted. It takes care of updating breakpoints to not reference
1825 breakpoint_program_space_exit (struct program_space
*pspace
)
1827 struct breakpoint
*b
, *b_temp
;
1828 struct bp_location
*loc
, **loc_temp
;
1830 /* Remove any breakpoint that was set through this program space. */
1831 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1833 if (b
->pspace
== pspace
)
1834 delete_breakpoint (b
);
1837 /* Breakpoints set through other program spaces could have locations
1838 bound to PSPACE as well. Remove those. */
1839 ALL_BP_LOCATIONS (loc
, loc_temp
)
1841 struct bp_location
*tmp
;
1843 if (loc
->pspace
== pspace
)
1845 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1846 if (loc
->owner
->loc
== loc
)
1847 loc
->owner
->loc
= loc
->next
;
1849 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1850 if (tmp
->next
== loc
)
1852 tmp
->next
= loc
->next
;
1858 /* Now update the global location list to permanently delete the
1859 removed locations above. */
1860 update_global_location_list (0);
1863 /* Make sure all breakpoints are inserted in inferior.
1864 Throws exception on any error.
1865 A breakpoint that is already inserted won't be inserted
1866 again, so calling this function twice is safe. */
1868 insert_breakpoints (void)
1870 struct breakpoint
*bpt
;
1872 ALL_BREAKPOINTS (bpt
)
1873 if (is_hardware_watchpoint (bpt
))
1874 update_watchpoint (bpt
, 0 /* don't reparse. */);
1876 update_global_location_list (1);
1878 /* update_global_location_list does not insert breakpoints when
1879 always_inserted_mode is not enabled. Explicitly insert them
1881 if (!breakpoints_always_inserted_mode ())
1882 insert_breakpoint_locations ();
1885 /* insert_breakpoints is used when starting or continuing the program.
1886 remove_breakpoints is used when the program stops.
1887 Both return zero if successful,
1888 or an `errno' value if could not write the inferior. */
1891 insert_breakpoint_locations (void)
1893 struct breakpoint
*bpt
;
1894 struct bp_location
*bl
, **blp_tmp
;
1897 int disabled_breaks
= 0;
1898 int hw_breakpoint_error
= 0;
1900 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1901 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1903 /* Explicitly mark the warning -- this will only be printed if
1904 there was an error. */
1905 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1907 save_current_space_and_thread ();
1909 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1911 if (!should_be_inserted (bl
) || bl
->inserted
)
1914 /* There is no point inserting thread-specific breakpoints if
1915 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1916 has BL->OWNER always non-NULL. */
1917 if (bl
->owner
->thread
!= -1
1918 && !valid_thread_id (bl
->owner
->thread
))
1921 switch_to_program_space_and_thread (bl
->pspace
);
1923 /* For targets that support global breakpoints, there's no need
1924 to select an inferior to insert breakpoint to. In fact, even
1925 if we aren't attached to any process yet, we should still
1926 insert breakpoints. */
1927 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1928 && ptid_equal (inferior_ptid
, null_ptid
))
1931 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1932 &hw_breakpoint_error
);
1937 /* If we failed to insert all locations of a watchpoint, remove
1938 them, as half-inserted watchpoint is of limited use. */
1939 ALL_BREAKPOINTS (bpt
)
1941 int some_failed
= 0;
1942 struct bp_location
*loc
;
1944 if (!is_hardware_watchpoint (bpt
))
1947 if (!breakpoint_enabled (bpt
))
1950 if (bpt
->disposition
== disp_del_at_next_stop
)
1953 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1954 if (!loc
->inserted
&& should_be_inserted (loc
))
1961 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1963 remove_breakpoint (loc
, mark_uninserted
);
1965 hw_breakpoint_error
= 1;
1966 fprintf_unfiltered (tmp_error_stream
,
1967 "Could not insert hardware watchpoint %d.\n",
1975 /* If a hardware breakpoint or watchpoint was inserted, add a
1976 message about possibly exhausted resources. */
1977 if (hw_breakpoint_error
)
1979 fprintf_unfiltered (tmp_error_stream
,
1980 "Could not insert hardware breakpoints:\n\
1981 You may have requested too many hardware breakpoints/watchpoints.\n");
1983 target_terminal_ours_for_output ();
1984 error_stream (tmp_error_stream
);
1987 do_cleanups (cleanups
);
1991 remove_breakpoints (void)
1993 struct bp_location
*bl
, **blp_tmp
;
1996 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1999 val
|= remove_breakpoint (bl
, mark_uninserted
);
2004 /* Remove breakpoints of process PID. */
2007 remove_breakpoints_pid (int pid
)
2009 struct bp_location
*bl
, **blp_tmp
;
2011 struct inferior
*inf
= find_inferior_pid (pid
);
2013 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2015 if (bl
->pspace
!= inf
->pspace
)
2020 val
= remove_breakpoint (bl
, mark_uninserted
);
2029 reattach_breakpoints (int pid
)
2031 struct cleanup
*old_chain
;
2032 struct bp_location
*bl
, **blp_tmp
;
2034 struct ui_file
*tmp_error_stream
;
2035 int dummy1
= 0, dummy2
= 0;
2036 struct inferior
*inf
;
2037 struct thread_info
*tp
;
2039 tp
= any_live_thread_of_process (pid
);
2043 inf
= find_inferior_pid (pid
);
2044 old_chain
= save_inferior_ptid ();
2046 inferior_ptid
= tp
->ptid
;
2048 tmp_error_stream
= mem_fileopen ();
2049 make_cleanup_ui_file_delete (tmp_error_stream
);
2051 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2053 if (bl
->pspace
!= inf
->pspace
)
2059 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2062 do_cleanups (old_chain
);
2067 do_cleanups (old_chain
);
2071 static int internal_breakpoint_number
= -1;
2073 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2074 If INTERNAL is non-zero, the breakpoint number will be populated
2075 from internal_breakpoint_number and that variable decremented.
2076 Otherwise the breakpoint number will be populated from
2077 breakpoint_count and that value incremented. Internal breakpoints
2078 do not set the internal var bpnum. */
2080 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2083 b
->number
= internal_breakpoint_number
--;
2086 set_breakpoint_count (breakpoint_count
+ 1);
2087 b
->number
= breakpoint_count
;
2091 static struct breakpoint
*
2092 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2093 CORE_ADDR address
, enum bptype type
,
2094 struct breakpoint_ops
*ops
)
2096 struct symtab_and_line sal
;
2097 struct breakpoint
*b
;
2099 init_sal (&sal
); /* Initialize to zeroes. */
2102 sal
.section
= find_pc_overlay (sal
.pc
);
2103 sal
.pspace
= current_program_space
;
2105 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2106 b
->number
= internal_breakpoint_number
--;
2107 b
->disposition
= disp_donttouch
;
2112 static const char *const longjmp_names
[] =
2114 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2116 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2118 /* Per-objfile data private to breakpoint.c. */
2119 struct breakpoint_objfile_data
2121 /* Minimal symbol for "_ovly_debug_event" (if any). */
2122 struct minimal_symbol
*overlay_msym
;
2124 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2125 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2127 /* Minimal symbol for "std::terminate()" (if any). */
2128 struct minimal_symbol
*terminate_msym
;
2130 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2131 struct minimal_symbol
*exception_msym
;
2134 static const struct objfile_data
*breakpoint_objfile_key
;
2136 /* Minimal symbol not found sentinel. */
2137 static struct minimal_symbol msym_not_found
;
2139 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2142 msym_not_found_p (const struct minimal_symbol
*msym
)
2144 return msym
== &msym_not_found
;
2147 /* Return per-objfile data needed by breakpoint.c.
2148 Allocate the data if necessary. */
2150 static struct breakpoint_objfile_data
*
2151 get_breakpoint_objfile_data (struct objfile
*objfile
)
2153 struct breakpoint_objfile_data
*bp_objfile_data
;
2155 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2156 if (bp_objfile_data
== NULL
)
2158 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2159 sizeof (*bp_objfile_data
));
2161 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2162 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2164 return bp_objfile_data
;
2168 create_overlay_event_breakpoint (void)
2170 struct objfile
*objfile
;
2171 const char *const func_name
= "_ovly_debug_event";
2173 ALL_OBJFILES (objfile
)
2175 struct breakpoint
*b
;
2176 struct breakpoint_objfile_data
*bp_objfile_data
;
2179 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2181 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2184 if (bp_objfile_data
->overlay_msym
== NULL
)
2186 struct minimal_symbol
*m
;
2188 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2191 /* Avoid future lookups in this objfile. */
2192 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2195 bp_objfile_data
->overlay_msym
= m
;
2198 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2199 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2201 &internal_breakpoint_ops
);
2202 b
->addr_string
= xstrdup (func_name
);
2204 if (overlay_debugging
== ovly_auto
)
2206 b
->enable_state
= bp_enabled
;
2207 overlay_events_enabled
= 1;
2211 b
->enable_state
= bp_disabled
;
2212 overlay_events_enabled
= 0;
2215 update_global_location_list (1);
2219 create_longjmp_master_breakpoint (void)
2221 struct program_space
*pspace
;
2222 struct cleanup
*old_chain
;
2224 old_chain
= save_current_program_space ();
2226 ALL_PSPACES (pspace
)
2228 struct objfile
*objfile
;
2230 set_current_program_space (pspace
);
2232 ALL_OBJFILES (objfile
)
2235 struct gdbarch
*gdbarch
;
2236 struct breakpoint_objfile_data
*bp_objfile_data
;
2238 gdbarch
= get_objfile_arch (objfile
);
2239 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2242 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2244 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2246 struct breakpoint
*b
;
2247 const char *func_name
;
2250 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2253 func_name
= longjmp_names
[i
];
2254 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2256 struct minimal_symbol
*m
;
2258 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2261 /* Prevent future lookups in this objfile. */
2262 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2265 bp_objfile_data
->longjmp_msym
[i
] = m
;
2268 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2269 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2270 &internal_breakpoint_ops
);
2271 b
->addr_string
= xstrdup (func_name
);
2272 b
->enable_state
= bp_disabled
;
2276 update_global_location_list (1);
2278 do_cleanups (old_chain
);
2281 /* Create a master std::terminate breakpoint. */
2283 create_std_terminate_master_breakpoint (void)
2285 struct program_space
*pspace
;
2286 struct cleanup
*old_chain
;
2287 const char *const func_name
= "std::terminate()";
2289 old_chain
= save_current_program_space ();
2291 ALL_PSPACES (pspace
)
2293 struct objfile
*objfile
;
2296 set_current_program_space (pspace
);
2298 ALL_OBJFILES (objfile
)
2300 struct breakpoint
*b
;
2301 struct breakpoint_objfile_data
*bp_objfile_data
;
2303 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2305 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2308 if (bp_objfile_data
->terminate_msym
== NULL
)
2310 struct minimal_symbol
*m
;
2312 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2313 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2314 && MSYMBOL_TYPE (m
) != mst_file_text
))
2316 /* Prevent future lookups in this objfile. */
2317 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2320 bp_objfile_data
->terminate_msym
= m
;
2323 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2324 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2325 bp_std_terminate_master
,
2326 &internal_breakpoint_ops
);
2327 b
->addr_string
= xstrdup (func_name
);
2328 b
->enable_state
= bp_disabled
;
2332 update_global_location_list (1);
2334 do_cleanups (old_chain
);
2337 /* Install a master breakpoint on the unwinder's debug hook. */
2340 create_exception_master_breakpoint (void)
2342 struct objfile
*objfile
;
2343 const char *const func_name
= "_Unwind_DebugHook";
2345 ALL_OBJFILES (objfile
)
2347 struct breakpoint
*b
;
2348 struct gdbarch
*gdbarch
;
2349 struct breakpoint_objfile_data
*bp_objfile_data
;
2352 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2354 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2357 gdbarch
= get_objfile_arch (objfile
);
2359 if (bp_objfile_data
->exception_msym
== NULL
)
2361 struct minimal_symbol
*debug_hook
;
2363 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2364 if (debug_hook
== NULL
)
2366 bp_objfile_data
->exception_msym
= &msym_not_found
;
2370 bp_objfile_data
->exception_msym
= debug_hook
;
2373 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2374 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2376 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2377 &internal_breakpoint_ops
);
2378 b
->addr_string
= xstrdup (func_name
);
2379 b
->enable_state
= bp_disabled
;
2382 update_global_location_list (1);
2386 update_breakpoints_after_exec (void)
2388 struct breakpoint
*b
, *b_tmp
;
2389 struct bp_location
*bploc
, **bplocp_tmp
;
2391 /* We're about to delete breakpoints from GDB's lists. If the
2392 INSERTED flag is true, GDB will try to lift the breakpoints by
2393 writing the breakpoints' "shadow contents" back into memory. The
2394 "shadow contents" are NOT valid after an exec, so GDB should not
2395 do that. Instead, the target is responsible from marking
2396 breakpoints out as soon as it detects an exec. We don't do that
2397 here instead, because there may be other attempts to delete
2398 breakpoints after detecting an exec and before reaching here. */
2399 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2400 if (bploc
->pspace
== current_program_space
)
2401 gdb_assert (!bploc
->inserted
);
2403 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2405 if (b
->pspace
!= current_program_space
)
2408 /* Solib breakpoints must be explicitly reset after an exec(). */
2409 if (b
->type
== bp_shlib_event
)
2411 delete_breakpoint (b
);
2415 /* JIT breakpoints must be explicitly reset after an exec(). */
2416 if (b
->type
== bp_jit_event
)
2418 delete_breakpoint (b
);
2422 /* Thread event breakpoints must be set anew after an exec(),
2423 as must overlay event and longjmp master breakpoints. */
2424 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2425 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2426 || b
->type
== bp_exception_master
)
2428 delete_breakpoint (b
);
2432 /* Step-resume breakpoints are meaningless after an exec(). */
2433 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2435 delete_breakpoint (b
);
2439 /* Longjmp and longjmp-resume breakpoints are also meaningless
2441 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2442 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2444 delete_breakpoint (b
);
2448 if (b
->type
== bp_catchpoint
)
2450 /* For now, none of the bp_catchpoint breakpoints need to
2451 do anything at this point. In the future, if some of
2452 the catchpoints need to something, we will need to add
2453 a new method, and call this method from here. */
2457 /* bp_finish is a special case. The only way we ought to be able
2458 to see one of these when an exec() has happened, is if the user
2459 caught a vfork, and then said "finish". Ordinarily a finish just
2460 carries them to the call-site of the current callee, by setting
2461 a temporary bp there and resuming. But in this case, the finish
2462 will carry them entirely through the vfork & exec.
2464 We don't want to allow a bp_finish to remain inserted now. But
2465 we can't safely delete it, 'cause finish_command has a handle to
2466 the bp on a bpstat, and will later want to delete it. There's a
2467 chance (and I've seen it happen) that if we delete the bp_finish
2468 here, that its storage will get reused by the time finish_command
2469 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2470 We really must allow finish_command to delete a bp_finish.
2472 In the absence of a general solution for the "how do we know
2473 it's safe to delete something others may have handles to?"
2474 problem, what we'll do here is just uninsert the bp_finish, and
2475 let finish_command delete it.
2477 (We know the bp_finish is "doomed" in the sense that it's
2478 momentary, and will be deleted as soon as finish_command sees
2479 the inferior stopped. So it doesn't matter that the bp's
2480 address is probably bogus in the new a.out, unlike e.g., the
2481 solib breakpoints.) */
2483 if (b
->type
== bp_finish
)
2488 /* Without a symbolic address, we have little hope of the
2489 pre-exec() address meaning the same thing in the post-exec()
2491 if (b
->addr_string
== NULL
)
2493 delete_breakpoint (b
);
2497 /* FIXME what about longjmp breakpoints? Re-create them here? */
2498 create_overlay_event_breakpoint ();
2499 create_longjmp_master_breakpoint ();
2500 create_std_terminate_master_breakpoint ();
2501 create_exception_master_breakpoint ();
2505 detach_breakpoints (int pid
)
2507 struct bp_location
*bl
, **blp_tmp
;
2509 struct cleanup
*old_chain
= save_inferior_ptid ();
2510 struct inferior
*inf
= current_inferior ();
2512 if (pid
== PIDGET (inferior_ptid
))
2513 error (_("Cannot detach breakpoints of inferior_ptid"));
2515 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2516 inferior_ptid
= pid_to_ptid (pid
);
2517 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2519 if (bl
->pspace
!= inf
->pspace
)
2523 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2526 /* Detach single-step breakpoints as well. */
2527 detach_single_step_breakpoints ();
2529 do_cleanups (old_chain
);
2533 /* Remove the breakpoint location BL from the current address space.
2534 Note that this is used to detach breakpoints from a child fork.
2535 When we get here, the child isn't in the inferior list, and neither
2536 do we have objects to represent its address space --- we should
2537 *not* look at bl->pspace->aspace here. */
2540 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2544 /* BL is never in moribund_locations by our callers. */
2545 gdb_assert (bl
->owner
!= NULL
);
2547 if (bl
->owner
->enable_state
== bp_permanent
)
2548 /* Permanent breakpoints cannot be inserted or removed. */
2551 /* The type of none suggests that owner is actually deleted.
2552 This should not ever happen. */
2553 gdb_assert (bl
->owner
->type
!= bp_none
);
2555 if (bl
->loc_type
== bp_loc_software_breakpoint
2556 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2558 /* "Normal" instruction breakpoint: either the standard
2559 trap-instruction bp (bp_breakpoint), or a
2560 bp_hardware_breakpoint. */
2562 /* First check to see if we have to handle an overlay. */
2563 if (overlay_debugging
== ovly_off
2564 || bl
->section
== NULL
2565 || !(section_is_overlay (bl
->section
)))
2567 /* No overlay handling: just remove the breakpoint. */
2568 val
= bl
->owner
->ops
->remove_location (bl
);
2572 /* This breakpoint is in an overlay section.
2573 Did we set a breakpoint at the LMA? */
2574 if (!overlay_events_enabled
)
2576 /* Yes -- overlay event support is not active, so we
2577 should have set a breakpoint at the LMA. Remove it.
2579 /* Ignore any failures: if the LMA is in ROM, we will
2580 have already warned when we failed to insert it. */
2581 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2582 target_remove_hw_breakpoint (bl
->gdbarch
,
2583 &bl
->overlay_target_info
);
2585 target_remove_breakpoint (bl
->gdbarch
,
2586 &bl
->overlay_target_info
);
2588 /* Did we set a breakpoint at the VMA?
2589 If so, we will have marked the breakpoint 'inserted'. */
2592 /* Yes -- remove it. Previously we did not bother to
2593 remove the breakpoint if the section had been
2594 unmapped, but let's not rely on that being safe. We
2595 don't know what the overlay manager might do. */
2597 /* However, we should remove *software* breakpoints only
2598 if the section is still mapped, or else we overwrite
2599 wrong code with the saved shadow contents. */
2600 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2601 || section_is_mapped (bl
->section
))
2602 val
= bl
->owner
->ops
->remove_location (bl
);
2608 /* No -- not inserted, so no need to remove. No error. */
2613 /* In some cases, we might not be able to remove a breakpoint
2614 in a shared library that has already been removed, but we
2615 have not yet processed the shlib unload event. */
2616 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2621 bl
->inserted
= (is
== mark_inserted
);
2623 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2625 gdb_assert (bl
->owner
->ops
!= NULL
2626 && bl
->owner
->ops
->remove_location
!= NULL
);
2628 bl
->inserted
= (is
== mark_inserted
);
2629 bl
->owner
->ops
->remove_location (bl
);
2631 /* Failure to remove any of the hardware watchpoints comes here. */
2632 if ((is
== mark_uninserted
) && (bl
->inserted
))
2633 warning (_("Could not remove hardware watchpoint %d."),
2636 else if (bl
->owner
->type
== bp_catchpoint
2637 && breakpoint_enabled (bl
->owner
)
2640 gdb_assert (bl
->owner
->ops
!= NULL
2641 && bl
->owner
->ops
->remove_location
!= NULL
);
2643 val
= bl
->owner
->ops
->remove_location (bl
);
2647 bl
->inserted
= (is
== mark_inserted
);
2654 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2657 struct cleanup
*old_chain
;
2659 /* BL is never in moribund_locations by our callers. */
2660 gdb_assert (bl
->owner
!= NULL
);
2662 if (bl
->owner
->enable_state
== bp_permanent
)
2663 /* Permanent breakpoints cannot be inserted or removed. */
2666 /* The type of none suggests that owner is actually deleted.
2667 This should not ever happen. */
2668 gdb_assert (bl
->owner
->type
!= bp_none
);
2670 old_chain
= save_current_space_and_thread ();
2672 switch_to_program_space_and_thread (bl
->pspace
);
2674 ret
= remove_breakpoint_1 (bl
, is
);
2676 do_cleanups (old_chain
);
2680 /* Clear the "inserted" flag in all breakpoints. */
2683 mark_breakpoints_out (void)
2685 struct bp_location
*bl
, **blp_tmp
;
2687 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2688 if (bl
->pspace
== current_program_space
)
2692 /* Clear the "inserted" flag in all breakpoints and delete any
2693 breakpoints which should go away between runs of the program.
2695 Plus other such housekeeping that has to be done for breakpoints
2698 Note: this function gets called at the end of a run (by
2699 generic_mourn_inferior) and when a run begins (by
2700 init_wait_for_inferior). */
2705 breakpoint_init_inferior (enum inf_context context
)
2707 struct breakpoint
*b
, *b_tmp
;
2708 struct bp_location
*bl
, **blp_tmp
;
2710 struct program_space
*pspace
= current_program_space
;
2712 /* If breakpoint locations are shared across processes, then there's
2714 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2717 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2719 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2720 if (bl
->pspace
== pspace
2721 && bl
->owner
->enable_state
!= bp_permanent
)
2725 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2727 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2734 /* If the call dummy breakpoint is at the entry point it will
2735 cause problems when the inferior is rerun, so we better get
2738 case bp_watchpoint_scope
:
2740 /* Also get rid of scope breakpoints. */
2742 case bp_shlib_event
:
2744 /* Also remove solib event breakpoints. Their addresses may
2745 have changed since the last time we ran the program.
2746 Actually we may now be debugging against different target;
2747 and so the solib backend that installed this breakpoint may
2748 not be used in by the target. E.g.,
2750 (gdb) file prog-linux
2751 (gdb) run # native linux target
2754 (gdb) file prog-win.exe
2755 (gdb) tar rem :9999 # remote Windows gdbserver.
2758 delete_breakpoint (b
);
2762 case bp_hardware_watchpoint
:
2763 case bp_read_watchpoint
:
2764 case bp_access_watchpoint
:
2766 /* Likewise for watchpoints on local expressions. */
2767 if (b
->exp_valid_block
!= NULL
)
2768 delete_breakpoint (b
);
2769 else if (context
== inf_starting
)
2771 /* Reset val field to force reread of starting value in
2772 insert_breakpoints. */
2774 value_free (b
->val
);
2784 /* Get rid of the moribund locations. */
2785 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2786 decref_bp_location (&bl
);
2787 VEC_free (bp_location_p
, moribund_locations
);
2790 /* These functions concern about actual breakpoints inserted in the
2791 target --- to e.g. check if we need to do decr_pc adjustment or if
2792 we need to hop over the bkpt --- so we check for address space
2793 match, not program space. */
2795 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2796 exists at PC. It returns ordinary_breakpoint_here if it's an
2797 ordinary breakpoint, or permanent_breakpoint_here if it's a
2798 permanent breakpoint.
2799 - When continuing from a location with an ordinary breakpoint, we
2800 actually single step once before calling insert_breakpoints.
2801 - When continuing from a location with a permanent breakpoint, we
2802 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2803 the target, to advance the PC past the breakpoint. */
2805 enum breakpoint_here
2806 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2808 struct bp_location
*bl
, **blp_tmp
;
2809 int any_breakpoint_here
= 0;
2811 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2813 if (bl
->loc_type
!= bp_loc_software_breakpoint
2814 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2817 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2818 if ((breakpoint_enabled (bl
->owner
)
2819 || bl
->owner
->enable_state
== bp_permanent
)
2820 && breakpoint_location_address_match (bl
, aspace
, pc
))
2822 if (overlay_debugging
2823 && section_is_overlay (bl
->section
)
2824 && !section_is_mapped (bl
->section
))
2825 continue; /* unmapped overlay -- can't be a match */
2826 else if (bl
->owner
->enable_state
== bp_permanent
)
2827 return permanent_breakpoint_here
;
2829 any_breakpoint_here
= 1;
2833 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2836 /* Return true if there's a moribund breakpoint at PC. */
2839 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2841 struct bp_location
*loc
;
2844 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2845 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2851 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2852 inserted using regular breakpoint_chain / bp_location array
2853 mechanism. This does not check for single-step breakpoints, which
2854 are inserted and removed using direct target manipulation. */
2857 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2860 struct bp_location
*bl
, **blp_tmp
;
2862 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2864 if (bl
->loc_type
!= bp_loc_software_breakpoint
2865 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2869 && breakpoint_location_address_match (bl
, aspace
, pc
))
2871 if (overlay_debugging
2872 && section_is_overlay (bl
->section
)
2873 && !section_is_mapped (bl
->section
))
2874 continue; /* unmapped overlay -- can't be a match */
2882 /* Returns non-zero iff there's either regular breakpoint
2883 or a single step breakpoint inserted at PC. */
2886 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2888 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2891 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2897 /* This function returns non-zero iff there is a software breakpoint
2901 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2904 struct bp_location
*bl
, **blp_tmp
;
2906 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2908 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2912 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2915 if (overlay_debugging
2916 && section_is_overlay (bl
->section
)
2917 && !section_is_mapped (bl
->section
))
2918 continue; /* unmapped overlay -- can't be a match */
2924 /* Also check for software single-step breakpoints. */
2925 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2932 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2933 CORE_ADDR addr
, ULONGEST len
)
2935 struct breakpoint
*bpt
;
2937 ALL_BREAKPOINTS (bpt
)
2939 struct bp_location
*loc
;
2941 if (bpt
->type
!= bp_hardware_watchpoint
2942 && bpt
->type
!= bp_access_watchpoint
)
2945 if (!breakpoint_enabled (bpt
))
2948 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2949 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2953 /* Check for intersection. */
2954 l
= max (loc
->address
, addr
);
2955 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2963 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2964 PC is valid for process/thread PTID. */
2967 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2970 struct bp_location
*bl
, **blp_tmp
;
2971 /* The thread and task IDs associated to PTID, computed lazily. */
2975 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2977 if (bl
->loc_type
!= bp_loc_software_breakpoint
2978 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2981 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2982 if (!breakpoint_enabled (bl
->owner
)
2983 && bl
->owner
->enable_state
!= bp_permanent
)
2986 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
2989 if (bl
->owner
->thread
!= -1)
2991 /* This is a thread-specific breakpoint. Check that ptid
2992 matches that thread. If thread hasn't been computed yet,
2993 it is now time to do so. */
2995 thread
= pid_to_thread_id (ptid
);
2996 if (bl
->owner
->thread
!= thread
)
3000 if (bl
->owner
->task
!= 0)
3002 /* This is a task-specific breakpoint. Check that ptid
3003 matches that task. If task hasn't been computed yet,
3004 it is now time to do so. */
3006 task
= ada_get_task_number (ptid
);
3007 if (bl
->owner
->task
!= task
)
3011 if (overlay_debugging
3012 && section_is_overlay (bl
->section
)
3013 && !section_is_mapped (bl
->section
))
3014 continue; /* unmapped overlay -- can't be a match */
3023 /* bpstat stuff. External routines' interfaces are documented
3027 ep_is_catchpoint (struct breakpoint
*ep
)
3029 return (ep
->type
== bp_catchpoint
);
3032 /* Frees any storage that is part of a bpstat. Does not walk the
3036 bpstat_free (bpstat bs
)
3038 if (bs
->old_val
!= NULL
)
3039 value_free (bs
->old_val
);
3040 decref_counted_command_line (&bs
->commands
);
3041 decref_bp_location (&bs
->bp_location_at
);
3045 /* Clear a bpstat so that it says we are not at any breakpoint.
3046 Also free any storage that is part of a bpstat. */
3049 bpstat_clear (bpstat
*bsp
)
3066 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3067 is part of the bpstat is copied as well. */
3070 bpstat_copy (bpstat bs
)
3074 bpstat retval
= NULL
;
3079 for (; bs
!= NULL
; bs
= bs
->next
)
3081 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3082 memcpy (tmp
, bs
, sizeof (*tmp
));
3083 incref_counted_command_line (tmp
->commands
);
3084 incref_bp_location (tmp
->bp_location_at
);
3085 if (bs
->old_val
!= NULL
)
3087 tmp
->old_val
= value_copy (bs
->old_val
);
3088 release_value (tmp
->old_val
);
3092 /* This is the first thing in the chain. */
3102 /* Find the bpstat associated with this breakpoint. */
3105 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3110 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3112 if (bsp
->breakpoint_at
== breakpoint
)
3118 /* Put in *NUM the breakpoint number of the first breakpoint we are
3119 stopped at. *BSP upon return is a bpstat which points to the
3120 remaining breakpoints stopped at (but which is not guaranteed to be
3121 good for anything but further calls to bpstat_num).
3123 Return 0 if passed a bpstat which does not indicate any breakpoints.
3124 Return -1 if stopped at a breakpoint that has been deleted since
3126 Return 1 otherwise. */
3129 bpstat_num (bpstat
*bsp
, int *num
)
3131 struct breakpoint
*b
;
3134 return 0; /* No more breakpoint values */
3136 /* We assume we'll never have several bpstats that correspond to a
3137 single breakpoint -- otherwise, this function might return the
3138 same number more than once and this will look ugly. */
3139 b
= (*bsp
)->breakpoint_at
;
3140 *bsp
= (*bsp
)->next
;
3142 return -1; /* breakpoint that's been deleted since */
3144 *num
= b
->number
; /* We have its number */
3148 /* Modify BS so that the actions will not be performed. */
3151 bpstat_clear_actions (bpstat bs
)
3153 for (; bs
!= NULL
; bs
= bs
->next
)
3155 decref_counted_command_line (&bs
->commands
);
3156 bs
->commands_left
= NULL
;
3157 if (bs
->old_val
!= NULL
)
3159 value_free (bs
->old_val
);
3165 /* Called when a command is about to proceed the inferior. */
3168 breakpoint_about_to_proceed (void)
3170 if (!ptid_equal (inferior_ptid
, null_ptid
))
3172 struct thread_info
*tp
= inferior_thread ();
3174 /* Allow inferior function calls in breakpoint commands to not
3175 interrupt the command list. When the call finishes
3176 successfully, the inferior will be standing at the same
3177 breakpoint as if nothing happened. */
3178 if (tp
->control
.in_infcall
)
3182 breakpoint_proceeded
= 1;
3185 /* Stub for cleaning up our state if we error-out of a breakpoint
3188 cleanup_executing_breakpoints (void *ignore
)
3190 executing_breakpoint_commands
= 0;
3193 /* Execute all the commands associated with all the breakpoints at
3194 this location. Any of these commands could cause the process to
3195 proceed beyond this point, etc. We look out for such changes by
3196 checking the global "breakpoint_proceeded" after each command.
3198 Returns true if a breakpoint command resumed the inferior. In that
3199 case, it is the caller's responsibility to recall it again with the
3200 bpstat of the current thread. */
3203 bpstat_do_actions_1 (bpstat
*bsp
)
3206 struct cleanup
*old_chain
;
3209 /* Avoid endless recursion if a `source' command is contained
3211 if (executing_breakpoint_commands
)
3214 executing_breakpoint_commands
= 1;
3215 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3217 prevent_dont_repeat ();
3219 /* This pointer will iterate over the list of bpstat's. */
3222 breakpoint_proceeded
= 0;
3223 for (; bs
!= NULL
; bs
= bs
->next
)
3225 struct counted_command_line
*ccmd
;
3226 struct command_line
*cmd
;
3227 struct cleanup
*this_cmd_tree_chain
;
3229 /* Take ownership of the BSP's command tree, if it has one.
3231 The command tree could legitimately contain commands like
3232 'step' and 'next', which call clear_proceed_status, which
3233 frees stop_bpstat's command tree. To make sure this doesn't
3234 free the tree we're executing out from under us, we need to
3235 take ownership of the tree ourselves. Since a given bpstat's
3236 commands are only executed once, we don't need to copy it; we
3237 can clear the pointer in the bpstat, and make sure we free
3238 the tree when we're done. */
3239 ccmd
= bs
->commands
;
3240 bs
->commands
= NULL
;
3242 = make_cleanup_decref_counted_command_line (&ccmd
);
3243 cmd
= bs
->commands_left
;
3244 bs
->commands_left
= NULL
;
3248 execute_control_command (cmd
);
3250 if (breakpoint_proceeded
)
3256 /* We can free this command tree now. */
3257 do_cleanups (this_cmd_tree_chain
);
3259 if (breakpoint_proceeded
)
3261 if (target_can_async_p ())
3262 /* If we are in async mode, then the target might be still
3263 running, not stopped at any breakpoint, so nothing for
3264 us to do here -- just return to the event loop. */
3267 /* In sync mode, when execute_control_command returns
3268 we're already standing on the next breakpoint.
3269 Breakpoint commands for that stop were not run, since
3270 execute_command does not run breakpoint commands --
3271 only command_line_handler does, but that one is not
3272 involved in execution of breakpoint commands. So, we
3273 can now execute breakpoint commands. It should be
3274 noted that making execute_command do bpstat actions is
3275 not an option -- in this case we'll have recursive
3276 invocation of bpstat for each breakpoint with a
3277 command, and can easily blow up GDB stack. Instead, we
3278 return true, which will trigger the caller to recall us
3279 with the new stop_bpstat. */
3284 do_cleanups (old_chain
);
3289 bpstat_do_actions (void)
3291 /* Do any commands attached to breakpoint we are stopped at. */
3292 while (!ptid_equal (inferior_ptid
, null_ptid
)
3293 && target_has_execution
3294 && !is_exited (inferior_ptid
)
3295 && !is_executing (inferior_ptid
))
3296 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3297 and only return when it is stopped at the next breakpoint, we
3298 keep doing breakpoint actions until it returns false to
3299 indicate the inferior was not resumed. */
3300 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3304 /* Print out the (old or new) value associated with a watchpoint. */
3307 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3310 fprintf_unfiltered (stream
, _("<unreadable>"));
3313 struct value_print_options opts
;
3314 get_user_print_options (&opts
);
3315 value_print (val
, stream
, &opts
);
3319 /* Generic routine for printing messages indicating why we
3320 stopped. The behavior of this function depends on the value
3321 'print_it' in the bpstat structure. Under some circumstances we
3322 may decide not to print anything here and delegate the task to
3325 static enum print_stop_action
3326 print_bp_stop_message (bpstat bs
)
3328 switch (bs
->print_it
)
3331 /* Nothing should be printed for this bpstat entry. */
3332 return PRINT_UNKNOWN
;
3336 /* We still want to print the frame, but we already printed the
3337 relevant messages. */
3338 return PRINT_SRC_AND_LOC
;
3341 case print_it_normal
:
3343 struct breakpoint
*b
= bs
->breakpoint_at
;
3345 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3346 which has since been deleted. */
3348 return PRINT_UNKNOWN
;
3350 /* Normal case. Call the breakpoint's print_it method. */
3351 return b
->ops
->print_it (bs
);
3356 internal_error (__FILE__
, __LINE__
,
3357 _("print_bp_stop_message: unrecognized enum value"));
3362 /* Print a message indicating what happened. This is called from
3363 normal_stop(). The input to this routine is the head of the bpstat
3364 list - a list of the eventpoints that caused this stop. This
3365 routine calls the generic print routine for printing a message
3366 about reasons for stopping. This will print (for example) the
3367 "Breakpoint n," part of the output. The return value of this
3370 PRINT_UNKNOWN: Means we printed nothing.
3371 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3372 code to print the location. An example is
3373 "Breakpoint 1, " which should be followed by
3375 PRINT_SRC_ONLY: Means we printed something, but there is no need
3376 to also print the location part of the message.
3377 An example is the catch/throw messages, which
3378 don't require a location appended to the end.
3379 PRINT_NOTHING: We have done some printing and we don't need any
3380 further info to be printed. */
3382 enum print_stop_action
3383 bpstat_print (bpstat bs
)
3387 /* Maybe another breakpoint in the chain caused us to stop.
3388 (Currently all watchpoints go on the bpstat whether hit or not.
3389 That probably could (should) be changed, provided care is taken
3390 with respect to bpstat_explains_signal). */
3391 for (; bs
; bs
= bs
->next
)
3393 val
= print_bp_stop_message (bs
);
3394 if (val
== PRINT_SRC_ONLY
3395 || val
== PRINT_SRC_AND_LOC
3396 || val
== PRINT_NOTHING
)
3400 /* We reached the end of the chain, or we got a null BS to start
3401 with and nothing was printed. */
3402 return PRINT_UNKNOWN
;
3405 /* Evaluate the expression EXP and return 1 if value is zero. This is
3406 used inside a catch_errors to evaluate the breakpoint condition.
3407 The argument is a "struct expression *" that has been cast to a
3408 "char *" to make it pass through catch_errors. */
3411 breakpoint_cond_eval (void *exp
)
3413 struct value
*mark
= value_mark ();
3414 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3416 value_free_to_mark (mark
);
3420 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3423 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3427 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3429 **bs_link_pointer
= bs
;
3430 *bs_link_pointer
= &bs
->next
;
3431 bs
->breakpoint_at
= bl
->owner
;
3432 bs
->bp_location_at
= bl
;
3433 incref_bp_location (bl
);
3434 /* If the condition is false, etc., don't do the commands. */
3435 bs
->commands
= NULL
;
3436 bs
->commands_left
= NULL
;
3438 bs
->print_it
= print_it_normal
;
3442 /* The target has stopped with waitstatus WS. Check if any hardware
3443 watchpoints have triggered, according to the target. */
3446 watchpoints_triggered (struct target_waitstatus
*ws
)
3448 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3450 struct breakpoint
*b
;
3452 if (!stopped_by_watchpoint
)
3454 /* We were not stopped by a watchpoint. Mark all watchpoints
3455 as not triggered. */
3457 if (is_hardware_watchpoint (b
))
3458 b
->watchpoint_triggered
= watch_triggered_no
;
3463 if (!target_stopped_data_address (¤t_target
, &addr
))
3465 /* We were stopped by a watchpoint, but we don't know where.
3466 Mark all watchpoints as unknown. */
3468 if (is_hardware_watchpoint (b
))
3469 b
->watchpoint_triggered
= watch_triggered_unknown
;
3471 return stopped_by_watchpoint
;
3474 /* The target could report the data address. Mark watchpoints
3475 affected by this data address as triggered, and all others as not
3479 if (is_hardware_watchpoint (b
))
3481 struct bp_location
*loc
;
3483 b
->watchpoint_triggered
= watch_triggered_no
;
3484 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3486 if (is_masked_watchpoint (loc
->owner
))
3488 CORE_ADDR newaddr
= addr
& loc
->owner
->hw_wp_mask
;
3489 CORE_ADDR start
= loc
->address
& loc
->owner
->hw_wp_mask
;
3491 if (newaddr
== start
)
3493 b
->watchpoint_triggered
= watch_triggered_yes
;
3497 /* Exact match not required. Within range is sufficient. */
3498 else if (target_watchpoint_addr_within_range (¤t_target
,
3502 b
->watchpoint_triggered
= watch_triggered_yes
;
3511 /* Possible return values for watchpoint_check (this can't be an enum
3512 because of check_errors). */
3513 /* The watchpoint has been deleted. */
3514 #define WP_DELETED 1
3515 /* The value has changed. */
3516 #define WP_VALUE_CHANGED 2
3517 /* The value has not changed. */
3518 #define WP_VALUE_NOT_CHANGED 3
3519 /* Ignore this watchpoint, no matter if the value changed or not. */
3522 #define BP_TEMPFLAG 1
3523 #define BP_HARDWAREFLAG 2
3525 /* Evaluate watchpoint condition expression and check if its value
3528 P should be a pointer to struct bpstat, but is defined as a void *
3529 in order for this function to be usable with catch_errors. */
3532 watchpoint_check (void *p
)
3534 bpstat bs
= (bpstat
) p
;
3535 struct breakpoint
*b
;
3536 struct frame_info
*fr
;
3537 int within_current_scope
;
3539 /* BS is built from an existing struct breakpoint. */
3540 gdb_assert (bs
->breakpoint_at
!= NULL
);
3541 b
= bs
->breakpoint_at
;
3543 gdb_assert (is_watchpoint (b
));
3545 /* If this is a local watchpoint, we only want to check if the
3546 watchpoint frame is in scope if the current thread is the thread
3547 that was used to create the watchpoint. */
3548 if (!watchpoint_in_thread_scope (b
))
3551 if (b
->exp_valid_block
== NULL
)
3552 within_current_scope
= 1;
3555 struct frame_info
*frame
= get_current_frame ();
3556 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3557 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3559 /* in_function_epilogue_p() returns a non-zero value if we're
3560 still in the function but the stack frame has already been
3561 invalidated. Since we can't rely on the values of local
3562 variables after the stack has been destroyed, we are treating
3563 the watchpoint in that state as `not changed' without further
3564 checking. Don't mark watchpoints as changed if the current
3565 frame is in an epilogue - even if they are in some other
3566 frame, our view of the stack is likely to be wrong and
3567 frame_find_by_id could error out. */
3568 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3571 fr
= frame_find_by_id (b
->watchpoint_frame
);
3572 within_current_scope
= (fr
!= NULL
);
3574 /* If we've gotten confused in the unwinder, we might have
3575 returned a frame that can't describe this variable. */
3576 if (within_current_scope
)
3578 struct symbol
*function
;
3580 function
= get_frame_function (fr
);
3581 if (function
== NULL
3582 || !contained_in (b
->exp_valid_block
,
3583 SYMBOL_BLOCK_VALUE (function
)))
3584 within_current_scope
= 0;
3587 if (within_current_scope
)
3588 /* If we end up stopping, the current frame will get selected
3589 in normal_stop. So this call to select_frame won't affect
3594 if (within_current_scope
)
3596 /* We use value_{,free_to_}mark because it could be a *long*
3597 time before we return to the command level and call
3598 free_all_values. We can't call free_all_values because we
3599 might be in the middle of evaluating a function call. */
3603 struct value
*new_val
;
3605 if (is_masked_watchpoint (b
))
3606 /* Since we don't know the exact trigger address (from
3607 stopped_data_address), just tell the user we've triggered
3608 a mask watchpoint. */
3609 return WP_VALUE_CHANGED
;
3611 mark
= value_mark ();
3612 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3614 /* We use value_equal_contents instead of value_equal because
3615 the latter coerces an array to a pointer, thus comparing just
3616 the address of the array instead of its contents. This is
3617 not what we want. */
3618 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3619 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3621 if (new_val
!= NULL
)
3623 release_value (new_val
);
3624 value_free_to_mark (mark
);
3626 bs
->old_val
= b
->val
;
3629 return WP_VALUE_CHANGED
;
3633 /* Nothing changed. */
3634 value_free_to_mark (mark
);
3635 return WP_VALUE_NOT_CHANGED
;
3640 /* This seems like the only logical thing to do because
3641 if we temporarily ignored the watchpoint, then when
3642 we reenter the block in which it is valid it contains
3643 garbage (in the case of a function, it may have two
3644 garbage values, one before and one after the prologue).
3645 So we can't even detect the first assignment to it and
3646 watch after that (since the garbage may or may not equal
3647 the first value assigned). */
3648 /* We print all the stop information in
3649 breakpoint_ops->print_it, but in this case, by the time we
3650 call breakpoint_ops->print_it this bp will be deleted
3651 already. So we have no choice but print the information
3653 if (ui_out_is_mi_like_p (uiout
))
3655 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3656 ui_out_text (uiout
, "\nWatchpoint ");
3657 ui_out_field_int (uiout
, "wpnum", b
->number
);
3659 " deleted because the program has left the block in\n\
3660 which its expression is valid.\n");
3662 /* Make sure the watchpoint's commands aren't executed. */
3663 decref_counted_command_line (&b
->commands
);
3664 watchpoint_del_at_next_stop (b
);
3670 /* Return true if it looks like target has stopped due to hitting
3671 breakpoint location BL. This function does not check if we should
3672 stop, only if BL explains the stop. */
3675 bpstat_check_location (const struct bp_location
*bl
,
3676 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3678 struct breakpoint
*b
= bl
->owner
;
3680 /* BL is from an existing breakpoint. */
3681 gdb_assert (b
!= NULL
);
3683 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3686 /* If BS refers to a watchpoint, determine if the watched values
3687 has actually changed, and we should stop. If not, set BS->stop
3690 bpstat_check_watchpoint (bpstat bs
)
3692 const struct bp_location
*bl
;
3693 struct breakpoint
*b
;
3695 /* BS is built for existing struct breakpoint. */
3696 bl
= bs
->bp_location_at
;
3697 gdb_assert (bl
!= NULL
);
3698 b
= bs
->breakpoint_at
;
3699 gdb_assert (b
!= NULL
);
3701 if (is_watchpoint (b
))
3703 int must_check_value
= 0;
3705 if (b
->type
== bp_watchpoint
)
3706 /* For a software watchpoint, we must always check the
3708 must_check_value
= 1;
3709 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3710 /* We have a hardware watchpoint (read, write, or access)
3711 and the target earlier reported an address watched by
3713 must_check_value
= 1;
3714 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3715 && b
->type
== bp_hardware_watchpoint
)
3716 /* We were stopped by a hardware watchpoint, but the target could
3717 not report the data address. We must check the watchpoint's
3718 value. Access and read watchpoints are out of luck; without
3719 a data address, we can't figure it out. */
3720 must_check_value
= 1;
3722 if (must_check_value
)
3725 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3727 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3728 int e
= catch_errors (watchpoint_check
, bs
, message
,
3730 do_cleanups (cleanups
);
3734 /* We've already printed what needs to be printed. */
3735 bs
->print_it
= print_it_done
;
3739 bs
->print_it
= print_it_noop
;
3742 case WP_VALUE_CHANGED
:
3743 if (b
->type
== bp_read_watchpoint
)
3745 /* There are two cases to consider here:
3747 1. We're watching the triggered memory for reads.
3748 In that case, trust the target, and always report
3749 the watchpoint hit to the user. Even though
3750 reads don't cause value changes, the value may
3751 have changed since the last time it was read, and
3752 since we're not trapping writes, we will not see
3753 those, and as such we should ignore our notion of
3756 2. We're watching the triggered memory for both
3757 reads and writes. There are two ways this may
3760 2.1. This is a target that can't break on data
3761 reads only, but can break on accesses (reads or
3762 writes), such as e.g., x86. We detect this case
3763 at the time we try to insert read watchpoints.
3765 2.2. Otherwise, the target supports read
3766 watchpoints, but, the user set an access or write
3767 watchpoint watching the same memory as this read
3770 If we're watching memory writes as well as reads,
3771 ignore watchpoint hits when we find that the
3772 value hasn't changed, as reads don't cause
3773 changes. This still gives false positives when
3774 the program writes the same value to memory as
3775 what there was already in memory (we will confuse
3776 it for a read), but it's much better than
3779 int other_write_watchpoint
= 0;
3781 if (bl
->watchpoint_type
== hw_read
)
3783 struct breakpoint
*other_b
;
3785 ALL_BREAKPOINTS (other_b
)
3786 if ((other_b
->type
== bp_hardware_watchpoint
3787 || other_b
->type
== bp_access_watchpoint
)
3788 && (other_b
->watchpoint_triggered
3789 == watch_triggered_yes
))
3791 other_write_watchpoint
= 1;
3796 if (other_write_watchpoint
3797 || bl
->watchpoint_type
== hw_access
)
3799 /* We're watching the same memory for writes,
3800 and the value changed since the last time we
3801 updated it, so this trap must be for a write.
3803 bs
->print_it
= print_it_noop
;
3808 case WP_VALUE_NOT_CHANGED
:
3809 if (b
->type
== bp_hardware_watchpoint
3810 || b
->type
== bp_watchpoint
)
3812 /* Don't stop: write watchpoints shouldn't fire if
3813 the value hasn't changed. */
3814 bs
->print_it
= print_it_noop
;
3822 /* Error from catch_errors. */
3823 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3824 watchpoint_del_at_next_stop (b
);
3825 /* We've already printed what needs to be printed. */
3826 bs
->print_it
= print_it_done
;
3830 else /* must_check_value == 0 */
3832 /* This is a case where some watchpoint(s) triggered, but
3833 not at the address of this watchpoint, or else no
3834 watchpoint triggered after all. So don't print
3835 anything for this watchpoint. */
3836 bs
->print_it
= print_it_noop
;
3843 /* Check conditions (condition proper, frame, thread and ignore count)
3844 of breakpoint referred to by BS. If we should not stop for this
3845 breakpoint, set BS->stop to 0. */
3848 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3850 int thread_id
= pid_to_thread_id (ptid
);
3851 const struct bp_location
*bl
;
3852 struct breakpoint
*b
;
3854 /* BS is built for existing struct breakpoint. */
3855 bl
= bs
->bp_location_at
;
3856 gdb_assert (bl
!= NULL
);
3857 b
= bs
->breakpoint_at
;
3858 gdb_assert (b
!= NULL
);
3860 if (frame_id_p (b
->frame_id
)
3861 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3865 int value_is_zero
= 0;
3866 struct expression
*cond
;
3868 /* Evaluate Python breakpoints that have a "stop"
3869 method implemented. */
3870 if (b
->py_bp_object
)
3871 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
3873 if (is_watchpoint (b
))
3878 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3880 int within_current_scope
= 1;
3882 /* We use value_mark and value_free_to_mark because it could
3883 be a long time before we return to the command level and
3884 call free_all_values. We can't call free_all_values
3885 because we might be in the middle of evaluating a
3887 struct value
*mark
= value_mark ();
3889 /* Need to select the frame, with all that implies so that
3890 the conditions will have the right context. Because we
3891 use the frame, we will not see an inlined function's
3892 variables when we arrive at a breakpoint at the start
3893 of the inlined function; the current frame will be the
3895 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3896 select_frame (get_current_frame ());
3899 struct frame_info
*frame
;
3901 /* For local watchpoint expressions, which particular
3902 instance of a local is being watched matters, so we
3903 keep track of the frame to evaluate the expression
3904 in. To evaluate the condition however, it doesn't
3905 really matter which instantiation of the function
3906 where the condition makes sense triggers the
3907 watchpoint. This allows an expression like "watch
3908 global if q > 10" set in `func', catch writes to
3909 global on all threads that call `func', or catch
3910 writes on all recursive calls of `func' by a single
3911 thread. We simply always evaluate the condition in
3912 the innermost frame that's executing where it makes
3913 sense to evaluate the condition. It seems
3915 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3917 select_frame (frame
);
3919 within_current_scope
= 0;
3921 if (within_current_scope
)
3923 = catch_errors (breakpoint_cond_eval
, cond
,
3924 "Error in testing breakpoint condition:\n",
3928 warning (_("Watchpoint condition cannot be tested "
3929 "in the current scope"));
3930 /* If we failed to set the right context for this
3931 watchpoint, unconditionally report it. */
3934 /* FIXME-someday, should give breakpoint #. */
3935 value_free_to_mark (mark
);
3938 if (cond
&& value_is_zero
)
3942 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3946 else if (b
->ignore_count
> 0)
3949 annotate_ignore_count_change ();
3951 /* Increase the hit count even though we don't stop. */
3953 observer_notify_breakpoint_modified (b
);
3959 /* Get a bpstat associated with having just stopped at address
3960 BP_ADDR in thread PTID.
3962 Determine whether we stopped at a breakpoint, etc, or whether we
3963 don't understand this stop. Result is a chain of bpstat's such
3966 if we don't understand the stop, the result is a null pointer.
3968 if we understand why we stopped, the result is not null.
3970 Each element of the chain refers to a particular breakpoint or
3971 watchpoint at which we have stopped. (We may have stopped for
3972 several reasons concurrently.)
3974 Each element of the chain has valid next, breakpoint_at,
3975 commands, FIXME??? fields. */
3978 bpstat_stop_status (struct address_space
*aspace
,
3979 CORE_ADDR bp_addr
, ptid_t ptid
)
3981 struct breakpoint
*b
= NULL
;
3982 struct bp_location
*bl
;
3983 struct bp_location
*loc
;
3984 /* First item of allocated bpstat's. */
3985 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
3986 /* Pointer to the last thing in the chain currently. */
3989 int need_remove_insert
;
3992 /* First, build the bpstat chain with locations that explain a
3993 target stop, while being careful to not set the target running,
3994 as that may invalidate locations (in particular watchpoint
3995 locations are recreated). Resuming will happen here with
3996 breakpoint conditions or watchpoint expressions that include
3997 inferior function calls. */
4001 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4004 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4006 /* For hardware watchpoints, we look only at the first
4007 location. The watchpoint_check function will work on the
4008 entire expression, not the individual locations. For
4009 read watchpoints, the watchpoints_triggered function has
4010 checked all locations already. */
4011 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4014 if (bl
->shlib_disabled
)
4017 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4020 /* Come here if it's a watchpoint, or if the break address
4023 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4026 /* Assume we stop. Should we find a watchpoint that is not
4027 actually triggered, or if the condition of the breakpoint
4028 evaluates as false, we'll reset 'stop' to 0. */
4032 /* If this is a scope breakpoint, mark the associated
4033 watchpoint as triggered so that we will handle the
4034 out-of-scope event. We'll get to the watchpoint next
4036 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4037 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4041 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4043 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4045 bs
= bpstat_alloc (loc
, &bs_link
);
4046 /* For hits of moribund locations, we should just proceed. */
4049 bs
->print_it
= print_it_noop
;
4053 /* Now go through the locations that caused the target to stop, and
4054 check whether we're interested in reporting this stop to higher
4055 layers, or whether we should resume the target transparently. */
4059 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4064 b
= bs
->breakpoint_at
;
4065 b
->ops
->check_status (bs
);
4068 bpstat_check_breakpoint_conditions (bs
, ptid
);
4073 observer_notify_breakpoint_modified (b
);
4075 /* We will stop here. */
4076 if (b
->disposition
== disp_disable
)
4078 if (b
->enable_state
!= bp_permanent
)
4079 b
->enable_state
= bp_disabled
;
4084 bs
->commands
= b
->commands
;
4085 incref_counted_command_line (bs
->commands
);
4086 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4087 if (bs
->commands_left
4088 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4091 bs
->commands_left
->line
) == 0)))
4093 bs
->commands_left
= bs
->commands_left
->next
;
4098 /* Print nothing for this entry if we don't stop or don't print. */
4099 if (bs
->stop
== 0 || bs
->print
== 0)
4100 bs
->print_it
= print_it_noop
;
4104 /* If we aren't stopping, the value of some hardware watchpoint may
4105 not have changed, but the intermediate memory locations we are
4106 watching may have. Don't bother if we're stopping; this will get
4108 need_remove_insert
= 0;
4109 if (! bpstat_causes_stop (bs_head
))
4110 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4112 && bs
->breakpoint_at
4113 && is_hardware_watchpoint (bs
->breakpoint_at
))
4115 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4116 need_remove_insert
= 1;
4119 if (need_remove_insert
)
4120 update_global_location_list (1);
4121 else if (removed_any
)
4122 update_global_location_list (0);
4128 handle_jit_event (void)
4130 struct frame_info
*frame
;
4131 struct gdbarch
*gdbarch
;
4133 /* Switch terminal for any messages produced by
4134 breakpoint_re_set. */
4135 target_terminal_ours_for_output ();
4137 frame
= get_current_frame ();
4138 gdbarch
= get_frame_arch (frame
);
4140 jit_event_handler (gdbarch
);
4142 target_terminal_inferior ();
4145 /* Prepare WHAT final decision for infrun. */
4147 /* Decide what infrun needs to do with this bpstat. */
4150 bpstat_what (bpstat bs_head
)
4152 struct bpstat_what retval
;
4153 /* We need to defer calling `solib_add', as adding new symbols
4154 resets breakpoints, which in turn deletes breakpoint locations,
4155 and hence may clear unprocessed entries in the BS chain. */
4156 int shlib_event
= 0;
4160 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4161 retval
.call_dummy
= STOP_NONE
;
4162 retval
.is_longjmp
= 0;
4164 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4166 /* Extract this BS's action. After processing each BS, we check
4167 if its action overrides all we've seem so far. */
4168 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4171 if (bs
->breakpoint_at
== NULL
)
4173 /* I suspect this can happen if it was a momentary
4174 breakpoint which has since been deleted. */
4178 bptype
= bs
->breakpoint_at
->type
;
4185 case bp_hardware_breakpoint
:
4191 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4193 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4196 this_action
= BPSTAT_WHAT_SINGLE
;
4199 case bp_hardware_watchpoint
:
4200 case bp_read_watchpoint
:
4201 case bp_access_watchpoint
:
4205 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4207 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4211 /* There was a watchpoint, but we're not stopping.
4212 This requires no further action. */
4217 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4218 retval
.is_longjmp
= bptype
== bp_longjmp
;
4220 case bp_longjmp_resume
:
4221 case bp_exception_resume
:
4222 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4223 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4225 case bp_step_resume
:
4227 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4230 /* It is for the wrong frame. */
4231 this_action
= BPSTAT_WHAT_SINGLE
;
4234 case bp_hp_step_resume
:
4236 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4239 /* It is for the wrong frame. */
4240 this_action
= BPSTAT_WHAT_SINGLE
;
4243 case bp_watchpoint_scope
:
4244 case bp_thread_event
:
4245 case bp_overlay_event
:
4246 case bp_longjmp_master
:
4247 case bp_std_terminate_master
:
4248 case bp_exception_master
:
4249 this_action
= BPSTAT_WHAT_SINGLE
;
4255 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4257 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4261 /* There was a catchpoint, but we're not stopping.
4262 This requires no further action. */
4265 case bp_shlib_event
:
4268 /* If requested, stop when the dynamic linker notifies GDB
4269 of events. This allows the user to get control and place
4270 breakpoints in initializer routines for dynamically
4271 loaded objects (among other things). */
4272 if (stop_on_solib_events
)
4273 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4275 this_action
= BPSTAT_WHAT_SINGLE
;
4279 this_action
= BPSTAT_WHAT_SINGLE
;
4282 /* Make sure the action is stop (silent or noisy),
4283 so infrun.c pops the dummy frame. */
4284 retval
.call_dummy
= STOP_STACK_DUMMY
;
4285 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4287 case bp_std_terminate
:
4288 /* Make sure the action is stop (silent or noisy),
4289 so infrun.c pops the dummy frame. */
4290 retval
.call_dummy
= STOP_STD_TERMINATE
;
4291 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4294 case bp_fast_tracepoint
:
4295 case bp_static_tracepoint
:
4296 /* Tracepoint hits should not be reported back to GDB, and
4297 if one got through somehow, it should have been filtered
4299 internal_error (__FILE__
, __LINE__
,
4300 _("bpstat_what: tracepoint encountered"));
4302 case bp_gnu_ifunc_resolver
:
4303 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4304 this_action
= BPSTAT_WHAT_SINGLE
;
4306 case bp_gnu_ifunc_resolver_return
:
4307 /* The breakpoint will be removed, execution will restart from the
4308 PC of the former breakpoint. */
4309 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4312 internal_error (__FILE__
, __LINE__
,
4313 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4316 retval
.main_action
= max (retval
.main_action
, this_action
);
4319 /* These operations may affect the bs->breakpoint_at state so they are
4320 delayed after MAIN_ACTION is decided above. */
4325 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4327 /* Check for any newly added shared libraries if we're supposed
4328 to be adding them automatically. */
4330 /* Switch terminal for any messages produced by
4331 breakpoint_re_set. */
4332 target_terminal_ours_for_output ();
4335 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4337 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4340 target_terminal_inferior ();
4346 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4348 handle_jit_event ();
4351 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4353 struct breakpoint
*b
= bs
->breakpoint_at
;
4359 case bp_gnu_ifunc_resolver
:
4360 gnu_ifunc_resolver_stop (b
);
4362 case bp_gnu_ifunc_resolver_return
:
4363 gnu_ifunc_resolver_return_stop (b
);
4371 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4372 without hardware support). This isn't related to a specific bpstat,
4373 just to things like whether watchpoints are set. */
4376 bpstat_should_step (void)
4378 struct breakpoint
*b
;
4381 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4387 bpstat_causes_stop (bpstat bs
)
4389 for (; bs
!= NULL
; bs
= bs
->next
)
4398 /* Compute a string of spaces suitable to indent the next line
4399 so it starts at the position corresponding to the table column
4400 named COL_NAME in the currently active table of UIOUT. */
4403 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4405 static char wrap_indent
[80];
4406 int i
, total_width
, width
, align
;
4410 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4412 if (strcmp (text
, col_name
) == 0)
4414 gdb_assert (total_width
< sizeof wrap_indent
);
4415 memset (wrap_indent
, ' ', total_width
);
4416 wrap_indent
[total_width
] = 0;
4421 total_width
+= width
+ 1;
4427 /* Print the LOC location out of the list of B->LOC locations. */
4430 print_breakpoint_location (struct breakpoint
*b
,
4431 struct bp_location
*loc
)
4433 struct cleanup
*old_chain
= save_current_program_space ();
4435 if (loc
!= NULL
&& loc
->shlib_disabled
)
4439 set_current_program_space (loc
->pspace
);
4441 if (b
->display_canonical
)
4442 ui_out_field_string (uiout
, "what", b
->addr_string
);
4443 else if (b
->source_file
&& loc
)
4446 = find_pc_sect_function (loc
->address
, loc
->section
);
4449 ui_out_text (uiout
, "in ");
4450 ui_out_field_string (uiout
, "func",
4451 SYMBOL_PRINT_NAME (sym
));
4452 ui_out_text (uiout
, " ");
4453 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4454 ui_out_text (uiout
, "at ");
4456 ui_out_field_string (uiout
, "file", b
->source_file
);
4457 ui_out_text (uiout
, ":");
4459 if (ui_out_is_mi_like_p (uiout
))
4461 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4462 char *fullname
= symtab_to_fullname (sal
.symtab
);
4465 ui_out_field_string (uiout
, "fullname", fullname
);
4468 ui_out_field_int (uiout
, "line", b
->line_number
);
4472 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4473 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4475 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4477 ui_out_field_stream (uiout
, "at", stb
);
4479 do_cleanups (stb_chain
);
4482 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4484 do_cleanups (old_chain
);
4488 bptype_string (enum bptype type
)
4490 struct ep_type_description
4495 static struct ep_type_description bptypes
[] =
4497 {bp_none
, "?deleted?"},
4498 {bp_breakpoint
, "breakpoint"},
4499 {bp_hardware_breakpoint
, "hw breakpoint"},
4500 {bp_until
, "until"},
4501 {bp_finish
, "finish"},
4502 {bp_watchpoint
, "watchpoint"},
4503 {bp_hardware_watchpoint
, "hw watchpoint"},
4504 {bp_read_watchpoint
, "read watchpoint"},
4505 {bp_access_watchpoint
, "acc watchpoint"},
4506 {bp_longjmp
, "longjmp"},
4507 {bp_longjmp_resume
, "longjmp resume"},
4508 {bp_exception
, "exception"},
4509 {bp_exception_resume
, "exception resume"},
4510 {bp_step_resume
, "step resume"},
4511 {bp_hp_step_resume
, "high-priority step resume"},
4512 {bp_watchpoint_scope
, "watchpoint scope"},
4513 {bp_call_dummy
, "call dummy"},
4514 {bp_std_terminate
, "std::terminate"},
4515 {bp_shlib_event
, "shlib events"},
4516 {bp_thread_event
, "thread events"},
4517 {bp_overlay_event
, "overlay events"},
4518 {bp_longjmp_master
, "longjmp master"},
4519 {bp_std_terminate_master
, "std::terminate master"},
4520 {bp_exception_master
, "exception master"},
4521 {bp_catchpoint
, "catchpoint"},
4522 {bp_tracepoint
, "tracepoint"},
4523 {bp_fast_tracepoint
, "fast tracepoint"},
4524 {bp_static_tracepoint
, "static tracepoint"},
4525 {bp_jit_event
, "jit events"},
4526 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4527 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4530 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4531 || ((int) type
!= bptypes
[(int) type
].type
))
4532 internal_error (__FILE__
, __LINE__
,
4533 _("bptypes table does not describe type #%d."),
4536 return bptypes
[(int) type
].description
;
4539 /* Print B to gdb_stdout. */
4542 print_one_breakpoint_location (struct breakpoint
*b
,
4543 struct bp_location
*loc
,
4545 struct bp_location
**last_loc
,
4548 struct command_line
*l
;
4549 static char bpenables
[] = "nynny";
4551 int header_of_multiple
= 0;
4552 int part_of_multiple
= (loc
!= NULL
);
4553 struct value_print_options opts
;
4555 get_user_print_options (&opts
);
4557 gdb_assert (!loc
|| loc_number
!= 0);
4558 /* See comment in print_one_breakpoint concerning treatment of
4559 breakpoints with single disabled location. */
4562 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4563 header_of_multiple
= 1;
4571 if (part_of_multiple
)
4574 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4575 ui_out_field_string (uiout
, "number", formatted
);
4580 ui_out_field_int (uiout
, "number", b
->number
);
4585 if (part_of_multiple
)
4586 ui_out_field_skip (uiout
, "type");
4588 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4592 if (part_of_multiple
)
4593 ui_out_field_skip (uiout
, "disp");
4595 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4600 if (part_of_multiple
)
4601 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4603 ui_out_field_fmt (uiout
, "enabled", "%c",
4604 bpenables
[(int) b
->enable_state
]);
4605 ui_out_spaces (uiout
, 2);
4609 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4611 /* Although the print_one can possibly print all locations,
4612 calling it here is not likely to get any nice result. So,
4613 make sure there's just one location. */
4614 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4615 b
->ops
->print_one (b
, last_loc
);
4621 internal_error (__FILE__
, __LINE__
,
4622 _("print_one_breakpoint: bp_none encountered\n"));
4626 case bp_hardware_watchpoint
:
4627 case bp_read_watchpoint
:
4628 case bp_access_watchpoint
:
4629 /* Field 4, the address, is omitted (which makes the columns
4630 not line up too nicely with the headers, but the effect
4631 is relatively readable). */
4632 if (opts
.addressprint
)
4633 ui_out_field_skip (uiout
, "addr");
4635 ui_out_field_string (uiout
, "what", b
->exp_string
);
4639 case bp_hardware_breakpoint
:
4643 case bp_longjmp_resume
:
4645 case bp_exception_resume
:
4646 case bp_step_resume
:
4647 case bp_hp_step_resume
:
4648 case bp_watchpoint_scope
:
4650 case bp_std_terminate
:
4651 case bp_shlib_event
:
4652 case bp_thread_event
:
4653 case bp_overlay_event
:
4654 case bp_longjmp_master
:
4655 case bp_std_terminate_master
:
4656 case bp_exception_master
:
4658 case bp_fast_tracepoint
:
4659 case bp_static_tracepoint
:
4661 case bp_gnu_ifunc_resolver
:
4662 case bp_gnu_ifunc_resolver_return
:
4663 if (opts
.addressprint
)
4666 if (header_of_multiple
)
4667 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4668 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4669 ui_out_field_string (uiout
, "addr", "<PENDING>");
4671 ui_out_field_core_addr (uiout
, "addr",
4672 loc
->gdbarch
, loc
->address
);
4675 if (!header_of_multiple
)
4676 print_breakpoint_location (b
, loc
);
4683 /* For backward compatibility, don't display inferiors unless there
4686 && !header_of_multiple
4688 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4689 && (number_of_program_spaces () > 1
4690 || number_of_inferiors () > 1)
4691 /* LOC is for existing B, it cannot be in
4692 moribund_locations and thus having NULL OWNER. */
4693 && loc
->owner
->type
!= bp_catchpoint
)))
4695 struct inferior
*inf
;
4698 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4700 if (inf
->pspace
== loc
->pspace
)
4705 ui_out_text (uiout
, " inf ");
4708 ui_out_text (uiout
, ", ");
4709 ui_out_text (uiout
, plongest (inf
->num
));
4714 if (!part_of_multiple
)
4716 if (b
->thread
!= -1)
4718 /* FIXME: This seems to be redundant and lost here; see the
4719 "stop only in" line a little further down. */
4720 ui_out_text (uiout
, " thread ");
4721 ui_out_field_int (uiout
, "thread", b
->thread
);
4723 else if (b
->task
!= 0)
4725 ui_out_text (uiout
, " task ");
4726 ui_out_field_int (uiout
, "task", b
->task
);
4730 ui_out_text (uiout
, "\n");
4732 if (!part_of_multiple
)
4733 b
->ops
->print_one_detail (b
, uiout
);
4735 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4738 ui_out_text (uiout
, "\tstop only in stack frame at ");
4739 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4741 ui_out_field_core_addr (uiout
, "frame",
4742 b
->gdbarch
, b
->frame_id
.stack_addr
);
4743 ui_out_text (uiout
, "\n");
4746 if (!part_of_multiple
&& b
->cond_string
)
4749 if (is_tracepoint (b
))
4750 ui_out_text (uiout
, "\ttrace only if ");
4752 ui_out_text (uiout
, "\tstop only if ");
4753 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4754 ui_out_text (uiout
, "\n");
4757 if (!part_of_multiple
&& b
->thread
!= -1)
4759 /* FIXME should make an annotation for this. */
4760 ui_out_text (uiout
, "\tstop only in thread ");
4761 ui_out_field_int (uiout
, "thread", b
->thread
);
4762 ui_out_text (uiout
, "\n");
4765 if (!part_of_multiple
&& b
->hit_count
)
4767 /* FIXME should make an annotation for this. */
4768 if (ep_is_catchpoint (b
))
4769 ui_out_text (uiout
, "\tcatchpoint");
4771 ui_out_text (uiout
, "\tbreakpoint");
4772 ui_out_text (uiout
, " already hit ");
4773 ui_out_field_int (uiout
, "times", b
->hit_count
);
4774 if (b
->hit_count
== 1)
4775 ui_out_text (uiout
, " time\n");
4777 ui_out_text (uiout
, " times\n");
4780 /* Output the count also if it is zero, but only if this is mi.
4781 FIXME: Should have a better test for this. */
4782 if (ui_out_is_mi_like_p (uiout
))
4783 if (!part_of_multiple
&& b
->hit_count
== 0)
4784 ui_out_field_int (uiout
, "times", b
->hit_count
);
4786 if (!part_of_multiple
&& b
->ignore_count
)
4789 ui_out_text (uiout
, "\tignore next ");
4790 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4791 ui_out_text (uiout
, " hits\n");
4794 l
= b
->commands
? b
->commands
->commands
: NULL
;
4795 if (!part_of_multiple
&& l
)
4797 struct cleanup
*script_chain
;
4800 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4801 print_command_lines (uiout
, l
, 4);
4802 do_cleanups (script_chain
);
4805 if (!part_of_multiple
&& b
->pass_count
)
4807 annotate_field (10);
4808 ui_out_text (uiout
, "\tpass count ");
4809 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4810 ui_out_text (uiout
, " \n");
4813 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4816 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4817 else if (b
->exp_string
)
4818 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4823 print_one_breakpoint (struct breakpoint
*b
,
4824 struct bp_location
**last_loc
,
4827 struct cleanup
*bkpt_chain
;
4829 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4831 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
4832 do_cleanups (bkpt_chain
);
4834 /* If this breakpoint has custom print function,
4835 it's already printed. Otherwise, print individual
4836 locations, if any. */
4837 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4839 /* If breakpoint has a single location that is disabled, we
4840 print it as if it had several locations, since otherwise it's
4841 hard to represent "breakpoint enabled, location disabled"
4844 Note that while hardware watchpoints have several locations
4845 internally, that's not a property exposed to user. */
4847 && !is_hardware_watchpoint (b
)
4848 && (b
->loc
->next
|| !b
->loc
->enabled
))
4850 struct bp_location
*loc
;
4853 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4855 struct cleanup
*inner2
=
4856 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
4857 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
4858 do_cleanups (inner2
);
4865 breakpoint_address_bits (struct breakpoint
*b
)
4867 int print_address_bits
= 0;
4868 struct bp_location
*loc
;
4870 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4874 /* Software watchpoints that aren't watching memory don't have
4875 an address to print. */
4876 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4879 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4880 if (addr_bit
> print_address_bits
)
4881 print_address_bits
= addr_bit
;
4884 return print_address_bits
;
4887 struct captured_breakpoint_query_args
4893 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4895 struct captured_breakpoint_query_args
*args
= data
;
4896 struct breakpoint
*b
;
4897 struct bp_location
*dummy_loc
= NULL
;
4901 if (args
->bnum
== b
->number
)
4903 print_one_breakpoint (b
, &dummy_loc
, 0);
4911 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
4912 char **error_message
)
4914 struct captured_breakpoint_query_args args
;
4917 /* For the moment we don't trust print_one_breakpoint() to not throw
4919 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4920 error_message
, RETURN_MASK_ALL
) < 0)
4926 /* Return true if this breakpoint was set by the user, false if it is
4927 internal or momentary. */
4930 user_breakpoint_p (struct breakpoint
*b
)
4932 return b
->number
> 0;
4935 /* Print information on user settable breakpoint (watchpoint, etc)
4936 number BNUM. If BNUM is -1 print all user-settable breakpoints.
4937 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
4938 FILTER is non-NULL, call it on each breakpoint and only include the
4939 ones for which it returns non-zero. Return the total number of
4940 breakpoints listed. */
4943 breakpoint_1 (char *args
, int allflag
,
4944 int (*filter
) (const struct breakpoint
*))
4946 struct breakpoint
*b
;
4947 struct bp_location
*last_loc
= NULL
;
4948 int nr_printable_breakpoints
;
4949 struct cleanup
*bkpttbl_chain
;
4950 struct value_print_options opts
;
4951 int print_address_bits
= 0;
4952 int print_type_col_width
= 14;
4954 get_user_print_options (&opts
);
4956 /* Compute the number of rows in the table, as well as the size
4957 required for address fields. */
4958 nr_printable_breakpoints
= 0;
4961 /* If we have a filter, only list the breakpoints it accepts. */
4962 if (filter
&& !filter (b
))
4965 /* If we have an "args" string, it is a list of breakpoints to
4966 accept. Skip the others. */
4967 if (args
!= NULL
&& *args
!= '\0')
4969 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
4971 if (!allflag
&& !number_is_in_list (args
, b
->number
))
4975 if (allflag
|| user_breakpoint_p (b
))
4977 int addr_bit
, type_len
;
4979 addr_bit
= breakpoint_address_bits (b
);
4980 if (addr_bit
> print_address_bits
)
4981 print_address_bits
= addr_bit
;
4983 type_len
= strlen (bptype_string (b
->type
));
4984 if (type_len
> print_type_col_width
)
4985 print_type_col_width
= type_len
;
4987 nr_printable_breakpoints
++;
4991 if (opts
.addressprint
)
4993 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
4994 nr_printable_breakpoints
,
4998 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
4999 nr_printable_breakpoints
,
5002 if (nr_printable_breakpoints
> 0)
5003 annotate_breakpoints_headers ();
5004 if (nr_printable_breakpoints
> 0)
5006 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5007 if (nr_printable_breakpoints
> 0)
5009 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5010 "type", "Type"); /* 2 */
5011 if (nr_printable_breakpoints
> 0)
5013 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5014 if (nr_printable_breakpoints
> 0)
5016 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5017 if (opts
.addressprint
)
5019 if (nr_printable_breakpoints
> 0)
5021 if (print_address_bits
<= 32)
5022 ui_out_table_header (uiout
, 10, ui_left
,
5023 "addr", "Address"); /* 5 */
5025 ui_out_table_header (uiout
, 18, ui_left
,
5026 "addr", "Address"); /* 5 */
5028 if (nr_printable_breakpoints
> 0)
5030 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5031 ui_out_table_body (uiout
);
5032 if (nr_printable_breakpoints
> 0)
5033 annotate_breakpoints_table ();
5038 /* If we have a filter, only list the breakpoints it accepts. */
5039 if (filter
&& !filter (b
))
5042 /* If we have an "args" string, it is a list of breakpoints to
5043 accept. Skip the others. */
5045 if (args
!= NULL
&& *args
!= '\0')
5047 if (allflag
) /* maintenance info breakpoint */
5049 if (parse_and_eval_long (args
) != b
->number
)
5052 else /* all others */
5054 if (!number_is_in_list (args
, b
->number
))
5058 /* We only print out user settable breakpoints unless the
5060 if (allflag
|| user_breakpoint_p (b
))
5061 print_one_breakpoint (b
, &last_loc
, allflag
);
5064 do_cleanups (bkpttbl_chain
);
5066 if (nr_printable_breakpoints
== 0)
5068 /* If there's a filter, let the caller decide how to report
5072 if (args
== NULL
|| *args
== '\0')
5073 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5075 ui_out_message (uiout
, 0,
5076 "No breakpoint or watchpoint matching '%s'.\n",
5082 if (last_loc
&& !server_command
)
5083 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5086 /* FIXME? Should this be moved up so that it is only called when
5087 there have been breakpoints? */
5088 annotate_breakpoints_table_end ();
5090 return nr_printable_breakpoints
;
5093 /* Display the value of default-collect in a way that is generally
5094 compatible with the breakpoint list. */
5097 default_collect_info (void)
5099 /* If it has no value (which is frequently the case), say nothing; a
5100 message like "No default-collect." gets in user's face when it's
5102 if (!*default_collect
)
5105 /* The following phrase lines up nicely with per-tracepoint collect
5107 ui_out_text (uiout
, "default collect ");
5108 ui_out_field_string (uiout
, "default-collect", default_collect
);
5109 ui_out_text (uiout
, " \n");
5113 breakpoints_info (char *args
, int from_tty
)
5115 breakpoint_1 (args
, 0, NULL
);
5117 default_collect_info ();
5121 watchpoints_info (char *args
, int from_tty
)
5123 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5125 if (num_printed
== 0)
5127 if (args
== NULL
|| *args
== '\0')
5128 ui_out_message (uiout
, 0, "No watchpoints.\n");
5130 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5135 maintenance_info_breakpoints (char *args
, int from_tty
)
5137 breakpoint_1 (args
, 1, NULL
);
5139 default_collect_info ();
5143 breakpoint_has_pc (struct breakpoint
*b
,
5144 struct program_space
*pspace
,
5145 CORE_ADDR pc
, struct obj_section
*section
)
5147 struct bp_location
*bl
= b
->loc
;
5149 for (; bl
; bl
= bl
->next
)
5151 if (bl
->pspace
== pspace
5152 && bl
->address
== pc
5153 && (!overlay_debugging
|| bl
->section
== section
))
5159 /* Print a message describing any breakpoints set at PC. This
5160 concerns with logical breakpoints, so we match program spaces, not
5164 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5165 struct program_space
*pspace
, CORE_ADDR pc
,
5166 struct obj_section
*section
, int thread
)
5169 struct breakpoint
*b
;
5172 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5176 printf_filtered (_("Note: breakpoint "));
5177 else /* if (others == ???) */
5178 printf_filtered (_("Note: breakpoints "));
5180 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5183 printf_filtered ("%d", b
->number
);
5184 if (b
->thread
== -1 && thread
!= -1)
5185 printf_filtered (" (all threads)");
5186 else if (b
->thread
!= -1)
5187 printf_filtered (" (thread %d)", b
->thread
);
5188 printf_filtered ("%s%s ",
5189 ((b
->enable_state
== bp_disabled
5190 || b
->enable_state
== bp_call_disabled
5191 || b
->enable_state
== bp_startup_disabled
)
5193 : b
->enable_state
== bp_permanent
5197 : ((others
== 1) ? " and" : ""));
5199 printf_filtered (_("also set at pc "));
5200 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5201 printf_filtered (".\n");
5205 /* Set the default place to put a breakpoint
5206 for the `break' command with no arguments. */
5209 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5210 CORE_ADDR addr
, struct symtab
*symtab
,
5213 default_breakpoint_valid
= valid
;
5214 default_breakpoint_pspace
= pspace
;
5215 default_breakpoint_address
= addr
;
5216 default_breakpoint_symtab
= symtab
;
5217 default_breakpoint_line
= line
;
5220 /* Return true iff it is meaningful to use the address member of
5221 BPT. For some breakpoint types, the address member is irrelevant
5222 and it makes no sense to attempt to compare it to other addresses
5223 (or use it for any other purpose either).
5225 More specifically, each of the following breakpoint types will
5226 always have a zero valued address and we don't want to mark
5227 breakpoints of any of these types to be a duplicate of an actual
5228 breakpoint at address zero:
5236 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5238 enum bptype type
= bpt
->type
;
5240 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5243 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5244 true if LOC1 and LOC2 represent the same watchpoint location. */
5247 watchpoint_locations_match (struct bp_location
*loc1
,
5248 struct bp_location
*loc2
)
5250 /* Both of them must not be in moribund_locations. */
5251 gdb_assert (loc1
->owner
!= NULL
);
5252 gdb_assert (loc2
->owner
!= NULL
);
5254 /* If the target can evaluate the condition expression in hardware,
5255 then we we need to insert both watchpoints even if they are at
5256 the same place. Otherwise the watchpoint will only trigger when
5257 the condition of whichever watchpoint was inserted evaluates to
5258 true, not giving a chance for GDB to check the condition of the
5259 other watchpoint. */
5260 if ((loc1
->owner
->cond_exp
5261 && target_can_accel_watchpoint_condition (loc1
->address
,
5263 loc1
->watchpoint_type
,
5264 loc1
->owner
->cond_exp
))
5265 || (loc2
->owner
->cond_exp
5266 && target_can_accel_watchpoint_condition (loc2
->address
,
5268 loc2
->watchpoint_type
,
5269 loc2
->owner
->cond_exp
)))
5272 /* Note that this checks the owner's type, not the location's. In
5273 case the target does not support read watchpoints, but does
5274 support access watchpoints, we'll have bp_read_watchpoint
5275 watchpoints with hw_access locations. Those should be considered
5276 duplicates of hw_read locations. The hw_read locations will
5277 become hw_access locations later. */
5278 return (loc1
->owner
->type
== loc2
->owner
->type
5279 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5280 && loc1
->address
== loc2
->address
5281 && loc1
->length
== loc2
->length
);
5284 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5285 same breakpoint location. In most targets, this can only be true
5286 if ASPACE1 matches ASPACE2. On targets that have global
5287 breakpoints, the address space doesn't really matter. */
5290 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5291 struct address_space
*aspace2
, CORE_ADDR addr2
)
5293 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5294 || aspace1
== aspace2
)
5298 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5299 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5300 matches ASPACE2. On targets that have global breakpoints, the address
5301 space doesn't really matter. */
5304 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5305 int len1
, struct address_space
*aspace2
,
5308 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5309 || aspace1
== aspace2
)
5310 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5313 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5314 a ranged breakpoint. In most targets, a match happens only if ASPACE
5315 matches the breakpoint's address space. On targets that have global
5316 breakpoints, the address space doesn't really matter. */
5319 breakpoint_location_address_match (struct bp_location
*bl
,
5320 struct address_space
*aspace
,
5323 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5326 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5327 bl
->address
, bl
->length
,
5331 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5332 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5333 represent the same location. */
5336 breakpoint_locations_match (struct bp_location
*loc1
,
5337 struct bp_location
*loc2
)
5339 int hw_point1
, hw_point2
;
5341 /* Both of them must not be in moribund_locations. */
5342 gdb_assert (loc1
->owner
!= NULL
);
5343 gdb_assert (loc2
->owner
!= NULL
);
5345 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5346 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5348 if (hw_point1
!= hw_point2
)
5351 return watchpoint_locations_match (loc1
, loc2
);
5353 /* We compare bp_location.length in order to cover ranged breakpoints. */
5354 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5355 loc2
->pspace
->aspace
, loc2
->address
)
5356 && loc1
->length
== loc2
->length
);
5360 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5361 int bnum
, int have_bnum
)
5363 /* The longest string possibly returned by hex_string_custom
5364 is 50 chars. These must be at least that big for safety. */
5368 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5369 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5371 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5372 bnum
, astr1
, astr2
);
5374 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5377 /* Adjust a breakpoint's address to account for architectural
5378 constraints on breakpoint placement. Return the adjusted address.
5379 Note: Very few targets require this kind of adjustment. For most
5380 targets, this function is simply the identity function. */
5383 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5384 CORE_ADDR bpaddr
, enum bptype bptype
)
5386 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5388 /* Very few targets need any kind of breakpoint adjustment. */
5391 else if (bptype
== bp_watchpoint
5392 || bptype
== bp_hardware_watchpoint
5393 || bptype
== bp_read_watchpoint
5394 || bptype
== bp_access_watchpoint
5395 || bptype
== bp_catchpoint
)
5397 /* Watchpoints and the various bp_catch_* eventpoints should not
5398 have their addresses modified. */
5403 CORE_ADDR adjusted_bpaddr
;
5405 /* Some targets have architectural constraints on the placement
5406 of breakpoint instructions. Obtain the adjusted address. */
5407 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5409 /* An adjusted breakpoint address can significantly alter
5410 a user's expectations. Print a warning if an adjustment
5412 if (adjusted_bpaddr
!= bpaddr
)
5413 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5415 return adjusted_bpaddr
;
5420 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5421 struct breakpoint
*owner
)
5423 memset (loc
, 0, sizeof (*loc
));
5425 gdb_assert (ops
!= NULL
);
5430 loc
->shlib_disabled
= 0;
5433 switch (owner
->type
)
5439 case bp_longjmp_resume
:
5441 case bp_exception_resume
:
5442 case bp_step_resume
:
5443 case bp_hp_step_resume
:
5444 case bp_watchpoint_scope
:
5446 case bp_std_terminate
:
5447 case bp_shlib_event
:
5448 case bp_thread_event
:
5449 case bp_overlay_event
:
5451 case bp_longjmp_master
:
5452 case bp_std_terminate_master
:
5453 case bp_exception_master
:
5454 case bp_gnu_ifunc_resolver
:
5455 case bp_gnu_ifunc_resolver_return
:
5456 loc
->loc_type
= bp_loc_software_breakpoint
;
5458 case bp_hardware_breakpoint
:
5459 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5461 case bp_hardware_watchpoint
:
5462 case bp_read_watchpoint
:
5463 case bp_access_watchpoint
:
5464 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5469 case bp_fast_tracepoint
:
5470 case bp_static_tracepoint
:
5471 loc
->loc_type
= bp_loc_other
;
5474 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5480 /* Allocate a struct bp_location. */
5482 static struct bp_location
*
5483 allocate_bp_location (struct breakpoint
*bpt
)
5485 return bpt
->ops
->allocate_location (bpt
);
5489 free_bp_location (struct bp_location
*loc
)
5491 loc
->ops
->dtor (loc
);
5495 /* Increment reference count. */
5498 incref_bp_location (struct bp_location
*bl
)
5503 /* Decrement reference count. If the reference count reaches 0,
5504 destroy the bp_location. Sets *BLP to NULL. */
5507 decref_bp_location (struct bp_location
**blp
)
5509 gdb_assert ((*blp
)->refc
> 0);
5511 if (--(*blp
)->refc
== 0)
5512 free_bp_location (*blp
);
5516 /* Add breakpoint B at the end of the global breakpoint chain. */
5519 add_to_breakpoint_chain (struct breakpoint
*b
)
5521 struct breakpoint
*b1
;
5523 /* Add this breakpoint to the end of the chain so that a list of
5524 breakpoints will come out in order of increasing numbers. */
5526 b1
= breakpoint_chain
;
5528 breakpoint_chain
= b
;
5537 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5540 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5541 struct gdbarch
*gdbarch
,
5543 struct breakpoint_ops
*ops
)
5545 memset (b
, 0, sizeof (*b
));
5547 gdb_assert (ops
!= NULL
);
5551 b
->gdbarch
= gdbarch
;
5552 b
->language
= current_language
->la_language
;
5553 b
->input_radix
= input_radix
;
5555 b
->enable_state
= bp_enabled
;
5558 b
->ignore_count
= 0;
5560 b
->frame_id
= null_frame_id
;
5561 b
->condition_not_parsed
= 0;
5562 b
->py_bp_object
= NULL
;
5563 b
->related_breakpoint
= b
;
5566 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5567 that has type BPTYPE and has no locations as yet. */
5569 static struct breakpoint
*
5570 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5572 struct breakpoint_ops
*ops
)
5574 struct breakpoint
*b
= XNEW (struct breakpoint
);
5576 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5577 add_to_breakpoint_chain (b
);
5581 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5582 resolutions should be made as the user specified the location explicitly
5586 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5588 gdb_assert (loc
->owner
!= NULL
);
5590 if (loc
->owner
->type
== bp_breakpoint
5591 || loc
->owner
->type
== bp_hardware_breakpoint
5592 || is_tracepoint (loc
->owner
))
5596 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5597 NULL
, NULL
, &is_gnu_ifunc
);
5599 if (is_gnu_ifunc
&& !explicit_loc
)
5601 struct breakpoint
*b
= loc
->owner
;
5603 gdb_assert (loc
->pspace
== current_program_space
);
5604 if (gnu_ifunc_resolve_name (loc
->function_name
,
5605 &loc
->requested_address
))
5607 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5608 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5609 loc
->requested_address
,
5612 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5613 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5615 /* Create only the whole new breakpoint of this type but do not
5616 mess more complicated breakpoints with multiple locations. */
5617 b
->type
= bp_gnu_ifunc_resolver
;
5621 if (loc
->function_name
)
5622 loc
->function_name
= xstrdup (loc
->function_name
);
5626 /* Attempt to determine architecture of location identified by SAL. */
5627 static struct gdbarch
*
5628 get_sal_arch (struct symtab_and_line sal
)
5631 return get_objfile_arch (sal
.section
->objfile
);
5633 return get_objfile_arch (sal
.symtab
->objfile
);
5638 /* Low level routine for partially initializing a breakpoint of type
5639 BPTYPE. The newly created breakpoint's address, section, source
5640 file name, and line number are provided by SAL.
5642 It is expected that the caller will complete the initialization of
5643 the newly created breakpoint struct as well as output any status
5644 information regarding the creation of a new breakpoint. */
5647 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5648 struct symtab_and_line sal
, enum bptype bptype
,
5649 struct breakpoint_ops
*ops
)
5651 CORE_ADDR adjusted_address
;
5652 struct gdbarch
*loc_gdbarch
;
5654 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5656 loc_gdbarch
= get_sal_arch (sal
);
5658 loc_gdbarch
= b
->gdbarch
;
5660 if (bptype
!= bp_catchpoint
)
5661 gdb_assert (sal
.pspace
!= NULL
);
5663 /* Adjust the breakpoint's address prior to allocating a location.
5664 Once we call allocate_bp_location(), that mostly uninitialized
5665 location will be placed on the location chain. Adjustment of the
5666 breakpoint may cause target_read_memory() to be called and we do
5667 not want its scan of the location chain to find a breakpoint and
5668 location that's only been partially initialized. */
5669 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5672 b
->loc
= allocate_bp_location (b
);
5673 b
->loc
->gdbarch
= loc_gdbarch
;
5674 b
->loc
->requested_address
= sal
.pc
;
5675 b
->loc
->address
= adjusted_address
;
5676 b
->loc
->pspace
= sal
.pspace
;
5678 /* Store the program space that was used to set the breakpoint, for
5679 breakpoint resetting. */
5680 b
->pspace
= sal
.pspace
;
5682 if (sal
.symtab
== NULL
)
5683 b
->source_file
= NULL
;
5685 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5686 b
->loc
->section
= sal
.section
;
5687 b
->line_number
= sal
.line
;
5689 set_breakpoint_location_function (b
->loc
,
5690 sal
.explicit_pc
|| sal
.explicit_line
);
5692 breakpoints_changed ();
5695 /* set_raw_breakpoint is a low level routine for allocating and
5696 partially initializing a breakpoint of type BPTYPE. The newly
5697 created breakpoint's address, section, source file name, and line
5698 number are provided by SAL. The newly created and partially
5699 initialized breakpoint is added to the breakpoint chain and
5700 is also returned as the value of this function.
5702 It is expected that the caller will complete the initialization of
5703 the newly created breakpoint struct as well as output any status
5704 information regarding the creation of a new breakpoint. In
5705 particular, set_raw_breakpoint does NOT set the breakpoint
5706 number! Care should be taken to not allow an error to occur
5707 prior to completing the initialization of the breakpoint. If this
5708 should happen, a bogus breakpoint will be left on the chain. */
5711 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5712 struct symtab_and_line sal
, enum bptype bptype
,
5713 struct breakpoint_ops
*ops
)
5715 struct breakpoint
*b
= XNEW (struct breakpoint
);
5717 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5718 add_to_breakpoint_chain (b
);
5723 /* Note that the breakpoint object B describes a permanent breakpoint
5724 instruction, hard-wired into the inferior's code. */
5726 make_breakpoint_permanent (struct breakpoint
*b
)
5728 struct bp_location
*bl
;
5730 b
->enable_state
= bp_permanent
;
5732 /* By definition, permanent breakpoints are already present in the
5733 code. Mark all locations as inserted. For now,
5734 make_breakpoint_permanent is called in just one place, so it's
5735 hard to say if it's reasonable to have permanent breakpoint with
5736 multiple locations or not, but it's easy to implement. */
5737 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5741 /* Call this routine when stepping and nexting to enable a breakpoint
5742 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5743 initiated the operation. */
5746 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5748 struct breakpoint
*b
, *b_tmp
;
5749 int thread
= tp
->num
;
5751 /* To avoid having to rescan all objfile symbols at every step,
5752 we maintain a list of continually-inserted but always disabled
5753 longjmp "master" breakpoints. Here, we simply create momentary
5754 clones of those and enable them for the requested thread. */
5755 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5756 if (b
->pspace
== current_program_space
5757 && (b
->type
== bp_longjmp_master
5758 || b
->type
== bp_exception_master
))
5760 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5761 struct breakpoint
*clone
;
5763 clone
= momentary_breakpoint_from_master (b
, type
,
5764 &momentary_breakpoint_ops
);
5765 clone
->thread
= thread
;
5768 tp
->initiating_frame
= frame
;
5771 /* Delete all longjmp breakpoints from THREAD. */
5773 delete_longjmp_breakpoint (int thread
)
5775 struct breakpoint
*b
, *b_tmp
;
5777 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5778 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5780 if (b
->thread
== thread
)
5781 delete_breakpoint (b
);
5786 enable_overlay_breakpoints (void)
5788 struct breakpoint
*b
;
5791 if (b
->type
== bp_overlay_event
)
5793 b
->enable_state
= bp_enabled
;
5794 update_global_location_list (1);
5795 overlay_events_enabled
= 1;
5800 disable_overlay_breakpoints (void)
5802 struct breakpoint
*b
;
5805 if (b
->type
== bp_overlay_event
)
5807 b
->enable_state
= bp_disabled
;
5808 update_global_location_list (0);
5809 overlay_events_enabled
= 0;
5813 /* Set an active std::terminate breakpoint for each std::terminate
5814 master breakpoint. */
5816 set_std_terminate_breakpoint (void)
5818 struct breakpoint
*b
, *b_tmp
;
5820 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5821 if (b
->pspace
== current_program_space
5822 && b
->type
== bp_std_terminate_master
)
5824 momentary_breakpoint_from_master (b
, bp_std_terminate
,
5825 &momentary_breakpoint_ops
);
5829 /* Delete all the std::terminate breakpoints. */
5831 delete_std_terminate_breakpoint (void)
5833 struct breakpoint
*b
, *b_tmp
;
5835 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5836 if (b
->type
== bp_std_terminate
)
5837 delete_breakpoint (b
);
5841 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5843 struct breakpoint
*b
;
5845 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
5846 &internal_breakpoint_ops
);
5848 b
->enable_state
= bp_enabled
;
5849 /* addr_string has to be used or breakpoint_re_set will delete me. */
5851 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5853 update_global_location_list_nothrow (1);
5859 remove_thread_event_breakpoints (void)
5861 struct breakpoint
*b
, *b_tmp
;
5863 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5864 if (b
->type
== bp_thread_event
5865 && b
->loc
->pspace
== current_program_space
)
5866 delete_breakpoint (b
);
5869 struct lang_and_radix
5875 /* Create a breakpoint for JIT code registration and unregistration. */
5878 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5880 struct breakpoint
*b
;
5882 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
5883 &internal_breakpoint_ops
);
5884 update_global_location_list_nothrow (1);
5888 /* Remove JIT code registration and unregistration breakpoint(s). */
5891 remove_jit_event_breakpoints (void)
5893 struct breakpoint
*b
, *b_tmp
;
5895 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5896 if (b
->type
== bp_jit_event
5897 && b
->loc
->pspace
== current_program_space
)
5898 delete_breakpoint (b
);
5902 remove_solib_event_breakpoints (void)
5904 struct breakpoint
*b
, *b_tmp
;
5906 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5907 if (b
->type
== bp_shlib_event
5908 && b
->loc
->pspace
== current_program_space
)
5909 delete_breakpoint (b
);
5913 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5915 struct breakpoint
*b
;
5917 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
5918 &internal_breakpoint_ops
);
5919 update_global_location_list_nothrow (1);
5923 /* Disable any breakpoints that are on code in shared libraries. Only
5924 apply to enabled breakpoints, disabled ones can just stay disabled. */
5927 disable_breakpoints_in_shlibs (void)
5929 struct bp_location
*loc
, **locp_tmp
;
5931 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5933 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5934 struct breakpoint
*b
= loc
->owner
;
5936 /* We apply the check to all breakpoints, including disabled for
5937 those with loc->duplicate set. This is so that when breakpoint
5938 becomes enabled, or the duplicate is removed, gdb will try to
5939 insert all breakpoints. If we don't set shlib_disabled here,
5940 we'll try to insert those breakpoints and fail. */
5941 if (((b
->type
== bp_breakpoint
)
5942 || (b
->type
== bp_jit_event
)
5943 || (b
->type
== bp_hardware_breakpoint
)
5944 || (is_tracepoint (b
)))
5945 && loc
->pspace
== current_program_space
5946 && !loc
->shlib_disabled
5948 && PC_SOLIB (loc
->address
)
5950 && solib_name_from_address (loc
->pspace
, loc
->address
)
5954 loc
->shlib_disabled
= 1;
5959 /* Disable any breakpoints that are in an unloaded shared library.
5960 Only apply to enabled breakpoints, disabled ones can just stay
5964 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5966 struct bp_location
*loc
, **locp_tmp
;
5967 int disabled_shlib_breaks
= 0;
5969 /* SunOS a.out shared libraries are always mapped, so do not
5970 disable breakpoints; they will only be reported as unloaded
5971 through clear_solib when GDB discards its shared library
5972 list. See clear_solib for more information. */
5973 if (exec_bfd
!= NULL
5974 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5977 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5979 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
5980 struct breakpoint
*b
= loc
->owner
;
5982 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5983 || loc
->loc_type
== bp_loc_software_breakpoint
)
5984 && solib
->pspace
== loc
->pspace
5985 && !loc
->shlib_disabled
5986 && (b
->type
== bp_breakpoint
5987 || b
->type
== bp_jit_event
5988 || b
->type
== bp_hardware_breakpoint
)
5989 && solib_contains_address_p (solib
, loc
->address
))
5991 loc
->shlib_disabled
= 1;
5992 /* At this point, we cannot rely on remove_breakpoint
5993 succeeding so we must mark the breakpoint as not inserted
5994 to prevent future errors occurring in remove_breakpoints. */
5997 /* This may cause duplicate notifications for the same breakpoint. */
5998 observer_notify_breakpoint_modified (b
);
6000 if (!disabled_shlib_breaks
)
6002 target_terminal_ours_for_output ();
6003 warning (_("Temporarily disabling breakpoints "
6004 "for unloaded shared library \"%s\""),
6007 disabled_shlib_breaks
= 1;
6012 /* FORK & VFORK catchpoints. */
6014 /* An instance of this type is used to represent a fork or vfork
6015 catchpoint. It includes a "struct breakpoint" as a kind of base
6016 class; users downcast to "struct breakpoint *" when needed. A
6017 breakpoint is really of this type iff its ops pointer points to
6018 CATCH_FORK_BREAKPOINT_OPS. */
6020 struct fork_catchpoint
6022 /* The base class. */
6023 struct breakpoint base
;
6025 /* Process id of a child process whose forking triggered this
6026 catchpoint. This field is only valid immediately after this
6027 catchpoint has triggered. */
6028 ptid_t forked_inferior_pid
;
6031 /* Implement the "insert" breakpoint_ops method for fork
6035 insert_catch_fork (struct bp_location
*bl
)
6037 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6040 /* Implement the "remove" breakpoint_ops method for fork
6044 remove_catch_fork (struct bp_location
*bl
)
6046 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6049 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6053 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6054 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6056 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6058 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6061 /* Implement the "print_it" breakpoint_ops method for fork
6064 static enum print_stop_action
6065 print_it_catch_fork (bpstat bs
)
6067 struct breakpoint
*b
= bs
->breakpoint_at
;
6068 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6070 annotate_catchpoint (b
->number
);
6071 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6072 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6073 return PRINT_SRC_AND_LOC
;
6076 /* Implement the "print_one" breakpoint_ops method for fork
6080 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6082 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6083 struct value_print_options opts
;
6085 get_user_print_options (&opts
);
6087 /* Field 4, the address, is omitted (which makes the columns not
6088 line up too nicely with the headers, but the effect is relatively
6090 if (opts
.addressprint
)
6091 ui_out_field_skip (uiout
, "addr");
6093 ui_out_text (uiout
, "fork");
6094 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6096 ui_out_text (uiout
, ", process ");
6097 ui_out_field_int (uiout
, "what",
6098 ptid_get_pid (c
->forked_inferior_pid
));
6099 ui_out_spaces (uiout
, 1);
6103 /* Implement the "print_mention" breakpoint_ops method for fork
6107 print_mention_catch_fork (struct breakpoint
*b
)
6109 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6112 /* Implement the "print_recreate" breakpoint_ops method for fork
6116 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6118 fprintf_unfiltered (fp
, "catch fork");
6121 /* The breakpoint_ops structure to be used in fork catchpoints. */
6123 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6125 /* Implement the "insert" breakpoint_ops method for vfork
6129 insert_catch_vfork (struct bp_location
*bl
)
6131 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6134 /* Implement the "remove" breakpoint_ops method for vfork
6138 remove_catch_vfork (struct bp_location
*bl
)
6140 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6143 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6147 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6148 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6150 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6152 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6155 /* Implement the "print_it" breakpoint_ops method for vfork
6158 static enum print_stop_action
6159 print_it_catch_vfork (bpstat bs
)
6161 struct breakpoint
*b
= bs
->breakpoint_at
;
6162 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6164 annotate_catchpoint (b
->number
);
6165 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6166 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6167 return PRINT_SRC_AND_LOC
;
6170 /* Implement the "print_one" breakpoint_ops method for vfork
6174 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6176 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6177 struct value_print_options opts
;
6179 get_user_print_options (&opts
);
6180 /* Field 4, the address, is omitted (which makes the columns not
6181 line up too nicely with the headers, but the effect is relatively
6183 if (opts
.addressprint
)
6184 ui_out_field_skip (uiout
, "addr");
6186 ui_out_text (uiout
, "vfork");
6187 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6189 ui_out_text (uiout
, ", process ");
6190 ui_out_field_int (uiout
, "what",
6191 ptid_get_pid (c
->forked_inferior_pid
));
6192 ui_out_spaces (uiout
, 1);
6196 /* Implement the "print_mention" breakpoint_ops method for vfork
6200 print_mention_catch_vfork (struct breakpoint
*b
)
6202 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6205 /* Implement the "print_recreate" breakpoint_ops method for vfork
6209 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6211 fprintf_unfiltered (fp
, "catch vfork");
6214 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6216 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6218 /* An instance of this type is used to represent a syscall catchpoint.
6219 It includes a "struct breakpoint" as a kind of base class; users
6220 downcast to "struct breakpoint *" when needed. A breakpoint is
6221 really of this type iff its ops pointer points to
6222 CATCH_SYSCALL_BREAKPOINT_OPS. */
6224 struct syscall_catchpoint
6226 /* The base class. */
6227 struct breakpoint base
;
6229 /* Syscall numbers used for the 'catch syscall' feature. If no
6230 syscall has been specified for filtering, its value is NULL.
6231 Otherwise, it holds a list of all syscalls to be caught. The
6232 list elements are allocated with xmalloc. */
6233 VEC(int) *syscalls_to_be_caught
;
6236 /* Implement the "dtor" breakpoint_ops method for syscall
6240 dtor_catch_syscall (struct breakpoint
*b
)
6242 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6244 VEC_free (int, c
->syscalls_to_be_caught
);
6246 base_breakpoint_ops
.dtor (b
);
6249 /* Implement the "insert" breakpoint_ops method for syscall
6253 insert_catch_syscall (struct bp_location
*bl
)
6255 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6256 struct inferior
*inf
= current_inferior ();
6258 ++inf
->total_syscalls_count
;
6259 if (!c
->syscalls_to_be_caught
)
6260 ++inf
->any_syscall_count
;
6266 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6271 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6273 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6274 uintptr_t vec_addr_offset
6275 = old_size
* ((uintptr_t) sizeof (int));
6277 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6278 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6280 memset ((void *) vec_addr
, 0,
6281 (iter
+ 1 - old_size
) * sizeof (int));
6283 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6284 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6288 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6289 inf
->total_syscalls_count
!= 0,
6290 inf
->any_syscall_count
,
6291 VEC_length (int, inf
->syscalls_counts
),
6292 VEC_address (int, inf
->syscalls_counts
));
6295 /* Implement the "remove" breakpoint_ops method for syscall
6299 remove_catch_syscall (struct bp_location
*bl
)
6301 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6302 struct inferior
*inf
= current_inferior ();
6304 --inf
->total_syscalls_count
;
6305 if (!c
->syscalls_to_be_caught
)
6306 --inf
->any_syscall_count
;
6312 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6316 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6317 /* Shouldn't happen. */
6319 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6320 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6324 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6325 inf
->total_syscalls_count
!= 0,
6326 inf
->any_syscall_count
,
6327 VEC_length (int, inf
->syscalls_counts
),
6329 inf
->syscalls_counts
));
6332 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6336 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6337 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6339 /* We must check if we are catching specific syscalls in this
6340 breakpoint. If we are, then we must guarantee that the called
6341 syscall is the same syscall we are catching. */
6342 int syscall_number
= 0;
6343 const struct syscall_catchpoint
*c
6344 = (const struct syscall_catchpoint
*) bl
->owner
;
6346 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6349 /* Now, checking if the syscall is the same. */
6350 if (c
->syscalls_to_be_caught
)
6355 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6357 if (syscall_number
== iter
)
6367 /* Implement the "print_it" breakpoint_ops method for syscall
6370 static enum print_stop_action
6371 print_it_catch_syscall (bpstat bs
)
6373 struct breakpoint
*b
= bs
->breakpoint_at
;
6374 /* These are needed because we want to know in which state a
6375 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6376 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6377 must print "called syscall" or "returned from syscall". */
6379 struct target_waitstatus last
;
6381 struct cleanup
*old_chain
;
6384 get_last_target_status (&ptid
, &last
);
6386 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6388 annotate_catchpoint (b
->number
);
6391 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6393 syscall_id
= xstrprintf ("'%s'", s
.name
);
6395 old_chain
= make_cleanup (xfree
, syscall_id
);
6397 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6398 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6399 b
->number
, syscall_id
);
6400 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6401 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6402 b
->number
, syscall_id
);
6404 do_cleanups (old_chain
);
6406 return PRINT_SRC_AND_LOC
;
6409 /* Implement the "print_one" breakpoint_ops method for syscall
6413 print_one_catch_syscall (struct breakpoint
*b
,
6414 struct bp_location
**last_loc
)
6416 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6417 struct value_print_options opts
;
6419 get_user_print_options (&opts
);
6420 /* Field 4, the address, is omitted (which makes the columns not
6421 line up too nicely with the headers, but the effect is relatively
6423 if (opts
.addressprint
)
6424 ui_out_field_skip (uiout
, "addr");
6427 if (c
->syscalls_to_be_caught
6428 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6429 ui_out_text (uiout
, "syscalls \"");
6431 ui_out_text (uiout
, "syscall \"");
6433 if (c
->syscalls_to_be_caught
)
6436 char *text
= xstrprintf ("%s", "");
6439 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6444 get_syscall_by_number (iter
, &s
);
6447 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6449 text
= xstrprintf ("%s%d, ", text
, iter
);
6451 /* We have to xfree the last 'text' (now stored at 'x')
6452 because xstrprintf dynamically allocates new space for it
6456 /* Remove the last comma. */
6457 text
[strlen (text
) - 2] = '\0';
6458 ui_out_field_string (uiout
, "what", text
);
6461 ui_out_field_string (uiout
, "what", "<any syscall>");
6462 ui_out_text (uiout
, "\" ");
6465 /* Implement the "print_mention" breakpoint_ops method for syscall
6469 print_mention_catch_syscall (struct breakpoint
*b
)
6471 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6473 if (c
->syscalls_to_be_caught
)
6477 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6478 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6480 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6483 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6487 get_syscall_by_number (iter
, &s
);
6490 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6492 printf_filtered (" %d", s
.number
);
6494 printf_filtered (")");
6497 printf_filtered (_("Catchpoint %d (any syscall)"),
6501 /* Implement the "print_recreate" breakpoint_ops method for syscall
6505 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6507 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6509 fprintf_unfiltered (fp
, "catch syscall");
6511 if (c
->syscalls_to_be_caught
)
6516 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6521 get_syscall_by_number (iter
, &s
);
6523 fprintf_unfiltered (fp
, " %s", s
.name
);
6525 fprintf_unfiltered (fp
, " %d", s
.number
);
6530 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6532 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6534 /* Returns non-zero if 'b' is a syscall catchpoint. */
6537 syscall_catchpoint_p (struct breakpoint
*b
)
6539 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6542 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6543 is non-zero, then make the breakpoint temporary. If COND_STRING is
6544 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6545 the breakpoint_ops structure associated to the catchpoint. */
6548 init_catchpoint (struct breakpoint
*b
,
6549 struct gdbarch
*gdbarch
, int tempflag
,
6551 struct breakpoint_ops
*ops
)
6553 struct symtab_and_line sal
;
6556 sal
.pspace
= current_program_space
;
6558 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6560 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6561 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6565 install_breakpoint (struct breakpoint
*b
)
6567 add_to_breakpoint_chain (b
);
6568 set_breakpoint_count (breakpoint_count
+ 1);
6569 b
->number
= breakpoint_count
;
6571 observer_notify_breakpoint_created (b
);
6572 update_global_location_list (1);
6576 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6577 int tempflag
, char *cond_string
,
6578 struct breakpoint_ops
*ops
)
6580 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6582 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6584 c
->forked_inferior_pid
= null_ptid
;
6586 install_breakpoint (&c
->base
);
6589 /* Exec catchpoints. */
6591 /* An instance of this type is used to represent an exec catchpoint.
6592 It includes a "struct breakpoint" as a kind of base class; users
6593 downcast to "struct breakpoint *" when needed. A breakpoint is
6594 really of this type iff its ops pointer points to
6595 CATCH_EXEC_BREAKPOINT_OPS. */
6597 struct exec_catchpoint
6599 /* The base class. */
6600 struct breakpoint base
;
6602 /* Filename of a program whose exec triggered this catchpoint.
6603 This field is only valid immediately after this catchpoint has
6605 char *exec_pathname
;
6608 /* Implement the "dtor" breakpoint_ops method for exec
6612 dtor_catch_exec (struct breakpoint
*b
)
6614 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6616 xfree (c
->exec_pathname
);
6618 base_breakpoint_ops
.dtor (b
);
6622 insert_catch_exec (struct bp_location
*bl
)
6624 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6628 remove_catch_exec (struct bp_location
*bl
)
6630 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6634 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6635 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6637 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6639 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6642 static enum print_stop_action
6643 print_it_catch_exec (bpstat bs
)
6645 struct breakpoint
*b
= bs
->breakpoint_at
;
6646 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6648 annotate_catchpoint (b
->number
);
6649 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6651 return PRINT_SRC_AND_LOC
;
6655 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6657 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6658 struct value_print_options opts
;
6660 get_user_print_options (&opts
);
6662 /* Field 4, the address, is omitted (which makes the columns
6663 not line up too nicely with the headers, but the effect
6664 is relatively readable). */
6665 if (opts
.addressprint
)
6666 ui_out_field_skip (uiout
, "addr");
6668 ui_out_text (uiout
, "exec");
6669 if (c
->exec_pathname
!= NULL
)
6671 ui_out_text (uiout
, ", program \"");
6672 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6673 ui_out_text (uiout
, "\" ");
6678 print_mention_catch_exec (struct breakpoint
*b
)
6680 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6683 /* Implement the "print_recreate" breakpoint_ops method for exec
6687 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6689 fprintf_unfiltered (fp
, "catch exec");
6692 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6695 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6696 struct breakpoint_ops
*ops
)
6698 struct syscall_catchpoint
*c
;
6699 struct gdbarch
*gdbarch
= get_current_arch ();
6701 c
= XNEW (struct syscall_catchpoint
);
6702 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6703 c
->syscalls_to_be_caught
= filter
;
6705 install_breakpoint (&c
->base
);
6709 hw_breakpoint_used_count (void)
6712 struct breakpoint
*b
;
6713 struct bp_location
*bl
;
6717 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6718 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6720 /* Special types of hardware breakpoints may use more than
6722 i
+= b
->ops
->resources_needed (bl
);
6730 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6733 struct breakpoint
*b
;
6734 struct bp_location
*bl
;
6736 *other_type_used
= 0;
6739 if (!breakpoint_enabled (b
))
6742 if (b
->type
== type
)
6743 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6745 /* Special types of hardware watchpoints may use more than
6747 i
+= b
->ops
->resources_needed (bl
);
6749 else if (is_hardware_watchpoint (b
))
6750 *other_type_used
= 1;
6757 disable_watchpoints_before_interactive_call_start (void)
6759 struct breakpoint
*b
;
6763 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6765 b
->enable_state
= bp_call_disabled
;
6766 update_global_location_list (0);
6772 enable_watchpoints_after_interactive_call_stop (void)
6774 struct breakpoint
*b
;
6778 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6780 b
->enable_state
= bp_enabled
;
6781 update_global_location_list (1);
6787 disable_breakpoints_before_startup (void)
6789 struct breakpoint
*b
;
6794 if (b
->pspace
!= current_program_space
)
6797 if ((b
->type
== bp_breakpoint
6798 || b
->type
== bp_hardware_breakpoint
)
6799 && breakpoint_enabled (b
))
6801 b
->enable_state
= bp_startup_disabled
;
6807 update_global_location_list (0);
6809 current_program_space
->executing_startup
= 1;
6813 enable_breakpoints_after_startup (void)
6815 struct breakpoint
*b
;
6818 current_program_space
->executing_startup
= 0;
6822 if (b
->pspace
!= current_program_space
)
6825 if ((b
->type
== bp_breakpoint
6826 || b
->type
== bp_hardware_breakpoint
)
6827 && b
->enable_state
== bp_startup_disabled
)
6829 b
->enable_state
= bp_enabled
;
6835 breakpoint_re_set ();
6839 /* Set a breakpoint that will evaporate an end of command
6840 at address specified by SAL.
6841 Restrict it to frame FRAME if FRAME is nonzero. */
6844 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6845 struct frame_id frame_id
, enum bptype type
)
6847 struct breakpoint
*b
;
6849 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6851 gdb_assert (!frame_id_inlined_p (frame_id
));
6853 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
6854 b
->enable_state
= bp_enabled
;
6855 b
->disposition
= disp_donttouch
;
6856 b
->frame_id
= frame_id
;
6858 /* If we're debugging a multi-threaded program, then we want
6859 momentary breakpoints to be active in only a single thread of
6861 if (in_thread_list (inferior_ptid
))
6862 b
->thread
= pid_to_thread_id (inferior_ptid
);
6864 update_global_location_list_nothrow (1);
6869 /* Make a momentary breakpoint based on the master breakpoint ORIG.
6870 The new breakpoint will have type TYPE, and use OPS as it
6873 static struct breakpoint
*
6874 momentary_breakpoint_from_master (struct breakpoint
*orig
,
6876 struct breakpoint_ops
*ops
)
6878 struct breakpoint
*copy
;
6880 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
6881 copy
->loc
= allocate_bp_location (copy
);
6882 set_breakpoint_location_function (copy
->loc
, 1);
6884 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6885 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6886 copy
->loc
->address
= orig
->loc
->address
;
6887 copy
->loc
->section
= orig
->loc
->section
;
6888 copy
->loc
->pspace
= orig
->loc
->pspace
;
6890 if (orig
->source_file
== NULL
)
6891 copy
->source_file
= NULL
;
6893 copy
->source_file
= xstrdup (orig
->source_file
);
6895 copy
->line_number
= orig
->line_number
;
6896 copy
->frame_id
= orig
->frame_id
;
6897 copy
->thread
= orig
->thread
;
6898 copy
->pspace
= orig
->pspace
;
6900 copy
->enable_state
= bp_enabled
;
6901 copy
->disposition
= disp_donttouch
;
6902 copy
->number
= internal_breakpoint_number
--;
6904 update_global_location_list_nothrow (0);
6908 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6912 clone_momentary_breakpoint (struct breakpoint
*orig
)
6914 /* If there's nothing to clone, then return nothing. */
6918 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
6922 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6925 struct symtab_and_line sal
;
6927 sal
= find_pc_line (pc
, 0);
6929 sal
.section
= find_pc_overlay (pc
);
6930 sal
.explicit_pc
= 1;
6932 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6936 /* Tell the user we have just set a breakpoint B. */
6939 mention (struct breakpoint
*b
)
6941 b
->ops
->print_mention (b
);
6942 if (ui_out_is_mi_like_p (uiout
))
6944 printf_filtered ("\n");
6948 static struct bp_location
*
6949 add_location_to_breakpoint (struct breakpoint
*b
,
6950 const struct symtab_and_line
*sal
)
6952 struct bp_location
*loc
, **tmp
;
6954 loc
= allocate_bp_location (b
);
6955 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6958 loc
->gdbarch
= get_sal_arch (*sal
);
6960 loc
->gdbarch
= b
->gdbarch
;
6961 loc
->requested_address
= sal
->pc
;
6962 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6963 loc
->requested_address
, b
->type
);
6964 loc
->pspace
= sal
->pspace
;
6965 gdb_assert (loc
->pspace
!= NULL
);
6966 loc
->section
= sal
->section
;
6968 set_breakpoint_location_function (loc
,
6969 sal
->explicit_pc
|| sal
->explicit_line
);
6974 /* Return 1 if LOC is pointing to a permanent breakpoint,
6975 return 0 otherwise. */
6978 bp_loc_is_permanent (struct bp_location
*loc
)
6982 const gdb_byte
*brk
;
6983 gdb_byte
*target_mem
;
6984 struct cleanup
*cleanup
;
6987 gdb_assert (loc
!= NULL
);
6989 addr
= loc
->address
;
6990 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6992 /* Software breakpoints unsupported? */
6996 target_mem
= alloca (len
);
6998 /* Enable the automatic memory restoration from breakpoints while
6999 we read the memory. Otherwise we could say about our temporary
7000 breakpoints they are permanent. */
7001 cleanup
= save_current_space_and_thread ();
7003 switch_to_program_space_and_thread (loc
->pspace
);
7004 make_show_memory_breakpoints_cleanup (0);
7006 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7007 && memcmp (target_mem
, brk
, len
) == 0)
7010 do_cleanups (cleanup
);
7017 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7018 as textual description of the location, and COND_STRING
7019 as condition expression. */
7022 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7023 struct symtabs_and_lines sals
, char *addr_string
,
7025 enum bptype type
, enum bpdisp disposition
,
7026 int thread
, int task
, int ignore_count
,
7027 struct breakpoint_ops
*ops
, int from_tty
,
7028 int enabled
, int internal
, int display_canonical
)
7030 struct breakpoint
*b
= NULL
;
7033 if (type
== bp_hardware_breakpoint
)
7035 int i
= hw_breakpoint_used_count ();
7036 int target_resources_ok
=
7037 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7039 if (target_resources_ok
== 0)
7040 error (_("No hardware breakpoint support in the target."));
7041 else if (target_resources_ok
< 0)
7042 error (_("Hardware breakpoints used exceeds limit."));
7045 gdb_assert (sals
.nelts
> 0);
7047 for (i
= 0; i
< sals
.nelts
; ++i
)
7049 struct symtab_and_line sal
= sals
.sals
[i
];
7050 struct bp_location
*loc
;
7054 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7056 loc_gdbarch
= gdbarch
;
7058 describe_other_breakpoints (loc_gdbarch
,
7059 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7064 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
7065 set_breakpoint_number (internal
, b
);
7069 b
->cond_string
= cond_string
;
7070 b
->ignore_count
= ignore_count
;
7071 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7072 b
->disposition
= disposition
;
7073 b
->pspace
= sals
.sals
[0].pspace
;
7075 if (type
== bp_static_tracepoint
)
7077 struct static_tracepoint_marker marker
;
7079 if (is_marker_spec (addr_string
))
7081 /* We already know the marker exists, otherwise, we
7082 wouldn't see a sal for it. */
7083 char *p
= &addr_string
[3];
7088 p
= skip_spaces (p
);
7090 endp
= skip_to_space (p
);
7092 marker_str
= savestring (p
, endp
- p
);
7093 b
->static_trace_marker_id
= marker_str
;
7095 printf_filtered (_("Probed static tracepoint "
7097 b
->static_trace_marker_id
);
7099 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7101 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7102 release_static_tracepoint_marker (&marker
);
7104 printf_filtered (_("Probed static tracepoint "
7106 b
->static_trace_marker_id
);
7109 warning (_("Couldn't determine the static "
7110 "tracepoint marker to probe"));
7113 if (enabled
&& b
->pspace
->executing_startup
7114 && (b
->type
== bp_breakpoint
7115 || b
->type
== bp_hardware_breakpoint
))
7116 b
->enable_state
= bp_startup_disabled
;
7122 loc
= add_location_to_breakpoint (b
, &sal
);
7125 if (bp_loc_is_permanent (loc
))
7126 make_breakpoint_permanent (b
);
7130 char *arg
= b
->cond_string
;
7131 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7133 error (_("Garbage %s follows condition"), arg
);
7137 b
->display_canonical
= display_canonical
;
7139 b
->addr_string
= addr_string
;
7141 /* addr_string has to be used or breakpoint_re_set will delete
7144 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7146 /* Do not mention breakpoints with a negative number, but do
7147 notify observers. */
7150 observer_notify_breakpoint_created (b
);
7153 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7154 elements to fill the void space. */
7156 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7158 int i
= index_to_remove
+1;
7159 int last_index
= sal
->nelts
-1;
7161 for (;i
<= last_index
; ++i
)
7162 sal
->sals
[i
-1] = sal
->sals
[i
];
7167 /* If appropriate, obtains all sals that correspond to the same file
7168 and line as SAL, in all program spaces. Users debugging with IDEs,
7169 will want to set a breakpoint at foo.c:line, and not really care
7170 about program spaces. This is done only if SAL does not have
7171 explicit PC and has line and file information. If we got just a
7172 single expanded sal, return the original.
7174 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7175 which the name of enclosing function is different from SAL. This
7176 makes sure that if we have breakpoint originally set in template
7177 instantiation, say foo<int>(), we won't expand SAL to locations at
7178 the same line in all existing instantiations of 'foo'. */
7180 static struct symtabs_and_lines
7181 expand_line_sal_maybe (struct symtab_and_line sal
)
7183 struct symtabs_and_lines expanded
;
7184 CORE_ADDR original_pc
= sal
.pc
;
7185 char *original_function
= NULL
;
7188 struct cleanup
*old_chain
;
7190 /* If we have explicit pc, don't expand.
7191 If we have no line number, we can't expand. */
7192 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7195 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7196 expanded
.sals
[0] = sal
;
7202 old_chain
= save_current_space_and_thread ();
7204 switch_to_program_space_and_thread (sal
.pspace
);
7206 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7208 /* Note that expand_line_sal visits *all* program spaces. */
7209 expanded
= expand_line_sal (sal
);
7211 if (expanded
.nelts
== 1)
7213 /* We had one sal, we got one sal. Return that sal, adjusting it
7214 past the function prologue if necessary. */
7215 xfree (expanded
.sals
);
7217 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7218 sal
.pc
= original_pc
;
7219 expanded
.sals
[0] = sal
;
7220 skip_prologue_sal (&expanded
.sals
[0]);
7221 do_cleanups (old_chain
);
7225 if (!sal
.explicit_line
)
7227 CORE_ADDR func_addr
, func_end
;
7228 for (i
= 0; i
< expanded
.nelts
; ++i
)
7230 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7231 char *this_function
;
7233 /* We need to switch threads as well since we're about to
7235 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7237 if (find_pc_partial_function (pc
, &this_function
,
7238 &func_addr
, &func_end
))
7241 && strcmp (this_function
, original_function
) != 0)
7243 remove_sal (&expanded
, i
);
7250 /* Skip the function prologue if necessary. */
7251 for (i
= 0; i
< expanded
.nelts
; ++i
)
7252 skip_prologue_sal (&expanded
.sals
[i
]);
7254 do_cleanups (old_chain
);
7256 if (expanded
.nelts
<= 1)
7258 /* This is an ugly workaround. If we get zero expanded sals
7259 then something is really wrong. Fix that by returning the
7262 xfree (expanded
.sals
);
7264 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7265 sal
.pc
= original_pc
;
7266 expanded
.sals
[0] = sal
;
7273 for (i
= 0; i
< expanded
.nelts
; ++i
)
7274 if (expanded
.sals
[i
].pc
== original_pc
)
7285 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7286 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7287 value. COND_STRING, if not NULL, specified the condition to be
7288 used for all breakpoints. Essentially the only case where
7289 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7290 function. In that case, it's still not possible to specify
7291 separate conditions for different overloaded functions, so
7292 we take just a single condition string.
7294 NOTE: If the function succeeds, the caller is expected to cleanup
7295 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7296 array contents). If the function fails (error() is called), the
7297 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7298 COND and SALS arrays and each of those arrays contents. */
7301 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7302 struct symtabs_and_lines sals
,
7303 struct linespec_result
*canonical
,
7305 enum bptype type
, enum bpdisp disposition
,
7306 int thread
, int task
, int ignore_count
,
7307 struct breakpoint_ops
*ops
, int from_tty
,
7308 int enabled
, int internal
)
7312 for (i
= 0; i
< sals
.nelts
; ++i
)
7314 struct symtabs_and_lines expanded
=
7315 expand_line_sal_maybe (sals
.sals
[i
]);
7317 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7318 cond_string
, type
, disposition
,
7319 thread
, task
, ignore_count
, ops
,
7320 from_tty
, enabled
, internal
,
7321 canonical
->special_display
);
7325 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7326 followed by conditionals. On return, SALS contains an array of SAL
7327 addresses found. ADDR_STRING contains a vector of (canonical)
7328 address strings. ADDRESS points to the end of the SAL.
7330 The array and the line spec strings are allocated on the heap, it is
7331 the caller's responsibility to free them. */
7334 parse_breakpoint_sals (char **address
,
7335 struct symtabs_and_lines
*sals
,
7336 struct linespec_result
*canonical
)
7338 char *addr_start
= *address
;
7340 /* If no arg given, or if first arg is 'if ', use the default
7342 if ((*address
) == NULL
7343 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7345 if (default_breakpoint_valid
)
7347 struct symtab_and_line sal
;
7349 init_sal (&sal
); /* Initialize to zeroes. */
7350 sals
->sals
= (struct symtab_and_line
*)
7351 xmalloc (sizeof (struct symtab_and_line
));
7352 sal
.pc
= default_breakpoint_address
;
7353 sal
.line
= default_breakpoint_line
;
7354 sal
.symtab
= default_breakpoint_symtab
;
7355 sal
.pspace
= default_breakpoint_pspace
;
7356 sal
.section
= find_pc_overlay (sal
.pc
);
7358 /* "break" without arguments is equivalent to "break *PC"
7359 where PC is the default_breakpoint_address. So make sure
7360 to set sal.explicit_pc to prevent GDB from trying to
7361 expand the list of sals to include all other instances
7362 with the same symtab and line. */
7363 sal
.explicit_pc
= 1;
7365 sals
->sals
[0] = sal
;
7369 error (_("No default breakpoint address now."));
7373 /* Force almost all breakpoints to be in terms of the
7374 current_source_symtab (which is decode_line_1's default).
7375 This should produce the results we want almost all of the
7376 time while leaving default_breakpoint_* alone.
7378 ObjC: However, don't match an Objective-C method name which
7379 may have a '+' or '-' succeeded by a '[' */
7381 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7383 if (default_breakpoint_valid
7385 || ((strchr ("+-", (*address
)[0]) != NULL
)
7386 && ((*address
)[1] != '['))))
7387 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7388 default_breakpoint_line
, canonical
);
7390 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7393 /* For any SAL that didn't have a canonical string, fill one in. */
7394 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7395 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7396 if (addr_start
!= (*address
))
7400 for (i
= 0; i
< sals
->nelts
; i
++)
7402 /* Add the string if not present. */
7403 if (canonical
->canonical
[i
] == NULL
)
7404 canonical
->canonical
[i
] = savestring (addr_start
,
7405 (*address
) - addr_start
);
7411 /* Convert each SAL into a real PC. Verify that the PC can be
7412 inserted as a breakpoint. If it can't throw an error. */
7415 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7419 for (i
= 0; i
< sals
->nelts
; i
++)
7420 resolve_sal_pc (&sals
->sals
[i
]);
7423 /* Fast tracepoints may have restrictions on valid locations. For
7424 instance, a fast tracepoint using a jump instead of a trap will
7425 likely have to overwrite more bytes than a trap would, and so can
7426 only be placed where the instruction is longer than the jump, or a
7427 multi-instruction sequence does not have a jump into the middle of
7431 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7432 struct symtabs_and_lines
*sals
)
7435 struct symtab_and_line
*sal
;
7437 struct cleanup
*old_chain
;
7439 for (i
= 0; i
< sals
->nelts
; i
++)
7441 sal
= &sals
->sals
[i
];
7443 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7445 old_chain
= make_cleanup (xfree
, msg
);
7448 error (_("May not have a fast tracepoint at 0x%s%s"),
7449 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7451 do_cleanups (old_chain
);
7455 /* Given TOK, a string specification of condition and thread, as
7456 accepted by the 'break' command, extract the condition
7457 string and thread number and set *COND_STRING and *THREAD.
7458 PC identifies the context at which the condition should be parsed.
7459 If no condition is found, *COND_STRING is set to NULL.
7460 If no thread is found, *THREAD is set to -1. */
7462 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7463 char **cond_string
, int *thread
, int *task
)
7465 *cond_string
= NULL
;
7471 char *cond_start
= NULL
;
7472 char *cond_end
= NULL
;
7474 tok
= skip_spaces (tok
);
7476 end_tok
= skip_to_space (tok
);
7478 toklen
= end_tok
- tok
;
7480 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7482 struct expression
*expr
;
7484 tok
= cond_start
= end_tok
+ 1;
7485 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7488 *cond_string
= savestring (cond_start
,
7489 cond_end
- cond_start
);
7491 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7497 *thread
= strtol (tok
, &tok
, 0);
7499 error (_("Junk after thread keyword."));
7500 if (!valid_thread_id (*thread
))
7501 error (_("Unknown thread %d."), *thread
);
7503 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7509 *task
= strtol (tok
, &tok
, 0);
7511 error (_("Junk after task keyword."));
7512 if (!valid_task_id (*task
))
7513 error (_("Unknown task %d."), *task
);
7516 error (_("Junk at end of arguments."));
7520 /* Decode a static tracepoint marker spec. */
7522 static struct symtabs_and_lines
7523 decode_static_tracepoint_spec (char **arg_p
)
7525 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7526 struct symtabs_and_lines sals
;
7527 struct symtab_and_line sal
;
7529 struct cleanup
*old_chain
;
7530 char *p
= &(*arg_p
)[3];
7535 p
= skip_spaces (p
);
7537 endp
= skip_to_space (p
);
7539 marker_str
= savestring (p
, endp
- p
);
7540 old_chain
= make_cleanup (xfree
, marker_str
);
7542 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7543 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7544 error (_("No known static tracepoint marker named %s"), marker_str
);
7546 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7547 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7549 for (i
= 0; i
< sals
.nelts
; i
++)
7551 struct static_tracepoint_marker
*marker
;
7553 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7555 init_sal (&sals
.sals
[i
]);
7557 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7558 sals
.sals
[i
].pc
= marker
->address
;
7560 release_static_tracepoint_marker (marker
);
7563 do_cleanups (old_chain
);
7569 /* Set a breakpoint. This function is shared between CLI and MI
7570 functions for setting a breakpoint. This function has two major
7571 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7572 parameter. If non-zero, the function will parse arg, extracting
7573 breakpoint location, address and thread. Otherwise, ARG is just
7574 the location of breakpoint, with condition and thread specified by
7575 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7576 the breakpoint number will be allocated from the internal
7577 breakpoint count. Returns true if any breakpoint was created;
7581 create_breakpoint (struct gdbarch
*gdbarch
,
7582 char *arg
, char *cond_string
, int thread
,
7583 int parse_condition_and_thread
,
7584 int tempflag
, enum bptype type_wanted
,
7586 enum auto_boolean pending_break_support
,
7587 struct breakpoint_ops
*ops
,
7588 int from_tty
, int enabled
, int internal
)
7590 volatile struct gdb_exception e
;
7591 struct symtabs_and_lines sals
;
7592 struct symtab_and_line pending_sal
;
7594 char *addr_start
= arg
;
7595 struct linespec_result canonical
;
7596 struct cleanup
*old_chain
;
7597 struct cleanup
*bkpt_chain
= NULL
;
7601 int prev_bkpt_count
= breakpoint_count
;
7603 gdb_assert (ops
!= NULL
);
7607 init_linespec_result (&canonical
);
7609 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7613 sals
= decode_static_tracepoint_spec (&arg
);
7615 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7616 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7617 for (i
= 0; i
< sals
.nelts
; i
++)
7618 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7622 TRY_CATCH (e
, RETURN_MASK_ALL
)
7624 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7627 /* If caller is interested in rc value from parse, set value. */
7631 throw_exception (e
);
7635 case NOT_FOUND_ERROR
:
7637 /* If pending breakpoint support is turned off, throw
7640 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7641 throw_exception (e
);
7643 exception_print (gdb_stderr
, e
);
7645 /* If pending breakpoint support is auto query and the user
7646 selects no, then simply return the error code. */
7647 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7648 && !nquery (_("Make breakpoint pending on "
7649 "future shared library load? ")))
7652 /* At this point, either the user was queried about setting
7653 a pending breakpoint and selected yes, or pending
7654 breakpoint behavior is on and thus a pending breakpoint
7655 is defaulted on behalf of the user. */
7656 copy_arg
= xstrdup (addr_start
);
7657 canonical
.canonical
= ©_arg
;
7659 sals
.sals
= &pending_sal
;
7664 throw_exception (e
);
7674 /* Create a chain of things that always need to be cleaned up. */
7675 old_chain
= make_cleanup (null_cleanup
, 0);
7679 /* Make sure that all storage allocated to SALS gets freed. */
7680 make_cleanup (xfree
, sals
.sals
);
7682 /* Cleanup the canonical array but not its contents. */
7683 make_cleanup (xfree
, canonical
.canonical
);
7686 /* ----------------------------- SNIP -----------------------------
7687 Anything added to the cleanup chain beyond this point is assumed
7688 to be part of a breakpoint. If the breakpoint create succeeds
7689 then the memory is not reclaimed. */
7690 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7692 /* Mark the contents of the canonical for cleanup. These go on
7693 the bkpt_chain and only occur if the breakpoint create fails. */
7694 for (i
= 0; i
< sals
.nelts
; i
++)
7696 if (canonical
.canonical
[i
] != NULL
)
7697 make_cleanup (xfree
, canonical
.canonical
[i
]);
7700 /* Resolve all line numbers to PC's and verify that the addresses
7701 are ok for the target. */
7703 breakpoint_sals_to_pc (&sals
);
7705 /* Fast tracepoints may have additional restrictions on location. */
7706 if (type_wanted
== bp_fast_tracepoint
)
7707 check_fast_tracepoint_sals (gdbarch
, &sals
);
7709 /* Verify that condition can be parsed, before setting any
7710 breakpoints. Allocate a separate condition expression for each
7714 if (parse_condition_and_thread
)
7716 /* Here we only parse 'arg' to separate condition
7717 from thread number, so parsing in context of first
7718 sal is OK. When setting the breakpoint we'll
7719 re-parse it in context of each sal. */
7722 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7725 make_cleanup (xfree
, cond_string
);
7729 /* Create a private copy of condition string. */
7732 cond_string
= xstrdup (cond_string
);
7733 make_cleanup (xfree
, cond_string
);
7737 /* If the user is creating a static tracepoint by marker id
7738 (strace -m MARKER_ID), then store the sals index, so that
7739 breakpoint_re_set can try to match up which of the newly
7740 found markers corresponds to this one, and, don't try to
7741 expand multiple locations for each sal, given than SALS
7742 already should contain all sals for MARKER_ID. */
7743 if (type_wanted
== bp_static_tracepoint
7744 && is_marker_spec (canonical
.canonical
[0]))
7748 for (i
= 0; i
< sals
.nelts
; ++i
)
7750 struct symtabs_and_lines expanded
;
7751 struct breakpoint
*tp
;
7752 struct cleanup
*old_chain
;
7755 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7756 expanded
.sals
[0] = sals
.sals
[i
];
7757 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7759 create_breakpoint_sal (gdbarch
, expanded
, canonical
.canonical
[i
],
7760 cond_string
, type_wanted
,
7761 tempflag
? disp_del
: disp_donttouch
,
7762 thread
, task
, ignore_count
, ops
,
7763 from_tty
, enabled
, internal
,
7764 canonical
.special_display
);
7766 do_cleanups (old_chain
);
7768 /* Get the tracepoint we just created. */
7770 tp
= get_breakpoint (internal_breakpoint_number
);
7772 tp
= get_breakpoint (breakpoint_count
);
7773 gdb_assert (tp
!= NULL
);
7775 /* Given that its possible to have multiple markers with
7776 the same string id, if the user is creating a static
7777 tracepoint by marker id ("strace -m MARKER_ID"), then
7778 store the sals index, so that breakpoint_re_set can
7779 try to match up which of the newly found markers
7780 corresponds to this one */
7781 tp
->static_trace_marker_id_idx
= i
;
7785 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
7787 tempflag
? disp_del
: disp_donttouch
,
7788 thread
, task
, ignore_count
, ops
, from_tty
,
7793 struct breakpoint
*b
;
7795 make_cleanup (xfree
, copy_arg
);
7797 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
, ops
);
7798 set_breakpoint_number (internal
, b
);
7800 b
->addr_string
= canonical
.canonical
[0];
7801 b
->cond_string
= NULL
;
7802 b
->ignore_count
= ignore_count
;
7803 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7804 b
->condition_not_parsed
= 1;
7805 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7806 b
->pspace
= current_program_space
;
7807 b
->py_bp_object
= NULL
;
7809 if (enabled
&& b
->pspace
->executing_startup
7810 && (b
->type
== bp_breakpoint
7811 || b
->type
== bp_hardware_breakpoint
))
7812 b
->enable_state
= bp_startup_disabled
;
7815 /* Do not mention breakpoints with a negative number,
7816 but do notify observers. */
7818 observer_notify_breakpoint_created (b
);
7823 warning (_("Multiple breakpoints were set.\nUse the "
7824 "\"delete\" command to delete unwanted breakpoints."));
7825 prev_breakpoint_count
= prev_bkpt_count
;
7828 /* That's it. Discard the cleanups for data inserted into the
7830 discard_cleanups (bkpt_chain
);
7831 /* But cleanup everything else. */
7832 do_cleanups (old_chain
);
7834 /* error call may happen here - have BKPT_CHAIN already discarded. */
7835 update_global_location_list (1);
7840 /* Set a breakpoint.
7841 ARG is a string describing breakpoint address,
7842 condition, and thread.
7843 FLAG specifies if a breakpoint is hardware on,
7844 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7848 break_command_1 (char *arg
, int flag
, int from_tty
)
7850 int tempflag
= flag
& BP_TEMPFLAG
;
7851 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7852 ? bp_hardware_breakpoint
7855 create_breakpoint (get_current_arch (),
7857 NULL
, 0, 1 /* parse arg */,
7858 tempflag
, type_wanted
,
7859 0 /* Ignore count */,
7860 pending_break_support
,
7861 &bkpt_breakpoint_ops
,
7867 /* Helper function for break_command_1 and disassemble_command. */
7870 resolve_sal_pc (struct symtab_and_line
*sal
)
7874 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7876 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7877 error (_("No line %d in file \"%s\"."),
7878 sal
->line
, sal
->symtab
->filename
);
7881 /* If this SAL corresponds to a breakpoint inserted using a line
7882 number, then skip the function prologue if necessary. */
7883 if (sal
->explicit_line
)
7884 skip_prologue_sal (sal
);
7887 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7889 struct blockvector
*bv
;
7893 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7896 sym
= block_linkage_function (b
);
7899 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7900 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7904 /* It really is worthwhile to have the section, so we'll
7905 just have to look harder. This case can be executed
7906 if we have line numbers but no functions (as can
7907 happen in assembly source). */
7909 struct minimal_symbol
*msym
;
7910 struct cleanup
*old_chain
= save_current_space_and_thread ();
7912 switch_to_program_space_and_thread (sal
->pspace
);
7914 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7916 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7918 do_cleanups (old_chain
);
7925 break_command (char *arg
, int from_tty
)
7927 break_command_1 (arg
, 0, from_tty
);
7931 tbreak_command (char *arg
, int from_tty
)
7933 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7937 hbreak_command (char *arg
, int from_tty
)
7939 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7943 thbreak_command (char *arg
, int from_tty
)
7945 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7949 stop_command (char *arg
, int from_tty
)
7951 printf_filtered (_("Specify the type of breakpoint to set.\n\
7952 Usage: stop in <function | address>\n\
7953 stop at <line>\n"));
7957 stopin_command (char *arg
, int from_tty
)
7961 if (arg
== (char *) NULL
)
7963 else if (*arg
!= '*')
7968 /* Look for a ':'. If this is a line number specification, then
7969 say it is bad, otherwise, it should be an address or
7970 function/method name. */
7971 while (*argptr
&& !hasColon
)
7973 hasColon
= (*argptr
== ':');
7978 badInput
= (*argptr
!= ':'); /* Not a class::method */
7980 badInput
= isdigit (*arg
); /* a simple line number */
7984 printf_filtered (_("Usage: stop in <function | address>\n"));
7986 break_command_1 (arg
, 0, from_tty
);
7990 stopat_command (char *arg
, int from_tty
)
7994 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8001 /* Look for a ':'. If there is a '::' then get out, otherwise
8002 it is probably a line number. */
8003 while (*argptr
&& !hasColon
)
8005 hasColon
= (*argptr
== ':');
8010 badInput
= (*argptr
== ':'); /* we have class::method */
8012 badInput
= !isdigit (*arg
); /* not a line number */
8016 printf_filtered (_("Usage: stop at <line>\n"));
8018 break_command_1 (arg
, 0, from_tty
);
8021 /* Implement the "breakpoint_hit" breakpoint_ops method for
8022 ranged breakpoints. */
8025 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8026 struct address_space
*aspace
,
8029 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8030 bl
->length
, aspace
, bp_addr
);
8033 /* Implement the "resources_needed" breakpoint_ops method for
8034 ranged breakpoints. */
8037 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8039 return target_ranged_break_num_registers ();
8042 /* Implement the "print_it" breakpoint_ops method for
8043 ranged breakpoints. */
8045 static enum print_stop_action
8046 print_it_ranged_breakpoint (bpstat bs
)
8048 struct breakpoint
*b
= bs
->breakpoint_at
;
8049 struct bp_location
*bl
= b
->loc
;
8051 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8053 /* Ranged breakpoints have only one location. */
8054 gdb_assert (bl
&& bl
->next
== NULL
);
8056 annotate_breakpoint (b
->number
);
8057 if (b
->disposition
== disp_del
)
8058 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8060 ui_out_text (uiout
, "\nRanged breakpoint ");
8061 if (ui_out_is_mi_like_p (uiout
))
8063 ui_out_field_string (uiout
, "reason",
8064 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8065 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8067 ui_out_field_int (uiout
, "bkptno", b
->number
);
8068 ui_out_text (uiout
, ", ");
8070 return PRINT_SRC_AND_LOC
;
8073 /* Implement the "print_one" breakpoint_ops method for
8074 ranged breakpoints. */
8077 print_one_ranged_breakpoint (struct breakpoint
*b
,
8078 struct bp_location
**last_loc
)
8080 struct bp_location
*bl
= b
->loc
;
8081 struct value_print_options opts
;
8083 /* Ranged breakpoints have only one location. */
8084 gdb_assert (bl
&& bl
->next
== NULL
);
8086 get_user_print_options (&opts
);
8088 if (opts
.addressprint
)
8089 /* We don't print the address range here, it will be printed later
8090 by print_one_detail_ranged_breakpoint. */
8091 ui_out_field_skip (uiout
, "addr");
8093 print_breakpoint_location (b
, bl
);
8097 /* Implement the "print_one_detail" breakpoint_ops method for
8098 ranged breakpoints. */
8101 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8102 struct ui_out
*uiout
)
8104 CORE_ADDR address_start
, address_end
;
8105 struct bp_location
*bl
= b
->loc
;
8106 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8107 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8111 address_start
= bl
->address
;
8112 address_end
= address_start
+ bl
->length
- 1;
8114 ui_out_text (uiout
, "\taddress range: ");
8115 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8116 print_core_address (bl
->gdbarch
, address_start
),
8117 print_core_address (bl
->gdbarch
, address_end
));
8118 ui_out_field_stream (uiout
, "addr", stb
);
8119 ui_out_text (uiout
, "\n");
8121 do_cleanups (cleanup
);
8124 /* Implement the "print_mention" breakpoint_ops method for
8125 ranged breakpoints. */
8128 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8130 struct bp_location
*bl
= b
->loc
;
8133 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8135 if (ui_out_is_mi_like_p (uiout
))
8138 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8139 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8140 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8143 /* Implement the "print_recreate" breakpoint_ops method for
8144 ranged breakpoints. */
8147 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8149 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8150 b
->addr_string_range_end
);
8153 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8155 static struct breakpoint_ops ranged_breakpoint_ops
;
8157 /* Find the address where the end of the breakpoint range should be
8158 placed, given the SAL of the end of the range. This is so that if
8159 the user provides a line number, the end of the range is set to the
8160 last instruction of the given line. */
8163 find_breakpoint_range_end (struct symtab_and_line sal
)
8167 /* If the user provided a PC value, use it. Otherwise,
8168 find the address of the end of the given location. */
8169 if (sal
.explicit_pc
)
8176 ret
= find_line_pc_range (sal
, &start
, &end
);
8178 error (_("Could not find location of the end of the range."));
8180 /* find_line_pc_range returns the start of the next line. */
8187 /* Implement the "break-range" CLI command. */
8190 break_range_command (char *arg
, int from_tty
)
8192 char *arg_start
, *addr_string_start
, *addr_string_end
;
8193 struct linespec_result canonical_start
, canonical_end
;
8194 int bp_count
, can_use_bp
, length
;
8196 struct breakpoint
*b
;
8197 struct symtab_and_line sal_start
, sal_end
;
8198 struct symtabs_and_lines sals_start
, sals_end
;
8199 struct cleanup
*cleanup_bkpt
;
8201 /* We don't support software ranged breakpoints. */
8202 if (target_ranged_break_num_registers () < 0)
8203 error (_("This target does not support hardware ranged breakpoints."));
8205 bp_count
= hw_breakpoint_used_count ();
8206 bp_count
+= target_ranged_break_num_registers ();
8207 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8210 error (_("Hardware breakpoints used exceeds limit."));
8212 if (arg
== NULL
|| arg
[0] == '\0')
8213 error(_("No address range specified."));
8215 sals_start
.sals
= NULL
;
8216 sals_start
.nelts
= 0;
8217 init_linespec_result (&canonical_start
);
8219 while (*arg
== ' ' || *arg
== '\t')
8222 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8224 sal_start
= sals_start
.sals
[0];
8225 addr_string_start
= canonical_start
.canonical
[0];
8226 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8227 xfree (sals_start
.sals
);
8228 xfree (canonical_start
.canonical
);
8231 error (_("Too few arguments."));
8232 else if (sals_start
.nelts
== 0)
8233 error (_("Could not find location of the beginning of the range."));
8234 else if (sals_start
.nelts
!= 1)
8235 error (_("Cannot create a ranged breakpoint with multiple locations."));
8237 resolve_sal_pc (&sal_start
);
8239 arg
++; /* Skip the comma. */
8240 while (*arg
== ' ' || *arg
== '\t')
8243 /* Parse the end location. */
8245 sals_end
.sals
= NULL
;
8247 init_linespec_result (&canonical_end
);
8250 /* We call decode_line_1 directly here instead of using
8251 parse_breakpoint_sals because we need to specify the start location's
8252 symtab and line as the default symtab and line for the end of the
8253 range. This makes it possible to have ranges like "foo.c:27, +14",
8254 where +14 means 14 lines from the start location. */
8255 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8258 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8259 if (canonical_end
.canonical
== NULL
)
8260 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8261 /* Add the string if not present. */
8262 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8263 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8265 sal_end
= sals_end
.sals
[0];
8266 addr_string_end
= canonical_end
.canonical
[0];
8267 make_cleanup (xfree
, addr_string_end
);
8268 xfree (sals_end
.sals
);
8269 xfree (canonical_end
.canonical
);
8271 if (sals_end
.nelts
== 0)
8272 error (_("Could not find location of the end of the range."));
8273 else if (sals_end
.nelts
!= 1)
8274 error (_("Cannot create a ranged breakpoint with multiple locations."));
8276 resolve_sal_pc (&sal_end
);
8278 end
= find_breakpoint_range_end (sal_end
);
8279 if (sal_start
.pc
> end
)
8280 error (_("Invalid address range, end precedes start."));
8282 length
= end
- sal_start
.pc
+ 1;
8284 /* Length overflowed. */
8285 error (_("Address range too large."));
8286 else if (length
== 1)
8288 /* This range is simple enough to be handled by
8289 the `hbreak' command. */
8290 hbreak_command (addr_string_start
, 1);
8292 do_cleanups (cleanup_bkpt
);
8297 /* Now set up the breakpoint. */
8298 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8299 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8300 set_breakpoint_count (breakpoint_count
+ 1);
8301 b
->number
= breakpoint_count
;
8302 b
->disposition
= disp_donttouch
;
8303 b
->addr_string
= addr_string_start
;
8304 b
->addr_string_range_end
= addr_string_end
;
8305 b
->loc
->length
= length
;
8307 discard_cleanups (cleanup_bkpt
);
8310 observer_notify_breakpoint_created (b
);
8311 update_global_location_list (1);
8314 /* Return non-zero if EXP is verified as constant. Returned zero
8315 means EXP is variable. Also the constant detection may fail for
8316 some constant expressions and in such case still falsely return
8319 watchpoint_exp_is_const (const struct expression
*exp
)
8327 /* We are only interested in the descriptor of each element. */
8328 operator_length (exp
, i
, &oplenp
, &argsp
);
8331 switch (exp
->elts
[i
].opcode
)
8341 case BINOP_LOGICAL_AND
:
8342 case BINOP_LOGICAL_OR
:
8343 case BINOP_BITWISE_AND
:
8344 case BINOP_BITWISE_IOR
:
8345 case BINOP_BITWISE_XOR
:
8347 case BINOP_NOTEQUAL
:
8363 case TERNOP_SLICE_COUNT
:
8375 case OP_OBJC_NSSTRING
:
8378 case UNOP_LOGICAL_NOT
:
8379 case UNOP_COMPLEMENT
:
8382 /* Unary, binary and ternary operators: We have to check
8383 their operands. If they are constant, then so is the
8384 result of that operation. For instance, if A and B are
8385 determined to be constants, then so is "A + B".
8387 UNOP_IND is one exception to the rule above, because the
8388 value of *ADDR is not necessarily a constant, even when
8393 /* Check whether the associated symbol is a constant.
8395 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8396 possible that a buggy compiler could mark a variable as
8397 constant even when it is not, and TYPE_CONST would return
8398 true in this case, while SYMBOL_CLASS wouldn't.
8400 We also have to check for function symbols because they
8401 are always constant. */
8403 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8405 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8406 && SYMBOL_CLASS (s
) != LOC_CONST
8407 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8412 /* The default action is to return 0 because we are using
8413 the optimistic approach here: If we don't know something,
8414 then it is not a constant. */
8423 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8426 re_set_watchpoint (struct breakpoint
*b
)
8428 /* Watchpoint can be either on expression using entirely global
8429 variables, or it can be on local variables.
8431 Watchpoints of the first kind are never auto-deleted, and even
8432 persist across program restarts. Since they can use variables
8433 from shared libraries, we need to reparse expression as libraries
8434 are loaded and unloaded.
8436 Watchpoints on local variables can also change meaning as result
8437 of solib event. For example, if a watchpoint uses both a local
8438 and a global variables in expression, it's a local watchpoint,
8439 but unloading of a shared library will make the expression
8440 invalid. This is not a very common use case, but we still
8441 re-evaluate expression, to avoid surprises to the user.
8443 Note that for local watchpoints, we re-evaluate it only if
8444 watchpoints frame id is still valid. If it's not, it means the
8445 watchpoint is out of scope and will be deleted soon. In fact,
8446 I'm not sure we'll ever be called in this case.
8448 If a local watchpoint's frame id is still valid, then
8449 b->exp_valid_block is likewise valid, and we can safely use it.
8451 Don't do anything about disabled watchpoints, since they will
8452 be reevaluated again when enabled. */
8453 update_watchpoint (b
, 1 /* reparse */);
8456 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8459 insert_watchpoint (struct bp_location
*bl
)
8461 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8463 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8464 bl
->owner
->cond_exp
);
8467 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8470 remove_watchpoint (struct bp_location
*bl
)
8472 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8474 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8475 bl
->owner
->cond_exp
);
8479 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8480 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8482 struct breakpoint
*b
= bl
->owner
;
8484 /* Continuable hardware watchpoints are treated as non-existent if the
8485 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8486 some data address). Otherwise gdb won't stop on a break instruction
8487 in the code (not from a breakpoint) when a hardware watchpoint has
8488 been defined. Also skip watchpoints which we know did not trigger
8489 (did not match the data address). */
8490 if (is_hardware_watchpoint (b
)
8491 && b
->watchpoint_triggered
== watch_triggered_no
)
8498 check_status_watchpoint (bpstat bs
)
8500 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8502 bpstat_check_watchpoint (bs
);
8505 /* Implement the "resources_needed" breakpoint_ops method for
8506 hardware watchpoints. */
8509 resources_needed_watchpoint (const struct bp_location
*bl
)
8511 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8513 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8516 /* Implement the "works_in_software_mode" breakpoint_ops method for
8517 hardware watchpoints. */
8520 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8522 return b
->type
== bp_hardware_watchpoint
;
8525 static enum print_stop_action
8526 print_it_watchpoint (bpstat bs
)
8528 struct cleanup
*old_chain
;
8529 struct breakpoint
*b
;
8530 const struct bp_location
*bl
;
8531 struct ui_stream
*stb
;
8532 enum print_stop_action result
;
8534 gdb_assert (bs
->bp_location_at
!= NULL
);
8536 bl
= bs
->bp_location_at
;
8537 b
= bs
->breakpoint_at
;
8539 stb
= ui_out_stream_new (uiout
);
8540 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8545 case bp_hardware_watchpoint
:
8546 annotate_watchpoint (b
->number
);
8547 if (ui_out_is_mi_like_p (uiout
))
8550 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8552 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8553 ui_out_text (uiout
, "\nOld value = ");
8554 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8555 ui_out_field_stream (uiout
, "old", stb
);
8556 ui_out_text (uiout
, "\nNew value = ");
8557 watchpoint_value_print (b
->val
, stb
->stream
);
8558 ui_out_field_stream (uiout
, "new", stb
);
8559 ui_out_text (uiout
, "\n");
8560 /* More than one watchpoint may have been triggered. */
8561 result
= PRINT_UNKNOWN
;
8564 case bp_read_watchpoint
:
8565 if (ui_out_is_mi_like_p (uiout
))
8568 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8570 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8571 ui_out_text (uiout
, "\nValue = ");
8572 watchpoint_value_print (b
->val
, stb
->stream
);
8573 ui_out_field_stream (uiout
, "value", stb
);
8574 ui_out_text (uiout
, "\n");
8575 result
= PRINT_UNKNOWN
;
8578 case bp_access_watchpoint
:
8579 if (bs
->old_val
!= NULL
)
8581 annotate_watchpoint (b
->number
);
8582 if (ui_out_is_mi_like_p (uiout
))
8585 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8587 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8588 ui_out_text (uiout
, "\nOld value = ");
8589 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8590 ui_out_field_stream (uiout
, "old", stb
);
8591 ui_out_text (uiout
, "\nNew value = ");
8596 if (ui_out_is_mi_like_p (uiout
))
8599 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8600 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8601 ui_out_text (uiout
, "\nValue = ");
8603 watchpoint_value_print (b
->val
, stb
->stream
);
8604 ui_out_field_stream (uiout
, "new", stb
);
8605 ui_out_text (uiout
, "\n");
8606 result
= PRINT_UNKNOWN
;
8609 result
= PRINT_UNKNOWN
;
8612 do_cleanups (old_chain
);
8616 /* Implement the "print_mention" breakpoint_ops method for hardware
8620 print_mention_watchpoint (struct breakpoint
*b
)
8622 struct cleanup
*ui_out_chain
;
8627 ui_out_text (uiout
, "Watchpoint ");
8628 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8630 case bp_hardware_watchpoint
:
8631 ui_out_text (uiout
, "Hardware watchpoint ");
8632 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8634 case bp_read_watchpoint
:
8635 ui_out_text (uiout
, "Hardware read watchpoint ");
8636 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8638 case bp_access_watchpoint
:
8639 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8640 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8643 internal_error (__FILE__
, __LINE__
,
8644 _("Invalid hardware watchpoint type."));
8647 ui_out_field_int (uiout
, "number", b
->number
);
8648 ui_out_text (uiout
, ": ");
8649 ui_out_field_string (uiout
, "exp", b
->exp_string
);
8650 do_cleanups (ui_out_chain
);
8653 /* Implement the "print_recreate" breakpoint_ops method for
8657 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8662 case bp_hardware_watchpoint
:
8663 fprintf_unfiltered (fp
, "watch");
8665 case bp_read_watchpoint
:
8666 fprintf_unfiltered (fp
, "rwatch");
8668 case bp_access_watchpoint
:
8669 fprintf_unfiltered (fp
, "awatch");
8672 internal_error (__FILE__
, __LINE__
,
8673 _("Invalid watchpoint type."));
8676 fprintf_unfiltered (fp
, " %s", b
->exp_string
);
8679 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8681 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8683 /* Implement the "insert" breakpoint_ops method for
8684 masked hardware watchpoints. */
8687 insert_masked_watchpoint (struct bp_location
*bl
)
8689 return target_insert_mask_watchpoint (bl
->address
, bl
->owner
->hw_wp_mask
,
8690 bl
->watchpoint_type
);
8693 /* Implement the "remove" breakpoint_ops method for
8694 masked hardware watchpoints. */
8697 remove_masked_watchpoint (struct bp_location
*bl
)
8699 return target_remove_mask_watchpoint (bl
->address
, bl
->owner
->hw_wp_mask
,
8700 bl
->watchpoint_type
);
8703 /* Implement the "resources_needed" breakpoint_ops method for
8704 masked hardware watchpoints. */
8707 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8709 return target_masked_watch_num_registers (bl
->address
,
8710 bl
->owner
->hw_wp_mask
);
8713 /* Implement the "works_in_software_mode" breakpoint_ops method for
8714 masked hardware watchpoints. */
8717 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8722 /* Implement the "print_it" breakpoint_ops method for
8723 masked hardware watchpoints. */
8725 static enum print_stop_action
8726 print_it_masked_watchpoint (bpstat bs
)
8728 struct breakpoint
*b
= bs
->breakpoint_at
;
8730 /* Masked watchpoints have only one location. */
8731 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8735 case bp_hardware_watchpoint
:
8736 annotate_watchpoint (b
->number
);
8737 if (ui_out_is_mi_like_p (uiout
))
8740 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8743 case bp_read_watchpoint
:
8744 if (ui_out_is_mi_like_p (uiout
))
8747 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8750 case bp_access_watchpoint
:
8751 if (ui_out_is_mi_like_p (uiout
))
8754 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8757 internal_error (__FILE__
, __LINE__
,
8758 _("Invalid hardware watchpoint type."));
8762 ui_out_text (uiout
, _("\n\
8763 Check the underlying instruction at PC for the memory\n\
8764 address and value which triggered this watchpoint.\n"));
8765 ui_out_text (uiout
, "\n");
8767 /* More than one watchpoint may have been triggered. */
8768 return PRINT_UNKNOWN
;
8771 /* Implement the "print_one_detail" breakpoint_ops method for
8772 masked hardware watchpoints. */
8775 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8776 struct ui_out
*uiout
)
8778 /* Masked watchpoints have only one location. */
8779 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8781 ui_out_text (uiout
, "\tmask ");
8782 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, b
->hw_wp_mask
);
8783 ui_out_text (uiout
, "\n");
8786 /* Implement the "print_mention" breakpoint_ops method for
8787 masked hardware watchpoints. */
8790 print_mention_masked_watchpoint (struct breakpoint
*b
)
8792 struct cleanup
*ui_out_chain
;
8796 case bp_hardware_watchpoint
:
8797 ui_out_text (uiout
, "Masked hardware watchpoint ");
8798 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8800 case bp_read_watchpoint
:
8801 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8802 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8804 case bp_access_watchpoint
:
8805 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8806 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8809 internal_error (__FILE__
, __LINE__
,
8810 _("Invalid hardware watchpoint type."));
8813 ui_out_field_int (uiout
, "number", b
->number
);
8814 ui_out_text (uiout
, ": ");
8815 ui_out_field_string (uiout
, "exp", b
->exp_string
);
8816 do_cleanups (ui_out_chain
);
8819 /* Implement the "print_recreate" breakpoint_ops method for
8820 masked hardware watchpoints. */
8823 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8829 case bp_hardware_watchpoint
:
8830 fprintf_unfiltered (fp
, "watch");
8832 case bp_read_watchpoint
:
8833 fprintf_unfiltered (fp
, "rwatch");
8835 case bp_access_watchpoint
:
8836 fprintf_unfiltered (fp
, "awatch");
8839 internal_error (__FILE__
, __LINE__
,
8840 _("Invalid hardware watchpoint type."));
8843 sprintf_vma (tmp
, b
->hw_wp_mask
);
8844 fprintf_unfiltered (fp
, " %s mask 0x%s", b
->exp_string
, tmp
);
8847 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
8849 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
8851 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
8854 is_masked_watchpoint (const struct breakpoint
*b
)
8856 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
8859 /* accessflag: hw_write: watch write,
8860 hw_read: watch read,
8861 hw_access: watch access (read or write) */
8863 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8864 int just_location
, int internal
)
8866 volatile struct gdb_exception e
;
8867 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8868 struct expression
*exp
;
8869 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8870 struct value
*val
, *mark
, *result
;
8871 struct frame_info
*frame
;
8872 char *exp_start
= NULL
;
8873 char *exp_end
= NULL
;
8874 char *tok
, *end_tok
;
8876 char *cond_start
= NULL
;
8877 char *cond_end
= NULL
;
8878 enum bptype bp_type
;
8881 /* Flag to indicate whether we are going to use masks for
8882 the hardware watchpoint. */
8886 /* Make sure that we actually have parameters to parse. */
8887 if (arg
!= NULL
&& arg
[0] != '\0')
8891 /* Look for "parameter value" pairs at the end
8892 of the arguments string. */
8893 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
8895 /* Skip whitespace at the end of the argument list. */
8896 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8899 /* Find the beginning of the last token.
8900 This is the value of the parameter. */
8901 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8903 value_start
= tok
+ 1;
8905 /* Skip whitespace. */
8906 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8911 /* Find the beginning of the second to last token.
8912 This is the parameter itself. */
8913 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8916 toklen
= end_tok
- tok
+ 1;
8918 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
8920 /* At this point we've found a "thread" token, which means
8921 the user is trying to set a watchpoint that triggers
8922 only in a specific thread. */
8926 error(_("You can specify only one thread."));
8928 /* Extract the thread ID from the next token. */
8929 thread
= strtol (value_start
, &endp
, 0);
8931 /* Check if the user provided a valid numeric value for the
8933 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8934 error (_("Invalid thread ID specification %s."), value_start
);
8936 /* Check if the thread actually exists. */
8937 if (!valid_thread_id (thread
))
8938 error (_("Unknown thread %d."), thread
);
8940 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
8942 /* We've found a "mask" token, which means the user wants to
8943 create a hardware watchpoint that is going to have the mask
8945 struct value
*mask_value
, *mark
;
8948 error(_("You can specify only one mask."));
8950 use_mask
= just_location
= 1;
8952 mark
= value_mark ();
8953 mask_value
= parse_to_comma_and_eval (&value_start
);
8954 mask
= value_as_address (mask_value
);
8955 value_free_to_mark (mark
);
8958 /* We didn't recognize what we found. We should stop here. */
8961 /* Truncate the string and get rid of the "parameter value" pair before
8962 the arguments string is parsed by the parse_exp_1 function. */
8967 /* Parse the rest of the arguments. */
8968 innermost_block
= NULL
;
8970 exp
= parse_exp_1 (&arg
, 0, 0);
8972 /* Remove trailing whitespace from the expression before saving it.
8973 This makes the eventual display of the expression string a bit
8975 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8978 /* Checking if the expression is not constant. */
8979 if (watchpoint_exp_is_const (exp
))
8983 len
= exp_end
- exp_start
;
8984 while (len
> 0 && isspace (exp_start
[len
- 1]))
8986 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8989 exp_valid_block
= innermost_block
;
8990 mark
= value_mark ();
8991 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8997 exp_valid_block
= NULL
;
8998 val
= value_addr (result
);
8999 release_value (val
);
9000 value_free_to_mark (mark
);
9004 ret
= target_masked_watch_num_registers (value_as_address (val
),
9007 error (_("This target does not support masked watchpoints."));
9009 error (_("Invalid mask or memory region."));
9012 else if (val
!= NULL
)
9013 release_value (val
);
9015 tok
= skip_spaces (arg
);
9016 end_tok
= skip_to_space (tok
);
9018 toklen
= end_tok
- tok
;
9019 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9021 struct expression
*cond
;
9023 innermost_block
= NULL
;
9024 tok
= cond_start
= end_tok
+ 1;
9025 cond
= parse_exp_1 (&tok
, 0, 0);
9027 /* The watchpoint expression may not be local, but the condition
9028 may still be. E.g.: `watch global if local > 0'. */
9029 cond_exp_valid_block
= innermost_block
;
9035 error (_("Junk at end of command."));
9037 if (accessflag
== hw_read
)
9038 bp_type
= bp_read_watchpoint
;
9039 else if (accessflag
== hw_access
)
9040 bp_type
= bp_access_watchpoint
;
9042 bp_type
= bp_hardware_watchpoint
;
9044 frame
= block_innermost_frame (exp_valid_block
);
9046 /* If the expression is "local", then set up a "watchpoint scope"
9047 breakpoint at the point where we've left the scope of the watchpoint
9048 expression. Create the scope breakpoint before the watchpoint, so
9049 that we will encounter it first in bpstat_stop_status. */
9050 if (exp_valid_block
&& frame
)
9052 if (frame_id_p (frame_unwind_caller_id (frame
)))
9055 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9056 frame_unwind_caller_pc (frame
),
9057 bp_watchpoint_scope
,
9058 &momentary_breakpoint_ops
);
9060 scope_breakpoint
->enable_state
= bp_enabled
;
9062 /* Automatically delete the breakpoint when it hits. */
9063 scope_breakpoint
->disposition
= disp_del
;
9065 /* Only break in the proper frame (help with recursion). */
9066 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9068 /* Set the address at which we will stop. */
9069 scope_breakpoint
->loc
->gdbarch
9070 = frame_unwind_caller_arch (frame
);
9071 scope_breakpoint
->loc
->requested_address
9072 = frame_unwind_caller_pc (frame
);
9073 scope_breakpoint
->loc
->address
9074 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9075 scope_breakpoint
->loc
->requested_address
,
9076 scope_breakpoint
->type
);
9080 /* Now set up the breakpoint. */
9082 b
= set_raw_breakpoint_without_location (NULL
, bp_type
,
9083 &masked_watchpoint_breakpoint_ops
);
9085 b
= set_raw_breakpoint_without_location (NULL
, bp_type
,
9086 &watchpoint_breakpoint_ops
);
9088 b
->disposition
= disp_donttouch
;
9090 b
->exp_valid_block
= exp_valid_block
;
9091 b
->cond_exp_valid_block
= cond_exp_valid_block
;
9092 b
->pspace
= current_program_space
;
9095 struct type
*t
= value_type (val
);
9096 CORE_ADDR addr
= value_as_address (val
);
9099 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9100 name
= type_to_string (t
);
9102 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9103 core_addr_to_string (addr
));
9106 b
->exp_string
= xstrprintf ("-location %.*s",
9107 (int) (exp_end
- exp_start
), exp_start
);
9109 /* The above expression is in C. */
9110 b
->language
= language_c
;
9113 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9117 b
->hw_wp_mask
= mask
;
9126 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9132 b
->watchpoint_frame
= get_frame_id (frame
);
9133 b
->watchpoint_thread
= inferior_ptid
;
9137 b
->watchpoint_frame
= null_frame_id
;
9138 b
->watchpoint_thread
= null_ptid
;
9141 if (scope_breakpoint
!= NULL
)
9143 /* The scope breakpoint is related to the watchpoint. We will
9144 need to act on them together. */
9145 b
->related_breakpoint
= scope_breakpoint
;
9146 scope_breakpoint
->related_breakpoint
= b
;
9150 value_free_to_mark (mark
);
9152 TRY_CATCH (e
, RETURN_MASK_ALL
)
9154 /* Finally update the new watchpoint. This creates the locations
9155 that should be inserted. */
9156 update_watchpoint (b
, 1);
9160 delete_breakpoint (b
);
9161 throw_exception (e
);
9164 set_breakpoint_number (internal
, b
);
9166 /* Do not mention breakpoints with a negative number, but do
9167 notify observers. */
9170 observer_notify_breakpoint_created (b
);
9172 update_global_location_list (1);
9175 /* Return count of debug registers needed to watch the given expression.
9176 If the watchpoint cannot be handled in hardware return zero. */
9179 can_use_hardware_watchpoint (struct value
*v
)
9181 int found_memory_cnt
= 0;
9182 struct value
*head
= v
;
9184 /* Did the user specifically forbid us to use hardware watchpoints? */
9185 if (!can_use_hw_watchpoints
)
9188 /* Make sure that the value of the expression depends only upon
9189 memory contents, and values computed from them within GDB. If we
9190 find any register references or function calls, we can't use a
9191 hardware watchpoint.
9193 The idea here is that evaluating an expression generates a series
9194 of values, one holding the value of every subexpression. (The
9195 expression a*b+c has five subexpressions: a, b, a*b, c, and
9196 a*b+c.) GDB's values hold almost enough information to establish
9197 the criteria given above --- they identify memory lvalues,
9198 register lvalues, computed values, etcetera. So we can evaluate
9199 the expression, and then scan the chain of values that leaves
9200 behind to decide whether we can detect any possible change to the
9201 expression's final value using only hardware watchpoints.
9203 However, I don't think that the values returned by inferior
9204 function calls are special in any way. So this function may not
9205 notice that an expression involving an inferior function call
9206 can't be watched with hardware watchpoints. FIXME. */
9207 for (; v
; v
= value_next (v
))
9209 if (VALUE_LVAL (v
) == lval_memory
)
9211 if (v
!= head
&& value_lazy (v
))
9212 /* A lazy memory lvalue in the chain is one that GDB never
9213 needed to fetch; we either just used its address (e.g.,
9214 `a' in `a.b') or we never needed it at all (e.g., `a'
9215 in `a,b'). This doesn't apply to HEAD; if that is
9216 lazy then it was not readable, but watch it anyway. */
9220 /* Ahh, memory we actually used! Check if we can cover
9221 it with hardware watchpoints. */
9222 struct type
*vtype
= check_typedef (value_type (v
));
9224 /* We only watch structs and arrays if user asked for it
9225 explicitly, never if they just happen to appear in a
9226 middle of some value chain. */
9228 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9229 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9231 CORE_ADDR vaddr
= value_address (v
);
9235 len
= (target_exact_watchpoints
9236 && is_scalar_type_recursive (vtype
))?
9237 1 : TYPE_LENGTH (value_type (v
));
9239 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9243 found_memory_cnt
+= num_regs
;
9247 else if (VALUE_LVAL (v
) != not_lval
9248 && deprecated_value_modifiable (v
) == 0)
9249 return 0; /* These are values from the history (e.g., $1). */
9250 else if (VALUE_LVAL (v
) == lval_register
)
9251 return 0; /* Cannot watch a register with a HW watchpoint. */
9254 /* The expression itself looks suitable for using a hardware
9255 watchpoint, but give the target machine a chance to reject it. */
9256 return found_memory_cnt
;
9260 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9262 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9265 /* A helper function that looks for an argument at the start of a
9266 string. The argument must also either be at the end of the string,
9267 or be followed by whitespace. Returns 1 if it finds the argument,
9268 0 otherwise. If the argument is found, it updates *STR. */
9271 check_for_argument (char **str
, char *arg
, int arg_len
)
9273 if (strncmp (*str
, arg
, arg_len
) == 0
9274 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9282 /* A helper function that looks for the "-location" argument and then
9283 calls watch_command_1. */
9286 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9288 int just_location
= 0;
9291 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9292 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9294 arg
= skip_spaces (arg
);
9298 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9302 watch_command (char *arg
, int from_tty
)
9304 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9308 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9310 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9314 rwatch_command (char *arg
, int from_tty
)
9316 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9320 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9322 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9326 awatch_command (char *arg
, int from_tty
)
9328 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9332 /* Helper routines for the until_command routine in infcmd.c. Here
9333 because it uses the mechanisms of breakpoints. */
9335 struct until_break_command_continuation_args
9337 struct breakpoint
*breakpoint
;
9338 struct breakpoint
*breakpoint2
;
9342 /* This function is called by fetch_inferior_event via the
9343 cmd_continuation pointer, to complete the until command. It takes
9344 care of cleaning up the temporary breakpoints set up by the until
9347 until_break_command_continuation (void *arg
, int err
)
9349 struct until_break_command_continuation_args
*a
= arg
;
9351 delete_breakpoint (a
->breakpoint
);
9353 delete_breakpoint (a
->breakpoint2
);
9354 delete_longjmp_breakpoint (a
->thread_num
);
9358 until_break_command (char *arg
, int from_tty
, int anywhere
)
9360 struct symtabs_and_lines sals
;
9361 struct symtab_and_line sal
;
9362 struct frame_info
*frame
= get_selected_frame (NULL
);
9363 struct breakpoint
*breakpoint
;
9364 struct breakpoint
*breakpoint2
= NULL
;
9365 struct cleanup
*old_chain
;
9367 struct thread_info
*tp
;
9369 clear_proceed_status ();
9371 /* Set a breakpoint where the user wants it and at return from
9374 if (default_breakpoint_valid
)
9375 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
9376 default_breakpoint_line
, NULL
);
9378 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9380 if (sals
.nelts
!= 1)
9381 error (_("Couldn't get information on specified line."));
9384 xfree (sals
.sals
); /* malloc'd, so freed. */
9387 error (_("Junk at end of arguments."));
9389 resolve_sal_pc (&sal
);
9392 /* If the user told us to continue until a specified location,
9393 we don't specify a frame at which we need to stop. */
9394 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9395 null_frame_id
, bp_until
);
9397 /* Otherwise, specify the selected frame, because we want to stop
9398 only at the very same frame. */
9399 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9400 get_stack_frame_id (frame
),
9403 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9405 tp
= inferior_thread ();
9408 /* Keep within the current frame, or in frames called by the current
9411 if (frame_id_p (frame_unwind_caller_id (frame
)))
9413 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9414 sal
.pc
= frame_unwind_caller_pc (frame
);
9415 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9417 frame_unwind_caller_id (frame
),
9419 make_cleanup_delete_breakpoint (breakpoint2
);
9421 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9422 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9425 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9427 /* If we are running asynchronously, and proceed call above has
9428 actually managed to start the target, arrange for breakpoints to
9429 be deleted when the target stops. Otherwise, we're already
9430 stopped and delete breakpoints via cleanup chain. */
9432 if (target_can_async_p () && is_running (inferior_ptid
))
9434 struct until_break_command_continuation_args
*args
;
9435 args
= xmalloc (sizeof (*args
));
9437 args
->breakpoint
= breakpoint
;
9438 args
->breakpoint2
= breakpoint2
;
9439 args
->thread_num
= thread
;
9441 discard_cleanups (old_chain
);
9442 add_continuation (inferior_thread (),
9443 until_break_command_continuation
, args
,
9447 do_cleanups (old_chain
);
9450 /* This function attempts to parse an optional "if <cond>" clause
9451 from the arg string. If one is not found, it returns NULL.
9453 Else, it returns a pointer to the condition string. (It does not
9454 attempt to evaluate the string against a particular block.) And,
9455 it updates arg to point to the first character following the parsed
9456 if clause in the arg string. */
9459 ep_parse_optional_if_clause (char **arg
)
9463 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9466 /* Skip the "if" keyword. */
9469 /* Skip any extra leading whitespace, and record the start of the
9470 condition string. */
9471 *arg
= skip_spaces (*arg
);
9474 /* Assume that the condition occupies the remainder of the arg
9476 (*arg
) += strlen (cond_string
);
9481 /* Commands to deal with catching events, such as signals, exceptions,
9482 process start/exit, etc. */
9486 catch_fork_temporary
, catch_vfork_temporary
,
9487 catch_fork_permanent
, catch_vfork_permanent
9492 catch_fork_command_1 (char *arg
, int from_tty
,
9493 struct cmd_list_element
*command
)
9495 struct gdbarch
*gdbarch
= get_current_arch ();
9496 char *cond_string
= NULL
;
9497 catch_fork_kind fork_kind
;
9500 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9501 tempflag
= (fork_kind
== catch_fork_temporary
9502 || fork_kind
== catch_vfork_temporary
);
9506 arg
= skip_spaces (arg
);
9508 /* The allowed syntax is:
9510 catch [v]fork if <cond>
9512 First, check if there's an if clause. */
9513 cond_string
= ep_parse_optional_if_clause (&arg
);
9515 if ((*arg
!= '\0') && !isspace (*arg
))
9516 error (_("Junk at end of arguments."));
9518 /* If this target supports it, create a fork or vfork catchpoint
9519 and enable reporting of such events. */
9522 case catch_fork_temporary
:
9523 case catch_fork_permanent
:
9524 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9525 &catch_fork_breakpoint_ops
);
9527 case catch_vfork_temporary
:
9528 case catch_vfork_permanent
:
9529 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9530 &catch_vfork_breakpoint_ops
);
9533 error (_("unsupported or unknown fork kind; cannot catch it"));
9539 catch_exec_command_1 (char *arg
, int from_tty
,
9540 struct cmd_list_element
*command
)
9542 struct exec_catchpoint
*c
;
9543 struct gdbarch
*gdbarch
= get_current_arch ();
9545 char *cond_string
= NULL
;
9547 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9551 arg
= skip_spaces (arg
);
9553 /* The allowed syntax is:
9555 catch exec if <cond>
9557 First, check if there's an if clause. */
9558 cond_string
= ep_parse_optional_if_clause (&arg
);
9560 if ((*arg
!= '\0') && !isspace (*arg
))
9561 error (_("Junk at end of arguments."));
9563 c
= XNEW (struct exec_catchpoint
);
9564 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9565 &catch_exec_breakpoint_ops
);
9566 c
->exec_pathname
= NULL
;
9568 install_breakpoint (&c
->base
);
9571 static enum print_stop_action
9572 print_it_exception_catchpoint (bpstat bs
)
9574 struct breakpoint
*b
= bs
->breakpoint_at
;
9575 int bp_temp
, bp_throw
;
9577 annotate_catchpoint (b
->number
);
9579 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9580 if (b
->loc
->address
!= b
->loc
->requested_address
)
9581 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9584 bp_temp
= b
->disposition
== disp_del
;
9586 bp_temp
? "Temporary catchpoint "
9588 if (!ui_out_is_mi_like_p (uiout
))
9589 ui_out_field_int (uiout
, "bkptno", b
->number
);
9591 bp_throw
? " (exception thrown), "
9592 : " (exception caught), ");
9593 if (ui_out_is_mi_like_p (uiout
))
9595 ui_out_field_string (uiout
, "reason",
9596 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9597 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9598 ui_out_field_int (uiout
, "bkptno", b
->number
);
9600 return PRINT_SRC_AND_LOC
;
9604 print_one_exception_catchpoint (struct breakpoint
*b
,
9605 struct bp_location
**last_loc
)
9607 struct value_print_options opts
;
9609 get_user_print_options (&opts
);
9610 if (opts
.addressprint
)
9613 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9614 ui_out_field_string (uiout
, "addr", "<PENDING>");
9616 ui_out_field_core_addr (uiout
, "addr",
9617 b
->loc
->gdbarch
, b
->loc
->address
);
9622 if (strstr (b
->addr_string
, "throw") != NULL
)
9623 ui_out_field_string (uiout
, "what", "exception throw");
9625 ui_out_field_string (uiout
, "what", "exception catch");
9629 print_mention_exception_catchpoint (struct breakpoint
*b
)
9634 bp_temp
= b
->disposition
== disp_del
;
9635 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9636 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9637 : _("Catchpoint "));
9638 ui_out_field_int (uiout
, "bkptno", b
->number
);
9639 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9643 /* Implement the "print_recreate" breakpoint_ops method for throw and
9644 catch catchpoints. */
9647 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9653 bp_temp
= b
->disposition
== disp_del
;
9654 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9655 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9656 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9659 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9662 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9663 enum exception_event_kind ex_event
, int from_tty
)
9665 char *trigger_func_name
;
9667 if (ex_event
== EX_EVENT_CATCH
)
9668 trigger_func_name
= "__cxa_begin_catch";
9670 trigger_func_name
= "__cxa_throw";
9672 create_breakpoint (get_current_arch (),
9673 trigger_func_name
, cond_string
, -1,
9674 0 /* condition and thread are valid. */,
9675 tempflag
, bp_breakpoint
,
9677 AUTO_BOOLEAN_TRUE
/* pending */,
9678 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9685 /* Deal with "catch catch" and "catch throw" commands. */
9688 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9689 int tempflag
, int from_tty
)
9691 char *cond_string
= NULL
;
9695 arg
= skip_spaces (arg
);
9697 cond_string
= ep_parse_optional_if_clause (&arg
);
9699 if ((*arg
!= '\0') && !isspace (*arg
))
9700 error (_("Junk at end of arguments."));
9702 if (ex_event
!= EX_EVENT_THROW
9703 && ex_event
!= EX_EVENT_CATCH
)
9704 error (_("Unsupported or unknown exception event; cannot catch it"));
9706 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9709 warning (_("Unsupported with this platform/compiler combination."));
9712 /* Implementation of "catch catch" command. */
9715 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9717 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9719 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9722 /* Implementation of "catch throw" command. */
9725 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9727 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9729 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9733 init_ada_exception_breakpoint (struct breakpoint
*b
,
9734 struct gdbarch
*gdbarch
,
9735 struct symtab_and_line sal
,
9737 struct breakpoint_ops
*ops
,
9743 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9745 loc_gdbarch
= gdbarch
;
9747 describe_other_breakpoints (loc_gdbarch
,
9748 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9749 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9750 version for exception catchpoints, because two catchpoints
9751 used for different exception names will use the same address.
9752 In this case, a "breakpoint ... also set at..." warning is
9753 unproductive. Besides, the warning phrasing is also a bit
9754 inappropriate, we should use the word catchpoint, and tell
9755 the user what type of catchpoint it is. The above is good
9756 enough for now, though. */
9759 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9761 b
->enable_state
= bp_enabled
;
9762 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9763 b
->addr_string
= addr_string
;
9764 b
->language
= language_ada
;
9767 /* Cleanup function for a syscall filter list. */
9769 clean_up_filters (void *arg
)
9771 VEC(int) *iter
= *(VEC(int) **) arg
;
9772 VEC_free (int, iter
);
9775 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9776 filter list, or NULL if no filtering is required. */
9778 catch_syscall_split_args (char *arg
)
9780 VEC(int) *result
= NULL
;
9781 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9783 while (*arg
!= '\0')
9785 int i
, syscall_number
;
9790 /* Skip whitespace. */
9791 while (isspace (*arg
))
9794 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9795 cur_name
[i
] = arg
[i
];
9799 /* Check if the user provided a syscall name or a number. */
9800 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9801 if (*endptr
== '\0')
9802 get_syscall_by_number (syscall_number
, &s
);
9805 /* We have a name. Let's check if it's valid and convert it
9807 get_syscall_by_name (cur_name
, &s
);
9809 if (s
.number
== UNKNOWN_SYSCALL
)
9810 /* Here we have to issue an error instead of a warning,
9811 because GDB cannot do anything useful if there's no
9812 syscall number to be caught. */
9813 error (_("Unknown syscall name '%s'."), cur_name
);
9816 /* Ok, it's valid. */
9817 VEC_safe_push (int, result
, s
.number
);
9820 discard_cleanups (cleanup
);
9824 /* Implement the "catch syscall" command. */
9827 catch_syscall_command_1 (char *arg
, int from_tty
,
9828 struct cmd_list_element
*command
)
9833 struct gdbarch
*gdbarch
= get_current_arch ();
9835 /* Checking if the feature if supported. */
9836 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9837 error (_("The feature 'catch syscall' is not supported on \
9838 this architecture yet."));
9840 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9842 arg
= skip_spaces (arg
);
9844 /* We need to do this first "dummy" translation in order
9845 to get the syscall XML file loaded or, most important,
9846 to display a warning to the user if there's no XML file
9847 for his/her architecture. */
9848 get_syscall_by_number (0, &s
);
9850 /* The allowed syntax is:
9852 catch syscall <name | number> [<name | number> ... <name | number>]
9854 Let's check if there's a syscall name. */
9857 filter
= catch_syscall_split_args (arg
);
9861 create_syscall_event_catchpoint (tempflag
, filter
,
9862 &catch_syscall_breakpoint_ops
);
9866 catch_command (char *arg
, int from_tty
)
9868 error (_("Catch requires an event name."));
9873 tcatch_command (char *arg
, int from_tty
)
9875 error (_("Catch requires an event name."));
9878 /* Delete breakpoints by address or line. */
9881 clear_command (char *arg
, int from_tty
)
9883 struct breakpoint
*b
;
9884 VEC(breakpoint_p
) *found
= 0;
9887 struct symtabs_and_lines sals
;
9888 struct symtab_and_line sal
;
9893 sals
= decode_line_spec (arg
, 1);
9898 sals
.sals
= (struct symtab_and_line
*)
9899 xmalloc (sizeof (struct symtab_and_line
));
9900 make_cleanup (xfree
, sals
.sals
);
9901 init_sal (&sal
); /* Initialize to zeroes. */
9902 sal
.line
= default_breakpoint_line
;
9903 sal
.symtab
= default_breakpoint_symtab
;
9904 sal
.pc
= default_breakpoint_address
;
9905 sal
.pspace
= default_breakpoint_pspace
;
9906 if (sal
.symtab
== 0)
9907 error (_("No source file specified."));
9915 /* We don't call resolve_sal_pc here. That's not as bad as it
9916 seems, because all existing breakpoints typically have both
9917 file/line and pc set. So, if clear is given file/line, we can
9918 match this to existing breakpoint without obtaining pc at all.
9920 We only support clearing given the address explicitly
9921 present in breakpoint table. Say, we've set breakpoint
9922 at file:line. There were several PC values for that file:line,
9923 due to optimization, all in one block.
9925 We've picked one PC value. If "clear" is issued with another
9926 PC corresponding to the same file:line, the breakpoint won't
9927 be cleared. We probably can still clear the breakpoint, but
9928 since the other PC value is never presented to user, user
9929 can only find it by guessing, and it does not seem important
9932 /* For each line spec given, delete bps which correspond to it. Do
9933 it in two passes, solely to preserve the current behavior that
9934 from_tty is forced true if we delete more than one
9938 for (i
= 0; i
< sals
.nelts
; i
++)
9940 /* If exact pc given, clear bpts at that pc.
9941 If line given (pc == 0), clear all bpts on specified line.
9942 If defaulting, clear all bpts on default line
9945 defaulting sal.pc != 0 tests to do
9950 1 0 <can't happen> */
9954 /* Find all matching breakpoints and add them to 'found'. */
9958 /* Are we going to delete b? */
9959 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9961 struct bp_location
*loc
= b
->loc
;
9962 for (; loc
; loc
= loc
->next
)
9964 int pc_match
= sal
.pc
9965 && (loc
->pspace
== sal
.pspace
)
9966 && (loc
->address
== sal
.pc
)
9967 && (!section_is_overlay (loc
->section
)
9968 || loc
->section
== sal
.section
);
9969 int line_match
= ((default_match
|| (0 == sal
.pc
))
9970 && b
->source_file
!= NULL
9971 && sal
.symtab
!= NULL
9972 && sal
.pspace
== loc
->pspace
9973 && filename_cmp (b
->source_file
,
9974 sal
.symtab
->filename
) == 0
9975 && b
->line_number
== sal
.line
);
9976 if (pc_match
|| line_match
)
9985 VEC_safe_push(breakpoint_p
, found
, b
);
9988 /* Now go thru the 'found' chain and delete them. */
9989 if (VEC_empty(breakpoint_p
, found
))
9992 error (_("No breakpoint at %s."), arg
);
9994 error (_("No breakpoint at this line."));
9997 if (VEC_length(breakpoint_p
, found
) > 1)
9998 from_tty
= 1; /* Always report if deleted more than one. */
10001 if (VEC_length(breakpoint_p
, found
) == 1)
10002 printf_unfiltered (_("Deleted breakpoint "));
10004 printf_unfiltered (_("Deleted breakpoints "));
10006 breakpoints_changed ();
10008 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10011 printf_unfiltered ("%d ", b
->number
);
10012 delete_breakpoint (b
);
10015 putchar_unfiltered ('\n');
10018 /* Delete breakpoint in BS if they are `delete' breakpoints and
10019 all breakpoints that are marked for deletion, whether hit or not.
10020 This is called after any breakpoint is hit, or after errors. */
10023 breakpoint_auto_delete (bpstat bs
)
10025 struct breakpoint
*b
, *b_tmp
;
10027 for (; bs
; bs
= bs
->next
)
10028 if (bs
->breakpoint_at
10029 && bs
->breakpoint_at
->disposition
== disp_del
10031 delete_breakpoint (bs
->breakpoint_at
);
10033 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10035 if (b
->disposition
== disp_del_at_next_stop
)
10036 delete_breakpoint (b
);
10040 /* A comparison function for bp_location AP and BP being interfaced to
10041 qsort. Sort elements primarily by their ADDRESS (no matter what
10042 does breakpoint_address_is_meaningful say for its OWNER),
10043 secondarily by ordering first bp_permanent OWNERed elements and
10044 terciarily just ensuring the array is sorted stable way despite
10045 qsort being an unstable algorithm. */
10048 bp_location_compare (const void *ap
, const void *bp
)
10050 struct bp_location
*a
= *(void **) ap
;
10051 struct bp_location
*b
= *(void **) bp
;
10052 /* A and B come from existing breakpoints having non-NULL OWNER. */
10053 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10054 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10056 if (a
->address
!= b
->address
)
10057 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10059 /* Sort permanent breakpoints first. */
10060 if (a_perm
!= b_perm
)
10061 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10063 /* Make the user-visible order stable across GDB runs. Locations of
10064 the same breakpoint can be sorted in arbitrary order. */
10066 if (a
->owner
->number
!= b
->owner
->number
)
10067 return (a
->owner
->number
> b
->owner
->number
)
10068 - (a
->owner
->number
< b
->owner
->number
);
10070 return (a
> b
) - (a
< b
);
10073 /* Set bp_location_placed_address_before_address_max and
10074 bp_location_shadow_len_after_address_max according to the current
10075 content of the bp_location array. */
10078 bp_location_target_extensions_update (void)
10080 struct bp_location
*bl
, **blp_tmp
;
10082 bp_location_placed_address_before_address_max
= 0;
10083 bp_location_shadow_len_after_address_max
= 0;
10085 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10087 CORE_ADDR start
, end
, addr
;
10089 if (!bp_location_has_shadow (bl
))
10092 start
= bl
->target_info
.placed_address
;
10093 end
= start
+ bl
->target_info
.shadow_len
;
10095 gdb_assert (bl
->address
>= start
);
10096 addr
= bl
->address
- start
;
10097 if (addr
> bp_location_placed_address_before_address_max
)
10098 bp_location_placed_address_before_address_max
= addr
;
10100 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10102 gdb_assert (bl
->address
< end
);
10103 addr
= end
- bl
->address
;
10104 if (addr
> bp_location_shadow_len_after_address_max
)
10105 bp_location_shadow_len_after_address_max
= addr
;
10109 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10110 into the inferior, only remove already-inserted locations that no
10111 longer should be inserted. Functions that delete a breakpoint or
10112 breakpoints should pass false, so that deleting a breakpoint
10113 doesn't have the side effect of inserting the locations of other
10114 breakpoints that are marked not-inserted, but should_be_inserted
10115 returns true on them.
10117 This behaviour is useful is situations close to tear-down -- e.g.,
10118 after an exec, while the target still has execution, but breakpoint
10119 shadows of the previous executable image should *NOT* be restored
10120 to the new image; or before detaching, where the target still has
10121 execution and wants to delete breakpoints from GDB's lists, and all
10122 breakpoints had already been removed from the inferior. */
10125 update_global_location_list (int should_insert
)
10127 struct breakpoint
*b
;
10128 struct bp_location
**locp
, *loc
;
10129 struct cleanup
*cleanups
;
10131 /* Used in the duplicates detection below. When iterating over all
10132 bp_locations, points to the first bp_location of a given address.
10133 Breakpoints and watchpoints of different types are never
10134 duplicates of each other. Keep one pointer for each type of
10135 breakpoint/watchpoint, so we only need to loop over all locations
10137 struct bp_location
*bp_loc_first
; /* breakpoint */
10138 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10139 struct bp_location
*awp_loc_first
; /* access watchpoint */
10140 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10142 /* Saved former bp_location array which we compare against the newly
10143 built bp_location from the current state of ALL_BREAKPOINTS. */
10144 struct bp_location
**old_location
, **old_locp
;
10145 unsigned old_location_count
;
10147 old_location
= bp_location
;
10148 old_location_count
= bp_location_count
;
10149 bp_location
= NULL
;
10150 bp_location_count
= 0;
10151 cleanups
= make_cleanup (xfree
, old_location
);
10153 ALL_BREAKPOINTS (b
)
10154 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10155 bp_location_count
++;
10157 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10158 locp
= bp_location
;
10159 ALL_BREAKPOINTS (b
)
10160 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10162 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10163 bp_location_compare
);
10165 bp_location_target_extensions_update ();
10167 /* Identify bp_location instances that are no longer present in the
10168 new list, and therefore should be freed. Note that it's not
10169 necessary that those locations should be removed from inferior --
10170 if there's another location at the same address (previously
10171 marked as duplicate), we don't need to remove/insert the
10174 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10175 and former bp_location array state respectively. */
10177 locp
= bp_location
;
10178 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10181 struct bp_location
*old_loc
= *old_locp
;
10182 struct bp_location
**loc2p
;
10184 /* Tells if 'old_loc' is found among the new locations. If
10185 not, we have to free it. */
10186 int found_object
= 0;
10187 /* Tells if the location should remain inserted in the target. */
10188 int keep_in_target
= 0;
10191 /* Skip LOCP entries which will definitely never be needed.
10192 Stop either at or being the one matching OLD_LOC. */
10193 while (locp
< bp_location
+ bp_location_count
10194 && (*locp
)->address
< old_loc
->address
)
10198 (loc2p
< bp_location
+ bp_location_count
10199 && (*loc2p
)->address
== old_loc
->address
);
10202 if (*loc2p
== old_loc
)
10209 /* If this location is no longer present, and inserted, look if
10210 there's maybe a new location at the same address. If so,
10211 mark that one inserted, and don't remove this one. This is
10212 needed so that we don't have a time window where a breakpoint
10213 at certain location is not inserted. */
10215 if (old_loc
->inserted
)
10217 /* If the location is inserted now, we might have to remove
10220 if (found_object
&& should_be_inserted (old_loc
))
10222 /* The location is still present in the location list,
10223 and still should be inserted. Don't do anything. */
10224 keep_in_target
= 1;
10228 /* The location is either no longer present, or got
10229 disabled. See if there's another location at the
10230 same address, in which case we don't need to remove
10231 this one from the target. */
10233 /* OLD_LOC comes from existing struct breakpoint. */
10234 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10237 (loc2p
< bp_location
+ bp_location_count
10238 && (*loc2p
)->address
== old_loc
->address
);
10241 struct bp_location
*loc2
= *loc2p
;
10243 if (breakpoint_locations_match (loc2
, old_loc
))
10245 /* For the sake of should_be_inserted.
10246 Duplicates check below will fix up this
10248 loc2
->duplicate
= 0;
10250 /* Read watchpoint locations are switched to
10251 access watchpoints, if the former are not
10252 supported, but the latter are. */
10253 if (is_hardware_watchpoint (old_loc
->owner
))
10255 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10256 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10259 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
10261 loc2
->inserted
= 1;
10262 loc2
->target_info
= old_loc
->target_info
;
10263 keep_in_target
= 1;
10271 if (!keep_in_target
)
10273 if (remove_breakpoint (old_loc
, mark_uninserted
))
10275 /* This is just about all we can do. We could keep
10276 this location on the global list, and try to
10277 remove it next time, but there's no particular
10278 reason why we will succeed next time.
10280 Note that at this point, old_loc->owner is still
10281 valid, as delete_breakpoint frees the breakpoint
10282 only after calling us. */
10283 printf_filtered (_("warning: Error removing "
10284 "breakpoint %d\n"),
10285 old_loc
->owner
->number
);
10293 if (removed
&& non_stop
10294 && breakpoint_address_is_meaningful (old_loc
->owner
)
10295 && !is_hardware_watchpoint (old_loc
->owner
))
10297 /* This location was removed from the target. In
10298 non-stop mode, a race condition is possible where
10299 we've removed a breakpoint, but stop events for that
10300 breakpoint are already queued and will arrive later.
10301 We apply an heuristic to be able to distinguish such
10302 SIGTRAPs from other random SIGTRAPs: we keep this
10303 breakpoint location for a bit, and will retire it
10304 after we see some number of events. The theory here
10305 is that reporting of events should, "on the average",
10306 be fair, so after a while we'll see events from all
10307 threads that have anything of interest, and no longer
10308 need to keep this breakpoint location around. We
10309 don't hold locations forever so to reduce chances of
10310 mistaking a non-breakpoint SIGTRAP for a breakpoint
10313 The heuristic failing can be disastrous on
10314 decr_pc_after_break targets.
10316 On decr_pc_after_break targets, like e.g., x86-linux,
10317 if we fail to recognize a late breakpoint SIGTRAP,
10318 because events_till_retirement has reached 0 too
10319 soon, we'll fail to do the PC adjustment, and report
10320 a random SIGTRAP to the user. When the user resumes
10321 the inferior, it will most likely immediately crash
10322 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10323 corrupted, because of being resumed e.g., in the
10324 middle of a multi-byte instruction, or skipped a
10325 one-byte instruction. This was actually seen happen
10326 on native x86-linux, and should be less rare on
10327 targets that do not support new thread events, like
10328 remote, due to the heuristic depending on
10331 Mistaking a random SIGTRAP for a breakpoint trap
10332 causes similar symptoms (PC adjustment applied when
10333 it shouldn't), but then again, playing with SIGTRAPs
10334 behind the debugger's back is asking for trouble.
10336 Since hardware watchpoint traps are always
10337 distinguishable from other traps, so we don't need to
10338 apply keep hardware watchpoint moribund locations
10339 around. We simply always ignore hardware watchpoint
10340 traps we can no longer explain. */
10342 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10343 old_loc
->owner
= NULL
;
10345 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10349 old_loc
->owner
= NULL
;
10350 decref_bp_location (&old_loc
);
10355 /* Rescan breakpoints at the same address and section, marking the
10356 first one as "first" and any others as "duplicates". This is so
10357 that the bpt instruction is only inserted once. If we have a
10358 permanent breakpoint at the same place as BPT, make that one the
10359 official one, and the rest as duplicates. Permanent breakpoints
10360 are sorted first for the same address.
10362 Do the same for hardware watchpoints, but also considering the
10363 watchpoint's type (regular/access/read) and length. */
10365 bp_loc_first
= NULL
;
10366 wp_loc_first
= NULL
;
10367 awp_loc_first
= NULL
;
10368 rwp_loc_first
= NULL
;
10369 ALL_BP_LOCATIONS (loc
, locp
)
10371 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10373 struct breakpoint
*b
= loc
->owner
;
10374 struct bp_location
**loc_first_p
;
10376 if (b
->enable_state
== bp_disabled
10377 || b
->enable_state
== bp_call_disabled
10378 || b
->enable_state
== bp_startup_disabled
10380 || loc
->shlib_disabled
10381 || !breakpoint_address_is_meaningful (b
)
10382 || is_tracepoint (b
))
10385 /* Permanent breakpoint should always be inserted. */
10386 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10387 internal_error (__FILE__
, __LINE__
,
10388 _("allegedly permanent breakpoint is not "
10389 "actually inserted"));
10391 if (b
->type
== bp_hardware_watchpoint
)
10392 loc_first_p
= &wp_loc_first
;
10393 else if (b
->type
== bp_read_watchpoint
)
10394 loc_first_p
= &rwp_loc_first
;
10395 else if (b
->type
== bp_access_watchpoint
)
10396 loc_first_p
= &awp_loc_first
;
10398 loc_first_p
= &bp_loc_first
;
10400 if (*loc_first_p
== NULL
10401 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10402 || !breakpoint_locations_match (loc
, *loc_first_p
))
10404 *loc_first_p
= loc
;
10405 loc
->duplicate
= 0;
10409 loc
->duplicate
= 1;
10411 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10412 && b
->enable_state
!= bp_permanent
)
10413 internal_error (__FILE__
, __LINE__
,
10414 _("another breakpoint was inserted on top of "
10415 "a permanent breakpoint"));
10418 if (breakpoints_always_inserted_mode () && should_insert
10419 && (have_live_inferiors ()
10420 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10421 insert_breakpoint_locations ();
10423 do_cleanups (cleanups
);
10427 breakpoint_retire_moribund (void)
10429 struct bp_location
*loc
;
10432 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10433 if (--(loc
->events_till_retirement
) == 0)
10435 decref_bp_location (&loc
);
10436 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10442 update_global_location_list_nothrow (int inserting
)
10444 struct gdb_exception e
;
10446 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10447 update_global_location_list (inserting
);
10450 /* Clear BKP from a BPS. */
10453 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10457 for (bs
= bps
; bs
; bs
= bs
->next
)
10458 if (bs
->breakpoint_at
== bpt
)
10460 bs
->breakpoint_at
= NULL
;
10461 bs
->old_val
= NULL
;
10462 /* bs->commands will be freed later. */
10466 /* Callback for iterate_over_threads. */
10468 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10470 struct breakpoint
*bpt
= data
;
10472 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10476 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10480 say_where (struct breakpoint
*b
)
10482 struct value_print_options opts
;
10484 get_user_print_options (&opts
);
10486 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10488 if (b
->loc
== NULL
)
10490 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10494 if (opts
.addressprint
|| b
->source_file
== NULL
)
10496 printf_filtered (" at ");
10497 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10500 if (b
->source_file
)
10501 printf_filtered (": file %s, line %d.",
10502 b
->source_file
, b
->line_number
);
10506 struct bp_location
*loc
= b
->loc
;
10508 for (; loc
; loc
= loc
->next
)
10510 printf_filtered (" (%d locations)", n
);
10515 /* Default bp_location_ops methods. */
10518 bp_location_dtor (struct bp_location
*self
)
10520 xfree (self
->cond
);
10521 xfree (self
->function_name
);
10524 static const struct bp_location_ops bp_location_ops
=
10529 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10533 base_breakpoint_dtor (struct breakpoint
*self
)
10535 decref_counted_command_line (&self
->commands
);
10536 xfree (self
->cond_string
);
10537 xfree (self
->cond_exp
);
10538 xfree (self
->addr_string
);
10539 xfree (self
->addr_string_range_end
);
10541 xfree (self
->exp_string
);
10542 xfree (self
->exp_string_reparse
);
10543 value_free (self
->val
);
10544 xfree (self
->source_file
);
10547 static struct bp_location
*
10548 base_breakpoint_allocate_location (struct breakpoint
*self
)
10550 struct bp_location
*loc
;
10552 loc
= XNEW (struct bp_location
);
10553 init_bp_location (loc
, &bp_location_ops
, self
);
10558 base_breakpoint_re_set (struct breakpoint
*b
)
10560 /* Nothing to re-set. */
10563 #define internal_error_pure_virtual_called() \
10564 gdb_assert_not_reached ("pure virtual function called")
10567 base_breakpoint_insert_location (struct bp_location
*bl
)
10569 internal_error_pure_virtual_called ();
10573 base_breakpoint_remove_location (struct bp_location
*bl
)
10575 internal_error_pure_virtual_called ();
10579 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10580 struct address_space
*aspace
,
10583 internal_error_pure_virtual_called ();
10587 base_breakpoint_check_status (bpstat bs
)
10592 /* A "works_in_software_mode" breakpoint_ops method that just internal
10596 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10598 internal_error_pure_virtual_called ();
10601 /* A "resources_needed" breakpoint_ops method that just internal
10605 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10607 internal_error_pure_virtual_called ();
10610 static enum print_stop_action
10611 base_breakpoint_print_it (bpstat bs
)
10613 internal_error_pure_virtual_called ();
10617 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10618 struct ui_out
*uiout
)
10624 base_breakpoint_print_mention (struct breakpoint
*b
)
10626 internal_error_pure_virtual_called ();
10630 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10632 internal_error_pure_virtual_called ();
10635 static struct breakpoint_ops base_breakpoint_ops
=
10637 base_breakpoint_dtor
,
10638 base_breakpoint_allocate_location
,
10639 base_breakpoint_re_set
,
10640 base_breakpoint_insert_location
,
10641 base_breakpoint_remove_location
,
10642 base_breakpoint_breakpoint_hit
,
10643 base_breakpoint_check_status
,
10644 base_breakpoint_resources_needed
,
10645 base_breakpoint_works_in_software_mode
,
10646 base_breakpoint_print_it
,
10648 base_breakpoint_print_one_detail
,
10649 base_breakpoint_print_mention
,
10650 base_breakpoint_print_recreate
10653 /* Default breakpoint_ops methods. */
10656 bkpt_re_set (struct breakpoint
*b
)
10658 /* Do not attempt to re-set breakpoints disabled during startup. */
10659 if (b
->enable_state
== bp_startup_disabled
)
10662 /* FIXME: is this still reachable? */
10663 if (b
->addr_string
== NULL
)
10665 /* Anything without a string can't be re-set. */
10666 delete_breakpoint (b
);
10670 breakpoint_re_set_default (b
);
10674 bkpt_insert_location (struct bp_location
*bl
)
10676 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10677 return target_insert_hw_breakpoint (bl
->gdbarch
,
10680 return target_insert_breakpoint (bl
->gdbarch
,
10685 bkpt_remove_location (struct bp_location
*bl
)
10687 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10688 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10690 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10694 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10695 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10697 struct breakpoint
*b
= bl
->owner
;
10699 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10703 if (overlay_debugging
/* unmapped overlay section */
10704 && section_is_overlay (bl
->section
)
10705 && !section_is_mapped (bl
->section
))
10712 bkpt_resources_needed (const struct bp_location
*bl
)
10714 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10719 static enum print_stop_action
10720 bkpt_print_it (bpstat bs
)
10722 struct breakpoint
*b
;
10723 const struct bp_location
*bl
;
10726 gdb_assert (bs
->bp_location_at
!= NULL
);
10728 bl
= bs
->bp_location_at
;
10729 b
= bs
->breakpoint_at
;
10731 bp_temp
= b
->disposition
== disp_del
;
10732 if (bl
->address
!= bl
->requested_address
)
10733 breakpoint_adjustment_warning (bl
->requested_address
,
10736 annotate_breakpoint (b
->number
);
10738 ui_out_text (uiout
, "\nTemporary breakpoint ");
10740 ui_out_text (uiout
, "\nBreakpoint ");
10741 if (ui_out_is_mi_like_p (uiout
))
10743 ui_out_field_string (uiout
, "reason",
10744 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10745 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10747 ui_out_field_int (uiout
, "bkptno", b
->number
);
10748 ui_out_text (uiout
, ", ");
10750 return PRINT_SRC_AND_LOC
;
10754 bkpt_print_mention (struct breakpoint
*b
)
10756 if (ui_out_is_mi_like_p (uiout
))
10761 case bp_breakpoint
:
10762 case bp_gnu_ifunc_resolver
:
10763 if (b
->disposition
== disp_del
)
10764 printf_filtered (_("Temporary breakpoint"));
10766 printf_filtered (_("Breakpoint"));
10767 printf_filtered (_(" %d"), b
->number
);
10768 if (b
->type
== bp_gnu_ifunc_resolver
)
10769 printf_filtered (_(" at gnu-indirect-function resolver"));
10771 case bp_hardware_breakpoint
:
10772 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
10780 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
10782 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
10783 fprintf_unfiltered (fp
, "tbreak");
10784 else if (tp
->type
== bp_breakpoint
)
10785 fprintf_unfiltered (fp
, "break");
10786 else if (tp
->type
== bp_hardware_breakpoint
10787 && tp
->disposition
== disp_del
)
10788 fprintf_unfiltered (fp
, "thbreak");
10789 else if (tp
->type
== bp_hardware_breakpoint
)
10790 fprintf_unfiltered (fp
, "hbreak");
10792 internal_error (__FILE__
, __LINE__
,
10793 _("unhandled breakpoint type %d"), (int) tp
->type
);
10795 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
10798 /* Virtual table for internal breakpoints. */
10801 internal_bkpt_re_set (struct breakpoint
*b
)
10805 /* Delete overlay event and longjmp master breakpoints; they
10806 will be reset later by breakpoint_re_set. */
10807 case bp_overlay_event
:
10808 case bp_longjmp_master
:
10809 case bp_std_terminate_master
:
10810 case bp_exception_master
:
10811 delete_breakpoint (b
);
10814 /* This breakpoint is special, it's set up when the inferior
10815 starts and we really don't want to touch it. */
10816 case bp_shlib_event
:
10818 /* Like bp_shlib_event, this breakpoint type is special. Once
10819 it is set up, we do not want to touch it. */
10820 case bp_thread_event
:
10826 internal_bkpt_check_status (bpstat bs
)
10828 /* We do not stop for these. */
10832 static enum print_stop_action
10833 internal_bkpt_print_it (bpstat bs
)
10835 struct breakpoint
*b
;
10837 b
= bs
->breakpoint_at
;
10841 case bp_shlib_event
:
10842 /* Did we stop because the user set the stop_on_solib_events
10843 variable? (If so, we report this as a generic, "Stopped due
10844 to shlib event" message.) */
10845 printf_filtered (_("Stopped due to shared library event\n"));
10848 case bp_thread_event
:
10849 /* Not sure how we will get here.
10850 GDB should not stop for these breakpoints. */
10851 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
10854 case bp_overlay_event
:
10855 /* By analogy with the thread event, GDB should not stop for these. */
10856 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
10859 case bp_longjmp_master
:
10860 /* These should never be enabled. */
10861 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
10864 case bp_std_terminate_master
:
10865 /* These should never be enabled. */
10866 printf_filtered (_("std::terminate Master Breakpoint: "
10867 "gdb should not stop!\n"));
10870 case bp_exception_master
:
10871 /* These should never be enabled. */
10872 printf_filtered (_("Exception Master Breakpoint: "
10873 "gdb should not stop!\n"));
10877 return PRINT_NOTHING
;
10881 internal_bkpt_print_mention (struct breakpoint
*b
)
10883 /* Nothing to mention. These breakpoints are internal. */
10886 /* Virtual table for momentary breakpoints */
10889 momentary_bkpt_re_set (struct breakpoint
*b
)
10891 /* Keep temporary breakpoints, which can be encountered when we step
10892 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
10893 Otherwise these should have been blown away via the cleanup chain
10894 or by breakpoint_init_inferior when we rerun the executable. */
10898 momentary_bkpt_check_status (bpstat bs
)
10900 /* Nothing. The point of these breakpoints is causing a stop. */
10903 static enum print_stop_action
10904 momentary_bkpt_print_it (bpstat bs
)
10906 if (ui_out_is_mi_like_p (uiout
))
10908 struct breakpoint
*b
= bs
->breakpoint_at
;
10913 ui_out_field_string
10915 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
10919 ui_out_field_string
10921 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
10926 return PRINT_UNKNOWN
;
10930 momentary_bkpt_print_mention (struct breakpoint
*b
)
10932 /* Nothing to mention. These breakpoints are internal. */
10935 /* The breakpoint_ops structure to be used in tracepoints. */
10938 tracepoint_re_set (struct breakpoint
*b
)
10940 breakpoint_re_set_default (b
);
10944 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
10945 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10947 /* By definition, the inferior does not report stops at
10953 tracepoint_print_one_detail (const struct breakpoint
*self
,
10954 struct ui_out
*uiout
)
10956 if (self
->static_trace_marker_id
)
10958 gdb_assert (self
->type
== bp_static_tracepoint
);
10960 ui_out_text (uiout
, "\tmarker id is ");
10961 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
10962 self
->static_trace_marker_id
);
10963 ui_out_text (uiout
, "\n");
10968 tracepoint_print_mention (struct breakpoint
*b
)
10970 if (ui_out_is_mi_like_p (uiout
))
10975 case bp_tracepoint
:
10976 printf_filtered (_("Tracepoint"));
10977 printf_filtered (_(" %d"), b
->number
);
10979 case bp_fast_tracepoint
:
10980 printf_filtered (_("Fast tracepoint"));
10981 printf_filtered (_(" %d"), b
->number
);
10983 case bp_static_tracepoint
:
10984 printf_filtered (_("Static tracepoint"));
10985 printf_filtered (_(" %d"), b
->number
);
10988 internal_error (__FILE__
, __LINE__
,
10989 _("unhandled tracepoint type %d"), (int) b
->type
);
10996 tracepoint_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
10998 if (tp
->type
== bp_fast_tracepoint
)
10999 fprintf_unfiltered (fp
, "ftrace");
11000 if (tp
->type
== bp_static_tracepoint
)
11001 fprintf_unfiltered (fp
, "strace");
11002 else if (tp
->type
== bp_tracepoint
)
11003 fprintf_unfiltered (fp
, "trace");
11005 internal_error (__FILE__
, __LINE__
,
11006 _("unhandled tracepoint type %d"), (int) tp
->type
);
11008 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11011 struct breakpoint_ops tracepoint_breakpoint_ops
;
11013 /* Delete a breakpoint and clean up all traces of it in the data
11017 delete_breakpoint (struct breakpoint
*bpt
)
11019 struct breakpoint
*b
;
11021 gdb_assert (bpt
!= NULL
);
11023 /* Has this bp already been deleted? This can happen because
11024 multiple lists can hold pointers to bp's. bpstat lists are
11027 One example of this happening is a watchpoint's scope bp. When
11028 the scope bp triggers, we notice that the watchpoint is out of
11029 scope, and delete it. We also delete its scope bp. But the
11030 scope bp is marked "auto-deleting", and is already on a bpstat.
11031 That bpstat is then checked for auto-deleting bp's, which are
11034 A real solution to this problem might involve reference counts in
11035 bp's, and/or giving them pointers back to their referencing
11036 bpstat's, and teaching delete_breakpoint to only free a bp's
11037 storage when no more references were extent. A cheaper bandaid
11039 if (bpt
->type
== bp_none
)
11042 /* At least avoid this stale reference until the reference counting
11043 of breakpoints gets resolved. */
11044 if (bpt
->related_breakpoint
!= bpt
)
11046 struct breakpoint
*related
;
11048 if (bpt
->type
== bp_watchpoint_scope
)
11049 watchpoint_del_at_next_stop (bpt
->related_breakpoint
);
11050 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11051 watchpoint_del_at_next_stop (bpt
);
11053 /* Unlink bpt from the bpt->related_breakpoint ring. */
11054 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11055 related
= related
->related_breakpoint
);
11056 related
->related_breakpoint
= bpt
->related_breakpoint
;
11057 bpt
->related_breakpoint
= bpt
;
11060 /* watch_command_1 creates a watchpoint but only sets its number if
11061 update_watchpoint succeeds in creating its bp_locations. If there's
11062 a problem in that process, we'll be asked to delete the half-created
11063 watchpoint. In that case, don't announce the deletion. */
11065 observer_notify_breakpoint_deleted (bpt
);
11067 if (breakpoint_chain
== bpt
)
11068 breakpoint_chain
= bpt
->next
;
11070 ALL_BREAKPOINTS (b
)
11071 if (b
->next
== bpt
)
11073 b
->next
= bpt
->next
;
11077 /* Be sure no bpstat's are pointing at the breakpoint after it's
11079 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11080 in all threads for now. Note that we cannot just remove bpstats
11081 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11082 commands are associated with the bpstat; if we remove it here,
11083 then the later call to bpstat_do_actions (&stop_bpstat); in
11084 event-top.c won't do anything, and temporary breakpoints with
11085 commands won't work. */
11087 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11089 /* Now that breakpoint is removed from breakpoint list, update the
11090 global location list. This will remove locations that used to
11091 belong to this breakpoint. Do this before freeing the breakpoint
11092 itself, since remove_breakpoint looks at location's owner. It
11093 might be better design to have location completely
11094 self-contained, but it's not the case now. */
11095 update_global_location_list (0);
11097 bpt
->ops
->dtor (bpt
);
11098 /* On the chance that someone will soon try again to delete this
11099 same bp, we mark it as deleted before freeing its storage. */
11100 bpt
->type
= bp_none
;
11105 do_delete_breakpoint_cleanup (void *b
)
11107 delete_breakpoint (b
);
11111 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11113 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11116 /* Iterator function to call a user-provided callback function once
11117 for each of B and its related breakpoints. */
11120 iterate_over_related_breakpoints (struct breakpoint
*b
,
11121 void (*function
) (struct breakpoint
*,
11125 struct breakpoint
*related
;
11130 struct breakpoint
*next
;
11132 /* FUNCTION may delete RELATED. */
11133 next
= related
->related_breakpoint
;
11135 if (next
== related
)
11137 /* RELATED is the last ring entry. */
11138 function (related
, data
);
11140 /* FUNCTION may have deleted it, so we'd never reach back to
11141 B. There's nothing left to do anyway, so just break
11146 function (related
, data
);
11150 while (related
!= b
);
11154 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11156 delete_breakpoint (b
);
11159 /* A callback for map_breakpoint_numbers that calls
11160 delete_breakpoint. */
11163 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11165 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11169 delete_command (char *arg
, int from_tty
)
11171 struct breakpoint
*b
, *b_tmp
;
11177 int breaks_to_delete
= 0;
11179 /* Delete all breakpoints if no argument. Do not delete
11180 internal breakpoints, these have to be deleted with an
11181 explicit breakpoint number argument. */
11182 ALL_BREAKPOINTS (b
)
11183 if (user_breakpoint_p (b
))
11185 breaks_to_delete
= 1;
11189 /* Ask user only if there are some breakpoints to delete. */
11191 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11193 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11194 if (user_breakpoint_p (b
))
11195 delete_breakpoint (b
);
11199 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11203 all_locations_are_pending (struct bp_location
*loc
)
11205 for (; loc
; loc
= loc
->next
)
11206 if (!loc
->shlib_disabled
)
11211 /* Subroutine of update_breakpoint_locations to simplify it.
11212 Return non-zero if multiple fns in list LOC have the same name.
11213 Null names are ignored. */
11216 ambiguous_names_p (struct bp_location
*loc
)
11218 struct bp_location
*l
;
11219 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11220 (int (*) (const void *,
11221 const void *)) streq
,
11222 NULL
, xcalloc
, xfree
);
11224 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11227 const char *name
= l
->function_name
;
11229 /* Allow for some names to be NULL, ignore them. */
11233 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11235 /* NOTE: We can assume slot != NULL here because xcalloc never
11239 htab_delete (htab
);
11245 htab_delete (htab
);
11249 /* When symbols change, it probably means the sources changed as well,
11250 and it might mean the static tracepoint markers are no longer at
11251 the same address or line numbers they used to be at last we
11252 checked. Losing your static tracepoints whenever you rebuild is
11253 undesirable. This function tries to resync/rematch gdb static
11254 tracepoints with the markers on the target, for static tracepoints
11255 that have not been set by marker id. Static tracepoint that have
11256 been set by marker id are reset by marker id in breakpoint_re_set.
11259 1) For a tracepoint set at a specific address, look for a marker at
11260 the old PC. If one is found there, assume to be the same marker.
11261 If the name / string id of the marker found is different from the
11262 previous known name, assume that means the user renamed the marker
11263 in the sources, and output a warning.
11265 2) For a tracepoint set at a given line number, look for a marker
11266 at the new address of the old line number. If one is found there,
11267 assume to be the same marker. If the name / string id of the
11268 marker found is different from the previous known name, assume that
11269 means the user renamed the marker in the sources, and output a
11272 3) If a marker is no longer found at the same address or line, it
11273 may mean the marker no longer exists. But it may also just mean
11274 the code changed a bit. Maybe the user added a few lines of code
11275 that made the marker move up or down (in line number terms). Ask
11276 the target for info about the marker with the string id as we knew
11277 it. If found, update line number and address in the matching
11278 static tracepoint. This will get confused if there's more than one
11279 marker with the same ID (possible in UST, although unadvised
11280 precisely because it confuses tools). */
11282 static struct symtab_and_line
11283 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11285 struct static_tracepoint_marker marker
;
11291 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11293 if (target_static_tracepoint_marker_at (pc
, &marker
))
11295 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
11296 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11298 b
->static_trace_marker_id
, marker
.str_id
);
11300 xfree (b
->static_trace_marker_id
);
11301 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11302 release_static_tracepoint_marker (&marker
);
11307 /* Old marker wasn't found on target at lineno. Try looking it up
11309 if (!sal
.explicit_pc
11311 && sal
.symtab
!= NULL
11312 && b
->static_trace_marker_id
!= NULL
)
11314 VEC(static_tracepoint_marker_p
) *markers
;
11317 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
11319 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11321 struct symtab_and_line sal
;
11322 struct symbol
*sym
;
11323 struct static_tracepoint_marker
*marker
;
11325 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11327 xfree (b
->static_trace_marker_id
);
11328 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11330 warning (_("marker for static tracepoint %d (%s) not "
11331 "found at previous line number"),
11332 b
->number
, b
->static_trace_marker_id
);
11336 sal
.pc
= marker
->address
;
11338 sal
= find_pc_line (marker
->address
, 0);
11339 sym
= find_pc_sect_function (marker
->address
, NULL
);
11340 ui_out_text (uiout
, "Now in ");
11343 ui_out_field_string (uiout
, "func",
11344 SYMBOL_PRINT_NAME (sym
));
11345 ui_out_text (uiout
, " at ");
11347 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11348 ui_out_text (uiout
, ":");
11350 if (ui_out_is_mi_like_p (uiout
))
11352 char *fullname
= symtab_to_fullname (sal
.symtab
);
11355 ui_out_field_string (uiout
, "fullname", fullname
);
11358 ui_out_field_int (uiout
, "line", sal
.line
);
11359 ui_out_text (uiout
, "\n");
11361 b
->line_number
= sal
.line
;
11363 xfree (b
->source_file
);
11365 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11367 b
->source_file
= NULL
;
11369 xfree (b
->addr_string
);
11370 b
->addr_string
= xstrprintf ("%s:%d",
11371 sal
.symtab
->filename
, b
->line_number
);
11373 /* Might be nice to check if function changed, and warn if
11376 release_static_tracepoint_marker (marker
);
11382 /* Returns 1 iff locations A and B are sufficiently same that
11383 we don't need to report breakpoint as changed. */
11386 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11390 if (a
->address
!= b
->address
)
11393 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11396 if (a
->enabled
!= b
->enabled
)
11403 if ((a
== NULL
) != (b
== NULL
))
11409 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11410 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11411 a ranged breakpoint. */
11414 update_breakpoint_locations (struct breakpoint
*b
,
11415 struct symtabs_and_lines sals
,
11416 struct symtabs_and_lines sals_end
)
11419 struct bp_location
*existing_locations
= b
->loc
;
11421 /* Ranged breakpoints have only one start location and one end location. */
11422 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11424 /* If there's no new locations, and all existing locations are
11425 pending, don't do anything. This optimizes the common case where
11426 all locations are in the same shared library, that was unloaded.
11427 We'd like to retain the location, so that when the library is
11428 loaded again, we don't loose the enabled/disabled status of the
11429 individual locations. */
11430 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11435 for (i
= 0; i
< sals
.nelts
; ++i
)
11437 struct bp_location
*new_loc
=
11438 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11440 /* Reparse conditions, they might contain references to the
11442 if (b
->cond_string
!= NULL
)
11445 struct gdb_exception e
;
11447 s
= b
->cond_string
;
11448 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11450 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11455 warning (_("failed to reevaluate condition "
11456 "for breakpoint %d: %s"),
11457 b
->number
, e
.message
);
11458 new_loc
->enabled
= 0;
11462 if (b
->source_file
!= NULL
)
11463 xfree (b
->source_file
);
11464 if (sals
.sals
[i
].symtab
== NULL
)
11465 b
->source_file
= NULL
;
11467 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11469 if (b
->line_number
== 0)
11470 b
->line_number
= sals
.sals
[i
].line
;
11472 if (sals_end
.nelts
)
11474 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11476 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11480 /* Update locations of permanent breakpoints. */
11481 if (b
->enable_state
== bp_permanent
)
11482 make_breakpoint_permanent (b
);
11484 /* If possible, carry over 'disable' status from existing
11487 struct bp_location
*e
= existing_locations
;
11488 /* If there are multiple breakpoints with the same function name,
11489 e.g. for inline functions, comparing function names won't work.
11490 Instead compare pc addresses; this is just a heuristic as things
11491 may have moved, but in practice it gives the correct answer
11492 often enough until a better solution is found. */
11493 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11495 for (; e
; e
= e
->next
)
11497 if (!e
->enabled
&& e
->function_name
)
11499 struct bp_location
*l
= b
->loc
;
11500 if (have_ambiguous_names
)
11502 for (; l
; l
= l
->next
)
11503 if (breakpoint_locations_match (e
, l
))
11511 for (; l
; l
= l
->next
)
11512 if (l
->function_name
11513 && strcmp (e
->function_name
, l
->function_name
) == 0)
11523 if (!locations_are_equal (existing_locations
, b
->loc
))
11524 observer_notify_breakpoint_modified (b
);
11526 update_global_location_list (1);
11529 /* Find the SaL locations corresponding to the given ADDR_STRING.
11530 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11532 static struct symtabs_and_lines
11533 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11537 struct symtabs_and_lines sals
= {0};
11538 struct gdb_exception e
;
11541 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11543 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11547 sals
= decode_static_tracepoint_spec (&s
);
11548 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
11550 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
11554 error (_("marker %s not found"), b
->static_trace_marker_id
);
11557 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11561 int not_found_and_ok
= 0;
11562 /* For pending breakpoints, it's expected that parsing will
11563 fail until the right shared library is loaded. User has
11564 already told to create pending breakpoints and don't need
11565 extra messages. If breakpoint is in bp_shlib_disabled
11566 state, then user already saw the message about that
11567 breakpoint being disabled, and don't want to see more
11569 if (e
.error
== NOT_FOUND_ERROR
11570 && (b
->condition_not_parsed
11571 || (b
->loc
&& b
->loc
->shlib_disabled
)
11572 || b
->enable_state
== bp_disabled
))
11573 not_found_and_ok
= 1;
11575 if (!not_found_and_ok
)
11577 /* We surely don't want to warn about the same breakpoint
11578 10 times. One solution, implemented here, is disable
11579 the breakpoint on error. Another solution would be to
11580 have separate 'warning emitted' flag. Since this
11581 happens only when a binary has changed, I don't know
11582 which approach is better. */
11583 b
->enable_state
= bp_disabled
;
11584 throw_exception (e
);
11588 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11590 gdb_assert (sals
.nelts
== 1);
11592 resolve_sal_pc (&sals
.sals
[0]);
11593 if (b
->condition_not_parsed
&& s
&& s
[0])
11595 char *cond_string
= 0;
11599 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11600 &cond_string
, &thread
, &task
);
11602 b
->cond_string
= cond_string
;
11603 b
->thread
= thread
;
11605 b
->condition_not_parsed
= 0;
11608 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11609 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11619 /* The default re_set method, for typical hardware or software
11620 breakpoints. Reevaluate the breakpoint and recreate its
11624 breakpoint_re_set_default (struct breakpoint
*b
)
11627 struct symtabs_and_lines sals
, sals_end
;
11628 struct symtabs_and_lines expanded
= {0};
11629 struct symtabs_and_lines expanded_end
= {0};
11631 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11634 make_cleanup (xfree
, sals
.sals
);
11635 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
11638 if (b
->addr_string_range_end
)
11640 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11643 make_cleanup (xfree
, sals_end
.sals
);
11644 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
11648 update_breakpoint_locations (b
, expanded
, expanded_end
);
11651 /* Prepare the global context for a re-set of breakpoint B. */
11653 static struct cleanup
*
11654 prepare_re_set_context (struct breakpoint
*b
)
11656 struct cleanup
*cleanups
;
11658 input_radix
= b
->input_radix
;
11659 cleanups
= save_current_space_and_thread ();
11660 switch_to_program_space_and_thread (b
->pspace
);
11661 set_language (b
->language
);
11666 /* Reset a breakpoint given it's struct breakpoint * BINT.
11667 The value we return ends up being the return value from catch_errors.
11668 Unused in this case. */
11671 breakpoint_re_set_one (void *bint
)
11673 /* Get past catch_errs. */
11674 struct breakpoint
*b
= (struct breakpoint
*) bint
;
11675 struct cleanup
*cleanups
;
11677 cleanups
= prepare_re_set_context (b
);
11678 b
->ops
->re_set (b
);
11679 do_cleanups (cleanups
);
11683 /* Re-set all breakpoints after symbols have been re-loaded. */
11685 breakpoint_re_set (void)
11687 struct breakpoint
*b
, *b_tmp
;
11688 enum language save_language
;
11689 int save_input_radix
;
11690 struct cleanup
*old_chain
;
11692 save_language
= current_language
->la_language
;
11693 save_input_radix
= input_radix
;
11694 old_chain
= save_current_program_space ();
11696 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11698 /* Format possible error msg. */
11699 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
11701 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
11702 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
11703 do_cleanups (cleanups
);
11705 set_language (save_language
);
11706 input_radix
= save_input_radix
;
11708 jit_breakpoint_re_set ();
11710 do_cleanups (old_chain
);
11712 create_overlay_event_breakpoint ();
11713 create_longjmp_master_breakpoint ();
11714 create_std_terminate_master_breakpoint ();
11715 create_exception_master_breakpoint ();
11718 /* Reset the thread number of this breakpoint:
11720 - If the breakpoint is for all threads, leave it as-is.
11721 - Else, reset it to the current thread for inferior_ptid. */
11723 breakpoint_re_set_thread (struct breakpoint
*b
)
11725 if (b
->thread
!= -1)
11727 if (in_thread_list (inferior_ptid
))
11728 b
->thread
= pid_to_thread_id (inferior_ptid
);
11730 /* We're being called after following a fork. The new fork is
11731 selected as current, and unless this was a vfork will have a
11732 different program space from the original thread. Reset that
11734 b
->loc
->pspace
= current_program_space
;
11738 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11739 If from_tty is nonzero, it prints a message to that effect,
11740 which ends with a period (no newline). */
11743 set_ignore_count (int bptnum
, int count
, int from_tty
)
11745 struct breakpoint
*b
;
11750 ALL_BREAKPOINTS (b
)
11751 if (b
->number
== bptnum
)
11753 if (is_tracepoint (b
))
11755 if (from_tty
&& count
!= 0)
11756 printf_filtered (_("Ignore count ignored for tracepoint %d."),
11761 b
->ignore_count
= count
;
11765 printf_filtered (_("Will stop next time "
11766 "breakpoint %d is reached."),
11768 else if (count
== 1)
11769 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
11772 printf_filtered (_("Will ignore next %d "
11773 "crossings of breakpoint %d."),
11776 breakpoints_changed ();
11777 observer_notify_breakpoint_modified (b
);
11781 error (_("No breakpoint number %d."), bptnum
);
11784 /* Command to set ignore-count of breakpoint N to COUNT. */
11787 ignore_command (char *args
, int from_tty
)
11793 error_no_arg (_("a breakpoint number"));
11795 num
= get_number (&p
);
11797 error (_("bad breakpoint number: '%s'"), args
);
11799 error (_("Second argument (specified ignore-count) is missing."));
11801 set_ignore_count (num
,
11802 longest_to_int (value_as_long (parse_and_eval (p
))),
11805 printf_filtered ("\n");
11808 /* Call FUNCTION on each of the breakpoints
11809 whose numbers are given in ARGS. */
11812 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
11817 struct breakpoint
*b
, *tmp
;
11819 struct get_number_or_range_state state
;
11822 error_no_arg (_("one or more breakpoint numbers"));
11824 init_number_or_range (&state
, args
);
11826 while (!state
.finished
)
11828 char *p
= state
.string
;
11832 num
= get_number_or_range (&state
);
11835 warning (_("bad breakpoint number at or near '%s'"), p
);
11839 ALL_BREAKPOINTS_SAFE (b
, tmp
)
11840 if (b
->number
== num
)
11843 function (b
, data
);
11847 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
11852 static struct bp_location
*
11853 find_location_by_number (char *number
)
11855 char *dot
= strchr (number
, '.');
11859 struct breakpoint
*b
;
11860 struct bp_location
*loc
;
11865 bp_num
= get_number (&p1
);
11867 error (_("Bad breakpoint number '%s'"), number
);
11869 ALL_BREAKPOINTS (b
)
11870 if (b
->number
== bp_num
)
11875 if (!b
|| b
->number
!= bp_num
)
11876 error (_("Bad breakpoint number '%s'"), number
);
11879 loc_num
= get_number (&p1
);
11881 error (_("Bad breakpoint location number '%s'"), number
);
11885 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
11888 error (_("Bad breakpoint location number '%s'"), dot
+1);
11894 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11895 If from_tty is nonzero, it prints a message to that effect,
11896 which ends with a period (no newline). */
11899 disable_breakpoint (struct breakpoint
*bpt
)
11901 /* Never disable a watchpoint scope breakpoint; we want to
11902 hit them when we leave scope so we can delete both the
11903 watchpoint and its scope breakpoint at that time. */
11904 if (bpt
->type
== bp_watchpoint_scope
)
11907 /* You can't disable permanent breakpoints. */
11908 if (bpt
->enable_state
== bp_permanent
)
11911 bpt
->enable_state
= bp_disabled
;
11913 if (target_supports_enable_disable_tracepoint ()
11914 && current_trace_status ()->running
&& is_tracepoint (bpt
))
11916 struct bp_location
*location
;
11918 for (location
= bpt
->loc
; location
; location
= location
->next
)
11919 target_disable_tracepoint (location
);
11922 update_global_location_list (0);
11924 observer_notify_breakpoint_modified (bpt
);
11927 /* A callback for iterate_over_related_breakpoints. */
11930 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
11932 disable_breakpoint (b
);
11935 /* A callback for map_breakpoint_numbers that calls
11936 disable_breakpoint. */
11939 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
11941 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
11945 disable_command (char *args
, int from_tty
)
11949 struct breakpoint
*bpt
;
11951 ALL_BREAKPOINTS (bpt
)
11952 if (user_breakpoint_p (bpt
))
11953 disable_breakpoint (bpt
);
11955 else if (strchr (args
, '.'))
11957 struct bp_location
*loc
= find_location_by_number (args
);
11961 if (target_supports_enable_disable_tracepoint ()
11962 && current_trace_status ()->running
&& loc
->owner
11963 && is_tracepoint (loc
->owner
))
11964 target_disable_tracepoint (loc
);
11966 update_global_location_list (0);
11969 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
11973 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
11975 int target_resources_ok
;
11977 if (bpt
->type
== bp_hardware_breakpoint
)
11980 i
= hw_breakpoint_used_count ();
11981 target_resources_ok
=
11982 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
11984 if (target_resources_ok
== 0)
11985 error (_("No hardware breakpoint support in the target."));
11986 else if (target_resources_ok
< 0)
11987 error (_("Hardware breakpoints used exceeds limit."));
11990 if (is_watchpoint (bpt
))
11992 /* Initialize it just to avoid a GCC false warning. */
11993 enum enable_state orig_enable_state
= 0;
11994 struct gdb_exception e
;
11996 TRY_CATCH (e
, RETURN_MASK_ALL
)
11998 orig_enable_state
= bpt
->enable_state
;
11999 bpt
->enable_state
= bp_enabled
;
12000 update_watchpoint (bpt
, 1 /* reparse */);
12004 bpt
->enable_state
= orig_enable_state
;
12005 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12011 if (bpt
->enable_state
!= bp_permanent
)
12012 bpt
->enable_state
= bp_enabled
;
12014 if (target_supports_enable_disable_tracepoint ()
12015 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12017 struct bp_location
*location
;
12019 for (location
= bpt
->loc
; location
; location
= location
->next
)
12020 target_enable_tracepoint (location
);
12023 bpt
->disposition
= disposition
;
12024 update_global_location_list (1);
12025 breakpoints_changed ();
12027 observer_notify_breakpoint_modified (bpt
);
12032 enable_breakpoint (struct breakpoint
*bpt
)
12034 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12038 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12040 enable_breakpoint (bpt
);
12043 /* A callback for map_breakpoint_numbers that calls
12044 enable_breakpoint. */
12047 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12049 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12052 /* The enable command enables the specified breakpoints (or all defined
12053 breakpoints) so they once again become (or continue to be) effective
12054 in stopping the inferior. */
12057 enable_command (char *args
, int from_tty
)
12061 struct breakpoint
*bpt
;
12063 ALL_BREAKPOINTS (bpt
)
12064 if (user_breakpoint_p (bpt
))
12065 enable_breakpoint (bpt
);
12067 else if (strchr (args
, '.'))
12069 struct bp_location
*loc
= find_location_by_number (args
);
12073 if (target_supports_enable_disable_tracepoint ()
12074 && current_trace_status ()->running
&& loc
->owner
12075 && is_tracepoint (loc
->owner
))
12076 target_enable_tracepoint (loc
);
12078 update_global_location_list (1);
12081 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12085 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12087 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12089 enable_breakpoint_disp (bpt
, disp
);
12093 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12095 enum bpdisp disp
= disp_disable
;
12097 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12101 enable_once_command (char *args
, int from_tty
)
12103 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12107 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12109 enum bpdisp disp
= disp_del
;
12111 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12115 enable_delete_command (char *args
, int from_tty
)
12117 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12121 set_breakpoint_cmd (char *args
, int from_tty
)
12126 show_breakpoint_cmd (char *args
, int from_tty
)
12130 /* Invalidate last known value of any hardware watchpoint if
12131 the memory which that value represents has been written to by
12135 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12136 const bfd_byte
*data
)
12138 struct breakpoint
*bp
;
12140 ALL_BREAKPOINTS (bp
)
12141 if (bp
->enable_state
== bp_enabled
12142 && bp
->type
== bp_hardware_watchpoint
12143 && bp
->val_valid
&& bp
->val
)
12145 struct bp_location
*loc
;
12147 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12148 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12149 && loc
->address
+ loc
->length
> addr
12150 && addr
+ len
> loc
->address
)
12152 value_free (bp
->val
);
12159 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12161 struct symtabs_and_lines
12162 decode_line_spec_1 (char *string
, int funfirstline
)
12164 struct symtabs_and_lines sals
;
12167 error (_("Empty line specification."));
12168 if (default_breakpoint_valid
)
12169 sals
= decode_line_1 (&string
, funfirstline
,
12170 default_breakpoint_symtab
,
12171 default_breakpoint_line
,
12174 sals
= decode_line_1 (&string
, funfirstline
,
12175 (struct symtab
*) NULL
, 0, NULL
);
12177 error (_("Junk at end of line specification: %s"), string
);
12181 /* Create and insert a raw software breakpoint at PC. Return an
12182 identifier, which should be used to remove the breakpoint later.
12183 In general, places which call this should be using something on the
12184 breakpoint chain instead; this function should be eliminated
12188 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12189 struct address_space
*aspace
, CORE_ADDR pc
)
12191 struct bp_target_info
*bp_tgt
;
12193 bp_tgt
= XZALLOC (struct bp_target_info
);
12195 bp_tgt
->placed_address_space
= aspace
;
12196 bp_tgt
->placed_address
= pc
;
12198 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12200 /* Could not insert the breakpoint. */
12208 /* Remove a breakpoint BP inserted by
12209 deprecated_insert_raw_breakpoint. */
12212 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12214 struct bp_target_info
*bp_tgt
= bp
;
12217 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12223 /* One (or perhaps two) breakpoints used for software single
12226 static void *single_step_breakpoints
[2];
12227 static struct gdbarch
*single_step_gdbarch
[2];
12229 /* Create and insert a breakpoint for software single step. */
12232 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12233 struct address_space
*aspace
,
12238 if (single_step_breakpoints
[0] == NULL
)
12240 bpt_p
= &single_step_breakpoints
[0];
12241 single_step_gdbarch
[0] = gdbarch
;
12245 gdb_assert (single_step_breakpoints
[1] == NULL
);
12246 bpt_p
= &single_step_breakpoints
[1];
12247 single_step_gdbarch
[1] = gdbarch
;
12250 /* NOTE drow/2006-04-11: A future improvement to this function would
12251 be to only create the breakpoints once, and actually put them on
12252 the breakpoint chain. That would let us use set_raw_breakpoint.
12253 We could adjust the addresses each time they were needed. Doing
12254 this requires corresponding changes elsewhere where single step
12255 breakpoints are handled, however. So, for now, we use this. */
12257 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12258 if (*bpt_p
== NULL
)
12259 error (_("Could not insert single-step breakpoint at %s"),
12260 paddress (gdbarch
, next_pc
));
12263 /* Check if the breakpoints used for software single stepping
12264 were inserted or not. */
12267 single_step_breakpoints_inserted (void)
12269 return (single_step_breakpoints
[0] != NULL
12270 || single_step_breakpoints
[1] != NULL
);
12273 /* Remove and delete any breakpoints used for software single step. */
12276 remove_single_step_breakpoints (void)
12278 gdb_assert (single_step_breakpoints
[0] != NULL
);
12280 /* See insert_single_step_breakpoint for more about this deprecated
12282 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12283 single_step_breakpoints
[0]);
12284 single_step_gdbarch
[0] = NULL
;
12285 single_step_breakpoints
[0] = NULL
;
12287 if (single_step_breakpoints
[1] != NULL
)
12289 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12290 single_step_breakpoints
[1]);
12291 single_step_gdbarch
[1] = NULL
;
12292 single_step_breakpoints
[1] = NULL
;
12296 /* Delete software single step breakpoints without removing them from
12297 the inferior. This is intended to be used if the inferior's address
12298 space where they were inserted is already gone, e.g. after exit or
12302 cancel_single_step_breakpoints (void)
12306 for (i
= 0; i
< 2; i
++)
12307 if (single_step_breakpoints
[i
])
12309 xfree (single_step_breakpoints
[i
]);
12310 single_step_breakpoints
[i
] = NULL
;
12311 single_step_gdbarch
[i
] = NULL
;
12315 /* Detach software single-step breakpoints from INFERIOR_PTID without
12319 detach_single_step_breakpoints (void)
12323 for (i
= 0; i
< 2; i
++)
12324 if (single_step_breakpoints
[i
])
12325 target_remove_breakpoint (single_step_gdbarch
[i
],
12326 single_step_breakpoints
[i
]);
12329 /* Check whether a software single-step breakpoint is inserted at
12333 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12338 for (i
= 0; i
< 2; i
++)
12340 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12342 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12343 bp_tgt
->placed_address
,
12351 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12352 non-zero otherwise. */
12354 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12356 if (syscall_catchpoint_p (bp
)
12357 && bp
->enable_state
!= bp_disabled
12358 && bp
->enable_state
!= bp_call_disabled
)
12365 catch_syscall_enabled (void)
12367 struct inferior
*inf
= current_inferior ();
12369 return inf
->total_syscalls_count
!= 0;
12373 catching_syscall_number (int syscall_number
)
12375 struct breakpoint
*bp
;
12377 ALL_BREAKPOINTS (bp
)
12378 if (is_syscall_catchpoint_enabled (bp
))
12380 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12382 if (c
->syscalls_to_be_caught
)
12386 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12388 if (syscall_number
== iter
)
12398 /* Complete syscall names. Used by "catch syscall". */
12400 catch_syscall_completer (struct cmd_list_element
*cmd
,
12401 char *text
, char *word
)
12403 const char **list
= get_syscall_names ();
12405 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12411 /* Tracepoint-specific operations. */
12413 /* Set tracepoint count to NUM. */
12415 set_tracepoint_count (int num
)
12417 tracepoint_count
= num
;
12418 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12422 trace_command (char *arg
, int from_tty
)
12424 if (create_breakpoint (get_current_arch (),
12426 NULL
, 0, 1 /* parse arg */,
12428 bp_tracepoint
/* type_wanted */,
12429 0 /* Ignore count */,
12430 pending_break_support
,
12431 &tracepoint_breakpoint_ops
,
12435 set_tracepoint_count (breakpoint_count
);
12439 ftrace_command (char *arg
, int from_tty
)
12441 if (create_breakpoint (get_current_arch (),
12443 NULL
, 0, 1 /* parse arg */,
12445 bp_fast_tracepoint
/* type_wanted */,
12446 0 /* Ignore count */,
12447 pending_break_support
,
12448 &tracepoint_breakpoint_ops
,
12452 set_tracepoint_count (breakpoint_count
);
12455 /* strace command implementation. Creates a static tracepoint. */
12458 strace_command (char *arg
, int from_tty
)
12460 if (create_breakpoint (get_current_arch (),
12462 NULL
, 0, 1 /* parse arg */,
12464 bp_static_tracepoint
/* type_wanted */,
12465 0 /* Ignore count */,
12466 pending_break_support
,
12467 &tracepoint_breakpoint_ops
,
12471 set_tracepoint_count (breakpoint_count
);
12474 /* Set up a fake reader function that gets command lines from a linked
12475 list that was acquired during tracepoint uploading. */
12477 static struct uploaded_tp
*this_utp
;
12478 static int next_cmd
;
12481 read_uploaded_action (void)
12485 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12492 /* Given information about a tracepoint as recorded on a target (which
12493 can be either a live system or a trace file), attempt to create an
12494 equivalent GDB tracepoint. This is not a reliable process, since
12495 the target does not necessarily have all the information used when
12496 the tracepoint was originally defined. */
12498 struct breakpoint
*
12499 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12501 char *addr_str
, small_buf
[100];
12502 struct breakpoint
*tp
;
12504 if (utp
->at_string
)
12505 addr_str
= utp
->at_string
;
12508 /* In the absence of a source location, fall back to raw
12509 address. Since there is no way to confirm that the address
12510 means the same thing as when the trace was started, warn the
12512 warning (_("Uploaded tracepoint %d has no "
12513 "source location, using raw address"),
12515 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12516 addr_str
= small_buf
;
12519 /* There's not much we can do with a sequence of bytecodes. */
12520 if (utp
->cond
&& !utp
->cond_string
)
12521 warning (_("Uploaded tracepoint %d condition "
12522 "has no source form, ignoring it"),
12525 if (!create_breakpoint (get_current_arch (),
12527 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12529 utp
->type
/* type_wanted */,
12530 0 /* Ignore count */,
12531 pending_break_support
,
12532 &tracepoint_breakpoint_ops
,
12534 utp
->enabled
/* enabled */,
12538 set_tracepoint_count (breakpoint_count
);
12540 /* Get the tracepoint we just created. */
12541 tp
= get_tracepoint (tracepoint_count
);
12542 gdb_assert (tp
!= NULL
);
12546 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
12548 trace_pass_command (small_buf
, 0);
12551 /* If we have uploaded versions of the original commands, set up a
12552 special-purpose "reader" function and call the usual command line
12553 reader, then pass the result to the breakpoint command-setting
12555 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12557 struct command_line
*cmd_list
;
12562 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12564 breakpoint_set_commands (tp
, cmd_list
);
12566 else if (!VEC_empty (char_ptr
, utp
->actions
)
12567 || !VEC_empty (char_ptr
, utp
->step_actions
))
12568 warning (_("Uploaded tracepoint %d actions "
12569 "have no source form, ignoring them"),
12575 /* Print information on tracepoint number TPNUM_EXP, or all if
12579 tracepoints_info (char *args
, int from_tty
)
12583 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12585 if (num_printed
== 0)
12587 if (args
== NULL
|| *args
== '\0')
12588 ui_out_message (uiout
, 0, "No tracepoints.\n");
12590 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12593 default_collect_info ();
12596 /* The 'enable trace' command enables tracepoints.
12597 Not supported by all targets. */
12599 enable_trace_command (char *args
, int from_tty
)
12601 enable_command (args
, from_tty
);
12604 /* The 'disable trace' command disables tracepoints.
12605 Not supported by all targets. */
12607 disable_trace_command (char *args
, int from_tty
)
12609 disable_command (args
, from_tty
);
12612 /* Remove a tracepoint (or all if no argument). */
12614 delete_trace_command (char *arg
, int from_tty
)
12616 struct breakpoint
*b
, *b_tmp
;
12622 int breaks_to_delete
= 0;
12624 /* Delete all breakpoints if no argument.
12625 Do not delete internal or call-dummy breakpoints, these
12626 have to be deleted with an explicit breakpoint number
12628 ALL_TRACEPOINTS (b
)
12629 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12631 breaks_to_delete
= 1;
12635 /* Ask user only if there are some breakpoints to delete. */
12637 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12639 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12640 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12641 delete_breakpoint (b
);
12645 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12648 /* Helper function for trace_pass_command. */
12651 trace_pass_set_count (struct breakpoint
*bp
, int count
, int from_tty
)
12653 bp
->pass_count
= count
;
12654 observer_notify_tracepoint_modified (bp
->number
);
12656 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12657 bp
->number
, count
);
12660 /* Set passcount for tracepoint.
12662 First command argument is passcount, second is tracepoint number.
12663 If tracepoint number omitted, apply to most recently defined.
12664 Also accepts special argument "all". */
12667 trace_pass_command (char *args
, int from_tty
)
12669 struct breakpoint
*t1
;
12670 unsigned int count
;
12672 if (args
== 0 || *args
== 0)
12673 error (_("passcount command requires an "
12674 "argument (count + optional TP num)"));
12676 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
12678 while (*args
&& isspace ((int) *args
))
12681 if (*args
&& strncasecmp (args
, "all", 3) == 0)
12683 args
+= 3; /* Skip special argument "all". */
12685 error (_("Junk at end of arguments."));
12687 ALL_TRACEPOINTS (t1
)
12689 trace_pass_set_count (t1
, count
, from_tty
);
12692 else if (*args
== '\0')
12694 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
12696 trace_pass_set_count (t1
, count
, from_tty
);
12700 struct get_number_or_range_state state
;
12702 init_number_or_range (&state
, args
);
12703 while (!state
.finished
)
12705 t1
= get_tracepoint_by_number (&args
, &state
, 1);
12707 trace_pass_set_count (t1
, count
, from_tty
);
12712 struct breakpoint
*
12713 get_tracepoint (int num
)
12715 struct breakpoint
*t
;
12717 ALL_TRACEPOINTS (t
)
12718 if (t
->number
== num
)
12724 /* Find the tracepoint with the given target-side number (which may be
12725 different from the tracepoint number after disconnecting and
12728 struct breakpoint
*
12729 get_tracepoint_by_number_on_target (int num
)
12731 struct breakpoint
*t
;
12733 ALL_TRACEPOINTS (t
)
12734 if (t
->number_on_target
== num
)
12740 /* Utility: parse a tracepoint number and look it up in the list.
12741 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
12742 If OPTIONAL_P is true, then if the argument is missing, the most
12743 recent tracepoint (tracepoint_count) is returned. */
12744 struct breakpoint
*
12745 get_tracepoint_by_number (char **arg
,
12746 struct get_number_or_range_state
*state
,
12749 extern int tracepoint_count
;
12750 struct breakpoint
*t
;
12752 char *instring
= arg
== NULL
? NULL
: *arg
;
12756 gdb_assert (!state
->finished
);
12757 tpnum
= get_number_or_range (state
);
12759 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
12762 tpnum
= tracepoint_count
;
12764 error_no_arg (_("tracepoint number"));
12767 tpnum
= get_number (arg
);
12771 if (instring
&& *instring
)
12772 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
12775 printf_filtered (_("Tracepoint argument missing "
12776 "and no previous tracepoint\n"));
12780 ALL_TRACEPOINTS (t
)
12781 if (t
->number
== tpnum
)
12786 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
12790 /* Save information on user settable breakpoints (watchpoints, etc) to
12791 a new script file named FILENAME. If FILTER is non-NULL, call it
12792 on each breakpoint and only include the ones for which it returns
12796 save_breakpoints (char *filename
, int from_tty
,
12797 int (*filter
) (const struct breakpoint
*))
12799 struct breakpoint
*tp
;
12802 struct cleanup
*cleanup
;
12803 struct ui_file
*fp
;
12804 int extra_trace_bits
= 0;
12806 if (filename
== 0 || *filename
== 0)
12807 error (_("Argument required (file name in which to save)"));
12809 /* See if we have anything to save. */
12810 ALL_BREAKPOINTS (tp
)
12812 /* Skip internal and momentary breakpoints. */
12813 if (!user_breakpoint_p (tp
))
12816 /* If we have a filter, only save the breakpoints it accepts. */
12817 if (filter
&& !filter (tp
))
12822 if (is_tracepoint (tp
))
12824 extra_trace_bits
= 1;
12826 /* We can stop searching. */
12833 warning (_("Nothing to save."));
12837 pathname
= tilde_expand (filename
);
12838 cleanup
= make_cleanup (xfree
, pathname
);
12839 fp
= gdb_fopen (pathname
, "w");
12841 error (_("Unable to open file '%s' for saving (%s)"),
12842 filename
, safe_strerror (errno
));
12843 make_cleanup_ui_file_delete (fp
);
12845 if (extra_trace_bits
)
12846 save_trace_state_variables (fp
);
12848 ALL_BREAKPOINTS (tp
)
12850 /* Skip internal and momentary breakpoints. */
12851 if (!user_breakpoint_p (tp
))
12854 /* If we have a filter, only save the breakpoints it accepts. */
12855 if (filter
&& !filter (tp
))
12858 tp
->ops
->print_recreate (tp
, fp
);
12860 if (tp
->thread
!= -1)
12861 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
12864 fprintf_unfiltered (fp
, " task %d", tp
->task
);
12866 fprintf_unfiltered (fp
, "\n");
12868 /* Note, we can't rely on tp->number for anything, as we can't
12869 assume the recreated breakpoint numbers will match. Use $bpnum
12872 if (tp
->cond_string
)
12873 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
12875 if (tp
->ignore_count
)
12876 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
12878 if (tp
->pass_count
)
12879 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12883 volatile struct gdb_exception ex
;
12885 fprintf_unfiltered (fp
, " commands\n");
12887 ui_out_redirect (uiout
, fp
);
12888 TRY_CATCH (ex
, RETURN_MASK_ALL
)
12890 print_command_lines (uiout
, tp
->commands
->commands
, 2);
12892 ui_out_redirect (uiout
, NULL
);
12895 throw_exception (ex
);
12897 fprintf_unfiltered (fp
, " end\n");
12900 if (tp
->enable_state
== bp_disabled
)
12901 fprintf_unfiltered (fp
, "disable\n");
12903 /* If this is a multi-location breakpoint, check if the locations
12904 should be individually disabled. Watchpoint locations are
12905 special, and not user visible. */
12906 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
12908 struct bp_location
*loc
;
12911 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
12913 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
12917 if (extra_trace_bits
&& *default_collect
)
12918 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
12920 do_cleanups (cleanup
);
12922 printf_filtered (_("Saved to file '%s'.\n"), filename
);
12925 /* The `save breakpoints' command. */
12928 save_breakpoints_command (char *args
, int from_tty
)
12930 save_breakpoints (args
, from_tty
, NULL
);
12933 /* The `save tracepoints' command. */
12936 save_tracepoints_command (char *args
, int from_tty
)
12938 save_breakpoints (args
, from_tty
, is_tracepoint
);
12941 /* Create a vector of all tracepoints. */
12943 VEC(breakpoint_p
) *
12944 all_tracepoints (void)
12946 VEC(breakpoint_p
) *tp_vec
= 0;
12947 struct breakpoint
*tp
;
12949 ALL_TRACEPOINTS (tp
)
12951 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
12958 /* This help string is used for the break, hbreak, tbreak and thbreak
12959 commands. It is defined as a macro to prevent duplication.
12960 COMMAND should be a string constant containing the name of the
12962 #define BREAK_ARGS_HELP(command) \
12963 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
12964 LOCATION may be a line number, function name, or \"*\" and an address.\n\
12965 If a line number is specified, break at start of code for that line.\n\
12966 If a function is specified, break at start of code for that function.\n\
12967 If an address is specified, break at that exact address.\n\
12968 With no LOCATION, uses current execution address of the selected\n\
12969 stack frame. This is useful for breaking on return to a stack frame.\n\
12971 THREADNUM is the number from \"info threads\".\n\
12972 CONDITION is a boolean expression.\n\
12974 Multiple breakpoints at one place are permitted, and useful if their\n\
12975 conditions are different.\n\
12977 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
12979 /* List of subcommands for "catch". */
12980 static struct cmd_list_element
*catch_cmdlist
;
12982 /* List of subcommands for "tcatch". */
12983 static struct cmd_list_element
*tcatch_cmdlist
;
12986 add_catch_command (char *name
, char *docstring
,
12987 void (*sfunc
) (char *args
, int from_tty
,
12988 struct cmd_list_element
*command
),
12989 char **(*completer
) (struct cmd_list_element
*cmd
,
12990 char *text
, char *word
),
12991 void *user_data_catch
,
12992 void *user_data_tcatch
)
12994 struct cmd_list_element
*command
;
12996 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12998 set_cmd_sfunc (command
, sfunc
);
12999 set_cmd_context (command
, user_data_catch
);
13000 set_cmd_completer (command
, completer
);
13002 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13004 set_cmd_sfunc (command
, sfunc
);
13005 set_cmd_context (command
, user_data_tcatch
);
13006 set_cmd_completer (command
, completer
);
13010 clear_syscall_counts (struct inferior
*inf
)
13012 inf
->total_syscalls_count
= 0;
13013 inf
->any_syscall_count
= 0;
13014 VEC_free (int, inf
->syscalls_counts
);
13018 save_command (char *arg
, int from_tty
)
13020 printf_unfiltered (_("\"save\" must be followed by "
13021 "the name of a save subcommand.\n"));
13022 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13025 struct breakpoint
*
13026 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13029 struct breakpoint
*b
, *b_tmp
;
13031 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13033 if ((*callback
) (b
, data
))
13041 initialize_breakpoint_ops (void)
13043 static int initialized
= 0;
13045 struct breakpoint_ops
*ops
;
13051 /* The breakpoint_ops structure to be inherit by all kinds of
13052 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13053 internal and momentary breakpoints, etc.). */
13054 ops
= &bkpt_base_breakpoint_ops
;
13055 *ops
= base_breakpoint_ops
;
13056 ops
->re_set
= bkpt_re_set
;
13057 ops
->insert_location
= bkpt_insert_location
;
13058 ops
->remove_location
= bkpt_remove_location
;
13059 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13061 /* The breakpoint_ops structure to be used in regular breakpoints. */
13062 ops
= &bkpt_breakpoint_ops
;
13063 *ops
= bkpt_base_breakpoint_ops
;
13064 ops
->re_set
= bkpt_re_set
;
13065 ops
->resources_needed
= bkpt_resources_needed
;
13066 ops
->print_it
= bkpt_print_it
;
13067 ops
->print_mention
= bkpt_print_mention
;
13068 ops
->print_recreate
= bkpt_print_recreate
;
13070 /* Ranged breakpoints. */
13071 ops
= &ranged_breakpoint_ops
;
13072 *ops
= bkpt_breakpoint_ops
;
13073 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13074 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13075 ops
->print_it
= print_it_ranged_breakpoint
;
13076 ops
->print_one
= print_one_ranged_breakpoint
;
13077 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13078 ops
->print_mention
= print_mention_ranged_breakpoint
;
13079 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13081 /* Internal breakpoints. */
13082 ops
= &internal_breakpoint_ops
;
13083 *ops
= bkpt_base_breakpoint_ops
;
13084 ops
->re_set
= internal_bkpt_re_set
;
13085 ops
->check_status
= internal_bkpt_check_status
;
13086 ops
->print_it
= internal_bkpt_print_it
;
13087 ops
->print_mention
= internal_bkpt_print_mention
;
13089 /* Momentary breakpoints. */
13090 ops
= &momentary_breakpoint_ops
;
13091 *ops
= bkpt_base_breakpoint_ops
;
13092 ops
->re_set
= momentary_bkpt_re_set
;
13093 ops
->check_status
= momentary_bkpt_check_status
;
13094 ops
->print_it
= momentary_bkpt_print_it
;
13095 ops
->print_mention
= momentary_bkpt_print_mention
;
13097 /* GNU v3 exception catchpoints. */
13098 ops
= &gnu_v3_exception_catchpoint_ops
;
13099 *ops
= bkpt_breakpoint_ops
;
13100 ops
->print_it
= print_it_exception_catchpoint
;
13101 ops
->print_one
= print_one_exception_catchpoint
;
13102 ops
->print_mention
= print_mention_exception_catchpoint
;
13103 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13106 ops
= &watchpoint_breakpoint_ops
;
13107 *ops
= base_breakpoint_ops
;
13108 ops
->re_set
= re_set_watchpoint
;
13109 ops
->insert_location
= insert_watchpoint
;
13110 ops
->remove_location
= remove_watchpoint
;
13111 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13112 ops
->check_status
= check_status_watchpoint
;
13113 ops
->resources_needed
= resources_needed_watchpoint
;
13114 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13115 ops
->print_it
= print_it_watchpoint
;
13116 ops
->print_mention
= print_mention_watchpoint
;
13117 ops
->print_recreate
= print_recreate_watchpoint
;
13119 /* Masked watchpoints. */
13120 ops
= &masked_watchpoint_breakpoint_ops
;
13121 *ops
= watchpoint_breakpoint_ops
;
13122 ops
->insert_location
= insert_masked_watchpoint
;
13123 ops
->remove_location
= remove_masked_watchpoint
;
13124 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13125 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13126 ops
->print_it
= print_it_masked_watchpoint
;
13127 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13128 ops
->print_mention
= print_mention_masked_watchpoint
;
13129 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13132 ops
= &tracepoint_breakpoint_ops
;
13133 *ops
= base_breakpoint_ops
;
13134 ops
->re_set
= tracepoint_re_set
;
13135 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13136 ops
->print_one_detail
= tracepoint_print_one_detail
;
13137 ops
->print_mention
= tracepoint_print_mention
;
13138 ops
->print_recreate
= tracepoint_print_recreate
;
13140 /* Fork catchpoints. */
13141 ops
= &catch_fork_breakpoint_ops
;
13142 *ops
= base_breakpoint_ops
;
13143 ops
->insert_location
= insert_catch_fork
;
13144 ops
->remove_location
= remove_catch_fork
;
13145 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13146 ops
->print_it
= print_it_catch_fork
;
13147 ops
->print_one
= print_one_catch_fork
;
13148 ops
->print_mention
= print_mention_catch_fork
;
13149 ops
->print_recreate
= print_recreate_catch_fork
;
13151 /* Vfork catchpoints. */
13152 ops
= &catch_vfork_breakpoint_ops
;
13153 *ops
= base_breakpoint_ops
;
13154 ops
->insert_location
= insert_catch_vfork
;
13155 ops
->remove_location
= remove_catch_vfork
;
13156 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13157 ops
->print_it
= print_it_catch_vfork
;
13158 ops
->print_one
= print_one_catch_vfork
;
13159 ops
->print_mention
= print_mention_catch_vfork
;
13160 ops
->print_recreate
= print_recreate_catch_vfork
;
13162 /* Exec catchpoints. */
13163 ops
= &catch_exec_breakpoint_ops
;
13164 *ops
= base_breakpoint_ops
;
13165 ops
->dtor
= dtor_catch_exec
;
13166 ops
->insert_location
= insert_catch_exec
;
13167 ops
->remove_location
= remove_catch_exec
;
13168 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13169 ops
->print_it
= print_it_catch_exec
;
13170 ops
->print_one
= print_one_catch_exec
;
13171 ops
->print_mention
= print_mention_catch_exec
;
13172 ops
->print_recreate
= print_recreate_catch_exec
;
13174 /* Syscall catchpoints. */
13175 ops
= &catch_syscall_breakpoint_ops
;
13176 *ops
= base_breakpoint_ops
;
13177 ops
->dtor
= dtor_catch_syscall
;
13178 ops
->insert_location
= insert_catch_syscall
;
13179 ops
->remove_location
= remove_catch_syscall
;
13180 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13181 ops
->print_it
= print_it_catch_syscall
;
13182 ops
->print_one
= print_one_catch_syscall
;
13183 ops
->print_mention
= print_mention_catch_syscall
;
13184 ops
->print_recreate
= print_recreate_catch_syscall
;
13188 _initialize_breakpoint (void)
13190 struct cmd_list_element
*c
;
13192 initialize_breakpoint_ops ();
13194 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13195 observer_attach_inferior_exit (clear_syscall_counts
);
13196 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13198 breakpoint_objfile_key
= register_objfile_data ();
13200 breakpoint_chain
= 0;
13201 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13202 before a breakpoint is set. */
13203 breakpoint_count
= 0;
13205 tracepoint_count
= 0;
13207 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13208 Set ignore-count of breakpoint number N to COUNT.\n\
13209 Usage is `ignore N COUNT'."));
13211 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13213 add_com ("commands", class_breakpoint
, commands_command
, _("\
13214 Set commands to be executed when a breakpoint is hit.\n\
13215 Give breakpoint number as argument after \"commands\".\n\
13216 With no argument, the targeted breakpoint is the last one set.\n\
13217 The commands themselves follow starting on the next line.\n\
13218 Type a line containing \"end\" to indicate the end of them.\n\
13219 Give \"silent\" as the first line to make the breakpoint silent;\n\
13220 then no output is printed when it is hit, except what the commands print."));
13222 add_com ("condition", class_breakpoint
, condition_command
, _("\
13223 Specify breakpoint number N to break only if COND is true.\n\
13224 Usage is `condition N COND', where N is an integer and COND is an\n\
13225 expression to be evaluated whenever breakpoint N is reached."));
13227 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13228 Set a temporary breakpoint.\n\
13229 Like \"break\" except the breakpoint is only temporary,\n\
13230 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13231 by using \"enable delete\" on the breakpoint number.\n\
13233 BREAK_ARGS_HELP ("tbreak")));
13234 set_cmd_completer (c
, location_completer
);
13236 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13237 Set a hardware assisted breakpoint.\n\
13238 Like \"break\" except the breakpoint requires hardware support,\n\
13239 some target hardware may not have this support.\n\
13241 BREAK_ARGS_HELP ("hbreak")));
13242 set_cmd_completer (c
, location_completer
);
13244 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13245 Set a temporary hardware assisted breakpoint.\n\
13246 Like \"hbreak\" except the breakpoint is only temporary,\n\
13247 so it will be deleted when hit.\n\
13249 BREAK_ARGS_HELP ("thbreak")));
13250 set_cmd_completer (c
, location_completer
);
13252 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13253 Enable some breakpoints.\n\
13254 Give breakpoint numbers (separated by spaces) as arguments.\n\
13255 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13256 This is used to cancel the effect of the \"disable\" command.\n\
13257 With a subcommand you can enable temporarily."),
13258 &enablelist
, "enable ", 1, &cmdlist
);
13260 add_com ("ab", class_breakpoint
, enable_command
, _("\
13261 Enable some breakpoints.\n\
13262 Give breakpoint numbers (separated by spaces) as arguments.\n\
13263 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13264 This is used to cancel the effect of the \"disable\" command.\n\
13265 With a subcommand you can enable temporarily."));
13267 add_com_alias ("en", "enable", class_breakpoint
, 1);
13269 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13270 Enable some breakpoints.\n\
13271 Give breakpoint numbers (separated by spaces) as arguments.\n\
13272 This is used to cancel the effect of the \"disable\" command.\n\
13273 May be abbreviated to simply \"enable\".\n"),
13274 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13276 add_cmd ("once", no_class
, enable_once_command
, _("\
13277 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13278 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13281 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13282 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13283 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13286 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13287 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13288 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13291 add_cmd ("once", no_class
, enable_once_command
, _("\
13292 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13293 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13296 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13297 Disable some breakpoints.\n\
13298 Arguments are breakpoint numbers with spaces in between.\n\
13299 To disable all breakpoints, give no argument.\n\
13300 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13301 &disablelist
, "disable ", 1, &cmdlist
);
13302 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13303 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13305 add_com ("sb", class_breakpoint
, disable_command
, _("\
13306 Disable some breakpoints.\n\
13307 Arguments are breakpoint numbers with spaces in between.\n\
13308 To disable all breakpoints, give no argument.\n\
13309 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13311 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13312 Disable some breakpoints.\n\
13313 Arguments are breakpoint numbers with spaces in between.\n\
13314 To disable all breakpoints, give no argument.\n\
13315 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13316 This command may be abbreviated \"disable\"."),
13319 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13320 Delete some breakpoints or auto-display expressions.\n\
13321 Arguments are breakpoint numbers with spaces in between.\n\
13322 To delete all breakpoints, give no argument.\n\
13324 Also a prefix command for deletion of other GDB objects.\n\
13325 The \"unset\" command is also an alias for \"delete\"."),
13326 &deletelist
, "delete ", 1, &cmdlist
);
13327 add_com_alias ("d", "delete", class_breakpoint
, 1);
13328 add_com_alias ("del", "delete", class_breakpoint
, 1);
13330 add_com ("db", class_breakpoint
, delete_command
, _("\
13331 Delete some breakpoints.\n\
13332 Arguments are breakpoint numbers with spaces in between.\n\
13333 To delete all breakpoints, give no argument.\n"));
13335 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13336 Delete some breakpoints or auto-display expressions.\n\
13337 Arguments are breakpoint numbers with spaces in between.\n\
13338 To delete all breakpoints, give no argument.\n\
13339 This command may be abbreviated \"delete\"."),
13342 add_com ("clear", class_breakpoint
, clear_command
, _("\
13343 Clear breakpoint at specified line or function.\n\
13344 Argument may be line number, function name, or \"*\" and an address.\n\
13345 If line number is specified, all breakpoints in that line are cleared.\n\
13346 If function is specified, breakpoints at beginning of function are cleared.\n\
13347 If an address is specified, breakpoints at that address are cleared.\n\
13349 With no argument, clears all breakpoints in the line that the selected frame\n\
13350 is executing in.\n\
13352 See also the \"delete\" command which clears breakpoints by number."));
13353 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13355 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13356 Set breakpoint at specified line or function.\n"
13357 BREAK_ARGS_HELP ("break")));
13358 set_cmd_completer (c
, location_completer
);
13360 add_com_alias ("b", "break", class_run
, 1);
13361 add_com_alias ("br", "break", class_run
, 1);
13362 add_com_alias ("bre", "break", class_run
, 1);
13363 add_com_alias ("brea", "break", class_run
, 1);
13366 add_com_alias ("ba", "break", class_breakpoint
, 1);
13370 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13371 Break in function/address or break at a line in the current file."),
13372 &stoplist
, "stop ", 1, &cmdlist
);
13373 add_cmd ("in", class_breakpoint
, stopin_command
,
13374 _("Break in function or address."), &stoplist
);
13375 add_cmd ("at", class_breakpoint
, stopat_command
,
13376 _("Break at a line in the current file."), &stoplist
);
13377 add_com ("status", class_info
, breakpoints_info
, _("\
13378 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13379 The \"Type\" column indicates one of:\n\
13380 \tbreakpoint - normal breakpoint\n\
13381 \twatchpoint - watchpoint\n\
13382 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13383 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13384 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13385 address and file/line number respectively.\n\
13387 Convenience variable \"$_\" and default examine address for \"x\"\n\
13388 are set to the address of the last breakpoint listed unless the command\n\
13389 is prefixed with \"server \".\n\n\
13390 Convenience variable \"$bpnum\" contains the number of the last\n\
13391 breakpoint set."));
13394 add_info ("breakpoints", breakpoints_info
, _("\
13395 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13396 The \"Type\" column indicates one of:\n\
13397 \tbreakpoint - normal breakpoint\n\
13398 \twatchpoint - watchpoint\n\
13399 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13400 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13401 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13402 address and file/line number respectively.\n\
13404 Convenience variable \"$_\" and default examine address for \"x\"\n\
13405 are set to the address of the last breakpoint listed unless the command\n\
13406 is prefixed with \"server \".\n\n\
13407 Convenience variable \"$bpnum\" contains the number of the last\n\
13408 breakpoint set."));
13410 add_info_alias ("b", "breakpoints", 1);
13413 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13414 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13415 The \"Type\" column indicates one of:\n\
13416 \tbreakpoint - normal breakpoint\n\
13417 \twatchpoint - watchpoint\n\
13418 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13419 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13420 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13421 address and file/line number respectively.\n\
13423 Convenience variable \"$_\" and default examine address for \"x\"\n\
13424 are set to the address of the last breakpoint listed unless the command\n\
13425 is prefixed with \"server \".\n\n\
13426 Convenience variable \"$bpnum\" contains the number of the last\n\
13427 breakpoint set."));
13429 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13430 Status of all breakpoints, or breakpoint number NUMBER.\n\
13431 The \"Type\" column indicates one of:\n\
13432 \tbreakpoint - normal breakpoint\n\
13433 \twatchpoint - watchpoint\n\
13434 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13435 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13436 \tuntil - internal breakpoint used by the \"until\" command\n\
13437 \tfinish - internal breakpoint used by the \"finish\" command\n\
13438 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13439 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13440 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13441 address and file/line number respectively.\n\
13443 Convenience variable \"$_\" and default examine address for \"x\"\n\
13444 are set to the address of the last breakpoint listed unless the command\n\
13445 is prefixed with \"server \".\n\n\
13446 Convenience variable \"$bpnum\" contains the number of the last\n\
13448 &maintenanceinfolist
);
13450 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13451 Set catchpoints to catch events."),
13452 &catch_cmdlist
, "catch ",
13453 0/*allow-unknown*/, &cmdlist
);
13455 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13456 Set temporary catchpoints to catch events."),
13457 &tcatch_cmdlist
, "tcatch ",
13458 0/*allow-unknown*/, &cmdlist
);
13460 /* Add catch and tcatch sub-commands. */
13461 add_catch_command ("catch", _("\
13462 Catch an exception, when caught.\n\
13463 With an argument, catch only exceptions with the given name."),
13464 catch_catch_command
,
13468 add_catch_command ("throw", _("\
13469 Catch an exception, when thrown.\n\
13470 With an argument, catch only exceptions with the given name."),
13471 catch_throw_command
,
13475 add_catch_command ("fork", _("Catch calls to fork."),
13476 catch_fork_command_1
,
13478 (void *) (uintptr_t) catch_fork_permanent
,
13479 (void *) (uintptr_t) catch_fork_temporary
);
13480 add_catch_command ("vfork", _("Catch calls to vfork."),
13481 catch_fork_command_1
,
13483 (void *) (uintptr_t) catch_vfork_permanent
,
13484 (void *) (uintptr_t) catch_vfork_temporary
);
13485 add_catch_command ("exec", _("Catch calls to exec."),
13486 catch_exec_command_1
,
13490 add_catch_command ("syscall", _("\
13491 Catch system calls by their names and/or numbers.\n\
13492 Arguments say which system calls to catch. If no arguments\n\
13493 are given, every system call will be caught.\n\
13494 Arguments, if given, should be one or more system call names\n\
13495 (if your system supports that), or system call numbers."),
13496 catch_syscall_command_1
,
13497 catch_syscall_completer
,
13501 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13502 Set a watchpoint for an expression.\n\
13503 Usage: watch [-l|-location] EXPRESSION\n\
13504 A watchpoint stops execution of your program whenever the value of\n\
13505 an expression changes.\n\
13506 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13507 the memory to which it refers."));
13508 set_cmd_completer (c
, expression_completer
);
13510 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13511 Set a read watchpoint for an expression.\n\
13512 Usage: rwatch [-l|-location] EXPRESSION\n\
13513 A watchpoint stops execution of your program whenever the value of\n\
13514 an expression is read.\n\
13515 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13516 the memory to which it refers."));
13517 set_cmd_completer (c
, expression_completer
);
13519 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13520 Set a watchpoint for an expression.\n\
13521 Usage: awatch [-l|-location] EXPRESSION\n\
13522 A watchpoint stops execution of your program whenever the value of\n\
13523 an expression is either read or written.\n\
13524 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13525 the memory to which it refers."));
13526 set_cmd_completer (c
, expression_completer
);
13528 add_info ("watchpoints", watchpoints_info
, _("\
13529 Status of specified watchpoints (all watchpoints if no argument)."));
13531 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13532 respond to changes - contrary to the description. */
13533 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13534 &can_use_hw_watchpoints
, _("\
13535 Set debugger's willingness to use watchpoint hardware."), _("\
13536 Show debugger's willingness to use watchpoint hardware."), _("\
13537 If zero, gdb will not use hardware for new watchpoints, even if\n\
13538 such is available. (However, any hardware watchpoints that were\n\
13539 created before setting this to nonzero, will continue to use watchpoint\n\
13542 show_can_use_hw_watchpoints
,
13543 &setlist
, &showlist
);
13545 can_use_hw_watchpoints
= 1;
13547 /* Tracepoint manipulation commands. */
13549 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13550 Set a tracepoint at specified line or function.\n\
13552 BREAK_ARGS_HELP ("trace") "\n\
13553 Do \"help tracepoints\" for info on other tracepoint commands."));
13554 set_cmd_completer (c
, location_completer
);
13556 add_com_alias ("tp", "trace", class_alias
, 0);
13557 add_com_alias ("tr", "trace", class_alias
, 1);
13558 add_com_alias ("tra", "trace", class_alias
, 1);
13559 add_com_alias ("trac", "trace", class_alias
, 1);
13561 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13562 Set a fast tracepoint at specified line or function.\n\
13564 BREAK_ARGS_HELP ("ftrace") "\n\
13565 Do \"help tracepoints\" for info on other tracepoint commands."));
13566 set_cmd_completer (c
, location_completer
);
13568 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13569 Set a static tracepoint at specified line, function or marker.\n\
13571 strace [LOCATION] [if CONDITION]\n\
13572 LOCATION may be a line number, function name, \"*\" and an address,\n\
13573 or -m MARKER_ID.\n\
13574 If a line number is specified, probe the marker at start of code\n\
13575 for that line. If a function is specified, probe the marker at start\n\
13576 of code for that function. If an address is specified, probe the marker\n\
13577 at that exact address. If a marker id is specified, probe the marker\n\
13578 with that name. With no LOCATION, uses current execution address of\n\
13579 the selected stack frame.\n\
13580 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13581 This collects arbitrary user data passed in the probe point call to the\n\
13582 tracing library. You can inspect it when analyzing the trace buffer,\n\
13583 by printing the $_sdata variable like any other convenience variable.\n\
13585 CONDITION is a boolean expression.\n\
13587 Multiple tracepoints at one place are permitted, and useful if their\n\
13588 conditions are different.\n\
13590 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13591 Do \"help tracepoints\" for info on other tracepoint commands."));
13592 set_cmd_completer (c
, location_completer
);
13594 add_info ("tracepoints", tracepoints_info
, _("\
13595 Status of specified tracepoints (all tracepoints if no argument).\n\
13596 Convenience variable \"$tpnum\" contains the number of the\n\
13597 last tracepoint set."));
13599 add_info_alias ("tp", "tracepoints", 1);
13601 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13602 Delete specified tracepoints.\n\
13603 Arguments are tracepoint numbers, separated by spaces.\n\
13604 No argument means delete all tracepoints."),
13607 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13608 Disable specified tracepoints.\n\
13609 Arguments are tracepoint numbers, separated by spaces.\n\
13610 No argument means disable all tracepoints."),
13612 deprecate_cmd (c
, "disable");
13614 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
13615 Enable specified tracepoints.\n\
13616 Arguments are tracepoint numbers, separated by spaces.\n\
13617 No argument means enable all tracepoints."),
13619 deprecate_cmd (c
, "enable");
13621 add_com ("passcount", class_trace
, trace_pass_command
, _("\
13622 Set the passcount for a tracepoint.\n\
13623 The trace will end when the tracepoint has been passed 'count' times.\n\
13624 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13625 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13627 add_prefix_cmd ("save", class_breakpoint
, save_command
,
13628 _("Save breakpoint definitions as a script."),
13629 &save_cmdlist
, "save ",
13630 0/*allow-unknown*/, &cmdlist
);
13632 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
13633 Save current breakpoint definitions as a script.\n\
13634 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13635 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13636 session to restore them."),
13638 set_cmd_completer (c
, filename_completer
);
13640 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
13641 Save current tracepoint definitions as a script.\n\
13642 Use the 'source' command in another debug session to restore them."),
13644 set_cmd_completer (c
, filename_completer
);
13646 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
13647 deprecate_cmd (c
, "save tracepoints");
13649 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
13650 Breakpoint specific settings\n\
13651 Configure various breakpoint-specific variables such as\n\
13652 pending breakpoint behavior"),
13653 &breakpoint_set_cmdlist
, "set breakpoint ",
13654 0/*allow-unknown*/, &setlist
);
13655 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
13656 Breakpoint specific settings\n\
13657 Configure various breakpoint-specific variables such as\n\
13658 pending breakpoint behavior"),
13659 &breakpoint_show_cmdlist
, "show breakpoint ",
13660 0/*allow-unknown*/, &showlist
);
13662 add_setshow_auto_boolean_cmd ("pending", no_class
,
13663 &pending_break_support
, _("\
13664 Set debugger's behavior regarding pending breakpoints."), _("\
13665 Show debugger's behavior regarding pending breakpoints."), _("\
13666 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13667 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13668 an error. If auto, an unrecognized breakpoint location results in a\n\
13669 user-query to see if a pending breakpoint should be created."),
13671 show_pending_break_support
,
13672 &breakpoint_set_cmdlist
,
13673 &breakpoint_show_cmdlist
);
13675 pending_break_support
= AUTO_BOOLEAN_AUTO
;
13677 add_setshow_boolean_cmd ("auto-hw", no_class
,
13678 &automatic_hardware_breakpoints
, _("\
13679 Set automatic usage of hardware breakpoints."), _("\
13680 Show automatic usage of hardware breakpoints."), _("\
13681 If set, the debugger will automatically use hardware breakpoints for\n\
13682 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13683 a warning will be emitted for such breakpoints."),
13685 show_automatic_hardware_breakpoints
,
13686 &breakpoint_set_cmdlist
,
13687 &breakpoint_show_cmdlist
);
13689 add_setshow_enum_cmd ("always-inserted", class_support
,
13690 always_inserted_enums
, &always_inserted_mode
, _("\
13691 Set mode for inserting breakpoints."), _("\
13692 Show mode for inserting breakpoints."), _("\
13693 When this mode is off, breakpoints are inserted in inferior when it is\n\
13694 resumed, and removed when execution stops. When this mode is on,\n\
13695 breakpoints are inserted immediately and removed only when the user\n\
13696 deletes the breakpoint. When this mode is auto (which is the default),\n\
13697 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13698 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13699 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13700 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13702 &show_always_inserted_mode
,
13703 &breakpoint_set_cmdlist
,
13704 &breakpoint_show_cmdlist
);
13706 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
13707 Set a breakpoint for an address range.\n\
13708 break-range START-LOCATION, END-LOCATION\n\
13709 where START-LOCATION and END-LOCATION can be one of the following:\n\
13710 LINENUM, for that line in the current file,\n\
13711 FILE:LINENUM, for that line in that file,\n\
13712 +OFFSET, for that number of lines after the current line\n\
13713 or the start of the range\n\
13714 FUNCTION, for the first line in that function,\n\
13715 FILE:FUNCTION, to distinguish among like-named static functions.\n\
13716 *ADDRESS, for the instruction at that address.\n\
13718 The breakpoint will stop execution of the inferior whenever it executes\n\
13719 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
13720 range (including START-LOCATION and END-LOCATION)."));
13722 automatic_hardware_breakpoints
= 1;
13724 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);