1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2023 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"
59 #include "parser-defs.h"
60 #include "gdbsupport/gdb_regex.h"
62 #include "cli/cli-utils.h"
65 #include "dummy-frame.h"
67 #include "gdbsupport/format.h"
68 #include "thread-fsm.h"
69 #include "tid-parse.h"
70 #include "cli/cli-style.h"
71 #include "cli/cli-decode.h"
73 /* readline include files */
74 #include "readline/tilde.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "extension.h"
82 #include "progspace-and-thread.h"
83 #include "gdbsupport/array-view.h"
84 #include "gdbsupport/gdb_optional.h"
86 /* Prototypes for local functions. */
88 static void map_breakpoint_numbers (const char *,
89 gdb::function_view
<void (breakpoint
*)>);
92 create_sals_from_location_spec_default (location_spec
*locspec
,
93 linespec_result
*canonical
);
95 static void create_breakpoints_sal (struct gdbarch
*,
96 struct linespec_result
*,
97 gdb::unique_xmalloc_ptr
<char>,
98 gdb::unique_xmalloc_ptr
<char>,
100 enum bpdisp
, int, int,
102 int, int, int, unsigned);
104 static int can_use_hardware_watchpoint
105 (const std::vector
<value_ref_ptr
> &vals
);
107 static void mention (const breakpoint
*);
109 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
111 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
113 static struct breakpoint
*
114 momentary_breakpoint_from_master (struct breakpoint
*orig
,
116 int loc_enabled
, int thread
);
118 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, bool);
120 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
123 struct program_space
*pspace
);
125 static bool watchpoint_locations_match (const struct bp_location
*loc1
,
126 const struct bp_location
*loc2
);
128 static bool breakpoint_locations_match (const struct bp_location
*loc1
,
129 const struct bp_location
*loc2
,
130 bool sw_hw_bps_match
= false);
132 static bool breakpoint_location_address_match (struct bp_location
*bl
,
133 const struct address_space
*aspace
,
136 static bool breakpoint_location_address_range_overlap (struct bp_location
*,
137 const address_space
*,
140 static int remove_breakpoint (struct bp_location
*);
141 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
143 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
145 static int hw_breakpoint_used_count (void);
147 static int hw_watchpoint_use_count (struct breakpoint
*);
149 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
151 int *other_type_used
);
153 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
156 static void decref_bp_location (struct bp_location
**loc
);
158 static std::vector
<symtab_and_line
> bkpt_probe_decode_location_spec
159 (struct breakpoint
*b
,
160 location_spec
*locspec
,
161 struct program_space
*search_pspace
);
163 static bool bl_address_is_meaningful (bp_location
*loc
);
165 static int find_loc_num_by_location (const bp_location
*loc
);
167 /* update_global_location_list's modes of operation wrt to whether to
168 insert locations now. */
169 enum ugll_insert_mode
171 /* Don't insert any breakpoint locations into the inferior, only
172 remove already-inserted locations that no longer should be
173 inserted. Functions that delete a breakpoint or breakpoints
174 should specify this mode, so that deleting a breakpoint doesn't
175 have the side effect of inserting the locations of other
176 breakpoints that are marked not-inserted, but should_be_inserted
177 returns true on them.
179 This behavior is useful is situations close to tear-down -- e.g.,
180 after an exec, while the target still has execution, but
181 breakpoint shadows of the previous executable image should *NOT*
182 be restored to the new image; or before detaching, where the
183 target still has execution and wants to delete breakpoints from
184 GDB's lists, and all breakpoints had already been removed from
188 /* May insert breakpoints iff breakpoints_should_be_inserted_now
189 claims breakpoints should be inserted now. */
192 /* Insert locations now, irrespective of
193 breakpoints_should_be_inserted_now. E.g., say all threads are
194 stopped right now, and the user did "continue". We need to
195 insert breakpoints _before_ resuming the target, but
196 UGLL_MAY_INSERT wouldn't insert them, because
197 breakpoints_should_be_inserted_now returns false at that point,
198 as no thread is running yet. */
202 static void update_global_location_list (enum ugll_insert_mode
);
204 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
206 static void insert_breakpoint_locations (void);
208 static void trace_pass_command (const char *, int);
210 static void set_tracepoint_count (int num
);
212 static bool is_masked_watchpoint (const struct breakpoint
*b
);
214 /* Return true if B refers to a static tracepoint set by marker ("-m"),
217 static bool strace_marker_p (struct breakpoint
*b
);
219 static void bkpt_probe_create_sals_from_location_spec
220 (location_spec
*locspec
,
221 struct linespec_result
*canonical
);
222 static void tracepoint_probe_create_sals_from_location_spec
223 (location_spec
*locspec
,
224 struct linespec_result
*canonical
);
226 const struct breakpoint_ops code_breakpoint_ops
=
228 create_sals_from_location_spec_default
,
229 create_breakpoints_sal
,
232 /* Breakpoints set on probes. */
233 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
235 bkpt_probe_create_sals_from_location_spec
,
236 create_breakpoints_sal
,
239 /* Tracepoints set on probes. */
240 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
242 tracepoint_probe_create_sals_from_location_spec
,
243 create_breakpoints_sal
,
246 /* Implementation of abstract dtors. These must exist to satisfy the
249 breakpoint::~breakpoint ()
253 code_breakpoint::~code_breakpoint ()
257 catchpoint::~catchpoint ()
261 /* The structure to be used in regular breakpoints. */
262 struct ordinary_breakpoint
: public code_breakpoint
264 using code_breakpoint::code_breakpoint
;
266 int resources_needed (const struct bp_location
*) override
;
267 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
268 void print_mention () const override
;
269 void print_recreate (struct ui_file
*fp
) const override
;
272 /* Internal breakpoints. These typically have a lifetime the same as
273 the program, and they end up installed on the breakpoint chain with
274 a negative breakpoint number. They're visible in "maint info
275 breakpoints", but not "info breakpoints". */
276 struct internal_breakpoint
: public code_breakpoint
278 internal_breakpoint (struct gdbarch
*gdbarch
,
279 enum bptype type
, CORE_ADDR address
)
280 : code_breakpoint (gdbarch
, type
)
284 sal
.section
= find_pc_overlay (sal
.pc
);
285 sal
.pspace
= current_program_space
;
288 pspace
= current_program_space
;
289 disposition
= disp_donttouch
;
292 void re_set () override
;
293 void check_status (struct bpstat
*bs
) override
;
294 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
295 void print_mention () const override
;
298 /* Momentary breakpoints. These typically have a lifetime of some run
299 control command only, are always thread-specific, and have 0 for
300 breakpoint number. I.e., there can be many momentary breakpoints
301 on the breakpoint chain and they all same the same number (zero).
302 They're visible in "maint info breakpoints", but not "info
304 struct momentary_breakpoint
: public code_breakpoint
306 momentary_breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
307 program_space
*pspace_
,
308 const struct frame_id
&frame_id_
,
310 : code_breakpoint (gdbarch_
, bptype
)
312 /* If FRAME_ID is valid, it should be a real frame, not an inlined
313 or tail-called one. */
314 gdb_assert (!frame_id_artificial_p (frame_id
));
316 /* Momentary breakpoints are always thread-specific. */
317 gdb_assert (thread_
> 0);
320 enable_state
= bp_enabled
;
321 disposition
= disp_donttouch
;
322 frame_id
= frame_id_
;
326 void re_set () override
;
327 void check_status (struct bpstat
*bs
) override
;
328 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
329 void print_mention () const override
;
332 /* DPrintf breakpoints. */
333 struct dprintf_breakpoint
: public ordinary_breakpoint
335 using ordinary_breakpoint::ordinary_breakpoint
;
337 void re_set () override
;
338 int breakpoint_hit (const struct bp_location
*bl
,
339 const address_space
*aspace
,
341 const target_waitstatus
&ws
) override
;
342 void print_recreate (struct ui_file
*fp
) const override
;
343 void after_condition_true (struct bpstat
*bs
) override
;
346 /* Ranged breakpoints. */
347 struct ranged_breakpoint
: public ordinary_breakpoint
349 explicit ranged_breakpoint (struct gdbarch
*gdbarch
,
350 const symtab_and_line
&sal_start
,
352 location_spec_up start_locspec
,
353 location_spec_up end_locspec
)
354 : ordinary_breakpoint (gdbarch
, bp_hardware_breakpoint
)
356 bp_location
*bl
= add_location (sal_start
);
359 disposition
= disp_donttouch
;
361 locspec
= std::move (start_locspec
);
362 locspec_range_end
= std::move (end_locspec
);
365 int breakpoint_hit (const struct bp_location
*bl
,
366 const address_space
*aspace
,
368 const target_waitstatus
&ws
) override
;
369 int resources_needed (const struct bp_location
*) override
;
370 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
371 bool print_one (bp_location
**) const override
;
372 void print_one_detail (struct ui_out
*) const override
;
373 void print_mention () const override
;
374 void print_recreate (struct ui_file
*fp
) const override
;
377 /* Static tracepoints with marker (`-m'). */
378 struct static_marker_tracepoint
: public tracepoint
380 using tracepoint::tracepoint
;
382 std::vector
<symtab_and_line
> decode_location_spec
383 (struct location_spec
*locspec
,
384 struct program_space
*search_pspace
) override
;
387 /* The style in which to perform a dynamic printf. This is a user
388 option because different output options have different tradeoffs;
389 if GDB does the printing, there is better error handling if there
390 is a problem with any of the arguments, but using an inferior
391 function lets you have special-purpose printers and sending of
392 output to the same place as compiled-in print functions. */
394 static const char dprintf_style_gdb
[] = "gdb";
395 static const char dprintf_style_call
[] = "call";
396 static const char dprintf_style_agent
[] = "agent";
397 static const char *const dprintf_style_enums
[] = {
403 static const char *dprintf_style
= dprintf_style_gdb
;
405 /* The function to use for dynamic printf if the preferred style is to
406 call into the inferior. The value is simply a string that is
407 copied into the command, so it can be anything that GDB can
408 evaluate to a callable address, not necessarily a function name. */
410 static std::string dprintf_function
= "printf";
412 /* The channel to use for dynamic printf if the preferred style is to
413 call into the inferior; if a nonempty string, it will be passed to
414 the call as the first argument, with the format string as the
415 second. As with the dprintf function, this can be anything that
416 GDB knows how to evaluate, so in addition to common choices like
417 "stderr", this could be an app-specific expression like
418 "mystreams[curlogger]". */
420 static std::string dprintf_channel
;
422 /* True if dprintf commands should continue to operate even if GDB
424 static bool disconnected_dprintf
= true;
426 struct command_line
*
427 breakpoint_commands (struct breakpoint
*b
)
429 return b
->commands
? b
->commands
.get () : NULL
;
432 /* Flag indicating that a command has proceeded the inferior past the
433 current breakpoint. */
435 static bool breakpoint_proceeded
;
438 bpdisp_text (enum bpdisp disp
)
440 /* NOTE: the following values are a part of MI protocol and
441 represent values of 'disp' field returned when inferior stops at
443 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
445 return bpdisps
[(int) disp
];
448 /* Prototypes for exported functions. */
449 /* If FALSE, gdb will not use hardware support for watchpoints, even
450 if such is available. */
451 static int can_use_hw_watchpoints
;
454 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
455 struct cmd_list_element
*c
,
459 _("Debugger's willingness to use "
460 "watchpoint hardware is %s.\n"),
464 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
465 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
466 for unrecognized breakpoint locations.
467 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
468 static enum auto_boolean pending_break_support
;
470 show_pending_break_support (struct ui_file
*file
, int from_tty
,
471 struct cmd_list_element
*c
,
475 _("Debugger's behavior regarding "
476 "pending breakpoints is %s.\n"),
480 /* If true, gdb will automatically use hardware breakpoints for breakpoints
481 set with "break" but falling in read-only memory.
482 If false, gdb will warn about such breakpoints, but won't automatically
483 use hardware breakpoints. */
484 static bool automatic_hardware_breakpoints
;
486 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
487 struct cmd_list_element
*c
,
491 _("Automatic usage of hardware breakpoints is %s.\n"),
495 /* If on, GDB keeps breakpoints inserted even if the inferior is
496 stopped, and immediately inserts any new breakpoints as soon as
497 they're created. If off (default), GDB keeps breakpoints off of
498 the target as long as possible. That is, it delays inserting
499 breakpoints until the next resume, and removes them again when the
500 target fully stops. This is a bit safer in case GDB crashes while
501 processing user input. */
502 static bool always_inserted_mode
= false;
505 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
506 struct cmd_list_element
*c
, const char *value
)
508 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
512 /* See breakpoint.h. */
515 breakpoints_should_be_inserted_now (void)
517 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
519 /* If breakpoints are global, they should be inserted even if no
520 thread under gdb's control is running, or even if there are
521 no threads under GDB's control yet. */
526 if (always_inserted_mode
)
528 /* The user wants breakpoints inserted even if all threads
533 for (inferior
*inf
: all_inferiors ())
534 if (inf
->has_execution ()
535 && threads_are_executing (inf
->process_target ()))
538 /* Don't remove breakpoints yet if, even though all threads are
539 stopped, we still have events to process. */
540 for (thread_info
*tp
: all_non_exited_threads ())
541 if (tp
->resumed () && tp
->has_pending_waitstatus ())
547 static const char condition_evaluation_both
[] = "host or target";
549 /* Modes for breakpoint condition evaluation. */
550 static const char condition_evaluation_auto
[] = "auto";
551 static const char condition_evaluation_host
[] = "host";
552 static const char condition_evaluation_target
[] = "target";
553 static const char *const condition_evaluation_enums
[] = {
554 condition_evaluation_auto
,
555 condition_evaluation_host
,
556 condition_evaluation_target
,
560 /* Global that holds the current mode for breakpoint condition evaluation. */
561 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
563 /* Global that we use to display information to the user (gets its value from
564 condition_evaluation_mode_1. */
565 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
567 /* Translate a condition evaluation mode MODE into either "host"
568 or "target". This is used mostly to translate from "auto" to the
569 real setting that is being used. It returns the translated
573 translate_condition_evaluation_mode (const char *mode
)
575 if (mode
== condition_evaluation_auto
)
577 if (target_supports_evaluation_of_breakpoint_conditions ())
578 return condition_evaluation_target
;
580 return condition_evaluation_host
;
586 /* Discovers what condition_evaluation_auto translates to. */
589 breakpoint_condition_evaluation_mode (void)
591 return translate_condition_evaluation_mode (condition_evaluation_mode
);
594 /* Return true if GDB should evaluate breakpoint conditions or false
598 gdb_evaluates_breakpoint_condition_p (void)
600 const char *mode
= breakpoint_condition_evaluation_mode ();
602 return (mode
== condition_evaluation_host
);
605 /* Are we executing breakpoint commands? */
606 static int executing_breakpoint_commands
;
608 /* Are overlay event breakpoints enabled? */
609 static int overlay_events_enabled
;
611 /* See description in breakpoint.h. */
612 bool target_exact_watchpoints
= false;
614 /* Walk the following statement or block through all breakpoints.
615 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
616 current breakpoint. */
618 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
619 for (B = breakpoint_chain; \
620 B ? (TMP=B->next, 1): 0; \
623 /* Chains of all breakpoints defined. */
625 static struct breakpoint
*breakpoint_chain
;
627 /* See breakpoint.h. */
632 return breakpoint_range (breakpoint_chain
);
635 /* See breakpoint.h. */
637 breakpoint_safe_range
638 all_breakpoints_safe ()
640 return breakpoint_safe_range (all_breakpoints ());
643 /* See breakpoint.h. */
648 return tracepoint_range (breakpoint_chain
);
651 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
653 static std::vector
<bp_location
*> bp_locations
;
655 /* See breakpoint.h. */
657 const std::vector
<bp_location
*> &
663 /* Range to iterate over breakpoint locations at a given address. */
665 struct bp_locations_at_addr_range
667 using iterator
= std::vector
<bp_location
*>::iterator
;
669 bp_locations_at_addr_range (CORE_ADDR addr
)
673 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
674 { return loc
->address
< addr_
; }
676 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
677 { return addr_
< loc
->address
; }
680 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
683 m_begin
= it_pair
.first
;
684 m_end
= it_pair
.second
;
687 iterator
begin () const
690 iterator
end () const
698 /* Return a range to iterate over all breakpoint locations exactly at address
701 If it's needed to iterate multiple times on the same range, it's possible
702 to save the range in a local variable and use it multiple times:
704 auto range = all_bp_locations_at_addr (addr);
706 for (bp_location *loc : range)
709 for (bp_location *loc : range)
712 This saves a bit of time, as it avoids re-doing the binary searches to find
713 the range's boundaries. Just remember not to change the bp_locations vector
714 in the mean time, as it could make the range's iterators stale. */
716 static bp_locations_at_addr_range
717 all_bp_locations_at_addr (CORE_ADDR addr
)
719 return bp_locations_at_addr_range (addr
);
722 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
723 ADDRESS for the current elements of BP_LOCATIONS which get a valid
724 result from bp_location_has_shadow. You can use it for roughly
725 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
726 an address you need to read. */
728 static CORE_ADDR bp_locations_placed_address_before_address_max
;
730 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
731 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
732 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
733 You can use it for roughly limiting the subrange of BP_LOCATIONS to
734 scan for shadow bytes for an address you need to read. */
736 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
738 /* The locations that no longer correspond to any breakpoint, unlinked
739 from the bp_locations array, but for which a hit may still be
740 reported by a target. */
741 static std::vector
<bp_location
*> moribund_locations
;
743 /* Number of last breakpoint made. */
745 static int breakpoint_count
;
747 /* The value of `breakpoint_count' before the last command that
748 created breakpoints. If the last (break-like) command created more
749 than one breakpoint, then the difference between BREAKPOINT_COUNT
750 and PREV_BREAKPOINT_COUNT is more than one. */
751 static int prev_breakpoint_count
;
753 /* Number of last tracepoint made. */
755 static int tracepoint_count
;
757 static struct cmd_list_element
*breakpoint_set_cmdlist
;
758 static struct cmd_list_element
*breakpoint_show_cmdlist
;
759 struct cmd_list_element
*save_cmdlist
;
761 /* Return whether a breakpoint is an active enabled breakpoint. */
763 breakpoint_enabled (struct breakpoint
*b
)
765 return (b
->enable_state
== bp_enabled
);
768 /* Set breakpoint count to NUM. */
771 set_breakpoint_count (int num
)
773 prev_breakpoint_count
= breakpoint_count
;
774 breakpoint_count
= num
;
775 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
778 /* Used by `start_rbreak_breakpoints' below, to record the current
779 breakpoint count before "rbreak" creates any breakpoint. */
780 static int rbreak_start_breakpoint_count
;
782 /* Called at the start an "rbreak" command to record the first
785 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
787 rbreak_start_breakpoint_count
= breakpoint_count
;
790 /* Called at the end of an "rbreak" command to record the last
793 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
795 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
798 /* Used in run_command to zero the hit count when a new run starts. */
801 clear_breakpoint_hit_counts (void)
803 for (breakpoint
*b
: all_breakpoints ())
808 /* Return the breakpoint with the specified number, or NULL
809 if the number does not refer to an existing breakpoint. */
812 get_breakpoint (int num
)
814 for (breakpoint
*b
: all_breakpoints ())
815 if (b
->number
== num
)
821 /* Return TRUE if NUM refer to an existing breakpoint that has
822 multiple code locations. */
825 has_multiple_locations (int num
)
827 for (breakpoint
*b
: all_breakpoints ())
828 if (b
->number
== num
)
829 return b
->loc
!= nullptr && b
->loc
->next
!= nullptr;
836 /* Mark locations as "conditions have changed" in case the target supports
837 evaluating conditions on its side. */
840 mark_breakpoint_modified (struct breakpoint
*b
)
842 /* This is only meaningful if the target is
843 evaluating conditions and if the user has
844 opted for condition evaluation on the target's
846 if (gdb_evaluates_breakpoint_condition_p ()
847 || !target_supports_evaluation_of_breakpoint_conditions ())
850 if (!is_breakpoint (b
))
853 for (bp_location
*loc
: b
->locations ())
854 loc
->condition_changed
= condition_modified
;
857 /* Mark location as "conditions have changed" in case the target supports
858 evaluating conditions on its side. */
861 mark_breakpoint_location_modified (struct bp_location
*loc
)
863 /* This is only meaningful if the target is
864 evaluating conditions and if the user has
865 opted for condition evaluation on the target's
867 if (gdb_evaluates_breakpoint_condition_p ()
868 || !target_supports_evaluation_of_breakpoint_conditions ())
872 if (!is_breakpoint (loc
->owner
))
875 loc
->condition_changed
= condition_modified
;
878 /* Sets the condition-evaluation mode using the static global
879 condition_evaluation_mode. */
882 set_condition_evaluation_mode (const char *args
, int from_tty
,
883 struct cmd_list_element
*c
)
885 const char *old_mode
, *new_mode
;
887 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
888 && !target_supports_evaluation_of_breakpoint_conditions ())
890 condition_evaluation_mode_1
= condition_evaluation_mode
;
891 warning (_("Target does not support breakpoint condition evaluation.\n"
892 "Using host evaluation mode instead."));
896 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
897 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
899 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
900 settings was "auto". */
901 condition_evaluation_mode
= condition_evaluation_mode_1
;
903 /* Only update the mode if the user picked a different one. */
904 if (new_mode
!= old_mode
)
906 /* If the user switched to a different evaluation mode, we
907 need to synch the changes with the target as follows:
909 "host" -> "target": Send all (valid) conditions to the target.
910 "target" -> "host": Remove all the conditions from the target.
913 if (new_mode
== condition_evaluation_target
)
915 /* Mark everything modified and synch conditions with the
917 for (bp_location
*loc
: all_bp_locations ())
918 mark_breakpoint_location_modified (loc
);
922 /* Manually mark non-duplicate locations to synch conditions
923 with the target. We do this to remove all the conditions the
924 target knows about. */
925 for (bp_location
*loc
: all_bp_locations ())
926 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
927 loc
->needs_update
= 1;
931 update_global_location_list (UGLL_MAY_INSERT
);
937 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
938 what "auto" is translating to. */
941 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
942 struct cmd_list_element
*c
, const char *value
)
944 if (condition_evaluation_mode
== condition_evaluation_auto
)
946 _("Breakpoint condition evaluation "
947 "mode is %s (currently %s).\n"),
949 breakpoint_condition_evaluation_mode ());
951 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
955 /* Parse COND_STRING in the context of LOC and set as the condition
956 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
957 the number of LOC within its owner. In case of parsing error, mark
958 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
961 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
962 int bp_num
, int loc_num
)
964 bool has_junk
= false;
967 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
968 block_for_pc (loc
->address
), 0);
969 if (*cond_string
!= 0)
973 loc
->cond
= std::move (new_exp
);
974 if (loc
->disabled_by_cond
&& loc
->enabled
)
975 gdb_printf (_("Breakpoint %d's condition is now valid at "
976 "location %d, enabling.\n"),
979 loc
->disabled_by_cond
= false;
982 catch (const gdb_exception_error
&e
)
986 /* Warn if a user-enabled location is now becoming disabled-by-cond.
987 BP_NUM is 0 if the breakpoint is being defined for the first
988 time using the "break ... if ..." command, and non-zero if
991 warning (_("failed to validate condition at location %d.%d, "
992 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
994 warning (_("failed to validate condition at location %d, "
995 "disabling:\n %s"), loc_num
, e
.what ());
998 loc
->disabled_by_cond
= true;
1002 error (_("Garbage '%s' follows condition"), cond_string
);
1006 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
1007 int from_tty
, bool force
)
1011 b
->cond_string
.reset ();
1013 if (is_watchpoint (b
))
1014 gdb::checked_static_cast
<watchpoint
*> (b
)->cond_exp
.reset ();
1018 for (bp_location
*loc
: b
->locations ())
1021 if (loc
->disabled_by_cond
&& loc
->enabled
)
1022 gdb_printf (_("Breakpoint %d's condition is now valid at "
1023 "location %d, enabling.\n"),
1024 b
->number
, loc_num
);
1025 loc
->disabled_by_cond
= false;
1028 /* No need to free the condition agent expression
1029 bytecode (if we have one). We will handle this
1030 when we go through update_global_location_list. */
1035 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
1039 if (is_watchpoint (b
))
1041 innermost_block_tracker tracker
;
1042 const char *arg
= exp
;
1043 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
1045 error (_("Junk at end of expression"));
1046 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
1047 w
->cond_exp
= std::move (new_exp
);
1048 w
->cond_exp_valid_block
= tracker
.block ();
1052 /* Parse and set condition expressions. We make two passes.
1053 In the first, we parse the condition string to see if it
1054 is valid in at least one location. If so, the condition
1055 would be accepted. So we go ahead and set the locations'
1056 conditions. In case no valid case is found, we throw
1057 the error and the condition string will be rejected.
1058 This two-pass approach is taken to avoid setting the
1059 state of locations in case of a reject. */
1060 for (bp_location
*loc
: b
->locations ())
1064 const char *arg
= exp
;
1065 parse_exp_1 (&arg
, loc
->address
,
1066 block_for_pc (loc
->address
), 0);
1068 error (_("Junk at end of expression"));
1071 catch (const gdb_exception_error
&e
)
1073 /* Condition string is invalid. If this happens to
1074 be the last loc, abandon (if not forced) or continue
1076 if (loc
->next
== nullptr && !force
)
1081 /* If we reach here, the condition is valid at some locations. */
1083 for (bp_location
*loc
: b
->locations ())
1085 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
1090 /* We know that the new condition parsed successfully. The
1091 condition string of the breakpoint can be safely updated. */
1092 b
->cond_string
= make_unique_xstrdup (exp
);
1093 b
->condition_not_parsed
= 0;
1095 mark_breakpoint_modified (b
);
1097 gdb::observers::breakpoint_modified
.notify (b
);
1100 /* See breakpoint.h. */
1103 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1106 for (breakpoint
*b
: all_breakpoints ())
1107 if (b
->number
== bpnum
)
1109 /* Check if this breakpoint has a "stop" method implemented in an
1110 extension language. This method and conditions entered into GDB
1111 from the CLI are mutually exclusive. */
1112 const struct extension_language_defn
*extlang
1113 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1115 if (extlang
!= NULL
)
1117 error (_("Only one stop condition allowed. There is currently"
1118 " a %s stop condition defined for this breakpoint."),
1119 ext_lang_capitalized_name (extlang
));
1121 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1123 if (is_breakpoint (b
))
1124 update_global_location_list (UGLL_MAY_INSERT
);
1129 error (_("No breakpoint number %d."), bpnum
);
1132 /* The options for the "condition" command. */
1134 struct condition_command_opts
1137 bool force_condition
= false;
1140 static const gdb::option::option_def condition_command_option_defs
[] = {
1142 gdb::option::flag_option_def
<condition_command_opts
> {
1144 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1145 N_("Set the condition even if it is invalid for all current locations."),
1150 /* Create an option_def_group for the "condition" options, with
1151 CC_OPTS as context. */
1153 static inline gdb::option::option_def_group
1154 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1156 return {{condition_command_option_defs
}, cc_opts
};
1159 /* Completion for the "condition" command. */
1162 condition_completer (struct cmd_list_element
*cmd
,
1163 completion_tracker
&tracker
,
1164 const char *text
, const char * /*word*/)
1166 bool has_no_arguments
= (*text
== '\0');
1167 condition_command_opts cc_opts
;
1168 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1169 if (gdb::option::complete_options
1170 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1173 text
= skip_spaces (text
);
1174 const char *space
= skip_to_space (text
);
1181 tracker
.advance_custom_word_point_by (1);
1182 /* We don't support completion of history indices. */
1183 if (!isdigit (text
[1]))
1184 complete_internalvar (tracker
, &text
[1]);
1188 /* Suggest the "-force" flag if no arguments are given. If
1189 arguments were passed, they either already include the flag,
1190 or we are beyond the point of suggesting it because it's
1191 positionally the first argument. */
1192 if (has_no_arguments
)
1193 gdb::option::complete_on_all_options (tracker
, group
);
1195 /* We're completing the breakpoint number. */
1196 len
= strlen (text
);
1198 for (breakpoint
*b
: all_breakpoints ())
1202 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1204 if (strncmp (number
, text
, len
) == 0)
1205 tracker
.add_completion (make_unique_xstrdup (number
));
1211 /* We're completing the expression part. Skip the breakpoint num. */
1212 const char *exp_start
= skip_spaces (space
);
1213 tracker
.advance_custom_word_point_by (exp_start
- text
);
1215 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1216 expression_completer (cmd
, tracker
, text
, word
);
1219 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1222 condition_command (const char *arg
, int from_tty
)
1228 error_no_arg (_("breakpoint number"));
1232 /* Check if the "-force" flag was passed. */
1233 condition_command_opts cc_opts
;
1234 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1235 gdb::option::process_options
1236 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1238 bnum
= get_number (&p
);
1240 error (_("Bad breakpoint argument: '%s'"), arg
);
1242 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1245 /* Check that COMMAND do not contain commands that are suitable
1246 only for tracepoints and not suitable for ordinary breakpoints.
1247 Throw if any such commands is found. */
1250 check_no_tracepoint_commands (struct command_line
*commands
)
1252 struct command_line
*c
;
1254 for (c
= commands
; c
; c
= c
->next
)
1256 if (c
->control_type
== while_stepping_control
)
1257 error (_("The 'while-stepping' command can "
1258 "only be used for tracepoints"));
1260 check_no_tracepoint_commands (c
->body_list_0
.get ());
1261 check_no_tracepoint_commands (c
->body_list_1
.get ());
1263 /* Not that command parsing removes leading whitespace and comment
1264 lines and also empty lines. So, we only need to check for
1265 command directly. */
1266 if (strstr (c
->line
, "collect ") == c
->line
)
1267 error (_("The 'collect' command can only be used for tracepoints"));
1269 if (strstr (c
->line
, "teval ") == c
->line
)
1270 error (_("The 'teval' command can only be used for tracepoints"));
1274 struct longjmp_breakpoint
: public momentary_breakpoint
1276 using momentary_breakpoint::momentary_breakpoint
;
1278 ~longjmp_breakpoint () override
;
1281 /* Encapsulate tests for different types of tracepoints. */
1284 is_tracepoint_type (bptype type
)
1286 return (type
== bp_tracepoint
1287 || type
== bp_fast_tracepoint
1288 || type
== bp_static_tracepoint
1289 || type
== bp_static_marker_tracepoint
);
1292 /* See breakpoint.h. */
1295 is_tracepoint (const struct breakpoint
*b
)
1297 return is_tracepoint_type (b
->type
);
1300 /* Factory function to create an appropriate instance of breakpoint given
1303 template<typename
... Arg
>
1304 static std::unique_ptr
<code_breakpoint
>
1305 new_breakpoint_from_type (struct gdbarch
*gdbarch
, bptype type
,
1313 case bp_hardware_breakpoint
:
1314 b
= new ordinary_breakpoint (gdbarch
, type
,
1315 std::forward
<Arg
> (args
)...);
1318 case bp_fast_tracepoint
:
1319 case bp_static_tracepoint
:
1321 b
= new tracepoint (gdbarch
, type
,
1322 std::forward
<Arg
> (args
)...);
1325 case bp_static_marker_tracepoint
:
1326 b
= new static_marker_tracepoint (gdbarch
, type
,
1327 std::forward
<Arg
> (args
)...);
1331 b
= new dprintf_breakpoint (gdbarch
, type
,
1332 std::forward
<Arg
> (args
)...);
1336 gdb_assert_not_reached ("invalid type");
1339 return std::unique_ptr
<code_breakpoint
> (b
);
1342 /* A helper function that validates that COMMANDS are valid for a
1343 breakpoint. This function will throw an exception if a problem is
1347 validate_commands_for_breakpoint (struct breakpoint
*b
,
1348 struct command_line
*commands
)
1350 if (is_tracepoint (b
))
1352 struct tracepoint
*t
= (struct tracepoint
*) b
;
1353 struct command_line
*c
;
1354 struct command_line
*while_stepping
= 0;
1356 /* Reset the while-stepping step count. The previous commands
1357 might have included a while-stepping action, while the new
1361 /* We need to verify that each top-level element of commands is
1362 valid for tracepoints, that there's at most one
1363 while-stepping element, and that the while-stepping's body
1364 has valid tracing commands excluding nested while-stepping.
1365 We also need to validate the tracepoint action line in the
1366 context of the tracepoint --- validate_actionline actually
1367 has side effects, like setting the tracepoint's
1368 while-stepping STEP_COUNT, in addition to checking if the
1369 collect/teval actions parse and make sense in the
1370 tracepoint's context. */
1371 for (c
= commands
; c
; c
= c
->next
)
1373 if (c
->control_type
== while_stepping_control
)
1375 if (b
->type
== bp_fast_tracepoint
)
1376 error (_("The 'while-stepping' command "
1377 "cannot be used for fast tracepoint"));
1378 else if (b
->type
== bp_static_tracepoint
1379 || b
->type
== bp_static_marker_tracepoint
)
1380 error (_("The 'while-stepping' command "
1381 "cannot be used for static tracepoint"));
1384 error (_("The 'while-stepping' command "
1385 "can be used only once"));
1390 validate_actionline (c
->line
, b
);
1394 struct command_line
*c2
;
1396 gdb_assert (while_stepping
->body_list_1
== nullptr);
1397 c2
= while_stepping
->body_list_0
.get ();
1398 for (; c2
; c2
= c2
->next
)
1400 if (c2
->control_type
== while_stepping_control
)
1401 error (_("The 'while-stepping' command cannot be nested"));
1407 check_no_tracepoint_commands (commands
);
1411 /* Return a vector of all the static tracepoints set at ADDR. The
1412 caller is responsible for releasing the vector. */
1414 std::vector
<breakpoint
*>
1415 static_tracepoints_here (CORE_ADDR addr
)
1417 std::vector
<breakpoint
*> found
;
1419 for (breakpoint
*b
: all_breakpoints ())
1420 if (b
->type
== bp_static_tracepoint
1421 || b
->type
== bp_static_marker_tracepoint
)
1423 for (bp_location
*loc
: b
->locations ())
1424 if (loc
->address
== addr
)
1425 found
.push_back (b
);
1431 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1432 validate that only allowed commands are included. */
1435 breakpoint_set_commands (struct breakpoint
*b
,
1436 counted_command_line
&&commands
)
1438 validate_commands_for_breakpoint (b
, commands
.get ());
1440 b
->commands
= std::move (commands
);
1441 gdb::observers::breakpoint_modified
.notify (b
);
1444 /* Set the internal `silent' flag on the breakpoint. Note that this
1445 is not the same as the "silent" that may appear in the breakpoint's
1449 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1451 int old_silent
= b
->silent
;
1454 if (old_silent
!= silent
)
1455 gdb::observers::breakpoint_modified
.notify (b
);
1458 /* See breakpoint.h. */
1461 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1463 /* It is invalid to set the thread field to anything other than -1 (which
1464 means no thread restriction) if a task restriction is already in
1466 gdb_assert (thread
== -1 || b
->task
== -1);
1468 int old_thread
= b
->thread
;
1471 if (old_thread
!= thread
)
1472 gdb::observers::breakpoint_modified
.notify (b
);
1475 /* See breakpoint.h. */
1478 breakpoint_set_task (struct breakpoint
*b
, int task
)
1480 /* It is invalid to set the task field to anything other than -1 (which
1481 means no task restriction) if a thread restriction is already in
1483 gdb_assert (task
== -1 || b
->thread
== -1);
1485 int old_task
= b
->task
;
1488 if (old_task
!= task
)
1489 gdb::observers::breakpoint_modified
.notify (b
);
1493 commands_command_1 (const char *arg
, int from_tty
,
1494 struct command_line
*control
)
1496 counted_command_line cmd
;
1497 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1498 NULL after the call to read_command_lines if the user provides an empty
1499 list of command by just typing "end". */
1500 bool cmd_read
= false;
1502 std::string new_arg
;
1504 if (arg
== NULL
|| !*arg
)
1506 /* Argument not explicitly given. Synthesize it. */
1507 if (breakpoint_count
- prev_breakpoint_count
> 1)
1508 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1510 else if (breakpoint_count
> 0)
1511 new_arg
= string_printf ("%d", breakpoint_count
);
1515 /* Create a copy of ARG. This is needed because the "commands"
1516 command may be coming from a script. In that case, the read
1517 line buffer is going to be overwritten in the lambda of
1518 'map_breakpoint_numbers' below when reading the next line
1519 before we are are done parsing the breakpoint numbers. */
1522 arg
= new_arg
.c_str ();
1524 map_breakpoint_numbers
1525 (arg
, [&] (breakpoint
*b
)
1529 gdb_assert (cmd
== NULL
);
1530 if (control
!= NULL
)
1531 cmd
= control
->body_list_0
;
1535 = string_printf (_("Type commands for breakpoint(s) "
1536 "%s, one per line."),
1539 auto do_validate
= [=] (const char *line
)
1541 validate_actionline (line
, b
);
1543 gdb::function_view
<void (const char *)> validator
;
1544 if (is_tracepoint (b
))
1545 validator
= do_validate
;
1547 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1552 /* If a breakpoint was on the list more than once, we don't need to
1554 if (b
->commands
!= cmd
)
1556 validate_commands_for_breakpoint (b
, cmd
.get ());
1558 gdb::observers::breakpoint_modified
.notify (b
);
1564 commands_command (const char *arg
, int from_tty
)
1566 commands_command_1 (arg
, from_tty
, NULL
);
1569 /* Like commands_command, but instead of reading the commands from
1570 input stream, takes them from an already parsed command structure.
1572 This is used by cli-script.c to DTRT with breakpoint commands
1573 that are part of if and while bodies. */
1574 enum command_control_type
1575 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1577 commands_command_1 (arg
, 0, cmd
);
1578 return simple_control
;
1581 /* Return true if BL->TARGET_INFO contains valid information. */
1584 bp_location_has_shadow (struct bp_location
*bl
)
1586 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1590 if (bl
->target_info
.shadow_len
== 0)
1591 /* BL isn't valid, or doesn't shadow memory. */
1596 /* Update BUF, which is LEN bytes read from the target address
1597 MEMADDR, by replacing a memory breakpoint with its shadowed
1600 If READBUF is not NULL, this buffer must not overlap with the of
1601 the breakpoint location's shadow_contents buffer. Otherwise, a
1602 failed assertion internal error will be raised. */
1605 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1606 const gdb_byte
*writebuf_org
,
1607 ULONGEST memaddr
, LONGEST len
,
1608 struct bp_target_info
*target_info
,
1609 struct gdbarch
*gdbarch
)
1611 /* Now do full processing of the found relevant range of elements. */
1612 CORE_ADDR bp_addr
= 0;
1616 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1617 current_program_space
->aspace
, 0))
1619 /* The breakpoint is inserted in a different address space. */
1623 /* Addresses and length of the part of the breakpoint that
1625 bp_addr
= target_info
->placed_address
;
1626 bp_size
= target_info
->shadow_len
;
1628 if (bp_addr
+ bp_size
<= memaddr
)
1630 /* The breakpoint is entirely before the chunk of memory we are
1635 if (bp_addr
>= memaddr
+ len
)
1637 /* The breakpoint is entirely after the chunk of memory we are
1642 /* Offset within shadow_contents. */
1643 if (bp_addr
< memaddr
)
1645 /* Only copy the second part of the breakpoint. */
1646 bp_size
-= memaddr
- bp_addr
;
1647 bptoffset
= memaddr
- bp_addr
;
1651 if (bp_addr
+ bp_size
> memaddr
+ len
)
1653 /* Only copy the first part of the breakpoint. */
1654 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1657 if (readbuf
!= NULL
)
1659 /* Verify that the readbuf buffer does not overlap with the
1660 shadow_contents buffer. */
1661 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1662 || readbuf
>= (target_info
->shadow_contents
1663 + target_info
->shadow_len
));
1665 /* Update the read buffer with this inserted breakpoint's
1667 memcpy (readbuf
+ bp_addr
- memaddr
,
1668 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1672 const unsigned char *bp
;
1673 CORE_ADDR addr
= target_info
->reqstd_address
;
1676 /* Update the shadow with what we want to write to memory. */
1677 memcpy (target_info
->shadow_contents
+ bptoffset
,
1678 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1680 /* Determine appropriate breakpoint contents and size for this
1682 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1684 /* Update the final write buffer with this inserted
1685 breakpoint's INSN. */
1686 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1690 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1691 by replacing any memory breakpoints with their shadowed contents.
1693 If READBUF is not NULL, this buffer must not overlap with any of
1694 the breakpoint location's shadow_contents buffers. Otherwise,
1695 a failed assertion internal error will be raised.
1697 The range of shadowed area by each bp_location is:
1698 bl->address - bp_locations_placed_address_before_address_max
1699 up to bl->address + bp_locations_shadow_len_after_address_max
1700 The range we were requested to resolve shadows for is:
1701 memaddr ... memaddr + len
1702 Thus the safe cutoff boundaries for performance optimization are
1703 memaddr + len <= (bl->address
1704 - bp_locations_placed_address_before_address_max)
1706 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1709 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1710 const gdb_byte
*writebuf_org
,
1711 ULONGEST memaddr
, LONGEST len
)
1713 /* Left boundary, right boundary and median element of our binary
1715 unsigned bc_l
, bc_r
, bc
;
1717 /* Find BC_L which is a leftmost element which may affect BUF
1718 content. It is safe to report lower value but a failure to
1719 report higher one. */
1722 bc_r
= bp_locations
.size ();
1723 while (bc_l
+ 1 < bc_r
)
1725 struct bp_location
*bl
;
1727 bc
= (bc_l
+ bc_r
) / 2;
1728 bl
= bp_locations
[bc
];
1730 /* Check first BL->ADDRESS will not overflow due to the added
1731 constant. Then advance the left boundary only if we are sure
1732 the BC element can in no way affect the BUF content (MEMADDR
1733 to MEMADDR + LEN range).
1735 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1736 offset so that we cannot miss a breakpoint with its shadow
1737 range tail still reaching MEMADDR. */
1739 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1741 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1748 /* Due to the binary search above, we need to make sure we pick the
1749 first location that's at BC_L's address. E.g., if there are
1750 multiple locations at the same address, BC_L may end up pointing
1751 at a duplicate location, and miss the "master"/"inserted"
1752 location. Say, given locations L1, L2 and L3 at addresses A and
1755 L1@A, L2@A, L3@B, ...
1757 BC_L could end up pointing at location L2, while the "master"
1758 location could be L1. Since the `loc->inserted' flag is only set
1759 on "master" locations, we'd forget to restore the shadow of L1
1762 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1765 /* Now do full processing of the found relevant range of elements. */
1767 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1769 struct bp_location
*bl
= bp_locations
[bc
];
1771 /* bp_location array has BL->OWNER always non-NULL. */
1772 if (bl
->owner
->type
== bp_none
)
1773 warning (_("reading through apparently deleted breakpoint #%d?"),
1776 /* Performance optimization: any further element can no longer affect BUF
1779 if (bl
->address
>= bp_locations_placed_address_before_address_max
1782 - bp_locations_placed_address_before_address_max
)))
1785 if (!bp_location_has_shadow (bl
))
1788 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1789 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1793 /* See breakpoint.h. */
1796 is_breakpoint (const struct breakpoint
*bpt
)
1798 return (bpt
->type
== bp_breakpoint
1799 || bpt
->type
== bp_hardware_breakpoint
1800 || bpt
->type
== bp_dprintf
);
1803 /* Return true if BPT is of any hardware watchpoint kind. */
1806 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1808 return (bpt
->type
== bp_hardware_watchpoint
1809 || bpt
->type
== bp_read_watchpoint
1810 || bpt
->type
== bp_access_watchpoint
);
1813 /* See breakpoint.h. */
1816 is_watchpoint (const struct breakpoint
*bpt
)
1818 return (is_hardware_watchpoint (bpt
)
1819 || bpt
->type
== bp_watchpoint
);
1822 /* Returns true if the current thread and its running state are safe
1823 to evaluate or update watchpoint B. Watchpoints on local
1824 expressions need to be evaluated in the context of the thread that
1825 was current when the watchpoint was created, and, that thread needs
1826 to be stopped to be able to select the correct frame context.
1827 Watchpoints on global expressions can be evaluated on any thread,
1828 and in any state. It is presently left to the target allowing
1829 memory accesses when threads are running. */
1832 watchpoint_in_thread_scope (struct watchpoint
*b
)
1834 return (b
->pspace
== current_program_space
1835 && (b
->watchpoint_thread
== null_ptid
1836 || (inferior_ptid
== b
->watchpoint_thread
1837 && !inferior_thread ()->executing ())));
1840 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1841 associated bp_watchpoint_scope breakpoint. */
1844 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1846 if (w
->related_breakpoint
!= w
)
1848 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1849 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1850 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1851 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1852 w
->related_breakpoint
= w
;
1854 w
->disposition
= disp_del_at_next_stop
;
1857 /* Extract a bitfield value from value VAL using the bit parameters contained in
1860 static struct value
*
1861 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1863 struct value
*bit_val
;
1868 bit_val
= value::allocate (val
->type ());
1870 val
->unpack_bitfield (bit_val
,
1873 val
->contents_for_printing ().data (),
1879 /* Allocate a dummy location and add it to B. This is required
1880 because bpstat_stop_status requires a location to be able to report
1884 add_dummy_location (struct breakpoint
*b
,
1885 struct program_space
*pspace
)
1887 gdb_assert (b
->loc
== NULL
);
1889 b
->loc
= new bp_location (b
, bp_loc_other
);
1890 b
->loc
->pspace
= pspace
;
1893 /* Assuming that B is a watchpoint:
1894 - Reparse watchpoint expression, if REPARSE is true
1895 - Evaluate expression and store the result in B->val
1896 - Evaluate the condition if there is one, and store the result
1898 - Update the list of values that must be watched in B->loc.
1900 If the watchpoint disposition is disp_del_at_next_stop, then do
1901 nothing. If this is local watchpoint that is out of scope, delete
1904 Even with `set breakpoint always-inserted on' the watchpoints are
1905 removed + inserted on each stop here. Normal breakpoints must
1906 never be removed because they might be missed by a running thread
1907 when debugging in non-stop mode. On the other hand, hardware
1908 watchpoints (is_hardware_watchpoint; processed here) are specific
1909 to each LWP since they are stored in each LWP's hardware debug
1910 registers. Therefore, such LWP must be stopped first in order to
1911 be able to modify its hardware watchpoints.
1913 Hardware watchpoints must be reset exactly once after being
1914 presented to the user. It cannot be done sooner, because it would
1915 reset the data used to present the watchpoint hit to the user. And
1916 it must not be done later because it could display the same single
1917 watchpoint hit during multiple GDB stops. Note that the latter is
1918 relevant only to the hardware watchpoint types bp_read_watchpoint
1919 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1920 not user-visible - its hit is suppressed if the memory content has
1923 The following constraints influence the location where we can reset
1924 hardware watchpoints:
1926 * target_stopped_by_watchpoint and target_stopped_data_address are
1927 called several times when GDB stops.
1930 * Multiple hardware watchpoints can be hit at the same time,
1931 causing GDB to stop. GDB only presents one hardware watchpoint
1932 hit at a time as the reason for stopping, and all the other hits
1933 are presented later, one after the other, each time the user
1934 requests the execution to be resumed. Execution is not resumed
1935 for the threads still having pending hit event stored in
1936 LWP_INFO->STATUS. While the watchpoint is already removed from
1937 the inferior on the first stop the thread hit event is kept being
1938 reported from its cached value by linux_nat_stopped_data_address
1939 until the real thread resume happens after the watchpoint gets
1940 presented and thus its LWP_INFO->STATUS gets reset.
1942 Therefore the hardware watchpoint hit can get safely reset on the
1943 watchpoint removal from inferior. */
1946 update_watchpoint (struct watchpoint
*b
, bool reparse
)
1948 bool within_current_scope
;
1950 /* If this is a local watchpoint, we only want to check if the
1951 watchpoint frame is in scope if the current thread is the thread
1952 that was used to create the watchpoint. */
1953 if (!watchpoint_in_thread_scope (b
))
1956 if (b
->disposition
== disp_del_at_next_stop
)
1959 gdb::optional
<scoped_restore_selected_frame
> restore_frame
;
1961 /* Determine if the watchpoint is within scope. */
1962 if (b
->exp_valid_block
== NULL
)
1963 within_current_scope
= true;
1966 frame_info_ptr fi
= get_current_frame ();
1967 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1968 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1970 /* If we're at a point where the stack has been destroyed
1971 (e.g. in a function epilogue), unwinding may not work
1972 properly. Do not attempt to recreate locations at this
1973 point. See similar comments in watchpoint_check. */
1974 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1977 /* Save the current frame's ID so we can restore it after
1978 evaluating the watchpoint expression on its own frame. */
1979 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1980 took a frame parameter, so that we didn't have to change the
1982 restore_frame
.emplace ();
1984 fi
= frame_find_by_id (b
->watchpoint_frame
);
1985 within_current_scope
= (fi
!= NULL
);
1986 if (within_current_scope
)
1990 /* We don't free locations. They are stored in the bp_location array
1991 and update_global_location_list will eventually delete them and
1992 remove breakpoints if needed. */
1995 if (within_current_scope
&& reparse
)
2000 s
= (b
->exp_string_reparse
2001 ? b
->exp_string_reparse
.get ()
2002 : b
->exp_string
.get ());
2003 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
2004 /* If the meaning of expression itself changed, the old value is
2005 no longer relevant. We don't want to report a watchpoint hit
2006 to the user when the old value and the new value may actually
2007 be completely different objects. */
2009 b
->val_valid
= false;
2011 /* Note that unlike with breakpoints, the watchpoint's condition
2012 expression is stored in the breakpoint object, not in the
2013 locations (re)created below. */
2014 if (b
->cond_string
!= NULL
)
2016 b
->cond_exp
.reset ();
2018 s
= b
->cond_string
.get ();
2019 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
2023 /* If we failed to parse the expression, for example because
2024 it refers to a global variable in a not-yet-loaded shared library,
2025 don't try to insert watchpoint. We don't automatically delete
2026 such watchpoint, though, since failure to parse expression
2027 is different from out-of-scope watchpoint. */
2028 if (!target_has_execution ())
2030 /* Without execution, memory can't change. No use to try and
2031 set watchpoint locations. The watchpoint will be reset when
2032 the target gains execution, through breakpoint_re_set. */
2033 if (!can_use_hw_watchpoints
)
2035 if (b
->works_in_software_mode ())
2036 b
->type
= bp_watchpoint
;
2038 error (_("Can't set read/access watchpoint when "
2039 "hardware watchpoints are disabled."));
2042 else if (within_current_scope
&& b
->exp
)
2044 std::vector
<value_ref_ptr
> val_chain
;
2045 struct value
*v
, *result
;
2046 struct program_space
*frame_pspace
;
2048 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2051 /* Avoid setting b->val if it's already set. The meaning of
2052 b->val is 'the last value' user saw, and we should update
2053 it only if we reported that last value to user. As it
2054 happens, the code that reports it updates b->val directly.
2055 We don't keep track of the memory value for masked
2057 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2059 if (b
->val_bitsize
!= 0)
2060 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2061 b
->val
= release_value (v
);
2062 b
->val_valid
= true;
2065 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2067 /* Look at each value on the value chain. */
2068 gdb_assert (!val_chain
.empty ());
2069 for (const value_ref_ptr
&iter
: val_chain
)
2073 /* If it's a memory location, and GDB actually needed
2074 its contents to evaluate the expression, then we
2075 must watch it. If the first value returned is
2076 still lazy, that means an error occurred reading it;
2077 watch it anyway in case it becomes readable. */
2078 if (v
->lval () == lval_memory
2079 && (v
== val_chain
[0] || ! v
->lazy ()))
2081 struct type
*vtype
= check_typedef (v
->type ());
2083 /* We only watch structs and arrays if user asked
2084 for it explicitly, never if they just happen to
2085 appear in the middle of some value chain. */
2087 || (vtype
->code () != TYPE_CODE_STRUCT
2088 && vtype
->code () != TYPE_CODE_ARRAY
))
2091 enum target_hw_bp_type type
;
2092 struct bp_location
*loc
, **tmp
;
2093 int bitpos
= 0, bitsize
= 0;
2095 if (v
->bitsize () != 0)
2097 /* Extract the bit parameters out from the bitfield
2099 bitpos
= v
->bitpos ();
2100 bitsize
= v
->bitsize ();
2102 else if (v
== result
&& b
->val_bitsize
!= 0)
2104 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2105 lvalue whose bit parameters are saved in the fields
2106 VAL_BITPOS and VAL_BITSIZE. */
2107 bitpos
= b
->val_bitpos
;
2108 bitsize
= b
->val_bitsize
;
2111 addr
= v
->address ();
2114 /* Skip the bytes that don't contain the bitfield. */
2119 if (b
->type
== bp_read_watchpoint
)
2121 else if (b
->type
== bp_access_watchpoint
)
2124 loc
= b
->allocate_location ();
2125 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2128 loc
->gdbarch
= v
->type ()->arch ();
2130 loc
->pspace
= frame_pspace
;
2132 = gdbarch_remove_non_address_bits (loc
->gdbarch
, addr
);
2136 /* Just cover the bytes that make up the bitfield. */
2137 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2140 loc
->length
= v
->type ()->length ();
2142 loc
->watchpoint_type
= type
;
2147 /* Helper function to bundle possibly emitting a warning along with
2148 changing the type of B to bp_watchpoint. */
2149 auto change_type_to_bp_watchpoint
= [] (breakpoint
*bp
)
2151 /* Only warn for breakpoints that have been assigned a +ve number,
2152 anything else is either an internal watchpoint (which we don't
2153 currently create) or has not yet been finalized, in which case
2154 this change of type will be occurring before the user is told
2155 the type of this watchpoint. */
2156 if (bp
->type
== bp_hardware_watchpoint
&& bp
->number
> 0)
2157 warning (_("watchpoint %d downgraded to software watchpoint"),
2159 bp
->type
= bp_watchpoint
;
2162 /* Change the type of breakpoint between hardware assisted or
2163 an ordinary watchpoint depending on the hardware support and
2164 free hardware slots. Recheck the number of free hardware slots
2165 as the value chain may have changed. */
2168 enum bp_loc_type loc_type
;
2170 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2174 int i
, target_resources_ok
, other_type_used
;
2177 /* Use an exact watchpoint when there's only one memory region to be
2178 watched, and only one debug register is needed to watch it. */
2179 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2181 /* We need to determine how many resources are already
2182 used for all other hardware watchpoints plus this one
2183 to see if we still have enough resources to also fit
2184 this watchpoint in as well. */
2186 /* If this is a software watchpoint, we try to turn it
2187 to a hardware one -- count resources as if B was of
2188 hardware watchpoint type. */
2190 if (type
== bp_watchpoint
)
2191 type
= bp_hardware_watchpoint
;
2193 /* This watchpoint may or may not have been placed on
2194 the list yet at this point (it won't be in the list
2195 if we're trying to create it for the first time,
2196 through watch_command), so always account for it
2199 /* Count resources used by all watchpoints except B. */
2200 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2202 /* Add in the resources needed for B. */
2203 i
+= hw_watchpoint_use_count (b
);
2206 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2207 if (target_resources_ok
<= 0)
2209 bool sw_mode
= b
->works_in_software_mode ();
2211 if (target_resources_ok
== 0 && !sw_mode
)
2212 error (_("Target does not support this type of "
2213 "hardware watchpoint."));
2214 else if (target_resources_ok
< 0 && !sw_mode
)
2215 error (_("There are not enough available hardware "
2216 "resources for this watchpoint."));
2218 /* Downgrade to software watchpoint. */
2219 change_type_to_bp_watchpoint (b
);
2223 /* If this was a software watchpoint, we've just
2224 found we have enough resources to turn it to a
2225 hardware watchpoint. Otherwise, this is a
2230 else if (!b
->works_in_software_mode ())
2232 if (!can_use_hw_watchpoints
)
2233 error (_("Can't set read/access watchpoint when "
2234 "hardware watchpoints are disabled."));
2236 error (_("Expression cannot be implemented with "
2237 "read/access watchpoint."));
2240 change_type_to_bp_watchpoint (b
);
2242 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_software_watchpoint
2243 : bp_loc_hardware_watchpoint
);
2244 for (bp_location
*bl
: b
->locations ())
2245 bl
->loc_type
= loc_type
;
2248 /* If a software watchpoint is not watching any memory, then the
2249 above left it without any location set up. But,
2250 bpstat_stop_status requires a location to be able to report
2251 stops, so make sure there's at least a dummy one. */
2252 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2253 add_dummy_location (b
, frame_pspace
);
2255 else if (!within_current_scope
)
2258 Watchpoint %d deleted because the program has left the block\n\
2259 in which its expression is valid.\n"),
2261 watchpoint_del_at_next_stop (b
);
2265 /* Returns true iff breakpoint location should be
2266 inserted in the inferior. We don't differentiate the type of BL's owner
2267 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2268 breakpoint_ops is not defined, because in insert_bp_location,
2269 tracepoint's insert_location will not be called. */
2272 should_be_inserted (struct bp_location
*bl
)
2274 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2277 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2280 if (!bl
->enabled
|| bl
->disabled_by_cond
2281 || bl
->shlib_disabled
|| bl
->duplicate
)
2284 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2287 /* This is set for example, when we're attached to the parent of a
2288 vfork, and have detached from the child. The child is running
2289 free, and we expect it to do an exec or exit, at which point the
2290 OS makes the parent schedulable again (and the target reports
2291 that the vfork is done). Until the child is done with the shared
2292 memory region, do not insert breakpoints in the parent, otherwise
2293 the child could still trip on the parent's breakpoints. Since
2294 the parent is blocked anyway, it won't miss any breakpoint. */
2295 if (bl
->pspace
->breakpoints_not_allowed
)
2298 /* Don't insert a breakpoint if we're trying to step past its
2299 location, except if the breakpoint is a single-step breakpoint,
2300 and the breakpoint's thread is the thread which is stepping past
2302 if ((bl
->loc_type
== bp_loc_software_breakpoint
2303 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2304 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2306 /* The single-step breakpoint may be inserted at the location
2307 we're trying to step if the instruction branches to itself.
2308 However, the instruction won't be executed at all and it may
2309 break the semantics of the instruction, for example, the
2310 instruction is a conditional branch or updates some flags.
2311 We can't fix it unless GDB is able to emulate the instruction
2312 or switch to displaced stepping. */
2313 && !(bl
->owner
->type
== bp_single_step
2314 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2316 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2317 paddress (bl
->gdbarch
, bl
->address
));
2321 /* Don't insert watchpoints if we're trying to step past the
2322 instruction that triggered one. */
2323 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2324 && stepping_past_nonsteppable_watchpoint ())
2326 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2327 "skipping watchpoint at %s:%d",
2328 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2335 /* Same as should_be_inserted but does the check assuming
2336 that the location is not duplicated. */
2339 unduplicated_should_be_inserted (struct bp_location
*bl
)
2341 scoped_restore restore_bl_duplicate
2342 = make_scoped_restore (&bl
->duplicate
, 0);
2344 return should_be_inserted (bl
);
2347 /* Parses a conditional described by an expression COND into an
2348 agent expression bytecode suitable for evaluation
2349 by the bytecode interpreter. Return NULL if there was
2350 any error during parsing. */
2352 static agent_expr_up
2353 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2358 agent_expr_up aexpr
;
2360 /* We don't want to stop processing, so catch any errors
2361 that may show up. */
2364 aexpr
= gen_eval_for_expr (scope
, cond
);
2367 catch (const gdb_exception_error
&ex
)
2369 /* If we got here, it means the condition could not be parsed to a valid
2370 bytecode expression and thus can't be evaluated on the target's side.
2371 It's no use iterating through the conditions. */
2374 /* We have a valid agent expression. */
2378 /* Based on location BL, create a list of breakpoint conditions to be
2379 passed on to the target. If we have duplicated locations with different
2380 conditions, we will add such conditions to the list. The idea is that the
2381 target will evaluate the list of conditions and will only notify GDB when
2382 one of them is true. */
2385 build_target_condition_list (struct bp_location
*bl
)
2387 bool null_condition_or_parse_error
= false;
2388 int modified
= bl
->needs_update
;
2390 /* Release conditions left over from a previous insert. */
2391 bl
->target_info
.conditions
.clear ();
2393 /* This is only meaningful if the target is
2394 evaluating conditions and if the user has
2395 opted for condition evaluation on the target's
2397 if (gdb_evaluates_breakpoint_condition_p ()
2398 || !target_supports_evaluation_of_breakpoint_conditions ())
2401 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2403 /* Do a first pass to check for locations with no assigned
2404 conditions or conditions that fail to parse to a valid agent
2405 expression bytecode. If any of these happen, then it's no use to
2406 send conditions to the target since this location will always
2407 trigger and generate a response back to GDB. Note we consider
2408 all locations at the same address irrespective of type, i.e.,
2409 even if the locations aren't considered duplicates (e.g.,
2410 software breakpoint and hardware breakpoint at the same
2412 for (bp_location
*loc
: loc_range
)
2414 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2418 /* Re-parse the conditions since something changed. In that
2419 case we already freed the condition bytecodes (see
2420 force_breakpoint_reinsertion). We just
2421 need to parse the condition to bytecodes again. */
2422 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2426 /* If we have a NULL bytecode expression, it means something
2427 went wrong or we have a null condition expression. */
2428 if (!loc
->cond_bytecode
)
2430 null_condition_or_parse_error
= true;
2436 /* If any of these happened, it means we will have to evaluate the conditions
2437 for the location's address on gdb's side. It is no use keeping bytecodes
2438 for all the other duplicate locations, thus we free all of them here.
2440 This is so we have a finer control over which locations' conditions are
2441 being evaluated by GDB or the remote stub. */
2442 if (null_condition_or_parse_error
)
2444 for (bp_location
*loc
: loc_range
)
2446 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2448 /* Only go as far as the first NULL bytecode is
2450 if (!loc
->cond_bytecode
)
2453 loc
->cond_bytecode
.reset ();
2458 /* No NULL conditions or failed bytecode generation. Build a
2459 condition list for this location's address. If we have software
2460 and hardware locations at the same address, they aren't
2461 considered duplicates, but we still marge all the conditions
2462 anyway, as it's simpler, and doesn't really make a practical
2464 for (bp_location
*loc
: loc_range
)
2466 && is_breakpoint (loc
->owner
)
2467 && loc
->pspace
->num
== bl
->pspace
->num
2468 && loc
->owner
->enable_state
== bp_enabled
2470 && !loc
->disabled_by_cond
)
2472 /* Add the condition to the vector. This will be used later
2473 to send the conditions to the target. */
2474 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2480 /* Parses a command described by string CMD into an agent expression
2481 bytecode suitable for evaluation by the bytecode interpreter.
2482 Return NULL if there was any error during parsing. */
2484 static agent_expr_up
2485 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2487 const char *cmdrest
;
2488 const char *format_start
, *format_end
;
2489 struct gdbarch
*gdbarch
= get_current_arch ();
2496 if (*cmdrest
== ',')
2498 cmdrest
= skip_spaces (cmdrest
);
2500 if (*cmdrest
++ != '"')
2501 error (_("No format string following the location"));
2503 format_start
= cmdrest
;
2505 format_pieces
fpieces (&cmdrest
);
2507 format_end
= cmdrest
;
2509 if (*cmdrest
++ != '"')
2510 error (_("Bad format string, non-terminated '\"'."));
2512 cmdrest
= skip_spaces (cmdrest
);
2514 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2515 error (_("Invalid argument syntax"));
2517 if (*cmdrest
== ',')
2519 cmdrest
= skip_spaces (cmdrest
);
2521 /* For each argument, make an expression. */
2523 std::vector
<struct expression
*> argvec
;
2524 while (*cmdrest
!= '\0')
2529 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2530 argvec
.push_back (expr
.release ());
2532 if (*cmdrest
== ',')
2536 agent_expr_up aexpr
;
2538 /* We don't want to stop processing, so catch any errors
2539 that may show up. */
2542 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2543 format_start
, format_end
- format_start
,
2544 argvec
.size (), argvec
.data ());
2546 catch (const gdb_exception_error
&ex
)
2548 /* If we got here, it means the command could not be parsed to a valid
2549 bytecode expression and thus can't be evaluated on the target's side.
2550 It's no use iterating through the other commands. */
2553 /* We have a valid agent expression, return it. */
2557 /* Based on location BL, create a list of breakpoint commands to be
2558 passed on to the target. If we have duplicated locations with
2559 different commands, we will add any such to the list. */
2562 build_target_command_list (struct bp_location
*bl
)
2564 bool null_command_or_parse_error
= false;
2565 int modified
= bl
->needs_update
;
2567 /* Clear commands left over from a previous insert. */
2568 bl
->target_info
.tcommands
.clear ();
2570 if (!target_can_run_breakpoint_commands ())
2573 /* For now, limit to agent-style dprintf breakpoints. */
2574 if (dprintf_style
!= dprintf_style_agent
)
2577 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2579 /* For now, if we have any location at the same address that isn't a
2580 dprintf, don't install the target-side commands, as that would
2581 make the breakpoint not be reported to the core, and we'd lose
2583 for (bp_location
*loc
: loc_range
)
2584 if (is_breakpoint (loc
->owner
)
2585 && loc
->pspace
->num
== bl
->pspace
->num
2586 && loc
->owner
->type
!= bp_dprintf
)
2589 /* Do a first pass to check for locations with no assigned
2590 conditions or conditions that fail to parse to a valid agent expression
2591 bytecode. If any of these happen, then it's no use to send conditions
2592 to the target since this location will always trigger and generate a
2593 response back to GDB. */
2594 for (bp_location
*loc
: loc_range
)
2596 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2600 /* Re-parse the commands since something changed. In that
2601 case we already freed the command bytecodes (see
2602 force_breakpoint_reinsertion). We just
2603 need to parse the command to bytecodes again. */
2605 = parse_cmd_to_aexpr (bl
->address
,
2606 loc
->owner
->extra_string
.get ());
2609 /* If we have a NULL bytecode expression, it means something
2610 went wrong or we have a null command expression. */
2611 if (!loc
->cmd_bytecode
)
2613 null_command_or_parse_error
= true;
2619 /* If anything failed, then we're not doing target-side commands,
2621 if (null_command_or_parse_error
)
2623 for (bp_location
*loc
: loc_range
)
2624 if (is_breakpoint (loc
->owner
)
2625 && loc
->pspace
->num
== bl
->pspace
->num
)
2627 /* Only go as far as the first NULL bytecode is
2629 if (loc
->cmd_bytecode
== NULL
)
2632 loc
->cmd_bytecode
.reset ();
2636 /* No NULL commands or failed bytecode generation. Build a command
2637 list for all duplicate locations at this location's address.
2638 Note that here we must care for whether the breakpoint location
2639 types are considered duplicates, otherwise, say, if we have a
2640 software and hardware location at the same address, the target
2641 could end up running the commands twice. For the moment, we only
2642 support targets-side commands with dprintf, but it doesn't hurt
2643 to be pedantically correct in case that changes. */
2644 for (bp_location
*loc
: loc_range
)
2645 if (breakpoint_locations_match (bl
, loc
)
2646 && loc
->owner
->extra_string
2647 && is_breakpoint (loc
->owner
)
2648 && loc
->pspace
->num
== bl
->pspace
->num
2649 && loc
->owner
->enable_state
== bp_enabled
2651 && !loc
->disabled_by_cond
)
2653 /* Add the command to the vector. This will be used later
2654 to send the commands to the target. */
2655 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2658 bl
->target_info
.persist
= 0;
2659 /* Maybe flag this location as persistent. */
2660 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2661 bl
->target_info
.persist
= 1;
2664 /* Return the kind of breakpoint on address *ADDR. Get the kind
2665 of breakpoint according to ADDR except single-step breakpoint.
2666 Get the kind of single-step breakpoint according to the current
2670 breakpoint_kind (const struct bp_location
*bl
, CORE_ADDR
*addr
)
2672 if (bl
->owner
->type
== bp_single_step
)
2674 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2675 struct regcache
*regcache
;
2677 regcache
= get_thread_regcache (thr
);
2679 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2683 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2686 /* Rethrow the currently handled exception, if it's a TARGET_CLOSE_ERROR.
2687 E is either the currently handled exception, or a copy, or a sliced copy,
2688 so we can't rethrow that one, but we can use it to inspect the properties
2689 of the currently handled exception. */
2692 rethrow_on_target_close_error (const gdb_exception
&e
)
2696 /* Can't set the breakpoint. */
2698 if (e
.error
!= TARGET_CLOSE_ERROR
)
2701 /* If the target has closed then it will have deleted any breakpoints
2702 inserted within the target inferior, as a result any further attempts
2703 to interact with the breakpoint objects is not possible. Just rethrow
2704 the error. Don't use e to rethrow, to prevent object slicing of the
2709 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2710 location. Any error messages are printed to TMP_ERROR_STREAM; and
2711 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2712 Returns 0 for success, 1 if the bp_location type is not supported or
2715 NOTE drow/2003-09-09: This routine could be broken down to an
2716 object-style method for each breakpoint or catchpoint type. */
2718 insert_bp_location (struct bp_location
*bl
,
2719 struct ui_file
*tmp_error_stream
,
2720 int *disabled_breaks
,
2721 int *hw_breakpoint_error
,
2722 int *hw_bp_error_explained_already
)
2724 gdb_exception bp_excpt
;
2726 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2729 /* Note we don't initialize bl->target_info, as that wipes out
2730 the breakpoint location's shadow_contents if the breakpoint
2731 is still inserted at that location. This in turn breaks
2732 target_read_memory which depends on these buffers when
2733 a memory read is requested at the breakpoint location:
2734 Once the target_info has been wiped, we fail to see that
2735 we have a breakpoint inserted at that address and thus
2736 read the breakpoint instead of returning the data saved in
2737 the breakpoint location's shadow contents. */
2738 bl
->target_info
.reqstd_address
= bl
->address
;
2739 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2740 bl
->target_info
.length
= bl
->length
;
2742 /* When working with target-side conditions, we must pass all the conditions
2743 for the same breakpoint address down to the target since GDB will not
2744 insert those locations. With a list of breakpoint conditions, the target
2745 can decide when to stop and notify GDB. */
2747 if (is_breakpoint (bl
->owner
))
2749 build_target_condition_list (bl
);
2750 build_target_command_list (bl
);
2751 /* Reset the modification marker. */
2752 bl
->needs_update
= 0;
2755 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2756 set at a read-only address, then a breakpoint location will have
2757 been changed to hardware breakpoint before we get here. If it is
2758 "off" however, error out before actually trying to insert the
2759 breakpoint, with a nicer error message. */
2760 if (bl
->loc_type
== bp_loc_software_breakpoint
2761 && !automatic_hardware_breakpoints
)
2763 mem_region
*mr
= lookup_mem_region (bl
->address
);
2765 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2767 gdb_printf (tmp_error_stream
,
2768 _("Cannot insert breakpoint %d.\n"
2769 "Cannot set software breakpoint "
2770 "at read-only address %s\n"),
2772 paddress (bl
->gdbarch
, bl
->address
));
2777 if (bl
->loc_type
== bp_loc_software_breakpoint
2778 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2780 /* First check to see if we have to handle an overlay. */
2781 if (overlay_debugging
== ovly_off
2782 || bl
->section
== NULL
2783 || !(section_is_overlay (bl
->section
)))
2785 /* No overlay handling: just set the breakpoint. */
2790 val
= bl
->owner
->insert_location (bl
);
2792 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2794 catch (gdb_exception
&e
)
2796 rethrow_on_target_close_error (e
);
2797 bp_excpt
= std::move (e
);
2802 /* This breakpoint is in an overlay section.
2803 Shall we set a breakpoint at the LMA? */
2804 if (!overlay_events_enabled
)
2806 /* Yes -- overlay event support is not active,
2807 so we must try to set a breakpoint at the LMA.
2808 This will not work for a hardware breakpoint. */
2809 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2810 warning (_("hardware breakpoint %d not supported in overlay!"),
2814 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2816 /* Set a software (trap) breakpoint at the LMA. */
2817 bl
->overlay_target_info
= bl
->target_info
;
2818 bl
->overlay_target_info
.reqstd_address
= addr
;
2820 /* No overlay handling: just set the breakpoint. */
2825 bl
->overlay_target_info
.kind
2826 = breakpoint_kind (bl
, &addr
);
2827 bl
->overlay_target_info
.placed_address
= addr
;
2828 val
= target_insert_breakpoint (bl
->gdbarch
,
2829 &bl
->overlay_target_info
);
2832 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2834 catch (gdb_exception
&e
)
2836 rethrow_on_target_close_error (e
);
2837 bp_excpt
= std::move (e
);
2840 if (bp_excpt
.reason
!= 0)
2841 gdb_printf (tmp_error_stream
,
2842 "Overlay breakpoint %d "
2843 "failed: in ROM?\n",
2847 /* Shall we set a breakpoint at the VMA? */
2848 if (section_is_mapped (bl
->section
))
2850 /* Yes. This overlay section is mapped into memory. */
2855 val
= bl
->owner
->insert_location (bl
);
2857 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2859 catch (gdb_exception_error
&e
)
2861 rethrow_on_target_close_error (e
);
2862 bp_excpt
= std::move (e
);
2867 /* No. This breakpoint will not be inserted.
2868 No error, but do not mark the bp as 'inserted'. */
2873 if (bp_excpt
.reason
!= 0)
2875 /* Can't set the breakpoint. */
2876 gdb_assert (bl
->owner
!= nullptr);
2878 /* In some cases, we might not be able to insert a
2879 breakpoint in a shared library that has already been
2880 removed, but we have not yet processed the shlib unload
2881 event. Unfortunately, some targets that implement
2882 breakpoint insertion themselves can't tell why the
2883 breakpoint insertion failed (e.g., the remote target
2884 doesn't define error codes), so we must treat generic
2885 errors as memory errors. */
2886 if (bp_excpt
.reason
== RETURN_ERROR
2887 && (bp_excpt
.error
== GENERIC_ERROR
2888 || bp_excpt
.error
== MEMORY_ERROR
)
2889 && bl
->loc_type
== bp_loc_software_breakpoint
2890 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2891 || shared_objfile_contains_address_p (bl
->pspace
,
2894 /* See also: disable_breakpoints_in_shlibs. */
2895 bl
->shlib_disabled
= 1;
2896 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2897 if (!*disabled_breaks
)
2899 gdb_printf (tmp_error_stream
,
2900 "Cannot insert breakpoint %d.\n",
2902 gdb_printf (tmp_error_stream
,
2903 "Temporarily disabling shared "
2904 "library breakpoints:\n");
2906 *disabled_breaks
= 1;
2907 gdb_printf (tmp_error_stream
,
2908 "breakpoint #%d\n", bl
->owner
->number
);
2913 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2915 *hw_breakpoint_error
= 1;
2916 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2917 gdb_printf (tmp_error_stream
,
2918 "Cannot insert hardware breakpoint %d%s",
2920 bp_excpt
.message
? ":" : ".\n");
2921 if (bp_excpt
.message
!= NULL
)
2922 gdb_printf (tmp_error_stream
, "%s.\n",
2927 if (bp_excpt
.message
== NULL
)
2930 = memory_error_message (TARGET_XFER_E_IO
,
2931 bl
->gdbarch
, bl
->address
);
2933 gdb_printf (tmp_error_stream
,
2934 "Cannot insert breakpoint %d.\n"
2936 bl
->owner
->number
, message
.c_str ());
2940 gdb_printf (tmp_error_stream
,
2941 "Cannot insert breakpoint %d: %s\n",
2956 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2957 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2961 val
= bl
->owner
->insert_location (bl
);
2963 /* If trying to set a read-watchpoint, and it turns out it's not
2964 supported, try emulating one with an access watchpoint. */
2965 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2967 /* But don't try to insert it, if there's already another
2968 hw_access location that would be considered a duplicate
2970 for (bp_location
*loc
: all_bp_locations ())
2972 && loc
->watchpoint_type
== hw_access
2973 && watchpoint_locations_match (bl
, loc
))
2977 bl
->target_info
= loc
->target_info
;
2978 bl
->watchpoint_type
= hw_access
;
2985 bl
->watchpoint_type
= hw_access
;
2986 val
= bl
->owner
->insert_location (bl
);
2989 /* Back to the original value. */
2990 bl
->watchpoint_type
= hw_read
;
2994 bl
->inserted
= (val
== 0);
2997 else if (bl
->owner
->type
== bp_catchpoint
)
3001 val
= bl
->owner
->insert_location (bl
);
3004 bl
->owner
->enable_state
= bp_disabled
;
3008 Error inserting catchpoint %d: Your system does not support this type\n\
3009 of catchpoint."), bl
->owner
->number
);
3011 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
3014 bl
->inserted
= (val
== 0);
3016 /* We've already printed an error message if there was a problem
3017 inserting this catchpoint, and we've disabled the catchpoint,
3018 so just return success. */
3025 /* This function is called when program space PSPACE is about to be
3026 deleted. It takes care of updating breakpoints to not reference
3030 breakpoint_program_space_exit (struct program_space
*pspace
)
3032 /* Remove any breakpoint that was set through this program space. */
3033 for (breakpoint
*b
: all_breakpoints_safe ())
3034 if (b
->pspace
== pspace
)
3035 delete_breakpoint (b
);
3037 /* Breakpoints set through other program spaces could have locations
3038 bound to PSPACE as well. Remove those. */
3039 for (bp_location
*loc
: all_bp_locations ())
3041 struct bp_location
*tmp
;
3043 if (loc
->pspace
== pspace
)
3045 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3046 if (loc
->owner
->loc
== loc
)
3047 loc
->owner
->loc
= loc
->next
;
3049 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3050 if (tmp
->next
== loc
)
3052 tmp
->next
= loc
->next
;
3058 /* Now update the global location list to permanently delete the
3059 removed locations above. */
3060 update_global_location_list (UGLL_DONT_INSERT
);
3063 /* Make sure all breakpoints are inserted in inferior.
3064 Throws exception on any error.
3065 A breakpoint that is already inserted won't be inserted
3066 again, so calling this function twice is safe. */
3068 insert_breakpoints (void)
3070 for (breakpoint
*bpt
: all_breakpoints ())
3071 if (is_hardware_watchpoint (bpt
))
3073 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3075 update_watchpoint (w
, false /* don't reparse. */);
3078 /* Updating watchpoints creates new locations, so update the global
3079 location list. Explicitly tell ugll to insert locations and
3080 ignore breakpoints_always_inserted_mode. Also,
3081 update_global_location_list tries to "upgrade" software
3082 breakpoints to hardware breakpoints to handle "set breakpoint
3083 auto-hw", so we need to call it even if we don't have new
3085 update_global_location_list (UGLL_INSERT
);
3088 /* This is used when we need to synch breakpoint conditions between GDB and the
3089 target. It is the case with deleting and disabling of breakpoints when using
3090 always-inserted mode. */
3093 update_inserted_breakpoint_locations (void)
3097 int disabled_breaks
= 0;
3098 int hw_breakpoint_error
= 0;
3099 int hw_bp_details_reported
= 0;
3101 string_file tmp_error_stream
;
3103 /* Explicitly mark the warning -- this will only be printed if
3104 there was an error. */
3105 tmp_error_stream
.puts ("Warning:\n");
3107 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3109 for (bp_location
*bl
: all_bp_locations ())
3111 /* We only want to update software breakpoints and hardware
3113 if (!is_breakpoint (bl
->owner
))
3116 /* We only want to update locations that are already inserted
3117 and need updating. This is to avoid unwanted insertion during
3118 deletion of breakpoints. */
3119 if (!bl
->inserted
|| !bl
->needs_update
)
3122 switch_to_program_space_and_thread (bl
->pspace
);
3124 /* For targets that support global breakpoints, there's no need
3125 to select an inferior to insert breakpoint to. In fact, even
3126 if we aren't attached to any process yet, we should still
3127 insert breakpoints. */
3128 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3129 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3132 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3133 &hw_breakpoint_error
, &hw_bp_details_reported
);
3140 target_terminal::ours_for_output ();
3141 error (("%s"), tmp_error_stream
.c_str ());
3145 /* Used when starting or continuing the program. */
3148 insert_breakpoint_locations (void)
3152 int disabled_breaks
= 0;
3153 int hw_breakpoint_error
= 0;
3154 int hw_bp_error_explained_already
= 0;
3156 string_file tmp_error_stream
;
3158 /* Explicitly mark the warning -- this will only be printed if
3159 there was an error. */
3160 tmp_error_stream
.puts ("Warning:\n");
3162 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3164 for (bp_location
*bl
: all_bp_locations ())
3166 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3169 /* There is no point inserting thread-specific breakpoints if
3170 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3171 has BL->OWNER always non-NULL. */
3172 if (bl
->owner
->thread
!= -1
3173 && !valid_global_thread_id (bl
->owner
->thread
))
3176 switch_to_program_space_and_thread (bl
->pspace
);
3178 /* For targets that support global breakpoints, there's no need
3179 to select an inferior to insert breakpoint to. In fact, even
3180 if we aren't attached to any process yet, we should still
3181 insert breakpoints. */
3182 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3183 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3186 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3187 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3192 /* If we failed to insert all locations of a watchpoint, remove
3193 them, as half-inserted watchpoint is of limited use. */
3194 for (breakpoint
*bpt
: all_breakpoints ())
3196 bool some_failed
= false;
3198 if (!is_hardware_watchpoint (bpt
))
3201 if (!breakpoint_enabled (bpt
))
3204 if (bpt
->disposition
== disp_del_at_next_stop
)
3207 for (bp_location
*loc
: bpt
->locations ())
3208 if (!loc
->inserted
&& should_be_inserted (loc
))
3216 for (bp_location
*loc
: bpt
->locations ())
3218 remove_breakpoint (loc
);
3220 hw_breakpoint_error
= 1;
3221 tmp_error_stream
.printf ("Could not insert "
3222 "hardware watchpoint %d.\n",
3230 /* If a hardware breakpoint or watchpoint was inserted, add a
3231 message about possibly exhausted resources. */
3232 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3234 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3235 You may have requested too many hardware breakpoints/watchpoints.\n");
3237 target_terminal::ours_for_output ();
3238 error (("%s"), tmp_error_stream
.c_str ());
3242 /* Used when the program stops.
3243 Returns zero if successful, or non-zero if there was a problem
3244 removing a breakpoint location. */
3247 remove_breakpoints (void)
3251 for (bp_location
*bl
: all_bp_locations ())
3252 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3253 val
|= remove_breakpoint (bl
);
3258 /* When a thread exits, remove breakpoints that are related to
3262 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3264 for (breakpoint
*b
: all_breakpoints_safe ())
3266 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3269 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3270 b
->number
, print_thread_id (tp
));
3271 delete_breakpoint (b
);
3276 /* See breakpoint.h. */
3279 remove_breakpoints_inf (inferior
*inf
)
3283 for (bp_location
*bl
: all_bp_locations ())
3285 if (bl
->pspace
!= inf
->pspace
)
3288 if (bl
->inserted
&& !bl
->target_info
.persist
)
3290 val
= remove_breakpoint (bl
);
3297 static int internal_breakpoint_number
= -1;
3299 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3300 If INTERNAL is non-zero, the breakpoint number will be populated
3301 from internal_breakpoint_number and that variable decremented.
3302 Otherwise the breakpoint number will be populated from
3303 breakpoint_count and that value incremented. Internal breakpoints
3304 do not set the internal var bpnum. */
3306 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3309 b
->number
= internal_breakpoint_number
--;
3312 set_breakpoint_count (breakpoint_count
+ 1);
3313 b
->number
= breakpoint_count
;
3317 /* Create a TYPE breakpoint on ADDRESS from an object file with GDBARCH. */
3319 static struct breakpoint
*
3320 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3321 CORE_ADDR address
, enum bptype type
)
3323 std::unique_ptr
<internal_breakpoint
> b
3324 (new internal_breakpoint (gdbarch
, type
, address
));
3326 b
->number
= internal_breakpoint_number
--;
3328 return add_to_breakpoint_chain (std::move (b
));
3331 /* Create a TYPE breakpoint on minimal symbol MSYM from an object file with
3334 static struct breakpoint
*
3335 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3336 struct bound_minimal_symbol
&msym
, enum bptype type
)
3340 address
= msym
.value_address ();
3342 address
= gdbarch_convert_from_func_ptr_addr
3343 (gdbarch
, address
, current_inferior ()->top_target ());
3345 /* Note that we're not using gdbarch_addr_bits_remove here, because that's
3346 related to addresses in $pc. We're getting the address from the
3347 minimal symbol table. */
3349 /* Is gdbarch_deprecated_function_start_offset needed here? Or is that dealt
3350 with elsewhere? Needs testing on vax. */
3352 if (gdbarch_skip_entrypoint_p (gdbarch
))
3353 address
= gdbarch_skip_entrypoint (gdbarch
, address
);
3355 return create_internal_breakpoint (gdbarch
, address
, type
);
3358 static const char *const longjmp_names
[] =
3360 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3362 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3364 /* Per-objfile data private to breakpoint.c. */
3365 struct breakpoint_objfile_data
3367 /* Minimal symbol for "_ovly_debug_event" (if any). */
3368 struct bound_minimal_symbol overlay_msym
;
3370 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3371 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3373 /* True if we have looked for longjmp probes. */
3374 int longjmp_searched
= 0;
3376 /* SystemTap probe points for longjmp (if any). These are non-owning
3378 std::vector
<probe
*> longjmp_probes
;
3380 /* Minimal symbol for "std::terminate()" (if any). */
3381 struct bound_minimal_symbol terminate_msym
;
3383 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3384 struct bound_minimal_symbol exception_msym
;
3386 /* True if we have looked for exception probes. */
3387 int exception_searched
= 0;
3389 /* SystemTap probe points for unwinding (if any). These are non-owning
3391 std::vector
<probe
*> exception_probes
;
3394 static const registry
<objfile
>::key
<breakpoint_objfile_data
>
3395 breakpoint_objfile_key
;
3397 /* Minimal symbol not found sentinel. */
3398 static struct minimal_symbol msym_not_found
;
3400 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3403 msym_not_found_p (const struct minimal_symbol
*msym
)
3405 return msym
== &msym_not_found
;
3408 /* Return per-objfile data needed by breakpoint.c.
3409 Allocate the data if necessary. */
3411 static struct breakpoint_objfile_data
*
3412 get_breakpoint_objfile_data (struct objfile
*objfile
)
3414 struct breakpoint_objfile_data
*bp_objfile_data
;
3416 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3417 if (bp_objfile_data
== NULL
)
3418 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3419 return bp_objfile_data
;
3423 create_overlay_event_breakpoint (void)
3425 const char *const func_name
= "_ovly_debug_event";
3427 for (objfile
*objfile
: current_program_space
->objfiles ())
3429 struct breakpoint
*b
;
3430 struct breakpoint_objfile_data
*bp_objfile_data
;
3433 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3435 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3438 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3440 struct bound_minimal_symbol m
;
3442 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3443 if (m
.minsym
== NULL
)
3445 /* Avoid future lookups in this objfile. */
3446 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3449 bp_objfile_data
->overlay_msym
= m
;
3452 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3453 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3455 b
->locspec
= new_explicit_location_spec_function (func_name
);
3457 if (overlay_debugging
== ovly_auto
)
3459 b
->enable_state
= bp_enabled
;
3460 overlay_events_enabled
= 1;
3464 b
->enable_state
= bp_disabled
;
3465 overlay_events_enabled
= 0;
3470 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3471 true if a breakpoint was installed. */
3474 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3476 struct gdbarch
*gdbarch
= objfile
->arch ();
3477 struct breakpoint_objfile_data
*bp_objfile_data
3478 = get_breakpoint_objfile_data (objfile
);
3480 if (!bp_objfile_data
->longjmp_searched
)
3482 std::vector
<probe
*> ret
3483 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3487 /* We are only interested in checking one element. */
3490 if (!p
->can_evaluate_arguments ())
3492 /* We cannot use the probe interface here,
3493 because it does not know how to evaluate
3498 bp_objfile_data
->longjmp_probes
= ret
;
3499 bp_objfile_data
->longjmp_searched
= 1;
3502 if (bp_objfile_data
->longjmp_probes
.empty ())
3505 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3507 struct breakpoint
*b
;
3509 b
= create_internal_breakpoint (gdbarch
,
3510 p
->get_relocated_address (objfile
),
3512 b
->locspec
= new_probe_location_spec ("-probe-stap libc:longjmp");
3513 b
->enable_state
= bp_disabled
;
3519 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3520 Return true if at least one breakpoint was installed. */
3523 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3525 struct gdbarch
*gdbarch
= objfile
->arch ();
3526 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3529 struct breakpoint_objfile_data
*bp_objfile_data
3530 = get_breakpoint_objfile_data (objfile
);
3531 unsigned int installed_bp
= 0;
3533 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3535 struct breakpoint
*b
;
3536 const char *func_name
;
3539 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3542 func_name
= longjmp_names
[i
];
3543 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3545 struct bound_minimal_symbol m
;
3547 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3548 if (m
.minsym
== NULL
)
3550 /* Prevent future lookups in this objfile. */
3551 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3554 bp_objfile_data
->longjmp_msym
[i
] = m
;
3557 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3558 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3559 b
->locspec
= new_explicit_location_spec_function (func_name
);
3560 b
->enable_state
= bp_disabled
;
3564 return installed_bp
> 0;
3567 /* Create a master longjmp breakpoint. */
3570 create_longjmp_master_breakpoint (void)
3572 scoped_restore_current_program_space restore_pspace
;
3574 for (struct program_space
*pspace
: program_spaces
)
3576 set_current_program_space (pspace
);
3578 for (objfile
*obj
: current_program_space
->objfiles ())
3580 /* Skip separate debug object, it's handled in the loop below. */
3581 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3584 /* Try a probe kind breakpoint on main objfile. */
3585 if (create_longjmp_master_breakpoint_probe (obj
))
3588 /* Try longjmp_names kind breakpoints on main and separate_debug
3590 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3591 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3597 /* Create a master std::terminate breakpoint. */
3599 create_std_terminate_master_breakpoint (void)
3601 const char *const func_name
= "std::terminate()";
3603 scoped_restore_current_program_space restore_pspace
;
3605 for (struct program_space
*pspace
: program_spaces
)
3607 set_current_program_space (pspace
);
3609 for (objfile
*objfile
: current_program_space
->objfiles ())
3611 struct breakpoint
*b
;
3612 struct breakpoint_objfile_data
*bp_objfile_data
;
3614 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3616 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3619 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3621 struct bound_minimal_symbol m
;
3623 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3624 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3625 && m
.minsym
->type () != mst_file_text
))
3627 /* Prevent future lookups in this objfile. */
3628 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3631 bp_objfile_data
->terminate_msym
= m
;
3634 b
= create_internal_breakpoint (objfile
->arch (),
3635 bp_objfile_data
->terminate_msym
,
3636 bp_std_terminate_master
);
3637 b
->locspec
= new_explicit_location_spec_function (func_name
);
3638 b
->enable_state
= bp_disabled
;
3643 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3644 probe. Return true if a breakpoint was installed. */
3647 create_exception_master_breakpoint_probe (objfile
*objfile
)
3649 struct breakpoint
*b
;
3650 struct gdbarch
*gdbarch
;
3651 struct breakpoint_objfile_data
*bp_objfile_data
;
3653 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3655 /* We prefer the SystemTap probe point if it exists. */
3656 if (!bp_objfile_data
->exception_searched
)
3658 std::vector
<probe
*> ret
3659 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3663 /* We are only interested in checking one element. */
3666 if (!p
->can_evaluate_arguments ())
3668 /* We cannot use the probe interface here, because it does
3669 not know how to evaluate arguments. */
3673 bp_objfile_data
->exception_probes
= ret
;
3674 bp_objfile_data
->exception_searched
= 1;
3677 if (bp_objfile_data
->exception_probes
.empty ())
3680 gdbarch
= objfile
->arch ();
3682 for (probe
*p
: bp_objfile_data
->exception_probes
)
3684 b
= create_internal_breakpoint (gdbarch
,
3685 p
->get_relocated_address (objfile
),
3686 bp_exception_master
);
3687 b
->locspec
= new_probe_location_spec ("-probe-stap libgcc:unwind");
3688 b
->enable_state
= bp_disabled
;
3694 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3695 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3698 create_exception_master_breakpoint_hook (objfile
*objfile
)
3700 const char *const func_name
= "_Unwind_DebugHook";
3701 struct breakpoint
*b
;
3702 struct gdbarch
*gdbarch
;
3703 struct breakpoint_objfile_data
*bp_objfile_data
;
3705 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3707 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3710 gdbarch
= objfile
->arch ();
3712 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3714 struct bound_minimal_symbol debug_hook
;
3716 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3717 if (debug_hook
.minsym
== NULL
)
3719 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3723 bp_objfile_data
->exception_msym
= debug_hook
;
3726 b
= create_internal_breakpoint (gdbarch
, bp_objfile_data
->exception_msym
,
3727 bp_exception_master
);
3728 b
->locspec
= new_explicit_location_spec_function (func_name
);
3729 b
->enable_state
= bp_disabled
;
3734 /* Install a master breakpoint on the unwinder's debug hook. */
3737 create_exception_master_breakpoint (void)
3739 for (objfile
*obj
: current_program_space
->objfiles ())
3741 /* Skip separate debug object. */
3742 if (obj
->separate_debug_objfile_backlink
)
3745 /* Try a probe kind breakpoint. */
3746 if (create_exception_master_breakpoint_probe (obj
))
3749 /* Iterate over main and separate debug objects and try an
3750 _Unwind_DebugHook kind breakpoint. */
3751 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3752 if (create_exception_master_breakpoint_hook (debug_objfile
))
3757 /* Does B have a location spec? */
3760 breakpoint_location_spec_empty_p (const struct breakpoint
*b
)
3762 return (b
->locspec
!= nullptr && b
->locspec
->empty_p ());
3766 update_breakpoints_after_exec (void)
3768 /* We're about to delete breakpoints from GDB's lists. If the
3769 INSERTED flag is true, GDB will try to lift the breakpoints by
3770 writing the breakpoints' "shadow contents" back into memory. The
3771 "shadow contents" are NOT valid after an exec, so GDB should not
3772 do that. Instead, the target is responsible from marking
3773 breakpoints out as soon as it detects an exec. We don't do that
3774 here instead, because there may be other attempts to delete
3775 breakpoints after detecting an exec and before reaching here. */
3776 for (bp_location
*bploc
: all_bp_locations ())
3777 if (bploc
->pspace
== current_program_space
)
3778 gdb_assert (!bploc
->inserted
);
3780 for (breakpoint
*b
: all_breakpoints_safe ())
3782 if (b
->pspace
!= current_program_space
)
3785 /* Solib breakpoints must be explicitly reset after an exec(). */
3786 if (b
->type
== bp_shlib_event
)
3788 delete_breakpoint (b
);
3792 /* JIT breakpoints must be explicitly reset after an exec(). */
3793 if (b
->type
== bp_jit_event
)
3795 delete_breakpoint (b
);
3799 /* Thread event breakpoints must be set anew after an exec(),
3800 as must overlay event and longjmp master breakpoints. */
3801 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3802 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3803 || b
->type
== bp_exception_master
)
3805 delete_breakpoint (b
);
3809 /* Step-resume breakpoints are meaningless after an exec(). */
3810 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3812 delete_breakpoint (b
);
3816 /* Just like single-step breakpoints. */
3817 if (b
->type
== bp_single_step
)
3819 delete_breakpoint (b
);
3823 /* Longjmp and longjmp-resume breakpoints are also meaningless
3825 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3826 || b
->type
== bp_longjmp_call_dummy
3827 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3829 delete_breakpoint (b
);
3833 if (b
->type
== bp_catchpoint
)
3835 /* For now, none of the bp_catchpoint breakpoints need to
3836 do anything at this point. In the future, if some of
3837 the catchpoints need to something, we will need to add
3838 a new method, and call this method from here. */
3842 /* bp_finish is a special case. The only way we ought to be able
3843 to see one of these when an exec() has happened, is if the user
3844 caught a vfork, and then said "finish". Ordinarily a finish just
3845 carries them to the call-site of the current callee, by setting
3846 a temporary bp there and resuming. But in this case, the finish
3847 will carry them entirely through the vfork & exec.
3849 We don't want to allow a bp_finish to remain inserted now. But
3850 we can't safely delete it, 'cause finish_command has a handle to
3851 the bp on a bpstat, and will later want to delete it. There's a
3852 chance (and I've seen it happen) that if we delete the bp_finish
3853 here, that its storage will get reused by the time finish_command
3854 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3855 We really must allow finish_command to delete a bp_finish.
3857 In the absence of a general solution for the "how do we know
3858 it's safe to delete something others may have handles to?"
3859 problem, what we'll do here is just uninsert the bp_finish, and
3860 let finish_command delete it.
3862 (We know the bp_finish is "doomed" in the sense that it's
3863 momentary, and will be deleted as soon as finish_command sees
3864 the inferior stopped. So it doesn't matter that the bp's
3865 address is probably bogus in the new a.out, unlike e.g., the
3866 solib breakpoints.) */
3868 if (b
->type
== bp_finish
)
3873 /* Without a symbolic address, we have little hope of the
3874 pre-exec() address meaning the same thing in the post-exec()
3876 if (breakpoint_location_spec_empty_p (b
))
3878 delete_breakpoint (b
);
3885 detach_breakpoints (ptid_t ptid
)
3888 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3889 struct inferior
*inf
= current_inferior ();
3891 if (ptid
.pid () == inferior_ptid
.pid ())
3892 error (_("Cannot detach breakpoints of inferior_ptid"));
3894 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3895 inferior_ptid
= ptid
;
3896 for (bp_location
*bl
: all_bp_locations ())
3898 if (bl
->pspace
!= inf
->pspace
)
3901 /* This function must physically remove breakpoints locations
3902 from the specified ptid, without modifying the breakpoint
3903 package's state. Locations of type bp_loc_other and
3904 bp_loc_software_watchpoint are only maintained at GDB side,
3905 so there is no need to remove them. Moreover, removing these
3906 would modify the breakpoint package's state. */
3907 if (bl
->loc_type
== bp_loc_other
3908 || bl
->loc_type
== bp_loc_software_watchpoint
)
3912 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3918 /* Remove the breakpoint location BL from the current address space.
3919 Note that this is used to detach breakpoints from a child fork.
3920 When we get here, the child isn't in the inferior list, and neither
3921 do we have objects to represent its address space --- we should
3922 *not* look at bl->pspace->aspace here. */
3925 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3929 /* BL is never in moribund_locations by our callers. */
3930 gdb_assert (bl
->owner
!= NULL
);
3932 /* The type of none suggests that owner is actually deleted.
3933 This should not ever happen. */
3934 gdb_assert (bl
->owner
->type
!= bp_none
);
3936 if (bl
->loc_type
== bp_loc_software_breakpoint
3937 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3939 /* "Normal" instruction breakpoint: either the standard
3940 trap-instruction bp (bp_breakpoint), or a
3941 bp_hardware_breakpoint. */
3943 /* First check to see if we have to handle an overlay. */
3944 if (overlay_debugging
== ovly_off
3945 || bl
->section
== NULL
3946 || !(section_is_overlay (bl
->section
)))
3948 /* No overlay handling: just remove the breakpoint. */
3950 /* If we're trying to uninsert a memory breakpoint that we
3951 know is set in a dynamic object that is marked
3952 shlib_disabled, then either the dynamic object was
3953 removed with "remove-symbol-file" or with
3954 "nosharedlibrary". In the former case, we don't know
3955 whether another dynamic object might have loaded over the
3956 breakpoint's address -- the user might well let us know
3957 about it next with add-symbol-file (the whole point of
3958 add-symbol-file is letting the user manually maintain a
3959 list of dynamically loaded objects). If we have the
3960 breakpoint's shadow memory, that is, this is a software
3961 breakpoint managed by GDB, check whether the breakpoint
3962 is still inserted in memory, to avoid overwriting wrong
3963 code with stale saved shadow contents. Note that HW
3964 breakpoints don't have shadow memory, as they're
3965 implemented using a mechanism that is not dependent on
3966 being able to modify the target's memory, and as such
3967 they should always be removed. */
3968 if (bl
->shlib_disabled
3969 && bl
->target_info
.shadow_len
!= 0
3970 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3973 val
= bl
->owner
->remove_location (bl
, reason
);
3977 /* This breakpoint is in an overlay section.
3978 Did we set a breakpoint at the LMA? */
3979 if (!overlay_events_enabled
)
3981 /* Yes -- overlay event support is not active, so we
3982 should have set a breakpoint at the LMA. Remove it.
3984 /* Ignore any failures: if the LMA is in ROM, we will
3985 have already warned when we failed to insert it. */
3986 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3987 target_remove_hw_breakpoint (bl
->gdbarch
,
3988 &bl
->overlay_target_info
);
3990 target_remove_breakpoint (bl
->gdbarch
,
3991 &bl
->overlay_target_info
,
3994 /* Did we set a breakpoint at the VMA?
3995 If so, we will have marked the breakpoint 'inserted'. */
3998 /* Yes -- remove it. Previously we did not bother to
3999 remove the breakpoint if the section had been
4000 unmapped, but let's not rely on that being safe. We
4001 don't know what the overlay manager might do. */
4003 /* However, we should remove *software* breakpoints only
4004 if the section is still mapped, or else we overwrite
4005 wrong code with the saved shadow contents. */
4006 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4007 || section_is_mapped (bl
->section
))
4008 val
= bl
->owner
->remove_location (bl
, reason
);
4014 /* No -- not inserted, so no need to remove. No error. */
4019 /* In some cases, we might not be able to remove a breakpoint in
4020 a shared library that has already been removed, but we have
4021 not yet processed the shlib unload event. Similarly for an
4022 unloaded add-symbol-file object - the user might not yet have
4023 had the chance to remove-symbol-file it. shlib_disabled will
4024 be set if the library/object has already been removed, but
4025 the breakpoint hasn't been uninserted yet, e.g., after
4026 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4027 always-inserted mode. */
4029 && (bl
->loc_type
== bp_loc_software_breakpoint
4030 && (bl
->shlib_disabled
4031 || solib_name_from_address (bl
->pspace
, bl
->address
)
4032 || shared_objfile_contains_address_p (bl
->pspace
,
4038 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4040 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4042 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4043 bl
->owner
->remove_location (bl
, reason
);
4045 /* Failure to remove any of the hardware watchpoints comes here. */
4046 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4047 warning (_("Could not remove hardware watchpoint %d."),
4050 else if (bl
->owner
->type
== bp_catchpoint
4051 && breakpoint_enabled (bl
->owner
)
4054 val
= bl
->owner
->remove_location (bl
, reason
);
4058 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4065 remove_breakpoint (struct bp_location
*bl
)
4067 /* BL is never in moribund_locations by our callers. */
4068 gdb_assert (bl
->owner
!= NULL
);
4070 /* The type of none suggests that owner is actually deleted.
4071 This should not ever happen. */
4072 gdb_assert (bl
->owner
->type
!= bp_none
);
4074 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4076 switch_to_program_space_and_thread (bl
->pspace
);
4078 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4081 /* Clear the "inserted" flag in all breakpoints. */
4084 mark_breakpoints_out (void)
4086 for (bp_location
*bl
: all_bp_locations ())
4087 if (bl
->pspace
== current_program_space
)
4091 /* Clear the "inserted" flag in all breakpoints and delete any
4092 breakpoints which should go away between runs of the program.
4094 Plus other such housekeeping that has to be done for breakpoints
4097 Note: this function gets called at the end of a run (by
4098 generic_mourn_inferior) and when a run begins (by
4099 init_wait_for_inferior). */
4104 breakpoint_init_inferior (enum inf_context context
)
4106 struct program_space
*pspace
= current_program_space
;
4108 /* If breakpoint locations are shared across processes, then there's
4110 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4113 mark_breakpoints_out ();
4115 for (breakpoint
*b
: all_breakpoints_safe ())
4117 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4123 case bp_longjmp_call_dummy
:
4125 /* If the call dummy breakpoint is at the entry point it will
4126 cause problems when the inferior is rerun, so we better get
4129 case bp_watchpoint_scope
:
4131 /* Also get rid of scope breakpoints. */
4133 case bp_shlib_event
:
4135 /* Also remove solib event breakpoints. Their addresses may
4136 have changed since the last time we ran the program.
4137 Actually we may now be debugging against different target;
4138 and so the solib backend that installed this breakpoint may
4139 not be used in by the target. E.g.,
4141 (gdb) file prog-linux
4142 (gdb) run # native linux target
4145 (gdb) file prog-win.exe
4146 (gdb) tar rem :9999 # remote Windows gdbserver.
4149 case bp_step_resume
:
4151 /* Also remove step-resume breakpoints. */
4153 case bp_single_step
:
4155 /* Also remove single-step breakpoints. */
4157 delete_breakpoint (b
);
4161 case bp_hardware_watchpoint
:
4162 case bp_read_watchpoint
:
4163 case bp_access_watchpoint
:
4165 struct watchpoint
*w
= (struct watchpoint
*) b
;
4167 /* Likewise for watchpoints on local expressions. */
4168 if (w
->exp_valid_block
!= NULL
)
4169 delete_breakpoint (b
);
4172 /* Get rid of existing locations, which are no longer
4173 valid. New ones will be created in
4174 update_watchpoint, when the inferior is restarted.
4175 The next update_global_location_list call will
4176 garbage collect them. */
4179 if (context
== inf_starting
)
4181 /* Reset val field to force reread of starting value in
4182 insert_breakpoints. */
4183 w
->val
.reset (nullptr);
4184 w
->val_valid
= false;
4194 /* Get rid of the moribund locations. */
4195 for (bp_location
*bl
: moribund_locations
)
4196 decref_bp_location (&bl
);
4197 moribund_locations
.clear ();
4200 /* These functions concern about actual breakpoints inserted in the
4201 target --- to e.g. check if we need to do decr_pc adjustment or if
4202 we need to hop over the bkpt --- so we check for address space
4203 match, not program space. */
4205 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4206 exists at PC. It returns ordinary_breakpoint_here if it's an
4207 ordinary breakpoint, or permanent_breakpoint_here if it's a
4208 permanent breakpoint.
4209 - When continuing from a location with an ordinary breakpoint, we
4210 actually single step once before calling insert_breakpoints.
4211 - When continuing from a location with a permanent breakpoint, we
4212 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4213 the target, to advance the PC past the breakpoint. */
4215 enum breakpoint_here
4216 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4218 bool any_breakpoint_here
= false;
4220 for (bp_location
*bl
: all_bp_locations ())
4222 if (bl
->loc_type
!= bp_loc_software_breakpoint
4223 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4226 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4227 if ((breakpoint_enabled (bl
->owner
)
4229 && breakpoint_location_address_match (bl
, aspace
, pc
))
4231 if (overlay_debugging
4232 && section_is_overlay (bl
->section
)
4233 && !section_is_mapped (bl
->section
))
4234 continue; /* unmapped overlay -- can't be a match */
4235 else if (bl
->permanent
)
4236 return permanent_breakpoint_here
;
4238 any_breakpoint_here
= true;
4242 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4245 /* See breakpoint.h. */
4248 breakpoint_in_range_p (const address_space
*aspace
,
4249 CORE_ADDR addr
, ULONGEST len
)
4251 for (bp_location
*bl
: all_bp_locations ())
4253 if (bl
->loc_type
!= bp_loc_software_breakpoint
4254 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4257 if ((breakpoint_enabled (bl
->owner
)
4259 && breakpoint_location_address_range_overlap (bl
, aspace
,
4262 if (overlay_debugging
4263 && section_is_overlay (bl
->section
)
4264 && !section_is_mapped (bl
->section
))
4266 /* Unmapped overlay -- can't be a match. */
4277 /* Return true if there's a moribund breakpoint at PC. */
4280 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4282 for (bp_location
*loc
: moribund_locations
)
4283 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4289 /* Returns true iff BL is inserted at PC, in address space ASPACE. */
4292 bp_location_inserted_here_p (const struct bp_location
*bl
,
4293 const address_space
*aspace
, CORE_ADDR pc
)
4296 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4299 /* An unmapped overlay can't be a match. */
4300 return !(overlay_debugging
4301 && section_is_overlay (bl
->section
)
4302 && !section_is_mapped (bl
->section
));
4307 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4310 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4312 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4314 if (bl
->loc_type
!= bp_loc_software_breakpoint
4315 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4318 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4324 /* This function returns non-zero iff there is a software breakpoint
4328 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4331 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4333 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4336 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4343 /* See breakpoint.h. */
4346 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4349 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4351 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4354 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4362 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4363 CORE_ADDR addr
, ULONGEST len
)
4365 for (breakpoint
*bpt
: all_breakpoints ())
4367 if (bpt
->type
!= bp_hardware_watchpoint
4368 && bpt
->type
!= bp_access_watchpoint
)
4371 if (!breakpoint_enabled (bpt
))
4374 for (bp_location
*loc
: bpt
->locations ())
4375 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4379 /* Check for intersection. */
4380 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4381 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4389 /* See breakpoint.h. */
4392 is_catchpoint (struct breakpoint
*b
)
4394 return (b
->type
== bp_catchpoint
);
4397 /* Clear a bpstat so that it says we are not at any breakpoint.
4398 Also free any storage that is part of a bpstat. */
4401 bpstat_clear (bpstat
**bsp
)
4418 bpstat::bpstat (const bpstat
&other
)
4420 bp_location_at (other
.bp_location_at
),
4421 breakpoint_at (other
.breakpoint_at
),
4422 commands (other
.commands
),
4423 print (other
.print
),
4425 print_it (other
.print_it
)
4427 if (other
.old_val
!= NULL
)
4428 old_val
= release_value (other
.old_val
->copy ());
4431 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4432 is part of the bpstat is copied as well. */
4435 bpstat_copy (bpstat
*bs
)
4437 bpstat
*p
= nullptr;
4439 bpstat
*retval
= nullptr;
4444 for (; bs
!= NULL
; bs
= bs
->next
)
4446 tmp
= new bpstat (*bs
);
4449 /* This is the first thing in the chain. */
4459 /* Find the bpstat associated with this breakpoint. */
4462 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4467 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4469 if (bsp
->breakpoint_at
== breakpoint
)
4475 /* See breakpoint.h. */
4478 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4480 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4482 if (bsp
->breakpoint_at
== NULL
)
4484 /* A moribund location can never explain a signal other than
4486 if (sig
== GDB_SIGNAL_TRAP
)
4491 if (bsp
->breakpoint_at
->explains_signal (sig
))
4499 /* See breakpoint.h. */
4502 bpstat_num (bpstat
**bsp
, int *num
)
4504 struct breakpoint
*b
;
4507 return 0; /* No more breakpoint values */
4509 /* We assume we'll never have several bpstats that correspond to a
4510 single breakpoint -- otherwise, this function might return the
4511 same number more than once and this will look ugly. */
4512 b
= (*bsp
)->breakpoint_at
;
4513 *bsp
= (*bsp
)->next
;
4515 return -1; /* breakpoint that's been deleted since */
4517 *num
= b
->number
; /* We have its number */
4521 /* See breakpoint.h */
4524 bpstat_locno (const bpstat
*bs
)
4526 const struct breakpoint
*b
= bs
->breakpoint_at
;
4527 const struct bp_location
*bl
= bs
->bp_location_at
.get ();
4531 if (b
!= nullptr && b
->loc
!= nullptr && b
->loc
->next
!= nullptr)
4533 const bp_location
*bl_i
;
4536 bl_i
!= bl
&& bl_i
->next
!= nullptr;
4544 warning (_("location number not found for breakpoint %d address %s."),
4545 b
->number
, paddress (bl
->gdbarch
, bl
->address
));
4553 /* See breakpoint.h. */
4556 print_num_locno (const bpstat
*bs
, struct ui_out
*uiout
)
4558 struct breakpoint
*b
= bs
->breakpoint_at
;
4561 uiout
->text (_("deleted breakpoint"));
4564 uiout
->field_signed ("bkptno", b
->number
);
4566 int locno
= bpstat_locno (bs
);
4568 uiout
->message (".%pF", signed_field ("locno", locno
));
4572 /* See breakpoint.h. */
4575 bpstat_clear_actions (void)
4579 if (inferior_ptid
== null_ptid
)
4582 thread_info
*tp
= inferior_thread ();
4583 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4585 bs
->commands
= NULL
;
4586 bs
->old_val
.reset (nullptr);
4590 /* Called when a command is about to proceed the inferior. */
4593 breakpoint_about_to_proceed (void)
4595 if (inferior_ptid
!= null_ptid
)
4597 struct thread_info
*tp
= inferior_thread ();
4599 /* Allow inferior function calls in breakpoint commands to not
4600 interrupt the command list. When the call finishes
4601 successfully, the inferior will be standing at the same
4602 breakpoint as if nothing happened. */
4603 if (tp
->control
.in_infcall
)
4607 breakpoint_proceeded
= 1;
4610 /* Return true iff CMD as the first line of a command sequence is `silent'
4611 or its equivalent. */
4614 command_line_is_silent (struct command_line
*cmd
)
4616 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4619 /* Sets the $_hit_bpnum and $_hit_locno to bpnum and locno.
4620 A locno 0 is changed to 1 to e.g. let the user do
4621 (gdb) disable $_hit_bpnum.$_hit_locno
4622 for a single location breakpoint. */
4625 set_hit_convenience_vars (int bpnum
, int locno
)
4627 set_internalvar_integer (lookup_internalvar ("_hit_bpnum"), bpnum
);
4628 set_internalvar_integer (lookup_internalvar ("_hit_locno"),
4629 (locno
> 0 ? locno
: 1));
4632 /* Execute all the commands associated with all the breakpoints at
4633 this location. Any of these commands could cause the process to
4634 proceed beyond this point, etc. We look out for such changes by
4635 checking the global "breakpoint_proceeded" after each command.
4637 Returns true if a breakpoint command resumed the inferior. In that
4638 case, it is the caller's responsibility to recall it again with the
4639 bpstat of the current thread. */
4642 bpstat_do_actions_1 (bpstat
**bsp
)
4647 /* Avoid endless recursion if a `source' command is contained
4649 if (executing_breakpoint_commands
)
4652 scoped_restore save_executing
4653 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4655 scoped_restore preventer
= prevent_dont_repeat ();
4657 /* This pointer will iterate over the list of bpstat's. */
4660 /* The $_hit_* convenience variables are set before running the
4661 commands of BS. In case we have several bs, after the loop,
4662 we set again the variables to the first printed bpnum and locno.
4663 For multiple breakpoints, this ensures the variables are set to the
4664 breakpoint printed for the user. */
4665 int printed_hit_bpnum
= -1;
4666 int printed_hit_locno
= -1;
4668 breakpoint_proceeded
= 0;
4669 for (; bs
!= NULL
; bs
= bs
->next
)
4671 struct command_line
*cmd
= NULL
;
4673 /* Set the _hit_* convenience variables before running BS's commands. */
4675 const struct breakpoint
*b
= bs
->breakpoint_at
;
4678 int locno
= bpstat_locno (bs
);
4680 set_hit_convenience_vars (b
->number
, locno
);
4681 if (printed_hit_locno
== -1 && bs
->print
)
4683 printed_hit_bpnum
= b
->number
;
4684 printed_hit_locno
= locno
;
4689 /* Take ownership of the BSP's command tree, if it has one.
4691 The command tree could legitimately contain commands like
4692 'step' and 'next', which call clear_proceed_status, which
4693 frees the bpstat BS and its command tree. To make sure this doesn't
4694 free the tree we're executing out from under us, we need to
4695 take ownership of the tree ourselves. Since a given bpstat's
4696 commands are only executed once, we don't need to copy it; we
4697 can clear the pointer in the bpstat, and make sure we free
4698 the tree when we're done. */
4699 counted_command_line ccmd
= bs
->commands
;
4700 bs
->commands
= NULL
;
4703 if (command_line_is_silent (cmd
))
4705 /* The action has been already done by bpstat_stop_status. */
4711 execute_control_command (cmd
);
4712 /* After execute_control_command, if breakpoint_proceeded is true,
4713 BS has been freed and cannot be accessed anymore. */
4715 if (breakpoint_proceeded
)
4721 if (breakpoint_proceeded
)
4723 if (current_ui
->async
)
4724 /* If we are in async mode, then the target might be still
4725 running, not stopped at any breakpoint, so nothing for
4726 us to do here -- just return to the event loop. */
4729 /* In sync mode, when execute_control_command returns
4730 we're already standing on the next breakpoint.
4731 Breakpoint commands for that stop were not run, since
4732 execute_command does not run breakpoint commands --
4733 only command_line_handler does, but that one is not
4734 involved in execution of breakpoint commands. So, we
4735 can now execute breakpoint commands. It should be
4736 noted that making execute_command do bpstat actions is
4737 not an option -- in this case we'll have recursive
4738 invocation of bpstat for each breakpoint with a
4739 command, and can easily blow up GDB stack. Instead, we
4740 return true, which will trigger the caller to recall us
4741 with the new stop_bpstat. */
4747 /* Now that we have executed the commands of all bs, set the _hit_*
4748 convenience variables to the printed values. */
4749 if (printed_hit_locno
!= -1)
4750 set_hit_convenience_vars (printed_hit_bpnum
, printed_hit_locno
);
4755 /* Helper for bpstat_do_actions. Get the current thread, if there's
4756 one, is alive and has execution. Return NULL otherwise. */
4758 static thread_info
*
4759 get_bpstat_thread ()
4761 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4764 thread_info
*tp
= inferior_thread ();
4765 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4771 bpstat_do_actions (void)
4773 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4776 /* Do any commands attached to breakpoint we are stopped at. */
4777 while ((tp
= get_bpstat_thread ()) != NULL
)
4779 /* Since in sync mode, bpstat_do_actions may resume the
4780 inferior, and only return when it is stopped at the next
4781 breakpoint, we keep doing breakpoint actions until it returns
4782 false to indicate the inferior was not resumed. */
4783 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4787 cleanup_if_error
.release ();
4790 /* Print out the (old or new) value associated with a watchpoint. */
4793 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4796 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4799 struct value_print_options opts
;
4800 get_user_print_options (&opts
);
4801 value_print (val
, stream
, &opts
);
4805 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4806 debugging multiple threads. */
4809 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4811 if (uiout
->is_mi_like_p ())
4816 if (show_thread_that_caused_stop ())
4818 struct thread_info
*thr
= inferior_thread ();
4820 uiout
->text ("Thread ");
4821 uiout
->field_string ("thread-id", print_thread_id (thr
));
4823 const char *name
= thread_name (thr
);
4826 uiout
->text (" \"");
4827 uiout
->field_string ("name", name
);
4831 uiout
->text (" hit ");
4835 /* Generic routine for printing messages indicating why we
4836 stopped. The behavior of this function depends on the value
4837 'print_it' in the bpstat structure. Under some circumstances we
4838 may decide not to print anything here and delegate the task to
4841 static enum print_stop_action
4842 print_bp_stop_message (bpstat
*bs
)
4844 switch (bs
->print_it
)
4847 /* Nothing should be printed for this bpstat entry. */
4848 return PRINT_UNKNOWN
;
4852 /* We still want to print the frame, but we already printed the
4853 relevant messages. */
4854 return PRINT_SRC_AND_LOC
;
4857 case print_it_normal
:
4859 struct breakpoint
*b
= bs
->breakpoint_at
;
4861 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4862 which has since been deleted. */
4864 return PRINT_UNKNOWN
;
4866 /* Normal case. Call the breakpoint's print_it method. */
4867 return b
->print_it (bs
);
4872 internal_error (_("print_bp_stop_message: unrecognized enum value"));
4877 /* See breakpoint.h. */
4880 print_solib_event (bool is_catchpoint
)
4882 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4883 bool any_added
= !current_program_space
->added_solibs
.empty ();
4887 if (any_added
|| any_deleted
)
4888 current_uiout
->text (_("Stopped due to shared library event:\n"));
4890 current_uiout
->text (_("Stopped due to shared library event (no "
4891 "libraries added or removed)\n"));
4894 if (current_uiout
->is_mi_like_p ())
4895 current_uiout
->field_string ("reason",
4896 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4900 current_uiout
->text (_(" Inferior unloaded "));
4901 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4902 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4904 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4907 current_uiout
->text (" ");
4908 current_uiout
->field_string ("library", name
);
4909 current_uiout
->text ("\n");
4915 current_uiout
->text (_(" Inferior loaded "));
4916 ui_out_emit_list
list_emitter (current_uiout
, "added");
4918 for (so_list
*iter
: current_program_space
->added_solibs
)
4921 current_uiout
->text (" ");
4923 current_uiout
->field_string ("library", iter
->so_name
);
4924 current_uiout
->text ("\n");
4929 /* Print a message indicating what happened. This is called from
4930 normal_stop(). The input to this routine is the head of the bpstat
4931 list - a list of the eventpoints that caused this stop. KIND is
4932 the target_waitkind for the stopping event. This
4933 routine calls the generic print routine for printing a message
4934 about reasons for stopping. This will print (for example) the
4935 "Breakpoint n," part of the output. The return value of this
4938 PRINT_UNKNOWN: Means we printed nothing.
4939 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4940 code to print the location. An example is
4941 "Breakpoint 1, " which should be followed by
4943 PRINT_SRC_ONLY: Means we printed something, but there is no need
4944 to also print the location part of the message.
4945 An example is the catch/throw messages, which
4946 don't require a location appended to the end.
4947 PRINT_NOTHING: We have done some printing and we don't need any
4948 further info to be printed. */
4950 enum print_stop_action
4951 bpstat_print (bpstat
*bs
, target_waitkind kind
)
4953 enum print_stop_action val
;
4955 /* Maybe another breakpoint in the chain caused us to stop.
4956 (Currently all watchpoints go on the bpstat whether hit or not.
4957 That probably could (should) be changed, provided care is taken
4958 with respect to bpstat_explains_signal). */
4959 for (; bs
; bs
= bs
->next
)
4961 val
= print_bp_stop_message (bs
);
4962 if (val
== PRINT_SRC_ONLY
4963 || val
== PRINT_SRC_AND_LOC
4964 || val
== PRINT_NOTHING
)
4968 /* If we had hit a shared library event breakpoint,
4969 print_bp_stop_message would print out this message. If we hit an
4970 OS-level shared library event, do the same thing. */
4971 if (kind
== TARGET_WAITKIND_LOADED
)
4973 print_solib_event (false);
4974 return PRINT_NOTHING
;
4977 /* We reached the end of the chain, or we got a null BS to start
4978 with and nothing was printed. */
4979 return PRINT_UNKNOWN
;
4982 /* Evaluate the boolean expression EXP and return the result. */
4985 breakpoint_cond_eval (expression
*exp
)
4987 scoped_value_mark mark
;
4988 return value_true (exp
->evaluate ());
4991 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4993 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4995 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4996 breakpoint_at (bl
->owner
),
5000 print_it (print_it_normal
)
5002 **bs_link_pointer
= this;
5003 *bs_link_pointer
= &next
;
5008 breakpoint_at (NULL
),
5012 print_it (print_it_normal
)
5016 /* The target has stopped with waitstatus WS. Check if any hardware
5017 watchpoints have triggered, according to the target. */
5020 watchpoints_triggered (const target_waitstatus
&ws
)
5022 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5025 if (!stopped_by_watchpoint
)
5027 /* We were not stopped by a watchpoint. Mark all watchpoints
5028 as not triggered. */
5029 for (breakpoint
*b
: all_breakpoints ())
5030 if (is_hardware_watchpoint (b
))
5032 struct watchpoint
*w
= (struct watchpoint
*) b
;
5034 w
->watchpoint_triggered
= watch_triggered_no
;
5040 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
5042 /* We were stopped by a watchpoint, but we don't know where.
5043 Mark all watchpoints as unknown. */
5044 for (breakpoint
*b
: all_breakpoints ())
5045 if (is_hardware_watchpoint (b
))
5047 struct watchpoint
*w
= (struct watchpoint
*) b
;
5049 w
->watchpoint_triggered
= watch_triggered_unknown
;
5055 /* The target could report the data address. Mark watchpoints
5056 affected by this data address as triggered, and all others as not
5059 for (breakpoint
*b
: all_breakpoints ())
5060 if (is_hardware_watchpoint (b
))
5062 struct watchpoint
*w
= (struct watchpoint
*) b
;
5064 w
->watchpoint_triggered
= watch_triggered_no
;
5065 for (bp_location
*loc
: b
->locations ())
5067 if (is_masked_watchpoint (b
))
5069 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5070 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5072 if (newaddr
== start
)
5074 w
->watchpoint_triggered
= watch_triggered_yes
;
5078 /* Exact match not required. Within range is sufficient. */
5079 else if (target_watchpoint_addr_within_range
5080 (current_inferior ()->top_target (), addr
, loc
->address
,
5083 w
->watchpoint_triggered
= watch_triggered_yes
;
5092 /* Possible return values for watchpoint_check. */
5093 enum wp_check_result
5095 /* The watchpoint has been deleted. */
5098 /* The value has changed. */
5099 WP_VALUE_CHANGED
= 2,
5101 /* The value has not changed. */
5102 WP_VALUE_NOT_CHANGED
= 3,
5104 /* Ignore this watchpoint, no matter if the value changed or not. */
5108 #define BP_TEMPFLAG 1
5109 #define BP_HARDWAREFLAG 2
5111 /* Evaluate watchpoint condition expression and check if its value
5114 static wp_check_result
5115 watchpoint_check (bpstat
*bs
)
5117 struct watchpoint
*b
;
5119 bool within_current_scope
;
5121 /* BS is built from an existing struct breakpoint. */
5122 gdb_assert (bs
->breakpoint_at
!= NULL
);
5123 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5125 /* If this is a local watchpoint, we only want to check if the
5126 watchpoint frame is in scope if the current thread is the thread
5127 that was used to create the watchpoint. */
5128 if (!watchpoint_in_thread_scope (b
))
5131 if (b
->exp_valid_block
== NULL
)
5132 within_current_scope
= true;
5135 frame_info_ptr frame
= get_current_frame ();
5136 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5137 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5139 /* stack_frame_destroyed_p() returns a non-zero value if we're
5140 still in the function but the stack frame has already been
5141 invalidated. Since we can't rely on the values of local
5142 variables after the stack has been destroyed, we are treating
5143 the watchpoint in that state as `not changed' without further
5144 checking. Don't mark watchpoints as changed if the current
5145 frame is in an epilogue - even if they are in some other
5146 frame, our view of the stack is likely to be wrong and
5147 frame_find_by_id could error out. */
5148 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5151 fr
= frame_find_by_id (b
->watchpoint_frame
);
5152 within_current_scope
= (fr
!= NULL
);
5154 /* If we've gotten confused in the unwinder, we might have
5155 returned a frame that can't describe this variable. */
5156 if (within_current_scope
)
5158 struct symbol
*function
;
5160 function
= get_frame_function (fr
);
5161 if (function
== NULL
5162 || !function
->value_block ()->contains (b
->exp_valid_block
))
5163 within_current_scope
= false;
5166 if (within_current_scope
)
5167 /* If we end up stopping, the current frame will get selected
5168 in normal_stop. So this call to select_frame won't affect
5173 if (within_current_scope
)
5175 /* We use value_{,free_to_}mark because it could be a *long*
5176 time before we return to the command level and call
5177 free_all_values. We can't call free_all_values because we
5178 might be in the middle of evaluating a function call. */
5181 struct value
*new_val
;
5183 if (is_masked_watchpoint (b
))
5184 /* Since we don't know the exact trigger address (from
5185 stopped_data_address), just tell the user we've triggered
5186 a mask watchpoint. */
5187 return WP_VALUE_CHANGED
;
5189 mark
= value_mark ();
5190 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5193 if (b
->val_bitsize
!= 0)
5194 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5196 /* We use value_equal_contents instead of value_equal because
5197 the latter coerces an array to a pointer, thus comparing just
5198 the address of the array instead of its contents. This is
5199 not what we want. */
5200 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5201 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5204 bs
->old_val
= b
->val
;
5205 b
->val
= release_value (new_val
);
5206 b
->val_valid
= true;
5207 if (new_val
!= NULL
)
5208 value_free_to_mark (mark
);
5209 return WP_VALUE_CHANGED
;
5213 /* Nothing changed. */
5214 value_free_to_mark (mark
);
5215 return WP_VALUE_NOT_CHANGED
;
5220 /* This seems like the only logical thing to do because
5221 if we temporarily ignored the watchpoint, then when
5222 we reenter the block in which it is valid it contains
5223 garbage (in the case of a function, it may have two
5224 garbage values, one before and one after the prologue).
5225 So we can't even detect the first assignment to it and
5226 watch after that (since the garbage may or may not equal
5227 the first value assigned). */
5228 /* We print all the stop information in
5229 breakpointprint_it, but in this case, by the time we
5230 call breakpoint->print_it this bp will be deleted
5231 already. So we have no choice but print the information
5234 SWITCH_THRU_ALL_UIS ()
5236 struct ui_out
*uiout
= current_uiout
;
5238 if (uiout
->is_mi_like_p ())
5240 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5241 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5242 "left the block in\n"
5243 "which its expression is valid.\n",
5244 signed_field ("wpnum", b
->number
));
5247 /* Make sure the watchpoint's commands aren't executed. */
5249 watchpoint_del_at_next_stop (b
);
5255 /* Return true if it looks like target has stopped due to hitting
5256 breakpoint location BL. This function does not check if we should
5257 stop, only if BL explains the stop. */
5260 bpstat_check_location (const struct bp_location
*bl
,
5261 const address_space
*aspace
, CORE_ADDR bp_addr
,
5262 const target_waitstatus
&ws
)
5264 struct breakpoint
*b
= bl
->owner
;
5266 /* BL is from an existing breakpoint. */
5267 gdb_assert (b
!= NULL
);
5269 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5272 /* Determine if the watched values have actually changed, and we
5273 should stop. If not, set BS->stop to false. */
5276 bpstat_check_watchpoint (bpstat
*bs
)
5278 const struct bp_location
*bl
;
5279 struct watchpoint
*b
;
5281 /* BS is built for existing struct breakpoint. */
5282 bl
= bs
->bp_location_at
.get ();
5283 gdb_assert (bl
!= NULL
);
5284 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5285 gdb_assert (b
!= NULL
);
5288 bool must_check_value
= false;
5290 if (b
->type
== bp_watchpoint
)
5291 /* For a software watchpoint, we must always check the
5293 must_check_value
= true;
5294 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5295 /* We have a hardware watchpoint (read, write, or access)
5296 and the target earlier reported an address watched by
5298 must_check_value
= true;
5299 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5300 && b
->type
== bp_hardware_watchpoint
)
5301 /* We were stopped by a hardware watchpoint, but the target could
5302 not report the data address. We must check the watchpoint's
5303 value. Access and read watchpoints are out of luck; without
5304 a data address, we can't figure it out. */
5305 must_check_value
= true;
5307 if (must_check_value
)
5313 e
= watchpoint_check (bs
);
5315 catch (const gdb_exception_error
&ex
)
5317 exception_fprintf (gdb_stderr
, ex
,
5318 "Error evaluating expression "
5319 "for watchpoint %d\n",
5322 SWITCH_THRU_ALL_UIS ()
5324 gdb_printf (_("Watchpoint %d deleted.\n"),
5327 watchpoint_del_at_next_stop (b
);
5334 /* We've already printed what needs to be printed. */
5335 bs
->print_it
= print_it_done
;
5339 bs
->print_it
= print_it_noop
;
5342 case WP_VALUE_CHANGED
:
5343 if (b
->type
== bp_read_watchpoint
)
5345 /* There are two cases to consider here:
5347 1. We're watching the triggered memory for reads.
5348 In that case, trust the target, and always report
5349 the watchpoint hit to the user. Even though
5350 reads don't cause value changes, the value may
5351 have changed since the last time it was read, and
5352 since we're not trapping writes, we will not see
5353 those, and as such we should ignore our notion of
5356 2. We're watching the triggered memory for both
5357 reads and writes. There are two ways this may
5360 2.1. This is a target that can't break on data
5361 reads only, but can break on accesses (reads or
5362 writes), such as e.g., x86. We detect this case
5363 at the time we try to insert read watchpoints.
5365 2.2. Otherwise, the target supports read
5366 watchpoints, but, the user set an access or write
5367 watchpoint watching the same memory as this read
5370 If we're watching memory writes as well as reads,
5371 ignore watchpoint hits when we find that the
5372 value hasn't changed, as reads don't cause
5373 changes. This still gives false positives when
5374 the program writes the same value to memory as
5375 what there was already in memory (we will confuse
5376 it for a read), but it's much better than
5379 int other_write_watchpoint
= 0;
5381 if (bl
->watchpoint_type
== hw_read
)
5383 for (breakpoint
*other_b
: all_breakpoints ())
5384 if (other_b
->type
== bp_hardware_watchpoint
5385 || other_b
->type
== bp_access_watchpoint
)
5387 struct watchpoint
*other_w
=
5388 (struct watchpoint
*) other_b
;
5390 if (other_w
->watchpoint_triggered
5391 == watch_triggered_yes
)
5393 other_write_watchpoint
= 1;
5399 if (other_write_watchpoint
5400 || bl
->watchpoint_type
== hw_access
)
5402 /* We're watching the same memory for writes,
5403 and the value changed since the last time we
5404 updated it, so this trap must be for a write.
5406 bs
->print_it
= print_it_noop
;
5411 case WP_VALUE_NOT_CHANGED
:
5412 if (b
->type
== bp_hardware_watchpoint
5413 || b
->type
== bp_watchpoint
)
5415 /* Don't stop: write watchpoints shouldn't fire if
5416 the value hasn't changed. */
5417 bs
->print_it
= print_it_noop
;
5427 else /* !must_check_value */
5429 /* This is a case where some watchpoint(s) triggered, but
5430 not at the address of this watchpoint, or else no
5431 watchpoint triggered after all. So don't print
5432 anything for this watchpoint. */
5433 bs
->print_it
= print_it_noop
;
5439 /* For breakpoints that are currently marked as telling gdb to stop,
5440 check conditions (condition proper, frame, thread and ignore count)
5441 of breakpoint referred to by BS. If we should not stop for this
5442 breakpoint, set BS->stop to 0. */
5445 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5447 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
5449 const struct bp_location
*bl
;
5450 struct breakpoint
*b
;
5452 bool condition_result
= true;
5453 struct expression
*cond
;
5455 gdb_assert (bs
->stop
);
5457 /* BS is built for existing struct breakpoint. */
5458 bl
= bs
->bp_location_at
.get ();
5459 gdb_assert (bl
!= NULL
);
5460 b
= bs
->breakpoint_at
;
5461 gdb_assert (b
!= NULL
);
5463 infrun_debug_printf ("thread = %s, breakpoint %d.%d",
5464 thread
->ptid
.to_string ().c_str (),
5465 b
->number
, find_loc_num_by_location (bl
));
5467 /* Even if the target evaluated the condition on its end and notified GDB, we
5468 need to do so again since GDB does not know if we stopped due to a
5469 breakpoint or a single step breakpoint. */
5471 if (frame_id_p (b
->frame_id
)
5472 && b
->frame_id
!= get_stack_frame_id (get_current_frame ()))
5474 infrun_debug_printf ("incorrect frame %s not %s, not stopping",
5475 get_stack_frame_id (get_current_frame ()).to_string ().c_str (),
5476 b
->frame_id
.to_string ().c_str ());
5481 /* If this is a thread/task-specific breakpoint, don't waste cpu
5482 evaluating the condition if this isn't the specified
5484 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5485 || (b
->task
!= -1 && b
->task
!= ada_get_task_number (thread
)))
5487 infrun_debug_printf ("incorrect thread or task, not stopping");
5492 /* Evaluate extension language breakpoints that have a "stop" method
5494 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5496 if (is_watchpoint (b
))
5498 struct watchpoint
*w
= (struct watchpoint
*) b
;
5500 cond
= w
->cond_exp
.get ();
5503 cond
= bl
->cond
.get ();
5505 if (cond
!= nullptr && b
->disposition
!= disp_del_at_next_stop
)
5507 bool within_current_scope
= true;
5508 struct watchpoint
* w
;
5510 /* We use scoped_value_mark because it could be a long time
5511 before we return to the command level and call
5512 free_all_values. We can't call free_all_values because we
5513 might be in the middle of evaluating a function call. */
5514 scoped_value_mark mark
;
5516 if (is_watchpoint (b
))
5517 w
= (struct watchpoint
*) b
;
5521 /* Need to select the frame, with all that implies so that
5522 the conditions will have the right context. Because we
5523 use the frame, we will not see an inlined function's
5524 variables when we arrive at a breakpoint at the start
5525 of the inlined function; the current frame will be the
5527 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5528 select_frame (get_current_frame ());
5531 frame_info_ptr frame
;
5533 /* For local watchpoint expressions, which particular
5534 instance of a local is being watched matters, so we
5535 keep track of the frame to evaluate the expression
5536 in. To evaluate the condition however, it doesn't
5537 really matter which instantiation of the function
5538 where the condition makes sense triggers the
5539 watchpoint. This allows an expression like "watch
5540 global if q > 10" set in `func', catch writes to
5541 global on all threads that call `func', or catch
5542 writes on all recursive calls of `func' by a single
5543 thread. We simply always evaluate the condition in
5544 the innermost frame that's executing where it makes
5545 sense to evaluate the condition. It seems
5547 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5549 select_frame (frame
);
5551 within_current_scope
= false;
5553 CORE_ADDR pc_before_check
= get_frame_pc (get_selected_frame (nullptr));
5554 if (within_current_scope
)
5558 condition_result
= breakpoint_cond_eval (cond
);
5560 catch (const gdb_exception_error
&ex
)
5562 exception_fprintf (gdb_stderr
, ex
,
5563 "Error in testing condition for breakpoint %d:\n",
5566 /* If the pc value changed as a result of evaluating the
5567 condition then we probably stopped within an inferior
5568 function call due to some unexpected stop, e.g. the thread
5569 hit another breakpoint, or the thread received an
5570 unexpected signal. In this case we don't want to also
5571 print the information about this breakpoint. */
5572 CORE_ADDR pc_after_check
5573 = get_frame_pc (get_selected_frame (nullptr));
5574 if (pc_before_check
!= pc_after_check
)
5580 warning (_("Watchpoint condition cannot be tested "
5581 "in the current scope"));
5582 /* If we failed to set the right context for this
5583 watchpoint, unconditionally report it. */
5585 /* FIXME-someday, should give breakpoint #. */
5588 if (cond
!= nullptr && !condition_result
)
5590 infrun_debug_printf ("condition_result = false, not stopping");
5594 else if (b
->ignore_count
> 0)
5596 infrun_debug_printf ("ignore count %d, not stopping",
5600 /* Increase the hit count even though we don't stop. */
5602 gdb::observers::breakpoint_modified
.notify (b
);
5607 infrun_debug_printf ("stopping at this breakpoint");
5609 infrun_debug_printf ("not stopping at this breakpoint");
5612 /* Returns true if we need to track moribund locations of LOC's type
5613 on the current target. */
5616 need_moribund_for_location_type (const struct bp_location
*loc
)
5618 return ((loc
->loc_type
== bp_loc_software_breakpoint
5619 && !target_supports_stopped_by_sw_breakpoint ())
5620 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5621 && !target_supports_stopped_by_hw_breakpoint ()));
5624 /* See breakpoint.h. */
5627 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5628 const target_waitstatus
&ws
)
5630 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5632 for (breakpoint
*b
: all_breakpoints ())
5634 if (!breakpoint_enabled (b
))
5637 for (bp_location
*bl
: b
->locations ())
5639 /* For hardware watchpoints, we look only at the first
5640 location. The watchpoint_check function will work on the
5641 entire expression, not the individual locations. For
5642 read watchpoints, the watchpoints_triggered function has
5643 checked all locations already. */
5644 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5647 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5650 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5653 /* Come here if it's a watchpoint, or if the break address
5656 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5659 /* Assume we stop. Should we find a watchpoint that is not
5660 actually triggered, or if the condition of the breakpoint
5661 evaluates as false, we'll reset 'stop' to 0. */
5665 /* If this is a scope breakpoint, mark the associated
5666 watchpoint as triggered so that we will handle the
5667 out-of-scope event. We'll get to the watchpoint next
5669 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5671 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5673 w
->watchpoint_triggered
= watch_triggered_yes
;
5678 /* Check if a moribund breakpoint explains the stop. */
5679 if (!target_supports_stopped_by_sw_breakpoint ()
5680 || !target_supports_stopped_by_hw_breakpoint ())
5682 for (bp_location
*loc
: moribund_locations
)
5684 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5685 && need_moribund_for_location_type (loc
))
5687 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5688 /* For hits of moribund locations, we should just proceed. */
5691 bs
->print_it
= print_it_noop
;
5699 /* See breakpoint.h. */
5702 bpstat_stop_status (const address_space
*aspace
,
5703 CORE_ADDR bp_addr
, thread_info
*thread
,
5704 const target_waitstatus
&ws
,
5707 struct breakpoint
*b
= NULL
;
5708 /* First item of allocated bpstat's. */
5709 bpstat
*bs_head
= stop_chain
;
5711 int need_remove_insert
;
5714 /* First, build the bpstat chain with locations that explain a
5715 target stop, while being careful to not set the target running,
5716 as that may invalidate locations (in particular watchpoint
5717 locations are recreated). Resuming will happen here with
5718 breakpoint conditions or watchpoint expressions that include
5719 inferior function calls. */
5720 if (bs_head
== NULL
)
5721 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5723 /* A bit of special processing for shlib breakpoints. We need to
5724 process solib loading here, so that the lists of loaded and
5725 unloaded libraries are correct before we handle "catch load" and
5727 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5729 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5731 handle_solib_event ();
5736 /* Now go through the locations that caused the target to stop, and
5737 check whether we're interested in reporting this stop to higher
5738 layers, or whether we should resume the target transparently. */
5742 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5747 b
= bs
->breakpoint_at
;
5748 b
->check_status (bs
);
5751 bpstat_check_breakpoint_conditions (bs
, thread
);
5757 /* We will stop here. */
5758 if (b
->disposition
== disp_disable
)
5760 --(b
->enable_count
);
5761 if (b
->enable_count
<= 0)
5762 b
->enable_state
= bp_disabled
;
5765 gdb::observers::breakpoint_modified
.notify (b
);
5768 bs
->commands
= b
->commands
;
5769 if (command_line_is_silent (bs
->commands
5770 ? bs
->commands
.get () : NULL
))
5773 b
->after_condition_true (bs
);
5778 /* Print nothing for this entry if we don't stop or don't
5780 if (!bs
->stop
|| !bs
->print
)
5781 bs
->print_it
= print_it_noop
;
5784 /* If we aren't stopping, the value of some hardware watchpoint may
5785 not have changed, but the intermediate memory locations we are
5786 watching may have. Don't bother if we're stopping; this will get
5788 need_remove_insert
= 0;
5789 if (! bpstat_causes_stop (bs_head
))
5790 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5792 && bs
->breakpoint_at
5793 && is_hardware_watchpoint (bs
->breakpoint_at
))
5795 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5797 update_watchpoint (w
, false /* don't reparse. */);
5798 need_remove_insert
= 1;
5801 if (need_remove_insert
)
5802 update_global_location_list (UGLL_MAY_INSERT
);
5803 else if (removed_any
)
5804 update_global_location_list (UGLL_DONT_INSERT
);
5809 /* See breakpoint.h. */
5812 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5813 thread_info
*thread
, const target_waitstatus
&ws
)
5815 gdb_assert (!target_stopped_by_watchpoint ());
5817 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5818 previous stop to avoid confusing bpstat_stop_status. */
5819 watchpoints_triggered (ws
);
5821 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5825 handle_jit_event (CORE_ADDR address
)
5827 struct gdbarch
*gdbarch
;
5829 infrun_debug_printf ("handling bp_jit_event");
5831 /* Switch terminal for any messages produced by
5832 breakpoint_re_set. */
5833 target_terminal::ours_for_output ();
5835 gdbarch
= get_frame_arch (get_current_frame ());
5836 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5837 thus it is expected that its objectfile can be found through
5838 minimal symbol lookup. If it doesn't work (and assert fails), it
5839 most likely means that `jit_breakpoint_re_set` was changes and this
5840 function needs to be updated too. */
5841 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5842 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5843 objfile
*objfile
= jit_bp_sym
.objfile
;
5844 if (objfile
->separate_debug_objfile_backlink
)
5845 objfile
= objfile
->separate_debug_objfile_backlink
;
5846 jit_event_handler (gdbarch
, objfile
);
5848 target_terminal::inferior ();
5851 /* Prepare WHAT final decision for infrun. */
5853 /* Decide what infrun needs to do with this bpstat. */
5856 bpstat_what (bpstat
*bs_head
)
5858 struct bpstat_what retval
;
5861 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5862 retval
.call_dummy
= STOP_NONE
;
5863 retval
.is_longjmp
= false;
5865 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5867 /* Extract this BS's action. After processing each BS, we check
5868 if its action overrides all we've seem so far. */
5869 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5872 if (bs
->breakpoint_at
== NULL
)
5874 /* I suspect this can happen if it was a momentary
5875 breakpoint which has since been deleted. */
5879 bptype
= bs
->breakpoint_at
->type
;
5886 case bp_hardware_breakpoint
:
5887 case bp_single_step
:
5890 case bp_shlib_event
:
5894 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5896 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5899 this_action
= BPSTAT_WHAT_SINGLE
;
5902 case bp_hardware_watchpoint
:
5903 case bp_read_watchpoint
:
5904 case bp_access_watchpoint
:
5908 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5910 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5914 /* There was a watchpoint, but we're not stopping.
5915 This requires no further action. */
5919 case bp_longjmp_call_dummy
:
5923 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5924 retval
.is_longjmp
= bptype
!= bp_exception
;
5927 this_action
= BPSTAT_WHAT_SINGLE
;
5929 case bp_longjmp_resume
:
5930 case bp_exception_resume
:
5933 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5934 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5937 this_action
= BPSTAT_WHAT_SINGLE
;
5939 case bp_step_resume
:
5941 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5944 /* It is for the wrong frame. */
5945 this_action
= BPSTAT_WHAT_SINGLE
;
5948 case bp_hp_step_resume
:
5950 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5953 /* It is for the wrong frame. */
5954 this_action
= BPSTAT_WHAT_SINGLE
;
5957 case bp_watchpoint_scope
:
5958 case bp_thread_event
:
5959 case bp_overlay_event
:
5960 case bp_longjmp_master
:
5961 case bp_std_terminate_master
:
5962 case bp_exception_master
:
5963 this_action
= BPSTAT_WHAT_SINGLE
;
5969 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5971 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5975 /* Some catchpoints are implemented with breakpoints.
5976 For those, we need to step over the breakpoint. */
5977 if (bs
->bp_location_at
->loc_type
== bp_loc_software_breakpoint
5978 || bs
->bp_location_at
->loc_type
== bp_loc_hardware_breakpoint
)
5979 this_action
= BPSTAT_WHAT_SINGLE
;
5983 this_action
= BPSTAT_WHAT_SINGLE
;
5986 /* Make sure the action is stop (silent or noisy),
5987 so infrun.c pops the dummy frame. */
5988 retval
.call_dummy
= STOP_STACK_DUMMY
;
5989 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5991 case bp_std_terminate
:
5992 /* Make sure the action is stop (silent or noisy),
5993 so infrun.c pops the dummy frame. */
5994 retval
.call_dummy
= STOP_STD_TERMINATE
;
5995 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5998 case bp_fast_tracepoint
:
5999 case bp_static_tracepoint
:
6000 case bp_static_marker_tracepoint
:
6001 /* Tracepoint hits should not be reported back to GDB, and
6002 if one got through somehow, it should have been filtered
6004 internal_error (_("bpstat_what: tracepoint encountered"));
6006 case bp_gnu_ifunc_resolver
:
6007 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
6008 this_action
= BPSTAT_WHAT_SINGLE
;
6010 case bp_gnu_ifunc_resolver_return
:
6011 /* The breakpoint will be removed, execution will restart from the
6012 PC of the former breakpoint. */
6013 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
6018 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6020 this_action
= BPSTAT_WHAT_SINGLE
;
6024 internal_error (_("bpstat_what: unhandled bptype %d"), (int) bptype
);
6027 retval
.main_action
= std::max (retval
.main_action
, this_action
);
6034 bpstat_run_callbacks (bpstat
*bs_head
)
6038 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6040 struct breakpoint
*b
= bs
->breakpoint_at
;
6047 handle_jit_event (bs
->bp_location_at
->address
);
6049 case bp_gnu_ifunc_resolver
:
6050 gnu_ifunc_resolver_stop ((code_breakpoint
*) b
);
6052 case bp_gnu_ifunc_resolver_return
:
6053 gnu_ifunc_resolver_return_stop ((code_breakpoint
*) b
);
6059 /* See breakpoint.h. */
6062 bpstat_should_step ()
6064 for (breakpoint
*b
: all_breakpoints ())
6065 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6071 /* See breakpoint.h. */
6074 bpstat_causes_stop (bpstat
*bs
)
6076 for (; bs
!= NULL
; bs
= bs
->next
)
6085 /* Compute a number of spaces suitable to indent the next line
6086 so it starts at the position corresponding to the table column
6087 named COL_NAME in the currently active table of UIOUT. */
6090 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6092 int i
, total_width
, width
, align
;
6096 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6098 if (strcmp (text
, col_name
) == 0)
6101 total_width
+= width
+ 1;
6107 /* Determine if the locations of this breakpoint will have their conditions
6108 evaluated by the target, host or a mix of both. Returns the following:
6110 "host": Host evals condition.
6111 "host or target": Host or Target evals condition.
6112 "target": Target evals condition.
6116 bp_condition_evaluator (const breakpoint
*b
)
6118 char host_evals
= 0;
6119 char target_evals
= 0;
6124 if (!is_breakpoint (b
))
6127 if (gdb_evaluates_breakpoint_condition_p ()
6128 || !target_supports_evaluation_of_breakpoint_conditions ())
6129 return condition_evaluation_host
;
6131 for (bp_location
*bl
: b
->locations ())
6133 if (bl
->cond_bytecode
)
6139 if (host_evals
&& target_evals
)
6140 return condition_evaluation_both
;
6141 else if (target_evals
)
6142 return condition_evaluation_target
;
6144 return condition_evaluation_host
;
6147 /* Determine the breakpoint location's condition evaluator. This is
6148 similar to bp_condition_evaluator, but for locations. */
6151 bp_location_condition_evaluator (const struct bp_location
*bl
)
6153 if (bl
&& !is_breakpoint (bl
->owner
))
6156 if (gdb_evaluates_breakpoint_condition_p ()
6157 || !target_supports_evaluation_of_breakpoint_conditions ())
6158 return condition_evaluation_host
;
6160 if (bl
&& bl
->cond_bytecode
)
6161 return condition_evaluation_target
;
6163 return condition_evaluation_host
;
6166 /* Print the LOC location out of the list of B->LOC locations. */
6169 print_breakpoint_location (const breakpoint
*b
,
6170 struct bp_location
*loc
)
6172 struct ui_out
*uiout
= current_uiout
;
6174 scoped_restore_current_program_space restore_pspace
;
6176 if (loc
!= NULL
&& loc
->shlib_disabled
)
6180 set_current_program_space (loc
->pspace
);
6182 if (b
->display_canonical
)
6183 uiout
->field_string ("what", b
->locspec
->to_string ());
6184 else if (loc
&& loc
->symtab
)
6186 const struct symbol
*sym
= loc
->symbol
;
6190 uiout
->text ("in ");
6191 uiout
->field_string ("func", sym
->print_name (),
6192 function_name_style
.style ());
6194 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6195 uiout
->text ("at ");
6197 uiout
->field_string ("file",
6198 symtab_to_filename_for_display (loc
->symtab
),
6199 file_name_style
.style ());
6202 if (uiout
->is_mi_like_p ())
6203 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6205 uiout
->field_signed ("line", loc
->line_number
);
6211 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6213 uiout
->field_stream ("at", stb
);
6217 uiout
->field_string ("pending", b
->locspec
->to_string ());
6218 /* If extra_string is available, it could be holding a condition
6219 or dprintf arguments. In either case, make sure it is printed,
6220 too, but only for non-MI streams. */
6221 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6223 if (b
->type
== bp_dprintf
)
6227 uiout
->text (b
->extra_string
.get ());
6231 if (loc
&& is_breakpoint (b
)
6232 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6233 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6236 uiout
->field_string ("evaluated-by",
6237 bp_location_condition_evaluator (loc
));
6243 bptype_string (enum bptype type
)
6245 struct ep_type_description
6248 const char *description
;
6250 static struct ep_type_description bptypes
[] =
6252 {bp_none
, "?deleted?"},
6253 {bp_breakpoint
, "breakpoint"},
6254 {bp_hardware_breakpoint
, "hw breakpoint"},
6255 {bp_single_step
, "sw single-step"},
6256 {bp_until
, "until"},
6257 {bp_finish
, "finish"},
6258 {bp_watchpoint
, "watchpoint"},
6259 {bp_hardware_watchpoint
, "hw watchpoint"},
6260 {bp_read_watchpoint
, "read watchpoint"},
6261 {bp_access_watchpoint
, "acc watchpoint"},
6262 {bp_longjmp
, "longjmp"},
6263 {bp_longjmp_resume
, "longjmp resume"},
6264 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6265 {bp_exception
, "exception"},
6266 {bp_exception_resume
, "exception resume"},
6267 {bp_step_resume
, "step resume"},
6268 {bp_hp_step_resume
, "high-priority step resume"},
6269 {bp_watchpoint_scope
, "watchpoint scope"},
6270 {bp_call_dummy
, "call dummy"},
6271 {bp_std_terminate
, "std::terminate"},
6272 {bp_shlib_event
, "shlib events"},
6273 {bp_thread_event
, "thread events"},
6274 {bp_overlay_event
, "overlay events"},
6275 {bp_longjmp_master
, "longjmp master"},
6276 {bp_std_terminate_master
, "std::terminate master"},
6277 {bp_exception_master
, "exception master"},
6278 {bp_catchpoint
, "catchpoint"},
6279 {bp_tracepoint
, "tracepoint"},
6280 {bp_fast_tracepoint
, "fast tracepoint"},
6281 {bp_static_tracepoint
, "static tracepoint"},
6282 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6283 {bp_dprintf
, "dprintf"},
6284 {bp_jit_event
, "jit events"},
6285 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6286 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6289 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6290 || ((int) type
!= bptypes
[(int) type
].type
))
6291 internal_error (_("bptypes table does not describe type #%d."),
6294 return bptypes
[(int) type
].description
;
6297 /* For MI, output a field named 'thread-groups' with a list as the value.
6298 For CLI, prefix the list with the string 'inf'. */
6301 output_thread_groups (struct ui_out
*uiout
,
6302 const char *field_name
,
6303 const std::vector
<int> &inf_nums
,
6306 int is_mi
= uiout
->is_mi_like_p ();
6308 /* For backward compatibility, don't display inferiors in CLI unless
6309 there are several. Always display them for MI. */
6310 if (!is_mi
&& mi_only
)
6313 ui_out_emit_list
list_emitter (uiout
, field_name
);
6315 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6321 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6322 uiout
->field_string (NULL
, mi_group
);
6327 uiout
->text (" inf ");
6331 uiout
->text (plongest (inf_nums
[i
]));
6336 /* See breakpoint.h. */
6338 bool fix_breakpoint_script_output_globally
= false;
6340 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6341 instead of going via breakpoint_ops::print_one. This makes "maint
6342 info breakpoints" show the software breakpoint locations of
6343 catchpoints, which are considered internal implementation
6344 detail. Returns true if RAW_LOC is false and if the breakpoint's
6345 print_one method did something; false otherwise. */
6348 print_one_breakpoint_location (struct breakpoint
*b
,
6349 struct bp_location
*loc
,
6351 struct bp_location
**last_loc
,
6352 int allflag
, bool raw_loc
)
6354 struct command_line
*l
;
6355 static char bpenables
[] = "nynny";
6357 struct ui_out
*uiout
= current_uiout
;
6358 bool header_of_multiple
= false;
6359 bool part_of_multiple
= (loc
!= NULL
);
6360 struct value_print_options opts
;
6362 get_user_print_options (&opts
);
6364 gdb_assert (!loc
|| loc_number
!= 0);
6365 /* See comment in print_one_breakpoint concerning treatment of
6366 breakpoints with single disabled location. */
6369 && (b
->loc
->next
!= NULL
6370 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6371 header_of_multiple
= true;
6379 if (part_of_multiple
)
6380 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6382 uiout
->field_signed ("number", b
->number
);
6386 if (part_of_multiple
)
6387 uiout
->field_skip ("type");
6389 uiout
->field_string ("type", bptype_string (b
->type
));
6393 if (part_of_multiple
)
6394 uiout
->field_skip ("disp");
6396 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6400 if (part_of_multiple
)
6402 /* For locations that are disabled because of an invalid
6403 condition, display "N*" on the CLI, where "*" refers to a
6404 footnote below the table. For MI, simply display a "N"
6405 without a footnote. On the CLI, for enabled locations whose
6406 breakpoint is disabled, display "y-". */
6407 auto get_enable_state
= [uiout
, loc
] () -> const char *
6409 if (uiout
->is_mi_like_p ())
6411 if (loc
->disabled_by_cond
)
6413 else if (!loc
->enabled
)
6420 if (loc
->disabled_by_cond
)
6422 else if (!loc
->enabled
)
6424 else if (!breakpoint_enabled (loc
->owner
))
6430 uiout
->field_string ("enabled", get_enable_state ());
6433 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6436 bool result
= false;
6437 if (!raw_loc
&& b
->print_one (last_loc
))
6441 if (is_watchpoint (b
))
6443 struct watchpoint
*w
= (struct watchpoint
*) b
;
6445 /* Field 4, the address, is omitted (which makes the columns
6446 not line up too nicely with the headers, but the effect
6447 is relatively readable). */
6448 if (opts
.addressprint
)
6449 uiout
->field_skip ("addr");
6451 uiout
->field_string ("what", w
->exp_string
.get ());
6453 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6454 || is_ada_exception_catchpoint (b
))
6456 if (opts
.addressprint
)
6459 if (header_of_multiple
)
6460 uiout
->field_string ("addr", "<MULTIPLE>",
6461 metadata_style
.style ());
6462 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6463 uiout
->field_string ("addr", "<PENDING>",
6464 metadata_style
.style ());
6466 uiout
->field_core_addr ("addr",
6467 loc
->gdbarch
, loc
->address
);
6470 if (!header_of_multiple
)
6471 print_breakpoint_location (b
, loc
);
6477 if (loc
!= NULL
&& !header_of_multiple
)
6479 std::vector
<int> inf_nums
;
6482 for (inferior
*inf
: all_inferiors ())
6484 if (inf
->pspace
== loc
->pspace
)
6485 inf_nums
.push_back (inf
->num
);
6488 /* For backward compatibility, don't display inferiors in CLI unless
6489 there are several. Always display for MI. */
6491 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6492 && (program_spaces
.size () > 1
6493 || number_of_inferiors () > 1)
6494 /* LOC is for existing B, it cannot be in
6495 moribund_locations and thus having NULL OWNER. */
6496 && loc
->owner
->type
!= bp_catchpoint
))
6498 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6501 /* In the MI output, each location of a thread or task specific
6502 breakpoint includes the relevant thread or task ID. This is done for
6503 backwards compatibility reasons.
6505 For the CLI output, the thread/task information is printed on a
6506 separate line, see the 'stop only in thread' and 'stop only in task'
6508 if (part_of_multiple
&& uiout
->is_mi_like_p ())
6510 if (b
->thread
!= -1)
6511 uiout
->field_signed ("thread", b
->thread
);
6512 else if (b
->task
!= -1)
6513 uiout
->field_signed ("task", b
->task
);
6518 if (!part_of_multiple
)
6519 b
->print_one_detail (uiout
);
6521 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6524 uiout
->text ("\tstop only in stack frame at ");
6525 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6527 uiout
->field_core_addr ("frame",
6528 b
->gdbarch
, b
->frame_id
.stack_addr
);
6532 if (!part_of_multiple
&& b
->cond_string
)
6535 if (is_tracepoint (b
))
6536 uiout
->text ("\ttrace only if ");
6538 uiout
->text ("\tstop only if ");
6539 uiout
->field_string ("cond", b
->cond_string
.get ());
6541 /* Print whether the target is doing the breakpoint's condition
6542 evaluation. If GDB is doing the evaluation, don't print anything. */
6543 if (is_breakpoint (b
)
6544 && breakpoint_condition_evaluation_mode ()
6545 == condition_evaluation_target
)
6547 uiout
->message (" (%pF evals)",
6548 string_field ("evaluated-by",
6549 bp_condition_evaluator (b
)));
6554 if (!part_of_multiple
&& b
->thread
!= -1)
6556 /* FIXME should make an annotation for this. */
6557 uiout
->text ("\tstop only in thread ");
6558 if (uiout
->is_mi_like_p ())
6559 uiout
->field_signed ("thread", b
->thread
);
6562 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6564 uiout
->field_string ("thread", print_thread_id (thr
));
6569 if (!part_of_multiple
&& b
->task
!= -1)
6571 uiout
->text ("\tstop only in task ");
6572 uiout
->field_signed ("task", b
->task
);
6576 if (!part_of_multiple
)
6580 /* FIXME should make an annotation for this. */
6581 if (is_catchpoint (b
))
6582 uiout
->text ("\tcatchpoint");
6583 else if (is_tracepoint (b
))
6584 uiout
->text ("\ttracepoint");
6586 uiout
->text ("\tbreakpoint");
6587 uiout
->text (" already hit ");
6588 uiout
->field_signed ("times", b
->hit_count
);
6589 if (b
->hit_count
== 1)
6590 uiout
->text (" time\n");
6592 uiout
->text (" times\n");
6596 /* Output the count also if it is zero, but only if this is mi. */
6597 if (uiout
->is_mi_like_p ())
6598 uiout
->field_signed ("times", b
->hit_count
);
6602 if (!part_of_multiple
&& b
->ignore_count
)
6605 uiout
->message ("\tignore next %pF hits\n",
6606 signed_field ("ignore", b
->ignore_count
));
6609 /* Note that an enable count of 1 corresponds to "enable once"
6610 behavior, which is reported by the combination of enablement and
6611 disposition, so we don't need to mention it here. */
6612 if (!part_of_multiple
&& b
->enable_count
> 1)
6615 uiout
->text ("\tdisable after ");
6616 /* Tweak the wording to clarify that ignore and enable counts
6617 are distinct, and have additive effect. */
6618 if (b
->ignore_count
)
6619 uiout
->text ("additional ");
6621 uiout
->text ("next ");
6622 uiout
->field_signed ("enable", b
->enable_count
);
6623 uiout
->text (" hits\n");
6626 if (!part_of_multiple
&& is_tracepoint (b
))
6628 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6630 if (tp
->traceframe_usage
)
6632 uiout
->text ("\ttrace buffer usage ");
6633 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6634 uiout
->text (" bytes\n");
6638 l
= b
->commands
? b
->commands
.get () : NULL
;
6639 if (!part_of_multiple
&& l
)
6643 bool use_fixed_output
=
6644 (uiout
->test_flags (fix_breakpoint_script_output
)
6645 || fix_breakpoint_script_output_globally
);
6647 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
6648 gdb::optional
<ui_out_emit_list
> list_emitter
;
6650 if (use_fixed_output
)
6651 list_emitter
.emplace (uiout
, "script");
6653 tuple_emitter
.emplace (uiout
, "script");
6655 print_command_lines (uiout
, l
, 4);
6658 if (is_tracepoint (b
))
6660 struct tracepoint
*t
= (struct tracepoint
*) b
;
6662 if (!part_of_multiple
&& t
->pass_count
)
6664 annotate_field (10);
6665 uiout
->text ("\tpass count ");
6666 uiout
->field_signed ("pass", t
->pass_count
);
6667 uiout
->text (" \n");
6670 /* Don't display it when tracepoint or tracepoint location is
6672 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6674 annotate_field (11);
6676 if (uiout
->is_mi_like_p ())
6677 uiout
->field_string ("installed",
6678 loc
->inserted
? "y" : "n");
6684 uiout
->text ("\tnot ");
6685 uiout
->text ("installed on target\n");
6690 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6692 if (is_watchpoint (b
))
6694 struct watchpoint
*w
= (struct watchpoint
*) b
;
6696 uiout
->field_string ("original-location", w
->exp_string
.get ());
6698 else if (b
->locspec
!= nullptr)
6700 const char *str
= b
->locspec
->to_string ();
6702 uiout
->field_string ("original-location", str
);
6709 /* See breakpoint.h. */
6711 bool fix_multi_location_breakpoint_output_globally
= false;
6714 print_one_breakpoint (struct breakpoint
*b
,
6715 struct bp_location
**last_loc
,
6718 struct ui_out
*uiout
= current_uiout
;
6719 bool use_fixed_output
6720 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6721 || fix_multi_location_breakpoint_output_globally
);
6723 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6724 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6727 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6729 if (!use_fixed_output
)
6730 bkpt_tuple_emitter
.reset ();
6732 /* If this breakpoint has custom print function,
6733 it's already printed. Otherwise, print individual
6734 locations, if any. */
6735 if (!printed
|| allflag
)
6737 /* If breakpoint has a single location that is disabled, we
6738 print it as if it had several locations, since otherwise it's
6739 hard to represent "breakpoint enabled, location disabled"
6742 Note that while hardware watchpoints have several locations
6743 internally, that's not a property exposed to users.
6745 Likewise, while catchpoints may be implemented with
6746 breakpoints (e.g., catch throw), that's not a property
6747 exposed to users. We do however display the internal
6748 breakpoint locations with "maint info breakpoints". */
6749 if (!is_hardware_watchpoint (b
)
6750 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6751 || is_ada_exception_catchpoint (b
))
6753 || (b
->loc
&& (b
->loc
->next
6755 || b
->loc
->disabled_by_cond
))))
6757 gdb::optional
<ui_out_emit_list
> locations_list
;
6759 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6760 MI record. For later versions, place breakpoint locations in a
6762 if (uiout
->is_mi_like_p () && use_fixed_output
)
6763 locations_list
.emplace (uiout
, "locations");
6766 for (bp_location
*loc
: b
->locations ())
6768 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6769 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6778 breakpoint_address_bits (struct breakpoint
*b
)
6780 int print_address_bits
= 0;
6782 for (bp_location
*loc
: b
->locations ())
6784 if (!bl_address_is_meaningful (loc
))
6787 int addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6788 if (addr_bit
> print_address_bits
)
6789 print_address_bits
= addr_bit
;
6792 return print_address_bits
;
6795 /* See breakpoint.h. */
6798 print_breakpoint (breakpoint
*b
)
6800 struct bp_location
*dummy_loc
= NULL
;
6801 print_one_breakpoint (b
, &dummy_loc
, 0);
6804 /* Return true if this breakpoint was set by the user, false if it is
6805 internal or momentary. */
6808 user_breakpoint_p (struct breakpoint
*b
)
6810 return b
->number
> 0;
6813 /* See breakpoint.h. */
6816 pending_breakpoint_p (struct breakpoint
*b
)
6818 return b
->loc
== NULL
;
6821 /* Print information on breakpoints (including watchpoints and tracepoints).
6823 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6824 understood by number_or_range_parser. Only breakpoints included in this
6825 list are then printed.
6827 If SHOW_INTERNAL is true, print internal breakpoints.
6829 If FILTER is non-NULL, call it on each breakpoint and only include the
6830 ones for which it returns true.
6832 Return the total number of breakpoints listed. */
6835 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6836 bool (*filter
) (const struct breakpoint
*))
6838 struct bp_location
*last_loc
= NULL
;
6839 int nr_printable_breakpoints
;
6840 struct value_print_options opts
;
6841 int print_address_bits
= 0;
6842 int print_type_col_width
= 14;
6843 struct ui_out
*uiout
= current_uiout
;
6844 bool has_disabled_by_cond_location
= false;
6846 get_user_print_options (&opts
);
6848 /* Compute the number of rows in the table, as well as the size
6849 required for address fields. */
6850 nr_printable_breakpoints
= 0;
6851 for (breakpoint
*b
: all_breakpoints ())
6853 /* If we have a filter, only list the breakpoints it accepts. */
6854 if (filter
&& !filter (b
))
6857 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6858 accept. Skip the others. */
6859 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6861 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6863 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6867 if (show_internal
|| user_breakpoint_p (b
))
6869 int addr_bit
, type_len
;
6871 addr_bit
= breakpoint_address_bits (b
);
6872 if (addr_bit
> print_address_bits
)
6873 print_address_bits
= addr_bit
;
6875 type_len
= strlen (bptype_string (b
->type
));
6876 if (type_len
> print_type_col_width
)
6877 print_type_col_width
= type_len
;
6879 nr_printable_breakpoints
++;
6884 ui_out_emit_table
table_emitter (uiout
,
6885 opts
.addressprint
? 6 : 5,
6886 nr_printable_breakpoints
,
6889 if (nr_printable_breakpoints
> 0)
6890 annotate_breakpoints_headers ();
6891 if (nr_printable_breakpoints
> 0)
6893 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6894 if (nr_printable_breakpoints
> 0)
6896 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6897 if (nr_printable_breakpoints
> 0)
6899 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6900 if (nr_printable_breakpoints
> 0)
6902 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6903 if (opts
.addressprint
)
6905 if (nr_printable_breakpoints
> 0)
6907 if (print_address_bits
<= 32)
6908 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6910 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6912 if (nr_printable_breakpoints
> 0)
6914 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6915 uiout
->table_body ();
6916 if (nr_printable_breakpoints
> 0)
6917 annotate_breakpoints_table ();
6919 for (breakpoint
*b
: all_breakpoints ())
6922 /* If we have a filter, only list the breakpoints it accepts. */
6923 if (filter
&& !filter (b
))
6926 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6927 accept. Skip the others. */
6929 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6931 if (show_internal
) /* maintenance info breakpoint */
6933 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6936 else /* all others */
6938 if (!number_is_in_list (bp_num_list
, b
->number
))
6942 /* We only print out user settable breakpoints unless the
6943 show_internal is set. */
6944 if (show_internal
|| user_breakpoint_p (b
))
6946 print_one_breakpoint (b
, &last_loc
, show_internal
);
6947 for (bp_location
*loc
: b
->locations ())
6948 if (loc
->disabled_by_cond
)
6949 has_disabled_by_cond_location
= true;
6954 if (nr_printable_breakpoints
== 0)
6956 /* If there's a filter, let the caller decide how to report
6960 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6961 uiout
->message ("No breakpoints or watchpoints.\n");
6963 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6969 if (last_loc
&& !server_command
)
6970 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6972 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6973 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6977 /* FIXME? Should this be moved up so that it is only called when
6978 there have been breakpoints? */
6979 annotate_breakpoints_table_end ();
6981 return nr_printable_breakpoints
;
6984 /* Display the value of default-collect in a way that is generally
6985 compatible with the breakpoint list. */
6988 default_collect_info (void)
6990 struct ui_out
*uiout
= current_uiout
;
6992 /* If it has no value (which is frequently the case), say nothing; a
6993 message like "No default-collect." gets in user's face when it's
6995 if (default_collect
.empty ())
6998 /* The following phrase lines up nicely with per-tracepoint collect
7000 uiout
->text ("default collect ");
7001 uiout
->field_string ("default-collect", default_collect
);
7002 uiout
->text (" \n");
7006 info_breakpoints_command (const char *args
, int from_tty
)
7008 breakpoint_1 (args
, false, NULL
);
7010 default_collect_info ();
7014 info_watchpoints_command (const char *args
, int from_tty
)
7016 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
7017 struct ui_out
*uiout
= current_uiout
;
7019 if (num_printed
== 0)
7021 if (args
== NULL
|| *args
== '\0')
7022 uiout
->message ("No watchpoints.\n");
7024 uiout
->message ("No watchpoint matching '%s'.\n", args
);
7029 maintenance_info_breakpoints (const char *args
, int from_tty
)
7031 breakpoint_1 (args
, true, NULL
);
7033 default_collect_info ();
7037 breakpoint_has_pc (struct breakpoint
*b
,
7038 struct program_space
*pspace
,
7039 CORE_ADDR pc
, struct obj_section
*section
)
7041 for (bp_location
*bl
: b
->locations ())
7043 if (bl
->pspace
== pspace
7044 && bl
->address
== pc
7045 && (!overlay_debugging
|| bl
->section
== section
))
7051 /* See breakpoint.h. */
7054 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7055 struct program_space
*pspace
, CORE_ADDR pc
,
7056 struct obj_section
*section
, int thread
)
7060 for (breakpoint
*b
: all_breakpoints ())
7061 others
+= (user_breakpoint_p (b
)
7062 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7067 gdb_printf (_("Note: breakpoint "));
7068 else /* if (others == ???) */
7069 gdb_printf (_("Note: breakpoints "));
7070 for (breakpoint
*b
: all_breakpoints ())
7071 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7074 gdb_printf ("%d", b
->number
);
7075 if (b
->thread
== -1 && thread
!= -1)
7076 gdb_printf (" (all threads)");
7077 else if (b
->thread
!= -1)
7079 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
7080 gdb_printf (" (thread %s)", print_thread_id (thr
));
7082 else if (b
->task
!= -1)
7083 gdb_printf (" (task %d)", b
->task
);
7084 gdb_printf ("%s%s ",
7085 ((b
->enable_state
== bp_disabled
7086 || b
->enable_state
== bp_call_disabled
)
7090 : ((others
== 1) ? " and" : ""));
7092 current_uiout
->message (_("also set at pc %ps.\n"),
7093 styled_string (address_style
.style (),
7094 paddress (gdbarch
, pc
)));
7099 /* Return true iff it is meaningful to use the address member of LOC.
7100 For some breakpoint types, the locations' address members are
7101 irrelevant and it makes no sense to attempt to compare them to
7102 other addresses (or use them for any other purpose either).
7104 More specifically, software watchpoints and catchpoints that are
7105 not backed by breakpoints always have a zero valued location
7106 address and we don't want to mark breakpoints of any of these types
7107 to be a duplicate of an actual breakpoint location at address
7111 bl_address_is_meaningful (bp_location
*loc
)
7113 return loc
->loc_type
!= bp_loc_other
;
7116 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7117 true if LOC1 and LOC2 represent the same watchpoint location. */
7120 watchpoint_locations_match (const struct bp_location
*loc1
,
7121 const struct bp_location
*loc2
)
7123 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7124 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7126 /* Both of them must exist. */
7127 gdb_assert (w1
!= NULL
);
7128 gdb_assert (w2
!= NULL
);
7130 /* If the target can evaluate the condition expression in hardware,
7131 then we we need to insert both watchpoints even if they are at
7132 the same place. Otherwise the watchpoint will only trigger when
7133 the condition of whichever watchpoint was inserted evaluates to
7134 true, not giving a chance for GDB to check the condition of the
7135 other watchpoint. */
7137 && target_can_accel_watchpoint_condition (loc1
->address
,
7139 loc1
->watchpoint_type
,
7140 w1
->cond_exp
.get ()))
7142 && target_can_accel_watchpoint_condition (loc2
->address
,
7144 loc2
->watchpoint_type
,
7145 w2
->cond_exp
.get ())))
7148 /* Note that this checks the owner's type, not the location's. In
7149 case the target does not support read watchpoints, but does
7150 support access watchpoints, we'll have bp_read_watchpoint
7151 watchpoints with hw_access locations. Those should be considered
7152 duplicates of hw_read locations. The hw_read locations will
7153 become hw_access locations later. */
7154 return (loc1
->owner
->type
== loc2
->owner
->type
7155 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7156 && loc1
->address
== loc2
->address
7157 && loc1
->length
== loc2
->length
);
7160 /* See breakpoint.h. */
7163 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
7164 const address_space
*aspace2
, CORE_ADDR addr2
)
7166 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7167 || aspace1
== aspace2
)
7171 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7172 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7173 matches ASPACE2. On targets that have global breakpoints, the address
7174 space doesn't really matter. */
7177 breakpoint_address_match_range (const address_space
*aspace1
,
7179 int len1
, const address_space
*aspace2
,
7182 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7183 || aspace1
== aspace2
)
7184 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7187 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7188 a ranged breakpoint. In most targets, a match happens only if ASPACE
7189 matches the breakpoint's address space. On targets that have global
7190 breakpoints, the address space doesn't really matter. */
7193 breakpoint_location_address_match (struct bp_location
*bl
,
7194 const address_space
*aspace
,
7197 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7200 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7201 bl
->address
, bl
->length
,
7205 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7206 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7207 match happens only if ASPACE matches the breakpoint's address
7208 space. On targets that have global breakpoints, the address space
7209 doesn't really matter. */
7212 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7213 const address_space
*aspace
,
7214 CORE_ADDR addr
, int len
)
7216 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7217 || bl
->pspace
->aspace
== aspace
)
7219 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7221 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7227 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7228 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7229 true, otherwise returns false. */
7232 tracepoint_locations_match (const struct bp_location
*loc1
,
7233 const struct bp_location
*loc2
)
7235 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7236 /* Since tracepoint locations are never duplicated with others', tracepoint
7237 locations at the same address of different tracepoints are regarded as
7238 different locations. */
7239 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7244 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7245 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7246 the same location. If SW_HW_BPS_MATCH is true, then software
7247 breakpoint locations and hardware breakpoint locations match,
7248 otherwise they don't. */
7251 breakpoint_locations_match (const struct bp_location
*loc1
,
7252 const struct bp_location
*loc2
,
7253 bool sw_hw_bps_match
)
7255 int hw_point1
, hw_point2
;
7257 /* Both of them must not be in moribund_locations. */
7258 gdb_assert (loc1
->owner
!= NULL
);
7259 gdb_assert (loc2
->owner
!= NULL
);
7261 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7262 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7264 if (hw_point1
!= hw_point2
)
7267 return watchpoint_locations_match (loc1
, loc2
);
7268 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7269 return tracepoint_locations_match (loc1
, loc2
);
7271 /* We compare bp_location.length in order to cover ranged
7272 breakpoints. Keep this in sync with
7273 bp_location_is_less_than. */
7274 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7275 loc2
->pspace
->aspace
, loc2
->address
)
7276 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7277 && loc1
->length
== loc2
->length
);
7281 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7282 int bnum
, bool have_bnum
)
7284 /* The longest string possibly returned by hex_string_custom
7285 is 50 chars. These must be at least that big for safety. */
7289 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7290 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7292 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7293 bnum
, astr1
, astr2
);
7295 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7298 /* Adjust a breakpoint's address to account for architectural
7299 constraints on breakpoint placement. Return the adjusted address.
7300 Note: Very few targets require this kind of adjustment. For most
7301 targets, this function is simply the identity function. */
7304 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7305 CORE_ADDR bpaddr
, enum bptype bptype
,
7306 struct program_space
*pspace
)
7308 gdb_assert (pspace
!= nullptr);
7310 if (bptype
== bp_watchpoint
7311 || bptype
== bp_hardware_watchpoint
7312 || bptype
== bp_read_watchpoint
7313 || bptype
== bp_access_watchpoint
7314 || bptype
== bp_catchpoint
)
7316 /* Watchpoints and the various bp_catch_* eventpoints should not
7317 have their addresses modified. */
7320 else if (bptype
== bp_single_step
)
7322 /* Single-step breakpoints should not have their addresses
7323 modified. If there's any architectural constrain that
7324 applies to this address, then it should have already been
7325 taken into account when the breakpoint was created in the
7326 first place. If we didn't do this, stepping through e.g.,
7327 Thumb-2 IT blocks would break. */
7332 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7334 /* Some targets have architectural constraints on the placement
7335 of breakpoint instructions. Obtain the adjusted address. */
7336 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7338 /* Targets that implement this adjustment function will likely
7339 inspect either the symbol table, target memory at BPADDR, or
7340 even state registers, so ensure a suitable thread (and its
7341 associated program space) are currently selected. */
7342 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
7343 switch_to_program_space_and_thread (pspace
);
7345 = gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7349 = gdbarch_remove_non_address_bits (gdbarch
, adjusted_bpaddr
);
7351 /* An adjusted breakpoint address can significantly alter
7352 a user's expectations. Print a warning if an adjustment
7354 if (adjusted_bpaddr
!= bpaddr
)
7355 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, false);
7357 return adjusted_bpaddr
;
7362 bp_location_from_bp_type (bptype type
)
7367 case bp_single_step
:
7371 case bp_longjmp_resume
:
7372 case bp_longjmp_call_dummy
:
7374 case bp_exception_resume
:
7375 case bp_step_resume
:
7376 case bp_hp_step_resume
:
7377 case bp_watchpoint_scope
:
7379 case bp_std_terminate
:
7380 case bp_shlib_event
:
7381 case bp_thread_event
:
7382 case bp_overlay_event
:
7384 case bp_longjmp_master
:
7385 case bp_std_terminate_master
:
7386 case bp_exception_master
:
7387 case bp_gnu_ifunc_resolver
:
7388 case bp_gnu_ifunc_resolver_return
:
7390 return bp_loc_software_breakpoint
;
7392 case bp_hardware_breakpoint
:
7393 return bp_loc_hardware_breakpoint
;
7395 case bp_hardware_watchpoint
:
7396 case bp_read_watchpoint
:
7397 case bp_access_watchpoint
:
7398 return bp_loc_hardware_watchpoint
;
7401 return bp_loc_software_watchpoint
;
7404 case bp_fast_tracepoint
:
7405 case bp_static_tracepoint
:
7406 case bp_static_marker_tracepoint
:
7407 return bp_loc_tracepoint
;
7410 return bp_loc_other
;
7413 internal_error (_("unknown breakpoint type"));
7417 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7419 this->owner
= owner
;
7420 this->cond_bytecode
= NULL
;
7421 this->shlib_disabled
= 0;
7423 this->disabled_by_cond
= false;
7425 this->loc_type
= type
;
7427 if (this->loc_type
== bp_loc_software_breakpoint
7428 || this->loc_type
== bp_loc_hardware_breakpoint
)
7429 mark_breakpoint_location_modified (this);
7434 bp_location::bp_location (breakpoint
*owner
)
7435 : bp_location::bp_location (owner
,
7436 bp_location_from_bp_type (owner
->type
))
7440 /* Decrement reference count. If the reference count reaches 0,
7441 destroy the bp_location. Sets *BLP to NULL. */
7444 decref_bp_location (struct bp_location
**blp
)
7446 bp_location_ref_policy::decref (*blp
);
7450 /* Add breakpoint B at the end of the global breakpoint chain. */
7453 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7455 struct breakpoint
*b1
;
7456 struct breakpoint
*result
= b
.get ();
7458 /* Add this breakpoint to the end of the chain so that a list of
7459 breakpoints will come out in order of increasing numbers. */
7461 b1
= breakpoint_chain
;
7463 breakpoint_chain
= b
.release ();
7468 b1
->next
= b
.release ();
7474 /* Initialize loc->function_name. */
7477 set_breakpoint_location_function (struct bp_location
*loc
)
7479 gdb_assert (loc
->owner
!= NULL
);
7481 if (loc
->owner
->type
== bp_breakpoint
7482 || loc
->owner
->type
== bp_hardware_breakpoint
7483 || is_tracepoint (loc
->owner
))
7485 const char *function_name
;
7487 if (loc
->msymbol
!= NULL
7488 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7489 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7491 struct breakpoint
*b
= loc
->owner
;
7493 function_name
= loc
->msymbol
->linkage_name ();
7495 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7496 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7498 /* Create only the whole new breakpoint of this type but do not
7499 mess more complicated breakpoints with multiple locations. */
7500 b
->type
= bp_gnu_ifunc_resolver
;
7501 /* Remember the resolver's address for use by the return
7503 loc
->related_address
= loc
->address
;
7507 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7510 loc
->function_name
= make_unique_xstrdup (function_name
);
7514 /* Attempt to determine architecture of location identified by SAL. */
7516 get_sal_arch (struct symtab_and_line sal
)
7519 return sal
.section
->objfile
->arch ();
7521 return sal
.symtab
->compunit ()->objfile ()->arch ();
7526 /* Call this routine when stepping and nexting to enable a breakpoint
7527 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7528 initiated the operation. */
7531 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7533 int thread
= tp
->global_num
;
7535 /* To avoid having to rescan all objfile symbols at every step,
7536 we maintain a list of continually-inserted but always disabled
7537 longjmp "master" breakpoints. Here, we simply create momentary
7538 clones of those and enable them for the requested thread. */
7539 for (breakpoint
*b
: all_breakpoints_safe ())
7540 if (b
->pspace
== current_program_space
7541 && (b
->type
== bp_longjmp_master
7542 || b
->type
== bp_exception_master
))
7544 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7545 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7546 after their removal. */
7547 momentary_breakpoint_from_master (b
, type
, 1, thread
);
7550 tp
->initiating_frame
= frame
;
7553 /* Delete all longjmp breakpoints from THREAD. */
7555 delete_longjmp_breakpoint (int thread
)
7557 for (breakpoint
*b
: all_breakpoints_safe ())
7558 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7560 if (b
->thread
== thread
)
7561 delete_breakpoint (b
);
7566 delete_longjmp_breakpoint_at_next_stop (int thread
)
7568 for (breakpoint
*b
: all_breakpoints_safe ())
7569 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7571 if (b
->thread
== thread
)
7572 b
->disposition
= disp_del_at_next_stop
;
7576 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7577 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7578 pointer to any of them. Return NULL if this system cannot place longjmp
7582 set_longjmp_breakpoint_for_call_dummy (void)
7584 breakpoint
*retval
= nullptr;
7586 for (breakpoint
*b
: all_breakpoints ())
7587 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7589 int thread
= inferior_thread ()->global_num
;
7591 = momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7594 /* Link NEW_B into the chain of RETVAL breakpoints. */
7596 gdb_assert (new_b
->related_breakpoint
== new_b
);
7599 new_b
->related_breakpoint
= retval
;
7600 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7601 retval
= retval
->related_breakpoint
;
7602 retval
->related_breakpoint
= new_b
;
7608 /* Verify all existing dummy frames and their associated breakpoints for
7609 TP. Remove those which can no longer be found in the current frame
7612 If the unwind fails then there is not sufficient information to discard
7613 dummy frames. In this case, elide the clean up and the dummy frames will
7614 be cleaned up next time this function is called from a location where
7615 unwinding is possible. */
7618 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7620 struct breakpoint
*b
, *b_tmp
;
7622 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7623 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7625 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7627 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7628 chained off b->related_breakpoint. */
7629 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7630 dummy_b
= dummy_b
->related_breakpoint
;
7632 /* If there was no bp_call_dummy breakpoint then there's nothing
7633 more to do. Or, if the dummy frame associated with the
7634 bp_call_dummy is still on the stack then we need to leave this
7635 bp_call_dummy in place. */
7636 if (dummy_b
->type
!= bp_call_dummy
7637 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7640 /* We didn't find the dummy frame on the stack, this could be
7641 because we have longjmp'd to a stack frame that is previous to
7642 the dummy frame, or it could be because the stack unwind is
7643 broken at some point between the longjmp frame and the dummy
7646 Next we figure out why the stack unwind stopped. If it looks
7647 like the unwind is complete then we assume the dummy frame has
7648 been jumped over, however, if the unwind stopped for an
7649 unexpected reason then we assume the stack unwind is currently
7650 broken, and that we will (eventually) return to the dummy
7653 It might be tempting to consider using frame_id_inner here, but
7654 that is not safe. There is no guarantee that the stack frames
7655 we are looking at here are even on the same stack as the
7656 original dummy frame, hence frame_id_inner can't be used. See
7657 the comments on frame_id_inner for more details. */
7658 bool unwind_finished_unexpectedly
= false;
7659 for (frame_info_ptr fi
= get_current_frame (); fi
!= nullptr; )
7661 frame_info_ptr prev
= get_prev_frame (fi
);
7662 if (prev
== nullptr)
7664 /* FI is the last stack frame. Why did this frame not
7666 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7667 if (stop_reason
!= UNWIND_NO_REASON
7668 && stop_reason
!= UNWIND_OUTERMOST
)
7669 unwind_finished_unexpectedly
= true;
7673 if (unwind_finished_unexpectedly
)
7676 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7678 while (b
->related_breakpoint
!= b
)
7680 if (b_tmp
== b
->related_breakpoint
)
7681 b_tmp
= b
->related_breakpoint
->next
;
7682 delete_breakpoint (b
->related_breakpoint
);
7684 delete_breakpoint (b
);
7689 enable_overlay_breakpoints (void)
7691 for (breakpoint
*b
: all_breakpoints ())
7692 if (b
->type
== bp_overlay_event
)
7694 b
->enable_state
= bp_enabled
;
7695 update_global_location_list (UGLL_MAY_INSERT
);
7696 overlay_events_enabled
= 1;
7701 disable_overlay_breakpoints (void)
7703 for (breakpoint
*b
: all_breakpoints ())
7704 if (b
->type
== bp_overlay_event
)
7706 b
->enable_state
= bp_disabled
;
7707 update_global_location_list (UGLL_DONT_INSERT
);
7708 overlay_events_enabled
= 0;
7712 /* Set an active std::terminate breakpoint for each std::terminate
7713 master breakpoint. */
7715 set_std_terminate_breakpoint (void)
7717 for (breakpoint
*b
: all_breakpoints_safe ())
7718 if (b
->pspace
== current_program_space
7719 && b
->type
== bp_std_terminate_master
)
7721 momentary_breakpoint_from_master (b
, bp_std_terminate
, 1,
7722 inferior_thread ()->global_num
);
7726 /* Delete all the std::terminate breakpoints. */
7728 delete_std_terminate_breakpoint (void)
7730 for (breakpoint
*b
: all_breakpoints_safe ())
7731 if (b
->type
== bp_std_terminate
)
7732 delete_breakpoint (b
);
7736 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7738 struct breakpoint
*b
;
7740 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7742 b
->enable_state
= bp_enabled
;
7743 /* locspec has to be used or breakpoint_re_set will delete me. */
7744 b
->locspec
= new_address_location_spec (b
->loc
->address
, NULL
, 0);
7746 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7751 struct lang_and_radix
7757 /* Create a breakpoint for JIT code registration and unregistration. */
7760 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7762 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7765 /* Remove JIT code registration and unregistration breakpoint(s). */
7768 remove_jit_event_breakpoints (void)
7770 for (breakpoint
*b
: all_breakpoints_safe ())
7771 if (b
->type
== bp_jit_event
7772 && b
->loc
->pspace
== current_program_space
)
7773 delete_breakpoint (b
);
7777 remove_solib_event_breakpoints (void)
7779 for (breakpoint
*b
: all_breakpoints_safe ())
7780 if (b
->type
== bp_shlib_event
7781 && b
->loc
->pspace
== current_program_space
)
7782 delete_breakpoint (b
);
7785 /* See breakpoint.h. */
7788 remove_solib_event_breakpoints_at_next_stop (void)
7790 for (breakpoint
*b
: all_breakpoints_safe ())
7791 if (b
->type
== bp_shlib_event
7792 && b
->loc
->pspace
== current_program_space
)
7793 b
->disposition
= disp_del_at_next_stop
;
7796 /* Helper for create_solib_event_breakpoint /
7797 create_and_insert_solib_event_breakpoint. Allows specifying which
7798 INSERT_MODE to pass through to update_global_location_list. */
7800 static struct breakpoint
*
7801 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7802 enum ugll_insert_mode insert_mode
)
7804 struct breakpoint
*b
;
7806 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
7807 update_global_location_list_nothrow (insert_mode
);
7812 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7814 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7817 /* See breakpoint.h. */
7820 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7822 struct breakpoint
*b
;
7824 /* Explicitly tell update_global_location_list to insert
7826 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7827 if (!b
->loc
->inserted
)
7829 delete_breakpoint (b
);
7835 /* Disable any breakpoints that are on code in shared libraries. Only
7836 apply to enabled breakpoints, disabled ones can just stay disabled. */
7839 disable_breakpoints_in_shlibs (void)
7841 for (bp_location
*loc
: all_bp_locations ())
7843 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7844 struct breakpoint
*b
= loc
->owner
;
7846 /* We apply the check to all breakpoints, including disabled for
7847 those with loc->duplicate set. This is so that when breakpoint
7848 becomes enabled, or the duplicate is removed, gdb will try to
7849 insert all breakpoints. If we don't set shlib_disabled here,
7850 we'll try to insert those breakpoints and fail. */
7851 if (((b
->type
== bp_breakpoint
)
7852 || (b
->type
== bp_jit_event
)
7853 || (b
->type
== bp_hardware_breakpoint
)
7854 || (is_tracepoint (b
)))
7855 && loc
->pspace
== current_program_space
7856 && !loc
->shlib_disabled
7857 && solib_name_from_address (loc
->pspace
, loc
->address
)
7860 loc
->shlib_disabled
= 1;
7865 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7866 notification of unloaded_shlib. Only apply to enabled breakpoints,
7867 disabled ones can just stay disabled. */
7870 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7872 bool disabled_shlib_breaks
= false;
7874 for (bp_location
*loc
: all_bp_locations ())
7876 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7877 struct breakpoint
*b
= loc
->owner
;
7879 if (solib
->pspace
== loc
->pspace
7880 && !loc
->shlib_disabled
7881 && (((b
->type
== bp_breakpoint
7882 || b
->type
== bp_jit_event
7883 || b
->type
== bp_hardware_breakpoint
)
7884 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7885 || loc
->loc_type
== bp_loc_software_breakpoint
))
7886 || is_tracepoint (b
))
7887 && solib_contains_address_p (solib
, loc
->address
))
7889 loc
->shlib_disabled
= 1;
7890 /* At this point, we cannot rely on remove_breakpoint
7891 succeeding so we must mark the breakpoint as not inserted
7892 to prevent future errors occurring in remove_breakpoints. */
7895 /* This may cause duplicate notifications for the same breakpoint. */
7896 gdb::observers::breakpoint_modified
.notify (b
);
7898 if (!disabled_shlib_breaks
)
7900 target_terminal::ours_for_output ();
7901 warning (_("Temporarily disabling breakpoints "
7902 "for unloaded shared library \"%s\""),
7905 disabled_shlib_breaks
= true;
7910 /* Disable any breakpoints and tracepoints in OBJFILE upon
7911 notification of free_objfile. Only apply to enabled breakpoints,
7912 disabled ones can just stay disabled. */
7915 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7917 if (objfile
== NULL
)
7920 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7921 managed by the user with add-symbol-file/remove-symbol-file.
7922 Similarly to how breakpoints in shared libraries are handled in
7923 response to "nosharedlibrary", mark breakpoints in such modules
7924 shlib_disabled so they end up uninserted on the next global
7925 location list update. Shared libraries not loaded by the user
7926 aren't handled here -- they're already handled in
7927 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7928 solib_unloaded observer. We skip objfiles that are not
7929 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7931 if ((objfile
->flags
& OBJF_SHARED
) == 0
7932 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7935 for (breakpoint
*b
: all_breakpoints ())
7937 bool bp_modified
= false;
7939 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7942 for (bp_location
*loc
: b
->locations ())
7944 CORE_ADDR loc_addr
= loc
->address
;
7946 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7947 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7950 if (loc
->shlib_disabled
!= 0)
7953 if (objfile
->pspace
!= loc
->pspace
)
7956 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7957 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7960 if (is_addr_in_objfile (loc_addr
, objfile
))
7962 loc
->shlib_disabled
= 1;
7963 /* At this point, we don't know whether the object was
7964 unmapped from the inferior or not, so leave the
7965 inserted flag alone. We'll handle failure to
7966 uninsert quietly, in case the object was indeed
7969 mark_breakpoint_location_modified (loc
);
7976 gdb::observers::breakpoint_modified
.notify (b
);
7980 /* See breakpoint.h. */
7982 breakpoint::breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
7983 bool temp
, const char *cond_string_
)
7985 disposition (temp
? disp_del
: disp_donttouch
),
7987 language (current_language
->la_language
),
7988 input_radix (::input_radix
),
7989 cond_string (cond_string_
!= nullptr
7990 ? make_unique_xstrdup (cond_string_
)
7992 related_breakpoint (this)
7996 /* See breakpoint.h. */
7998 catchpoint::catchpoint (struct gdbarch
*gdbarch
, bool temp
,
7999 const char *cond_string
)
8000 : breakpoint (gdbarch
, bp_catchpoint
, temp
, cond_string
)
8002 add_dummy_location (this, current_program_space
);
8004 pspace
= current_program_space
;
8008 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8010 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8011 set_breakpoint_number (internal
, b
);
8012 if (is_tracepoint (b
))
8013 set_tracepoint_count (breakpoint_count
);
8016 gdb::observers::breakpoint_created
.notify (b
);
8019 update_global_location_list (UGLL_MAY_INSERT
);
8025 hw_breakpoint_used_count (void)
8029 for (breakpoint
*b
: all_breakpoints ())
8030 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8031 for (bp_location
*bl
: b
->locations ())
8033 /* Special types of hardware breakpoints may use more than
8035 i
+= b
->resources_needed (bl
);
8041 /* Returns the resources B would use if it were a hardware
8045 hw_watchpoint_use_count (struct breakpoint
*b
)
8049 if (!breakpoint_enabled (b
))
8052 for (bp_location
*bl
: b
->locations ())
8054 /* Special types of hardware watchpoints may use more than
8056 i
+= b
->resources_needed (bl
);
8062 /* Returns the sum the used resources of all hardware watchpoints of
8063 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8064 the sum of the used resources of all hardware watchpoints of other
8065 types _not_ TYPE. */
8068 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8069 enum bptype type
, int *other_type_used
)
8073 *other_type_used
= 0;
8074 for (breakpoint
*b
: all_breakpoints ())
8078 if (!breakpoint_enabled (b
))
8081 if (b
->type
== type
)
8082 i
+= hw_watchpoint_use_count (b
);
8083 else if (is_hardware_watchpoint (b
))
8084 *other_type_used
= 1;
8091 disable_watchpoints_before_interactive_call_start (void)
8093 for (breakpoint
*b
: all_breakpoints ())
8094 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8096 b
->enable_state
= bp_call_disabled
;
8097 update_global_location_list (UGLL_DONT_INSERT
);
8102 enable_watchpoints_after_interactive_call_stop (void)
8104 for (breakpoint
*b
: all_breakpoints ())
8105 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8107 b
->enable_state
= bp_enabled
;
8108 update_global_location_list (UGLL_MAY_INSERT
);
8113 disable_breakpoints_before_startup (void)
8115 current_program_space
->executing_startup
= 1;
8116 update_global_location_list (UGLL_DONT_INSERT
);
8120 enable_breakpoints_after_startup (void)
8122 current_program_space
->executing_startup
= 0;
8123 breakpoint_re_set ();
8126 /* Allocate a new momentary breakpoint. */
8128 template<typename
... Arg
>
8129 static momentary_breakpoint
*
8130 new_momentary_breakpoint (struct gdbarch
*gdbarch
, enum bptype type
,
8133 if (type
== bp_longjmp
|| type
== bp_exception
)
8134 return new longjmp_breakpoint (gdbarch
, type
,
8135 std::forward
<Arg
> (args
)...);
8137 return new momentary_breakpoint (gdbarch
, type
,
8138 std::forward
<Arg
> (args
)...);
8141 /* Set a momentary breakpoint of type TYPE at address specified by
8142 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8146 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8147 struct frame_id frame_id
, enum bptype type
)
8149 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8151 gdb_assert (!frame_id_artificial_p (frame_id
));
8153 std::unique_ptr
<momentary_breakpoint
> b
8154 (new_momentary_breakpoint (gdbarch
, type
, sal
.pspace
, frame_id
,
8155 inferior_thread ()->global_num
));
8157 b
->add_location (sal
);
8159 breakpoint_up
bp (add_to_breakpoint_chain (std::move (b
)));
8161 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8166 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8167 The new breakpoint will have type TYPE, use OPS as its
8168 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8170 static struct breakpoint
*
8171 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8176 std::unique_ptr
<breakpoint
> copy
8177 (new_momentary_breakpoint (orig
->gdbarch
, type
, orig
->pspace
,
8178 orig
->frame_id
, thread
));
8179 copy
->loc
= copy
->allocate_location ();
8180 set_breakpoint_location_function (copy
->loc
);
8182 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8183 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8184 copy
->loc
->address
= orig
->loc
->address
;
8185 copy
->loc
->section
= orig
->loc
->section
;
8186 copy
->loc
->pspace
= orig
->loc
->pspace
;
8187 copy
->loc
->probe
= orig
->loc
->probe
;
8188 copy
->loc
->line_number
= orig
->loc
->line_number
;
8189 copy
->loc
->symtab
= orig
->loc
->symtab
;
8190 copy
->loc
->enabled
= loc_enabled
;
8192 breakpoint
*b
= add_to_breakpoint_chain (std::move (copy
));
8193 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8197 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8201 clone_momentary_breakpoint (struct breakpoint
*orig
)
8203 /* If there's nothing to clone, then return nothing. */
8207 return momentary_breakpoint_from_master (orig
, orig
->type
, 0,
8212 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8215 struct symtab_and_line sal
;
8217 sal
= find_pc_line (pc
, 0);
8219 sal
.section
= find_pc_overlay (pc
);
8220 sal
.explicit_pc
= 1;
8222 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8226 /* Tell the user we have just set a breakpoint B. */
8229 mention (const breakpoint
*b
)
8231 b
->print_mention ();
8232 current_uiout
->text ("\n");
8236 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8238 /* Handle "set breakpoint auto-hw on".
8240 If the explicitly specified breakpoint type is not hardware
8241 breakpoint, check the memory map to see whether the breakpoint
8242 address is in read-only memory.
8244 - location type is not hardware breakpoint, memory is read-only.
8245 We change the type of the location to hardware breakpoint.
8247 - location type is hardware breakpoint, memory is read-write. This
8248 means we've previously made the location hardware one, but then the
8249 memory map changed, so we undo.
8253 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8255 if (automatic_hardware_breakpoints
8256 && bl
->owner
->type
!= bp_hardware_breakpoint
8257 && (bl
->loc_type
== bp_loc_software_breakpoint
8258 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8260 /* When breakpoints are removed, remove_breakpoints will use
8261 location types we've just set here, the only possible problem
8262 is that memory map has changed during running program, but
8263 it's not going to work anyway with current gdb. */
8264 mem_region
*mr
= lookup_mem_region (bl
->address
);
8268 enum bp_loc_type new_type
;
8270 if (mr
->attrib
.mode
!= MEM_RW
)
8271 new_type
= bp_loc_hardware_breakpoint
;
8273 new_type
= bp_loc_software_breakpoint
;
8275 if (new_type
!= bl
->loc_type
)
8277 static bool said
= false;
8279 bl
->loc_type
= new_type
;
8282 gdb_printf (_("Note: automatically using "
8283 "hardware breakpoints for "
8284 "read-only addresses.\n"));
8293 code_breakpoint::add_location (const symtab_and_line
&sal
)
8295 struct bp_location
*new_loc
, **tmp
;
8296 CORE_ADDR adjusted_address
;
8297 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8299 if (loc_gdbarch
== NULL
)
8300 loc_gdbarch
= gdbarch
;
8302 /* Adjust the breakpoint's address prior to allocating a location.
8303 Once we call allocate_location(), that mostly uninitialized
8304 location will be placed on the location chain. Adjustment of the
8305 breakpoint may cause target_read_memory() to be called and we do
8306 not want its scan of the location chain to find a breakpoint and
8307 location that's only been partially initialized. */
8308 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8312 /* Sort the locations by their ADDRESS. */
8313 new_loc
= allocate_location ();
8314 for (tmp
= &(loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8315 tmp
= &((*tmp
)->next
))
8317 new_loc
->next
= *tmp
;
8320 new_loc
->requested_address
= sal
.pc
;
8321 new_loc
->address
= adjusted_address
;
8322 new_loc
->pspace
= sal
.pspace
;
8323 new_loc
->probe
.prob
= sal
.prob
;
8324 new_loc
->probe
.objfile
= sal
.objfile
;
8325 gdb_assert (new_loc
->pspace
!= NULL
);
8326 new_loc
->section
= sal
.section
;
8327 new_loc
->gdbarch
= loc_gdbarch
;
8328 new_loc
->line_number
= sal
.line
;
8329 new_loc
->symtab
= sal
.symtab
;
8330 new_loc
->symbol
= sal
.symbol
;
8331 new_loc
->msymbol
= sal
.msymbol
;
8332 new_loc
->objfile
= sal
.objfile
;
8334 set_breakpoint_location_function (new_loc
);
8336 /* While by definition, permanent breakpoints are already present in the
8337 code, we don't mark the location as inserted. Normally one would expect
8338 that GDB could rely on that breakpoint instruction to stop the program,
8339 thus removing the need to insert its own breakpoint, except that executing
8340 the breakpoint instruction can kill the target instead of reporting a
8341 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8342 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8343 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8344 breakpoint be inserted normally results in QEMU knowing about the GDB
8345 breakpoint, and thus trap before the breakpoint instruction is executed.
8346 (If GDB later needs to continue execution past the permanent breakpoint,
8347 it manually increments the PC, thus avoiding executing the breakpoint
8349 if (bp_loc_is_permanent (new_loc
))
8350 new_loc
->permanent
= 1;
8356 /* Return true if LOC is pointing to a permanent breakpoint,
8357 return false otherwise. */
8360 bp_loc_is_permanent (struct bp_location
*loc
)
8362 gdb_assert (loc
!= NULL
);
8364 /* If we have a non-breakpoint-backed catchpoint or a software
8365 watchpoint, just return 0. We should not attempt to read from
8366 the addresses the locations of these breakpoint types point to.
8367 gdbarch_program_breakpoint_here_p, below, will attempt to read
8369 if (!bl_address_is_meaningful (loc
))
8372 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8373 switch_to_program_space_and_thread (loc
->pspace
);
8374 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8377 /* Build a command list for the dprintf corresponding to the current
8378 settings of the dprintf style options. */
8381 update_dprintf_command_list (struct breakpoint
*b
)
8383 const char *dprintf_args
= b
->extra_string
.get ();
8384 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8389 dprintf_args
= skip_spaces (dprintf_args
);
8391 /* Allow a comma, as it may have terminated a location, but don't
8393 if (*dprintf_args
== ',')
8395 dprintf_args
= skip_spaces (dprintf_args
);
8397 if (*dprintf_args
!= '"')
8398 error (_("Bad format string, missing '\"'."));
8400 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8401 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8402 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8404 if (dprintf_function
.empty ())
8405 error (_("No function supplied for dprintf call"));
8407 if (!dprintf_channel
.empty ())
8408 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8409 dprintf_function
.c_str (),
8410 dprintf_channel
.c_str (),
8413 printf_line
= xstrprintf ("call (void) %s (%s)",
8414 dprintf_function
.c_str (),
8417 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8419 if (target_can_run_breakpoint_commands ())
8420 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8423 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8424 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8428 internal_error (_("Invalid dprintf style."));
8430 gdb_assert (printf_line
!= NULL
);
8432 /* Manufacture a printf sequence. */
8433 struct command_line
*printf_cmd_line
8434 = new struct command_line (simple_control
, printf_line
.release ());
8435 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8436 command_lines_deleter ()));
8439 /* Update all dprintf commands, making their command lists reflect
8440 current style settings. */
8443 update_dprintf_commands (const char *args
, int from_tty
,
8444 struct cmd_list_element
*c
)
8446 for (breakpoint
*b
: all_breakpoints ())
8447 if (b
->type
== bp_dprintf
)
8448 update_dprintf_command_list (b
);
8451 code_breakpoint::code_breakpoint (struct gdbarch
*gdbarch_
,
8453 gdb::array_view
<const symtab_and_line
> sals
,
8454 location_spec_up
&&locspec_
,
8455 gdb::unique_xmalloc_ptr
<char> filter_
,
8456 gdb::unique_xmalloc_ptr
<char> cond_string_
,
8457 gdb::unique_xmalloc_ptr
<char> extra_string_
,
8458 enum bpdisp disposition_
,
8459 int thread_
, int task_
, int ignore_count_
,
8461 int enabled_
, unsigned flags
,
8462 int display_canonical_
)
8463 : breakpoint (gdbarch_
, type_
)
8467 if (type
== bp_hardware_breakpoint
)
8469 int target_resources_ok
;
8471 i
= hw_breakpoint_used_count ();
8472 target_resources_ok
=
8473 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8475 if (target_resources_ok
== 0)
8476 error (_("No hardware breakpoint support in the target."));
8477 else if (target_resources_ok
< 0)
8478 error (_("Hardware breakpoints used exceeds limit."));
8481 gdb_assert (!sals
.empty ());
8483 /* At most one of thread or task can be set on any breakpoint. */
8484 gdb_assert (thread
== -1 || task
== -1);
8488 cond_string
= std::move (cond_string_
);
8489 extra_string
= std::move (extra_string_
);
8490 ignore_count
= ignore_count_
;
8491 enable_state
= enabled_
? bp_enabled
: bp_disabled
;
8492 disposition
= disposition_
;
8494 if (type
== bp_static_tracepoint
8495 || type
== bp_static_marker_tracepoint
)
8497 auto *t
= gdb::checked_static_cast
<struct tracepoint
*> (this);
8498 struct static_tracepoint_marker marker
;
8500 if (strace_marker_p (this))
8502 /* We already know the marker exists, otherwise, we wouldn't
8503 see a sal for it. */
8504 const char *p
= &locspec_
->to_string ()[3];
8507 p
= skip_spaces (p
);
8509 endp
= skip_to_space (p
);
8511 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8513 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8514 t
->static_trace_marker_id
.c_str ());
8516 else if (target_static_tracepoint_marker_at (sals
[0].pc
, &marker
))
8518 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8520 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8521 t
->static_trace_marker_id
.c_str ());
8524 warning (_("Couldn't determine the static tracepoint marker to probe"));
8527 for (const auto &sal
: sals
)
8531 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8532 if (loc_gdbarch
== nullptr)
8533 loc_gdbarch
= gdbarch
;
8535 describe_other_breakpoints (loc_gdbarch
,
8536 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8539 bp_location
*new_loc
= add_location (sal
);
8540 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8541 new_loc
->inserted
= 1;
8543 /* Do not set breakpoint locations conditions yet. As locations
8544 are inserted, they get sorted based on their addresses. Let
8545 the list stabilize to have reliable location numbers. */
8547 /* Dynamic printf requires and uses additional arguments on the
8548 command line, otherwise it's an error. */
8549 if (type
== bp_dprintf
)
8551 if (extra_string
!= nullptr)
8552 update_dprintf_command_list (this);
8554 error (_("Format string required"));
8556 else if (extra_string
!= nullptr)
8557 error (_("Garbage '%s' at end of command"), extra_string
.get ());
8560 /* The order of the locations is now stable. Set the location
8561 condition using the location's number. */
8563 for (bp_location
*bl
: locations ())
8565 if (cond_string
!= nullptr)
8566 set_breakpoint_location_condition (cond_string
.get (), bl
,
8572 display_canonical
= display_canonical_
;
8573 if (locspec_
!= nullptr)
8574 locspec
= std::move (locspec_
);
8576 locspec
= new_address_location_spec (this->loc
->address
, NULL
, 0);
8577 filter
= std::move (filter_
);
8581 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8582 gdb::array_view
<const symtab_and_line
> sals
,
8583 location_spec_up
&&locspec
,
8584 gdb::unique_xmalloc_ptr
<char> filter
,
8585 gdb::unique_xmalloc_ptr
<char> cond_string
,
8586 gdb::unique_xmalloc_ptr
<char> extra_string
,
8587 enum bptype type
, enum bpdisp disposition
,
8588 int thread
, int task
, int ignore_count
,
8590 int enabled
, int internal
, unsigned flags
,
8591 int display_canonical
)
8593 std::unique_ptr
<code_breakpoint
> b
8594 = new_breakpoint_from_type (gdbarch
,
8597 std::move (locspec
),
8599 std::move (cond_string
),
8600 std::move (extra_string
),
8602 thread
, task
, ignore_count
,
8607 install_breakpoint (internal
, std::move (b
), 0);
8610 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8611 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8612 value. COND_STRING, if not NULL, specified the condition to be
8613 used for all breakpoints. Essentially the only case where
8614 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8615 function. In that case, it's still not possible to specify
8616 separate conditions for different overloaded functions, so
8617 we take just a single condition string.
8619 NOTE: If the function succeeds, the caller is expected to cleanup
8620 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8621 array contents). If the function fails (error() is called), the
8622 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8623 COND and SALS arrays and each of those arrays contents. */
8626 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8627 struct linespec_result
*canonical
,
8628 gdb::unique_xmalloc_ptr
<char> cond_string
,
8629 gdb::unique_xmalloc_ptr
<char> extra_string
,
8630 enum bptype type
, enum bpdisp disposition
,
8631 int thread
, int task
, int ignore_count
,
8633 int enabled
, int internal
, unsigned flags
)
8635 if (canonical
->pre_expanded
)
8636 gdb_assert (canonical
->lsals
.size () == 1);
8638 for (const auto &lsal
: canonical
->lsals
)
8640 /* Note that 'location' can be NULL in the case of a plain
8641 'break', without arguments. */
8642 location_spec_up locspec
8643 = (canonical
->locspec
!= nullptr
8644 ? canonical
->locspec
->clone ()
8646 gdb::unique_xmalloc_ptr
<char> filter_string
8647 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8649 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8650 std::move (locspec
),
8651 std::move (filter_string
),
8652 std::move (cond_string
),
8653 std::move (extra_string
),
8655 thread
, task
, ignore_count
,
8656 from_tty
, enabled
, internal
, flags
,
8657 canonical
->special_display
);
8661 /* Parse LOCSPEC which is assumed to be a SAL specification possibly
8662 followed by conditionals. On return, SALS contains an array of SAL
8663 addresses found. LOCSPEC points to the end of the SAL (for
8666 The array and the line spec strings are allocated on the heap, it is
8667 the caller's responsibility to free them. */
8670 parse_breakpoint_sals (location_spec
*locspec
,
8671 struct linespec_result
*canonical
)
8673 struct symtab_and_line cursal
;
8675 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8677 const char *spec
= as_linespec_location_spec (locspec
)->spec_string
;
8681 /* The last displayed codepoint, if it's valid, is our default
8682 breakpoint address. */
8683 if (last_displayed_sal_is_valid ())
8685 /* Set sal's pspace, pc, symtab, and line to the values
8686 corresponding to the last call to print_frame_info.
8687 Be sure to reinitialize LINE with NOTCURRENT == 0
8688 as the breakpoint line number is inappropriate otherwise.
8689 find_pc_line would adjust PC, re-set it back. */
8690 symtab_and_line sal
= get_last_displayed_sal ();
8691 CORE_ADDR pc
= sal
.pc
;
8693 sal
= find_pc_line (pc
, 0);
8695 /* "break" without arguments is equivalent to "break *PC"
8696 where PC is the last displayed codepoint's address. So
8697 make sure to set sal.explicit_pc to prevent GDB from
8698 trying to expand the list of sals to include all other
8699 instances with the same symtab and line. */
8701 sal
.explicit_pc
= 1;
8703 struct linespec_sals lsal
;
8705 lsal
.canonical
= NULL
;
8707 canonical
->lsals
.push_back (std::move (lsal
));
8711 error (_("No default breakpoint address now."));
8715 /* Force almost all breakpoints to be in terms of the
8716 current_source_symtab (which is decode_line_1's default).
8717 This should produce the results we want almost all of the
8718 time while leaving default_breakpoint_* alone.
8720 ObjC: However, don't match an Objective-C method name which
8721 may have a '+' or '-' succeeded by a '['. */
8722 cursal
= get_current_source_symtab_and_line ();
8723 if (last_displayed_sal_is_valid ())
8725 const char *spec
= NULL
;
8727 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8728 spec
= as_linespec_location_spec (locspec
)->spec_string
;
8732 && strchr ("+-", spec
[0]) != NULL
8735 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8736 get_last_displayed_symtab (),
8737 get_last_displayed_line (),
8738 canonical
, NULL
, NULL
);
8743 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8744 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8748 /* Convert each SAL into a real PC. Verify that the PC can be
8749 inserted as a breakpoint. If it can't throw an error. */
8752 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8754 for (auto &sal
: sals
)
8755 resolve_sal_pc (&sal
);
8758 /* Fast tracepoints may have restrictions on valid locations. For
8759 instance, a fast tracepoint using a jump instead of a trap will
8760 likely have to overwrite more bytes than a trap would, and so can
8761 only be placed where the instruction is longer than the jump, or a
8762 multi-instruction sequence does not have a jump into the middle of
8766 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8767 gdb::array_view
<const symtab_and_line
> sals
)
8769 for (const auto &sal
: sals
)
8771 struct gdbarch
*sarch
;
8773 sarch
= get_sal_arch (sal
);
8774 /* We fall back to GDBARCH if there is no architecture
8775 associated with SAL. */
8779 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8780 error (_("May not have a fast tracepoint at %s%s"),
8781 paddress (sarch
, sal
.pc
), msg
.c_str ());
8785 /* Given TOK, a string specification of condition and thread, as
8786 accepted by the 'break' command, extract the condition
8787 string and thread number and set *COND_STRING and *THREAD.
8788 PC identifies the context at which the condition should be parsed.
8789 If no condition is found, *COND_STRING is set to NULL.
8790 If no thread is found, *THREAD is set to -1. */
8793 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8794 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8795 int *thread
, int *task
,
8796 gdb::unique_xmalloc_ptr
<char> *rest
)
8798 cond_string
->reset ();
8806 const char *end_tok
;
8808 const char *cond_start
= NULL
;
8809 const char *cond_end
= NULL
;
8811 tok
= skip_spaces (tok
);
8813 if ((*tok
== '"' || *tok
== ',') && rest
)
8815 rest
->reset (savestring (tok
, strlen (tok
)));
8819 end_tok
= skip_to_space (tok
);
8821 toklen
= end_tok
- tok
;
8823 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8825 tok
= cond_start
= end_tok
+ 1;
8828 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8830 catch (const gdb_exception_error
&)
8835 tok
= tok
+ strlen (tok
);
8838 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8840 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8845 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8848 struct thread_info
*thr
;
8851 error(_("You can specify only one thread."));
8854 error (_("You can specify only one of thread or task."));
8857 thr
= parse_thread_id (tok
, &tmptok
);
8859 error (_("Junk after thread keyword."));
8860 *thread
= thr
->global_num
;
8863 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8868 error(_("You can specify only one task."));
8871 error (_("You can specify only one of thread or task."));
8874 *task
= strtol (tok
, &tmptok
, 0);
8876 error (_("Junk after task keyword."));
8877 if (!valid_task_id (*task
))
8878 error (_("Unknown task %d."), *task
);
8883 rest
->reset (savestring (tok
, strlen (tok
)));
8887 error (_("Junk at end of arguments."));
8891 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8892 succeeds. The parsed values are written to COND_STRING, THREAD,
8893 TASK, and REST. See the comment of 'find_condition_and_thread'
8894 for the description of these parameters and INPUT. */
8897 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8899 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8900 int *thread
, int *task
,
8901 gdb::unique_xmalloc_ptr
<char> *rest
)
8903 int num_failures
= 0;
8904 for (auto &sal
: sals
)
8906 gdb::unique_xmalloc_ptr
<char> cond
;
8909 gdb::unique_xmalloc_ptr
<char> remaining
;
8911 /* Here we want to parse 'arg' to separate condition from thread
8912 number. But because parsing happens in a context and the
8913 contexts of sals might be different, try each until there is
8914 success. Finding one successful parse is sufficient for our
8915 goal. When setting the breakpoint we'll re-parse the
8916 condition in the context of each sal. */
8919 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8920 &task_id
, &remaining
);
8921 *cond_string
= std::move (cond
);
8922 /* At most one of thread or task can be set. */
8923 gdb_assert (thread_id
== -1 || task_id
== -1);
8924 *thread
= thread_id
;
8926 *rest
= std::move (remaining
);
8929 catch (const gdb_exception_error
&e
)
8932 /* If no sal remains, do not continue. */
8933 if (num_failures
== sals
.size ())
8939 /* Decode a static tracepoint marker spec. */
8941 static std::vector
<symtab_and_line
>
8942 decode_static_tracepoint_spec (const char **arg_p
)
8944 const char *p
= &(*arg_p
)[3];
8947 p
= skip_spaces (p
);
8949 endp
= skip_to_space (p
);
8951 std::string
marker_str (p
, endp
- p
);
8953 std::vector
<static_tracepoint_marker
> markers
8954 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8955 if (markers
.empty ())
8956 error (_("No known static tracepoint marker named %s"),
8957 marker_str
.c_str ());
8959 std::vector
<symtab_and_line
> sals
;
8960 sals
.reserve (markers
.size ());
8962 for (const static_tracepoint_marker
&marker
: markers
)
8964 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8965 sal
.pc
= marker
.address
;
8966 sals
.push_back (sal
);
8973 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8974 according to IS_TRACEPOINT. */
8976 static const struct breakpoint_ops
*
8977 breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type
,
8982 if (locspec_type
== PROBE_LOCATION_SPEC
)
8983 return &tracepoint_probe_breakpoint_ops
;
8985 return &code_breakpoint_ops
;
8989 if (locspec_type
== PROBE_LOCATION_SPEC
)
8990 return &bkpt_probe_breakpoint_ops
;
8992 return &code_breakpoint_ops
;
8996 /* See breakpoint.h. */
8998 const struct breakpoint_ops
*
8999 breakpoint_ops_for_location_spec (const location_spec
*locspec
,
9002 if (locspec
!= nullptr)
9003 return (breakpoint_ops_for_location_spec_type
9004 (locspec
->type (), is_tracepoint
));
9005 return &code_breakpoint_ops
;
9008 /* See breakpoint.h. */
9011 create_breakpoint (struct gdbarch
*gdbarch
,
9012 location_spec
*locspec
,
9013 const char *cond_string
,
9014 int thread
, const char *extra_string
,
9015 bool force_condition
, int parse_extra
,
9016 int tempflag
, enum bptype type_wanted
,
9018 enum auto_boolean pending_break_support
,
9019 const struct breakpoint_ops
*ops
,
9020 int from_tty
, int enabled
, int internal
,
9023 struct linespec_result canonical
;
9024 bool pending
= false;
9026 int prev_bkpt_count
= breakpoint_count
;
9028 gdb_assert (ops
!= NULL
);
9030 /* If extra_string isn't useful, set it to NULL. */
9031 if (extra_string
!= NULL
&& *extra_string
== '\0')
9032 extra_string
= NULL
;
9036 ops
->create_sals_from_location_spec (locspec
, &canonical
);
9038 catch (const gdb_exception_error
&e
)
9040 /* If caller is interested in rc value from parse, set
9042 if (e
.error
== NOT_FOUND_ERROR
)
9044 /* If pending breakpoint support is turned off, throw
9047 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9050 exception_print (gdb_stderr
, e
);
9052 /* If pending breakpoint support is auto query and the user
9053 selects no, then simply return the error code. */
9054 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9055 && !nquery (_("Make %s pending on future shared library load? "),
9056 bptype_string (type_wanted
)))
9059 /* At this point, either the user was queried about setting
9060 a pending breakpoint and selected yes, or pending
9061 breakpoint behavior is on and thus a pending breakpoint
9062 is defaulted on behalf of the user. */
9069 if (!pending
&& canonical
.lsals
.empty ())
9072 /* Resolve all line numbers to PC's and verify that the addresses
9073 are ok for the target. */
9076 for (auto &lsal
: canonical
.lsals
)
9077 breakpoint_sals_to_pc (lsal
.sals
);
9080 /* Fast tracepoints may have additional restrictions on location. */
9081 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9083 for (const auto &lsal
: canonical
.lsals
)
9084 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9087 /* Verify that condition can be parsed, before setting any
9088 breakpoints. Allocate a separate condition expression for each
9092 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9093 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9097 gdb::unique_xmalloc_ptr
<char> rest
;
9098 gdb::unique_xmalloc_ptr
<char> cond
;
9100 const linespec_sals
&lsal
= canonical
.lsals
[0];
9102 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9103 &cond
, &thread
, &task
, &rest
);
9104 cond_string_copy
= std::move (cond
);
9105 extra_string_copy
= std::move (rest
);
9109 if (type_wanted
!= bp_dprintf
9110 && extra_string
!= NULL
&& *extra_string
!= '\0')
9111 error (_("Garbage '%s' at end of location"), extra_string
);
9113 /* Check the validity of the condition. We should error out
9114 if the condition is invalid at all of the locations and
9115 if it is not forced. In the PARSE_EXTRA case above, this
9116 check is done when parsing the EXTRA_STRING. */
9117 if (cond_string
!= nullptr && !force_condition
)
9119 int num_failures
= 0;
9120 const linespec_sals
&lsal
= canonical
.lsals
[0];
9121 for (const auto &sal
: lsal
.sals
)
9123 const char *cond
= cond_string
;
9126 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9127 /* One success is sufficient to keep going. */
9130 catch (const gdb_exception_error
&)
9133 /* If this is the last sal, error out. */
9134 if (num_failures
== lsal
.sals
.size ())
9140 /* Create a private copy of condition string. */
9142 cond_string_copy
.reset (xstrdup (cond_string
));
9143 /* Create a private copy of any extra string. */
9145 extra_string_copy
.reset (xstrdup (extra_string
));
9148 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9149 std::move (cond_string_copy
),
9150 std::move (extra_string_copy
),
9152 tempflag
? disp_del
: disp_donttouch
,
9153 thread
, task
, ignore_count
,
9154 from_tty
, enabled
, internal
, flags
);
9158 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
,
9160 b
->locspec
= locspec
->clone ();
9163 b
->cond_string
= NULL
;
9166 /* Create a private copy of condition string. */
9167 b
->cond_string
.reset (cond_string
!= NULL
9168 ? xstrdup (cond_string
)
9173 /* Create a private copy of any extra string. */
9174 b
->extra_string
.reset (extra_string
!= NULL
9175 ? xstrdup (extra_string
)
9177 b
->ignore_count
= ignore_count
;
9178 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9179 b
->condition_not_parsed
= 1;
9180 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9181 if ((type_wanted
!= bp_breakpoint
9182 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9183 b
->pspace
= current_program_space
;
9185 install_breakpoint (internal
, std::move (b
), 0);
9188 if (canonical
.lsals
.size () > 1)
9190 warning (_("Multiple breakpoints were set.\nUse the "
9191 "\"delete\" command to delete unwanted breakpoints."));
9192 prev_breakpoint_count
= prev_bkpt_count
;
9195 update_global_location_list (UGLL_MAY_INSERT
);
9200 /* Set a breakpoint.
9201 ARG is a string describing breakpoint address,
9202 condition, and thread.
9203 FLAG specifies if a breakpoint is hardware on,
9204 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9208 break_command_1 (const char *arg
, int flag
, int from_tty
)
9210 int tempflag
= flag
& BP_TEMPFLAG
;
9211 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9212 ? bp_hardware_breakpoint
9215 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9216 const struct breakpoint_ops
*ops
9217 = breakpoint_ops_for_location_spec (locspec
.get (),
9218 false /* is_tracepoint */);
9220 create_breakpoint (get_current_arch (),
9222 NULL
, 0, arg
, false, 1 /* parse arg */,
9223 tempflag
, type_wanted
,
9224 0 /* Ignore count */,
9225 pending_break_support
,
9233 /* Helper function for break_command_1 and disassemble_command. */
9236 resolve_sal_pc (struct symtab_and_line
*sal
)
9240 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9242 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9243 error (_("No line %d in file \"%s\"."),
9244 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9247 /* If this SAL corresponds to a breakpoint inserted using a line
9248 number, then skip the function prologue if necessary. */
9249 if (sal
->explicit_line
)
9250 skip_prologue_sal (sal
);
9253 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9255 const struct blockvector
*bv
;
9256 const struct block
*b
;
9259 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9260 sal
->symtab
->compunit ());
9263 sym
= b
->linkage_function ();
9266 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9269 /* It really is worthwhile to have the section, so we'll
9270 just have to look harder. This case can be executed
9271 if we have line numbers but no functions (as can
9272 happen in assembly source). */
9274 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9275 switch_to_program_space_and_thread (sal
->pspace
);
9277 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9279 sal
->section
= msym
.obj_section ();
9286 break_command (const char *arg
, int from_tty
)
9288 break_command_1 (arg
, 0, from_tty
);
9292 tbreak_command (const char *arg
, int from_tty
)
9294 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9298 hbreak_command (const char *arg
, int from_tty
)
9300 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9304 thbreak_command (const char *arg
, int from_tty
)
9306 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9309 /* The dynamic printf command is mostly like a regular breakpoint, but
9310 with a prewired command list consisting of a single output command,
9311 built from extra arguments supplied on the dprintf command
9315 dprintf_command (const char *arg
, int from_tty
)
9317 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9319 /* If non-NULL, ARG should have been advanced past the location;
9320 the next character must be ','. */
9323 if (arg
[0] != ',' || arg
[1] == '\0')
9324 error (_("Format string required"));
9327 /* Skip the comma. */
9332 create_breakpoint (get_current_arch (),
9334 NULL
, 0, arg
, false, 1 /* parse arg */,
9336 0 /* Ignore count */,
9337 pending_break_support
,
9338 &code_breakpoint_ops
,
9346 agent_printf_command (const char *arg
, int from_tty
)
9348 error (_("May only run agent-printf on the target"));
9351 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9354 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9355 const address_space
*aspace
,
9357 const target_waitstatus
&ws
)
9359 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9360 || ws
.sig () != GDB_SIGNAL_TRAP
)
9363 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9364 bl
->length
, aspace
, bp_addr
);
9367 /* Implement the "resources_needed" method for ranged breakpoints. */
9370 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9372 return target_ranged_break_num_registers ();
9375 /* Implement the "print_it" method for ranged breakpoints. */
9377 enum print_stop_action
9378 ranged_breakpoint::print_it (const bpstat
*bs
) const
9380 struct bp_location
*bl
= loc
;
9381 struct ui_out
*uiout
= current_uiout
;
9383 gdb_assert (type
== bp_hardware_breakpoint
);
9385 /* Ranged breakpoints have only one location. */
9386 gdb_assert (bl
&& bl
->next
== NULL
);
9388 annotate_breakpoint (number
);
9390 maybe_print_thread_hit_breakpoint (uiout
);
9392 if (disposition
== disp_del
)
9393 uiout
->text ("Temporary ranged breakpoint ");
9395 uiout
->text ("Ranged breakpoint ");
9396 if (uiout
->is_mi_like_p ())
9398 uiout
->field_string ("reason",
9399 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9400 uiout
->field_string ("disp", bpdisp_text (disposition
));
9402 print_num_locno (bs
, uiout
);
9405 return PRINT_SRC_AND_LOC
;
9408 /* Implement the "print_one" method for ranged breakpoints. */
9411 ranged_breakpoint::print_one (bp_location
**last_loc
) const
9413 struct bp_location
*bl
= loc
;
9414 struct value_print_options opts
;
9415 struct ui_out
*uiout
= current_uiout
;
9417 /* Ranged breakpoints have only one location. */
9418 gdb_assert (bl
&& bl
->next
== NULL
);
9420 get_user_print_options (&opts
);
9422 if (opts
.addressprint
)
9423 /* We don't print the address range here, it will be printed later
9424 by ranged_breakpoint::print_one_detail. */
9425 uiout
->field_skip ("addr");
9427 print_breakpoint_location (this, bl
);
9433 /* Implement the "print_one_detail" method for ranged breakpoints. */
9436 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9438 CORE_ADDR address_start
, address_end
;
9439 struct bp_location
*bl
= loc
;
9444 address_start
= bl
->address
;
9445 address_end
= address_start
+ bl
->length
- 1;
9447 uiout
->text ("\taddress range: ");
9448 stb
.printf ("[%s, %s]",
9449 print_core_address (bl
->gdbarch
, address_start
),
9450 print_core_address (bl
->gdbarch
, address_end
));
9451 uiout
->field_stream ("addr", stb
);
9455 /* Implement the "print_mention" method for ranged breakpoints. */
9458 ranged_breakpoint::print_mention () const
9460 struct bp_location
*bl
= loc
;
9461 struct ui_out
*uiout
= current_uiout
;
9464 gdb_assert (type
== bp_hardware_breakpoint
);
9466 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9467 number
, paddress (bl
->gdbarch
, bl
->address
),
9468 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9471 /* Implement the "print_recreate" method for ranged breakpoints. */
9474 ranged_breakpoint::print_recreate (struct ui_file
*fp
) const
9476 gdb_printf (fp
, "break-range %s, %s",
9477 locspec
->to_string (),
9478 locspec_range_end
->to_string ());
9479 print_recreate_thread (fp
);
9482 /* Find the address where the end of the breakpoint range should be
9483 placed, given the SAL of the end of the range. This is so that if
9484 the user provides a line number, the end of the range is set to the
9485 last instruction of the given line. */
9488 find_breakpoint_range_end (struct symtab_and_line sal
)
9492 /* If the user provided a PC value, use it. Otherwise,
9493 find the address of the end of the given location. */
9494 if (sal
.explicit_pc
)
9501 ret
= find_line_pc_range (sal
, &start
, &end
);
9503 error (_("Could not find location of the end of the range."));
9505 /* find_line_pc_range returns the start of the next line. */
9512 /* Implement the "break-range" CLI command. */
9515 break_range_command (const char *arg
, int from_tty
)
9517 const char *arg_start
;
9518 struct linespec_result canonical_start
, canonical_end
;
9519 int bp_count
, can_use_bp
, length
;
9522 /* We don't support software ranged breakpoints. */
9523 if (target_ranged_break_num_registers () < 0)
9524 error (_("This target does not support hardware ranged breakpoints."));
9526 bp_count
= hw_breakpoint_used_count ();
9527 bp_count
+= target_ranged_break_num_registers ();
9528 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9531 error (_("Hardware breakpoints used exceeds limit."));
9533 arg
= skip_spaces (arg
);
9534 if (arg
== NULL
|| arg
[0] == '\0')
9535 error(_("No address range specified."));
9538 location_spec_up start_locspec
9539 = string_to_location_spec (&arg
, current_language
);
9540 parse_breakpoint_sals (start_locspec
.get (), &canonical_start
);
9543 error (_("Too few arguments."));
9544 else if (canonical_start
.lsals
.empty ())
9545 error (_("Could not find location of the beginning of the range."));
9547 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9549 if (canonical_start
.lsals
.size () > 1
9550 || lsal_start
.sals
.size () != 1)
9551 error (_("Cannot create a ranged breakpoint with multiple locations."));
9553 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9554 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9556 arg
++; /* Skip the comma. */
9557 arg
= skip_spaces (arg
);
9559 /* Parse the end location specification. */
9563 /* We call decode_line_full directly here instead of using
9564 parse_breakpoint_sals because we need to specify the start
9565 location spec's symtab and line as the default symtab and line
9566 for the end of the range. This makes it possible to have ranges
9567 like "foo.c:27, +14", where +14 means 14 lines from the start
9569 location_spec_up end_locspec
9570 = string_to_location_spec (&arg
, current_language
);
9571 decode_line_full (end_locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9572 sal_start
.symtab
, sal_start
.line
,
9573 &canonical_end
, NULL
, NULL
);
9575 if (canonical_end
.lsals
.empty ())
9576 error (_("Could not find location of the end of the range."));
9578 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9579 if (canonical_end
.lsals
.size () > 1
9580 || lsal_end
.sals
.size () != 1)
9581 error (_("Cannot create a ranged breakpoint with multiple locations."));
9583 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9585 end
= find_breakpoint_range_end (sal_end
);
9586 if (sal_start
.pc
> end
)
9587 error (_("Invalid address range, end precedes start."));
9589 length
= end
- sal_start
.pc
+ 1;
9591 /* Length overflowed. */
9592 error (_("Address range too large."));
9593 else if (length
== 1)
9595 /* This range is simple enough to be handled by
9596 the `hbreak' command. */
9597 hbreak_command (&addr_string_start
[0], 1);
9602 /* Now set up the breakpoint and install it. */
9604 std::unique_ptr
<breakpoint
> br
9605 (new ranged_breakpoint (get_current_arch (),
9607 std::move (start_locspec
),
9608 std::move (end_locspec
)));
9610 install_breakpoint (false, std::move (br
), true);
9613 /* Return non-zero if EXP is verified as constant. Returned zero
9614 means EXP is variable. Also the constant detection may fail for
9615 some constant expressions and in such case still falsely return
9619 watchpoint_exp_is_const (const struct expression
*exp
)
9621 return exp
->op
->constant_p ();
9624 /* Implement the "re_set" method for watchpoints. */
9627 watchpoint::re_set ()
9629 /* Watchpoint can be either on expression using entirely global
9630 variables, or it can be on local variables.
9632 Watchpoints of the first kind are never auto-deleted, and even
9633 persist across program restarts. Since they can use variables
9634 from shared libraries, we need to reparse expression as libraries
9635 are loaded and unloaded.
9637 Watchpoints on local variables can also change meaning as result
9638 of solib event. For example, if a watchpoint uses both a local
9639 and a global variables in expression, it's a local watchpoint,
9640 but unloading of a shared library will make the expression
9641 invalid. This is not a very common use case, but we still
9642 re-evaluate expression, to avoid surprises to the user.
9644 Note that for local watchpoints, we re-evaluate it only if
9645 watchpoints frame id is still valid. If it's not, it means the
9646 watchpoint is out of scope and will be deleted soon. In fact,
9647 I'm not sure we'll ever be called in this case.
9649 If a local watchpoint's frame id is still valid, then
9650 exp_valid_block is likewise valid, and we can safely use it.
9652 Don't do anything about disabled watchpoints, since they will be
9653 reevaluated again when enabled. */
9654 update_watchpoint (this, true /* reparse */);
9657 /* Implement the "insert" method for hardware watchpoints. */
9660 watchpoint::insert_location (struct bp_location
*bl
)
9662 int length
= exact
? 1 : bl
->length
;
9664 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9668 /* Implement the "remove" method for hardware watchpoints. */
9671 watchpoint::remove_location (struct bp_location
*bl
,
9672 enum remove_bp_reason reason
)
9674 int length
= exact
? 1 : bl
->length
;
9676 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9681 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9682 const address_space
*aspace
, CORE_ADDR bp_addr
,
9683 const target_waitstatus
&ws
)
9685 struct breakpoint
*b
= bl
->owner
;
9687 /* Continuable hardware watchpoints are treated as non-existent if the
9688 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9689 some data address). Otherwise gdb won't stop on a break instruction
9690 in the code (not from a breakpoint) when a hardware watchpoint has
9691 been defined. Also skip watchpoints which we know did not trigger
9692 (did not match the data address). */
9693 if (is_hardware_watchpoint (b
)
9694 && watchpoint_triggered
== watch_triggered_no
)
9701 watchpoint::check_status (bpstat
*bs
)
9703 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9705 bpstat_check_watchpoint (bs
);
9708 /* Implement the "resources_needed" method for hardware
9712 watchpoint::resources_needed (const struct bp_location
*bl
)
9714 int length
= exact
? 1 : bl
->length
;
9716 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9719 /* Implement the "works_in_software_mode" method for hardware
9723 watchpoint::works_in_software_mode () const
9725 /* Read and access watchpoints only work with hardware support. */
9726 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9729 enum print_stop_action
9730 watchpoint::print_it (const bpstat
*bs
) const
9732 struct breakpoint
*b
;
9733 enum print_stop_action result
;
9734 struct ui_out
*uiout
= current_uiout
;
9736 gdb_assert (bs
->bp_location_at
!= NULL
);
9738 b
= bs
->breakpoint_at
;
9740 annotate_watchpoint (b
->number
);
9741 maybe_print_thread_hit_breakpoint (uiout
);
9745 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9749 case bp_hardware_watchpoint
:
9750 if (uiout
->is_mi_like_p ())
9752 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9754 tuple_emitter
.emplace (uiout
, "value");
9755 uiout
->text ("\nOld value = ");
9756 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9757 uiout
->field_stream ("old", stb
);
9758 uiout
->text ("\nNew value = ");
9759 watchpoint_value_print (val
.get (), &stb
);
9760 uiout
->field_stream ("new", stb
);
9762 /* More than one watchpoint may have been triggered. */
9763 result
= PRINT_UNKNOWN
;
9766 case bp_read_watchpoint
:
9767 if (uiout
->is_mi_like_p ())
9769 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9771 tuple_emitter
.emplace (uiout
, "value");
9772 uiout
->text ("\nValue = ");
9773 watchpoint_value_print (val
.get (), &stb
);
9774 uiout
->field_stream ("value", stb
);
9776 result
= PRINT_UNKNOWN
;
9779 case bp_access_watchpoint
:
9780 if (bs
->old_val
!= NULL
)
9782 if (uiout
->is_mi_like_p ())
9785 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9787 tuple_emitter
.emplace (uiout
, "value");
9788 uiout
->text ("\nOld value = ");
9789 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9790 uiout
->field_stream ("old", stb
);
9791 uiout
->text ("\nNew value = ");
9796 if (uiout
->is_mi_like_p ())
9799 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9800 tuple_emitter
.emplace (uiout
, "value");
9801 uiout
->text ("\nValue = ");
9803 watchpoint_value_print (val
.get (), &stb
);
9804 uiout
->field_stream ("new", stb
);
9806 result
= PRINT_UNKNOWN
;
9809 result
= PRINT_UNKNOWN
;
9815 /* Implement the "print_mention" method for hardware watchpoints. */
9818 watchpoint::print_mention () const
9820 struct ui_out
*uiout
= current_uiout
;
9821 const char *tuple_name
;
9826 uiout
->text ("Watchpoint ");
9829 case bp_hardware_watchpoint
:
9830 uiout
->text ("Hardware watchpoint ");
9833 case bp_read_watchpoint
:
9834 uiout
->text ("Hardware read watchpoint ");
9835 tuple_name
= "hw-rwpt";
9837 case bp_access_watchpoint
:
9838 uiout
->text ("Hardware access (read/write) watchpoint ");
9839 tuple_name
= "hw-awpt";
9842 internal_error (_("Invalid hardware watchpoint type."));
9845 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9846 uiout
->field_signed ("number", number
);
9848 uiout
->field_string ("exp", exp_string
.get ());
9851 /* Implement the "print_recreate" method for watchpoints. */
9854 watchpoint::print_recreate (struct ui_file
*fp
) const
9859 case bp_hardware_watchpoint
:
9860 gdb_printf (fp
, "watch");
9862 case bp_read_watchpoint
:
9863 gdb_printf (fp
, "rwatch");
9865 case bp_access_watchpoint
:
9866 gdb_printf (fp
, "awatch");
9869 internal_error (_("Invalid watchpoint type."));
9872 gdb_printf (fp
, " %s", exp_string
.get ());
9873 print_recreate_thread (fp
);
9876 /* Implement the "explains_signal" method for watchpoints. */
9879 watchpoint::explains_signal (enum gdb_signal sig
)
9881 /* A software watchpoint cannot cause a signal other than
9883 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9889 struct masked_watchpoint
: public watchpoint
9891 using watchpoint::watchpoint
;
9893 int insert_location (struct bp_location
*) override
;
9894 int remove_location (struct bp_location
*,
9895 enum remove_bp_reason reason
) override
;
9896 int resources_needed (const struct bp_location
*) override
;
9897 bool works_in_software_mode () const override
;
9898 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
9899 void print_one_detail (struct ui_out
*) const override
;
9900 void print_mention () const override
;
9901 void print_recreate (struct ui_file
*fp
) const override
;
9904 /* Implement the "insert" method for masked hardware watchpoints. */
9907 masked_watchpoint::insert_location (struct bp_location
*bl
)
9909 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9910 bl
->watchpoint_type
);
9913 /* Implement the "remove" method for masked hardware watchpoints. */
9916 masked_watchpoint::remove_location (struct bp_location
*bl
,
9917 enum remove_bp_reason reason
)
9919 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9920 bl
->watchpoint_type
);
9923 /* Implement the "resources_needed" method for masked hardware
9927 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9929 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9932 /* Implement the "works_in_software_mode" method for masked hardware
9936 masked_watchpoint::works_in_software_mode () const
9941 /* Implement the "print_it" method for masked hardware
9944 enum print_stop_action
9945 masked_watchpoint::print_it (const bpstat
*bs
) const
9947 struct breakpoint
*b
= bs
->breakpoint_at
;
9948 struct ui_out
*uiout
= current_uiout
;
9950 /* Masked watchpoints have only one location. */
9951 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9953 annotate_watchpoint (b
->number
);
9954 maybe_print_thread_hit_breakpoint (uiout
);
9958 case bp_hardware_watchpoint
:
9959 if (uiout
->is_mi_like_p ())
9961 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9964 case bp_read_watchpoint
:
9965 if (uiout
->is_mi_like_p ())
9967 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9970 case bp_access_watchpoint
:
9971 if (uiout
->is_mi_like_p ())
9974 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9977 internal_error (_("Invalid hardware watchpoint type."));
9982 Check the underlying instruction at PC for the memory\n\
9983 address and value which triggered this watchpoint.\n"));
9986 /* More than one watchpoint may have been triggered. */
9987 return PRINT_UNKNOWN
;
9990 /* Implement the "print_one_detail" method for masked hardware
9994 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9996 /* Masked watchpoints have only one location. */
9997 gdb_assert (loc
&& loc
->next
== NULL
);
9999 uiout
->text ("\tmask ");
10000 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
10001 uiout
->text ("\n");
10004 /* Implement the "print_mention" method for masked hardware
10008 masked_watchpoint::print_mention () const
10010 struct ui_out
*uiout
= current_uiout
;
10011 const char *tuple_name
;
10015 case bp_hardware_watchpoint
:
10016 uiout
->text ("Masked hardware watchpoint ");
10017 tuple_name
= "wpt";
10019 case bp_read_watchpoint
:
10020 uiout
->text ("Masked hardware read watchpoint ");
10021 tuple_name
= "hw-rwpt";
10023 case bp_access_watchpoint
:
10024 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10025 tuple_name
= "hw-awpt";
10028 internal_error (_("Invalid hardware watchpoint type."));
10031 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10032 uiout
->field_signed ("number", number
);
10033 uiout
->text (": ");
10034 uiout
->field_string ("exp", exp_string
.get ());
10037 /* Implement the "print_recreate" method for masked hardware
10041 masked_watchpoint::print_recreate (struct ui_file
*fp
) const
10045 case bp_hardware_watchpoint
:
10046 gdb_printf (fp
, "watch");
10048 case bp_read_watchpoint
:
10049 gdb_printf (fp
, "rwatch");
10051 case bp_access_watchpoint
:
10052 gdb_printf (fp
, "awatch");
10055 internal_error (_("Invalid hardware watchpoint type."));
10058 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
10059 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
10060 print_recreate_thread (fp
);
10063 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10066 is_masked_watchpoint (const struct breakpoint
*b
)
10068 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
10071 /* accessflag: hw_write: watch write,
10072 hw_read: watch read,
10073 hw_access: watch access (read or write) */
10075 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10076 bool just_location
, bool internal
)
10078 struct breakpoint
*scope_breakpoint
= NULL
;
10079 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10080 struct value
*result
;
10081 int saved_bitpos
= 0, saved_bitsize
= 0;
10082 const char *exp_start
= NULL
;
10083 const char *exp_end
= NULL
;
10084 const char *tok
, *end_tok
;
10086 const char *cond_start
= NULL
;
10087 const char *cond_end
= NULL
;
10088 enum bptype bp_type
;
10090 /* Flag to indicate whether we are going to use masks for
10091 the hardware watchpoint. */
10092 bool use_mask
= false;
10093 CORE_ADDR mask
= 0;
10096 /* Make sure that we actually have parameters to parse. */
10097 if (arg
!= NULL
&& arg
[0] != '\0')
10099 const char *value_start
;
10101 exp_end
= arg
+ strlen (arg
);
10103 /* Look for "parameter value" pairs at the end
10104 of the arguments string. */
10105 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10107 /* Skip whitespace at the end of the argument list. */
10108 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10111 /* Find the beginning of the last token.
10112 This is the value of the parameter. */
10113 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10115 value_start
= tok
+ 1;
10117 /* Skip whitespace. */
10118 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10123 /* Find the beginning of the second to last token.
10124 This is the parameter itself. */
10125 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10128 toklen
= end_tok
- tok
+ 1;
10130 if (toklen
== 6 && startswith (tok
, "thread"))
10132 struct thread_info
*thr
;
10133 /* At this point we've found a "thread" token, which means
10134 the user is trying to set a watchpoint that triggers
10135 only in a specific thread. */
10139 error(_("You can specify only one thread."));
10142 error (_("You can specify only one of thread or task."));
10144 /* Extract the thread ID from the next token. */
10145 thr
= parse_thread_id (value_start
, &endp
);
10147 /* Check if the user provided a valid thread ID. */
10148 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10149 invalid_thread_id_error (value_start
);
10151 thread
= thr
->global_num
;
10153 else if (toklen
== 4 && startswith (tok
, "task"))
10158 error(_("You can specify only one task."));
10161 error (_("You can specify only one of thread or task."));
10163 task
= strtol (value_start
, &tmp
, 0);
10164 if (tmp
== value_start
)
10165 error (_("Junk after task keyword."));
10166 if (!valid_task_id (task
))
10167 error (_("Unknown task %d."), task
);
10169 else if (toklen
== 4 && startswith (tok
, "mask"))
10171 /* We've found a "mask" token, which means the user wants to
10172 create a hardware watchpoint that is going to have the mask
10174 struct value
*mask_value
;
10177 error(_("You can specify only one mask."));
10179 use_mask
= just_location
= true;
10181 scoped_value_mark mark
;
10182 mask_value
= parse_to_comma_and_eval (&value_start
);
10183 mask
= value_as_address (mask_value
);
10186 /* We didn't recognize what we found. We should stop here. */
10189 /* Truncate the string and get rid of the "parameter value" pair before
10190 the arguments string is parsed by the parse_exp_1 function. */
10197 /* Parse the rest of the arguments. From here on out, everything
10198 is in terms of a newly allocated string instead of the original
10200 std::string
expression (arg
, exp_end
- arg
);
10201 exp_start
= arg
= expression
.c_str ();
10202 innermost_block_tracker tracker
;
10203 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10205 /* Remove trailing whitespace from the expression before saving it.
10206 This makes the eventual display of the expression string a bit
10208 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10211 /* Checking if the expression is not constant. */
10212 if (watchpoint_exp_is_const (exp
.get ()))
10216 len
= exp_end
- exp_start
;
10217 while (len
> 0 && isspace (exp_start
[len
- 1]))
10219 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10222 exp_valid_block
= tracker
.block ();
10223 struct value
*mark
= value_mark ();
10224 struct value
*val_as_value
= nullptr;
10225 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10228 if (val_as_value
!= NULL
&& just_location
)
10230 saved_bitpos
= val_as_value
->bitpos ();
10231 saved_bitsize
= val_as_value
->bitsize ();
10239 exp_valid_block
= NULL
;
10240 val
= release_value (value_addr (result
));
10241 value_free_to_mark (mark
);
10245 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10248 error (_("This target does not support masked watchpoints."));
10249 else if (ret
== -2)
10250 error (_("Invalid mask or memory region."));
10253 else if (val_as_value
!= NULL
)
10254 val
= release_value (val_as_value
);
10256 tok
= skip_spaces (arg
);
10257 end_tok
= skip_to_space (tok
);
10259 toklen
= end_tok
- tok
;
10260 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10262 tok
= cond_start
= end_tok
+ 1;
10263 innermost_block_tracker if_tracker
;
10264 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10266 /* The watchpoint expression may not be local, but the condition
10267 may still be. E.g.: `watch global if local > 0'. */
10268 cond_exp_valid_block
= if_tracker
.block ();
10273 error (_("Junk at end of command."));
10275 frame_info_ptr wp_frame
= block_innermost_frame (exp_valid_block
);
10277 /* Save this because create_internal_breakpoint below invalidates
10279 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10281 /* If the expression is "local", then set up a "watchpoint scope"
10282 breakpoint at the point where we've left the scope of the watchpoint
10283 expression. Create the scope breakpoint before the watchpoint, so
10284 that we will encounter it first in bpstat_stop_status. */
10285 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10287 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10289 if (frame_id_p (caller_frame_id
))
10291 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10292 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10295 = create_internal_breakpoint (caller_arch
, caller_pc
,
10296 bp_watchpoint_scope
);
10298 /* create_internal_breakpoint could invalidate WP_FRAME. */
10301 scope_breakpoint
->enable_state
= bp_enabled
;
10303 /* Automatically delete the breakpoint when it hits. */
10304 scope_breakpoint
->disposition
= disp_del
;
10306 /* Only break in the proper frame (help with recursion). */
10307 scope_breakpoint
->frame_id
= caller_frame_id
;
10309 /* Set the address at which we will stop. */
10310 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10311 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10312 scope_breakpoint
->loc
->address
10313 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10314 scope_breakpoint
->loc
->requested_address
,
10315 scope_breakpoint
->type
,
10316 current_program_space
);
10320 /* Now set up the breakpoint. We create all watchpoints as hardware
10321 watchpoints here even if hardware watchpoints are turned off, a call
10322 to update_watchpoint later in this function will cause the type to
10323 drop back to bp_watchpoint (software watchpoint) if required. */
10325 if (accessflag
== hw_read
)
10326 bp_type
= bp_read_watchpoint
;
10327 else if (accessflag
== hw_access
)
10328 bp_type
= bp_access_watchpoint
;
10330 bp_type
= bp_hardware_watchpoint
;
10332 std::unique_ptr
<watchpoint
> w
;
10334 w
.reset (new masked_watchpoint (nullptr, bp_type
));
10336 w
.reset (new watchpoint (nullptr, bp_type
));
10338 /* At most one of thread or task can be set on a watchpoint. */
10339 gdb_assert (thread
== -1 || task
== -1);
10340 w
->thread
= thread
;
10342 w
->disposition
= disp_donttouch
;
10343 w
->pspace
= current_program_space
;
10344 w
->exp
= std::move (exp
);
10345 w
->exp_valid_block
= exp_valid_block
;
10346 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10349 struct type
*t
= val
->type ();
10350 CORE_ADDR addr
= value_as_address (val
.get ());
10352 w
->exp_string_reparse
10353 = current_language
->watch_location_expression (t
, addr
);
10355 w
->exp_string
= xstrprintf ("-location %.*s",
10356 (int) (exp_end
- exp_start
), exp_start
);
10359 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10363 w
->hw_wp_mask
= mask
;
10368 w
->val_bitpos
= saved_bitpos
;
10369 w
->val_bitsize
= saved_bitsize
;
10370 w
->val_valid
= true;
10374 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10376 w
->cond_string
= 0;
10378 if (frame_id_p (watchpoint_frame
))
10380 w
->watchpoint_frame
= watchpoint_frame
;
10381 w
->watchpoint_thread
= inferior_ptid
;
10385 w
->watchpoint_frame
= null_frame_id
;
10386 w
->watchpoint_thread
= null_ptid
;
10389 if (scope_breakpoint
!= NULL
)
10391 /* The scope breakpoint is related to the watchpoint. We will
10392 need to act on them together. */
10393 w
->related_breakpoint
= scope_breakpoint
;
10394 scope_breakpoint
->related_breakpoint
= w
.get ();
10397 if (!just_location
)
10398 value_free_to_mark (mark
);
10400 /* Finally update the new watchpoint. This creates the locations
10401 that should be inserted. */
10402 update_watchpoint (w
.get (), true /* reparse */);
10404 install_breakpoint (internal
, std::move (w
), 1);
10407 /* Return count of debug registers needed to watch the given expression.
10408 If the watchpoint cannot be handled in hardware return zero. */
10411 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10413 int found_memory_cnt
= 0;
10415 /* Did the user specifically forbid us to use hardware watchpoints? */
10416 if (!can_use_hw_watchpoints
)
10419 gdb_assert (!vals
.empty ());
10420 struct value
*head
= vals
[0].get ();
10422 /* Make sure that the value of the expression depends only upon
10423 memory contents, and values computed from them within GDB. If we
10424 find any register references or function calls, we can't use a
10425 hardware watchpoint.
10427 The idea here is that evaluating an expression generates a series
10428 of values, one holding the value of every subexpression. (The
10429 expression a*b+c has five subexpressions: a, b, a*b, c, and
10430 a*b+c.) GDB's values hold almost enough information to establish
10431 the criteria given above --- they identify memory lvalues,
10432 register lvalues, computed values, etcetera. So we can evaluate
10433 the expression, and then scan the chain of values that leaves
10434 behind to decide whether we can detect any possible change to the
10435 expression's final value using only hardware watchpoints.
10437 However, I don't think that the values returned by inferior
10438 function calls are special in any way. So this function may not
10439 notice that an expression involving an inferior function call
10440 can't be watched with hardware watchpoints. FIXME. */
10441 for (const value_ref_ptr
&iter
: vals
)
10443 struct value
*v
= iter
.get ();
10445 if (v
->lval () == lval_memory
)
10447 if (v
!= head
&& v
->lazy ())
10448 /* A lazy memory lvalue in the chain is one that GDB never
10449 needed to fetch; we either just used its address (e.g.,
10450 `a' in `a.b') or we never needed it at all (e.g., `a'
10451 in `a,b'). This doesn't apply to HEAD; if that is
10452 lazy then it was not readable, but watch it anyway. */
10456 /* Ahh, memory we actually used! Check if we can cover
10457 it with hardware watchpoints. */
10458 struct type
*vtype
= check_typedef (v
->type ());
10460 /* We only watch structs and arrays if user asked for it
10461 explicitly, never if they just happen to appear in a
10462 middle of some value chain. */
10464 || (vtype
->code () != TYPE_CODE_STRUCT
10465 && vtype
->code () != TYPE_CODE_ARRAY
))
10467 CORE_ADDR vaddr
= v
->address ();
10471 len
= (target_exact_watchpoints
10472 && is_scalar_type_recursive (vtype
))?
10473 1 : v
->type ()->length ();
10475 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10479 found_memory_cnt
+= num_regs
;
10483 else if (v
->lval () != not_lval
&& !v
->deprecated_modifiable ())
10484 return 0; /* These are values from the history (e.g., $1). */
10485 else if (v
->lval () == lval_register
)
10486 return 0; /* Cannot watch a register with a HW watchpoint. */
10489 /* The expression itself looks suitable for using a hardware
10490 watchpoint, but give the target machine a chance to reject it. */
10491 return found_memory_cnt
;
10495 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10497 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10500 /* Options for the watch, awatch, and rwatch commands. */
10502 struct watch_options
10504 /* For -location. */
10505 bool location
= false;
10508 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10510 Historically GDB always accepted both '-location' and '-l' flags for
10511 these commands (both flags being synonyms). When converting to the
10512 newer option scheme only '-location' is added here. That's fine (for
10513 backward compatibility) as any non-ambiguous prefix of a flag will be
10514 accepted, so '-l', '-loc', are now all accepted.
10516 What this means is that, if in the future, we add any new flag here
10517 that starts with '-l' then this will break backward compatibility, so
10518 please, don't do that! */
10520 static const gdb::option::option_def watch_option_defs
[] = {
10521 gdb::option::flag_option_def
<watch_options
> {
10523 [] (watch_options
*opt
) { return &opt
->location
; },
10525 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10526 -l can be used as a short form of -location."),
10530 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10533 static gdb::option::option_def_group
10534 make_watch_options_def_group (watch_options
*opts
)
10536 return {{watch_option_defs
}, opts
};
10539 /* A helper function that looks for the "-location" argument and then
10540 calls watch_command_1. */
10543 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10545 watch_options opts
;
10546 auto grp
= make_watch_options_def_group (&opts
);
10547 gdb::option::process_options
10548 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10549 if (arg
!= nullptr && *arg
== '\0')
10552 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10555 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10557 watch_command_completer (struct cmd_list_element
*ignore
,
10558 completion_tracker
&tracker
,
10559 const char *text
, const char * /*word*/)
10561 const auto group
= make_watch_options_def_group (nullptr);
10562 if (gdb::option::complete_options
10563 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10566 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10567 expression_completer (ignore
, tracker
, text
, word
);
10571 watch_command (const char *arg
, int from_tty
)
10573 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10577 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10579 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10583 rwatch_command (const char *arg
, int from_tty
)
10585 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10589 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10591 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10595 awatch_command (const char *arg
, int from_tty
)
10597 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10601 /* Data for the FSM that manages the until(location)/advance commands
10602 in infcmd.c. Here because it uses the mechanisms of
10605 struct until_break_fsm
: public thread_fsm
10607 /* The thread that was current when the command was executed. */
10610 /* The breakpoint set at the return address in the caller frame,
10611 plus breakpoints at all the destination locations. */
10612 std::vector
<breakpoint_up
> breakpoints
;
10614 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10615 std::vector
<breakpoint_up
> &&breakpoints
)
10616 : thread_fsm (cmd_interp
),
10618 breakpoints (std::move (breakpoints
))
10622 void clean_up (struct thread_info
*thread
) override
;
10623 bool should_stop (struct thread_info
*thread
) override
;
10624 enum async_reply_reason
do_async_reply_reason () override
;
10627 /* Implementation of the 'should_stop' FSM method for the
10628 until(location)/advance commands. */
10631 until_break_fsm::should_stop (struct thread_info
*tp
)
10633 for (const breakpoint_up
&bp
: breakpoints
)
10634 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10635 bp
.get ()) != NULL
)
10644 /* Implementation of the 'clean_up' FSM method for the
10645 until(location)/advance commands. */
10648 until_break_fsm::clean_up (struct thread_info
*)
10650 /* Clean up our temporary breakpoints. */
10651 breakpoints
.clear ();
10652 delete_longjmp_breakpoint (thread
);
10655 /* Implementation of the 'async_reply_reason' FSM method for the
10656 until(location)/advance commands. */
10658 enum async_reply_reason
10659 until_break_fsm::do_async_reply_reason ()
10661 return EXEC_ASYNC_LOCATION_REACHED
;
10665 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10667 frame_info_ptr frame
;
10668 struct gdbarch
*frame_gdbarch
;
10669 struct frame_id stack_frame_id
;
10670 struct frame_id caller_frame_id
;
10672 struct thread_info
*tp
;
10674 clear_proceed_status (0);
10676 /* Set a breakpoint where the user wants it and at return from
10679 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
10681 std::vector
<symtab_and_line
> sals
10682 = (last_displayed_sal_is_valid ()
10683 ? decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10684 get_last_displayed_symtab (),
10685 get_last_displayed_line ())
10686 : decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
,
10690 error (_("Couldn't get information on specified line."));
10693 error (_("Junk at end of arguments."));
10695 tp
= inferior_thread ();
10696 thread
= tp
->global_num
;
10698 /* Note linespec handling above invalidates the frame chain.
10699 Installing a breakpoint also invalidates the frame chain (as it
10700 may need to switch threads), so do any frame handling before
10703 frame
= get_selected_frame (NULL
);
10704 frame_gdbarch
= get_frame_arch (frame
);
10705 stack_frame_id
= get_stack_frame_id (frame
);
10706 caller_frame_id
= frame_unwind_caller_id (frame
);
10708 /* Keep within the current frame, or in frames called by the current
10711 std::vector
<breakpoint_up
> breakpoints
;
10713 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10715 if (frame_id_p (caller_frame_id
))
10717 struct symtab_and_line sal2
;
10718 struct gdbarch
*caller_gdbarch
;
10720 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10721 sal2
.pc
= frame_unwind_caller_pc (frame
);
10722 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10724 breakpoint_up caller_breakpoint
10725 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10726 caller_frame_id
, bp_until
);
10727 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10729 set_longjmp_breakpoint (tp
, stack_frame_id
);
10730 lj_deleter
.emplace (thread
);
10733 /* set_momentary_breakpoint could invalidate FRAME. */
10736 /* If the user told us to continue until a specified location, we
10737 don't specify a frame at which we need to stop. Otherwise,
10738 specify the selected frame, because we want to stop only at the
10739 very same frame. */
10740 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10742 for (symtab_and_line
&sal
: sals
)
10744 resolve_sal_pc (&sal
);
10746 breakpoint_up location_breakpoint
10747 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10748 stop_frame_id
, bp_until
);
10749 breakpoints
.emplace_back (std::move (location_breakpoint
));
10753 (std::unique_ptr
<thread_fsm
>
10754 (new until_break_fsm (command_interp (), tp
->global_num
,
10755 std::move (breakpoints
))));
10758 lj_deleter
->release ();
10760 proceed (-1, GDB_SIGNAL_DEFAULT
);
10765 /* Compare two breakpoints and return a strcmp-like result. */
10768 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10770 uintptr_t ua
= (uintptr_t) a
;
10771 uintptr_t ub
= (uintptr_t) b
;
10773 if (a
->number
< b
->number
)
10775 else if (a
->number
> b
->number
)
10778 /* Now sort by address, in case we see, e..g, two breakpoints with
10782 return ua
> ub
? 1 : 0;
10785 /* Delete breakpoints by address or line. */
10788 clear_command (const char *arg
, int from_tty
)
10792 std::vector
<symtab_and_line
> decoded_sals
;
10793 symtab_and_line last_sal
;
10794 gdb::array_view
<symtab_and_line
> sals
;
10798 = decode_line_with_current_source (arg
,
10799 (DECODE_LINE_FUNFIRSTLINE
10800 | DECODE_LINE_LIST_MODE
));
10802 sals
= decoded_sals
;
10806 /* Set sal's line, symtab, pc, and pspace to the values
10807 corresponding to the last call to print_frame_info. If the
10808 codepoint is not valid, this will set all the fields to 0. */
10809 last_sal
= get_last_displayed_sal ();
10810 if (last_sal
.symtab
== 0)
10811 error (_("No source file specified."));
10817 /* We don't call resolve_sal_pc here. That's not as bad as it
10818 seems, because all existing breakpoints typically have both
10819 file/line and pc set. So, if clear is given file/line, we can
10820 match this to existing breakpoint without obtaining pc at all.
10822 We only support clearing given the address explicitly
10823 present in breakpoint table. Say, we've set breakpoint
10824 at file:line. There were several PC values for that file:line,
10825 due to optimization, all in one block.
10827 We've picked one PC value. If "clear" is issued with another
10828 PC corresponding to the same file:line, the breakpoint won't
10829 be cleared. We probably can still clear the breakpoint, but
10830 since the other PC value is never presented to user, user
10831 can only find it by guessing, and it does not seem important
10832 to support that. */
10834 /* For each line spec given, delete bps which correspond to it. Do
10835 it in two passes, solely to preserve the current behavior that
10836 from_tty is forced true if we delete more than one
10839 std::vector
<struct breakpoint
*> found
;
10840 for (const auto &sal
: sals
)
10842 const char *sal_fullname
;
10844 /* If exact pc given, clear bpts at that pc.
10845 If line given (pc == 0), clear all bpts on specified line.
10846 If defaulting, clear all bpts on default line
10849 defaulting sal.pc != 0 tests to do
10854 1 0 <can't happen> */
10856 sal_fullname
= (sal
.symtab
== NULL
10857 ? NULL
: symtab_to_fullname (sal
.symtab
));
10859 /* Find all matching breakpoints and add them to 'found'. */
10860 for (breakpoint
*b
: all_breakpoints ())
10863 /* Are we going to delete b? */
10864 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10865 && user_breakpoint_p (b
))
10867 for (bp_location
*loc
: b
->locations ())
10869 /* If the user specified file:line, don't allow a PC
10870 match. This matches historical gdb behavior. */
10871 int pc_match
= (!sal
.explicit_line
10873 && (loc
->pspace
== sal
.pspace
)
10874 && (loc
->address
== sal
.pc
)
10875 && (!section_is_overlay (loc
->section
)
10876 || loc
->section
== sal
.section
));
10877 int line_match
= 0;
10879 if ((default_match
|| sal
.explicit_line
)
10880 && loc
->symtab
!= NULL
10881 && sal_fullname
!= NULL
10882 && sal
.pspace
== loc
->pspace
10883 && loc
->line_number
== sal
.line
10884 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10885 sal_fullname
) == 0)
10888 if (pc_match
|| line_match
)
10897 found
.push_back (b
);
10901 /* Now go thru the 'found' chain and delete them. */
10902 if (found
.empty ())
10905 error (_("No breakpoint at %s."), arg
);
10907 error (_("No breakpoint at this line."));
10910 /* Remove duplicates from the vec. */
10911 std::sort (found
.begin (), found
.end (),
10912 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10914 return compare_breakpoints (bp_a
, bp_b
) < 0;
10916 found
.erase (std::unique (found
.begin (), found
.end (),
10917 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10919 return compare_breakpoints (bp_a
, bp_b
) == 0;
10923 if (found
.size () > 1)
10924 from_tty
= 1; /* Always report if deleted more than one. */
10927 if (found
.size () == 1)
10928 gdb_printf (_("Deleted breakpoint "));
10930 gdb_printf (_("Deleted breakpoints "));
10933 for (breakpoint
*iter
: found
)
10936 gdb_printf ("%d ", iter
->number
);
10937 delete_breakpoint (iter
);
10943 /* Delete breakpoint in BS if they are `delete' breakpoints and
10944 all breakpoints that are marked for deletion, whether hit or not.
10945 This is called after any breakpoint is hit, or after errors. */
10948 breakpoint_auto_delete (bpstat
*bs
)
10950 for (; bs
; bs
= bs
->next
)
10951 if (bs
->breakpoint_at
10952 && bs
->breakpoint_at
->disposition
== disp_del
10954 delete_breakpoint (bs
->breakpoint_at
);
10956 for (breakpoint
*b
: all_breakpoints_safe ())
10957 if (b
->disposition
== disp_del_at_next_stop
)
10958 delete_breakpoint (b
);
10961 /* A comparison function for bp_location AP and BP being interfaced to
10962 std::sort. Sort elements primarily by their ADDRESS (no matter what
10963 bl_address_is_meaningful says), secondarily by ordering first
10964 permanent elements and terciarily just ensuring the array is sorted
10965 stable way despite std::sort being an unstable algorithm. */
10968 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10970 if (a
->address
!= b
->address
)
10971 return a
->address
< b
->address
;
10973 /* Sort locations at the same address by their pspace number, keeping
10974 locations of the same inferior (in a multi-inferior environment)
10977 if (a
->pspace
->num
!= b
->pspace
->num
)
10978 return a
->pspace
->num
< b
->pspace
->num
;
10980 /* Sort permanent breakpoints first. */
10981 if (a
->permanent
!= b
->permanent
)
10982 return a
->permanent
> b
->permanent
;
10984 /* Sort by type in order to make duplicate determination easier.
10985 See update_global_location_list. This is kept in sync with
10986 breakpoint_locations_match. */
10987 if (a
->loc_type
< b
->loc_type
)
10990 /* Likewise, for range-breakpoints, sort by length. */
10991 if (a
->loc_type
== bp_loc_hardware_breakpoint
10992 && b
->loc_type
== bp_loc_hardware_breakpoint
10993 && a
->length
< b
->length
)
10996 /* Make the internal GDB representation stable across GDB runs
10997 where A and B memory inside GDB can differ. Breakpoint locations of
10998 the same type at the same address can be sorted in arbitrary order. */
11000 if (a
->owner
->number
!= b
->owner
->number
)
11001 return a
->owner
->number
< b
->owner
->number
;
11006 /* Set bp_locations_placed_address_before_address_max and
11007 bp_locations_shadow_len_after_address_max according to the current
11008 content of the bp_locations array. */
11011 bp_locations_target_extensions_update (void)
11013 bp_locations_placed_address_before_address_max
= 0;
11014 bp_locations_shadow_len_after_address_max
= 0;
11016 for (bp_location
*bl
: all_bp_locations ())
11018 CORE_ADDR start
, end
, addr
;
11020 if (!bp_location_has_shadow (bl
))
11023 start
= bl
->target_info
.placed_address
;
11024 end
= start
+ bl
->target_info
.shadow_len
;
11026 gdb_assert (bl
->address
>= start
);
11027 addr
= bl
->address
- start
;
11028 if (addr
> bp_locations_placed_address_before_address_max
)
11029 bp_locations_placed_address_before_address_max
= addr
;
11031 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11033 gdb_assert (bl
->address
< end
);
11034 addr
= end
- bl
->address
;
11035 if (addr
> bp_locations_shadow_len_after_address_max
)
11036 bp_locations_shadow_len_after_address_max
= addr
;
11040 /* Download tracepoint locations if they haven't been. */
11043 download_tracepoint_locations (void)
11045 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11047 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11049 for (breakpoint
*b
: all_tracepoints ())
11051 struct tracepoint
*t
;
11052 bool bp_location_downloaded
= false;
11054 if ((b
->type
== bp_fast_tracepoint
11055 ? !may_insert_fast_tracepoints
11056 : !may_insert_tracepoints
))
11059 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11061 if (target_can_download_tracepoint ())
11062 can_download_tracepoint
= TRIBOOL_TRUE
;
11064 can_download_tracepoint
= TRIBOOL_FALSE
;
11067 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11070 for (bp_location
*bl
: b
->locations ())
11072 /* In tracepoint, locations are _never_ duplicated, so
11073 should_be_inserted is equivalent to
11074 unduplicated_should_be_inserted. */
11075 if (!should_be_inserted (bl
) || bl
->inserted
)
11078 switch_to_program_space_and_thread (bl
->pspace
);
11080 target_download_tracepoint (bl
);
11083 bp_location_downloaded
= true;
11085 t
= (struct tracepoint
*) b
;
11086 t
->number_on_target
= b
->number
;
11087 if (bp_location_downloaded
)
11088 gdb::observers::breakpoint_modified
.notify (b
);
11092 /* Swap the insertion/duplication state between two locations. */
11095 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11097 const int left_inserted
= left
->inserted
;
11098 const int left_duplicate
= left
->duplicate
;
11099 const int left_needs_update
= left
->needs_update
;
11100 const struct bp_target_info left_target_info
= left
->target_info
;
11102 /* Locations of tracepoints can never be duplicated. */
11103 if (is_tracepoint (left
->owner
))
11104 gdb_assert (!left
->duplicate
);
11105 if (is_tracepoint (right
->owner
))
11106 gdb_assert (!right
->duplicate
);
11108 left
->inserted
= right
->inserted
;
11109 left
->duplicate
= right
->duplicate
;
11110 left
->needs_update
= right
->needs_update
;
11111 left
->target_info
= right
->target_info
;
11112 right
->inserted
= left_inserted
;
11113 right
->duplicate
= left_duplicate
;
11114 right
->needs_update
= left_needs_update
;
11115 right
->target_info
= left_target_info
;
11118 /* Force the re-insertion of the locations at ADDRESS. This is called
11119 once a new/deleted/modified duplicate location is found and we are evaluating
11120 conditions on the target's side. Such conditions need to be updated on
11124 force_breakpoint_reinsertion (struct bp_location
*bl
)
11126 CORE_ADDR address
= 0;
11129 address
= bl
->address
;
11130 pspace_num
= bl
->pspace
->num
;
11132 /* This is only meaningful if the target is
11133 evaluating conditions and if the user has
11134 opted for condition evaluation on the target's
11136 if (gdb_evaluates_breakpoint_condition_p ()
11137 || !target_supports_evaluation_of_breakpoint_conditions ())
11140 /* Flag all breakpoint locations with this address and
11141 the same program space as the location
11142 as "its condition has changed". We need to
11143 update the conditions on the target's side. */
11144 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11146 if (!is_breakpoint (loc
->owner
)
11147 || pspace_num
!= loc
->pspace
->num
)
11150 /* Flag the location appropriately. We use a different state to
11151 let everyone know that we already updated the set of locations
11152 with addr bl->address and program space bl->pspace. This is so
11153 we don't have to keep calling these functions just to mark locations
11154 that have already been marked. */
11155 loc
->condition_changed
= condition_updated
;
11157 /* Free the agent expression bytecode as well. We will compute
11159 loc
->cond_bytecode
.reset ();
11163 /* Called whether new breakpoints are created, or existing breakpoints
11164 deleted, to update the global location list and recompute which
11165 locations are duplicate of which.
11167 The INSERT_MODE flag determines whether locations may not, may, or
11168 shall be inserted now. See 'enum ugll_insert_mode' for more
11172 update_global_location_list (enum ugll_insert_mode insert_mode
)
11174 /* Last breakpoint location address that was marked for update. */
11175 CORE_ADDR last_addr
= 0;
11176 /* Last breakpoint location program space that was marked for update. */
11177 int last_pspace_num
= -1;
11179 /* Used in the duplicates detection below. When iterating over all
11180 bp_locations, points to the first bp_location of a given address.
11181 Breakpoints and watchpoints of different types are never
11182 duplicates of each other. Keep one pointer for each type of
11183 breakpoint/watchpoint, so we only need to loop over all locations
11185 struct bp_location
*bp_loc_first
; /* breakpoint */
11186 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11187 struct bp_location
*awp_loc_first
; /* access watchpoint */
11188 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11190 /* Saved former bp_locations array which we compare against the newly
11191 built bp_locations from the current state of ALL_BREAKPOINTS. */
11192 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11193 bp_locations
.clear ();
11195 for (breakpoint
*b
: all_breakpoints ())
11196 for (bp_location
*loc
: b
->locations ())
11197 bp_locations
.push_back (loc
);
11199 /* See if we need to "upgrade" a software breakpoint to a hardware
11200 breakpoint. Do this before deciding whether locations are
11201 duplicates. Also do this before sorting because sorting order
11202 depends on location type. */
11203 for (bp_location
*loc
: bp_locations
)
11204 if (!loc
->inserted
&& should_be_inserted (loc
))
11205 handle_automatic_hardware_breakpoints (loc
);
11207 std::sort (bp_locations
.begin (), bp_locations
.end (),
11208 bp_location_is_less_than
);
11210 bp_locations_target_extensions_update ();
11212 /* Identify bp_location instances that are no longer present in the
11213 new list, and therefore should be freed. Note that it's not
11214 necessary that those locations should be removed from inferior --
11215 if there's another location at the same address (previously
11216 marked as duplicate), we don't need to remove/insert the
11219 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11220 and former bp_location array state respectively. */
11223 for (bp_location
*old_loc
: old_locations
)
11225 /* Tells if 'old_loc' is found among the new locations. If
11226 not, we have to free it. */
11227 bool found_object
= false;
11228 /* Tells if the location should remain inserted in the target. */
11229 bool keep_in_target
= false;
11230 bool removed
= false;
11232 /* Skip LOCP entries which will definitely never be needed.
11233 Stop either at or being the one matching OLD_LOC. */
11234 while (loc_i
< bp_locations
.size ()
11235 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11238 for (size_t loc2_i
= loc_i
;
11239 (loc2_i
< bp_locations
.size ()
11240 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11243 /* Check if this is a new/duplicated location or a duplicated
11244 location that had its condition modified. If so, we want to send
11245 its condition to the target if evaluation of conditions is taking
11247 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11248 && (last_addr
!= old_loc
->address
11249 || last_pspace_num
!= old_loc
->pspace
->num
))
11251 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11252 last_pspace_num
= old_loc
->pspace
->num
;
11255 if (bp_locations
[loc2_i
] == old_loc
)
11256 found_object
= true;
11259 /* We have already handled this address, update it so that we don't
11260 have to go through updates again. */
11261 last_addr
= old_loc
->address
;
11263 /* Target-side condition evaluation: Handle deleted locations. */
11265 force_breakpoint_reinsertion (old_loc
);
11267 /* If this location is no longer present, and inserted, look if
11268 there's maybe a new location at the same address. If so,
11269 mark that one inserted, and don't remove this one. This is
11270 needed so that we don't have a time window where a breakpoint
11271 at certain location is not inserted. */
11273 if (old_loc
->inserted
)
11275 /* If the location is inserted now, we might have to remove
11278 if (found_object
&& should_be_inserted (old_loc
))
11280 /* The location is still present in the location list,
11281 and still should be inserted. Don't do anything. */
11282 keep_in_target
= true;
11286 /* This location still exists, but it won't be kept in the
11287 target since it may have been disabled. We proceed to
11288 remove its target-side condition. */
11290 /* The location is either no longer present, or got
11291 disabled. See if there's another location at the
11292 same address, in which case we don't need to remove
11293 this one from the target. */
11295 /* OLD_LOC comes from existing struct breakpoint. */
11296 if (bl_address_is_meaningful (old_loc
))
11298 for (size_t loc2_i
= loc_i
;
11299 (loc2_i
< bp_locations
.size ()
11300 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11303 bp_location
*loc2
= bp_locations
[loc2_i
];
11305 if (loc2
== old_loc
)
11308 if (breakpoint_locations_match (loc2
, old_loc
))
11310 /* Read watchpoint locations are switched to
11311 access watchpoints, if the former are not
11312 supported, but the latter are. */
11313 if (is_hardware_watchpoint (old_loc
->owner
))
11315 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11316 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11319 /* loc2 is a duplicated location. We need to check
11320 if it should be inserted in case it will be
11322 if (unduplicated_should_be_inserted (loc2
))
11324 swap_insertion (old_loc
, loc2
);
11325 keep_in_target
= true;
11333 if (!keep_in_target
)
11335 if (remove_breakpoint (old_loc
))
11337 /* This is just about all we can do. We could keep
11338 this location on the global list, and try to
11339 remove it next time, but there's no particular
11340 reason why we will succeed next time.
11342 Note that at this point, old_loc->owner is still
11343 valid, as delete_breakpoint frees the breakpoint
11344 only after calling us. */
11345 gdb_printf (_("warning: Error removing "
11346 "breakpoint %d\n"),
11347 old_loc
->owner
->number
);
11355 if (removed
&& target_is_non_stop_p ()
11356 && need_moribund_for_location_type (old_loc
))
11358 /* This location was removed from the target. In
11359 non-stop mode, a race condition is possible where
11360 we've removed a breakpoint, but stop events for that
11361 breakpoint are already queued and will arrive later.
11362 We apply an heuristic to be able to distinguish such
11363 SIGTRAPs from other random SIGTRAPs: we keep this
11364 breakpoint location for a bit, and will retire it
11365 after we see some number of events. The theory here
11366 is that reporting of events should, "on the average",
11367 be fair, so after a while we'll see events from all
11368 threads that have anything of interest, and no longer
11369 need to keep this breakpoint location around. We
11370 don't hold locations forever so to reduce chances of
11371 mistaking a non-breakpoint SIGTRAP for a breakpoint
11374 The heuristic failing can be disastrous on
11375 decr_pc_after_break targets.
11377 On decr_pc_after_break targets, like e.g., x86-linux,
11378 if we fail to recognize a late breakpoint SIGTRAP,
11379 because events_till_retirement has reached 0 too
11380 soon, we'll fail to do the PC adjustment, and report
11381 a random SIGTRAP to the user. When the user resumes
11382 the inferior, it will most likely immediately crash
11383 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11384 corrupted, because of being resumed e.g., in the
11385 middle of a multi-byte instruction, or skipped a
11386 one-byte instruction. This was actually seen happen
11387 on native x86-linux, and should be less rare on
11388 targets that do not support new thread events, like
11389 remote, due to the heuristic depending on
11392 Mistaking a random SIGTRAP for a breakpoint trap
11393 causes similar symptoms (PC adjustment applied when
11394 it shouldn't), but then again, playing with SIGTRAPs
11395 behind the debugger's back is asking for trouble.
11397 Since hardware watchpoint traps are always
11398 distinguishable from other traps, so we don't need to
11399 apply keep hardware watchpoint moribund locations
11400 around. We simply always ignore hardware watchpoint
11401 traps we can no longer explain. */
11403 process_stratum_target
*proc_target
= nullptr;
11404 for (inferior
*inf
: all_inferiors ())
11405 if (inf
->pspace
== old_loc
->pspace
)
11407 proc_target
= inf
->process_target ();
11410 if (proc_target
!= nullptr)
11411 old_loc
->events_till_retirement
11412 = 3 * (thread_count (proc_target
) + 1);
11414 old_loc
->events_till_retirement
= 1;
11415 old_loc
->owner
= NULL
;
11417 moribund_locations
.push_back (old_loc
);
11421 old_loc
->owner
= NULL
;
11422 decref_bp_location (&old_loc
);
11427 /* Rescan breakpoints at the same address and section, marking the
11428 first one as "first" and any others as "duplicates". This is so
11429 that the bpt instruction is only inserted once. If we have a
11430 permanent breakpoint at the same place as BPT, make that one the
11431 official one, and the rest as duplicates. Permanent breakpoints
11432 are sorted first for the same address.
11434 Do the same for hardware watchpoints, but also considering the
11435 watchpoint's type (regular/access/read) and length. */
11437 bp_loc_first
= NULL
;
11438 wp_loc_first
= NULL
;
11439 awp_loc_first
= NULL
;
11440 rwp_loc_first
= NULL
;
11442 for (bp_location
*loc
: all_bp_locations ())
11444 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11446 struct bp_location
**loc_first_p
;
11447 breakpoint
*b
= loc
->owner
;
11449 if (!unduplicated_should_be_inserted (loc
)
11450 || !bl_address_is_meaningful (loc
)
11451 /* Don't detect duplicate for tracepoint locations because they are
11452 never duplicated. See the comments in field `duplicate' of
11453 `struct bp_location'. */
11454 || is_tracepoint (b
))
11456 /* Clear the condition modification flag. */
11457 loc
->condition_changed
= condition_unchanged
;
11461 if (b
->type
== bp_hardware_watchpoint
)
11462 loc_first_p
= &wp_loc_first
;
11463 else if (b
->type
== bp_read_watchpoint
)
11464 loc_first_p
= &rwp_loc_first
;
11465 else if (b
->type
== bp_access_watchpoint
)
11466 loc_first_p
= &awp_loc_first
;
11468 loc_first_p
= &bp_loc_first
;
11470 if (*loc_first_p
== NULL
11471 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11472 || !breakpoint_locations_match (loc
, *loc_first_p
))
11474 *loc_first_p
= loc
;
11475 loc
->duplicate
= 0;
11477 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11479 loc
->needs_update
= 1;
11480 /* Clear the condition modification flag. */
11481 loc
->condition_changed
= condition_unchanged
;
11487 /* This and the above ensure the invariant that the first location
11488 is not duplicated, and is the inserted one.
11489 All following are marked as duplicated, and are not inserted. */
11491 swap_insertion (loc
, *loc_first_p
);
11492 loc
->duplicate
= 1;
11494 /* Clear the condition modification flag. */
11495 loc
->condition_changed
= condition_unchanged
;
11498 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11500 if (insert_mode
!= UGLL_DONT_INSERT
)
11501 insert_breakpoint_locations ();
11504 /* Even though the caller told us to not insert new
11505 locations, we may still need to update conditions on the
11506 target's side of breakpoints that were already inserted
11507 if the target is evaluating breakpoint conditions. We
11508 only update conditions for locations that are marked
11510 update_inserted_breakpoint_locations ();
11514 if (insert_mode
!= UGLL_DONT_INSERT
)
11515 download_tracepoint_locations ();
11519 breakpoint_retire_moribund (void)
11521 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11523 struct bp_location
*loc
= moribund_locations
[ix
];
11524 if (--(loc
->events_till_retirement
) == 0)
11526 decref_bp_location (&loc
);
11527 unordered_remove (moribund_locations
, ix
);
11534 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11539 update_global_location_list (insert_mode
);
11541 catch (const gdb_exception_error
&e
)
11546 /* Clear BKP from a BPS. */
11549 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11553 for (bs
= bps
; bs
; bs
= bs
->next
)
11554 if (bs
->breakpoint_at
== bpt
)
11556 bs
->breakpoint_at
= NULL
;
11557 bs
->old_val
= NULL
;
11558 /* bs->commands will be freed later. */
11562 /* Callback for iterate_over_threads. */
11564 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11566 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11568 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11572 /* See breakpoint.h. */
11575 code_breakpoint::say_where () const
11577 struct value_print_options opts
;
11579 get_user_print_options (&opts
);
11581 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11585 /* For pending locations, the output differs slightly based
11586 on extra_string. If this is non-NULL, it contains either
11587 a condition or dprintf arguments. */
11588 if (extra_string
== NULL
)
11590 gdb_printf (_(" (%s) pending."), locspec
->to_string ());
11592 else if (type
== bp_dprintf
)
11594 gdb_printf (_(" (%s,%s) pending."),
11595 locspec
->to_string (),
11596 extra_string
.get ());
11600 gdb_printf (_(" (%s %s) pending."),
11601 locspec
->to_string (),
11602 extra_string
.get ());
11607 if (opts
.addressprint
|| loc
->symtab
== NULL
)
11608 gdb_printf (" at %ps",
11609 styled_string (address_style
.style (),
11610 paddress (loc
->gdbarch
,
11612 if (loc
->symtab
!= NULL
)
11614 /* If there is a single location, we can print the location
11616 if (loc
->next
== NULL
)
11618 const char *filename
11619 = symtab_to_filename_for_display (loc
->symtab
);
11620 gdb_printf (": file %ps, line %d.",
11621 styled_string (file_name_style
.style (),
11626 /* This is not ideal, but each location may have a
11627 different file name, and this at least reflects the
11628 real situation somewhat. */
11629 gdb_printf (": %s.", locspec
->to_string ());
11634 struct bp_location
*iter
= loc
;
11636 for (; iter
; iter
= iter
->next
)
11638 gdb_printf (" (%d locations)", n
);
11643 /* See breakpoint.h. */
11645 bp_location_range
breakpoint::locations () const
11647 return bp_location_range (this->loc
);
11650 struct bp_location
*
11651 breakpoint::allocate_location ()
11653 return new bp_location (this);
11656 #define internal_error_pure_virtual_called() \
11657 gdb_assert_not_reached ("pure virtual function called")
11660 breakpoint::insert_location (struct bp_location
*bl
)
11662 internal_error_pure_virtual_called ();
11666 breakpoint::remove_location (struct bp_location
*bl
,
11667 enum remove_bp_reason reason
)
11669 internal_error_pure_virtual_called ();
11673 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11674 const address_space
*aspace
,
11676 const target_waitstatus
&ws
)
11678 internal_error_pure_virtual_called ();
11682 breakpoint::resources_needed (const struct bp_location
*bl
)
11684 internal_error_pure_virtual_called ();
11687 enum print_stop_action
11688 breakpoint::print_it (const bpstat
*bs
) const
11690 internal_error_pure_virtual_called ();
11694 breakpoint::print_mention () const
11696 internal_error_pure_virtual_called ();
11700 breakpoint::print_recreate (struct ui_file
*fp
) const
11702 internal_error_pure_virtual_called ();
11705 /* Default breakpoint_ops methods. */
11708 code_breakpoint::re_set ()
11710 /* FIXME: is this still reachable? */
11711 if (breakpoint_location_spec_empty_p (this))
11713 /* Anything without a location can't be re-set. */
11714 delete_breakpoint (this);
11722 code_breakpoint::insert_location (struct bp_location
*bl
)
11724 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11726 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11727 bl
->target_info
.placed_address
= addr
;
11730 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11731 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11733 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11735 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11737 /* The insertion was successful, now let's set the probe's semaphore
11739 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11746 code_breakpoint::remove_location (struct bp_location
*bl
,
11747 enum remove_bp_reason reason
)
11749 if (bl
->probe
.prob
!= nullptr)
11751 /* Let's clear the semaphore before removing the location. */
11752 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11755 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11756 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11758 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11762 code_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11763 const address_space
*aspace
,
11765 const target_waitstatus
&ws
)
11767 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11768 || ws
.sig () != GDB_SIGNAL_TRAP
)
11771 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11775 if (overlay_debugging
/* unmapped overlay section */
11776 && section_is_overlay (bl
->section
)
11777 && !section_is_mapped (bl
->section
))
11784 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11785 const address_space
*aspace
,
11787 const target_waitstatus
&ws
)
11789 if (dprintf_style
== dprintf_style_agent
11790 && target_can_run_breakpoint_commands ())
11792 /* An agent-style dprintf never causes a stop. If we see a trap
11793 for this address it must be for a breakpoint that happens to
11794 be set at the same address. */
11798 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11802 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
11804 gdb_assert (type
== bp_hardware_breakpoint
);
11809 enum print_stop_action
11810 ordinary_breakpoint::print_it (const bpstat
*bs
) const
11812 const struct bp_location
*bl
;
11814 struct ui_out
*uiout
= current_uiout
;
11816 bl
= bs
->bp_location_at
.get ();
11818 bp_temp
= disposition
== disp_del
;
11819 if (bl
->address
!= bl
->requested_address
)
11820 breakpoint_adjustment_warning (bl
->requested_address
,
11823 annotate_breakpoint (number
);
11824 maybe_print_thread_hit_breakpoint (uiout
);
11826 if (uiout
->is_mi_like_p ())
11828 uiout
->field_string ("reason",
11829 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11830 uiout
->field_string ("disp", bpdisp_text (disposition
));
11834 uiout
->text ("Temporary breakpoint ");
11836 uiout
->text ("Breakpoint ");
11837 print_num_locno (bs
, uiout
);
11838 uiout
->text (", ");
11840 return PRINT_SRC_AND_LOC
;
11844 ordinary_breakpoint::print_mention () const
11846 if (current_uiout
->is_mi_like_p ())
11851 case bp_breakpoint
:
11852 case bp_gnu_ifunc_resolver
:
11853 if (disposition
== disp_del
)
11854 gdb_printf (_("Temporary breakpoint"));
11856 gdb_printf (_("Breakpoint"));
11857 gdb_printf (_(" %d"), number
);
11858 if (type
== bp_gnu_ifunc_resolver
)
11859 gdb_printf (_(" at gnu-indirect-function resolver"));
11861 case bp_hardware_breakpoint
:
11862 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
11865 gdb_printf (_("Dprintf %d"), number
);
11873 ordinary_breakpoint::print_recreate (struct ui_file
*fp
) const
11875 if (type
== bp_breakpoint
&& disposition
== disp_del
)
11876 gdb_printf (fp
, "tbreak");
11877 else if (type
== bp_breakpoint
)
11878 gdb_printf (fp
, "break");
11879 else if (type
== bp_hardware_breakpoint
11880 && disposition
== disp_del
)
11881 gdb_printf (fp
, "thbreak");
11882 else if (type
== bp_hardware_breakpoint
)
11883 gdb_printf (fp
, "hbreak");
11885 internal_error (_("unhandled breakpoint type %d"), (int) type
);
11887 gdb_printf (fp
, " %s", locspec
->to_string ());
11889 /* Print out extra_string if this breakpoint is pending. It might
11890 contain, for example, conditions that were set by the user. */
11891 if (loc
== NULL
&& extra_string
!= NULL
)
11892 gdb_printf (fp
, " %s", extra_string
.get ());
11894 print_recreate_thread (fp
);
11897 std::vector
<symtab_and_line
>
11898 code_breakpoint::decode_location_spec (location_spec
*locspec
,
11899 program_space
*search_pspace
)
11901 if (locspec
->type () == PROBE_LOCATION_SPEC
)
11902 return bkpt_probe_decode_location_spec (this, locspec
, search_pspace
);
11904 struct linespec_result canonical
;
11906 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
11907 NULL
, 0, &canonical
, multiple_symbols_all
,
11910 /* We should get 0 or 1 resulting SALs. */
11911 gdb_assert (canonical
.lsals
.size () < 2);
11913 if (!canonical
.lsals
.empty ())
11915 const linespec_sals
&lsal
= canonical
.lsals
[0];
11916 return std::move (lsal
.sals
);
11921 /* Virtual table for internal breakpoints. */
11924 internal_breakpoint::re_set ()
11928 /* Delete overlay event and longjmp master breakpoints; they
11929 will be reset later by breakpoint_re_set. */
11930 case bp_overlay_event
:
11931 case bp_longjmp_master
:
11932 case bp_std_terminate_master
:
11933 case bp_exception_master
:
11934 delete_breakpoint (this);
11937 /* This breakpoint is special, it's set up when the inferior
11938 starts and we really don't want to touch it. */
11939 case bp_shlib_event
:
11941 /* Like bp_shlib_event, this breakpoint type is special. Once
11942 it is set up, we do not want to touch it. */
11943 case bp_thread_event
:
11949 internal_breakpoint::check_status (bpstat
*bs
)
11951 if (type
== bp_shlib_event
)
11953 /* If requested, stop when the dynamic linker notifies GDB of
11954 events. This allows the user to get control and place
11955 breakpoints in initializer routines for dynamically loaded
11956 objects (among other things). */
11957 bs
->stop
= stop_on_solib_events
!= 0;
11958 bs
->print
= stop_on_solib_events
!= 0;
11964 enum print_stop_action
11965 internal_breakpoint::print_it (const bpstat
*bs
) const
11969 case bp_shlib_event
:
11970 /* Did we stop because the user set the stop_on_solib_events
11971 variable? (If so, we report this as a generic, "Stopped due
11972 to shlib event" message.) */
11973 print_solib_event (false);
11976 case bp_thread_event
:
11977 /* Not sure how we will get here.
11978 GDB should not stop for these breakpoints. */
11979 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
11982 case bp_overlay_event
:
11983 /* By analogy with the thread event, GDB should not stop for these. */
11984 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11987 case bp_longjmp_master
:
11988 /* These should never be enabled. */
11989 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11992 case bp_std_terminate_master
:
11993 /* These should never be enabled. */
11994 gdb_printf (_("std::terminate Master Breakpoint: "
11995 "gdb should not stop!\n"));
11998 case bp_exception_master
:
11999 /* These should never be enabled. */
12000 gdb_printf (_("Exception Master Breakpoint: "
12001 "gdb should not stop!\n"));
12005 return PRINT_NOTHING
;
12009 internal_breakpoint::print_mention () const
12011 /* Nothing to mention. These breakpoints are internal. */
12014 /* Virtual table for momentary breakpoints */
12017 momentary_breakpoint::re_set ()
12019 /* Keep temporary breakpoints, which can be encountered when we step
12020 over a dlopen call and solib_add is resetting the breakpoints.
12021 Otherwise these should have been blown away via the cleanup chain
12022 or by breakpoint_init_inferior when we rerun the executable. */
12026 momentary_breakpoint::check_status (bpstat
*bs
)
12028 /* Nothing. The point of these breakpoints is causing a stop. */
12031 enum print_stop_action
12032 momentary_breakpoint::print_it (const bpstat
*bs
) const
12034 return PRINT_UNKNOWN
;
12038 momentary_breakpoint::print_mention () const
12040 /* Nothing to mention. These breakpoints are internal. */
12043 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12045 It gets cleared already on the removal of the first one of such placed
12046 breakpoints. This is OK as they get all removed altogether. */
12048 longjmp_breakpoint::~longjmp_breakpoint ()
12050 thread_info
*tp
= find_thread_global_id (this->thread
);
12053 tp
->initiating_frame
= null_frame_id
;
12057 bkpt_probe_create_sals_from_location_spec (location_spec
*locspec
,
12058 struct linespec_result
*canonical
)
12061 struct linespec_sals lsal
;
12063 lsal
.sals
= parse_probes (locspec
, NULL
, canonical
);
12064 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12065 canonical
->lsals
.push_back (std::move (lsal
));
12068 static std::vector
<symtab_and_line
>
12069 bkpt_probe_decode_location_spec (struct breakpoint
*b
,
12070 location_spec
*locspec
,
12071 program_space
*search_pspace
)
12073 std::vector
<symtab_and_line
> sals
12074 = parse_probes (locspec
, search_pspace
, NULL
);
12076 error (_("probe not found"));
12081 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
12082 const address_space
*aspace
, CORE_ADDR bp_addr
,
12083 const target_waitstatus
&ws
)
12085 /* By definition, the inferior does not report stops at
12091 tracepoint::print_one_detail (struct ui_out
*uiout
) const
12093 if (!static_trace_marker_id
.empty ())
12095 gdb_assert (type
== bp_static_tracepoint
12096 || type
== bp_static_marker_tracepoint
);
12098 uiout
->message ("\tmarker id is %pF\n",
12099 string_field ("static-tracepoint-marker-string-id",
12100 static_trace_marker_id
.c_str ()));
12105 tracepoint::print_mention () const
12107 if (current_uiout
->is_mi_like_p ())
12112 case bp_tracepoint
:
12113 gdb_printf (_("Tracepoint"));
12114 gdb_printf (_(" %d"), number
);
12116 case bp_fast_tracepoint
:
12117 gdb_printf (_("Fast tracepoint"));
12118 gdb_printf (_(" %d"), number
);
12120 case bp_static_tracepoint
:
12121 case bp_static_marker_tracepoint
:
12122 gdb_printf (_("Static tracepoint"));
12123 gdb_printf (_(" %d"), number
);
12126 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12133 tracepoint::print_recreate (struct ui_file
*fp
) const
12135 if (type
== bp_fast_tracepoint
)
12136 gdb_printf (fp
, "ftrace");
12137 else if (type
== bp_static_tracepoint
12138 || type
== bp_static_marker_tracepoint
)
12139 gdb_printf (fp
, "strace");
12140 else if (type
== bp_tracepoint
)
12141 gdb_printf (fp
, "trace");
12143 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12145 gdb_printf (fp
, " %s", locspec
->to_string ());
12146 print_recreate_thread (fp
);
12149 gdb_printf (fp
, " passcount %d\n", pass_count
);
12152 /* Virtual table for tracepoints on static probes. */
12155 tracepoint_probe_create_sals_from_location_spec
12156 (location_spec
*locspec
,
12157 struct linespec_result
*canonical
)
12159 /* We use the same method for breakpoint on probes. */
12160 bkpt_probe_create_sals_from_location_spec (locspec
, canonical
);
12164 dprintf_breakpoint::re_set ()
12168 /* extra_string should never be non-NULL for dprintf. */
12169 gdb_assert (extra_string
!= NULL
);
12171 /* 1 - connect to target 1, that can run breakpoint commands.
12172 2 - create a dprintf, which resolves fine.
12173 3 - disconnect from target 1
12174 4 - connect to target 2, that can NOT run breakpoint commands.
12176 After steps #3/#4, you'll want the dprintf command list to
12177 be updated, because target 1 and 2 may well return different
12178 answers for target_can_run_breakpoint_commands().
12179 Given absence of finer grained resetting, we get to do
12180 it all the time. */
12181 if (extra_string
!= NULL
)
12182 update_dprintf_command_list (this);
12185 /* Implement the "print_recreate" method for dprintf. */
12188 dprintf_breakpoint::print_recreate (struct ui_file
*fp
) const
12190 gdb_printf (fp
, "dprintf %s,%s", locspec
->to_string (), extra_string
.get ());
12191 print_recreate_thread (fp
);
12194 /* Implement the "after_condition_true" method for dprintf.
12196 dprintf's are implemented with regular commands in their command
12197 list, but we run the commands here instead of before presenting the
12198 stop to the user, as dprintf's don't actually cause a stop. This
12199 also makes it so that the commands of multiple dprintfs at the same
12200 address are all handled. */
12203 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
12205 /* dprintf's never cause a stop. This wasn't set in the
12206 check_status hook instead because that would make the dprintf's
12207 condition not be evaluated. */
12210 /* Run the command list here. Take ownership of it instead of
12211 copying. We never want these commands to run later in
12212 bpstat_do_actions, if a breakpoint that causes a stop happens to
12213 be set at same address as this dprintf, or even if running the
12214 commands here throws. */
12215 counted_command_line cmds
= std::move (bs
->commands
);
12216 gdb_assert (cmds
!= nullptr);
12217 execute_control_commands (cmds
.get (), 0);
12220 /* The breakpoint_ops structure to be used on static tracepoints with
12224 strace_marker_create_sals_from_location_spec (location_spec
*locspec
,
12225 struct linespec_result
*canonical
)
12227 struct linespec_sals lsal
;
12228 const char *arg_start
, *arg
;
12230 arg
= arg_start
= as_linespec_location_spec (locspec
)->spec_string
;
12231 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12233 std::string
str (arg_start
, arg
- arg_start
);
12234 const char *ptr
= str
.c_str ();
12236 = new_linespec_location_spec (&ptr
, symbol_name_match_type::FULL
);
12238 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12239 canonical
->lsals
.push_back (std::move (lsal
));
12243 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12244 struct linespec_result
*canonical
,
12245 gdb::unique_xmalloc_ptr
<char> cond_string
,
12246 gdb::unique_xmalloc_ptr
<char> extra_string
,
12247 enum bptype type_wanted
,
12248 enum bpdisp disposition
,
12250 int task
, int ignore_count
,
12251 int from_tty
, int enabled
,
12252 int internal
, unsigned flags
)
12254 const linespec_sals
&lsal
= canonical
->lsals
[0];
12256 /* If the user is creating a static tracepoint by marker id
12257 (strace -m MARKER_ID), then store the sals index, so that
12258 breakpoint_re_set can try to match up which of the newly
12259 found markers corresponds to this one, and, don't try to
12260 expand multiple locations for each sal, given than SALS
12261 already should contain all sals for MARKER_ID. */
12263 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12265 location_spec_up locspec
= canonical
->locspec
->clone ();
12267 std::unique_ptr
<tracepoint
> tp
12268 (new tracepoint (gdbarch
,
12271 std::move (locspec
),
12273 std::move (cond_string
),
12274 std::move (extra_string
),
12276 thread
, task
, ignore_count
,
12277 from_tty
, enabled
, flags
,
12278 canonical
->special_display
));
12280 /* Given that its possible to have multiple markers with
12281 the same string id, if the user is creating a static
12282 tracepoint by marker id ("strace -m MARKER_ID"), then
12283 store the sals index, so that breakpoint_re_set can
12284 try to match up which of the newly found markers
12285 corresponds to this one */
12286 tp
->static_trace_marker_id_idx
= i
;
12288 install_breakpoint (internal
, std::move (tp
), 0);
12292 std::vector
<symtab_and_line
>
12293 static_marker_tracepoint::decode_location_spec (location_spec
*locspec
,
12294 program_space
*search_pspace
)
12296 const char *s
= as_linespec_location_spec (locspec
)->spec_string
;
12298 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12299 if (sals
.size () > static_trace_marker_id_idx
)
12301 sals
[0] = sals
[static_trace_marker_id_idx
];
12306 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12309 /* Static tracepoints with marker (`-m'). */
12310 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12312 strace_marker_create_sals_from_location_spec
,
12313 strace_marker_create_breakpoints_sal
,
12317 strace_marker_p (struct breakpoint
*b
)
12319 return b
->type
== bp_static_marker_tracepoint
;
12322 /* Delete a breakpoint and clean up all traces of it in the data
12326 delete_breakpoint (struct breakpoint
*bpt
)
12328 gdb_assert (bpt
!= NULL
);
12330 /* Has this bp already been deleted? This can happen because
12331 multiple lists can hold pointers to bp's. bpstat lists are
12334 One example of this happening is a watchpoint's scope bp. When
12335 the scope bp triggers, we notice that the watchpoint is out of
12336 scope, and delete it. We also delete its scope bp. But the
12337 scope bp is marked "auto-deleting", and is already on a bpstat.
12338 That bpstat is then checked for auto-deleting bp's, which are
12341 A real solution to this problem might involve reference counts in
12342 bp's, and/or giving them pointers back to their referencing
12343 bpstat's, and teaching delete_breakpoint to only free a bp's
12344 storage when no more references were extent. A cheaper bandaid
12346 if (bpt
->type
== bp_none
)
12349 /* At least avoid this stale reference until the reference counting
12350 of breakpoints gets resolved. */
12351 if (bpt
->related_breakpoint
!= bpt
)
12353 struct breakpoint
*related
;
12354 struct watchpoint
*w
;
12356 if (bpt
->type
== bp_watchpoint_scope
)
12357 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12358 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12359 w
= (struct watchpoint
*) bpt
;
12363 watchpoint_del_at_next_stop (w
);
12365 /* Unlink bpt from the bpt->related_breakpoint ring. */
12366 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12367 related
= related
->related_breakpoint
);
12368 related
->related_breakpoint
= bpt
->related_breakpoint
;
12369 bpt
->related_breakpoint
= bpt
;
12372 /* watch_command_1 creates a watchpoint but only sets its number if
12373 update_watchpoint succeeds in creating its bp_locations. If there's
12374 a problem in that process, we'll be asked to delete the half-created
12375 watchpoint. In that case, don't announce the deletion. */
12377 gdb::observers::breakpoint_deleted
.notify (bpt
);
12379 if (breakpoint_chain
== bpt
)
12380 breakpoint_chain
= bpt
->next
;
12382 for (breakpoint
*b
: all_breakpoints ())
12383 if (b
->next
== bpt
)
12385 b
->next
= bpt
->next
;
12389 /* Be sure no bpstat's are pointing at the breakpoint after it's
12391 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12392 in all threads for now. Note that we cannot just remove bpstats
12393 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12394 commands are associated with the bpstat; if we remove it here,
12395 then the later call to bpstat_do_actions (&stop_bpstat); in
12396 event-top.c won't do anything, and temporary breakpoints with
12397 commands won't work. */
12399 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12401 /* Now that breakpoint is removed from breakpoint list, update the
12402 global location list. This will remove locations that used to
12403 belong to this breakpoint. Do this before freeing the breakpoint
12404 itself, since remove_breakpoint looks at location's owner. It
12405 might be better design to have location completely
12406 self-contained, but it's not the case now. */
12407 update_global_location_list (UGLL_DONT_INSERT
);
12409 /* On the chance that someone will soon try again to delete this
12410 same bp, we mark it as deleted before freeing its storage. */
12411 bpt
->type
= bp_none
;
12415 /* Iterator function to call a user-provided callback function once
12416 for each of B and its related breakpoints. */
12419 iterate_over_related_breakpoints (struct breakpoint
*b
,
12420 gdb::function_view
<void (breakpoint
*)> function
)
12422 struct breakpoint
*related
;
12427 struct breakpoint
*next
;
12429 /* FUNCTION may delete RELATED. */
12430 next
= related
->related_breakpoint
;
12432 if (next
== related
)
12434 /* RELATED is the last ring entry. */
12435 function (related
);
12437 /* FUNCTION may have deleted it, so we'd never reach back to
12438 B. There's nothing left to do anyway, so just break
12443 function (related
);
12447 while (related
!= b
);
12451 delete_command (const char *arg
, int from_tty
)
12457 int breaks_to_delete
= 0;
12459 /* Delete all breakpoints if no argument. Do not delete
12460 internal breakpoints, these have to be deleted with an
12461 explicit breakpoint number argument. */
12462 for (breakpoint
*b
: all_breakpoints ())
12463 if (user_breakpoint_p (b
))
12465 breaks_to_delete
= 1;
12469 /* Ask user only if there are some breakpoints to delete. */
12471 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12472 for (breakpoint
*b
: all_breakpoints_safe ())
12473 if (user_breakpoint_p (b
))
12474 delete_breakpoint (b
);
12477 map_breakpoint_numbers
12478 (arg
, [&] (breakpoint
*br
)
12480 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12484 /* Return true if all locations of B bound to PSPACE are pending. If
12485 PSPACE is NULL, all locations of all program spaces are
12489 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12491 for (bp_location
*loc
: b
->locations ())
12492 if ((pspace
== NULL
12493 || loc
->pspace
== pspace
)
12494 && !loc
->shlib_disabled
12495 && !loc
->pspace
->executing_startup
)
12500 /* Subroutine of update_breakpoint_locations to simplify it.
12501 Return true if multiple fns in list LOC have the same name.
12502 Null names are ignored. */
12505 ambiguous_names_p (struct bp_location
*loc
)
12507 struct bp_location
*l
;
12508 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12511 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12514 const char *name
= l
->function_name
.get ();
12516 /* Allow for some names to be NULL, ignore them. */
12520 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12522 /* NOTE: We can assume slot != NULL here because xcalloc never
12532 /* When symbols change, it probably means the sources changed as well,
12533 and it might mean the static tracepoint markers are no longer at
12534 the same address or line numbers they used to be at last we
12535 checked. Losing your static tracepoints whenever you rebuild is
12536 undesirable. This function tries to resync/rematch gdb static
12537 tracepoints with the markers on the target, for static tracepoints
12538 that have not been set by marker id. Static tracepoint that have
12539 been set by marker id are reset by marker id in breakpoint_re_set.
12542 1) For a tracepoint set at a specific address, look for a marker at
12543 the old PC. If one is found there, assume to be the same marker.
12544 If the name / string id of the marker found is different from the
12545 previous known name, assume that means the user renamed the marker
12546 in the sources, and output a warning.
12548 2) For a tracepoint set at a given line number, look for a marker
12549 at the new address of the old line number. If one is found there,
12550 assume to be the same marker. If the name / string id of the
12551 marker found is different from the previous known name, assume that
12552 means the user renamed the marker in the sources, and output a
12555 3) If a marker is no longer found at the same address or line, it
12556 may mean the marker no longer exists. But it may also just mean
12557 the code changed a bit. Maybe the user added a few lines of code
12558 that made the marker move up or down (in line number terms). Ask
12559 the target for info about the marker with the string id as we knew
12560 it. If found, update line number and address in the matching
12561 static tracepoint. This will get confused if there's more than one
12562 marker with the same ID (possible in UST, although unadvised
12563 precisely because it confuses tools). */
12565 static struct symtab_and_line
12566 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12568 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12569 struct static_tracepoint_marker marker
;
12574 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12576 if (target_static_tracepoint_marker_at (pc
, &marker
))
12578 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12579 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12580 b
->number
, tp
->static_trace_marker_id
.c_str (),
12581 marker
.str_id
.c_str ());
12583 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12588 /* Old marker wasn't found on target at lineno. Try looking it up
12590 if (!sal
.explicit_pc
12592 && sal
.symtab
!= NULL
12593 && !tp
->static_trace_marker_id
.empty ())
12595 std::vector
<static_tracepoint_marker
> markers
12596 = target_static_tracepoint_markers_by_strid
12597 (tp
->static_trace_marker_id
.c_str ());
12599 if (!markers
.empty ())
12601 struct symbol
*sym
;
12602 struct static_tracepoint_marker
*tpmarker
;
12603 struct ui_out
*uiout
= current_uiout
;
12605 tpmarker
= &markers
[0];
12607 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12609 warning (_("marker for static tracepoint %d (%s) not "
12610 "found at previous line number"),
12611 b
->number
, tp
->static_trace_marker_id
.c_str ());
12613 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12614 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12615 uiout
->text ("Now in ");
12618 uiout
->field_string ("func", sym
->print_name (),
12619 function_name_style
.style ());
12620 uiout
->text (" at ");
12622 uiout
->field_string ("file",
12623 symtab_to_filename_for_display (sal2
.symtab
),
12624 file_name_style
.style ());
12627 if (uiout
->is_mi_like_p ())
12629 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12631 uiout
->field_string ("fullname", fullname
);
12634 uiout
->field_signed ("line", sal2
.line
);
12635 uiout
->text ("\n");
12637 b
->loc
->line_number
= sal2
.line
;
12638 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12640 std::unique_ptr
<explicit_location_spec
> els
12641 (new explicit_location_spec ());
12642 els
->source_filename
12643 = xstrdup (symtab_to_filename_for_display (sal2
.symtab
));
12644 els
->line_offset
.offset
= b
->loc
->line_number
;
12645 els
->line_offset
.sign
= LINE_OFFSET_NONE
;
12647 b
->locspec
= std::move (els
);
12649 /* Might be nice to check if function changed, and warn if
12656 /* Returns true iff locations A and B are sufficiently same that
12657 we don't need to report breakpoint as changed. */
12660 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12664 if (a
->address
!= b
->address
)
12667 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12670 if (a
->enabled
!= b
->enabled
)
12673 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12680 if ((a
== NULL
) != (b
== NULL
))
12686 /* Split all locations of B that are bound to PSPACE out of B's
12687 location list to a separate list and return that list's head. If
12688 PSPACE is NULL, hoist out all locations of B. */
12690 static struct bp_location
*
12691 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12693 struct bp_location head
;
12694 struct bp_location
*i
= b
->loc
;
12695 struct bp_location
**i_link
= &b
->loc
;
12696 struct bp_location
*hoisted
= &head
;
12698 if (pspace
== NULL
)
12709 if (i
->pspace
== pspace
)
12724 /* Create new breakpoint locations for B (a hardware or software
12725 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12726 zero, then B is a ranged breakpoint. Only recreates locations for
12727 FILTER_PSPACE. Locations of other program spaces are left
12731 update_breakpoint_locations (code_breakpoint
*b
,
12732 struct program_space
*filter_pspace
,
12733 gdb::array_view
<const symtab_and_line
> sals
,
12734 gdb::array_view
<const symtab_and_line
> sals_end
)
12736 struct bp_location
*existing_locations
;
12738 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12740 /* Ranged breakpoints have only one start location and one end
12742 b
->enable_state
= bp_disabled
;
12743 gdb_printf (gdb_stderr
,
12744 _("Could not reset ranged breakpoint %d: "
12745 "multiple locations found\n"),
12750 /* If there's no new locations, and all existing locations are
12751 pending, don't do anything. This optimizes the common case where
12752 all locations are in the same shared library, that was unloaded.
12753 We'd like to retain the location, so that when the library is
12754 loaded again, we don't loose the enabled/disabled status of the
12755 individual locations. */
12756 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12759 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12761 for (const auto &sal
: sals
)
12763 struct bp_location
*new_loc
;
12765 switch_to_program_space_and_thread (sal
.pspace
);
12767 new_loc
= b
->add_location (sal
);
12769 /* Reparse conditions, they might contain references to the
12771 if (b
->cond_string
!= NULL
)
12775 s
= b
->cond_string
.get ();
12778 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12779 block_for_pc (sal
.pc
),
12782 catch (const gdb_exception_error
&e
)
12784 new_loc
->disabled_by_cond
= true;
12788 if (!sals_end
.empty ())
12790 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12792 new_loc
->length
= end
- sals
[0].pc
+ 1;
12796 /* If possible, carry over 'disable' status from existing
12799 struct bp_location
*e
= existing_locations
;
12800 /* If there are multiple breakpoints with the same function name,
12801 e.g. for inline functions, comparing function names won't work.
12802 Instead compare pc addresses; this is just a heuristic as things
12803 may have moved, but in practice it gives the correct answer
12804 often enough until a better solution is found. */
12805 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12807 for (; e
; e
= e
->next
)
12809 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12811 if (have_ambiguous_names
)
12813 for (bp_location
*l
: b
->locations ())
12815 /* Ignore software vs hardware location type at
12816 this point, because with "set breakpoint
12817 auto-hw", after a re-set, locations that were
12818 hardware can end up as software, or vice versa.
12819 As mentioned above, this is an heuristic and in
12820 practice should give the correct answer often
12822 if (breakpoint_locations_match (e
, l
, true))
12824 l
->enabled
= e
->enabled
;
12825 l
->disabled_by_cond
= e
->disabled_by_cond
;
12832 for (bp_location
*l
: b
->locations ())
12833 if (l
->function_name
12834 && strcmp (e
->function_name
.get (),
12835 l
->function_name
.get ()) == 0)
12837 l
->enabled
= e
->enabled
;
12838 l
->disabled_by_cond
= e
->disabled_by_cond
;
12846 if (!locations_are_equal (existing_locations
, b
->loc
))
12847 gdb::observers::breakpoint_modified
.notify (b
);
12850 /* Find the SaL locations corresponding to the given LOCSPEC.
12851 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12853 std::vector
<symtab_and_line
>
12854 code_breakpoint::location_spec_to_sals (location_spec
*locspec
,
12855 struct program_space
*search_pspace
,
12858 struct gdb_exception exception
;
12860 std::vector
<symtab_and_line
> sals
;
12864 sals
= decode_location_spec (locspec
, search_pspace
);
12866 catch (gdb_exception_error
&e
)
12868 int not_found_and_ok
= false;
12870 /* For pending breakpoints, it's expected that parsing will
12871 fail until the right shared library is loaded. User has
12872 already told to create pending breakpoints and don't need
12873 extra messages. If breakpoint is in bp_shlib_disabled
12874 state, then user already saw the message about that
12875 breakpoint being disabled, and don't want to see more
12877 if (e
.error
== NOT_FOUND_ERROR
12878 && (condition_not_parsed
12880 && search_pspace
!= NULL
12881 && loc
->pspace
!= search_pspace
)
12882 || (loc
&& loc
->shlib_disabled
)
12883 || (loc
&& loc
->pspace
->executing_startup
)
12884 || enable_state
== bp_disabled
))
12885 not_found_and_ok
= true;
12887 if (!not_found_and_ok
)
12889 /* We surely don't want to warn about the same breakpoint
12890 10 times. One solution, implemented here, is disable
12891 the breakpoint on error. Another solution would be to
12892 have separate 'warning emitted' flag. Since this
12893 happens only when a binary has changed, I don't know
12894 which approach is better. */
12895 enable_state
= bp_disabled
;
12899 exception
= std::move (e
);
12902 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
12904 for (auto &sal
: sals
)
12905 resolve_sal_pc (&sal
);
12906 if (condition_not_parsed
&& extra_string
!= NULL
)
12908 gdb::unique_xmalloc_ptr
<char> local_cond
, local_extra
;
12909 int local_thread
, local_task
;
12911 find_condition_and_thread_for_sals (sals
, extra_string
.get (),
12912 &local_cond
, &local_thread
,
12913 &local_task
, &local_extra
);
12914 gdb_assert (cond_string
== nullptr);
12915 if (local_cond
!= nullptr)
12916 cond_string
= std::move (local_cond
);
12917 thread
= local_thread
;
12919 if (local_extra
!= nullptr)
12920 extra_string
= std::move (local_extra
);
12921 condition_not_parsed
= 0;
12924 if (type
== bp_static_tracepoint
)
12925 sals
[0] = update_static_tracepoint (this, sals
[0]);
12935 /* The default re_set method, for typical hardware or software
12936 breakpoints. Reevaluate the breakpoint and recreate its
12940 code_breakpoint::re_set_default ()
12942 struct program_space
*filter_pspace
= current_program_space
;
12943 std::vector
<symtab_and_line
> expanded
, expanded_end
;
12946 std::vector
<symtab_and_line
> sals
= location_spec_to_sals (locspec
.get (),
12950 expanded
= std::move (sals
);
12952 if (locspec_range_end
!= nullptr)
12954 std::vector
<symtab_and_line
> sals_end
12955 = location_spec_to_sals (locspec_range_end
.get (),
12956 filter_pspace
, &found
);
12958 expanded_end
= std::move (sals_end
);
12961 update_breakpoint_locations (this, filter_pspace
, expanded
, expanded_end
);
12964 /* Default method for creating SALs from an address string. It basically
12965 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12968 create_sals_from_location_spec_default (location_spec
*locspec
,
12969 struct linespec_result
*canonical
)
12971 parse_breakpoint_sals (locspec
, canonical
);
12974 /* Reset a breakpoint. */
12977 breakpoint_re_set_one (breakpoint
*b
)
12979 input_radix
= b
->input_radix
;
12980 set_language (b
->language
);
12985 /* Re-set breakpoint locations for the current program space.
12986 Locations bound to other program spaces are left untouched. */
12989 breakpoint_re_set (void)
12992 scoped_restore_current_language save_language
;
12993 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
12994 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12996 /* breakpoint_re_set_one sets the current_language to the language
12997 of the breakpoint it is resetting (see prepare_re_set_context)
12998 before re-evaluating the breakpoint's location. This change can
12999 unfortunately get undone by accident if the language_mode is set
13000 to auto, and we either switch frames, or more likely in this context,
13001 we select the current frame.
13003 We prevent this by temporarily turning the language_mode to
13004 language_mode_manual. We restore it once all breakpoints
13005 have been reset. */
13006 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13007 language_mode
= language_mode_manual
;
13009 /* Note: we must not try to insert locations until after all
13010 breakpoints have been re-set. Otherwise, e.g., when re-setting
13011 breakpoint 1, we'd insert the locations of breakpoint 2, which
13012 hadn't been re-set yet, and thus may have stale locations. */
13014 for (breakpoint
*b
: all_breakpoints_safe ())
13018 breakpoint_re_set_one (b
);
13020 catch (const gdb_exception
&ex
)
13022 exception_fprintf (gdb_stderr
, ex
,
13023 "Error in re-setting breakpoint %d: ",
13028 jit_breakpoint_re_set ();
13031 create_overlay_event_breakpoint ();
13032 create_longjmp_master_breakpoint ();
13033 create_std_terminate_master_breakpoint ();
13034 create_exception_master_breakpoint ();
13036 /* Now we can insert. */
13037 update_global_location_list (UGLL_MAY_INSERT
);
13040 /* Reset the thread number of this breakpoint:
13042 - If the breakpoint is for all threads, leave it as-is.
13043 - Else, reset it to the current thread for inferior_ptid. */
13045 breakpoint_re_set_thread (struct breakpoint
*b
)
13047 if (b
->thread
!= -1)
13049 b
->thread
= inferior_thread ()->global_num
;
13051 /* We're being called after following a fork. The new fork is
13052 selected as current, and unless this was a vfork will have a
13053 different program space from the original thread. Reset that
13055 b
->loc
->pspace
= current_program_space
;
13059 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13060 If from_tty is nonzero, it prints a message to that effect,
13061 which ends with a period (no newline). */
13064 set_ignore_count (int bptnum
, int count
, int from_tty
)
13069 for (breakpoint
*b
: all_breakpoints ())
13070 if (b
->number
== bptnum
)
13072 if (is_tracepoint (b
))
13074 if (from_tty
&& count
!= 0)
13075 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13080 b
->ignore_count
= count
;
13084 gdb_printf (_("Will stop next time "
13085 "breakpoint %d is reached."),
13087 else if (count
== 1)
13088 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13091 gdb_printf (_("Will ignore next %d "
13092 "crossings of breakpoint %d."),
13095 gdb::observers::breakpoint_modified
.notify (b
);
13099 error (_("No breakpoint number %d."), bptnum
);
13102 /* Command to set ignore-count of breakpoint N to COUNT. */
13105 ignore_command (const char *args
, int from_tty
)
13107 const char *p
= args
;
13111 error_no_arg (_("a breakpoint number"));
13113 num
= get_number (&p
);
13115 error (_("bad breakpoint number: '%s'"), args
);
13117 error (_("Second argument (specified ignore-count) is missing."));
13119 set_ignore_count (num
,
13120 longest_to_int (value_as_long (parse_and_eval (p
))),
13127 /* Call FUNCTION on each of the breakpoints with numbers in the range
13128 defined by BP_NUM_RANGE (an inclusive range). */
13131 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13132 gdb::function_view
<void (breakpoint
*)> function
)
13134 if (bp_num_range
.first
== 0)
13136 warning (_("bad breakpoint number at or near '%d'"),
13137 bp_num_range
.first
);
13141 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13143 bool match
= false;
13145 for (breakpoint
*b
: all_breakpoints_safe ())
13146 if (b
->number
== i
)
13153 gdb_printf (_("No breakpoint number %d.\n"), i
);
13158 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13162 map_breakpoint_numbers (const char *args
,
13163 gdb::function_view
<void (breakpoint
*)> function
)
13165 if (args
== NULL
|| *args
== '\0')
13166 error_no_arg (_("one or more breakpoint numbers"));
13168 number_or_range_parser
parser (args
);
13170 while (!parser
.finished ())
13172 int num
= parser
.get_number ();
13173 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13177 /* Return the breakpoint location structure corresponding to the
13178 BP_NUM and LOC_NUM values. */
13180 static struct bp_location
*
13181 find_location_by_number (int bp_num
, int loc_num
)
13183 breakpoint
*b
= get_breakpoint (bp_num
);
13185 if (!b
|| b
->number
!= bp_num
)
13186 error (_("Bad breakpoint number '%d'"), bp_num
);
13189 error (_("Bad breakpoint location number '%d'"), loc_num
);
13192 for (bp_location
*loc
: b
->locations ())
13193 if (++n
== loc_num
)
13196 error (_("Bad breakpoint location number '%d'"), loc_num
);
13199 /* Modes of operation for extract_bp_num. */
13200 enum class extract_bp_kind
13202 /* Extracting a breakpoint number. */
13205 /* Extracting a location number. */
13209 /* Extract a breakpoint or location number (as determined by KIND)
13210 from the string starting at START. TRAILER is a character which
13211 can be found after the number. If you don't want a trailer, use
13212 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13213 string. This always returns a positive integer. */
13216 extract_bp_num (extract_bp_kind kind
, const char *start
,
13217 int trailer
, const char **end_out
= NULL
)
13219 const char *end
= start
;
13220 int num
= get_number_trailer (&end
, trailer
);
13222 error (kind
== extract_bp_kind::bp
13223 ? _("Negative breakpoint number '%.*s'")
13224 : _("Negative breakpoint location number '%.*s'"),
13225 int (end
- start
), start
);
13227 error (kind
== extract_bp_kind::bp
13228 ? _("Bad breakpoint number '%.*s'")
13229 : _("Bad breakpoint location number '%.*s'"),
13230 int (end
- start
), start
);
13232 if (end_out
!= NULL
)
13237 /* Extract a breakpoint or location range (as determined by KIND) in
13238 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13239 representing the (inclusive) range. The returned pair's elements
13240 are always positive integers. */
13242 static std::pair
<int, int>
13243 extract_bp_or_bp_range (extract_bp_kind kind
,
13244 const std::string
&arg
,
13245 std::string::size_type arg_offset
)
13247 std::pair
<int, int> range
;
13248 const char *bp_loc
= &arg
[arg_offset
];
13249 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13250 if (dash
!= std::string::npos
)
13252 /* bp_loc is a range (x-z). */
13253 if (arg
.length () == dash
+ 1)
13254 error (kind
== extract_bp_kind::bp
13255 ? _("Bad breakpoint number at or near: '%s'")
13256 : _("Bad breakpoint location number at or near: '%s'"),
13260 const char *start_first
= bp_loc
;
13261 const char *start_second
= &arg
[dash
+ 1];
13262 range
.first
= extract_bp_num (kind
, start_first
, '-');
13263 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13265 if (range
.first
> range
.second
)
13266 error (kind
== extract_bp_kind::bp
13267 ? _("Inverted breakpoint range at '%.*s'")
13268 : _("Inverted breakpoint location range at '%.*s'"),
13269 int (end
- start_first
), start_first
);
13273 /* bp_loc is a single value. */
13274 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13275 range
.second
= range
.first
;
13280 /* Extract the breakpoint/location range specified by ARG. Returns
13281 the breakpoint range in BP_NUM_RANGE, and the location range in
13284 ARG may be in any of the following forms:
13286 x where 'x' is a breakpoint number.
13287 x-y where 'x' and 'y' specify a breakpoint numbers range.
13288 x.y where 'x' is a breakpoint number and 'y' a location number.
13289 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13290 location number range.
13294 extract_bp_number_and_location (const std::string
&arg
,
13295 std::pair
<int, int> &bp_num_range
,
13296 std::pair
<int, int> &bp_loc_range
)
13298 std::string::size_type dot
= arg
.find ('.');
13300 if (dot
!= std::string::npos
)
13302 /* Handle 'x.y' and 'x.y-z' cases. */
13304 if (arg
.length () == dot
+ 1 || dot
== 0)
13305 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13308 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13309 bp_num_range
.second
= bp_num_range
.first
;
13311 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13316 /* Handle x and x-y cases. */
13318 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13319 bp_loc_range
.first
= 0;
13320 bp_loc_range
.second
= 0;
13324 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13325 specifies whether to enable or disable. */
13328 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13330 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13333 if (loc
->disabled_by_cond
&& enable
)
13334 error (_("Breakpoint %d's condition is invalid at location %d, "
13335 "cannot enable."), bp_num
, loc_num
);
13337 if (loc
->enabled
!= enable
)
13339 loc
->enabled
= enable
;
13340 mark_breakpoint_location_modified (loc
);
13342 if (target_supports_enable_disable_tracepoint ()
13343 && current_trace_status ()->running
&& loc
->owner
13344 && is_tracepoint (loc
->owner
))
13345 target_disable_tracepoint (loc
);
13347 update_global_location_list (UGLL_DONT_INSERT
);
13349 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13352 /* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
13353 owner. 1-based indexing. -1 signals NOT FOUND. */
13356 find_loc_num_by_location (const bp_location
*loc
)
13358 if (loc
!= nullptr && loc
->owner
!= nullptr)
13360 /* Locations use 1-based indexing. */
13362 for (bp_location
*it
: loc
->owner
->locations ())
13372 /* Enable or disable a breakpoint location LOC. ENABLE
13373 specifies whether to enable or disable. */
13376 enable_disable_bp_location (bp_location
*loc
, bool enable
)
13378 if (loc
== nullptr)
13379 error (_("Breakpoint location is invalid."));
13381 if (loc
->owner
== nullptr)
13382 error (_("Breakpoint location does not have an owner breakpoint."));
13384 if (loc
->disabled_by_cond
&& enable
)
13386 int loc_num
= find_loc_num_by_location (loc
);
13388 error (_("Breakpoint location LOC_NUM could not be found."));
13390 error (_("Breakpoint %d's condition is invalid at location %d, "
13391 "cannot enable."), loc
->owner
->number
, loc_num
);
13394 if (loc
->enabled
!= enable
)
13396 loc
->enabled
= enable
;
13397 mark_breakpoint_location_modified (loc
);
13400 if (target_supports_enable_disable_tracepoint ()
13401 && current_trace_status ()->running
&& loc
->owner
13402 && is_tracepoint (loc
->owner
))
13403 target_disable_tracepoint (loc
);
13405 update_global_location_list (UGLL_DONT_INSERT
);
13406 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13409 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13410 number of the breakpoint, and BP_LOC_RANGE specifies the
13411 (inclusive) range of location numbers of that breakpoint to
13412 enable/disable. ENABLE specifies whether to enable or disable the
13416 enable_disable_breakpoint_location_range (int bp_num
,
13417 std::pair
<int, int> &bp_loc_range
,
13420 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13421 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13424 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13425 If from_tty is nonzero, it prints a message to that effect,
13426 which ends with a period (no newline). */
13429 disable_breakpoint (struct breakpoint
*bpt
)
13431 /* Never disable a watchpoint scope breakpoint; we want to
13432 hit them when we leave scope so we can delete both the
13433 watchpoint and its scope breakpoint at that time. */
13434 if (bpt
->type
== bp_watchpoint_scope
)
13437 bpt
->enable_state
= bp_disabled
;
13439 /* Mark breakpoint locations modified. */
13440 mark_breakpoint_modified (bpt
);
13442 if (target_supports_enable_disable_tracepoint ()
13443 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13445 for (bp_location
*location
: bpt
->locations ())
13446 target_disable_tracepoint (location
);
13449 update_global_location_list (UGLL_DONT_INSERT
);
13451 gdb::observers::breakpoint_modified
.notify (bpt
);
13454 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13455 specified in ARGS. ARGS may be in any of the formats handled by
13456 extract_bp_number_and_location. ENABLE specifies whether to enable
13457 or disable the breakpoints/locations. */
13460 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13464 for (breakpoint
*bpt
: all_breakpoints ())
13465 if (user_breakpoint_p (bpt
))
13468 enable_breakpoint (bpt
);
13470 disable_breakpoint (bpt
);
13475 std::string num
= extract_arg (&args
);
13477 while (!num
.empty ())
13479 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13481 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13483 if (bp_loc_range
.first
== bp_loc_range
.second
13484 && (bp_loc_range
.first
== 0
13485 || (bp_loc_range
.first
== 1
13486 && bp_num_range
.first
== bp_num_range
.second
13487 && !has_multiple_locations (bp_num_range
.first
))))
13489 /* Handle breakpoint ids with formats 'x' or 'x-z'
13490 or 'y.1' where y has only one code location. */
13491 map_breakpoint_number_range (bp_num_range
,
13493 ? enable_breakpoint
13494 : disable_breakpoint
);
13498 /* Handle breakpoint ids with formats 'x.y' or
13500 enable_disable_breakpoint_location_range
13501 (bp_num_range
.first
, bp_loc_range
, enable
);
13503 num
= extract_arg (&args
);
13508 /* The disable command disables the specified breakpoints/locations
13509 (or all defined breakpoints) so they're no longer effective in
13510 stopping the inferior. ARGS may be in any of the forms defined in
13511 extract_bp_number_and_location. */
13514 disable_command (const char *args
, int from_tty
)
13516 enable_disable_command (args
, from_tty
, false);
13520 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13523 int target_resources_ok
;
13525 if (bpt
->type
== bp_hardware_breakpoint
)
13528 i
= hw_breakpoint_used_count ();
13529 target_resources_ok
=
13530 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13532 if (target_resources_ok
== 0)
13533 error (_("No hardware breakpoint support in the target."));
13534 else if (target_resources_ok
< 0)
13535 error (_("Hardware breakpoints used exceeds limit."));
13538 if (is_watchpoint (bpt
))
13540 /* Initialize it just to avoid a GCC false warning. */
13541 enum enable_state orig_enable_state
= bp_disabled
;
13545 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13547 orig_enable_state
= bpt
->enable_state
;
13548 bpt
->enable_state
= bp_enabled
;
13549 update_watchpoint (w
, true /* reparse */);
13551 catch (const gdb_exception_error
&e
)
13553 bpt
->enable_state
= orig_enable_state
;
13554 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13560 bpt
->enable_state
= bp_enabled
;
13562 /* Mark breakpoint locations modified. */
13563 mark_breakpoint_modified (bpt
);
13565 if (target_supports_enable_disable_tracepoint ()
13566 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13568 for (bp_location
*location
: bpt
->locations ())
13569 target_enable_tracepoint (location
);
13572 bpt
->disposition
= disposition
;
13573 bpt
->enable_count
= count
;
13574 update_global_location_list (UGLL_MAY_INSERT
);
13576 gdb::observers::breakpoint_modified
.notify (bpt
);
13581 enable_breakpoint (struct breakpoint
*bpt
)
13583 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13586 /* The enable command enables the specified breakpoints/locations (or
13587 all defined breakpoints) so they once again become (or continue to
13588 be) effective in stopping the inferior. ARGS may be in any of the
13589 forms defined in extract_bp_number_and_location. */
13592 enable_command (const char *args
, int from_tty
)
13594 enable_disable_command (args
, from_tty
, true);
13598 enable_once_command (const char *args
, int from_tty
)
13600 map_breakpoint_numbers
13601 (args
, [&] (breakpoint
*b
)
13603 iterate_over_related_breakpoints
13604 (b
, [&] (breakpoint
*bpt
)
13606 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13612 enable_count_command (const char *args
, int from_tty
)
13617 error_no_arg (_("hit count"));
13619 count
= get_number (&args
);
13621 map_breakpoint_numbers
13622 (args
, [&] (breakpoint
*b
)
13624 iterate_over_related_breakpoints
13625 (b
, [&] (breakpoint
*bpt
)
13627 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13633 enable_delete_command (const char *args
, int from_tty
)
13635 map_breakpoint_numbers
13636 (args
, [&] (breakpoint
*b
)
13638 iterate_over_related_breakpoints
13639 (b
, [&] (breakpoint
*bpt
)
13641 enable_breakpoint_disp (bpt
, disp_del
, 1);
13646 /* Invalidate last known value of any hardware watchpoint if
13647 the memory which that value represents has been written to by
13651 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13652 CORE_ADDR addr
, ssize_t len
,
13653 const bfd_byte
*data
)
13655 for (breakpoint
*bp
: all_breakpoints ())
13656 if (bp
->enable_state
== bp_enabled
13657 && bp
->type
== bp_hardware_watchpoint
)
13659 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13661 if (wp
->val_valid
&& wp
->val
!= nullptr)
13663 for (bp_location
*loc
: bp
->locations ())
13664 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13665 && loc
->address
+ loc
->length
> addr
13666 && addr
+ len
> loc
->address
)
13669 wp
->val_valid
= false;
13675 /* Create and insert a breakpoint for software single step. */
13678 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13679 const address_space
*aspace
,
13682 struct thread_info
*tp
= inferior_thread ();
13683 struct symtab_and_line sal
;
13684 CORE_ADDR pc
= next_pc
;
13686 if (tp
->control
.single_step_breakpoints
== NULL
)
13688 std::unique_ptr
<breakpoint
> b
13689 (new momentary_breakpoint (gdbarch
, bp_single_step
,
13690 current_program_space
,
13694 tp
->control
.single_step_breakpoints
13695 = add_to_breakpoint_chain (std::move (b
));
13698 sal
= find_pc_line (pc
, 0);
13700 sal
.section
= find_pc_overlay (pc
);
13701 sal
.explicit_pc
= 1;
13704 = (gdb::checked_static_cast
<momentary_breakpoint
*>
13705 (tp
->control
.single_step_breakpoints
));
13706 ss_bp
->add_location (sal
);
13708 update_global_location_list (UGLL_INSERT
);
13711 /* Insert single step breakpoints according to the current state. */
13714 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13716 struct regcache
*regcache
= get_current_regcache ();
13717 std::vector
<CORE_ADDR
> next_pcs
;
13719 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13721 if (!next_pcs
.empty ())
13723 frame_info_ptr frame
= get_current_frame ();
13724 const address_space
*aspace
= get_frame_address_space (frame
);
13726 for (CORE_ADDR pc
: next_pcs
)
13727 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13735 /* See breakpoint.h. */
13738 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13739 const address_space
*aspace
,
13742 for (bp_location
*loc
: bp
->locations ())
13744 && breakpoint_location_address_match (loc
, aspace
, pc
))
13750 /* Check whether a software single-step breakpoint is inserted at
13754 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13757 for (breakpoint
*bpt
: all_breakpoints ())
13759 if (bpt
->type
== bp_single_step
13760 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13766 /* Tracepoint-specific operations. */
13768 /* Set tracepoint count to NUM. */
13770 set_tracepoint_count (int num
)
13772 tracepoint_count
= num
;
13773 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13777 trace_command (const char *arg
, int from_tty
)
13779 location_spec_up locspec
= string_to_location_spec (&arg
,
13781 const struct breakpoint_ops
*ops
= breakpoint_ops_for_location_spec
13782 (locspec
.get (), true /* is_tracepoint */);
13784 create_breakpoint (get_current_arch (),
13786 NULL
, 0, arg
, false, 1 /* parse arg */,
13788 bp_tracepoint
/* type_wanted */,
13789 0 /* Ignore count */,
13790 pending_break_support
,
13794 0 /* internal */, 0);
13798 ftrace_command (const char *arg
, int from_tty
)
13800 location_spec_up locspec
= string_to_location_spec (&arg
,
13802 create_breakpoint (get_current_arch (),
13804 NULL
, 0, arg
, false, 1 /* parse arg */,
13806 bp_fast_tracepoint
/* type_wanted */,
13807 0 /* Ignore count */,
13808 pending_break_support
,
13809 &code_breakpoint_ops
,
13812 0 /* internal */, 0);
13815 /* strace command implementation. Creates a static tracepoint. */
13818 strace_command (const char *arg
, int from_tty
)
13820 const struct breakpoint_ops
*ops
;
13821 location_spec_up locspec
;
13824 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13825 or with a normal static tracepoint. */
13826 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13828 ops
= &strace_marker_breakpoint_ops
;
13829 locspec
= new_linespec_location_spec (&arg
,
13830 symbol_name_match_type::FULL
);
13831 type
= bp_static_marker_tracepoint
;
13835 ops
= &code_breakpoint_ops
;
13836 locspec
= string_to_location_spec (&arg
, current_language
);
13837 type
= bp_static_tracepoint
;
13840 create_breakpoint (get_current_arch (),
13842 NULL
, 0, arg
, false, 1 /* parse arg */,
13844 type
/* type_wanted */,
13845 0 /* Ignore count */,
13846 pending_break_support
,
13850 0 /* internal */, 0);
13853 /* Set up a fake reader function that gets command lines from a linked
13854 list that was acquired during tracepoint uploading. */
13856 static struct uploaded_tp
*this_utp
;
13857 static int next_cmd
;
13859 static const char *
13860 read_uploaded_action (std::string
&buffer
)
13862 char *rslt
= nullptr;
13864 if (next_cmd
< this_utp
->cmd_strings
.size ())
13866 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13873 /* Given information about a tracepoint as recorded on a target (which
13874 can be either a live system or a trace file), attempt to create an
13875 equivalent GDB tracepoint. This is not a reliable process, since
13876 the target does not necessarily have all the information used when
13877 the tracepoint was originally defined. */
13879 struct tracepoint
*
13880 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13882 const char *addr_str
;
13883 char small_buf
[100];
13884 struct tracepoint
*tp
;
13886 if (utp
->at_string
)
13887 addr_str
= utp
->at_string
.get ();
13890 /* In the absence of a source location, fall back to raw
13891 address. Since there is no way to confirm that the address
13892 means the same thing as when the trace was started, warn the
13894 warning (_("Uploaded tracepoint %d has no "
13895 "source location, using raw address"),
13897 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13898 addr_str
= small_buf
;
13901 /* There's not much we can do with a sequence of bytecodes. */
13902 if (utp
->cond
&& !utp
->cond_string
)
13903 warning (_("Uploaded tracepoint %d condition "
13904 "has no source form, ignoring it"),
13907 location_spec_up locspec
= string_to_location_spec (&addr_str
,
13909 if (!create_breakpoint (get_current_arch (),
13911 utp
->cond_string
.get (), -1, addr_str
,
13912 false /* force_condition */,
13913 0 /* parse cond/thread */,
13915 utp
->type
/* type_wanted */,
13916 0 /* Ignore count */,
13917 pending_break_support
,
13918 &code_breakpoint_ops
,
13920 utp
->enabled
/* enabled */,
13922 CREATE_BREAKPOINT_FLAGS_INSERTED
))
13925 /* Get the tracepoint we just created. */
13926 tp
= get_tracepoint (tracepoint_count
);
13927 gdb_assert (tp
!= NULL
);
13931 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
13934 trace_pass_command (small_buf
, 0);
13937 /* If we have uploaded versions of the original commands, set up a
13938 special-purpose "reader" function and call the usual command line
13939 reader, then pass the result to the breakpoint command-setting
13941 if (!utp
->cmd_strings
.empty ())
13943 counted_command_line cmd_list
;
13948 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
13950 breakpoint_set_commands (tp
, std::move (cmd_list
));
13952 else if (!utp
->actions
.empty ()
13953 || !utp
->step_actions
.empty ())
13954 warning (_("Uploaded tracepoint %d actions "
13955 "have no source form, ignoring them"),
13958 /* Copy any status information that might be available. */
13959 tp
->hit_count
= utp
->hit_count
;
13960 tp
->traceframe_usage
= utp
->traceframe_usage
;
13965 /* Print information on tracepoint number TPNUM_EXP, or all if
13969 info_tracepoints_command (const char *args
, int from_tty
)
13971 struct ui_out
*uiout
= current_uiout
;
13974 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
13976 if (num_printed
== 0)
13978 if (args
== NULL
|| *args
== '\0')
13979 uiout
->message ("No tracepoints.\n");
13981 uiout
->message ("No tracepoint matching '%s'.\n", args
);
13984 default_collect_info ();
13987 /* The 'enable trace' command enables tracepoints.
13988 Not supported by all targets. */
13990 enable_trace_command (const char *args
, int from_tty
)
13992 enable_command (args
, from_tty
);
13995 /* The 'disable trace' command disables tracepoints.
13996 Not supported by all targets. */
13998 disable_trace_command (const char *args
, int from_tty
)
14000 disable_command (args
, from_tty
);
14003 /* Remove a tracepoint (or all if no argument). */
14005 delete_trace_command (const char *arg
, int from_tty
)
14011 int breaks_to_delete
= 0;
14013 /* Delete all breakpoints if no argument.
14014 Do not delete internal or call-dummy breakpoints, these
14015 have to be deleted with an explicit breakpoint number
14017 for (breakpoint
*tp
: all_tracepoints ())
14018 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14020 breaks_to_delete
= 1;
14024 /* Ask user only if there are some breakpoints to delete. */
14026 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14028 for (breakpoint
*b
: all_breakpoints_safe ())
14029 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14030 delete_breakpoint (b
);
14034 map_breakpoint_numbers
14035 (arg
, [&] (breakpoint
*br
)
14037 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14041 /* Helper function for trace_pass_command. */
14044 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14046 tp
->pass_count
= count
;
14047 gdb::observers::breakpoint_modified
.notify (tp
);
14049 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14050 tp
->number
, count
);
14053 /* Set passcount for tracepoint.
14055 First command argument is passcount, second is tracepoint number.
14056 If tracepoint number omitted, apply to most recently defined.
14057 Also accepts special argument "all". */
14060 trace_pass_command (const char *args
, int from_tty
)
14062 struct tracepoint
*t1
;
14065 if (args
== 0 || *args
== 0)
14066 error (_("passcount command requires an "
14067 "argument (count + optional TP num)"));
14069 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14071 args
= skip_spaces (args
);
14072 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14074 args
+= 3; /* Skip special argument "all". */
14076 error (_("Junk at end of arguments."));
14078 for (breakpoint
*b
: all_tracepoints ())
14080 t1
= (struct tracepoint
*) b
;
14081 trace_pass_set_count (t1
, count
, from_tty
);
14084 else if (*args
== '\0')
14086 t1
= get_tracepoint_by_number (&args
, NULL
);
14088 trace_pass_set_count (t1
, count
, from_tty
);
14092 number_or_range_parser
parser (args
);
14093 while (!parser
.finished ())
14095 t1
= get_tracepoint_by_number (&args
, &parser
);
14097 trace_pass_set_count (t1
, count
, from_tty
);
14102 struct tracepoint
*
14103 get_tracepoint (int num
)
14105 for (breakpoint
*t
: all_tracepoints ())
14106 if (t
->number
== num
)
14107 return (struct tracepoint
*) t
;
14112 /* Find the tracepoint with the given target-side number (which may be
14113 different from the tracepoint number after disconnecting and
14116 struct tracepoint
*
14117 get_tracepoint_by_number_on_target (int num
)
14119 for (breakpoint
*b
: all_tracepoints ())
14121 struct tracepoint
*t
= (struct tracepoint
*) b
;
14123 if (t
->number_on_target
== num
)
14130 /* Utility: parse a tracepoint number and look it up in the list.
14131 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14132 If the argument is missing, the most recent tracepoint
14133 (tracepoint_count) is returned. */
14135 struct tracepoint
*
14136 get_tracepoint_by_number (const char **arg
,
14137 number_or_range_parser
*parser
)
14140 const char *instring
= arg
== NULL
? NULL
: *arg
;
14142 if (parser
!= NULL
)
14144 gdb_assert (!parser
->finished ());
14145 tpnum
= parser
->get_number ();
14147 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14148 tpnum
= tracepoint_count
;
14150 tpnum
= get_number (arg
);
14154 if (instring
&& *instring
)
14155 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14158 gdb_printf (_("No previous tracepoint\n"));
14162 for (breakpoint
*t
: all_tracepoints ())
14163 if (t
->number
== tpnum
)
14164 return (struct tracepoint
*) t
;
14166 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14171 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
14175 struct thread_info
*thr
= find_thread_global_id (thread
);
14176 gdb_printf (fp
, " thread %s", print_full_thread_id (thr
));
14180 gdb_printf (fp
, " task %d", task
);
14182 gdb_printf (fp
, "\n");
14185 /* Save information on user settable breakpoints (watchpoints, etc) to
14186 a new script file named FILENAME. If FILTER is non-NULL, call it
14187 on each breakpoint and only include the ones for which it returns
14191 save_breakpoints (const char *filename
, int from_tty
,
14192 bool (*filter
) (const struct breakpoint
*))
14195 int extra_trace_bits
= 0;
14197 if (filename
== 0 || *filename
== 0)
14198 error (_("Argument required (file name in which to save)"));
14200 /* See if we have anything to save. */
14201 for (breakpoint
*tp
: all_breakpoints ())
14203 /* Skip internal and momentary breakpoints. */
14204 if (!user_breakpoint_p (tp
))
14207 /* If we have a filter, only save the breakpoints it accepts. */
14208 if (filter
&& !filter (tp
))
14213 if (is_tracepoint (tp
))
14215 extra_trace_bits
= 1;
14217 /* We can stop searching. */
14224 warning (_("Nothing to save."));
14228 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14232 if (!fp
.open (expanded_filename
.get (), "w"))
14233 error (_("Unable to open file '%s' for saving (%s)"),
14234 expanded_filename
.get (), safe_strerror (errno
));
14236 if (extra_trace_bits
)
14237 save_trace_state_variables (&fp
);
14239 for (breakpoint
*tp
: all_breakpoints ())
14241 /* Skip internal and momentary breakpoints. */
14242 if (!user_breakpoint_p (tp
))
14245 /* If we have a filter, only save the breakpoints it accepts. */
14246 if (filter
&& !filter (tp
))
14249 tp
->print_recreate (&fp
);
14251 /* Note, we can't rely on tp->number for anything, as we can't
14252 assume the recreated breakpoint numbers will match. Use $bpnum
14255 if (tp
->cond_string
)
14256 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14258 if (tp
->ignore_count
)
14259 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14261 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14263 fp
.puts (" commands\n");
14265 ui_out_redirect_pop
redir (current_uiout
, &fp
);
14266 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14268 fp
.puts (" end\n");
14271 if (tp
->enable_state
== bp_disabled
)
14272 fp
.puts ("disable $bpnum\n");
14274 /* If this is a multi-location breakpoint, check if the locations
14275 should be individually disabled. Watchpoint locations are
14276 special, and not user visible. */
14277 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14281 for (bp_location
*loc
: tp
->locations ())
14284 fp
.printf ("disable $bpnum.%d\n", n
);
14291 if (extra_trace_bits
&& !default_collect
.empty ())
14292 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14295 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14298 /* The `save breakpoints' command. */
14301 save_breakpoints_command (const char *args
, int from_tty
)
14303 save_breakpoints (args
, from_tty
, NULL
);
14306 /* The `save tracepoints' command. */
14309 save_tracepoints_command (const char *args
, int from_tty
)
14311 save_breakpoints (args
, from_tty
, is_tracepoint
);
14315 /* This help string is used to consolidate all the help string for specifying
14316 locations used by several commands. */
14318 #define LOCATION_SPEC_HELP_STRING \
14319 "Linespecs are colon-separated lists of location parameters, such as\n\
14320 source filename, function name, label name, and line number.\n\
14321 Example: To specify the start of a label named \"the_top\" in the\n\
14322 function \"fact\" in the file \"factorial.c\", use\n\
14323 \"factorial.c:fact:the_top\".\n\
14325 Address locations begin with \"*\" and specify an exact address in the\n\
14326 program. Example: To specify the fourth byte past the start function\n\
14327 \"main\", use \"*main + 4\".\n\
14329 Explicit locations are similar to linespecs but use an option/argument\n\
14330 syntax to specify location parameters.\n\
14331 Example: To specify the start of the label named \"the_top\" in the\n\
14332 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14333 -function fact -label the_top\".\n\
14335 By default, a specified function is matched against the program's\n\
14336 functions in all scopes. For C++, this means in all namespaces and\n\
14337 classes. For Ada, this means in all packages. E.g., in C++,\n\
14338 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14339 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14340 specified name as a complete fully-qualified name instead."
14342 /* This help string is used for the break, hbreak, tbreak and thbreak
14343 commands. It is defined as a macro to prevent duplication.
14344 COMMAND should be a string constant containing the name of the
14347 #define BREAK_ARGS_HELP(command) \
14348 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14349 \t[-force-condition] [if CONDITION]\n\
14350 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14351 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14352 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14353 `-probe-dtrace' (for a DTrace probe).\n\
14354 LOCATION may be a linespec, address, or explicit location as described\n\
14357 With no LOCATION, uses current execution address of the selected\n\
14358 stack frame. This is useful for breaking on return to a stack frame.\n\
14360 THREADNUM is the number from \"info threads\".\n\
14361 CONDITION is a boolean expression.\n\
14363 With the \"-force-condition\" flag, the condition is defined even when\n\
14364 it is invalid for all current locations.\n\
14365 \n" LOCATION_SPEC_HELP_STRING "\n\n\
14366 Multiple breakpoints at one place are permitted, and useful if their\n\
14367 conditions are different.\n\
14369 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14371 /* List of subcommands for "catch". */
14372 static struct cmd_list_element
*catch_cmdlist
;
14374 /* List of subcommands for "tcatch". */
14375 static struct cmd_list_element
*tcatch_cmdlist
;
14378 add_catch_command (const char *name
, const char *docstring
,
14379 cmd_func_ftype
*func
,
14380 completer_ftype
*completer
,
14381 void *user_data_catch
,
14382 void *user_data_tcatch
)
14384 struct cmd_list_element
*command
;
14386 command
= add_cmd (name
, class_breakpoint
, docstring
,
14388 command
->func
= func
;
14389 command
->set_context (user_data_catch
);
14390 set_cmd_completer (command
, completer
);
14392 command
= add_cmd (name
, class_breakpoint
, docstring
,
14394 command
->func
= func
;
14395 command
->set_context (user_data_tcatch
);
14396 set_cmd_completer (command
, completer
);
14399 /* False if any of the breakpoint's locations could be a location where
14400 functions have been inlined, true otherwise. */
14403 is_non_inline_function (struct breakpoint
*b
)
14405 /* The shared library event breakpoint is set on the address of a
14406 non-inline function. */
14407 return (b
->type
== bp_shlib_event
);
14410 /* Nonzero if the specified PC cannot be a location where functions
14411 have been inlined. */
14414 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14415 const target_waitstatus
&ws
)
14417 for (breakpoint
*b
: all_breakpoints ())
14419 if (!is_non_inline_function (b
))
14422 for (bp_location
*bl
: b
->locations ())
14424 if (!bl
->shlib_disabled
14425 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14433 /* Remove any references to OBJFILE which is going to be freed. */
14436 breakpoint_free_objfile (struct objfile
*objfile
)
14438 for (bp_location
*loc
: all_bp_locations ())
14439 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14440 loc
->symtab
= NULL
;
14443 /* Chain containing all defined "enable breakpoint" subcommands. */
14445 static struct cmd_list_element
*enablebreaklist
= NULL
;
14447 /* See breakpoint.h. */
14449 cmd_list_element
*commands_cmd_element
= nullptr;
14451 void _initialize_breakpoint ();
14453 _initialize_breakpoint ()
14455 struct cmd_list_element
*c
;
14457 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14459 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14461 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14464 breakpoint_chain
= 0;
14465 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14466 before a breakpoint is set. */
14467 breakpoint_count
= 0;
14469 tracepoint_count
= 0;
14471 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14472 Set ignore-count of breakpoint number N to COUNT.\n\
14473 Usage is `ignore N COUNT'."));
14475 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14476 commands_command
, _("\
14477 Set commands to be executed when the given breakpoints are hit.\n\
14478 Give a space-separated breakpoint list as argument after \"commands\".\n\
14479 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14481 With no argument, the targeted breakpoint is the last one set.\n\
14482 The commands themselves follow starting on the next line.\n\
14483 Type a line containing \"end\" to indicate the end of them.\n\
14484 Give \"silent\" as the first line to make the breakpoint silent;\n\
14485 then no output is printed when it is hit, except what the commands print."));
14487 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14488 static std::string condition_command_help
14489 = gdb::option::build_help (_("\
14490 Specify breakpoint number N to break only if COND is true.\n\
14491 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14492 is an expression to be evaluated whenever breakpoint N is reached.\n\
14495 %OPTIONS%"), cc_opts
);
14497 c
= add_com ("condition", class_breakpoint
, condition_command
,
14498 condition_command_help
.c_str ());
14499 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14501 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14502 Set a temporary breakpoint.\n\
14503 Like \"break\" except the breakpoint is only temporary,\n\
14504 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14505 by using \"enable delete\" on the breakpoint number.\n\
14507 BREAK_ARGS_HELP ("tbreak")));
14508 set_cmd_completer (c
, location_completer
);
14510 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14511 Set a hardware assisted breakpoint.\n\
14512 Like \"break\" except the breakpoint requires hardware support,\n\
14513 some target hardware may not have this support.\n\
14515 BREAK_ARGS_HELP ("hbreak")));
14516 set_cmd_completer (c
, location_completer
);
14518 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14519 Set a temporary hardware assisted breakpoint.\n\
14520 Like \"hbreak\" except the breakpoint is only temporary,\n\
14521 so it will be deleted when hit.\n\
14523 BREAK_ARGS_HELP ("thbreak")));
14524 set_cmd_completer (c
, location_completer
);
14526 cmd_list_element
*enable_cmd
14527 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14528 Enable all or some breakpoints.\n\
14529 Usage: enable [BREAKPOINTNUM]...\n\
14530 Give breakpoint numbers (separated by spaces) as arguments.\n\
14531 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14532 This is used to cancel the effect of the \"disable\" command.\n\
14533 With a subcommand you can enable temporarily."),
14534 &enablelist
, 1, &cmdlist
);
14536 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14538 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14539 Enable all or some breakpoints.\n\
14540 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14541 Give breakpoint numbers (separated by spaces) as arguments.\n\
14542 This is used to cancel the effect of the \"disable\" command.\n\
14543 May be abbreviated to simply \"enable\"."),
14544 &enablebreaklist
, 1, &enablelist
);
14546 add_cmd ("once", no_class
, enable_once_command
, _("\
14547 Enable some breakpoints for one hit.\n\
14548 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14549 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14552 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14553 Enable some breakpoints and delete when hit.\n\
14554 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14555 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14558 add_cmd ("count", no_class
, enable_count_command
, _("\
14559 Enable some breakpoints for COUNT hits.\n\
14560 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14561 If a breakpoint is hit while enabled in this fashion,\n\
14562 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14565 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14566 Enable some breakpoints and delete when hit.\n\
14567 Usage: enable delete BREAKPOINTNUM...\n\
14568 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14571 add_cmd ("once", no_class
, enable_once_command
, _("\
14572 Enable some breakpoints for one hit.\n\
14573 Usage: enable once BREAKPOINTNUM...\n\
14574 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14577 add_cmd ("count", no_class
, enable_count_command
, _("\
14578 Enable some breakpoints for COUNT hits.\n\
14579 Usage: enable count COUNT BREAKPOINTNUM...\n\
14580 If a breakpoint is hit while enabled in this fashion,\n\
14581 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14584 cmd_list_element
*disable_cmd
14585 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14586 Disable all or some breakpoints.\n\
14587 Usage: disable [BREAKPOINTNUM]...\n\
14588 Arguments are breakpoint numbers with spaces in between.\n\
14589 To disable all breakpoints, give no argument.\n\
14590 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14591 &disablelist
, 1, &cmdlist
);
14592 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14593 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14595 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14596 Disable all or some breakpoints.\n\
14597 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14598 Arguments are breakpoint numbers with spaces in between.\n\
14599 To disable all breakpoints, give no argument.\n\
14600 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14601 This command may be abbreviated \"disable\"."),
14604 cmd_list_element
*delete_cmd
14605 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14606 Delete all or some breakpoints.\n\
14607 Usage: delete [BREAKPOINTNUM]...\n\
14608 Arguments are breakpoint numbers with spaces in between.\n\
14609 To delete all breakpoints, give no argument.\n\
14611 Also a prefix command for deletion of other GDB objects."),
14612 &deletelist
, 1, &cmdlist
);
14613 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14614 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14616 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14617 Delete all or some breakpoints or auto-display expressions.\n\
14618 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14619 Arguments are breakpoint numbers with spaces in between.\n\
14620 To delete all breakpoints, give no argument.\n\
14621 This command may be abbreviated \"delete\"."),
14624 cmd_list_element
*clear_cmd
14625 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14626 Clear breakpoint at specified location.\n\
14627 Argument may be a linespec, explicit, or address location as described below.\n\
14629 With no argument, clears all breakpoints in the line that the selected frame\n\
14630 is executing in.\n"
14631 "\n" LOCATION_SPEC_HELP_STRING
"\n\n\
14632 See also the \"delete\" command which clears breakpoints by number."));
14633 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14635 cmd_list_element
*break_cmd
14636 = add_com ("break", class_breakpoint
, break_command
, _("\
14637 Set breakpoint at specified location.\n"
14638 BREAK_ARGS_HELP ("break")));
14639 set_cmd_completer (break_cmd
, location_completer
);
14641 add_com_alias ("b", break_cmd
, class_run
, 1);
14642 add_com_alias ("br", break_cmd
, class_run
, 1);
14643 add_com_alias ("bre", break_cmd
, class_run
, 1);
14644 add_com_alias ("brea", break_cmd
, class_run
, 1);
14646 cmd_list_element
*info_breakpoints_cmd
14647 = add_info ("breakpoints", info_breakpoints_command
, _("\
14648 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14649 The \"Type\" column indicates one of:\n\
14650 \tbreakpoint - normal breakpoint\n\
14651 \twatchpoint - watchpoint\n\
14652 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14653 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14654 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14655 address and file/line number respectively.\n\
14657 Convenience variable \"$_\" and default examine address for \"x\"\n\
14658 are set to the address of the last breakpoint listed unless the command\n\
14659 is prefixed with \"server \".\n\n\
14660 Convenience variable \"$bpnum\" contains the number of the last\n\
14661 breakpoint set."));
14663 add_info_alias ("b", info_breakpoints_cmd
, 1);
14665 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14666 Status of all breakpoints, or breakpoint number NUMBER.\n\
14667 The \"Type\" column indicates one of:\n\
14668 \tbreakpoint - normal breakpoint\n\
14669 \twatchpoint - watchpoint\n\
14670 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14671 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14672 \tuntil - internal breakpoint used by the \"until\" command\n\
14673 \tfinish - internal breakpoint used by the \"finish\" command\n\
14674 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14675 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14676 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14677 address and file/line number respectively.\n\
14679 Convenience variable \"$_\" and default examine address for \"x\"\n\
14680 are set to the address of the last breakpoint listed unless the command\n\
14681 is prefixed with \"server \".\n\n\
14682 Convenience variable \"$bpnum\" contains the number of the last\n\
14684 &maintenanceinfolist
);
14686 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14687 Set catchpoints to catch events."),
14689 0/*allow-unknown*/, &cmdlist
);
14691 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14692 Set temporary catchpoints to catch events."),
14694 0/*allow-unknown*/, &cmdlist
);
14696 const auto opts
= make_watch_options_def_group (nullptr);
14698 static const std::string watch_help
= gdb::option::build_help (_("\
14699 Set a watchpoint for EXPRESSION.\n\
14700 Usage: watch [-location] EXPRESSION\n\
14705 A watchpoint stops execution of your program whenever the value of\n\
14706 an expression changes."), opts
);
14707 c
= add_com ("watch", class_breakpoint
, watch_command
,
14708 watch_help
.c_str ());
14709 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14711 static const std::string rwatch_help
= gdb::option::build_help (_("\
14712 Set a read watchpoint for EXPRESSION.\n\
14713 Usage: rwatch [-location] EXPRESSION\n\
14718 A read watchpoint stops execution of your program whenever the value of\n\
14719 an expression is read."), opts
);
14720 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14721 rwatch_help
.c_str ());
14722 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14724 static const std::string awatch_help
= gdb::option::build_help (_("\
14725 Set an access watchpoint for EXPRESSION.\n\
14726 Usage: awatch [-location] EXPRESSION\n\
14731 An access watchpoint stops execution of your program whenever the value\n\
14732 of an expression is either read or written."), opts
);
14733 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14734 awatch_help
.c_str ());
14735 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14737 add_info ("watchpoints", info_watchpoints_command
, _("\
14738 Status of specified watchpoints (all watchpoints if no argument)."));
14740 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14741 respond to changes - contrary to the description. */
14742 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14743 &can_use_hw_watchpoints
, _("\
14744 Set debugger's willingness to use watchpoint hardware."), _("\
14745 Show debugger's willingness to use watchpoint hardware."), _("\
14746 If zero, gdb will not use hardware for new watchpoints, even if\n\
14747 such is available. (However, any hardware watchpoints that were\n\
14748 created before setting this to nonzero, will continue to use watchpoint\n\
14751 show_can_use_hw_watchpoints
,
14752 &setlist
, &showlist
);
14754 can_use_hw_watchpoints
= 1;
14756 /* Tracepoint manipulation commands. */
14758 cmd_list_element
*trace_cmd
14759 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14760 Set a tracepoint at specified location.\n\
14762 BREAK_ARGS_HELP ("trace") "\n\
14763 Do \"help tracepoints\" for info on other tracepoint commands."));
14764 set_cmd_completer (trace_cmd
, location_completer
);
14766 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14767 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14768 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14769 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14771 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14772 Set a fast tracepoint at specified location.\n\
14774 BREAK_ARGS_HELP ("ftrace") "\n\
14775 Do \"help tracepoints\" for info on other tracepoint commands."));
14776 set_cmd_completer (c
, location_completer
);
14778 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14779 Set a static tracepoint at location or marker.\n\
14781 strace [LOCATION] [if CONDITION]\n\
14782 LOCATION may be a linespec, explicit, or address location (described below) \n\
14783 or -m MARKER_ID.\n\n\
14784 If a marker id is specified, probe the marker with that name. With\n\
14785 no LOCATION, uses current execution address of the selected stack frame.\n\
14786 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14787 This collects arbitrary user data passed in the probe point call to the\n\
14788 tracing library. You can inspect it when analyzing the trace buffer,\n\
14789 by printing the $_sdata variable like any other convenience variable.\n\
14791 CONDITION is a boolean expression.\n\
14792 \n" LOCATION_SPEC_HELP_STRING
"\n\n\
14793 Multiple tracepoints at one place are permitted, and useful if their\n\
14794 conditions are different.\n\
14796 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14797 Do \"help tracepoints\" for info on other tracepoint commands."));
14798 set_cmd_completer (c
, location_completer
);
14800 cmd_list_element
*info_tracepoints_cmd
14801 = add_info ("tracepoints", info_tracepoints_command
, _("\
14802 Status of specified tracepoints (all tracepoints if no argument).\n\
14803 Convenience variable \"$tpnum\" contains the number of the\n\
14804 last tracepoint set."));
14806 add_info_alias ("tp", info_tracepoints_cmd
, 1);
14808 cmd_list_element
*delete_tracepoints_cmd
14809 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14810 Delete specified tracepoints.\n\
14811 Arguments are tracepoint numbers, separated by spaces.\n\
14812 No argument means delete all tracepoints."),
14814 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
14816 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14817 Disable specified tracepoints.\n\
14818 Arguments are tracepoint numbers, separated by spaces.\n\
14819 No argument means disable all tracepoints."),
14821 deprecate_cmd (c
, "disable");
14823 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14824 Enable specified tracepoints.\n\
14825 Arguments are tracepoint numbers, separated by spaces.\n\
14826 No argument means enable all tracepoints."),
14828 deprecate_cmd (c
, "enable");
14830 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14831 Set the passcount for a tracepoint.\n\
14832 The trace will end when the tracepoint has been passed 'count' times.\n\
14833 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14834 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14836 add_basic_prefix_cmd ("save", class_breakpoint
,
14837 _("Save breakpoint definitions as a script."),
14839 0/*allow-unknown*/, &cmdlist
);
14841 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14842 Save current breakpoint definitions as a script.\n\
14843 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14844 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14845 session to restore them."),
14847 set_cmd_completer (c
, filename_completer
);
14849 cmd_list_element
*save_tracepoints_cmd
14850 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14851 Save current tracepoint definitions as a script.\n\
14852 Use the 'source' command in another debug session to restore them."),
14854 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
14856 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
14857 deprecate_cmd (c
, "save tracepoints");
14859 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
14861 Breakpoint specific settings.\n\
14862 Configure various breakpoint-specific variables such as\n\
14863 pending breakpoint behavior."),
14865 Breakpoint specific settings.\n\
14866 Configure various breakpoint-specific variables such as\n\
14867 pending breakpoint behavior."),
14868 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
14869 &setlist
, &showlist
);
14871 add_setshow_auto_boolean_cmd ("pending", no_class
,
14872 &pending_break_support
, _("\
14873 Set debugger's behavior regarding pending breakpoints."), _("\
14874 Show debugger's behavior regarding pending breakpoints."), _("\
14875 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14876 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14877 an error. If auto, an unrecognized breakpoint location results in a\n\
14878 user-query to see if a pending breakpoint should be created."),
14880 show_pending_break_support
,
14881 &breakpoint_set_cmdlist
,
14882 &breakpoint_show_cmdlist
);
14884 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14886 add_setshow_boolean_cmd ("auto-hw", no_class
,
14887 &automatic_hardware_breakpoints
, _("\
14888 Set automatic usage of hardware breakpoints."), _("\
14889 Show automatic usage of hardware breakpoints."), _("\
14890 If set, the debugger will automatically use hardware breakpoints for\n\
14891 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14892 a warning will be emitted for such breakpoints."),
14894 show_automatic_hardware_breakpoints
,
14895 &breakpoint_set_cmdlist
,
14896 &breakpoint_show_cmdlist
);
14898 add_setshow_boolean_cmd ("always-inserted", class_support
,
14899 &always_inserted_mode
, _("\
14900 Set mode for inserting breakpoints."), _("\
14901 Show mode for inserting breakpoints."), _("\
14902 When this mode is on, breakpoints are inserted immediately as soon as\n\
14903 they're created, kept inserted even when execution stops, and removed\n\
14904 only when the user deletes them. When this mode is off (the default),\n\
14905 breakpoints are inserted only when execution continues, and removed\n\
14906 when execution stops."),
14908 &show_always_inserted_mode
,
14909 &breakpoint_set_cmdlist
,
14910 &breakpoint_show_cmdlist
);
14912 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
14913 condition_evaluation_enums
,
14914 &condition_evaluation_mode_1
, _("\
14915 Set mode of breakpoint condition evaluation."), _("\
14916 Show mode of breakpoint condition evaluation."), _("\
14917 When this is set to \"host\", breakpoint conditions will be\n\
14918 evaluated on the host's side by GDB. When it is set to \"target\",\n\
14919 breakpoint conditions will be downloaded to the target (if the target\n\
14920 supports such feature) and conditions will be evaluated on the target's side.\n\
14921 If this is set to \"auto\" (default), this will be automatically set to\n\
14922 \"target\" if it supports condition evaluation, otherwise it will\n\
14923 be set to \"host\"."),
14924 &set_condition_evaluation_mode
,
14925 &show_condition_evaluation_mode
,
14926 &breakpoint_set_cmdlist
,
14927 &breakpoint_show_cmdlist
);
14929 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14930 Set a breakpoint for an address range.\n\
14931 break-range START-LOCATION, END-LOCATION\n\
14932 where START-LOCATION and END-LOCATION can be one of the following:\n\
14933 LINENUM, for that line in the current file,\n\
14934 FILE:LINENUM, for that line in that file,\n\
14935 +OFFSET, for that number of lines after the current line\n\
14936 or the start of the range\n\
14937 FUNCTION, for the first line in that function,\n\
14938 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14939 *ADDRESS, for the instruction at that address.\n\
14941 The breakpoint will stop execution of the inferior whenever it executes\n\
14942 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14943 range (including START-LOCATION and END-LOCATION)."));
14945 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
14946 Set a dynamic printf at specified location.\n\
14947 dprintf location,format string,arg1,arg2,...\n\
14948 location may be a linespec, explicit, or address location.\n"
14949 "\n" LOCATION_SPEC_HELP_STRING
));
14950 set_cmd_completer (c
, location_completer
);
14952 add_setshow_enum_cmd ("dprintf-style", class_support
,
14953 dprintf_style_enums
, &dprintf_style
, _("\
14954 Set the style of usage for dynamic printf."), _("\
14955 Show the style of usage for dynamic printf."), _("\
14956 This setting chooses how GDB will do a dynamic printf.\n\
14957 If the value is \"gdb\", then the printing is done by GDB to its own\n\
14958 console, as with the \"printf\" command.\n\
14959 If the value is \"call\", the print is done by calling a function in your\n\
14960 program; by default printf(), but you can choose a different function or\n\
14961 output stream by setting dprintf-function and dprintf-channel."),
14962 update_dprintf_commands
, NULL
,
14963 &setlist
, &showlist
);
14965 add_setshow_string_cmd ("dprintf-function", class_support
,
14966 &dprintf_function
, _("\
14967 Set the function to use for dynamic printf."), _("\
14968 Show the function to use for dynamic printf."), NULL
,
14969 update_dprintf_commands
, NULL
,
14970 &setlist
, &showlist
);
14972 add_setshow_string_cmd ("dprintf-channel", class_support
,
14973 &dprintf_channel
, _("\
14974 Set the channel to use for dynamic printf."), _("\
14975 Show the channel to use for dynamic printf."), NULL
,
14976 update_dprintf_commands
, NULL
,
14977 &setlist
, &showlist
);
14979 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
14980 &disconnected_dprintf
, _("\
14981 Set whether dprintf continues after GDB disconnects."), _("\
14982 Show whether dprintf continues after GDB disconnects."), _("\
14983 Use this to let dprintf commands continue to hit and produce output\n\
14984 even if GDB disconnects or detaches from the target."),
14987 &setlist
, &showlist
);
14989 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
14990 Target agent only formatted printing, like the C \"printf\" function.\n\
14991 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
14992 This supports most C printf format specifications, like %s, %d, etc.\n\
14993 This is useful for formatted output in user-defined commands."));
14995 automatic_hardware_breakpoints
= true;
14997 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
14999 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,