1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdbsupport/gdb_regex.h"
61 #include "cli/cli-utils.h"
64 #include "dummy-frame.h"
66 #include "gdbsupport/format.h"
67 #include "thread-fsm.h"
68 #include "tid-parse.h"
69 #include "cli/cli-style.h"
70 #include "cli/cli-decode.h"
72 /* readline include files */
73 #include "readline/tilde.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "extension.h"
81 #include "progspace-and-thread.h"
82 #include "gdbsupport/array-view.h"
83 #include "gdbsupport/gdb_optional.h"
85 /* Prototypes for local functions. */
87 static void map_breakpoint_numbers (const char *,
88 gdb::function_view
<void (breakpoint
*)>);
90 static void breakpoint_re_set_default (struct breakpoint
*);
93 create_sals_from_location_default (struct event_location
*location
,
94 struct linespec_result
*canonical
,
95 enum bptype type_wanted
);
97 static void create_breakpoints_sal_default (struct gdbarch
*,
98 struct linespec_result
*,
99 gdb::unique_xmalloc_ptr
<char>,
100 gdb::unique_xmalloc_ptr
<char>,
102 enum bpdisp
, int, int,
104 const struct breakpoint_ops
*,
105 int, int, int, unsigned);
107 static std::vector
<symtab_and_line
> decode_location_default
108 (struct breakpoint
*b
, struct event_location
*location
,
109 struct program_space
*search_pspace
);
111 static int can_use_hardware_watchpoint
112 (const std::vector
<value_ref_ptr
> &vals
);
114 static void mention (struct breakpoint
*);
116 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
118 const struct breakpoint_ops
*);
119 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
120 const struct symtab_and_line
*);
122 /* This function is used in gdbtk sources and thus can not be made
124 static struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
125 struct symtab_and_line
,
127 const struct breakpoint_ops
*);
129 static struct breakpoint
*
130 momentary_breakpoint_from_master (struct breakpoint
*orig
,
132 const struct breakpoint_ops
*ops
,
135 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
137 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
141 static void describe_other_breakpoints (struct gdbarch
*,
142 struct program_space
*, CORE_ADDR
,
143 struct obj_section
*, int);
145 static int watchpoint_locations_match (struct bp_location
*loc1
,
146 struct bp_location
*loc2
);
148 static int breakpoint_locations_match (struct bp_location
*loc1
,
149 struct bp_location
*loc2
,
150 bool sw_hw_bps_match
= false);
152 static int breakpoint_location_address_match (struct bp_location
*bl
,
153 const struct address_space
*aspace
,
156 static int breakpoint_location_address_range_overlap (struct bp_location
*,
157 const address_space
*,
160 static int remove_breakpoint (struct bp_location
*);
161 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
163 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
165 static int hw_breakpoint_used_count (void);
167 static int hw_watchpoint_use_count (struct breakpoint
*);
169 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
171 int *other_type_used
);
173 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
176 static void decref_bp_location (struct bp_location
**loc
);
178 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
180 /* update_global_location_list's modes of operation wrt to whether to
181 insert locations now. */
182 enum ugll_insert_mode
184 /* Don't insert any breakpoint locations into the inferior, only
185 remove already-inserted locations that no longer should be
186 inserted. Functions that delete a breakpoint or breakpoints
187 should specify this mode, so that deleting a breakpoint doesn't
188 have the side effect of inserting the locations of other
189 breakpoints that are marked not-inserted, but should_be_inserted
190 returns true on them.
192 This behavior is useful is situations close to tear-down -- e.g.,
193 after an exec, while the target still has execution, but
194 breakpoint shadows of the previous executable image should *NOT*
195 be restored to the new image; or before detaching, where the
196 target still has execution and wants to delete breakpoints from
197 GDB's lists, and all breakpoints had already been removed from
201 /* May insert breakpoints iff breakpoints_should_be_inserted_now
202 claims breakpoints should be inserted now. */
205 /* Insert locations now, irrespective of
206 breakpoints_should_be_inserted_now. E.g., say all threads are
207 stopped right now, and the user did "continue". We need to
208 insert breakpoints _before_ resuming the target, but
209 UGLL_MAY_INSERT wouldn't insert them, because
210 breakpoints_should_be_inserted_now returns false at that point,
211 as no thread is running yet. */
215 static void update_global_location_list (enum ugll_insert_mode
);
217 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
219 static void insert_breakpoint_locations (void);
221 static void trace_pass_command (const char *, int);
223 static void set_tracepoint_count (int num
);
225 static bool is_masked_watchpoint (const struct breakpoint
*b
);
227 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
230 static int strace_marker_p (struct breakpoint
*b
);
232 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
233 that are implemented on top of software or hardware breakpoints
234 (user breakpoints, internal and momentary breakpoints, etc.). */
235 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
237 /* Internal breakpoints class type. */
238 static struct breakpoint_ops internal_breakpoint_ops
;
240 /* Momentary breakpoints class type. */
241 static struct breakpoint_ops momentary_breakpoint_ops
;
243 /* The breakpoint_ops structure to be used in regular user created
245 struct breakpoint_ops bkpt_breakpoint_ops
;
247 /* Breakpoints set on probes. */
248 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
250 /* Tracepoints set on probes. */
251 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
253 /* Dynamic printf class type. */
254 struct breakpoint_ops dprintf_breakpoint_ops
;
256 /* The style in which to perform a dynamic printf. This is a user
257 option because different output options have different tradeoffs;
258 if GDB does the printing, there is better error handling if there
259 is a problem with any of the arguments, but using an inferior
260 function lets you have special-purpose printers and sending of
261 output to the same place as compiled-in print functions. */
263 static const char dprintf_style_gdb
[] = "gdb";
264 static const char dprintf_style_call
[] = "call";
265 static const char dprintf_style_agent
[] = "agent";
266 static const char *const dprintf_style_enums
[] = {
272 static const char *dprintf_style
= dprintf_style_gdb
;
274 /* The function to use for dynamic printf if the preferred style is to
275 call into the inferior. The value is simply a string that is
276 copied into the command, so it can be anything that GDB can
277 evaluate to a callable address, not necessarily a function name. */
279 static std::string dprintf_function
= "printf";
281 /* The channel to use for dynamic printf if the preferred style is to
282 call into the inferior; if a nonempty string, it will be passed to
283 the call as the first argument, with the format string as the
284 second. As with the dprintf function, this can be anything that
285 GDB knows how to evaluate, so in addition to common choices like
286 "stderr", this could be an app-specific expression like
287 "mystreams[curlogger]". */
289 static std::string dprintf_channel
;
291 /* True if dprintf commands should continue to operate even if GDB
293 static bool disconnected_dprintf
= true;
295 struct command_line
*
296 breakpoint_commands (struct breakpoint
*b
)
298 return b
->commands
? b
->commands
.get () : NULL
;
301 /* Flag indicating that a command has proceeded the inferior past the
302 current breakpoint. */
304 static bool breakpoint_proceeded
;
307 bpdisp_text (enum bpdisp disp
)
309 /* NOTE: the following values are a part of MI protocol and
310 represent values of 'disp' field returned when inferior stops at
312 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
314 return bpdisps
[(int) disp
];
317 /* Prototypes for exported functions. */
318 /* If FALSE, gdb will not use hardware support for watchpoints, even
319 if such is available. */
320 static int can_use_hw_watchpoints
;
323 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
324 struct cmd_list_element
*c
,
328 _("Debugger's willingness to use "
329 "watchpoint hardware is %s.\n"),
333 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
334 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
335 for unrecognized breakpoint locations.
336 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
337 static enum auto_boolean pending_break_support
;
339 show_pending_break_support (struct ui_file
*file
, int from_tty
,
340 struct cmd_list_element
*c
,
344 _("Debugger's behavior regarding "
345 "pending breakpoints is %s.\n"),
349 /* If true, gdb will automatically use hardware breakpoints for breakpoints
350 set with "break" but falling in read-only memory.
351 If false, gdb will warn about such breakpoints, but won't automatically
352 use hardware breakpoints. */
353 static bool automatic_hardware_breakpoints
;
355 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
356 struct cmd_list_element
*c
,
360 _("Automatic usage of hardware breakpoints is %s.\n"),
364 /* If on, GDB keeps breakpoints inserted even if the inferior is
365 stopped, and immediately inserts any new breakpoints as soon as
366 they're created. If off (default), GDB keeps breakpoints off of
367 the target as long as possible. That is, it delays inserting
368 breakpoints until the next resume, and removes them again when the
369 target fully stops. This is a bit safer in case GDB crashes while
370 processing user input. */
371 static bool always_inserted_mode
= false;
374 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
375 struct cmd_list_element
*c
, const char *value
)
377 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
381 /* See breakpoint.h. */
384 breakpoints_should_be_inserted_now (void)
386 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
388 /* If breakpoints are global, they should be inserted even if no
389 thread under gdb's control is running, or even if there are
390 no threads under GDB's control yet. */
395 if (always_inserted_mode
)
397 /* The user wants breakpoints inserted even if all threads
402 for (inferior
*inf
: all_inferiors ())
403 if (inf
->has_execution ()
404 && threads_are_executing (inf
->process_target ()))
407 /* Don't remove breakpoints yet if, even though all threads are
408 stopped, we still have events to process. */
409 for (thread_info
*tp
: all_non_exited_threads ())
410 if (tp
->resumed () && tp
->has_pending_waitstatus ())
416 static const char condition_evaluation_both
[] = "host or target";
418 /* Modes for breakpoint condition evaluation. */
419 static const char condition_evaluation_auto
[] = "auto";
420 static const char condition_evaluation_host
[] = "host";
421 static const char condition_evaluation_target
[] = "target";
422 static const char *const condition_evaluation_enums
[] = {
423 condition_evaluation_auto
,
424 condition_evaluation_host
,
425 condition_evaluation_target
,
429 /* Global that holds the current mode for breakpoint condition evaluation. */
430 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
432 /* Global that we use to display information to the user (gets its value from
433 condition_evaluation_mode_1. */
434 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
436 /* Translate a condition evaluation mode MODE into either "host"
437 or "target". This is used mostly to translate from "auto" to the
438 real setting that is being used. It returns the translated
442 translate_condition_evaluation_mode (const char *mode
)
444 if (mode
== condition_evaluation_auto
)
446 if (target_supports_evaluation_of_breakpoint_conditions ())
447 return condition_evaluation_target
;
449 return condition_evaluation_host
;
455 /* Discovers what condition_evaluation_auto translates to. */
458 breakpoint_condition_evaluation_mode (void)
460 return translate_condition_evaluation_mode (condition_evaluation_mode
);
463 /* Return true if GDB should evaluate breakpoint conditions or false
467 gdb_evaluates_breakpoint_condition_p (void)
469 const char *mode
= breakpoint_condition_evaluation_mode ();
471 return (mode
== condition_evaluation_host
);
474 /* Are we executing breakpoint commands? */
475 static int executing_breakpoint_commands
;
477 /* Are overlay event breakpoints enabled? */
478 static int overlay_events_enabled
;
480 /* See description in breakpoint.h. */
481 bool target_exact_watchpoints
= false;
483 /* Walk the following statement or block through all breakpoints.
484 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
485 current breakpoint. */
487 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
488 for (B = breakpoint_chain; \
489 B ? (TMP=B->next, 1): 0; \
492 /* Chains of all breakpoints defined. */
494 static struct breakpoint
*breakpoint_chain
;
496 /* See breakpoint.h. */
501 return breakpoint_range (breakpoint_chain
);
504 /* See breakpoint.h. */
506 breakpoint_safe_range
507 all_breakpoints_safe ()
509 return breakpoint_safe_range (all_breakpoints ());
512 /* See breakpoint.h. */
517 return tracepoint_range (breakpoint_chain
);
520 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
522 static std::vector
<bp_location
*> bp_locations
;
524 /* See breakpoint.h. */
526 const std::vector
<bp_location
*> &
532 /* Range to iterate over breakpoint locations at a given address. */
534 struct bp_locations_at_addr_range
536 using iterator
= std::vector
<bp_location
*>::iterator
;
538 bp_locations_at_addr_range (CORE_ADDR addr
)
542 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
543 { return loc
->address
< addr_
; }
545 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
546 { return addr_
< loc
->address
; }
549 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
552 m_begin
= it_pair
.first
;
553 m_end
= it_pair
.second
;
556 iterator
begin () const
559 iterator
end () const
567 /* Return a range to iterate over all breakpoint locations exactly at address
570 If it's needed to iterate multiple times on the same range, it's possible
571 to save the range in a local variable and use it multiple times:
573 auto range = all_bp_locations_at_addr (addr);
575 for (bp_location *loc : range)
578 for (bp_location *loc : range)
581 This saves a bit of time, as it avoids re-doing the binary searches to find
582 the range's boundaries. Just remember not to change the bp_locations vector
583 in the mean time, as it could make the range's iterators stale. */
585 static bp_locations_at_addr_range
586 all_bp_locations_at_addr (CORE_ADDR addr
)
588 return bp_locations_at_addr_range (addr
);
591 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
592 ADDRESS for the current elements of BP_LOCATIONS which get a valid
593 result from bp_location_has_shadow. You can use it for roughly
594 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
595 an address you need to read. */
597 static CORE_ADDR bp_locations_placed_address_before_address_max
;
599 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
600 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
601 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
602 You can use it for roughly limiting the subrange of BP_LOCATIONS to
603 scan for shadow bytes for an address you need to read. */
605 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
607 /* The locations that no longer correspond to any breakpoint, unlinked
608 from the bp_locations array, but for which a hit may still be
609 reported by a target. */
610 static std::vector
<bp_location
*> moribund_locations
;
612 /* Number of last breakpoint made. */
614 static int breakpoint_count
;
616 /* The value of `breakpoint_count' before the last command that
617 created breakpoints. If the last (break-like) command created more
618 than one breakpoint, then the difference between BREAKPOINT_COUNT
619 and PREV_BREAKPOINT_COUNT is more than one. */
620 static int prev_breakpoint_count
;
622 /* Number of last tracepoint made. */
624 static int tracepoint_count
;
626 static struct cmd_list_element
*breakpoint_set_cmdlist
;
627 static struct cmd_list_element
*breakpoint_show_cmdlist
;
628 struct cmd_list_element
*save_cmdlist
;
630 /* Return whether a breakpoint is an active enabled breakpoint. */
632 breakpoint_enabled (struct breakpoint
*b
)
634 return (b
->enable_state
== bp_enabled
);
637 /* Set breakpoint count to NUM. */
640 set_breakpoint_count (int num
)
642 prev_breakpoint_count
= breakpoint_count
;
643 breakpoint_count
= num
;
644 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
647 /* Used by `start_rbreak_breakpoints' below, to record the current
648 breakpoint count before "rbreak" creates any breakpoint. */
649 static int rbreak_start_breakpoint_count
;
651 /* Called at the start an "rbreak" command to record the first
654 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
656 rbreak_start_breakpoint_count
= breakpoint_count
;
659 /* Called at the end of an "rbreak" command to record the last
662 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
664 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
667 /* Used in run_command to zero the hit count when a new run starts. */
670 clear_breakpoint_hit_counts (void)
672 for (breakpoint
*b
: all_breakpoints ())
677 /* Return the breakpoint with the specified number, or NULL
678 if the number does not refer to an existing breakpoint. */
681 get_breakpoint (int num
)
683 for (breakpoint
*b
: all_breakpoints ())
684 if (b
->number
== num
)
692 /* Mark locations as "conditions have changed" in case the target supports
693 evaluating conditions on its side. */
696 mark_breakpoint_modified (struct breakpoint
*b
)
698 /* This is only meaningful if the target is
699 evaluating conditions and if the user has
700 opted for condition evaluation on the target's
702 if (gdb_evaluates_breakpoint_condition_p ()
703 || !target_supports_evaluation_of_breakpoint_conditions ())
706 if (!is_breakpoint (b
))
709 for (bp_location
*loc
: b
->locations ())
710 loc
->condition_changed
= condition_modified
;
713 /* Mark location as "conditions have changed" in case the target supports
714 evaluating conditions on its side. */
717 mark_breakpoint_location_modified (struct bp_location
*loc
)
719 /* This is only meaningful if the target is
720 evaluating conditions and if the user has
721 opted for condition evaluation on the target's
723 if (gdb_evaluates_breakpoint_condition_p ()
724 || !target_supports_evaluation_of_breakpoint_conditions ())
728 if (!is_breakpoint (loc
->owner
))
731 loc
->condition_changed
= condition_modified
;
734 /* Sets the condition-evaluation mode using the static global
735 condition_evaluation_mode. */
738 set_condition_evaluation_mode (const char *args
, int from_tty
,
739 struct cmd_list_element
*c
)
741 const char *old_mode
, *new_mode
;
743 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
744 && !target_supports_evaluation_of_breakpoint_conditions ())
746 condition_evaluation_mode_1
= condition_evaluation_mode
;
747 warning (_("Target does not support breakpoint condition evaluation.\n"
748 "Using host evaluation mode instead."));
752 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
753 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
755 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
756 settings was "auto". */
757 condition_evaluation_mode
= condition_evaluation_mode_1
;
759 /* Only update the mode if the user picked a different one. */
760 if (new_mode
!= old_mode
)
762 /* If the user switched to a different evaluation mode, we
763 need to synch the changes with the target as follows:
765 "host" -> "target": Send all (valid) conditions to the target.
766 "target" -> "host": Remove all the conditions from the target.
769 if (new_mode
== condition_evaluation_target
)
771 /* Mark everything modified and synch conditions with the
773 for (bp_location
*loc
: all_bp_locations ())
774 mark_breakpoint_location_modified (loc
);
778 /* Manually mark non-duplicate locations to synch conditions
779 with the target. We do this to remove all the conditions the
780 target knows about. */
781 for (bp_location
*loc
: all_bp_locations ())
782 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
783 loc
->needs_update
= 1;
787 update_global_location_list (UGLL_MAY_INSERT
);
793 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
794 what "auto" is translating to. */
797 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
798 struct cmd_list_element
*c
, const char *value
)
800 if (condition_evaluation_mode
== condition_evaluation_auto
)
802 _("Breakpoint condition evaluation "
803 "mode is %s (currently %s).\n"),
805 breakpoint_condition_evaluation_mode ());
807 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
811 /* Parse COND_STRING in the context of LOC and set as the condition
812 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
813 the number of LOC within its owner. In case of parsing error, mark
814 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
817 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
818 int bp_num
, int loc_num
)
820 bool has_junk
= false;
823 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
824 block_for_pc (loc
->address
), 0);
825 if (*cond_string
!= 0)
829 loc
->cond
= std::move (new_exp
);
830 if (loc
->disabled_by_cond
&& loc
->enabled
)
831 gdb_printf (_("Breakpoint %d's condition is now valid at "
832 "location %d, enabling.\n"),
835 loc
->disabled_by_cond
= false;
838 catch (const gdb_exception_error
&e
)
842 /* Warn if a user-enabled location is now becoming disabled-by-cond.
843 BP_NUM is 0 if the breakpoint is being defined for the first
844 time using the "break ... if ..." command, and non-zero if
847 warning (_("failed to validate condition at location %d.%d, "
848 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
850 warning (_("failed to validate condition at location %d, "
851 "disabling:\n %s"), loc_num
, e
.what ());
854 loc
->disabled_by_cond
= true;
858 error (_("Garbage '%s' follows condition"), cond_string
);
862 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
863 int from_tty
, bool force
)
867 b
->cond_string
.reset ();
869 if (is_watchpoint (b
))
870 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
874 for (bp_location
*loc
: b
->locations ())
877 if (loc
->disabled_by_cond
&& loc
->enabled
)
878 gdb_printf (_("Breakpoint %d's condition is now valid at "
879 "location %d, enabling.\n"),
881 loc
->disabled_by_cond
= false;
884 /* No need to free the condition agent expression
885 bytecode (if we have one). We will handle this
886 when we go through update_global_location_list. */
891 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
895 if (is_watchpoint (b
))
897 innermost_block_tracker tracker
;
898 const char *arg
= exp
;
899 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
901 error (_("Junk at end of expression"));
902 watchpoint
*w
= static_cast<watchpoint
*> (b
);
903 w
->cond_exp
= std::move (new_exp
);
904 w
->cond_exp_valid_block
= tracker
.block ();
908 /* Parse and set condition expressions. We make two passes.
909 In the first, we parse the condition string to see if it
910 is valid in at least one location. If so, the condition
911 would be accepted. So we go ahead and set the locations'
912 conditions. In case no valid case is found, we throw
913 the error and the condition string will be rejected.
914 This two-pass approach is taken to avoid setting the
915 state of locations in case of a reject. */
916 for (bp_location
*loc
: b
->locations ())
920 const char *arg
= exp
;
921 parse_exp_1 (&arg
, loc
->address
,
922 block_for_pc (loc
->address
), 0);
924 error (_("Junk at end of expression"));
927 catch (const gdb_exception_error
&e
)
929 /* Condition string is invalid. If this happens to
930 be the last loc, abandon (if not forced) or continue
932 if (loc
->next
== nullptr && !force
)
937 /* If we reach here, the condition is valid at some locations. */
939 for (bp_location
*loc
: b
->locations ())
941 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
946 /* We know that the new condition parsed successfully. The
947 condition string of the breakpoint can be safely updated. */
948 b
->cond_string
= make_unique_xstrdup (exp
);
949 b
->condition_not_parsed
= 0;
951 mark_breakpoint_modified (b
);
953 gdb::observers::breakpoint_modified
.notify (b
);
956 /* See breakpoint.h. */
959 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
962 for (breakpoint
*b
: all_breakpoints ())
963 if (b
->number
== bpnum
)
965 /* Check if this breakpoint has a "stop" method implemented in an
966 extension language. This method and conditions entered into GDB
967 from the CLI are mutually exclusive. */
968 const struct extension_language_defn
*extlang
969 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
973 error (_("Only one stop condition allowed. There is currently"
974 " a %s stop condition defined for this breakpoint."),
975 ext_lang_capitalized_name (extlang
));
977 set_breakpoint_condition (b
, exp
, from_tty
, force
);
979 if (is_breakpoint (b
))
980 update_global_location_list (UGLL_MAY_INSERT
);
985 error (_("No breakpoint number %d."), bpnum
);
988 /* The options for the "condition" command. */
990 struct condition_command_opts
993 bool force_condition
= false;
996 static const gdb::option::option_def condition_command_option_defs
[] = {
998 gdb::option::flag_option_def
<condition_command_opts
> {
1000 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1001 N_("Set the condition even if it is invalid for all current locations."),
1006 /* Create an option_def_group for the "condition" options, with
1007 CC_OPTS as context. */
1009 static inline gdb::option::option_def_group
1010 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1012 return {{condition_command_option_defs
}, cc_opts
};
1015 /* Completion for the "condition" command. */
1018 condition_completer (struct cmd_list_element
*cmd
,
1019 completion_tracker
&tracker
,
1020 const char *text
, const char * /*word*/)
1022 bool has_no_arguments
= (*text
== '\0');
1023 condition_command_opts cc_opts
;
1024 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1025 if (gdb::option::complete_options
1026 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1029 text
= skip_spaces (text
);
1030 const char *space
= skip_to_space (text
);
1037 tracker
.advance_custom_word_point_by (1);
1038 /* We don't support completion of history indices. */
1039 if (!isdigit (text
[1]))
1040 complete_internalvar (tracker
, &text
[1]);
1044 /* Suggest the "-force" flag if no arguments are given. If
1045 arguments were passed, they either already include the flag,
1046 or we are beyond the point of suggesting it because it's
1047 positionally the first argument. */
1048 if (has_no_arguments
)
1049 gdb::option::complete_on_all_options (tracker
, group
);
1051 /* We're completing the breakpoint number. */
1052 len
= strlen (text
);
1054 for (breakpoint
*b
: all_breakpoints ())
1058 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1060 if (strncmp (number
, text
, len
) == 0)
1061 tracker
.add_completion (make_unique_xstrdup (number
));
1067 /* We're completing the expression part. Skip the breakpoint num. */
1068 const char *exp_start
= skip_spaces (space
);
1069 tracker
.advance_custom_word_point_by (exp_start
- text
);
1071 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1072 expression_completer (cmd
, tracker
, text
, word
);
1075 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1078 condition_command (const char *arg
, int from_tty
)
1084 error_no_arg (_("breakpoint number"));
1088 /* Check if the "-force" flag was passed. */
1089 condition_command_opts cc_opts
;
1090 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1091 gdb::option::process_options
1092 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1094 bnum
= get_number (&p
);
1096 error (_("Bad breakpoint argument: '%s'"), arg
);
1098 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1101 /* Check that COMMAND do not contain commands that are suitable
1102 only for tracepoints and not suitable for ordinary breakpoints.
1103 Throw if any such commands is found. */
1106 check_no_tracepoint_commands (struct command_line
*commands
)
1108 struct command_line
*c
;
1110 for (c
= commands
; c
; c
= c
->next
)
1112 if (c
->control_type
== while_stepping_control
)
1113 error (_("The 'while-stepping' command can "
1114 "only be used for tracepoints"));
1116 check_no_tracepoint_commands (c
->body_list_0
.get ());
1117 check_no_tracepoint_commands (c
->body_list_1
.get ());
1119 /* Not that command parsing removes leading whitespace and comment
1120 lines and also empty lines. So, we only need to check for
1121 command directly. */
1122 if (strstr (c
->line
, "collect ") == c
->line
)
1123 error (_("The 'collect' command can only be used for tracepoints"));
1125 if (strstr (c
->line
, "teval ") == c
->line
)
1126 error (_("The 'teval' command can only be used for tracepoints"));
1130 struct longjmp_breakpoint
: public breakpoint
1132 ~longjmp_breakpoint () override
;
1135 /* Encapsulate tests for different types of tracepoints. */
1138 is_tracepoint_type (bptype type
)
1140 return (type
== bp_tracepoint
1141 || type
== bp_fast_tracepoint
1142 || type
== bp_static_tracepoint
);
1146 is_longjmp_type (bptype type
)
1148 return type
== bp_longjmp
|| type
== bp_exception
;
1151 /* See breakpoint.h. */
1154 is_tracepoint (const struct breakpoint
*b
)
1156 return is_tracepoint_type (b
->type
);
1159 /* Factory function to create an appropriate instance of breakpoint given
1162 static std::unique_ptr
<breakpoint
>
1163 new_breakpoint_from_type (bptype type
)
1167 if (is_tracepoint_type (type
))
1168 b
= new tracepoint ();
1169 else if (is_longjmp_type (type
))
1170 b
= new longjmp_breakpoint ();
1172 b
= new breakpoint ();
1174 return std::unique_ptr
<breakpoint
> (b
);
1177 /* A helper function that validates that COMMANDS are valid for a
1178 breakpoint. This function will throw an exception if a problem is
1182 validate_commands_for_breakpoint (struct breakpoint
*b
,
1183 struct command_line
*commands
)
1185 if (is_tracepoint (b
))
1187 struct tracepoint
*t
= (struct tracepoint
*) b
;
1188 struct command_line
*c
;
1189 struct command_line
*while_stepping
= 0;
1191 /* Reset the while-stepping step count. The previous commands
1192 might have included a while-stepping action, while the new
1196 /* We need to verify that each top-level element of commands is
1197 valid for tracepoints, that there's at most one
1198 while-stepping element, and that the while-stepping's body
1199 has valid tracing commands excluding nested while-stepping.
1200 We also need to validate the tracepoint action line in the
1201 context of the tracepoint --- validate_actionline actually
1202 has side effects, like setting the tracepoint's
1203 while-stepping STEP_COUNT, in addition to checking if the
1204 collect/teval actions parse and make sense in the
1205 tracepoint's context. */
1206 for (c
= commands
; c
; c
= c
->next
)
1208 if (c
->control_type
== while_stepping_control
)
1210 if (b
->type
== bp_fast_tracepoint
)
1211 error (_("The 'while-stepping' command "
1212 "cannot be used for fast tracepoint"));
1213 else if (b
->type
== bp_static_tracepoint
)
1214 error (_("The 'while-stepping' command "
1215 "cannot be used for static tracepoint"));
1218 error (_("The 'while-stepping' command "
1219 "can be used only once"));
1224 validate_actionline (c
->line
, b
);
1228 struct command_line
*c2
;
1230 gdb_assert (while_stepping
->body_list_1
== nullptr);
1231 c2
= while_stepping
->body_list_0
.get ();
1232 for (; c2
; c2
= c2
->next
)
1234 if (c2
->control_type
== while_stepping_control
)
1235 error (_("The 'while-stepping' command cannot be nested"));
1241 check_no_tracepoint_commands (commands
);
1245 /* Return a vector of all the static tracepoints set at ADDR. The
1246 caller is responsible for releasing the vector. */
1248 std::vector
<breakpoint
*>
1249 static_tracepoints_here (CORE_ADDR addr
)
1251 std::vector
<breakpoint
*> found
;
1253 for (breakpoint
*b
: all_breakpoints ())
1254 if (b
->type
== bp_static_tracepoint
)
1256 for (bp_location
*loc
: b
->locations ())
1257 if (loc
->address
== addr
)
1258 found
.push_back (b
);
1264 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1265 validate that only allowed commands are included. */
1268 breakpoint_set_commands (struct breakpoint
*b
,
1269 counted_command_line
&&commands
)
1271 validate_commands_for_breakpoint (b
, commands
.get ());
1273 b
->commands
= std::move (commands
);
1274 gdb::observers::breakpoint_modified
.notify (b
);
1277 /* Set the internal `silent' flag on the breakpoint. Note that this
1278 is not the same as the "silent" that may appear in the breakpoint's
1282 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1284 int old_silent
= b
->silent
;
1287 if (old_silent
!= silent
)
1288 gdb::observers::breakpoint_modified
.notify (b
);
1291 /* Set the thread for this breakpoint. If THREAD is -1, make the
1292 breakpoint work for any thread. */
1295 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1297 int old_thread
= b
->thread
;
1300 if (old_thread
!= thread
)
1301 gdb::observers::breakpoint_modified
.notify (b
);
1304 /* Set the task for this breakpoint. If TASK is 0, make the
1305 breakpoint work for any task. */
1308 breakpoint_set_task (struct breakpoint
*b
, int task
)
1310 int old_task
= b
->task
;
1313 if (old_task
!= task
)
1314 gdb::observers::breakpoint_modified
.notify (b
);
1318 commands_command_1 (const char *arg
, int from_tty
,
1319 struct command_line
*control
)
1321 counted_command_line cmd
;
1322 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1323 NULL after the call to read_command_lines if the user provides an empty
1324 list of command by just typing "end". */
1325 bool cmd_read
= false;
1327 std::string new_arg
;
1329 if (arg
== NULL
|| !*arg
)
1331 /* Argument not explicitly given. Synthesize it. */
1332 if (breakpoint_count
- prev_breakpoint_count
> 1)
1333 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1335 else if (breakpoint_count
> 0)
1336 new_arg
= string_printf ("%d", breakpoint_count
);
1340 /* Create a copy of ARG. This is needed because the "commands"
1341 command may be coming from a script. In that case, the read
1342 line buffer is going to be overwritten in the lambda of
1343 'map_breakpoint_numbers' below when reading the next line
1344 before we are are done parsing the breakpoint numbers. */
1347 arg
= new_arg
.c_str ();
1349 map_breakpoint_numbers
1350 (arg
, [&] (breakpoint
*b
)
1354 gdb_assert (cmd
== NULL
);
1355 if (control
!= NULL
)
1356 cmd
= control
->body_list_0
;
1360 = string_printf (_("Type commands for breakpoint(s) "
1361 "%s, one per line."),
1364 auto do_validate
= [=] (const char *line
)
1366 validate_actionline (line
, b
);
1368 gdb::function_view
<void (const char *)> validator
;
1369 if (is_tracepoint (b
))
1370 validator
= do_validate
;
1372 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1377 /* If a breakpoint was on the list more than once, we don't need to
1379 if (b
->commands
!= cmd
)
1381 validate_commands_for_breakpoint (b
, cmd
.get ());
1383 gdb::observers::breakpoint_modified
.notify (b
);
1389 commands_command (const char *arg
, int from_tty
)
1391 commands_command_1 (arg
, from_tty
, NULL
);
1394 /* Like commands_command, but instead of reading the commands from
1395 input stream, takes them from an already parsed command structure.
1397 This is used by cli-script.c to DTRT with breakpoint commands
1398 that are part of if and while bodies. */
1399 enum command_control_type
1400 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1402 commands_command_1 (arg
, 0, cmd
);
1403 return simple_control
;
1406 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1409 bp_location_has_shadow (struct bp_location
*bl
)
1411 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1415 if (bl
->target_info
.shadow_len
== 0)
1416 /* BL isn't valid, or doesn't shadow memory. */
1421 /* Update BUF, which is LEN bytes read from the target address
1422 MEMADDR, by replacing a memory breakpoint with its shadowed
1425 If READBUF is not NULL, this buffer must not overlap with the of
1426 the breakpoint location's shadow_contents buffer. Otherwise, a
1427 failed assertion internal error will be raised. */
1430 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1431 const gdb_byte
*writebuf_org
,
1432 ULONGEST memaddr
, LONGEST len
,
1433 struct bp_target_info
*target_info
,
1434 struct gdbarch
*gdbarch
)
1436 /* Now do full processing of the found relevant range of elements. */
1437 CORE_ADDR bp_addr
= 0;
1441 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1442 current_program_space
->aspace
, 0))
1444 /* The breakpoint is inserted in a different address space. */
1448 /* Addresses and length of the part of the breakpoint that
1450 bp_addr
= target_info
->placed_address
;
1451 bp_size
= target_info
->shadow_len
;
1453 if (bp_addr
+ bp_size
<= memaddr
)
1455 /* The breakpoint is entirely before the chunk of memory we are
1460 if (bp_addr
>= memaddr
+ len
)
1462 /* The breakpoint is entirely after the chunk of memory we are
1467 /* Offset within shadow_contents. */
1468 if (bp_addr
< memaddr
)
1470 /* Only copy the second part of the breakpoint. */
1471 bp_size
-= memaddr
- bp_addr
;
1472 bptoffset
= memaddr
- bp_addr
;
1476 if (bp_addr
+ bp_size
> memaddr
+ len
)
1478 /* Only copy the first part of the breakpoint. */
1479 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1482 if (readbuf
!= NULL
)
1484 /* Verify that the readbuf buffer does not overlap with the
1485 shadow_contents buffer. */
1486 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1487 || readbuf
>= (target_info
->shadow_contents
1488 + target_info
->shadow_len
));
1490 /* Update the read buffer with this inserted breakpoint's
1492 memcpy (readbuf
+ bp_addr
- memaddr
,
1493 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1497 const unsigned char *bp
;
1498 CORE_ADDR addr
= target_info
->reqstd_address
;
1501 /* Update the shadow with what we want to write to memory. */
1502 memcpy (target_info
->shadow_contents
+ bptoffset
,
1503 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1505 /* Determine appropriate breakpoint contents and size for this
1507 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1509 /* Update the final write buffer with this inserted
1510 breakpoint's INSN. */
1511 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1515 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1516 by replacing any memory breakpoints with their shadowed contents.
1518 If READBUF is not NULL, this buffer must not overlap with any of
1519 the breakpoint location's shadow_contents buffers. Otherwise,
1520 a failed assertion internal error will be raised.
1522 The range of shadowed area by each bp_location is:
1523 bl->address - bp_locations_placed_address_before_address_max
1524 up to bl->address + bp_locations_shadow_len_after_address_max
1525 The range we were requested to resolve shadows for is:
1526 memaddr ... memaddr + len
1527 Thus the safe cutoff boundaries for performance optimization are
1528 memaddr + len <= (bl->address
1529 - bp_locations_placed_address_before_address_max)
1531 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1534 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1535 const gdb_byte
*writebuf_org
,
1536 ULONGEST memaddr
, LONGEST len
)
1538 /* Left boundary, right boundary and median element of our binary
1540 unsigned bc_l
, bc_r
, bc
;
1542 /* Find BC_L which is a leftmost element which may affect BUF
1543 content. It is safe to report lower value but a failure to
1544 report higher one. */
1547 bc_r
= bp_locations
.size ();
1548 while (bc_l
+ 1 < bc_r
)
1550 struct bp_location
*bl
;
1552 bc
= (bc_l
+ bc_r
) / 2;
1553 bl
= bp_locations
[bc
];
1555 /* Check first BL->ADDRESS will not overflow due to the added
1556 constant. Then advance the left boundary only if we are sure
1557 the BC element can in no way affect the BUF content (MEMADDR
1558 to MEMADDR + LEN range).
1560 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1561 offset so that we cannot miss a breakpoint with its shadow
1562 range tail still reaching MEMADDR. */
1564 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1566 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1573 /* Due to the binary search above, we need to make sure we pick the
1574 first location that's at BC_L's address. E.g., if there are
1575 multiple locations at the same address, BC_L may end up pointing
1576 at a duplicate location, and miss the "master"/"inserted"
1577 location. Say, given locations L1, L2 and L3 at addresses A and
1580 L1@A, L2@A, L3@B, ...
1582 BC_L could end up pointing at location L2, while the "master"
1583 location could be L1. Since the `loc->inserted' flag is only set
1584 on "master" locations, we'd forget to restore the shadow of L1
1587 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1590 /* Now do full processing of the found relevant range of elements. */
1592 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1594 struct bp_location
*bl
= bp_locations
[bc
];
1596 /* bp_location array has BL->OWNER always non-NULL. */
1597 if (bl
->owner
->type
== bp_none
)
1598 warning (_("reading through apparently deleted breakpoint #%d?"),
1601 /* Performance optimization: any further element can no longer affect BUF
1604 if (bl
->address
>= bp_locations_placed_address_before_address_max
1607 - bp_locations_placed_address_before_address_max
)))
1610 if (!bp_location_has_shadow (bl
))
1613 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1614 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1618 /* See breakpoint.h. */
1621 is_breakpoint (const struct breakpoint
*bpt
)
1623 return (bpt
->type
== bp_breakpoint
1624 || bpt
->type
== bp_hardware_breakpoint
1625 || bpt
->type
== bp_dprintf
);
1628 /* Return true if BPT is of any hardware watchpoint kind. */
1631 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1633 return (bpt
->type
== bp_hardware_watchpoint
1634 || bpt
->type
== bp_read_watchpoint
1635 || bpt
->type
== bp_access_watchpoint
);
1638 /* See breakpoint.h. */
1641 is_watchpoint (const struct breakpoint
*bpt
)
1643 return (is_hardware_watchpoint (bpt
)
1644 || bpt
->type
== bp_watchpoint
);
1647 /* Returns true if the current thread and its running state are safe
1648 to evaluate or update watchpoint B. Watchpoints on local
1649 expressions need to be evaluated in the context of the thread that
1650 was current when the watchpoint was created, and, that thread needs
1651 to be stopped to be able to select the correct frame context.
1652 Watchpoints on global expressions can be evaluated on any thread,
1653 and in any state. It is presently left to the target allowing
1654 memory accesses when threads are running. */
1657 watchpoint_in_thread_scope (struct watchpoint
*b
)
1659 return (b
->pspace
== current_program_space
1660 && (b
->watchpoint_thread
== null_ptid
1661 || (inferior_ptid
== b
->watchpoint_thread
1662 && !inferior_thread ()->executing ())));
1665 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1666 associated bp_watchpoint_scope breakpoint. */
1669 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1671 if (w
->related_breakpoint
!= w
)
1673 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1674 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1675 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1676 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1677 w
->related_breakpoint
= w
;
1679 w
->disposition
= disp_del_at_next_stop
;
1682 /* Extract a bitfield value from value VAL using the bit parameters contained in
1685 static struct value
*
1686 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1688 struct value
*bit_val
;
1693 bit_val
= allocate_value (value_type (val
));
1695 unpack_value_bitfield (bit_val
,
1698 value_contents_for_printing (val
).data (),
1705 /* Allocate a dummy location and add it to B, which must be a software
1706 watchpoint. This is required because even if a software watchpoint
1707 is not watching any memory, bpstat_stop_status requires a location
1708 to be able to report stops. */
1711 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1712 struct program_space
*pspace
)
1714 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1716 b
->loc
= allocate_bp_location (b
);
1717 b
->loc
->pspace
= pspace
;
1718 b
->loc
->address
= -1;
1719 b
->loc
->length
= -1;
1722 /* Returns true if B is a software watchpoint that is not watching any
1723 memory (e.g., "watch $pc"). */
1726 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1728 return (b
->type
== bp_watchpoint
1730 && b
->loc
->next
== NULL
1731 && b
->loc
->address
== -1
1732 && b
->loc
->length
== -1);
1735 /* Assuming that B is a watchpoint:
1736 - Reparse watchpoint expression, if REPARSE is non-zero
1737 - Evaluate expression and store the result in B->val
1738 - Evaluate the condition if there is one, and store the result
1740 - Update the list of values that must be watched in B->loc.
1742 If the watchpoint disposition is disp_del_at_next_stop, then do
1743 nothing. If this is local watchpoint that is out of scope, delete
1746 Even with `set breakpoint always-inserted on' the watchpoints are
1747 removed + inserted on each stop here. Normal breakpoints must
1748 never be removed because they might be missed by a running thread
1749 when debugging in non-stop mode. On the other hand, hardware
1750 watchpoints (is_hardware_watchpoint; processed here) are specific
1751 to each LWP since they are stored in each LWP's hardware debug
1752 registers. Therefore, such LWP must be stopped first in order to
1753 be able to modify its hardware watchpoints.
1755 Hardware watchpoints must be reset exactly once after being
1756 presented to the user. It cannot be done sooner, because it would
1757 reset the data used to present the watchpoint hit to the user. And
1758 it must not be done later because it could display the same single
1759 watchpoint hit during multiple GDB stops. Note that the latter is
1760 relevant only to the hardware watchpoint types bp_read_watchpoint
1761 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1762 not user-visible - its hit is suppressed if the memory content has
1765 The following constraints influence the location where we can reset
1766 hardware watchpoints:
1768 * target_stopped_by_watchpoint and target_stopped_data_address are
1769 called several times when GDB stops.
1772 * Multiple hardware watchpoints can be hit at the same time,
1773 causing GDB to stop. GDB only presents one hardware watchpoint
1774 hit at a time as the reason for stopping, and all the other hits
1775 are presented later, one after the other, each time the user
1776 requests the execution to be resumed. Execution is not resumed
1777 for the threads still having pending hit event stored in
1778 LWP_INFO->STATUS. While the watchpoint is already removed from
1779 the inferior on the first stop the thread hit event is kept being
1780 reported from its cached value by linux_nat_stopped_data_address
1781 until the real thread resume happens after the watchpoint gets
1782 presented and thus its LWP_INFO->STATUS gets reset.
1784 Therefore the hardware watchpoint hit can get safely reset on the
1785 watchpoint removal from inferior. */
1788 update_watchpoint (struct watchpoint
*b
, int reparse
)
1790 int within_current_scope
;
1791 struct frame_id saved_frame_id
;
1794 /* If this is a local watchpoint, we only want to check if the
1795 watchpoint frame is in scope if the current thread is the thread
1796 that was used to create the watchpoint. */
1797 if (!watchpoint_in_thread_scope (b
))
1800 if (b
->disposition
== disp_del_at_next_stop
)
1805 /* Determine if the watchpoint is within scope. */
1806 if (b
->exp_valid_block
== NULL
)
1807 within_current_scope
= 1;
1810 struct frame_info
*fi
= get_current_frame ();
1811 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1812 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1814 /* If we're at a point where the stack has been destroyed
1815 (e.g. in a function epilogue), unwinding may not work
1816 properly. Do not attempt to recreate locations at this
1817 point. See similar comments in watchpoint_check. */
1818 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1821 /* Save the current frame's ID so we can restore it after
1822 evaluating the watchpoint expression on its own frame. */
1823 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1824 took a frame parameter, so that we didn't have to change the
1827 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1829 fi
= frame_find_by_id (b
->watchpoint_frame
);
1830 within_current_scope
= (fi
!= NULL
);
1831 if (within_current_scope
)
1835 /* We don't free locations. They are stored in the bp_location array
1836 and update_global_location_list will eventually delete them and
1837 remove breakpoints if needed. */
1840 if (within_current_scope
&& reparse
)
1845 s
= (b
->exp_string_reparse
1846 ? b
->exp_string_reparse
.get ()
1847 : b
->exp_string
.get ());
1848 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1849 /* If the meaning of expression itself changed, the old value is
1850 no longer relevant. We don't want to report a watchpoint hit
1851 to the user when the old value and the new value may actually
1852 be completely different objects. */
1854 b
->val_valid
= false;
1856 /* Note that unlike with breakpoints, the watchpoint's condition
1857 expression is stored in the breakpoint object, not in the
1858 locations (re)created below. */
1859 if (b
->cond_string
!= NULL
)
1861 b
->cond_exp
.reset ();
1863 s
= b
->cond_string
.get ();
1864 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1868 /* If we failed to parse the expression, for example because
1869 it refers to a global variable in a not-yet-loaded shared library,
1870 don't try to insert watchpoint. We don't automatically delete
1871 such watchpoint, though, since failure to parse expression
1872 is different from out-of-scope watchpoint. */
1873 if (!target_has_execution ())
1875 /* Without execution, memory can't change. No use to try and
1876 set watchpoint locations. The watchpoint will be reset when
1877 the target gains execution, through breakpoint_re_set. */
1878 if (!can_use_hw_watchpoints
)
1880 if (b
->ops
->works_in_software_mode (b
))
1881 b
->type
= bp_watchpoint
;
1883 error (_("Can't set read/access watchpoint when "
1884 "hardware watchpoints are disabled."));
1887 else if (within_current_scope
&& b
->exp
)
1889 std::vector
<value_ref_ptr
> val_chain
;
1890 struct value
*v
, *result
;
1891 struct program_space
*frame_pspace
;
1893 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1896 /* Avoid setting b->val if it's already set. The meaning of
1897 b->val is 'the last value' user saw, and we should update
1898 it only if we reported that last value to user. As it
1899 happens, the code that reports it updates b->val directly.
1900 We don't keep track of the memory value for masked
1902 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1904 if (b
->val_bitsize
!= 0)
1905 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1906 b
->val
= release_value (v
);
1907 b
->val_valid
= true;
1910 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1912 /* Look at each value on the value chain. */
1913 gdb_assert (!val_chain
.empty ());
1914 for (const value_ref_ptr
&iter
: val_chain
)
1918 /* If it's a memory location, and GDB actually needed
1919 its contents to evaluate the expression, then we
1920 must watch it. If the first value returned is
1921 still lazy, that means an error occurred reading it;
1922 watch it anyway in case it becomes readable. */
1923 if (VALUE_LVAL (v
) == lval_memory
1924 && (v
== val_chain
[0] || ! value_lazy (v
)))
1926 struct type
*vtype
= check_typedef (value_type (v
));
1928 /* We only watch structs and arrays if user asked
1929 for it explicitly, never if they just happen to
1930 appear in the middle of some value chain. */
1932 || (vtype
->code () != TYPE_CODE_STRUCT
1933 && vtype
->code () != TYPE_CODE_ARRAY
))
1936 enum target_hw_bp_type type
;
1937 struct bp_location
*loc
, **tmp
;
1938 int bitpos
= 0, bitsize
= 0;
1940 if (value_bitsize (v
) != 0)
1942 /* Extract the bit parameters out from the bitfield
1944 bitpos
= value_bitpos (v
);
1945 bitsize
= value_bitsize (v
);
1947 else if (v
== result
&& b
->val_bitsize
!= 0)
1949 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1950 lvalue whose bit parameters are saved in the fields
1951 VAL_BITPOS and VAL_BITSIZE. */
1952 bitpos
= b
->val_bitpos
;
1953 bitsize
= b
->val_bitsize
;
1956 addr
= value_address (v
);
1959 /* Skip the bytes that don't contain the bitfield. */
1964 if (b
->type
== bp_read_watchpoint
)
1966 else if (b
->type
== bp_access_watchpoint
)
1969 loc
= allocate_bp_location (b
);
1970 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1973 loc
->gdbarch
= value_type (v
)->arch ();
1975 loc
->pspace
= frame_pspace
;
1976 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1980 /* Just cover the bytes that make up the bitfield. */
1981 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1984 loc
->length
= TYPE_LENGTH (value_type (v
));
1986 loc
->watchpoint_type
= type
;
1991 /* Change the type of breakpoint between hardware assisted or
1992 an ordinary watchpoint depending on the hardware support
1993 and free hardware slots. REPARSE is set when the inferior
1998 enum bp_loc_type loc_type
;
2000 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2004 int i
, target_resources_ok
, other_type_used
;
2007 /* Use an exact watchpoint when there's only one memory region to be
2008 watched, and only one debug register is needed to watch it. */
2009 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2011 /* We need to determine how many resources are already
2012 used for all other hardware watchpoints plus this one
2013 to see if we still have enough resources to also fit
2014 this watchpoint in as well. */
2016 /* If this is a software watchpoint, we try to turn it
2017 to a hardware one -- count resources as if B was of
2018 hardware watchpoint type. */
2020 if (type
== bp_watchpoint
)
2021 type
= bp_hardware_watchpoint
;
2023 /* This watchpoint may or may not have been placed on
2024 the list yet at this point (it won't be in the list
2025 if we're trying to create it for the first time,
2026 through watch_command), so always account for it
2029 /* Count resources used by all watchpoints except B. */
2030 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2032 /* Add in the resources needed for B. */
2033 i
+= hw_watchpoint_use_count (b
);
2036 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2037 if (target_resources_ok
<= 0)
2039 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2041 if (target_resources_ok
== 0 && !sw_mode
)
2042 error (_("Target does not support this type of "
2043 "hardware watchpoint."));
2044 else if (target_resources_ok
< 0 && !sw_mode
)
2045 error (_("There are not enough available hardware "
2046 "resources for this watchpoint."));
2048 /* Downgrade to software watchpoint. */
2049 b
->type
= bp_watchpoint
;
2053 /* If this was a software watchpoint, we've just
2054 found we have enough resources to turn it to a
2055 hardware watchpoint. Otherwise, this is a
2060 else if (!b
->ops
->works_in_software_mode (b
))
2062 if (!can_use_hw_watchpoints
)
2063 error (_("Can't set read/access watchpoint when "
2064 "hardware watchpoints are disabled."));
2066 error (_("Expression cannot be implemented with "
2067 "read/access watchpoint."));
2070 b
->type
= bp_watchpoint
;
2072 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2073 : bp_loc_hardware_watchpoint
);
2074 for (bp_location
*bl
: b
->locations ())
2075 bl
->loc_type
= loc_type
;
2078 /* If a software watchpoint is not watching any memory, then the
2079 above left it without any location set up. But,
2080 bpstat_stop_status requires a location to be able to report
2081 stops, so make sure there's at least a dummy one. */
2082 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2083 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2085 else if (!within_current_scope
)
2088 Watchpoint %d deleted because the program has left the block\n\
2089 in which its expression is valid.\n"),
2091 watchpoint_del_at_next_stop (b
);
2094 /* Restore the selected frame. */
2096 select_frame (frame_find_by_id (saved_frame_id
));
2100 /* Returns 1 iff breakpoint location should be
2101 inserted in the inferior. We don't differentiate the type of BL's owner
2102 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2103 breakpoint_ops is not defined, because in insert_bp_location,
2104 tracepoint's insert_location will not be called. */
2106 should_be_inserted (struct bp_location
*bl
)
2108 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2111 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2114 if (!bl
->enabled
|| bl
->disabled_by_cond
2115 || bl
->shlib_disabled
|| bl
->duplicate
)
2118 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2121 /* This is set for example, when we're attached to the parent of a
2122 vfork, and have detached from the child. The child is running
2123 free, and we expect it to do an exec or exit, at which point the
2124 OS makes the parent schedulable again (and the target reports
2125 that the vfork is done). Until the child is done with the shared
2126 memory region, do not insert breakpoints in the parent, otherwise
2127 the child could still trip on the parent's breakpoints. Since
2128 the parent is blocked anyway, it won't miss any breakpoint. */
2129 if (bl
->pspace
->breakpoints_not_allowed
)
2132 /* Don't insert a breakpoint if we're trying to step past its
2133 location, except if the breakpoint is a single-step breakpoint,
2134 and the breakpoint's thread is the thread which is stepping past
2136 if ((bl
->loc_type
== bp_loc_software_breakpoint
2137 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2138 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2140 /* The single-step breakpoint may be inserted at the location
2141 we're trying to step if the instruction branches to itself.
2142 However, the instruction won't be executed at all and it may
2143 break the semantics of the instruction, for example, the
2144 instruction is a conditional branch or updates some flags.
2145 We can't fix it unless GDB is able to emulate the instruction
2146 or switch to displaced stepping. */
2147 && !(bl
->owner
->type
== bp_single_step
2148 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2150 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2151 paddress (bl
->gdbarch
, bl
->address
));
2155 /* Don't insert watchpoints if we're trying to step past the
2156 instruction that triggered one. */
2157 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2158 && stepping_past_nonsteppable_watchpoint ())
2160 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2161 "skipping watchpoint at %s:%d",
2162 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2169 /* Same as should_be_inserted but does the check assuming
2170 that the location is not duplicated. */
2173 unduplicated_should_be_inserted (struct bp_location
*bl
)
2176 const int save_duplicate
= bl
->duplicate
;
2179 result
= should_be_inserted (bl
);
2180 bl
->duplicate
= save_duplicate
;
2184 /* Parses a conditional described by an expression COND into an
2185 agent expression bytecode suitable for evaluation
2186 by the bytecode interpreter. Return NULL if there was
2187 any error during parsing. */
2189 static agent_expr_up
2190 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2195 agent_expr_up aexpr
;
2197 /* We don't want to stop processing, so catch any errors
2198 that may show up. */
2201 aexpr
= gen_eval_for_expr (scope
, cond
);
2204 catch (const gdb_exception_error
&ex
)
2206 /* If we got here, it means the condition could not be parsed to a valid
2207 bytecode expression and thus can't be evaluated on the target's side.
2208 It's no use iterating through the conditions. */
2211 /* We have a valid agent expression. */
2215 /* Based on location BL, create a list of breakpoint conditions to be
2216 passed on to the target. If we have duplicated locations with different
2217 conditions, we will add such conditions to the list. The idea is that the
2218 target will evaluate the list of conditions and will only notify GDB when
2219 one of them is true. */
2222 build_target_condition_list (struct bp_location
*bl
)
2224 int null_condition_or_parse_error
= 0;
2225 int modified
= bl
->needs_update
;
2227 /* Release conditions left over from a previous insert. */
2228 bl
->target_info
.conditions
.clear ();
2230 /* This is only meaningful if the target is
2231 evaluating conditions and if the user has
2232 opted for condition evaluation on the target's
2234 if (gdb_evaluates_breakpoint_condition_p ()
2235 || !target_supports_evaluation_of_breakpoint_conditions ())
2238 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2240 /* Do a first pass to check for locations with no assigned
2241 conditions or conditions that fail to parse to a valid agent
2242 expression bytecode. If any of these happen, then it's no use to
2243 send conditions to the target since this location will always
2244 trigger and generate a response back to GDB. Note we consider
2245 all locations at the same address irrespective of type, i.e.,
2246 even if the locations aren't considered duplicates (e.g.,
2247 software breakpoint and hardware breakpoint at the same
2249 for (bp_location
*loc
: loc_range
)
2251 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2255 /* Re-parse the conditions since something changed. In that
2256 case we already freed the condition bytecodes (see
2257 force_breakpoint_reinsertion). We just
2258 need to parse the condition to bytecodes again. */
2259 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2263 /* If we have a NULL bytecode expression, it means something
2264 went wrong or we have a null condition expression. */
2265 if (!loc
->cond_bytecode
)
2267 null_condition_or_parse_error
= 1;
2273 /* If any of these happened, it means we will have to evaluate the conditions
2274 for the location's address on gdb's side. It is no use keeping bytecodes
2275 for all the other duplicate locations, thus we free all of them here.
2277 This is so we have a finer control over which locations' conditions are
2278 being evaluated by GDB or the remote stub. */
2279 if (null_condition_or_parse_error
)
2281 for (bp_location
*loc
: loc_range
)
2283 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2285 /* Only go as far as the first NULL bytecode is
2287 if (!loc
->cond_bytecode
)
2290 loc
->cond_bytecode
.reset ();
2295 /* No NULL conditions or failed bytecode generation. Build a
2296 condition list for this location's address. If we have software
2297 and hardware locations at the same address, they aren't
2298 considered duplicates, but we still marge all the conditions
2299 anyway, as it's simpler, and doesn't really make a practical
2301 for (bp_location
*loc
: loc_range
)
2303 && is_breakpoint (loc
->owner
)
2304 && loc
->pspace
->num
== bl
->pspace
->num
2305 && loc
->owner
->enable_state
== bp_enabled
2307 && !loc
->disabled_by_cond
)
2309 /* Add the condition to the vector. This will be used later
2310 to send the conditions to the target. */
2311 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2317 /* Parses a command described by string CMD into an agent expression
2318 bytecode suitable for evaluation by the bytecode interpreter.
2319 Return NULL if there was any error during parsing. */
2321 static agent_expr_up
2322 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2324 const char *cmdrest
;
2325 const char *format_start
, *format_end
;
2326 struct gdbarch
*gdbarch
= get_current_arch ();
2333 if (*cmdrest
== ',')
2335 cmdrest
= skip_spaces (cmdrest
);
2337 if (*cmdrest
++ != '"')
2338 error (_("No format string following the location"));
2340 format_start
= cmdrest
;
2342 format_pieces
fpieces (&cmdrest
);
2344 format_end
= cmdrest
;
2346 if (*cmdrest
++ != '"')
2347 error (_("Bad format string, non-terminated '\"'."));
2349 cmdrest
= skip_spaces (cmdrest
);
2351 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2352 error (_("Invalid argument syntax"));
2354 if (*cmdrest
== ',')
2356 cmdrest
= skip_spaces (cmdrest
);
2358 /* For each argument, make an expression. */
2360 std::vector
<struct expression
*> argvec
;
2361 while (*cmdrest
!= '\0')
2366 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2367 argvec
.push_back (expr
.release ());
2369 if (*cmdrest
== ',')
2373 agent_expr_up aexpr
;
2375 /* We don't want to stop processing, so catch any errors
2376 that may show up. */
2379 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2380 format_start
, format_end
- format_start
,
2381 argvec
.size (), argvec
.data ());
2383 catch (const gdb_exception_error
&ex
)
2385 /* If we got here, it means the command could not be parsed to a valid
2386 bytecode expression and thus can't be evaluated on the target's side.
2387 It's no use iterating through the other commands. */
2390 /* We have a valid agent expression, return it. */
2394 /* Based on location BL, create a list of breakpoint commands to be
2395 passed on to the target. If we have duplicated locations with
2396 different commands, we will add any such to the list. */
2399 build_target_command_list (struct bp_location
*bl
)
2401 int null_command_or_parse_error
= 0;
2402 int modified
= bl
->needs_update
;
2404 /* Clear commands left over from a previous insert. */
2405 bl
->target_info
.tcommands
.clear ();
2407 if (!target_can_run_breakpoint_commands ())
2410 /* For now, limit to agent-style dprintf breakpoints. */
2411 if (dprintf_style
!= dprintf_style_agent
)
2414 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2416 /* For now, if we have any location at the same address that isn't a
2417 dprintf, don't install the target-side commands, as that would
2418 make the breakpoint not be reported to the core, and we'd lose
2420 for (bp_location
*loc
: loc_range
)
2421 if (is_breakpoint (loc
->owner
)
2422 && loc
->pspace
->num
== bl
->pspace
->num
2423 && loc
->owner
->type
!= bp_dprintf
)
2426 /* Do a first pass to check for locations with no assigned
2427 conditions or conditions that fail to parse to a valid agent expression
2428 bytecode. If any of these happen, then it's no use to send conditions
2429 to the target since this location will always trigger and generate a
2430 response back to GDB. */
2431 for (bp_location
*loc
: loc_range
)
2433 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2437 /* Re-parse the commands since something changed. In that
2438 case we already freed the command bytecodes (see
2439 force_breakpoint_reinsertion). We just
2440 need to parse the command to bytecodes again. */
2442 = parse_cmd_to_aexpr (bl
->address
,
2443 loc
->owner
->extra_string
.get ());
2446 /* If we have a NULL bytecode expression, it means something
2447 went wrong or we have a null command expression. */
2448 if (!loc
->cmd_bytecode
)
2450 null_command_or_parse_error
= 1;
2456 /* If anything failed, then we're not doing target-side commands,
2458 if (null_command_or_parse_error
)
2460 for (bp_location
*loc
: loc_range
)
2461 if (is_breakpoint (loc
->owner
)
2462 && loc
->pspace
->num
== bl
->pspace
->num
)
2464 /* Only go as far as the first NULL bytecode is
2466 if (loc
->cmd_bytecode
== NULL
)
2469 loc
->cmd_bytecode
.reset ();
2473 /* No NULL commands or failed bytecode generation. Build a command
2474 list for all duplicate locations at this location's address.
2475 Note that here we must care for whether the breakpoint location
2476 types are considered duplicates, otherwise, say, if we have a
2477 software and hardware location at the same address, the target
2478 could end up running the commands twice. For the moment, we only
2479 support targets-side commands with dprintf, but it doesn't hurt
2480 to be pedantically correct in case that changes. */
2481 for (bp_location
*loc
: loc_range
)
2482 if (breakpoint_locations_match (bl
, loc
)
2483 && loc
->owner
->extra_string
2484 && is_breakpoint (loc
->owner
)
2485 && loc
->pspace
->num
== bl
->pspace
->num
2486 && loc
->owner
->enable_state
== bp_enabled
2488 && !loc
->disabled_by_cond
)
2490 /* Add the command to the vector. This will be used later
2491 to send the commands to the target. */
2492 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2495 bl
->target_info
.persist
= 0;
2496 /* Maybe flag this location as persistent. */
2497 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2498 bl
->target_info
.persist
= 1;
2501 /* Return the kind of breakpoint on address *ADDR. Get the kind
2502 of breakpoint according to ADDR except single-step breakpoint.
2503 Get the kind of single-step breakpoint according to the current
2507 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2509 if (bl
->owner
->type
== bp_single_step
)
2511 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2512 struct regcache
*regcache
;
2514 regcache
= get_thread_regcache (thr
);
2516 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2520 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2523 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2524 location. Any error messages are printed to TMP_ERROR_STREAM; and
2525 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2526 Returns 0 for success, 1 if the bp_location type is not supported or
2529 NOTE drow/2003-09-09: This routine could be broken down to an
2530 object-style method for each breakpoint or catchpoint type. */
2532 insert_bp_location (struct bp_location
*bl
,
2533 struct ui_file
*tmp_error_stream
,
2534 int *disabled_breaks
,
2535 int *hw_breakpoint_error
,
2536 int *hw_bp_error_explained_already
)
2538 gdb_exception bp_excpt
;
2540 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2543 /* Note we don't initialize bl->target_info, as that wipes out
2544 the breakpoint location's shadow_contents if the breakpoint
2545 is still inserted at that location. This in turn breaks
2546 target_read_memory which depends on these buffers when
2547 a memory read is requested at the breakpoint location:
2548 Once the target_info has been wiped, we fail to see that
2549 we have a breakpoint inserted at that address and thus
2550 read the breakpoint instead of returning the data saved in
2551 the breakpoint location's shadow contents. */
2552 bl
->target_info
.reqstd_address
= bl
->address
;
2553 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2554 bl
->target_info
.length
= bl
->length
;
2556 /* When working with target-side conditions, we must pass all the conditions
2557 for the same breakpoint address down to the target since GDB will not
2558 insert those locations. With a list of breakpoint conditions, the target
2559 can decide when to stop and notify GDB. */
2561 if (is_breakpoint (bl
->owner
))
2563 build_target_condition_list (bl
);
2564 build_target_command_list (bl
);
2565 /* Reset the modification marker. */
2566 bl
->needs_update
= 0;
2569 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2570 set at a read-only address, then a breakpoint location will have
2571 been changed to hardware breakpoint before we get here. If it is
2572 "off" however, error out before actually trying to insert the
2573 breakpoint, with a nicer error message. */
2574 if (bl
->loc_type
== bp_loc_software_breakpoint
2575 && !automatic_hardware_breakpoints
)
2577 mem_region
*mr
= lookup_mem_region (bl
->address
);
2579 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2581 gdb_printf (tmp_error_stream
,
2582 _("Cannot insert breakpoint %d.\n"
2583 "Cannot set software breakpoint "
2584 "at read-only address %s\n"),
2586 paddress (bl
->gdbarch
, bl
->address
));
2591 if (bl
->loc_type
== bp_loc_software_breakpoint
2592 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2594 /* First check to see if we have to handle an overlay. */
2595 if (overlay_debugging
== ovly_off
2596 || bl
->section
== NULL
2597 || !(section_is_overlay (bl
->section
)))
2599 /* No overlay handling: just set the breakpoint. */
2604 val
= bl
->owner
->ops
->insert_location (bl
);
2606 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2608 catch (gdb_exception
&e
)
2610 bp_excpt
= std::move (e
);
2615 /* This breakpoint is in an overlay section.
2616 Shall we set a breakpoint at the LMA? */
2617 if (!overlay_events_enabled
)
2619 /* Yes -- overlay event support is not active,
2620 so we must try to set a breakpoint at the LMA.
2621 This will not work for a hardware breakpoint. */
2622 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2623 warning (_("hardware breakpoint %d not supported in overlay!"),
2627 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2629 /* Set a software (trap) breakpoint at the LMA. */
2630 bl
->overlay_target_info
= bl
->target_info
;
2631 bl
->overlay_target_info
.reqstd_address
= addr
;
2633 /* No overlay handling: just set the breakpoint. */
2638 bl
->overlay_target_info
.kind
2639 = breakpoint_kind (bl
, &addr
);
2640 bl
->overlay_target_info
.placed_address
= addr
;
2641 val
= target_insert_breakpoint (bl
->gdbarch
,
2642 &bl
->overlay_target_info
);
2645 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2647 catch (gdb_exception
&e
)
2649 bp_excpt
= std::move (e
);
2652 if (bp_excpt
.reason
!= 0)
2653 gdb_printf (tmp_error_stream
,
2654 "Overlay breakpoint %d "
2655 "failed: in ROM?\n",
2659 /* Shall we set a breakpoint at the VMA? */
2660 if (section_is_mapped (bl
->section
))
2662 /* Yes. This overlay section is mapped into memory. */
2667 val
= bl
->owner
->ops
->insert_location (bl
);
2669 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2671 catch (gdb_exception
&e
)
2673 bp_excpt
= std::move (e
);
2678 /* No. This breakpoint will not be inserted.
2679 No error, but do not mark the bp as 'inserted'. */
2684 if (bp_excpt
.reason
!= 0)
2686 /* Can't set the breakpoint. */
2688 /* If the target has closed then it will have deleted any
2689 breakpoints inserted within the target inferior, as a result
2690 any further attempts to interact with the breakpoint objects
2691 is not possible. Just rethrow the error. */
2692 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2694 gdb_assert (bl
->owner
!= nullptr);
2696 /* In some cases, we might not be able to insert a
2697 breakpoint in a shared library that has already been
2698 removed, but we have not yet processed the shlib unload
2699 event. Unfortunately, some targets that implement
2700 breakpoint insertion themselves can't tell why the
2701 breakpoint insertion failed (e.g., the remote target
2702 doesn't define error codes), so we must treat generic
2703 errors as memory errors. */
2704 if (bp_excpt
.reason
== RETURN_ERROR
2705 && (bp_excpt
.error
== GENERIC_ERROR
2706 || bp_excpt
.error
== MEMORY_ERROR
)
2707 && bl
->loc_type
== bp_loc_software_breakpoint
2708 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2709 || shared_objfile_contains_address_p (bl
->pspace
,
2712 /* See also: disable_breakpoints_in_shlibs. */
2713 bl
->shlib_disabled
= 1;
2714 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2715 if (!*disabled_breaks
)
2717 gdb_printf (tmp_error_stream
,
2718 "Cannot insert breakpoint %d.\n",
2720 gdb_printf (tmp_error_stream
,
2721 "Temporarily disabling shared "
2722 "library breakpoints:\n");
2724 *disabled_breaks
= 1;
2725 gdb_printf (tmp_error_stream
,
2726 "breakpoint #%d\n", bl
->owner
->number
);
2731 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2733 *hw_breakpoint_error
= 1;
2734 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2735 gdb_printf (tmp_error_stream
,
2736 "Cannot insert hardware breakpoint %d%s",
2738 bp_excpt
.message
? ":" : ".\n");
2739 if (bp_excpt
.message
!= NULL
)
2740 gdb_printf (tmp_error_stream
, "%s.\n",
2745 if (bp_excpt
.message
== NULL
)
2748 = memory_error_message (TARGET_XFER_E_IO
,
2749 bl
->gdbarch
, bl
->address
);
2751 gdb_printf (tmp_error_stream
,
2752 "Cannot insert breakpoint %d.\n"
2754 bl
->owner
->number
, message
.c_str ());
2758 gdb_printf (tmp_error_stream
,
2759 "Cannot insert breakpoint %d: %s\n",
2774 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2775 /* NOTE drow/2003-09-08: This state only exists for removing
2776 watchpoints. It's not clear that it's necessary... */
2777 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2781 gdb_assert (bl
->owner
->ops
!= NULL
2782 && bl
->owner
->ops
->insert_location
!= NULL
);
2784 val
= bl
->owner
->ops
->insert_location (bl
);
2786 /* If trying to set a read-watchpoint, and it turns out it's not
2787 supported, try emulating one with an access watchpoint. */
2788 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2790 /* But don't try to insert it, if there's already another
2791 hw_access location that would be considered a duplicate
2793 for (bp_location
*loc
: all_bp_locations ())
2795 && loc
->watchpoint_type
== hw_access
2796 && watchpoint_locations_match (bl
, loc
))
2800 bl
->target_info
= loc
->target_info
;
2801 bl
->watchpoint_type
= hw_access
;
2808 bl
->watchpoint_type
= hw_access
;
2809 val
= bl
->owner
->ops
->insert_location (bl
);
2812 /* Back to the original value. */
2813 bl
->watchpoint_type
= hw_read
;
2817 bl
->inserted
= (val
== 0);
2820 else if (bl
->owner
->type
== bp_catchpoint
)
2824 gdb_assert (bl
->owner
->ops
!= NULL
2825 && bl
->owner
->ops
->insert_location
!= NULL
);
2827 val
= bl
->owner
->ops
->insert_location (bl
);
2830 bl
->owner
->enable_state
= bp_disabled
;
2834 Error inserting catchpoint %d: Your system does not support this type\n\
2835 of catchpoint."), bl
->owner
->number
);
2837 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2840 bl
->inserted
= (val
== 0);
2842 /* We've already printed an error message if there was a problem
2843 inserting this catchpoint, and we've disabled the catchpoint,
2844 so just return success. */
2851 /* This function is called when program space PSPACE is about to be
2852 deleted. It takes care of updating breakpoints to not reference
2856 breakpoint_program_space_exit (struct program_space
*pspace
)
2858 /* Remove any breakpoint that was set through this program space. */
2859 for (breakpoint
*b
: all_breakpoints_safe ())
2860 if (b
->pspace
== pspace
)
2861 delete_breakpoint (b
);
2863 /* Breakpoints set through other program spaces could have locations
2864 bound to PSPACE as well. Remove those. */
2865 for (bp_location
*loc
: all_bp_locations ())
2867 struct bp_location
*tmp
;
2869 if (loc
->pspace
== pspace
)
2871 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2872 if (loc
->owner
->loc
== loc
)
2873 loc
->owner
->loc
= loc
->next
;
2875 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2876 if (tmp
->next
== loc
)
2878 tmp
->next
= loc
->next
;
2884 /* Now update the global location list to permanently delete the
2885 removed locations above. */
2886 update_global_location_list (UGLL_DONT_INSERT
);
2889 /* Make sure all breakpoints are inserted in inferior.
2890 Throws exception on any error.
2891 A breakpoint that is already inserted won't be inserted
2892 again, so calling this function twice is safe. */
2894 insert_breakpoints (void)
2896 for (breakpoint
*bpt
: all_breakpoints ())
2897 if (is_hardware_watchpoint (bpt
))
2899 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2901 update_watchpoint (w
, 0 /* don't reparse. */);
2904 /* Updating watchpoints creates new locations, so update the global
2905 location list. Explicitly tell ugll to insert locations and
2906 ignore breakpoints_always_inserted_mode. Also,
2907 update_global_location_list tries to "upgrade" software
2908 breakpoints to hardware breakpoints to handle "set breakpoint
2909 auto-hw", so we need to call it even if we don't have new
2911 update_global_location_list (UGLL_INSERT
);
2914 /* This is used when we need to synch breakpoint conditions between GDB and the
2915 target. It is the case with deleting and disabling of breakpoints when using
2916 always-inserted mode. */
2919 update_inserted_breakpoint_locations (void)
2923 int disabled_breaks
= 0;
2924 int hw_breakpoint_error
= 0;
2925 int hw_bp_details_reported
= 0;
2927 string_file tmp_error_stream
;
2929 /* Explicitly mark the warning -- this will only be printed if
2930 there was an error. */
2931 tmp_error_stream
.puts ("Warning:\n");
2933 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2935 for (bp_location
*bl
: all_bp_locations ())
2937 /* We only want to update software breakpoints and hardware
2939 if (!is_breakpoint (bl
->owner
))
2942 /* We only want to update locations that are already inserted
2943 and need updating. This is to avoid unwanted insertion during
2944 deletion of breakpoints. */
2945 if (!bl
->inserted
|| !bl
->needs_update
)
2948 switch_to_program_space_and_thread (bl
->pspace
);
2950 /* For targets that support global breakpoints, there's no need
2951 to select an inferior to insert breakpoint to. In fact, even
2952 if we aren't attached to any process yet, we should still
2953 insert breakpoints. */
2954 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2955 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
2958 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2959 &hw_breakpoint_error
, &hw_bp_details_reported
);
2966 target_terminal::ours_for_output ();
2967 error_stream (tmp_error_stream
);
2971 /* Used when starting or continuing the program. */
2974 insert_breakpoint_locations (void)
2978 int disabled_breaks
= 0;
2979 int hw_breakpoint_error
= 0;
2980 int hw_bp_error_explained_already
= 0;
2982 string_file tmp_error_stream
;
2984 /* Explicitly mark the warning -- this will only be printed if
2985 there was an error. */
2986 tmp_error_stream
.puts ("Warning:\n");
2988 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2990 for (bp_location
*bl
: all_bp_locations ())
2992 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2995 /* There is no point inserting thread-specific breakpoints if
2996 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2997 has BL->OWNER always non-NULL. */
2998 if (bl
->owner
->thread
!= -1
2999 && !valid_global_thread_id (bl
->owner
->thread
))
3002 switch_to_program_space_and_thread (bl
->pspace
);
3004 /* For targets that support global breakpoints, there's no need
3005 to select an inferior to insert breakpoint to. In fact, even
3006 if we aren't attached to any process yet, we should still
3007 insert breakpoints. */
3008 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3009 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3012 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3013 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3018 /* If we failed to insert all locations of a watchpoint, remove
3019 them, as half-inserted watchpoint is of limited use. */
3020 for (breakpoint
*bpt
: all_breakpoints ())
3022 int some_failed
= 0;
3024 if (!is_hardware_watchpoint (bpt
))
3027 if (!breakpoint_enabled (bpt
))
3030 if (bpt
->disposition
== disp_del_at_next_stop
)
3033 for (bp_location
*loc
: bpt
->locations ())
3034 if (!loc
->inserted
&& should_be_inserted (loc
))
3042 for (bp_location
*loc
: bpt
->locations ())
3044 remove_breakpoint (loc
);
3046 hw_breakpoint_error
= 1;
3047 tmp_error_stream
.printf ("Could not insert "
3048 "hardware watchpoint %d.\n",
3056 /* If a hardware breakpoint or watchpoint was inserted, add a
3057 message about possibly exhausted resources. */
3058 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3060 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3061 You may have requested too many hardware breakpoints/watchpoints.\n");
3063 target_terminal::ours_for_output ();
3064 error_stream (tmp_error_stream
);
3068 /* Used when the program stops.
3069 Returns zero if successful, or non-zero if there was a problem
3070 removing a breakpoint location. */
3073 remove_breakpoints (void)
3077 for (bp_location
*bl
: all_bp_locations ())
3078 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3079 val
|= remove_breakpoint (bl
);
3084 /* When a thread exits, remove breakpoints that are related to
3088 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3090 for (breakpoint
*b
: all_breakpoints_safe ())
3092 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3094 b
->disposition
= disp_del_at_next_stop
;
3097 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3098 b
->number
, print_thread_id (tp
));
3100 /* Hide it from the user. */
3106 /* See breakpoint.h. */
3109 remove_breakpoints_inf (inferior
*inf
)
3113 for (bp_location
*bl
: all_bp_locations ())
3115 if (bl
->pspace
!= inf
->pspace
)
3118 if (bl
->inserted
&& !bl
->target_info
.persist
)
3120 val
= remove_breakpoint (bl
);
3127 static int internal_breakpoint_number
= -1;
3129 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3130 If INTERNAL is non-zero, the breakpoint number will be populated
3131 from internal_breakpoint_number and that variable decremented.
3132 Otherwise the breakpoint number will be populated from
3133 breakpoint_count and that value incremented. Internal breakpoints
3134 do not set the internal var bpnum. */
3136 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3139 b
->number
= internal_breakpoint_number
--;
3142 set_breakpoint_count (breakpoint_count
+ 1);
3143 b
->number
= breakpoint_count
;
3147 static struct breakpoint
*
3148 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3149 CORE_ADDR address
, enum bptype type
,
3150 const struct breakpoint_ops
*ops
)
3152 symtab_and_line sal
;
3154 sal
.section
= find_pc_overlay (sal
.pc
);
3155 sal
.pspace
= current_program_space
;
3157 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3158 b
->number
= internal_breakpoint_number
--;
3159 b
->disposition
= disp_donttouch
;
3164 static const char *const longjmp_names
[] =
3166 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3168 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3170 /* Per-objfile data private to breakpoint.c. */
3171 struct breakpoint_objfile_data
3173 /* Minimal symbol for "_ovly_debug_event" (if any). */
3174 struct bound_minimal_symbol overlay_msym
;
3176 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3177 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3179 /* True if we have looked for longjmp probes. */
3180 int longjmp_searched
= 0;
3182 /* SystemTap probe points for longjmp (if any). These are non-owning
3184 std::vector
<probe
*> longjmp_probes
;
3186 /* Minimal symbol for "std::terminate()" (if any). */
3187 struct bound_minimal_symbol terminate_msym
;
3189 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3190 struct bound_minimal_symbol exception_msym
;
3192 /* True if we have looked for exception probes. */
3193 int exception_searched
= 0;
3195 /* SystemTap probe points for unwinding (if any). These are non-owning
3197 std::vector
<probe
*> exception_probes
;
3200 static const struct objfile_key
<breakpoint_objfile_data
>
3201 breakpoint_objfile_key
;
3203 /* Minimal symbol not found sentinel. */
3204 static struct minimal_symbol msym_not_found
;
3206 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3209 msym_not_found_p (const struct minimal_symbol
*msym
)
3211 return msym
== &msym_not_found
;
3214 /* Return per-objfile data needed by breakpoint.c.
3215 Allocate the data if necessary. */
3217 static struct breakpoint_objfile_data
*
3218 get_breakpoint_objfile_data (struct objfile
*objfile
)
3220 struct breakpoint_objfile_data
*bp_objfile_data
;
3222 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3223 if (bp_objfile_data
== NULL
)
3224 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3225 return bp_objfile_data
;
3229 create_overlay_event_breakpoint (void)
3231 const char *const func_name
= "_ovly_debug_event";
3233 for (objfile
*objfile
: current_program_space
->objfiles ())
3235 struct breakpoint
*b
;
3236 struct breakpoint_objfile_data
*bp_objfile_data
;
3238 struct explicit_location explicit_loc
;
3240 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3242 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3245 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3247 struct bound_minimal_symbol m
;
3249 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3250 if (m
.minsym
== NULL
)
3252 /* Avoid future lookups in this objfile. */
3253 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3256 bp_objfile_data
->overlay_msym
= m
;
3259 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3260 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3262 &internal_breakpoint_ops
);
3263 initialize_explicit_location (&explicit_loc
);
3264 explicit_loc
.function_name
= ASTRDUP (func_name
);
3265 b
->location
= new_explicit_location (&explicit_loc
);
3267 if (overlay_debugging
== ovly_auto
)
3269 b
->enable_state
= bp_enabled
;
3270 overlay_events_enabled
= 1;
3274 b
->enable_state
= bp_disabled
;
3275 overlay_events_enabled
= 0;
3280 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3281 true if a breakpoint was installed. */
3284 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3286 struct gdbarch
*gdbarch
= objfile
->arch ();
3287 struct breakpoint_objfile_data
*bp_objfile_data
3288 = get_breakpoint_objfile_data (objfile
);
3290 if (!bp_objfile_data
->longjmp_searched
)
3292 std::vector
<probe
*> ret
3293 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3297 /* We are only interested in checking one element. */
3300 if (!p
->can_evaluate_arguments ())
3302 /* We cannot use the probe interface here,
3303 because it does not know how to evaluate
3308 bp_objfile_data
->longjmp_probes
= ret
;
3309 bp_objfile_data
->longjmp_searched
= 1;
3312 if (bp_objfile_data
->longjmp_probes
.empty ())
3315 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3317 struct breakpoint
*b
;
3319 b
= create_internal_breakpoint (gdbarch
,
3320 p
->get_relocated_address (objfile
),
3322 &internal_breakpoint_ops
);
3323 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3324 b
->enable_state
= bp_disabled
;
3330 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3331 Return true if at least one breakpoint was installed. */
3334 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3336 struct gdbarch
*gdbarch
= objfile
->arch ();
3337 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3340 struct breakpoint_objfile_data
*bp_objfile_data
3341 = get_breakpoint_objfile_data (objfile
);
3342 unsigned int installed_bp
= 0;
3344 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3346 struct breakpoint
*b
;
3347 const char *func_name
;
3349 struct explicit_location explicit_loc
;
3351 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3354 func_name
= longjmp_names
[i
];
3355 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3357 struct bound_minimal_symbol m
;
3359 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3360 if (m
.minsym
== NULL
)
3362 /* Prevent future lookups in this objfile. */
3363 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3366 bp_objfile_data
->longjmp_msym
[i
] = m
;
3369 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3370 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3371 &internal_breakpoint_ops
);
3372 initialize_explicit_location (&explicit_loc
);
3373 explicit_loc
.function_name
= ASTRDUP (func_name
);
3374 b
->location
= new_explicit_location (&explicit_loc
);
3375 b
->enable_state
= bp_disabled
;
3379 return installed_bp
> 0;
3382 /* Create a master longjmp breakpoint. */
3385 create_longjmp_master_breakpoint (void)
3387 scoped_restore_current_program_space restore_pspace
;
3389 for (struct program_space
*pspace
: program_spaces
)
3391 set_current_program_space (pspace
);
3393 for (objfile
*obj
: current_program_space
->objfiles ())
3395 /* Skip separate debug object, it's handled in the loop below. */
3396 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3399 /* Try a probe kind breakpoint on main objfile. */
3400 if (create_longjmp_master_breakpoint_probe (obj
))
3403 /* Try longjmp_names kind breakpoints on main and separate_debug
3405 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3406 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3412 /* Create a master std::terminate breakpoint. */
3414 create_std_terminate_master_breakpoint (void)
3416 const char *const func_name
= "std::terminate()";
3418 scoped_restore_current_program_space restore_pspace
;
3420 for (struct program_space
*pspace
: program_spaces
)
3424 set_current_program_space (pspace
);
3426 for (objfile
*objfile
: current_program_space
->objfiles ())
3428 struct breakpoint
*b
;
3429 struct breakpoint_objfile_data
*bp_objfile_data
;
3430 struct explicit_location explicit_loc
;
3432 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3434 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3437 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3439 struct bound_minimal_symbol m
;
3441 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3442 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3443 && m
.minsym
->type () != mst_file_text
))
3445 /* Prevent future lookups in this objfile. */
3446 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3449 bp_objfile_data
->terminate_msym
= m
;
3452 addr
= bp_objfile_data
->terminate_msym
.value_address ();
3453 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3454 bp_std_terminate_master
,
3455 &internal_breakpoint_ops
);
3456 initialize_explicit_location (&explicit_loc
);
3457 explicit_loc
.function_name
= ASTRDUP (func_name
);
3458 b
->location
= new_explicit_location (&explicit_loc
);
3459 b
->enable_state
= bp_disabled
;
3464 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3465 probe. Return true if a breakpoint was installed. */
3468 create_exception_master_breakpoint_probe (objfile
*objfile
)
3470 struct breakpoint
*b
;
3471 struct gdbarch
*gdbarch
;
3472 struct breakpoint_objfile_data
*bp_objfile_data
;
3474 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3476 /* We prefer the SystemTap probe point if it exists. */
3477 if (!bp_objfile_data
->exception_searched
)
3479 std::vector
<probe
*> ret
3480 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3484 /* We are only interested in checking one element. */
3487 if (!p
->can_evaluate_arguments ())
3489 /* We cannot use the probe interface here, because it does
3490 not know how to evaluate arguments. */
3494 bp_objfile_data
->exception_probes
= ret
;
3495 bp_objfile_data
->exception_searched
= 1;
3498 if (bp_objfile_data
->exception_probes
.empty ())
3501 gdbarch
= objfile
->arch ();
3503 for (probe
*p
: bp_objfile_data
->exception_probes
)
3505 b
= create_internal_breakpoint (gdbarch
,
3506 p
->get_relocated_address (objfile
),
3507 bp_exception_master
,
3508 &internal_breakpoint_ops
);
3509 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3510 b
->enable_state
= bp_disabled
;
3516 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3517 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3520 create_exception_master_breakpoint_hook (objfile
*objfile
)
3522 const char *const func_name
= "_Unwind_DebugHook";
3523 struct breakpoint
*b
;
3524 struct gdbarch
*gdbarch
;
3525 struct breakpoint_objfile_data
*bp_objfile_data
;
3527 struct explicit_location explicit_loc
;
3529 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3531 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3534 gdbarch
= objfile
->arch ();
3536 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3538 struct bound_minimal_symbol debug_hook
;
3540 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3541 if (debug_hook
.minsym
== NULL
)
3543 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3547 bp_objfile_data
->exception_msym
= debug_hook
;
3550 addr
= bp_objfile_data
->exception_msym
.value_address ();
3551 addr
= gdbarch_convert_from_func_ptr_addr
3552 (gdbarch
, addr
, current_inferior ()->top_target ());
3553 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3554 &internal_breakpoint_ops
);
3555 initialize_explicit_location (&explicit_loc
);
3556 explicit_loc
.function_name
= ASTRDUP (func_name
);
3557 b
->location
= new_explicit_location (&explicit_loc
);
3558 b
->enable_state
= bp_disabled
;
3563 /* Install a master breakpoint on the unwinder's debug hook. */
3566 create_exception_master_breakpoint (void)
3568 for (objfile
*obj
: current_program_space
->objfiles ())
3570 /* Skip separate debug object. */
3571 if (obj
->separate_debug_objfile_backlink
)
3574 /* Try a probe kind breakpoint. */
3575 if (create_exception_master_breakpoint_probe (obj
))
3578 /* Iterate over main and separate debug objects and try an
3579 _Unwind_DebugHook kind breakpoint. */
3580 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3581 if (create_exception_master_breakpoint_hook (debug_objfile
))
3586 /* Does B have a location spec? */
3589 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3591 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3595 update_breakpoints_after_exec (void)
3597 /* We're about to delete breakpoints from GDB's lists. If the
3598 INSERTED flag is true, GDB will try to lift the breakpoints by
3599 writing the breakpoints' "shadow contents" back into memory. The
3600 "shadow contents" are NOT valid after an exec, so GDB should not
3601 do that. Instead, the target is responsible from marking
3602 breakpoints out as soon as it detects an exec. We don't do that
3603 here instead, because there may be other attempts to delete
3604 breakpoints after detecting an exec and before reaching here. */
3605 for (bp_location
*bploc
: all_bp_locations ())
3606 if (bploc
->pspace
== current_program_space
)
3607 gdb_assert (!bploc
->inserted
);
3609 for (breakpoint
*b
: all_breakpoints_safe ())
3611 if (b
->pspace
!= current_program_space
)
3614 /* Solib breakpoints must be explicitly reset after an exec(). */
3615 if (b
->type
== bp_shlib_event
)
3617 delete_breakpoint (b
);
3621 /* JIT breakpoints must be explicitly reset after an exec(). */
3622 if (b
->type
== bp_jit_event
)
3624 delete_breakpoint (b
);
3628 /* Thread event breakpoints must be set anew after an exec(),
3629 as must overlay event and longjmp master breakpoints. */
3630 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3631 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3632 || b
->type
== bp_exception_master
)
3634 delete_breakpoint (b
);
3638 /* Step-resume breakpoints are meaningless after an exec(). */
3639 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3641 delete_breakpoint (b
);
3645 /* Just like single-step breakpoints. */
3646 if (b
->type
== bp_single_step
)
3648 delete_breakpoint (b
);
3652 /* Longjmp and longjmp-resume breakpoints are also meaningless
3654 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3655 || b
->type
== bp_longjmp_call_dummy
3656 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3658 delete_breakpoint (b
);
3662 if (b
->type
== bp_catchpoint
)
3664 /* For now, none of the bp_catchpoint breakpoints need to
3665 do anything at this point. In the future, if some of
3666 the catchpoints need to something, we will need to add
3667 a new method, and call this method from here. */
3671 /* bp_finish is a special case. The only way we ought to be able
3672 to see one of these when an exec() has happened, is if the user
3673 caught a vfork, and then said "finish". Ordinarily a finish just
3674 carries them to the call-site of the current callee, by setting
3675 a temporary bp there and resuming. But in this case, the finish
3676 will carry them entirely through the vfork & exec.
3678 We don't want to allow a bp_finish to remain inserted now. But
3679 we can't safely delete it, 'cause finish_command has a handle to
3680 the bp on a bpstat, and will later want to delete it. There's a
3681 chance (and I've seen it happen) that if we delete the bp_finish
3682 here, that its storage will get reused by the time finish_command
3683 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3684 We really must allow finish_command to delete a bp_finish.
3686 In the absence of a general solution for the "how do we know
3687 it's safe to delete something others may have handles to?"
3688 problem, what we'll do here is just uninsert the bp_finish, and
3689 let finish_command delete it.
3691 (We know the bp_finish is "doomed" in the sense that it's
3692 momentary, and will be deleted as soon as finish_command sees
3693 the inferior stopped. So it doesn't matter that the bp's
3694 address is probably bogus in the new a.out, unlike e.g., the
3695 solib breakpoints.) */
3697 if (b
->type
== bp_finish
)
3702 /* Without a symbolic address, we have little hope of the
3703 pre-exec() address meaning the same thing in the post-exec()
3705 if (breakpoint_event_location_empty_p (b
))
3707 delete_breakpoint (b
);
3714 detach_breakpoints (ptid_t ptid
)
3717 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3718 struct inferior
*inf
= current_inferior ();
3720 if (ptid
.pid () == inferior_ptid
.pid ())
3721 error (_("Cannot detach breakpoints of inferior_ptid"));
3723 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3724 inferior_ptid
= ptid
;
3725 for (bp_location
*bl
: all_bp_locations ())
3727 if (bl
->pspace
!= inf
->pspace
)
3730 /* This function must physically remove breakpoints locations
3731 from the specified ptid, without modifying the breakpoint
3732 package's state. Locations of type bp_loc_other are only
3733 maintained at GDB side. So, there is no need to remove
3734 these bp_loc_other locations. Moreover, removing these
3735 would modify the breakpoint package's state. */
3736 if (bl
->loc_type
== bp_loc_other
)
3740 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3746 /* Remove the breakpoint location BL from the current address space.
3747 Note that this is used to detach breakpoints from a child fork.
3748 When we get here, the child isn't in the inferior list, and neither
3749 do we have objects to represent its address space --- we should
3750 *not* look at bl->pspace->aspace here. */
3753 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3757 /* BL is never in moribund_locations by our callers. */
3758 gdb_assert (bl
->owner
!= NULL
);
3760 /* The type of none suggests that owner is actually deleted.
3761 This should not ever happen. */
3762 gdb_assert (bl
->owner
->type
!= bp_none
);
3764 if (bl
->loc_type
== bp_loc_software_breakpoint
3765 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3767 /* "Normal" instruction breakpoint: either the standard
3768 trap-instruction bp (bp_breakpoint), or a
3769 bp_hardware_breakpoint. */
3771 /* First check to see if we have to handle an overlay. */
3772 if (overlay_debugging
== ovly_off
3773 || bl
->section
== NULL
3774 || !(section_is_overlay (bl
->section
)))
3776 /* No overlay handling: just remove the breakpoint. */
3778 /* If we're trying to uninsert a memory breakpoint that we
3779 know is set in a dynamic object that is marked
3780 shlib_disabled, then either the dynamic object was
3781 removed with "remove-symbol-file" or with
3782 "nosharedlibrary". In the former case, we don't know
3783 whether another dynamic object might have loaded over the
3784 breakpoint's address -- the user might well let us know
3785 about it next with add-symbol-file (the whole point of
3786 add-symbol-file is letting the user manually maintain a
3787 list of dynamically loaded objects). If we have the
3788 breakpoint's shadow memory, that is, this is a software
3789 breakpoint managed by GDB, check whether the breakpoint
3790 is still inserted in memory, to avoid overwriting wrong
3791 code with stale saved shadow contents. Note that HW
3792 breakpoints don't have shadow memory, as they're
3793 implemented using a mechanism that is not dependent on
3794 being able to modify the target's memory, and as such
3795 they should always be removed. */
3796 if (bl
->shlib_disabled
3797 && bl
->target_info
.shadow_len
!= 0
3798 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3801 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3805 /* This breakpoint is in an overlay section.
3806 Did we set a breakpoint at the LMA? */
3807 if (!overlay_events_enabled
)
3809 /* Yes -- overlay event support is not active, so we
3810 should have set a breakpoint at the LMA. Remove it.
3812 /* Ignore any failures: if the LMA is in ROM, we will
3813 have already warned when we failed to insert it. */
3814 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3815 target_remove_hw_breakpoint (bl
->gdbarch
,
3816 &bl
->overlay_target_info
);
3818 target_remove_breakpoint (bl
->gdbarch
,
3819 &bl
->overlay_target_info
,
3822 /* Did we set a breakpoint at the VMA?
3823 If so, we will have marked the breakpoint 'inserted'. */
3826 /* Yes -- remove it. Previously we did not bother to
3827 remove the breakpoint if the section had been
3828 unmapped, but let's not rely on that being safe. We
3829 don't know what the overlay manager might do. */
3831 /* However, we should remove *software* breakpoints only
3832 if the section is still mapped, or else we overwrite
3833 wrong code with the saved shadow contents. */
3834 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3835 || section_is_mapped (bl
->section
))
3836 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3842 /* No -- not inserted, so no need to remove. No error. */
3847 /* In some cases, we might not be able to remove a breakpoint in
3848 a shared library that has already been removed, but we have
3849 not yet processed the shlib unload event. Similarly for an
3850 unloaded add-symbol-file object - the user might not yet have
3851 had the chance to remove-symbol-file it. shlib_disabled will
3852 be set if the library/object has already been removed, but
3853 the breakpoint hasn't been uninserted yet, e.g., after
3854 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3855 always-inserted mode. */
3857 && (bl
->loc_type
== bp_loc_software_breakpoint
3858 && (bl
->shlib_disabled
3859 || solib_name_from_address (bl
->pspace
, bl
->address
)
3860 || shared_objfile_contains_address_p (bl
->pspace
,
3866 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3868 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3870 gdb_assert (bl
->owner
->ops
!= NULL
3871 && bl
->owner
->ops
->remove_location
!= NULL
);
3873 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3874 bl
->owner
->ops
->remove_location (bl
, reason
);
3876 /* Failure to remove any of the hardware watchpoints comes here. */
3877 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3878 warning (_("Could not remove hardware watchpoint %d."),
3881 else if (bl
->owner
->type
== bp_catchpoint
3882 && breakpoint_enabled (bl
->owner
)
3885 gdb_assert (bl
->owner
->ops
!= NULL
3886 && bl
->owner
->ops
->remove_location
!= NULL
);
3888 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3892 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3899 remove_breakpoint (struct bp_location
*bl
)
3901 /* BL is never in moribund_locations by our callers. */
3902 gdb_assert (bl
->owner
!= NULL
);
3904 /* The type of none suggests that owner is actually deleted.
3905 This should not ever happen. */
3906 gdb_assert (bl
->owner
->type
!= bp_none
);
3908 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3910 switch_to_program_space_and_thread (bl
->pspace
);
3912 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3915 /* Clear the "inserted" flag in all breakpoints. */
3918 mark_breakpoints_out (void)
3920 for (bp_location
*bl
: all_bp_locations ())
3921 if (bl
->pspace
== current_program_space
)
3925 /* Clear the "inserted" flag in all breakpoints and delete any
3926 breakpoints which should go away between runs of the program.
3928 Plus other such housekeeping that has to be done for breakpoints
3931 Note: this function gets called at the end of a run (by
3932 generic_mourn_inferior) and when a run begins (by
3933 init_wait_for_inferior). */
3938 breakpoint_init_inferior (enum inf_context context
)
3940 struct program_space
*pspace
= current_program_space
;
3942 /* If breakpoint locations are shared across processes, then there's
3944 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3947 mark_breakpoints_out ();
3949 for (breakpoint
*b
: all_breakpoints_safe ())
3951 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3957 case bp_longjmp_call_dummy
:
3959 /* If the call dummy breakpoint is at the entry point it will
3960 cause problems when the inferior is rerun, so we better get
3963 case bp_watchpoint_scope
:
3965 /* Also get rid of scope breakpoints. */
3967 case bp_shlib_event
:
3969 /* Also remove solib event breakpoints. Their addresses may
3970 have changed since the last time we ran the program.
3971 Actually we may now be debugging against different target;
3972 and so the solib backend that installed this breakpoint may
3973 not be used in by the target. E.g.,
3975 (gdb) file prog-linux
3976 (gdb) run # native linux target
3979 (gdb) file prog-win.exe
3980 (gdb) tar rem :9999 # remote Windows gdbserver.
3983 case bp_step_resume
:
3985 /* Also remove step-resume breakpoints. */
3987 case bp_single_step
:
3989 /* Also remove single-step breakpoints. */
3991 delete_breakpoint (b
);
3995 case bp_hardware_watchpoint
:
3996 case bp_read_watchpoint
:
3997 case bp_access_watchpoint
:
3999 struct watchpoint
*w
= (struct watchpoint
*) b
;
4001 /* Likewise for watchpoints on local expressions. */
4002 if (w
->exp_valid_block
!= NULL
)
4003 delete_breakpoint (b
);
4006 /* Get rid of existing locations, which are no longer
4007 valid. New ones will be created in
4008 update_watchpoint, when the inferior is restarted.
4009 The next update_global_location_list call will
4010 garbage collect them. */
4013 if (context
== inf_starting
)
4015 /* Reset val field to force reread of starting value in
4016 insert_breakpoints. */
4017 w
->val
.reset (nullptr);
4018 w
->val_valid
= false;
4028 /* Get rid of the moribund locations. */
4029 for (bp_location
*bl
: moribund_locations
)
4030 decref_bp_location (&bl
);
4031 moribund_locations
.clear ();
4034 /* These functions concern about actual breakpoints inserted in the
4035 target --- to e.g. check if we need to do decr_pc adjustment or if
4036 we need to hop over the bkpt --- so we check for address space
4037 match, not program space. */
4039 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4040 exists at PC. It returns ordinary_breakpoint_here if it's an
4041 ordinary breakpoint, or permanent_breakpoint_here if it's a
4042 permanent breakpoint.
4043 - When continuing from a location with an ordinary breakpoint, we
4044 actually single step once before calling insert_breakpoints.
4045 - When continuing from a location with a permanent breakpoint, we
4046 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4047 the target, to advance the PC past the breakpoint. */
4049 enum breakpoint_here
4050 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4052 int any_breakpoint_here
= 0;
4054 for (bp_location
*bl
: all_bp_locations ())
4056 if (bl
->loc_type
!= bp_loc_software_breakpoint
4057 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4060 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4061 if ((breakpoint_enabled (bl
->owner
)
4063 && breakpoint_location_address_match (bl
, aspace
, pc
))
4065 if (overlay_debugging
4066 && section_is_overlay (bl
->section
)
4067 && !section_is_mapped (bl
->section
))
4068 continue; /* unmapped overlay -- can't be a match */
4069 else if (bl
->permanent
)
4070 return permanent_breakpoint_here
;
4072 any_breakpoint_here
= 1;
4076 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4079 /* See breakpoint.h. */
4082 breakpoint_in_range_p (const address_space
*aspace
,
4083 CORE_ADDR addr
, ULONGEST len
)
4085 for (bp_location
*bl
: all_bp_locations ())
4087 if (bl
->loc_type
!= bp_loc_software_breakpoint
4088 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4091 if ((breakpoint_enabled (bl
->owner
)
4093 && breakpoint_location_address_range_overlap (bl
, aspace
,
4096 if (overlay_debugging
4097 && section_is_overlay (bl
->section
)
4098 && !section_is_mapped (bl
->section
))
4100 /* Unmapped overlay -- can't be a match. */
4111 /* Return true if there's a moribund breakpoint at PC. */
4114 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4116 for (bp_location
*loc
: moribund_locations
)
4117 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4123 /* Returns non-zero iff BL is inserted at PC, in address space
4127 bp_location_inserted_here_p (struct bp_location
*bl
,
4128 const address_space
*aspace
, CORE_ADDR pc
)
4131 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4134 if (overlay_debugging
4135 && section_is_overlay (bl
->section
)
4136 && !section_is_mapped (bl
->section
))
4137 return 0; /* unmapped overlay -- can't be a match */
4144 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4147 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4149 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4151 if (bl
->loc_type
!= bp_loc_software_breakpoint
4152 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4155 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4161 /* This function returns non-zero iff there is a software breakpoint
4165 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4168 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4170 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4173 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4180 /* See breakpoint.h. */
4183 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4186 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4188 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4191 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4199 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4200 CORE_ADDR addr
, ULONGEST len
)
4202 for (breakpoint
*bpt
: all_breakpoints ())
4204 if (bpt
->type
!= bp_hardware_watchpoint
4205 && bpt
->type
!= bp_access_watchpoint
)
4208 if (!breakpoint_enabled (bpt
))
4211 for (bp_location
*loc
: bpt
->locations ())
4212 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4216 /* Check for intersection. */
4217 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4218 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4226 /* See breakpoint.h. */
4229 is_catchpoint (struct breakpoint
*b
)
4231 return (b
->type
== bp_catchpoint
);
4234 /* Clear a bpstat so that it says we are not at any breakpoint.
4235 Also free any storage that is part of a bpstat. */
4238 bpstat_clear (bpstat
**bsp
)
4255 bpstat::bpstat (const bpstat
&other
)
4257 bp_location_at (other
.bp_location_at
),
4258 breakpoint_at (other
.breakpoint_at
),
4259 commands (other
.commands
),
4260 print (other
.print
),
4262 print_it (other
.print_it
)
4264 if (other
.old_val
!= NULL
)
4265 old_val
= release_value (value_copy (other
.old_val
.get ()));
4268 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4269 is part of the bpstat is copied as well. */
4272 bpstat_copy (bpstat
*bs
)
4274 bpstat
*p
= nullptr;
4276 bpstat
*retval
= nullptr;
4281 for (; bs
!= NULL
; bs
= bs
->next
)
4283 tmp
= new bpstat (*bs
);
4286 /* This is the first thing in the chain. */
4296 /* Find the bpstat associated with this breakpoint. */
4299 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4304 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4306 if (bsp
->breakpoint_at
== breakpoint
)
4312 /* See breakpoint.h. */
4315 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4317 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4319 if (bsp
->breakpoint_at
== NULL
)
4321 /* A moribund location can never explain a signal other than
4323 if (sig
== GDB_SIGNAL_TRAP
)
4328 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4337 /* Put in *NUM the breakpoint number of the first breakpoint we are
4338 stopped at. *BSP upon return is a bpstat which points to the
4339 remaining breakpoints stopped at (but which is not guaranteed to be
4340 good for anything but further calls to bpstat_num).
4342 Return 0 if passed a bpstat which does not indicate any breakpoints.
4343 Return -1 if stopped at a breakpoint that has been deleted since
4345 Return 1 otherwise. */
4348 bpstat_num (bpstat
**bsp
, int *num
)
4350 struct breakpoint
*b
;
4353 return 0; /* No more breakpoint values */
4355 /* We assume we'll never have several bpstats that correspond to a
4356 single breakpoint -- otherwise, this function might return the
4357 same number more than once and this will look ugly. */
4358 b
= (*bsp
)->breakpoint_at
;
4359 *bsp
= (*bsp
)->next
;
4361 return -1; /* breakpoint that's been deleted since */
4363 *num
= b
->number
; /* We have its number */
4367 /* See breakpoint.h. */
4370 bpstat_clear_actions (void)
4374 if (inferior_ptid
== null_ptid
)
4377 thread_info
*tp
= inferior_thread ();
4378 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4380 bs
->commands
= NULL
;
4381 bs
->old_val
.reset (nullptr);
4385 /* Called when a command is about to proceed the inferior. */
4388 breakpoint_about_to_proceed (void)
4390 if (inferior_ptid
!= null_ptid
)
4392 struct thread_info
*tp
= inferior_thread ();
4394 /* Allow inferior function calls in breakpoint commands to not
4395 interrupt the command list. When the call finishes
4396 successfully, the inferior will be standing at the same
4397 breakpoint as if nothing happened. */
4398 if (tp
->control
.in_infcall
)
4402 breakpoint_proceeded
= 1;
4405 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4406 or its equivalent. */
4409 command_line_is_silent (struct command_line
*cmd
)
4411 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4414 /* Execute all the commands associated with all the breakpoints at
4415 this location. Any of these commands could cause the process to
4416 proceed beyond this point, etc. We look out for such changes by
4417 checking the global "breakpoint_proceeded" after each command.
4419 Returns true if a breakpoint command resumed the inferior. In that
4420 case, it is the caller's responsibility to recall it again with the
4421 bpstat of the current thread. */
4424 bpstat_do_actions_1 (bpstat
**bsp
)
4429 /* Avoid endless recursion if a `source' command is contained
4431 if (executing_breakpoint_commands
)
4434 scoped_restore save_executing
4435 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4437 scoped_restore preventer
= prevent_dont_repeat ();
4439 /* This pointer will iterate over the list of bpstat's. */
4442 breakpoint_proceeded
= 0;
4443 for (; bs
!= NULL
; bs
= bs
->next
)
4445 struct command_line
*cmd
= NULL
;
4447 /* Take ownership of the BSP's command tree, if it has one.
4449 The command tree could legitimately contain commands like
4450 'step' and 'next', which call clear_proceed_status, which
4451 frees stop_bpstat's command tree. To make sure this doesn't
4452 free the tree we're executing out from under us, we need to
4453 take ownership of the tree ourselves. Since a given bpstat's
4454 commands are only executed once, we don't need to copy it; we
4455 can clear the pointer in the bpstat, and make sure we free
4456 the tree when we're done. */
4457 counted_command_line ccmd
= bs
->commands
;
4458 bs
->commands
= NULL
;
4461 if (command_line_is_silent (cmd
))
4463 /* The action has been already done by bpstat_stop_status. */
4469 execute_control_command (cmd
);
4471 if (breakpoint_proceeded
)
4477 if (breakpoint_proceeded
)
4479 if (current_ui
->async
)
4480 /* If we are in async mode, then the target might be still
4481 running, not stopped at any breakpoint, so nothing for
4482 us to do here -- just return to the event loop. */
4485 /* In sync mode, when execute_control_command returns
4486 we're already standing on the next breakpoint.
4487 Breakpoint commands for that stop were not run, since
4488 execute_command does not run breakpoint commands --
4489 only command_line_handler does, but that one is not
4490 involved in execution of breakpoint commands. So, we
4491 can now execute breakpoint commands. It should be
4492 noted that making execute_command do bpstat actions is
4493 not an option -- in this case we'll have recursive
4494 invocation of bpstat for each breakpoint with a
4495 command, and can easily blow up GDB stack. Instead, we
4496 return true, which will trigger the caller to recall us
4497 with the new stop_bpstat. */
4505 /* Helper for bpstat_do_actions. Get the current thread, if there's
4506 one, is alive and has execution. Return NULL otherwise. */
4508 static thread_info
*
4509 get_bpstat_thread ()
4511 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4514 thread_info
*tp
= inferior_thread ();
4515 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4521 bpstat_do_actions (void)
4523 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4526 /* Do any commands attached to breakpoint we are stopped at. */
4527 while ((tp
= get_bpstat_thread ()) != NULL
)
4529 /* Since in sync mode, bpstat_do_actions may resume the
4530 inferior, and only return when it is stopped at the next
4531 breakpoint, we keep doing breakpoint actions until it returns
4532 false to indicate the inferior was not resumed. */
4533 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4537 cleanup_if_error
.release ();
4540 /* Print out the (old or new) value associated with a watchpoint. */
4543 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4546 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4549 struct value_print_options opts
;
4550 get_user_print_options (&opts
);
4551 value_print (val
, stream
, &opts
);
4555 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4556 debugging multiple threads. */
4559 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4561 if (uiout
->is_mi_like_p ())
4566 if (show_thread_that_caused_stop ())
4568 struct thread_info
*thr
= inferior_thread ();
4570 uiout
->text ("Thread ");
4571 uiout
->field_string ("thread-id", print_thread_id (thr
));
4573 const char *name
= thread_name (thr
);
4576 uiout
->text (" \"");
4577 uiout
->field_string ("name", name
);
4581 uiout
->text (" hit ");
4585 /* Generic routine for printing messages indicating why we
4586 stopped. The behavior of this function depends on the value
4587 'print_it' in the bpstat structure. Under some circumstances we
4588 may decide not to print anything here and delegate the task to
4591 static enum print_stop_action
4592 print_bp_stop_message (bpstat
*bs
)
4594 switch (bs
->print_it
)
4597 /* Nothing should be printed for this bpstat entry. */
4598 return PRINT_UNKNOWN
;
4602 /* We still want to print the frame, but we already printed the
4603 relevant messages. */
4604 return PRINT_SRC_AND_LOC
;
4607 case print_it_normal
:
4609 struct breakpoint
*b
= bs
->breakpoint_at
;
4611 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4612 which has since been deleted. */
4614 return PRINT_UNKNOWN
;
4616 /* Normal case. Call the breakpoint's print_it method. */
4617 return b
->ops
->print_it (bs
);
4622 internal_error (__FILE__
, __LINE__
,
4623 _("print_bp_stop_message: unrecognized enum value"));
4628 /* A helper function that prints a shared library stopped event. */
4631 print_solib_event (int is_catchpoint
)
4633 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4634 bool any_added
= !current_program_space
->added_solibs
.empty ();
4638 if (any_added
|| any_deleted
)
4639 current_uiout
->text (_("Stopped due to shared library event:\n"));
4641 current_uiout
->text (_("Stopped due to shared library event (no "
4642 "libraries added or removed)\n"));
4645 if (current_uiout
->is_mi_like_p ())
4646 current_uiout
->field_string ("reason",
4647 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4651 current_uiout
->text (_(" Inferior unloaded "));
4652 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4653 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4655 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4658 current_uiout
->text (" ");
4659 current_uiout
->field_string ("library", name
);
4660 current_uiout
->text ("\n");
4666 current_uiout
->text (_(" Inferior loaded "));
4667 ui_out_emit_list
list_emitter (current_uiout
, "added");
4669 for (so_list
*iter
: current_program_space
->added_solibs
)
4672 current_uiout
->text (" ");
4674 current_uiout
->field_string ("library", iter
->so_name
);
4675 current_uiout
->text ("\n");
4680 /* Print a message indicating what happened. This is called from
4681 normal_stop(). The input to this routine is the head of the bpstat
4682 list - a list of the eventpoints that caused this stop. KIND is
4683 the target_waitkind for the stopping event. This
4684 routine calls the generic print routine for printing a message
4685 about reasons for stopping. This will print (for example) the
4686 "Breakpoint n," part of the output. The return value of this
4689 PRINT_UNKNOWN: Means we printed nothing.
4690 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4691 code to print the location. An example is
4692 "Breakpoint 1, " which should be followed by
4694 PRINT_SRC_ONLY: Means we printed something, but there is no need
4695 to also print the location part of the message.
4696 An example is the catch/throw messages, which
4697 don't require a location appended to the end.
4698 PRINT_NOTHING: We have done some printing and we don't need any
4699 further info to be printed. */
4701 enum print_stop_action
4702 bpstat_print (bpstat
*bs
, int kind
)
4704 enum print_stop_action val
;
4706 /* Maybe another breakpoint in the chain caused us to stop.
4707 (Currently all watchpoints go on the bpstat whether hit or not.
4708 That probably could (should) be changed, provided care is taken
4709 with respect to bpstat_explains_signal). */
4710 for (; bs
; bs
= bs
->next
)
4712 val
= print_bp_stop_message (bs
);
4713 if (val
== PRINT_SRC_ONLY
4714 || val
== PRINT_SRC_AND_LOC
4715 || val
== PRINT_NOTHING
)
4719 /* If we had hit a shared library event breakpoint,
4720 print_bp_stop_message would print out this message. If we hit an
4721 OS-level shared library event, do the same thing. */
4722 if (kind
== TARGET_WAITKIND_LOADED
)
4724 print_solib_event (0);
4725 return PRINT_NOTHING
;
4728 /* We reached the end of the chain, or we got a null BS to start
4729 with and nothing was printed. */
4730 return PRINT_UNKNOWN
;
4733 /* Evaluate the boolean expression EXP and return the result. */
4736 breakpoint_cond_eval (expression
*exp
)
4738 struct value
*mark
= value_mark ();
4739 bool res
= value_true (evaluate_expression (exp
));
4741 value_free_to_mark (mark
);
4745 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4747 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4749 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4750 breakpoint_at (bl
->owner
),
4754 print_it (print_it_normal
)
4756 **bs_link_pointer
= this;
4757 *bs_link_pointer
= &next
;
4762 breakpoint_at (NULL
),
4766 print_it (print_it_normal
)
4770 /* The target has stopped with waitstatus WS. Check if any hardware
4771 watchpoints have triggered, according to the target. */
4774 watchpoints_triggered (const target_waitstatus
&ws
)
4776 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4779 if (!stopped_by_watchpoint
)
4781 /* We were not stopped by a watchpoint. Mark all watchpoints
4782 as not triggered. */
4783 for (breakpoint
*b
: all_breakpoints ())
4784 if (is_hardware_watchpoint (b
))
4786 struct watchpoint
*w
= (struct watchpoint
*) b
;
4788 w
->watchpoint_triggered
= watch_triggered_no
;
4794 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4796 /* We were stopped by a watchpoint, but we don't know where.
4797 Mark all watchpoints as unknown. */
4798 for (breakpoint
*b
: all_breakpoints ())
4799 if (is_hardware_watchpoint (b
))
4801 struct watchpoint
*w
= (struct watchpoint
*) b
;
4803 w
->watchpoint_triggered
= watch_triggered_unknown
;
4809 /* The target could report the data address. Mark watchpoints
4810 affected by this data address as triggered, and all others as not
4813 for (breakpoint
*b
: all_breakpoints ())
4814 if (is_hardware_watchpoint (b
))
4816 struct watchpoint
*w
= (struct watchpoint
*) b
;
4818 w
->watchpoint_triggered
= watch_triggered_no
;
4819 for (bp_location
*loc
: b
->locations ())
4821 if (is_masked_watchpoint (b
))
4823 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4824 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4826 if (newaddr
== start
)
4828 w
->watchpoint_triggered
= watch_triggered_yes
;
4832 /* Exact match not required. Within range is sufficient. */
4833 else if (target_watchpoint_addr_within_range
4834 (current_inferior ()->top_target (), addr
, loc
->address
,
4837 w
->watchpoint_triggered
= watch_triggered_yes
;
4846 /* Possible return values for watchpoint_check. */
4847 enum wp_check_result
4849 /* The watchpoint has been deleted. */
4852 /* The value has changed. */
4853 WP_VALUE_CHANGED
= 2,
4855 /* The value has not changed. */
4856 WP_VALUE_NOT_CHANGED
= 3,
4858 /* Ignore this watchpoint, no matter if the value changed or not. */
4862 #define BP_TEMPFLAG 1
4863 #define BP_HARDWAREFLAG 2
4865 /* Evaluate watchpoint condition expression and check if its value
4868 static wp_check_result
4869 watchpoint_check (bpstat
*bs
)
4871 struct watchpoint
*b
;
4872 struct frame_info
*fr
;
4873 int within_current_scope
;
4875 /* BS is built from an existing struct breakpoint. */
4876 gdb_assert (bs
->breakpoint_at
!= NULL
);
4877 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4879 /* If this is a local watchpoint, we only want to check if the
4880 watchpoint frame is in scope if the current thread is the thread
4881 that was used to create the watchpoint. */
4882 if (!watchpoint_in_thread_scope (b
))
4885 if (b
->exp_valid_block
== NULL
)
4886 within_current_scope
= 1;
4889 struct frame_info
*frame
= get_current_frame ();
4890 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4891 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4893 /* stack_frame_destroyed_p() returns a non-zero value if we're
4894 still in the function but the stack frame has already been
4895 invalidated. Since we can't rely on the values of local
4896 variables after the stack has been destroyed, we are treating
4897 the watchpoint in that state as `not changed' without further
4898 checking. Don't mark watchpoints as changed if the current
4899 frame is in an epilogue - even if they are in some other
4900 frame, our view of the stack is likely to be wrong and
4901 frame_find_by_id could error out. */
4902 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4905 fr
= frame_find_by_id (b
->watchpoint_frame
);
4906 within_current_scope
= (fr
!= NULL
);
4908 /* If we've gotten confused in the unwinder, we might have
4909 returned a frame that can't describe this variable. */
4910 if (within_current_scope
)
4912 struct symbol
*function
;
4914 function
= get_frame_function (fr
);
4915 if (function
== NULL
4916 || !contained_in (b
->exp_valid_block
, function
->value_block ()))
4917 within_current_scope
= 0;
4920 if (within_current_scope
)
4921 /* If we end up stopping, the current frame will get selected
4922 in normal_stop. So this call to select_frame won't affect
4927 if (within_current_scope
)
4929 /* We use value_{,free_to_}mark because it could be a *long*
4930 time before we return to the command level and call
4931 free_all_values. We can't call free_all_values because we
4932 might be in the middle of evaluating a function call. */
4935 struct value
*new_val
;
4937 if (is_masked_watchpoint (b
))
4938 /* Since we don't know the exact trigger address (from
4939 stopped_data_address), just tell the user we've triggered
4940 a mask watchpoint. */
4941 return WP_VALUE_CHANGED
;
4943 mark
= value_mark ();
4944 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
4947 if (b
->val_bitsize
!= 0)
4948 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4950 /* We use value_equal_contents instead of value_equal because
4951 the latter coerces an array to a pointer, thus comparing just
4952 the address of the array instead of its contents. This is
4953 not what we want. */
4954 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4955 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4958 bs
->old_val
= b
->val
;
4959 b
->val
= release_value (new_val
);
4960 b
->val_valid
= true;
4961 if (new_val
!= NULL
)
4962 value_free_to_mark (mark
);
4963 return WP_VALUE_CHANGED
;
4967 /* Nothing changed. */
4968 value_free_to_mark (mark
);
4969 return WP_VALUE_NOT_CHANGED
;
4974 /* This seems like the only logical thing to do because
4975 if we temporarily ignored the watchpoint, then when
4976 we reenter the block in which it is valid it contains
4977 garbage (in the case of a function, it may have two
4978 garbage values, one before and one after the prologue).
4979 So we can't even detect the first assignment to it and
4980 watch after that (since the garbage may or may not equal
4981 the first value assigned). */
4982 /* We print all the stop information in
4983 breakpoint_ops->print_it, but in this case, by the time we
4984 call breakpoint_ops->print_it this bp will be deleted
4985 already. So we have no choice but print the information
4988 SWITCH_THRU_ALL_UIS ()
4990 struct ui_out
*uiout
= current_uiout
;
4992 if (uiout
->is_mi_like_p ())
4994 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4995 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4996 "left the block in\n"
4997 "which its expression is valid.\n",
4998 signed_field ("wpnum", b
->number
));
5001 /* Make sure the watchpoint's commands aren't executed. */
5003 watchpoint_del_at_next_stop (b
);
5009 /* Return true if it looks like target has stopped due to hitting
5010 breakpoint location BL. This function does not check if we should
5011 stop, only if BL explains the stop. */
5014 bpstat_check_location (const struct bp_location
*bl
,
5015 const address_space
*aspace
, CORE_ADDR bp_addr
,
5016 const target_waitstatus
&ws
)
5018 struct breakpoint
*b
= bl
->owner
;
5020 /* BL is from an existing breakpoint. */
5021 gdb_assert (b
!= NULL
);
5023 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5026 /* Determine if the watched values have actually changed, and we
5027 should stop. If not, set BS->stop to 0. */
5030 bpstat_check_watchpoint (bpstat
*bs
)
5032 const struct bp_location
*bl
;
5033 struct watchpoint
*b
;
5035 /* BS is built for existing struct breakpoint. */
5036 bl
= bs
->bp_location_at
.get ();
5037 gdb_assert (bl
!= NULL
);
5038 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5039 gdb_assert (b
!= NULL
);
5042 int must_check_value
= 0;
5044 if (b
->type
== bp_watchpoint
)
5045 /* For a software watchpoint, we must always check the
5047 must_check_value
= 1;
5048 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5049 /* We have a hardware watchpoint (read, write, or access)
5050 and the target earlier reported an address watched by
5052 must_check_value
= 1;
5053 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5054 && b
->type
== bp_hardware_watchpoint
)
5055 /* We were stopped by a hardware watchpoint, but the target could
5056 not report the data address. We must check the watchpoint's
5057 value. Access and read watchpoints are out of luck; without
5058 a data address, we can't figure it out. */
5059 must_check_value
= 1;
5061 if (must_check_value
)
5067 e
= watchpoint_check (bs
);
5069 catch (const gdb_exception
&ex
)
5071 exception_fprintf (gdb_stderr
, ex
,
5072 "Error evaluating expression "
5073 "for watchpoint %d\n",
5076 SWITCH_THRU_ALL_UIS ()
5078 gdb_printf (_("Watchpoint %d deleted.\n"),
5081 watchpoint_del_at_next_stop (b
);
5088 /* We've already printed what needs to be printed. */
5089 bs
->print_it
= print_it_done
;
5093 bs
->print_it
= print_it_noop
;
5096 case WP_VALUE_CHANGED
:
5097 if (b
->type
== bp_read_watchpoint
)
5099 /* There are two cases to consider here:
5101 1. We're watching the triggered memory for reads.
5102 In that case, trust the target, and always report
5103 the watchpoint hit to the user. Even though
5104 reads don't cause value changes, the value may
5105 have changed since the last time it was read, and
5106 since we're not trapping writes, we will not see
5107 those, and as such we should ignore our notion of
5110 2. We're watching the triggered memory for both
5111 reads and writes. There are two ways this may
5114 2.1. This is a target that can't break on data
5115 reads only, but can break on accesses (reads or
5116 writes), such as e.g., x86. We detect this case
5117 at the time we try to insert read watchpoints.
5119 2.2. Otherwise, the target supports read
5120 watchpoints, but, the user set an access or write
5121 watchpoint watching the same memory as this read
5124 If we're watching memory writes as well as reads,
5125 ignore watchpoint hits when we find that the
5126 value hasn't changed, as reads don't cause
5127 changes. This still gives false positives when
5128 the program writes the same value to memory as
5129 what there was already in memory (we will confuse
5130 it for a read), but it's much better than
5133 int other_write_watchpoint
= 0;
5135 if (bl
->watchpoint_type
== hw_read
)
5137 for (breakpoint
*other_b
: all_breakpoints ())
5138 if (other_b
->type
== bp_hardware_watchpoint
5139 || other_b
->type
== bp_access_watchpoint
)
5141 struct watchpoint
*other_w
=
5142 (struct watchpoint
*) other_b
;
5144 if (other_w
->watchpoint_triggered
5145 == watch_triggered_yes
)
5147 other_write_watchpoint
= 1;
5153 if (other_write_watchpoint
5154 || bl
->watchpoint_type
== hw_access
)
5156 /* We're watching the same memory for writes,
5157 and the value changed since the last time we
5158 updated it, so this trap must be for a write.
5160 bs
->print_it
= print_it_noop
;
5165 case WP_VALUE_NOT_CHANGED
:
5166 if (b
->type
== bp_hardware_watchpoint
5167 || b
->type
== bp_watchpoint
)
5169 /* Don't stop: write watchpoints shouldn't fire if
5170 the value hasn't changed. */
5171 bs
->print_it
= print_it_noop
;
5181 else /* must_check_value == 0 */
5183 /* This is a case where some watchpoint(s) triggered, but
5184 not at the address of this watchpoint, or else no
5185 watchpoint triggered after all. So don't print
5186 anything for this watchpoint. */
5187 bs
->print_it
= print_it_noop
;
5193 /* For breakpoints that are currently marked as telling gdb to stop,
5194 check conditions (condition proper, frame, thread and ignore count)
5195 of breakpoint referred to by BS. If we should not stop for this
5196 breakpoint, set BS->stop to 0. */
5199 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5201 const struct bp_location
*bl
;
5202 struct breakpoint
*b
;
5204 bool condition_result
= true;
5205 struct expression
*cond
;
5207 gdb_assert (bs
->stop
);
5209 /* BS is built for existing struct breakpoint. */
5210 bl
= bs
->bp_location_at
.get ();
5211 gdb_assert (bl
!= NULL
);
5212 b
= bs
->breakpoint_at
;
5213 gdb_assert (b
!= NULL
);
5215 /* Even if the target evaluated the condition on its end and notified GDB, we
5216 need to do so again since GDB does not know if we stopped due to a
5217 breakpoint or a single step breakpoint. */
5219 if (frame_id_p (b
->frame_id
)
5220 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5226 /* If this is a thread/task-specific breakpoint, don't waste cpu
5227 evaluating the condition if this isn't the specified
5229 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5230 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5236 /* Evaluate extension language breakpoints that have a "stop" method
5238 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5240 if (is_watchpoint (b
))
5242 struct watchpoint
*w
= (struct watchpoint
*) b
;
5244 cond
= w
->cond_exp
.get ();
5247 cond
= bl
->cond
.get ();
5249 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5251 int within_current_scope
= 1;
5252 struct watchpoint
* w
;
5254 /* We use value_mark and value_free_to_mark because it could
5255 be a long time before we return to the command level and
5256 call free_all_values. We can't call free_all_values
5257 because we might be in the middle of evaluating a
5259 struct value
*mark
= value_mark ();
5261 if (is_watchpoint (b
))
5262 w
= (struct watchpoint
*) b
;
5266 /* Need to select the frame, with all that implies so that
5267 the conditions will have the right context. Because we
5268 use the frame, we will not see an inlined function's
5269 variables when we arrive at a breakpoint at the start
5270 of the inlined function; the current frame will be the
5272 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5273 select_frame (get_current_frame ());
5276 struct frame_info
*frame
;
5278 /* For local watchpoint expressions, which particular
5279 instance of a local is being watched matters, so we
5280 keep track of the frame to evaluate the expression
5281 in. To evaluate the condition however, it doesn't
5282 really matter which instantiation of the function
5283 where the condition makes sense triggers the
5284 watchpoint. This allows an expression like "watch
5285 global if q > 10" set in `func', catch writes to
5286 global on all threads that call `func', or catch
5287 writes on all recursive calls of `func' by a single
5288 thread. We simply always evaluate the condition in
5289 the innermost frame that's executing where it makes
5290 sense to evaluate the condition. It seems
5292 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5294 select_frame (frame
);
5296 within_current_scope
= 0;
5298 if (within_current_scope
)
5302 condition_result
= breakpoint_cond_eval (cond
);
5304 catch (const gdb_exception
&ex
)
5306 exception_fprintf (gdb_stderr
, ex
,
5307 "Error in testing breakpoint condition:\n");
5312 warning (_("Watchpoint condition cannot be tested "
5313 "in the current scope"));
5314 /* If we failed to set the right context for this
5315 watchpoint, unconditionally report it. */
5317 /* FIXME-someday, should give breakpoint #. */
5318 value_free_to_mark (mark
);
5321 if (cond
&& !condition_result
)
5325 else if (b
->ignore_count
> 0)
5329 /* Increase the hit count even though we don't stop. */
5331 gdb::observers::breakpoint_modified
.notify (b
);
5335 /* Returns true if we need to track moribund locations of LOC's type
5336 on the current target. */
5339 need_moribund_for_location_type (struct bp_location
*loc
)
5341 return ((loc
->loc_type
== bp_loc_software_breakpoint
5342 && !target_supports_stopped_by_sw_breakpoint ())
5343 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5344 && !target_supports_stopped_by_hw_breakpoint ()));
5347 /* See breakpoint.h. */
5350 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5351 const target_waitstatus
&ws
)
5353 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5355 for (breakpoint
*b
: all_breakpoints ())
5357 if (!breakpoint_enabled (b
))
5360 for (bp_location
*bl
: b
->locations ())
5362 /* For hardware watchpoints, we look only at the first
5363 location. The watchpoint_check function will work on the
5364 entire expression, not the individual locations. For
5365 read watchpoints, the watchpoints_triggered function has
5366 checked all locations already. */
5367 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5370 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5373 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5376 /* Come here if it's a watchpoint, or if the break address
5379 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5382 /* Assume we stop. Should we find a watchpoint that is not
5383 actually triggered, or if the condition of the breakpoint
5384 evaluates as false, we'll reset 'stop' to 0. */
5388 /* If this is a scope breakpoint, mark the associated
5389 watchpoint as triggered so that we will handle the
5390 out-of-scope event. We'll get to the watchpoint next
5392 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5394 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5396 w
->watchpoint_triggered
= watch_triggered_yes
;
5401 /* Check if a moribund breakpoint explains the stop. */
5402 if (!target_supports_stopped_by_sw_breakpoint ()
5403 || !target_supports_stopped_by_hw_breakpoint ())
5405 for (bp_location
*loc
: moribund_locations
)
5407 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5408 && need_moribund_for_location_type (loc
))
5410 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5411 /* For hits of moribund locations, we should just proceed. */
5414 bs
->print_it
= print_it_noop
;
5422 /* See breakpoint.h. */
5425 bpstat_stop_status (const address_space
*aspace
,
5426 CORE_ADDR bp_addr
, thread_info
*thread
,
5427 const target_waitstatus
&ws
,
5430 struct breakpoint
*b
= NULL
;
5431 /* First item of allocated bpstat's. */
5432 bpstat
*bs_head
= stop_chain
;
5434 int need_remove_insert
;
5437 /* First, build the bpstat chain with locations that explain a
5438 target stop, while being careful to not set the target running,
5439 as that may invalidate locations (in particular watchpoint
5440 locations are recreated). Resuming will happen here with
5441 breakpoint conditions or watchpoint expressions that include
5442 inferior function calls. */
5443 if (bs_head
== NULL
)
5444 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5446 /* A bit of special processing for shlib breakpoints. We need to
5447 process solib loading here, so that the lists of loaded and
5448 unloaded libraries are correct before we handle "catch load" and
5450 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5452 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5454 handle_solib_event ();
5459 /* Now go through the locations that caused the target to stop, and
5460 check whether we're interested in reporting this stop to higher
5461 layers, or whether we should resume the target transparently. */
5465 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5470 b
= bs
->breakpoint_at
;
5471 b
->ops
->check_status (bs
);
5474 bpstat_check_breakpoint_conditions (bs
, thread
);
5480 /* We will stop here. */
5481 if (b
->disposition
== disp_disable
)
5483 --(b
->enable_count
);
5484 if (b
->enable_count
<= 0)
5485 b
->enable_state
= bp_disabled
;
5488 gdb::observers::breakpoint_modified
.notify (b
);
5491 bs
->commands
= b
->commands
;
5492 if (command_line_is_silent (bs
->commands
5493 ? bs
->commands
.get () : NULL
))
5496 b
->ops
->after_condition_true (bs
);
5501 /* Print nothing for this entry if we don't stop or don't
5503 if (!bs
->stop
|| !bs
->print
)
5504 bs
->print_it
= print_it_noop
;
5507 /* If we aren't stopping, the value of some hardware watchpoint may
5508 not have changed, but the intermediate memory locations we are
5509 watching may have. Don't bother if we're stopping; this will get
5511 need_remove_insert
= 0;
5512 if (! bpstat_causes_stop (bs_head
))
5513 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5515 && bs
->breakpoint_at
5516 && is_hardware_watchpoint (bs
->breakpoint_at
))
5518 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5520 update_watchpoint (w
, 0 /* don't reparse. */);
5521 need_remove_insert
= 1;
5524 if (need_remove_insert
)
5525 update_global_location_list (UGLL_MAY_INSERT
);
5526 else if (removed_any
)
5527 update_global_location_list (UGLL_DONT_INSERT
);
5532 /* See breakpoint.h. */
5535 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5536 thread_info
*thread
, const target_waitstatus
&ws
)
5538 gdb_assert (!target_stopped_by_watchpoint ());
5540 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5541 previous stop to avoid confusing bpstat_stop_status. */
5542 watchpoints_triggered (ws
);
5544 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5548 handle_jit_event (CORE_ADDR address
)
5550 struct gdbarch
*gdbarch
;
5552 infrun_debug_printf ("handling bp_jit_event");
5554 /* Switch terminal for any messages produced by
5555 breakpoint_re_set. */
5556 target_terminal::ours_for_output ();
5558 gdbarch
= get_frame_arch (get_current_frame ());
5559 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5560 thus it is expected that its objectfile can be found through
5561 minimal symbol lookup. If it doesn't work (and assert fails), it
5562 most likely means that `jit_breakpoint_re_set` was changes and this
5563 function needs to be updated too. */
5564 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5565 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5566 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5568 target_terminal::inferior ();
5571 /* Prepare WHAT final decision for infrun. */
5573 /* Decide what infrun needs to do with this bpstat. */
5576 bpstat_what (bpstat
*bs_head
)
5578 struct bpstat_what retval
;
5581 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5582 retval
.call_dummy
= STOP_NONE
;
5583 retval
.is_longjmp
= false;
5585 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5587 /* Extract this BS's action. After processing each BS, we check
5588 if its action overrides all we've seem so far. */
5589 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5592 if (bs
->breakpoint_at
== NULL
)
5594 /* I suspect this can happen if it was a momentary
5595 breakpoint which has since been deleted. */
5599 bptype
= bs
->breakpoint_at
->type
;
5606 case bp_hardware_breakpoint
:
5607 case bp_single_step
:
5610 case bp_shlib_event
:
5614 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5616 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5619 this_action
= BPSTAT_WHAT_SINGLE
;
5622 case bp_hardware_watchpoint
:
5623 case bp_read_watchpoint
:
5624 case bp_access_watchpoint
:
5628 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5630 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5634 /* There was a watchpoint, but we're not stopping.
5635 This requires no further action. */
5639 case bp_longjmp_call_dummy
:
5643 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5644 retval
.is_longjmp
= bptype
!= bp_exception
;
5647 this_action
= BPSTAT_WHAT_SINGLE
;
5649 case bp_longjmp_resume
:
5650 case bp_exception_resume
:
5653 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5654 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5657 this_action
= BPSTAT_WHAT_SINGLE
;
5659 case bp_step_resume
:
5661 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5664 /* It is for the wrong frame. */
5665 this_action
= BPSTAT_WHAT_SINGLE
;
5668 case bp_hp_step_resume
:
5670 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5673 /* It is for the wrong frame. */
5674 this_action
= BPSTAT_WHAT_SINGLE
;
5677 case bp_watchpoint_scope
:
5678 case bp_thread_event
:
5679 case bp_overlay_event
:
5680 case bp_longjmp_master
:
5681 case bp_std_terminate_master
:
5682 case bp_exception_master
:
5683 this_action
= BPSTAT_WHAT_SINGLE
;
5689 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5691 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5695 /* Some catchpoints are implemented with breakpoints.
5696 For those, we need to step over the breakpoint. */
5697 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5698 this_action
= BPSTAT_WHAT_SINGLE
;
5702 this_action
= BPSTAT_WHAT_SINGLE
;
5705 /* Make sure the action is stop (silent or noisy),
5706 so infrun.c pops the dummy frame. */
5707 retval
.call_dummy
= STOP_STACK_DUMMY
;
5708 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5710 case bp_std_terminate
:
5711 /* Make sure the action is stop (silent or noisy),
5712 so infrun.c pops the dummy frame. */
5713 retval
.call_dummy
= STOP_STD_TERMINATE
;
5714 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5717 case bp_fast_tracepoint
:
5718 case bp_static_tracepoint
:
5719 /* Tracepoint hits should not be reported back to GDB, and
5720 if one got through somehow, it should have been filtered
5722 internal_error (__FILE__
, __LINE__
,
5723 _("bpstat_what: tracepoint encountered"));
5725 case bp_gnu_ifunc_resolver
:
5726 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5727 this_action
= BPSTAT_WHAT_SINGLE
;
5729 case bp_gnu_ifunc_resolver_return
:
5730 /* The breakpoint will be removed, execution will restart from the
5731 PC of the former breakpoint. */
5732 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5737 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5739 this_action
= BPSTAT_WHAT_SINGLE
;
5743 internal_error (__FILE__
, __LINE__
,
5744 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5747 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5754 bpstat_run_callbacks (bpstat
*bs_head
)
5758 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5760 struct breakpoint
*b
= bs
->breakpoint_at
;
5767 handle_jit_event (bs
->bp_location_at
->address
);
5769 case bp_gnu_ifunc_resolver
:
5770 gnu_ifunc_resolver_stop (b
);
5772 case bp_gnu_ifunc_resolver_return
:
5773 gnu_ifunc_resolver_return_stop (b
);
5779 /* See breakpoint.h. */
5782 bpstat_should_step ()
5784 for (breakpoint
*b
: all_breakpoints ())
5785 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5791 /* See breakpoint.h. */
5794 bpstat_causes_stop (bpstat
*bs
)
5796 for (; bs
!= NULL
; bs
= bs
->next
)
5805 /* Compute a number of spaces suitable to indent the next line
5806 so it starts at the position corresponding to the table column
5807 named COL_NAME in the currently active table of UIOUT. */
5810 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5812 int i
, total_width
, width
, align
;
5816 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5818 if (strcmp (text
, col_name
) == 0)
5821 total_width
+= width
+ 1;
5827 /* Determine if the locations of this breakpoint will have their conditions
5828 evaluated by the target, host or a mix of both. Returns the following:
5830 "host": Host evals condition.
5831 "host or target": Host or Target evals condition.
5832 "target": Target evals condition.
5836 bp_condition_evaluator (struct breakpoint
*b
)
5838 char host_evals
= 0;
5839 char target_evals
= 0;
5844 if (!is_breakpoint (b
))
5847 if (gdb_evaluates_breakpoint_condition_p ()
5848 || !target_supports_evaluation_of_breakpoint_conditions ())
5849 return condition_evaluation_host
;
5851 for (bp_location
*bl
: b
->locations ())
5853 if (bl
->cond_bytecode
)
5859 if (host_evals
&& target_evals
)
5860 return condition_evaluation_both
;
5861 else if (target_evals
)
5862 return condition_evaluation_target
;
5864 return condition_evaluation_host
;
5867 /* Determine the breakpoint location's condition evaluator. This is
5868 similar to bp_condition_evaluator, but for locations. */
5871 bp_location_condition_evaluator (struct bp_location
*bl
)
5873 if (bl
&& !is_breakpoint (bl
->owner
))
5876 if (gdb_evaluates_breakpoint_condition_p ()
5877 || !target_supports_evaluation_of_breakpoint_conditions ())
5878 return condition_evaluation_host
;
5880 if (bl
&& bl
->cond_bytecode
)
5881 return condition_evaluation_target
;
5883 return condition_evaluation_host
;
5886 /* Print the LOC location out of the list of B->LOC locations. */
5889 print_breakpoint_location (struct breakpoint
*b
,
5890 struct bp_location
*loc
)
5892 struct ui_out
*uiout
= current_uiout
;
5894 scoped_restore_current_program_space restore_pspace
;
5896 if (loc
!= NULL
&& loc
->shlib_disabled
)
5900 set_current_program_space (loc
->pspace
);
5902 if (b
->display_canonical
)
5903 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5904 else if (loc
&& loc
->symtab
)
5906 const struct symbol
*sym
= loc
->symbol
;
5910 uiout
->text ("in ");
5911 uiout
->field_string ("func", sym
->print_name (),
5912 function_name_style
.style ());
5914 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5915 uiout
->text ("at ");
5917 uiout
->field_string ("file",
5918 symtab_to_filename_for_display (loc
->symtab
),
5919 file_name_style
.style ());
5922 if (uiout
->is_mi_like_p ())
5923 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5925 uiout
->field_signed ("line", loc
->line_number
);
5931 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5933 uiout
->field_stream ("at", stb
);
5937 uiout
->field_string ("pending",
5938 event_location_to_string (b
->location
.get ()));
5939 /* If extra_string is available, it could be holding a condition
5940 or dprintf arguments. In either case, make sure it is printed,
5941 too, but only for non-MI streams. */
5942 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5944 if (b
->type
== bp_dprintf
)
5948 uiout
->text (b
->extra_string
.get ());
5952 if (loc
&& is_breakpoint (b
)
5953 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5954 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5957 uiout
->field_string ("evaluated-by",
5958 bp_location_condition_evaluator (loc
));
5964 bptype_string (enum bptype type
)
5966 struct ep_type_description
5969 const char *description
;
5971 static struct ep_type_description bptypes
[] =
5973 {bp_none
, "?deleted?"},
5974 {bp_breakpoint
, "breakpoint"},
5975 {bp_hardware_breakpoint
, "hw breakpoint"},
5976 {bp_single_step
, "sw single-step"},
5977 {bp_until
, "until"},
5978 {bp_finish
, "finish"},
5979 {bp_watchpoint
, "watchpoint"},
5980 {bp_hardware_watchpoint
, "hw watchpoint"},
5981 {bp_read_watchpoint
, "read watchpoint"},
5982 {bp_access_watchpoint
, "acc watchpoint"},
5983 {bp_longjmp
, "longjmp"},
5984 {bp_longjmp_resume
, "longjmp resume"},
5985 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5986 {bp_exception
, "exception"},
5987 {bp_exception_resume
, "exception resume"},
5988 {bp_step_resume
, "step resume"},
5989 {bp_hp_step_resume
, "high-priority step resume"},
5990 {bp_watchpoint_scope
, "watchpoint scope"},
5991 {bp_call_dummy
, "call dummy"},
5992 {bp_std_terminate
, "std::terminate"},
5993 {bp_shlib_event
, "shlib events"},
5994 {bp_thread_event
, "thread events"},
5995 {bp_overlay_event
, "overlay events"},
5996 {bp_longjmp_master
, "longjmp master"},
5997 {bp_std_terminate_master
, "std::terminate master"},
5998 {bp_exception_master
, "exception master"},
5999 {bp_catchpoint
, "catchpoint"},
6000 {bp_tracepoint
, "tracepoint"},
6001 {bp_fast_tracepoint
, "fast tracepoint"},
6002 {bp_static_tracepoint
, "static tracepoint"},
6003 {bp_dprintf
, "dprintf"},
6004 {bp_jit_event
, "jit events"},
6005 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6006 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6009 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6010 || ((int) type
!= bptypes
[(int) type
].type
))
6011 internal_error (__FILE__
, __LINE__
,
6012 _("bptypes table does not describe type #%d."),
6015 return bptypes
[(int) type
].description
;
6018 /* For MI, output a field named 'thread-groups' with a list as the value.
6019 For CLI, prefix the list with the string 'inf'. */
6022 output_thread_groups (struct ui_out
*uiout
,
6023 const char *field_name
,
6024 const std::vector
<int> &inf_nums
,
6027 int is_mi
= uiout
->is_mi_like_p ();
6029 /* For backward compatibility, don't display inferiors in CLI unless
6030 there are several. Always display them for MI. */
6031 if (!is_mi
&& mi_only
)
6034 ui_out_emit_list
list_emitter (uiout
, field_name
);
6036 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6042 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6043 uiout
->field_string (NULL
, mi_group
);
6048 uiout
->text (" inf ");
6052 uiout
->text (plongest (inf_nums
[i
]));
6057 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6058 instead of going via breakpoint_ops::print_one. This makes "maint
6059 info breakpoints" show the software breakpoint locations of
6060 catchpoints, which are considered internal implementation
6064 print_one_breakpoint_location (struct breakpoint
*b
,
6065 struct bp_location
*loc
,
6067 struct bp_location
**last_loc
,
6068 int allflag
, bool raw_loc
)
6070 struct command_line
*l
;
6071 static char bpenables
[] = "nynny";
6073 struct ui_out
*uiout
= current_uiout
;
6074 int header_of_multiple
= 0;
6075 int part_of_multiple
= (loc
!= NULL
);
6076 struct value_print_options opts
;
6078 get_user_print_options (&opts
);
6080 gdb_assert (!loc
|| loc_number
!= 0);
6081 /* See comment in print_one_breakpoint concerning treatment of
6082 breakpoints with single disabled location. */
6085 && (b
->loc
->next
!= NULL
6086 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6087 header_of_multiple
= 1;
6095 if (part_of_multiple
)
6096 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6098 uiout
->field_signed ("number", b
->number
);
6102 if (part_of_multiple
)
6103 uiout
->field_skip ("type");
6105 uiout
->field_string ("type", bptype_string (b
->type
));
6109 if (part_of_multiple
)
6110 uiout
->field_skip ("disp");
6112 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6116 /* For locations that are disabled because of an invalid condition,
6117 display "N*" on CLI, where "*" refers to a footnote below the
6118 table. For MI, simply display a "N" without a footnote. */
6119 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6120 if (part_of_multiple
)
6121 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6122 : (loc
->enabled
? "y" : "n")));
6124 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6127 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6128 b
->ops
->print_one (b
, last_loc
);
6131 if (is_watchpoint (b
))
6133 struct watchpoint
*w
= (struct watchpoint
*) b
;
6135 /* Field 4, the address, is omitted (which makes the columns
6136 not line up too nicely with the headers, but the effect
6137 is relatively readable). */
6138 if (opts
.addressprint
)
6139 uiout
->field_skip ("addr");
6141 uiout
->field_string ("what", w
->exp_string
.get ());
6143 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6144 || is_ada_exception_catchpoint (b
))
6146 if (opts
.addressprint
)
6149 if (header_of_multiple
)
6150 uiout
->field_string ("addr", "<MULTIPLE>",
6151 metadata_style
.style ());
6152 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6153 uiout
->field_string ("addr", "<PENDING>",
6154 metadata_style
.style ());
6156 uiout
->field_core_addr ("addr",
6157 loc
->gdbarch
, loc
->address
);
6160 if (!header_of_multiple
)
6161 print_breakpoint_location (b
, loc
);
6167 if (loc
!= NULL
&& !header_of_multiple
)
6169 std::vector
<int> inf_nums
;
6172 for (inferior
*inf
: all_inferiors ())
6174 if (inf
->pspace
== loc
->pspace
)
6175 inf_nums
.push_back (inf
->num
);
6178 /* For backward compatibility, don't display inferiors in CLI unless
6179 there are several. Always display for MI. */
6181 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6182 && (program_spaces
.size () > 1
6183 || number_of_inferiors () > 1)
6184 /* LOC is for existing B, it cannot be in
6185 moribund_locations and thus having NULL OWNER. */
6186 && loc
->owner
->type
!= bp_catchpoint
))
6188 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6191 if (!part_of_multiple
)
6193 if (b
->thread
!= -1)
6195 /* FIXME: This seems to be redundant and lost here; see the
6196 "stop only in" line a little further down. */
6197 uiout
->text (" thread ");
6198 uiout
->field_signed ("thread", b
->thread
);
6200 else if (b
->task
!= 0)
6202 uiout
->text (" task ");
6203 uiout
->field_signed ("task", b
->task
);
6209 if (!part_of_multiple
)
6210 b
->ops
->print_one_detail (b
, uiout
);
6212 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6215 uiout
->text ("\tstop only in stack frame at ");
6216 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6218 uiout
->field_core_addr ("frame",
6219 b
->gdbarch
, b
->frame_id
.stack_addr
);
6223 if (!part_of_multiple
&& b
->cond_string
)
6226 if (is_tracepoint (b
))
6227 uiout
->text ("\ttrace only if ");
6229 uiout
->text ("\tstop only if ");
6230 uiout
->field_string ("cond", b
->cond_string
.get ());
6232 /* Print whether the target is doing the breakpoint's condition
6233 evaluation. If GDB is doing the evaluation, don't print anything. */
6234 if (is_breakpoint (b
)
6235 && breakpoint_condition_evaluation_mode ()
6236 == condition_evaluation_target
)
6238 uiout
->message (" (%pF evals)",
6239 string_field ("evaluated-by",
6240 bp_condition_evaluator (b
)));
6245 if (!part_of_multiple
&& b
->thread
!= -1)
6247 /* FIXME should make an annotation for this. */
6248 uiout
->text ("\tstop only in thread ");
6249 if (uiout
->is_mi_like_p ())
6250 uiout
->field_signed ("thread", b
->thread
);
6253 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6255 uiout
->field_string ("thread", print_thread_id (thr
));
6260 if (!part_of_multiple
)
6264 /* FIXME should make an annotation for this. */
6265 if (is_catchpoint (b
))
6266 uiout
->text ("\tcatchpoint");
6267 else if (is_tracepoint (b
))
6268 uiout
->text ("\ttracepoint");
6270 uiout
->text ("\tbreakpoint");
6271 uiout
->text (" already hit ");
6272 uiout
->field_signed ("times", b
->hit_count
);
6273 if (b
->hit_count
== 1)
6274 uiout
->text (" time\n");
6276 uiout
->text (" times\n");
6280 /* Output the count also if it is zero, but only if this is mi. */
6281 if (uiout
->is_mi_like_p ())
6282 uiout
->field_signed ("times", b
->hit_count
);
6286 if (!part_of_multiple
&& b
->ignore_count
)
6289 uiout
->message ("\tignore next %pF hits\n",
6290 signed_field ("ignore", b
->ignore_count
));
6293 /* Note that an enable count of 1 corresponds to "enable once"
6294 behavior, which is reported by the combination of enablement and
6295 disposition, so we don't need to mention it here. */
6296 if (!part_of_multiple
&& b
->enable_count
> 1)
6299 uiout
->text ("\tdisable after ");
6300 /* Tweak the wording to clarify that ignore and enable counts
6301 are distinct, and have additive effect. */
6302 if (b
->ignore_count
)
6303 uiout
->text ("additional ");
6305 uiout
->text ("next ");
6306 uiout
->field_signed ("enable", b
->enable_count
);
6307 uiout
->text (" hits\n");
6310 if (!part_of_multiple
&& is_tracepoint (b
))
6312 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6314 if (tp
->traceframe_usage
)
6316 uiout
->text ("\ttrace buffer usage ");
6317 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6318 uiout
->text (" bytes\n");
6322 l
= b
->commands
? b
->commands
.get () : NULL
;
6323 if (!part_of_multiple
&& l
)
6326 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6327 print_command_lines (uiout
, l
, 4);
6330 if (is_tracepoint (b
))
6332 struct tracepoint
*t
= (struct tracepoint
*) b
;
6334 if (!part_of_multiple
&& t
->pass_count
)
6336 annotate_field (10);
6337 uiout
->text ("\tpass count ");
6338 uiout
->field_signed ("pass", t
->pass_count
);
6339 uiout
->text (" \n");
6342 /* Don't display it when tracepoint or tracepoint location is
6344 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6346 annotate_field (11);
6348 if (uiout
->is_mi_like_p ())
6349 uiout
->field_string ("installed",
6350 loc
->inserted
? "y" : "n");
6356 uiout
->text ("\tnot ");
6357 uiout
->text ("installed on target\n");
6362 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6364 if (is_watchpoint (b
))
6366 struct watchpoint
*w
= (struct watchpoint
*) b
;
6368 uiout
->field_string ("original-location", w
->exp_string
.get ());
6370 else if (b
->location
!= NULL
6371 && event_location_to_string (b
->location
.get ()) != NULL
)
6372 uiout
->field_string ("original-location",
6373 event_location_to_string (b
->location
.get ()));
6377 /* See breakpoint.h. */
6379 bool fix_multi_location_breakpoint_output_globally
= false;
6382 print_one_breakpoint (struct breakpoint
*b
,
6383 struct bp_location
**last_loc
,
6386 struct ui_out
*uiout
= current_uiout
;
6387 bool use_fixed_output
6388 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6389 || fix_multi_location_breakpoint_output_globally
);
6391 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6392 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6394 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6396 if (!use_fixed_output
)
6397 bkpt_tuple_emitter
.reset ();
6399 /* If this breakpoint has custom print function,
6400 it's already printed. Otherwise, print individual
6401 locations, if any. */
6403 || b
->ops
->print_one
== NULL
6406 /* If breakpoint has a single location that is disabled, we
6407 print it as if it had several locations, since otherwise it's
6408 hard to represent "breakpoint enabled, location disabled"
6411 Note that while hardware watchpoints have several locations
6412 internally, that's not a property exposed to users.
6414 Likewise, while catchpoints may be implemented with
6415 breakpoints (e.g., catch throw), that's not a property
6416 exposed to users. We do however display the internal
6417 breakpoint locations with "maint info breakpoints". */
6418 if (!is_hardware_watchpoint (b
)
6419 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6420 || is_ada_exception_catchpoint (b
))
6422 || (b
->loc
&& (b
->loc
->next
6424 || b
->loc
->disabled_by_cond
))))
6426 gdb::optional
<ui_out_emit_list
> locations_list
;
6428 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6429 MI record. For later versions, place breakpoint locations in a
6431 if (uiout
->is_mi_like_p () && use_fixed_output
)
6432 locations_list
.emplace (uiout
, "locations");
6435 for (bp_location
*loc
: b
->locations ())
6437 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6438 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6447 breakpoint_address_bits (struct breakpoint
*b
)
6449 int print_address_bits
= 0;
6451 /* Software watchpoints that aren't watching memory don't have an
6452 address to print. */
6453 if (is_no_memory_software_watchpoint (b
))
6456 for (bp_location
*loc
: b
->locations ())
6460 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6461 if (addr_bit
> print_address_bits
)
6462 print_address_bits
= addr_bit
;
6465 return print_address_bits
;
6468 /* See breakpoint.h. */
6471 print_breakpoint (breakpoint
*b
)
6473 struct bp_location
*dummy_loc
= NULL
;
6474 print_one_breakpoint (b
, &dummy_loc
, 0);
6477 /* Return true if this breakpoint was set by the user, false if it is
6478 internal or momentary. */
6481 user_breakpoint_p (struct breakpoint
*b
)
6483 return b
->number
> 0;
6486 /* See breakpoint.h. */
6489 pending_breakpoint_p (struct breakpoint
*b
)
6491 return b
->loc
== NULL
;
6494 /* Print information on breakpoints (including watchpoints and tracepoints).
6496 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6497 understood by number_or_range_parser. Only breakpoints included in this
6498 list are then printed.
6500 If SHOW_INTERNAL is true, print internal breakpoints.
6502 If FILTER is non-NULL, call it on each breakpoint and only include the
6503 ones for which it returns true.
6505 Return the total number of breakpoints listed. */
6508 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6509 bool (*filter
) (const struct breakpoint
*))
6511 struct bp_location
*last_loc
= NULL
;
6512 int nr_printable_breakpoints
;
6513 struct value_print_options opts
;
6514 int print_address_bits
= 0;
6515 int print_type_col_width
= 14;
6516 struct ui_out
*uiout
= current_uiout
;
6517 bool has_disabled_by_cond_location
= false;
6519 get_user_print_options (&opts
);
6521 /* Compute the number of rows in the table, as well as the size
6522 required for address fields. */
6523 nr_printable_breakpoints
= 0;
6524 for (breakpoint
*b
: all_breakpoints ())
6526 /* If we have a filter, only list the breakpoints it accepts. */
6527 if (filter
&& !filter (b
))
6530 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6531 accept. Skip the others. */
6532 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6534 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6536 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6540 if (show_internal
|| user_breakpoint_p (b
))
6542 int addr_bit
, type_len
;
6544 addr_bit
= breakpoint_address_bits (b
);
6545 if (addr_bit
> print_address_bits
)
6546 print_address_bits
= addr_bit
;
6548 type_len
= strlen (bptype_string (b
->type
));
6549 if (type_len
> print_type_col_width
)
6550 print_type_col_width
= type_len
;
6552 nr_printable_breakpoints
++;
6557 ui_out_emit_table
table_emitter (uiout
,
6558 opts
.addressprint
? 6 : 5,
6559 nr_printable_breakpoints
,
6562 if (nr_printable_breakpoints
> 0)
6563 annotate_breakpoints_headers ();
6564 if (nr_printable_breakpoints
> 0)
6566 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6567 if (nr_printable_breakpoints
> 0)
6569 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6570 if (nr_printable_breakpoints
> 0)
6572 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6573 if (nr_printable_breakpoints
> 0)
6575 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6576 if (opts
.addressprint
)
6578 if (nr_printable_breakpoints
> 0)
6580 if (print_address_bits
<= 32)
6581 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6583 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6585 if (nr_printable_breakpoints
> 0)
6587 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6588 uiout
->table_body ();
6589 if (nr_printable_breakpoints
> 0)
6590 annotate_breakpoints_table ();
6592 for (breakpoint
*b
: all_breakpoints ())
6595 /* If we have a filter, only list the breakpoints it accepts. */
6596 if (filter
&& !filter (b
))
6599 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6600 accept. Skip the others. */
6602 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6604 if (show_internal
) /* maintenance info breakpoint */
6606 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6609 else /* all others */
6611 if (!number_is_in_list (bp_num_list
, b
->number
))
6615 /* We only print out user settable breakpoints unless the
6616 show_internal is set. */
6617 if (show_internal
|| user_breakpoint_p (b
))
6619 print_one_breakpoint (b
, &last_loc
, show_internal
);
6620 for (bp_location
*loc
: b
->locations ())
6621 if (loc
->disabled_by_cond
)
6622 has_disabled_by_cond_location
= true;
6627 if (nr_printable_breakpoints
== 0)
6629 /* If there's a filter, let the caller decide how to report
6633 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6634 uiout
->message ("No breakpoints or watchpoints.\n");
6636 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6642 if (last_loc
&& !server_command
)
6643 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6645 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6646 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6650 /* FIXME? Should this be moved up so that it is only called when
6651 there have been breakpoints? */
6652 annotate_breakpoints_table_end ();
6654 return nr_printable_breakpoints
;
6657 /* Display the value of default-collect in a way that is generally
6658 compatible with the breakpoint list. */
6661 default_collect_info (void)
6663 struct ui_out
*uiout
= current_uiout
;
6665 /* If it has no value (which is frequently the case), say nothing; a
6666 message like "No default-collect." gets in user's face when it's
6668 if (default_collect
.empty ())
6671 /* The following phrase lines up nicely with per-tracepoint collect
6673 uiout
->text ("default collect ");
6674 uiout
->field_string ("default-collect", default_collect
);
6675 uiout
->text (" \n");
6679 info_breakpoints_command (const char *args
, int from_tty
)
6681 breakpoint_1 (args
, false, NULL
);
6683 default_collect_info ();
6687 info_watchpoints_command (const char *args
, int from_tty
)
6689 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6690 struct ui_out
*uiout
= current_uiout
;
6692 if (num_printed
== 0)
6694 if (args
== NULL
|| *args
== '\0')
6695 uiout
->message ("No watchpoints.\n");
6697 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6702 maintenance_info_breakpoints (const char *args
, int from_tty
)
6704 breakpoint_1 (args
, true, NULL
);
6706 default_collect_info ();
6710 breakpoint_has_pc (struct breakpoint
*b
,
6711 struct program_space
*pspace
,
6712 CORE_ADDR pc
, struct obj_section
*section
)
6714 for (bp_location
*bl
: b
->locations ())
6716 if (bl
->pspace
== pspace
6717 && bl
->address
== pc
6718 && (!overlay_debugging
|| bl
->section
== section
))
6724 /* Print a message describing any user-breakpoints set at PC. This
6725 concerns with logical breakpoints, so we match program spaces, not
6729 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6730 struct program_space
*pspace
, CORE_ADDR pc
,
6731 struct obj_section
*section
, int thread
)
6735 for (breakpoint
*b
: all_breakpoints ())
6736 others
+= (user_breakpoint_p (b
)
6737 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6742 gdb_printf (_("Note: breakpoint "));
6743 else /* if (others == ???) */
6744 gdb_printf (_("Note: breakpoints "));
6745 for (breakpoint
*b
: all_breakpoints ())
6746 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6749 gdb_printf ("%d", b
->number
);
6750 if (b
->thread
== -1 && thread
!= -1)
6751 gdb_printf (" (all threads)");
6752 else if (b
->thread
!= -1)
6753 gdb_printf (" (thread %d)", b
->thread
);
6754 gdb_printf ("%s%s ",
6755 ((b
->enable_state
== bp_disabled
6756 || b
->enable_state
== bp_call_disabled
)
6760 : ((others
== 1) ? " and" : ""));
6762 current_uiout
->message (_("also set at pc %ps.\n"),
6763 styled_string (address_style
.style (),
6764 paddress (gdbarch
, pc
)));
6769 /* Return true iff it is meaningful to use the address member of LOC.
6770 For some breakpoint types, the locations' address members are
6771 irrelevant and it makes no sense to attempt to compare them to
6772 other addresses (or use them for any other purpose either).
6774 More specifically, software watchpoints and catchpoints that are
6775 not backed by breakpoints always have a zero valued location
6776 address and we don't want to mark breakpoints of any of these types
6777 to be a duplicate of an actual breakpoint location at address
6781 bl_address_is_meaningful (bp_location
*loc
)
6783 return loc
->loc_type
!= bp_loc_other
;
6786 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6787 true if LOC1 and LOC2 represent the same watchpoint location. */
6790 watchpoint_locations_match (struct bp_location
*loc1
,
6791 struct bp_location
*loc2
)
6793 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6794 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6796 /* Both of them must exist. */
6797 gdb_assert (w1
!= NULL
);
6798 gdb_assert (w2
!= NULL
);
6800 /* If the target can evaluate the condition expression in hardware,
6801 then we we need to insert both watchpoints even if they are at
6802 the same place. Otherwise the watchpoint will only trigger when
6803 the condition of whichever watchpoint was inserted evaluates to
6804 true, not giving a chance for GDB to check the condition of the
6805 other watchpoint. */
6807 && target_can_accel_watchpoint_condition (loc1
->address
,
6809 loc1
->watchpoint_type
,
6810 w1
->cond_exp
.get ()))
6812 && target_can_accel_watchpoint_condition (loc2
->address
,
6814 loc2
->watchpoint_type
,
6815 w2
->cond_exp
.get ())))
6818 /* Note that this checks the owner's type, not the location's. In
6819 case the target does not support read watchpoints, but does
6820 support access watchpoints, we'll have bp_read_watchpoint
6821 watchpoints with hw_access locations. Those should be considered
6822 duplicates of hw_read locations. The hw_read locations will
6823 become hw_access locations later. */
6824 return (loc1
->owner
->type
== loc2
->owner
->type
6825 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6826 && loc1
->address
== loc2
->address
6827 && loc1
->length
== loc2
->length
);
6830 /* See breakpoint.h. */
6833 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6834 const address_space
*aspace2
, CORE_ADDR addr2
)
6836 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6837 || aspace1
== aspace2
)
6841 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6842 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6843 matches ASPACE2. On targets that have global breakpoints, the address
6844 space doesn't really matter. */
6847 breakpoint_address_match_range (const address_space
*aspace1
,
6849 int len1
, const address_space
*aspace2
,
6852 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6853 || aspace1
== aspace2
)
6854 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6857 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6858 a ranged breakpoint. In most targets, a match happens only if ASPACE
6859 matches the breakpoint's address space. On targets that have global
6860 breakpoints, the address space doesn't really matter. */
6863 breakpoint_location_address_match (struct bp_location
*bl
,
6864 const address_space
*aspace
,
6867 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6870 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6871 bl
->address
, bl
->length
,
6875 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6876 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6877 match happens only if ASPACE matches the breakpoint's address
6878 space. On targets that have global breakpoints, the address space
6879 doesn't really matter. */
6882 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6883 const address_space
*aspace
,
6884 CORE_ADDR addr
, int len
)
6886 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6887 || bl
->pspace
->aspace
== aspace
)
6889 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6891 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6897 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6898 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6899 true, otherwise returns false. */
6902 tracepoint_locations_match (struct bp_location
*loc1
,
6903 struct bp_location
*loc2
)
6905 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6906 /* Since tracepoint locations are never duplicated with others', tracepoint
6907 locations at the same address of different tracepoints are regarded as
6908 different locations. */
6909 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6914 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6915 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6916 the same location. If SW_HW_BPS_MATCH is true, then software
6917 breakpoint locations and hardware breakpoint locations match,
6918 otherwise they don't. */
6921 breakpoint_locations_match (struct bp_location
*loc1
,
6922 struct bp_location
*loc2
,
6923 bool sw_hw_bps_match
)
6925 int hw_point1
, hw_point2
;
6927 /* Both of them must not be in moribund_locations. */
6928 gdb_assert (loc1
->owner
!= NULL
);
6929 gdb_assert (loc2
->owner
!= NULL
);
6931 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6932 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6934 if (hw_point1
!= hw_point2
)
6937 return watchpoint_locations_match (loc1
, loc2
);
6938 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6939 return tracepoint_locations_match (loc1
, loc2
);
6941 /* We compare bp_location.length in order to cover ranged
6942 breakpoints. Keep this in sync with
6943 bp_location_is_less_than. */
6944 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6945 loc2
->pspace
->aspace
, loc2
->address
)
6946 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
6947 && loc1
->length
== loc2
->length
);
6951 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6952 int bnum
, int have_bnum
)
6954 /* The longest string possibly returned by hex_string_custom
6955 is 50 chars. These must be at least that big for safety. */
6959 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6960 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6962 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6963 bnum
, astr1
, astr2
);
6965 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6968 /* Adjust a breakpoint's address to account for architectural
6969 constraints on breakpoint placement. Return the adjusted address.
6970 Note: Very few targets require this kind of adjustment. For most
6971 targets, this function is simply the identity function. */
6974 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6975 CORE_ADDR bpaddr
, enum bptype bptype
)
6977 if (bptype
== bp_watchpoint
6978 || bptype
== bp_hardware_watchpoint
6979 || bptype
== bp_read_watchpoint
6980 || bptype
== bp_access_watchpoint
6981 || bptype
== bp_catchpoint
)
6983 /* Watchpoints and the various bp_catch_* eventpoints should not
6984 have their addresses modified. */
6987 else if (bptype
== bp_single_step
)
6989 /* Single-step breakpoints should not have their addresses
6990 modified. If there's any architectural constrain that
6991 applies to this address, then it should have already been
6992 taken into account when the breakpoint was created in the
6993 first place. If we didn't do this, stepping through e.g.,
6994 Thumb-2 IT blocks would break. */
6999 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7001 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7003 /* Some targets have architectural constraints on the placement
7004 of breakpoint instructions. Obtain the adjusted address. */
7005 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7008 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7010 /* An adjusted breakpoint address can significantly alter
7011 a user's expectations. Print a warning if an adjustment
7013 if (adjusted_bpaddr
!= bpaddr
)
7014 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7016 return adjusted_bpaddr
;
7021 bp_location_from_bp_type (bptype type
)
7026 case bp_single_step
:
7030 case bp_longjmp_resume
:
7031 case bp_longjmp_call_dummy
:
7033 case bp_exception_resume
:
7034 case bp_step_resume
:
7035 case bp_hp_step_resume
:
7036 case bp_watchpoint_scope
:
7038 case bp_std_terminate
:
7039 case bp_shlib_event
:
7040 case bp_thread_event
:
7041 case bp_overlay_event
:
7043 case bp_longjmp_master
:
7044 case bp_std_terminate_master
:
7045 case bp_exception_master
:
7046 case bp_gnu_ifunc_resolver
:
7047 case bp_gnu_ifunc_resolver_return
:
7049 return bp_loc_software_breakpoint
;
7050 case bp_hardware_breakpoint
:
7051 return bp_loc_hardware_breakpoint
;
7052 case bp_hardware_watchpoint
:
7053 case bp_read_watchpoint
:
7054 case bp_access_watchpoint
:
7055 return bp_loc_hardware_watchpoint
;
7059 case bp_fast_tracepoint
:
7060 case bp_static_tracepoint
:
7061 return bp_loc_other
;
7063 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7067 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7069 this->owner
= owner
;
7070 this->cond_bytecode
= NULL
;
7071 this->shlib_disabled
= 0;
7073 this->disabled_by_cond
= false;
7075 this->loc_type
= type
;
7077 if (this->loc_type
== bp_loc_software_breakpoint
7078 || this->loc_type
== bp_loc_hardware_breakpoint
)
7079 mark_breakpoint_location_modified (this);
7084 bp_location::bp_location (breakpoint
*owner
)
7085 : bp_location::bp_location (owner
,
7086 bp_location_from_bp_type (owner
->type
))
7090 /* Allocate a struct bp_location. */
7092 static struct bp_location
*
7093 allocate_bp_location (struct breakpoint
*bpt
)
7095 return bpt
->ops
->allocate_location (bpt
);
7098 /* Decrement reference count. If the reference count reaches 0,
7099 destroy the bp_location. Sets *BLP to NULL. */
7102 decref_bp_location (struct bp_location
**blp
)
7104 bp_location_ref_policy::decref (*blp
);
7108 /* Add breakpoint B at the end of the global breakpoint chain. */
7111 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7113 struct breakpoint
*b1
;
7114 struct breakpoint
*result
= b
.get ();
7116 /* Add this breakpoint to the end of the chain so that a list of
7117 breakpoints will come out in order of increasing numbers. */
7119 b1
= breakpoint_chain
;
7121 breakpoint_chain
= b
.release ();
7126 b1
->next
= b
.release ();
7132 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7135 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7136 struct gdbarch
*gdbarch
,
7138 const struct breakpoint_ops
*ops
)
7140 gdb_assert (ops
!= NULL
);
7144 b
->gdbarch
= gdbarch
;
7145 b
->language
= current_language
->la_language
;
7146 b
->input_radix
= input_radix
;
7147 b
->related_breakpoint
= b
;
7150 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7151 that has type BPTYPE and has no locations as yet. */
7153 static struct breakpoint
*
7154 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7156 const struct breakpoint_ops
*ops
)
7158 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7160 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7161 return add_to_breakpoint_chain (std::move (b
));
7164 /* Initialize loc->function_name. */
7167 set_breakpoint_location_function (struct bp_location
*loc
)
7169 gdb_assert (loc
->owner
!= NULL
);
7171 if (loc
->owner
->type
== bp_breakpoint
7172 || loc
->owner
->type
== bp_hardware_breakpoint
7173 || is_tracepoint (loc
->owner
))
7175 const char *function_name
;
7177 if (loc
->msymbol
!= NULL
7178 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7179 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7181 struct breakpoint
*b
= loc
->owner
;
7183 function_name
= loc
->msymbol
->linkage_name ();
7185 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7186 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7188 /* Create only the whole new breakpoint of this type but do not
7189 mess more complicated breakpoints with multiple locations. */
7190 b
->type
= bp_gnu_ifunc_resolver
;
7191 /* Remember the resolver's address for use by the return
7193 loc
->related_address
= loc
->address
;
7197 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7200 loc
->function_name
= make_unique_xstrdup (function_name
);
7204 /* Attempt to determine architecture of location identified by SAL. */
7206 get_sal_arch (struct symtab_and_line sal
)
7209 return sal
.section
->objfile
->arch ();
7211 return sal
.symtab
->compunit ()->objfile ()->arch ();
7216 /* Low level routine for partially initializing a breakpoint of type
7217 BPTYPE. The newly created breakpoint's address, section, source
7218 file name, and line number are provided by SAL.
7220 It is expected that the caller will complete the initialization of
7221 the newly created breakpoint struct as well as output any status
7222 information regarding the creation of a new breakpoint. */
7225 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7226 struct symtab_and_line sal
, enum bptype bptype
,
7227 const struct breakpoint_ops
*ops
)
7229 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7231 add_location_to_breakpoint (b
, &sal
);
7233 if (bptype
!= bp_catchpoint
)
7234 gdb_assert (sal
.pspace
!= NULL
);
7236 /* Store the program space that was used to set the breakpoint,
7237 except for ordinary breakpoints, which are independent of the
7239 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7240 b
->pspace
= sal
.pspace
;
7243 /* set_raw_breakpoint is a low level routine for allocating and
7244 partially initializing a breakpoint of type BPTYPE. The newly
7245 created breakpoint's address, section, source file name, and line
7246 number are provided by SAL. The newly created and partially
7247 initialized breakpoint is added to the breakpoint chain and
7248 is also returned as the value of this function.
7250 It is expected that the caller will complete the initialization of
7251 the newly created breakpoint struct as well as output any status
7252 information regarding the creation of a new breakpoint. In
7253 particular, set_raw_breakpoint does NOT set the breakpoint
7254 number! Care should be taken to not allow an error to occur
7255 prior to completing the initialization of the breakpoint. If this
7256 should happen, a bogus breakpoint will be left on the chain. */
7258 static struct breakpoint
*
7259 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7260 struct symtab_and_line sal
, enum bptype bptype
,
7261 const struct breakpoint_ops
*ops
)
7263 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7265 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7266 return add_to_breakpoint_chain (std::move (b
));
7269 /* Call this routine when stepping and nexting to enable a breakpoint
7270 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7271 initiated the operation. */
7274 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7276 int thread
= tp
->global_num
;
7278 /* To avoid having to rescan all objfile symbols at every step,
7279 we maintain a list of continually-inserted but always disabled
7280 longjmp "master" breakpoints. Here, we simply create momentary
7281 clones of those and enable them for the requested thread. */
7282 for (breakpoint
*b
: all_breakpoints_safe ())
7283 if (b
->pspace
== current_program_space
7284 && (b
->type
== bp_longjmp_master
7285 || b
->type
== bp_exception_master
))
7287 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7288 struct breakpoint
*clone
;
7290 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7291 after their removal. */
7292 clone
= momentary_breakpoint_from_master (b
, type
,
7293 &momentary_breakpoint_ops
, 1);
7294 clone
->thread
= thread
;
7297 tp
->initiating_frame
= frame
;
7300 /* Delete all longjmp breakpoints from THREAD. */
7302 delete_longjmp_breakpoint (int thread
)
7304 for (breakpoint
*b
: all_breakpoints_safe ())
7305 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7307 if (b
->thread
== thread
)
7308 delete_breakpoint (b
);
7313 delete_longjmp_breakpoint_at_next_stop (int thread
)
7315 for (breakpoint
*b
: all_breakpoints_safe ())
7316 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7318 if (b
->thread
== thread
)
7319 b
->disposition
= disp_del_at_next_stop
;
7323 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7324 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7325 pointer to any of them. Return NULL if this system cannot place longjmp
7329 set_longjmp_breakpoint_for_call_dummy (void)
7331 breakpoint
*retval
= nullptr;
7333 for (breakpoint
*b
: all_breakpoints ())
7334 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7336 struct breakpoint
*new_b
;
7338 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7339 &momentary_breakpoint_ops
,
7341 new_b
->thread
= inferior_thread ()->global_num
;
7343 /* Link NEW_B into the chain of RETVAL breakpoints. */
7345 gdb_assert (new_b
->related_breakpoint
== new_b
);
7348 new_b
->related_breakpoint
= retval
;
7349 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7350 retval
= retval
->related_breakpoint
;
7351 retval
->related_breakpoint
= new_b
;
7357 /* Verify all existing dummy frames and their associated breakpoints for
7358 TP. Remove those which can no longer be found in the current frame
7361 If the unwind fails then there is not sufficient information to discard
7362 dummy frames. In this case, elide the clean up and the dummy frames will
7363 be cleaned up next time this function is called from a location where
7364 unwinding is possible. */
7367 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7369 struct breakpoint
*b
, *b_tmp
;
7371 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7372 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7374 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7376 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7377 chained off b->related_breakpoint. */
7378 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7379 dummy_b
= dummy_b
->related_breakpoint
;
7381 /* If there was no bp_call_dummy breakpoint then there's nothing
7382 more to do. Or, if the dummy frame associated with the
7383 bp_call_dummy is still on the stack then we need to leave this
7384 bp_call_dummy in place. */
7385 if (dummy_b
->type
!= bp_call_dummy
7386 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7389 /* We didn't find the dummy frame on the stack, this could be
7390 because we have longjmp'd to a stack frame that is previous to
7391 the dummy frame, or it could be because the stack unwind is
7392 broken at some point between the longjmp frame and the dummy
7395 Next we figure out why the stack unwind stopped. If it looks
7396 like the unwind is complete then we assume the dummy frame has
7397 been jumped over, however, if the unwind stopped for an
7398 unexpected reason then we assume the stack unwind is currently
7399 broken, and that we will (eventually) return to the dummy
7402 It might be tempting to consider using frame_id_inner here, but
7403 that is not safe. There is no guarantee that the stack frames
7404 we are looking at here are even on the same stack as the
7405 original dummy frame, hence frame_id_inner can't be used. See
7406 the comments on frame_id_inner for more details. */
7407 bool unwind_finished_unexpectedly
= false;
7408 for (struct frame_info
*fi
= get_current_frame (); fi
!= nullptr; )
7410 struct frame_info
*prev
= get_prev_frame (fi
);
7411 if (prev
== nullptr)
7413 /* FI is the last stack frame. Why did this frame not
7415 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7416 if (stop_reason
!= UNWIND_NO_REASON
7417 && stop_reason
!= UNWIND_OUTERMOST
)
7418 unwind_finished_unexpectedly
= true;
7422 if (unwind_finished_unexpectedly
)
7425 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7427 while (b
->related_breakpoint
!= b
)
7429 if (b_tmp
== b
->related_breakpoint
)
7430 b_tmp
= b
->related_breakpoint
->next
;
7431 delete_breakpoint (b
->related_breakpoint
);
7433 delete_breakpoint (b
);
7438 enable_overlay_breakpoints (void)
7440 for (breakpoint
*b
: all_breakpoints ())
7441 if (b
->type
== bp_overlay_event
)
7443 b
->enable_state
= bp_enabled
;
7444 update_global_location_list (UGLL_MAY_INSERT
);
7445 overlay_events_enabled
= 1;
7450 disable_overlay_breakpoints (void)
7452 for (breakpoint
*b
: all_breakpoints ())
7453 if (b
->type
== bp_overlay_event
)
7455 b
->enable_state
= bp_disabled
;
7456 update_global_location_list (UGLL_DONT_INSERT
);
7457 overlay_events_enabled
= 0;
7461 /* Set an active std::terminate breakpoint for each std::terminate
7462 master breakpoint. */
7464 set_std_terminate_breakpoint (void)
7466 for (breakpoint
*b
: all_breakpoints_safe ())
7467 if (b
->pspace
== current_program_space
7468 && b
->type
== bp_std_terminate_master
)
7470 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7471 &momentary_breakpoint_ops
, 1);
7475 /* Delete all the std::terminate breakpoints. */
7477 delete_std_terminate_breakpoint (void)
7479 for (breakpoint
*b
: all_breakpoints_safe ())
7480 if (b
->type
== bp_std_terminate
)
7481 delete_breakpoint (b
);
7485 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7487 struct breakpoint
*b
;
7489 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7490 &internal_breakpoint_ops
);
7492 b
->enable_state
= bp_enabled
;
7493 /* location has to be used or breakpoint_re_set will delete me. */
7494 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7496 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7501 struct lang_and_radix
7507 /* Create a breakpoint for JIT code registration and unregistration. */
7510 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7512 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7513 &internal_breakpoint_ops
);
7516 /* Remove JIT code registration and unregistration breakpoint(s). */
7519 remove_jit_event_breakpoints (void)
7521 for (breakpoint
*b
: all_breakpoints_safe ())
7522 if (b
->type
== bp_jit_event
7523 && b
->loc
->pspace
== current_program_space
)
7524 delete_breakpoint (b
);
7528 remove_solib_event_breakpoints (void)
7530 for (breakpoint
*b
: all_breakpoints_safe ())
7531 if (b
->type
== bp_shlib_event
7532 && b
->loc
->pspace
== current_program_space
)
7533 delete_breakpoint (b
);
7536 /* See breakpoint.h. */
7539 remove_solib_event_breakpoints_at_next_stop (void)
7541 for (breakpoint
*b
: all_breakpoints_safe ())
7542 if (b
->type
== bp_shlib_event
7543 && b
->loc
->pspace
== current_program_space
)
7544 b
->disposition
= disp_del_at_next_stop
;
7547 /* Helper for create_solib_event_breakpoint /
7548 create_and_insert_solib_event_breakpoint. Allows specifying which
7549 INSERT_MODE to pass through to update_global_location_list. */
7551 static struct breakpoint
*
7552 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7553 enum ugll_insert_mode insert_mode
)
7555 struct breakpoint
*b
;
7557 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7558 &internal_breakpoint_ops
);
7559 update_global_location_list_nothrow (insert_mode
);
7564 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7566 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7569 /* See breakpoint.h. */
7572 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7574 struct breakpoint
*b
;
7576 /* Explicitly tell update_global_location_list to insert
7578 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7579 if (!b
->loc
->inserted
)
7581 delete_breakpoint (b
);
7587 /* Disable any breakpoints that are on code in shared libraries. Only
7588 apply to enabled breakpoints, disabled ones can just stay disabled. */
7591 disable_breakpoints_in_shlibs (void)
7593 for (bp_location
*loc
: all_bp_locations ())
7595 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7596 struct breakpoint
*b
= loc
->owner
;
7598 /* We apply the check to all breakpoints, including disabled for
7599 those with loc->duplicate set. This is so that when breakpoint
7600 becomes enabled, or the duplicate is removed, gdb will try to
7601 insert all breakpoints. If we don't set shlib_disabled here,
7602 we'll try to insert those breakpoints and fail. */
7603 if (((b
->type
== bp_breakpoint
)
7604 || (b
->type
== bp_jit_event
)
7605 || (b
->type
== bp_hardware_breakpoint
)
7606 || (is_tracepoint (b
)))
7607 && loc
->pspace
== current_program_space
7608 && !loc
->shlib_disabled
7609 && solib_name_from_address (loc
->pspace
, loc
->address
)
7612 loc
->shlib_disabled
= 1;
7617 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7618 notification of unloaded_shlib. Only apply to enabled breakpoints,
7619 disabled ones can just stay disabled. */
7622 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7624 int disabled_shlib_breaks
= 0;
7626 for (bp_location
*loc
: all_bp_locations ())
7628 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7629 struct breakpoint
*b
= loc
->owner
;
7631 if (solib
->pspace
== loc
->pspace
7632 && !loc
->shlib_disabled
7633 && (((b
->type
== bp_breakpoint
7634 || b
->type
== bp_jit_event
7635 || b
->type
== bp_hardware_breakpoint
)
7636 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7637 || loc
->loc_type
== bp_loc_software_breakpoint
))
7638 || is_tracepoint (b
))
7639 && solib_contains_address_p (solib
, loc
->address
))
7641 loc
->shlib_disabled
= 1;
7642 /* At this point, we cannot rely on remove_breakpoint
7643 succeeding so we must mark the breakpoint as not inserted
7644 to prevent future errors occurring in remove_breakpoints. */
7647 /* This may cause duplicate notifications for the same breakpoint. */
7648 gdb::observers::breakpoint_modified
.notify (b
);
7650 if (!disabled_shlib_breaks
)
7652 target_terminal::ours_for_output ();
7653 warning (_("Temporarily disabling breakpoints "
7654 "for unloaded shared library \"%s\""),
7657 disabled_shlib_breaks
= 1;
7662 /* Disable any breakpoints and tracepoints in OBJFILE upon
7663 notification of free_objfile. Only apply to enabled breakpoints,
7664 disabled ones can just stay disabled. */
7667 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7669 if (objfile
== NULL
)
7672 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7673 managed by the user with add-symbol-file/remove-symbol-file.
7674 Similarly to how breakpoints in shared libraries are handled in
7675 response to "nosharedlibrary", mark breakpoints in such modules
7676 shlib_disabled so they end up uninserted on the next global
7677 location list update. Shared libraries not loaded by the user
7678 aren't handled here -- they're already handled in
7679 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7680 solib_unloaded observer. We skip objfiles that are not
7681 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7683 if ((objfile
->flags
& OBJF_SHARED
) == 0
7684 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7687 for (breakpoint
*b
: all_breakpoints ())
7689 int bp_modified
= 0;
7691 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7694 for (bp_location
*loc
: b
->locations ())
7696 CORE_ADDR loc_addr
= loc
->address
;
7698 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7699 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7702 if (loc
->shlib_disabled
!= 0)
7705 if (objfile
->pspace
!= loc
->pspace
)
7708 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7709 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7712 if (is_addr_in_objfile (loc_addr
, objfile
))
7714 loc
->shlib_disabled
= 1;
7715 /* At this point, we don't know whether the object was
7716 unmapped from the inferior or not, so leave the
7717 inserted flag alone. We'll handle failure to
7718 uninsert quietly, in case the object was indeed
7721 mark_breakpoint_location_modified (loc
);
7728 gdb::observers::breakpoint_modified
.notify (b
);
7732 /* An instance of this type is used to represent an solib catchpoint.
7733 A breakpoint is really of this type iff its ops pointer points to
7734 CATCH_SOLIB_BREAKPOINT_OPS. */
7736 struct solib_catchpoint
: public breakpoint
7738 /* True for "catch load", false for "catch unload". */
7741 /* Regular expression to match, if any. COMPILED is only valid when
7742 REGEX is non-NULL. */
7743 gdb::unique_xmalloc_ptr
<char> regex
;
7744 std::unique_ptr
<compiled_regex
> compiled
;
7748 insert_catch_solib (struct bp_location
*ignore
)
7754 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7760 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7761 const address_space
*aspace
,
7763 const target_waitstatus
&ws
)
7765 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7767 if (ws
.kind () == TARGET_WAITKIND_LOADED
)
7770 for (breakpoint
*other
: all_breakpoints ())
7772 if (other
== bl
->owner
)
7775 if (other
->type
!= bp_shlib_event
)
7778 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
7781 for (bp_location
*other_bl
: other
->locations ())
7783 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7792 check_status_catch_solib (struct bpstat
*bs
)
7794 struct solib_catchpoint
*self
7795 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7799 for (so_list
*iter
: current_program_space
->added_solibs
)
7802 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
7808 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
7811 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
7817 bs
->print_it
= print_it_noop
;
7820 static enum print_stop_action
7821 print_it_catch_solib (bpstat
*bs
)
7823 struct breakpoint
*b
= bs
->breakpoint_at
;
7824 struct ui_out
*uiout
= current_uiout
;
7826 annotate_catchpoint (b
->number
);
7827 maybe_print_thread_hit_breakpoint (uiout
);
7828 if (b
->disposition
== disp_del
)
7829 uiout
->text ("Temporary catchpoint ");
7831 uiout
->text ("Catchpoint ");
7832 uiout
->field_signed ("bkptno", b
->number
);
7834 if (uiout
->is_mi_like_p ())
7835 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7836 print_solib_event (1);
7837 return PRINT_SRC_AND_LOC
;
7841 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7843 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7844 struct value_print_options opts
;
7845 struct ui_out
*uiout
= current_uiout
;
7847 get_user_print_options (&opts
);
7848 /* Field 4, the address, is omitted (which makes the columns not
7849 line up too nicely with the headers, but the effect is relatively
7851 if (opts
.addressprint
)
7854 uiout
->field_skip ("addr");
7862 msg
= string_printf (_("load of library matching %s"),
7863 self
->regex
.get ());
7865 msg
= _("load of library");
7870 msg
= string_printf (_("unload of library matching %s"),
7871 self
->regex
.get ());
7873 msg
= _("unload of library");
7875 uiout
->field_string ("what", msg
);
7877 if (uiout
->is_mi_like_p ())
7878 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
7882 print_mention_catch_solib (struct breakpoint
*b
)
7884 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7886 gdb_printf (_("Catchpoint %d (%s)"), b
->number
,
7887 self
->is_load
? "load" : "unload");
7891 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
7893 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7895 gdb_printf (fp
, "%s %s",
7896 b
->disposition
== disp_del
? "tcatch" : "catch",
7897 self
->is_load
? "load" : "unload");
7899 gdb_printf (fp
, " %s", self
->regex
.get ());
7900 gdb_printf (fp
, "\n");
7903 static struct breakpoint_ops catch_solib_breakpoint_ops
;
7905 /* See breakpoint.h. */
7908 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
7910 struct gdbarch
*gdbarch
= get_current_arch ();
7914 arg
= skip_spaces (arg
);
7916 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
7920 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
7921 _("Invalid regexp")));
7922 c
->regex
= make_unique_xstrdup (arg
);
7925 c
->is_load
= is_load
;
7926 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
7927 &catch_solib_breakpoint_ops
);
7929 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7931 install_breakpoint (0, std::move (c
), 1);
7934 /* A helper function that does all the work for "catch load" and
7938 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
7939 struct cmd_list_element
*command
)
7941 const int enabled
= 1;
7942 bool temp
= command
->context () == CATCH_TEMPORARY
;
7944 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
7948 catch_load_command_1 (const char *arg
, int from_tty
,
7949 struct cmd_list_element
*command
)
7951 catch_load_or_unload (arg
, from_tty
, 1, command
);
7955 catch_unload_command_1 (const char *arg
, int from_tty
,
7956 struct cmd_list_element
*command
)
7958 catch_load_or_unload (arg
, from_tty
, 0, command
);
7961 /* See breakpoint.h. */
7964 init_catchpoint (struct breakpoint
*b
,
7965 struct gdbarch
*gdbarch
, bool temp
,
7966 const char *cond_string
,
7967 const struct breakpoint_ops
*ops
)
7969 symtab_and_line sal
;
7970 sal
.pspace
= current_program_space
;
7972 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
7974 if (cond_string
== nullptr)
7975 b
->cond_string
.reset ();
7977 b
->cond_string
= make_unique_xstrdup (cond_string
);
7978 b
->disposition
= temp
? disp_del
: disp_donttouch
;
7982 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
7984 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
7985 set_breakpoint_number (internal
, b
);
7986 if (is_tracepoint (b
))
7987 set_tracepoint_count (breakpoint_count
);
7990 gdb::observers::breakpoint_created
.notify (b
);
7993 update_global_location_list (UGLL_MAY_INSERT
);
7997 hw_breakpoint_used_count (void)
8001 for (breakpoint
*b
: all_breakpoints ())
8002 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8003 for (bp_location
*bl
: b
->locations ())
8005 /* Special types of hardware breakpoints may use more than
8007 i
+= b
->ops
->resources_needed (bl
);
8013 /* Returns the resources B would use if it were a hardware
8017 hw_watchpoint_use_count (struct breakpoint
*b
)
8021 if (!breakpoint_enabled (b
))
8024 for (bp_location
*bl
: b
->locations ())
8026 /* Special types of hardware watchpoints may use more than
8028 i
+= b
->ops
->resources_needed (bl
);
8034 /* Returns the sum the used resources of all hardware watchpoints of
8035 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8036 the sum of the used resources of all hardware watchpoints of other
8037 types _not_ TYPE. */
8040 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8041 enum bptype type
, int *other_type_used
)
8045 *other_type_used
= 0;
8046 for (breakpoint
*b
: all_breakpoints ())
8050 if (!breakpoint_enabled (b
))
8053 if (b
->type
== type
)
8054 i
+= hw_watchpoint_use_count (b
);
8055 else if (is_hardware_watchpoint (b
))
8056 *other_type_used
= 1;
8063 disable_watchpoints_before_interactive_call_start (void)
8065 for (breakpoint
*b
: all_breakpoints ())
8066 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8068 b
->enable_state
= bp_call_disabled
;
8069 update_global_location_list (UGLL_DONT_INSERT
);
8074 enable_watchpoints_after_interactive_call_stop (void)
8076 for (breakpoint
*b
: all_breakpoints ())
8077 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8079 b
->enable_state
= bp_enabled
;
8080 update_global_location_list (UGLL_MAY_INSERT
);
8085 disable_breakpoints_before_startup (void)
8087 current_program_space
->executing_startup
= 1;
8088 update_global_location_list (UGLL_DONT_INSERT
);
8092 enable_breakpoints_after_startup (void)
8094 current_program_space
->executing_startup
= 0;
8095 breakpoint_re_set ();
8098 /* Create a new single-step breakpoint for thread THREAD, with no
8101 static struct breakpoint
*
8102 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8104 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8106 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8107 &momentary_breakpoint_ops
);
8109 b
->disposition
= disp_donttouch
;
8110 b
->frame_id
= null_frame_id
;
8113 gdb_assert (b
->thread
!= 0);
8115 return add_to_breakpoint_chain (std::move (b
));
8118 /* Set a momentary breakpoint of type TYPE at address specified by
8119 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8123 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8124 struct frame_id frame_id
, enum bptype type
)
8126 struct breakpoint
*b
;
8128 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8130 gdb_assert (!frame_id_artificial_p (frame_id
));
8132 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8133 b
->enable_state
= bp_enabled
;
8134 b
->disposition
= disp_donttouch
;
8135 b
->frame_id
= frame_id
;
8137 b
->thread
= inferior_thread ()->global_num
;
8139 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8141 return breakpoint_up (b
);
8144 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8145 The new breakpoint will have type TYPE, use OPS as its
8146 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8148 static struct breakpoint
*
8149 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8151 const struct breakpoint_ops
*ops
,
8154 struct breakpoint
*copy
;
8156 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8157 copy
->loc
= allocate_bp_location (copy
);
8158 set_breakpoint_location_function (copy
->loc
);
8160 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8161 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8162 copy
->loc
->address
= orig
->loc
->address
;
8163 copy
->loc
->section
= orig
->loc
->section
;
8164 copy
->loc
->pspace
= orig
->loc
->pspace
;
8165 copy
->loc
->probe
= orig
->loc
->probe
;
8166 copy
->loc
->line_number
= orig
->loc
->line_number
;
8167 copy
->loc
->symtab
= orig
->loc
->symtab
;
8168 copy
->loc
->enabled
= loc_enabled
;
8169 copy
->frame_id
= orig
->frame_id
;
8170 copy
->thread
= orig
->thread
;
8171 copy
->pspace
= orig
->pspace
;
8173 copy
->enable_state
= bp_enabled
;
8174 copy
->disposition
= disp_donttouch
;
8175 copy
->number
= internal_breakpoint_number
--;
8177 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8181 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8185 clone_momentary_breakpoint (struct breakpoint
*orig
)
8187 /* If there's nothing to clone, then return nothing. */
8191 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8195 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8198 struct symtab_and_line sal
;
8200 sal
= find_pc_line (pc
, 0);
8202 sal
.section
= find_pc_overlay (pc
);
8203 sal
.explicit_pc
= 1;
8205 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8209 /* Tell the user we have just set a breakpoint B. */
8212 mention (struct breakpoint
*b
)
8214 b
->ops
->print_mention (b
);
8215 current_uiout
->text ("\n");
8219 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8221 /* Handle "set breakpoint auto-hw on".
8223 If the explicitly specified breakpoint type is not hardware
8224 breakpoint, check the memory map to see whether the breakpoint
8225 address is in read-only memory.
8227 - location type is not hardware breakpoint, memory is read-only.
8228 We change the type of the location to hardware breakpoint.
8230 - location type is hardware breakpoint, memory is read-write. This
8231 means we've previously made the location hardware one, but then the
8232 memory map changed, so we undo.
8236 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8238 if (automatic_hardware_breakpoints
8239 && bl
->owner
->type
!= bp_hardware_breakpoint
8240 && (bl
->loc_type
== bp_loc_software_breakpoint
8241 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8243 /* When breakpoints are removed, remove_breakpoints will use
8244 location types we've just set here, the only possible problem
8245 is that memory map has changed during running program, but
8246 it's not going to work anyway with current gdb. */
8247 mem_region
*mr
= lookup_mem_region (bl
->address
);
8251 enum bp_loc_type new_type
;
8253 if (mr
->attrib
.mode
!= MEM_RW
)
8254 new_type
= bp_loc_hardware_breakpoint
;
8256 new_type
= bp_loc_software_breakpoint
;
8258 if (new_type
!= bl
->loc_type
)
8260 static bool said
= false;
8262 bl
->loc_type
= new_type
;
8265 gdb_printf (_("Note: automatically using "
8266 "hardware breakpoints for "
8267 "read-only addresses.\n"));
8275 static struct bp_location
*
8276 add_location_to_breakpoint (struct breakpoint
*b
,
8277 const struct symtab_and_line
*sal
)
8279 struct bp_location
*loc
, **tmp
;
8280 CORE_ADDR adjusted_address
;
8281 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8283 if (loc_gdbarch
== NULL
)
8284 loc_gdbarch
= b
->gdbarch
;
8286 /* Adjust the breakpoint's address prior to allocating a location.
8287 Once we call allocate_bp_location(), that mostly uninitialized
8288 location will be placed on the location chain. Adjustment of the
8289 breakpoint may cause target_read_memory() to be called and we do
8290 not want its scan of the location chain to find a breakpoint and
8291 location that's only been partially initialized. */
8292 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8295 /* Sort the locations by their ADDRESS. */
8296 loc
= allocate_bp_location (b
);
8297 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8298 tmp
= &((*tmp
)->next
))
8303 loc
->requested_address
= sal
->pc
;
8304 loc
->address
= adjusted_address
;
8305 loc
->pspace
= sal
->pspace
;
8306 loc
->probe
.prob
= sal
->prob
;
8307 loc
->probe
.objfile
= sal
->objfile
;
8308 gdb_assert (loc
->pspace
!= NULL
);
8309 loc
->section
= sal
->section
;
8310 loc
->gdbarch
= loc_gdbarch
;
8311 loc
->line_number
= sal
->line
;
8312 loc
->symtab
= sal
->symtab
;
8313 loc
->symbol
= sal
->symbol
;
8314 loc
->msymbol
= sal
->msymbol
;
8315 loc
->objfile
= sal
->objfile
;
8317 set_breakpoint_location_function (loc
);
8319 /* While by definition, permanent breakpoints are already present in the
8320 code, we don't mark the location as inserted. Normally one would expect
8321 that GDB could rely on that breakpoint instruction to stop the program,
8322 thus removing the need to insert its own breakpoint, except that executing
8323 the breakpoint instruction can kill the target instead of reporting a
8324 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8325 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8326 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8327 breakpoint be inserted normally results in QEMU knowing about the GDB
8328 breakpoint, and thus trap before the breakpoint instruction is executed.
8329 (If GDB later needs to continue execution past the permanent breakpoint,
8330 it manually increments the PC, thus avoiding executing the breakpoint
8332 if (bp_loc_is_permanent (loc
))
8339 /* Return true if LOC is pointing to a permanent breakpoint,
8340 return false otherwise. */
8343 bp_loc_is_permanent (struct bp_location
*loc
)
8345 gdb_assert (loc
!= NULL
);
8347 /* If we have a non-breakpoint-backed catchpoint or a software
8348 watchpoint, just return 0. We should not attempt to read from
8349 the addresses the locations of these breakpoint types point to.
8350 gdbarch_program_breakpoint_here_p, below, will attempt to read
8352 if (!bl_address_is_meaningful (loc
))
8355 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8356 switch_to_program_space_and_thread (loc
->pspace
);
8357 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8360 /* Build a command list for the dprintf corresponding to the current
8361 settings of the dprintf style options. */
8364 update_dprintf_command_list (struct breakpoint
*b
)
8366 const char *dprintf_args
= b
->extra_string
.get ();
8367 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8372 dprintf_args
= skip_spaces (dprintf_args
);
8374 /* Allow a comma, as it may have terminated a location, but don't
8376 if (*dprintf_args
== ',')
8378 dprintf_args
= skip_spaces (dprintf_args
);
8380 if (*dprintf_args
!= '"')
8381 error (_("Bad format string, missing '\"'."));
8383 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8384 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8385 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8387 if (dprintf_function
.empty ())
8388 error (_("No function supplied for dprintf call"));
8390 if (!dprintf_channel
.empty ())
8391 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8392 dprintf_function
.c_str (),
8393 dprintf_channel
.c_str (),
8396 printf_line
= xstrprintf ("call (void) %s (%s)",
8397 dprintf_function
.c_str (),
8400 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8402 if (target_can_run_breakpoint_commands ())
8403 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8406 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8407 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8411 internal_error (__FILE__
, __LINE__
,
8412 _("Invalid dprintf style."));
8414 gdb_assert (printf_line
!= NULL
);
8416 /* Manufacture a printf sequence. */
8417 struct command_line
*printf_cmd_line
8418 = new struct command_line (simple_control
, printf_line
.release ());
8419 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8420 command_lines_deleter ()));
8423 /* Update all dprintf commands, making their command lists reflect
8424 current style settings. */
8427 update_dprintf_commands (const char *args
, int from_tty
,
8428 struct cmd_list_element
*c
)
8430 for (breakpoint
*b
: all_breakpoints ())
8431 if (b
->type
== bp_dprintf
)
8432 update_dprintf_command_list (b
);
8435 /* Create a breakpoint with SAL as location. Use LOCATION
8436 as a description of the location, and COND_STRING
8437 as condition expression. If LOCATION is NULL then create an
8438 "address location" from the address in the SAL. */
8441 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8442 gdb::array_view
<const symtab_and_line
> sals
,
8443 event_location_up
&&location
,
8444 gdb::unique_xmalloc_ptr
<char> filter
,
8445 gdb::unique_xmalloc_ptr
<char> cond_string
,
8446 gdb::unique_xmalloc_ptr
<char> extra_string
,
8447 enum bptype type
, enum bpdisp disposition
,
8448 int thread
, int task
, int ignore_count
,
8449 const struct breakpoint_ops
*ops
, int from_tty
,
8450 int enabled
, int internal
, unsigned flags
,
8451 int display_canonical
)
8455 if (type
== bp_hardware_breakpoint
)
8457 int target_resources_ok
;
8459 i
= hw_breakpoint_used_count ();
8460 target_resources_ok
=
8461 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8463 if (target_resources_ok
== 0)
8464 error (_("No hardware breakpoint support in the target."));
8465 else if (target_resources_ok
< 0)
8466 error (_("Hardware breakpoints used exceeds limit."));
8469 gdb_assert (!sals
.empty ());
8471 for (const auto &sal
: sals
)
8473 struct bp_location
*loc
;
8477 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8479 loc_gdbarch
= gdbarch
;
8481 describe_other_breakpoints (loc_gdbarch
,
8482 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8485 if (&sal
== &sals
[0])
8487 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8491 b
->cond_string
= std::move (cond_string
);
8492 b
->extra_string
= std::move (extra_string
);
8493 b
->ignore_count
= ignore_count
;
8494 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8495 b
->disposition
= disposition
;
8497 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8498 b
->loc
->inserted
= 1;
8500 if (type
== bp_static_tracepoint
)
8502 struct tracepoint
*t
= (struct tracepoint
*) b
;
8503 struct static_tracepoint_marker marker
;
8505 if (strace_marker_p (b
))
8507 /* We already know the marker exists, otherwise, we
8508 wouldn't see a sal for it. */
8510 = &event_location_to_string (b
->location
.get ())[3];
8513 p
= skip_spaces (p
);
8515 endp
= skip_to_space (p
);
8517 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8519 gdb_printf (_("Probed static tracepoint "
8521 t
->static_trace_marker_id
.c_str ());
8523 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8525 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8527 gdb_printf (_("Probed static tracepoint "
8529 t
->static_trace_marker_id
.c_str ());
8532 warning (_("Couldn't determine the static "
8533 "tracepoint marker to probe"));
8540 loc
= add_location_to_breakpoint (b
, &sal
);
8541 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8545 /* Do not set breakpoint locations conditions yet. As locations
8546 are inserted, they get sorted based on their addresses. Let
8547 the list stabilize to have reliable location numbers. */
8549 /* Dynamic printf requires and uses additional arguments on the
8550 command line, otherwise it's an error. */
8551 if (type
== bp_dprintf
)
8553 if (b
->extra_string
)
8554 update_dprintf_command_list (b
);
8556 error (_("Format string required"));
8558 else if (b
->extra_string
)
8559 error (_("Garbage '%s' at end of command"), b
->extra_string
.get ());
8563 /* The order of the locations is now stable. Set the location
8564 condition using the location's number. */
8566 for (bp_location
*loc
: b
->locations ())
8568 if (b
->cond_string
!= nullptr)
8569 set_breakpoint_location_condition (b
->cond_string
.get (), loc
,
8570 b
->number
, loc_num
);
8575 b
->display_canonical
= display_canonical
;
8576 if (location
!= NULL
)
8577 b
->location
= std::move (location
);
8579 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8580 b
->filter
= std::move (filter
);
8584 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8585 gdb::array_view
<const symtab_and_line
> sals
,
8586 event_location_up
&&location
,
8587 gdb::unique_xmalloc_ptr
<char> filter
,
8588 gdb::unique_xmalloc_ptr
<char> cond_string
,
8589 gdb::unique_xmalloc_ptr
<char> extra_string
,
8590 enum bptype type
, enum bpdisp disposition
,
8591 int thread
, int task
, int ignore_count
,
8592 const struct breakpoint_ops
*ops
, int from_tty
,
8593 int enabled
, int internal
, unsigned flags
,
8594 int display_canonical
)
8596 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8598 init_breakpoint_sal (b
.get (), gdbarch
,
8599 sals
, std::move (location
),
8601 std::move (cond_string
),
8602 std::move (extra_string
),
8604 thread
, task
, ignore_count
,
8606 enabled
, internal
, flags
,
8609 install_breakpoint (internal
, std::move (b
), 0);
8612 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8613 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8614 value. COND_STRING, if not NULL, specified the condition to be
8615 used for all breakpoints. Essentially the only case where
8616 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8617 function. In that case, it's still not possible to specify
8618 separate conditions for different overloaded functions, so
8619 we take just a single condition string.
8621 NOTE: If the function succeeds, the caller is expected to cleanup
8622 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8623 array contents). If the function fails (error() is called), the
8624 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8625 COND and SALS arrays and each of those arrays contents. */
8628 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8629 struct linespec_result
*canonical
,
8630 gdb::unique_xmalloc_ptr
<char> cond_string
,
8631 gdb::unique_xmalloc_ptr
<char> extra_string
,
8632 enum bptype type
, enum bpdisp disposition
,
8633 int thread
, int task
, int ignore_count
,
8634 const struct breakpoint_ops
*ops
, int from_tty
,
8635 int enabled
, int internal
, unsigned flags
)
8637 if (canonical
->pre_expanded
)
8638 gdb_assert (canonical
->lsals
.size () == 1);
8640 for (const auto &lsal
: canonical
->lsals
)
8642 /* Note that 'location' can be NULL in the case of a plain
8643 'break', without arguments. */
8644 event_location_up location
8645 = (canonical
->location
!= NULL
8646 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8647 gdb::unique_xmalloc_ptr
<char> filter_string
8648 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8650 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8651 std::move (location
),
8652 std::move (filter_string
),
8653 std::move (cond_string
),
8654 std::move (extra_string
),
8656 thread
, task
, ignore_count
, ops
,
8657 from_tty
, enabled
, internal
, flags
,
8658 canonical
->special_display
);
8662 /* Parse LOCATION which is assumed to be a SAL specification possibly
8663 followed by conditionals. On return, SALS contains an array of SAL
8664 addresses found. LOCATION points to the end of the SAL (for
8665 linespec locations).
8667 The array and the line spec strings are allocated on the heap, it is
8668 the caller's responsibility to free them. */
8671 parse_breakpoint_sals (struct event_location
*location
,
8672 struct linespec_result
*canonical
)
8674 struct symtab_and_line cursal
;
8676 if (event_location_type (location
) == LINESPEC_LOCATION
)
8678 const char *spec
= get_linespec_location (location
)->spec_string
;
8682 /* The last displayed codepoint, if it's valid, is our default
8683 breakpoint address. */
8684 if (last_displayed_sal_is_valid ())
8686 /* Set sal's pspace, pc, symtab, and line to the values
8687 corresponding to the last call to print_frame_info.
8688 Be sure to reinitialize LINE with NOTCURRENT == 0
8689 as the breakpoint line number is inappropriate otherwise.
8690 find_pc_line would adjust PC, re-set it back. */
8691 symtab_and_line sal
= get_last_displayed_sal ();
8692 CORE_ADDR pc
= sal
.pc
;
8694 sal
= find_pc_line (pc
, 0);
8696 /* "break" without arguments is equivalent to "break *PC"
8697 where PC is the last displayed codepoint's address. So
8698 make sure to set sal.explicit_pc to prevent GDB from
8699 trying to expand the list of sals to include all other
8700 instances with the same symtab and line. */
8702 sal
.explicit_pc
= 1;
8704 struct linespec_sals lsal
;
8706 lsal
.canonical
= NULL
;
8708 canonical
->lsals
.push_back (std::move (lsal
));
8712 error (_("No default breakpoint address now."));
8716 /* Force almost all breakpoints to be in terms of the
8717 current_source_symtab (which is decode_line_1's default).
8718 This should produce the results we want almost all of the
8719 time while leaving default_breakpoint_* alone.
8721 ObjC: However, don't match an Objective-C method name which
8722 may have a '+' or '-' succeeded by a '['. */
8723 cursal
= get_current_source_symtab_and_line ();
8724 if (last_displayed_sal_is_valid ())
8726 const char *spec
= NULL
;
8728 if (event_location_type (location
) == LINESPEC_LOCATION
)
8729 spec
= get_linespec_location (location
)->spec_string
;
8733 && strchr ("+-", spec
[0]) != NULL
8736 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8737 get_last_displayed_symtab (),
8738 get_last_displayed_line (),
8739 canonical
, NULL
, NULL
);
8744 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8745 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8749 /* Convert each SAL into a real PC. Verify that the PC can be
8750 inserted as a breakpoint. If it can't throw an error. */
8753 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8755 for (auto &sal
: sals
)
8756 resolve_sal_pc (&sal
);
8759 /* Fast tracepoints may have restrictions on valid locations. For
8760 instance, a fast tracepoint using a jump instead of a trap will
8761 likely have to overwrite more bytes than a trap would, and so can
8762 only be placed where the instruction is longer than the jump, or a
8763 multi-instruction sequence does not have a jump into the middle of
8767 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8768 gdb::array_view
<const symtab_and_line
> sals
)
8770 for (const auto &sal
: sals
)
8772 struct gdbarch
*sarch
;
8774 sarch
= get_sal_arch (sal
);
8775 /* We fall back to GDBARCH if there is no architecture
8776 associated with SAL. */
8780 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8781 error (_("May not have a fast tracepoint at %s%s"),
8782 paddress (sarch
, sal
.pc
), msg
.c_str ());
8786 /* Given TOK, a string specification of condition and thread, as
8787 accepted by the 'break' command, extract the condition
8788 string and thread number and set *COND_STRING and *THREAD.
8789 PC identifies the context at which the condition should be parsed.
8790 If no condition is found, *COND_STRING is set to NULL.
8791 If no thread is found, *THREAD is set to -1. */
8794 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8795 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8796 int *thread
, int *task
,
8797 gdb::unique_xmalloc_ptr
<char> *rest
)
8799 cond_string
->reset ();
8807 const char *end_tok
;
8809 const char *cond_start
= NULL
;
8810 const char *cond_end
= NULL
;
8812 tok
= skip_spaces (tok
);
8814 if ((*tok
== '"' || *tok
== ',') && rest
)
8816 rest
->reset (savestring (tok
, strlen (tok
)));
8820 end_tok
= skip_to_space (tok
);
8822 toklen
= end_tok
- tok
;
8824 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8826 tok
= cond_start
= end_tok
+ 1;
8829 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8831 catch (const gdb_exception_error
&)
8836 tok
= tok
+ strlen (tok
);
8839 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8841 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8846 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8849 struct thread_info
*thr
;
8852 thr
= parse_thread_id (tok
, &tmptok
);
8854 error (_("Junk after thread keyword."));
8855 *thread
= thr
->global_num
;
8858 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8863 *task
= strtol (tok
, &tmptok
, 0);
8865 error (_("Junk after task keyword."));
8866 if (!valid_task_id (*task
))
8867 error (_("Unknown task %d."), *task
);
8872 rest
->reset (savestring (tok
, strlen (tok
)));
8876 error (_("Junk at end of arguments."));
8880 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8881 succeeds. The parsed values are written to COND_STRING, THREAD,
8882 TASK, and REST. See the comment of 'find_condition_and_thread'
8883 for the description of these parameters and INPUT. */
8886 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8888 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8889 int *thread
, int *task
,
8890 gdb::unique_xmalloc_ptr
<char> *rest
)
8892 int num_failures
= 0;
8893 for (auto &sal
: sals
)
8895 gdb::unique_xmalloc_ptr
<char> cond
;
8898 gdb::unique_xmalloc_ptr
<char> remaining
;
8900 /* Here we want to parse 'arg' to separate condition from thread
8901 number. But because parsing happens in a context and the
8902 contexts of sals might be different, try each until there is
8903 success. Finding one successful parse is sufficient for our
8904 goal. When setting the breakpoint we'll re-parse the
8905 condition in the context of each sal. */
8908 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8909 &task_id
, &remaining
);
8910 *cond_string
= std::move (cond
);
8911 *thread
= thread_id
;
8913 *rest
= std::move (remaining
);
8916 catch (const gdb_exception_error
&e
)
8919 /* If no sal remains, do not continue. */
8920 if (num_failures
== sals
.size ())
8926 /* Decode a static tracepoint marker spec. */
8928 static std::vector
<symtab_and_line
>
8929 decode_static_tracepoint_spec (const char **arg_p
)
8931 const char *p
= &(*arg_p
)[3];
8934 p
= skip_spaces (p
);
8936 endp
= skip_to_space (p
);
8938 std::string
marker_str (p
, endp
- p
);
8940 std::vector
<static_tracepoint_marker
> markers
8941 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8942 if (markers
.empty ())
8943 error (_("No known static tracepoint marker named %s"),
8944 marker_str
.c_str ());
8946 std::vector
<symtab_and_line
> sals
;
8947 sals
.reserve (markers
.size ());
8949 for (const static_tracepoint_marker
&marker
: markers
)
8951 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8952 sal
.pc
= marker
.address
;
8953 sals
.push_back (sal
);
8960 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8961 according to IS_TRACEPOINT. */
8963 static const struct breakpoint_ops
*
8964 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
8969 if (location_type
== PROBE_LOCATION
)
8970 return &tracepoint_probe_breakpoint_ops
;
8972 return &tracepoint_breakpoint_ops
;
8976 if (location_type
== PROBE_LOCATION
)
8977 return &bkpt_probe_breakpoint_ops
;
8979 return &bkpt_breakpoint_ops
;
8983 /* See breakpoint.h. */
8985 const struct breakpoint_ops
*
8986 breakpoint_ops_for_event_location (const struct event_location
*location
,
8989 if (location
!= nullptr)
8990 return breakpoint_ops_for_event_location_type
8991 (event_location_type (location
), is_tracepoint
);
8992 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
8995 /* See breakpoint.h. */
8998 create_breakpoint (struct gdbarch
*gdbarch
,
8999 struct event_location
*location
,
9000 const char *cond_string
,
9001 int thread
, const char *extra_string
,
9002 bool force_condition
, int parse_extra
,
9003 int tempflag
, enum bptype type_wanted
,
9005 enum auto_boolean pending_break_support
,
9006 const struct breakpoint_ops
*ops
,
9007 int from_tty
, int enabled
, int internal
,
9010 struct linespec_result canonical
;
9013 int prev_bkpt_count
= breakpoint_count
;
9015 gdb_assert (ops
!= NULL
);
9017 /* If extra_string isn't useful, set it to NULL. */
9018 if (extra_string
!= NULL
&& *extra_string
== '\0')
9019 extra_string
= NULL
;
9023 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9025 catch (const gdb_exception_error
&e
)
9027 /* If caller is interested in rc value from parse, set
9029 if (e
.error
== NOT_FOUND_ERROR
)
9031 /* If pending breakpoint support is turned off, throw
9034 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9037 exception_print (gdb_stderr
, e
);
9039 /* If pending breakpoint support is auto query and the user
9040 selects no, then simply return the error code. */
9041 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9042 && !nquery (_("Make %s pending on future shared library load? "),
9043 bptype_string (type_wanted
)))
9046 /* At this point, either the user was queried about setting
9047 a pending breakpoint and selected yes, or pending
9048 breakpoint behavior is on and thus a pending breakpoint
9049 is defaulted on behalf of the user. */
9056 if (!pending
&& canonical
.lsals
.empty ())
9059 /* Resolve all line numbers to PC's and verify that the addresses
9060 are ok for the target. */
9063 for (auto &lsal
: canonical
.lsals
)
9064 breakpoint_sals_to_pc (lsal
.sals
);
9067 /* Fast tracepoints may have additional restrictions on location. */
9068 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9070 for (const auto &lsal
: canonical
.lsals
)
9071 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9074 /* Verify that condition can be parsed, before setting any
9075 breakpoints. Allocate a separate condition expression for each
9079 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9080 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9084 gdb::unique_xmalloc_ptr
<char> rest
;
9085 gdb::unique_xmalloc_ptr
<char> cond
;
9087 const linespec_sals
&lsal
= canonical
.lsals
[0];
9089 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9090 &cond
, &thread
, &task
, &rest
);
9091 cond_string_copy
= std::move (cond
);
9092 extra_string_copy
= std::move (rest
);
9096 if (type_wanted
!= bp_dprintf
9097 && extra_string
!= NULL
&& *extra_string
!= '\0')
9098 error (_("Garbage '%s' at end of location"), extra_string
);
9100 /* Check the validity of the condition. We should error out
9101 if the condition is invalid at all of the locations and
9102 if it is not forced. In the PARSE_EXTRA case above, this
9103 check is done when parsing the EXTRA_STRING. */
9104 if (cond_string
!= nullptr && !force_condition
)
9106 int num_failures
= 0;
9107 const linespec_sals
&lsal
= canonical
.lsals
[0];
9108 for (const auto &sal
: lsal
.sals
)
9110 const char *cond
= cond_string
;
9113 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9114 /* One success is sufficient to keep going. */
9117 catch (const gdb_exception_error
&)
9120 /* If this is the last sal, error out. */
9121 if (num_failures
== lsal
.sals
.size ())
9127 /* Create a private copy of condition string. */
9129 cond_string_copy
.reset (xstrdup (cond_string
));
9130 /* Create a private copy of any extra string. */
9132 extra_string_copy
.reset (xstrdup (extra_string
));
9135 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9136 std::move (cond_string_copy
),
9137 std::move (extra_string_copy
),
9139 tempflag
? disp_del
: disp_donttouch
,
9140 thread
, task
, ignore_count
, ops
,
9141 from_tty
, enabled
, internal
, flags
);
9145 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9147 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9148 b
->location
= copy_event_location (location
);
9151 b
->cond_string
= NULL
;
9154 /* Create a private copy of condition string. */
9155 b
->cond_string
.reset (cond_string
!= NULL
9156 ? xstrdup (cond_string
)
9161 /* Create a private copy of any extra string. */
9162 b
->extra_string
.reset (extra_string
!= NULL
9163 ? xstrdup (extra_string
)
9165 b
->ignore_count
= ignore_count
;
9166 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9167 b
->condition_not_parsed
= 1;
9168 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9169 if ((type_wanted
!= bp_breakpoint
9170 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9171 b
->pspace
= current_program_space
;
9173 install_breakpoint (internal
, std::move (b
), 0);
9176 if (canonical
.lsals
.size () > 1)
9178 warning (_("Multiple breakpoints were set.\nUse the "
9179 "\"delete\" command to delete unwanted breakpoints."));
9180 prev_breakpoint_count
= prev_bkpt_count
;
9183 update_global_location_list (UGLL_MAY_INSERT
);
9188 /* Set a breakpoint.
9189 ARG is a string describing breakpoint address,
9190 condition, and thread.
9191 FLAG specifies if a breakpoint is hardware on,
9192 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9196 break_command_1 (const char *arg
, int flag
, int from_tty
)
9198 int tempflag
= flag
& BP_TEMPFLAG
;
9199 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9200 ? bp_hardware_breakpoint
9203 event_location_up location
= string_to_event_location (&arg
, current_language
);
9204 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9205 (location
.get (), false /* is_tracepoint */);
9207 create_breakpoint (get_current_arch (),
9209 NULL
, 0, arg
, false, 1 /* parse arg */,
9210 tempflag
, type_wanted
,
9211 0 /* Ignore count */,
9212 pending_break_support
,
9220 /* Helper function for break_command_1 and disassemble_command. */
9223 resolve_sal_pc (struct symtab_and_line
*sal
)
9227 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9229 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9230 error (_("No line %d in file \"%s\"."),
9231 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9234 /* If this SAL corresponds to a breakpoint inserted using a line
9235 number, then skip the function prologue if necessary. */
9236 if (sal
->explicit_line
)
9237 skip_prologue_sal (sal
);
9240 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9242 const struct blockvector
*bv
;
9243 const struct block
*b
;
9246 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9247 sal
->symtab
->compunit ());
9250 sym
= block_linkage_function (b
);
9253 fixup_symbol_section (sym
, sal
->symtab
->compunit ()->objfile ());
9255 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9259 /* It really is worthwhile to have the section, so we'll
9260 just have to look harder. This case can be executed
9261 if we have line numbers but no functions (as can
9262 happen in assembly source). */
9264 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9265 switch_to_program_space_and_thread (sal
->pspace
);
9267 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9269 sal
->section
= msym
.obj_section ();
9276 break_command (const char *arg
, int from_tty
)
9278 break_command_1 (arg
, 0, from_tty
);
9282 tbreak_command (const char *arg
, int from_tty
)
9284 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9288 hbreak_command (const char *arg
, int from_tty
)
9290 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9294 thbreak_command (const char *arg
, int from_tty
)
9296 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9299 /* The dynamic printf command is mostly like a regular breakpoint, but
9300 with a prewired command list consisting of a single output command,
9301 built from extra arguments supplied on the dprintf command
9305 dprintf_command (const char *arg
, int from_tty
)
9307 event_location_up location
= string_to_event_location (&arg
, current_language
);
9309 /* If non-NULL, ARG should have been advanced past the location;
9310 the next character must be ','. */
9313 if (arg
[0] != ',' || arg
[1] == '\0')
9314 error (_("Format string required"));
9317 /* Skip the comma. */
9322 create_breakpoint (get_current_arch (),
9324 NULL
, 0, arg
, false, 1 /* parse arg */,
9326 0 /* Ignore count */,
9327 pending_break_support
,
9328 &dprintf_breakpoint_ops
,
9336 agent_printf_command (const char *arg
, int from_tty
)
9338 error (_("May only run agent-printf on the target"));
9341 /* Implement the "breakpoint_hit" breakpoint_ops method for
9342 ranged breakpoints. */
9345 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9346 const address_space
*aspace
,
9348 const target_waitstatus
&ws
)
9350 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9351 || ws
.sig () != GDB_SIGNAL_TRAP
)
9354 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9355 bl
->length
, aspace
, bp_addr
);
9358 /* Implement the "resources_needed" breakpoint_ops method for
9359 ranged breakpoints. */
9362 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9364 return target_ranged_break_num_registers ();
9367 /* Implement the "print_it" breakpoint_ops method for
9368 ranged breakpoints. */
9370 static enum print_stop_action
9371 print_it_ranged_breakpoint (bpstat
*bs
)
9373 struct breakpoint
*b
= bs
->breakpoint_at
;
9374 struct bp_location
*bl
= b
->loc
;
9375 struct ui_out
*uiout
= current_uiout
;
9377 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9379 /* Ranged breakpoints have only one location. */
9380 gdb_assert (bl
&& bl
->next
== NULL
);
9382 annotate_breakpoint (b
->number
);
9384 maybe_print_thread_hit_breakpoint (uiout
);
9386 if (b
->disposition
== disp_del
)
9387 uiout
->text ("Temporary ranged breakpoint ");
9389 uiout
->text ("Ranged breakpoint ");
9390 if (uiout
->is_mi_like_p ())
9392 uiout
->field_string ("reason",
9393 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9394 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9396 uiout
->field_signed ("bkptno", b
->number
);
9399 return PRINT_SRC_AND_LOC
;
9402 /* Implement the "print_one" breakpoint_ops method for
9403 ranged breakpoints. */
9406 print_one_ranged_breakpoint (struct breakpoint
*b
,
9407 struct bp_location
**last_loc
)
9409 struct bp_location
*bl
= b
->loc
;
9410 struct value_print_options opts
;
9411 struct ui_out
*uiout
= current_uiout
;
9413 /* Ranged breakpoints have only one location. */
9414 gdb_assert (bl
&& bl
->next
== NULL
);
9416 get_user_print_options (&opts
);
9418 if (opts
.addressprint
)
9419 /* We don't print the address range here, it will be printed later
9420 by print_one_detail_ranged_breakpoint. */
9421 uiout
->field_skip ("addr");
9423 print_breakpoint_location (b
, bl
);
9427 /* Implement the "print_one_detail" breakpoint_ops method for
9428 ranged breakpoints. */
9431 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9432 struct ui_out
*uiout
)
9434 CORE_ADDR address_start
, address_end
;
9435 struct bp_location
*bl
= b
->loc
;
9440 address_start
= bl
->address
;
9441 address_end
= address_start
+ bl
->length
- 1;
9443 uiout
->text ("\taddress range: ");
9444 stb
.printf ("[%s, %s]",
9445 print_core_address (bl
->gdbarch
, address_start
),
9446 print_core_address (bl
->gdbarch
, address_end
));
9447 uiout
->field_stream ("addr", stb
);
9451 /* Implement the "print_mention" breakpoint_ops method for
9452 ranged breakpoints. */
9455 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9457 struct bp_location
*bl
= b
->loc
;
9458 struct ui_out
*uiout
= current_uiout
;
9461 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9463 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9464 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9465 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9468 /* Implement the "print_recreate" breakpoint_ops method for
9469 ranged breakpoints. */
9472 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9474 gdb_printf (fp
, "break-range %s, %s",
9475 event_location_to_string (b
->location
.get ()),
9476 event_location_to_string (b
->location_range_end
.get ()));
9477 print_recreate_thread (b
, fp
);
9480 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9482 static struct breakpoint_ops ranged_breakpoint_ops
;
9484 /* Find the address where the end of the breakpoint range should be
9485 placed, given the SAL of the end of the range. This is so that if
9486 the user provides a line number, the end of the range is set to the
9487 last instruction of the given line. */
9490 find_breakpoint_range_end (struct symtab_and_line sal
)
9494 /* If the user provided a PC value, use it. Otherwise,
9495 find the address of the end of the given location. */
9496 if (sal
.explicit_pc
)
9503 ret
= find_line_pc_range (sal
, &start
, &end
);
9505 error (_("Could not find location of the end of the range."));
9507 /* find_line_pc_range returns the start of the next line. */
9514 /* Implement the "break-range" CLI command. */
9517 break_range_command (const char *arg
, int from_tty
)
9519 const char *arg_start
;
9520 struct linespec_result canonical_start
, canonical_end
;
9521 int bp_count
, can_use_bp
, length
;
9523 struct breakpoint
*b
;
9525 /* We don't support software ranged breakpoints. */
9526 if (target_ranged_break_num_registers () < 0)
9527 error (_("This target does not support hardware ranged breakpoints."));
9529 bp_count
= hw_breakpoint_used_count ();
9530 bp_count
+= target_ranged_break_num_registers ();
9531 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9534 error (_("Hardware breakpoints used exceeds limit."));
9536 arg
= skip_spaces (arg
);
9537 if (arg
== NULL
|| arg
[0] == '\0')
9538 error(_("No address range specified."));
9541 event_location_up start_location
= string_to_event_location (&arg
,
9543 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9546 error (_("Too few arguments."));
9547 else if (canonical_start
.lsals
.empty ())
9548 error (_("Could not find location of the beginning of the range."));
9550 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9552 if (canonical_start
.lsals
.size () > 1
9553 || lsal_start
.sals
.size () != 1)
9554 error (_("Cannot create a ranged breakpoint with multiple locations."));
9556 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9557 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9559 arg
++; /* Skip the comma. */
9560 arg
= skip_spaces (arg
);
9562 /* Parse the end location. */
9566 /* We call decode_line_full directly here instead of using
9567 parse_breakpoint_sals because we need to specify the start location's
9568 symtab and line as the default symtab and line for the end of the
9569 range. This makes it possible to have ranges like "foo.c:27, +14",
9570 where +14 means 14 lines from the start location. */
9571 event_location_up end_location
= string_to_event_location (&arg
,
9573 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9574 sal_start
.symtab
, sal_start
.line
,
9575 &canonical_end
, NULL
, NULL
);
9577 if (canonical_end
.lsals
.empty ())
9578 error (_("Could not find location of the end of the range."));
9580 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9581 if (canonical_end
.lsals
.size () > 1
9582 || lsal_end
.sals
.size () != 1)
9583 error (_("Cannot create a ranged breakpoint with multiple locations."));
9585 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9587 end
= find_breakpoint_range_end (sal_end
);
9588 if (sal_start
.pc
> end
)
9589 error (_("Invalid address range, end precedes start."));
9591 length
= end
- sal_start
.pc
+ 1;
9593 /* Length overflowed. */
9594 error (_("Address range too large."));
9595 else if (length
== 1)
9597 /* This range is simple enough to be handled by
9598 the `hbreak' command. */
9599 hbreak_command (&addr_string_start
[0], 1);
9604 /* Now set up the breakpoint. */
9605 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9606 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9607 set_breakpoint_count (breakpoint_count
+ 1);
9608 b
->number
= breakpoint_count
;
9609 b
->disposition
= disp_donttouch
;
9610 b
->location
= std::move (start_location
);
9611 b
->location_range_end
= std::move (end_location
);
9612 b
->loc
->length
= length
;
9615 gdb::observers::breakpoint_created
.notify (b
);
9616 update_global_location_list (UGLL_MAY_INSERT
);
9619 /* Return non-zero if EXP is verified as constant. Returned zero
9620 means EXP is variable. Also the constant detection may fail for
9621 some constant expressions and in such case still falsely return
9625 watchpoint_exp_is_const (const struct expression
*exp
)
9627 return exp
->op
->constant_p ();
9630 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9633 re_set_watchpoint (struct breakpoint
*b
)
9635 struct watchpoint
*w
= (struct watchpoint
*) b
;
9637 /* Watchpoint can be either on expression using entirely global
9638 variables, or it can be on local variables.
9640 Watchpoints of the first kind are never auto-deleted, and even
9641 persist across program restarts. Since they can use variables
9642 from shared libraries, we need to reparse expression as libraries
9643 are loaded and unloaded.
9645 Watchpoints on local variables can also change meaning as result
9646 of solib event. For example, if a watchpoint uses both a local
9647 and a global variables in expression, it's a local watchpoint,
9648 but unloading of a shared library will make the expression
9649 invalid. This is not a very common use case, but we still
9650 re-evaluate expression, to avoid surprises to the user.
9652 Note that for local watchpoints, we re-evaluate it only if
9653 watchpoints frame id is still valid. If it's not, it means the
9654 watchpoint is out of scope and will be deleted soon. In fact,
9655 I'm not sure we'll ever be called in this case.
9657 If a local watchpoint's frame id is still valid, then
9658 w->exp_valid_block is likewise valid, and we can safely use it.
9660 Don't do anything about disabled watchpoints, since they will be
9661 reevaluated again when enabled. */
9662 update_watchpoint (w
, 1 /* reparse */);
9665 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9668 insert_watchpoint (struct bp_location
*bl
)
9670 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9671 int length
= w
->exact
? 1 : bl
->length
;
9673 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9674 w
->cond_exp
.get ());
9677 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9680 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
9682 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9683 int length
= w
->exact
? 1 : bl
->length
;
9685 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9686 w
->cond_exp
.get ());
9690 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
9691 const address_space
*aspace
, CORE_ADDR bp_addr
,
9692 const target_waitstatus
&ws
)
9694 struct breakpoint
*b
= bl
->owner
;
9695 struct watchpoint
*w
= (struct watchpoint
*) b
;
9697 /* Continuable hardware watchpoints are treated as non-existent if the
9698 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9699 some data address). Otherwise gdb won't stop on a break instruction
9700 in the code (not from a breakpoint) when a hardware watchpoint has
9701 been defined. Also skip watchpoints which we know did not trigger
9702 (did not match the data address). */
9703 if (is_hardware_watchpoint (b
)
9704 && w
->watchpoint_triggered
== watch_triggered_no
)
9711 check_status_watchpoint (bpstat
*bs
)
9713 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9715 bpstat_check_watchpoint (bs
);
9718 /* Implement the "resources_needed" breakpoint_ops method for
9719 hardware watchpoints. */
9722 resources_needed_watchpoint (const struct bp_location
*bl
)
9724 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9725 int length
= w
->exact
? 1 : bl
->length
;
9727 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9730 /* Implement the "works_in_software_mode" breakpoint_ops method for
9731 hardware watchpoints. */
9734 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
9736 /* Read and access watchpoints only work with hardware support. */
9737 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
9740 static enum print_stop_action
9741 print_it_watchpoint (bpstat
*bs
)
9743 struct breakpoint
*b
;
9744 enum print_stop_action result
;
9745 struct watchpoint
*w
;
9746 struct ui_out
*uiout
= current_uiout
;
9748 gdb_assert (bs
->bp_location_at
!= NULL
);
9750 b
= bs
->breakpoint_at
;
9751 w
= (struct watchpoint
*) b
;
9753 annotate_watchpoint (b
->number
);
9754 maybe_print_thread_hit_breakpoint (uiout
);
9758 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9762 case bp_hardware_watchpoint
:
9763 if (uiout
->is_mi_like_p ())
9765 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9767 tuple_emitter
.emplace (uiout
, "value");
9768 uiout
->text ("\nOld value = ");
9769 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9770 uiout
->field_stream ("old", stb
);
9771 uiout
->text ("\nNew value = ");
9772 watchpoint_value_print (w
->val
.get (), &stb
);
9773 uiout
->field_stream ("new", stb
);
9775 /* More than one watchpoint may have been triggered. */
9776 result
= PRINT_UNKNOWN
;
9779 case bp_read_watchpoint
:
9780 if (uiout
->is_mi_like_p ())
9782 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9784 tuple_emitter
.emplace (uiout
, "value");
9785 uiout
->text ("\nValue = ");
9786 watchpoint_value_print (w
->val
.get (), &stb
);
9787 uiout
->field_stream ("value", stb
);
9789 result
= PRINT_UNKNOWN
;
9792 case bp_access_watchpoint
:
9793 if (bs
->old_val
!= NULL
)
9795 if (uiout
->is_mi_like_p ())
9798 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9800 tuple_emitter
.emplace (uiout
, "value");
9801 uiout
->text ("\nOld value = ");
9802 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9803 uiout
->field_stream ("old", stb
);
9804 uiout
->text ("\nNew value = ");
9809 if (uiout
->is_mi_like_p ())
9812 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9813 tuple_emitter
.emplace (uiout
, "value");
9814 uiout
->text ("\nValue = ");
9816 watchpoint_value_print (w
->val
.get (), &stb
);
9817 uiout
->field_stream ("new", stb
);
9819 result
= PRINT_UNKNOWN
;
9822 result
= PRINT_UNKNOWN
;
9828 /* Implement the "print_mention" breakpoint_ops method for hardware
9832 print_mention_watchpoint (struct breakpoint
*b
)
9834 struct watchpoint
*w
= (struct watchpoint
*) b
;
9835 struct ui_out
*uiout
= current_uiout
;
9836 const char *tuple_name
;
9841 uiout
->text ("Watchpoint ");
9844 case bp_hardware_watchpoint
:
9845 uiout
->text ("Hardware watchpoint ");
9848 case bp_read_watchpoint
:
9849 uiout
->text ("Hardware read watchpoint ");
9850 tuple_name
= "hw-rwpt";
9852 case bp_access_watchpoint
:
9853 uiout
->text ("Hardware access (read/write) watchpoint ");
9854 tuple_name
= "hw-awpt";
9857 internal_error (__FILE__
, __LINE__
,
9858 _("Invalid hardware watchpoint type."));
9861 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9862 uiout
->field_signed ("number", b
->number
);
9864 uiout
->field_string ("exp", w
->exp_string
.get ());
9867 /* Implement the "print_recreate" breakpoint_ops method for
9871 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9873 struct watchpoint
*w
= (struct watchpoint
*) b
;
9878 case bp_hardware_watchpoint
:
9879 gdb_printf (fp
, "watch");
9881 case bp_read_watchpoint
:
9882 gdb_printf (fp
, "rwatch");
9884 case bp_access_watchpoint
:
9885 gdb_printf (fp
, "awatch");
9888 internal_error (__FILE__
, __LINE__
,
9889 _("Invalid watchpoint type."));
9892 gdb_printf (fp
, " %s", w
->exp_string
.get ());
9893 print_recreate_thread (b
, fp
);
9896 /* Implement the "explains_signal" breakpoint_ops method for
9900 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
9902 /* A software watchpoint cannot cause a signal other than
9904 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9910 /* The breakpoint_ops structure to be used in hardware watchpoints. */
9912 static struct breakpoint_ops watchpoint_breakpoint_ops
;
9914 /* Implement the "insert" breakpoint_ops method for
9915 masked hardware watchpoints. */
9918 insert_masked_watchpoint (struct bp_location
*bl
)
9920 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9922 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9923 bl
->watchpoint_type
);
9926 /* Implement the "remove" breakpoint_ops method for
9927 masked hardware watchpoints. */
9930 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
9932 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9934 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9935 bl
->watchpoint_type
);
9938 /* Implement the "resources_needed" breakpoint_ops method for
9939 masked hardware watchpoints. */
9942 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
9944 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9946 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
9949 /* Implement the "works_in_software_mode" breakpoint_ops method for
9950 masked hardware watchpoints. */
9953 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
9958 /* Implement the "print_it" breakpoint_ops method for
9959 masked hardware watchpoints. */
9961 static enum print_stop_action
9962 print_it_masked_watchpoint (bpstat
*bs
)
9964 struct breakpoint
*b
= bs
->breakpoint_at
;
9965 struct ui_out
*uiout
= current_uiout
;
9967 /* Masked watchpoints have only one location. */
9968 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9970 annotate_watchpoint (b
->number
);
9971 maybe_print_thread_hit_breakpoint (uiout
);
9975 case bp_hardware_watchpoint
:
9976 if (uiout
->is_mi_like_p ())
9978 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9981 case bp_read_watchpoint
:
9982 if (uiout
->is_mi_like_p ())
9984 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9987 case bp_access_watchpoint
:
9988 if (uiout
->is_mi_like_p ())
9991 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9994 internal_error (__FILE__
, __LINE__
,
9995 _("Invalid hardware watchpoint type."));
10000 Check the underlying instruction at PC for the memory\n\
10001 address and value which triggered this watchpoint.\n"));
10002 uiout
->text ("\n");
10004 /* More than one watchpoint may have been triggered. */
10005 return PRINT_UNKNOWN
;
10008 /* Implement the "print_one_detail" breakpoint_ops method for
10009 masked hardware watchpoints. */
10012 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10013 struct ui_out
*uiout
)
10015 struct watchpoint
*w
= (struct watchpoint
*) b
;
10017 /* Masked watchpoints have only one location. */
10018 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10020 uiout
->text ("\tmask ");
10021 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10022 uiout
->text ("\n");
10025 /* Implement the "print_mention" breakpoint_ops method for
10026 masked hardware watchpoints. */
10029 print_mention_masked_watchpoint (struct breakpoint
*b
)
10031 struct watchpoint
*w
= (struct watchpoint
*) b
;
10032 struct ui_out
*uiout
= current_uiout
;
10033 const char *tuple_name
;
10037 case bp_hardware_watchpoint
:
10038 uiout
->text ("Masked hardware watchpoint ");
10039 tuple_name
= "wpt";
10041 case bp_read_watchpoint
:
10042 uiout
->text ("Masked hardware read watchpoint ");
10043 tuple_name
= "hw-rwpt";
10045 case bp_access_watchpoint
:
10046 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10047 tuple_name
= "hw-awpt";
10050 internal_error (__FILE__
, __LINE__
,
10051 _("Invalid hardware watchpoint type."));
10054 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10055 uiout
->field_signed ("number", b
->number
);
10056 uiout
->text (": ");
10057 uiout
->field_string ("exp", w
->exp_string
.get ());
10060 /* Implement the "print_recreate" breakpoint_ops method for
10061 masked hardware watchpoints. */
10064 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10066 struct watchpoint
*w
= (struct watchpoint
*) b
;
10070 case bp_hardware_watchpoint
:
10071 gdb_printf (fp
, "watch");
10073 case bp_read_watchpoint
:
10074 gdb_printf (fp
, "rwatch");
10076 case bp_access_watchpoint
:
10077 gdb_printf (fp
, "awatch");
10080 internal_error (__FILE__
, __LINE__
,
10081 _("Invalid hardware watchpoint type."));
10084 gdb_printf (fp
, " %s mask 0x%s", w
->exp_string
.get (),
10085 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10086 print_recreate_thread (b
, fp
);
10089 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10091 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10093 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10096 is_masked_watchpoint (const struct breakpoint
*b
)
10098 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10101 /* accessflag: hw_write: watch write,
10102 hw_read: watch read,
10103 hw_access: watch access (read or write) */
10105 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10106 bool just_location
, bool internal
)
10108 struct breakpoint
*scope_breakpoint
= NULL
;
10109 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10110 struct value
*result
;
10111 int saved_bitpos
= 0, saved_bitsize
= 0;
10112 const char *exp_start
= NULL
;
10113 const char *exp_end
= NULL
;
10114 const char *tok
, *end_tok
;
10116 const char *cond_start
= NULL
;
10117 const char *cond_end
= NULL
;
10118 enum bptype bp_type
;
10120 /* Flag to indicate whether we are going to use masks for
10121 the hardware watchpoint. */
10122 bool use_mask
= false;
10123 CORE_ADDR mask
= 0;
10126 /* Make sure that we actually have parameters to parse. */
10127 if (arg
!= NULL
&& arg
[0] != '\0')
10129 const char *value_start
;
10131 exp_end
= arg
+ strlen (arg
);
10133 /* Look for "parameter value" pairs at the end
10134 of the arguments string. */
10135 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10137 /* Skip whitespace at the end of the argument list. */
10138 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10141 /* Find the beginning of the last token.
10142 This is the value of the parameter. */
10143 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10145 value_start
= tok
+ 1;
10147 /* Skip whitespace. */
10148 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10153 /* Find the beginning of the second to last token.
10154 This is the parameter itself. */
10155 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10158 toklen
= end_tok
- tok
+ 1;
10160 if (toklen
== 6 && startswith (tok
, "thread"))
10162 struct thread_info
*thr
;
10163 /* At this point we've found a "thread" token, which means
10164 the user is trying to set a watchpoint that triggers
10165 only in a specific thread. */
10169 error(_("You can specify only one thread."));
10171 /* Extract the thread ID from the next token. */
10172 thr
= parse_thread_id (value_start
, &endp
);
10174 /* Check if the user provided a valid thread ID. */
10175 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10176 invalid_thread_id_error (value_start
);
10178 thread
= thr
->global_num
;
10180 else if (toklen
== 4 && startswith (tok
, "task"))
10184 task
= strtol (value_start
, &tmp
, 0);
10185 if (tmp
== value_start
)
10186 error (_("Junk after task keyword."));
10187 if (!valid_task_id (task
))
10188 error (_("Unknown task %d."), task
);
10190 else if (toklen
== 4 && startswith (tok
, "mask"))
10192 /* We've found a "mask" token, which means the user wants to
10193 create a hardware watchpoint that is going to have the mask
10195 struct value
*mask_value
, *mark
;
10198 error(_("You can specify only one mask."));
10200 use_mask
= just_location
= true;
10202 mark
= value_mark ();
10203 mask_value
= parse_to_comma_and_eval (&value_start
);
10204 mask
= value_as_address (mask_value
);
10205 value_free_to_mark (mark
);
10208 /* We didn't recognize what we found. We should stop here. */
10211 /* Truncate the string and get rid of the "parameter value" pair before
10212 the arguments string is parsed by the parse_exp_1 function. */
10219 /* Parse the rest of the arguments. From here on out, everything
10220 is in terms of a newly allocated string instead of the original
10222 std::string
expression (arg
, exp_end
- arg
);
10223 exp_start
= arg
= expression
.c_str ();
10224 innermost_block_tracker tracker
;
10225 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10227 /* Remove trailing whitespace from the expression before saving it.
10228 This makes the eventual display of the expression string a bit
10230 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10233 /* Checking if the expression is not constant. */
10234 if (watchpoint_exp_is_const (exp
.get ()))
10238 len
= exp_end
- exp_start
;
10239 while (len
> 0 && isspace (exp_start
[len
- 1]))
10241 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10244 exp_valid_block
= tracker
.block ();
10245 struct value
*mark
= value_mark ();
10246 struct value
*val_as_value
= nullptr;
10247 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10250 if (val_as_value
!= NULL
&& just_location
)
10252 saved_bitpos
= value_bitpos (val_as_value
);
10253 saved_bitsize
= value_bitsize (val_as_value
);
10261 exp_valid_block
= NULL
;
10262 val
= release_value (value_addr (result
));
10263 value_free_to_mark (mark
);
10267 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10270 error (_("This target does not support masked watchpoints."));
10271 else if (ret
== -2)
10272 error (_("Invalid mask or memory region."));
10275 else if (val_as_value
!= NULL
)
10276 val
= release_value (val_as_value
);
10278 tok
= skip_spaces (arg
);
10279 end_tok
= skip_to_space (tok
);
10281 toklen
= end_tok
- tok
;
10282 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10284 tok
= cond_start
= end_tok
+ 1;
10285 innermost_block_tracker if_tracker
;
10286 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10288 /* The watchpoint expression may not be local, but the condition
10289 may still be. E.g.: `watch global if local > 0'. */
10290 cond_exp_valid_block
= if_tracker
.block ();
10295 error (_("Junk at end of command."));
10297 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10299 /* Save this because create_internal_breakpoint below invalidates
10301 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10303 /* If the expression is "local", then set up a "watchpoint scope"
10304 breakpoint at the point where we've left the scope of the watchpoint
10305 expression. Create the scope breakpoint before the watchpoint, so
10306 that we will encounter it first in bpstat_stop_status. */
10307 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10309 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10311 if (frame_id_p (caller_frame_id
))
10313 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10314 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10317 = create_internal_breakpoint (caller_arch
, caller_pc
,
10318 bp_watchpoint_scope
,
10319 &momentary_breakpoint_ops
);
10321 /* create_internal_breakpoint could invalidate WP_FRAME. */
10324 scope_breakpoint
->enable_state
= bp_enabled
;
10326 /* Automatically delete the breakpoint when it hits. */
10327 scope_breakpoint
->disposition
= disp_del
;
10329 /* Only break in the proper frame (help with recursion). */
10330 scope_breakpoint
->frame_id
= caller_frame_id
;
10332 /* Set the address at which we will stop. */
10333 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10334 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10335 scope_breakpoint
->loc
->address
10336 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10337 scope_breakpoint
->loc
->requested_address
,
10338 scope_breakpoint
->type
);
10342 /* Now set up the breakpoint. We create all watchpoints as hardware
10343 watchpoints here even if hardware watchpoints are turned off, a call
10344 to update_watchpoint later in this function will cause the type to
10345 drop back to bp_watchpoint (software watchpoint) if required. */
10347 if (accessflag
== hw_read
)
10348 bp_type
= bp_read_watchpoint
;
10349 else if (accessflag
== hw_access
)
10350 bp_type
= bp_access_watchpoint
;
10352 bp_type
= bp_hardware_watchpoint
;
10354 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10357 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10358 &masked_watchpoint_breakpoint_ops
);
10360 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10361 &watchpoint_breakpoint_ops
);
10362 w
->thread
= thread
;
10364 w
->disposition
= disp_donttouch
;
10365 w
->pspace
= current_program_space
;
10366 w
->exp
= std::move (exp
);
10367 w
->exp_valid_block
= exp_valid_block
;
10368 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10371 struct type
*t
= value_type (val
.get ());
10372 CORE_ADDR addr
= value_as_address (val
.get ());
10374 w
->exp_string_reparse
10375 = current_language
->watch_location_expression (t
, addr
);
10377 w
->exp_string
= xstrprintf ("-location %.*s",
10378 (int) (exp_end
- exp_start
), exp_start
);
10381 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10385 w
->hw_wp_mask
= mask
;
10390 w
->val_bitpos
= saved_bitpos
;
10391 w
->val_bitsize
= saved_bitsize
;
10392 w
->val_valid
= true;
10396 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10398 w
->cond_string
= 0;
10400 if (frame_id_p (watchpoint_frame
))
10402 w
->watchpoint_frame
= watchpoint_frame
;
10403 w
->watchpoint_thread
= inferior_ptid
;
10407 w
->watchpoint_frame
= null_frame_id
;
10408 w
->watchpoint_thread
= null_ptid
;
10411 if (scope_breakpoint
!= NULL
)
10413 /* The scope breakpoint is related to the watchpoint. We will
10414 need to act on them together. */
10415 w
->related_breakpoint
= scope_breakpoint
;
10416 scope_breakpoint
->related_breakpoint
= w
.get ();
10419 if (!just_location
)
10420 value_free_to_mark (mark
);
10422 /* Finally update the new watchpoint. This creates the locations
10423 that should be inserted. */
10424 update_watchpoint (w
.get (), 1);
10426 install_breakpoint (internal
, std::move (w
), 1);
10429 /* Return count of debug registers needed to watch the given expression.
10430 If the watchpoint cannot be handled in hardware return zero. */
10433 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10435 int found_memory_cnt
= 0;
10437 /* Did the user specifically forbid us to use hardware watchpoints? */
10438 if (!can_use_hw_watchpoints
)
10441 gdb_assert (!vals
.empty ());
10442 struct value
*head
= vals
[0].get ();
10444 /* Make sure that the value of the expression depends only upon
10445 memory contents, and values computed from them within GDB. If we
10446 find any register references or function calls, we can't use a
10447 hardware watchpoint.
10449 The idea here is that evaluating an expression generates a series
10450 of values, one holding the value of every subexpression. (The
10451 expression a*b+c has five subexpressions: a, b, a*b, c, and
10452 a*b+c.) GDB's values hold almost enough information to establish
10453 the criteria given above --- they identify memory lvalues,
10454 register lvalues, computed values, etcetera. So we can evaluate
10455 the expression, and then scan the chain of values that leaves
10456 behind to decide whether we can detect any possible change to the
10457 expression's final value using only hardware watchpoints.
10459 However, I don't think that the values returned by inferior
10460 function calls are special in any way. So this function may not
10461 notice that an expression involving an inferior function call
10462 can't be watched with hardware watchpoints. FIXME. */
10463 for (const value_ref_ptr
&iter
: vals
)
10465 struct value
*v
= iter
.get ();
10467 if (VALUE_LVAL (v
) == lval_memory
)
10469 if (v
!= head
&& value_lazy (v
))
10470 /* A lazy memory lvalue in the chain is one that GDB never
10471 needed to fetch; we either just used its address (e.g.,
10472 `a' in `a.b') or we never needed it at all (e.g., `a'
10473 in `a,b'). This doesn't apply to HEAD; if that is
10474 lazy then it was not readable, but watch it anyway. */
10478 /* Ahh, memory we actually used! Check if we can cover
10479 it with hardware watchpoints. */
10480 struct type
*vtype
= check_typedef (value_type (v
));
10482 /* We only watch structs and arrays if user asked for it
10483 explicitly, never if they just happen to appear in a
10484 middle of some value chain. */
10486 || (vtype
->code () != TYPE_CODE_STRUCT
10487 && vtype
->code () != TYPE_CODE_ARRAY
))
10489 CORE_ADDR vaddr
= value_address (v
);
10493 len
= (target_exact_watchpoints
10494 && is_scalar_type_recursive (vtype
))?
10495 1 : TYPE_LENGTH (value_type (v
));
10497 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10501 found_memory_cnt
+= num_regs
;
10505 else if (VALUE_LVAL (v
) != not_lval
10506 && deprecated_value_modifiable (v
) == 0)
10507 return 0; /* These are values from the history (e.g., $1). */
10508 else if (VALUE_LVAL (v
) == lval_register
)
10509 return 0; /* Cannot watch a register with a HW watchpoint. */
10512 /* The expression itself looks suitable for using a hardware
10513 watchpoint, but give the target machine a chance to reject it. */
10514 return found_memory_cnt
;
10518 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10520 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10523 /* Options for the watch, awatch, and rwatch commands. */
10525 struct watch_options
10527 /* For -location. */
10528 bool location
= false;
10531 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10533 Historically GDB always accepted both '-location' and '-l' flags for
10534 these commands (both flags being synonyms). When converting to the
10535 newer option scheme only '-location' is added here. That's fine (for
10536 backward compatibility) as any non-ambiguous prefix of a flag will be
10537 accepted, so '-l', '-loc', are now all accepted.
10539 What this means is that, if in the future, we add any new flag here
10540 that starts with '-l' then this will break backward compatibility, so
10541 please, don't do that! */
10543 static const gdb::option::option_def watch_option_defs
[] = {
10544 gdb::option::flag_option_def
<watch_options
> {
10546 [] (watch_options
*opt
) { return &opt
->location
; },
10548 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10549 -l can be used as a short form of -location."),
10553 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10556 static gdb::option::option_def_group
10557 make_watch_options_def_group (watch_options
*opts
)
10559 return {{watch_option_defs
}, opts
};
10562 /* A helper function that looks for the "-location" argument and then
10563 calls watch_command_1. */
10566 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10568 watch_options opts
;
10569 auto grp
= make_watch_options_def_group (&opts
);
10570 gdb::option::process_options
10571 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10572 if (arg
!= nullptr && *arg
== '\0')
10575 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10578 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10580 watch_command_completer (struct cmd_list_element
*ignore
,
10581 completion_tracker
&tracker
,
10582 const char *text
, const char * /*word*/)
10584 const auto group
= make_watch_options_def_group (nullptr);
10585 if (gdb::option::complete_options
10586 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10589 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10590 expression_completer (ignore
, tracker
, text
, word
);
10594 watch_command (const char *arg
, int from_tty
)
10596 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10600 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10602 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10606 rwatch_command (const char *arg
, int from_tty
)
10608 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10612 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10614 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10618 awatch_command (const char *arg
, int from_tty
)
10620 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10624 /* Data for the FSM that manages the until(location)/advance commands
10625 in infcmd.c. Here because it uses the mechanisms of
10628 struct until_break_fsm
: public thread_fsm
10630 /* The thread that was current when the command was executed. */
10633 /* The breakpoint set at the return address in the caller frame,
10634 plus breakpoints at all the destination locations. */
10635 std::vector
<breakpoint_up
> breakpoints
;
10637 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10638 std::vector
<breakpoint_up
> &&breakpoints
)
10639 : thread_fsm (cmd_interp
),
10641 breakpoints (std::move (breakpoints
))
10645 void clean_up (struct thread_info
*thread
) override
;
10646 bool should_stop (struct thread_info
*thread
) override
;
10647 enum async_reply_reason
do_async_reply_reason () override
;
10650 /* Implementation of the 'should_stop' FSM method for the
10651 until(location)/advance commands. */
10654 until_break_fsm::should_stop (struct thread_info
*tp
)
10656 for (const breakpoint_up
&bp
: breakpoints
)
10657 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10658 bp
.get ()) != NULL
)
10667 /* Implementation of the 'clean_up' FSM method for the
10668 until(location)/advance commands. */
10671 until_break_fsm::clean_up (struct thread_info
*)
10673 /* Clean up our temporary breakpoints. */
10674 breakpoints
.clear ();
10675 delete_longjmp_breakpoint (thread
);
10678 /* Implementation of the 'async_reply_reason' FSM method for the
10679 until(location)/advance commands. */
10681 enum async_reply_reason
10682 until_break_fsm::do_async_reply_reason ()
10684 return EXEC_ASYNC_LOCATION_REACHED
;
10688 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10690 struct frame_info
*frame
;
10691 struct gdbarch
*frame_gdbarch
;
10692 struct frame_id stack_frame_id
;
10693 struct frame_id caller_frame_id
;
10695 struct thread_info
*tp
;
10697 clear_proceed_status (0);
10699 /* Set a breakpoint where the user wants it and at return from
10702 event_location_up location
= string_to_event_location (&arg
, current_language
);
10704 std::vector
<symtab_and_line
> sals
10705 = (last_displayed_sal_is_valid ()
10706 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10707 get_last_displayed_symtab (),
10708 get_last_displayed_line ())
10709 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
10713 error (_("Couldn't get information on specified line."));
10716 error (_("Junk at end of arguments."));
10718 tp
= inferior_thread ();
10719 thread
= tp
->global_num
;
10721 /* Note linespec handling above invalidates the frame chain.
10722 Installing a breakpoint also invalidates the frame chain (as it
10723 may need to switch threads), so do any frame handling before
10726 frame
= get_selected_frame (NULL
);
10727 frame_gdbarch
= get_frame_arch (frame
);
10728 stack_frame_id
= get_stack_frame_id (frame
);
10729 caller_frame_id
= frame_unwind_caller_id (frame
);
10731 /* Keep within the current frame, or in frames called by the current
10734 std::vector
<breakpoint_up
> breakpoints
;
10736 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10738 if (frame_id_p (caller_frame_id
))
10740 struct symtab_and_line sal2
;
10741 struct gdbarch
*caller_gdbarch
;
10743 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10744 sal2
.pc
= frame_unwind_caller_pc (frame
);
10745 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10747 breakpoint_up caller_breakpoint
10748 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10749 caller_frame_id
, bp_until
);
10750 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10752 set_longjmp_breakpoint (tp
, caller_frame_id
);
10753 lj_deleter
.emplace (thread
);
10756 /* set_momentary_breakpoint could invalidate FRAME. */
10759 /* If the user told us to continue until a specified location, we
10760 don't specify a frame at which we need to stop. Otherwise,
10761 specify the selected frame, because we want to stop only at the
10762 very same frame. */
10763 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10765 for (symtab_and_line
&sal
: sals
)
10767 resolve_sal_pc (&sal
);
10769 breakpoint_up location_breakpoint
10770 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10771 stop_frame_id
, bp_until
);
10772 breakpoints
.emplace_back (std::move (location_breakpoint
));
10776 (std::unique_ptr
<thread_fsm
>
10777 (new until_break_fsm (command_interp (), tp
->global_num
,
10778 std::move (breakpoints
))));
10781 lj_deleter
->release ();
10783 proceed (-1, GDB_SIGNAL_DEFAULT
);
10787 init_ada_exception_breakpoint (struct breakpoint
*b
,
10788 struct gdbarch
*gdbarch
,
10789 struct symtab_and_line sal
,
10790 const char *addr_string
,
10791 const struct breakpoint_ops
*ops
,
10798 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10800 loc_gdbarch
= gdbarch
;
10802 describe_other_breakpoints (loc_gdbarch
,
10803 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10804 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10805 version for exception catchpoints, because two catchpoints
10806 used for different exception names will use the same address.
10807 In this case, a "breakpoint ... also set at..." warning is
10808 unproductive. Besides, the warning phrasing is also a bit
10809 inappropriate, we should use the word catchpoint, and tell
10810 the user what type of catchpoint it is. The above is good
10811 enough for now, though. */
10814 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
10816 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10817 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10818 b
->location
= string_to_event_location (&addr_string
,
10819 language_def (language_ada
));
10820 b
->language
= language_ada
;
10825 /* Compare two breakpoints and return a strcmp-like result. */
10828 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10830 uintptr_t ua
= (uintptr_t) a
;
10831 uintptr_t ub
= (uintptr_t) b
;
10833 if (a
->number
< b
->number
)
10835 else if (a
->number
> b
->number
)
10838 /* Now sort by address, in case we see, e..g, two breakpoints with
10842 return ua
> ub
? 1 : 0;
10845 /* Delete breakpoints by address or line. */
10848 clear_command (const char *arg
, int from_tty
)
10852 std::vector
<symtab_and_line
> decoded_sals
;
10853 symtab_and_line last_sal
;
10854 gdb::array_view
<symtab_and_line
> sals
;
10858 = decode_line_with_current_source (arg
,
10859 (DECODE_LINE_FUNFIRSTLINE
10860 | DECODE_LINE_LIST_MODE
));
10862 sals
= decoded_sals
;
10866 /* Set sal's line, symtab, pc, and pspace to the values
10867 corresponding to the last call to print_frame_info. If the
10868 codepoint is not valid, this will set all the fields to 0. */
10869 last_sal
= get_last_displayed_sal ();
10870 if (last_sal
.symtab
== 0)
10871 error (_("No source file specified."));
10877 /* We don't call resolve_sal_pc here. That's not as bad as it
10878 seems, because all existing breakpoints typically have both
10879 file/line and pc set. So, if clear is given file/line, we can
10880 match this to existing breakpoint without obtaining pc at all.
10882 We only support clearing given the address explicitly
10883 present in breakpoint table. Say, we've set breakpoint
10884 at file:line. There were several PC values for that file:line,
10885 due to optimization, all in one block.
10887 We've picked one PC value. If "clear" is issued with another
10888 PC corresponding to the same file:line, the breakpoint won't
10889 be cleared. We probably can still clear the breakpoint, but
10890 since the other PC value is never presented to user, user
10891 can only find it by guessing, and it does not seem important
10892 to support that. */
10894 /* For each line spec given, delete bps which correspond to it. Do
10895 it in two passes, solely to preserve the current behavior that
10896 from_tty is forced true if we delete more than one
10899 std::vector
<struct breakpoint
*> found
;
10900 for (const auto &sal
: sals
)
10902 const char *sal_fullname
;
10904 /* If exact pc given, clear bpts at that pc.
10905 If line given (pc == 0), clear all bpts on specified line.
10906 If defaulting, clear all bpts on default line
10909 defaulting sal.pc != 0 tests to do
10914 1 0 <can't happen> */
10916 sal_fullname
= (sal
.symtab
== NULL
10917 ? NULL
: symtab_to_fullname (sal
.symtab
));
10919 /* Find all matching breakpoints and add them to 'found'. */
10920 for (breakpoint
*b
: all_breakpoints ())
10923 /* Are we going to delete b? */
10924 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10926 for (bp_location
*loc
: b
->locations ())
10928 /* If the user specified file:line, don't allow a PC
10929 match. This matches historical gdb behavior. */
10930 int pc_match
= (!sal
.explicit_line
10932 && (loc
->pspace
== sal
.pspace
)
10933 && (loc
->address
== sal
.pc
)
10934 && (!section_is_overlay (loc
->section
)
10935 || loc
->section
== sal
.section
));
10936 int line_match
= 0;
10938 if ((default_match
|| sal
.explicit_line
)
10939 && loc
->symtab
!= NULL
10940 && sal_fullname
!= NULL
10941 && sal
.pspace
== loc
->pspace
10942 && loc
->line_number
== sal
.line
10943 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10944 sal_fullname
) == 0)
10947 if (pc_match
|| line_match
)
10956 found
.push_back (b
);
10960 /* Now go thru the 'found' chain and delete them. */
10961 if (found
.empty ())
10964 error (_("No breakpoint at %s."), arg
);
10966 error (_("No breakpoint at this line."));
10969 /* Remove duplicates from the vec. */
10970 std::sort (found
.begin (), found
.end (),
10971 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10973 return compare_breakpoints (bp_a
, bp_b
) < 0;
10975 found
.erase (std::unique (found
.begin (), found
.end (),
10976 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10978 return compare_breakpoints (bp_a
, bp_b
) == 0;
10982 if (found
.size () > 1)
10983 from_tty
= 1; /* Always report if deleted more than one. */
10986 if (found
.size () == 1)
10987 gdb_printf (_("Deleted breakpoint "));
10989 gdb_printf (_("Deleted breakpoints "));
10992 for (breakpoint
*iter
: found
)
10995 gdb_printf ("%d ", iter
->number
);
10996 delete_breakpoint (iter
);
11002 /* Delete breakpoint in BS if they are `delete' breakpoints and
11003 all breakpoints that are marked for deletion, whether hit or not.
11004 This is called after any breakpoint is hit, or after errors. */
11007 breakpoint_auto_delete (bpstat
*bs
)
11009 for (; bs
; bs
= bs
->next
)
11010 if (bs
->breakpoint_at
11011 && bs
->breakpoint_at
->disposition
== disp_del
11013 delete_breakpoint (bs
->breakpoint_at
);
11015 for (breakpoint
*b
: all_breakpoints_safe ())
11016 if (b
->disposition
== disp_del_at_next_stop
)
11017 delete_breakpoint (b
);
11020 /* A comparison function for bp_location AP and BP being interfaced to
11021 std::sort. Sort elements primarily by their ADDRESS (no matter what
11022 bl_address_is_meaningful says), secondarily by ordering first
11023 permanent elements and terciarily just ensuring the array is sorted
11024 stable way despite std::sort being an unstable algorithm. */
11027 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11029 if (a
->address
!= b
->address
)
11030 return a
->address
< b
->address
;
11032 /* Sort locations at the same address by their pspace number, keeping
11033 locations of the same inferior (in a multi-inferior environment)
11036 if (a
->pspace
->num
!= b
->pspace
->num
)
11037 return a
->pspace
->num
< b
->pspace
->num
;
11039 /* Sort permanent breakpoints first. */
11040 if (a
->permanent
!= b
->permanent
)
11041 return a
->permanent
> b
->permanent
;
11043 /* Sort by type in order to make duplicate determination easier.
11044 See update_global_location_list. This is kept in sync with
11045 breakpoint_locations_match. */
11046 if (a
->loc_type
< b
->loc_type
)
11049 /* Likewise, for range-breakpoints, sort by length. */
11050 if (a
->loc_type
== bp_loc_hardware_breakpoint
11051 && b
->loc_type
== bp_loc_hardware_breakpoint
11052 && a
->length
< b
->length
)
11055 /* Make the internal GDB representation stable across GDB runs
11056 where A and B memory inside GDB can differ. Breakpoint locations of
11057 the same type at the same address can be sorted in arbitrary order. */
11059 if (a
->owner
->number
!= b
->owner
->number
)
11060 return a
->owner
->number
< b
->owner
->number
;
11065 /* Set bp_locations_placed_address_before_address_max and
11066 bp_locations_shadow_len_after_address_max according to the current
11067 content of the bp_locations array. */
11070 bp_locations_target_extensions_update (void)
11072 bp_locations_placed_address_before_address_max
= 0;
11073 bp_locations_shadow_len_after_address_max
= 0;
11075 for (bp_location
*bl
: all_bp_locations ())
11077 CORE_ADDR start
, end
, addr
;
11079 if (!bp_location_has_shadow (bl
))
11082 start
= bl
->target_info
.placed_address
;
11083 end
= start
+ bl
->target_info
.shadow_len
;
11085 gdb_assert (bl
->address
>= start
);
11086 addr
= bl
->address
- start
;
11087 if (addr
> bp_locations_placed_address_before_address_max
)
11088 bp_locations_placed_address_before_address_max
= addr
;
11090 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11092 gdb_assert (bl
->address
< end
);
11093 addr
= end
- bl
->address
;
11094 if (addr
> bp_locations_shadow_len_after_address_max
)
11095 bp_locations_shadow_len_after_address_max
= addr
;
11099 /* Download tracepoint locations if they haven't been. */
11102 download_tracepoint_locations (void)
11104 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11106 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11108 for (breakpoint
*b
: all_tracepoints ())
11110 struct tracepoint
*t
;
11111 int bp_location_downloaded
= 0;
11113 if ((b
->type
== bp_fast_tracepoint
11114 ? !may_insert_fast_tracepoints
11115 : !may_insert_tracepoints
))
11118 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11120 if (target_can_download_tracepoint ())
11121 can_download_tracepoint
= TRIBOOL_TRUE
;
11123 can_download_tracepoint
= TRIBOOL_FALSE
;
11126 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11129 for (bp_location
*bl
: b
->locations ())
11131 /* In tracepoint, locations are _never_ duplicated, so
11132 should_be_inserted is equivalent to
11133 unduplicated_should_be_inserted. */
11134 if (!should_be_inserted (bl
) || bl
->inserted
)
11137 switch_to_program_space_and_thread (bl
->pspace
);
11139 target_download_tracepoint (bl
);
11142 bp_location_downloaded
= 1;
11144 t
= (struct tracepoint
*) b
;
11145 t
->number_on_target
= b
->number
;
11146 if (bp_location_downloaded
)
11147 gdb::observers::breakpoint_modified
.notify (b
);
11151 /* Swap the insertion/duplication state between two locations. */
11154 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11156 const int left_inserted
= left
->inserted
;
11157 const int left_duplicate
= left
->duplicate
;
11158 const int left_needs_update
= left
->needs_update
;
11159 const struct bp_target_info left_target_info
= left
->target_info
;
11161 /* Locations of tracepoints can never be duplicated. */
11162 if (is_tracepoint (left
->owner
))
11163 gdb_assert (!left
->duplicate
);
11164 if (is_tracepoint (right
->owner
))
11165 gdb_assert (!right
->duplicate
);
11167 left
->inserted
= right
->inserted
;
11168 left
->duplicate
= right
->duplicate
;
11169 left
->needs_update
= right
->needs_update
;
11170 left
->target_info
= right
->target_info
;
11171 right
->inserted
= left_inserted
;
11172 right
->duplicate
= left_duplicate
;
11173 right
->needs_update
= left_needs_update
;
11174 right
->target_info
= left_target_info
;
11177 /* Force the re-insertion of the locations at ADDRESS. This is called
11178 once a new/deleted/modified duplicate location is found and we are evaluating
11179 conditions on the target's side. Such conditions need to be updated on
11183 force_breakpoint_reinsertion (struct bp_location
*bl
)
11185 CORE_ADDR address
= 0;
11188 address
= bl
->address
;
11189 pspace_num
= bl
->pspace
->num
;
11191 /* This is only meaningful if the target is
11192 evaluating conditions and if the user has
11193 opted for condition evaluation on the target's
11195 if (gdb_evaluates_breakpoint_condition_p ()
11196 || !target_supports_evaluation_of_breakpoint_conditions ())
11199 /* Flag all breakpoint locations with this address and
11200 the same program space as the location
11201 as "its condition has changed". We need to
11202 update the conditions on the target's side. */
11203 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11205 if (!is_breakpoint (loc
->owner
)
11206 || pspace_num
!= loc
->pspace
->num
)
11209 /* Flag the location appropriately. We use a different state to
11210 let everyone know that we already updated the set of locations
11211 with addr bl->address and program space bl->pspace. This is so
11212 we don't have to keep calling these functions just to mark locations
11213 that have already been marked. */
11214 loc
->condition_changed
= condition_updated
;
11216 /* Free the agent expression bytecode as well. We will compute
11218 loc
->cond_bytecode
.reset ();
11222 /* Called whether new breakpoints are created, or existing breakpoints
11223 deleted, to update the global location list and recompute which
11224 locations are duplicate of which.
11226 The INSERT_MODE flag determines whether locations may not, may, or
11227 shall be inserted now. See 'enum ugll_insert_mode' for more
11231 update_global_location_list (enum ugll_insert_mode insert_mode
)
11233 /* Last breakpoint location address that was marked for update. */
11234 CORE_ADDR last_addr
= 0;
11235 /* Last breakpoint location program space that was marked for update. */
11236 int last_pspace_num
= -1;
11238 /* Used in the duplicates detection below. When iterating over all
11239 bp_locations, points to the first bp_location of a given address.
11240 Breakpoints and watchpoints of different types are never
11241 duplicates of each other. Keep one pointer for each type of
11242 breakpoint/watchpoint, so we only need to loop over all locations
11244 struct bp_location
*bp_loc_first
; /* breakpoint */
11245 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11246 struct bp_location
*awp_loc_first
; /* access watchpoint */
11247 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11249 /* Saved former bp_locations array which we compare against the newly
11250 built bp_locations from the current state of ALL_BREAKPOINTS. */
11251 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11252 bp_locations
.clear ();
11254 for (breakpoint
*b
: all_breakpoints ())
11255 for (bp_location
*loc
: b
->locations ())
11256 bp_locations
.push_back (loc
);
11258 /* See if we need to "upgrade" a software breakpoint to a hardware
11259 breakpoint. Do this before deciding whether locations are
11260 duplicates. Also do this before sorting because sorting order
11261 depends on location type. */
11262 for (bp_location
*loc
: bp_locations
)
11263 if (!loc
->inserted
&& should_be_inserted (loc
))
11264 handle_automatic_hardware_breakpoints (loc
);
11266 std::sort (bp_locations
.begin (), bp_locations
.end (),
11267 bp_location_is_less_than
);
11269 bp_locations_target_extensions_update ();
11271 /* Identify bp_location instances that are no longer present in the
11272 new list, and therefore should be freed. Note that it's not
11273 necessary that those locations should be removed from inferior --
11274 if there's another location at the same address (previously
11275 marked as duplicate), we don't need to remove/insert the
11278 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11279 and former bp_location array state respectively. */
11282 for (bp_location
*old_loc
: old_locations
)
11284 /* Tells if 'old_loc' is found among the new locations. If
11285 not, we have to free it. */
11286 int found_object
= 0;
11287 /* Tells if the location should remain inserted in the target. */
11288 int keep_in_target
= 0;
11291 /* Skip LOCP entries which will definitely never be needed.
11292 Stop either at or being the one matching OLD_LOC. */
11293 while (loc_i
< bp_locations
.size ()
11294 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11297 for (size_t loc2_i
= loc_i
;
11298 (loc2_i
< bp_locations
.size ()
11299 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11302 /* Check if this is a new/duplicated location or a duplicated
11303 location that had its condition modified. If so, we want to send
11304 its condition to the target if evaluation of conditions is taking
11306 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11307 && (last_addr
!= old_loc
->address
11308 || last_pspace_num
!= old_loc
->pspace
->num
))
11310 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11311 last_pspace_num
= old_loc
->pspace
->num
;
11314 if (bp_locations
[loc2_i
] == old_loc
)
11318 /* We have already handled this address, update it so that we don't
11319 have to go through updates again. */
11320 last_addr
= old_loc
->address
;
11322 /* Target-side condition evaluation: Handle deleted locations. */
11324 force_breakpoint_reinsertion (old_loc
);
11326 /* If this location is no longer present, and inserted, look if
11327 there's maybe a new location at the same address. If so,
11328 mark that one inserted, and don't remove this one. This is
11329 needed so that we don't have a time window where a breakpoint
11330 at certain location is not inserted. */
11332 if (old_loc
->inserted
)
11334 /* If the location is inserted now, we might have to remove
11337 if (found_object
&& should_be_inserted (old_loc
))
11339 /* The location is still present in the location list,
11340 and still should be inserted. Don't do anything. */
11341 keep_in_target
= 1;
11345 /* This location still exists, but it won't be kept in the
11346 target since it may have been disabled. We proceed to
11347 remove its target-side condition. */
11349 /* The location is either no longer present, or got
11350 disabled. See if there's another location at the
11351 same address, in which case we don't need to remove
11352 this one from the target. */
11354 /* OLD_LOC comes from existing struct breakpoint. */
11355 if (bl_address_is_meaningful (old_loc
))
11357 for (size_t loc2_i
= loc_i
;
11358 (loc2_i
< bp_locations
.size ()
11359 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11362 bp_location
*loc2
= bp_locations
[loc2_i
];
11364 if (loc2
== old_loc
)
11367 if (breakpoint_locations_match (loc2
, old_loc
))
11369 /* Read watchpoint locations are switched to
11370 access watchpoints, if the former are not
11371 supported, but the latter are. */
11372 if (is_hardware_watchpoint (old_loc
->owner
))
11374 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11375 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11378 /* loc2 is a duplicated location. We need to check
11379 if it should be inserted in case it will be
11381 if (unduplicated_should_be_inserted (loc2
))
11383 swap_insertion (old_loc
, loc2
);
11384 keep_in_target
= 1;
11392 if (!keep_in_target
)
11394 if (remove_breakpoint (old_loc
))
11396 /* This is just about all we can do. We could keep
11397 this location on the global list, and try to
11398 remove it next time, but there's no particular
11399 reason why we will succeed next time.
11401 Note that at this point, old_loc->owner is still
11402 valid, as delete_breakpoint frees the breakpoint
11403 only after calling us. */
11404 gdb_printf (_("warning: Error removing "
11405 "breakpoint %d\n"),
11406 old_loc
->owner
->number
);
11414 if (removed
&& target_is_non_stop_p ()
11415 && need_moribund_for_location_type (old_loc
))
11417 /* This location was removed from the target. In
11418 non-stop mode, a race condition is possible where
11419 we've removed a breakpoint, but stop events for that
11420 breakpoint are already queued and will arrive later.
11421 We apply an heuristic to be able to distinguish such
11422 SIGTRAPs from other random SIGTRAPs: we keep this
11423 breakpoint location for a bit, and will retire it
11424 after we see some number of events. The theory here
11425 is that reporting of events should, "on the average",
11426 be fair, so after a while we'll see events from all
11427 threads that have anything of interest, and no longer
11428 need to keep this breakpoint location around. We
11429 don't hold locations forever so to reduce chances of
11430 mistaking a non-breakpoint SIGTRAP for a breakpoint
11433 The heuristic failing can be disastrous on
11434 decr_pc_after_break targets.
11436 On decr_pc_after_break targets, like e.g., x86-linux,
11437 if we fail to recognize a late breakpoint SIGTRAP,
11438 because events_till_retirement has reached 0 too
11439 soon, we'll fail to do the PC adjustment, and report
11440 a random SIGTRAP to the user. When the user resumes
11441 the inferior, it will most likely immediately crash
11442 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11443 corrupted, because of being resumed e.g., in the
11444 middle of a multi-byte instruction, or skipped a
11445 one-byte instruction. This was actually seen happen
11446 on native x86-linux, and should be less rare on
11447 targets that do not support new thread events, like
11448 remote, due to the heuristic depending on
11451 Mistaking a random SIGTRAP for a breakpoint trap
11452 causes similar symptoms (PC adjustment applied when
11453 it shouldn't), but then again, playing with SIGTRAPs
11454 behind the debugger's back is asking for trouble.
11456 Since hardware watchpoint traps are always
11457 distinguishable from other traps, so we don't need to
11458 apply keep hardware watchpoint moribund locations
11459 around. We simply always ignore hardware watchpoint
11460 traps we can no longer explain. */
11462 process_stratum_target
*proc_target
= nullptr;
11463 for (inferior
*inf
: all_inferiors ())
11464 if (inf
->pspace
== old_loc
->pspace
)
11466 proc_target
= inf
->process_target ();
11469 if (proc_target
!= nullptr)
11470 old_loc
->events_till_retirement
11471 = 3 * (thread_count (proc_target
) + 1);
11473 old_loc
->events_till_retirement
= 1;
11474 old_loc
->owner
= NULL
;
11476 moribund_locations
.push_back (old_loc
);
11480 old_loc
->owner
= NULL
;
11481 decref_bp_location (&old_loc
);
11486 /* Rescan breakpoints at the same address and section, marking the
11487 first one as "first" and any others as "duplicates". This is so
11488 that the bpt instruction is only inserted once. If we have a
11489 permanent breakpoint at the same place as BPT, make that one the
11490 official one, and the rest as duplicates. Permanent breakpoints
11491 are sorted first for the same address.
11493 Do the same for hardware watchpoints, but also considering the
11494 watchpoint's type (regular/access/read) and length. */
11496 bp_loc_first
= NULL
;
11497 wp_loc_first
= NULL
;
11498 awp_loc_first
= NULL
;
11499 rwp_loc_first
= NULL
;
11501 for (bp_location
*loc
: all_bp_locations ())
11503 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11505 struct bp_location
**loc_first_p
;
11506 breakpoint
*b
= loc
->owner
;
11508 if (!unduplicated_should_be_inserted (loc
)
11509 || !bl_address_is_meaningful (loc
)
11510 /* Don't detect duplicate for tracepoint locations because they are
11511 never duplicated. See the comments in field `duplicate' of
11512 `struct bp_location'. */
11513 || is_tracepoint (b
))
11515 /* Clear the condition modification flag. */
11516 loc
->condition_changed
= condition_unchanged
;
11520 if (b
->type
== bp_hardware_watchpoint
)
11521 loc_first_p
= &wp_loc_first
;
11522 else if (b
->type
== bp_read_watchpoint
)
11523 loc_first_p
= &rwp_loc_first
;
11524 else if (b
->type
== bp_access_watchpoint
)
11525 loc_first_p
= &awp_loc_first
;
11527 loc_first_p
= &bp_loc_first
;
11529 if (*loc_first_p
== NULL
11530 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11531 || !breakpoint_locations_match (loc
, *loc_first_p
))
11533 *loc_first_p
= loc
;
11534 loc
->duplicate
= 0;
11536 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11538 loc
->needs_update
= 1;
11539 /* Clear the condition modification flag. */
11540 loc
->condition_changed
= condition_unchanged
;
11546 /* This and the above ensure the invariant that the first location
11547 is not duplicated, and is the inserted one.
11548 All following are marked as duplicated, and are not inserted. */
11550 swap_insertion (loc
, *loc_first_p
);
11551 loc
->duplicate
= 1;
11553 /* Clear the condition modification flag. */
11554 loc
->condition_changed
= condition_unchanged
;
11557 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11559 if (insert_mode
!= UGLL_DONT_INSERT
)
11560 insert_breakpoint_locations ();
11563 /* Even though the caller told us to not insert new
11564 locations, we may still need to update conditions on the
11565 target's side of breakpoints that were already inserted
11566 if the target is evaluating breakpoint conditions. We
11567 only update conditions for locations that are marked
11569 update_inserted_breakpoint_locations ();
11573 if (insert_mode
!= UGLL_DONT_INSERT
)
11574 download_tracepoint_locations ();
11578 breakpoint_retire_moribund (void)
11580 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11582 struct bp_location
*loc
= moribund_locations
[ix
];
11583 if (--(loc
->events_till_retirement
) == 0)
11585 decref_bp_location (&loc
);
11586 unordered_remove (moribund_locations
, ix
);
11593 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11598 update_global_location_list (insert_mode
);
11600 catch (const gdb_exception_error
&e
)
11605 /* Clear BKP from a BPS. */
11608 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11612 for (bs
= bps
; bs
; bs
= bs
->next
)
11613 if (bs
->breakpoint_at
== bpt
)
11615 bs
->breakpoint_at
= NULL
;
11616 bs
->old_val
= NULL
;
11617 /* bs->commands will be freed later. */
11621 /* Callback for iterate_over_threads. */
11623 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11625 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11627 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11631 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11635 say_where (struct breakpoint
*b
)
11637 struct value_print_options opts
;
11639 get_user_print_options (&opts
);
11641 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11643 if (b
->loc
== NULL
)
11645 /* For pending locations, the output differs slightly based
11646 on b->extra_string. If this is non-NULL, it contains either
11647 a condition or dprintf arguments. */
11648 if (b
->extra_string
== NULL
)
11650 gdb_printf (_(" (%s) pending."),
11651 event_location_to_string (b
->location
.get ()));
11653 else if (b
->type
== bp_dprintf
)
11655 gdb_printf (_(" (%s,%s) pending."),
11656 event_location_to_string (b
->location
.get ()),
11657 b
->extra_string
.get ());
11661 gdb_printf (_(" (%s %s) pending."),
11662 event_location_to_string (b
->location
.get ()),
11663 b
->extra_string
.get ());
11668 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
11669 gdb_printf (" at %ps",
11670 styled_string (address_style
.style (),
11671 paddress (b
->loc
->gdbarch
,
11672 b
->loc
->address
)));
11673 if (b
->loc
->symtab
!= NULL
)
11675 /* If there is a single location, we can print the location
11677 if (b
->loc
->next
== NULL
)
11679 const char *filename
11680 = symtab_to_filename_for_display (b
->loc
->symtab
);
11681 gdb_printf (": file %ps, line %d.",
11682 styled_string (file_name_style
.style (),
11684 b
->loc
->line_number
);
11687 /* This is not ideal, but each location may have a
11688 different file name, and this at least reflects the
11689 real situation somewhat. */
11690 gdb_printf (": %s.",
11691 event_location_to_string (b
->location
.get ()));
11696 struct bp_location
*loc
= b
->loc
;
11698 for (; loc
; loc
= loc
->next
)
11700 gdb_printf (" (%d locations)", n
);
11705 /* See breakpoint.h. */
11707 bp_location_range
breakpoint::locations ()
11709 return bp_location_range (this->loc
);
11712 static struct bp_location
*
11713 base_breakpoint_allocate_location (struct breakpoint
*self
)
11715 return new bp_location (self
);
11719 base_breakpoint_re_set (struct breakpoint
*b
)
11721 /* Nothing to re-set. */
11724 #define internal_error_pure_virtual_called() \
11725 gdb_assert_not_reached ("pure virtual function called")
11728 base_breakpoint_insert_location (struct bp_location
*bl
)
11730 internal_error_pure_virtual_called ();
11734 base_breakpoint_remove_location (struct bp_location
*bl
,
11735 enum remove_bp_reason reason
)
11737 internal_error_pure_virtual_called ();
11741 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
11742 const address_space
*aspace
,
11744 const target_waitstatus
&ws
)
11746 internal_error_pure_virtual_called ();
11750 base_breakpoint_check_status (bpstat
*bs
)
11755 /* A "works_in_software_mode" breakpoint_ops method that just internal
11759 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
11761 internal_error_pure_virtual_called ();
11764 /* A "resources_needed" breakpoint_ops method that just internal
11768 base_breakpoint_resources_needed (const struct bp_location
*bl
)
11770 internal_error_pure_virtual_called ();
11773 static enum print_stop_action
11774 base_breakpoint_print_it (bpstat
*bs
)
11776 internal_error_pure_virtual_called ();
11780 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
11781 struct ui_out
*uiout
)
11787 base_breakpoint_print_mention (struct breakpoint
*b
)
11789 internal_error_pure_virtual_called ();
11793 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
11795 internal_error_pure_virtual_called ();
11799 base_breakpoint_create_sals_from_location
11800 (struct event_location
*location
,
11801 struct linespec_result
*canonical
,
11802 enum bptype type_wanted
)
11804 internal_error_pure_virtual_called ();
11808 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11809 struct linespec_result
*c
,
11810 gdb::unique_xmalloc_ptr
<char> cond_string
,
11811 gdb::unique_xmalloc_ptr
<char> extra_string
,
11812 enum bptype type_wanted
,
11813 enum bpdisp disposition
,
11815 int task
, int ignore_count
,
11816 const struct breakpoint_ops
*o
,
11817 int from_tty
, int enabled
,
11818 int internal
, unsigned flags
)
11820 internal_error_pure_virtual_called ();
11823 static std::vector
<symtab_and_line
>
11824 base_breakpoint_decode_location (struct breakpoint
*b
,
11825 struct event_location
*location
,
11826 struct program_space
*search_pspace
)
11828 internal_error_pure_virtual_called ();
11831 /* The default 'explains_signal' method. */
11834 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
11839 /* The default "after_condition_true" method. */
11842 base_breakpoint_after_condition_true (struct bpstat
*bs
)
11844 /* Nothing to do. */
11847 struct breakpoint_ops base_breakpoint_ops
=
11849 base_breakpoint_allocate_location
,
11850 base_breakpoint_re_set
,
11851 base_breakpoint_insert_location
,
11852 base_breakpoint_remove_location
,
11853 base_breakpoint_breakpoint_hit
,
11854 base_breakpoint_check_status
,
11855 base_breakpoint_resources_needed
,
11856 base_breakpoint_works_in_software_mode
,
11857 base_breakpoint_print_it
,
11859 base_breakpoint_print_one_detail
,
11860 base_breakpoint_print_mention
,
11861 base_breakpoint_print_recreate
,
11862 base_breakpoint_create_sals_from_location
,
11863 base_breakpoint_create_breakpoints_sal
,
11864 base_breakpoint_decode_location
,
11865 base_breakpoint_explains_signal
,
11866 base_breakpoint_after_condition_true
,
11869 /* Default breakpoint_ops methods. */
11872 bkpt_re_set (struct breakpoint
*b
)
11874 /* FIXME: is this still reachable? */
11875 if (breakpoint_event_location_empty_p (b
))
11877 /* Anything without a location can't be re-set. */
11878 delete_breakpoint (b
);
11882 breakpoint_re_set_default (b
);
11886 bkpt_insert_location (struct bp_location
*bl
)
11888 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11890 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11891 bl
->target_info
.placed_address
= addr
;
11893 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11894 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11896 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11900 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
11902 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11903 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11905 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11909 bkpt_breakpoint_hit (const struct bp_location
*bl
,
11910 const address_space
*aspace
, CORE_ADDR bp_addr
,
11911 const target_waitstatus
&ws
)
11913 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11914 || ws
.sig () != GDB_SIGNAL_TRAP
)
11917 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11921 if (overlay_debugging
/* unmapped overlay section */
11922 && section_is_overlay (bl
->section
)
11923 && !section_is_mapped (bl
->section
))
11930 dprintf_breakpoint_hit (const struct bp_location
*bl
,
11931 const address_space
*aspace
, CORE_ADDR bp_addr
,
11932 const target_waitstatus
&ws
)
11934 if (dprintf_style
== dprintf_style_agent
11935 && target_can_run_breakpoint_commands ())
11937 /* An agent-style dprintf never causes a stop. If we see a trap
11938 for this address it must be for a breakpoint that happens to
11939 be set at the same address. */
11943 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11947 bkpt_resources_needed (const struct bp_location
*bl
)
11949 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
11954 static enum print_stop_action
11955 bkpt_print_it (bpstat
*bs
)
11957 struct breakpoint
*b
;
11958 const struct bp_location
*bl
;
11960 struct ui_out
*uiout
= current_uiout
;
11962 gdb_assert (bs
->bp_location_at
!= NULL
);
11964 bl
= bs
->bp_location_at
.get ();
11965 b
= bs
->breakpoint_at
;
11967 bp_temp
= b
->disposition
== disp_del
;
11968 if (bl
->address
!= bl
->requested_address
)
11969 breakpoint_adjustment_warning (bl
->requested_address
,
11972 annotate_breakpoint (b
->number
);
11973 maybe_print_thread_hit_breakpoint (uiout
);
11975 if (uiout
->is_mi_like_p ())
11977 uiout
->field_string ("reason",
11978 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11979 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
11982 uiout
->message ("Temporary breakpoint %pF, ",
11983 signed_field ("bkptno", b
->number
));
11985 uiout
->message ("Breakpoint %pF, ",
11986 signed_field ("bkptno", b
->number
));
11988 return PRINT_SRC_AND_LOC
;
11992 bkpt_print_mention (struct breakpoint
*b
)
11994 if (current_uiout
->is_mi_like_p ())
11999 case bp_breakpoint
:
12000 case bp_gnu_ifunc_resolver
:
12001 if (b
->disposition
== disp_del
)
12002 gdb_printf (_("Temporary breakpoint"));
12004 gdb_printf (_("Breakpoint"));
12005 gdb_printf (_(" %d"), b
->number
);
12006 if (b
->type
== bp_gnu_ifunc_resolver
)
12007 gdb_printf (_(" at gnu-indirect-function resolver"));
12009 case bp_hardware_breakpoint
:
12010 gdb_printf (_("Hardware assisted breakpoint %d"), b
->number
);
12013 gdb_printf (_("Dprintf %d"), b
->number
);
12021 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12023 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12024 gdb_printf (fp
, "tbreak");
12025 else if (tp
->type
== bp_breakpoint
)
12026 gdb_printf (fp
, "break");
12027 else if (tp
->type
== bp_hardware_breakpoint
12028 && tp
->disposition
== disp_del
)
12029 gdb_printf (fp
, "thbreak");
12030 else if (tp
->type
== bp_hardware_breakpoint
)
12031 gdb_printf (fp
, "hbreak");
12033 internal_error (__FILE__
, __LINE__
,
12034 _("unhandled breakpoint type %d"), (int) tp
->type
);
12036 gdb_printf (fp
, " %s",
12037 event_location_to_string (tp
->location
.get ()));
12039 /* Print out extra_string if this breakpoint is pending. It might
12040 contain, for example, conditions that were set by the user. */
12041 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12042 gdb_printf (fp
, " %s", tp
->extra_string
.get ());
12044 print_recreate_thread (tp
, fp
);
12048 bkpt_create_sals_from_location (struct event_location
*location
,
12049 struct linespec_result
*canonical
,
12050 enum bptype type_wanted
)
12052 create_sals_from_location_default (location
, canonical
, type_wanted
);
12056 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12057 struct linespec_result
*canonical
,
12058 gdb::unique_xmalloc_ptr
<char> cond_string
,
12059 gdb::unique_xmalloc_ptr
<char> extra_string
,
12060 enum bptype type_wanted
,
12061 enum bpdisp disposition
,
12063 int task
, int ignore_count
,
12064 const struct breakpoint_ops
*ops
,
12065 int from_tty
, int enabled
,
12066 int internal
, unsigned flags
)
12068 create_breakpoints_sal_default (gdbarch
, canonical
,
12069 std::move (cond_string
),
12070 std::move (extra_string
),
12072 disposition
, thread
, task
,
12073 ignore_count
, ops
, from_tty
,
12074 enabled
, internal
, flags
);
12077 static std::vector
<symtab_and_line
>
12078 bkpt_decode_location (struct breakpoint
*b
,
12079 struct event_location
*location
,
12080 struct program_space
*search_pspace
)
12082 return decode_location_default (b
, location
, search_pspace
);
12085 /* Virtual table for internal breakpoints. */
12088 internal_bkpt_re_set (struct breakpoint
*b
)
12092 /* Delete overlay event and longjmp master breakpoints; they
12093 will be reset later by breakpoint_re_set. */
12094 case bp_overlay_event
:
12095 case bp_longjmp_master
:
12096 case bp_std_terminate_master
:
12097 case bp_exception_master
:
12098 delete_breakpoint (b
);
12101 /* This breakpoint is special, it's set up when the inferior
12102 starts and we really don't want to touch it. */
12103 case bp_shlib_event
:
12105 /* Like bp_shlib_event, this breakpoint type is special. Once
12106 it is set up, we do not want to touch it. */
12107 case bp_thread_event
:
12113 internal_bkpt_check_status (bpstat
*bs
)
12115 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12117 /* If requested, stop when the dynamic linker notifies GDB of
12118 events. This allows the user to get control and place
12119 breakpoints in initializer routines for dynamically loaded
12120 objects (among other things). */
12121 bs
->stop
= stop_on_solib_events
;
12122 bs
->print
= stop_on_solib_events
;
12128 static enum print_stop_action
12129 internal_bkpt_print_it (bpstat
*bs
)
12131 struct breakpoint
*b
;
12133 b
= bs
->breakpoint_at
;
12137 case bp_shlib_event
:
12138 /* Did we stop because the user set the stop_on_solib_events
12139 variable? (If so, we report this as a generic, "Stopped due
12140 to shlib event" message.) */
12141 print_solib_event (0);
12144 case bp_thread_event
:
12145 /* Not sure how we will get here.
12146 GDB should not stop for these breakpoints. */
12147 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
12150 case bp_overlay_event
:
12151 /* By analogy with the thread event, GDB should not stop for these. */
12152 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12155 case bp_longjmp_master
:
12156 /* These should never be enabled. */
12157 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12160 case bp_std_terminate_master
:
12161 /* These should never be enabled. */
12162 gdb_printf (_("std::terminate Master Breakpoint: "
12163 "gdb should not stop!\n"));
12166 case bp_exception_master
:
12167 /* These should never be enabled. */
12168 gdb_printf (_("Exception Master Breakpoint: "
12169 "gdb should not stop!\n"));
12173 return PRINT_NOTHING
;
12177 internal_bkpt_print_mention (struct breakpoint
*b
)
12179 /* Nothing to mention. These breakpoints are internal. */
12182 /* Virtual table for momentary breakpoints */
12185 momentary_bkpt_re_set (struct breakpoint
*b
)
12187 /* Keep temporary breakpoints, which can be encountered when we step
12188 over a dlopen call and solib_add is resetting the breakpoints.
12189 Otherwise these should have been blown away via the cleanup chain
12190 or by breakpoint_init_inferior when we rerun the executable. */
12194 momentary_bkpt_check_status (bpstat
*bs
)
12196 /* Nothing. The point of these breakpoints is causing a stop. */
12199 static enum print_stop_action
12200 momentary_bkpt_print_it (bpstat
*bs
)
12202 return PRINT_UNKNOWN
;
12206 momentary_bkpt_print_mention (struct breakpoint
*b
)
12208 /* Nothing to mention. These breakpoints are internal. */
12211 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12213 It gets cleared already on the removal of the first one of such placed
12214 breakpoints. This is OK as they get all removed altogether. */
12216 longjmp_breakpoint::~longjmp_breakpoint ()
12218 thread_info
*tp
= find_thread_global_id (this->thread
);
12221 tp
->initiating_frame
= null_frame_id
;
12224 /* Specific methods for probe breakpoints. */
12227 bkpt_probe_insert_location (struct bp_location
*bl
)
12229 int v
= bkpt_insert_location (bl
);
12233 /* The insertion was successful, now let's set the probe's semaphore
12235 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12242 bkpt_probe_remove_location (struct bp_location
*bl
,
12243 enum remove_bp_reason reason
)
12245 /* Let's clear the semaphore before removing the location. */
12246 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12248 return bkpt_remove_location (bl
, reason
);
12252 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12253 struct linespec_result
*canonical
,
12254 enum bptype type_wanted
)
12256 struct linespec_sals lsal
;
12258 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12260 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12261 canonical
->lsals
.push_back (std::move (lsal
));
12264 static std::vector
<symtab_and_line
>
12265 bkpt_probe_decode_location (struct breakpoint
*b
,
12266 struct event_location
*location
,
12267 struct program_space
*search_pspace
)
12269 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12271 error (_("probe not found"));
12275 /* The breakpoint_ops structure to be used in tracepoints. */
12278 tracepoint_re_set (struct breakpoint
*b
)
12280 breakpoint_re_set_default (b
);
12284 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12285 const address_space
*aspace
, CORE_ADDR bp_addr
,
12286 const target_waitstatus
&ws
)
12288 /* By definition, the inferior does not report stops at
12294 tracepoint_print_one_detail (const struct breakpoint
*self
,
12295 struct ui_out
*uiout
)
12297 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12298 if (!tp
->static_trace_marker_id
.empty ())
12300 gdb_assert (self
->type
== bp_static_tracepoint
);
12302 uiout
->message ("\tmarker id is %pF\n",
12303 string_field ("static-tracepoint-marker-string-id",
12304 tp
->static_trace_marker_id
.c_str ()));
12309 tracepoint_print_mention (struct breakpoint
*b
)
12311 if (current_uiout
->is_mi_like_p ())
12316 case bp_tracepoint
:
12317 gdb_printf (_("Tracepoint"));
12318 gdb_printf (_(" %d"), b
->number
);
12320 case bp_fast_tracepoint
:
12321 gdb_printf (_("Fast tracepoint"));
12322 gdb_printf (_(" %d"), b
->number
);
12324 case bp_static_tracepoint
:
12325 gdb_printf (_("Static tracepoint"));
12326 gdb_printf (_(" %d"), b
->number
);
12329 internal_error (__FILE__
, __LINE__
,
12330 _("unhandled tracepoint type %d"), (int) b
->type
);
12337 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12339 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12341 if (self
->type
== bp_fast_tracepoint
)
12342 gdb_printf (fp
, "ftrace");
12343 else if (self
->type
== bp_static_tracepoint
)
12344 gdb_printf (fp
, "strace");
12345 else if (self
->type
== bp_tracepoint
)
12346 gdb_printf (fp
, "trace");
12348 internal_error (__FILE__
, __LINE__
,
12349 _("unhandled tracepoint type %d"), (int) self
->type
);
12351 gdb_printf (fp
, " %s",
12352 event_location_to_string (self
->location
.get ()));
12353 print_recreate_thread (self
, fp
);
12355 if (tp
->pass_count
)
12356 gdb_printf (fp
, " passcount %d\n", tp
->pass_count
);
12360 tracepoint_create_sals_from_location (struct event_location
*location
,
12361 struct linespec_result
*canonical
,
12362 enum bptype type_wanted
)
12364 create_sals_from_location_default (location
, canonical
, type_wanted
);
12368 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12369 struct linespec_result
*canonical
,
12370 gdb::unique_xmalloc_ptr
<char> cond_string
,
12371 gdb::unique_xmalloc_ptr
<char> extra_string
,
12372 enum bptype type_wanted
,
12373 enum bpdisp disposition
,
12375 int task
, int ignore_count
,
12376 const struct breakpoint_ops
*ops
,
12377 int from_tty
, int enabled
,
12378 int internal
, unsigned flags
)
12380 create_breakpoints_sal_default (gdbarch
, canonical
,
12381 std::move (cond_string
),
12382 std::move (extra_string
),
12384 disposition
, thread
, task
,
12385 ignore_count
, ops
, from_tty
,
12386 enabled
, internal
, flags
);
12389 static std::vector
<symtab_and_line
>
12390 tracepoint_decode_location (struct breakpoint
*b
,
12391 struct event_location
*location
,
12392 struct program_space
*search_pspace
)
12394 return decode_location_default (b
, location
, search_pspace
);
12397 struct breakpoint_ops tracepoint_breakpoint_ops
;
12399 /* Virtual table for tracepoints on static probes. */
12402 tracepoint_probe_create_sals_from_location
12403 (struct event_location
*location
,
12404 struct linespec_result
*canonical
,
12405 enum bptype type_wanted
)
12407 /* We use the same method for breakpoint on probes. */
12408 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12411 static std::vector
<symtab_and_line
>
12412 tracepoint_probe_decode_location (struct breakpoint
*b
,
12413 struct event_location
*location
,
12414 struct program_space
*search_pspace
)
12416 /* We use the same method for breakpoint on probes. */
12417 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12420 /* Dprintf breakpoint_ops methods. */
12423 dprintf_re_set (struct breakpoint
*b
)
12425 breakpoint_re_set_default (b
);
12427 /* extra_string should never be non-NULL for dprintf. */
12428 gdb_assert (b
->extra_string
!= NULL
);
12430 /* 1 - connect to target 1, that can run breakpoint commands.
12431 2 - create a dprintf, which resolves fine.
12432 3 - disconnect from target 1
12433 4 - connect to target 2, that can NOT run breakpoint commands.
12435 After steps #3/#4, you'll want the dprintf command list to
12436 be updated, because target 1 and 2 may well return different
12437 answers for target_can_run_breakpoint_commands().
12438 Given absence of finer grained resetting, we get to do
12439 it all the time. */
12440 if (b
->extra_string
!= NULL
)
12441 update_dprintf_command_list (b
);
12444 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12447 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12449 gdb_printf (fp
, "dprintf %s,%s",
12450 event_location_to_string (tp
->location
.get ()),
12451 tp
->extra_string
.get ());
12452 print_recreate_thread (tp
, fp
);
12455 /* Implement the "after_condition_true" breakpoint_ops method for
12458 dprintf's are implemented with regular commands in their command
12459 list, but we run the commands here instead of before presenting the
12460 stop to the user, as dprintf's don't actually cause a stop. This
12461 also makes it so that the commands of multiple dprintfs at the same
12462 address are all handled. */
12465 dprintf_after_condition_true (struct bpstat
*bs
)
12467 /* dprintf's never cause a stop. This wasn't set in the
12468 check_status hook instead because that would make the dprintf's
12469 condition not be evaluated. */
12472 /* Run the command list here. Take ownership of it instead of
12473 copying. We never want these commands to run later in
12474 bpstat_do_actions, if a breakpoint that causes a stop happens to
12475 be set at same address as this dprintf, or even if running the
12476 commands here throws. */
12477 counted_command_line cmds
= std::move (bs
->commands
);
12478 gdb_assert (cmds
!= nullptr);
12479 execute_control_commands (cmds
.get (), 0);
12482 /* The breakpoint_ops structure to be used on static tracepoints with
12486 strace_marker_create_sals_from_location (struct event_location
*location
,
12487 struct linespec_result
*canonical
,
12488 enum bptype type_wanted
)
12490 struct linespec_sals lsal
;
12491 const char *arg_start
, *arg
;
12493 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12494 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12496 std::string
str (arg_start
, arg
- arg_start
);
12497 const char *ptr
= str
.c_str ();
12498 canonical
->location
12499 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12502 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12503 canonical
->lsals
.push_back (std::move (lsal
));
12507 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12508 struct linespec_result
*canonical
,
12509 gdb::unique_xmalloc_ptr
<char> cond_string
,
12510 gdb::unique_xmalloc_ptr
<char> extra_string
,
12511 enum bptype type_wanted
,
12512 enum bpdisp disposition
,
12514 int task
, int ignore_count
,
12515 const struct breakpoint_ops
*ops
,
12516 int from_tty
, int enabled
,
12517 int internal
, unsigned flags
)
12519 const linespec_sals
&lsal
= canonical
->lsals
[0];
12521 /* If the user is creating a static tracepoint by marker id
12522 (strace -m MARKER_ID), then store the sals index, so that
12523 breakpoint_re_set can try to match up which of the newly
12524 found markers corresponds to this one, and, don't try to
12525 expand multiple locations for each sal, given than SALS
12526 already should contain all sals for MARKER_ID. */
12528 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12530 event_location_up location
12531 = copy_event_location (canonical
->location
.get ());
12533 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12534 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12535 std::move (location
), NULL
,
12536 std::move (cond_string
),
12537 std::move (extra_string
),
12538 type_wanted
, disposition
,
12539 thread
, task
, ignore_count
, ops
,
12540 from_tty
, enabled
, internal
, flags
,
12541 canonical
->special_display
);
12542 /* Given that its possible to have multiple markers with
12543 the same string id, if the user is creating a static
12544 tracepoint by marker id ("strace -m MARKER_ID"), then
12545 store the sals index, so that breakpoint_re_set can
12546 try to match up which of the newly found markers
12547 corresponds to this one */
12548 tp
->static_trace_marker_id_idx
= i
;
12550 install_breakpoint (internal
, std::move (tp
), 0);
12554 static std::vector
<symtab_and_line
>
12555 strace_marker_decode_location (struct breakpoint
*b
,
12556 struct event_location
*location
,
12557 struct program_space
*search_pspace
)
12559 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12560 const char *s
= get_linespec_location (location
)->spec_string
;
12562 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12563 if (sals
.size () > tp
->static_trace_marker_id_idx
)
12565 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
12570 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
12573 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12576 strace_marker_p (struct breakpoint
*b
)
12578 return b
->ops
== &strace_marker_breakpoint_ops
;
12581 /* Delete a breakpoint and clean up all traces of it in the data
12585 delete_breakpoint (struct breakpoint
*bpt
)
12587 gdb_assert (bpt
!= NULL
);
12589 /* Has this bp already been deleted? This can happen because
12590 multiple lists can hold pointers to bp's. bpstat lists are
12593 One example of this happening is a watchpoint's scope bp. When
12594 the scope bp triggers, we notice that the watchpoint is out of
12595 scope, and delete it. We also delete its scope bp. But the
12596 scope bp is marked "auto-deleting", and is already on a bpstat.
12597 That bpstat is then checked for auto-deleting bp's, which are
12600 A real solution to this problem might involve reference counts in
12601 bp's, and/or giving them pointers back to their referencing
12602 bpstat's, and teaching delete_breakpoint to only free a bp's
12603 storage when no more references were extent. A cheaper bandaid
12605 if (bpt
->type
== bp_none
)
12608 /* At least avoid this stale reference until the reference counting
12609 of breakpoints gets resolved. */
12610 if (bpt
->related_breakpoint
!= bpt
)
12612 struct breakpoint
*related
;
12613 struct watchpoint
*w
;
12615 if (bpt
->type
== bp_watchpoint_scope
)
12616 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12617 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12618 w
= (struct watchpoint
*) bpt
;
12622 watchpoint_del_at_next_stop (w
);
12624 /* Unlink bpt from the bpt->related_breakpoint ring. */
12625 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12626 related
= related
->related_breakpoint
);
12627 related
->related_breakpoint
= bpt
->related_breakpoint
;
12628 bpt
->related_breakpoint
= bpt
;
12631 /* watch_command_1 creates a watchpoint but only sets its number if
12632 update_watchpoint succeeds in creating its bp_locations. If there's
12633 a problem in that process, we'll be asked to delete the half-created
12634 watchpoint. In that case, don't announce the deletion. */
12636 gdb::observers::breakpoint_deleted
.notify (bpt
);
12638 if (breakpoint_chain
== bpt
)
12639 breakpoint_chain
= bpt
->next
;
12641 for (breakpoint
*b
: all_breakpoints ())
12642 if (b
->next
== bpt
)
12644 b
->next
= bpt
->next
;
12648 /* Be sure no bpstat's are pointing at the breakpoint after it's
12650 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12651 in all threads for now. Note that we cannot just remove bpstats
12652 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12653 commands are associated with the bpstat; if we remove it here,
12654 then the later call to bpstat_do_actions (&stop_bpstat); in
12655 event-top.c won't do anything, and temporary breakpoints with
12656 commands won't work. */
12658 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12660 /* Now that breakpoint is removed from breakpoint list, update the
12661 global location list. This will remove locations that used to
12662 belong to this breakpoint. Do this before freeing the breakpoint
12663 itself, since remove_breakpoint looks at location's owner. It
12664 might be better design to have location completely
12665 self-contained, but it's not the case now. */
12666 update_global_location_list (UGLL_DONT_INSERT
);
12668 /* On the chance that someone will soon try again to delete this
12669 same bp, we mark it as deleted before freeing its storage. */
12670 bpt
->type
= bp_none
;
12674 /* Iterator function to call a user-provided callback function once
12675 for each of B and its related breakpoints. */
12678 iterate_over_related_breakpoints (struct breakpoint
*b
,
12679 gdb::function_view
<void (breakpoint
*)> function
)
12681 struct breakpoint
*related
;
12686 struct breakpoint
*next
;
12688 /* FUNCTION may delete RELATED. */
12689 next
= related
->related_breakpoint
;
12691 if (next
== related
)
12693 /* RELATED is the last ring entry. */
12694 function (related
);
12696 /* FUNCTION may have deleted it, so we'd never reach back to
12697 B. There's nothing left to do anyway, so just break
12702 function (related
);
12706 while (related
!= b
);
12710 delete_command (const char *arg
, int from_tty
)
12716 int breaks_to_delete
= 0;
12718 /* Delete all breakpoints if no argument. Do not delete
12719 internal breakpoints, these have to be deleted with an
12720 explicit breakpoint number argument. */
12721 for (breakpoint
*b
: all_breakpoints ())
12722 if (user_breakpoint_p (b
))
12724 breaks_to_delete
= 1;
12728 /* Ask user only if there are some breakpoints to delete. */
12730 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12731 for (breakpoint
*b
: all_breakpoints_safe ())
12732 if (user_breakpoint_p (b
))
12733 delete_breakpoint (b
);
12736 map_breakpoint_numbers
12737 (arg
, [&] (breakpoint
*br
)
12739 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12743 /* Return true if all locations of B bound to PSPACE are pending. If
12744 PSPACE is NULL, all locations of all program spaces are
12748 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12750 for (bp_location
*loc
: b
->locations ())
12751 if ((pspace
== NULL
12752 || loc
->pspace
== pspace
)
12753 && !loc
->shlib_disabled
12754 && !loc
->pspace
->executing_startup
)
12759 /* Subroutine of update_breakpoint_locations to simplify it.
12760 Return non-zero if multiple fns in list LOC have the same name.
12761 Null names are ignored. */
12764 ambiguous_names_p (struct bp_location
*loc
)
12766 struct bp_location
*l
;
12767 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12770 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12773 const char *name
= l
->function_name
.get ();
12775 /* Allow for some names to be NULL, ignore them. */
12779 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12781 /* NOTE: We can assume slot != NULL here because xcalloc never
12791 /* When symbols change, it probably means the sources changed as well,
12792 and it might mean the static tracepoint markers are no longer at
12793 the same address or line numbers they used to be at last we
12794 checked. Losing your static tracepoints whenever you rebuild is
12795 undesirable. This function tries to resync/rematch gdb static
12796 tracepoints with the markers on the target, for static tracepoints
12797 that have not been set by marker id. Static tracepoint that have
12798 been set by marker id are reset by marker id in breakpoint_re_set.
12801 1) For a tracepoint set at a specific address, look for a marker at
12802 the old PC. If one is found there, assume to be the same marker.
12803 If the name / string id of the marker found is different from the
12804 previous known name, assume that means the user renamed the marker
12805 in the sources, and output a warning.
12807 2) For a tracepoint set at a given line number, look for a marker
12808 at the new address of the old line number. If one is found there,
12809 assume to be the same marker. If the name / string id of the
12810 marker found is different from the previous known name, assume that
12811 means the user renamed the marker in the sources, and output a
12814 3) If a marker is no longer found at the same address or line, it
12815 may mean the marker no longer exists. But it may also just mean
12816 the code changed a bit. Maybe the user added a few lines of code
12817 that made the marker move up or down (in line number terms). Ask
12818 the target for info about the marker with the string id as we knew
12819 it. If found, update line number and address in the matching
12820 static tracepoint. This will get confused if there's more than one
12821 marker with the same ID (possible in UST, although unadvised
12822 precisely because it confuses tools). */
12824 static struct symtab_and_line
12825 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12827 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12828 struct static_tracepoint_marker marker
;
12833 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12835 if (target_static_tracepoint_marker_at (pc
, &marker
))
12837 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12838 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12839 b
->number
, tp
->static_trace_marker_id
.c_str (),
12840 marker
.str_id
.c_str ());
12842 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12847 /* Old marker wasn't found on target at lineno. Try looking it up
12849 if (!sal
.explicit_pc
12851 && sal
.symtab
!= NULL
12852 && !tp
->static_trace_marker_id
.empty ())
12854 std::vector
<static_tracepoint_marker
> markers
12855 = target_static_tracepoint_markers_by_strid
12856 (tp
->static_trace_marker_id
.c_str ());
12858 if (!markers
.empty ())
12860 struct symbol
*sym
;
12861 struct static_tracepoint_marker
*tpmarker
;
12862 struct ui_out
*uiout
= current_uiout
;
12863 struct explicit_location explicit_loc
;
12865 tpmarker
= &markers
[0];
12867 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12869 warning (_("marker for static tracepoint %d (%s) not "
12870 "found at previous line number"),
12871 b
->number
, tp
->static_trace_marker_id
.c_str ());
12873 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12874 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12875 uiout
->text ("Now in ");
12878 uiout
->field_string ("func", sym
->print_name (),
12879 function_name_style
.style ());
12880 uiout
->text (" at ");
12882 uiout
->field_string ("file",
12883 symtab_to_filename_for_display (sal2
.symtab
),
12884 file_name_style
.style ());
12887 if (uiout
->is_mi_like_p ())
12889 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12891 uiout
->field_string ("fullname", fullname
);
12894 uiout
->field_signed ("line", sal2
.line
);
12895 uiout
->text ("\n");
12897 b
->loc
->line_number
= sal2
.line
;
12898 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12900 b
->location
.reset (NULL
);
12901 initialize_explicit_location (&explicit_loc
);
12902 explicit_loc
.source_filename
12903 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
12904 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
12905 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
12906 b
->location
= new_explicit_location (&explicit_loc
);
12908 /* Might be nice to check if function changed, and warn if
12915 /* Returns 1 iff locations A and B are sufficiently same that
12916 we don't need to report breakpoint as changed. */
12919 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12923 if (a
->address
!= b
->address
)
12926 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12929 if (a
->enabled
!= b
->enabled
)
12932 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12939 if ((a
== NULL
) != (b
== NULL
))
12945 /* Split all locations of B that are bound to PSPACE out of B's
12946 location list to a separate list and return that list's head. If
12947 PSPACE is NULL, hoist out all locations of B. */
12949 static struct bp_location
*
12950 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12952 struct bp_location head
;
12953 struct bp_location
*i
= b
->loc
;
12954 struct bp_location
**i_link
= &b
->loc
;
12955 struct bp_location
*hoisted
= &head
;
12957 if (pspace
== NULL
)
12968 if (i
->pspace
== pspace
)
12983 /* Create new breakpoint locations for B (a hardware or software
12984 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12985 zero, then B is a ranged breakpoint. Only recreates locations for
12986 FILTER_PSPACE. Locations of other program spaces are left
12990 update_breakpoint_locations (struct breakpoint
*b
,
12991 struct program_space
*filter_pspace
,
12992 gdb::array_view
<const symtab_and_line
> sals
,
12993 gdb::array_view
<const symtab_and_line
> sals_end
)
12995 struct bp_location
*existing_locations
;
12997 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12999 /* Ranged breakpoints have only one start location and one end
13001 b
->enable_state
= bp_disabled
;
13002 gdb_printf (gdb_stderr
,
13003 _("Could not reset ranged breakpoint %d: "
13004 "multiple locations found\n"),
13009 /* If there's no new locations, and all existing locations are
13010 pending, don't do anything. This optimizes the common case where
13011 all locations are in the same shared library, that was unloaded.
13012 We'd like to retain the location, so that when the library is
13013 loaded again, we don't loose the enabled/disabled status of the
13014 individual locations. */
13015 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13018 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13020 for (const auto &sal
: sals
)
13022 struct bp_location
*new_loc
;
13024 switch_to_program_space_and_thread (sal
.pspace
);
13026 new_loc
= add_location_to_breakpoint (b
, &sal
);
13028 /* Reparse conditions, they might contain references to the
13030 if (b
->cond_string
!= NULL
)
13034 s
= b
->cond_string
.get ();
13037 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13038 block_for_pc (sal
.pc
),
13041 catch (const gdb_exception_error
&e
)
13043 new_loc
->disabled_by_cond
= true;
13047 if (!sals_end
.empty ())
13049 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13051 new_loc
->length
= end
- sals
[0].pc
+ 1;
13055 /* If possible, carry over 'disable' status from existing
13058 struct bp_location
*e
= existing_locations
;
13059 /* If there are multiple breakpoints with the same function name,
13060 e.g. for inline functions, comparing function names won't work.
13061 Instead compare pc addresses; this is just a heuristic as things
13062 may have moved, but in practice it gives the correct answer
13063 often enough until a better solution is found. */
13064 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13066 for (; e
; e
= e
->next
)
13068 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13070 if (have_ambiguous_names
)
13072 for (bp_location
*l
: b
->locations ())
13074 /* Ignore software vs hardware location type at
13075 this point, because with "set breakpoint
13076 auto-hw", after a re-set, locations that were
13077 hardware can end up as software, or vice versa.
13078 As mentioned above, this is an heuristic and in
13079 practice should give the correct answer often
13081 if (breakpoint_locations_match (e
, l
, true))
13083 l
->enabled
= e
->enabled
;
13084 l
->disabled_by_cond
= e
->disabled_by_cond
;
13091 for (bp_location
*l
: b
->locations ())
13092 if (l
->function_name
13093 && strcmp (e
->function_name
.get (),
13094 l
->function_name
.get ()) == 0)
13096 l
->enabled
= e
->enabled
;
13097 l
->disabled_by_cond
= e
->disabled_by_cond
;
13105 if (!locations_are_equal (existing_locations
, b
->loc
))
13106 gdb::observers::breakpoint_modified
.notify (b
);
13109 /* Find the SaL locations corresponding to the given LOCATION.
13110 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13112 static std::vector
<symtab_and_line
>
13113 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13114 struct program_space
*search_pspace
, int *found
)
13116 struct gdb_exception exception
;
13118 gdb_assert (b
->ops
!= NULL
);
13120 std::vector
<symtab_and_line
> sals
;
13124 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13126 catch (gdb_exception_error
&e
)
13128 int not_found_and_ok
= 0;
13130 /* For pending breakpoints, it's expected that parsing will
13131 fail until the right shared library is loaded. User has
13132 already told to create pending breakpoints and don't need
13133 extra messages. If breakpoint is in bp_shlib_disabled
13134 state, then user already saw the message about that
13135 breakpoint being disabled, and don't want to see more
13137 if (e
.error
== NOT_FOUND_ERROR
13138 && (b
->condition_not_parsed
13140 && search_pspace
!= NULL
13141 && b
->loc
->pspace
!= search_pspace
)
13142 || (b
->loc
&& b
->loc
->shlib_disabled
)
13143 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13144 || b
->enable_state
== bp_disabled
))
13145 not_found_and_ok
= 1;
13147 if (!not_found_and_ok
)
13149 /* We surely don't want to warn about the same breakpoint
13150 10 times. One solution, implemented here, is disable
13151 the breakpoint on error. Another solution would be to
13152 have separate 'warning emitted' flag. Since this
13153 happens only when a binary has changed, I don't know
13154 which approach is better. */
13155 b
->enable_state
= bp_disabled
;
13159 exception
= std::move (e
);
13162 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13164 for (auto &sal
: sals
)
13165 resolve_sal_pc (&sal
);
13166 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13168 gdb::unique_xmalloc_ptr
<char> cond_string
, extra_string
;
13171 find_condition_and_thread_for_sals (sals
, b
->extra_string
.get (),
13172 &cond_string
, &thread
,
13173 &task
, &extra_string
);
13174 gdb_assert (b
->cond_string
== NULL
);
13176 b
->cond_string
= std::move (cond_string
);
13177 b
->thread
= thread
;
13180 b
->extra_string
= std::move (extra_string
);
13181 b
->condition_not_parsed
= 0;
13184 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13185 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13195 /* The default re_set method, for typical hardware or software
13196 breakpoints. Reevaluate the breakpoint and recreate its
13200 breakpoint_re_set_default (struct breakpoint
*b
)
13202 struct program_space
*filter_pspace
= current_program_space
;
13203 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13206 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13207 filter_pspace
, &found
);
13209 expanded
= std::move (sals
);
13211 if (b
->location_range_end
!= NULL
)
13213 std::vector
<symtab_and_line
> sals_end
13214 = location_to_sals (b
, b
->location_range_end
.get (),
13215 filter_pspace
, &found
);
13217 expanded_end
= std::move (sals_end
);
13220 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13223 /* Default method for creating SALs from an address string. It basically
13224 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13227 create_sals_from_location_default (struct event_location
*location
,
13228 struct linespec_result
*canonical
,
13229 enum bptype type_wanted
)
13231 parse_breakpoint_sals (location
, canonical
);
13234 /* Call create_breakpoints_sal for the given arguments. This is the default
13235 function for the `create_breakpoints_sal' method of
13239 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13240 struct linespec_result
*canonical
,
13241 gdb::unique_xmalloc_ptr
<char> cond_string
,
13242 gdb::unique_xmalloc_ptr
<char> extra_string
,
13243 enum bptype type_wanted
,
13244 enum bpdisp disposition
,
13246 int task
, int ignore_count
,
13247 const struct breakpoint_ops
*ops
,
13248 int from_tty
, int enabled
,
13249 int internal
, unsigned flags
)
13251 create_breakpoints_sal (gdbarch
, canonical
,
13252 std::move (cond_string
),
13253 std::move (extra_string
),
13254 type_wanted
, disposition
,
13255 thread
, task
, ignore_count
, ops
, from_tty
,
13256 enabled
, internal
, flags
);
13259 /* Decode the line represented by S by calling decode_line_full. This is the
13260 default function for the `decode_location' method of breakpoint_ops. */
13262 static std::vector
<symtab_and_line
>
13263 decode_location_default (struct breakpoint
*b
,
13264 struct event_location
*location
,
13265 struct program_space
*search_pspace
)
13267 struct linespec_result canonical
;
13269 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13270 NULL
, 0, &canonical
, multiple_symbols_all
,
13273 /* We should get 0 or 1 resulting SALs. */
13274 gdb_assert (canonical
.lsals
.size () < 2);
13276 if (!canonical
.lsals
.empty ())
13278 const linespec_sals
&lsal
= canonical
.lsals
[0];
13279 return std::move (lsal
.sals
);
13284 /* Reset a breakpoint. */
13287 breakpoint_re_set_one (breakpoint
*b
)
13289 input_radix
= b
->input_radix
;
13290 set_language (b
->language
);
13292 b
->ops
->re_set (b
);
13295 /* Re-set breakpoint locations for the current program space.
13296 Locations bound to other program spaces are left untouched. */
13299 breakpoint_re_set (void)
13302 scoped_restore_current_language save_language
;
13303 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13304 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13306 /* breakpoint_re_set_one sets the current_language to the language
13307 of the breakpoint it is resetting (see prepare_re_set_context)
13308 before re-evaluating the breakpoint's location. This change can
13309 unfortunately get undone by accident if the language_mode is set
13310 to auto, and we either switch frames, or more likely in this context,
13311 we select the current frame.
13313 We prevent this by temporarily turning the language_mode to
13314 language_mode_manual. We restore it once all breakpoints
13315 have been reset. */
13316 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13317 language_mode
= language_mode_manual
;
13319 /* Note: we must not try to insert locations until after all
13320 breakpoints have been re-set. Otherwise, e.g., when re-setting
13321 breakpoint 1, we'd insert the locations of breakpoint 2, which
13322 hadn't been re-set yet, and thus may have stale locations. */
13324 for (breakpoint
*b
: all_breakpoints_safe ())
13328 breakpoint_re_set_one (b
);
13330 catch (const gdb_exception
&ex
)
13332 exception_fprintf (gdb_stderr
, ex
,
13333 "Error in re-setting breakpoint %d: ",
13338 jit_breakpoint_re_set ();
13341 create_overlay_event_breakpoint ();
13342 create_longjmp_master_breakpoint ();
13343 create_std_terminate_master_breakpoint ();
13344 create_exception_master_breakpoint ();
13346 /* Now we can insert. */
13347 update_global_location_list (UGLL_MAY_INSERT
);
13350 /* Reset the thread number of this breakpoint:
13352 - If the breakpoint is for all threads, leave it as-is.
13353 - Else, reset it to the current thread for inferior_ptid. */
13355 breakpoint_re_set_thread (struct breakpoint
*b
)
13357 if (b
->thread
!= -1)
13359 b
->thread
= inferior_thread ()->global_num
;
13361 /* We're being called after following a fork. The new fork is
13362 selected as current, and unless this was a vfork will have a
13363 different program space from the original thread. Reset that
13365 b
->loc
->pspace
= current_program_space
;
13369 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13370 If from_tty is nonzero, it prints a message to that effect,
13371 which ends with a period (no newline). */
13374 set_ignore_count (int bptnum
, int count
, int from_tty
)
13379 for (breakpoint
*b
: all_breakpoints ())
13380 if (b
->number
== bptnum
)
13382 if (is_tracepoint (b
))
13384 if (from_tty
&& count
!= 0)
13385 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13390 b
->ignore_count
= count
;
13394 gdb_printf (_("Will stop next time "
13395 "breakpoint %d is reached."),
13397 else if (count
== 1)
13398 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13401 gdb_printf (_("Will ignore next %d "
13402 "crossings of breakpoint %d."),
13405 gdb::observers::breakpoint_modified
.notify (b
);
13409 error (_("No breakpoint number %d."), bptnum
);
13412 /* Command to set ignore-count of breakpoint N to COUNT. */
13415 ignore_command (const char *args
, int from_tty
)
13417 const char *p
= args
;
13421 error_no_arg (_("a breakpoint number"));
13423 num
= get_number (&p
);
13425 error (_("bad breakpoint number: '%s'"), args
);
13427 error (_("Second argument (specified ignore-count) is missing."));
13429 set_ignore_count (num
,
13430 longest_to_int (value_as_long (parse_and_eval (p
))),
13437 /* Call FUNCTION on each of the breakpoints with numbers in the range
13438 defined by BP_NUM_RANGE (an inclusive range). */
13441 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13442 gdb::function_view
<void (breakpoint
*)> function
)
13444 if (bp_num_range
.first
== 0)
13446 warning (_("bad breakpoint number at or near '%d'"),
13447 bp_num_range
.first
);
13451 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13453 bool match
= false;
13455 for (breakpoint
*b
: all_breakpoints_safe ())
13456 if (b
->number
== i
)
13463 gdb_printf (_("No breakpoint number %d.\n"), i
);
13468 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13472 map_breakpoint_numbers (const char *args
,
13473 gdb::function_view
<void (breakpoint
*)> function
)
13475 if (args
== NULL
|| *args
== '\0')
13476 error_no_arg (_("one or more breakpoint numbers"));
13478 number_or_range_parser
parser (args
);
13480 while (!parser
.finished ())
13482 int num
= parser
.get_number ();
13483 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13487 /* Return the breakpoint location structure corresponding to the
13488 BP_NUM and LOC_NUM values. */
13490 static struct bp_location
*
13491 find_location_by_number (int bp_num
, int loc_num
)
13493 breakpoint
*b
= get_breakpoint (bp_num
);
13495 if (!b
|| b
->number
!= bp_num
)
13496 error (_("Bad breakpoint number '%d'"), bp_num
);
13499 error (_("Bad breakpoint location number '%d'"), loc_num
);
13502 for (bp_location
*loc
: b
->locations ())
13503 if (++n
== loc_num
)
13506 error (_("Bad breakpoint location number '%d'"), loc_num
);
13509 /* Modes of operation for extract_bp_num. */
13510 enum class extract_bp_kind
13512 /* Extracting a breakpoint number. */
13515 /* Extracting a location number. */
13519 /* Extract a breakpoint or location number (as determined by KIND)
13520 from the string starting at START. TRAILER is a character which
13521 can be found after the number. If you don't want a trailer, use
13522 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13523 string. This always returns a positive integer. */
13526 extract_bp_num (extract_bp_kind kind
, const char *start
,
13527 int trailer
, const char **end_out
= NULL
)
13529 const char *end
= start
;
13530 int num
= get_number_trailer (&end
, trailer
);
13532 error (kind
== extract_bp_kind::bp
13533 ? _("Negative breakpoint number '%.*s'")
13534 : _("Negative breakpoint location number '%.*s'"),
13535 int (end
- start
), start
);
13537 error (kind
== extract_bp_kind::bp
13538 ? _("Bad breakpoint number '%.*s'")
13539 : _("Bad breakpoint location number '%.*s'"),
13540 int (end
- start
), start
);
13542 if (end_out
!= NULL
)
13547 /* Extract a breakpoint or location range (as determined by KIND) in
13548 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13549 representing the (inclusive) range. The returned pair's elements
13550 are always positive integers. */
13552 static std::pair
<int, int>
13553 extract_bp_or_bp_range (extract_bp_kind kind
,
13554 const std::string
&arg
,
13555 std::string::size_type arg_offset
)
13557 std::pair
<int, int> range
;
13558 const char *bp_loc
= &arg
[arg_offset
];
13559 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13560 if (dash
!= std::string::npos
)
13562 /* bp_loc is a range (x-z). */
13563 if (arg
.length () == dash
+ 1)
13564 error (kind
== extract_bp_kind::bp
13565 ? _("Bad breakpoint number at or near: '%s'")
13566 : _("Bad breakpoint location number at or near: '%s'"),
13570 const char *start_first
= bp_loc
;
13571 const char *start_second
= &arg
[dash
+ 1];
13572 range
.first
= extract_bp_num (kind
, start_first
, '-');
13573 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13575 if (range
.first
> range
.second
)
13576 error (kind
== extract_bp_kind::bp
13577 ? _("Inverted breakpoint range at '%.*s'")
13578 : _("Inverted breakpoint location range at '%.*s'"),
13579 int (end
- start_first
), start_first
);
13583 /* bp_loc is a single value. */
13584 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13585 range
.second
= range
.first
;
13590 /* Extract the breakpoint/location range specified by ARG. Returns
13591 the breakpoint range in BP_NUM_RANGE, and the location range in
13594 ARG may be in any of the following forms:
13596 x where 'x' is a breakpoint number.
13597 x-y where 'x' and 'y' specify a breakpoint numbers range.
13598 x.y where 'x' is a breakpoint number and 'y' a location number.
13599 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13600 location number range.
13604 extract_bp_number_and_location (const std::string
&arg
,
13605 std::pair
<int, int> &bp_num_range
,
13606 std::pair
<int, int> &bp_loc_range
)
13608 std::string::size_type dot
= arg
.find ('.');
13610 if (dot
!= std::string::npos
)
13612 /* Handle 'x.y' and 'x.y-z' cases. */
13614 if (arg
.length () == dot
+ 1 || dot
== 0)
13615 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13618 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13619 bp_num_range
.second
= bp_num_range
.first
;
13621 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13626 /* Handle x and x-y cases. */
13628 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13629 bp_loc_range
.first
= 0;
13630 bp_loc_range
.second
= 0;
13634 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13635 specifies whether to enable or disable. */
13638 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13640 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13643 if (loc
->disabled_by_cond
&& enable
)
13644 error (_("Breakpoint %d's condition is invalid at location %d, "
13645 "cannot enable."), bp_num
, loc_num
);
13647 if (loc
->enabled
!= enable
)
13649 loc
->enabled
= enable
;
13650 mark_breakpoint_location_modified (loc
);
13652 if (target_supports_enable_disable_tracepoint ()
13653 && current_trace_status ()->running
&& loc
->owner
13654 && is_tracepoint (loc
->owner
))
13655 target_disable_tracepoint (loc
);
13657 update_global_location_list (UGLL_DONT_INSERT
);
13659 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13662 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13663 number of the breakpoint, and BP_LOC_RANGE specifies the
13664 (inclusive) range of location numbers of that breakpoint to
13665 enable/disable. ENABLE specifies whether to enable or disable the
13669 enable_disable_breakpoint_location_range (int bp_num
,
13670 std::pair
<int, int> &bp_loc_range
,
13673 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13674 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13677 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13678 If from_tty is nonzero, it prints a message to that effect,
13679 which ends with a period (no newline). */
13682 disable_breakpoint (struct breakpoint
*bpt
)
13684 /* Never disable a watchpoint scope breakpoint; we want to
13685 hit them when we leave scope so we can delete both the
13686 watchpoint and its scope breakpoint at that time. */
13687 if (bpt
->type
== bp_watchpoint_scope
)
13690 bpt
->enable_state
= bp_disabled
;
13692 /* Mark breakpoint locations modified. */
13693 mark_breakpoint_modified (bpt
);
13695 if (target_supports_enable_disable_tracepoint ()
13696 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13698 for (bp_location
*location
: bpt
->locations ())
13699 target_disable_tracepoint (location
);
13702 update_global_location_list (UGLL_DONT_INSERT
);
13704 gdb::observers::breakpoint_modified
.notify (bpt
);
13707 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13708 specified in ARGS. ARGS may be in any of the formats handled by
13709 extract_bp_number_and_location. ENABLE specifies whether to enable
13710 or disable the breakpoints/locations. */
13713 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13717 for (breakpoint
*bpt
: all_breakpoints ())
13718 if (user_breakpoint_p (bpt
))
13721 enable_breakpoint (bpt
);
13723 disable_breakpoint (bpt
);
13728 std::string num
= extract_arg (&args
);
13730 while (!num
.empty ())
13732 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13734 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13736 if (bp_loc_range
.first
== bp_loc_range
.second
13737 && bp_loc_range
.first
== 0)
13739 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
13740 map_breakpoint_number_range (bp_num_range
,
13742 ? enable_breakpoint
13743 : disable_breakpoint
);
13747 /* Handle breakpoint ids with formats 'x.y' or
13749 enable_disable_breakpoint_location_range
13750 (bp_num_range
.first
, bp_loc_range
, enable
);
13752 num
= extract_arg (&args
);
13757 /* The disable command disables the specified breakpoints/locations
13758 (or all defined breakpoints) so they're no longer effective in
13759 stopping the inferior. ARGS may be in any of the forms defined in
13760 extract_bp_number_and_location. */
13763 disable_command (const char *args
, int from_tty
)
13765 enable_disable_command (args
, from_tty
, false);
13769 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13772 int target_resources_ok
;
13774 if (bpt
->type
== bp_hardware_breakpoint
)
13777 i
= hw_breakpoint_used_count ();
13778 target_resources_ok
=
13779 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13781 if (target_resources_ok
== 0)
13782 error (_("No hardware breakpoint support in the target."));
13783 else if (target_resources_ok
< 0)
13784 error (_("Hardware breakpoints used exceeds limit."));
13787 if (is_watchpoint (bpt
))
13789 /* Initialize it just to avoid a GCC false warning. */
13790 enum enable_state orig_enable_state
= bp_disabled
;
13794 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13796 orig_enable_state
= bpt
->enable_state
;
13797 bpt
->enable_state
= bp_enabled
;
13798 update_watchpoint (w
, 1 /* reparse */);
13800 catch (const gdb_exception
&e
)
13802 bpt
->enable_state
= orig_enable_state
;
13803 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13809 bpt
->enable_state
= bp_enabled
;
13811 /* Mark breakpoint locations modified. */
13812 mark_breakpoint_modified (bpt
);
13814 if (target_supports_enable_disable_tracepoint ()
13815 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13817 for (bp_location
*location
: bpt
->locations ())
13818 target_enable_tracepoint (location
);
13821 bpt
->disposition
= disposition
;
13822 bpt
->enable_count
= count
;
13823 update_global_location_list (UGLL_MAY_INSERT
);
13825 gdb::observers::breakpoint_modified
.notify (bpt
);
13830 enable_breakpoint (struct breakpoint
*bpt
)
13832 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13835 /* The enable command enables the specified breakpoints/locations (or
13836 all defined breakpoints) so they once again become (or continue to
13837 be) effective in stopping the inferior. ARGS may be in any of the
13838 forms defined in extract_bp_number_and_location. */
13841 enable_command (const char *args
, int from_tty
)
13843 enable_disable_command (args
, from_tty
, true);
13847 enable_once_command (const char *args
, int from_tty
)
13849 map_breakpoint_numbers
13850 (args
, [&] (breakpoint
*b
)
13852 iterate_over_related_breakpoints
13853 (b
, [&] (breakpoint
*bpt
)
13855 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13861 enable_count_command (const char *args
, int from_tty
)
13866 error_no_arg (_("hit count"));
13868 count
= get_number (&args
);
13870 map_breakpoint_numbers
13871 (args
, [&] (breakpoint
*b
)
13873 iterate_over_related_breakpoints
13874 (b
, [&] (breakpoint
*bpt
)
13876 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13882 enable_delete_command (const char *args
, int from_tty
)
13884 map_breakpoint_numbers
13885 (args
, [&] (breakpoint
*b
)
13887 iterate_over_related_breakpoints
13888 (b
, [&] (breakpoint
*bpt
)
13890 enable_breakpoint_disp (bpt
, disp_del
, 1);
13895 /* Invalidate last known value of any hardware watchpoint if
13896 the memory which that value represents has been written to by
13900 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13901 CORE_ADDR addr
, ssize_t len
,
13902 const bfd_byte
*data
)
13904 for (breakpoint
*bp
: all_breakpoints ())
13905 if (bp
->enable_state
== bp_enabled
13906 && bp
->type
== bp_hardware_watchpoint
)
13908 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13910 if (wp
->val_valid
&& wp
->val
!= nullptr)
13912 for (bp_location
*loc
: bp
->locations ())
13913 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13914 && loc
->address
+ loc
->length
> addr
13915 && addr
+ len
> loc
->address
)
13918 wp
->val_valid
= false;
13924 /* Create and insert a breakpoint for software single step. */
13927 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13928 const address_space
*aspace
,
13931 struct thread_info
*tp
= inferior_thread ();
13932 struct symtab_and_line sal
;
13933 CORE_ADDR pc
= next_pc
;
13935 if (tp
->control
.single_step_breakpoints
== NULL
)
13937 tp
->control
.single_step_breakpoints
13938 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
13941 sal
= find_pc_line (pc
, 0);
13943 sal
.section
= find_pc_overlay (pc
);
13944 sal
.explicit_pc
= 1;
13945 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
13947 update_global_location_list (UGLL_INSERT
);
13950 /* Insert single step breakpoints according to the current state. */
13953 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13955 struct regcache
*regcache
= get_current_regcache ();
13956 std::vector
<CORE_ADDR
> next_pcs
;
13958 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13960 if (!next_pcs
.empty ())
13962 struct frame_info
*frame
= get_current_frame ();
13963 const address_space
*aspace
= get_frame_address_space (frame
);
13965 for (CORE_ADDR pc
: next_pcs
)
13966 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13974 /* See breakpoint.h. */
13977 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13978 const address_space
*aspace
,
13981 for (bp_location
*loc
: bp
->locations ())
13983 && breakpoint_location_address_match (loc
, aspace
, pc
))
13989 /* Check whether a software single-step breakpoint is inserted at
13993 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13996 for (breakpoint
*bpt
: all_breakpoints ())
13998 if (bpt
->type
== bp_single_step
13999 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14005 /* Tracepoint-specific operations. */
14007 /* Set tracepoint count to NUM. */
14009 set_tracepoint_count (int num
)
14011 tracepoint_count
= num
;
14012 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14016 trace_command (const char *arg
, int from_tty
)
14018 event_location_up location
= string_to_event_location (&arg
,
14020 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14021 (location
.get (), true /* is_tracepoint */);
14023 create_breakpoint (get_current_arch (),
14025 NULL
, 0, arg
, false, 1 /* parse arg */,
14027 bp_tracepoint
/* type_wanted */,
14028 0 /* Ignore count */,
14029 pending_break_support
,
14033 0 /* internal */, 0);
14037 ftrace_command (const char *arg
, int from_tty
)
14039 event_location_up location
= string_to_event_location (&arg
,
14041 create_breakpoint (get_current_arch (),
14043 NULL
, 0, arg
, false, 1 /* parse arg */,
14045 bp_fast_tracepoint
/* type_wanted */,
14046 0 /* Ignore count */,
14047 pending_break_support
,
14048 &tracepoint_breakpoint_ops
,
14051 0 /* internal */, 0);
14054 /* strace command implementation. Creates a static tracepoint. */
14057 strace_command (const char *arg
, int from_tty
)
14059 struct breakpoint_ops
*ops
;
14060 event_location_up location
;
14062 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14063 or with a normal static tracepoint. */
14064 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14066 ops
= &strace_marker_breakpoint_ops
;
14067 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14071 ops
= &tracepoint_breakpoint_ops
;
14072 location
= string_to_event_location (&arg
, current_language
);
14075 create_breakpoint (get_current_arch (),
14077 NULL
, 0, arg
, false, 1 /* parse arg */,
14079 bp_static_tracepoint
/* type_wanted */,
14080 0 /* Ignore count */,
14081 pending_break_support
,
14085 0 /* internal */, 0);
14088 /* Set up a fake reader function that gets command lines from a linked
14089 list that was acquired during tracepoint uploading. */
14091 static struct uploaded_tp
*this_utp
;
14092 static int next_cmd
;
14095 read_uploaded_action (void)
14097 char *rslt
= nullptr;
14099 if (next_cmd
< this_utp
->cmd_strings
.size ())
14101 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14108 /* Given information about a tracepoint as recorded on a target (which
14109 can be either a live system or a trace file), attempt to create an
14110 equivalent GDB tracepoint. This is not a reliable process, since
14111 the target does not necessarily have all the information used when
14112 the tracepoint was originally defined. */
14114 struct tracepoint
*
14115 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14117 const char *addr_str
;
14118 char small_buf
[100];
14119 struct tracepoint
*tp
;
14121 if (utp
->at_string
)
14122 addr_str
= utp
->at_string
.get ();
14125 /* In the absence of a source location, fall back to raw
14126 address. Since there is no way to confirm that the address
14127 means the same thing as when the trace was started, warn the
14129 warning (_("Uploaded tracepoint %d has no "
14130 "source location, using raw address"),
14132 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14133 addr_str
= small_buf
;
14136 /* There's not much we can do with a sequence of bytecodes. */
14137 if (utp
->cond
&& !utp
->cond_string
)
14138 warning (_("Uploaded tracepoint %d condition "
14139 "has no source form, ignoring it"),
14142 event_location_up location
= string_to_event_location (&addr_str
,
14144 if (!create_breakpoint (get_current_arch (),
14146 utp
->cond_string
.get (), -1, addr_str
,
14147 false /* force_condition */,
14148 0 /* parse cond/thread */,
14150 utp
->type
/* type_wanted */,
14151 0 /* Ignore count */,
14152 pending_break_support
,
14153 &tracepoint_breakpoint_ops
,
14155 utp
->enabled
/* enabled */,
14157 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14160 /* Get the tracepoint we just created. */
14161 tp
= get_tracepoint (tracepoint_count
);
14162 gdb_assert (tp
!= NULL
);
14166 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14169 trace_pass_command (small_buf
, 0);
14172 /* If we have uploaded versions of the original commands, set up a
14173 special-purpose "reader" function and call the usual command line
14174 reader, then pass the result to the breakpoint command-setting
14176 if (!utp
->cmd_strings
.empty ())
14178 counted_command_line cmd_list
;
14183 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14185 breakpoint_set_commands (tp
, std::move (cmd_list
));
14187 else if (!utp
->actions
.empty ()
14188 || !utp
->step_actions
.empty ())
14189 warning (_("Uploaded tracepoint %d actions "
14190 "have no source form, ignoring them"),
14193 /* Copy any status information that might be available. */
14194 tp
->hit_count
= utp
->hit_count
;
14195 tp
->traceframe_usage
= utp
->traceframe_usage
;
14200 /* Print information on tracepoint number TPNUM_EXP, or all if
14204 info_tracepoints_command (const char *args
, int from_tty
)
14206 struct ui_out
*uiout
= current_uiout
;
14209 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14211 if (num_printed
== 0)
14213 if (args
== NULL
|| *args
== '\0')
14214 uiout
->message ("No tracepoints.\n");
14216 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14219 default_collect_info ();
14222 /* The 'enable trace' command enables tracepoints.
14223 Not supported by all targets. */
14225 enable_trace_command (const char *args
, int from_tty
)
14227 enable_command (args
, from_tty
);
14230 /* The 'disable trace' command disables tracepoints.
14231 Not supported by all targets. */
14233 disable_trace_command (const char *args
, int from_tty
)
14235 disable_command (args
, from_tty
);
14238 /* Remove a tracepoint (or all if no argument). */
14240 delete_trace_command (const char *arg
, int from_tty
)
14246 int breaks_to_delete
= 0;
14248 /* Delete all breakpoints if no argument.
14249 Do not delete internal or call-dummy breakpoints, these
14250 have to be deleted with an explicit breakpoint number
14252 for (breakpoint
*tp
: all_tracepoints ())
14253 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14255 breaks_to_delete
= 1;
14259 /* Ask user only if there are some breakpoints to delete. */
14261 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14263 for (breakpoint
*b
: all_breakpoints_safe ())
14264 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14265 delete_breakpoint (b
);
14269 map_breakpoint_numbers
14270 (arg
, [&] (breakpoint
*br
)
14272 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14276 /* Helper function for trace_pass_command. */
14279 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14281 tp
->pass_count
= count
;
14282 gdb::observers::breakpoint_modified
.notify (tp
);
14284 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14285 tp
->number
, count
);
14288 /* Set passcount for tracepoint.
14290 First command argument is passcount, second is tracepoint number.
14291 If tracepoint number omitted, apply to most recently defined.
14292 Also accepts special argument "all". */
14295 trace_pass_command (const char *args
, int from_tty
)
14297 struct tracepoint
*t1
;
14300 if (args
== 0 || *args
== 0)
14301 error (_("passcount command requires an "
14302 "argument (count + optional TP num)"));
14304 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14306 args
= skip_spaces (args
);
14307 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14309 args
+= 3; /* Skip special argument "all". */
14311 error (_("Junk at end of arguments."));
14313 for (breakpoint
*b
: all_tracepoints ())
14315 t1
= (struct tracepoint
*) b
;
14316 trace_pass_set_count (t1
, count
, from_tty
);
14319 else if (*args
== '\0')
14321 t1
= get_tracepoint_by_number (&args
, NULL
);
14323 trace_pass_set_count (t1
, count
, from_tty
);
14327 number_or_range_parser
parser (args
);
14328 while (!parser
.finished ())
14330 t1
= get_tracepoint_by_number (&args
, &parser
);
14332 trace_pass_set_count (t1
, count
, from_tty
);
14337 struct tracepoint
*
14338 get_tracepoint (int num
)
14340 for (breakpoint
*t
: all_tracepoints ())
14341 if (t
->number
== num
)
14342 return (struct tracepoint
*) t
;
14347 /* Find the tracepoint with the given target-side number (which may be
14348 different from the tracepoint number after disconnecting and
14351 struct tracepoint
*
14352 get_tracepoint_by_number_on_target (int num
)
14354 for (breakpoint
*b
: all_tracepoints ())
14356 struct tracepoint
*t
= (struct tracepoint
*) b
;
14358 if (t
->number_on_target
== num
)
14365 /* Utility: parse a tracepoint number and look it up in the list.
14366 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14367 If the argument is missing, the most recent tracepoint
14368 (tracepoint_count) is returned. */
14370 struct tracepoint
*
14371 get_tracepoint_by_number (const char **arg
,
14372 number_or_range_parser
*parser
)
14375 const char *instring
= arg
== NULL
? NULL
: *arg
;
14377 if (parser
!= NULL
)
14379 gdb_assert (!parser
->finished ());
14380 tpnum
= parser
->get_number ();
14382 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14383 tpnum
= tracepoint_count
;
14385 tpnum
= get_number (arg
);
14389 if (instring
&& *instring
)
14390 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14393 gdb_printf (_("No previous tracepoint\n"));
14397 for (breakpoint
*t
: all_tracepoints ())
14398 if (t
->number
== tpnum
)
14399 return (struct tracepoint
*) t
;
14401 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14406 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14408 if (b
->thread
!= -1)
14409 gdb_printf (fp
, " thread %d", b
->thread
);
14412 gdb_printf (fp
, " task %d", b
->task
);
14414 gdb_printf (fp
, "\n");
14417 /* Save information on user settable breakpoints (watchpoints, etc) to
14418 a new script file named FILENAME. If FILTER is non-NULL, call it
14419 on each breakpoint and only include the ones for which it returns
14423 save_breakpoints (const char *filename
, int from_tty
,
14424 bool (*filter
) (const struct breakpoint
*))
14427 int extra_trace_bits
= 0;
14429 if (filename
== 0 || *filename
== 0)
14430 error (_("Argument required (file name in which to save)"));
14432 /* See if we have anything to save. */
14433 for (breakpoint
*tp
: all_breakpoints ())
14435 /* Skip internal and momentary breakpoints. */
14436 if (!user_breakpoint_p (tp
))
14439 /* If we have a filter, only save the breakpoints it accepts. */
14440 if (filter
&& !filter (tp
))
14445 if (is_tracepoint (tp
))
14447 extra_trace_bits
= 1;
14449 /* We can stop searching. */
14456 warning (_("Nothing to save."));
14460 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14464 if (!fp
.open (expanded_filename
.get (), "w"))
14465 error (_("Unable to open file '%s' for saving (%s)"),
14466 expanded_filename
.get (), safe_strerror (errno
));
14468 if (extra_trace_bits
)
14469 save_trace_state_variables (&fp
);
14471 for (breakpoint
*tp
: all_breakpoints ())
14473 /* Skip internal and momentary breakpoints. */
14474 if (!user_breakpoint_p (tp
))
14477 /* If we have a filter, only save the breakpoints it accepts. */
14478 if (filter
&& !filter (tp
))
14481 tp
->ops
->print_recreate (tp
, &fp
);
14483 /* Note, we can't rely on tp->number for anything, as we can't
14484 assume the recreated breakpoint numbers will match. Use $bpnum
14487 if (tp
->cond_string
)
14488 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14490 if (tp
->ignore_count
)
14491 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14493 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14495 fp
.puts (" commands\n");
14497 current_uiout
->redirect (&fp
);
14500 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14502 catch (const gdb_exception
&ex
)
14504 current_uiout
->redirect (NULL
);
14508 current_uiout
->redirect (NULL
);
14509 fp
.puts (" end\n");
14512 if (tp
->enable_state
== bp_disabled
)
14513 fp
.puts ("disable $bpnum\n");
14515 /* If this is a multi-location breakpoint, check if the locations
14516 should be individually disabled. Watchpoint locations are
14517 special, and not user visible. */
14518 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14522 for (bp_location
*loc
: tp
->locations ())
14525 fp
.printf ("disable $bpnum.%d\n", n
);
14532 if (extra_trace_bits
&& !default_collect
.empty ())
14533 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14536 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14539 /* The `save breakpoints' command. */
14542 save_breakpoints_command (const char *args
, int from_tty
)
14544 save_breakpoints (args
, from_tty
, NULL
);
14547 /* The `save tracepoints' command. */
14550 save_tracepoints_command (const char *args
, int from_tty
)
14552 save_breakpoints (args
, from_tty
, is_tracepoint
);
14556 /* This help string is used to consolidate all the help string for specifying
14557 locations used by several commands. */
14559 #define LOCATION_HELP_STRING \
14560 "Linespecs are colon-separated lists of location parameters, such as\n\
14561 source filename, function name, label name, and line number.\n\
14562 Example: To specify the start of a label named \"the_top\" in the\n\
14563 function \"fact\" in the file \"factorial.c\", use\n\
14564 \"factorial.c:fact:the_top\".\n\
14566 Address locations begin with \"*\" and specify an exact address in the\n\
14567 program. Example: To specify the fourth byte past the start function\n\
14568 \"main\", use \"*main + 4\".\n\
14570 Explicit locations are similar to linespecs but use an option/argument\n\
14571 syntax to specify location parameters.\n\
14572 Example: To specify the start of the label named \"the_top\" in the\n\
14573 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14574 -function fact -label the_top\".\n\
14576 By default, a specified function is matched against the program's\n\
14577 functions in all scopes. For C++, this means in all namespaces and\n\
14578 classes. For Ada, this means in all packages. E.g., in C++,\n\
14579 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14580 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14581 specified name as a complete fully-qualified name instead."
14583 /* This help string is used for the break, hbreak, tbreak and thbreak
14584 commands. It is defined as a macro to prevent duplication.
14585 COMMAND should be a string constant containing the name of the
14588 #define BREAK_ARGS_HELP(command) \
14589 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14590 \t[-force-condition] [if CONDITION]\n\
14591 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14592 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14593 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14594 `-probe-dtrace' (for a DTrace probe).\n\
14595 LOCATION may be a linespec, address, or explicit location as described\n\
14598 With no LOCATION, uses current execution address of the selected\n\
14599 stack frame. This is useful for breaking on return to a stack frame.\n\
14601 THREADNUM is the number from \"info threads\".\n\
14602 CONDITION is a boolean expression.\n\
14604 With the \"-force-condition\" flag, the condition is defined even when\n\
14605 it is invalid for all current locations.\n\
14606 \n" LOCATION_HELP_STRING "\n\n\
14607 Multiple breakpoints at one place are permitted, and useful if their\n\
14608 conditions are different.\n\
14610 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14612 /* List of subcommands for "catch". */
14613 static struct cmd_list_element
*catch_cmdlist
;
14615 /* List of subcommands for "tcatch". */
14616 static struct cmd_list_element
*tcatch_cmdlist
;
14619 add_catch_command (const char *name
, const char *docstring
,
14620 cmd_func_ftype
*func
,
14621 completer_ftype
*completer
,
14622 void *user_data_catch
,
14623 void *user_data_tcatch
)
14625 struct cmd_list_element
*command
;
14627 command
= add_cmd (name
, class_breakpoint
, docstring
,
14629 command
->func
= func
;
14630 command
->set_context (user_data_catch
);
14631 set_cmd_completer (command
, completer
);
14633 command
= add_cmd (name
, class_breakpoint
, docstring
,
14635 command
->func
= func
;
14636 command
->set_context (user_data_tcatch
);
14637 set_cmd_completer (command
, completer
);
14640 /* Zero if any of the breakpoint's locations could be a location where
14641 functions have been inlined, nonzero otherwise. */
14644 is_non_inline_function (struct breakpoint
*b
)
14646 /* The shared library event breakpoint is set on the address of a
14647 non-inline function. */
14648 if (b
->type
== bp_shlib_event
)
14654 /* Nonzero if the specified PC cannot be a location where functions
14655 have been inlined. */
14658 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14659 const target_waitstatus
&ws
)
14661 for (breakpoint
*b
: all_breakpoints ())
14663 if (!is_non_inline_function (b
))
14666 for (bp_location
*bl
: b
->locations ())
14668 if (!bl
->shlib_disabled
14669 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14677 /* Remove any references to OBJFILE which is going to be freed. */
14680 breakpoint_free_objfile (struct objfile
*objfile
)
14682 for (bp_location
*loc
: all_bp_locations ())
14683 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14684 loc
->symtab
= NULL
;
14688 initialize_breakpoint_ops (void)
14690 static int initialized
= 0;
14692 struct breakpoint_ops
*ops
;
14698 /* The breakpoint_ops structure to be inherit by all kinds of
14699 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14700 internal and momentary breakpoints, etc.). */
14701 ops
= &bkpt_base_breakpoint_ops
;
14702 *ops
= base_breakpoint_ops
;
14703 ops
->re_set
= bkpt_re_set
;
14704 ops
->insert_location
= bkpt_insert_location
;
14705 ops
->remove_location
= bkpt_remove_location
;
14706 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
14707 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
14708 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
14709 ops
->decode_location
= bkpt_decode_location
;
14711 /* The breakpoint_ops structure to be used in regular breakpoints. */
14712 ops
= &bkpt_breakpoint_ops
;
14713 *ops
= bkpt_base_breakpoint_ops
;
14714 ops
->re_set
= bkpt_re_set
;
14715 ops
->resources_needed
= bkpt_resources_needed
;
14716 ops
->print_it
= bkpt_print_it
;
14717 ops
->print_mention
= bkpt_print_mention
;
14718 ops
->print_recreate
= bkpt_print_recreate
;
14720 /* Ranged breakpoints. */
14721 ops
= &ranged_breakpoint_ops
;
14722 *ops
= bkpt_breakpoint_ops
;
14723 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
14724 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
14725 ops
->print_it
= print_it_ranged_breakpoint
;
14726 ops
->print_one
= print_one_ranged_breakpoint
;
14727 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
14728 ops
->print_mention
= print_mention_ranged_breakpoint
;
14729 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
14731 /* Internal breakpoints. */
14732 ops
= &internal_breakpoint_ops
;
14733 *ops
= bkpt_base_breakpoint_ops
;
14734 ops
->re_set
= internal_bkpt_re_set
;
14735 ops
->check_status
= internal_bkpt_check_status
;
14736 ops
->print_it
= internal_bkpt_print_it
;
14737 ops
->print_mention
= internal_bkpt_print_mention
;
14739 /* Momentary breakpoints. */
14740 ops
= &momentary_breakpoint_ops
;
14741 *ops
= bkpt_base_breakpoint_ops
;
14742 ops
->re_set
= momentary_bkpt_re_set
;
14743 ops
->check_status
= momentary_bkpt_check_status
;
14744 ops
->print_it
= momentary_bkpt_print_it
;
14745 ops
->print_mention
= momentary_bkpt_print_mention
;
14747 /* Probe breakpoints. */
14748 ops
= &bkpt_probe_breakpoint_ops
;
14749 *ops
= bkpt_breakpoint_ops
;
14750 ops
->insert_location
= bkpt_probe_insert_location
;
14751 ops
->remove_location
= bkpt_probe_remove_location
;
14752 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
14753 ops
->decode_location
= bkpt_probe_decode_location
;
14756 ops
= &watchpoint_breakpoint_ops
;
14757 *ops
= base_breakpoint_ops
;
14758 ops
->re_set
= re_set_watchpoint
;
14759 ops
->insert_location
= insert_watchpoint
;
14760 ops
->remove_location
= remove_watchpoint
;
14761 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
14762 ops
->check_status
= check_status_watchpoint
;
14763 ops
->resources_needed
= resources_needed_watchpoint
;
14764 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
14765 ops
->print_it
= print_it_watchpoint
;
14766 ops
->print_mention
= print_mention_watchpoint
;
14767 ops
->print_recreate
= print_recreate_watchpoint
;
14768 ops
->explains_signal
= explains_signal_watchpoint
;
14770 /* Masked watchpoints. */
14771 ops
= &masked_watchpoint_breakpoint_ops
;
14772 *ops
= watchpoint_breakpoint_ops
;
14773 ops
->insert_location
= insert_masked_watchpoint
;
14774 ops
->remove_location
= remove_masked_watchpoint
;
14775 ops
->resources_needed
= resources_needed_masked_watchpoint
;
14776 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
14777 ops
->print_it
= print_it_masked_watchpoint
;
14778 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
14779 ops
->print_mention
= print_mention_masked_watchpoint
;
14780 ops
->print_recreate
= print_recreate_masked_watchpoint
;
14783 ops
= &tracepoint_breakpoint_ops
;
14784 *ops
= base_breakpoint_ops
;
14785 ops
->re_set
= tracepoint_re_set
;
14786 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
14787 ops
->print_one_detail
= tracepoint_print_one_detail
;
14788 ops
->print_mention
= tracepoint_print_mention
;
14789 ops
->print_recreate
= tracepoint_print_recreate
;
14790 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
14791 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
14792 ops
->decode_location
= tracepoint_decode_location
;
14794 /* Probe tracepoints. */
14795 ops
= &tracepoint_probe_breakpoint_ops
;
14796 *ops
= tracepoint_breakpoint_ops
;
14797 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
14798 ops
->decode_location
= tracepoint_probe_decode_location
;
14800 /* Static tracepoints with marker (`-m'). */
14801 ops
= &strace_marker_breakpoint_ops
;
14802 *ops
= tracepoint_breakpoint_ops
;
14803 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
14804 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
14805 ops
->decode_location
= strace_marker_decode_location
;
14807 /* Solib-related catchpoints. */
14808 ops
= &catch_solib_breakpoint_ops
;
14809 *ops
= base_breakpoint_ops
;
14810 ops
->insert_location
= insert_catch_solib
;
14811 ops
->remove_location
= remove_catch_solib
;
14812 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
14813 ops
->check_status
= check_status_catch_solib
;
14814 ops
->print_it
= print_it_catch_solib
;
14815 ops
->print_one
= print_one_catch_solib
;
14816 ops
->print_mention
= print_mention_catch_solib
;
14817 ops
->print_recreate
= print_recreate_catch_solib
;
14819 ops
= &dprintf_breakpoint_ops
;
14820 *ops
= bkpt_base_breakpoint_ops
;
14821 ops
->re_set
= dprintf_re_set
;
14822 ops
->resources_needed
= bkpt_resources_needed
;
14823 ops
->print_it
= bkpt_print_it
;
14824 ops
->print_mention
= bkpt_print_mention
;
14825 ops
->print_recreate
= dprintf_print_recreate
;
14826 ops
->after_condition_true
= dprintf_after_condition_true
;
14827 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
14830 /* Chain containing all defined "enable breakpoint" subcommands. */
14832 static struct cmd_list_element
*enablebreaklist
= NULL
;
14834 /* See breakpoint.h. */
14836 cmd_list_element
*commands_cmd_element
= nullptr;
14838 void _initialize_breakpoint ();
14840 _initialize_breakpoint ()
14842 struct cmd_list_element
*c
;
14844 initialize_breakpoint_ops ();
14846 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14848 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14850 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14853 breakpoint_chain
= 0;
14854 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14855 before a breakpoint is set. */
14856 breakpoint_count
= 0;
14858 tracepoint_count
= 0;
14860 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14861 Set ignore-count of breakpoint number N to COUNT.\n\
14862 Usage is `ignore N COUNT'."));
14864 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14865 commands_command
, _("\
14866 Set commands to be executed when the given breakpoints are hit.\n\
14867 Give a space-separated breakpoint list as argument after \"commands\".\n\
14868 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14870 With no argument, the targeted breakpoint is the last one set.\n\
14871 The commands themselves follow starting on the next line.\n\
14872 Type a line containing \"end\" to indicate the end of them.\n\
14873 Give \"silent\" as the first line to make the breakpoint silent;\n\
14874 then no output is printed when it is hit, except what the commands print."));
14876 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14877 static std::string condition_command_help
14878 = gdb::option::build_help (_("\
14879 Specify breakpoint number N to break only if COND is true.\n\
14880 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14881 is an expression to be evaluated whenever breakpoint N is reached.\n\
14884 %OPTIONS%"), cc_opts
);
14886 c
= add_com ("condition", class_breakpoint
, condition_command
,
14887 condition_command_help
.c_str ());
14888 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14890 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14891 Set a temporary breakpoint.\n\
14892 Like \"break\" except the breakpoint is only temporary,\n\
14893 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14894 by using \"enable delete\" on the breakpoint number.\n\
14896 BREAK_ARGS_HELP ("tbreak")));
14897 set_cmd_completer (c
, location_completer
);
14899 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14900 Set a hardware assisted breakpoint.\n\
14901 Like \"break\" except the breakpoint requires hardware support,\n\
14902 some target hardware may not have this support.\n\
14904 BREAK_ARGS_HELP ("hbreak")));
14905 set_cmd_completer (c
, location_completer
);
14907 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14908 Set a temporary hardware assisted breakpoint.\n\
14909 Like \"hbreak\" except the breakpoint is only temporary,\n\
14910 so it will be deleted when hit.\n\
14912 BREAK_ARGS_HELP ("thbreak")));
14913 set_cmd_completer (c
, location_completer
);
14915 cmd_list_element
*enable_cmd
14916 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14917 Enable all or some breakpoints.\n\
14918 Usage: enable [BREAKPOINTNUM]...\n\
14919 Give breakpoint numbers (separated by spaces) as arguments.\n\
14920 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14921 This is used to cancel the effect of the \"disable\" command.\n\
14922 With a subcommand you can enable temporarily."),
14923 &enablelist
, 1, &cmdlist
);
14925 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14927 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14928 Enable all or some breakpoints.\n\
14929 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14930 Give breakpoint numbers (separated by spaces) as arguments.\n\
14931 This is used to cancel the effect of the \"disable\" command.\n\
14932 May be abbreviated to simply \"enable\"."),
14933 &enablebreaklist
, 1, &enablelist
);
14935 add_cmd ("once", no_class
, enable_once_command
, _("\
14936 Enable some breakpoints for one hit.\n\
14937 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14938 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14941 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14942 Enable some breakpoints and delete when hit.\n\
14943 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14944 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14947 add_cmd ("count", no_class
, enable_count_command
, _("\
14948 Enable some breakpoints for COUNT hits.\n\
14949 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14950 If a breakpoint is hit while enabled in this fashion,\n\
14951 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14954 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14955 Enable some breakpoints and delete when hit.\n\
14956 Usage: enable delete BREAKPOINTNUM...\n\
14957 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14960 add_cmd ("once", no_class
, enable_once_command
, _("\
14961 Enable some breakpoints for one hit.\n\
14962 Usage: enable once BREAKPOINTNUM...\n\
14963 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14966 add_cmd ("count", no_class
, enable_count_command
, _("\
14967 Enable some breakpoints for COUNT hits.\n\
14968 Usage: enable count COUNT BREAKPOINTNUM...\n\
14969 If a breakpoint is hit while enabled in this fashion,\n\
14970 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14973 cmd_list_element
*disable_cmd
14974 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14975 Disable all or some breakpoints.\n\
14976 Usage: disable [BREAKPOINTNUM]...\n\
14977 Arguments are breakpoint numbers with spaces in between.\n\
14978 To disable all breakpoints, give no argument.\n\
14979 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14980 &disablelist
, 1, &cmdlist
);
14981 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14982 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14984 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14985 Disable all or some breakpoints.\n\
14986 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14987 Arguments are breakpoint numbers with spaces in between.\n\
14988 To disable all breakpoints, give no argument.\n\
14989 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14990 This command may be abbreviated \"disable\"."),
14993 cmd_list_element
*delete_cmd
14994 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14995 Delete all or some breakpoints.\n\
14996 Usage: delete [BREAKPOINTNUM]...\n\
14997 Arguments are breakpoint numbers with spaces in between.\n\
14998 To delete all breakpoints, give no argument.\n\
15000 Also a prefix command for deletion of other GDB objects."),
15001 &deletelist
, 1, &cmdlist
);
15002 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15003 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15005 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15006 Delete all or some breakpoints or auto-display expressions.\n\
15007 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15008 Arguments are breakpoint numbers with spaces in between.\n\
15009 To delete all breakpoints, give no argument.\n\
15010 This command may be abbreviated \"delete\"."),
15013 cmd_list_element
*clear_cmd
15014 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15015 Clear breakpoint at specified location.\n\
15016 Argument may be a linespec, explicit, or address location as described below.\n\
15018 With no argument, clears all breakpoints in the line that the selected frame\n\
15019 is executing in.\n"
15020 "\n" LOCATION_HELP_STRING
"\n\n\
15021 See also the \"delete\" command which clears breakpoints by number."));
15022 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15024 cmd_list_element
*break_cmd
15025 = add_com ("break", class_breakpoint
, break_command
, _("\
15026 Set breakpoint at specified location.\n"
15027 BREAK_ARGS_HELP ("break")));
15028 set_cmd_completer (break_cmd
, location_completer
);
15030 add_com_alias ("b", break_cmd
, class_run
, 1);
15031 add_com_alias ("br", break_cmd
, class_run
, 1);
15032 add_com_alias ("bre", break_cmd
, class_run
, 1);
15033 add_com_alias ("brea", break_cmd
, class_run
, 1);
15035 cmd_list_element
*info_breakpoints_cmd
15036 = add_info ("breakpoints", info_breakpoints_command
, _("\
15037 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15038 The \"Type\" column indicates one of:\n\
15039 \tbreakpoint - normal breakpoint\n\
15040 \twatchpoint - watchpoint\n\
15041 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15042 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15043 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15044 address and file/line number respectively.\n\
15046 Convenience variable \"$_\" and default examine address for \"x\"\n\
15047 are set to the address of the last breakpoint listed unless the command\n\
15048 is prefixed with \"server \".\n\n\
15049 Convenience variable \"$bpnum\" contains the number of the last\n\
15050 breakpoint set."));
15052 add_info_alias ("b", info_breakpoints_cmd
, 1);
15054 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15055 Status of all breakpoints, or breakpoint number NUMBER.\n\
15056 The \"Type\" column indicates one of:\n\
15057 \tbreakpoint - normal breakpoint\n\
15058 \twatchpoint - watchpoint\n\
15059 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15060 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15061 \tuntil - internal breakpoint used by the \"until\" command\n\
15062 \tfinish - internal breakpoint used by the \"finish\" command\n\
15063 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15064 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15065 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15066 address and file/line number respectively.\n\
15068 Convenience variable \"$_\" and default examine address for \"x\"\n\
15069 are set to the address of the last breakpoint listed unless the command\n\
15070 is prefixed with \"server \".\n\n\
15071 Convenience variable \"$bpnum\" contains the number of the last\n\
15073 &maintenanceinfolist
);
15075 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15076 Set catchpoints to catch events."),
15078 0/*allow-unknown*/, &cmdlist
);
15080 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15081 Set temporary catchpoints to catch events."),
15083 0/*allow-unknown*/, &cmdlist
);
15085 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15086 Usage: catch load [REGEX]\n\
15087 If REGEX is given, only stop for libraries matching the regular expression."),
15088 catch_load_command_1
,
15092 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15093 Usage: catch unload [REGEX]\n\
15094 If REGEX is given, only stop for libraries matching the regular expression."),
15095 catch_unload_command_1
,
15100 const auto opts
= make_watch_options_def_group (nullptr);
15102 static const std::string watch_help
= gdb::option::build_help (_("\
15103 Set a watchpoint for EXPRESSION.\n\
15104 Usage: watch [-location] EXPRESSION\n\
15109 A watchpoint stops execution of your program whenever the value of\n\
15110 an expression changes."), opts
);
15111 c
= add_com ("watch", class_breakpoint
, watch_command
,
15112 watch_help
.c_str ());
15113 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15115 static const std::string rwatch_help
= gdb::option::build_help (_("\
15116 Set a read watchpoint for EXPRESSION.\n\
15117 Usage: rwatch [-location] EXPRESSION\n\
15122 A read watchpoint stops execution of your program whenever the value of\n\
15123 an expression is read."), opts
);
15124 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15125 rwatch_help
.c_str ());
15126 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15128 static const std::string awatch_help
= gdb::option::build_help (_("\
15129 Set an access watchpoint for EXPRESSION.\n\
15130 Usage: awatch [-location] EXPRESSION\n\
15135 An access watchpoint stops execution of your program whenever the value\n\
15136 of an expression is either read or written."), opts
);
15137 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15138 awatch_help
.c_str ());
15139 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15141 add_info ("watchpoints", info_watchpoints_command
, _("\
15142 Status of specified watchpoints (all watchpoints if no argument)."));
15144 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15145 respond to changes - contrary to the description. */
15146 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15147 &can_use_hw_watchpoints
, _("\
15148 Set debugger's willingness to use watchpoint hardware."), _("\
15149 Show debugger's willingness to use watchpoint hardware."), _("\
15150 If zero, gdb will not use hardware for new watchpoints, even if\n\
15151 such is available. (However, any hardware watchpoints that were\n\
15152 created before setting this to nonzero, will continue to use watchpoint\n\
15155 show_can_use_hw_watchpoints
,
15156 &setlist
, &showlist
);
15158 can_use_hw_watchpoints
= 1;
15160 /* Tracepoint manipulation commands. */
15162 cmd_list_element
*trace_cmd
15163 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15164 Set a tracepoint at specified location.\n\
15166 BREAK_ARGS_HELP ("trace") "\n\
15167 Do \"help tracepoints\" for info on other tracepoint commands."));
15168 set_cmd_completer (trace_cmd
, location_completer
);
15170 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15171 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15172 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15173 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15175 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15176 Set a fast tracepoint at specified location.\n\
15178 BREAK_ARGS_HELP ("ftrace") "\n\
15179 Do \"help tracepoints\" for info on other tracepoint commands."));
15180 set_cmd_completer (c
, location_completer
);
15182 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15183 Set a static tracepoint at location or marker.\n\
15185 strace [LOCATION] [if CONDITION]\n\
15186 LOCATION may be a linespec, explicit, or address location (described below) \n\
15187 or -m MARKER_ID.\n\n\
15188 If a marker id is specified, probe the marker with that name. With\n\
15189 no LOCATION, uses current execution address of the selected stack frame.\n\
15190 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15191 This collects arbitrary user data passed in the probe point call to the\n\
15192 tracing library. You can inspect it when analyzing the trace buffer,\n\
15193 by printing the $_sdata variable like any other convenience variable.\n\
15195 CONDITION is a boolean expression.\n\
15196 \n" LOCATION_HELP_STRING
"\n\n\
15197 Multiple tracepoints at one place are permitted, and useful if their\n\
15198 conditions are different.\n\
15200 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15201 Do \"help tracepoints\" for info on other tracepoint commands."));
15202 set_cmd_completer (c
, location_completer
);
15204 cmd_list_element
*info_tracepoints_cmd
15205 = add_info ("tracepoints", info_tracepoints_command
, _("\
15206 Status of specified tracepoints (all tracepoints if no argument).\n\
15207 Convenience variable \"$tpnum\" contains the number of the\n\
15208 last tracepoint set."));
15210 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15212 cmd_list_element
*delete_tracepoints_cmd
15213 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15214 Delete specified tracepoints.\n\
15215 Arguments are tracepoint numbers, separated by spaces.\n\
15216 No argument means delete all tracepoints."),
15218 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15220 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15221 Disable specified tracepoints.\n\
15222 Arguments are tracepoint numbers, separated by spaces.\n\
15223 No argument means disable all tracepoints."),
15225 deprecate_cmd (c
, "disable");
15227 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15228 Enable specified tracepoints.\n\
15229 Arguments are tracepoint numbers, separated by spaces.\n\
15230 No argument means enable all tracepoints."),
15232 deprecate_cmd (c
, "enable");
15234 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15235 Set the passcount for a tracepoint.\n\
15236 The trace will end when the tracepoint has been passed 'count' times.\n\
15237 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15238 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15240 add_basic_prefix_cmd ("save", class_breakpoint
,
15241 _("Save breakpoint definitions as a script."),
15243 0/*allow-unknown*/, &cmdlist
);
15245 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15246 Save current breakpoint definitions as a script.\n\
15247 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15248 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15249 session to restore them."),
15251 set_cmd_completer (c
, filename_completer
);
15253 cmd_list_element
*save_tracepoints_cmd
15254 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15255 Save current tracepoint definitions as a script.\n\
15256 Use the 'source' command in another debug session to restore them."),
15258 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15260 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15261 deprecate_cmd (c
, "save tracepoints");
15263 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
15265 Breakpoint specific settings.\n\
15266 Configure various breakpoint-specific variables such as\n\
15267 pending breakpoint behavior."),
15269 Breakpoint specific settings.\n\
15270 Configure various breakpoint-specific variables such as\n\
15271 pending breakpoint behavior."),
15272 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
15273 &setlist
, &showlist
);
15275 add_setshow_auto_boolean_cmd ("pending", no_class
,
15276 &pending_break_support
, _("\
15277 Set debugger's behavior regarding pending breakpoints."), _("\
15278 Show debugger's behavior regarding pending breakpoints."), _("\
15279 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15280 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15281 an error. If auto, an unrecognized breakpoint location results in a\n\
15282 user-query to see if a pending breakpoint should be created."),
15284 show_pending_break_support
,
15285 &breakpoint_set_cmdlist
,
15286 &breakpoint_show_cmdlist
);
15288 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15290 add_setshow_boolean_cmd ("auto-hw", no_class
,
15291 &automatic_hardware_breakpoints
, _("\
15292 Set automatic usage of hardware breakpoints."), _("\
15293 Show automatic usage of hardware breakpoints."), _("\
15294 If set, the debugger will automatically use hardware breakpoints for\n\
15295 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15296 a warning will be emitted for such breakpoints."),
15298 show_automatic_hardware_breakpoints
,
15299 &breakpoint_set_cmdlist
,
15300 &breakpoint_show_cmdlist
);
15302 add_setshow_boolean_cmd ("always-inserted", class_support
,
15303 &always_inserted_mode
, _("\
15304 Set mode for inserting breakpoints."), _("\
15305 Show mode for inserting breakpoints."), _("\
15306 When this mode is on, breakpoints are inserted immediately as soon as\n\
15307 they're created, kept inserted even when execution stops, and removed\n\
15308 only when the user deletes them. When this mode is off (the default),\n\
15309 breakpoints are inserted only when execution continues, and removed\n\
15310 when execution stops."),
15312 &show_always_inserted_mode
,
15313 &breakpoint_set_cmdlist
,
15314 &breakpoint_show_cmdlist
);
15316 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15317 condition_evaluation_enums
,
15318 &condition_evaluation_mode_1
, _("\
15319 Set mode of breakpoint condition evaluation."), _("\
15320 Show mode of breakpoint condition evaluation."), _("\
15321 When this is set to \"host\", breakpoint conditions will be\n\
15322 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15323 breakpoint conditions will be downloaded to the target (if the target\n\
15324 supports such feature) and conditions will be evaluated on the target's side.\n\
15325 If this is set to \"auto\" (default), this will be automatically set to\n\
15326 \"target\" if it supports condition evaluation, otherwise it will\n\
15327 be set to \"host\"."),
15328 &set_condition_evaluation_mode
,
15329 &show_condition_evaluation_mode
,
15330 &breakpoint_set_cmdlist
,
15331 &breakpoint_show_cmdlist
);
15333 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15334 Set a breakpoint for an address range.\n\
15335 break-range START-LOCATION, END-LOCATION\n\
15336 where START-LOCATION and END-LOCATION can be one of the following:\n\
15337 LINENUM, for that line in the current file,\n\
15338 FILE:LINENUM, for that line in that file,\n\
15339 +OFFSET, for that number of lines after the current line\n\
15340 or the start of the range\n\
15341 FUNCTION, for the first line in that function,\n\
15342 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15343 *ADDRESS, for the instruction at that address.\n\
15345 The breakpoint will stop execution of the inferior whenever it executes\n\
15346 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15347 range (including START-LOCATION and END-LOCATION)."));
15349 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15350 Set a dynamic printf at specified location.\n\
15351 dprintf location,format string,arg1,arg2,...\n\
15352 location may be a linespec, explicit, or address location.\n"
15353 "\n" LOCATION_HELP_STRING
));
15354 set_cmd_completer (c
, location_completer
);
15356 add_setshow_enum_cmd ("dprintf-style", class_support
,
15357 dprintf_style_enums
, &dprintf_style
, _("\
15358 Set the style of usage for dynamic printf."), _("\
15359 Show the style of usage for dynamic printf."), _("\
15360 This setting chooses how GDB will do a dynamic printf.\n\
15361 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15362 console, as with the \"printf\" command.\n\
15363 If the value is \"call\", the print is done by calling a function in your\n\
15364 program; by default printf(), but you can choose a different function or\n\
15365 output stream by setting dprintf-function and dprintf-channel."),
15366 update_dprintf_commands
, NULL
,
15367 &setlist
, &showlist
);
15369 add_setshow_string_cmd ("dprintf-function", class_support
,
15370 &dprintf_function
, _("\
15371 Set the function to use for dynamic printf."), _("\
15372 Show the function to use for dynamic printf."), NULL
,
15373 update_dprintf_commands
, NULL
,
15374 &setlist
, &showlist
);
15376 add_setshow_string_cmd ("dprintf-channel", class_support
,
15377 &dprintf_channel
, _("\
15378 Set the channel to use for dynamic printf."), _("\
15379 Show the channel to use for dynamic printf."), NULL
,
15380 update_dprintf_commands
, NULL
,
15381 &setlist
, &showlist
);
15383 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15384 &disconnected_dprintf
, _("\
15385 Set whether dprintf continues after GDB disconnects."), _("\
15386 Show whether dprintf continues after GDB disconnects."), _("\
15387 Use this to let dprintf commands continue to hit and produce output\n\
15388 even if GDB disconnects or detaches from the target."),
15391 &setlist
, &showlist
);
15393 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15394 Target agent only formatted printing, like the C \"printf\" function.\n\
15395 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15396 This supports most C printf format specifications, like %s, %d, etc.\n\
15397 This is useful for formatted output in user-defined commands."));
15399 automatic_hardware_breakpoints
= true;
15401 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
15403 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,