1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2024 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/>. */
20 #include "arch-utils.h"
22 #include "event-top.h"
23 #include "exceptions.h"
27 #include "breakpoint.h"
28 #include "tracepoint.h"
30 #include "expression.h"
32 #include "cli/cli-cmds.h"
37 #include "gdbthread.h"
40 #include "gdb-demangle.h"
41 #include "filenames.h"
47 #include "completer.h"
49 #include "cli/cli-script.h"
53 #include "observable.h"
60 #include "parser-defs.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"
72 #include <unordered_set>
73 #include "break-cond-parse.h"
75 /* readline include files */
76 #include "readline/tilde.h"
78 /* readline defines this. */
81 #include "mi/mi-common.h"
82 #include "extension.h"
84 #include "progspace-and-thread.h"
85 #include "gdbsupport/array-view.h"
87 #include "gdbsupport/common-utils.h"
89 /* Prototypes for local functions. */
91 static void map_breakpoint_numbers (const char *,
92 gdb::function_view
<void (breakpoint
*)>);
94 static void parse_breakpoint_sals (location_spec
*locspec
,
95 linespec_result
*canonical
,
96 program_space
*search_pspace
);
98 static void breakpoint_re_set_one (breakpoint
*b
,
99 program_space
*filter_pspace
);
101 static void create_breakpoints_sal (struct gdbarch
*,
102 struct linespec_result
*,
103 gdb::unique_xmalloc_ptr
<char>,
104 gdb::unique_xmalloc_ptr
<char>,
106 enum bpdisp
, int, int, int,
108 int, int, int, unsigned);
110 static int can_use_hardware_watchpoint
111 (const std::vector
<value_ref_ptr
> &vals
);
113 static void mention (const breakpoint
*);
115 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
117 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
119 static struct breakpoint
*
120 momentary_breakpoint_from_master (struct breakpoint
*orig
,
122 int loc_enabled
, int thread
);
124 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, bool);
126 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
129 struct program_space
*pspace
);
131 static bool watchpoint_locations_match (const struct bp_location
*loc1
,
132 const struct bp_location
*loc2
);
134 static bool breakpoint_locations_match (const struct bp_location
*loc1
,
135 const struct bp_location
*loc2
,
136 bool sw_hw_bps_match
= false);
138 static bool breakpoint_location_address_match (struct bp_location
*bl
,
139 const struct address_space
*aspace
,
142 static bool breakpoint_location_address_range_overlap (struct bp_location
*,
143 const address_space
*,
146 static int remove_breakpoint (struct bp_location
*);
147 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
149 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
151 static int hw_breakpoint_used_count (void);
153 static int hw_watchpoint_use_count (struct breakpoint
*);
155 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
157 int *other_type_used
);
159 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
162 static void decref_bp_location (struct bp_location
**loc
);
164 static std::vector
<symtab_and_line
> bkpt_probe_decode_location_spec
165 (struct breakpoint
*b
,
166 location_spec
*locspec
,
167 struct program_space
*search_pspace
);
169 static bool bl_address_is_meaningful (bp_location
*loc
);
171 static int find_loc_num_by_location (const bp_location
*loc
);
173 /* update_global_location_list's modes of operation wrt to whether to
174 insert locations now. */
175 enum ugll_insert_mode
177 /* Don't insert any breakpoint locations into the inferior, only
178 remove already-inserted locations that no longer should be
179 inserted. Functions that delete a breakpoint or breakpoints
180 should specify this mode, so that deleting a breakpoint doesn't
181 have the side effect of inserting the locations of other
182 breakpoints that are marked not-inserted, but should_be_inserted
183 returns true on them.
185 This behavior is useful is situations close to tear-down -- e.g.,
186 after an exec, while the target still has execution, but
187 breakpoint shadows of the previous executable image should *NOT*
188 be restored to the new image; or before detaching, where the
189 target still has execution and wants to delete breakpoints from
190 GDB's lists, and all breakpoints had already been removed from
194 /* May insert breakpoints iff breakpoints_should_be_inserted_now
195 claims breakpoints should be inserted now. */
198 /* Insert locations now, irrespective of
199 breakpoints_should_be_inserted_now. E.g., say all threads are
200 stopped right now, and the user did "continue". We need to
201 insert breakpoints _before_ resuming the target, but
202 UGLL_MAY_INSERT wouldn't insert them, because
203 breakpoints_should_be_inserted_now returns false at that point,
204 as no thread is running yet. */
208 /* Return a textual version of INSERT_MODE. */
211 ugll_insert_mode_text (ugll_insert_mode insert_mode
)
213 /* Make sure the compiler warns if a new ugll_insert_mode enumerator is added
214 but not handled here. */
216 DIAGNOSTIC_ERROR_SWITCH
219 case UGLL_DONT_INSERT
:
220 return "UGLL_DONT_INSERT";
221 case UGLL_MAY_INSERT
:
222 return "UGLL_MAY_INSERT";
224 return "UGLL_INSERT";
228 gdb_assert_not_reached ("must handle all enum values");
231 /* Return a textual version of REASON. */
234 remove_bp_reason_str (remove_bp_reason reason
)
236 /* Make sure the compiler warns if a new remove_bp_reason enumerator is added
237 but not handled here. */
239 DIAGNOSTIC_ERROR_SWITCH
242 case REMOVE_BREAKPOINT
:
243 return "regular remove";
244 case DETACH_BREAKPOINT
:
249 gdb_assert_not_reached ("must handle all enum values");
252 /* Return a textual version of breakpoint location BL describing number,
253 location and address. */
256 breakpoint_location_address_str (const bp_location
*bl
)
258 std::string str
= string_printf ("Breakpoint %d (%s) at address %s",
260 host_address_to_string (bl
),
261 paddress (bl
->gdbarch
, bl
->address
));
263 std::string loc_string
= bl
->to_string ();
264 if (!loc_string
.empty ())
265 str
+= string_printf (" %s", loc_string
.c_str ());
270 static void update_global_location_list (enum ugll_insert_mode
);
272 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
274 static void insert_breakpoint_locations (void);
276 static void trace_pass_command (const char *, int);
278 static void set_tracepoint_count (int num
);
280 static bool is_masked_watchpoint (const struct breakpoint
*b
);
282 /* Return true if B refers to a static tracepoint set by marker ("-m"),
285 static bool strace_marker_p (struct breakpoint
*b
);
287 static void bkpt_probe_create_sals_from_location_spec
288 (location_spec
*locspec
,
289 struct linespec_result
*canonical
,
290 struct program_space
*search_pspace
);
292 const struct breakpoint_ops code_breakpoint_ops
=
294 parse_breakpoint_sals
,
295 create_breakpoints_sal
,
298 /* Breakpoints set on probes. */
299 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
301 bkpt_probe_create_sals_from_location_spec
,
302 create_breakpoints_sal
,
305 /* Tracepoints set on probes. We use the same methods as for breakpoints
307 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
309 bkpt_probe_create_sals_from_location_spec
,
310 create_breakpoints_sal
,
313 /* Implementation of abstract dtors. These must exist to satisfy the
316 breakpoint::~breakpoint ()
320 code_breakpoint::~code_breakpoint ()
324 catchpoint::~catchpoint ()
328 /* The structure to be used in regular breakpoints. */
329 struct ordinary_breakpoint
: public code_breakpoint
331 using code_breakpoint::code_breakpoint
;
333 int resources_needed (const struct bp_location
*) override
;
334 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
335 void print_mention () const override
;
336 void print_recreate (struct ui_file
*fp
) const override
;
339 /* Internal breakpoints. These typically have a lifetime the same as
340 the program, and they end up installed on the breakpoint chain with
341 a negative breakpoint number. They're visible in "maint info
342 breakpoints", but not "info breakpoints". */
343 struct internal_breakpoint
: public code_breakpoint
345 internal_breakpoint (struct gdbarch
*gdbarch
,
346 enum bptype type
, CORE_ADDR address
)
347 : code_breakpoint (gdbarch
, type
)
351 sal
.section
= find_pc_overlay (sal
.pc
);
352 sal
.pspace
= current_program_space
;
355 pspace
= current_program_space
;
356 disposition
= disp_donttouch
;
359 void re_set (program_space
*pspace
) override
;
360 void check_status (struct bpstat
*bs
) override
;
361 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
362 void print_mention () const override
;
365 /* Momentary breakpoints. These typically have a lifetime of some run
366 control command only, are always thread-specific, and have 0 for
367 breakpoint number. I.e., there can be many momentary breakpoints
368 on the breakpoint chain and they all same the same number (zero).
369 They're visible in "maint info breakpoints", but not "info
371 struct momentary_breakpoint
: public code_breakpoint
373 momentary_breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
374 program_space
*pspace_
,
375 const struct frame_id
&frame_id_
,
377 : code_breakpoint (gdbarch_
, bptype
)
379 /* If FRAME_ID is valid, it should be a real frame, not an inlined
380 or tail-called one. */
381 gdb_assert (!frame_id_artificial_p (frame_id
));
383 /* Momentary breakpoints are always thread-specific. */
384 gdb_assert (thread_
> 0);
387 enable_state
= bp_enabled
;
388 disposition
= disp_donttouch
;
389 frame_id
= frame_id_
;
392 /* The inferior should have been set by the parent constructor. */
393 gdb_assert (inferior
== -1);
396 void re_set (program_space
*pspace
) override
;
397 void check_status (struct bpstat
*bs
) override
;
398 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
399 void print_mention () const override
;
402 /* DPrintf breakpoints. */
403 struct dprintf_breakpoint
: public ordinary_breakpoint
405 using ordinary_breakpoint::ordinary_breakpoint
;
407 void re_set (program_space
*pspace
) override
;
408 int breakpoint_hit (const struct bp_location
*bl
,
409 const address_space
*aspace
,
411 const target_waitstatus
&ws
) override
;
412 void print_recreate (struct ui_file
*fp
) const override
;
413 void after_condition_true (struct bpstat
*bs
) override
;
416 /* Ranged breakpoints. */
417 struct ranged_breakpoint
: public ordinary_breakpoint
419 explicit ranged_breakpoint (struct gdbarch
*gdbarch
,
420 const symtab_and_line
&sal_start
,
422 location_spec_up start_locspec
,
423 location_spec_up end_locspec
)
424 : ordinary_breakpoint (gdbarch
, bp_hardware_breakpoint
)
426 bp_location
*bl
= add_location (sal_start
);
429 disposition
= disp_donttouch
;
431 locspec
= std::move (start_locspec
);
432 locspec_range_end
= std::move (end_locspec
);
435 int breakpoint_hit (const struct bp_location
*bl
,
436 const address_space
*aspace
,
438 const target_waitstatus
&ws
) override
;
439 int resources_needed (const struct bp_location
*) override
;
440 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
441 bool print_one (const bp_location
**) const override
;
442 void print_one_detail (struct ui_out
*) const override
;
443 void print_mention () const override
;
444 void print_recreate (struct ui_file
*fp
) const override
;
447 /* Static tracepoints with marker (`-m'). */
448 struct static_marker_tracepoint
: public tracepoint
450 using tracepoint::tracepoint
;
452 std::vector
<symtab_and_line
> decode_location_spec
453 (struct location_spec
*locspec
,
454 struct program_space
*search_pspace
) override
;
457 /* The style in which to perform a dynamic printf. This is a user
458 option because different output options have different tradeoffs;
459 if GDB does the printing, there is better error handling if there
460 is a problem with any of the arguments, but using an inferior
461 function lets you have special-purpose printers and sending of
462 output to the same place as compiled-in print functions. */
464 static const char dprintf_style_gdb
[] = "gdb";
465 static const char dprintf_style_call
[] = "call";
466 static const char dprintf_style_agent
[] = "agent";
467 static const char *const dprintf_style_enums
[] = {
473 static const char *dprintf_style
= dprintf_style_gdb
;
475 /* The function to use for dynamic printf if the preferred style is to
476 call into the inferior. The value is simply a string that is
477 copied into the command, so it can be anything that GDB can
478 evaluate to a callable address, not necessarily a function name. */
480 static std::string dprintf_function
= "printf";
482 /* The channel to use for dynamic printf if the preferred style is to
483 call into the inferior; if a nonempty string, it will be passed to
484 the call as the first argument, with the format string as the
485 second. As with the dprintf function, this can be anything that
486 GDB knows how to evaluate, so in addition to common choices like
487 "stderr", this could be an app-specific expression like
488 "mystreams[curlogger]". */
490 static std::string dprintf_channel
;
492 /* True if dprintf commands should continue to operate even if GDB
494 static bool disconnected_dprintf
= true;
496 struct command_line
*
497 breakpoint_commands (struct breakpoint
*b
)
499 return b
->commands
? b
->commands
.get () : NULL
;
502 /* Flag indicating that a command has proceeded the inferior past the
503 current breakpoint. */
505 static bool breakpoint_proceeded
;
508 bpdisp_text (enum bpdisp disp
)
510 /* NOTE: the following values are a part of MI protocol and
511 represent values of 'disp' field returned when inferior stops at
513 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
515 return bpdisps
[(int) disp
];
518 /* Prototypes for exported functions. */
519 /* If FALSE, gdb will not use hardware support for watchpoints, even
520 if such is available. */
521 static int can_use_hw_watchpoints
;
524 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
525 struct cmd_list_element
*c
,
529 _("Debugger's willingness to use "
530 "watchpoint hardware is %s.\n"),
534 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
535 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
536 for unrecognized breakpoint locations.
537 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
538 static enum auto_boolean pending_break_support
;
540 show_pending_break_support (struct ui_file
*file
, int from_tty
,
541 struct cmd_list_element
*c
,
545 _("Debugger's behavior regarding "
546 "pending breakpoints is %s.\n"),
550 /* If true, gdb will automatically use hardware breakpoints for breakpoints
551 set with "break" but falling in read-only memory.
552 If false, gdb will warn about such breakpoints, but won't automatically
553 use hardware breakpoints. */
554 static bool automatic_hardware_breakpoints
;
556 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
557 struct cmd_list_element
*c
,
561 _("Automatic usage of hardware breakpoints is %s.\n"),
565 /* If on, GDB keeps breakpoints inserted even if the inferior is
566 stopped, and immediately inserts any new breakpoints as soon as
567 they're created. If off (default), GDB keeps breakpoints off of
568 the target as long as possible. That is, it delays inserting
569 breakpoints until the next resume, and removes them again when the
570 target fully stops. This is a bit safer in case GDB crashes while
571 processing user input. */
572 static bool always_inserted_mode
= false;
575 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
576 struct cmd_list_element
*c
, const char *value
)
578 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
582 /* See breakpoint.h. */
583 bool debug_breakpoint
= false;
585 /* "show debug breakpoint" implementation. */
587 show_debug_breakpoint (struct ui_file
*file
, int from_tty
,
588 struct cmd_list_element
*c
, const char *value
)
590 gdb_printf (file
, _("Breakpoint location debugging is %s.\n"), value
);
593 /* See breakpoint.h. */
596 breakpoints_should_be_inserted_now (void)
598 if (gdbarch_has_global_breakpoints (current_inferior ()->arch ()))
600 /* If breakpoints are global, they should be inserted even if no
601 thread under gdb's control is running, or even if there are
602 no threads under GDB's control yet. */
607 if (always_inserted_mode
)
609 /* The user wants breakpoints inserted even if all threads
614 for (inferior
*inf
: all_inferiors ())
615 if (inf
->has_execution ()
616 && threads_are_executing (inf
->process_target ()))
619 /* Don't remove breakpoints yet if, even though all threads are
620 stopped, we still have events to process. */
621 for (thread_info
*tp
: all_non_exited_threads ())
622 if (tp
->resumed () && tp
->has_pending_waitstatus ())
628 static const char condition_evaluation_both
[] = "host or target";
630 /* Modes for breakpoint condition evaluation. */
631 static const char condition_evaluation_auto
[] = "auto";
632 static const char condition_evaluation_host
[] = "host";
633 static const char condition_evaluation_target
[] = "target";
634 static const char *const condition_evaluation_enums
[] = {
635 condition_evaluation_auto
,
636 condition_evaluation_host
,
637 condition_evaluation_target
,
641 /* Global that holds the current mode for breakpoint condition evaluation. */
642 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
644 /* Global that we use to display information to the user (gets its value from
645 condition_evaluation_mode_1. */
646 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
648 /* Translate a condition evaluation mode MODE into either "host"
649 or "target". This is used mostly to translate from "auto" to the
650 real setting that is being used. It returns the translated
654 translate_condition_evaluation_mode (const char *mode
)
656 if (mode
== condition_evaluation_auto
)
658 if (target_supports_evaluation_of_breakpoint_conditions ())
659 return condition_evaluation_target
;
661 return condition_evaluation_host
;
667 /* Discovers what condition_evaluation_auto translates to. */
670 breakpoint_condition_evaluation_mode (void)
672 return translate_condition_evaluation_mode (condition_evaluation_mode
);
675 /* Return true if GDB should evaluate breakpoint conditions or false
679 gdb_evaluates_breakpoint_condition_p (void)
681 const char *mode
= breakpoint_condition_evaluation_mode ();
683 return (mode
== condition_evaluation_host
);
686 /* Are we executing breakpoint commands? */
687 static int executing_breakpoint_commands
;
689 /* Are overlay event breakpoints enabled? */
690 static int overlay_events_enabled
;
692 /* See description in breakpoint.h. */
693 bool target_exact_watchpoints
= false;
695 /* Chains of all breakpoints defined. */
697 static intrusive_list
<breakpoint
> breakpoint_chain
;
699 /* See breakpoint.h. */
704 return breakpoint_range (breakpoint_chain
.begin (), breakpoint_chain
.end ());
707 /* See breakpoint.h. */
709 breakpoint_safe_range
710 all_breakpoints_safe ()
712 return breakpoint_safe_range (all_breakpoints ());
715 /* See breakpoint.h. */
720 return tracepoint_range (tracepoint_iterator (breakpoint_chain
.begin ()),
721 tracepoint_iterator (breakpoint_chain
.end ()));
724 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
726 static std::vector
<bp_location
*> bp_locations
;
728 /* See breakpoint.h. */
730 const std::vector
<bp_location
*> &
736 /* Range to iterate over breakpoint locations at a given address. */
738 struct bp_locations_at_addr_range
740 using iterator
= std::vector
<bp_location
*>::iterator
;
742 bp_locations_at_addr_range (CORE_ADDR addr
)
746 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
747 { return loc
->address
< addr_
; }
749 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
750 { return addr_
< loc
->address
; }
753 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
756 m_begin
= it_pair
.first
;
757 m_end
= it_pair
.second
;
760 iterator
begin () const
763 iterator
end () const
771 /* Return a range to iterate over all breakpoint locations exactly at address
774 If it's needed to iterate multiple times on the same range, it's possible
775 to save the range in a local variable and use it multiple times:
777 auto range = all_bp_locations_at_addr (addr);
779 for (bp_location *loc : range)
782 for (bp_location *loc : range)
785 This saves a bit of time, as it avoids re-doing the binary searches to find
786 the range's boundaries. Just remember not to change the bp_locations vector
787 in the mean time, as it could make the range's iterators stale. */
789 static bp_locations_at_addr_range
790 all_bp_locations_at_addr (CORE_ADDR addr
)
792 return bp_locations_at_addr_range (addr
);
795 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
796 ADDRESS for the current elements of BP_LOCATIONS which get a valid
797 result from bp_location_has_shadow. You can use it for roughly
798 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
799 an address you need to read. */
801 static CORE_ADDR bp_locations_placed_address_before_address_max
;
803 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
804 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
805 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
806 You can use it for roughly limiting the subrange of BP_LOCATIONS to
807 scan for shadow bytes for an address you need to read. */
809 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
811 /* The locations that no longer correspond to any breakpoint, unlinked
812 from the bp_locations array, but for which a hit may still be
813 reported by a target. */
814 static std::vector
<bp_location
*> moribund_locations
;
816 /* Number of last breakpoint made. */
818 static int breakpoint_count
;
820 /* The value of `breakpoint_count' before the last command that
821 created breakpoints. If the last (break-like) command created more
822 than one breakpoint, then the difference between BREAKPOINT_COUNT
823 and PREV_BREAKPOINT_COUNT is more than one. */
824 static int prev_breakpoint_count
;
826 /* Number of last tracepoint made. */
828 static int tracepoint_count
;
830 static struct cmd_list_element
*breakpoint_set_cmdlist
;
831 static struct cmd_list_element
*breakpoint_show_cmdlist
;
832 struct cmd_list_element
*save_cmdlist
;
834 /* Return whether a breakpoint is an active enabled breakpoint. */
836 breakpoint_enabled (struct breakpoint
*b
)
838 return (b
->enable_state
== bp_enabled
);
841 /* Set breakpoint count to NUM. */
844 set_breakpoint_count (int num
)
846 prev_breakpoint_count
= breakpoint_count
;
847 breakpoint_count
= num
;
848 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
851 /* Used by `start_rbreak_breakpoints' below, to record the current
852 breakpoint count before "rbreak" creates any breakpoint. */
853 static int rbreak_start_breakpoint_count
;
855 /* Called at the start an "rbreak" command to record the first
858 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
860 rbreak_start_breakpoint_count
= breakpoint_count
;
863 /* Called at the end of an "rbreak" command to record the last
866 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
868 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
871 /* Used in run_command to zero the hit count when a new run starts. */
874 clear_breakpoint_hit_counts (void)
876 for (breakpoint
&b
: all_breakpoints ())
881 /* Return the breakpoint with the specified number, or NULL
882 if the number does not refer to an existing breakpoint. */
885 get_breakpoint (int num
)
887 for (breakpoint
&b
: all_breakpoints ())
894 /* Return TRUE if NUM refer to an existing breakpoint that has
895 multiple code locations. */
898 has_multiple_locations (int num
)
900 for (breakpoint
&b
: all_breakpoints ())
902 return b
.has_multiple_locations ();
909 /* Mark locations as "conditions have changed" in case the target supports
910 evaluating conditions on its side. */
913 mark_breakpoint_modified (struct breakpoint
*b
)
915 /* This is only meaningful if the target is
916 evaluating conditions and if the user has
917 opted for condition evaluation on the target's
919 if (gdb_evaluates_breakpoint_condition_p ()
920 || !target_supports_evaluation_of_breakpoint_conditions ())
923 if (!is_breakpoint (b
))
926 for (bp_location
&loc
: b
->locations ())
927 loc
.condition_changed
= condition_modified
;
930 /* Mark location as "conditions have changed" in case the target supports
931 evaluating conditions on its side. */
934 mark_breakpoint_location_modified (struct bp_location
*loc
)
936 /* This is only meaningful if the target is
937 evaluating conditions and if the user has
938 opted for condition evaluation on the target's
940 if (gdb_evaluates_breakpoint_condition_p ()
941 || !target_supports_evaluation_of_breakpoint_conditions ())
945 if (!is_breakpoint (loc
->owner
))
948 loc
->condition_changed
= condition_modified
;
951 /* Sets the condition-evaluation mode using the static global
952 condition_evaluation_mode. */
955 set_condition_evaluation_mode (const char *args
, int from_tty
,
956 struct cmd_list_element
*c
)
958 const char *old_mode
, *new_mode
;
960 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
961 && !target_supports_evaluation_of_breakpoint_conditions ())
963 condition_evaluation_mode_1
= condition_evaluation_mode
;
964 warning (_("Target does not support breakpoint condition evaluation.\n"
965 "Using host evaluation mode instead."));
969 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
970 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
972 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
973 settings was "auto". */
974 condition_evaluation_mode
= condition_evaluation_mode_1
;
976 /* Only update the mode if the user picked a different one. */
977 if (new_mode
!= old_mode
)
979 /* If the user switched to a different evaluation mode, we
980 need to synch the changes with the target as follows:
982 "host" -> "target": Send all (valid) conditions to the target.
983 "target" -> "host": Remove all the conditions from the target.
986 if (new_mode
== condition_evaluation_target
)
988 /* Mark everything modified and synch conditions with the
990 for (bp_location
*loc
: all_bp_locations ())
991 mark_breakpoint_location_modified (loc
);
995 /* Manually mark non-duplicate locations to synch conditions
996 with the target. We do this to remove all the conditions the
997 target knows about. */
998 for (bp_location
*loc
: all_bp_locations ())
999 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
1000 loc
->needs_update
= 1;
1003 /* Do the update. */
1004 update_global_location_list (UGLL_MAY_INSERT
);
1010 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
1011 what "auto" is translating to. */
1014 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
1015 struct cmd_list_element
*c
, const char *value
)
1017 if (condition_evaluation_mode
== condition_evaluation_auto
)
1019 _("Breakpoint condition evaluation "
1020 "mode is %s (currently %s).\n"),
1022 breakpoint_condition_evaluation_mode ());
1024 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
1028 /* Parse COND_STRING in the context of LOC and set as the condition
1029 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
1030 the number of LOC within its owner. In case of parsing error, mark
1031 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
1034 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
1035 int bp_num
, int loc_num
)
1037 bool has_junk
= false;
1040 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
1041 block_for_pc (loc
->address
), 0);
1042 if (*cond_string
!= 0)
1046 loc
->cond
= std::move (new_exp
);
1047 if (loc
->disabled_by_cond
&& loc
->enabled
)
1048 gdb_printf (_("Breakpoint %d's condition is now valid at "
1049 "location %d, enabling.\n"),
1052 loc
->disabled_by_cond
= false;
1055 catch (const gdb_exception_error
&e
)
1059 /* Warn if a user-enabled location is now becoming disabled-by-cond.
1060 BP_NUM is 0 if the breakpoint is being defined for the first
1061 time using the "break ... if ..." command, and non-zero if
1064 warning (_("failed to validate condition at location %d.%d, "
1065 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
1067 warning (_("failed to validate condition at location %d, "
1068 "disabling:\n %s"), loc_num
, e
.what ());
1071 loc
->disabled_by_cond
= true;
1075 error (_("Garbage '%s' follows condition"), cond_string
);
1078 /* See breakpoint.h. */
1081 notify_breakpoint_modified (breakpoint
*b
)
1083 interps_notify_breakpoint_modified (b
);
1084 gdb::observers::breakpoint_modified
.notify (b
);
1088 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
1089 int from_tty
, bool force
)
1093 b
->cond_string
.reset ();
1095 if (is_watchpoint (b
))
1096 gdb::checked_static_cast
<watchpoint
*> (b
)->cond_exp
.reset ();
1100 for (bp_location
&loc
: b
->locations ())
1103 if (loc
.disabled_by_cond
&& loc
.enabled
)
1104 gdb_printf (_("Breakpoint %d's condition is now valid at "
1105 "location %d, enabling.\n"),
1106 b
->number
, loc_num
);
1107 loc
.disabled_by_cond
= false;
1110 /* No need to free the condition agent expression
1111 bytecode (if we have one). We will handle this
1112 when we go through update_global_location_list. */
1117 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
1121 if (is_watchpoint (b
))
1123 innermost_block_tracker tracker
;
1124 const char *arg
= exp
;
1125 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
1127 error (_("Junk at end of expression"));
1128 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
1129 w
->cond_exp
= std::move (new_exp
);
1130 w
->cond_exp_valid_block
= tracker
.block ();
1134 /* Parse and set condition expressions. We make two passes.
1135 In the first, we parse the condition string to see if it
1136 is valid in at least one location. If so, the condition
1137 would be accepted. So we go ahead and set the locations'
1138 conditions. In case no valid case is found, we throw
1139 the error and the condition string will be rejected.
1140 This two-pass approach is taken to avoid setting the
1141 state of locations in case of a reject. */
1142 for (const bp_location
&loc
: b
->locations ())
1146 const char *arg
= exp
;
1147 parse_exp_1 (&arg
, loc
.address
,
1148 block_for_pc (loc
.address
), 0);
1150 error (_("Junk at end of expression"));
1153 catch (const gdb_exception_error
&e
)
1155 /* Condition string is invalid. If this happens to
1156 be the last loc, abandon (if not forced) or continue
1158 if (&loc
== &b
->last_loc () && !force
)
1163 /* If we reach here, the condition is valid at some locations. */
1165 for (bp_location
&loc
: b
->locations ())
1167 set_breakpoint_location_condition (exp
, &loc
, b
->number
, loc_num
);
1172 /* We know that the new condition parsed successfully. The
1173 condition string of the breakpoint can be safely updated. */
1174 b
->cond_string
= make_unique_xstrdup (exp
);
1175 b
->condition_not_parsed
= 0;
1177 mark_breakpoint_modified (b
);
1179 notify_breakpoint_modified (b
);
1182 /* See breakpoint.h. */
1185 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1188 for (breakpoint
&b
: all_breakpoints ())
1189 if (b
.number
== bpnum
)
1191 /* Check if this breakpoint has a "stop" method implemented in an
1192 extension language. This method and conditions entered into GDB
1193 from the CLI are mutually exclusive. */
1194 const struct extension_language_defn
*extlang
1195 = get_breakpoint_cond_ext_lang (&b
, EXT_LANG_NONE
);
1197 if (extlang
!= NULL
)
1199 error (_("Only one stop condition allowed. There is currently"
1200 " a %s stop condition defined for this breakpoint."),
1201 ext_lang_capitalized_name (extlang
));
1203 set_breakpoint_condition (&b
, exp
, from_tty
, force
);
1205 if (is_breakpoint (&b
))
1206 update_global_location_list (UGLL_MAY_INSERT
);
1211 error (_("No breakpoint number %d."), bpnum
);
1214 /* The options for the "condition" command. */
1216 struct condition_command_opts
1219 bool force_condition
= false;
1222 static const gdb::option::option_def condition_command_option_defs
[] = {
1224 gdb::option::flag_option_def
<condition_command_opts
> {
1226 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1227 N_("Set the condition even if it is invalid for all current locations."),
1232 /* Create an option_def_group for the "condition" options, with
1233 CC_OPTS as context. */
1235 static inline gdb::option::option_def_group
1236 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1238 return {{condition_command_option_defs
}, cc_opts
};
1241 /* Completion for the "condition" command. */
1244 condition_completer (struct cmd_list_element
*cmd
,
1245 completion_tracker
&tracker
,
1246 const char *text
, const char * /*word*/)
1248 bool has_no_arguments
= (*text
== '\0');
1249 condition_command_opts cc_opts
;
1250 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1251 if (gdb::option::complete_options
1252 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1255 text
= skip_spaces (text
);
1256 const char *space
= skip_to_space (text
);
1263 tracker
.advance_custom_word_point_by (1);
1264 /* We don't support completion of history indices. */
1265 if (!isdigit (text
[1]))
1266 complete_internalvar (tracker
, &text
[1]);
1270 /* Suggest the "-force" flag if no arguments are given. If
1271 arguments were passed, they either already include the flag,
1272 or we are beyond the point of suggesting it because it's
1273 positionally the first argument. */
1274 if (has_no_arguments
)
1275 gdb::option::complete_on_all_options (tracker
, group
);
1277 /* We're completing the breakpoint number. */
1278 len
= strlen (text
);
1280 for (breakpoint
&b
: all_breakpoints ())
1284 xsnprintf (number
, sizeof (number
), "%d", b
.number
);
1286 if (strncmp (number
, text
, len
) == 0)
1287 tracker
.add_completion (make_unique_xstrdup (number
));
1293 /* We're completing the expression part. Skip the breakpoint num. */
1294 const char *exp_start
= skip_spaces (space
);
1295 tracker
.advance_custom_word_point_by (exp_start
- text
);
1297 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1298 expression_completer (cmd
, tracker
, text
, word
);
1301 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1304 condition_command (const char *arg
, int from_tty
)
1310 error_no_arg (_("breakpoint number"));
1314 /* Check if the "-force" flag was passed. */
1315 condition_command_opts cc_opts
;
1316 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1317 gdb::option::process_options
1318 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1320 bnum
= get_number (&p
);
1322 error (_("Bad breakpoint argument: '%s'"), arg
);
1324 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1327 /* Check that COMMAND do not contain commands that are suitable
1328 only for tracepoints and not suitable for ordinary breakpoints.
1329 Throw if any such commands is found. */
1332 check_no_tracepoint_commands (struct command_line
*commands
)
1334 struct command_line
*c
;
1336 for (c
= commands
; c
; c
= c
->next
)
1338 if (c
->control_type
== while_stepping_control
)
1339 error (_("The 'while-stepping' command can "
1340 "only be used for tracepoints"));
1342 check_no_tracepoint_commands (c
->body_list_0
.get ());
1343 check_no_tracepoint_commands (c
->body_list_1
.get ());
1345 /* Not that command parsing removes leading whitespace and comment
1346 lines and also empty lines. So, we only need to check for
1347 command directly. */
1348 if (strstr (c
->line
, "collect ") == c
->line
)
1349 error (_("The 'collect' command can only be used for tracepoints"));
1351 if (strstr (c
->line
, "teval ") == c
->line
)
1352 error (_("The 'teval' command can only be used for tracepoints"));
1356 struct longjmp_breakpoint
: public momentary_breakpoint
1358 using momentary_breakpoint::momentary_breakpoint
;
1360 ~longjmp_breakpoint () override
;
1363 /* Encapsulate tests for different types of tracepoints. */
1366 is_tracepoint_type (bptype type
)
1368 return (type
== bp_tracepoint
1369 || type
== bp_fast_tracepoint
1370 || type
== bp_static_tracepoint
1371 || type
== bp_static_marker_tracepoint
);
1374 /* See breakpoint.h. */
1377 is_tracepoint (const struct breakpoint
*b
)
1379 return is_tracepoint_type (b
->type
);
1382 /* Factory function to create an appropriate instance of breakpoint given
1385 template<typename
... Arg
>
1386 static std::unique_ptr
<code_breakpoint
>
1387 new_breakpoint_from_type (struct gdbarch
*gdbarch
, bptype type
,
1395 case bp_hardware_breakpoint
:
1396 b
= new ordinary_breakpoint (gdbarch
, type
,
1397 std::forward
<Arg
> (args
)...);
1400 case bp_fast_tracepoint
:
1401 case bp_static_tracepoint
:
1403 b
= new tracepoint (gdbarch
, type
,
1404 std::forward
<Arg
> (args
)...);
1407 case bp_static_marker_tracepoint
:
1408 b
= new static_marker_tracepoint (gdbarch
, type
,
1409 std::forward
<Arg
> (args
)...);
1413 b
= new dprintf_breakpoint (gdbarch
, type
,
1414 std::forward
<Arg
> (args
)...);
1418 gdb_assert_not_reached ("invalid type");
1421 return std::unique_ptr
<code_breakpoint
> (b
);
1424 /* A helper function that validates that COMMANDS are valid for a
1425 breakpoint. This function will throw an exception if a problem is
1429 validate_commands_for_breakpoint (struct breakpoint
*b
,
1430 struct command_line
*commands
)
1432 if (is_tracepoint (b
))
1434 tracepoint
*t
= gdb::checked_static_cast
<tracepoint
*> (b
);
1435 struct command_line
*c
;
1436 struct command_line
*while_stepping
= 0;
1438 /* Reset the while-stepping step count. The previous commands
1439 might have included a while-stepping action, while the new
1443 /* We need to verify that each top-level element of commands is
1444 valid for tracepoints, that there's at most one
1445 while-stepping element, and that the while-stepping's body
1446 has valid tracing commands excluding nested while-stepping.
1447 We also need to validate the tracepoint action line in the
1448 context of the tracepoint --- validate_actionline actually
1449 has side effects, like setting the tracepoint's
1450 while-stepping STEP_COUNT, in addition to checking if the
1451 collect/teval actions parse and make sense in the
1452 tracepoint's context. */
1453 for (c
= commands
; c
; c
= c
->next
)
1455 if (c
->control_type
== while_stepping_control
)
1457 if (b
->type
== bp_fast_tracepoint
)
1458 error (_("The 'while-stepping' command "
1459 "cannot be used for fast tracepoint"));
1460 else if (b
->type
== bp_static_tracepoint
1461 || b
->type
== bp_static_marker_tracepoint
)
1462 error (_("The 'while-stepping' command "
1463 "cannot be used for static tracepoint"));
1466 error (_("The 'while-stepping' command "
1467 "can be used only once"));
1472 validate_actionline (c
->line
, t
);
1476 struct command_line
*c2
;
1478 gdb_assert (while_stepping
->body_list_1
== nullptr);
1479 c2
= while_stepping
->body_list_0
.get ();
1480 for (; c2
; c2
= c2
->next
)
1482 if (c2
->control_type
== while_stepping_control
)
1483 error (_("The 'while-stepping' command cannot be nested"));
1489 check_no_tracepoint_commands (commands
);
1493 /* Return a vector of all the static tracepoints set at ADDR. The
1494 caller is responsible for releasing the vector. */
1496 std::vector
<breakpoint
*>
1497 static_tracepoints_here (CORE_ADDR addr
)
1499 std::vector
<breakpoint
*> found
;
1501 for (breakpoint
&b
: all_breakpoints ())
1502 if (b
.type
== bp_static_tracepoint
1503 || b
.type
== bp_static_marker_tracepoint
)
1505 for (bp_location
&loc
: b
.locations ())
1506 if (loc
.address
== addr
)
1507 found
.push_back (&b
);
1513 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1514 validate that only allowed commands are included. */
1517 breakpoint_set_commands (struct breakpoint
*b
,
1518 counted_command_line
&&commands
)
1520 validate_commands_for_breakpoint (b
, commands
.get ());
1522 b
->commands
= std::move (commands
);
1523 notify_breakpoint_modified (b
);
1526 /* Set the internal `silent' flag on the breakpoint. Note that this
1527 is not the same as the "silent" that may appear in the breakpoint's
1531 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1533 int old_silent
= b
->silent
;
1536 if (old_silent
!= silent
)
1537 notify_breakpoint_modified (b
);
1540 /* See breakpoint.h. */
1543 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1545 /* THREAD should be -1, meaning no thread restriction, or it should be a
1546 valid global thread-id, which are greater than zero. */
1547 gdb_assert (thread
== -1 || thread
> 0);
1549 /* It is not valid to set a thread restriction for a breakpoint that
1550 already has task or inferior restriction. */
1551 gdb_assert (thread
== -1 || (b
->task
== -1 && b
->inferior
== -1));
1553 int old_thread
= b
->thread
;
1555 if (old_thread
!= thread
)
1557 /* If THREAD is in a different program_space than OLD_THREAD, or the
1558 breakpoint has switched to or from being thread-specific, then we
1559 need to re-set the locations of this breakpoint. First, figure
1560 out the program_space for the old and new threads, use a value of
1561 nullptr to indicate the breakpoint is in all program spaces. */
1562 program_space
*old_pspace
= nullptr;
1563 if (old_thread
!= -1)
1565 struct thread_info
*thr
= find_thread_global_id (old_thread
);
1566 gdb_assert (thr
!= nullptr);
1567 old_pspace
= thr
->inf
->pspace
;
1570 program_space
*new_pspace
= nullptr;
1573 struct thread_info
*thr
= find_thread_global_id (thread
);
1574 gdb_assert (thr
!= nullptr);
1575 new_pspace
= thr
->inf
->pspace
;
1578 /* If the program space has changed for this breakpoint, then
1579 re-evaluate it's locations. */
1580 if (old_pspace
!= new_pspace
)
1582 /* The breakpoint is now associated with a completely different
1583 program space. Discard all of the current locations and then
1584 re-set the breakpoint in the new program space, this will
1585 create the new locations. */
1586 b
->clear_locations ();
1587 breakpoint_re_set_one (b
, new_pspace
);
1590 /* If the program space didn't change, or the breakpoint didn't
1591 acquire any new locations after the clear_locations call, then we
1592 need to notify of the breakpoint modification now. */
1593 if (old_pspace
== new_pspace
|| !b
->has_locations ())
1594 notify_breakpoint_modified (b
);
1598 /* See breakpoint.h. */
1601 breakpoint_set_inferior (struct breakpoint
*b
, int inferior
)
1603 /* INFERIOR should be -1, meaning no inferior restriction, or it should
1604 be a valid inferior number, which are greater than zero. */
1605 gdb_assert (inferior
== -1 || inferior
> 0);
1607 /* It is not valid to set an inferior restriction for a breakpoint that
1608 already has a task or thread restriction. */
1609 gdb_assert (inferior
== -1 || (b
->task
== -1 && b
->thread
== -1));
1611 int old_inferior
= b
->inferior
;
1612 b
->inferior
= inferior
;
1613 if (old_inferior
!= inferior
)
1615 /* If INFERIOR is in a different program_space than OLD_INFERIOR, or
1616 the breakpoint has switch to or from inferior-specific, then we
1617 need to re-set the locations of this breakpoint. First, figure
1618 out the program_space for the old and new inferiors, use a value
1619 of nullptr to indicate the breakpoint is in all program
1621 program_space
*old_pspace
= nullptr;
1622 if (old_inferior
!= -1)
1624 struct inferior
*inf
= find_inferior_id (old_inferior
);
1625 gdb_assert (inf
!= nullptr);
1626 old_pspace
= inf
->pspace
;
1629 program_space
*new_pspace
= nullptr;
1632 struct inferior
*inf
= find_inferior_id (inferior
);
1633 gdb_assert (inf
!= nullptr);
1634 new_pspace
= inf
->pspace
;
1637 if (old_pspace
!= new_pspace
)
1639 /* The breakpoint is now associated with a completely different
1640 program space. Discard all of the current locations and then
1641 re-set the breakpoint in the new program space, this will
1642 create the new locations. */
1643 b
->clear_locations ();
1644 breakpoint_re_set_one (b
, new_pspace
);
1647 /* If the program space didn't change, or the breakpoint didn't
1648 acquire any new locations after the clear_locations call, then we
1649 need to notify of the breakpoint modification now. */
1650 if (old_pspace
== new_pspace
|| !b
->has_locations ())
1651 notify_breakpoint_modified (b
);
1655 /* See breakpoint.h. */
1658 breakpoint_set_task (struct breakpoint
*b
, int task
)
1660 /* TASK should be -1, meaning no task restriction, or it should be a
1661 valid task-id, which are greater than zero. */
1662 gdb_assert (task
== -1 || task
> 0);
1664 /* It is not valid to set a task restriction for a breakpoint that
1665 already has a thread or inferior restriction. */
1666 gdb_assert (task
== -1 || (b
->thread
== -1 && b
->inferior
== -1));
1668 int old_task
= b
->task
;
1670 if (old_task
!= task
)
1671 notify_breakpoint_modified (b
);
1675 commands_command_1 (const char *arg
, int from_tty
,
1676 struct command_line
*control
)
1678 counted_command_line cmd
;
1679 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1680 NULL after the call to read_command_lines if the user provides an empty
1681 list of command by just typing "end". */
1682 bool cmd_read
= false;
1684 std::string new_arg
;
1686 if (arg
== NULL
|| !*arg
)
1688 /* Argument not explicitly given. Synthesize it. */
1689 if (breakpoint_count
- prev_breakpoint_count
> 1)
1690 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1692 else if (breakpoint_count
> 0)
1693 new_arg
= string_printf ("%d", breakpoint_count
);
1697 /* Create a copy of ARG. This is needed because the "commands"
1698 command may be coming from a script. In that case, the read
1699 line buffer is going to be overwritten in the lambda of
1700 'map_breakpoint_numbers' below when reading the next line
1701 before we are are done parsing the breakpoint numbers. */
1704 arg
= new_arg
.c_str ();
1706 map_breakpoint_numbers
1707 (arg
, [&] (breakpoint
*b
)
1711 gdb_assert (cmd
== NULL
);
1712 if (control
!= NULL
)
1713 cmd
= control
->body_list_0
;
1717 = string_printf (_("Type commands for breakpoint(s) "
1718 "%s, one per line."),
1721 auto do_validate
= [=] (const char *line
)
1724 = gdb::checked_static_cast
<tracepoint
*> (b
);
1725 validate_actionline (line
, t
);
1727 gdb::function_view
<void (const char *)> validator
;
1728 if (is_tracepoint (b
))
1729 validator
= do_validate
;
1731 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1736 /* If a breakpoint was on the list more than once, we don't need to
1738 if (b
->commands
!= cmd
)
1740 validate_commands_for_breakpoint (b
, cmd
.get ());
1742 notify_breakpoint_modified (b
);
1748 commands_command (const char *arg
, int from_tty
)
1750 commands_command_1 (arg
, from_tty
, NULL
);
1753 /* Like commands_command, but instead of reading the commands from
1754 input stream, takes them from an already parsed command structure.
1756 This is used by cli-script.c to DTRT with breakpoint commands
1757 that are part of if and while bodies. */
1758 enum command_control_type
1759 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1761 commands_command_1 (arg
, 0, cmd
);
1762 return simple_control
;
1765 /* Return true if BL->TARGET_INFO contains valid information. */
1768 bp_location_has_shadow (struct bp_location
*bl
)
1770 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1774 if (bl
->target_info
.shadow_len
== 0)
1775 /* BL isn't valid, or doesn't shadow memory. */
1780 /* Update BUF, which is LEN bytes read from the target address
1781 MEMADDR, by replacing a memory breakpoint with its shadowed
1784 If READBUF is not NULL, this buffer must not overlap with the of
1785 the breakpoint location's shadow_contents buffer. Otherwise, a
1786 failed assertion internal error will be raised. */
1789 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1790 const gdb_byte
*writebuf_org
,
1791 ULONGEST memaddr
, LONGEST len
,
1792 struct bp_target_info
*target_info
,
1793 struct gdbarch
*gdbarch
)
1795 /* Now do full processing of the found relevant range of elements. */
1796 CORE_ADDR bp_addr
= 0;
1800 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1801 current_program_space
->aspace
.get (), 0))
1803 /* The breakpoint is inserted in a different address space. */
1807 /* Addresses and length of the part of the breakpoint that
1809 bp_addr
= target_info
->placed_address
;
1810 bp_size
= target_info
->shadow_len
;
1812 if (bp_addr
+ bp_size
<= memaddr
)
1814 /* The breakpoint is entirely before the chunk of memory we are
1819 if (bp_addr
>= memaddr
+ len
)
1821 /* The breakpoint is entirely after the chunk of memory we are
1826 /* Offset within shadow_contents. */
1827 if (bp_addr
< memaddr
)
1829 /* Only copy the second part of the breakpoint. */
1830 bp_size
-= memaddr
- bp_addr
;
1831 bptoffset
= memaddr
- bp_addr
;
1835 if (bp_addr
+ bp_size
> memaddr
+ len
)
1837 /* Only copy the first part of the breakpoint. */
1838 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1841 if (readbuf
!= NULL
)
1843 /* Verify that the readbuf buffer does not overlap with the
1844 shadow_contents buffer. */
1845 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1846 || readbuf
>= (target_info
->shadow_contents
1847 + target_info
->shadow_len
));
1849 /* Update the read buffer with this inserted breakpoint's
1851 memcpy (readbuf
+ bp_addr
- memaddr
,
1852 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1856 const unsigned char *bp
;
1857 CORE_ADDR addr
= target_info
->reqstd_address
;
1860 /* Update the shadow with what we want to write to memory. */
1861 memcpy (target_info
->shadow_contents
+ bptoffset
,
1862 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1864 /* Determine appropriate breakpoint contents and size for this
1866 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1868 /* Update the final write buffer with this inserted
1869 breakpoint's INSN. */
1870 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1874 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1875 by replacing any memory breakpoints with their shadowed contents.
1877 If READBUF is not NULL, this buffer must not overlap with any of
1878 the breakpoint location's shadow_contents buffers. Otherwise,
1879 a failed assertion internal error will be raised.
1881 The range of shadowed area by each bp_location is:
1882 bl->address - bp_locations_placed_address_before_address_max
1883 up to bl->address + bp_locations_shadow_len_after_address_max
1884 The range we were requested to resolve shadows for is:
1885 memaddr ... memaddr + len
1886 Thus the safe cutoff boundaries for performance optimization are
1887 memaddr + len <= (bl->address
1888 - bp_locations_placed_address_before_address_max)
1890 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1893 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1894 const gdb_byte
*writebuf_org
,
1895 ULONGEST memaddr
, LONGEST len
)
1897 /* Left boundary, right boundary and median element of our binary
1899 unsigned bc_l
, bc_r
, bc
;
1901 /* Find BC_L which is a leftmost element which may affect BUF
1902 content. It is safe to report lower value but a failure to
1903 report higher one. */
1906 bc_r
= bp_locations
.size ();
1907 while (bc_l
+ 1 < bc_r
)
1909 struct bp_location
*bl
;
1911 bc
= (bc_l
+ bc_r
) / 2;
1912 bl
= bp_locations
[bc
];
1914 /* Check first BL->ADDRESS will not overflow due to the added
1915 constant. Then advance the left boundary only if we are sure
1916 the BC element can in no way affect the BUF content (MEMADDR
1917 to MEMADDR + LEN range).
1919 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1920 offset so that we cannot miss a breakpoint with its shadow
1921 range tail still reaching MEMADDR. */
1923 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1925 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1932 /* Due to the binary search above, we need to make sure we pick the
1933 first location that's at BC_L's address. E.g., if there are
1934 multiple locations at the same address, BC_L may end up pointing
1935 at a duplicate location, and miss the "master"/"inserted"
1936 location. Say, given locations L1, L2 and L3 at addresses A and
1939 L1@A, L2@A, L3@B, ...
1941 BC_L could end up pointing at location L2, while the "master"
1942 location could be L1. Since the `loc->inserted' flag is only set
1943 on "master" locations, we'd forget to restore the shadow of L1
1946 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1949 /* Now do full processing of the found relevant range of elements. */
1951 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1953 struct bp_location
*bl
= bp_locations
[bc
];
1955 /* bp_location array has BL->OWNER always non-NULL. */
1956 if (bl
->owner
->type
== bp_none
)
1957 warning (_("reading through apparently deleted breakpoint #%d?"),
1960 /* Performance optimization: any further element can no longer affect BUF
1963 if (bl
->address
>= bp_locations_placed_address_before_address_max
1966 - bp_locations_placed_address_before_address_max
)))
1969 if (!bp_location_has_shadow (bl
))
1972 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1973 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1977 /* See breakpoint.h. */
1980 is_breakpoint (const struct breakpoint
*bpt
)
1982 return (bpt
->type
== bp_breakpoint
1983 || bpt
->type
== bp_hardware_breakpoint
1984 || bpt
->type
== bp_dprintf
);
1987 /* Return true if BPT is of any hardware watchpoint kind. */
1990 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1992 return (bpt
->type
== bp_hardware_watchpoint
1993 || bpt
->type
== bp_read_watchpoint
1994 || bpt
->type
== bp_access_watchpoint
);
1997 /* See breakpoint.h. */
2000 is_watchpoint (const struct breakpoint
*bpt
)
2002 return (is_hardware_watchpoint (bpt
)
2003 || bpt
->type
== bp_watchpoint
);
2006 /* Returns true if the current thread and its running state are safe
2007 to evaluate or update watchpoint B. Watchpoints on local
2008 expressions need to be evaluated in the context of the thread that
2009 was current when the watchpoint was created, and, that thread needs
2010 to be stopped to be able to select the correct frame context.
2011 Watchpoints on global expressions can be evaluated on any thread,
2012 and in any state. It is presently left to the target allowing
2013 memory accesses when threads are running. */
2016 watchpoint_in_thread_scope (struct watchpoint
*b
)
2018 return (b
->pspace
== current_program_space
2019 && (b
->watchpoint_thread
== null_ptid
2020 || (inferior_ptid
== b
->watchpoint_thread
2021 && !inferior_thread ()->executing ())));
2024 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
2025 associated bp_watchpoint_scope breakpoint. */
2028 watchpoint_del_at_next_stop (struct watchpoint
*w
)
2030 if (w
->related_breakpoint
!= w
)
2032 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
2033 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
2034 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2035 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
2036 w
->related_breakpoint
= w
;
2038 w
->disposition
= disp_del_at_next_stop
;
2039 disable_breakpoint (w
);
2042 /* Extract a bitfield value from value VAL using the bit parameters contained in
2045 static struct value
*
2046 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
2048 struct value
*bit_val
;
2053 bit_val
= value::allocate (val
->type ());
2055 val
->unpack_bitfield (bit_val
,
2058 val
->contents_for_printing ().data (),
2064 /* Allocate a dummy location and add it to B. This is required
2065 because bpstat_stop_status requires a location to be able to report
2069 add_dummy_location (struct breakpoint
*b
,
2070 struct program_space
*pspace
)
2072 gdb_assert (!b
->has_locations ());
2074 bp_location
*loc
= new bp_location (b
, bp_loc_other
);
2075 loc
->pspace
= pspace
;
2076 b
->add_location (*loc
);
2079 /* Assuming that B is a watchpoint:
2080 - Reparse watchpoint expression, if REPARSE is true
2081 - Evaluate expression and store the result in B->val
2082 - Evaluate the condition if there is one, and store the result
2084 - Update the list of values that must be watched in B->loc.
2086 If the watchpoint disposition is disp_del_at_next_stop, then do
2087 nothing. If this is local watchpoint that is out of scope, delete
2090 Even with `set breakpoint always-inserted on' the watchpoints are
2091 removed + inserted on each stop here. Normal breakpoints must
2092 never be removed because they might be missed by a running thread
2093 when debugging in non-stop mode. On the other hand, hardware
2094 watchpoints (is_hardware_watchpoint; processed here) are specific
2095 to each LWP since they are stored in each LWP's hardware debug
2096 registers. Therefore, such LWP must be stopped first in order to
2097 be able to modify its hardware watchpoints.
2099 Hardware watchpoints must be reset exactly once after being
2100 presented to the user. It cannot be done sooner, because it would
2101 reset the data used to present the watchpoint hit to the user. And
2102 it must not be done later because it could display the same single
2103 watchpoint hit during multiple GDB stops. Note that the latter is
2104 relevant only to the hardware watchpoint types bp_read_watchpoint
2105 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
2106 not user-visible - its hit is suppressed if the memory content has
2109 The following constraints influence the location where we can reset
2110 hardware watchpoints:
2112 * target_stopped_by_watchpoint and target_stopped_data_address are
2113 called several times when GDB stops.
2116 * Multiple hardware watchpoints can be hit at the same time,
2117 causing GDB to stop. GDB only presents one hardware watchpoint
2118 hit at a time as the reason for stopping, and all the other hits
2119 are presented later, one after the other, each time the user
2120 requests the execution to be resumed. Execution is not resumed
2121 for the threads still having pending hit event stored in
2122 LWP_INFO->STATUS. While the watchpoint is already removed from
2123 the inferior on the first stop the thread hit event is kept being
2124 reported from its cached value by linux_nat_stopped_data_address
2125 until the real thread resume happens after the watchpoint gets
2126 presented and thus its LWP_INFO->STATUS gets reset.
2128 Therefore the hardware watchpoint hit can get safely reset on the
2129 watchpoint removal from inferior. */
2132 update_watchpoint (struct watchpoint
*b
, bool reparse
)
2134 bool within_current_scope
;
2136 /* If this is a local watchpoint, we only want to check if the
2137 watchpoint frame is in scope if the current thread is the thread
2138 that was used to create the watchpoint. */
2139 if (!watchpoint_in_thread_scope (b
))
2142 if (b
->disposition
== disp_del_at_next_stop
)
2145 std::optional
<scoped_restore_selected_frame
> restore_frame
;
2147 /* Determine if the watchpoint is within scope. */
2148 if (b
->exp_valid_block
== NULL
)
2149 within_current_scope
= true;
2152 frame_info_ptr fi
= get_current_frame ();
2153 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
2154 CORE_ADDR frame_pc
= get_frame_pc (fi
);
2156 /* If we're at a point where the stack has been destroyed
2157 (e.g. in a function epilogue), unwinding may not work
2158 properly. Do not attempt to recreate locations at this
2159 point. See similar comments in watchpoint_check. */
2160 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
2163 /* Save the current frame's ID so we can restore it after
2164 evaluating the watchpoint expression on its own frame. */
2165 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
2166 took a frame parameter, so that we didn't have to change the
2168 restore_frame
.emplace ();
2170 fi
= frame_find_by_id (b
->watchpoint_frame
);
2171 within_current_scope
= (fi
!= NULL
);
2172 if (within_current_scope
)
2176 /* We don't free locations. They are stored in the bp_location array
2177 and update_global_location_list will eventually delete them and
2178 remove breakpoints if needed. */
2179 b
->clear_locations ();
2181 if (within_current_scope
&& reparse
)
2186 s
= (b
->exp_string_reparse
2187 ? b
->exp_string_reparse
.get ()
2188 : b
->exp_string
.get ());
2189 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
2190 /* If the meaning of expression itself changed, the old value is
2191 no longer relevant. We don't want to report a watchpoint hit
2192 to the user when the old value and the new value may actually
2193 be completely different objects. */
2195 b
->val_valid
= false;
2197 /* Note that unlike with breakpoints, the watchpoint's condition
2198 expression is stored in the breakpoint object, not in the
2199 locations (re)created below. */
2200 if (b
->cond_string
!= NULL
)
2202 b
->cond_exp
.reset ();
2204 s
= b
->cond_string
.get ();
2205 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
2209 /* If we failed to parse the expression, for example because
2210 it refers to a global variable in a not-yet-loaded shared library,
2211 don't try to insert watchpoint. We don't automatically delete
2212 such watchpoint, though, since failure to parse expression
2213 is different from out-of-scope watchpoint. */
2214 if (!target_has_execution ())
2216 /* Without execution, memory can't change. No use to try and
2217 set watchpoint locations. The watchpoint will be reset when
2218 the target gains execution, through breakpoint_re_set. */
2219 if (!can_use_hw_watchpoints
)
2221 if (b
->works_in_software_mode ())
2222 b
->type
= bp_watchpoint
;
2224 error (_("Can't set read/access watchpoint when "
2225 "hardware watchpoints are disabled."));
2228 else if (within_current_scope
&& b
->exp
)
2230 std::vector
<value_ref_ptr
> val_chain
;
2231 struct value
*v
, *result
;
2232 struct program_space
*wp_pspace
;
2234 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2237 /* Avoid setting b->val if it's already set. The meaning of
2238 b->val is 'the last value' user saw, and we should update
2239 it only if we reported that last value to user. As it
2240 happens, the code that reports it updates b->val directly.
2241 We don't keep track of the memory value for masked
2243 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2245 if (b
->val_bitsize
!= 0)
2246 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2247 b
->val
= release_value (v
);
2248 b
->val_valid
= true;
2251 if (b
->exp_valid_block
== nullptr)
2252 wp_pspace
= current_program_space
;
2254 wp_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2256 /* Look at each value on the value chain. */
2257 gdb_assert (!val_chain
.empty ());
2258 for (const value_ref_ptr
&iter
: val_chain
)
2262 /* If it's a memory location, and GDB actually needed
2263 its contents to evaluate the expression, then we
2264 must watch it. If the first value returned is
2265 still lazy, that means an error occurred reading it;
2266 watch it anyway in case it becomes readable. */
2267 if (v
->lval () == lval_memory
2268 && (v
== val_chain
[0] || ! v
->lazy ()))
2270 struct type
*vtype
= check_typedef (v
->type ());
2272 /* We only watch structs and arrays if user asked
2273 for it explicitly, never if they just happen to
2274 appear in the middle of some value chain. */
2276 || (vtype
->code () != TYPE_CODE_STRUCT
2277 && vtype
->code () != TYPE_CODE_ARRAY
))
2280 enum target_hw_bp_type type
;
2281 int bitpos
= 0, bitsize
= 0;
2283 if (v
->bitsize () != 0)
2285 /* Extract the bit parameters out from the bitfield
2287 bitpos
= v
->bitpos ();
2288 bitsize
= v
->bitsize ();
2290 else if (v
== result
&& b
->val_bitsize
!= 0)
2292 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2293 lvalue whose bit parameters are saved in the fields
2294 VAL_BITPOS and VAL_BITSIZE. */
2295 bitpos
= b
->val_bitpos
;
2296 bitsize
= b
->val_bitsize
;
2299 addr
= v
->address ();
2302 /* Skip the bytes that don't contain the bitfield. */
2307 if (b
->type
== bp_read_watchpoint
)
2309 else if (b
->type
== bp_access_watchpoint
)
2312 bp_location
*loc
= b
->allocate_location ();
2313 loc
->gdbarch
= v
->type ()->arch ();
2314 loc
->pspace
= wp_pspace
;
2316 = gdbarch_remove_non_address_bits_watchpoint (loc
->gdbarch
,
2318 b
->add_location (*loc
);
2322 /* Just cover the bytes that make up the bitfield. */
2323 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2326 loc
->length
= v
->type ()->length ();
2328 loc
->watchpoint_type
= type
;
2333 /* Helper function to bundle possibly emitting a warning along with
2334 changing the type of B to bp_watchpoint. */
2335 auto change_type_to_bp_watchpoint
= [] (breakpoint
*bp
)
2337 /* Only warn for breakpoints that have been assigned a +ve number,
2338 anything else is either an internal watchpoint (which we don't
2339 currently create) or has not yet been finalized, in which case
2340 this change of type will be occurring before the user is told
2341 the type of this watchpoint. */
2342 if (bp
->type
== bp_hardware_watchpoint
&& bp
->number
> 0)
2343 warning (_("watchpoint %d downgraded to software watchpoint"),
2345 bp
->type
= bp_watchpoint
;
2348 /* Change the type of breakpoint between hardware assisted or
2349 an ordinary watchpoint depending on the hardware support and
2350 free hardware slots. Recheck the number of free hardware slots
2351 as the value chain may have changed. */
2354 enum bp_loc_type loc_type
;
2356 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2360 int i
, target_resources_ok
, other_type_used
;
2363 /* Use an exact watchpoint when there's only one memory region to be
2364 watched, and only one debug register is needed to watch it. */
2365 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2367 /* We need to determine how many resources are already
2368 used for all other hardware watchpoints plus this one
2369 to see if we still have enough resources to also fit
2370 this watchpoint in as well. */
2372 /* If this is a software watchpoint, we try to turn it
2373 to a hardware one -- count resources as if B was of
2374 hardware watchpoint type. */
2376 if (type
== bp_watchpoint
)
2377 type
= bp_hardware_watchpoint
;
2379 /* This watchpoint may or may not have been placed on
2380 the list yet at this point (it won't be in the list
2381 if we're trying to create it for the first time,
2382 through watch_command), so always account for it
2385 /* Count resources used by all watchpoints except B. */
2386 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2388 /* Add in the resources needed for B. */
2389 i
+= hw_watchpoint_use_count (b
);
2392 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2393 if (target_resources_ok
<= 0)
2395 bool sw_mode
= b
->works_in_software_mode ();
2397 if (target_resources_ok
== 0 && !sw_mode
)
2398 error (_("Target does not support this type of "
2399 "hardware watchpoint."));
2400 else if (target_resources_ok
< 0 && !sw_mode
)
2401 error (_("There are not enough available hardware "
2402 "resources for this watchpoint."));
2404 /* Downgrade to software watchpoint. */
2405 change_type_to_bp_watchpoint (b
);
2409 /* If this was a software watchpoint, we've just
2410 found we have enough resources to turn it to a
2411 hardware watchpoint. Otherwise, this is a
2416 else if (!b
->works_in_software_mode ())
2418 if (!can_use_hw_watchpoints
)
2419 error (_("Can't set read/access watchpoint when "
2420 "hardware watchpoints are disabled."));
2422 error (_("Expression cannot be implemented with "
2423 "read/access watchpoint."));
2426 change_type_to_bp_watchpoint (b
);
2428 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_software_watchpoint
2429 : bp_loc_hardware_watchpoint
);
2431 for (bp_location
&bl
: b
->locations ())
2432 bl
.loc_type
= loc_type
;
2435 /* If a software watchpoint is not watching any memory, then the
2436 above left it without any location set up. But,
2437 bpstat_stop_status requires a location to be able to report
2438 stops, so make sure there's at least a dummy one. */
2439 if (b
->type
== bp_watchpoint
&& !b
->has_locations ())
2440 add_dummy_location (b
, wp_pspace
);
2442 else if (!within_current_scope
)
2445 Watchpoint %d deleted because the program has left the block\n\
2446 in which its expression is valid.\n"),
2448 watchpoint_del_at_next_stop (b
);
2452 /* Returns true iff breakpoint location should be
2453 inserted in the inferior. We don't differentiate the type of BL's owner
2454 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2455 breakpoint_ops is not defined, because in insert_bp_location,
2456 tracepoint's insert_location will not be called. */
2459 should_be_inserted (struct bp_location
*bl
)
2461 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2464 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2467 if (!bl
->enabled
|| bl
->disabled_by_cond
2468 || bl
->shlib_disabled
|| bl
->duplicate
)
2471 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2474 /* This is set for example, when we're attached to the parent of a
2475 vfork, and have detached from the child. The child is running
2476 free, and we expect it to do an exec or exit, at which point the
2477 OS makes the parent schedulable again (and the target reports
2478 that the vfork is done). Until the child is done with the shared
2479 memory region, do not insert breakpoints in the parent, otherwise
2480 the child could still trip on the parent's breakpoints. Since
2481 the parent is blocked anyway, it won't miss any breakpoint. */
2482 if (bl
->pspace
->breakpoints_not_allowed
)
2485 /* Don't insert a breakpoint if we're trying to step past its
2486 location, except if the breakpoint is a single-step breakpoint,
2487 and the breakpoint's thread is the thread which is stepping past
2489 if ((bl
->loc_type
== bp_loc_software_breakpoint
2490 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2491 && stepping_past_instruction_at (bl
->pspace
->aspace
.get (),
2493 /* The single-step breakpoint may be inserted at the location
2494 we're trying to step if the instruction branches to itself.
2495 However, the instruction won't be executed at all and it may
2496 break the semantics of the instruction, for example, the
2497 instruction is a conditional branch or updates some flags.
2498 We can't fix it unless GDB is able to emulate the instruction
2499 or switch to displaced stepping. */
2500 && !(bl
->owner
->type
== bp_single_step
2501 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2503 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2504 paddress (bl
->gdbarch
, bl
->address
));
2508 /* Don't insert watchpoints if we're trying to step past the
2509 instruction that triggered one. */
2510 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2511 && stepping_past_nonsteppable_watchpoint ())
2513 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2514 "skipping watchpoint at %s:%d",
2515 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2522 /* Same as should_be_inserted but does the check assuming
2523 that the location is not duplicated. */
2526 unduplicated_should_be_inserted (struct bp_location
*bl
)
2528 scoped_restore restore_bl_duplicate
2529 = make_scoped_restore (&bl
->duplicate
, 0);
2531 return should_be_inserted (bl
);
2534 /* Parses a conditional described by an expression COND into an
2535 agent expression bytecode suitable for evaluation
2536 by the bytecode interpreter. Return NULL if there was
2537 any error during parsing. */
2539 static agent_expr_up
2540 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2545 agent_expr_up aexpr
;
2547 /* We don't want to stop processing, so catch any errors
2548 that may show up. */
2551 aexpr
= gen_eval_for_expr (scope
, cond
);
2554 catch (const gdb_exception_error
&ex
)
2556 /* If we got here, it means the condition could not be parsed to a valid
2557 bytecode expression and thus can't be evaluated on the target's side.
2558 It's no use iterating through the conditions. */
2561 /* We have a valid agent expression. */
2565 /* Based on location BL, create a list of breakpoint conditions to be
2566 passed on to the target. If we have duplicated locations with different
2567 conditions, we will add such conditions to the list. The idea is that the
2568 target will evaluate the list of conditions and will only notify GDB when
2569 one of them is true. */
2572 build_target_condition_list (struct bp_location
*bl
)
2574 bool null_condition_or_parse_error
= false;
2575 int modified
= bl
->needs_update
;
2577 /* Release conditions left over from a previous insert. */
2578 bl
->target_info
.conditions
.clear ();
2580 /* This is only meaningful if the target is
2581 evaluating conditions and if the user has
2582 opted for condition evaluation on the target's
2584 if (gdb_evaluates_breakpoint_condition_p ()
2585 || !target_supports_evaluation_of_breakpoint_conditions ())
2588 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2590 /* Do a first pass to check for locations with no assigned
2591 conditions or conditions that fail to parse to a valid agent
2592 expression bytecode. If any of these happen, then it's no use to
2593 send conditions to the target since this location will always
2594 trigger and generate a response back to GDB. Note we consider
2595 all locations at the same address irrespective of type, i.e.,
2596 even if the locations aren't considered duplicates (e.g.,
2597 software breakpoint and hardware breakpoint at the same
2599 for (bp_location
*loc
: loc_range
)
2601 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2605 /* Re-parse the conditions since something changed. In that
2606 case we already freed the condition bytecodes (see
2607 force_breakpoint_reinsertion). We just
2608 need to parse the condition to bytecodes again. */
2609 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2613 /* If we have a NULL bytecode expression, it means something
2614 went wrong or we have a null condition expression. */
2615 if (!loc
->cond_bytecode
)
2617 null_condition_or_parse_error
= true;
2623 /* If any of these happened, it means we will have to evaluate the conditions
2624 for the location's address on gdb's side. It is no use keeping bytecodes
2625 for all the other duplicate locations, thus we free all of them here.
2627 This is so we have a finer control over which locations' conditions are
2628 being evaluated by GDB or the remote stub. */
2629 if (null_condition_or_parse_error
)
2631 for (bp_location
*loc
: loc_range
)
2633 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2635 /* Only go as far as the first NULL bytecode is
2637 if (!loc
->cond_bytecode
)
2640 loc
->cond_bytecode
.reset ();
2645 /* No NULL conditions or failed bytecode generation. Build a
2646 condition list for this location's address. If we have software
2647 and hardware locations at the same address, they aren't
2648 considered duplicates, but we still merge all the conditions
2649 anyway, as it's simpler, and doesn't really make a practical
2651 for (bp_location
*loc
: loc_range
)
2653 && is_breakpoint (loc
->owner
)
2654 && loc
->pspace
->num
== bl
->pspace
->num
2655 && loc
->owner
->enable_state
== bp_enabled
2657 && !loc
->disabled_by_cond
)
2659 /* Add the condition to the vector. This will be used later
2660 to send the conditions to the target. */
2661 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2667 /* Parses a command described by string CMD into an agent expression
2668 bytecode suitable for evaluation by the bytecode interpreter.
2669 Return NULL if there was any error during parsing. */
2671 static agent_expr_up
2672 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2674 const char *cmdrest
;
2675 const char *format_start
, *format_end
;
2676 struct gdbarch
*gdbarch
= get_current_arch ();
2683 if (*cmdrest
== ',')
2685 cmdrest
= skip_spaces (cmdrest
);
2687 if (*cmdrest
++ != '"')
2688 error (_("No format string following the location"));
2690 format_start
= cmdrest
;
2692 format_pieces
fpieces (&cmdrest
);
2694 format_end
= cmdrest
;
2696 if (*cmdrest
++ != '"')
2697 error (_("Bad format string, non-terminated '\"'."));
2699 cmdrest
= skip_spaces (cmdrest
);
2701 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2702 error (_("Invalid argument syntax"));
2704 if (*cmdrest
== ',')
2706 cmdrest
= skip_spaces (cmdrest
);
2708 /* For each argument, make an expression. */
2710 std::vector
<struct expression
*> argvec
;
2711 while (*cmdrest
!= '\0')
2716 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
),
2717 PARSER_COMMA_TERMINATES
);
2718 argvec
.push_back (expr
.release ());
2720 if (*cmdrest
== ',')
2724 agent_expr_up aexpr
;
2726 /* We don't want to stop processing, so catch any errors
2727 that may show up. */
2730 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2731 format_start
, format_end
- format_start
,
2732 argvec
.size (), argvec
.data ());
2734 catch (const gdb_exception_error
&ex
)
2736 /* If we got here, it means the command could not be parsed to a valid
2737 bytecode expression and thus can't be evaluated on the target's side.
2738 It's no use iterating through the other commands. */
2741 /* We have a valid agent expression, return it. */
2745 /* Based on location BL, create a list of breakpoint commands to be
2746 passed on to the target. If we have duplicated locations with
2747 different commands, we will add any such to the list. */
2750 build_target_command_list (struct bp_location
*bl
)
2752 bool null_command_or_parse_error
= false;
2753 int modified
= bl
->needs_update
;
2755 /* Clear commands left over from a previous insert. */
2756 bl
->target_info
.tcommands
.clear ();
2758 if (!target_can_run_breakpoint_commands ())
2761 /* For now, limit to agent-style dprintf breakpoints. */
2762 if (dprintf_style
!= dprintf_style_agent
)
2765 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2767 /* For now, if we have any location at the same address that isn't a
2768 dprintf, don't install the target-side commands, as that would
2769 make the breakpoint not be reported to the core, and we'd lose
2771 for (bp_location
*loc
: loc_range
)
2772 if (is_breakpoint (loc
->owner
)
2773 && loc
->pspace
->num
== bl
->pspace
->num
2774 && loc
->owner
->type
!= bp_dprintf
)
2777 /* Do a first pass to check for locations with no assigned
2778 conditions or conditions that fail to parse to a valid agent expression
2779 bytecode. If any of these happen, then it's no use to send conditions
2780 to the target since this location will always trigger and generate a
2781 response back to GDB. */
2782 for (bp_location
*loc
: loc_range
)
2784 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2788 /* Re-parse the commands since something changed. In that
2789 case we already freed the command bytecodes (see
2790 force_breakpoint_reinsertion). We just
2791 need to parse the command to bytecodes again. */
2793 = parse_cmd_to_aexpr (bl
->address
,
2794 loc
->owner
->extra_string
.get ());
2797 /* If we have a NULL bytecode expression, it means something
2798 went wrong or we have a null command expression. */
2799 if (!loc
->cmd_bytecode
)
2801 null_command_or_parse_error
= true;
2807 /* If anything failed, then we're not doing target-side commands,
2809 if (null_command_or_parse_error
)
2811 for (bp_location
*loc
: loc_range
)
2812 if (is_breakpoint (loc
->owner
)
2813 && loc
->pspace
->num
== bl
->pspace
->num
)
2815 /* Only go as far as the first NULL bytecode is
2817 if (loc
->cmd_bytecode
== NULL
)
2820 loc
->cmd_bytecode
.reset ();
2824 /* No NULL commands or failed bytecode generation. Build a command
2825 list for all duplicate locations at this location's address.
2826 Note that here we must care for whether the breakpoint location
2827 types are considered duplicates, otherwise, say, if we have a
2828 software and hardware location at the same address, the target
2829 could end up running the commands twice. For the moment, we only
2830 support targets-side commands with dprintf, but it doesn't hurt
2831 to be pedantically correct in case that changes. */
2832 for (bp_location
*loc
: loc_range
)
2833 if (breakpoint_locations_match (bl
, loc
)
2834 && loc
->owner
->extra_string
2835 && is_breakpoint (loc
->owner
)
2836 && loc
->pspace
->num
== bl
->pspace
->num
2837 && loc
->owner
->enable_state
== bp_enabled
2839 && !loc
->disabled_by_cond
)
2841 /* Add the command to the vector. This will be used later
2842 to send the commands to the target. */
2843 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2846 bl
->target_info
.persist
= 0;
2847 /* Maybe flag this location as persistent. */
2848 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2849 bl
->target_info
.persist
= 1;
2852 /* Return the kind of breakpoint on address *ADDR. Get the kind
2853 of breakpoint according to ADDR except single-step breakpoint.
2854 Get the kind of single-step breakpoint according to the current
2858 breakpoint_kind (const struct bp_location
*bl
, CORE_ADDR
*addr
)
2860 if (bl
->owner
->type
== bp_single_step
)
2862 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2863 struct regcache
*regcache
;
2865 regcache
= get_thread_regcache (thr
);
2867 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2871 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2874 /* Rethrow the currently handled exception, if it's a TARGET_CLOSE_ERROR.
2875 E is either the currently handled exception, or a copy, or a sliced copy,
2876 so we can't rethrow that one, but we can use it to inspect the properties
2877 of the currently handled exception. */
2880 rethrow_on_target_close_error (const gdb_exception
&e
)
2884 /* Can't set the breakpoint. */
2886 if (e
.error
!= TARGET_CLOSE_ERROR
)
2889 /* If the target has closed then it will have deleted any breakpoints
2890 inserted within the target inferior, as a result any further attempts
2891 to interact with the breakpoint objects is not possible. Just rethrow
2892 the error. Don't use e to rethrow, to prevent object slicing of the
2897 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2898 location. Any error messages are printed to TMP_ERROR_STREAM; and
2899 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2900 Returns 0 for success, 1 if the bp_location type is not supported or
2903 NOTE drow/2003-09-09: This routine could be broken down to an
2904 object-style method for each breakpoint or catchpoint type. */
2906 insert_bp_location (struct bp_location
*bl
,
2907 struct ui_file
*tmp_error_stream
,
2908 int *disabled_breaks
,
2909 int *hw_breakpoint_error
,
2910 int *hw_bp_error_explained_already
)
2912 gdb_exception bp_excpt
;
2914 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2917 breakpoint_debug_printf ("%s", breakpoint_location_address_str (bl
).c_str ());
2919 /* Note we don't initialize bl->target_info, as that wipes out
2920 the breakpoint location's shadow_contents if the breakpoint
2921 is still inserted at that location. This in turn breaks
2922 target_read_memory which depends on these buffers when
2923 a memory read is requested at the breakpoint location:
2924 Once the target_info has been wiped, we fail to see that
2925 we have a breakpoint inserted at that address and thus
2926 read the breakpoint instead of returning the data saved in
2927 the breakpoint location's shadow contents. */
2928 bl
->target_info
.reqstd_address
= bl
->address
;
2929 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
.get ();
2930 bl
->target_info
.length
= bl
->length
;
2932 /* When working with target-side conditions, we must pass all the conditions
2933 for the same breakpoint address down to the target since GDB will not
2934 insert those locations. With a list of breakpoint conditions, the target
2935 can decide when to stop and notify GDB. */
2937 if (is_breakpoint (bl
->owner
))
2939 build_target_condition_list (bl
);
2940 build_target_command_list (bl
);
2941 /* Reset the modification marker. */
2942 bl
->needs_update
= 0;
2945 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2946 set at a read-only address, then a breakpoint location will have
2947 been changed to hardware breakpoint before we get here. If it is
2948 "off" however, error out before actually trying to insert the
2949 breakpoint, with a nicer error message. */
2950 if (bl
->loc_type
== bp_loc_software_breakpoint
2951 && !automatic_hardware_breakpoints
)
2953 mem_region
*mr
= lookup_mem_region (bl
->address
);
2955 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2957 gdb_printf (tmp_error_stream
,
2958 _("Cannot insert breakpoint %d.\n"
2959 "Cannot set software breakpoint "
2960 "at read-only address %s\n"),
2962 paddress (bl
->gdbarch
, bl
->address
));
2967 if (bl
->loc_type
== bp_loc_software_breakpoint
2968 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2970 /* First check to see if we have to handle an overlay. */
2971 if (overlay_debugging
== ovly_off
2972 || bl
->section
== NULL
2973 || !(section_is_overlay (bl
->section
)))
2975 /* No overlay handling: just set the breakpoint. */
2980 val
= bl
->owner
->insert_location (bl
);
2982 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2984 catch (gdb_exception
&e
)
2986 rethrow_on_target_close_error (e
);
2987 bp_excpt
= std::move (e
);
2992 /* This breakpoint is in an overlay section.
2993 Shall we set a breakpoint at the LMA? */
2994 if (!overlay_events_enabled
)
2996 /* Yes -- overlay event support is not active,
2997 so we must try to set a breakpoint at the LMA.
2998 This will not work for a hardware breakpoint. */
2999 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3000 warning (_("hardware breakpoint %d not supported in overlay!"),
3004 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
3006 /* Set a software (trap) breakpoint at the LMA. */
3007 bl
->overlay_target_info
= bl
->target_info
;
3008 bl
->overlay_target_info
.reqstd_address
= addr
;
3010 /* No overlay handling: just set the breakpoint. */
3015 bl
->overlay_target_info
.kind
3016 = breakpoint_kind (bl
, &addr
);
3017 bl
->overlay_target_info
.placed_address
= addr
;
3018 val
= target_insert_breakpoint (bl
->gdbarch
,
3019 &bl
->overlay_target_info
);
3022 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
3024 catch (gdb_exception
&e
)
3026 rethrow_on_target_close_error (e
);
3027 bp_excpt
= std::move (e
);
3030 if (bp_excpt
.reason
!= 0)
3031 gdb_printf (tmp_error_stream
,
3032 "Overlay breakpoint %d "
3033 "failed: in ROM?\n",
3037 /* Shall we set a breakpoint at the VMA? */
3038 if (section_is_mapped (bl
->section
))
3040 /* Yes. This overlay section is mapped into memory. */
3045 val
= bl
->owner
->insert_location (bl
);
3047 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
3049 catch (gdb_exception_error
&e
)
3051 rethrow_on_target_close_error (e
);
3052 bp_excpt
= std::move (e
);
3057 /* No. This breakpoint will not be inserted.
3058 No error, but do not mark the bp as 'inserted'. */
3063 if (bp_excpt
.reason
!= 0)
3065 /* Can't set the breakpoint. */
3066 gdb_assert (bl
->owner
!= nullptr);
3068 /* In some cases, we might not be able to insert a
3069 breakpoint in a shared library that has already been
3070 removed, but we have not yet processed the shlib unload
3071 event. Unfortunately, some targets that implement
3072 breakpoint insertion themselves can't tell why the
3073 breakpoint insertion failed (e.g., the remote target
3074 doesn't define error codes), so we must treat generic
3075 errors as memory errors. */
3076 if (bp_excpt
.reason
== RETURN_ERROR
3077 && (bp_excpt
.error
== GENERIC_ERROR
3078 || bp_excpt
.error
== MEMORY_ERROR
)
3079 && bl
->loc_type
== bp_loc_software_breakpoint
3080 && (solib_name_from_address (bl
->pspace
, bl
->address
)
3081 || shared_objfile_contains_address_p (bl
->pspace
,
3084 /* See also: disable_breakpoints_in_shlibs. */
3085 bl
->shlib_disabled
= 1;
3086 notify_breakpoint_modified (bl
->owner
);
3087 if (!*disabled_breaks
)
3089 gdb_printf (tmp_error_stream
,
3090 "Cannot insert breakpoint %d.\n",
3092 gdb_printf (tmp_error_stream
,
3093 "Temporarily disabling shared "
3094 "library breakpoints:\n");
3096 *disabled_breaks
= 1;
3097 gdb_printf (tmp_error_stream
,
3098 "breakpoint #%d\n", bl
->owner
->number
);
3103 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3105 *hw_breakpoint_error
= 1;
3106 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
3107 gdb_printf (tmp_error_stream
,
3108 "Cannot insert hardware breakpoint %d%s",
3110 bp_excpt
.message
? ":" : ".\n");
3111 if (bp_excpt
.message
!= NULL
)
3112 gdb_printf (tmp_error_stream
, "%s.\n",
3117 if (bp_excpt
.message
== NULL
)
3120 = memory_error_message (TARGET_XFER_E_IO
,
3121 bl
->gdbarch
, bl
->address
);
3123 gdb_printf (tmp_error_stream
,
3124 "Cannot insert breakpoint %d.\n"
3126 bl
->owner
->number
, message
.c_str ());
3130 gdb_printf (tmp_error_stream
,
3131 "Cannot insert breakpoint %d: %s\n",
3146 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
3147 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
3151 val
= bl
->owner
->insert_location (bl
);
3153 /* If trying to set a read-watchpoint, and it turns out it's not
3154 supported, try emulating one with an access watchpoint. */
3155 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
3157 /* But don't try to insert it, if there's already another
3158 hw_access location that would be considered a duplicate
3160 for (bp_location
*loc
: all_bp_locations ())
3162 && loc
->watchpoint_type
== hw_access
3163 && watchpoint_locations_match (bl
, loc
))
3167 bl
->target_info
= loc
->target_info
;
3168 bl
->watchpoint_type
= hw_access
;
3175 bl
->watchpoint_type
= hw_access
;
3176 val
= bl
->owner
->insert_location (bl
);
3179 /* Back to the original value. */
3180 bl
->watchpoint_type
= hw_read
;
3184 bl
->inserted
= (val
== 0);
3187 else if (bl
->owner
->type
== bp_catchpoint
)
3191 val
= bl
->owner
->insert_location (bl
);
3194 bl
->owner
->enable_state
= bp_disabled
;
3198 Error inserting catchpoint %d: Your system does not support this type\n\
3199 of catchpoint."), bl
->owner
->number
);
3201 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
3204 bl
->inserted
= (val
== 0);
3206 /* We've already printed an error message if there was a problem
3207 inserting this catchpoint, and we've disabled the catchpoint,
3208 so just return success. */
3215 /* This function is called when program space PSPACE is about to be
3216 deleted. It takes care of updating breakpoints to not reference
3220 breakpoint_program_space_exit (struct program_space
*pspace
)
3222 /* Remove any breakpoint that was set through this program space. */
3223 for (breakpoint
&b
: all_breakpoints_safe ())
3224 if (b
.pspace
== pspace
)
3225 delete_breakpoint (&b
);
3227 /* Breakpoints set through other program spaces could have locations
3228 bound to PSPACE as well. Remove those. */
3229 for (bp_location
*loc
: all_bp_locations ())
3230 if (loc
->pspace
== pspace
)
3232 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3233 loc
->owner
->unadd_location (*loc
);
3236 /* Now update the global location list to permanently delete the
3237 removed locations above. */
3238 update_global_location_list (UGLL_DONT_INSERT
);
3241 /* Make sure all breakpoints are inserted in inferior.
3242 Throws exception on any error.
3243 A breakpoint that is already inserted won't be inserted
3244 again, so calling this function twice is safe. */
3246 insert_breakpoints (void)
3248 for (breakpoint
&bpt
: all_breakpoints ())
3249 if (is_hardware_watchpoint (&bpt
))
3251 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (bpt
);
3253 update_watchpoint (&w
, false /* don't reparse. */);
3256 /* Updating watchpoints creates new locations, so update the global
3257 location list. Explicitly tell ugll to insert locations and
3258 ignore breakpoints_always_inserted_mode. Also,
3259 update_global_location_list tries to "upgrade" software
3260 breakpoints to hardware breakpoints to handle "set breakpoint
3261 auto-hw", so we need to call it even if we don't have new
3263 update_global_location_list (UGLL_INSERT
);
3266 /* This is used when we need to synch breakpoint conditions between GDB and the
3267 target. It is the case with deleting and disabling of breakpoints when using
3268 always-inserted mode. */
3271 update_inserted_breakpoint_locations (void)
3275 int disabled_breaks
= 0;
3276 int hw_breakpoint_error
= 0;
3277 int hw_bp_details_reported
= 0;
3279 string_file tmp_error_stream
;
3281 /* Explicitly mark the warning -- this will only be printed if
3282 there was an error. */
3283 tmp_error_stream
.puts ("Warning:\n");
3285 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3287 for (bp_location
*bl
: all_bp_locations ())
3289 /* We only want to update software breakpoints and hardware
3291 if (!is_breakpoint (bl
->owner
))
3294 /* We only want to update locations that are already inserted
3295 and need updating. This is to avoid unwanted insertion during
3296 deletion of breakpoints. */
3297 if (!bl
->inserted
|| !bl
->needs_update
)
3300 switch_to_program_space_and_thread (bl
->pspace
);
3302 /* For targets that support global breakpoints, there's no need
3303 to select an inferior to insert breakpoint to. In fact, even
3304 if we aren't attached to any process yet, we should still
3305 insert breakpoints. */
3306 if (!gdbarch_has_global_breakpoints (current_inferior ()->arch ())
3307 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3310 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3311 &hw_breakpoint_error
, &hw_bp_details_reported
);
3318 target_terminal::ours_for_output ();
3319 error (("%s"), tmp_error_stream
.c_str ());
3323 /* Used when starting or continuing the program. */
3326 insert_breakpoint_locations (void)
3330 int disabled_breaks
= 0;
3331 int hw_breakpoint_error
= 0;
3332 int hw_bp_error_explained_already
= 0;
3334 string_file tmp_error_stream
;
3336 /* Explicitly mark the warning -- this will only be printed if
3337 there was an error. */
3338 tmp_error_stream
.puts ("Warning:\n");
3340 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3342 for (bp_location
*bl
: all_bp_locations ())
3344 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3347 /* There is no point inserting thread-specific breakpoints if
3348 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3349 has BL->OWNER always non-NULL. */
3350 if (bl
->owner
->thread
!= -1
3351 && !valid_global_thread_id (bl
->owner
->thread
))
3354 /* Or inferior specific breakpoints if the inferior no longer
3356 if (bl
->owner
->inferior
!= -1
3357 && !valid_global_inferior_id (bl
->owner
->inferior
))
3360 switch_to_program_space_and_thread (bl
->pspace
);
3362 /* For targets that support global breakpoints, there's no need
3363 to select an inferior to insert breakpoint to. In fact, even
3364 if we aren't attached to any process yet, we should still
3365 insert breakpoints. */
3366 if (!gdbarch_has_global_breakpoints (current_inferior ()->arch ())
3367 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3370 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3371 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3376 /* If we failed to insert all locations of a watchpoint, remove
3377 them, as half-inserted watchpoint is of limited use. */
3378 for (breakpoint
&bpt
: all_breakpoints ())
3380 bool some_failed
= false;
3382 if (!is_hardware_watchpoint (&bpt
))
3385 if (!breakpoint_enabled (&bpt
))
3388 if (bpt
.disposition
== disp_del_at_next_stop
)
3391 for (bp_location
&loc
: bpt
.locations ())
3392 if (!loc
.inserted
&& should_be_inserted (&loc
))
3400 for (bp_location
&loc
: bpt
.locations ())
3402 remove_breakpoint (&loc
);
3404 hw_breakpoint_error
= 1;
3405 tmp_error_stream
.printf ("Could not insert "
3406 "hardware watchpoint %d.\n",
3414 /* If a hardware breakpoint or watchpoint was inserted, add a
3415 message about possibly exhausted resources. */
3416 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3418 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3419 You may have requested too many hardware breakpoints/watchpoints.\n");
3421 target_terminal::ours_for_output ();
3422 error (("%s"), tmp_error_stream
.c_str ());
3426 /* Used when the program stops.
3427 Returns zero if successful, or non-zero if there was a problem
3428 removing a breakpoint location. */
3431 remove_breakpoints (void)
3435 for (bp_location
*bl
: all_bp_locations ())
3436 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3437 val
|= remove_breakpoint (bl
);
3442 /* When a thread exits, remove breakpoints that are related to
3446 remove_threaded_breakpoints (thread_info
*tp
,
3447 std::optional
<ULONGEST
> /* exit_code */,
3450 for (breakpoint
&b
: all_breakpoints_safe ())
3452 if (b
.thread
== tp
->global_num
&& user_breakpoint_p (&b
))
3455 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3456 b
.number
, print_thread_id (tp
));
3457 delete_breakpoint (&b
);
3462 /* Called when inferior INF has been removed from GDB. Remove associated
3463 per-inferior breakpoints. */
3466 remove_inferior_breakpoints (struct inferior
*inf
)
3468 for (breakpoint
&b
: all_breakpoints_safe ())
3470 if (b
.inferior
== inf
->num
&& user_breakpoint_p (&b
))
3472 /* Tell the user the breakpoint has been deleted. But only for
3473 breakpoints that would not normally have been deleted at the
3474 next stop anyway. */
3475 if (b
.disposition
!= disp_del
3476 && b
.disposition
!= disp_del_at_next_stop
)
3478 Inferior-specific breakpoint %d deleted - inferior %d has been removed.\n"),
3479 b
.number
, inf
->num
);
3480 delete_breakpoint (&b
);
3485 /* See breakpoint.h. */
3488 remove_breakpoints_inf (inferior
*inf
)
3492 breakpoint_debug_printf ("inf->num = %d", inf
->num
);
3494 for (bp_location
*bl
: all_bp_locations ())
3496 if (bl
->pspace
!= inf
->pspace
)
3499 if (bl
->inserted
&& !bl
->target_info
.persist
)
3501 val
= remove_breakpoint (bl
);
3508 static int internal_breakpoint_number
= -1;
3510 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3511 If INTERNAL is non-zero, the breakpoint number will be populated
3512 from internal_breakpoint_number and that variable decremented.
3513 Otherwise the breakpoint number will be populated from
3514 breakpoint_count and that value incremented. Internal breakpoints
3515 do not set the internal var bpnum. */
3517 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3520 b
->number
= internal_breakpoint_number
--;
3523 set_breakpoint_count (breakpoint_count
+ 1);
3524 b
->number
= breakpoint_count
;
3528 /* Create a TYPE breakpoint on ADDRESS from an object file with GDBARCH. */
3530 static struct breakpoint
*
3531 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3532 CORE_ADDR address
, enum bptype type
)
3534 std::unique_ptr
<internal_breakpoint
> b
3535 (new internal_breakpoint (gdbarch
, type
, address
));
3537 b
->number
= internal_breakpoint_number
--;
3539 return add_to_breakpoint_chain (std::move (b
));
3542 /* Create a TYPE breakpoint on minimal symbol MSYM from an object file with
3545 static struct breakpoint
*
3546 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3547 bound_minimal_symbol
&msym
, enum bptype type
)
3551 address
= msym
.value_address ();
3553 address
= gdbarch_convert_from_func_ptr_addr
3554 (gdbarch
, address
, current_inferior ()->top_target ());
3556 /* Note that we're not using gdbarch_addr_bits_remove here, because that's
3557 related to addresses in $pc. We're getting the address from the
3558 minimal symbol table. */
3560 /* Is gdbarch_deprecated_function_start_offset needed here? Or is that dealt
3561 with elsewhere? Needs testing on vax. */
3563 if (gdbarch_skip_entrypoint_p (gdbarch
))
3564 address
= gdbarch_skip_entrypoint (gdbarch
, address
);
3566 return create_internal_breakpoint (gdbarch
, address
, type
);
3569 static const char *const longjmp_names
[] =
3571 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3573 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3575 /* Per-objfile data private to breakpoint.c. */
3576 struct breakpoint_objfile_data
3578 /* Minimal symbol for "_ovly_debug_event" (if any). */
3579 bound_minimal_symbol overlay_msym
;
3581 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3582 bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3584 /* True if we have looked for longjmp probes. */
3585 int longjmp_searched
= 0;
3587 /* SystemTap probe points for longjmp (if any). These are non-owning
3589 std::vector
<probe
*> longjmp_probes
;
3591 /* Minimal symbol for "std::terminate()" (if any). */
3592 bound_minimal_symbol terminate_msym
;
3594 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3595 bound_minimal_symbol exception_msym
;
3597 /* True if we have looked for exception probes. */
3598 int exception_searched
= 0;
3600 /* SystemTap probe points for unwinding (if any). These are non-owning
3602 std::vector
<probe
*> exception_probes
;
3605 static const registry
<objfile
>::key
<breakpoint_objfile_data
>
3606 breakpoint_objfile_key
;
3608 /* Minimal symbol not found sentinel. */
3609 static struct minimal_symbol msym_not_found
;
3611 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3614 msym_not_found_p (const struct minimal_symbol
*msym
)
3616 return msym
== &msym_not_found
;
3619 /* Return per-objfile data needed by breakpoint.c.
3620 Allocate the data if necessary. */
3622 static struct breakpoint_objfile_data
*
3623 get_breakpoint_objfile_data (struct objfile
*objfile
)
3625 struct breakpoint_objfile_data
*bp_objfile_data
;
3627 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3628 if (bp_objfile_data
== NULL
)
3629 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3630 return bp_objfile_data
;
3634 create_overlay_event_breakpoint (void)
3636 const char *const func_name
= "_ovly_debug_event";
3638 for (objfile
*objfile
: current_program_space
->objfiles ())
3640 struct breakpoint
*b
;
3641 struct breakpoint_objfile_data
*bp_objfile_data
;
3644 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3646 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3649 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3651 bound_minimal_symbol m
3652 = lookup_minimal_symbol_text (current_program_space
, func_name
,
3654 if (m
.minsym
== NULL
)
3656 /* Avoid future lookups in this objfile. */
3657 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3660 bp_objfile_data
->overlay_msym
= m
;
3663 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3664 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3666 b
->locspec
= new_explicit_location_spec_function (func_name
);
3668 if (overlay_debugging
== ovly_auto
)
3670 b
->enable_state
= bp_enabled
;
3671 overlay_events_enabled
= 1;
3675 b
->enable_state
= bp_disabled
;
3676 overlay_events_enabled
= 0;
3681 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3682 true if a breakpoint was installed. */
3685 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3687 struct gdbarch
*gdbarch
= objfile
->arch ();
3688 struct breakpoint_objfile_data
*bp_objfile_data
3689 = get_breakpoint_objfile_data (objfile
);
3691 if (!bp_objfile_data
->longjmp_searched
)
3693 std::vector
<probe
*> ret
3694 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3698 /* We are only interested in checking one element. */
3701 if (!p
->can_evaluate_arguments ())
3703 /* We cannot use the probe interface here,
3704 because it does not know how to evaluate
3709 bp_objfile_data
->longjmp_probes
= ret
;
3710 bp_objfile_data
->longjmp_searched
= 1;
3713 if (bp_objfile_data
->longjmp_probes
.empty ())
3716 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3718 struct breakpoint
*b
;
3720 b
= create_internal_breakpoint (gdbarch
,
3721 p
->get_relocated_address (objfile
),
3723 b
->locspec
= new_probe_location_spec ("-probe-stap libc:longjmp");
3724 b
->enable_state
= bp_disabled
;
3730 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3731 Return true if at least one breakpoint was installed. */
3734 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3736 struct gdbarch
*gdbarch
= objfile
->arch ();
3737 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3740 struct breakpoint_objfile_data
*bp_objfile_data
3741 = get_breakpoint_objfile_data (objfile
);
3742 unsigned int installed_bp
= 0;
3744 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3746 struct breakpoint
*b
;
3747 const char *func_name
;
3750 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3753 func_name
= longjmp_names
[i
];
3754 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3756 bound_minimal_symbol m
3757 = lookup_minimal_symbol_text (objfile
->pspace (), func_name
,
3759 if (m
.minsym
== NULL
)
3761 /* Prevent future lookups in this objfile. */
3762 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3765 bp_objfile_data
->longjmp_msym
[i
] = m
;
3768 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3769 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3770 b
->locspec
= new_explicit_location_spec_function (func_name
);
3771 b
->enable_state
= bp_disabled
;
3775 return installed_bp
> 0;
3778 /* Create a master longjmp breakpoint. */
3781 create_longjmp_master_breakpoint (void)
3783 scoped_restore_current_program_space restore_pspace
;
3785 for (struct program_space
*pspace
: program_spaces
)
3787 set_current_program_space (pspace
);
3789 for (objfile
*obj
: pspace
->objfiles ())
3791 /* Skip separate debug object, it's handled in the loop below. */
3792 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3795 /* Try a probe kind breakpoint on main objfile. */
3796 if (create_longjmp_master_breakpoint_probe (obj
))
3799 /* Try longjmp_names kind breakpoints on main and separate_debug
3801 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3802 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3808 /* Create a master std::terminate breakpoint. */
3810 create_std_terminate_master_breakpoint (void)
3812 const char *const func_name
= "std::terminate()";
3814 scoped_restore_current_program_space restore_pspace
;
3815 scoped_restore_current_language
save_language (language_cplus
);
3817 for (struct program_space
*pspace
: program_spaces
)
3819 set_current_program_space (pspace
);
3821 for (objfile
*objfile
: pspace
->objfiles ())
3823 struct breakpoint
*b
;
3824 struct breakpoint_objfile_data
*bp_objfile_data
;
3826 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3828 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3831 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3833 bound_minimal_symbol m
3834 = lookup_minimal_symbol (current_program_space
, func_name
,
3836 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3837 && m
.minsym
->type () != mst_file_text
))
3839 /* Prevent future lookups in this objfile. */
3840 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3843 bp_objfile_data
->terminate_msym
= m
;
3846 b
= create_internal_breakpoint (objfile
->arch (),
3847 bp_objfile_data
->terminate_msym
,
3848 bp_std_terminate_master
);
3849 b
->locspec
= new_explicit_location_spec_function (func_name
);
3850 b
->enable_state
= bp_disabled
;
3855 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3856 probe. Return true if a breakpoint was installed. */
3859 create_exception_master_breakpoint_probe (objfile
*objfile
)
3861 struct breakpoint
*b
;
3862 struct gdbarch
*gdbarch
;
3863 struct breakpoint_objfile_data
*bp_objfile_data
;
3865 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3867 /* We prefer the SystemTap probe point if it exists. */
3868 if (!bp_objfile_data
->exception_searched
)
3870 std::vector
<probe
*> ret
3871 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3875 /* We are only interested in checking one element. */
3878 if (!p
->can_evaluate_arguments ())
3880 /* We cannot use the probe interface here, because it does
3881 not know how to evaluate arguments. */
3885 bp_objfile_data
->exception_probes
= ret
;
3886 bp_objfile_data
->exception_searched
= 1;
3889 if (bp_objfile_data
->exception_probes
.empty ())
3892 gdbarch
= objfile
->arch ();
3894 for (probe
*p
: bp_objfile_data
->exception_probes
)
3896 b
= create_internal_breakpoint (gdbarch
,
3897 p
->get_relocated_address (objfile
),
3898 bp_exception_master
);
3899 b
->locspec
= new_probe_location_spec ("-probe-stap libgcc:unwind");
3900 b
->enable_state
= bp_disabled
;
3906 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3907 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3910 create_exception_master_breakpoint_hook (objfile
*objfile
)
3912 const char *const func_name
= "_Unwind_DebugHook";
3913 struct breakpoint
*b
;
3914 struct gdbarch
*gdbarch
;
3915 struct breakpoint_objfile_data
*bp_objfile_data
;
3917 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3919 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3922 gdbarch
= objfile
->arch ();
3924 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3926 bound_minimal_symbol debug_hook
3927 = lookup_minimal_symbol_text (objfile
->pspace (), func_name
, objfile
);
3928 if (debug_hook
.minsym
== NULL
)
3930 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3934 bp_objfile_data
->exception_msym
= debug_hook
;
3937 b
= create_internal_breakpoint (gdbarch
, bp_objfile_data
->exception_msym
,
3938 bp_exception_master
);
3939 b
->locspec
= new_explicit_location_spec_function (func_name
);
3940 b
->enable_state
= bp_disabled
;
3945 /* Install a master breakpoint on the unwinder's debug hook. */
3948 create_exception_master_breakpoint (void)
3950 for (objfile
*obj
: current_program_space
->objfiles ())
3952 /* Skip separate debug object. */
3953 if (obj
->separate_debug_objfile_backlink
)
3956 /* Try a probe kind breakpoint. */
3957 if (create_exception_master_breakpoint_probe (obj
))
3960 /* Iterate over main and separate debug objects and try an
3961 _Unwind_DebugHook kind breakpoint. */
3962 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3963 if (create_exception_master_breakpoint_hook (debug_objfile
))
3968 /* Does B have a location spec? */
3971 breakpoint_location_spec_empty_p (const struct breakpoint
*b
)
3973 return (b
->locspec
!= nullptr && b
->locspec
->empty_p ());
3977 update_breakpoints_after_exec (void)
3979 /* We're about to delete breakpoints from GDB's lists. If the
3980 INSERTED flag is true, GDB will try to lift the breakpoints by
3981 writing the breakpoints' "shadow contents" back into memory. The
3982 "shadow contents" are NOT valid after an exec, so GDB should not
3983 do that. Instead, the target is responsible from marking
3984 breakpoints out as soon as it detects an exec. We don't do that
3985 here instead, because there may be other attempts to delete
3986 breakpoints after detecting an exec and before reaching here. */
3987 for (bp_location
*bploc
: all_bp_locations ())
3988 if (bploc
->pspace
== current_program_space
)
3989 gdb_assert (!bploc
->inserted
);
3991 for (breakpoint
&b
: all_breakpoints_safe ())
3993 if (b
.pspace
!= current_program_space
)
3996 /* Solib breakpoints must be explicitly reset after an exec(). */
3997 if (b
.type
== bp_shlib_event
)
3999 delete_breakpoint (&b
);
4003 /* JIT breakpoints must be explicitly reset after an exec(). */
4004 if (b
.type
== bp_jit_event
)
4006 delete_breakpoint (&b
);
4010 /* Thread event breakpoints must be set anew after an exec(),
4011 as must overlay event and longjmp master breakpoints. */
4012 if (b
.type
== bp_thread_event
|| b
.type
== bp_overlay_event
4013 || b
.type
== bp_longjmp_master
|| b
.type
== bp_std_terminate_master
4014 || b
.type
== bp_exception_master
)
4016 delete_breakpoint (&b
);
4020 /* Step-resume breakpoints are meaningless after an exec(). */
4021 if (b
.type
== bp_step_resume
|| b
.type
== bp_hp_step_resume
)
4023 delete_breakpoint (&b
);
4027 /* Just like single-step breakpoints. */
4028 if (b
.type
== bp_single_step
)
4030 delete_breakpoint (&b
);
4034 /* Longjmp and longjmp-resume breakpoints are also meaningless
4036 if (b
.type
== bp_longjmp
|| b
.type
== bp_longjmp_resume
4037 || b
.type
== bp_longjmp_call_dummy
4038 || b
.type
== bp_exception
|| b
.type
== bp_exception_resume
)
4040 delete_breakpoint (&b
);
4044 if (b
.type
== bp_catchpoint
)
4046 /* For now, none of the bp_catchpoint breakpoints need to
4047 do anything at this point. In the future, if some of
4048 the catchpoints need to something, we will need to add
4049 a new method, and call this method from here. */
4053 /* bp_finish is a special case. The only way we ought to be able
4054 to see one of these when an exec() has happened, is if the user
4055 caught a vfork, and then said "finish". Ordinarily a finish just
4056 carries them to the call-site of the current callee, by setting
4057 a temporary bp there and resuming. But in this case, the finish
4058 will carry them entirely through the vfork & exec.
4060 We don't want to allow a bp_finish to remain inserted now. But
4061 we can't safely delete it, 'cause finish_command has a handle to
4062 the bp on a bpstat, and will later want to delete it. There's a
4063 chance (and I've seen it happen) that if we delete the bp_finish
4064 here, that its storage will get reused by the time finish_command
4065 gets 'round to deleting the "use to be a bp_finish" breakpoint.
4066 We really must allow finish_command to delete a bp_finish.
4068 In the absence of a general solution for the "how do we know
4069 it's safe to delete something others may have handles to?"
4070 problem, what we'll do here is just uninsert the bp_finish, and
4071 let finish_command delete it.
4073 (We know the bp_finish is "doomed" in the sense that it's
4074 momentary, and will be deleted as soon as finish_command sees
4075 the inferior stopped. So it doesn't matter that the bp's
4076 address is probably bogus in the new a.out, unlike e.g., the
4077 solib breakpoints.) */
4079 if (b
.type
== bp_finish
)
4084 /* Without a symbolic address, we have little hope of the
4085 pre-exec() address meaning the same thing in the post-exec()
4087 if (breakpoint_location_spec_empty_p (&b
))
4089 delete_breakpoint (&b
);
4096 detach_breakpoints (ptid_t ptid
)
4099 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
4100 struct inferior
*inf
= current_inferior ();
4102 if (ptid
.pid () == inferior_ptid
.pid ())
4103 error (_("Cannot detach breakpoints of inferior_ptid"));
4105 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
4106 inferior_ptid
= ptid
;
4107 for (bp_location
*bl
: all_bp_locations ())
4109 if (bl
->pspace
!= inf
->pspace
)
4112 /* This function must physically remove breakpoints locations
4113 from the specified ptid, without modifying the breakpoint
4114 package's state. Locations of type bp_loc_other and
4115 bp_loc_software_watchpoint are only maintained at GDB side,
4116 so there is no need to remove them. Moreover, removing these
4117 would modify the breakpoint package's state. */
4118 if (bl
->loc_type
== bp_loc_other
4119 || bl
->loc_type
== bp_loc_software_watchpoint
)
4123 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
4129 /* Remove the breakpoint location BL from the current address space.
4130 Note that this is used to detach breakpoints from a child fork.
4131 When we get here, the child isn't in the inferior list, and neither
4132 do we have objects to represent its address space --- we should
4133 *not* look at bl->pspace->aspace here. */
4136 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
4138 breakpoint_debug_printf ("%s due to %s",
4139 breakpoint_location_address_str (bl
).c_str (),
4140 remove_bp_reason_str (reason
));
4144 /* BL is never in moribund_locations by our callers. */
4145 gdb_assert (bl
->owner
!= NULL
);
4147 /* The type of none suggests that owner is actually deleted.
4148 This should not ever happen. */
4149 gdb_assert (bl
->owner
->type
!= bp_none
);
4151 if (bl
->loc_type
== bp_loc_software_breakpoint
4152 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
4154 /* "Normal" instruction breakpoint: either the standard
4155 trap-instruction bp (bp_breakpoint), or a
4156 bp_hardware_breakpoint. */
4158 /* First check to see if we have to handle an overlay. */
4159 if (overlay_debugging
== ovly_off
4160 || bl
->section
== NULL
4161 || !(section_is_overlay (bl
->section
)))
4163 /* No overlay handling: just remove the breakpoint. */
4165 /* If we're trying to uninsert a memory breakpoint that we
4166 know is set in a dynamic object that is marked
4167 shlib_disabled, then either the dynamic object was
4168 removed with "remove-symbol-file" or with
4169 "nosharedlibrary". In the former case, we don't know
4170 whether another dynamic object might have loaded over the
4171 breakpoint's address -- the user might well let us know
4172 about it next with add-symbol-file (the whole point of
4173 add-symbol-file is letting the user manually maintain a
4174 list of dynamically loaded objects). If we have the
4175 breakpoint's shadow memory, that is, this is a software
4176 breakpoint managed by GDB, check whether the breakpoint
4177 is still inserted in memory, to avoid overwriting wrong
4178 code with stale saved shadow contents. Note that HW
4179 breakpoints don't have shadow memory, as they're
4180 implemented using a mechanism that is not dependent on
4181 being able to modify the target's memory, and as such
4182 they should always be removed. */
4183 if (bl
->shlib_disabled
4184 && bl
->target_info
.shadow_len
!= 0
4185 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
4188 val
= bl
->owner
->remove_location (bl
, reason
);
4192 /* This breakpoint is in an overlay section.
4193 Did we set a breakpoint at the LMA? */
4194 if (!overlay_events_enabled
)
4196 /* Yes -- overlay event support is not active, so we
4197 should have set a breakpoint at the LMA. Remove it.
4199 /* Ignore any failures: if the LMA is in ROM, we will
4200 have already warned when we failed to insert it. */
4201 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4202 target_remove_hw_breakpoint (bl
->gdbarch
,
4203 &bl
->overlay_target_info
);
4205 target_remove_breakpoint (bl
->gdbarch
,
4206 &bl
->overlay_target_info
,
4209 /* Did we set a breakpoint at the VMA?
4210 If so, we will have marked the breakpoint 'inserted'. */
4213 /* Yes -- remove it. Previously we did not bother to
4214 remove the breakpoint if the section had been
4215 unmapped, but let's not rely on that being safe. We
4216 don't know what the overlay manager might do. */
4218 /* However, we should remove *software* breakpoints only
4219 if the section is still mapped, or else we overwrite
4220 wrong code with the saved shadow contents. */
4221 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4222 || section_is_mapped (bl
->section
))
4223 val
= bl
->owner
->remove_location (bl
, reason
);
4229 /* No -- not inserted, so no need to remove. No error. */
4234 /* In some cases, we might not be able to remove a breakpoint in
4235 a shared library that has already been removed, but we have
4236 not yet processed the shlib unload event. Similarly for an
4237 unloaded add-symbol-file object - the user might not yet have
4238 had the chance to remove-symbol-file it. shlib_disabled will
4239 be set if the library/object has already been removed, but
4240 the breakpoint hasn't been uninserted yet, e.g., after
4241 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4242 always-inserted mode. */
4244 && (bl
->loc_type
== bp_loc_software_breakpoint
4245 && (bl
->shlib_disabled
4246 || solib_name_from_address (bl
->pspace
, bl
->address
)
4247 || shared_objfile_contains_address_p (bl
->pspace
,
4253 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4255 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4257 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4258 bl
->owner
->remove_location (bl
, reason
);
4260 /* Failure to remove any of the hardware watchpoints comes here. */
4261 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4262 warning (_("Could not remove hardware watchpoint %d."),
4265 else if (bl
->owner
->type
== bp_catchpoint
4266 && breakpoint_enabled (bl
->owner
)
4269 val
= bl
->owner
->remove_location (bl
, reason
);
4273 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4280 remove_breakpoint (struct bp_location
*bl
)
4282 /* BL is never in moribund_locations by our callers. */
4283 gdb_assert (bl
->owner
!= NULL
);
4285 /* The type of none suggests that owner is actually deleted.
4286 This should not ever happen. */
4287 gdb_assert (bl
->owner
->type
!= bp_none
);
4289 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4291 switch_to_program_space_and_thread (bl
->pspace
);
4293 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4296 /* See breakpoint.h. */
4299 mark_breakpoints_out (program_space
*pspace
)
4301 for (bp_location
*bl
: all_bp_locations ())
4302 if (bl
->pspace
== pspace
)
4306 /* See breakpoint.h. */
4309 breakpoint_init_inferior (inferior
*inf
, inf_context context
)
4311 /* If breakpoint locations are shared across processes, then there's
4313 if (gdbarch_has_global_breakpoints (inf
->arch ()))
4316 mark_breakpoints_out (inf
->pspace
);
4318 for (breakpoint
&b
: all_breakpoints_safe ())
4320 if (b
.has_locations () && b
.first_loc ().pspace
!= inf
->pspace
)
4326 case bp_longjmp_call_dummy
:
4328 /* If the call dummy breakpoint is at the entry point it will
4329 cause problems when the inferior is rerun, so we better get
4332 case bp_watchpoint_scope
:
4334 /* Also get rid of scope breakpoints. */
4336 case bp_shlib_event
:
4338 /* Also remove solib event breakpoints. Their addresses may
4339 have changed since the last time we ran the program.
4340 Actually we may now be debugging against different target;
4341 and so the solib backend that installed this breakpoint may
4342 not be used in by the target. E.g.,
4344 (gdb) file prog-linux
4345 (gdb) run # native linux target
4348 (gdb) file prog-win.exe
4349 (gdb) tar rem :9999 # remote Windows gdbserver.
4352 case bp_step_resume
:
4354 /* Also remove step-resume breakpoints. */
4356 case bp_single_step
:
4358 /* Also remove single-step breakpoints. */
4360 delete_breakpoint (&b
);
4364 case bp_hardware_watchpoint
:
4365 case bp_read_watchpoint
:
4366 case bp_access_watchpoint
:
4368 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
4370 /* Likewise for watchpoints on local expressions. */
4371 if (w
.exp_valid_block
!= NULL
)
4372 delete_breakpoint (&b
);
4375 /* Get rid of existing locations, which are no longer
4376 valid. New ones will be created in
4377 update_watchpoint, when the inferior is restarted.
4378 The next update_global_location_list call will
4379 garbage collect them. */
4380 b
.clear_locations ();
4382 if (context
== inf_starting
)
4384 /* Reset val field to force reread of starting value in
4385 insert_breakpoints. */
4386 w
.val
.reset (nullptr);
4387 w
.val_valid
= false;
4397 /* Get rid of the moribund locations. */
4398 for (bp_location
*bl
: moribund_locations
)
4399 decref_bp_location (&bl
);
4400 moribund_locations
.clear ();
4403 /* These functions concern about actual breakpoints inserted in the
4404 target --- to e.g. check if we need to do decr_pc adjustment or if
4405 we need to hop over the bkpt --- so we check for address space
4406 match, not program space. */
4408 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4409 exists at PC. It returns ordinary_breakpoint_here if it's an
4410 ordinary breakpoint, or permanent_breakpoint_here if it's a
4411 permanent breakpoint.
4412 - When continuing from a location with an ordinary breakpoint, we
4413 actually single step once before calling insert_breakpoints.
4414 - When continuing from a location with a permanent breakpoint, we
4415 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4416 the target, to advance the PC past the breakpoint. */
4418 enum breakpoint_here
4419 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4421 bool any_breakpoint_here
= false;
4423 for (bp_location
*bl
: all_bp_locations ())
4425 if (bl
->loc_type
!= bp_loc_software_breakpoint
4426 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4429 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4430 if ((breakpoint_enabled (bl
->owner
)
4432 && breakpoint_location_address_match (bl
, aspace
, pc
))
4434 if (overlay_debugging
4435 && section_is_overlay (bl
->section
)
4436 && !section_is_mapped (bl
->section
))
4437 continue; /* unmapped overlay -- can't be a match */
4438 else if (bl
->permanent
)
4439 return permanent_breakpoint_here
;
4441 any_breakpoint_here
= true;
4445 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4448 /* See breakpoint.h. */
4451 breakpoint_in_range_p (const address_space
*aspace
,
4452 CORE_ADDR addr
, ULONGEST len
)
4454 for (bp_location
*bl
: all_bp_locations ())
4456 if (bl
->loc_type
!= bp_loc_software_breakpoint
4457 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4460 if ((breakpoint_enabled (bl
->owner
)
4462 && breakpoint_location_address_range_overlap (bl
, aspace
,
4465 if (overlay_debugging
4466 && section_is_overlay (bl
->section
)
4467 && !section_is_mapped (bl
->section
))
4469 /* Unmapped overlay -- can't be a match. */
4480 /* Return true if there's a moribund breakpoint at PC. */
4483 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4485 for (bp_location
*loc
: moribund_locations
)
4486 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4492 /* Returns true iff BL is inserted at PC, in address space ASPACE. */
4495 bp_location_inserted_here_p (const struct bp_location
*bl
,
4496 const address_space
*aspace
, CORE_ADDR pc
)
4499 && breakpoint_address_match (bl
->pspace
->aspace
.get (), bl
->address
,
4502 /* An unmapped overlay can't be a match. */
4503 return !(overlay_debugging
4504 && section_is_overlay (bl
->section
)
4505 && !section_is_mapped (bl
->section
));
4510 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4513 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4515 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4517 if (bl
->loc_type
!= bp_loc_software_breakpoint
4518 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4521 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4527 /* This function returns non-zero iff there is a software breakpoint
4531 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4534 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4536 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4539 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4546 /* See breakpoint.h. */
4549 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4552 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4554 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4557 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4565 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4566 CORE_ADDR addr
, ULONGEST len
)
4568 for (breakpoint
&bpt
: all_breakpoints ())
4570 if (bpt
.type
!= bp_hardware_watchpoint
4571 && bpt
.type
!= bp_access_watchpoint
)
4574 if (!breakpoint_enabled (&bpt
))
4577 for (bp_location
&loc
: bpt
.locations ())
4578 if (loc
.pspace
->aspace
.get () == aspace
&& loc
.inserted
)
4582 /* Check for intersection. */
4583 l
= std::max
<CORE_ADDR
> (loc
.address
, addr
);
4584 h
= std::min
<CORE_ADDR
> (loc
.address
+ loc
.length
, addr
+ len
);
4592 /* See breakpoint.h. */
4595 is_catchpoint (struct breakpoint
*b
)
4597 return (b
->type
== bp_catchpoint
);
4600 /* Clear a bpstat so that it says we are not at any breakpoint.
4601 Also free any storage that is part of a bpstat. */
4604 bpstat_clear (bpstat
**bsp
)
4621 bpstat::bpstat (const bpstat
&other
)
4623 bp_location_at (other
.bp_location_at
),
4624 breakpoint_at (other
.breakpoint_at
),
4625 commands (other
.commands
),
4626 print (other
.print
),
4628 print_it (other
.print_it
)
4630 if (other
.old_val
!= NULL
)
4631 old_val
= release_value (other
.old_val
->copy ());
4634 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4635 is part of the bpstat is copied as well. */
4638 bpstat_copy (bpstat
*bs
)
4640 bpstat
*p
= nullptr;
4642 bpstat
*retval
= nullptr;
4647 for (; bs
!= NULL
; bs
= bs
->next
)
4649 tmp
= new bpstat (*bs
);
4652 /* This is the first thing in the chain. */
4662 /* Find the bpstat associated with this breakpoint. */
4665 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4670 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4672 if (bsp
->breakpoint_at
== breakpoint
)
4678 /* See breakpoint.h. */
4681 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4683 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4685 if (bsp
->breakpoint_at
== NULL
)
4687 /* A moribund location can never explain a signal other than
4689 if (sig
== GDB_SIGNAL_TRAP
)
4694 if (bsp
->breakpoint_at
->explains_signal (sig
))
4702 /* See breakpoint.h. */
4705 bpstat_num (bpstat
**bsp
, int *num
)
4707 struct breakpoint
*b
;
4710 return 0; /* No more breakpoint values */
4712 /* We assume we'll never have several bpstats that correspond to a
4713 single breakpoint -- otherwise, this function might return the
4714 same number more than once and this will look ugly. */
4715 b
= (*bsp
)->breakpoint_at
;
4716 *bsp
= (*bsp
)->next
;
4718 return -1; /* breakpoint that's been deleted since */
4720 *num
= b
->number
; /* We have its number */
4724 /* See breakpoint.h */
4727 bpstat_locno (const bpstat
*bs
)
4729 const struct breakpoint
*b
= bs
->breakpoint_at
;
4730 const struct bp_location
*bl
= bs
->bp_location_at
.get ();
4732 if (b
!= nullptr && b
->has_multiple_locations ())
4736 for (bp_location
&loc
: b
->locations ())
4744 warning (_("location number not found for breakpoint %d address %s."),
4745 b
->number
, paddress (bl
->gdbarch
, bl
->address
));
4751 /* See breakpoint.h. */
4754 print_num_locno (const bpstat
*bs
, struct ui_out
*uiout
)
4756 struct breakpoint
*b
= bs
->breakpoint_at
;
4759 uiout
->text (_("deleted breakpoint"));
4762 uiout
->field_signed ("bkptno", b
->number
);
4764 int locno
= bpstat_locno (bs
);
4766 uiout
->message (".%pF", signed_field ("locno", locno
));
4770 /* See breakpoint.h. */
4773 bpstat_clear_actions (void)
4777 if (inferior_ptid
== null_ptid
)
4780 thread_info
*tp
= inferior_thread ();
4781 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4783 bs
->commands
= NULL
;
4784 bs
->old_val
.reset (nullptr);
4788 /* Called when a command is about to proceed the inferior. */
4791 breakpoint_about_to_proceed (void)
4793 if (inferior_ptid
!= null_ptid
)
4795 struct thread_info
*tp
= inferior_thread ();
4797 /* Allow inferior function calls in breakpoint commands to not
4798 interrupt the command list. When the call finishes
4799 successfully, the inferior will be standing at the same
4800 breakpoint as if nothing happened. */
4801 if (tp
->control
.in_infcall
)
4805 breakpoint_proceeded
= 1;
4808 /* Return true iff CMD as the first line of a command sequence is `silent'
4809 or its equivalent. */
4812 command_line_is_silent (struct command_line
*cmd
)
4814 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4817 /* Sets the $_hit_bpnum and $_hit_locno to bpnum and locno.
4818 A locno 0 is changed to 1 to e.g. let the user do
4819 (gdb) disable $_hit_bpnum.$_hit_locno
4820 for a single location breakpoint. */
4823 set_hit_convenience_vars (int bpnum
, int locno
)
4825 set_internalvar_integer (lookup_internalvar ("_hit_bpnum"), bpnum
);
4826 set_internalvar_integer (lookup_internalvar ("_hit_locno"),
4827 (locno
> 0 ? locno
: 1));
4830 /* Execute all the commands associated with all the breakpoints at
4831 this location. Any of these commands could cause the process to
4832 proceed beyond this point, etc. We look out for such changes by
4833 checking the global "breakpoint_proceeded" after each command.
4835 Returns true if a breakpoint command resumed the inferior. In that
4836 case, it is the caller's responsibility to recall it again with the
4837 bpstat of the current thread. */
4840 bpstat_do_actions_1 (bpstat
**bsp
)
4845 /* Avoid endless recursion if a `source' command is contained
4847 if (executing_breakpoint_commands
)
4850 scoped_restore save_executing
4851 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4853 scoped_restore preventer
= prevent_dont_repeat ();
4855 /* This pointer will iterate over the list of bpstat's. */
4858 /* The $_hit_* convenience variables are set before running the
4859 commands of BS. In case we have several bs, after the loop,
4860 we set again the variables to the first printed bpnum and locno.
4861 For multiple breakpoints, this ensures the variables are set to the
4862 breakpoint printed for the user. */
4863 int printed_hit_bpnum
= -1;
4864 int printed_hit_locno
= -1;
4866 breakpoint_proceeded
= 0;
4867 for (; bs
!= NULL
; bs
= bs
->next
)
4869 struct command_line
*cmd
= NULL
;
4871 /* Set the _hit_* convenience variables before running BS's commands. */
4873 const struct breakpoint
*b
= bs
->breakpoint_at
;
4876 int locno
= bpstat_locno (bs
);
4878 set_hit_convenience_vars (b
->number
, locno
);
4879 if (printed_hit_locno
== -1 && bs
->print
)
4881 printed_hit_bpnum
= b
->number
;
4882 printed_hit_locno
= locno
;
4887 /* Take ownership of the BSP's command tree, if it has one.
4889 The command tree could legitimately contain commands like
4890 'step' and 'next', which call clear_proceed_status, which
4891 frees the bpstat BS and its command tree. To make sure this doesn't
4892 free the tree we're executing out from under us, we need to
4893 take ownership of the tree ourselves. Since a given bpstat's
4894 commands are only executed once, we don't need to copy it; we
4895 can clear the pointer in the bpstat, and make sure we free
4896 the tree when we're done. */
4897 counted_command_line ccmd
= bs
->commands
;
4898 bs
->commands
= NULL
;
4901 if (command_line_is_silent (cmd
))
4903 /* The action has been already done by bpstat_stop_status. */
4909 execute_control_command (cmd
);
4910 /* After execute_control_command, if breakpoint_proceeded is true,
4911 BS has been freed and cannot be accessed anymore. */
4913 if (breakpoint_proceeded
)
4919 if (breakpoint_proceeded
)
4921 if (current_ui
->async
)
4922 /* If we are in async mode, then the target might be still
4923 running, not stopped at any breakpoint, so nothing for
4924 us to do here -- just return to the event loop. */
4927 /* In sync mode, when execute_control_command returns
4928 we're already standing on the next breakpoint.
4929 Breakpoint commands for that stop were not run, since
4930 execute_command does not run breakpoint commands --
4931 only command_line_handler does, but that one is not
4932 involved in execution of breakpoint commands. So, we
4933 can now execute breakpoint commands. It should be
4934 noted that making execute_command do bpstat actions is
4935 not an option -- in this case we'll have recursive
4936 invocation of bpstat for each breakpoint with a
4937 command, and can easily blow up GDB stack. Instead, we
4938 return true, which will trigger the caller to recall us
4939 with the new stop_bpstat. */
4945 /* Now that we have executed the commands of all bs, set the _hit_*
4946 convenience variables to the printed values. */
4947 if (printed_hit_locno
!= -1)
4948 set_hit_convenience_vars (printed_hit_bpnum
, printed_hit_locno
);
4953 /* Helper for bpstat_do_actions. Get the current thread, if there's
4954 one, is alive and has execution. Return NULL otherwise. */
4956 static thread_info
*
4957 get_bpstat_thread ()
4959 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4962 thread_info
*tp
= inferior_thread ();
4963 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4969 bpstat_do_actions (void)
4971 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4974 /* Do any commands attached to breakpoint we are stopped at. */
4975 while ((tp
= get_bpstat_thread ()) != NULL
)
4977 /* Since in sync mode, bpstat_do_actions may resume the
4978 inferior, and only return when it is stopped at the next
4979 breakpoint, we keep doing breakpoint actions until it returns
4980 false to indicate the inferior was not resumed. */
4981 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4985 cleanup_if_error
.release ();
4988 /* Print out the (old or new) value associated with a watchpoint. */
4991 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4994 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4997 struct value_print_options opts
;
4998 get_user_print_options (&opts
);
4999 value_print (val
, stream
, &opts
);
5003 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
5004 debugging multiple threads. */
5007 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
5009 if (uiout
->is_mi_like_p ())
5014 if (show_thread_that_caused_stop ())
5016 struct thread_info
*thr
= inferior_thread ();
5018 uiout
->text ("Thread ");
5019 uiout
->field_string ("thread-id", print_thread_id (thr
));
5021 const char *name
= thread_name (thr
);
5024 uiout
->text (" \"");
5025 uiout
->field_string ("name", name
);
5029 uiout
->text (" hit ");
5033 /* Generic routine for printing messages indicating why we
5034 stopped. The behavior of this function depends on the value
5035 'print_it' in the bpstat structure. Under some circumstances we
5036 may decide not to print anything here and delegate the task to
5039 static enum print_stop_action
5040 print_bp_stop_message (bpstat
*bs
)
5042 switch (bs
->print_it
)
5045 /* Nothing should be printed for this bpstat entry. */
5046 return PRINT_UNKNOWN
;
5049 /* We still want to print the frame, but we already printed the
5050 relevant messages. */
5051 return PRINT_SRC_AND_LOC
;
5053 case print_it_normal
:
5055 struct breakpoint
*b
= bs
->breakpoint_at
;
5057 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
5058 which has since been deleted. */
5060 return PRINT_UNKNOWN
;
5062 /* Normal case. Call the breakpoint's print_it method. */
5063 return b
->print_it (bs
);
5067 internal_error (_("print_bp_stop_message: unrecognized enum value"));
5071 /* See breakpoint.h. */
5074 print_solib_event (bool is_catchpoint
)
5076 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
5077 bool any_added
= !current_program_space
->added_solibs
.empty ();
5081 if (any_added
|| any_deleted
)
5082 current_uiout
->text (_("Stopped due to shared library event:\n"));
5084 current_uiout
->text (_("Stopped due to shared library event (no "
5085 "libraries added or removed)\n"));
5088 if (current_uiout
->is_mi_like_p ())
5089 current_uiout
->field_string ("reason",
5090 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
5094 current_uiout
->text (_(" Inferior unloaded "));
5095 ui_out_emit_list
list_emitter (current_uiout
, "removed");
5096 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
5098 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
5101 current_uiout
->text (" ");
5102 current_uiout
->field_string ("library", name
);
5103 current_uiout
->text ("\n");
5109 current_uiout
->text (_(" Inferior loaded "));
5110 ui_out_emit_list
list_emitter (current_uiout
, "added");
5112 for (solib
*iter
: current_program_space
->added_solibs
)
5115 current_uiout
->text (" ");
5117 current_uiout
->field_string ("library", iter
->so_name
);
5118 current_uiout
->text ("\n");
5123 /* Print a message indicating what happened. This is called from
5124 normal_stop(). The input to this routine is the head of the bpstat
5125 list - a list of the eventpoints that caused this stop. KIND is
5126 the target_waitkind for the stopping event. This
5127 routine calls the generic print routine for printing a message
5128 about reasons for stopping. This will print (for example) the
5129 "Breakpoint n," part of the output. The return value of this
5132 PRINT_UNKNOWN: Means we printed nothing.
5133 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
5134 code to print the location. An example is
5135 "Breakpoint 1, " which should be followed by
5137 PRINT_SRC_ONLY: Means we printed something, but there is no need
5138 to also print the location part of the message.
5139 An example is the catch/throw messages, which
5140 don't require a location appended to the end.
5141 PRINT_NOTHING: We have done some printing and we don't need any
5142 further info to be printed. */
5144 enum print_stop_action
5145 bpstat_print (bpstat
*bs
, target_waitkind kind
)
5147 enum print_stop_action val
;
5149 /* Maybe another breakpoint in the chain caused us to stop.
5150 (Currently all watchpoints go on the bpstat whether hit or not.
5151 That probably could (should) be changed, provided care is taken
5152 with respect to bpstat_explains_signal). */
5153 for (; bs
; bs
= bs
->next
)
5155 val
= print_bp_stop_message (bs
);
5156 if (val
== PRINT_SRC_ONLY
5157 || val
== PRINT_SRC_AND_LOC
5158 || val
== PRINT_NOTHING
)
5162 /* If we had hit a shared library event breakpoint,
5163 print_bp_stop_message would print out this message. If we hit an
5164 OS-level shared library event, do the same thing. */
5165 if (kind
== TARGET_WAITKIND_LOADED
)
5167 print_solib_event (false);
5168 return PRINT_NOTHING
;
5171 /* We reached the end of the chain, or we got a null BS to start
5172 with and nothing was printed. */
5173 return PRINT_UNKNOWN
;
5176 /* Evaluate the boolean expression EXP and return the result. */
5179 breakpoint_cond_eval (expression
*exp
)
5181 scoped_value_mark mark
;
5182 return value_true (exp
->evaluate ());
5185 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5187 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
5189 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
5190 breakpoint_at (bl
->owner
),
5194 print_it (print_it_normal
)
5196 **bs_link_pointer
= this;
5197 *bs_link_pointer
= &next
;
5202 breakpoint_at (NULL
),
5206 print_it (print_it_normal
)
5210 /* The target has stopped with waitstatus WS. Check if any hardware
5211 watchpoints have triggered, according to the target. */
5214 watchpoints_triggered (const target_waitstatus
&ws
)
5216 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5219 if (!stopped_by_watchpoint
)
5221 /* We were not stopped by a watchpoint. Mark all watchpoints
5222 as not triggered. */
5223 for (breakpoint
&b
: all_breakpoints ())
5224 if (is_hardware_watchpoint (&b
))
5226 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
5228 w
.watchpoint_triggered
= watch_triggered_no
;
5234 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
5236 /* We were stopped by a watchpoint, but we don't know where.
5237 Mark all watchpoints as unknown. */
5238 for (breakpoint
&b
: all_breakpoints ())
5239 if (is_hardware_watchpoint (&b
))
5241 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
5243 w
.watchpoint_triggered
= watch_triggered_unknown
;
5249 /* The target could report the data address. Mark watchpoints
5250 affected by this data address as triggered, and all others as not
5253 for (breakpoint
&b
: all_breakpoints ())
5254 if (is_hardware_watchpoint (&b
))
5256 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
5258 w
.watchpoint_triggered
= watch_triggered_no
;
5259 for (bp_location
&loc
: b
.locations ())
5261 if (is_masked_watchpoint (&b
))
5263 CORE_ADDR newaddr
= addr
& w
.hw_wp_mask
;
5264 CORE_ADDR start
= loc
.address
& w
.hw_wp_mask
;
5266 if (newaddr
== start
)
5268 w
.watchpoint_triggered
= watch_triggered_yes
;
5272 /* Exact match not required. Within range is sufficient. */
5273 else if (target_watchpoint_addr_within_range
5274 (current_inferior ()->top_target (), addr
, loc
.address
,
5277 w
.watchpoint_triggered
= watch_triggered_yes
;
5286 /* Possible return values for watchpoint_check. */
5287 enum wp_check_result
5289 /* The watchpoint has been deleted. */
5292 /* The value has changed. */
5293 WP_VALUE_CHANGED
= 2,
5295 /* The value has not changed. */
5296 WP_VALUE_NOT_CHANGED
= 3,
5298 /* Ignore this watchpoint, no matter if the value changed or not. */
5302 #define BP_TEMPFLAG 1
5303 #define BP_HARDWAREFLAG 2
5305 /* Evaluate watchpoint condition expression and check if its value
5308 static wp_check_result
5309 watchpoint_check (bpstat
*bs
)
5312 bool within_current_scope
;
5314 /* BS is built from an existing struct breakpoint. */
5315 gdb_assert (bs
->breakpoint_at
!= NULL
);
5316 watchpoint
*b
= gdb::checked_static_cast
<watchpoint
*> (bs
->breakpoint_at
);
5318 /* If this is a local watchpoint, we only want to check if the
5319 watchpoint frame is in scope if the current thread is the thread
5320 that was used to create the watchpoint. */
5321 if (!watchpoint_in_thread_scope (b
))
5324 if (b
->exp_valid_block
== NULL
)
5325 within_current_scope
= true;
5328 frame_info_ptr frame
= get_current_frame ();
5329 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5330 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5332 /* stack_frame_destroyed_p() returns a non-zero value if we're
5333 still in the function but the stack frame has already been
5334 invalidated. Since we can't rely on the values of local
5335 variables after the stack has been destroyed, we are treating
5336 the watchpoint in that state as `not changed' without further
5337 checking. Don't mark watchpoints as changed if the current
5338 frame is in an epilogue - even if they are in some other
5339 frame, our view of the stack is likely to be wrong and
5340 frame_find_by_id could error out. */
5341 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5344 fr
= frame_find_by_id (b
->watchpoint_frame
);
5345 within_current_scope
= (fr
!= NULL
);
5347 /* If we've gotten confused in the unwinder, we might have
5348 returned a frame that can't describe this variable. */
5349 if (within_current_scope
)
5351 struct symbol
*function
;
5353 function
= get_frame_function (fr
);
5354 if (function
== NULL
5355 || !function
->value_block ()->contains (b
->exp_valid_block
))
5356 within_current_scope
= false;
5359 if (within_current_scope
)
5360 /* If we end up stopping, the current frame will get selected
5361 in normal_stop. So this call to select_frame won't affect
5366 if (within_current_scope
)
5368 /* We use value_{,free_to_}mark because it could be a *long*
5369 time before we return to the command level and call
5370 free_all_values. We can't call free_all_values because we
5371 might be in the middle of evaluating a function call. */
5374 struct value
*new_val
;
5376 if (is_masked_watchpoint (b
))
5377 /* Since we don't know the exact trigger address (from
5378 stopped_data_address), just tell the user we've triggered
5379 a mask watchpoint. */
5380 return WP_VALUE_CHANGED
;
5382 mark
= value_mark ();
5383 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5386 if (b
->val_bitsize
!= 0)
5387 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5389 /* We use value_equal_contents instead of value_equal because
5390 the latter coerces an array to a pointer, thus comparing just
5391 the address of the array instead of its contents. This is
5392 not what we want. */
5393 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5394 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5397 bs
->old_val
= b
->val
;
5398 b
->val
= release_value (new_val
);
5399 b
->val_valid
= true;
5400 if (new_val
!= NULL
)
5401 value_free_to_mark (mark
);
5402 return WP_VALUE_CHANGED
;
5406 /* Nothing changed. */
5407 value_free_to_mark (mark
);
5408 return WP_VALUE_NOT_CHANGED
;
5413 /* This seems like the only logical thing to do because
5414 if we temporarily ignored the watchpoint, then when
5415 we reenter the block in which it is valid it contains
5416 garbage (in the case of a function, it may have two
5417 garbage values, one before and one after the prologue).
5418 So we can't even detect the first assignment to it and
5419 watch after that (since the garbage may or may not equal
5420 the first value assigned). */
5421 /* We print all the stop information in
5422 breakpointprint_it, but in this case, by the time we
5423 call breakpoint->print_it this bp will be deleted
5424 already. So we have no choice but print the information
5427 SWITCH_THRU_ALL_UIS ()
5429 struct ui_out
*uiout
= current_uiout
;
5431 if (uiout
->is_mi_like_p ())
5433 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5434 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5435 "left the block in\n"
5436 "which its expression is valid.\n",
5437 signed_field ("wpnum", b
->number
));
5440 /* Make sure the watchpoint's commands aren't executed. */
5442 watchpoint_del_at_next_stop (b
);
5448 /* Return true if it looks like target has stopped due to hitting
5449 breakpoint location BL. This function does not check if we should
5450 stop, only if BL explains the stop. */
5453 bpstat_check_location (const struct bp_location
*bl
,
5454 const address_space
*aspace
, CORE_ADDR bp_addr
,
5455 const target_waitstatus
&ws
)
5457 struct breakpoint
*b
= bl
->owner
;
5459 /* BL is from an existing breakpoint. */
5460 gdb_assert (b
!= NULL
);
5462 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5465 /* Determine if the watched values have actually changed, and we
5466 should stop. If not, set BS->stop to false. */
5469 bpstat_check_watchpoint (bpstat
*bs
)
5471 const struct bp_location
*bl
;
5473 /* BS is built for existing struct breakpoint. */
5474 bl
= bs
->bp_location_at
.get ();
5475 gdb_assert (bl
!= NULL
);
5476 watchpoint
*b
= gdb::checked_static_cast
<watchpoint
*> (bs
->breakpoint_at
);
5478 bool must_check_value
= false;
5480 if (b
->type
== bp_watchpoint
)
5481 /* For a software watchpoint, we must always check the
5483 must_check_value
= true;
5484 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5485 /* We have a hardware watchpoint (read, write, or access)
5486 and the target earlier reported an address watched by
5488 must_check_value
= true;
5489 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5490 && b
->type
== bp_hardware_watchpoint
)
5491 /* We were stopped by a hardware watchpoint, but the target could
5492 not report the data address. We must check the watchpoint's
5493 value. Access and read watchpoints are out of luck; without
5494 a data address, we can't figure it out. */
5495 must_check_value
= true;
5497 if (must_check_value
)
5503 e
= watchpoint_check (bs
);
5505 catch (const gdb_exception_error
&ex
)
5507 exception_fprintf (gdb_stderr
, ex
,
5508 "Error evaluating expression "
5509 "for watchpoint %d\n",
5512 SWITCH_THRU_ALL_UIS ()
5514 gdb_printf (_("Watchpoint %d deleted.\n"),
5517 watchpoint_del_at_next_stop (b
);
5524 /* We've already printed what needs to be printed. */
5525 bs
->print_it
= print_it_done
;
5529 bs
->print_it
= print_it_noop
;
5532 case WP_VALUE_CHANGED
:
5533 if (b
->type
== bp_read_watchpoint
)
5535 /* There are two cases to consider here:
5537 1. We're watching the triggered memory for reads.
5538 In that case, trust the target, and always report
5539 the watchpoint hit to the user. Even though
5540 reads don't cause value changes, the value may
5541 have changed since the last time it was read, and
5542 since we're not trapping writes, we will not see
5543 those, and as such we should ignore our notion of
5546 2. We're watching the triggered memory for both
5547 reads and writes. There are two ways this may
5550 2.1. This is a target that can't break on data
5551 reads only, but can break on accesses (reads or
5552 writes), such as e.g., x86. We detect this case
5553 at the time we try to insert read watchpoints.
5555 2.2. Otherwise, the target supports read
5556 watchpoints, but, the user set an access or write
5557 watchpoint watching the same memory as this read
5560 If we're watching memory writes as well as reads,
5561 ignore watchpoint hits when we find that the
5562 value hasn't changed, as reads don't cause
5563 changes. This still gives false positives when
5564 the program writes the same value to memory as
5565 what there was already in memory (we will confuse
5566 it for a read), but it's much better than
5569 int other_write_watchpoint
= 0;
5571 if (bl
->watchpoint_type
== hw_read
)
5573 for (breakpoint
&other_b
: all_breakpoints ())
5574 if (other_b
.type
== bp_hardware_watchpoint
5575 || other_b
.type
== bp_access_watchpoint
)
5577 watchpoint
&other_w
=
5578 gdb::checked_static_cast
<watchpoint
&> (other_b
);
5580 if (other_w
.watchpoint_triggered
5581 == watch_triggered_yes
)
5583 other_write_watchpoint
= 1;
5589 if (other_write_watchpoint
5590 || bl
->watchpoint_type
== hw_access
)
5592 /* We're watching the same memory for writes,
5593 and the value changed since the last time we
5594 updated it, so this trap must be for a write.
5596 bs
->print_it
= print_it_noop
;
5601 case WP_VALUE_NOT_CHANGED
:
5602 if (b
->type
== bp_hardware_watchpoint
5603 || b
->type
== bp_watchpoint
)
5605 /* Don't stop: write watchpoints shouldn't fire if
5606 the value hasn't changed. */
5607 bs
->print_it
= print_it_noop
;
5617 else /* !must_check_value */
5619 /* This is a case where some watchpoint(s) triggered, but
5620 not at the address of this watchpoint, or else no
5621 watchpoint triggered after all. So don't print
5622 anything for this watchpoint. */
5623 bs
->print_it
= print_it_noop
;
5628 /* For breakpoints that are currently marked as telling gdb to stop,
5629 check conditions (condition proper, frame, thread and ignore count)
5630 of breakpoint referred to by BS. If we should not stop for this
5631 breakpoint, set BS->stop to 0. */
5634 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5636 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
5638 const struct bp_location
*bl
;
5639 struct breakpoint
*b
;
5641 bool condition_result
= true;
5642 struct expression
*cond
;
5644 gdb_assert (bs
->stop
);
5646 /* BS is built for existing struct breakpoint. */
5647 bl
= bs
->bp_location_at
.get ();
5648 gdb_assert (bl
!= NULL
);
5649 b
= bs
->breakpoint_at
;
5650 gdb_assert (b
!= NULL
);
5652 infrun_debug_printf ("thread = %s, breakpoint %d.%d",
5653 thread
->ptid
.to_string ().c_str (),
5654 b
->number
, find_loc_num_by_location (bl
));
5656 /* Even if the target evaluated the condition on its end and notified GDB, we
5657 need to do so again since GDB does not know if we stopped due to a
5658 breakpoint or a single step breakpoint. */
5660 if (frame_id_p (b
->frame_id
)
5661 && b
->frame_id
!= get_stack_frame_id (get_current_frame ()))
5663 infrun_debug_printf ("incorrect frame %s not %s, not stopping",
5664 get_stack_frame_id (get_current_frame ()).to_string ().c_str (),
5665 b
->frame_id
.to_string ().c_str ());
5670 /* If this is a thread/task-specific breakpoint, don't waste cpu
5671 evaluating the condition if this isn't the specified
5673 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5674 || (b
->inferior
!= -1 && b
->inferior
!= thread
->inf
->num
)
5675 || (b
->task
!= -1 && b
->task
!= ada_get_task_number (thread
)))
5677 infrun_debug_printf ("incorrect thread or task, not stopping");
5682 /* Evaluate extension language breakpoints that have a "stop" method
5684 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5686 if (is_watchpoint (b
))
5688 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
5690 cond
= w
->cond_exp
.get ();
5693 cond
= bl
->cond
.get ();
5695 if (cond
!= nullptr && b
->disposition
!= disp_del_at_next_stop
)
5697 bool within_current_scope
= true;
5699 /* We use scoped_value_mark because it could be a long time
5700 before we return to the command level and call
5701 free_all_values. We can't call free_all_values because we
5702 might be in the middle of evaluating a function call. */
5703 scoped_value_mark mark
;
5705 watchpoint
*w
= nullptr;
5706 if (is_watchpoint (b
))
5707 w
= gdb::checked_static_cast
<watchpoint
*> (b
);
5709 /* Need to select the frame, with all that implies so that
5710 the conditions will have the right context. Because we
5711 use the frame, we will not see an inlined function's
5712 variables when we arrive at a breakpoint at the start
5713 of the inlined function; the current frame will be the
5715 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5716 select_frame (get_current_frame ());
5719 frame_info_ptr frame
;
5721 /* For local watchpoint expressions, which particular
5722 instance of a local is being watched matters, so we
5723 keep track of the frame to evaluate the expression
5724 in. To evaluate the condition however, it doesn't
5725 really matter which instantiation of the function
5726 where the condition makes sense triggers the
5727 watchpoint. This allows an expression like "watch
5728 global if q > 10" set in `func', catch writes to
5729 global on all threads that call `func', or catch
5730 writes on all recursive calls of `func' by a single
5731 thread. We simply always evaluate the condition in
5732 the innermost frame that's executing where it makes
5733 sense to evaluate the condition. It seems
5735 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5737 select_frame (frame
);
5739 within_current_scope
= false;
5741 if (within_current_scope
)
5745 scoped_restore reset_in_cond_eval
5746 = make_scoped_restore (&thread
->control
.in_cond_eval
, true);
5747 condition_result
= breakpoint_cond_eval (cond
);
5749 catch (const gdb_exception_error
&ex
)
5751 int locno
= bpstat_locno (bs
);
5755 "Error in testing condition for breakpoint %d.%d:\n",
5760 "Error in testing condition for breakpoint %d:\n",
5766 warning (_("Watchpoint condition cannot be tested "
5767 "in the current scope"));
5768 /* If we failed to set the right context for this
5769 watchpoint, unconditionally report it. */
5771 /* FIXME-someday, should give breakpoint #. */
5774 if (cond
!= nullptr && !condition_result
)
5776 infrun_debug_printf ("condition_result = false, not stopping");
5780 else if (b
->ignore_count
> 0)
5782 infrun_debug_printf ("ignore count %d, not stopping",
5786 /* Increase the hit count even though we don't stop. */
5788 notify_breakpoint_modified (b
);
5793 infrun_debug_printf ("stopping at this breakpoint");
5795 infrun_debug_printf ("not stopping at this breakpoint");
5798 /* Returns true if we need to track moribund locations of LOC's type
5799 on the current target. */
5802 need_moribund_for_location_type (const struct bp_location
*loc
)
5804 return ((loc
->loc_type
== bp_loc_software_breakpoint
5805 && !target_supports_stopped_by_sw_breakpoint ())
5806 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5807 && !target_supports_stopped_by_hw_breakpoint ()));
5810 /* See breakpoint.h. */
5813 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5814 const target_waitstatus
&ws
)
5816 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5818 for (breakpoint
&b
: all_breakpoints ())
5820 if (!breakpoint_enabled (&b
))
5823 for (bp_location
&bl
: b
.locations ())
5825 /* For hardware watchpoints, we look only at the first
5826 location. The watchpoint_check function will work on the
5827 entire expression, not the individual locations. For
5828 read watchpoints, the watchpoints_triggered function has
5829 checked all locations already. */
5830 if (b
.type
== bp_hardware_watchpoint
&& &bl
!= &b
.first_loc ())
5833 if (!bl
.enabled
|| bl
.disabled_by_cond
|| bl
.shlib_disabled
)
5836 if (!bpstat_check_location (&bl
, aspace
, bp_addr
, ws
))
5839 /* Come here if it's a watchpoint, or if the break address
5842 bpstat
*bs
= new bpstat (&bl
, &bs_link
); /* Alloc a bpstat to
5845 /* Assume we stop. Should we find a watchpoint that is not
5846 actually triggered, or if the condition of the breakpoint
5847 evaluates as false, we'll reset 'stop' to 0. */
5851 /* If this is a scope breakpoint, mark the associated
5852 watchpoint as triggered so that we will handle the
5853 out-of-scope event. We'll get to the watchpoint next
5855 if (b
.type
== bp_watchpoint_scope
&& b
.related_breakpoint
!= &b
)
5858 = gdb::checked_static_cast
<watchpoint
*> (b
.related_breakpoint
);
5860 w
->watchpoint_triggered
= watch_triggered_yes
;
5865 /* Check if a moribund breakpoint explains the stop. */
5866 if (!target_supports_stopped_by_sw_breakpoint ()
5867 || !target_supports_stopped_by_hw_breakpoint ())
5869 for (bp_location
*loc
: moribund_locations
)
5871 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5872 && need_moribund_for_location_type (loc
))
5874 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5875 /* For hits of moribund locations, we should just proceed. */
5878 bs
->print_it
= print_it_noop
;
5886 /* See breakpoint.h. */
5889 bpstat_stop_status (const address_space
*aspace
,
5890 CORE_ADDR bp_addr
, thread_info
*thread
,
5891 const target_waitstatus
&ws
,
5894 struct breakpoint
*b
= NULL
;
5895 /* First item of allocated bpstat's. */
5896 bpstat
*bs_head
= stop_chain
;
5898 int need_remove_insert
;
5901 /* First, build the bpstat chain with locations that explain a
5902 target stop, while being careful to not set the target running,
5903 as that may invalidate locations (in particular watchpoint
5904 locations are recreated). Resuming will happen here with
5905 breakpoint conditions or watchpoint expressions that include
5906 inferior function calls. */
5907 if (bs_head
== NULL
)
5908 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5910 /* A bit of special processing for shlib breakpoints. We need to
5911 process solib loading here, so that the lists of loaded and
5912 unloaded libraries are correct before we handle "catch load" and
5914 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5916 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5918 handle_solib_event ();
5923 /* Now go through the locations that caused the target to stop, and
5924 check whether we're interested in reporting this stop to higher
5925 layers, or whether we should resume the target transparently. */
5929 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5934 b
= bs
->breakpoint_at
;
5935 b
->check_status (bs
);
5938 bpstat_check_breakpoint_conditions (bs
, thread
);
5944 /* We will stop here. */
5945 if (b
->disposition
== disp_disable
)
5947 --(b
->enable_count
);
5948 if (b
->enable_count
<= 0)
5949 b
->enable_state
= bp_disabled
;
5952 notify_breakpoint_modified (b
);
5955 bs
->commands
= b
->commands
;
5956 if (command_line_is_silent (bs
->commands
5957 ? bs
->commands
.get () : NULL
))
5960 b
->after_condition_true (bs
);
5965 /* Print nothing for this entry if we don't stop or don't
5967 if (!bs
->stop
|| !bs
->print
)
5968 bs
->print_it
= print_it_noop
;
5971 /* If we aren't stopping, the value of some hardware watchpoint may
5972 not have changed, but the intermediate memory locations we are
5973 watching may have. Don't bother if we're stopping; this will get
5975 need_remove_insert
= 0;
5976 if (! bpstat_causes_stop (bs_head
))
5977 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5979 && bs
->breakpoint_at
5980 && is_hardware_watchpoint (bs
->breakpoint_at
))
5983 = gdb::checked_static_cast
<watchpoint
*> (bs
->breakpoint_at
);
5985 update_watchpoint (w
, false /* don't reparse. */);
5986 need_remove_insert
= 1;
5989 if (need_remove_insert
)
5990 update_global_location_list (UGLL_MAY_INSERT
);
5991 else if (removed_any
)
5992 update_global_location_list (UGLL_DONT_INSERT
);
5997 /* See breakpoint.h. */
6000 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
6001 thread_info
*thread
, const target_waitstatus
&ws
)
6003 gdb_assert (!target_stopped_by_watchpoint ());
6005 /* Clear all watchpoints' 'watchpoint_triggered' value from a
6006 previous stop to avoid confusing bpstat_stop_status. */
6007 watchpoints_triggered (ws
);
6009 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
6013 handle_jit_event (CORE_ADDR address
)
6015 struct gdbarch
*gdbarch
;
6017 infrun_debug_printf ("handling bp_jit_event");
6019 /* Switch terminal for any messages produced by
6020 breakpoint_re_set. */
6021 target_terminal::ours_for_output ();
6023 gdbarch
= get_frame_arch (get_current_frame ());
6024 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
6025 thus it is expected that its objectfile can be found through
6026 minimal symbol lookup. If it doesn't work (and assert fails), it
6027 most likely means that `jit_breakpoint_re_set` was changes and this
6028 function needs to be updated too. */
6029 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
6030 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
6031 objfile
*objfile
= jit_bp_sym
.objfile
;
6032 if (objfile
->separate_debug_objfile_backlink
)
6033 objfile
= objfile
->separate_debug_objfile_backlink
;
6034 jit_event_handler (gdbarch
, objfile
);
6036 target_terminal::inferior ();
6039 /* Prepare WHAT final decision for infrun. */
6041 /* Decide what infrun needs to do with this bpstat. */
6044 bpstat_what (bpstat
*bs_head
)
6046 struct bpstat_what retval
;
6049 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
6050 retval
.call_dummy
= STOP_NONE
;
6051 retval
.is_longjmp
= false;
6053 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6055 /* Extract this BS's action. After processing each BS, we check
6056 if its action overrides all we've seem so far. */
6057 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
6060 if (bs
->breakpoint_at
== NULL
)
6062 /* I suspect this can happen if it was a momentary
6063 breakpoint which has since been deleted. */
6067 bptype
= bs
->breakpoint_at
->type
;
6074 case bp_hardware_breakpoint
:
6075 case bp_single_step
:
6078 case bp_shlib_event
:
6082 this_action
= BPSTAT_WHAT_STOP_NOISY
;
6084 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6087 this_action
= BPSTAT_WHAT_SINGLE
;
6090 case bp_hardware_watchpoint
:
6091 case bp_read_watchpoint
:
6092 case bp_access_watchpoint
:
6096 this_action
= BPSTAT_WHAT_STOP_NOISY
;
6098 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6102 /* There was a watchpoint, but we're not stopping.
6103 This requires no further action. */
6107 case bp_longjmp_call_dummy
:
6111 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
6112 retval
.is_longjmp
= bptype
!= bp_exception
;
6115 this_action
= BPSTAT_WHAT_SINGLE
;
6117 case bp_longjmp_resume
:
6118 case bp_exception_resume
:
6121 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
6122 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
6125 this_action
= BPSTAT_WHAT_SINGLE
;
6127 case bp_step_resume
:
6129 this_action
= BPSTAT_WHAT_STEP_RESUME
;
6132 /* It is for the wrong frame. */
6133 this_action
= BPSTAT_WHAT_SINGLE
;
6136 case bp_hp_step_resume
:
6138 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
6141 /* It is for the wrong frame. */
6142 this_action
= BPSTAT_WHAT_SINGLE
;
6145 case bp_watchpoint_scope
:
6146 case bp_thread_event
:
6147 case bp_overlay_event
:
6148 case bp_longjmp_master
:
6149 case bp_std_terminate_master
:
6150 case bp_exception_master
:
6151 this_action
= BPSTAT_WHAT_SINGLE
;
6157 this_action
= BPSTAT_WHAT_STOP_NOISY
;
6159 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6163 /* Some catchpoints are implemented with breakpoints.
6164 For those, we need to step over the breakpoint. */
6165 if (bs
->bp_location_at
->loc_type
== bp_loc_software_breakpoint
6166 || bs
->bp_location_at
->loc_type
== bp_loc_hardware_breakpoint
)
6167 this_action
= BPSTAT_WHAT_SINGLE
;
6171 this_action
= BPSTAT_WHAT_SINGLE
;
6174 /* Make sure the action is stop (silent or noisy),
6175 so infrun.c pops the dummy frame. */
6176 retval
.call_dummy
= STOP_STACK_DUMMY
;
6177 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6179 case bp_std_terminate
:
6180 /* Make sure the action is stop (silent or noisy),
6181 so infrun.c pops the dummy frame. */
6182 retval
.call_dummy
= STOP_STD_TERMINATE
;
6183 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6186 case bp_fast_tracepoint
:
6187 case bp_static_tracepoint
:
6188 case bp_static_marker_tracepoint
:
6189 /* Tracepoint hits should not be reported back to GDB, and
6190 if one got through somehow, it should have been filtered
6192 internal_error (_("bpstat_what: tracepoint encountered"));
6194 case bp_gnu_ifunc_resolver
:
6195 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
6196 this_action
= BPSTAT_WHAT_SINGLE
;
6198 case bp_gnu_ifunc_resolver_return
:
6199 /* The breakpoint will be removed, execution will restart from the
6200 PC of the former breakpoint. */
6201 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
6206 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6208 this_action
= BPSTAT_WHAT_SINGLE
;
6212 internal_error (_("bpstat_what: unhandled bptype %d"), (int) bptype
);
6215 retval
.main_action
= std::max (retval
.main_action
, this_action
);
6222 bpstat_run_callbacks (bpstat
*bs_head
)
6226 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6228 struct breakpoint
*b
= bs
->breakpoint_at
;
6235 handle_jit_event (bs
->bp_location_at
->address
);
6237 case bp_gnu_ifunc_resolver
:
6238 gnu_ifunc_resolver_stop
6239 (gdb::checked_static_cast
<code_breakpoint
*> (b
));
6241 case bp_gnu_ifunc_resolver_return
:
6242 gnu_ifunc_resolver_return_stop
6243 (gdb::checked_static_cast
<code_breakpoint
*> (b
));
6249 /* See breakpoint.h. */
6252 bpstat_should_step ()
6254 for (breakpoint
&b
: all_breakpoints ())
6255 if (breakpoint_enabled (&b
)
6256 && b
.type
== bp_watchpoint
6257 && b
.has_locations ())
6263 /* See breakpoint.h. */
6266 bpstat_causes_stop (bpstat
*bs
)
6268 for (; bs
!= NULL
; bs
= bs
->next
)
6277 /* Compute a number of spaces suitable to indent the next line
6278 so it starts at the position corresponding to the table column
6279 named COL_NAME in the currently active table of UIOUT. */
6282 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6284 int i
, total_width
, width
, align
;
6288 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6290 if (strcmp (text
, col_name
) == 0)
6293 total_width
+= width
+ 1;
6299 /* Determine if the locations of this breakpoint will have their conditions
6300 evaluated by the target, host or a mix of both. Returns the following:
6302 "host": Host evals condition.
6303 "host or target": Host or Target evals condition.
6304 "target": Target evals condition.
6308 bp_condition_evaluator (const breakpoint
*b
)
6310 char host_evals
= 0;
6311 char target_evals
= 0;
6316 if (!is_breakpoint (b
))
6319 if (gdb_evaluates_breakpoint_condition_p ()
6320 || !target_supports_evaluation_of_breakpoint_conditions ())
6321 return condition_evaluation_host
;
6323 for (bp_location
&bl
: b
->locations ())
6325 if (bl
.cond_bytecode
)
6331 if (host_evals
&& target_evals
)
6332 return condition_evaluation_both
;
6333 else if (target_evals
)
6334 return condition_evaluation_target
;
6336 return condition_evaluation_host
;
6339 /* Determine the breakpoint location's condition evaluator. This is
6340 similar to bp_condition_evaluator, but for locations. */
6343 bp_location_condition_evaluator (const struct bp_location
*bl
)
6345 if (bl
&& !is_breakpoint (bl
->owner
))
6348 if (gdb_evaluates_breakpoint_condition_p ()
6349 || !target_supports_evaluation_of_breakpoint_conditions ())
6350 return condition_evaluation_host
;
6352 if (bl
&& bl
->cond_bytecode
)
6353 return condition_evaluation_target
;
6355 return condition_evaluation_host
;
6358 /* Print the LOC location out of the list of B->LOC locations. */
6361 print_breakpoint_location (const breakpoint
*b
, const bp_location
*loc
)
6363 struct ui_out
*uiout
= current_uiout
;
6365 scoped_restore_current_program_space restore_pspace
;
6367 if (loc
!= NULL
&& loc
->shlib_disabled
)
6371 set_current_program_space (loc
->pspace
);
6373 if (b
->display_canonical
)
6374 uiout
->field_string ("what", b
->locspec
->to_string ());
6375 else if (loc
&& loc
->symtab
)
6377 const struct symbol
*sym
= loc
->symbol
;
6381 uiout
->text ("in ");
6382 uiout
->field_string ("func", sym
->print_name (),
6383 function_name_style
.style ());
6385 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6386 uiout
->text ("at ");
6388 uiout
->field_string ("file",
6389 symtab_to_filename_for_display (loc
->symtab
),
6390 file_name_style
.style ());
6393 if (uiout
->is_mi_like_p ())
6394 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6396 uiout
->field_signed ("line", loc
->line_number
,
6397 line_number_style
.style ());
6403 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6405 uiout
->field_stream ("at", stb
);
6408 uiout
->field_string ("pending", b
->locspec
->to_string ());
6410 if (loc
&& is_breakpoint (b
)
6411 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6412 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6415 uiout
->field_string ("evaluated-by",
6416 bp_location_condition_evaluator (loc
));
6422 bptype_string (enum bptype type
)
6424 struct ep_type_description
6427 const char *description
;
6429 static struct ep_type_description bptypes
[] =
6431 {bp_none
, "?deleted?"},
6432 {bp_breakpoint
, "breakpoint"},
6433 {bp_hardware_breakpoint
, "hw breakpoint"},
6434 {bp_single_step
, "sw single-step"},
6435 {bp_until
, "until"},
6436 {bp_finish
, "finish"},
6437 {bp_watchpoint
, "watchpoint"},
6438 {bp_hardware_watchpoint
, "hw watchpoint"},
6439 {bp_read_watchpoint
, "read watchpoint"},
6440 {bp_access_watchpoint
, "acc watchpoint"},
6441 {bp_longjmp
, "longjmp"},
6442 {bp_longjmp_resume
, "longjmp resume"},
6443 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6444 {bp_exception
, "exception"},
6445 {bp_exception_resume
, "exception resume"},
6446 {bp_step_resume
, "step resume"},
6447 {bp_hp_step_resume
, "high-priority step resume"},
6448 {bp_watchpoint_scope
, "watchpoint scope"},
6449 {bp_call_dummy
, "call dummy"},
6450 {bp_std_terminate
, "std::terminate"},
6451 {bp_shlib_event
, "shlib events"},
6452 {bp_thread_event
, "thread events"},
6453 {bp_overlay_event
, "overlay events"},
6454 {bp_longjmp_master
, "longjmp master"},
6455 {bp_std_terminate_master
, "std::terminate master"},
6456 {bp_exception_master
, "exception master"},
6457 {bp_catchpoint
, "catchpoint"},
6458 {bp_tracepoint
, "tracepoint"},
6459 {bp_fast_tracepoint
, "fast tracepoint"},
6460 {bp_static_tracepoint
, "static tracepoint"},
6461 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6462 {bp_dprintf
, "dprintf"},
6463 {bp_jit_event
, "jit events"},
6464 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6465 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6468 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6469 || ((int) type
!= bptypes
[(int) type
].type
))
6470 internal_error (_("bptypes table does not describe type #%d."),
6473 return bptypes
[(int) type
].description
;
6476 /* For MI, output a field named 'thread-groups' with a list as the value.
6477 For CLI, prefix the list with the string 'inf'. */
6480 output_thread_groups (struct ui_out
*uiout
,
6481 const char *field_name
,
6482 const std::vector
<int> &inf_nums
,
6485 int is_mi
= uiout
->is_mi_like_p ();
6487 /* For backward compatibility, don't display inferiors in CLI unless
6488 there are several. Always display them for MI. */
6489 if (!is_mi
&& mi_only
)
6492 ui_out_emit_list
list_emitter (uiout
, field_name
);
6494 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6500 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6501 uiout
->field_string (NULL
, mi_group
);
6506 uiout
->text (" inf ");
6510 uiout
->text (plongest (inf_nums
[i
]));
6515 /* See breakpoint.h. */
6517 bool fix_breakpoint_script_output_globally
= false;
6519 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6520 instead of going via breakpoint_ops::print_one. This makes "maint
6521 info breakpoints" show the software breakpoint locations of
6522 catchpoints, which are considered internal implementation
6523 detail. Returns true if RAW_LOC is false and if the breakpoint's
6524 print_one method did something; false otherwise. */
6527 print_one_breakpoint_location (struct breakpoint
*b
,
6528 struct bp_location
*loc
,
6530 const bp_location
**last_loc
,
6531 int allflag
, bool raw_loc
)
6533 struct command_line
*l
;
6534 static char bpenables
[] = "nynny";
6536 struct ui_out
*uiout
= current_uiout
;
6537 bool header_of_multiple
= false;
6538 bool part_of_multiple
= (loc
!= NULL
);
6539 struct value_print_options opts
;
6541 get_user_print_options (&opts
);
6543 gdb_assert (!loc
|| loc_number
!= 0);
6544 /* See comment in print_one_breakpoint concerning treatment of
6545 breakpoints with single disabled location. */
6547 && (b
->has_locations ()
6548 && (b
->has_multiple_locations ()
6549 || !b
->first_loc ().enabled
|| b
->first_loc ().disabled_by_cond
)))
6550 header_of_multiple
= true;
6552 if (loc
== NULL
&& b
->has_locations ())
6553 loc
= &b
->first_loc ();
6559 if (part_of_multiple
)
6560 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6562 uiout
->field_signed ("number", b
->number
);
6566 if (part_of_multiple
)
6567 uiout
->field_skip ("type");
6569 uiout
->field_string ("type", bptype_string (b
->type
));
6573 if (part_of_multiple
)
6574 uiout
->field_skip ("disp");
6576 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6580 if (part_of_multiple
)
6582 /* For locations that are disabled because of an invalid
6583 condition, display "N*" on the CLI, where "*" refers to a
6584 footnote below the table. For MI, simply display a "N"
6585 without a footnote. On the CLI, for enabled locations whose
6586 breakpoint is disabled, display "y-". */
6587 auto get_enable_state
= [uiout
, loc
] () -> const char *
6589 if (uiout
->is_mi_like_p ())
6591 if (loc
->disabled_by_cond
)
6593 else if (!loc
->enabled
)
6600 if (loc
->disabled_by_cond
)
6602 else if (!loc
->enabled
)
6604 else if (!breakpoint_enabled (loc
->owner
))
6610 uiout
->field_string ("enabled", get_enable_state ());
6613 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6616 bool result
= false;
6617 if (!raw_loc
&& b
->print_one (last_loc
))
6621 if (is_watchpoint (b
))
6623 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
6625 /* Field 4, the address, is omitted (which makes the columns
6626 not line up too nicely with the headers, but the effect
6627 is relatively readable). */
6628 if (opts
.addressprint
)
6629 uiout
->field_skip ("addr");
6631 uiout
->field_string ("what", w
->exp_string
.get ());
6633 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6634 || is_ada_exception_catchpoint (b
))
6636 if (opts
.addressprint
)
6639 if (header_of_multiple
)
6640 uiout
->field_string ("addr", "<MULTIPLE>",
6641 metadata_style
.style ());
6642 else if (!b
->has_locations () || loc
->shlib_disabled
)
6643 uiout
->field_string ("addr", "<PENDING>",
6644 metadata_style
.style ());
6646 uiout
->field_core_addr ("addr",
6647 loc
->gdbarch
, loc
->address
);
6650 if (!header_of_multiple
)
6651 print_breakpoint_location (b
, loc
);
6652 if (b
->has_locations ())
6653 *last_loc
= &b
->first_loc ();
6657 if (loc
!= nullptr && !header_of_multiple
&& !loc
->shlib_disabled
)
6659 std::vector
<int> inf_nums
;
6662 for (inferior
*inf
: all_inferiors ())
6664 if (inf
->pspace
== loc
->pspace
)
6665 inf_nums
.push_back (inf
->num
);
6668 /* For backward compatibility, don't display inferiors in CLI unless
6669 there are several. Always display for MI. */
6671 || (!gdbarch_has_global_breakpoints (current_inferior ()->arch ())
6672 && (program_spaces
.size () > 1
6673 || number_of_inferiors () > 1)
6674 /* LOC is for existing B, it cannot be in
6675 moribund_locations and thus having NULL OWNER. */
6676 && loc
->owner
->type
!= bp_catchpoint
))
6678 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6681 /* In the MI output, each location of a thread or task specific
6682 breakpoint includes the relevant thread or task ID. This is done for
6683 backwards compatibility reasons.
6685 For the CLI output, the thread/task information is printed on a
6686 separate line, see the 'stop only in thread' and 'stop only in task'
6688 if (part_of_multiple
&& uiout
->is_mi_like_p ())
6690 if (b
->thread
!= -1)
6691 uiout
->field_signed ("thread", b
->thread
);
6692 else if (b
->task
!= -1)
6693 uiout
->field_signed ("task", b
->task
);
6694 else if (b
->inferior
!= -1)
6695 uiout
->field_signed ("inferior", b
->inferior
);
6700 if (!part_of_multiple
)
6701 b
->print_one_detail (uiout
);
6703 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6706 uiout
->text ("\tstop only in stack frame at ");
6707 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6709 uiout
->field_core_addr ("frame",
6710 b
->gdbarch
, b
->frame_id
.stack_addr
);
6714 if (!part_of_multiple
&& b
->cond_string
)
6717 if (is_tracepoint (b
))
6718 uiout
->text ("\ttrace only if ");
6720 uiout
->text ("\tstop only if ");
6721 uiout
->field_string ("cond", b
->cond_string
.get ());
6723 /* Print whether the target is doing the breakpoint's condition
6724 evaluation. If GDB is doing the evaluation, don't print anything. */
6725 if (is_breakpoint (b
)
6726 && breakpoint_condition_evaluation_mode ()
6727 == condition_evaluation_target
)
6729 uiout
->message (" (%pF evals)",
6730 string_field ("evaluated-by",
6731 bp_condition_evaluator (b
)));
6736 if (!part_of_multiple
&& b
->thread
!= -1)
6738 /* FIXME should make an annotation for this. */
6739 uiout
->text ("\tstop only in thread ");
6740 if (uiout
->is_mi_like_p ())
6741 uiout
->field_signed ("thread", b
->thread
);
6744 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6746 uiout
->field_string ("thread", print_thread_id (thr
));
6751 if (!part_of_multiple
&& b
->task
!= -1)
6753 uiout
->text ("\tstop only in task ");
6754 uiout
->field_signed ("task", b
->task
);
6758 if (!part_of_multiple
&& b
->inferior
!= -1)
6760 uiout
->text ("\tstop only in inferior ");
6761 uiout
->field_signed ("inferior", b
->inferior
);
6765 if (!part_of_multiple
)
6769 /* FIXME should make an annotation for this. */
6770 if (is_catchpoint (b
))
6771 uiout
->text ("\tcatchpoint");
6772 else if (is_tracepoint (b
))
6773 uiout
->text ("\ttracepoint");
6775 uiout
->text ("\tbreakpoint");
6776 uiout
->text (" already hit ");
6777 uiout
->field_signed ("times", b
->hit_count
);
6778 if (b
->hit_count
== 1)
6779 uiout
->text (" time\n");
6781 uiout
->text (" times\n");
6785 /* Output the count also if it is zero, but only if this is mi. */
6786 if (uiout
->is_mi_like_p ())
6787 uiout
->field_signed ("times", b
->hit_count
);
6791 if (!part_of_multiple
&& b
->ignore_count
)
6794 uiout
->message ("\tignore next %pF hits\n",
6795 signed_field ("ignore", b
->ignore_count
));
6798 /* Note that an enable count of 1 corresponds to "enable once"
6799 behavior, which is reported by the combination of enablement and
6800 disposition, so we don't need to mention it here. */
6801 if (!part_of_multiple
&& b
->enable_count
> 1)
6804 uiout
->text ("\tdisable after ");
6805 /* Tweak the wording to clarify that ignore and enable counts
6806 are distinct, and have additive effect. */
6807 if (b
->ignore_count
)
6808 uiout
->text ("additional ");
6810 uiout
->text ("next ");
6811 uiout
->field_signed ("enable", b
->enable_count
);
6812 uiout
->text (" hits\n");
6815 if (!part_of_multiple
&& is_tracepoint (b
))
6817 tracepoint
*tp
= gdb::checked_static_cast
<tracepoint
*> (b
);
6819 if (tp
->traceframe_usage
)
6821 uiout
->text ("\ttrace buffer usage ");
6822 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6823 uiout
->text (" bytes\n");
6827 l
= b
->commands
? b
->commands
.get () : NULL
;
6828 if (!part_of_multiple
&& l
)
6832 bool use_fixed_output
=
6833 (uiout
->test_flags (fix_breakpoint_script_output
)
6834 || fix_breakpoint_script_output_globally
);
6836 std::optional
<ui_out_emit_tuple
> tuple_emitter
;
6837 std::optional
<ui_out_emit_list
> list_emitter
;
6839 if (use_fixed_output
)
6840 list_emitter
.emplace (uiout
, "script");
6842 tuple_emitter
.emplace (uiout
, "script");
6844 print_command_lines (uiout
, l
, 4);
6847 if (is_tracepoint (b
))
6849 tracepoint
*t
= gdb::checked_static_cast
<tracepoint
*> (b
);
6851 if (!part_of_multiple
&& t
->pass_count
)
6853 annotate_field (10);
6854 uiout
->text ("\tpass count ");
6855 uiout
->field_signed ("pass", t
->pass_count
);
6856 uiout
->text (" \n");
6859 /* Don't display it when tracepoint or tracepoint location is
6861 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6863 annotate_field (11);
6865 if (uiout
->is_mi_like_p ())
6866 uiout
->field_string ("installed",
6867 loc
->inserted
? "y" : "n");
6873 uiout
->text ("\tnot ");
6874 uiout
->text ("installed on target\n");
6879 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6881 if (is_watchpoint (b
))
6883 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
6885 uiout
->field_string ("original-location", w
->exp_string
.get ());
6887 else if (b
->locspec
!= nullptr)
6889 const char *str
= b
->locspec
->to_string ();
6891 uiout
->field_string ("original-location", str
);
6898 /* See breakpoint.h. */
6900 bool fix_multi_location_breakpoint_output_globally
= false;
6903 print_one_breakpoint (breakpoint
*b
, const bp_location
**last_loc
, int allflag
)
6905 struct ui_out
*uiout
= current_uiout
;
6906 bool use_fixed_output
6907 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6908 || fix_multi_location_breakpoint_output_globally
);
6910 std::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (std::in_place
, uiout
,
6912 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6915 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6917 if (!use_fixed_output
)
6918 bkpt_tuple_emitter
.reset ();
6920 /* If this breakpoint has custom print function,
6921 it's already printed. Otherwise, print individual
6922 locations, if any. */
6923 if (!printed
|| allflag
)
6925 /* If breakpoint has a single location that is disabled, we
6926 print it as if it had several locations, since otherwise it's
6927 hard to represent "breakpoint enabled, location disabled"
6930 Note that while hardware watchpoints have several locations
6931 internally, that's not a property exposed to users.
6933 Likewise, while catchpoints may be implemented with
6934 breakpoints (e.g., catch throw), that's not a property
6935 exposed to users. We do however display the internal
6936 breakpoint locations with "maint info breakpoints". */
6937 if (!is_hardware_watchpoint (b
)
6938 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6939 || is_ada_exception_catchpoint (b
))
6941 || (b
->has_locations ()
6942 && (b
->has_multiple_locations ()
6943 || !b
->first_loc ().enabled
6944 || b
->first_loc ().disabled_by_cond
))))
6946 std::optional
<ui_out_emit_list
> locations_list
;
6948 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6949 MI record. For later versions, place breakpoint locations in a
6951 if (uiout
->is_mi_like_p () && use_fixed_output
)
6952 locations_list
.emplace (uiout
, "locations");
6955 for (bp_location
&loc
: b
->locations ())
6957 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6958 print_one_breakpoint_location (b
, &loc
, n
, last_loc
,
6967 breakpoint_address_bits (struct breakpoint
*b
)
6969 int print_address_bits
= 0;
6971 for (bp_location
&loc
: b
->locations ())
6973 if (!bl_address_is_meaningful (&loc
))
6976 int addr_bit
= gdbarch_addr_bit (loc
.gdbarch
);
6977 if (addr_bit
> print_address_bits
)
6978 print_address_bits
= addr_bit
;
6981 return print_address_bits
;
6984 /* See breakpoint.h. */
6987 print_breakpoint (breakpoint
*b
)
6989 const bp_location
*dummy_loc
= nullptr;
6990 print_one_breakpoint (b
, &dummy_loc
, 0);
6993 /* Return true if this breakpoint was set by the user, false if it is
6994 internal or momentary. */
6997 user_breakpoint_p (struct breakpoint
*b
)
6999 return b
->number
> 0;
7002 /* See breakpoint.h. */
7005 pending_breakpoint_p (struct breakpoint
*b
)
7007 return !b
->has_locations ();
7010 /* Print information on breakpoints (including watchpoints and tracepoints).
7012 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
7013 understood by number_or_range_parser. Only breakpoints included in this
7014 list are then printed.
7016 If SHOW_INTERNAL is true, print internal breakpoints.
7018 If FILTER is non-NULL, call it on each breakpoint and only include the
7019 ones for which it returns true.
7021 Return the total number of breakpoints listed. */
7024 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
7025 bool (*filter
) (const struct breakpoint
*))
7027 const bp_location
*last_loc
= nullptr;
7028 int nr_printable_breakpoints
;
7029 struct value_print_options opts
;
7030 int print_address_bits
= 0;
7031 int print_type_col_width
= 14;
7032 struct ui_out
*uiout
= current_uiout
;
7033 bool has_disabled_by_cond_location
= false;
7035 get_user_print_options (&opts
);
7037 /* Compute the number of rows in the table, as well as the size
7038 required for address fields. */
7039 nr_printable_breakpoints
= 0;
7040 for (breakpoint
&b
: all_breakpoints ())
7042 /* If we have a filter, only list the breakpoints it accepts. */
7043 if (filter
&& !filter (&b
))
7046 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
7047 accept. Skip the others. */
7048 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
7050 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
.number
)
7052 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
.number
))
7056 if (show_internal
|| user_breakpoint_p (&b
))
7058 int addr_bit
, type_len
;
7060 addr_bit
= breakpoint_address_bits (&b
);
7061 if (addr_bit
> print_address_bits
)
7062 print_address_bits
= addr_bit
;
7064 type_len
= strlen (bptype_string (b
.type
));
7065 if (type_len
> print_type_col_width
)
7066 print_type_col_width
= type_len
;
7068 nr_printable_breakpoints
++;
7073 ui_out_emit_table
table_emitter (uiout
,
7074 opts
.addressprint
? 6 : 5,
7075 nr_printable_breakpoints
,
7078 if (nr_printable_breakpoints
> 0)
7079 annotate_breakpoints_headers ();
7080 if (nr_printable_breakpoints
> 0)
7082 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
7083 if (nr_printable_breakpoints
> 0)
7085 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
7086 if (nr_printable_breakpoints
> 0)
7088 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
7089 if (nr_printable_breakpoints
> 0)
7091 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
7092 if (opts
.addressprint
)
7094 if (nr_printable_breakpoints
> 0)
7096 if (print_address_bits
<= 32)
7097 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
7099 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
7101 if (nr_printable_breakpoints
> 0)
7103 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
7104 uiout
->table_body ();
7105 if (nr_printable_breakpoints
> 0)
7106 annotate_breakpoints_table ();
7108 for (breakpoint
&b
: all_breakpoints ())
7111 /* If we have a filter, only list the breakpoints it accepts. */
7112 if (filter
&& !filter (&b
))
7115 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
7116 accept. Skip the others. */
7118 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
7120 if (show_internal
) /* maintenance info breakpoint */
7122 if (parse_and_eval_long (bp_num_list
) != b
.number
)
7125 else /* all others */
7127 if (!number_is_in_list (bp_num_list
, b
.number
))
7131 /* We only print out user settable breakpoints unless the
7132 show_internal is set. */
7133 if (show_internal
|| user_breakpoint_p (&b
))
7135 print_one_breakpoint (&b
, &last_loc
, show_internal
);
7136 for (bp_location
&loc
: b
.locations ())
7137 if (loc
.disabled_by_cond
)
7138 has_disabled_by_cond_location
= true;
7143 if (nr_printable_breakpoints
== 0)
7145 /* If there's a filter, let the caller decide how to report
7149 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
7150 uiout
->message ("No breakpoints, watchpoints, tracepoints, "
7151 "or catchpoints.\n");
7153 uiout
->message ("No breakpoint, watchpoint, tracepoint, "
7154 "or catchpoint matching '%s'.\n", bp_num_list
);
7159 if (last_loc
&& !server_command
)
7160 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
7162 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
7163 uiout
->message (_("(*): Breakpoint condition is invalid at this "
7167 /* FIXME? Should this be moved up so that it is only called when
7168 there have been breakpoints? */
7169 annotate_breakpoints_table_end ();
7171 return nr_printable_breakpoints
;
7174 /* Display the value of default-collect in a way that is generally
7175 compatible with the breakpoint list. */
7178 default_collect_info (void)
7180 struct ui_out
*uiout
= current_uiout
;
7182 /* If it has no value (which is frequently the case), say nothing; a
7183 message like "No default-collect." gets in user's face when it's
7185 if (default_collect
.empty ())
7188 /* The following phrase lines up nicely with per-tracepoint collect
7190 uiout
->text ("default collect ");
7191 uiout
->field_string ("default-collect", default_collect
);
7192 uiout
->text (" \n");
7196 info_breakpoints_command (const char *args
, int from_tty
)
7198 breakpoint_1 (args
, false, NULL
);
7200 default_collect_info ();
7204 info_watchpoints_command (const char *args
, int from_tty
)
7206 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
7207 struct ui_out
*uiout
= current_uiout
;
7209 if (num_printed
== 0)
7211 if (args
== NULL
|| *args
== '\0')
7212 uiout
->message ("No watchpoints.\n");
7214 uiout
->message ("No watchpoint matching '%s'.\n", args
);
7219 maintenance_info_breakpoints (const char *args
, int from_tty
)
7221 breakpoint_1 (args
, true, NULL
);
7223 default_collect_info ();
7227 breakpoint_has_pc (struct breakpoint
*b
,
7228 struct program_space
*pspace
,
7229 CORE_ADDR pc
, struct obj_section
*section
)
7231 for (bp_location
&bl
: b
->locations ())
7233 if (bl
.pspace
== pspace
7235 && (!overlay_debugging
|| bl
.section
== section
))
7241 /* See breakpoint.h. */
7244 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7245 struct program_space
*pspace
, CORE_ADDR pc
,
7246 struct obj_section
*section
, int thread
)
7250 for (breakpoint
&b
: all_breakpoints ())
7251 others
+= (user_breakpoint_p (&b
)
7252 && breakpoint_has_pc (&b
, pspace
, pc
, section
));
7257 gdb_printf (_("Note: breakpoint "));
7258 else /* if (others == ???) */
7259 gdb_printf (_("Note: breakpoints "));
7260 for (breakpoint
&b
: all_breakpoints ())
7261 if (user_breakpoint_p (&b
)
7262 && breakpoint_has_pc (&b
, pspace
, pc
, section
))
7265 gdb_printf ("%d", b
.number
);
7266 if (b
.thread
== -1 && thread
!= -1)
7267 gdb_printf (" (all threads)");
7268 else if (b
.thread
!= -1)
7270 struct thread_info
*thr
= find_thread_global_id (b
.thread
);
7271 gdb_printf (" (thread %s)", print_thread_id (thr
));
7273 else if (b
.task
!= -1)
7274 gdb_printf (" (task %d)", b
.task
);
7275 gdb_printf ("%s%s ",
7276 ((b
.enable_state
== bp_disabled
7277 || b
.enable_state
== bp_call_disabled
)
7281 : ((others
== 1) ? " and" : ""));
7283 current_uiout
->message (_("also set at pc %ps.\n"),
7284 styled_string (address_style
.style (),
7285 paddress (gdbarch
, pc
)));
7290 /* Return true iff it is meaningful to use the address member of LOC.
7291 For some breakpoint types, the locations' address members are
7292 irrelevant and it makes no sense to attempt to compare them to
7293 other addresses (or use them for any other purpose either).
7295 More specifically, software watchpoints and catchpoints that are
7296 not backed by breakpoints always have a zero valued location
7297 address and we don't want to mark breakpoints of any of these types
7298 to be a duplicate of an actual breakpoint location at address
7302 bl_address_is_meaningful (bp_location
*loc
)
7304 return loc
->loc_type
!= bp_loc_other
;
7307 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7308 true if LOC1 and LOC2 represent the same watchpoint location. */
7311 watchpoint_locations_match (const struct bp_location
*loc1
,
7312 const struct bp_location
*loc2
)
7314 watchpoint
*w1
= gdb::checked_static_cast
<watchpoint
*> (loc1
->owner
);
7315 watchpoint
*w2
= gdb::checked_static_cast
<watchpoint
*> (loc2
->owner
);
7317 /* Both of them must exist. */
7318 gdb_assert (w1
!= NULL
);
7319 gdb_assert (w2
!= NULL
);
7321 /* If the target can evaluate the condition expression in hardware,
7322 then we we need to insert both watchpoints even if they are at
7323 the same place. Otherwise the watchpoint will only trigger when
7324 the condition of whichever watchpoint was inserted evaluates to
7325 true, not giving a chance for GDB to check the condition of the
7326 other watchpoint. */
7328 && target_can_accel_watchpoint_condition (loc1
->address
,
7330 loc1
->watchpoint_type
,
7331 w1
->cond_exp
.get ()))
7333 && target_can_accel_watchpoint_condition (loc2
->address
,
7335 loc2
->watchpoint_type
,
7336 w2
->cond_exp
.get ())))
7339 /* Note that this checks the owner's type, not the location's. In
7340 case the target does not support read watchpoints, but does
7341 support access watchpoints, we'll have bp_read_watchpoint
7342 watchpoints with hw_access locations. Those should be considered
7343 duplicates of hw_read locations. The hw_read locations will
7344 become hw_access locations later. */
7345 return (loc1
->owner
->type
== loc2
->owner
->type
7346 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7347 && loc1
->address
== loc2
->address
7348 && loc1
->length
== loc2
->length
);
7351 /* See breakpoint.h. */
7354 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
7355 const address_space
*aspace2
, CORE_ADDR addr2
)
7357 return ((gdbarch_has_global_breakpoints (current_inferior ()->arch ())
7358 || aspace1
== aspace2
)
7362 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7363 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7364 matches ASPACE2. On targets that have global breakpoints, the address
7365 space doesn't really matter. */
7368 breakpoint_address_match_range (const address_space
*aspace1
,
7370 int len1
, const address_space
*aspace2
,
7373 return ((gdbarch_has_global_breakpoints (current_inferior ()->arch ())
7374 || aspace1
== aspace2
)
7375 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7378 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7379 a ranged breakpoint. In most targets, a match happens only if ASPACE
7380 matches the breakpoint's address space. On targets that have global
7381 breakpoints, the address space doesn't really matter. */
7384 breakpoint_location_address_match (struct bp_location
*bl
,
7385 const address_space
*aspace
,
7388 return (breakpoint_address_match (bl
->pspace
->aspace
.get (), bl
->address
,
7391 && breakpoint_address_match_range (bl
->pspace
->aspace
.get (),
7392 bl
->address
, bl
->length
,
7396 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7397 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7398 match happens only if ASPACE matches the breakpoint's address
7399 space. On targets that have global breakpoints, the address space
7400 doesn't really matter. */
7403 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7404 const address_space
*aspace
,
7405 CORE_ADDR addr
, int len
)
7407 if (gdbarch_has_global_breakpoints (current_inferior ()->arch ())
7408 || bl
->pspace
->aspace
.get () == aspace
)
7410 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7412 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7418 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7419 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7420 true, otherwise returns false. */
7423 tracepoint_locations_match (const struct bp_location
*loc1
,
7424 const struct bp_location
*loc2
)
7426 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7427 /* Since tracepoint locations are never duplicated with others', tracepoint
7428 locations at the same address of different tracepoints are regarded as
7429 different locations. */
7430 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7435 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7436 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7437 the same location. If SW_HW_BPS_MATCH is true, then software
7438 breakpoint locations and hardware breakpoint locations match,
7439 otherwise they don't. */
7442 breakpoint_locations_match (const struct bp_location
*loc1
,
7443 const struct bp_location
*loc2
,
7444 bool sw_hw_bps_match
)
7446 int hw_point1
, hw_point2
;
7448 /* Both of them must not be in moribund_locations. */
7449 gdb_assert (loc1
->owner
!= NULL
);
7450 gdb_assert (loc2
->owner
!= NULL
);
7452 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7453 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7455 if (hw_point1
!= hw_point2
)
7458 return watchpoint_locations_match (loc1
, loc2
);
7459 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7460 return tracepoint_locations_match (loc1
, loc2
);
7462 /* We compare bp_location.length in order to cover ranged
7463 breakpoints. Keep this in sync with
7464 bp_location_is_less_than. */
7465 return (breakpoint_address_match (loc1
->pspace
->aspace
.get (),
7467 loc2
->pspace
->aspace
.get (),
7469 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7470 && loc1
->length
== loc2
->length
);
7474 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7475 int bnum
, bool have_bnum
)
7477 /* The longest string possibly returned by hex_string_custom
7478 is 50 chars. These must be at least that big for safety. */
7482 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7483 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7485 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7486 bnum
, astr1
, astr2
);
7488 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7491 /* Adjust a breakpoint's address to account for architectural
7492 constraints on breakpoint placement. Return the adjusted address.
7493 Note: Very few targets require this kind of adjustment. For most
7494 targets, this function is simply the identity function. */
7497 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7498 CORE_ADDR bpaddr
, enum bptype bptype
,
7499 struct program_space
*pspace
)
7501 gdb_assert (pspace
!= nullptr);
7503 if (bptype
== bp_watchpoint
7504 || bptype
== bp_hardware_watchpoint
7505 || bptype
== bp_read_watchpoint
7506 || bptype
== bp_access_watchpoint
7507 || bptype
== bp_catchpoint
)
7509 /* Watchpoints and the various bp_catch_* eventpoints should not
7510 have their addresses modified. */
7513 else if (bptype
== bp_single_step
)
7515 /* Single-step breakpoints should not have their addresses
7516 modified. If there's any architectural constrain that
7517 applies to this address, then it should have already been
7518 taken into account when the breakpoint was created in the
7519 first place. If we didn't do this, stepping through e.g.,
7520 Thumb-2 IT blocks would break. */
7525 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7527 /* Some targets have architectural constraints on the placement
7528 of breakpoint instructions. Obtain the adjusted address. */
7529 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7531 /* Targets that implement this adjustment function will likely
7532 inspect either the symbol table, target memory at BPADDR, or
7533 even state registers, so ensure a suitable thread (and its
7534 associated program space) are currently selected. */
7535 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
7536 switch_to_program_space_and_thread (pspace
);
7538 = gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7542 = gdbarch_remove_non_address_bits_breakpoint (gdbarch
, adjusted_bpaddr
);
7544 /* An adjusted breakpoint address can significantly alter
7545 a user's expectations. Print a warning if an adjustment
7547 if (adjusted_bpaddr
!= bpaddr
)
7548 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, false);
7550 return adjusted_bpaddr
;
7555 bp_location_from_bp_type (bptype type
)
7560 case bp_single_step
:
7564 case bp_longjmp_resume
:
7565 case bp_longjmp_call_dummy
:
7567 case bp_exception_resume
:
7568 case bp_step_resume
:
7569 case bp_hp_step_resume
:
7570 case bp_watchpoint_scope
:
7572 case bp_std_terminate
:
7573 case bp_shlib_event
:
7574 case bp_thread_event
:
7575 case bp_overlay_event
:
7577 case bp_longjmp_master
:
7578 case bp_std_terminate_master
:
7579 case bp_exception_master
:
7580 case bp_gnu_ifunc_resolver
:
7581 case bp_gnu_ifunc_resolver_return
:
7583 return bp_loc_software_breakpoint
;
7585 case bp_hardware_breakpoint
:
7586 return bp_loc_hardware_breakpoint
;
7588 case bp_hardware_watchpoint
:
7589 case bp_read_watchpoint
:
7590 case bp_access_watchpoint
:
7591 return bp_loc_hardware_watchpoint
;
7594 return bp_loc_software_watchpoint
;
7597 case bp_fast_tracepoint
:
7598 case bp_static_tracepoint
:
7599 case bp_static_marker_tracepoint
:
7600 return bp_loc_tracepoint
;
7603 return bp_loc_other
;
7606 internal_error (_("unknown breakpoint type"));
7610 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7612 this->owner
= owner
;
7613 this->cond_bytecode
= NULL
;
7614 this->shlib_disabled
= 0;
7616 this->disabled_by_cond
= false;
7618 this->loc_type
= type
;
7620 if (this->loc_type
== bp_loc_software_breakpoint
7621 || this->loc_type
== bp_loc_hardware_breakpoint
)
7622 mark_breakpoint_location_modified (this);
7627 bp_location::bp_location (breakpoint
*owner
)
7628 : bp_location::bp_location (owner
,
7629 bp_location_from_bp_type (owner
->type
))
7633 /* See breakpoint.h. */
7636 bp_location::to_string () const
7639 ui_out_redirect_pop
redir (current_uiout
, &stb
);
7640 print_breakpoint_location (this->owner
, this);
7641 return stb
.release ();
7644 /* Decrement reference count. If the reference count reaches 0,
7645 destroy the bp_location. Sets *BLP to NULL. */
7648 decref_bp_location (struct bp_location
**blp
)
7650 bp_location_ref_policy::decref (*blp
);
7654 /* Add breakpoint B at the end of the global breakpoint chain. */
7657 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7659 /* Add this breakpoint to the end of the chain so that a list of
7660 breakpoints will come out in order of increasing numbers. */
7662 breakpoint_chain
.push_back (*b
.release ());
7664 return &breakpoint_chain
.back ();
7667 /* Initialize loc->function_name. */
7670 set_breakpoint_location_function (struct bp_location
*loc
)
7672 gdb_assert (loc
->owner
!= NULL
);
7674 if (loc
->owner
->type
== bp_breakpoint
7675 || loc
->owner
->type
== bp_hardware_breakpoint
7676 || is_tracepoint (loc
->owner
))
7678 const char *function_name
;
7680 if (loc
->msymbol
!= NULL
7681 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7682 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7684 struct breakpoint
*b
= loc
->owner
;
7686 function_name
= loc
->msymbol
->linkage_name ();
7688 if (b
->type
== bp_breakpoint
7689 && b
->has_single_location ()
7690 && b
->related_breakpoint
== b
)
7692 /* Create only the whole new breakpoint of this type but do not
7693 mess more complicated breakpoints with multiple locations. */
7694 b
->type
= bp_gnu_ifunc_resolver
;
7695 /* Remember the resolver's address for use by the return
7697 loc
->related_address
= loc
->address
;
7701 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7704 loc
->function_name
= make_unique_xstrdup (function_name
);
7708 /* Attempt to determine architecture of location identified by SAL. */
7710 get_sal_arch (struct symtab_and_line sal
)
7713 return sal
.section
->objfile
->arch ();
7715 return sal
.symtab
->compunit ()->objfile ()->arch ();
7720 /* Call this routine when stepping and nexting to enable a breakpoint
7721 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7722 initiated the operation. */
7725 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7727 int thread
= tp
->global_num
;
7729 /* To avoid having to rescan all objfile symbols at every step,
7730 we maintain a list of continually-inserted but always disabled
7731 longjmp "master" breakpoints. Here, we simply create momentary
7732 clones of those and enable them for the requested thread. */
7733 for (breakpoint
&b
: all_breakpoints_safe ())
7734 if (b
.pspace
== current_program_space
7735 && (b
.type
== bp_longjmp_master
7736 || b
.type
== bp_exception_master
))
7738 bptype type
= b
.type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7739 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7740 after their removal. */
7741 momentary_breakpoint_from_master (&b
, type
, 1, thread
);
7744 tp
->initiating_frame
= frame
;
7747 /* Delete all longjmp breakpoints from THREAD. */
7749 delete_longjmp_breakpoint (int thread
)
7751 for (breakpoint
&b
: all_breakpoints_safe ())
7752 if (b
.type
== bp_longjmp
|| b
.type
== bp_exception
)
7754 if (b
.thread
== thread
)
7756 gdb_assert (b
.inferior
== -1);
7757 delete_breakpoint (&b
);
7763 delete_longjmp_breakpoint_at_next_stop (int thread
)
7765 for (breakpoint
&b
: all_breakpoints_safe ())
7766 if (b
.type
== bp_longjmp
|| b
.type
== bp_exception
)
7768 if (b
.thread
== thread
)
7770 gdb_assert (b
.inferior
== -1);
7771 b
.disposition
= disp_del_at_next_stop
;
7776 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7777 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7778 pointer to any of them. Return NULL if this system cannot place longjmp
7782 set_longjmp_breakpoint_for_call_dummy (void)
7784 breakpoint
*retval
= nullptr;
7786 for (breakpoint
&b
: all_breakpoints ())
7787 if (b
.pspace
== current_program_space
&& b
.type
== bp_longjmp_master
)
7789 int thread
= inferior_thread ()->global_num
;
7791 = momentary_breakpoint_from_master (&b
, bp_longjmp_call_dummy
,
7794 /* Link NEW_B into the chain of RETVAL breakpoints. */
7796 gdb_assert (new_b
->related_breakpoint
== new_b
);
7799 new_b
->related_breakpoint
= retval
;
7800 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7801 retval
= retval
->related_breakpoint
;
7802 retval
->related_breakpoint
= new_b
;
7808 /* Verify all existing dummy frames and their associated breakpoints for
7809 TP. Remove those which can no longer be found in the current frame
7812 If the unwind fails then there is not sufficient information to discard
7813 dummy frames. In this case, elide the clean up and the dummy frames will
7814 be cleaned up next time this function is called from a location where
7815 unwinding is possible. */
7818 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7820 /* We would need to delete breakpoints other than the current one while
7821 iterating, so all_breakpoints_safe is not sufficient to make that safe.
7822 Save all breakpoints to delete in that set and delete them at the end. */
7823 std::unordered_set
<breakpoint
*> to_delete
;
7825 for (struct breakpoint
&b
: all_breakpoints ())
7827 if (b
.type
== bp_longjmp_call_dummy
&& b
.thread
== tp
->global_num
)
7829 gdb_assert (b
.inferior
== -1);
7830 struct breakpoint
*dummy_b
= b
.related_breakpoint
;
7832 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7833 chained off b->related_breakpoint. */
7834 while (dummy_b
!= &b
&& dummy_b
->type
!= bp_call_dummy
)
7835 dummy_b
= dummy_b
->related_breakpoint
;
7837 /* If there was no bp_call_dummy breakpoint then there's nothing
7838 more to do. Or, if the dummy frame associated with the
7839 bp_call_dummy is still on the stack then we need to leave this
7840 bp_call_dummy in place. */
7841 if (dummy_b
->type
!= bp_call_dummy
7842 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7845 /* We didn't find the dummy frame on the stack, this could be
7846 because we have longjmp'd to a stack frame that is previous to
7847 the dummy frame, or it could be because the stack unwind is
7848 broken at some point between the longjmp frame and the dummy
7851 Next we figure out why the stack unwind stopped. If it looks
7852 like the unwind is complete then we assume the dummy frame has
7853 been jumped over, however, if the unwind stopped for an
7854 unexpected reason then we assume the stack unwind is currently
7855 broken, and that we will (eventually) return to the dummy
7858 It might be tempting to consider using frame_id_inner here, but
7859 that is not safe. There is no guarantee that the stack frames
7860 we are looking at here are even on the same stack as the
7861 original dummy frame, hence frame_id_inner can't be used. See
7862 the comments on frame_id_inner for more details. */
7863 bool unwind_finished_unexpectedly
= false;
7864 for (frame_info_ptr fi
= get_current_frame (); fi
!= nullptr; )
7866 frame_info_ptr prev
= get_prev_frame (fi
);
7867 if (prev
== nullptr)
7869 /* FI is the last stack frame. Why did this frame not
7871 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7872 if (stop_reason
!= UNWIND_NO_REASON
7873 && stop_reason
!= UNWIND_OUTERMOST
)
7874 unwind_finished_unexpectedly
= true;
7878 if (unwind_finished_unexpectedly
)
7881 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7883 for (breakpoint
*related_breakpoint
= b
.related_breakpoint
;
7884 related_breakpoint
!= &b
;
7885 related_breakpoint
= related_breakpoint
->related_breakpoint
)
7886 to_delete
.insert (b
.related_breakpoint
);
7888 to_delete
.insert (&b
);
7892 for (breakpoint
*b
: to_delete
)
7893 delete_breakpoint (b
);
7897 enable_overlay_breakpoints (void)
7899 for (breakpoint
&b
: all_breakpoints ())
7900 if (b
.type
== bp_overlay_event
)
7902 b
.enable_state
= bp_enabled
;
7903 update_global_location_list (UGLL_MAY_INSERT
);
7904 overlay_events_enabled
= 1;
7909 disable_overlay_breakpoints (void)
7911 for (breakpoint
&b
: all_breakpoints ())
7912 if (b
.type
== bp_overlay_event
)
7914 b
.enable_state
= bp_disabled
;
7915 update_global_location_list (UGLL_DONT_INSERT
);
7916 overlay_events_enabled
= 0;
7920 /* Set an active std::terminate breakpoint for each std::terminate
7921 master breakpoint. */
7923 set_std_terminate_breakpoint (void)
7925 for (breakpoint
&b
: all_breakpoints_safe ())
7926 if (b
.pspace
== current_program_space
7927 && b
.type
== bp_std_terminate_master
)
7929 momentary_breakpoint_from_master (&b
, bp_std_terminate
, 1,
7930 inferior_thread ()->global_num
);
7934 /* Delete all the std::terminate breakpoints. */
7936 delete_std_terminate_breakpoint (void)
7938 for (breakpoint
&b
: all_breakpoints_safe ())
7939 if (b
.type
== bp_std_terminate
)
7940 delete_breakpoint (&b
);
7944 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7946 struct breakpoint
*b
;
7948 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7950 b
->enable_state
= bp_enabled
;
7951 /* locspec has to be used or breakpoint_re_set will delete me. */
7952 b
->locspec
= new_address_location_spec (b
->first_loc ().address
, NULL
, 0);
7954 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7959 struct lang_and_radix
7965 /* Create a breakpoint for JIT code registration and unregistration. */
7968 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7970 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7973 /* Remove JIT code registration and unregistration breakpoint(s). */
7976 remove_jit_event_breakpoints (void)
7978 for (breakpoint
&b
: all_breakpoints_safe ())
7979 if (b
.type
== bp_jit_event
7980 && b
.first_loc ().pspace
== current_program_space
)
7981 delete_breakpoint (&b
);
7985 remove_solib_event_breakpoints (void)
7987 for (breakpoint
&b
: all_breakpoints_safe ())
7988 if (b
.type
== bp_shlib_event
7989 && b
.first_loc ().pspace
== current_program_space
)
7990 delete_breakpoint (&b
);
7993 /* See breakpoint.h. */
7996 remove_solib_event_breakpoints_at_next_stop (void)
7998 for (breakpoint
&b
: all_breakpoints_safe ())
7999 if (b
.type
== bp_shlib_event
8000 && b
.first_loc ().pspace
== current_program_space
)
8001 b
.disposition
= disp_del_at_next_stop
;
8004 /* Helper for create_solib_event_breakpoint /
8005 create_and_insert_solib_event_breakpoint. Allows specifying which
8006 INSERT_MODE to pass through to update_global_location_list. */
8008 static struct breakpoint
*
8009 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
8010 enum ugll_insert_mode insert_mode
)
8012 struct breakpoint
*b
;
8014 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
8015 update_global_location_list_nothrow (insert_mode
);
8020 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8022 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
8025 /* See breakpoint.h. */
8028 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8030 struct breakpoint
*b
;
8032 /* Explicitly tell update_global_location_list to insert
8034 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
8035 if (!b
->first_loc ().inserted
)
8037 delete_breakpoint (b
);
8043 /* See breakpoint.h. */
8046 disable_breakpoints_in_shlibs (program_space
*pspace
)
8048 for (bp_location
*loc
: all_bp_locations ())
8050 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
8051 struct breakpoint
*b
= loc
->owner
;
8053 /* We apply the check to all breakpoints, including disabled for
8054 those with loc->duplicate set. This is so that when breakpoint
8055 becomes enabled, or the duplicate is removed, gdb will try to
8056 insert all breakpoints. If we don't set shlib_disabled here,
8057 we'll try to insert those breakpoints and fail. */
8058 if (((b
->type
== bp_breakpoint
)
8059 || (b
->type
== bp_jit_event
)
8060 || (b
->type
== bp_hardware_breakpoint
)
8061 || (is_tracepoint (b
)))
8062 && loc
->pspace
== pspace
8063 && !loc
->shlib_disabled
8064 && solib_name_from_address (loc
->pspace
, loc
->address
)
8067 loc
->shlib_disabled
= 1;
8072 /* Disable any breakpoints and tracepoints that are in SOLIB upon
8073 notification of unloaded_shlib. Only apply to enabled breakpoints,
8074 disabled ones can just stay disabled. */
8077 disable_breakpoints_in_unloaded_shlib (program_space
*pspace
, const solib
&solib
)
8079 bool disabled_shlib_breaks
= false;
8081 for (bp_location
*loc
: all_bp_locations ())
8083 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
8084 struct breakpoint
*b
= loc
->owner
;
8086 if (pspace
== loc
->pspace
8087 && !loc
->shlib_disabled
8088 && (((b
->type
== bp_breakpoint
8089 || b
->type
== bp_jit_event
8090 || b
->type
== bp_hardware_breakpoint
)
8091 && (loc
->loc_type
== bp_loc_hardware_breakpoint
8092 || loc
->loc_type
== bp_loc_software_breakpoint
))
8093 || is_tracepoint (b
))
8094 && solib_contains_address_p (solib
, loc
->address
))
8096 loc
->shlib_disabled
= 1;
8097 /* At this point, we cannot rely on remove_breakpoint
8098 succeeding so we must mark the breakpoint as not inserted
8099 to prevent future errors occurring in remove_breakpoints. */
8102 /* This may cause duplicate notifications for the same breakpoint. */
8103 notify_breakpoint_modified (b
);
8105 if (!disabled_shlib_breaks
)
8107 target_terminal::ours_for_output ();
8108 warning (_("Temporarily disabling breakpoints "
8109 "for unloaded shared library \"%s\""),
8110 solib
.so_name
.c_str ());
8112 disabled_shlib_breaks
= true;
8117 /* Disable any breakpoints and tracepoints in OBJFILE upon
8118 notification of free_objfile. Only apply to enabled breakpoints,
8119 disabled ones can just stay disabled. */
8122 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
8124 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8125 managed by the user with add-symbol-file/remove-symbol-file.
8126 Similarly to how breakpoints in shared libraries are handled in
8127 response to "nosharedlibrary", mark breakpoints in such modules
8128 shlib_disabled so they end up uninserted on the next global
8129 location list update. Shared libraries not loaded by the user
8130 aren't handled here -- they're already handled in
8131 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8132 solib_unloaded observer. We skip objfiles that are not
8133 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8135 if ((objfile
->flags
& OBJF_SHARED
) == 0
8136 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
8139 for (breakpoint
&b
: all_breakpoints ())
8141 bool bp_modified
= false;
8143 if (!is_breakpoint (&b
) && !is_tracepoint (&b
))
8146 for (bp_location
&loc
: b
.locations ())
8148 CORE_ADDR loc_addr
= loc
.address
;
8150 if (loc
.loc_type
!= bp_loc_hardware_breakpoint
8151 && loc
.loc_type
!= bp_loc_software_breakpoint
)
8154 if (loc
.shlib_disabled
!= 0)
8157 if (objfile
->pspace () != loc
.pspace
)
8160 if (is_addr_in_objfile (loc_addr
, objfile
))
8162 loc
.shlib_disabled
= 1;
8163 /* At this point, we don't know whether the object was
8164 unmapped from the inferior or not, so leave the
8165 inserted flag alone. We'll handle failure to
8166 uninsert quietly, in case the object was indeed
8169 mark_breakpoint_location_modified (&loc
);
8176 notify_breakpoint_modified (&b
);
8180 /* See breakpoint.h. */
8182 breakpoint::breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
8183 bool temp
, const char *cond_string_
)
8185 disposition (temp
? disp_del
: disp_donttouch
),
8187 language (current_language
->la_language
),
8188 input_radix (::input_radix
),
8189 cond_string (cond_string_
!= nullptr
8190 ? make_unique_xstrdup (cond_string_
)
8192 related_breakpoint (this)
8196 /* See breakpoint.h. */
8198 catchpoint::catchpoint (struct gdbarch
*gdbarch
, bool temp
,
8199 const char *cond_string
)
8200 : breakpoint (gdbarch
, bp_catchpoint
, temp
, cond_string
)
8202 add_dummy_location (this, current_program_space
);
8204 pspace
= current_program_space
;
8207 /* See breakpoint.h. */
8210 catchpoint::re_set (program_space
*filter_pspace
)
8212 /* All catchpoints are associated with a specific program_space. */
8213 gdb_assert (pspace
!= nullptr);
8215 /* If only a single program space changed, and it's not the program space
8216 for which this catchpoint applies, then there's nothing to do. */
8217 if (filter_pspace
!= nullptr && filter_pspace
!= pspace
)
8220 /* Catchpoints have a single dummy location. */
8221 gdb_assert (locations ().size () == 1);
8222 bp_location
&bl
= m_locations
.front ();
8224 if (cond_string
== nullptr)
8226 /* It shouldn't be possible to have a parsed condition expression
8227 cached on this location if the catchpoint doesn't have a condition
8229 gdb_assert (bl
.cond
== nullptr);
8231 /* Nothing to re-compute, and the catchpoint cannot change. */
8235 bool previous_disabled_by_cond
= bl
.disabled_by_cond
;
8237 /* Start by marking the location disabled and discarding the previously
8238 computed condition expression. Now if we get an exception, even if
8239 it's a quit exception, we'll leave the location disabled and there
8240 will be no (possibly invalid) expression cached. */
8241 bl
.disabled_by_cond
= true;
8244 const char *s
= cond_string
.get ();
8247 switch_to_program_space_and_thread (pspace
);
8249 bl
.cond
= parse_exp_1 (&s
, bl
.address
, block_for_pc (bl
.address
),
8251 bl
.disabled_by_cond
= false;
8253 catch (const gdb_exception_error
&e
)
8255 /* Any exception thrown must be from either the parse_exp_1 or
8256 earlier in the try block. As such the following two asserts
8258 gdb_assert (bl
.disabled_by_cond
);
8259 gdb_assert (bl
.cond
== nullptr);
8262 if (previous_disabled_by_cond
!= bl
.disabled_by_cond
)
8263 notify_breakpoint_modified (this);
8266 /* Notify interpreters and observers that breakpoint B was created. */
8269 notify_breakpoint_created (breakpoint
*b
)
8271 interps_notify_breakpoint_created (b
);
8272 gdb::observers::breakpoint_created
.notify (b
);
8276 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8278 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8279 set_breakpoint_number (internal
, b
);
8280 if (is_tracepoint (b
))
8281 set_tracepoint_count (breakpoint_count
);
8285 notify_breakpoint_created (b
);
8288 update_global_location_list (UGLL_MAY_INSERT
);
8294 hw_breakpoint_used_count (void)
8298 for (breakpoint
&b
: all_breakpoints ())
8299 if (b
.type
== bp_hardware_breakpoint
&& breakpoint_enabled (&b
))
8300 for (bp_location
&bl
: b
.locations ())
8302 /* Special types of hardware breakpoints may use more than
8304 i
+= b
.resources_needed (&bl
);
8310 /* Returns the resources B would use if it were a hardware
8314 hw_watchpoint_use_count (struct breakpoint
*b
)
8318 if (!breakpoint_enabled (b
))
8321 for (bp_location
&bl
: b
->locations ())
8323 /* Special types of hardware watchpoints may use more than
8325 i
+= b
->resources_needed (&bl
);
8331 /* Returns the sum the used resources of all hardware watchpoints of
8332 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8333 the sum of the used resources of all hardware watchpoints of other
8334 types _not_ TYPE. */
8337 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8338 enum bptype type
, int *other_type_used
)
8342 *other_type_used
= 0;
8343 for (breakpoint
&b
: all_breakpoints ())
8347 if (!breakpoint_enabled (&b
))
8351 i
+= hw_watchpoint_use_count (&b
);
8352 else if (is_hardware_watchpoint (&b
))
8353 *other_type_used
= 1;
8360 disable_watchpoints_before_interactive_call_start (void)
8362 for (breakpoint
&b
: all_breakpoints ())
8363 if (is_watchpoint (&b
) && breakpoint_enabled (&b
))
8365 b
.enable_state
= bp_call_disabled
;
8366 update_global_location_list (UGLL_DONT_INSERT
);
8371 enable_watchpoints_after_interactive_call_stop (void)
8373 for (breakpoint
&b
: all_breakpoints ())
8374 if (is_watchpoint (&b
) && b
.enable_state
== bp_call_disabled
)
8376 b
.enable_state
= bp_enabled
;
8377 update_global_location_list (UGLL_MAY_INSERT
);
8382 disable_breakpoints_before_startup (void)
8384 current_program_space
->executing_startup
= 1;
8385 update_global_location_list (UGLL_DONT_INSERT
);
8389 enable_breakpoints_after_startup (void)
8391 current_program_space
->executing_startup
= 0;
8392 breakpoint_re_set ();
8395 /* Allocate a new momentary breakpoint. */
8397 template<typename
... Arg
>
8398 static momentary_breakpoint
*
8399 new_momentary_breakpoint (struct gdbarch
*gdbarch
, enum bptype type
,
8402 if (type
== bp_longjmp
|| type
== bp_exception
)
8403 return new longjmp_breakpoint (gdbarch
, type
,
8404 std::forward
<Arg
> (args
)...);
8406 return new momentary_breakpoint (gdbarch
, type
,
8407 std::forward
<Arg
> (args
)...);
8410 /* Set a momentary breakpoint of type TYPE at address specified by
8411 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8415 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8416 struct frame_id frame_id
, enum bptype type
)
8418 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8420 gdb_assert (!frame_id_artificial_p (frame_id
));
8422 std::unique_ptr
<momentary_breakpoint
> b
8423 (new_momentary_breakpoint (gdbarch
, type
, sal
.pspace
, frame_id
,
8424 inferior_thread ()->global_num
));
8426 b
->add_location (sal
);
8428 breakpoint_up
bp (add_to_breakpoint_chain (std::move (b
)));
8430 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8435 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8436 The new breakpoint will have type TYPE, use OPS as its
8437 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8439 static struct breakpoint
*
8440 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8445 std::unique_ptr
<breakpoint
> copy
8446 (new_momentary_breakpoint (orig
->gdbarch
, type
, orig
->pspace
,
8447 orig
->frame_id
, thread
));
8448 const bp_location
&orig_loc
= orig
->first_loc ();
8449 bp_location
*copy_loc
= copy
->allocate_location ();
8450 copy
->add_location (*copy_loc
);
8451 set_breakpoint_location_function (copy_loc
);
8453 copy_loc
->gdbarch
= orig_loc
.gdbarch
;
8454 copy_loc
->requested_address
= orig_loc
.requested_address
;
8455 copy_loc
->address
= orig_loc
.address
;
8456 copy_loc
->section
= orig_loc
.section
;
8457 copy_loc
->pspace
= orig_loc
.pspace
;
8458 copy_loc
->probe
= orig_loc
.probe
;
8459 copy_loc
->line_number
= orig_loc
.line_number
;
8460 copy_loc
->symtab
= orig_loc
.symtab
;
8461 copy_loc
->enabled
= loc_enabled
;
8463 breakpoint
*b
= add_to_breakpoint_chain (std::move (copy
));
8464 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8468 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8472 clone_momentary_breakpoint (struct breakpoint
*orig
)
8474 /* If there's nothing to clone, then return nothing. */
8478 return momentary_breakpoint_from_master (orig
, orig
->type
, 0,
8483 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8486 struct symtab_and_line sal
;
8488 sal
= find_pc_line (pc
, 0);
8490 sal
.section
= find_pc_overlay (pc
);
8491 sal
.explicit_pc
= 1;
8493 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8497 /* Tell the user we have just set a breakpoint B. */
8500 mention (const breakpoint
*b
)
8502 b
->print_mention ();
8503 current_uiout
->text ("\n");
8507 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8509 /* Handle "set breakpoint auto-hw on".
8511 If the explicitly specified breakpoint type is not hardware
8512 breakpoint, check the memory map to see whether the breakpoint
8513 address is in read-only memory.
8515 - location type is not hardware breakpoint, memory is read-only.
8516 We change the type of the location to hardware breakpoint.
8518 - location type is hardware breakpoint, memory is read-write. This
8519 means we've previously made the location hardware one, but then the
8520 memory map changed, so we undo.
8524 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8526 if (automatic_hardware_breakpoints
8527 && bl
->owner
->type
!= bp_hardware_breakpoint
8528 && (bl
->loc_type
== bp_loc_software_breakpoint
8529 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8531 /* When breakpoints are removed, remove_breakpoints will use
8532 location types we've just set here, the only possible problem
8533 is that memory map has changed during running program, but
8534 it's not going to work anyway with current gdb. */
8535 mem_region
*mr
= lookup_mem_region (bl
->address
);
8539 enum bp_loc_type new_type
;
8541 if (mr
->attrib
.mode
!= MEM_RW
)
8542 new_type
= bp_loc_hardware_breakpoint
;
8544 new_type
= bp_loc_software_breakpoint
;
8546 if (new_type
!= bl
->loc_type
)
8548 static bool said
= false;
8550 bl
->loc_type
= new_type
;
8553 gdb_printf (_("Note: automatically using "
8554 "hardware breakpoints for "
8555 "read-only addresses.\n"));
8564 code_breakpoint::add_location (const symtab_and_line
&sal
)
8566 CORE_ADDR adjusted_address
;
8567 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8569 if (loc_gdbarch
== NULL
)
8570 loc_gdbarch
= gdbarch
;
8572 /* Adjust the breakpoint's address prior to allocating a location.
8573 Once we call allocate_location(), that mostly uninitialized
8574 location will be placed on the location chain. Adjustment of the
8575 breakpoint may cause target_read_memory() to be called and we do
8576 not want its scan of the location chain to find a breakpoint and
8577 location that's only been partially initialized. */
8578 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8582 /* Sort the locations by their ADDRESS. */
8583 bp_location
*new_loc
= this->allocate_location ();
8585 new_loc
->requested_address
= sal
.pc
;
8586 new_loc
->address
= adjusted_address
;
8587 new_loc
->pspace
= sal
.pspace
;
8588 new_loc
->probe
.prob
= sal
.prob
;
8589 new_loc
->probe
.objfile
= sal
.objfile
;
8590 gdb_assert (new_loc
->pspace
!= NULL
);
8591 new_loc
->section
= sal
.section
;
8592 new_loc
->gdbarch
= loc_gdbarch
;
8593 new_loc
->line_number
= sal
.line
;
8594 new_loc
->symtab
= sal
.symtab
;
8595 new_loc
->symbol
= sal
.symbol
;
8596 new_loc
->msymbol
= sal
.msymbol
;
8597 new_loc
->objfile
= sal
.objfile
;
8599 breakpoint::add_location (*new_loc
);
8601 set_breakpoint_location_function (new_loc
);
8603 /* While by definition, permanent breakpoints are already present in the
8604 code, we don't mark the location as inserted. Normally one would expect
8605 that GDB could rely on that breakpoint instruction to stop the program,
8606 thus removing the need to insert its own breakpoint, except that executing
8607 the breakpoint instruction can kill the target instead of reporting a
8608 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8609 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8610 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8611 breakpoint be inserted normally results in QEMU knowing about the GDB
8612 breakpoint, and thus trap before the breakpoint instruction is executed.
8613 (If GDB later needs to continue execution past the permanent breakpoint,
8614 it manually increments the PC, thus avoiding executing the breakpoint
8616 if (bp_loc_is_permanent (new_loc
))
8617 new_loc
->permanent
= 1;
8623 /* Return true if LOC is pointing to a permanent breakpoint,
8624 return false otherwise. */
8627 bp_loc_is_permanent (struct bp_location
*loc
)
8629 gdb_assert (loc
!= NULL
);
8631 /* If we have a non-breakpoint-backed catchpoint or a software
8632 watchpoint, just return 0. We should not attempt to read from
8633 the addresses the locations of these breakpoint types point to.
8634 gdbarch_program_breakpoint_here_p, below, will attempt to read
8636 if (!bl_address_is_meaningful (loc
))
8639 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8640 switch_to_program_space_and_thread (loc
->pspace
);
8641 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8644 /* Build a command list for the dprintf corresponding to the current
8645 settings of the dprintf style options. */
8648 update_dprintf_command_list (struct breakpoint
*b
)
8650 gdb_assert (b
->type
== bp_dprintf
);
8651 gdb_assert (b
->extra_string
!= nullptr);
8653 const char *dprintf_args
= b
->extra_string
.get ();
8654 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8656 /* Trying to create a dprintf breakpoint without a format and args
8657 string should be detected at creation time. */
8658 gdb_assert (dprintf_args
!= nullptr);
8660 dprintf_args
= skip_spaces (dprintf_args
);
8662 /* Allow a comma, as it may have terminated a location, but don't
8664 if (*dprintf_args
== ',')
8666 dprintf_args
= skip_spaces (dprintf_args
);
8668 if (*dprintf_args
!= '"')
8669 error (_("Bad format string, missing '\"'."));
8671 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8672 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8673 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8675 if (dprintf_function
.empty ())
8676 error (_("No function supplied for dprintf call"));
8678 if (!dprintf_channel
.empty ())
8679 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8680 dprintf_function
.c_str (),
8681 dprintf_channel
.c_str (),
8684 printf_line
= xstrprintf ("call (void) %s (%s)",
8685 dprintf_function
.c_str (),
8688 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8690 if (target_can_run_breakpoint_commands ())
8691 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8694 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8695 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8699 internal_error (_("Invalid dprintf style."));
8701 gdb_assert (printf_line
!= NULL
);
8703 /* Manufacture a printf sequence. */
8704 struct command_line
*printf_cmd_line
8705 = new struct command_line (simple_control
, printf_line
.release ());
8706 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8707 command_lines_deleter ()));
8710 /* Update all dprintf commands, making their command lists reflect
8711 current style settings. */
8714 update_dprintf_commands (const char *args
, int from_tty
,
8715 struct cmd_list_element
*c
)
8717 for (breakpoint
&b
: all_breakpoints ())
8718 if (b
.type
== bp_dprintf
)
8719 update_dprintf_command_list (&b
);
8722 code_breakpoint::code_breakpoint (struct gdbarch
*gdbarch_
,
8724 gdb::array_view
<const symtab_and_line
> sals
,
8725 location_spec_up
&&locspec_
,
8726 gdb::unique_xmalloc_ptr
<char> filter_
,
8727 gdb::unique_xmalloc_ptr
<char> cond_string_
,
8728 gdb::unique_xmalloc_ptr
<char> extra_string_
,
8729 enum bpdisp disposition_
,
8730 int thread_
, int task_
, int inferior_
,
8733 int enabled_
, unsigned flags
,
8734 int display_canonical_
)
8735 : breakpoint (gdbarch_
, type_
)
8739 if (type
== bp_hardware_breakpoint
)
8741 int target_resources_ok
;
8743 i
= hw_breakpoint_used_count ();
8744 target_resources_ok
=
8745 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8747 if (target_resources_ok
== 0)
8748 error (_("No hardware breakpoint support in the target."));
8749 else if (target_resources_ok
< 0)
8750 error (_("Hardware breakpoints used exceeds limit."));
8753 gdb_assert (!sals
.empty ());
8755 /* At most one of thread, task, or inferior can be set on any breakpoint. */
8756 gdb_assert (((thread
== -1 ? 0 : 1)
8757 + (task
== -1 ? 0 : 1)
8758 + (inferior
== -1 ? 0 : 1)) <= 1);
8762 inferior
= inferior_
;
8764 cond_string
= std::move (cond_string_
);
8765 extra_string
= std::move (extra_string_
);
8766 ignore_count
= ignore_count_
;
8767 enable_state
= enabled_
? bp_enabled
: bp_disabled
;
8768 disposition
= disposition_
;
8770 if (type
== bp_static_tracepoint
8771 || type
== bp_static_marker_tracepoint
)
8773 auto *t
= gdb::checked_static_cast
<tracepoint
*> (this);
8774 struct static_tracepoint_marker marker
;
8776 if (strace_marker_p (this))
8778 /* We already know the marker exists, otherwise, we wouldn't
8779 see a sal for it. */
8780 const char *p
= &locspec_
->to_string ()[3];
8783 p
= skip_spaces (p
);
8785 endp
= skip_to_space (p
);
8787 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8789 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8790 t
->static_trace_marker_id
.c_str ());
8792 else if (target_static_tracepoint_marker_at (sals
[0].pc
, &marker
))
8794 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8796 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8797 t
->static_trace_marker_id
.c_str ());
8800 warning (_("Couldn't determine the static tracepoint marker to probe"));
8803 for (const auto &sal
: sals
)
8807 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8808 if (loc_gdbarch
== nullptr)
8809 loc_gdbarch
= gdbarch
;
8811 describe_other_breakpoints (loc_gdbarch
,
8812 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8815 bp_location
*new_loc
= add_location (sal
);
8816 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8817 new_loc
->inserted
= 1;
8819 /* Do not set breakpoint locations conditions yet. As locations
8820 are inserted, they get sorted based on their addresses. Let
8821 the list stabilize to have reliable location numbers. */
8824 /* Dynamic printf requires and uses additional arguments on the
8825 command line, otherwise it's an error. */
8826 if (type
== bp_dprintf
)
8827 update_dprintf_command_list (this);
8829 gdb_assert (extra_string
== nullptr);
8831 /* The order of the locations is now stable. Set the location
8832 condition using the location's number. */
8834 for (bp_location
&bl
: locations ())
8836 if (cond_string
!= nullptr)
8837 set_breakpoint_location_condition (cond_string
.get (), &bl
,
8843 display_canonical
= display_canonical_
;
8844 if (locspec_
!= nullptr)
8845 locspec
= std::move (locspec_
);
8847 locspec
= new_address_location_spec (this->first_loc ().address
, NULL
, 0);
8848 filter
= std::move (filter_
);
8852 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8853 gdb::array_view
<const symtab_and_line
> sals
,
8854 location_spec_up
&&locspec
,
8855 gdb::unique_xmalloc_ptr
<char> filter
,
8856 gdb::unique_xmalloc_ptr
<char> cond_string
,
8857 gdb::unique_xmalloc_ptr
<char> extra_string
,
8858 enum bptype type
, enum bpdisp disposition
,
8859 int thread
, int task
, int inferior
, int ignore_count
,
8861 int enabled
, int internal
, unsigned flags
,
8862 int display_canonical
)
8864 std::unique_ptr
<code_breakpoint
> b
8865 = new_breakpoint_from_type (gdbarch
,
8868 std::move (locspec
),
8870 std::move (cond_string
),
8871 std::move (extra_string
),
8873 thread
, task
, inferior
, ignore_count
,
8878 install_breakpoint (internal
, std::move (b
), 0);
8881 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8882 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8883 value. COND_STRING, if not NULL, specified the condition to be
8884 used for all breakpoints. Essentially the only case where
8885 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8886 function. In that case, it's still not possible to specify
8887 separate conditions for different overloaded functions, so
8888 we take just a single condition string.
8890 NOTE: If the function succeeds, the caller is expected to cleanup
8891 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8892 array contents). If the function fails (error() is called), the
8893 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8894 COND and SALS arrays and each of those arrays contents. */
8897 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8898 struct linespec_result
*canonical
,
8899 gdb::unique_xmalloc_ptr
<char> cond_string
,
8900 gdb::unique_xmalloc_ptr
<char> extra_string
,
8901 enum bptype type
, enum bpdisp disposition
,
8902 int thread
, int task
, int inferior
,
8905 int enabled
, int internal
, unsigned flags
)
8907 if (canonical
->pre_expanded
)
8908 gdb_assert (canonical
->lsals
.size () == 1);
8910 for (const auto &lsal
: canonical
->lsals
)
8912 /* Note that 'location' can be NULL in the case of a plain
8913 'break', without arguments. */
8914 location_spec_up locspec
8915 = (canonical
->locspec
!= nullptr
8916 ? canonical
->locspec
->clone ()
8918 gdb::unique_xmalloc_ptr
<char> filter_string
8919 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8921 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8922 std::move (locspec
),
8923 std::move (filter_string
),
8924 std::move (cond_string
),
8925 std::move (extra_string
),
8927 thread
, task
, inferior
, ignore_count
,
8928 from_tty
, enabled
, internal
, flags
,
8929 canonical
->special_display
);
8933 /* Parse LOCSPEC which is assumed to be a SAL specification possibly
8934 followed by conditionals. On return, SALS contains an array of SAL
8935 addresses found. LOCSPEC points to the end of the SAL (for
8938 The array and the line spec strings are allocated on the heap, it is
8939 the caller's responsibility to free them. */
8942 parse_breakpoint_sals (location_spec
*locspec
,
8943 struct linespec_result
*canonical
,
8944 struct program_space
*search_pspace
)
8946 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8949 = as_linespec_location_spec (locspec
)->spec_string
.get ();
8953 /* The last displayed codepoint, if it's valid, is our default
8954 breakpoint address. */
8955 if (last_displayed_sal_is_valid ())
8957 /* Set sal's pspace, pc, symtab, and line to the values
8958 corresponding to the last call to print_frame_info.
8959 Be sure to reinitialize LINE with NOTCURRENT == 0
8960 as the breakpoint line number is inappropriate otherwise.
8961 find_pc_line would adjust PC, re-set it back. */
8962 symtab_and_line sal
= get_last_displayed_sal ();
8963 CORE_ADDR pc
= sal
.pc
;
8965 sal
= find_pc_line (pc
, 0);
8967 /* "break" without arguments is equivalent to "break *PC"
8968 where PC is the last displayed codepoint's address. So
8969 make sure to set sal.explicit_pc to prevent GDB from
8970 trying to expand the list of sals to include all other
8971 instances with the same symtab and line. */
8973 sal
.explicit_pc
= 1;
8975 struct linespec_sals lsal
;
8977 lsal
.canonical
= NULL
;
8979 canonical
->lsals
.push_back (std::move (lsal
));
8983 error (_("No default breakpoint address now."));
8987 /* Force almost all breakpoints to be in terms of the
8988 current_source_symtab (which is decode_line_1's default).
8989 This should produce the results we want almost all of the
8990 time while leaving default_breakpoint_* alone.
8992 ObjC: However, don't match an Objective-C method name which
8993 may have a '+' or '-' succeeded by a '['. */
8994 symtab_and_line cursal
8995 = get_current_source_symtab_and_line (current_program_space
);
8996 if (last_displayed_sal_is_valid ())
8998 const char *spec
= NULL
;
9000 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
9001 spec
= as_linespec_location_spec (locspec
)->spec_string
.get ();
9005 && strchr ("+-", spec
[0]) != NULL
9008 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
9009 get_last_displayed_symtab (),
9010 get_last_displayed_line (),
9011 canonical
, NULL
, NULL
);
9016 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
9017 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9021 /* Convert each SAL into a real PC. Verify that the PC can be
9022 inserted as a breakpoint. If it can't throw an error. */
9025 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9027 for (auto &sal
: sals
)
9028 resolve_sal_pc (&sal
);
9031 /* Fast tracepoints may have restrictions on valid locations. For
9032 instance, a fast tracepoint using a jump instead of a trap will
9033 likely have to overwrite more bytes than a trap would, and so can
9034 only be placed where the instruction is longer than the jump, or a
9035 multi-instruction sequence does not have a jump into the middle of
9039 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9040 gdb::array_view
<const symtab_and_line
> sals
)
9042 for (const auto &sal
: sals
)
9044 struct gdbarch
*sarch
;
9046 sarch
= get_sal_arch (sal
);
9047 /* We fall back to GDBARCH if there is no architecture
9048 associated with SAL. */
9052 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9053 error (_("May not have a fast tracepoint at %s%s"),
9054 paddress (sarch
, sal
.pc
), msg
.c_str ());
9058 /* Decode a static tracepoint marker spec. */
9060 static std::vector
<symtab_and_line
>
9061 decode_static_tracepoint_spec (const char **arg_p
)
9063 const char *p
= &(*arg_p
)[3];
9066 p
= skip_spaces (p
);
9068 endp
= skip_to_space (p
);
9070 std::string
marker_str (p
, endp
- p
);
9072 std::vector
<static_tracepoint_marker
> markers
9073 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9074 if (markers
.empty ())
9075 error (_("No known static tracepoint marker named %s"),
9076 marker_str
.c_str ());
9078 std::vector
<symtab_and_line
> sals
;
9079 sals
.reserve (markers
.size ());
9081 for (const static_tracepoint_marker
&marker
: markers
)
9083 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9084 sal
.pc
= marker
.address
;
9085 sals
.push_back (sal
);
9092 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9093 according to IS_TRACEPOINT. */
9095 static const struct breakpoint_ops
*
9096 breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type
,
9101 if (locspec_type
== PROBE_LOCATION_SPEC
)
9102 return &tracepoint_probe_breakpoint_ops
;
9104 return &code_breakpoint_ops
;
9108 if (locspec_type
== PROBE_LOCATION_SPEC
)
9109 return &bkpt_probe_breakpoint_ops
;
9111 return &code_breakpoint_ops
;
9115 /* Return the program space to use as a filter when searching for locations
9116 of a breakpoint specific to THREAD or INFERIOR. If THREAD and INFERIOR
9117 are both -1, meaning all threads/inferiors, then this function returns
9118 nullptr, indicating no program space filtering should be performed.
9119 Otherwise, this function returns the program space for the inferior that
9120 contains THREAD (when THREAD is not -1), or the program space for
9121 INFERIOR (when INFERIOR is not -1). */
9123 static struct program_space
*
9124 find_program_space_for_breakpoint (int thread
, int inferior
)
9128 gdb_assert (inferior
== -1);
9130 struct thread_info
*thr
= find_thread_global_id (thread
);
9131 gdb_assert (thr
!= nullptr);
9132 gdb_assert (thr
->inf
!= nullptr);
9133 return thr
->inf
->pspace
;
9135 else if (inferior
!= -1)
9137 gdb_assert (thread
== -1);
9139 struct inferior
*inf
= find_inferior_id (inferior
);
9140 gdb_assert (inf
!= nullptr);
9148 /* See breakpoint.h. */
9150 const struct breakpoint_ops
*
9151 breakpoint_ops_for_location_spec (const location_spec
*locspec
,
9154 if (locspec
!= nullptr)
9155 return (breakpoint_ops_for_location_spec_type
9156 (locspec
->type (), is_tracepoint
));
9157 return &code_breakpoint_ops
;
9160 /* See breakpoint.h. */
9163 create_breakpoint (struct gdbarch
*gdbarch
,
9164 location_spec
*locspec
,
9165 const char *cond_string
,
9166 int thread
, int inferior
,
9167 const char *extra_string
,
9168 bool force_condition
, int parse_extra
,
9169 int tempflag
, enum bptype type_wanted
,
9171 enum auto_boolean pending_break_support
,
9172 const struct breakpoint_ops
*ops
,
9173 int from_tty
, int enabled
, int internal
,
9176 struct linespec_result canonical
;
9177 bool pending
= false;
9179 int prev_bkpt_count
= breakpoint_count
;
9181 gdb_assert (thread
== -1 || thread
> 0);
9182 gdb_assert (inferior
== -1 || inferior
> 0);
9183 gdb_assert (thread
== -1 || inferior
== -1);
9185 /* If PARSE_EXTRA is true then the thread and inferior details will be
9186 parsed from the EXTRA_STRING, the THREAD and INFERIOR arguments
9188 gdb_assert (!parse_extra
|| thread
== -1);
9189 gdb_assert (!parse_extra
|| inferior
== -1);
9191 gdb_assert (ops
!= NULL
);
9193 /* If extra_string isn't useful, set it to NULL. */
9194 if (extra_string
!= NULL
&& *extra_string
== '\0')
9195 extra_string
= NULL
;
9197 /* A bp_dprintf must always have an accompanying EXTRA_STRING containing
9198 the dprintf format and arguments -- PARSE_EXTRA should always be false
9201 For all other breakpoint types, EXTRA_STRING should be nullptr unless
9202 PARSE_EXTRA is true. */
9203 gdb_assert ((type_wanted
== bp_dprintf
)
9204 ? (extra_string
!= nullptr && !parse_extra
)
9205 : (extra_string
== nullptr || parse_extra
));
9207 /* Will hold either copies of the similarly named function argument, or
9208 will hold a modified version of the function argument, depending on
9209 the value of PARSE_EXTRA. */
9210 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9211 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9215 /* Parse EXTRA_STRING splitting the parts out. */
9216 create_breakpoint_parse_arg_string (extra_string
, &cond_string_copy
,
9217 &thread
, &inferior
, &task
,
9221 /* We could check that EXTRA_STRING_COPY is empty at this point -- it
9222 should be, as we only get here for things that are not bp_dprintf,
9223 however, we prefer to give the location spec parser a chance to
9224 run first, this means the user will get errors about invalid
9225 location spec instead of an error about garbage at the end of the
9228 We still do the EXTRA_STRING_COPY is empty check, just later in
9231 gdb_assert (thread
== -1 || thread
> 0);
9232 gdb_assert (task
== -1 || task
> 0);
9233 gdb_assert (inferior
== -1 || inferior
> 0);
9237 if (cond_string
!= nullptr)
9238 cond_string_copy
.reset (xstrdup (cond_string
));
9239 if (extra_string
!= nullptr)
9240 extra_string_copy
.reset (xstrdup (extra_string
));
9243 /* Clear these. Updated values are now held in the *_copy locals. */
9244 cond_string
= nullptr;
9245 extra_string
= nullptr;
9249 struct program_space
*search_pspace
9250 = find_program_space_for_breakpoint (thread
, inferior
);
9251 ops
->create_sals_from_location_spec (locspec
, &canonical
,
9254 catch (const gdb_exception_error
&e
)
9256 /* If caller is interested in rc value from parse, set
9258 if (e
.error
== NOT_FOUND_ERROR
)
9260 /* If pending breakpoint support is turned off, throw
9263 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9266 exception_print (gdb_stderr
, e
);
9268 /* If pending breakpoint support is auto query and the user
9269 selects no, then simply return the error code. */
9270 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9271 && !nquery (_("Make %s pending on future shared library load? "),
9272 bptype_string (type_wanted
)))
9275 /* At this point, either the user was queried about setting
9276 a pending breakpoint and selected yes, or pending
9277 breakpoint behavior is on and thus a pending breakpoint
9278 is defaulted on behalf of the user. */
9285 /* Only bp_dprintf breakpoints should have anything in EXTRA_STRING_COPY
9286 by this point. For all other breakpoints this indicates an error. We
9287 could place this check earlier in the function, but we prefer to see
9288 errors from the location spec parser before we see this error message. */
9289 if (type_wanted
!= bp_dprintf
&& extra_string_copy
.get () != nullptr)
9290 error (_("Garbage '%s' at end of command"), extra_string_copy
.get ());
9292 if (!pending
&& canonical
.lsals
.empty ())
9295 /* Resolve all line numbers to PC's and verify that the addresses
9296 are ok for the target. */
9299 for (auto &lsal
: canonical
.lsals
)
9300 breakpoint_sals_to_pc (lsal
.sals
);
9303 /* Fast tracepoints may have additional restrictions on location. */
9304 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9306 for (const auto &lsal
: canonical
.lsals
)
9307 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9310 /* Verify that condition can be parsed, before setting any
9311 breakpoints. Allocate a separate condition expression for each
9315 /* Check the validity of the condition. We should error out if the
9316 condition is invalid at all of the locations and if it is not
9317 forced. In the PARSE_EXTRA case above, this check is done when
9318 parsing the EXTRA_STRING. */
9319 if (cond_string_copy
.get () != nullptr && !force_condition
)
9321 int num_failures
= 0;
9322 const linespec_sals
&lsal
= canonical
.lsals
[0];
9323 for (const auto &sal
: lsal
.sals
)
9325 const char *cond
= cond_string_copy
.get ();
9328 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9329 /* One success is sufficient to keep going. */
9332 catch (const gdb_exception_error
&)
9335 /* If this is the last sal, error out. */
9336 if (num_failures
== lsal
.sals
.size ())
9342 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9343 std::move (cond_string_copy
),
9344 std::move (extra_string_copy
),
9346 tempflag
? disp_del
: disp_donttouch
,
9347 thread
, task
, inferior
, ignore_count
,
9348 from_tty
, enabled
, internal
, flags
);
9352 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
,
9354 b
->locspec
= locspec
->clone ();
9356 /* Create a private copy of the condition string. */
9357 b
->cond_string
= std::move (cond_string_copy
);
9361 b
->inferior
= inferior
;
9363 /* Create a private copy of any extra string. */
9364 b
->extra_string
= std::move (extra_string_copy
);
9366 b
->ignore_count
= ignore_count
;
9367 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9368 b
->condition_not_parsed
= 1;
9369 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9371 if (b
->type
== bp_dprintf
)
9372 update_dprintf_command_list (b
.get ());
9374 install_breakpoint (internal
, std::move (b
), 0);
9377 if (canonical
.lsals
.size () > 1)
9379 warning (_("Multiple breakpoints were set.\nUse the "
9380 "\"delete\" command to delete unwanted breakpoints."));
9381 prev_breakpoint_count
= prev_bkpt_count
;
9384 update_global_location_list (UGLL_MAY_INSERT
);
9389 /* Set a breakpoint.
9390 ARG is a string describing breakpoint address,
9391 condition, and thread.
9392 FLAG specifies if a breakpoint is hardware on,
9393 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9397 break_command_1 (const char *arg
, int flag
, int from_tty
)
9399 int tempflag
= flag
& BP_TEMPFLAG
;
9400 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9401 ? bp_hardware_breakpoint
9404 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9405 const struct breakpoint_ops
*ops
9406 = breakpoint_ops_for_location_spec (locspec
.get (),
9407 false /* is_tracepoint */);
9409 create_breakpoint (get_current_arch (),
9412 -1 /* thread */, -1 /* inferior */,
9413 arg
, false, 1 /* parse arg */,
9414 tempflag
, type_wanted
,
9415 0 /* Ignore count */,
9416 pending_break_support
,
9424 /* Helper function for break_command_1 and disassemble_command. */
9427 resolve_sal_pc (struct symtab_and_line
*sal
)
9431 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9433 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9434 error (_("No line %d in file \"%s\"."),
9435 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9438 /* If this SAL corresponds to a breakpoint inserted using a line
9439 number, then skip the function prologue if necessary. */
9440 if (sal
->explicit_line
)
9441 skip_prologue_sal (sal
);
9444 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9446 const struct blockvector
*bv
;
9447 const struct block
*b
;
9450 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9451 sal
->symtab
->compunit ());
9454 sym
= b
->linkage_function ();
9457 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9460 /* It really is worthwhile to have the section, so we'll
9461 just have to look harder. This case can be executed
9462 if we have line numbers but no functions (as can
9463 happen in assembly source). */
9465 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9466 switch_to_program_space_and_thread (sal
->pspace
);
9468 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9470 sal
->section
= msym
.obj_section ();
9477 break_command (const char *arg
, int from_tty
)
9479 break_command_1 (arg
, 0, from_tty
);
9483 tbreak_command (const char *arg
, int from_tty
)
9485 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9489 hbreak_command (const char *arg
, int from_tty
)
9491 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9495 thbreak_command (const char *arg
, int from_tty
)
9497 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9500 /* The dynamic printf command is mostly like a regular breakpoint, but
9501 with a prewired command list consisting of a single output command,
9502 built from extra arguments supplied on the dprintf command
9506 dprintf_command (const char *arg
, int from_tty
)
9508 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9510 /* If non-NULL, ARG should have been advanced past the location;
9511 the next character must be ','. */
9512 if (arg
== nullptr || arg
[0] != ',' || arg
[1] == '\0')
9513 error (_("Format string required"));
9516 /* Skip the comma. */
9520 create_breakpoint (get_current_arch (),
9523 arg
, false, 0 /* parse arg */,
9525 0 /* Ignore count */,
9526 pending_break_support
,
9527 &code_breakpoint_ops
,
9535 agent_printf_command (const char *arg
, int from_tty
)
9537 error (_("May only run agent-printf on the target"));
9540 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9543 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9544 const address_space
*aspace
,
9546 const target_waitstatus
&ws
)
9548 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9549 || ws
.sig () != GDB_SIGNAL_TRAP
)
9552 return breakpoint_address_match_range (bl
->pspace
->aspace
.get (),
9553 bl
->address
, bl
->length
, aspace
,
9557 /* Implement the "resources_needed" method for ranged breakpoints. */
9560 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9562 return target_ranged_break_num_registers ();
9565 /* Implement the "print_it" method for ranged breakpoints. */
9567 enum print_stop_action
9568 ranged_breakpoint::print_it (const bpstat
*bs
) const
9570 struct ui_out
*uiout
= current_uiout
;
9572 gdb_assert (type
== bp_hardware_breakpoint
);
9574 /* Ranged breakpoints have only one location. */
9575 gdb_assert (this->has_single_location ());
9577 annotate_breakpoint (number
);
9579 maybe_print_thread_hit_breakpoint (uiout
);
9581 if (disposition
== disp_del
)
9582 uiout
->text ("Temporary ranged breakpoint ");
9584 uiout
->text ("Ranged breakpoint ");
9585 if (uiout
->is_mi_like_p ())
9587 uiout
->field_string ("reason",
9588 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9589 uiout
->field_string ("disp", bpdisp_text (disposition
));
9591 print_num_locno (bs
, uiout
);
9594 return PRINT_SRC_AND_LOC
;
9597 /* Implement the "print_one" method for ranged breakpoints. */
9600 ranged_breakpoint::print_one (const bp_location
**last_loc
) const
9602 struct value_print_options opts
;
9603 struct ui_out
*uiout
= current_uiout
;
9605 /* Ranged breakpoints have only one location. */
9606 gdb_assert (this->has_single_location ());
9608 get_user_print_options (&opts
);
9610 if (opts
.addressprint
)
9611 /* We don't print the address range here, it will be printed later
9612 by ranged_breakpoint::print_one_detail. */
9613 uiout
->field_skip ("addr");
9615 print_breakpoint_location (this, &this->first_loc ());
9616 *last_loc
= &this->first_loc ();
9621 /* Implement the "print_one_detail" method for ranged breakpoints. */
9624 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9626 CORE_ADDR address_start
, address_end
;
9627 const bp_location
&bl
= this->first_loc ();
9630 address_start
= bl
.address
;
9631 address_end
= address_start
+ bl
.length
- 1;
9633 uiout
->text ("\taddress range: ");
9634 stb
.printf ("[%s, %s]",
9635 print_core_address (bl
.gdbarch
, address_start
),
9636 print_core_address (bl
.gdbarch
, address_end
));
9637 uiout
->field_stream ("addr", stb
);
9641 /* Implement the "print_mention" method for ranged breakpoints. */
9644 ranged_breakpoint::print_mention () const
9646 const bp_location
&bl
= this->first_loc ();
9647 struct ui_out
*uiout
= current_uiout
;
9649 gdb_assert (type
== bp_hardware_breakpoint
);
9651 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9652 number
, paddress (bl
.gdbarch
, bl
.address
),
9653 paddress (bl
.gdbarch
, bl
.address
+ bl
.length
- 1));
9656 /* Implement the "print_recreate" method for ranged breakpoints. */
9659 ranged_breakpoint::print_recreate (struct ui_file
*fp
) const
9661 gdb_printf (fp
, "break-range %s, %s",
9662 locspec
->to_string (),
9663 locspec_range_end
->to_string ());
9664 print_recreate_thread (fp
);
9667 /* Find the address where the end of the breakpoint range should be
9668 placed, given the SAL of the end of the range. This is so that if
9669 the user provides a line number, the end of the range is set to the
9670 last instruction of the given line. */
9673 find_breakpoint_range_end (struct symtab_and_line sal
)
9677 /* If the user provided a PC value, use it. Otherwise,
9678 find the address of the end of the given location. */
9679 if (sal
.explicit_pc
)
9686 ret
= find_line_pc_range (sal
, &start
, &end
);
9688 error (_("Could not find location of the end of the range."));
9690 /* find_line_pc_range returns the start of the next line. */
9697 /* Implement the "break-range" CLI command. */
9700 break_range_command (const char *arg
, int from_tty
)
9702 const char *arg_start
;
9703 struct linespec_result canonical_start
, canonical_end
;
9704 int bp_count
, can_use_bp
, length
;
9707 /* We don't support software ranged breakpoints. */
9708 if (target_ranged_break_num_registers () < 0)
9709 error (_("This target does not support hardware ranged breakpoints."));
9711 bp_count
= hw_breakpoint_used_count ();
9712 bp_count
+= target_ranged_break_num_registers ();
9713 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9716 error (_("Hardware breakpoints used exceeds limit."));
9718 arg
= skip_spaces (arg
);
9719 if (arg
== NULL
|| arg
[0] == '\0')
9720 error(_("No address range specified."));
9723 location_spec_up start_locspec
9724 = string_to_location_spec (&arg
, current_language
);
9725 parse_breakpoint_sals (start_locspec
.get (), &canonical_start
, nullptr);
9728 error (_("Too few arguments."));
9729 else if (canonical_start
.lsals
.empty ())
9730 error (_("Could not find location of the beginning of the range."));
9732 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9734 if (canonical_start
.lsals
.size () > 1
9735 || lsal_start
.sals
.size () != 1)
9736 error (_("Cannot create a ranged breakpoint with multiple locations."));
9738 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9739 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9741 arg
++; /* Skip the comma. */
9742 arg
= skip_spaces (arg
);
9744 /* Parse the end location specification. */
9748 /* We call decode_line_full directly here instead of using
9749 parse_breakpoint_sals because we need to specify the start
9750 location spec's symtab and line as the default symtab and line
9751 for the end of the range. This makes it possible to have ranges
9752 like "foo.c:27, +14", where +14 means 14 lines from the start
9754 location_spec_up end_locspec
9755 = string_to_location_spec (&arg
, current_language
);
9756 decode_line_full (end_locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9757 sal_start
.symtab
, sal_start
.line
,
9758 &canonical_end
, NULL
, NULL
);
9760 if (canonical_end
.lsals
.empty ())
9761 error (_("Could not find location of the end of the range."));
9763 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9764 if (canonical_end
.lsals
.size () > 1
9765 || lsal_end
.sals
.size () != 1)
9766 error (_("Cannot create a ranged breakpoint with multiple locations."));
9768 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9770 end
= find_breakpoint_range_end (sal_end
);
9771 if (sal_start
.pc
> end
)
9772 error (_("Invalid address range, end precedes start."));
9774 length
= end
- sal_start
.pc
+ 1;
9776 /* Length overflowed. */
9777 error (_("Address range too large."));
9778 else if (length
== 1)
9780 /* This range is simple enough to be handled by
9781 the `hbreak' command. */
9782 hbreak_command (&addr_string_start
[0], 1);
9787 /* Now set up the breakpoint and install it. */
9789 std::unique_ptr
<breakpoint
> br
9790 (new ranged_breakpoint (get_current_arch (),
9792 std::move (start_locspec
),
9793 std::move (end_locspec
)));
9795 install_breakpoint (false, std::move (br
), true);
9798 /* See breakpoint.h. */
9800 watchpoint::~watchpoint ()
9802 /* Make sure to unlink the destroyed watchpoint from the related
9805 breakpoint
*bpt
= this;
9806 while (bpt
->related_breakpoint
!= this)
9807 bpt
= bpt
->related_breakpoint
;
9809 bpt
->related_breakpoint
= this->related_breakpoint
;
9812 /* Return non-zero if EXP is verified as constant. Returned zero
9813 means EXP is variable. Also the constant detection may fail for
9814 some constant expressions and in such case still falsely return
9818 watchpoint_exp_is_const (const struct expression
*exp
)
9820 return exp
->op
->constant_p ();
9823 /* Implement the "re_set" method for watchpoints. */
9826 watchpoint::re_set (struct program_space
*pspace
)
9828 /* Watchpoint can be either on expression using entirely global
9829 variables, or it can be on local variables.
9831 Watchpoints of the first kind are never auto-deleted, and even
9832 persist across program restarts. Since they can use variables
9833 from shared libraries, we need to reparse expression as libraries
9834 are loaded and unloaded.
9836 Watchpoints on local variables can also change meaning as result
9837 of solib event. For example, if a watchpoint uses both a local
9838 and a global variables in expression, it's a local watchpoint,
9839 but unloading of a shared library will make the expression
9840 invalid. This is not a very common use case, but we still
9841 re-evaluate expression, to avoid surprises to the user.
9843 Note that for local watchpoints, we re-evaluate it only if
9844 watchpoints frame id is still valid. If it's not, it means the
9845 watchpoint is out of scope and will be deleted soon. In fact,
9846 I'm not sure we'll ever be called in this case.
9848 If a local watchpoint's frame id is still valid, then
9849 exp_valid_block is likewise valid, and we can safely use it.
9851 Don't do anything about disabled watchpoints, since they will be
9852 reevaluated again when enabled. */
9853 update_watchpoint (this, true /* reparse */);
9856 /* Implement the "insert" method for hardware watchpoints. */
9859 watchpoint::insert_location (struct bp_location
*bl
)
9861 int length
= exact
? 1 : bl
->length
;
9863 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9867 /* Implement the "remove" method for hardware watchpoints. */
9870 watchpoint::remove_location (struct bp_location
*bl
,
9871 enum remove_bp_reason reason
)
9873 int length
= exact
? 1 : bl
->length
;
9875 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9880 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9881 const address_space
*aspace
, CORE_ADDR bp_addr
,
9882 const target_waitstatus
&ws
)
9884 struct breakpoint
*b
= bl
->owner
;
9886 /* Continuable hardware watchpoints are treated as non-existent if the
9887 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9888 some data address). Otherwise gdb won't stop on a break instruction
9889 in the code (not from a breakpoint) when a hardware watchpoint has
9890 been defined. Also skip watchpoints which we know did not trigger
9891 (did not match the data address). */
9892 if (is_hardware_watchpoint (b
)
9893 && watchpoint_triggered
== watch_triggered_no
)
9900 watchpoint::check_status (bpstat
*bs
)
9902 bpstat_check_watchpoint (bs
);
9905 /* Implement the "resources_needed" method for hardware
9909 watchpoint::resources_needed (const struct bp_location
*bl
)
9911 int length
= exact
? 1 : bl
->length
;
9913 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9916 /* Implement the "works_in_software_mode" method for hardware
9920 watchpoint::works_in_software_mode () const
9922 /* Read and access watchpoints only work with hardware support. */
9923 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9926 enum print_stop_action
9927 watchpoint::print_it (const bpstat
*bs
) const
9929 enum print_stop_action result
;
9930 struct ui_out
*uiout
= current_uiout
;
9932 gdb_assert (bs
->bp_location_at
!= NULL
);
9934 annotate_watchpoint (this->number
);
9935 maybe_print_thread_hit_breakpoint (uiout
);
9939 std::optional
<ui_out_emit_tuple
> tuple_emitter
;
9943 case bp_hardware_watchpoint
:
9944 if (uiout
->is_mi_like_p ())
9946 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9948 tuple_emitter
.emplace (uiout
, "value");
9949 uiout
->text ("\nOld value = ");
9950 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9951 uiout
->field_stream ("old", stb
);
9952 uiout
->text ("\nNew value = ");
9953 watchpoint_value_print (val
.get (), &stb
);
9954 uiout
->field_stream ("new", stb
);
9956 /* More than one watchpoint may have been triggered. */
9957 result
= PRINT_UNKNOWN
;
9960 case bp_read_watchpoint
:
9961 if (uiout
->is_mi_like_p ())
9963 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9965 tuple_emitter
.emplace (uiout
, "value");
9966 uiout
->text ("\nValue = ");
9967 watchpoint_value_print (val
.get (), &stb
);
9968 uiout
->field_stream ("value", stb
);
9970 result
= PRINT_UNKNOWN
;
9973 case bp_access_watchpoint
:
9974 if (bs
->old_val
!= NULL
)
9976 if (uiout
->is_mi_like_p ())
9979 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9981 tuple_emitter
.emplace (uiout
, "value");
9982 uiout
->text ("\nOld value = ");
9983 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9984 uiout
->field_stream ("old", stb
);
9985 uiout
->text ("\nNew value = ");
9990 if (uiout
->is_mi_like_p ())
9993 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9994 tuple_emitter
.emplace (uiout
, "value");
9995 uiout
->text ("\nValue = ");
9997 watchpoint_value_print (val
.get (), &stb
);
9998 uiout
->field_stream ("new", stb
);
10000 result
= PRINT_UNKNOWN
;
10003 result
= PRINT_UNKNOWN
;
10009 /* Implement the "print_mention" method for hardware watchpoints. */
10012 watchpoint::print_mention () const
10014 struct ui_out
*uiout
= current_uiout
;
10015 const char *tuple_name
;
10019 case bp_watchpoint
:
10020 uiout
->text ("Watchpoint ");
10021 tuple_name
= "wpt";
10023 case bp_hardware_watchpoint
:
10024 uiout
->text ("Hardware watchpoint ");
10025 tuple_name
= "wpt";
10027 case bp_read_watchpoint
:
10028 uiout
->text ("Hardware read watchpoint ");
10029 tuple_name
= "hw-rwpt";
10031 case bp_access_watchpoint
:
10032 uiout
->text ("Hardware access (read/write) watchpoint ");
10033 tuple_name
= "hw-awpt";
10036 internal_error (_("Invalid hardware watchpoint type."));
10039 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10040 uiout
->field_signed ("number", number
);
10041 uiout
->text (": ");
10042 uiout
->field_string ("exp", exp_string
.get ());
10045 /* Implement the "print_recreate" method for watchpoints. */
10048 watchpoint::print_recreate (struct ui_file
*fp
) const
10052 case bp_watchpoint
:
10053 case bp_hardware_watchpoint
:
10054 gdb_printf (fp
, "watch");
10056 case bp_read_watchpoint
:
10057 gdb_printf (fp
, "rwatch");
10059 case bp_access_watchpoint
:
10060 gdb_printf (fp
, "awatch");
10063 internal_error (_("Invalid watchpoint type."));
10066 gdb_printf (fp
, " %s", exp_string
.get ());
10067 print_recreate_thread (fp
);
10070 /* Implement the "explains_signal" method for watchpoints. */
10073 watchpoint::explains_signal (enum gdb_signal sig
)
10075 /* A software watchpoint cannot cause a signal other than
10076 GDB_SIGNAL_TRAP. */
10077 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10083 struct masked_watchpoint
: public watchpoint
10085 using watchpoint::watchpoint
;
10087 int insert_location (struct bp_location
*) override
;
10088 int remove_location (struct bp_location
*,
10089 enum remove_bp_reason reason
) override
;
10090 int resources_needed (const struct bp_location
*) override
;
10091 bool works_in_software_mode () const override
;
10092 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
10093 void print_one_detail (struct ui_out
*) const override
;
10094 void print_mention () const override
;
10095 void print_recreate (struct ui_file
*fp
) const override
;
10098 /* Implement the "insert" method for masked hardware watchpoints. */
10101 masked_watchpoint::insert_location (struct bp_location
*bl
)
10103 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
10104 bl
->watchpoint_type
);
10107 /* Implement the "remove" method for masked hardware watchpoints. */
10110 masked_watchpoint::remove_location (struct bp_location
*bl
,
10111 enum remove_bp_reason reason
)
10113 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
10114 bl
->watchpoint_type
);
10117 /* Implement the "resources_needed" method for masked hardware
10121 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
10123 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
10126 /* Implement the "works_in_software_mode" method for masked hardware
10130 masked_watchpoint::works_in_software_mode () const
10135 /* Implement the "print_it" method for masked hardware
10138 enum print_stop_action
10139 masked_watchpoint::print_it (const bpstat
*bs
) const
10141 struct ui_out
*uiout
= current_uiout
;
10143 /* Masked watchpoints have only one location. */
10144 gdb_assert (this->has_single_location ());
10146 annotate_watchpoint (this->number
);
10147 maybe_print_thread_hit_breakpoint (uiout
);
10149 switch (this->type
)
10151 case bp_hardware_watchpoint
:
10152 if (uiout
->is_mi_like_p ())
10153 uiout
->field_string
10154 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10157 case bp_read_watchpoint
:
10158 if (uiout
->is_mi_like_p ())
10159 uiout
->field_string
10160 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10163 case bp_access_watchpoint
:
10164 if (uiout
->is_mi_like_p ())
10165 uiout
->field_string
10167 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10170 internal_error (_("Invalid hardware watchpoint type."));
10174 uiout
->text (_("\n\
10175 Check the underlying instruction at PC for the memory\n\
10176 address and value which triggered this watchpoint.\n"));
10177 uiout
->text ("\n");
10179 /* More than one watchpoint may have been triggered. */
10180 return PRINT_UNKNOWN
;
10183 /* Implement the "print_one_detail" method for masked hardware
10187 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
10189 /* Masked watchpoints have only one location. */
10190 gdb_assert (this->has_single_location ());
10192 uiout
->text ("\tmask ");
10193 uiout
->field_core_addr ("mask", this->first_loc ().gdbarch
, hw_wp_mask
);
10194 uiout
->text ("\n");
10197 /* Implement the "print_mention" method for masked hardware
10201 masked_watchpoint::print_mention () const
10203 struct ui_out
*uiout
= current_uiout
;
10204 const char *tuple_name
;
10208 case bp_hardware_watchpoint
:
10209 uiout
->text ("Masked hardware watchpoint ");
10210 tuple_name
= "wpt";
10212 case bp_read_watchpoint
:
10213 uiout
->text ("Masked hardware read watchpoint ");
10214 tuple_name
= "hw-rwpt";
10216 case bp_access_watchpoint
:
10217 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10218 tuple_name
= "hw-awpt";
10221 internal_error (_("Invalid hardware watchpoint type."));
10224 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10225 uiout
->field_signed ("number", number
);
10226 uiout
->text (": ");
10227 uiout
->field_string ("exp", exp_string
.get ());
10230 /* Implement the "print_recreate" method for masked hardware
10234 masked_watchpoint::print_recreate (struct ui_file
*fp
) const
10238 case bp_hardware_watchpoint
:
10239 gdb_printf (fp
, "watch");
10241 case bp_read_watchpoint
:
10242 gdb_printf (fp
, "rwatch");
10244 case bp_access_watchpoint
:
10245 gdb_printf (fp
, "awatch");
10248 internal_error (_("Invalid hardware watchpoint type."));
10251 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
10252 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
10253 print_recreate_thread (fp
);
10256 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10259 is_masked_watchpoint (const struct breakpoint
*b
)
10261 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
10264 /* accessflag: hw_write: watch write,
10265 hw_read: watch read,
10266 hw_access: watch access (read or write) */
10268 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10269 bool just_location
, bool internal
)
10271 struct breakpoint
*scope_breakpoint
= NULL
;
10272 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10273 struct value
*result
;
10274 int saved_bitpos
= 0, saved_bitsize
= 0;
10275 const char *exp_start
= NULL
;
10276 const char *exp_end
= NULL
;
10277 const char *tok
, *end_tok
;
10279 const char *cond_start
= NULL
;
10280 const char *cond_end
= NULL
;
10281 enum bptype bp_type
;
10284 /* Flag to indicate whether we are going to use masks for
10285 the hardware watchpoint. */
10286 bool use_mask
= false;
10287 CORE_ADDR mask
= 0;
10290 /* Make sure that we actually have parameters to parse. */
10291 if (arg
!= NULL
&& arg
[0] != '\0')
10293 const char *value_start
;
10295 exp_end
= arg
+ strlen (arg
);
10297 /* Look for "parameter value" pairs at the end
10298 of the arguments string. */
10299 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10301 /* Skip whitespace at the end of the argument list. */
10302 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10305 /* Find the beginning of the last token.
10306 This is the value of the parameter. */
10307 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10309 value_start
= tok
+ 1;
10311 /* Skip whitespace. */
10312 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10317 /* Find the beginning of the second to last token.
10318 This is the parameter itself. */
10319 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10322 toklen
= end_tok
- tok
+ 1;
10324 if (toklen
== 6 && startswith (tok
, "thread"))
10326 struct thread_info
*thr
;
10327 /* At this point we've found a "thread" token, which means
10328 the user is trying to set a watchpoint that triggers
10329 only in a specific thread. */
10333 error(_("You can specify only one thread."));
10336 error (_("You can specify only one of thread or task."));
10338 if (inferior
!= -1)
10339 error (_("You can specify only one of inferior or thread."));
10341 /* Extract the thread ID from the next token. */
10342 thr
= parse_thread_id (value_start
, &endp
);
10343 if (value_start
== endp
)
10344 error (_("Junk after thread keyword."));
10346 thread
= thr
->global_num
;
10348 else if (toklen
== 4 && startswith (tok
, "task"))
10353 error(_("You can specify only one task."));
10356 error (_("You can specify only one of thread or task."));
10358 if (inferior
!= -1)
10359 error (_("You can specify only one of inferior or task."));
10361 task
= strtol (value_start
, &tmp
, 0);
10362 if (tmp
== value_start
)
10363 error (_("Junk after task keyword."));
10364 if (!valid_task_id (task
))
10365 error (_("Unknown task %d."), task
);
10367 else if (toklen
== 8 && startswith (tok
, "inferior"))
10369 /* Support for watchpoints will be added in a later commit. */
10370 error (_("Cannot use 'inferior' keyword with watchpoints"));
10372 else if (toklen
== 4 && startswith (tok
, "mask"))
10374 /* We've found a "mask" token, which means the user wants to
10375 create a hardware watchpoint that is going to have the mask
10377 struct value
*mask_value
;
10380 error(_("You can specify only one mask."));
10382 use_mask
= just_location
= true;
10384 scoped_value_mark mark
;
10385 mask_value
= parse_to_comma_and_eval (&value_start
);
10386 mask
= value_as_address (mask_value
);
10389 /* We didn't recognize what we found. We should stop here. */
10392 /* Truncate the string and get rid of the "parameter value" pair before
10393 the arguments string is parsed by the parse_exp_1 function. */
10400 /* Parse the rest of the arguments. From here on out, everything
10401 is in terms of a newly allocated string instead of the original
10403 std::string
expression (arg
, exp_end
- arg
);
10404 exp_start
= arg
= expression
.c_str ();
10405 innermost_block_tracker tracker
;
10406 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10408 /* Remove trailing whitespace from the expression before saving it.
10409 This makes the eventual display of the expression string a bit
10411 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10414 /* Checking if the expression is not constant. */
10415 if (watchpoint_exp_is_const (exp
.get ()))
10419 len
= exp_end
- exp_start
;
10420 while (len
> 0 && isspace (exp_start
[len
- 1]))
10422 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10425 exp_valid_block
= tracker
.block ();
10426 struct value
*mark
= value_mark ();
10427 struct value
*val_as_value
= nullptr;
10428 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10431 if (val_as_value
!= NULL
&& just_location
)
10433 saved_bitpos
= val_as_value
->bitpos ();
10434 saved_bitsize
= val_as_value
->bitsize ();
10442 exp_valid_block
= NULL
;
10443 val
= release_value (value_addr (result
));
10444 value_free_to_mark (mark
);
10448 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10451 error (_("This target does not support masked watchpoints."));
10452 else if (ret
== -2)
10453 error (_("Invalid mask or memory region."));
10456 else if (val_as_value
!= NULL
)
10457 val
= release_value (val_as_value
);
10459 tok
= skip_spaces (arg
);
10460 end_tok
= skip_to_space (tok
);
10462 toklen
= end_tok
- tok
;
10463 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10465 tok
= cond_start
= end_tok
+ 1;
10466 innermost_block_tracker if_tracker
;
10467 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10469 /* The watchpoint expression may not be local, but the condition
10470 may still be. E.g.: `watch global if local > 0'. */
10471 cond_exp_valid_block
= if_tracker
.block ();
10476 error (_("Junk at end of command."));
10478 frame_info_ptr wp_frame
= block_innermost_frame (exp_valid_block
);
10480 /* Save this because create_internal_breakpoint below invalidates
10482 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10484 /* Now set up the breakpoint. We create all watchpoints as hardware
10485 watchpoints here even if hardware watchpoints are turned off, a call
10486 to update_watchpoint later in this function will cause the type to
10487 drop back to bp_watchpoint (software watchpoint) if required. */
10489 if (accessflag
== hw_read
)
10490 bp_type
= bp_read_watchpoint
;
10491 else if (accessflag
== hw_access
)
10492 bp_type
= bp_access_watchpoint
;
10494 bp_type
= bp_hardware_watchpoint
;
10496 std::unique_ptr
<watchpoint
> w
;
10498 w
= std::make_unique
<masked_watchpoint
> (nullptr, bp_type
);
10500 w
= std::make_unique
<watchpoint
> (nullptr, bp_type
);
10502 /* At most one of thread or task can be set on a watchpoint. */
10503 gdb_assert (thread
== -1 || task
== -1);
10504 w
->thread
= thread
;
10505 w
->inferior
= inferior
;
10507 w
->disposition
= disp_donttouch
;
10508 w
->pspace
= current_program_space
;
10509 w
->exp
= std::move (exp
);
10510 w
->exp_valid_block
= exp_valid_block
;
10511 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10514 struct type
*t
= val
->type ();
10515 CORE_ADDR addr
= value_as_address (val
.get ());
10517 w
->exp_string_reparse
10518 = current_language
->watch_location_expression (t
, addr
);
10520 w
->exp_string
= xstrprintf ("-location %.*s",
10521 (int) (exp_end
- exp_start
), exp_start
);
10524 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10528 w
->hw_wp_mask
= mask
;
10533 w
->val_bitpos
= saved_bitpos
;
10534 w
->val_bitsize
= saved_bitsize
;
10535 w
->val_valid
= true;
10539 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10541 w
->cond_string
= 0;
10543 if (frame_id_p (watchpoint_frame
))
10545 w
->watchpoint_frame
= watchpoint_frame
;
10546 w
->watchpoint_thread
= inferior_ptid
;
10550 w
->watchpoint_frame
= null_frame_id
;
10551 w
->watchpoint_thread
= null_ptid
;
10554 if (!just_location
)
10555 value_free_to_mark (mark
);
10557 /* Finally update the new watchpoint. This creates the locations
10558 that should be inserted. */
10559 update_watchpoint (w
.get (), true /* reparse */);
10561 /* If the expression is "local", then set up a "watchpoint scope"
10562 breakpoint at the point where we've left the scope of the watchpoint
10563 expression. Create the scope breakpoint before the watchpoint, so
10564 that we will encounter it first in bpstat_stop_status. */
10565 if (exp_valid_block
!= nullptr && wp_frame
!= nullptr)
10567 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10569 if (frame_id_p (caller_frame_id
))
10571 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10572 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10575 = create_internal_breakpoint (caller_arch
, caller_pc
,
10576 bp_watchpoint_scope
);
10578 /* create_internal_breakpoint could invalidate WP_FRAME. */
10579 wp_frame
= nullptr;
10581 scope_breakpoint
->enable_state
= bp_enabled
;
10583 /* Automatically delete the breakpoint when it hits. */
10584 scope_breakpoint
->disposition
= disp_del
;
10586 /* Only break in the proper frame (help with recursion). */
10587 scope_breakpoint
->frame_id
= caller_frame_id
;
10589 /* Set the address at which we will stop. */
10590 bp_location
&loc
= scope_breakpoint
->first_loc ();
10591 loc
.gdbarch
= caller_arch
;
10592 loc
.requested_address
= caller_pc
;
10594 = adjust_breakpoint_address (loc
.gdbarch
, loc
.requested_address
,
10595 scope_breakpoint
->type
,
10596 current_program_space
);
10600 if (scope_breakpoint
!= nullptr)
10602 /* The scope breakpoint is related to the watchpoint. We will
10603 need to act on them together. */
10604 w
->related_breakpoint
= scope_breakpoint
;
10605 scope_breakpoint
->related_breakpoint
= w
.get ();
10608 /* Verify that the scope breakpoint comes before the watchpoint in the
10609 breakpoint chain. */
10610 gdb_assert (scope_breakpoint
== nullptr
10611 || &breakpoint_chain
.back () == scope_breakpoint
);
10612 watchpoint
*watchpoint_ptr
= w
.get ();
10613 install_breakpoint (internal
, std::move (w
), 1);
10614 gdb_assert (&breakpoint_chain
.back () == watchpoint_ptr
);
10617 /* Return count of debug registers needed to watch the given expression.
10618 If the watchpoint cannot be handled in hardware return zero. */
10621 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10623 int found_memory_cnt
= 0;
10625 /* Did the user specifically forbid us to use hardware watchpoints? */
10626 if (!can_use_hw_watchpoints
)
10629 gdb_assert (!vals
.empty ());
10630 struct value
*head
= vals
[0].get ();
10632 /* Make sure that the value of the expression depends only upon
10633 memory contents, and values computed from them within GDB. If we
10634 find any register references or function calls, we can't use a
10635 hardware watchpoint.
10637 The idea here is that evaluating an expression generates a series
10638 of values, one holding the value of every subexpression. (The
10639 expression a*b+c has five subexpressions: a, b, a*b, c, and
10640 a*b+c.) GDB's values hold almost enough information to establish
10641 the criteria given above --- they identify memory lvalues,
10642 register lvalues, computed values, etcetera. So we can evaluate
10643 the expression, and then scan the chain of values that leaves
10644 behind to decide whether we can detect any possible change to the
10645 expression's final value using only hardware watchpoints.
10647 However, I don't think that the values returned by inferior
10648 function calls are special in any way. So this function may not
10649 notice that an expression involving an inferior function call
10650 can't be watched with hardware watchpoints. FIXME. */
10651 for (const value_ref_ptr
&iter
: vals
)
10653 struct value
*v
= iter
.get ();
10655 if (v
->lval () == lval_memory
)
10657 if (v
!= head
&& v
->lazy ())
10658 /* A lazy memory lvalue in the chain is one that GDB never
10659 needed to fetch; we either just used its address (e.g.,
10660 `a' in `a.b') or we never needed it at all (e.g., `a'
10661 in `a,b'). This doesn't apply to HEAD; if that is
10662 lazy then it was not readable, but watch it anyway. */
10666 /* Ahh, memory we actually used! Check if we can cover
10667 it with hardware watchpoints. */
10668 struct type
*vtype
= check_typedef (v
->type ());
10670 /* We only watch structs and arrays if user asked for it
10671 explicitly, never if they just happen to appear in a
10672 middle of some value chain. */
10674 || (vtype
->code () != TYPE_CODE_STRUCT
10675 && vtype
->code () != TYPE_CODE_ARRAY
))
10677 CORE_ADDR vaddr
= v
->address ();
10681 len
= (target_exact_watchpoints
10682 && is_scalar_type_recursive (vtype
))?
10683 1 : v
->type ()->length ();
10685 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10689 found_memory_cnt
+= num_regs
;
10693 else if (v
->lval () != not_lval
&& !v
->deprecated_modifiable ())
10694 return 0; /* These are values from the history (e.g., $1). */
10695 else if (v
->lval () == lval_register
)
10696 return 0; /* Cannot watch a register with a HW watchpoint. */
10699 /* The expression itself looks suitable for using a hardware
10700 watchpoint, but give the target machine a chance to reject it. */
10701 return found_memory_cnt
;
10705 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10707 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10710 /* Options for the watch, awatch, and rwatch commands. */
10712 struct watch_options
10714 /* For -location. */
10715 bool location
= false;
10718 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10720 Historically GDB always accepted both '-location' and '-l' flags for
10721 these commands (both flags being synonyms). When converting to the
10722 newer option scheme only '-location' is added here. That's fine (for
10723 backward compatibility) as any non-ambiguous prefix of a flag will be
10724 accepted, so '-l', '-loc', are now all accepted.
10726 What this means is that, if in the future, we add any new flag here
10727 that starts with '-l' then this will break backward compatibility, so
10728 please, don't do that! */
10730 static const gdb::option::option_def watch_option_defs
[] = {
10731 gdb::option::flag_option_def
<watch_options
> {
10733 [] (watch_options
*opt
) { return &opt
->location
; },
10735 This evaluates EXPRESSION and watches the memory to which it refers.\n\
10736 -l can be used as a short form of -location."),
10740 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10743 static gdb::option::option_def_group
10744 make_watch_options_def_group (watch_options
*opts
)
10746 return {{watch_option_defs
}, opts
};
10749 /* A helper function that looks for the "-location" argument and then
10750 calls watch_command_1. */
10753 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10755 watch_options opts
;
10756 auto grp
= make_watch_options_def_group (&opts
);
10757 gdb::option::process_options
10758 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10759 if (arg
!= nullptr && *arg
== '\0')
10762 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10765 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10767 watch_command_completer (struct cmd_list_element
*ignore
,
10768 completion_tracker
&tracker
,
10769 const char *text
, const char * /*word*/)
10771 const auto group
= make_watch_options_def_group (nullptr);
10772 if (gdb::option::complete_options
10773 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10776 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10777 expression_completer (ignore
, tracker
, text
, word
);
10781 watch_command (const char *arg
, int from_tty
)
10783 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10787 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10789 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10793 rwatch_command (const char *arg
, int from_tty
)
10795 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10799 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10801 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10805 awatch_command (const char *arg
, int from_tty
)
10807 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10811 /* Data for the FSM that manages the until(location)/advance commands
10812 in infcmd.c. Here because it uses the mechanisms of
10815 struct until_break_fsm
: public thread_fsm
10817 /* The thread that was current when the command was executed. */
10820 /* The breakpoint set at the return address in the caller frame,
10821 plus breakpoints at all the destination locations. */
10822 std::vector
<breakpoint_up
> breakpoints
;
10824 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10825 std::vector
<breakpoint_up
> &&breakpoints
)
10826 : thread_fsm (cmd_interp
),
10828 breakpoints (std::move (breakpoints
))
10832 void clean_up (struct thread_info
*thread
) override
;
10833 bool should_stop (struct thread_info
*thread
) override
;
10834 enum async_reply_reason
do_async_reply_reason () override
;
10837 /* Implementation of the 'should_stop' FSM method for the
10838 until(location)/advance commands. */
10841 until_break_fsm::should_stop (struct thread_info
*tp
)
10843 for (const breakpoint_up
&bp
: breakpoints
)
10844 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10845 bp
.get ()) != NULL
)
10854 /* Implementation of the 'clean_up' FSM method for the
10855 until(location)/advance commands. */
10858 until_break_fsm::clean_up (struct thread_info
*)
10860 /* Clean up our temporary breakpoints. */
10861 breakpoints
.clear ();
10862 delete_longjmp_breakpoint (thread
);
10865 /* Implementation of the 'async_reply_reason' FSM method for the
10866 until(location)/advance commands. */
10868 enum async_reply_reason
10869 until_break_fsm::do_async_reply_reason ()
10871 return EXEC_ASYNC_LOCATION_REACHED
;
10875 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10877 frame_info_ptr frame
;
10878 struct gdbarch
*frame_gdbarch
;
10879 struct frame_id stack_frame_id
;
10880 struct frame_id caller_frame_id
;
10882 struct thread_info
*tp
;
10884 clear_proceed_status (0);
10886 /* Set a breakpoint where the user wants it and at return from
10889 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
10891 std::vector
<symtab_and_line
> sals
10892 = (last_displayed_sal_is_valid ()
10893 ? decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10894 get_last_displayed_symtab (),
10895 get_last_displayed_line ())
10896 : decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
,
10900 error (_("Couldn't get information on specified line."));
10903 error (_("Junk at end of arguments."));
10905 tp
= inferior_thread ();
10906 thread
= tp
->global_num
;
10908 /* Note linespec handling above invalidates the frame chain.
10909 Installing a breakpoint also invalidates the frame chain (as it
10910 may need to switch threads), so do any frame handling before
10913 frame
= get_selected_frame (NULL
);
10914 frame_gdbarch
= get_frame_arch (frame
);
10915 stack_frame_id
= get_stack_frame_id (frame
);
10916 caller_frame_id
= frame_unwind_caller_id (frame
);
10918 /* Keep within the current frame, or in frames called by the current
10921 std::vector
<breakpoint_up
> breakpoints
;
10923 std::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10925 if (frame_id_p (caller_frame_id
))
10927 struct symtab_and_line sal2
;
10928 struct gdbarch
*caller_gdbarch
;
10930 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10931 sal2
.pc
= frame_unwind_caller_pc (frame
);
10932 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10934 breakpoint_up caller_breakpoint
10935 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10936 caller_frame_id
, bp_until
);
10937 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10939 set_longjmp_breakpoint (tp
, stack_frame_id
);
10940 lj_deleter
.emplace (thread
);
10943 /* If the user told us to continue until a specified location, we
10944 don't specify a frame at which we need to stop. Otherwise,
10945 specify the selected frame, because we want to stop only at the
10946 very same frame. */
10947 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10949 for (symtab_and_line
&sal
: sals
)
10951 resolve_sal_pc (&sal
);
10953 breakpoint_up location_breakpoint
10954 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10955 stop_frame_id
, bp_until
);
10956 breakpoints
.emplace_back (std::move (location_breakpoint
));
10960 (std::unique_ptr
<thread_fsm
>
10961 (new until_break_fsm (command_interp (), tp
->global_num
,
10962 std::move (breakpoints
))));
10965 lj_deleter
->release ();
10967 proceed (-1, GDB_SIGNAL_DEFAULT
);
10972 /* Compare two breakpoints and return a strcmp-like result. */
10975 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10977 uintptr_t ua
= (uintptr_t) a
;
10978 uintptr_t ub
= (uintptr_t) b
;
10980 if (a
->number
< b
->number
)
10982 else if (a
->number
> b
->number
)
10985 /* Now sort by address, in case we see, e..g, two breakpoints with
10989 return ua
> ub
? 1 : 0;
10992 /* Delete breakpoints by address or line. */
10995 clear_command (const char *arg
, int from_tty
)
10999 std::vector
<symtab_and_line
> decoded_sals
;
11000 symtab_and_line last_sal
;
11001 gdb::array_view
<symtab_and_line
> sals
;
11005 = decode_line_with_current_source (arg
,
11006 (DECODE_LINE_FUNFIRSTLINE
11007 | DECODE_LINE_LIST_MODE
));
11009 sals
= decoded_sals
;
11013 /* Set sal's line, symtab, pc, and pspace to the values
11014 corresponding to the last call to print_frame_info. If the
11015 codepoint is not valid, this will set all the fields to 0. */
11016 last_sal
= get_last_displayed_sal ();
11017 if (last_sal
.symtab
== 0)
11018 error (_("No source file specified."));
11024 /* We don't call resolve_sal_pc here. That's not as bad as it
11025 seems, because all existing breakpoints typically have both
11026 file/line and pc set. So, if clear is given file/line, we can
11027 match this to existing breakpoint without obtaining pc at all.
11029 We only support clearing given the address explicitly
11030 present in breakpoint table. Say, we've set breakpoint
11031 at file:line. There were several PC values for that file:line,
11032 due to optimization, all in one block.
11034 We've picked one PC value. If "clear" is issued with another
11035 PC corresponding to the same file:line, the breakpoint won't
11036 be cleared. We probably can still clear the breakpoint, but
11037 since the other PC value is never presented to user, user
11038 can only find it by guessing, and it does not seem important
11039 to support that. */
11041 /* For each line spec given, delete bps which correspond to it. Do
11042 it in two passes, solely to preserve the current behavior that
11043 from_tty is forced true if we delete more than one
11046 std::vector
<struct breakpoint
*> found
;
11047 for (const auto &sal
: sals
)
11049 const char *sal_fullname
;
11051 /* If exact pc given, clear bpts at that pc.
11052 If line given (pc == 0), clear all bpts on specified line.
11053 If defaulting, clear all bpts on default line
11056 defaulting sal.pc != 0 tests to do
11061 1 0 <can't happen> */
11063 sal_fullname
= (sal
.symtab
== NULL
11064 ? NULL
: symtab_to_fullname (sal
.symtab
));
11066 /* Find all matching breakpoints and add them to 'found'. */
11067 for (breakpoint
&b
: all_breakpoints ())
11070 /* Are we going to delete b? */
11071 if (b
.type
!= bp_none
&& !is_watchpoint (&b
)
11072 && user_breakpoint_p (&b
))
11074 for (bp_location
&loc
: b
.locations ())
11076 /* If the user specified file:line, don't allow a PC
11077 match. This matches historical gdb behavior. */
11078 int pc_match
= (!sal
.explicit_line
11080 && (loc
.pspace
== sal
.pspace
)
11081 && (loc
.address
== sal
.pc
)
11082 && (!section_is_overlay (loc
.section
)
11083 || loc
.section
== sal
.section
));
11084 int line_match
= 0;
11086 if ((default_match
|| sal
.explicit_line
)
11087 && loc
.symtab
!= NULL
11088 && sal_fullname
!= NULL
11089 && sal
.pspace
== loc
.pspace
11090 && loc
.line_number
== sal
.line
11091 && filename_cmp (symtab_to_fullname (loc
.symtab
),
11092 sal_fullname
) == 0)
11095 if (pc_match
|| line_match
)
11104 found
.push_back (&b
);
11108 /* Now go through the 'found' chain and delete them. */
11109 if (found
.empty ())
11112 error (_("No breakpoint at %s."), arg
);
11114 error (_("No breakpoint at this line."));
11117 /* Remove duplicates from the vec. */
11118 std::sort (found
.begin (), found
.end (),
11119 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11121 return compare_breakpoints (bp_a
, bp_b
) < 0;
11123 found
.erase (std::unique (found
.begin (), found
.end (),
11124 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11126 return compare_breakpoints (bp_a
, bp_b
) == 0;
11130 if (found
.size () > 1)
11131 from_tty
= 1; /* Always report if deleted more than one. */
11134 if (found
.size () == 1)
11135 gdb_printf (_("Deleted breakpoint "));
11137 gdb_printf (_("Deleted breakpoints "));
11140 for (breakpoint
*iter
: found
)
11143 gdb_printf ("%d ", iter
->number
);
11144 delete_breakpoint (iter
);
11150 /* Delete breakpoint in BS if they are `delete' breakpoints and
11151 all breakpoints that are marked for deletion, whether hit or not.
11152 This is called after any breakpoint is hit, or after errors. */
11155 breakpoint_auto_delete (bpstat
*bs
)
11157 for (; bs
; bs
= bs
->next
)
11158 if (bs
->breakpoint_at
11159 && bs
->breakpoint_at
->disposition
== disp_del
11161 delete_breakpoint (bs
->breakpoint_at
);
11163 for (breakpoint
&b
: all_breakpoints_safe ())
11164 if (b
.disposition
== disp_del_at_next_stop
)
11165 delete_breakpoint (&b
);
11168 /* A comparison function for bp_location AP and BP being interfaced to
11169 std::sort. Sort elements primarily by their ADDRESS (no matter what
11170 bl_address_is_meaningful says), secondarily by ordering first
11171 permanent elements and tertiarily just ensuring the array is sorted
11172 stable way despite std::sort being an unstable algorithm. */
11175 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11177 if (a
->address
!= b
->address
)
11178 return a
->address
< b
->address
;
11180 /* Sort locations at the same address by their pspace number, keeping
11181 locations of the same inferior (in a multi-inferior environment)
11184 if (a
->pspace
->num
!= b
->pspace
->num
)
11185 return a
->pspace
->num
< b
->pspace
->num
;
11187 /* Sort permanent breakpoints first. */
11188 if (a
->permanent
!= b
->permanent
)
11189 return a
->permanent
> b
->permanent
;
11191 /* Sort by type in order to make duplicate determination easier.
11192 See update_global_location_list. This is kept in sync with
11193 breakpoint_locations_match. */
11194 if (a
->loc_type
< b
->loc_type
)
11197 /* Likewise, for range-breakpoints, sort by length. */
11198 if (a
->loc_type
== bp_loc_hardware_breakpoint
11199 && b
->loc_type
== bp_loc_hardware_breakpoint
11200 && a
->length
< b
->length
)
11203 /* Make the internal GDB representation stable across GDB runs
11204 where A and B memory inside GDB can differ. Breakpoint locations of
11205 the same type at the same address can be sorted in arbitrary order. */
11207 if (a
->owner
->number
!= b
->owner
->number
)
11208 return a
->owner
->number
< b
->owner
->number
;
11213 /* Set bp_locations_placed_address_before_address_max and
11214 bp_locations_shadow_len_after_address_max according to the current
11215 content of the bp_locations array. */
11218 bp_locations_target_extensions_update (void)
11220 bp_locations_placed_address_before_address_max
= 0;
11221 bp_locations_shadow_len_after_address_max
= 0;
11223 for (bp_location
*bl
: all_bp_locations ())
11225 CORE_ADDR start
, end
, addr
;
11227 if (!bp_location_has_shadow (bl
))
11230 start
= bl
->target_info
.placed_address
;
11231 end
= start
+ bl
->target_info
.shadow_len
;
11233 gdb_assert (bl
->address
>= start
);
11234 addr
= bl
->address
- start
;
11235 if (addr
> bp_locations_placed_address_before_address_max
)
11236 bp_locations_placed_address_before_address_max
= addr
;
11238 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11240 gdb_assert (bl
->address
< end
);
11241 addr
= end
- bl
->address
;
11242 if (addr
> bp_locations_shadow_len_after_address_max
)
11243 bp_locations_shadow_len_after_address_max
= addr
;
11247 /* Download tracepoint locations if they haven't been. */
11250 download_tracepoint_locations (void)
11252 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11254 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11256 for (breakpoint
&b
: all_tracepoints ())
11258 bool bp_location_downloaded
= false;
11260 if ((b
.type
== bp_fast_tracepoint
11261 ? !may_insert_fast_tracepoints
11262 : !may_insert_tracepoints
))
11265 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11267 if (target_can_download_tracepoint ())
11268 can_download_tracepoint
= TRIBOOL_TRUE
;
11270 can_download_tracepoint
= TRIBOOL_FALSE
;
11273 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11276 for (bp_location
&bl
: b
.locations ())
11278 /* In tracepoint, locations are _never_ duplicated, so
11279 should_be_inserted is equivalent to
11280 unduplicated_should_be_inserted. */
11281 if (!should_be_inserted (&bl
) || bl
.inserted
)
11284 switch_to_program_space_and_thread (bl
.pspace
);
11286 target_download_tracepoint (&bl
);
11289 bp_location_downloaded
= true;
11292 tracepoint
&t
= gdb::checked_static_cast
<tracepoint
&> (b
);
11293 t
.number_on_target
= b
.number
;
11294 if (bp_location_downloaded
)
11295 notify_breakpoint_modified (&b
);
11299 /* Swap the insertion/duplication state between two locations. */
11302 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11304 const int left_inserted
= left
->inserted
;
11305 const int left_duplicate
= left
->duplicate
;
11306 const int left_needs_update
= left
->needs_update
;
11307 const struct bp_target_info left_target_info
= left
->target_info
;
11309 /* Locations of tracepoints can never be duplicated. */
11310 if (is_tracepoint (left
->owner
))
11311 gdb_assert (!left
->duplicate
);
11312 if (is_tracepoint (right
->owner
))
11313 gdb_assert (!right
->duplicate
);
11315 left
->inserted
= right
->inserted
;
11316 left
->duplicate
= right
->duplicate
;
11317 left
->needs_update
= right
->needs_update
;
11318 left
->target_info
= right
->target_info
;
11319 right
->inserted
= left_inserted
;
11320 right
->duplicate
= left_duplicate
;
11321 right
->needs_update
= left_needs_update
;
11322 right
->target_info
= left_target_info
;
11325 /* Force the re-insertion of the locations at ADDRESS. This is called
11326 once a new/deleted/modified duplicate location is found and we are evaluating
11327 conditions on the target's side. Such conditions need to be updated on
11331 force_breakpoint_reinsertion (struct bp_location
*bl
)
11333 CORE_ADDR address
= 0;
11336 address
= bl
->address
;
11337 pspace_num
= bl
->pspace
->num
;
11339 /* This is only meaningful if the target is
11340 evaluating conditions and if the user has
11341 opted for condition evaluation on the target's
11343 if (gdb_evaluates_breakpoint_condition_p ()
11344 || !target_supports_evaluation_of_breakpoint_conditions ())
11347 /* Flag all breakpoint locations with this address and
11348 the same program space as the location
11349 as "its condition has changed". We need to
11350 update the conditions on the target's side. */
11351 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11353 if (!is_breakpoint (loc
->owner
)
11354 || pspace_num
!= loc
->pspace
->num
)
11357 /* Flag the location appropriately. We use a different state to
11358 let everyone know that we already updated the set of locations
11359 with addr bl->address and program space bl->pspace. This is so
11360 we don't have to keep calling these functions just to mark locations
11361 that have already been marked. */
11362 loc
->condition_changed
= condition_updated
;
11364 /* Free the agent expression bytecode as well. We will compute
11366 loc
->cond_bytecode
.reset ();
11370 /* Called whether new breakpoints are created, or existing breakpoints
11371 deleted, to update the global location list and recompute which
11372 locations are duplicate of which.
11374 The INSERT_MODE flag determines whether locations may not, may, or
11375 shall be inserted now. See 'enum ugll_insert_mode' for more
11379 update_global_location_list (enum ugll_insert_mode insert_mode
)
11381 /* Last breakpoint location address that was marked for update. */
11382 CORE_ADDR last_addr
= 0;
11383 /* Last breakpoint location program space that was marked for update. */
11384 int last_pspace_num
= -1;
11386 breakpoint_debug_printf ("insert_mode = %s",
11387 ugll_insert_mode_text (insert_mode
));
11389 /* Used in the duplicates detection below. When iterating over all
11390 bp_locations, points to the first bp_location of a given address.
11391 Breakpoints and watchpoints of different types are never
11392 duplicates of each other. Keep one pointer for each type of
11393 breakpoint/watchpoint, so we only need to loop over all locations
11395 struct bp_location
*bp_loc_first
; /* breakpoint */
11396 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11397 struct bp_location
*awp_loc_first
; /* access watchpoint */
11398 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11400 /* Saved former bp_locations array which we compare against the newly
11401 built bp_locations from the current state of ALL_BREAKPOINTS. */
11402 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11403 bp_locations
.clear ();
11405 for (breakpoint
&b
: all_breakpoints ())
11406 for (bp_location
&loc
: b
.locations ())
11407 bp_locations
.push_back (&loc
);
11409 /* See if we need to "upgrade" a software breakpoint to a hardware
11410 breakpoint. Do this before deciding whether locations are
11411 duplicates. Also do this before sorting because sorting order
11412 depends on location type. */
11413 for (bp_location
*loc
: bp_locations
)
11414 if (!loc
->inserted
&& should_be_inserted (loc
))
11415 handle_automatic_hardware_breakpoints (loc
);
11417 std::sort (bp_locations
.begin (), bp_locations
.end (),
11418 bp_location_is_less_than
);
11420 bp_locations_target_extensions_update ();
11422 /* Identify bp_location instances that are no longer present in the
11423 new list, and therefore should be freed. Note that it's not
11424 necessary that those locations should be removed from inferior --
11425 if there's another location at the same address (previously
11426 marked as duplicate), we don't need to remove/insert the
11429 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11430 and former bp_location array state respectively. */
11433 for (bp_location
*old_loc
: old_locations
)
11435 /* Tells if 'old_loc' is found among the new locations. If
11436 not, we have to free it. */
11437 bool found_object
= false;
11438 /* Tells if the location should remain inserted in the target. */
11439 bool keep_in_target
= false;
11440 bool removed
= false;
11442 /* Skip LOCP entries which will definitely never be needed.
11443 Stop either at or being the one matching OLD_LOC. */
11444 while (loc_i
< bp_locations
.size ()
11445 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11448 for (size_t loc2_i
= loc_i
;
11449 (loc2_i
< bp_locations
.size ()
11450 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11453 /* Check if this is a new/duplicated location or a duplicated
11454 location that had its condition modified. If so, we want to send
11455 its condition to the target if evaluation of conditions is taking
11457 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11458 && (last_addr
!= old_loc
->address
11459 || last_pspace_num
!= old_loc
->pspace
->num
))
11461 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11462 last_pspace_num
= old_loc
->pspace
->num
;
11465 if (bp_locations
[loc2_i
] == old_loc
)
11466 found_object
= true;
11469 /* We have already handled this address, update it so that we don't
11470 have to go through updates again. */
11471 last_addr
= old_loc
->address
;
11473 /* Target-side condition evaluation: Handle deleted locations. */
11475 force_breakpoint_reinsertion (old_loc
);
11477 /* If this location is no longer present, and inserted, look if
11478 there's maybe a new location at the same address. If so,
11479 mark that one inserted, and don't remove this one. This is
11480 needed so that we don't have a time window where a breakpoint
11481 at certain location is not inserted. */
11483 if (old_loc
->inserted
)
11485 /* If the location is inserted now, we might have to remove
11488 if (found_object
&& should_be_inserted (old_loc
))
11490 /* The location is still present in the location list,
11491 and still should be inserted. Don't do anything. */
11492 keep_in_target
= true;
11496 /* This location still exists, but it won't be kept in the
11497 target since it may have been disabled. We proceed to
11498 remove its target-side condition. */
11500 /* The location is either no longer present, or got
11501 disabled. See if there's another location at the
11502 same address, in which case we don't need to remove
11503 this one from the target. */
11505 /* OLD_LOC comes from existing struct breakpoint. */
11506 if (bl_address_is_meaningful (old_loc
))
11508 for (size_t loc2_i
= loc_i
;
11509 (loc2_i
< bp_locations
.size ()
11510 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11513 bp_location
*loc2
= bp_locations
[loc2_i
];
11515 if (loc2
== old_loc
)
11518 if (breakpoint_locations_match (loc2
, old_loc
))
11520 /* Read watchpoint locations are switched to
11521 access watchpoints, if the former are not
11522 supported, but the latter are. */
11523 if (is_hardware_watchpoint (old_loc
->owner
))
11525 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11526 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11529 /* loc2 is a duplicated location. We need to check
11530 if it should be inserted in case it will be
11532 if (unduplicated_should_be_inserted (loc2
))
11534 swap_insertion (old_loc
, loc2
);
11535 keep_in_target
= true;
11543 if (!keep_in_target
)
11545 if (remove_breakpoint (old_loc
))
11547 /* This is just about all we can do. We could keep
11548 this location on the global list, and try to
11549 remove it next time, but there's no particular
11550 reason why we will succeed next time.
11552 Note that at this point, old_loc->owner is still
11553 valid, as delete_breakpoint frees the breakpoint
11554 only after calling us. */
11555 warning (_("error removing breakpoint %d at %s"),
11556 old_loc
->owner
->number
,
11557 paddress (old_loc
->gdbarch
, old_loc
->address
));
11565 if (removed
&& target_is_non_stop_p ()
11566 && need_moribund_for_location_type (old_loc
))
11568 /* This location was removed from the target. In
11569 non-stop mode, a race condition is possible where
11570 we've removed a breakpoint, but stop events for that
11571 breakpoint are already queued and will arrive later.
11572 We apply an heuristic to be able to distinguish such
11573 SIGTRAPs from other random SIGTRAPs: we keep this
11574 breakpoint location for a bit, and will retire it
11575 after we see some number of events. The theory here
11576 is that reporting of events should, "on the average",
11577 be fair, so after a while we'll see events from all
11578 threads that have anything of interest, and no longer
11579 need to keep this breakpoint location around. We
11580 don't hold locations forever so to reduce chances of
11581 mistaking a non-breakpoint SIGTRAP for a breakpoint
11584 The heuristic failing can be disastrous on
11585 decr_pc_after_break targets.
11587 On decr_pc_after_break targets, like e.g., x86-linux,
11588 if we fail to recognize a late breakpoint SIGTRAP,
11589 because events_till_retirement has reached 0 too
11590 soon, we'll fail to do the PC adjustment, and report
11591 a random SIGTRAP to the user. When the user resumes
11592 the inferior, it will most likely immediately crash
11593 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11594 corrupted, because of being resumed e.g., in the
11595 middle of a multi-byte instruction, or skipped a
11596 one-byte instruction. This was actually seen happen
11597 on native x86-linux, and should be less rare on
11598 targets that do not support new thread events, like
11599 remote, due to the heuristic depending on
11602 Mistaking a random SIGTRAP for a breakpoint trap
11603 causes similar symptoms (PC adjustment applied when
11604 it shouldn't), but then again, playing with SIGTRAPs
11605 behind the debugger's back is asking for trouble.
11607 Since hardware watchpoint traps are always
11608 distinguishable from other traps, so we don't need to
11609 apply keep hardware watchpoint moribund locations
11610 around. We simply always ignore hardware watchpoint
11611 traps we can no longer explain. */
11613 process_stratum_target
*proc_target
= nullptr;
11614 for (inferior
*inf
: all_inferiors ())
11615 if (inf
->pspace
== old_loc
->pspace
)
11617 proc_target
= inf
->process_target ();
11620 if (proc_target
!= nullptr)
11621 old_loc
->events_till_retirement
11622 = 3 * (thread_count (proc_target
) + 1);
11624 old_loc
->events_till_retirement
= 1;
11625 old_loc
->owner
= NULL
;
11627 moribund_locations
.push_back (old_loc
);
11631 old_loc
->owner
= NULL
;
11632 decref_bp_location (&old_loc
);
11637 /* Rescan breakpoints at the same address and section, marking the
11638 first one as "first" and any others as "duplicates". This is so
11639 that the bpt instruction is only inserted once. If we have a
11640 permanent breakpoint at the same place as BPT, make that one the
11641 official one, and the rest as duplicates. Permanent breakpoints
11642 are sorted first for the same address.
11644 Do the same for hardware watchpoints, but also considering the
11645 watchpoint's type (regular/access/read) and length. */
11647 bp_loc_first
= NULL
;
11648 wp_loc_first
= NULL
;
11649 awp_loc_first
= NULL
;
11650 rwp_loc_first
= NULL
;
11652 for (bp_location
*loc
: all_bp_locations ())
11654 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11656 struct bp_location
**loc_first_p
;
11657 breakpoint
*b
= loc
->owner
;
11659 if (!unduplicated_should_be_inserted (loc
)
11660 || !bl_address_is_meaningful (loc
)
11661 /* Don't detect duplicate for tracepoint locations because they are
11662 never duplicated. See the comments in field `duplicate' of
11663 `struct bp_location'. */
11664 || is_tracepoint (b
))
11666 /* Clear the condition modification flag. */
11667 loc
->condition_changed
= condition_unchanged
;
11671 if (b
->type
== bp_hardware_watchpoint
)
11672 loc_first_p
= &wp_loc_first
;
11673 else if (b
->type
== bp_read_watchpoint
)
11674 loc_first_p
= &rwp_loc_first
;
11675 else if (b
->type
== bp_access_watchpoint
)
11676 loc_first_p
= &awp_loc_first
;
11678 loc_first_p
= &bp_loc_first
;
11680 if (*loc_first_p
== NULL
11681 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11682 || !breakpoint_locations_match (loc
, *loc_first_p
))
11684 *loc_first_p
= loc
;
11685 loc
->duplicate
= 0;
11687 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11689 loc
->needs_update
= 1;
11690 /* Clear the condition modification flag. */
11691 loc
->condition_changed
= condition_unchanged
;
11697 /* This and the above ensure the invariant that the first location
11698 is not duplicated, and is the inserted one.
11699 All following are marked as duplicated, and are not inserted. */
11701 swap_insertion (loc
, *loc_first_p
);
11702 loc
->duplicate
= 1;
11704 /* Clear the condition modification flag. */
11705 loc
->condition_changed
= condition_unchanged
;
11708 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11710 if (insert_mode
!= UGLL_DONT_INSERT
)
11711 insert_breakpoint_locations ();
11714 /* Even though the caller told us to not insert new
11715 locations, we may still need to update conditions on the
11716 target's side of breakpoints that were already inserted
11717 if the target is evaluating breakpoint conditions. We
11718 only update conditions for locations that are marked
11720 update_inserted_breakpoint_locations ();
11724 if (insert_mode
!= UGLL_DONT_INSERT
)
11725 download_tracepoint_locations ();
11729 breakpoint_retire_moribund (void)
11731 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11733 struct bp_location
*loc
= moribund_locations
[ix
];
11734 if (--(loc
->events_till_retirement
) == 0)
11736 decref_bp_location (&loc
);
11737 unordered_remove (moribund_locations
, ix
);
11744 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11749 update_global_location_list (insert_mode
);
11751 catch (const gdb_exception_error
&e
)
11756 /* Clear BKP from a BPS. */
11759 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11763 for (bs
= bps
; bs
; bs
= bs
->next
)
11764 if (bs
->breakpoint_at
== bpt
)
11766 bs
->breakpoint_at
= NULL
;
11767 bs
->old_val
= NULL
;
11768 /* bs->commands will be freed later. */
11772 /* Callback for iterate_over_threads. */
11774 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11776 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11778 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11782 /* See breakpoint.h. */
11785 code_breakpoint::say_where () const
11787 struct value_print_options opts
;
11789 get_user_print_options (&opts
);
11791 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11793 if (!this->has_locations ())
11795 /* For pending locations, the output differs slightly based
11796 on extra_string. If this is non-NULL, it contains either
11797 a condition or dprintf arguments. */
11798 if (extra_string
== NULL
)
11800 gdb_printf (_(" (%s) pending."), locspec
->to_string ());
11802 else if (type
== bp_dprintf
)
11804 gdb_printf (_(" (%s,%s) pending."),
11805 locspec
->to_string (),
11806 extra_string
.get ());
11810 gdb_printf (_(" (%s %s) pending."),
11811 locspec
->to_string (),
11812 extra_string
.get ());
11817 const bp_location
&bl
= this->first_loc ();
11818 if (opts
.addressprint
|| bl
.symtab
== nullptr)
11819 gdb_printf (" at %ps",
11820 styled_string (address_style
.style (),
11821 paddress (bl
.gdbarch
,
11823 if (bl
.symtab
!= NULL
)
11825 /* If there is a single location, we can print the location
11827 if (!this->has_multiple_locations ())
11829 const char *filename
11830 = symtab_to_filename_for_display (bl
.symtab
);
11831 gdb_printf (": file %ps, line %ps.",
11832 styled_string (file_name_style
.style (),
11834 styled_string (line_number_style
.style (),
11835 pulongest (bl
.line_number
)));
11838 /* This is not ideal, but each location may have a
11839 different file name, and this at least reflects the
11840 real situation somewhat. */
11841 gdb_printf (": %s.", locspec
->to_string ());
11844 if (this->has_multiple_locations ())
11846 int n
= std::distance (m_locations
.begin (), m_locations
.end ());
11847 gdb_printf (" (%d locations)", n
);
11852 /* See breakpoint.h. */
11855 breakpoint::locations () const
11857 return bp_location_range (m_locations
.begin (), m_locations
.end ());
11860 struct bp_location
*
11861 breakpoint::allocate_location ()
11863 return new bp_location (this);
11866 /* See breakpoint.h. */
11869 breakpoint::add_location (bp_location
&loc
)
11871 gdb_assert (loc
.owner
== this);
11872 gdb_assert (!loc
.is_linked ());
11874 auto ub
= std::upper_bound (m_locations
.begin (), m_locations
.end (),
11876 [] (const bp_location
&left
,
11877 const bp_location
&right
)
11878 { return left
.address
< right
.address
; });
11879 m_locations
.insert (ub
, loc
);
11882 /* See breakpoint.h. */
11885 breakpoint::unadd_location (bp_location
&loc
)
11887 gdb_assert (loc
.owner
== this);
11888 gdb_assert (loc
.is_linked ());
11890 m_locations
.erase (m_locations
.iterator_to (loc
));
11893 #define internal_error_pure_virtual_called() \
11894 gdb_assert_not_reached ("pure virtual function called")
11897 breakpoint::insert_location (struct bp_location
*bl
)
11899 internal_error_pure_virtual_called ();
11903 breakpoint::remove_location (struct bp_location
*bl
,
11904 enum remove_bp_reason reason
)
11906 internal_error_pure_virtual_called ();
11910 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11911 const address_space
*aspace
,
11913 const target_waitstatus
&ws
)
11915 internal_error_pure_virtual_called ();
11919 breakpoint::resources_needed (const struct bp_location
*bl
)
11921 internal_error_pure_virtual_called ();
11924 enum print_stop_action
11925 breakpoint::print_it (const bpstat
*bs
) const
11927 internal_error_pure_virtual_called ();
11931 breakpoint::print_mention () const
11933 internal_error_pure_virtual_called ();
11937 breakpoint::print_recreate (struct ui_file
*fp
) const
11939 internal_error_pure_virtual_called ();
11942 /* Default breakpoint_ops methods. */
11945 code_breakpoint::re_set (struct program_space
*pspace
)
11947 /* FIXME: is this still reachable? */
11948 if (breakpoint_location_spec_empty_p (this))
11950 /* Anything without a location can't be re-set. */
11951 delete_breakpoint (this);
11955 re_set_default (pspace
);
11959 code_breakpoint::insert_location (struct bp_location
*bl
)
11961 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11963 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11964 bl
->target_info
.placed_address
= addr
;
11967 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11968 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11970 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11972 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11974 /* The insertion was successful, now let's set the probe's semaphore
11976 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11983 code_breakpoint::remove_location (struct bp_location
*bl
,
11984 enum remove_bp_reason reason
)
11986 if (bl
->probe
.prob
!= nullptr)
11988 /* Let's clear the semaphore before removing the location. */
11989 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11992 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11993 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11995 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11999 code_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
12000 const address_space
*aspace
,
12002 const target_waitstatus
&ws
)
12004 if (ws
.kind () != TARGET_WAITKIND_STOPPED
12005 || ws
.sig () != GDB_SIGNAL_TRAP
)
12008 if (!breakpoint_address_match (bl
->pspace
->aspace
.get (), bl
->address
,
12012 if (overlay_debugging
/* unmapped overlay section */
12013 && section_is_overlay (bl
->section
)
12014 && !section_is_mapped (bl
->section
))
12021 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
12022 const address_space
*aspace
,
12024 const target_waitstatus
&ws
)
12026 if (dprintf_style
== dprintf_style_agent
12027 && target_can_run_breakpoint_commands ())
12029 /* An agent-style dprintf never causes a stop. If we see a trap
12030 for this address it must be for a breakpoint that happens to
12031 be set at the same address. */
12035 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12039 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
12041 gdb_assert (type
== bp_hardware_breakpoint
);
12046 enum print_stop_action
12047 ordinary_breakpoint::print_it (const bpstat
*bs
) const
12049 const struct bp_location
*bl
;
12051 struct ui_out
*uiout
= current_uiout
;
12053 bl
= bs
->bp_location_at
.get ();
12055 bp_temp
= disposition
== disp_del
;
12056 if (bl
->address
!= bl
->requested_address
)
12057 breakpoint_adjustment_warning (bl
->requested_address
,
12060 annotate_breakpoint (number
);
12061 maybe_print_thread_hit_breakpoint (uiout
);
12063 if (uiout
->is_mi_like_p ())
12065 uiout
->field_string ("reason",
12066 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12067 uiout
->field_string ("disp", bpdisp_text (disposition
));
12071 uiout
->text ("Temporary breakpoint ");
12073 uiout
->text ("Breakpoint ");
12074 print_num_locno (bs
, uiout
);
12075 uiout
->text (", ");
12077 return PRINT_SRC_AND_LOC
;
12081 ordinary_breakpoint::print_mention () const
12083 if (current_uiout
->is_mi_like_p ())
12088 case bp_breakpoint
:
12089 case bp_gnu_ifunc_resolver
:
12090 if (disposition
== disp_del
)
12091 gdb_printf (_("Temporary breakpoint"));
12093 gdb_printf (_("Breakpoint"));
12094 gdb_printf (_(" %d"), number
);
12095 if (type
== bp_gnu_ifunc_resolver
)
12096 gdb_printf (_(" at gnu-indirect-function resolver"));
12098 case bp_hardware_breakpoint
:
12099 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
12102 gdb_printf (_("Dprintf %d"), number
);
12110 ordinary_breakpoint::print_recreate (struct ui_file
*fp
) const
12112 if (type
== bp_breakpoint
&& disposition
== disp_del
)
12113 gdb_printf (fp
, "tbreak");
12114 else if (type
== bp_breakpoint
)
12115 gdb_printf (fp
, "break");
12116 else if (type
== bp_hardware_breakpoint
12117 && disposition
== disp_del
)
12118 gdb_printf (fp
, "thbreak");
12119 else if (type
== bp_hardware_breakpoint
)
12120 gdb_printf (fp
, "hbreak");
12122 internal_error (_("unhandled breakpoint type %d"), (int) type
);
12124 gdb_printf (fp
, " %s", locspec
->to_string ());
12126 /* Print out extra_string if this breakpoint is pending. It might
12127 contain, for example, conditions that were set by the user. */
12128 if (!this->has_locations () && extra_string
!= NULL
)
12129 gdb_printf (fp
, " %s", extra_string
.get ());
12131 print_recreate_thread (fp
);
12134 std::vector
<symtab_and_line
>
12135 code_breakpoint::decode_location_spec (location_spec
*locspec
,
12136 program_space
*search_pspace
)
12138 if (locspec
->type () == PROBE_LOCATION_SPEC
)
12139 return bkpt_probe_decode_location_spec (this, locspec
, search_pspace
);
12141 struct linespec_result canonical
;
12143 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
12144 NULL
, 0, &canonical
, multiple_symbols_all
,
12147 /* We should get 0 or 1 resulting SALs. */
12148 gdb_assert (canonical
.lsals
.size () < 2);
12150 if (!canonical
.lsals
.empty ())
12152 const linespec_sals
&lsal
= canonical
.lsals
[0];
12153 return std::move (lsal
.sals
);
12158 /* Virtual table for internal breakpoints. */
12161 internal_breakpoint::re_set (struct program_space
*pspace
)
12165 /* Delete overlay event and longjmp master breakpoints; they
12166 will be reset later by breakpoint_re_set. */
12167 case bp_overlay_event
:
12168 case bp_longjmp_master
:
12169 case bp_std_terminate_master
:
12170 case bp_exception_master
:
12171 delete_breakpoint (this);
12174 /* This breakpoint is special, it's set up when the inferior
12175 starts and we really don't want to touch it. */
12176 case bp_shlib_event
:
12178 /* Like bp_shlib_event, this breakpoint type is special. Once
12179 it is set up, we do not want to touch it. */
12180 case bp_thread_event
:
12186 internal_breakpoint::check_status (bpstat
*bs
)
12188 if (type
== bp_shlib_event
)
12190 /* If requested, stop when the dynamic linker notifies GDB of
12191 events. This allows the user to get control and place
12192 breakpoints in initializer routines for dynamically loaded
12193 objects (among other things). */
12194 bs
->stop
= stop_on_solib_events
!= 0;
12195 bs
->print
= stop_on_solib_events
!= 0;
12201 enum print_stop_action
12202 internal_breakpoint::print_it (const bpstat
*bs
) const
12206 case bp_shlib_event
:
12207 /* Did we stop because the user set the stop_on_solib_events
12208 variable? (If so, we report this as a generic, "Stopped due
12209 to shlib event" message.) */
12210 print_solib_event (false);
12213 case bp_thread_event
:
12214 /* Not sure how we will get here.
12215 GDB should not stop for these breakpoints. */
12216 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
12219 case bp_overlay_event
:
12220 /* By analogy with the thread event, GDB should not stop for these. */
12221 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12224 case bp_longjmp_master
:
12225 /* These should never be enabled. */
12226 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12229 case bp_std_terminate_master
:
12230 /* These should never be enabled. */
12231 gdb_printf (_("std::terminate Master Breakpoint: "
12232 "gdb should not stop!\n"));
12235 case bp_exception_master
:
12236 /* These should never be enabled. */
12237 gdb_printf (_("Exception Master Breakpoint: "
12238 "gdb should not stop!\n"));
12242 return PRINT_NOTHING
;
12246 internal_breakpoint::print_mention () const
12248 /* Nothing to mention. These breakpoints are internal. */
12251 /* Virtual table for momentary breakpoints */
12254 momentary_breakpoint::re_set (struct program_space
*pspace
)
12256 /* Keep temporary breakpoints, which can be encountered when we step
12257 over a dlopen call and solib_add is resetting the breakpoints.
12258 Otherwise these should have been blown away via the cleanup chain
12259 or by breakpoint_init_inferior when we rerun the executable. */
12263 momentary_breakpoint::check_status (bpstat
*bs
)
12265 /* Nothing. The point of these breakpoints is causing a stop. */
12268 enum print_stop_action
12269 momentary_breakpoint::print_it (const bpstat
*bs
) const
12271 return PRINT_UNKNOWN
;
12275 momentary_breakpoint::print_mention () const
12277 /* Nothing to mention. These breakpoints are internal. */
12280 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12282 It gets cleared already on the removal of the first one of such placed
12283 breakpoints. This is OK as they get all removed altogether. */
12285 longjmp_breakpoint::~longjmp_breakpoint ()
12287 thread_info
*tp
= find_thread_global_id (this->thread
);
12290 tp
->initiating_frame
= null_frame_id
;
12294 bkpt_probe_create_sals_from_location_spec (location_spec
*locspec
,
12295 struct linespec_result
*canonical
,
12296 struct program_space
*search_pspace
)
12299 struct linespec_sals lsal
;
12301 lsal
.sals
= parse_probes (locspec
, search_pspace
, canonical
);
12302 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12303 canonical
->lsals
.push_back (std::move (lsal
));
12306 static std::vector
<symtab_and_line
>
12307 bkpt_probe_decode_location_spec (struct breakpoint
*b
,
12308 location_spec
*locspec
,
12309 program_space
*search_pspace
)
12311 std::vector
<symtab_and_line
> sals
12312 = parse_probes (locspec
, search_pspace
, NULL
);
12314 error (_("probe not found"));
12319 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
12320 const address_space
*aspace
, CORE_ADDR bp_addr
,
12321 const target_waitstatus
&ws
)
12323 /* By definition, the inferior does not report stops at
12329 tracepoint::print_one_detail (struct ui_out
*uiout
) const
12331 if (!static_trace_marker_id
.empty ())
12333 gdb_assert (type
== bp_static_tracepoint
12334 || type
== bp_static_marker_tracepoint
);
12336 uiout
->message ("\tmarker id is %pF\n",
12337 string_field ("static-tracepoint-marker-string-id",
12338 static_trace_marker_id
.c_str ()));
12343 tracepoint::print_mention () const
12345 if (current_uiout
->is_mi_like_p ())
12350 case bp_tracepoint
:
12351 gdb_printf (_("Tracepoint"));
12352 gdb_printf (_(" %d"), number
);
12354 case bp_fast_tracepoint
:
12355 gdb_printf (_("Fast tracepoint"));
12356 gdb_printf (_(" %d"), number
);
12358 case bp_static_tracepoint
:
12359 case bp_static_marker_tracepoint
:
12360 gdb_printf (_("Static tracepoint"));
12361 gdb_printf (_(" %d"), number
);
12364 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12371 tracepoint::print_recreate (struct ui_file
*fp
) const
12373 if (type
== bp_fast_tracepoint
)
12374 gdb_printf (fp
, "ftrace");
12375 else if (type
== bp_static_tracepoint
12376 || type
== bp_static_marker_tracepoint
)
12377 gdb_printf (fp
, "strace");
12378 else if (type
== bp_tracepoint
)
12379 gdb_printf (fp
, "trace");
12381 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12383 gdb_printf (fp
, " %s", locspec
->to_string ());
12384 print_recreate_thread (fp
);
12387 gdb_printf (fp
, " passcount %d\n", pass_count
);
12391 dprintf_breakpoint::re_set (struct program_space
*pspace
)
12393 re_set_default (pspace
);
12395 /* 1 - connect to target 1, that can run breakpoint commands.
12396 2 - create a dprintf, which resolves fine.
12397 3 - disconnect from target 1
12398 4 - connect to target 2, that can NOT run breakpoint commands.
12400 After steps #3/#4, you'll want the dprintf command list to
12401 be updated, because target 1 and 2 may well return different
12402 answers for target_can_run_breakpoint_commands().
12403 Given absence of finer grained resetting, we get to do
12404 it all the time. */
12405 update_dprintf_command_list (this);
12408 /* Implement the "print_recreate" method for dprintf. */
12411 dprintf_breakpoint::print_recreate (struct ui_file
*fp
) const
12413 gdb_printf (fp
, "dprintf %s,%s", locspec
->to_string (), extra_string
.get ());
12414 print_recreate_thread (fp
);
12417 /* Implement the "after_condition_true" method for dprintf.
12419 dprintf's are implemented with regular commands in their command
12420 list, but we run the commands here instead of before presenting the
12421 stop to the user, as dprintf's don't actually cause a stop. This
12422 also makes it so that the commands of multiple dprintfs at the same
12423 address are all handled. */
12426 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
12428 /* dprintf's never cause a stop. This wasn't set in the
12429 check_status hook instead because that would make the dprintf's
12430 condition not be evaluated. */
12433 /* Run the command list here. Take ownership of it instead of
12434 copying. We never want these commands to run later in
12435 bpstat_do_actions, if a breakpoint that causes a stop happens to
12436 be set at same address as this dprintf, or even if running the
12437 commands here throws. */
12438 counted_command_line cmds
= std::move (bs
->commands
);
12439 gdb_assert (cmds
!= nullptr);
12440 execute_control_commands (cmds
.get (), 0);
12443 /* The breakpoint_ops structure to be used on static tracepoints with
12447 strace_marker_create_sals_from_location_spec
12448 (location_spec
*locspec
,
12449 struct linespec_result
*canonical
,
12450 struct program_space
*search_pspace
)
12452 struct linespec_sals lsal
;
12453 const char *arg_start
, *arg
;
12455 arg
= arg_start
= as_linespec_location_spec (locspec
)->spec_string
.get ();
12456 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12458 std::string
str (arg_start
, arg
- arg_start
);
12459 const char *ptr
= str
.c_str ();
12461 = new_linespec_location_spec (&ptr
, symbol_name_match_type::FULL
);
12463 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12464 canonical
->lsals
.push_back (std::move (lsal
));
12468 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12469 struct linespec_result
*canonical
,
12470 gdb::unique_xmalloc_ptr
<char> cond_string
,
12471 gdb::unique_xmalloc_ptr
<char> extra_string
,
12472 enum bptype type_wanted
,
12473 enum bpdisp disposition
,
12475 int task
, int inferior
,
12477 int from_tty
, int enabled
,
12478 int internal
, unsigned flags
)
12480 const linespec_sals
&lsal
= canonical
->lsals
[0];
12482 /* If the user is creating a static tracepoint by marker id
12483 (strace -m MARKER_ID), then store the sals index, so that
12484 breakpoint_re_set can try to match up which of the newly
12485 found markers corresponds to this one, and, don't try to
12486 expand multiple locations for each sal, given than SALS
12487 already should contain all sals for MARKER_ID. */
12489 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12491 location_spec_up locspec
= canonical
->locspec
->clone ();
12493 std::unique_ptr
<tracepoint
> tp
12494 (new tracepoint (gdbarch
,
12497 std::move (locspec
),
12499 std::move (cond_string
),
12500 std::move (extra_string
),
12502 thread
, task
, inferior
, ignore_count
,
12503 from_tty
, enabled
, flags
,
12504 canonical
->special_display
));
12506 /* Given that its possible to have multiple markers with
12507 the same string id, if the user is creating a static
12508 tracepoint by marker id ("strace -m MARKER_ID"), then
12509 store the sals index, so that breakpoint_re_set can
12510 try to match up which of the newly found markers
12511 corresponds to this one */
12512 tp
->static_trace_marker_id_idx
= i
;
12514 install_breakpoint (internal
, std::move (tp
), 0);
12518 std::vector
<symtab_and_line
>
12519 static_marker_tracepoint::decode_location_spec (location_spec
*locspec
,
12520 program_space
*search_pspace
)
12522 const char *s
= as_linespec_location_spec (locspec
)->spec_string
.get ();
12524 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12525 if (sals
.size () > static_trace_marker_id_idx
)
12527 sals
[0] = sals
[static_trace_marker_id_idx
];
12532 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12535 /* Static tracepoints with marker (`-m'). */
12536 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12538 strace_marker_create_sals_from_location_spec
,
12539 strace_marker_create_breakpoints_sal
,
12543 strace_marker_p (struct breakpoint
*b
)
12545 return b
->type
== bp_static_marker_tracepoint
;
12548 /* Notify interpreters and observers that breakpoint B was deleted. */
12551 notify_breakpoint_deleted (breakpoint
*b
)
12553 interps_notify_breakpoint_deleted (b
);
12554 gdb::observers::breakpoint_deleted
.notify (b
);
12557 /* Delete a breakpoint and clean up all traces of it in the data
12561 delete_breakpoint (struct breakpoint
*bpt
)
12563 gdb_assert (bpt
!= NULL
);
12565 /* Has this bp already been deleted? This can happen because
12566 multiple lists can hold pointers to bp's. bpstat lists are
12569 One example of this happening is a watchpoint's scope bp. When
12570 the scope bp triggers, we notice that the watchpoint is out of
12571 scope, and delete it. We also delete its scope bp. But the
12572 scope bp is marked "auto-deleting", and is already on a bpstat.
12573 That bpstat is then checked for auto-deleting bp's, which are
12576 A real solution to this problem might involve reference counts in
12577 bp's, and/or giving them pointers back to their referencing
12578 bpstat's, and teaching delete_breakpoint to only free a bp's
12579 storage when no more references were extent. A cheaper bandaid
12581 if (bpt
->type
== bp_none
)
12584 /* At least avoid this stale reference until the reference counting
12585 of breakpoints gets resolved. */
12586 if (bpt
->related_breakpoint
!= bpt
)
12588 struct breakpoint
*related
;
12589 struct watchpoint
*w
;
12591 if (bpt
->type
== bp_watchpoint_scope
)
12592 w
= gdb::checked_static_cast
<watchpoint
*> (bpt
->related_breakpoint
);
12593 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12594 w
= gdb::checked_static_cast
<watchpoint
*> (bpt
);
12598 watchpoint_del_at_next_stop (w
);
12600 /* Unlink bpt from the bpt->related_breakpoint ring. */
12601 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12602 related
= related
->related_breakpoint
);
12603 related
->related_breakpoint
= bpt
->related_breakpoint
;
12604 bpt
->related_breakpoint
= bpt
;
12607 /* watch_command_1 creates a watchpoint but only sets its number if
12608 update_watchpoint succeeds in creating its bp_locations. If there's
12609 a problem in that process, we'll be asked to delete the half-created
12610 watchpoint. In that case, don't announce the deletion. */
12612 notify_breakpoint_deleted (bpt
);
12614 breakpoint_chain
.erase (breakpoint_chain
.iterator_to (*bpt
));
12616 /* Be sure no bpstat's are pointing at the breakpoint after it's
12618 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12619 in all threads for now. Note that we cannot just remove bpstats
12620 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12621 commands are associated with the bpstat; if we remove it here,
12622 then the later call to bpstat_do_actions (&stop_bpstat); in
12623 event-top.c won't do anything, and temporary breakpoints with
12624 commands won't work. */
12626 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12628 /* Now that breakpoint is removed from breakpoint list, update the
12629 global location list. This will remove locations that used to
12630 belong to this breakpoint. Do this before freeing the breakpoint
12631 itself, since remove_breakpoint looks at location's owner. It
12632 might be better design to have location completely
12633 self-contained, but it's not the case now.
12635 Clear the location linked list first, otherwise, the intrusive_list
12636 destructor accesses the locations after they are freed. */
12637 bpt
->clear_locations ();
12638 update_global_location_list (UGLL_DONT_INSERT
);
12640 /* On the chance that someone will soon try again to delete this
12641 same bp, we mark it as deleted before freeing its storage. */
12642 bpt
->type
= bp_none
;
12646 /* Iterator function to call a user-provided callback function once
12647 for each of B and its related breakpoints. */
12650 iterate_over_related_breakpoints (struct breakpoint
*b
,
12651 gdb::function_view
<void (breakpoint
*)> function
)
12653 struct breakpoint
*related
;
12658 struct breakpoint
*next
;
12660 /* FUNCTION may delete RELATED. */
12661 next
= related
->related_breakpoint
;
12663 if (next
== related
)
12665 /* RELATED is the last ring entry. */
12666 function (related
);
12668 /* FUNCTION may have deleted it, so we'd never reach back to
12669 B. There's nothing left to do anyway, so just break
12674 function (related
);
12678 while (related
!= b
);
12682 delete_command (const char *arg
, int from_tty
)
12688 int breaks_to_delete
= 0;
12690 /* Delete all breakpoints, watchpoints, tracepoints, and catchpoints
12691 if no argument. Do not delete internal breakpoints, these have to
12692 be deleted with an explicit breakpoint number argument. */
12693 for (breakpoint
&b
: all_breakpoints ())
12694 if (user_breakpoint_p (&b
))
12696 breaks_to_delete
= 1;
12700 /* Ask user only if there are some breakpoints to delete. */
12702 || (breaks_to_delete
12703 && query (_("Delete all breakpoints, watchpoints, tracepoints, "
12704 "and catchpoints? "))))
12705 for (breakpoint
&b
: all_breakpoints_safe ())
12706 if (user_breakpoint_p (&b
))
12707 delete_breakpoint (&b
);
12710 map_breakpoint_numbers
12711 (arg
, [&] (breakpoint
*br
)
12713 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12717 /* Return true if all locations of B bound to PSPACE are pending. If
12718 PSPACE is NULL, all locations of all program spaces are
12722 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12724 for (bp_location
&loc
: b
->locations ())
12725 if ((pspace
== NULL
12726 || loc
.pspace
== pspace
)
12727 && !loc
.shlib_disabled
12728 && !loc
.pspace
->executing_startup
)
12733 /* Subroutine of update_breakpoint_locations to simplify it.
12734 Return true if multiple fns in list LOCS have the same name.
12735 Null names are ignored. */
12738 ambiguous_names_p (const bp_location_range
&locs
)
12740 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12743 for (const bp_location
&l
: locs
)
12746 const char *name
= l
.function_name
.get ();
12748 /* Allow for some names to be NULL, ignore them. */
12752 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12754 /* NOTE: We can assume slot != NULL here because xcalloc never
12764 /* When symbols change, it probably means the sources changed as well,
12765 and it might mean the static tracepoint markers are no longer at
12766 the same address or line numbers they used to be at last we
12767 checked. Losing your static tracepoints whenever you rebuild is
12768 undesirable. This function tries to resync/rematch gdb static
12769 tracepoints with the markers on the target, for static tracepoints
12770 that have not been set by marker id. Static tracepoint that have
12771 been set by marker id are reset by marker id in breakpoint_re_set.
12774 1) For a tracepoint set at a specific address, look for a marker at
12775 the old PC. If one is found there, assume to be the same marker.
12776 If the name / string id of the marker found is different from the
12777 previous known name, assume that means the user renamed the marker
12778 in the sources, and output a warning.
12780 2) For a tracepoint set at a given line number, look for a marker
12781 at the new address of the old line number. If one is found there,
12782 assume to be the same marker. If the name / string id of the
12783 marker found is different from the previous known name, assume that
12784 means the user renamed the marker in the sources, and output a
12787 3) If a marker is no longer found at the same address or line, it
12788 may mean the marker no longer exists. But it may also just mean
12789 the code changed a bit. Maybe the user added a few lines of code
12790 that made the marker move up or down (in line number terms). Ask
12791 the target for info about the marker with the string id as we knew
12792 it. If found, update line number and address in the matching
12793 static tracepoint. This will get confused if there's more than one
12794 marker with the same ID (possible in UST, although unadvised
12795 precisely because it confuses tools). */
12797 static struct symtab_and_line
12798 update_static_tracepoint (tracepoint
*tp
, struct symtab_and_line sal
)
12800 struct static_tracepoint_marker marker
;
12805 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12807 if (target_static_tracepoint_marker_at (pc
, &marker
))
12809 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12810 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12811 tp
->number
, tp
->static_trace_marker_id
.c_str (),
12812 marker
.str_id
.c_str ());
12814 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12819 /* Old marker wasn't found on target at lineno. Try looking it up
12821 if (!sal
.explicit_pc
12823 && sal
.symtab
!= NULL
12824 && !tp
->static_trace_marker_id
.empty ())
12826 std::vector
<static_tracepoint_marker
> markers
12827 = target_static_tracepoint_markers_by_strid
12828 (tp
->static_trace_marker_id
.c_str ());
12830 if (!markers
.empty ())
12832 struct symbol
*sym
;
12833 struct static_tracepoint_marker
*tpmarker
;
12834 struct ui_out
*uiout
= current_uiout
;
12836 tpmarker
= &markers
[0];
12838 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12840 warning (_("marker for static tracepoint %d (%s) not "
12841 "found at previous line number"),
12842 tp
->number
, tp
->static_trace_marker_id
.c_str ());
12844 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12845 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12846 uiout
->text ("Now in ");
12849 uiout
->field_string ("func", sym
->print_name (),
12850 function_name_style
.style ());
12851 uiout
->text (" at ");
12853 uiout
->field_string ("file",
12854 symtab_to_filename_for_display (sal2
.symtab
),
12855 file_name_style
.style ());
12858 if (uiout
->is_mi_like_p ())
12860 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12862 uiout
->field_string ("fullname", fullname
);
12865 uiout
->field_signed ("line", sal2
.line
, line_number_style
.style ());
12866 uiout
->text ("\n");
12868 tp
->first_loc ().line_number
= sal2
.line
;
12869 tp
->first_loc ().symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12871 std::unique_ptr
<explicit_location_spec
> els
12872 (new explicit_location_spec
12873 (symtab_to_filename_for_display (sal2
.symtab
)));
12874 els
->line_offset
.offset
= tp
->first_loc ().line_number
;
12875 els
->line_offset
.sign
= LINE_OFFSET_NONE
;
12877 tp
->locspec
= std::move (els
);
12879 /* Might be nice to check if function changed, and warn if
12886 /* Returns true iff location lists A and B are sufficiently same that
12887 we don't need to report breakpoint as changed. */
12890 locations_are_equal (const bp_location_list
&a
, const bp_location_range
&b
)
12892 auto a_iter
= a
.begin ();
12893 auto b_iter
= b
.begin ();
12895 for (; a_iter
!= a
.end () && b_iter
!= b
.end (); ++a_iter
, ++b_iter
)
12897 if (a_iter
->address
!= b_iter
->address
)
12900 if (a_iter
->shlib_disabled
!= b_iter
->shlib_disabled
)
12903 if (a_iter
->enabled
!= b_iter
->enabled
)
12906 if (a_iter
->disabled_by_cond
!= b_iter
->disabled_by_cond
)
12909 /* When a breakpoint is set by address, it is not created as
12910 pending; but then during an solib event or the like it may
12911 acquire a symbol. So, check this here. */
12912 if (a_iter
->symbol
!= b_iter
->symbol
12913 || a_iter
->msymbol
!= b_iter
->msymbol
)
12917 return (a_iter
== a
.end ()) == (b_iter
== b
.end ());
12920 /* See breakpoint.h. */
12923 breakpoint::steal_locations (program_space
*pspace
)
12925 if (pspace
== NULL
)
12926 return std::move (m_locations
);
12928 bp_location_list ret
;
12930 for (auto it
= m_locations
.begin (); it
!= m_locations
.end (); )
12932 if (it
->pspace
== pspace
)
12934 bp_location
&loc
= *it
;
12935 it
= m_locations
.erase (it
);
12936 ret
.push_back (loc
);
12945 /* Create new breakpoint locations for B (a hardware or software
12946 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12947 zero, then B is a ranged breakpoint. Only recreates locations for
12948 FILTER_PSPACE. Locations of other program spaces are left
12952 update_breakpoint_locations (code_breakpoint
*b
,
12953 struct program_space
*filter_pspace
,
12954 gdb::array_view
<const symtab_and_line
> sals
,
12955 gdb::array_view
<const symtab_and_line
> sals_end
)
12957 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12959 /* Ranged breakpoints have only one start location and one end
12961 b
->enable_state
= bp_disabled
;
12962 gdb_printf (gdb_stderr
,
12963 _("Could not reset ranged breakpoint %d: "
12964 "multiple locations found\n"),
12969 /* If there's no new locations, and all existing locations are
12970 pending, don't do anything. This optimizes the common case where
12971 all locations are in the same shared library, that was unloaded.
12972 We'd like to retain the location, so that when the library is
12973 loaded again, we don't loose the enabled/disabled status of the
12974 individual locations. */
12975 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12978 bp_location_list existing_locations
= b
->steal_locations (filter_pspace
);
12980 for (const auto &sal
: sals
)
12982 struct bp_location
*new_loc
;
12984 switch_to_program_space_and_thread (sal
.pspace
);
12986 new_loc
= b
->add_location (sal
);
12988 /* Reparse conditions, they might contain references to the
12990 if (b
->cond_string
!= NULL
)
12994 s
= b
->cond_string
.get ();
12997 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12998 block_for_pc (sal
.pc
),
13001 catch (const gdb_exception_error
&e
)
13003 new_loc
->disabled_by_cond
= true;
13007 if (!sals_end
.empty ())
13009 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13011 new_loc
->length
= end
- sals
[0].pc
+ 1;
13015 /* If possible, carry over 'disable' status from existing
13018 /* If there are multiple breakpoints with the same function name,
13019 e.g. for inline functions, comparing function names won't work.
13020 Instead compare pc addresses; this is just a heuristic as things
13021 may have moved, but in practice it gives the correct answer
13022 often enough until a better solution is found. */
13023 int have_ambiguous_names
= ambiguous_names_p (b
->locations ());
13025 for (const bp_location
&e
: existing_locations
)
13027 if ((!e
.enabled
|| e
.disabled_by_cond
) && e
.function_name
)
13029 if (have_ambiguous_names
)
13031 for (bp_location
&l
: b
->locations ())
13033 /* Ignore software vs hardware location type at
13034 this point, because with "set breakpoint
13035 auto-hw", after a re-set, locations that were
13036 hardware can end up as software, or vice versa.
13037 As mentioned above, this is an heuristic and in
13038 practice should give the correct answer often
13040 if (breakpoint_locations_match (&e
, &l
, true))
13042 l
.enabled
= e
.enabled
;
13043 l
.disabled_by_cond
= e
.disabled_by_cond
;
13050 for (bp_location
&l
: b
->locations ())
13051 if (l
.function_name
13052 && strcmp (e
.function_name
.get (),
13053 l
.function_name
.get ()) == 0)
13055 l
.enabled
= e
.enabled
;
13056 l
.disabled_by_cond
= e
.disabled_by_cond
;
13064 if (!locations_are_equal (existing_locations
, b
->locations ()))
13065 notify_breakpoint_modified (b
);
13068 /* Find the SaL locations corresponding to the given LOCSPEC.
13069 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13071 std::vector
<symtab_and_line
>
13072 code_breakpoint::location_spec_to_sals (location_spec
*locspec
,
13073 struct program_space
*search_pspace
,
13076 struct gdb_exception exception
;
13078 std::vector
<symtab_and_line
> sals
;
13082 sals
= decode_location_spec (locspec
, search_pspace
);
13084 catch (gdb_exception_error
&e
)
13086 int not_found_and_ok
= false;
13088 /* For pending breakpoints, it's expected that parsing will
13089 fail until the right shared library is loaded. User has
13090 already told to create pending breakpoints and don't need
13091 extra messages. If breakpoint is in bp_shlib_disabled
13092 state, then user already saw the message about that
13093 breakpoint being disabled, and don't want to see more
13095 if (e
.error
== NOT_FOUND_ERROR
13096 && (condition_not_parsed
13097 || (this->has_locations ()
13098 && search_pspace
!= NULL
13099 && this->first_loc ().pspace
!= search_pspace
)
13100 || (this->has_locations () && this->first_loc ().shlib_disabled
)
13101 || (this->has_locations ()
13102 && this->first_loc ().pspace
->executing_startup
)
13103 || enable_state
== bp_disabled
))
13104 not_found_and_ok
= true;
13106 if (!not_found_and_ok
)
13108 /* We surely don't want to warn about the same breakpoint
13109 10 times. One solution, implemented here, is disable
13110 the breakpoint on error. Another solution would be to
13111 have separate 'warning emitted' flag. Since this
13112 happens only when a binary has changed, I don't know
13113 which approach is better. */
13114 enable_state
= bp_disabled
;
13118 exception
= std::move (e
);
13121 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13123 for (auto &sal
: sals
)
13124 resolve_sal_pc (&sal
);
13126 if (type
== bp_static_tracepoint
)
13128 tracepoint
*t
= gdb::checked_static_cast
<tracepoint
*> (this);
13129 sals
[0] = update_static_tracepoint (t
, sals
[0]);
13140 /* The default re_set method, for typical hardware or software
13141 breakpoints. Reevaluate the breakpoint and recreate its
13145 code_breakpoint::re_set_default (struct program_space
*filter_pspace
)
13147 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13149 /* If this breakpoint is thread- or inferior-specific, then find the
13150 program space in which this breakpoint exists. Otherwise, for
13151 breakpoints that are not thread- or inferior-specific, BP_PSPACE will
13153 program_space
*bp_pspace
13154 = find_program_space_for_breakpoint (this->thread
, this->inferior
);
13156 /* If this is not a thread or inferior specific breakpoint, or it is a
13157 thread or inferior specific breakpoint but we are looking for new
13158 locations in the program space that the specific thread or inferior is
13159 running, then look for new locations for this breakpoint. */
13160 if (bp_pspace
== nullptr || filter_pspace
== bp_pspace
)
13163 std::vector
<symtab_and_line
> sals
13164 = location_spec_to_sals (locspec
.get (), filter_pspace
, &found
);
13166 expanded
= std::move (sals
);
13168 if (locspec_range_end
!= nullptr)
13170 std::vector
<symtab_and_line
> sals_end
13171 = location_spec_to_sals (locspec_range_end
.get (),
13172 filter_pspace
, &found
);
13174 expanded_end
= std::move (sals_end
);
13178 /* Update the locations for this breakpoint. For thread-specific
13179 breakpoints this will remove any old locations that are for the wrong
13180 program space -- this can happen if the user changes the thread of a
13181 thread-specific breakpoint. */
13182 update_breakpoint_locations (this, filter_pspace
, expanded
, expanded_end
);
13185 /* Re-set breakpoint locations for the current program space.
13186 Locations bound to other program spaces are left untouched. */
13189 breakpoint_re_set (void)
13192 scoped_restore_current_language save_language
;
13193 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13194 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13196 /* To ::re_set each breakpoint we set the current_language to the
13197 language of the breakpoint before re-evaluating the breakpoint's
13198 location. This change can unfortunately get undone by accident if
13199 the language_mode is set to auto, and we either switch frames, or
13200 more likely in this context, we select the current frame.
13202 We prevent this by temporarily turning the language_mode to
13203 language_mode_manual. We restore it once all breakpoints
13204 have been reset. */
13205 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13206 language_mode
= language_mode_manual
;
13208 /* Note: we must not try to insert locations until after all
13209 breakpoints have been re-set. Otherwise, e.g., when re-setting
13210 breakpoint 1, we'd insert the locations of breakpoint 2, which
13211 hadn't been re-set yet, and thus may have stale locations. */
13213 for (breakpoint
&b
: all_breakpoints_safe ())
13217 input_radix
= b
.input_radix
;
13218 set_language (b
.language
);
13219 b
.re_set (current_program_space
);
13221 catch (const gdb_exception
&ex
)
13223 exception_fprintf (gdb_stderr
, ex
,
13224 "Error in re-setting breakpoint %d: ",
13229 jit_breakpoint_re_set ();
13232 create_overlay_event_breakpoint ();
13233 create_longjmp_master_breakpoint ();
13234 create_std_terminate_master_breakpoint ();
13235 create_exception_master_breakpoint ();
13237 /* Now we can insert. */
13238 update_global_location_list (UGLL_MAY_INSERT
);
13241 /* Re-set locations for breakpoint B in FILTER_PSPACE. If FILTER_PSPACE is
13242 nullptr then re-set locations for B in all program spaces. Locations
13243 bound to program spaces other than FILTER_PSPACE are left untouched. */
13246 breakpoint_re_set_one (breakpoint
*b
, program_space
*filter_pspace
)
13249 scoped_restore_current_language save_language
;
13250 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13251 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13253 /* To ::re_set each breakpoint we set the current_language to the
13254 language of the breakpoint before re-evaluating the breakpoint's
13255 location. This change can unfortunately get undone by accident if
13256 the language_mode is set to auto, and we either switch frames, or
13257 more likely in this context, we select the current frame.
13259 We prevent this by temporarily turning the language_mode to
13260 language_mode_manual. We restore it once all breakpoints
13261 have been reset. */
13262 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13263 language_mode
= language_mode_manual
;
13265 /* Note: we must not try to insert locations until after all
13266 breakpoints have been re-set. Otherwise, e.g., when re-setting
13267 breakpoint 1, we'd insert the locations of breakpoint 2, which
13268 hadn't been re-set yet, and thus may have stale locations. */
13272 input_radix
= b
->input_radix
;
13273 set_language (b
->language
);
13274 b
->re_set (filter_pspace
);
13276 catch (const gdb_exception
&ex
)
13278 exception_fprintf (gdb_stderr
, ex
,
13279 "Error in re-setting breakpoint %d: ",
13284 /* Now we can insert. */
13285 update_global_location_list (UGLL_MAY_INSERT
);
13288 /* Reset the thread number of this breakpoint:
13290 - If the breakpoint is for all threads, leave it as-is.
13291 - Else, reset it to the current thread for inferior_ptid. */
13293 breakpoint_re_set_thread (struct breakpoint
*b
)
13295 if (b
->thread
!= -1)
13297 b
->thread
= inferior_thread ()->global_num
;
13299 /* We're being called after following a fork. The new fork is
13300 selected as current, and unless this was a vfork will have a
13301 different program space from the original thread. Reset that
13303 b
->first_loc ().pspace
= current_program_space
;
13307 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13308 If from_tty is nonzero, it prints a message to that effect,
13309 which ends with a period (no newline). */
13312 set_ignore_count (int bptnum
, int count
, int from_tty
)
13317 for (breakpoint
&b
: all_breakpoints ())
13318 if (b
.number
== bptnum
)
13320 if (is_tracepoint (&b
))
13322 if (from_tty
&& count
!= 0)
13323 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13328 b
.ignore_count
= count
;
13332 gdb_printf (_("Will stop next time "
13333 "breakpoint %d is reached."),
13335 else if (count
== 1)
13336 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13339 gdb_printf (_("Will ignore next %d "
13340 "crossings of breakpoint %d."),
13343 notify_breakpoint_modified (&b
);
13347 error (_("No breakpoint number %d."), bptnum
);
13350 /* Command to set ignore-count of breakpoint N to COUNT. */
13353 ignore_command (const char *args
, int from_tty
)
13355 const char *p
= args
;
13359 error_no_arg (_("a breakpoint number"));
13361 num
= get_number (&p
);
13363 error (_("bad breakpoint number: '%s'"), args
);
13365 error (_("Second argument (specified ignore-count) is missing."));
13367 set_ignore_count (num
,
13368 longest_to_int (value_as_long (parse_and_eval (p
))),
13375 /* Call FUNCTION on each of the breakpoints with numbers in the range
13376 defined by BP_NUM_RANGE (an inclusive range). */
13379 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13380 gdb::function_view
<void (breakpoint
*)> function
)
13382 if (bp_num_range
.first
== 0)
13384 warning (_("bad breakpoint number at or near '%d'"),
13385 bp_num_range
.first
);
13389 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13391 bool match
= false;
13393 for (breakpoint
&b
: all_breakpoints_safe ())
13401 gdb_printf (_("No breakpoint number %d.\n"), i
);
13406 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13410 map_breakpoint_numbers (const char *args
,
13411 gdb::function_view
<void (breakpoint
*)> function
)
13413 if (args
== NULL
|| *args
== '\0')
13414 error_no_arg (_("one or more breakpoint numbers"));
13416 number_or_range_parser
parser (args
);
13418 while (!parser
.finished ())
13420 int num
= parser
.get_number ();
13421 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13425 /* Return the breakpoint location structure corresponding to the
13426 BP_NUM and LOC_NUM values. */
13428 static struct bp_location
*
13429 find_location_by_number (int bp_num
, int loc_num
)
13431 breakpoint
*b
= get_breakpoint (bp_num
);
13433 if (!b
|| b
->number
!= bp_num
)
13434 error (_("Bad breakpoint number '%d'"), bp_num
);
13437 error (_("Bad breakpoint location number '%d'"), loc_num
);
13440 for (bp_location
&loc
: b
->locations ())
13441 if (++n
== loc_num
)
13444 error (_("Bad breakpoint location number '%d'"), loc_num
);
13447 /* Modes of operation for extract_bp_num. */
13448 enum class extract_bp_kind
13450 /* Extracting a breakpoint number. */
13453 /* Extracting a location number. */
13457 /* Extract a breakpoint or location number (as determined by KIND)
13458 from the string starting at START. TRAILER is a character which
13459 can be found after the number. If you don't want a trailer, use
13460 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13461 string. This always returns a positive integer. */
13464 extract_bp_num (extract_bp_kind kind
, const char *start
,
13465 int trailer
, const char **end_out
= NULL
)
13467 const char *end
= start
;
13468 int num
= get_number_trailer (&end
, trailer
);
13470 error (kind
== extract_bp_kind::bp
13471 ? _("Negative breakpoint number '%.*s'")
13472 : _("Negative breakpoint location number '%.*s'"),
13473 int (end
- start
), start
);
13475 error (kind
== extract_bp_kind::bp
13476 ? _("Bad breakpoint number '%.*s'")
13477 : _("Bad breakpoint location number '%.*s'"),
13478 int (end
- start
), start
);
13480 if (end_out
!= NULL
)
13485 /* Extract a breakpoint or location range (as determined by KIND) in
13486 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13487 representing the (inclusive) range. The returned pair's elements
13488 are always positive integers. */
13490 static std::pair
<int, int>
13491 extract_bp_or_bp_range (extract_bp_kind kind
,
13492 const std::string
&arg
,
13493 std::string::size_type arg_offset
)
13495 std::pair
<int, int> range
;
13496 const char *bp_loc
= &arg
[arg_offset
];
13497 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13498 if (dash
!= std::string::npos
)
13500 /* bp_loc is a range (x-z). */
13501 if (arg
.length () == dash
+ 1)
13502 error (kind
== extract_bp_kind::bp
13503 ? _("Bad breakpoint number at or near: '%s'")
13504 : _("Bad breakpoint location number at or near: '%s'"),
13508 const char *start_first
= bp_loc
;
13509 const char *start_second
= &arg
[dash
+ 1];
13510 range
.first
= extract_bp_num (kind
, start_first
, '-');
13511 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13513 if (range
.first
> range
.second
)
13514 error (kind
== extract_bp_kind::bp
13515 ? _("Inverted breakpoint range at '%.*s'")
13516 : _("Inverted breakpoint location range at '%.*s'"),
13517 int (end
- start_first
), start_first
);
13521 /* bp_loc is a single value. */
13522 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13523 range
.second
= range
.first
;
13528 /* Extract the breakpoint/location range specified by ARG. Returns
13529 the breakpoint range in BP_NUM_RANGE, and the location range in
13532 ARG may be in any of the following forms:
13534 x where 'x' is a breakpoint number.
13535 x-y where 'x' and 'y' specify a breakpoint numbers range.
13536 x.y where 'x' is a breakpoint number and 'y' a location number.
13537 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13538 location number range.
13542 extract_bp_number_and_location (const std::string
&arg
,
13543 std::pair
<int, int> &bp_num_range
,
13544 std::pair
<int, int> &bp_loc_range
)
13546 std::string::size_type dot
= arg
.find ('.');
13548 if (dot
!= std::string::npos
)
13550 /* Handle 'x.y' and 'x.y-z' cases. */
13552 if (arg
.length () == dot
+ 1 || dot
== 0)
13553 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13556 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13557 bp_num_range
.second
= bp_num_range
.first
;
13559 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13564 /* Handle x and x-y cases. */
13566 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13567 bp_loc_range
.first
= 0;
13568 bp_loc_range
.second
= 0;
13572 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13573 specifies whether to enable or disable. */
13576 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13578 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13581 if (loc
->disabled_by_cond
&& enable
)
13582 error (_("Breakpoint %d's condition is invalid at location %d, "
13583 "cannot enable."), bp_num
, loc_num
);
13585 if (loc
->enabled
!= enable
)
13587 loc
->enabled
= enable
;
13588 mark_breakpoint_location_modified (loc
);
13590 if (target_supports_enable_disable_tracepoint ()
13591 && current_trace_status ()->running
&& loc
->owner
13592 && is_tracepoint (loc
->owner
))
13593 target_disable_tracepoint (loc
);
13595 update_global_location_list (UGLL_DONT_INSERT
);
13597 notify_breakpoint_modified (loc
->owner
);
13600 /* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
13601 owner. 1-based indexing. -1 signals NOT FOUND. */
13604 find_loc_num_by_location (const bp_location
*loc
)
13606 if (loc
!= nullptr && loc
->owner
!= nullptr)
13608 /* Locations use 1-based indexing. */
13610 for (bp_location
&it
: loc
->owner
->locations ())
13620 /* Enable or disable a breakpoint location LOC. ENABLE
13621 specifies whether to enable or disable. */
13624 enable_disable_bp_location (bp_location
*loc
, bool enable
)
13626 if (loc
== nullptr)
13627 error (_("Breakpoint location is invalid."));
13629 if (loc
->owner
== nullptr)
13630 error (_("Breakpoint location does not have an owner breakpoint."));
13632 if (loc
->disabled_by_cond
&& enable
)
13634 int loc_num
= find_loc_num_by_location (loc
);
13636 error (_("Breakpoint location LOC_NUM could not be found."));
13638 error (_("Breakpoint %d's condition is invalid at location %d, "
13639 "cannot enable."), loc
->owner
->number
, loc_num
);
13642 if (loc
->enabled
!= enable
)
13644 loc
->enabled
= enable
;
13645 mark_breakpoint_location_modified (loc
);
13648 if (target_supports_enable_disable_tracepoint ()
13649 && current_trace_status ()->running
&& loc
->owner
13650 && is_tracepoint (loc
->owner
))
13651 target_disable_tracepoint (loc
);
13653 update_global_location_list (UGLL_DONT_INSERT
);
13654 notify_breakpoint_modified (loc
->owner
);
13657 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13658 number of the breakpoint, and BP_LOC_RANGE specifies the
13659 (inclusive) range of location numbers of that breakpoint to
13660 enable/disable. ENABLE specifies whether to enable or disable the
13664 enable_disable_breakpoint_location_range (int bp_num
,
13665 std::pair
<int, int> &bp_loc_range
,
13668 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13669 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13672 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13673 If from_tty is nonzero, it prints a message to that effect,
13674 which ends with a period (no newline). */
13677 disable_breakpoint (struct breakpoint
*bpt
)
13679 /* Never disable a watchpoint scope breakpoint; we want to
13680 hit them when we leave scope so we can delete both the
13681 watchpoint and its scope breakpoint at that time. */
13682 if (bpt
->type
== bp_watchpoint_scope
)
13685 bpt
->enable_state
= bp_disabled
;
13687 /* Mark breakpoint locations modified. */
13688 mark_breakpoint_modified (bpt
);
13690 if (target_supports_enable_disable_tracepoint ()
13691 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13693 for (bp_location
&location
: bpt
->locations ())
13694 target_disable_tracepoint (&location
);
13697 update_global_location_list (UGLL_DONT_INSERT
);
13699 notify_breakpoint_modified (bpt
);
13702 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13703 specified in ARGS. ARGS may be in any of the formats handled by
13704 extract_bp_number_and_location. ENABLE specifies whether to enable
13705 or disable the breakpoints/locations. */
13708 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13712 for (breakpoint
&bpt
: all_breakpoints ())
13713 if (user_breakpoint_p (&bpt
))
13716 enable_breakpoint (&bpt
);
13718 disable_breakpoint (&bpt
);
13723 std::string num
= extract_arg (&args
);
13725 while (!num
.empty ())
13727 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13729 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13731 if (bp_loc_range
.first
== bp_loc_range
.second
13732 && (bp_loc_range
.first
== 0
13733 || (bp_loc_range
.first
== 1
13734 && bp_num_range
.first
== bp_num_range
.second
13735 && !has_multiple_locations (bp_num_range
.first
))))
13737 /* Handle breakpoint ids with formats 'x' or 'x-z'
13738 or 'y.1' where y has only one code location. */
13739 map_breakpoint_number_range (bp_num_range
,
13741 ? enable_breakpoint
13742 : disable_breakpoint
);
13746 /* Handle breakpoint ids with formats 'x.y' or
13748 enable_disable_breakpoint_location_range
13749 (bp_num_range
.first
, bp_loc_range
, enable
);
13751 num
= extract_arg (&args
);
13756 /* The disable command disables the specified breakpoints/locations
13757 (or all defined breakpoints) so they're no longer effective in
13758 stopping the inferior. ARGS may be in any of the forms defined in
13759 extract_bp_number_and_location. */
13762 disable_command (const char *args
, int from_tty
)
13764 enable_disable_command (args
, from_tty
, false);
13768 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13771 int target_resources_ok
;
13773 if (bpt
->type
== bp_hardware_breakpoint
)
13776 i
= hw_breakpoint_used_count ();
13777 target_resources_ok
=
13778 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13780 if (target_resources_ok
== 0)
13781 error (_("No hardware breakpoint support in the target."));
13782 else if (target_resources_ok
< 0)
13783 error (_("Hardware breakpoints used exceeds limit."));
13786 if (is_watchpoint (bpt
))
13788 /* Initialize it just to avoid a GCC false warning. */
13789 enum enable_state orig_enable_state
= bp_disabled
;
13793 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (bpt
);
13795 orig_enable_state
= bpt
->enable_state
;
13796 bpt
->enable_state
= bp_enabled
;
13797 update_watchpoint (w
, true /* reparse */);
13799 catch (const gdb_exception_error
&e
)
13801 bpt
->enable_state
= orig_enable_state
;
13802 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13808 bpt
->enable_state
= bp_enabled
;
13810 /* Mark breakpoint locations modified. */
13811 mark_breakpoint_modified (bpt
);
13813 if (target_supports_enable_disable_tracepoint ()
13814 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13816 for (bp_location
&location
: bpt
->locations ())
13817 target_enable_tracepoint (&location
);
13820 bpt
->disposition
= disposition
;
13821 bpt
->enable_count
= count
;
13822 update_global_location_list (UGLL_MAY_INSERT
);
13824 notify_breakpoint_modified (bpt
);
13829 enable_breakpoint (struct breakpoint
*bpt
)
13831 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13834 /* The enable command enables the specified breakpoints/locations (or
13835 all defined breakpoints) so they once again become (or continue to
13836 be) effective in stopping the inferior. ARGS may be in any of the
13837 forms defined in extract_bp_number_and_location. */
13840 enable_command (const char *args
, int from_tty
)
13842 enable_disable_command (args
, from_tty
, true);
13846 enable_once_command (const char *args
, int from_tty
)
13848 map_breakpoint_numbers
13849 (args
, [&] (breakpoint
*b
)
13851 iterate_over_related_breakpoints
13852 (b
, [&] (breakpoint
*bpt
)
13854 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13860 enable_count_command (const char *args
, int from_tty
)
13865 error_no_arg (_("hit count"));
13867 count
= get_number (&args
);
13869 map_breakpoint_numbers
13870 (args
, [&] (breakpoint
*b
)
13872 iterate_over_related_breakpoints
13873 (b
, [&] (breakpoint
*bpt
)
13875 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13881 enable_delete_command (const char *args
, int from_tty
)
13883 map_breakpoint_numbers
13884 (args
, [&] (breakpoint
*b
)
13886 iterate_over_related_breakpoints
13887 (b
, [&] (breakpoint
*bpt
)
13889 enable_breakpoint_disp (bpt
, disp_del
, 1);
13894 /* Invalidate last known value of any hardware watchpoint if
13895 the memory which that value represents has been written to by
13899 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13900 CORE_ADDR addr
, ssize_t len
,
13901 const bfd_byte
*data
)
13903 for (breakpoint
&bp
: all_breakpoints ())
13904 if (bp
.enable_state
== bp_enabled
13905 && bp
.type
== bp_hardware_watchpoint
)
13907 watchpoint
&wp
= gdb::checked_static_cast
<watchpoint
&> (bp
);
13909 if (wp
.val_valid
&& wp
.val
!= nullptr)
13911 for (bp_location
&loc
: bp
.locations ())
13912 if (loc
.loc_type
== bp_loc_hardware_watchpoint
13913 && loc
.address
+ loc
.length
> addr
13914 && addr
+ len
> loc
.address
)
13917 wp
.val_valid
= false;
13923 /* Create and insert a breakpoint for software single step. */
13926 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13927 const address_space
*aspace
,
13930 struct thread_info
*tp
= inferior_thread ();
13931 struct symtab_and_line sal
;
13932 CORE_ADDR pc
= next_pc
;
13934 if (tp
->control
.single_step_breakpoints
== NULL
)
13936 std::unique_ptr
<breakpoint
> b
13937 (new momentary_breakpoint (gdbarch
, bp_single_step
,
13938 current_program_space
,
13942 tp
->control
.single_step_breakpoints
13943 = add_to_breakpoint_chain (std::move (b
));
13946 sal
= find_pc_line (pc
, 0);
13948 sal
.section
= find_pc_overlay (pc
);
13949 sal
.explicit_pc
= 1;
13952 = (gdb::checked_static_cast
<momentary_breakpoint
*>
13953 (tp
->control
.single_step_breakpoints
));
13954 ss_bp
->add_location (sal
);
13956 update_global_location_list (UGLL_INSERT
);
13959 /* Insert single step breakpoints according to the current state. */
13962 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13964 regcache
*regcache
= get_thread_regcache (inferior_thread ());
13965 std::vector
<CORE_ADDR
> next_pcs
;
13967 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13969 if (!next_pcs
.empty ())
13971 frame_info_ptr frame
= get_current_frame ();
13972 const address_space
*aspace
= get_frame_address_space (frame
);
13974 for (CORE_ADDR pc
: next_pcs
)
13975 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13983 /* See breakpoint.h. */
13986 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13987 const address_space
*aspace
,
13990 for (bp_location
&loc
: bp
->locations ())
13992 && breakpoint_location_address_match (&loc
, aspace
, pc
))
13998 /* Check whether a software single-step breakpoint is inserted at
14002 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14005 for (breakpoint
&bpt
: all_breakpoints ())
14007 if (bpt
.type
== bp_single_step
14008 && breakpoint_has_location_inserted_here (&bpt
, aspace
, pc
))
14014 /* Tracepoint-specific operations. */
14016 /* Set tracepoint count to NUM. */
14018 set_tracepoint_count (int num
)
14020 tracepoint_count
= num
;
14021 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14025 trace_command (const char *arg
, int from_tty
)
14027 location_spec_up locspec
= string_to_location_spec (&arg
,
14029 const struct breakpoint_ops
*ops
= breakpoint_ops_for_location_spec
14030 (locspec
.get (), true /* is_tracepoint */);
14032 create_breakpoint (get_current_arch (),
14034 NULL
, -1, -1, arg
, false, 1 /* parse arg */,
14036 bp_tracepoint
/* type_wanted */,
14037 0 /* Ignore count */,
14038 pending_break_support
,
14042 0 /* internal */, 0);
14046 ftrace_command (const char *arg
, int from_tty
)
14048 location_spec_up locspec
= string_to_location_spec (&arg
,
14050 create_breakpoint (get_current_arch (),
14052 NULL
, -1, -1, arg
, false, 1 /* parse arg */,
14054 bp_fast_tracepoint
/* type_wanted */,
14055 0 /* Ignore count */,
14056 pending_break_support
,
14057 &code_breakpoint_ops
,
14060 0 /* internal */, 0);
14063 /* strace command implementation. Creates a static tracepoint. */
14066 strace_command (const char *arg
, int from_tty
)
14068 const struct breakpoint_ops
*ops
;
14069 location_spec_up locspec
;
14072 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14073 or with a normal static tracepoint. */
14074 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14076 ops
= &strace_marker_breakpoint_ops
;
14077 locspec
= new_linespec_location_spec (&arg
,
14078 symbol_name_match_type::FULL
);
14079 type
= bp_static_marker_tracepoint
;
14083 ops
= &code_breakpoint_ops
;
14084 locspec
= string_to_location_spec (&arg
, current_language
);
14085 type
= bp_static_tracepoint
;
14088 create_breakpoint (get_current_arch (),
14090 NULL
, -1, -1, arg
, false, 1 /* parse arg */,
14092 type
/* type_wanted */,
14093 0 /* Ignore count */,
14094 pending_break_support
,
14098 0 /* internal */, 0);
14101 /* Set up a fake reader function that gets command lines from a linked
14102 list that was acquired during tracepoint uploading. */
14104 static struct uploaded_tp
*this_utp
;
14105 static int next_cmd
;
14107 static const char *
14108 read_uploaded_action (std::string
&buffer
)
14110 char *rslt
= nullptr;
14112 if (next_cmd
< this_utp
->cmd_strings
.size ())
14114 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14121 /* Given information about a tracepoint as recorded on a target (which
14122 can be either a live system or a trace file), attempt to create an
14123 equivalent GDB tracepoint. This is not a reliable process, since
14124 the target does not necessarily have all the information used when
14125 the tracepoint was originally defined. */
14127 struct tracepoint
*
14128 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14130 const char *addr_str
;
14131 char small_buf
[100];
14132 struct tracepoint
*tp
;
14134 if (utp
->at_string
)
14135 addr_str
= utp
->at_string
.get ();
14138 /* In the absence of a source location, fall back to raw
14139 address. Since there is no way to confirm that the address
14140 means the same thing as when the trace was started, warn the
14142 warning (_("Uploaded tracepoint %d has no "
14143 "source location, using raw address"),
14145 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14146 addr_str
= small_buf
;
14149 /* There's not much we can do with a sequence of bytecodes. */
14150 if (utp
->cond
&& !utp
->cond_string
)
14151 warning (_("Uploaded tracepoint %d condition "
14152 "has no source form, ignoring it"),
14155 location_spec_up locspec
= string_to_location_spec (&addr_str
,
14159 gdb_assert (addr_str
!= nullptr);
14160 if (*addr_str
!= '\0')
14161 error (_("Garbage '%s' at end of location"), addr_str
);
14163 if (!create_breakpoint (get_current_arch (),
14165 utp
->cond_string
.get (), -1, -1, addr_str
,
14166 false /* force_condition */,
14167 0 /* parse cond/thread */,
14169 utp
->type
/* type_wanted */,
14170 0 /* Ignore count */,
14171 pending_break_support
,
14172 &code_breakpoint_ops
,
14174 utp
->enabled
/* enabled */,
14176 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14179 /* Get the tracepoint we just created. */
14180 tp
= get_tracepoint (tracepoint_count
);
14181 gdb_assert (tp
!= NULL
);
14185 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14188 trace_pass_command (small_buf
, 0);
14191 /* If we have uploaded versions of the original commands, set up a
14192 special-purpose "reader" function and call the usual command line
14193 reader, then pass the result to the breakpoint command-setting
14195 if (!utp
->cmd_strings
.empty ())
14197 counted_command_line cmd_list
;
14202 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14204 breakpoint_set_commands (tp
, std::move (cmd_list
));
14206 else if (!utp
->actions
.empty ()
14207 || !utp
->step_actions
.empty ())
14208 warning (_("Uploaded tracepoint %d actions "
14209 "have no source form, ignoring them"),
14212 /* Copy any status information that might be available. */
14213 tp
->hit_count
= utp
->hit_count
;
14214 tp
->traceframe_usage
= utp
->traceframe_usage
;
14219 /* Print information on tracepoint number TPNUM_EXP, or all if
14223 info_tracepoints_command (const char *args
, int from_tty
)
14225 struct ui_out
*uiout
= current_uiout
;
14228 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14230 if (num_printed
== 0)
14232 if (args
== NULL
|| *args
== '\0')
14233 uiout
->message ("No tracepoints.\n");
14235 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14238 default_collect_info ();
14241 /* The 'enable trace' command enables tracepoints.
14242 Not supported by all targets. */
14244 enable_trace_command (const char *args
, int from_tty
)
14246 enable_command (args
, from_tty
);
14249 /* The 'disable trace' command disables tracepoints.
14250 Not supported by all targets. */
14252 disable_trace_command (const char *args
, int from_tty
)
14254 disable_command (args
, from_tty
);
14257 /* Remove a tracepoint (or all if no argument). */
14259 delete_trace_command (const char *arg
, int from_tty
)
14265 int breaks_to_delete
= 0;
14267 /* Delete all tracepoints if no argument.
14268 Do not delete internal or call-dummy breakpoints, these
14269 have to be deleted with an explicit breakpoint number
14271 for (breakpoint
&tp
: all_tracepoints ())
14272 if (is_tracepoint (&tp
) && user_breakpoint_p (&tp
))
14274 breaks_to_delete
= 1;
14278 /* Ask user only if there are some breakpoints to delete. */
14280 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14282 for (breakpoint
&b
: all_breakpoints_safe ())
14283 if (is_tracepoint (&b
) && user_breakpoint_p (&b
))
14284 delete_breakpoint (&b
);
14288 map_breakpoint_numbers
14289 (arg
, [&] (breakpoint
*br
)
14291 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14295 /* Helper function for trace_pass_command. */
14298 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14300 tp
->pass_count
= count
;
14301 notify_breakpoint_modified (tp
);
14303 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14304 tp
->number
, count
);
14307 /* Set passcount for tracepoint.
14309 First command argument is passcount, second is tracepoint number.
14310 If tracepoint number omitted, apply to most recently defined.
14311 Also accepts special argument "all". */
14314 trace_pass_command (const char *args
, int from_tty
)
14318 if (args
== 0 || *args
== 0)
14319 error (_("passcount command requires an "
14320 "argument (count + optional TP num)"));
14322 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14324 args
= skip_spaces (args
);
14325 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14327 args
+= 3; /* Skip special argument "all". */
14329 error (_("Junk at end of arguments."));
14331 for (breakpoint
&b
: all_tracepoints ())
14333 tracepoint
&t1
= gdb::checked_static_cast
<tracepoint
&> (b
);
14334 trace_pass_set_count (&t1
, count
, from_tty
);
14337 else if (*args
== '\0')
14339 tracepoint
*t1
= get_tracepoint_by_number (&args
, NULL
);
14341 trace_pass_set_count (t1
, count
, from_tty
);
14345 number_or_range_parser
parser (args
);
14346 while (!parser
.finished ())
14348 tracepoint
*t1
= get_tracepoint_by_number (&args
, &parser
);
14350 trace_pass_set_count (t1
, count
, from_tty
);
14355 struct tracepoint
*
14356 get_tracepoint (int num
)
14358 for (breakpoint
&t
: all_tracepoints ())
14359 if (t
.number
== num
)
14360 return gdb::checked_static_cast
<tracepoint
*> (&t
);
14365 /* Find the tracepoint with the given target-side number (which may be
14366 different from the tracepoint number after disconnecting and
14369 struct tracepoint
*
14370 get_tracepoint_by_number_on_target (int num
)
14372 for (breakpoint
&b
: all_tracepoints ())
14374 tracepoint
&t
= gdb::checked_static_cast
<tracepoint
&> (b
);
14376 if (t
.number_on_target
== num
)
14383 /* Utility: parse a tracepoint number and look it up in the list.
14384 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14385 If the argument is missing, the most recent tracepoint
14386 (tracepoint_count) is returned. */
14388 struct tracepoint
*
14389 get_tracepoint_by_number (const char **arg
,
14390 number_or_range_parser
*parser
)
14393 const char *instring
= arg
== NULL
? NULL
: *arg
;
14395 if (parser
!= NULL
)
14397 gdb_assert (!parser
->finished ());
14398 tpnum
= parser
->get_number ();
14400 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14401 tpnum
= tracepoint_count
;
14403 tpnum
= get_number (arg
);
14407 if (instring
&& *instring
)
14408 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14411 gdb_printf (_("No previous tracepoint\n"));
14415 for (breakpoint
&t
: all_tracepoints ())
14416 if (t
.number
== tpnum
)
14417 return gdb::checked_static_cast
<tracepoint
*> (&t
);
14419 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14424 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
14428 struct thread_info
*thr
= find_thread_global_id (thread
);
14429 gdb_printf (fp
, " thread %s", print_full_thread_id (thr
));
14433 gdb_printf (fp
, " task %d", task
);
14435 gdb_printf (fp
, "\n");
14438 /* Save information on user settable breakpoints (watchpoints, etc) to
14439 a new script file named FILENAME. If FILTER is non-NULL, call it
14440 on each breakpoint and only include the ones for which it returns
14444 save_breakpoints (const char *filename
, int from_tty
,
14445 bool (*filter
) (const struct breakpoint
*))
14448 int extra_trace_bits
= 0;
14450 if (filename
== 0 || *filename
== 0)
14451 error (_("Argument required (file name in which to save)"));
14453 /* See if we have anything to save. */
14454 for (breakpoint
&tp
: all_breakpoints ())
14456 /* Skip internal and momentary breakpoints. */
14457 if (!user_breakpoint_p (&tp
))
14460 /* If we have a filter, only save the breakpoints it accepts. */
14461 if (filter
&& !filter (&tp
))
14466 if (is_tracepoint (&tp
))
14468 extra_trace_bits
= 1;
14470 /* We can stop searching. */
14477 warning (_("Nothing to save."));
14481 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14485 if (!fp
.open (expanded_filename
.get (), "w"))
14486 error (_("Unable to open file '%s' for saving (%s)"),
14487 expanded_filename
.get (), safe_strerror (errno
));
14489 if (extra_trace_bits
)
14490 save_trace_state_variables (&fp
);
14492 for (breakpoint
&tp
: all_breakpoints ())
14494 /* Skip internal and momentary breakpoints. */
14495 if (!user_breakpoint_p (&tp
))
14498 /* If we have a filter, only save the breakpoints it accepts. */
14499 if (filter
&& !filter (&tp
))
14502 tp
.print_recreate (&fp
);
14504 /* Note, we can't rely on tp->number for anything, as we can't
14505 assume the recreated breakpoint numbers will match. Use $bpnum
14508 if (tp
.cond_string
)
14509 fp
.printf (" condition $bpnum %s\n", tp
.cond_string
.get ());
14511 if (tp
.ignore_count
)
14512 fp
.printf (" ignore $bpnum %d\n", tp
.ignore_count
);
14514 if (tp
.type
!= bp_dprintf
&& tp
.commands
)
14516 fp
.puts (" commands\n");
14518 ui_out_redirect_pop
redir (current_uiout
, &fp
);
14519 print_command_lines (current_uiout
, tp
.commands
.get (), 2);
14521 fp
.puts (" end\n");
14524 if (tp
.enable_state
== bp_disabled
)
14525 fp
.puts ("disable $bpnum\n");
14527 /* If this is a multi-location breakpoint, check if the locations
14528 should be individually disabled. Watchpoint locations are
14529 special, and not user visible. */
14530 if (!is_watchpoint (&tp
) && tp
.has_multiple_locations ())
14534 for (bp_location
&loc
: tp
.locations ())
14537 fp
.printf ("disable $bpnum.%d\n", n
);
14544 if (extra_trace_bits
&& !default_collect
.empty ())
14545 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14548 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14551 /* The `save breakpoints' command. */
14554 save_breakpoints_command (const char *args
, int from_tty
)
14556 save_breakpoints (args
, from_tty
, NULL
);
14559 /* The `save tracepoints' command. */
14562 save_tracepoints_command (const char *args
, int from_tty
)
14564 save_breakpoints (args
, from_tty
, is_tracepoint
);
14568 /* This help string is used to consolidate all the help string for specifying
14569 locations used by several commands. */
14571 #define LOCATION_SPEC_HELP_STRING \
14572 "Linespecs are colon-separated lists of location parameters, such as\n\
14573 source filename, function name, label name, and line number.\n\
14574 Example: To specify the start of a label named \"the_top\" in the\n\
14575 function \"fact\" in the file \"factorial.c\", use\n\
14576 \"factorial.c:fact:the_top\".\n\
14578 Address locations begin with \"*\" and specify an exact address in the\n\
14579 program. Example: To specify the fourth byte past the start function\n\
14580 \"main\", use \"*main + 4\".\n\
14582 Explicit locations are similar to linespecs but use an option/argument\n\
14583 syntax to specify location parameters.\n\
14584 Example: To specify the start of the label named \"the_top\" in the\n\
14585 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14586 -function fact -label the_top\".\n\
14588 By default, a specified function is matched against the program's\n\
14589 functions in all scopes. For C++, this means in all namespaces and\n\
14590 classes. For Ada, this means in all packages. E.g., in C++,\n\
14591 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14592 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14593 specified name as a complete fully-qualified name instead."
14595 /* This help string is used for the break, hbreak, tbreak and thbreak
14596 commands. It is defined as a macro to prevent duplication.
14597 COMMAND should be a string constant containing the name of the
14600 #define BREAK_ARGS_HELP(command) \
14601 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14602 \t[-force-condition] [if CONDITION]\n\
14603 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14604 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14605 guessed probe type), `-probe-stap' (for a SystemTap probe) or\n\
14606 `-probe-dtrace' (for a DTrace probe).\n\
14607 LOCATION may be a linespec, address, or explicit location as described\n\
14610 With no LOCATION, uses current execution address of the selected\n\
14611 stack frame. This is useful for breaking on return to a stack frame.\n\
14613 THREADNUM is the number from \"info threads\".\n\
14614 CONDITION is a boolean expression.\n\
14616 With the \"-force-condition\" flag, the condition is defined even when\n\
14617 it is invalid for all current locations.\n\
14618 \n" LOCATION_SPEC_HELP_STRING "\n\n\
14619 Multiple breakpoints at one place are permitted, and useful if their\n\
14620 conditions are different.\n\
14622 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14624 /* List of subcommands for "catch". */
14625 static struct cmd_list_element
*catch_cmdlist
;
14627 /* List of subcommands for "tcatch". */
14628 static struct cmd_list_element
*tcatch_cmdlist
;
14631 add_catch_command (const char *name
, const char *docstring
,
14632 cmd_func_ftype
*func
,
14633 completer_ftype
*completer
,
14634 void *user_data_catch
,
14635 void *user_data_tcatch
)
14637 struct cmd_list_element
*command
;
14639 command
= add_cmd (name
, class_breakpoint
, docstring
,
14641 command
->func
= func
;
14642 command
->set_context (user_data_catch
);
14643 set_cmd_completer (command
, completer
);
14645 command
= add_cmd (name
, class_breakpoint
, docstring
,
14647 command
->func
= func
;
14648 command
->set_context (user_data_tcatch
);
14649 set_cmd_completer (command
, completer
);
14652 /* False if any of the breakpoint's locations could be a location where
14653 functions have been inlined, true otherwise. */
14656 is_non_inline_function (struct breakpoint
*b
)
14658 /* The shared library event breakpoint is set on the address of a
14659 non-inline function. */
14660 return (b
->type
== bp_shlib_event
);
14663 /* Nonzero if the specified PC cannot be a location where functions
14664 have been inlined. */
14667 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14668 const target_waitstatus
&ws
)
14670 for (breakpoint
&b
: all_breakpoints ())
14672 if (!is_non_inline_function (&b
))
14675 for (bp_location
&bl
: b
.locations ())
14677 if (!bl
.shlib_disabled
14678 && bpstat_check_location (&bl
, aspace
, pc
, ws
))
14686 /* Remove any references to OBJFILE which is going to be freed. */
14689 breakpoint_free_objfile (struct objfile
*objfile
)
14691 for (bp_location
*loc
: all_bp_locations ())
14692 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14693 loc
->symtab
= NULL
;
14696 /* Chain containing all defined "enable breakpoint" subcommands. */
14698 static struct cmd_list_element
*enablebreaklist
= NULL
;
14700 /* See breakpoint.h. */
14702 cmd_list_element
*commands_cmd_element
= nullptr;
14704 void _initialize_breakpoint ();
14706 _initialize_breakpoint ()
14708 struct cmd_list_element
*c
;
14710 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14712 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14714 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14717 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14718 before a breakpoint is set. */
14719 breakpoint_count
= 0;
14721 tracepoint_count
= 0;
14723 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14724 Set ignore-count of breakpoint number N to COUNT.\n\
14725 Usage is `ignore N COUNT'."));
14727 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14728 commands_command
, _("\
14729 Set commands to be executed when the given breakpoints are hit.\n\
14730 Give a space-separated breakpoint list as argument after \"commands\".\n\
14731 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14733 With no argument, the targeted breakpoint is the last one set.\n\
14734 The commands themselves follow starting on the next line.\n\
14735 Type a line containing \"end\" to indicate the end of them.\n\
14736 Give \"silent\" as the first line to make the breakpoint silent;\n\
14737 then no output is printed when it is hit, except what the commands print."));
14739 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14740 static std::string condition_command_help
14741 = gdb::option::build_help (_("\
14742 Specify breakpoint number N to break only if COND is true.\n\
14743 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14744 is an expression to be evaluated whenever breakpoint N is reached.\n\
14747 %OPTIONS%"), cc_opts
);
14749 c
= add_com ("condition", class_breakpoint
, condition_command
,
14750 condition_command_help
.c_str ());
14751 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14753 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14754 Set a temporary breakpoint.\n\
14755 Like \"break\" except the breakpoint is only temporary,\n\
14756 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14757 by using \"enable delete\" on the breakpoint number.\n\
14759 BREAK_ARGS_HELP ("tbreak")));
14760 set_cmd_completer (c
, location_completer
);
14762 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14763 Set a hardware assisted breakpoint.\n\
14764 Like \"break\" except the breakpoint requires hardware support,\n\
14765 some target hardware may not have this support.\n\
14767 BREAK_ARGS_HELP ("hbreak")));
14768 set_cmd_completer (c
, location_completer
);
14770 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14771 Set a temporary hardware assisted breakpoint.\n\
14772 Like \"hbreak\" except the breakpoint is only temporary,\n\
14773 so it will be deleted when hit.\n\
14775 BREAK_ARGS_HELP ("thbreak")));
14776 set_cmd_completer (c
, location_completer
);
14778 cmd_list_element
*enable_cmd
14779 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14780 Enable all or some breakpoints.\n\
14781 Usage: enable [BREAKPOINTNUM]...\n\
14782 Give breakpoint numbers (separated by spaces) as arguments.\n\
14783 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14784 This is used to cancel the effect of the \"disable\" command.\n\
14785 With a subcommand you can enable temporarily."),
14786 &enablelist
, 1, &cmdlist
);
14788 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14790 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14791 Enable all or some breakpoints.\n\
14792 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14793 Give breakpoint numbers (separated by spaces) as arguments.\n\
14794 This is used to cancel the effect of the \"disable\" command.\n\
14795 May be abbreviated to simply \"enable\"."),
14796 &enablebreaklist
, 1, &enablelist
);
14798 add_cmd ("once", no_class
, enable_once_command
, _("\
14799 Enable some breakpoints for one hit.\n\
14800 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14801 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14804 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14805 Enable some breakpoints and delete when hit.\n\
14806 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14807 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14810 add_cmd ("count", no_class
, enable_count_command
, _("\
14811 Enable some breakpoints for COUNT hits.\n\
14812 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14813 If a breakpoint is hit while enabled in this fashion,\n\
14814 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14817 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14818 Enable some breakpoints and delete when hit.\n\
14819 Usage: enable delete BREAKPOINTNUM...\n\
14820 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14823 add_cmd ("once", no_class
, enable_once_command
, _("\
14824 Enable some breakpoints for one hit.\n\
14825 Usage: enable once BREAKPOINTNUM...\n\
14826 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14829 add_cmd ("count", no_class
, enable_count_command
, _("\
14830 Enable some breakpoints for COUNT hits.\n\
14831 Usage: enable count COUNT BREAKPOINTNUM...\n\
14832 If a breakpoint is hit while enabled in this fashion,\n\
14833 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14836 cmd_list_element
*disable_cmd
14837 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14838 Disable all or some breakpoints.\n\
14839 Usage: disable [BREAKPOINTNUM]...\n\
14840 Arguments are breakpoint numbers with spaces in between.\n\
14841 To disable all breakpoints, give no argument.\n\
14842 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14843 &disablelist
, 1, &cmdlist
);
14844 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14845 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14847 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14848 Disable all or some breakpoints.\n\
14849 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14850 Arguments are breakpoint numbers with spaces in between.\n\
14851 To disable all breakpoints, give no argument.\n\
14852 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14853 This command may be abbreviated \"disable\"."),
14856 cmd_list_element
*delete_cmd
14857 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14858 Delete all or some breakpoints.\n\
14859 Usage: delete [BREAKPOINTNUM]...\n\
14860 Arguments are breakpoint numbers with spaces in between.\n\
14861 To delete all breakpoints, watchpoints, tracepoints, and catchpoints,\n\
14862 give no argument.\n\
14864 Also a prefix command for deletion of other GDB objects."),
14865 &deletelist
, 1, &cmdlist
);
14866 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14867 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14869 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14870 Delete all or some breakpoints or auto-display expressions.\n\
14871 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14872 Arguments are breakpoint numbers with spaces in between.\n\
14873 To delete all breakpoints, watchpoints, tracepoints, and catchpoints,\n\
14874 give no argument.\n\
14875 This command may be abbreviated \"delete\"."),
14878 cmd_list_element
*clear_cmd
14879 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14880 Clear breakpoint at specified location.\n\
14881 Argument may be a linespec, explicit, or address location as described below.\n\
14883 With no argument, clears all breakpoints in the line that the selected frame\n\
14884 is executing in.\n"
14885 "\n" LOCATION_SPEC_HELP_STRING
"\n\n\
14886 See also the \"delete\" command which clears breakpoints by number."));
14887 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14889 cmd_list_element
*break_cmd
14890 = add_com ("break", class_breakpoint
, break_command
, _("\
14891 Set breakpoint at specified location.\n"
14892 BREAK_ARGS_HELP ("break")));
14893 set_cmd_completer (break_cmd
, location_completer
);
14895 add_com_alias ("b", break_cmd
, class_run
, 1);
14896 add_com_alias ("br", break_cmd
, class_run
, 1);
14897 add_com_alias ("bre", break_cmd
, class_run
, 1);
14898 add_com_alias ("brea", break_cmd
, class_run
, 1);
14900 cmd_list_element
*info_breakpoints_cmd
14901 = add_info ("breakpoints", info_breakpoints_command
, _("\
14902 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14903 The \"Type\" column indicates one of:\n\
14904 \tbreakpoint - normal breakpoint\n\
14905 \twatchpoint - watchpoint\n\
14906 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14907 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14908 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14909 address and file/line number respectively.\n\
14911 Convenience variable \"$_\" and default examine address for \"x\"\n\
14912 are set to the address of the last breakpoint listed unless the command\n\
14913 is prefixed with \"server \".\n\n\
14914 Convenience variable \"$bpnum\" contains the number of the last\n\
14915 breakpoint set."));
14917 add_info_alias ("b", info_breakpoints_cmd
, 1);
14919 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14920 Status of all breakpoints, or breakpoint number NUMBER.\n\
14921 The \"Type\" column indicates one of:\n\
14922 \tbreakpoint - normal breakpoint\n\
14923 \twatchpoint - watchpoint\n\
14924 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14925 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14926 \tuntil - internal breakpoint used by the \"until\" command\n\
14927 \tfinish - internal breakpoint used by the \"finish\" command\n\
14928 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14929 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14930 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14931 address and file/line number respectively.\n\
14933 Convenience variable \"$_\" and default examine address for \"x\"\n\
14934 are set to the address of the last breakpoint listed unless the command\n\
14935 is prefixed with \"server \".\n\n\
14936 Convenience variable \"$bpnum\" contains the number of the last\n\
14938 &maintenanceinfolist
);
14940 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14941 Set catchpoints to catch events."),
14943 0/*allow-unknown*/, &cmdlist
);
14945 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14946 Set temporary catchpoints to catch events."),
14948 0/*allow-unknown*/, &cmdlist
);
14950 const auto opts
= make_watch_options_def_group (nullptr);
14952 static const std::string watch_help
= gdb::option::build_help (_("\
14953 Set a watchpoint for EXPRESSION.\n\
14954 Usage: watch [-location] EXPRESSION\n\
14959 A watchpoint stops execution of your program whenever the value of\n\
14960 an expression changes."), opts
);
14961 c
= add_com ("watch", class_breakpoint
, watch_command
,
14962 watch_help
.c_str ());
14963 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14965 static const std::string rwatch_help
= gdb::option::build_help (_("\
14966 Set a read watchpoint for EXPRESSION.\n\
14967 Usage: rwatch [-location] EXPRESSION\n\
14972 A read watchpoint stops execution of your program whenever the value of\n\
14973 an expression is read."), opts
);
14974 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14975 rwatch_help
.c_str ());
14976 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14978 static const std::string awatch_help
= gdb::option::build_help (_("\
14979 Set an access watchpoint for EXPRESSION.\n\
14980 Usage: awatch [-location] EXPRESSION\n\
14985 An access watchpoint stops execution of your program whenever the value\n\
14986 of an expression is either read or written."), opts
);
14987 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14988 awatch_help
.c_str ());
14989 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14991 add_info ("watchpoints", info_watchpoints_command
, _("\
14992 Status of specified watchpoints (all watchpoints if no argument)."));
14994 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14995 respond to changes - contrary to the description. */
14996 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14997 &can_use_hw_watchpoints
, _("\
14998 Set debugger's willingness to use watchpoint hardware."), _("\
14999 Show debugger's willingness to use watchpoint hardware."), _("\
15000 If zero, gdb will not use hardware for new watchpoints, even if\n\
15001 such is available. (However, any hardware watchpoints that were\n\
15002 created before setting this to nonzero, will continue to use watchpoint\n\
15005 show_can_use_hw_watchpoints
,
15006 &setlist
, &showlist
);
15008 can_use_hw_watchpoints
= 1;
15010 /* Tracepoint manipulation commands. */
15012 cmd_list_element
*trace_cmd
15013 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15014 Set a tracepoint at specified location.\n\
15016 BREAK_ARGS_HELP ("trace") "\n\
15017 Do \"help tracepoints\" for info on other tracepoint commands."));
15018 set_cmd_completer (trace_cmd
, location_completer
);
15020 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15021 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15022 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15023 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15025 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15026 Set a fast tracepoint at specified location.\n\
15028 BREAK_ARGS_HELP ("ftrace") "\n\
15029 Do \"help tracepoints\" for info on other tracepoint commands."));
15030 set_cmd_completer (c
, location_completer
);
15032 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15033 Set a static tracepoint at location or marker.\n\
15035 strace [LOCATION] [if CONDITION]\n\
15036 LOCATION may be a linespec, explicit, or address location (described below)\n\
15037 or -m MARKER_ID.\n\n\
15038 If a marker id is specified, probe the marker with that name. With\n\
15039 no LOCATION, uses current execution address of the selected stack frame.\n\
15040 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15041 This collects arbitrary user data passed in the probe point call to the\n\
15042 tracing library. You can inspect it when analyzing the trace buffer,\n\
15043 by printing the $_sdata variable like any other convenience variable.\n\
15045 CONDITION is a boolean expression.\n\
15046 \n" LOCATION_SPEC_HELP_STRING
"\n\n\
15047 Multiple tracepoints at one place are permitted, and useful if their\n\
15048 conditions are different.\n\
15050 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15051 Do \"help tracepoints\" for info on other tracepoint commands."));
15052 set_cmd_completer (c
, location_completer
);
15054 cmd_list_element
*info_tracepoints_cmd
15055 = add_info ("tracepoints", info_tracepoints_command
, _("\
15056 Status of specified tracepoints (all tracepoints if no argument).\n\
15057 Convenience variable \"$tpnum\" contains the number of the\n\
15058 last tracepoint set."));
15060 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15062 cmd_list_element
*delete_tracepoints_cmd
15063 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15064 Delete specified tracepoints.\n\
15065 Arguments are tracepoint numbers, separated by spaces.\n\
15066 No argument means delete all tracepoints."),
15068 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15070 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15071 Disable specified tracepoints.\n\
15072 Arguments are tracepoint numbers, separated by spaces.\n\
15073 No argument means disable all tracepoints."),
15075 deprecate_cmd (c
, "disable");
15077 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15078 Enable specified tracepoints.\n\
15079 Arguments are tracepoint numbers, separated by spaces.\n\
15080 No argument means enable all tracepoints."),
15082 deprecate_cmd (c
, "enable");
15084 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15085 Set the passcount for a tracepoint.\n\
15086 The trace will end when the tracepoint has been passed 'count' times.\n\
15087 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15088 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15090 add_basic_prefix_cmd ("save", class_breakpoint
,
15091 _("Save breakpoint definitions as a script."),
15093 0/*allow-unknown*/, &cmdlist
);
15095 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15096 Save current breakpoint definitions as a script.\n\
15097 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15098 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15099 session to restore them."),
15101 set_cmd_completer (c
, deprecated_filename_completer
);
15103 cmd_list_element
*save_tracepoints_cmd
15104 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15105 Save current tracepoint definitions as a script.\n\
15106 Use the 'source' command in another debug session to restore them."),
15108 set_cmd_completer (save_tracepoints_cmd
, deprecated_filename_completer
);
15110 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15111 deprecate_cmd (c
, "save tracepoints");
15113 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
15115 Breakpoint specific settings.\n\
15116 Configure various breakpoint-specific variables such as\n\
15117 pending breakpoint behavior."),
15119 Breakpoint specific settings.\n\
15120 Configure various breakpoint-specific variables such as\n\
15121 pending breakpoint behavior."),
15122 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
15123 &setlist
, &showlist
);
15125 add_setshow_auto_boolean_cmd ("pending", no_class
,
15126 &pending_break_support
, _("\
15127 Set debugger's behavior regarding pending breakpoints."), _("\
15128 Show debugger's behavior regarding pending breakpoints."), _("\
15129 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15130 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15131 an error. If auto, an unrecognized breakpoint location results in a\n\
15132 user-query to see if a pending breakpoint should be created."),
15134 show_pending_break_support
,
15135 &breakpoint_set_cmdlist
,
15136 &breakpoint_show_cmdlist
);
15138 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15140 add_setshow_boolean_cmd ("auto-hw", no_class
,
15141 &automatic_hardware_breakpoints
, _("\
15142 Set automatic usage of hardware breakpoints."), _("\
15143 Show automatic usage of hardware breakpoints."), _("\
15144 If set, the debugger will automatically use hardware breakpoints for\n\
15145 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15146 a warning will be emitted for such breakpoints."),
15148 show_automatic_hardware_breakpoints
,
15149 &breakpoint_set_cmdlist
,
15150 &breakpoint_show_cmdlist
);
15152 add_setshow_boolean_cmd ("always-inserted", class_support
,
15153 &always_inserted_mode
, _("\
15154 Set mode for inserting breakpoints."), _("\
15155 Show mode for inserting breakpoints."), _("\
15156 When this mode is on, breakpoints are inserted immediately as soon as\n\
15157 they're created, kept inserted even when execution stops, and removed\n\
15158 only when the user deletes them. When this mode is off (the default),\n\
15159 breakpoints are inserted only when execution continues, and removed\n\
15160 when execution stops."),
15162 &show_always_inserted_mode
,
15163 &breakpoint_set_cmdlist
,
15164 &breakpoint_show_cmdlist
);
15166 add_setshow_boolean_cmd ("breakpoint", class_maintenance
,
15167 &debug_breakpoint
, _("\
15168 Set breakpoint location debugging."), _("\
15169 Show breakpoint location debugging."), _("\
15170 When on, breakpoint location specific debugging is enabled."),
15172 show_debug_breakpoint
,
15173 &setdebuglist
, &showdebuglist
);
15175 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15176 condition_evaluation_enums
,
15177 &condition_evaluation_mode_1
, _("\
15178 Set mode of breakpoint condition evaluation."), _("\
15179 Show mode of breakpoint condition evaluation."), _("\
15180 When this is set to \"host\", breakpoint conditions will be\n\
15181 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15182 breakpoint conditions will be downloaded to the target (if the target\n\
15183 supports such feature) and conditions will be evaluated on the target's side.\n\
15184 If this is set to \"auto\" (default), this will be automatically set to\n\
15185 \"target\" if it supports condition evaluation, otherwise it will\n\
15186 be set to \"host\"."),
15187 &set_condition_evaluation_mode
,
15188 &show_condition_evaluation_mode
,
15189 &breakpoint_set_cmdlist
,
15190 &breakpoint_show_cmdlist
);
15192 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15193 Set a breakpoint for an address range.\n\
15194 break-range START-LOCATION, END-LOCATION\n\
15195 where START-LOCATION and END-LOCATION can be one of the following:\n\
15196 LINENUM, for that line in the current file,\n\
15197 FILE:LINENUM, for that line in that file,\n\
15198 +OFFSET, for that number of lines after the current line\n\
15199 or the start of the range\n\
15200 FUNCTION, for the first line in that function,\n\
15201 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15202 *ADDRESS, for the instruction at that address.\n\
15204 The breakpoint will stop execution of the inferior whenever it executes\n\
15205 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15206 range (including START-LOCATION and END-LOCATION)."));
15208 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15209 Set a dynamic printf at specified location.\n\
15210 dprintf location,format string,arg1,arg2,...\n\
15211 location may be a linespec, explicit, or address location.\n"
15212 "\n" LOCATION_SPEC_HELP_STRING
));
15213 set_cmd_completer (c
, location_completer
);
15215 add_setshow_enum_cmd ("dprintf-style", class_support
,
15216 dprintf_style_enums
, &dprintf_style
, _("\
15217 Set the style of usage for dynamic printf."), _("\
15218 Show the style of usage for dynamic printf."), _("\
15219 This setting chooses how GDB will do a dynamic printf.\n\
15220 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15221 console, as with the \"printf\" command.\n\
15222 If the value is \"call\", the print is done by calling a function in your\n\
15223 program; by default printf(), but you can choose a different function or\n\
15224 output stream by setting dprintf-function and dprintf-channel."),
15225 update_dprintf_commands
, NULL
,
15226 &setlist
, &showlist
);
15228 add_setshow_string_cmd ("dprintf-function", class_support
,
15229 &dprintf_function
, _("\
15230 Set the function to use for dynamic printf."), _("\
15231 Show the function to use for dynamic printf."), NULL
,
15232 update_dprintf_commands
, NULL
,
15233 &setlist
, &showlist
);
15235 add_setshow_string_cmd ("dprintf-channel", class_support
,
15236 &dprintf_channel
, _("\
15237 Set the channel to use for dynamic printf."), _("\
15238 Show the channel to use for dynamic printf."), NULL
,
15239 update_dprintf_commands
, NULL
,
15240 &setlist
, &showlist
);
15242 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15243 &disconnected_dprintf
, _("\
15244 Set whether dprintf continues after GDB disconnects."), _("\
15245 Show whether dprintf continues after GDB disconnects."), _("\
15246 Use this to let dprintf commands continue to hit and produce output\n\
15247 even if GDB disconnects or detaches from the target."),
15250 &setlist
, &showlist
);
15252 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15253 Target agent only formatted printing, like the C \"printf\" function.\n\
15254 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15255 This supports most C printf format specifications, like %s, %d, etc.\n\
15256 This is useful for formatted output in user-defined commands."));
15258 automatic_hardware_breakpoints
= true;
15260 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
15262 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,
15264 gdb::observers::inferior_removed
.attach (remove_inferior_breakpoints
,