1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdbsupport/gdb_regex.h"
61 #include "cli/cli-utils.h"
64 #include "dummy-frame.h"
66 #include "gdbsupport/format.h"
67 #include "thread-fsm.h"
68 #include "tid-parse.h"
69 #include "cli/cli-style.h"
70 #include "cli/cli-decode.h"
72 /* readline include files */
73 #include "readline/tilde.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "extension.h"
81 #include "progspace-and-thread.h"
82 #include "gdbsupport/array-view.h"
83 #include "gdbsupport/gdb_optional.h"
85 /* Prototypes for local functions. */
87 static void map_breakpoint_numbers (const char *,
88 gdb::function_view
<void (breakpoint
*)>);
91 create_sals_from_location_spec_default (location_spec
*locspec
,
92 linespec_result
*canonical
);
94 static void create_breakpoints_sal (struct gdbarch
*,
95 struct linespec_result
*,
96 gdb::unique_xmalloc_ptr
<char>,
97 gdb::unique_xmalloc_ptr
<char>,
99 enum bpdisp
, int, int,
101 int, int, int, unsigned);
103 static int can_use_hardware_watchpoint
104 (const std::vector
<value_ref_ptr
> &vals
);
106 static void mention (const breakpoint
*);
108 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
110 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
112 static struct breakpoint
*
113 momentary_breakpoint_from_master (struct breakpoint
*orig
,
115 int loc_enabled
, int thread
);
117 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, bool);
119 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
122 struct program_space
*pspace
);
124 static bool watchpoint_locations_match (const struct bp_location
*loc1
,
125 const struct bp_location
*loc2
);
127 static bool breakpoint_locations_match (const struct bp_location
*loc1
,
128 const struct bp_location
*loc2
,
129 bool sw_hw_bps_match
= false);
131 static bool breakpoint_location_address_match (struct bp_location
*bl
,
132 const struct address_space
*aspace
,
135 static bool breakpoint_location_address_range_overlap (struct bp_location
*,
136 const address_space
*,
139 static int remove_breakpoint (struct bp_location
*);
140 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
142 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
144 static int hw_breakpoint_used_count (void);
146 static int hw_watchpoint_use_count (struct breakpoint
*);
148 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
150 int *other_type_used
);
152 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
155 static void decref_bp_location (struct bp_location
**loc
);
157 static std::vector
<symtab_and_line
> bkpt_probe_decode_location_spec
158 (struct breakpoint
*b
,
159 location_spec
*locspec
,
160 struct program_space
*search_pspace
);
162 static bool bl_address_is_meaningful (bp_location
*loc
);
164 static int find_loc_num_by_location (const bp_location
*loc
);
166 /* update_global_location_list's modes of operation wrt to whether to
167 insert locations now. */
168 enum ugll_insert_mode
170 /* Don't insert any breakpoint locations into the inferior, only
171 remove already-inserted locations that no longer should be
172 inserted. Functions that delete a breakpoint or breakpoints
173 should specify this mode, so that deleting a breakpoint doesn't
174 have the side effect of inserting the locations of other
175 breakpoints that are marked not-inserted, but should_be_inserted
176 returns true on them.
178 This behavior is useful is situations close to tear-down -- e.g.,
179 after an exec, while the target still has execution, but
180 breakpoint shadows of the previous executable image should *NOT*
181 be restored to the new image; or before detaching, where the
182 target still has execution and wants to delete breakpoints from
183 GDB's lists, and all breakpoints had already been removed from
187 /* May insert breakpoints iff breakpoints_should_be_inserted_now
188 claims breakpoints should be inserted now. */
191 /* Insert locations now, irrespective of
192 breakpoints_should_be_inserted_now. E.g., say all threads are
193 stopped right now, and the user did "continue". We need to
194 insert breakpoints _before_ resuming the target, but
195 UGLL_MAY_INSERT wouldn't insert them, because
196 breakpoints_should_be_inserted_now returns false at that point,
197 as no thread is running yet. */
201 static void update_global_location_list (enum ugll_insert_mode
);
203 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
205 static void insert_breakpoint_locations (void);
207 static void trace_pass_command (const char *, int);
209 static void set_tracepoint_count (int num
);
211 static bool is_masked_watchpoint (const struct breakpoint
*b
);
213 /* Return true if B refers to a static tracepoint set by marker ("-m"),
216 static bool strace_marker_p (struct breakpoint
*b
);
218 static void bkpt_probe_create_sals_from_location_spec
219 (location_spec
*locspec
,
220 struct linespec_result
*canonical
);
221 static void tracepoint_probe_create_sals_from_location_spec
222 (location_spec
*locspec
,
223 struct linespec_result
*canonical
);
225 const struct breakpoint_ops code_breakpoint_ops
=
227 create_sals_from_location_spec_default
,
228 create_breakpoints_sal
,
231 /* Breakpoints set on probes. */
232 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
234 bkpt_probe_create_sals_from_location_spec
,
235 create_breakpoints_sal
,
238 /* Tracepoints set on probes. */
239 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
241 tracepoint_probe_create_sals_from_location_spec
,
242 create_breakpoints_sal
,
245 /* Implementation of abstract dtors. These must exist to satisfy the
248 breakpoint::~breakpoint ()
252 code_breakpoint::~code_breakpoint ()
256 catchpoint::~catchpoint ()
260 /* The structure to be used in regular breakpoints. */
261 struct ordinary_breakpoint
: public code_breakpoint
263 using code_breakpoint::code_breakpoint
;
265 int resources_needed (const struct bp_location
*) override
;
266 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
267 void print_mention () const override
;
268 void print_recreate (struct ui_file
*fp
) const override
;
271 /* Internal breakpoints. These typically have a lifetime the same as
272 the program, and they end up installed on the breakpoint chain with
273 a negative breakpoint number. They're visible in "maint info
274 breakpoints", but not "info breakpoints". */
275 struct internal_breakpoint
: public code_breakpoint
277 internal_breakpoint (struct gdbarch
*gdbarch
,
278 enum bptype type
, CORE_ADDR address
)
279 : code_breakpoint (gdbarch
, type
)
283 sal
.section
= find_pc_overlay (sal
.pc
);
284 sal
.pspace
= current_program_space
;
287 pspace
= current_program_space
;
288 disposition
= disp_donttouch
;
291 void re_set () override
;
292 void check_status (struct bpstat
*bs
) override
;
293 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
294 void print_mention () const override
;
297 /* Momentary breakpoints. These typically have a lifetime of some run
298 control command only, are always thread-specific, and have 0 for
299 breakpoint number. I.e., there can be many momentary breakpoints
300 on the breakpoint chain and they all same the same number (zero).
301 They're visible in "maint info breakpoints", but not "info
303 struct momentary_breakpoint
: public code_breakpoint
305 momentary_breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
306 program_space
*pspace_
,
307 const struct frame_id
&frame_id_
,
309 : code_breakpoint (gdbarch_
, bptype
)
311 /* If FRAME_ID is valid, it should be a real frame, not an inlined
312 or tail-called one. */
313 gdb_assert (!frame_id_artificial_p (frame_id
));
315 /* Momentary breakpoints are always thread-specific. */
316 gdb_assert (thread_
> 0);
319 enable_state
= bp_enabled
;
320 disposition
= disp_donttouch
;
321 frame_id
= frame_id_
;
325 void re_set () override
;
326 void check_status (struct bpstat
*bs
) override
;
327 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
328 void print_mention () const override
;
331 /* DPrintf breakpoints. */
332 struct dprintf_breakpoint
: public ordinary_breakpoint
334 using ordinary_breakpoint::ordinary_breakpoint
;
336 void re_set () override
;
337 int breakpoint_hit (const struct bp_location
*bl
,
338 const address_space
*aspace
,
340 const target_waitstatus
&ws
) override
;
341 void print_recreate (struct ui_file
*fp
) const override
;
342 void after_condition_true (struct bpstat
*bs
) override
;
345 /* Ranged breakpoints. */
346 struct ranged_breakpoint
: public ordinary_breakpoint
348 explicit ranged_breakpoint (struct gdbarch
*gdbarch
,
349 const symtab_and_line
&sal_start
,
351 location_spec_up start_locspec
,
352 location_spec_up end_locspec
)
353 : ordinary_breakpoint (gdbarch
, bp_hardware_breakpoint
)
355 bp_location
*bl
= add_location (sal_start
);
358 disposition
= disp_donttouch
;
360 locspec
= std::move (start_locspec
);
361 locspec_range_end
= std::move (end_locspec
);
364 int breakpoint_hit (const struct bp_location
*bl
,
365 const address_space
*aspace
,
367 const target_waitstatus
&ws
) override
;
368 int resources_needed (const struct bp_location
*) override
;
369 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
370 bool print_one (bp_location
**) const override
;
371 void print_one_detail (struct ui_out
*) const override
;
372 void print_mention () const override
;
373 void print_recreate (struct ui_file
*fp
) const override
;
376 /* Static tracepoints with marker (`-m'). */
377 struct static_marker_tracepoint
: public tracepoint
379 using tracepoint::tracepoint
;
381 std::vector
<symtab_and_line
> decode_location_spec
382 (struct location_spec
*locspec
,
383 struct program_space
*search_pspace
) override
;
386 /* The style in which to perform a dynamic printf. This is a user
387 option because different output options have different tradeoffs;
388 if GDB does the printing, there is better error handling if there
389 is a problem with any of the arguments, but using an inferior
390 function lets you have special-purpose printers and sending of
391 output to the same place as compiled-in print functions. */
393 static const char dprintf_style_gdb
[] = "gdb";
394 static const char dprintf_style_call
[] = "call";
395 static const char dprintf_style_agent
[] = "agent";
396 static const char *const dprintf_style_enums
[] = {
402 static const char *dprintf_style
= dprintf_style_gdb
;
404 /* The function to use for dynamic printf if the preferred style is to
405 call into the inferior. The value is simply a string that is
406 copied into the command, so it can be anything that GDB can
407 evaluate to a callable address, not necessarily a function name. */
409 static std::string dprintf_function
= "printf";
411 /* The channel to use for dynamic printf if the preferred style is to
412 call into the inferior; if a nonempty string, it will be passed to
413 the call as the first argument, with the format string as the
414 second. As with the dprintf function, this can be anything that
415 GDB knows how to evaluate, so in addition to common choices like
416 "stderr", this could be an app-specific expression like
417 "mystreams[curlogger]". */
419 static std::string dprintf_channel
;
421 /* True if dprintf commands should continue to operate even if GDB
423 static bool disconnected_dprintf
= true;
425 struct command_line
*
426 breakpoint_commands (struct breakpoint
*b
)
428 return b
->commands
? b
->commands
.get () : NULL
;
431 /* Flag indicating that a command has proceeded the inferior past the
432 current breakpoint. */
434 static bool breakpoint_proceeded
;
437 bpdisp_text (enum bpdisp disp
)
439 /* NOTE: the following values are a part of MI protocol and
440 represent values of 'disp' field returned when inferior stops at
442 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
444 return bpdisps
[(int) disp
];
447 /* Prototypes for exported functions. */
448 /* If FALSE, gdb will not use hardware support for watchpoints, even
449 if such is available. */
450 static int can_use_hw_watchpoints
;
453 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
454 struct cmd_list_element
*c
,
458 _("Debugger's willingness to use "
459 "watchpoint hardware is %s.\n"),
463 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
464 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
465 for unrecognized breakpoint locations.
466 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
467 static enum auto_boolean pending_break_support
;
469 show_pending_break_support (struct ui_file
*file
, int from_tty
,
470 struct cmd_list_element
*c
,
474 _("Debugger's behavior regarding "
475 "pending breakpoints is %s.\n"),
479 /* If true, gdb will automatically use hardware breakpoints for breakpoints
480 set with "break" but falling in read-only memory.
481 If false, gdb will warn about such breakpoints, but won't automatically
482 use hardware breakpoints. */
483 static bool automatic_hardware_breakpoints
;
485 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
486 struct cmd_list_element
*c
,
490 _("Automatic usage of hardware breakpoints is %s.\n"),
494 /* If on, GDB keeps breakpoints inserted even if the inferior is
495 stopped, and immediately inserts any new breakpoints as soon as
496 they're created. If off (default), GDB keeps breakpoints off of
497 the target as long as possible. That is, it delays inserting
498 breakpoints until the next resume, and removes them again when the
499 target fully stops. This is a bit safer in case GDB crashes while
500 processing user input. */
501 static bool always_inserted_mode
= false;
504 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
505 struct cmd_list_element
*c
, const char *value
)
507 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
511 /* See breakpoint.h. */
514 breakpoints_should_be_inserted_now (void)
516 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
518 /* If breakpoints are global, they should be inserted even if no
519 thread under gdb's control is running, or even if there are
520 no threads under GDB's control yet. */
525 if (always_inserted_mode
)
527 /* The user wants breakpoints inserted even if all threads
532 for (inferior
*inf
: all_inferiors ())
533 if (inf
->has_execution ()
534 && threads_are_executing (inf
->process_target ()))
537 /* Don't remove breakpoints yet if, even though all threads are
538 stopped, we still have events to process. */
539 for (thread_info
*tp
: all_non_exited_threads ())
540 if (tp
->resumed () && tp
->has_pending_waitstatus ())
546 static const char condition_evaluation_both
[] = "host or target";
548 /* Modes for breakpoint condition evaluation. */
549 static const char condition_evaluation_auto
[] = "auto";
550 static const char condition_evaluation_host
[] = "host";
551 static const char condition_evaluation_target
[] = "target";
552 static const char *const condition_evaluation_enums
[] = {
553 condition_evaluation_auto
,
554 condition_evaluation_host
,
555 condition_evaluation_target
,
559 /* Global that holds the current mode for breakpoint condition evaluation. */
560 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
562 /* Global that we use to display information to the user (gets its value from
563 condition_evaluation_mode_1. */
564 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
566 /* Translate a condition evaluation mode MODE into either "host"
567 or "target". This is used mostly to translate from "auto" to the
568 real setting that is being used. It returns the translated
572 translate_condition_evaluation_mode (const char *mode
)
574 if (mode
== condition_evaluation_auto
)
576 if (target_supports_evaluation_of_breakpoint_conditions ())
577 return condition_evaluation_target
;
579 return condition_evaluation_host
;
585 /* Discovers what condition_evaluation_auto translates to. */
588 breakpoint_condition_evaluation_mode (void)
590 return translate_condition_evaluation_mode (condition_evaluation_mode
);
593 /* Return true if GDB should evaluate breakpoint conditions or false
597 gdb_evaluates_breakpoint_condition_p (void)
599 const char *mode
= breakpoint_condition_evaluation_mode ();
601 return (mode
== condition_evaluation_host
);
604 /* Are we executing breakpoint commands? */
605 static int executing_breakpoint_commands
;
607 /* Are overlay event breakpoints enabled? */
608 static int overlay_events_enabled
;
610 /* See description in breakpoint.h. */
611 bool target_exact_watchpoints
= false;
613 /* Walk the following statement or block through all breakpoints.
614 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
615 current breakpoint. */
617 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
618 for (B = breakpoint_chain; \
619 B ? (TMP=B->next, 1): 0; \
622 /* Chains of all breakpoints defined. */
624 static struct breakpoint
*breakpoint_chain
;
626 /* See breakpoint.h. */
631 return breakpoint_range (breakpoint_chain
);
634 /* See breakpoint.h. */
636 breakpoint_safe_range
637 all_breakpoints_safe ()
639 return breakpoint_safe_range (all_breakpoints ());
642 /* See breakpoint.h. */
647 return tracepoint_range (breakpoint_chain
);
650 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
652 static std::vector
<bp_location
*> bp_locations
;
654 /* See breakpoint.h. */
656 const std::vector
<bp_location
*> &
662 /* Range to iterate over breakpoint locations at a given address. */
664 struct bp_locations_at_addr_range
666 using iterator
= std::vector
<bp_location
*>::iterator
;
668 bp_locations_at_addr_range (CORE_ADDR addr
)
672 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
673 { return loc
->address
< addr_
; }
675 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
676 { return addr_
< loc
->address
; }
679 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
682 m_begin
= it_pair
.first
;
683 m_end
= it_pair
.second
;
686 iterator
begin () const
689 iterator
end () const
697 /* Return a range to iterate over all breakpoint locations exactly at address
700 If it's needed to iterate multiple times on the same range, it's possible
701 to save the range in a local variable and use it multiple times:
703 auto range = all_bp_locations_at_addr (addr);
705 for (bp_location *loc : range)
708 for (bp_location *loc : range)
711 This saves a bit of time, as it avoids re-doing the binary searches to find
712 the range's boundaries. Just remember not to change the bp_locations vector
713 in the mean time, as it could make the range's iterators stale. */
715 static bp_locations_at_addr_range
716 all_bp_locations_at_addr (CORE_ADDR addr
)
718 return bp_locations_at_addr_range (addr
);
721 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
722 ADDRESS for the current elements of BP_LOCATIONS which get a valid
723 result from bp_location_has_shadow. You can use it for roughly
724 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
725 an address you need to read. */
727 static CORE_ADDR bp_locations_placed_address_before_address_max
;
729 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
730 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
731 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
732 You can use it for roughly limiting the subrange of BP_LOCATIONS to
733 scan for shadow bytes for an address you need to read. */
735 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
737 /* The locations that no longer correspond to any breakpoint, unlinked
738 from the bp_locations array, but for which a hit may still be
739 reported by a target. */
740 static std::vector
<bp_location
*> moribund_locations
;
742 /* Number of last breakpoint made. */
744 static int breakpoint_count
;
746 /* The value of `breakpoint_count' before the last command that
747 created breakpoints. If the last (break-like) command created more
748 than one breakpoint, then the difference between BREAKPOINT_COUNT
749 and PREV_BREAKPOINT_COUNT is more than one. */
750 static int prev_breakpoint_count
;
752 /* Number of last tracepoint made. */
754 static int tracepoint_count
;
756 static struct cmd_list_element
*breakpoint_set_cmdlist
;
757 static struct cmd_list_element
*breakpoint_show_cmdlist
;
758 struct cmd_list_element
*save_cmdlist
;
760 /* Return whether a breakpoint is an active enabled breakpoint. */
762 breakpoint_enabled (struct breakpoint
*b
)
764 return (b
->enable_state
== bp_enabled
);
767 /* Set breakpoint count to NUM. */
770 set_breakpoint_count (int num
)
772 prev_breakpoint_count
= breakpoint_count
;
773 breakpoint_count
= num
;
774 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
777 /* Used by `start_rbreak_breakpoints' below, to record the current
778 breakpoint count before "rbreak" creates any breakpoint. */
779 static int rbreak_start_breakpoint_count
;
781 /* Called at the start an "rbreak" command to record the first
784 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
786 rbreak_start_breakpoint_count
= breakpoint_count
;
789 /* Called at the end of an "rbreak" command to record the last
792 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
794 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
797 /* Used in run_command to zero the hit count when a new run starts. */
800 clear_breakpoint_hit_counts (void)
802 for (breakpoint
*b
: all_breakpoints ())
807 /* Return the breakpoint with the specified number, or NULL
808 if the number does not refer to an existing breakpoint. */
811 get_breakpoint (int num
)
813 for (breakpoint
*b
: all_breakpoints ())
814 if (b
->number
== num
)
820 /* Return TRUE if NUM refer to an existing breakpoint that has
821 multiple code locations. */
824 has_multiple_locations (int num
)
826 for (breakpoint
*b
: all_breakpoints ())
827 if (b
->number
== num
)
828 return b
->loc
!= nullptr && b
->loc
->next
!= nullptr;
835 /* Mark locations as "conditions have changed" in case the target supports
836 evaluating conditions on its side. */
839 mark_breakpoint_modified (struct breakpoint
*b
)
841 /* This is only meaningful if the target is
842 evaluating conditions and if the user has
843 opted for condition evaluation on the target's
845 if (gdb_evaluates_breakpoint_condition_p ()
846 || !target_supports_evaluation_of_breakpoint_conditions ())
849 if (!is_breakpoint (b
))
852 for (bp_location
*loc
: b
->locations ())
853 loc
->condition_changed
= condition_modified
;
856 /* Mark location as "conditions have changed" in case the target supports
857 evaluating conditions on its side. */
860 mark_breakpoint_location_modified (struct bp_location
*loc
)
862 /* This is only meaningful if the target is
863 evaluating conditions and if the user has
864 opted for condition evaluation on the target's
866 if (gdb_evaluates_breakpoint_condition_p ()
867 || !target_supports_evaluation_of_breakpoint_conditions ())
871 if (!is_breakpoint (loc
->owner
))
874 loc
->condition_changed
= condition_modified
;
877 /* Sets the condition-evaluation mode using the static global
878 condition_evaluation_mode. */
881 set_condition_evaluation_mode (const char *args
, int from_tty
,
882 struct cmd_list_element
*c
)
884 const char *old_mode
, *new_mode
;
886 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
887 && !target_supports_evaluation_of_breakpoint_conditions ())
889 condition_evaluation_mode_1
= condition_evaluation_mode
;
890 warning (_("Target does not support breakpoint condition evaluation.\n"
891 "Using host evaluation mode instead."));
895 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
896 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
898 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
899 settings was "auto". */
900 condition_evaluation_mode
= condition_evaluation_mode_1
;
902 /* Only update the mode if the user picked a different one. */
903 if (new_mode
!= old_mode
)
905 /* If the user switched to a different evaluation mode, we
906 need to synch the changes with the target as follows:
908 "host" -> "target": Send all (valid) conditions to the target.
909 "target" -> "host": Remove all the conditions from the target.
912 if (new_mode
== condition_evaluation_target
)
914 /* Mark everything modified and synch conditions with the
916 for (bp_location
*loc
: all_bp_locations ())
917 mark_breakpoint_location_modified (loc
);
921 /* Manually mark non-duplicate locations to synch conditions
922 with the target. We do this to remove all the conditions the
923 target knows about. */
924 for (bp_location
*loc
: all_bp_locations ())
925 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
926 loc
->needs_update
= 1;
930 update_global_location_list (UGLL_MAY_INSERT
);
936 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
937 what "auto" is translating to. */
940 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
941 struct cmd_list_element
*c
, const char *value
)
943 if (condition_evaluation_mode
== condition_evaluation_auto
)
945 _("Breakpoint condition evaluation "
946 "mode is %s (currently %s).\n"),
948 breakpoint_condition_evaluation_mode ());
950 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
954 /* Parse COND_STRING in the context of LOC and set as the condition
955 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
956 the number of LOC within its owner. In case of parsing error, mark
957 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
960 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
961 int bp_num
, int loc_num
)
963 bool has_junk
= false;
966 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
967 block_for_pc (loc
->address
), 0);
968 if (*cond_string
!= 0)
972 loc
->cond
= std::move (new_exp
);
973 if (loc
->disabled_by_cond
&& loc
->enabled
)
974 gdb_printf (_("Breakpoint %d's condition is now valid at "
975 "location %d, enabling.\n"),
978 loc
->disabled_by_cond
= false;
981 catch (const gdb_exception_error
&e
)
985 /* Warn if a user-enabled location is now becoming disabled-by-cond.
986 BP_NUM is 0 if the breakpoint is being defined for the first
987 time using the "break ... if ..." command, and non-zero if
990 warning (_("failed to validate condition at location %d.%d, "
991 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
993 warning (_("failed to validate condition at location %d, "
994 "disabling:\n %s"), loc_num
, e
.what ());
997 loc
->disabled_by_cond
= true;
1001 error (_("Garbage '%s' follows condition"), cond_string
);
1005 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
1006 int from_tty
, bool force
)
1010 b
->cond_string
.reset ();
1012 if (is_watchpoint (b
))
1013 gdb::checked_static_cast
<watchpoint
*> (b
)->cond_exp
.reset ();
1017 for (bp_location
*loc
: b
->locations ())
1020 if (loc
->disabled_by_cond
&& loc
->enabled
)
1021 gdb_printf (_("Breakpoint %d's condition is now valid at "
1022 "location %d, enabling.\n"),
1023 b
->number
, loc_num
);
1024 loc
->disabled_by_cond
= false;
1027 /* No need to free the condition agent expression
1028 bytecode (if we have one). We will handle this
1029 when we go through update_global_location_list. */
1034 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
1038 if (is_watchpoint (b
))
1040 innermost_block_tracker tracker
;
1041 const char *arg
= exp
;
1042 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
1044 error (_("Junk at end of expression"));
1045 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
1046 w
->cond_exp
= std::move (new_exp
);
1047 w
->cond_exp_valid_block
= tracker
.block ();
1051 /* Parse and set condition expressions. We make two passes.
1052 In the first, we parse the condition string to see if it
1053 is valid in at least one location. If so, the condition
1054 would be accepted. So we go ahead and set the locations'
1055 conditions. In case no valid case is found, we throw
1056 the error and the condition string will be rejected.
1057 This two-pass approach is taken to avoid setting the
1058 state of locations in case of a reject. */
1059 for (bp_location
*loc
: b
->locations ())
1063 const char *arg
= exp
;
1064 parse_exp_1 (&arg
, loc
->address
,
1065 block_for_pc (loc
->address
), 0);
1067 error (_("Junk at end of expression"));
1070 catch (const gdb_exception_error
&e
)
1072 /* Condition string is invalid. If this happens to
1073 be the last loc, abandon (if not forced) or continue
1075 if (loc
->next
== nullptr && !force
)
1080 /* If we reach here, the condition is valid at some locations. */
1082 for (bp_location
*loc
: b
->locations ())
1084 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
1089 /* We know that the new condition parsed successfully. The
1090 condition string of the breakpoint can be safely updated. */
1091 b
->cond_string
= make_unique_xstrdup (exp
);
1092 b
->condition_not_parsed
= 0;
1094 mark_breakpoint_modified (b
);
1096 gdb::observers::breakpoint_modified
.notify (b
);
1099 /* See breakpoint.h. */
1102 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1105 for (breakpoint
*b
: all_breakpoints ())
1106 if (b
->number
== bpnum
)
1108 /* Check if this breakpoint has a "stop" method implemented in an
1109 extension language. This method and conditions entered into GDB
1110 from the CLI are mutually exclusive. */
1111 const struct extension_language_defn
*extlang
1112 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1114 if (extlang
!= NULL
)
1116 error (_("Only one stop condition allowed. There is currently"
1117 " a %s stop condition defined for this breakpoint."),
1118 ext_lang_capitalized_name (extlang
));
1120 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1122 if (is_breakpoint (b
))
1123 update_global_location_list (UGLL_MAY_INSERT
);
1128 error (_("No breakpoint number %d."), bpnum
);
1131 /* The options for the "condition" command. */
1133 struct condition_command_opts
1136 bool force_condition
= false;
1139 static const gdb::option::option_def condition_command_option_defs
[] = {
1141 gdb::option::flag_option_def
<condition_command_opts
> {
1143 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1144 N_("Set the condition even if it is invalid for all current locations."),
1149 /* Create an option_def_group for the "condition" options, with
1150 CC_OPTS as context. */
1152 static inline gdb::option::option_def_group
1153 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1155 return {{condition_command_option_defs
}, cc_opts
};
1158 /* Completion for the "condition" command. */
1161 condition_completer (struct cmd_list_element
*cmd
,
1162 completion_tracker
&tracker
,
1163 const char *text
, const char * /*word*/)
1165 bool has_no_arguments
= (*text
== '\0');
1166 condition_command_opts cc_opts
;
1167 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1168 if (gdb::option::complete_options
1169 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1172 text
= skip_spaces (text
);
1173 const char *space
= skip_to_space (text
);
1180 tracker
.advance_custom_word_point_by (1);
1181 /* We don't support completion of history indices. */
1182 if (!isdigit (text
[1]))
1183 complete_internalvar (tracker
, &text
[1]);
1187 /* Suggest the "-force" flag if no arguments are given. If
1188 arguments were passed, they either already include the flag,
1189 or we are beyond the point of suggesting it because it's
1190 positionally the first argument. */
1191 if (has_no_arguments
)
1192 gdb::option::complete_on_all_options (tracker
, group
);
1194 /* We're completing the breakpoint number. */
1195 len
= strlen (text
);
1197 for (breakpoint
*b
: all_breakpoints ())
1201 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1203 if (strncmp (number
, text
, len
) == 0)
1204 tracker
.add_completion (make_unique_xstrdup (number
));
1210 /* We're completing the expression part. Skip the breakpoint num. */
1211 const char *exp_start
= skip_spaces (space
);
1212 tracker
.advance_custom_word_point_by (exp_start
- text
);
1214 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1215 expression_completer (cmd
, tracker
, text
, word
);
1218 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1221 condition_command (const char *arg
, int from_tty
)
1227 error_no_arg (_("breakpoint number"));
1231 /* Check if the "-force" flag was passed. */
1232 condition_command_opts cc_opts
;
1233 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1234 gdb::option::process_options
1235 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1237 bnum
= get_number (&p
);
1239 error (_("Bad breakpoint argument: '%s'"), arg
);
1241 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1244 /* Check that COMMAND do not contain commands that are suitable
1245 only for tracepoints and not suitable for ordinary breakpoints.
1246 Throw if any such commands is found. */
1249 check_no_tracepoint_commands (struct command_line
*commands
)
1251 struct command_line
*c
;
1253 for (c
= commands
; c
; c
= c
->next
)
1255 if (c
->control_type
== while_stepping_control
)
1256 error (_("The 'while-stepping' command can "
1257 "only be used for tracepoints"));
1259 check_no_tracepoint_commands (c
->body_list_0
.get ());
1260 check_no_tracepoint_commands (c
->body_list_1
.get ());
1262 /* Not that command parsing removes leading whitespace and comment
1263 lines and also empty lines. So, we only need to check for
1264 command directly. */
1265 if (strstr (c
->line
, "collect ") == c
->line
)
1266 error (_("The 'collect' command can only be used for tracepoints"));
1268 if (strstr (c
->line
, "teval ") == c
->line
)
1269 error (_("The 'teval' command can only be used for tracepoints"));
1273 struct longjmp_breakpoint
: public momentary_breakpoint
1275 using momentary_breakpoint::momentary_breakpoint
;
1277 ~longjmp_breakpoint () override
;
1280 /* Encapsulate tests for different types of tracepoints. */
1283 is_tracepoint_type (bptype type
)
1285 return (type
== bp_tracepoint
1286 || type
== bp_fast_tracepoint
1287 || type
== bp_static_tracepoint
1288 || type
== bp_static_marker_tracepoint
);
1291 /* See breakpoint.h. */
1294 is_tracepoint (const struct breakpoint
*b
)
1296 return is_tracepoint_type (b
->type
);
1299 /* Factory function to create an appropriate instance of breakpoint given
1302 template<typename
... Arg
>
1303 static std::unique_ptr
<code_breakpoint
>
1304 new_breakpoint_from_type (struct gdbarch
*gdbarch
, bptype type
,
1312 case bp_hardware_breakpoint
:
1313 b
= new ordinary_breakpoint (gdbarch
, type
,
1314 std::forward
<Arg
> (args
)...);
1317 case bp_fast_tracepoint
:
1318 case bp_static_tracepoint
:
1320 b
= new tracepoint (gdbarch
, type
,
1321 std::forward
<Arg
> (args
)...);
1324 case bp_static_marker_tracepoint
:
1325 b
= new static_marker_tracepoint (gdbarch
, type
,
1326 std::forward
<Arg
> (args
)...);
1330 b
= new dprintf_breakpoint (gdbarch
, type
,
1331 std::forward
<Arg
> (args
)...);
1335 gdb_assert_not_reached ("invalid type");
1338 return std::unique_ptr
<code_breakpoint
> (b
);
1341 /* A helper function that validates that COMMANDS are valid for a
1342 breakpoint. This function will throw an exception if a problem is
1346 validate_commands_for_breakpoint (struct breakpoint
*b
,
1347 struct command_line
*commands
)
1349 if (is_tracepoint (b
))
1351 struct tracepoint
*t
= (struct tracepoint
*) b
;
1352 struct command_line
*c
;
1353 struct command_line
*while_stepping
= 0;
1355 /* Reset the while-stepping step count. The previous commands
1356 might have included a while-stepping action, while the new
1360 /* We need to verify that each top-level element of commands is
1361 valid for tracepoints, that there's at most one
1362 while-stepping element, and that the while-stepping's body
1363 has valid tracing commands excluding nested while-stepping.
1364 We also need to validate the tracepoint action line in the
1365 context of the tracepoint --- validate_actionline actually
1366 has side effects, like setting the tracepoint's
1367 while-stepping STEP_COUNT, in addition to checking if the
1368 collect/teval actions parse and make sense in the
1369 tracepoint's context. */
1370 for (c
= commands
; c
; c
= c
->next
)
1372 if (c
->control_type
== while_stepping_control
)
1374 if (b
->type
== bp_fast_tracepoint
)
1375 error (_("The 'while-stepping' command "
1376 "cannot be used for fast tracepoint"));
1377 else if (b
->type
== bp_static_tracepoint
1378 || b
->type
== bp_static_marker_tracepoint
)
1379 error (_("The 'while-stepping' command "
1380 "cannot be used for static tracepoint"));
1383 error (_("The 'while-stepping' command "
1384 "can be used only once"));
1389 validate_actionline (c
->line
, b
);
1393 struct command_line
*c2
;
1395 gdb_assert (while_stepping
->body_list_1
== nullptr);
1396 c2
= while_stepping
->body_list_0
.get ();
1397 for (; c2
; c2
= c2
->next
)
1399 if (c2
->control_type
== while_stepping_control
)
1400 error (_("The 'while-stepping' command cannot be nested"));
1406 check_no_tracepoint_commands (commands
);
1410 /* Return a vector of all the static tracepoints set at ADDR. The
1411 caller is responsible for releasing the vector. */
1413 std::vector
<breakpoint
*>
1414 static_tracepoints_here (CORE_ADDR addr
)
1416 std::vector
<breakpoint
*> found
;
1418 for (breakpoint
*b
: all_breakpoints ())
1419 if (b
->type
== bp_static_tracepoint
1420 || b
->type
== bp_static_marker_tracepoint
)
1422 for (bp_location
*loc
: b
->locations ())
1423 if (loc
->address
== addr
)
1424 found
.push_back (b
);
1430 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1431 validate that only allowed commands are included. */
1434 breakpoint_set_commands (struct breakpoint
*b
,
1435 counted_command_line
&&commands
)
1437 validate_commands_for_breakpoint (b
, commands
.get ());
1439 b
->commands
= std::move (commands
);
1440 gdb::observers::breakpoint_modified
.notify (b
);
1443 /* Set the internal `silent' flag on the breakpoint. Note that this
1444 is not the same as the "silent" that may appear in the breakpoint's
1448 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1450 int old_silent
= b
->silent
;
1453 if (old_silent
!= silent
)
1454 gdb::observers::breakpoint_modified
.notify (b
);
1457 /* See breakpoint.h. */
1460 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1462 /* It is invalid to set the thread field to anything other than -1 (which
1463 means no thread restriction) if a task restriction is already in
1465 gdb_assert (thread
== -1 || b
->task
== -1);
1467 int old_thread
= b
->thread
;
1470 if (old_thread
!= thread
)
1471 gdb::observers::breakpoint_modified
.notify (b
);
1474 /* See breakpoint.h. */
1477 breakpoint_set_task (struct breakpoint
*b
, int task
)
1479 /* It is invalid to set the task field to anything other than -1 (which
1480 means no task restriction) if a thread restriction is already in
1482 gdb_assert (task
== -1 || b
->thread
== -1);
1484 int old_task
= b
->task
;
1487 if (old_task
!= task
)
1488 gdb::observers::breakpoint_modified
.notify (b
);
1492 commands_command_1 (const char *arg
, int from_tty
,
1493 struct command_line
*control
)
1495 counted_command_line cmd
;
1496 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1497 NULL after the call to read_command_lines if the user provides an empty
1498 list of command by just typing "end". */
1499 bool cmd_read
= false;
1501 std::string new_arg
;
1503 if (arg
== NULL
|| !*arg
)
1505 /* Argument not explicitly given. Synthesize it. */
1506 if (breakpoint_count
- prev_breakpoint_count
> 1)
1507 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1509 else if (breakpoint_count
> 0)
1510 new_arg
= string_printf ("%d", breakpoint_count
);
1514 /* Create a copy of ARG. This is needed because the "commands"
1515 command may be coming from a script. In that case, the read
1516 line buffer is going to be overwritten in the lambda of
1517 'map_breakpoint_numbers' below when reading the next line
1518 before we are are done parsing the breakpoint numbers. */
1521 arg
= new_arg
.c_str ();
1523 map_breakpoint_numbers
1524 (arg
, [&] (breakpoint
*b
)
1528 gdb_assert (cmd
== NULL
);
1529 if (control
!= NULL
)
1530 cmd
= control
->body_list_0
;
1534 = string_printf (_("Type commands for breakpoint(s) "
1535 "%s, one per line."),
1538 auto do_validate
= [=] (const char *line
)
1540 validate_actionline (line
, b
);
1542 gdb::function_view
<void (const char *)> validator
;
1543 if (is_tracepoint (b
))
1544 validator
= do_validate
;
1546 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1551 /* If a breakpoint was on the list more than once, we don't need to
1553 if (b
->commands
!= cmd
)
1555 validate_commands_for_breakpoint (b
, cmd
.get ());
1557 gdb::observers::breakpoint_modified
.notify (b
);
1563 commands_command (const char *arg
, int from_tty
)
1565 commands_command_1 (arg
, from_tty
, NULL
);
1568 /* Like commands_command, but instead of reading the commands from
1569 input stream, takes them from an already parsed command structure.
1571 This is used by cli-script.c to DTRT with breakpoint commands
1572 that are part of if and while bodies. */
1573 enum command_control_type
1574 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1576 commands_command_1 (arg
, 0, cmd
);
1577 return simple_control
;
1580 /* Return true if BL->TARGET_INFO contains valid information. */
1583 bp_location_has_shadow (struct bp_location
*bl
)
1585 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1589 if (bl
->target_info
.shadow_len
== 0)
1590 /* BL isn't valid, or doesn't shadow memory. */
1595 /* Update BUF, which is LEN bytes read from the target address
1596 MEMADDR, by replacing a memory breakpoint with its shadowed
1599 If READBUF is not NULL, this buffer must not overlap with the of
1600 the breakpoint location's shadow_contents buffer. Otherwise, a
1601 failed assertion internal error will be raised. */
1604 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1605 const gdb_byte
*writebuf_org
,
1606 ULONGEST memaddr
, LONGEST len
,
1607 struct bp_target_info
*target_info
,
1608 struct gdbarch
*gdbarch
)
1610 /* Now do full processing of the found relevant range of elements. */
1611 CORE_ADDR bp_addr
= 0;
1615 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1616 current_program_space
->aspace
, 0))
1618 /* The breakpoint is inserted in a different address space. */
1622 /* Addresses and length of the part of the breakpoint that
1624 bp_addr
= target_info
->placed_address
;
1625 bp_size
= target_info
->shadow_len
;
1627 if (bp_addr
+ bp_size
<= memaddr
)
1629 /* The breakpoint is entirely before the chunk of memory we are
1634 if (bp_addr
>= memaddr
+ len
)
1636 /* The breakpoint is entirely after the chunk of memory we are
1641 /* Offset within shadow_contents. */
1642 if (bp_addr
< memaddr
)
1644 /* Only copy the second part of the breakpoint. */
1645 bp_size
-= memaddr
- bp_addr
;
1646 bptoffset
= memaddr
- bp_addr
;
1650 if (bp_addr
+ bp_size
> memaddr
+ len
)
1652 /* Only copy the first part of the breakpoint. */
1653 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1656 if (readbuf
!= NULL
)
1658 /* Verify that the readbuf buffer does not overlap with the
1659 shadow_contents buffer. */
1660 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1661 || readbuf
>= (target_info
->shadow_contents
1662 + target_info
->shadow_len
));
1664 /* Update the read buffer with this inserted breakpoint's
1666 memcpy (readbuf
+ bp_addr
- memaddr
,
1667 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1671 const unsigned char *bp
;
1672 CORE_ADDR addr
= target_info
->reqstd_address
;
1675 /* Update the shadow with what we want to write to memory. */
1676 memcpy (target_info
->shadow_contents
+ bptoffset
,
1677 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1679 /* Determine appropriate breakpoint contents and size for this
1681 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1683 /* Update the final write buffer with this inserted
1684 breakpoint's INSN. */
1685 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1689 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1690 by replacing any memory breakpoints with their shadowed contents.
1692 If READBUF is not NULL, this buffer must not overlap with any of
1693 the breakpoint location's shadow_contents buffers. Otherwise,
1694 a failed assertion internal error will be raised.
1696 The range of shadowed area by each bp_location is:
1697 bl->address - bp_locations_placed_address_before_address_max
1698 up to bl->address + bp_locations_shadow_len_after_address_max
1699 The range we were requested to resolve shadows for is:
1700 memaddr ... memaddr + len
1701 Thus the safe cutoff boundaries for performance optimization are
1702 memaddr + len <= (bl->address
1703 - bp_locations_placed_address_before_address_max)
1705 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1708 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1709 const gdb_byte
*writebuf_org
,
1710 ULONGEST memaddr
, LONGEST len
)
1712 /* Left boundary, right boundary and median element of our binary
1714 unsigned bc_l
, bc_r
, bc
;
1716 /* Find BC_L which is a leftmost element which may affect BUF
1717 content. It is safe to report lower value but a failure to
1718 report higher one. */
1721 bc_r
= bp_locations
.size ();
1722 while (bc_l
+ 1 < bc_r
)
1724 struct bp_location
*bl
;
1726 bc
= (bc_l
+ bc_r
) / 2;
1727 bl
= bp_locations
[bc
];
1729 /* Check first BL->ADDRESS will not overflow due to the added
1730 constant. Then advance the left boundary only if we are sure
1731 the BC element can in no way affect the BUF content (MEMADDR
1732 to MEMADDR + LEN range).
1734 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1735 offset so that we cannot miss a breakpoint with its shadow
1736 range tail still reaching MEMADDR. */
1738 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1740 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1747 /* Due to the binary search above, we need to make sure we pick the
1748 first location that's at BC_L's address. E.g., if there are
1749 multiple locations at the same address, BC_L may end up pointing
1750 at a duplicate location, and miss the "master"/"inserted"
1751 location. Say, given locations L1, L2 and L3 at addresses A and
1754 L1@A, L2@A, L3@B, ...
1756 BC_L could end up pointing at location L2, while the "master"
1757 location could be L1. Since the `loc->inserted' flag is only set
1758 on "master" locations, we'd forget to restore the shadow of L1
1761 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1764 /* Now do full processing of the found relevant range of elements. */
1766 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1768 struct bp_location
*bl
= bp_locations
[bc
];
1770 /* bp_location array has BL->OWNER always non-NULL. */
1771 if (bl
->owner
->type
== bp_none
)
1772 warning (_("reading through apparently deleted breakpoint #%d?"),
1775 /* Performance optimization: any further element can no longer affect BUF
1778 if (bl
->address
>= bp_locations_placed_address_before_address_max
1781 - bp_locations_placed_address_before_address_max
)))
1784 if (!bp_location_has_shadow (bl
))
1787 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1788 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1792 /* See breakpoint.h. */
1795 is_breakpoint (const struct breakpoint
*bpt
)
1797 return (bpt
->type
== bp_breakpoint
1798 || bpt
->type
== bp_hardware_breakpoint
1799 || bpt
->type
== bp_dprintf
);
1802 /* Return true if BPT is of any hardware watchpoint kind. */
1805 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1807 return (bpt
->type
== bp_hardware_watchpoint
1808 || bpt
->type
== bp_read_watchpoint
1809 || bpt
->type
== bp_access_watchpoint
);
1812 /* See breakpoint.h. */
1815 is_watchpoint (const struct breakpoint
*bpt
)
1817 return (is_hardware_watchpoint (bpt
)
1818 || bpt
->type
== bp_watchpoint
);
1821 /* Returns true if the current thread and its running state are safe
1822 to evaluate or update watchpoint B. Watchpoints on local
1823 expressions need to be evaluated in the context of the thread that
1824 was current when the watchpoint was created, and, that thread needs
1825 to be stopped to be able to select the correct frame context.
1826 Watchpoints on global expressions can be evaluated on any thread,
1827 and in any state. It is presently left to the target allowing
1828 memory accesses when threads are running. */
1831 watchpoint_in_thread_scope (struct watchpoint
*b
)
1833 return (b
->pspace
== current_program_space
1834 && (b
->watchpoint_thread
== null_ptid
1835 || (inferior_ptid
== b
->watchpoint_thread
1836 && !inferior_thread ()->executing ())));
1839 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1840 associated bp_watchpoint_scope breakpoint. */
1843 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1845 if (w
->related_breakpoint
!= w
)
1847 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1848 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1849 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1850 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1851 w
->related_breakpoint
= w
;
1853 w
->disposition
= disp_del_at_next_stop
;
1856 /* Extract a bitfield value from value VAL using the bit parameters contained in
1859 static struct value
*
1860 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1862 struct value
*bit_val
;
1867 bit_val
= value::allocate (val
->type ());
1869 val
->unpack_bitfield (bit_val
,
1872 val
->contents_for_printing ().data (),
1878 /* Allocate a dummy location and add it to B. This is required
1879 because bpstat_stop_status requires a location to be able to report
1883 add_dummy_location (struct breakpoint
*b
,
1884 struct program_space
*pspace
)
1886 gdb_assert (b
->loc
== NULL
);
1888 b
->loc
= new bp_location (b
, bp_loc_other
);
1889 b
->loc
->pspace
= pspace
;
1892 /* Assuming that B is a watchpoint:
1893 - Reparse watchpoint expression, if REPARSE is true
1894 - Evaluate expression and store the result in B->val
1895 - Evaluate the condition if there is one, and store the result
1897 - Update the list of values that must be watched in B->loc.
1899 If the watchpoint disposition is disp_del_at_next_stop, then do
1900 nothing. If this is local watchpoint that is out of scope, delete
1903 Even with `set breakpoint always-inserted on' the watchpoints are
1904 removed + inserted on each stop here. Normal breakpoints must
1905 never be removed because they might be missed by a running thread
1906 when debugging in non-stop mode. On the other hand, hardware
1907 watchpoints (is_hardware_watchpoint; processed here) are specific
1908 to each LWP since they are stored in each LWP's hardware debug
1909 registers. Therefore, such LWP must be stopped first in order to
1910 be able to modify its hardware watchpoints.
1912 Hardware watchpoints must be reset exactly once after being
1913 presented to the user. It cannot be done sooner, because it would
1914 reset the data used to present the watchpoint hit to the user. And
1915 it must not be done later because it could display the same single
1916 watchpoint hit during multiple GDB stops. Note that the latter is
1917 relevant only to the hardware watchpoint types bp_read_watchpoint
1918 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1919 not user-visible - its hit is suppressed if the memory content has
1922 The following constraints influence the location where we can reset
1923 hardware watchpoints:
1925 * target_stopped_by_watchpoint and target_stopped_data_address are
1926 called several times when GDB stops.
1929 * Multiple hardware watchpoints can be hit at the same time,
1930 causing GDB to stop. GDB only presents one hardware watchpoint
1931 hit at a time as the reason for stopping, and all the other hits
1932 are presented later, one after the other, each time the user
1933 requests the execution to be resumed. Execution is not resumed
1934 for the threads still having pending hit event stored in
1935 LWP_INFO->STATUS. While the watchpoint is already removed from
1936 the inferior on the first stop the thread hit event is kept being
1937 reported from its cached value by linux_nat_stopped_data_address
1938 until the real thread resume happens after the watchpoint gets
1939 presented and thus its LWP_INFO->STATUS gets reset.
1941 Therefore the hardware watchpoint hit can get safely reset on the
1942 watchpoint removal from inferior. */
1945 update_watchpoint (struct watchpoint
*b
, bool reparse
)
1947 bool within_current_scope
;
1949 /* If this is a local watchpoint, we only want to check if the
1950 watchpoint frame is in scope if the current thread is the thread
1951 that was used to create the watchpoint. */
1952 if (!watchpoint_in_thread_scope (b
))
1955 if (b
->disposition
== disp_del_at_next_stop
)
1958 gdb::optional
<scoped_restore_selected_frame
> restore_frame
;
1960 /* Determine if the watchpoint is within scope. */
1961 if (b
->exp_valid_block
== NULL
)
1962 within_current_scope
= true;
1965 frame_info_ptr fi
= get_current_frame ();
1966 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1967 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1969 /* If we're at a point where the stack has been destroyed
1970 (e.g. in a function epilogue), unwinding may not work
1971 properly. Do not attempt to recreate locations at this
1972 point. See similar comments in watchpoint_check. */
1973 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1976 /* Save the current frame's ID so we can restore it after
1977 evaluating the watchpoint expression on its own frame. */
1978 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1979 took a frame parameter, so that we didn't have to change the
1981 restore_frame
.emplace ();
1983 fi
= frame_find_by_id (b
->watchpoint_frame
);
1984 within_current_scope
= (fi
!= NULL
);
1985 if (within_current_scope
)
1989 /* We don't free locations. They are stored in the bp_location array
1990 and update_global_location_list will eventually delete them and
1991 remove breakpoints if needed. */
1994 if (within_current_scope
&& reparse
)
1999 s
= (b
->exp_string_reparse
2000 ? b
->exp_string_reparse
.get ()
2001 : b
->exp_string
.get ());
2002 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
2003 /* If the meaning of expression itself changed, the old value is
2004 no longer relevant. We don't want to report a watchpoint hit
2005 to the user when the old value and the new value may actually
2006 be completely different objects. */
2008 b
->val_valid
= false;
2010 /* Note that unlike with breakpoints, the watchpoint's condition
2011 expression is stored in the breakpoint object, not in the
2012 locations (re)created below. */
2013 if (b
->cond_string
!= NULL
)
2015 b
->cond_exp
.reset ();
2017 s
= b
->cond_string
.get ();
2018 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
2022 /* If we failed to parse the expression, for example because
2023 it refers to a global variable in a not-yet-loaded shared library,
2024 don't try to insert watchpoint. We don't automatically delete
2025 such watchpoint, though, since failure to parse expression
2026 is different from out-of-scope watchpoint. */
2027 if (!target_has_execution ())
2029 /* Without execution, memory can't change. No use to try and
2030 set watchpoint locations. The watchpoint will be reset when
2031 the target gains execution, through breakpoint_re_set. */
2032 if (!can_use_hw_watchpoints
)
2034 if (b
->works_in_software_mode ())
2035 b
->type
= bp_watchpoint
;
2037 error (_("Can't set read/access watchpoint when "
2038 "hardware watchpoints are disabled."));
2041 else if (within_current_scope
&& b
->exp
)
2043 std::vector
<value_ref_ptr
> val_chain
;
2044 struct value
*v
, *result
;
2045 struct program_space
*frame_pspace
;
2047 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2050 /* Avoid setting b->val if it's already set. The meaning of
2051 b->val is 'the last value' user saw, and we should update
2052 it only if we reported that last value to user. As it
2053 happens, the code that reports it updates b->val directly.
2054 We don't keep track of the memory value for masked
2056 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2058 if (b
->val_bitsize
!= 0)
2059 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2060 b
->val
= release_value (v
);
2061 b
->val_valid
= true;
2064 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2066 /* Look at each value on the value chain. */
2067 gdb_assert (!val_chain
.empty ());
2068 for (const value_ref_ptr
&iter
: val_chain
)
2072 /* If it's a memory location, and GDB actually needed
2073 its contents to evaluate the expression, then we
2074 must watch it. If the first value returned is
2075 still lazy, that means an error occurred reading it;
2076 watch it anyway in case it becomes readable. */
2077 if (v
->lval () == lval_memory
2078 && (v
== val_chain
[0] || ! v
->lazy ()))
2080 struct type
*vtype
= check_typedef (v
->type ());
2082 /* We only watch structs and arrays if user asked
2083 for it explicitly, never if they just happen to
2084 appear in the middle of some value chain. */
2086 || (vtype
->code () != TYPE_CODE_STRUCT
2087 && vtype
->code () != TYPE_CODE_ARRAY
))
2090 enum target_hw_bp_type type
;
2091 struct bp_location
*loc
, **tmp
;
2092 int bitpos
= 0, bitsize
= 0;
2094 if (v
->bitsize () != 0)
2096 /* Extract the bit parameters out from the bitfield
2098 bitpos
= v
->bitpos ();
2099 bitsize
= v
->bitsize ();
2101 else if (v
== result
&& b
->val_bitsize
!= 0)
2103 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2104 lvalue whose bit parameters are saved in the fields
2105 VAL_BITPOS and VAL_BITSIZE. */
2106 bitpos
= b
->val_bitpos
;
2107 bitsize
= b
->val_bitsize
;
2110 addr
= v
->address ();
2113 /* Skip the bytes that don't contain the bitfield. */
2118 if (b
->type
== bp_read_watchpoint
)
2120 else if (b
->type
== bp_access_watchpoint
)
2123 loc
= b
->allocate_location ();
2124 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2127 loc
->gdbarch
= v
->type ()->arch ();
2129 loc
->pspace
= frame_pspace
;
2131 = gdbarch_remove_non_address_bits (loc
->gdbarch
, addr
);
2135 /* Just cover the bytes that make up the bitfield. */
2136 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2139 loc
->length
= v
->type ()->length ();
2141 loc
->watchpoint_type
= type
;
2146 /* Helper function to bundle possibly emitting a warning along with
2147 changing the type of B to bp_watchpoint. */
2148 auto change_type_to_bp_watchpoint
= [] (breakpoint
*bp
)
2150 /* Only warn for breakpoints that have been assigned a +ve number,
2151 anything else is either an internal watchpoint (which we don't
2152 currently create) or has not yet been finalized, in which case
2153 this change of type will be occurring before the user is told
2154 the type of this watchpoint. */
2155 if (bp
->type
== bp_hardware_watchpoint
&& bp
->number
> 0)
2156 warning (_("watchpoint %d downgraded to software watchpoint"),
2158 bp
->type
= bp_watchpoint
;
2161 /* Change the type of breakpoint between hardware assisted or
2162 an ordinary watchpoint depending on the hardware support and
2163 free hardware slots. Recheck the number of free hardware slots
2164 as the value chain may have changed. */
2167 enum bp_loc_type loc_type
;
2169 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2173 int i
, target_resources_ok
, other_type_used
;
2176 /* Use an exact watchpoint when there's only one memory region to be
2177 watched, and only one debug register is needed to watch it. */
2178 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2180 /* We need to determine how many resources are already
2181 used for all other hardware watchpoints plus this one
2182 to see if we still have enough resources to also fit
2183 this watchpoint in as well. */
2185 /* If this is a software watchpoint, we try to turn it
2186 to a hardware one -- count resources as if B was of
2187 hardware watchpoint type. */
2189 if (type
== bp_watchpoint
)
2190 type
= bp_hardware_watchpoint
;
2192 /* This watchpoint may or may not have been placed on
2193 the list yet at this point (it won't be in the list
2194 if we're trying to create it for the first time,
2195 through watch_command), so always account for it
2198 /* Count resources used by all watchpoints except B. */
2199 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2201 /* Add in the resources needed for B. */
2202 i
+= hw_watchpoint_use_count (b
);
2205 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2206 if (target_resources_ok
<= 0)
2208 bool sw_mode
= b
->works_in_software_mode ();
2210 if (target_resources_ok
== 0 && !sw_mode
)
2211 error (_("Target does not support this type of "
2212 "hardware watchpoint."));
2213 else if (target_resources_ok
< 0 && !sw_mode
)
2214 error (_("There are not enough available hardware "
2215 "resources for this watchpoint."));
2217 /* Downgrade to software watchpoint. */
2218 change_type_to_bp_watchpoint (b
);
2222 /* If this was a software watchpoint, we've just
2223 found we have enough resources to turn it to a
2224 hardware watchpoint. Otherwise, this is a
2229 else if (!b
->works_in_software_mode ())
2231 if (!can_use_hw_watchpoints
)
2232 error (_("Can't set read/access watchpoint when "
2233 "hardware watchpoints are disabled."));
2235 error (_("Expression cannot be implemented with "
2236 "read/access watchpoint."));
2239 change_type_to_bp_watchpoint (b
);
2241 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_software_watchpoint
2242 : bp_loc_hardware_watchpoint
);
2243 for (bp_location
*bl
: b
->locations ())
2244 bl
->loc_type
= loc_type
;
2247 /* If a software watchpoint is not watching any memory, then the
2248 above left it without any location set up. But,
2249 bpstat_stop_status requires a location to be able to report
2250 stops, so make sure there's at least a dummy one. */
2251 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2252 add_dummy_location (b
, frame_pspace
);
2254 else if (!within_current_scope
)
2257 Watchpoint %d deleted because the program has left the block\n\
2258 in which its expression is valid.\n"),
2260 watchpoint_del_at_next_stop (b
);
2264 /* Returns true iff breakpoint location should be
2265 inserted in the inferior. We don't differentiate the type of BL's owner
2266 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2267 breakpoint_ops is not defined, because in insert_bp_location,
2268 tracepoint's insert_location will not be called. */
2271 should_be_inserted (struct bp_location
*bl
)
2273 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2276 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2279 if (!bl
->enabled
|| bl
->disabled_by_cond
2280 || bl
->shlib_disabled
|| bl
->duplicate
)
2283 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2286 /* This is set for example, when we're attached to the parent of a
2287 vfork, and have detached from the child. The child is running
2288 free, and we expect it to do an exec or exit, at which point the
2289 OS makes the parent schedulable again (and the target reports
2290 that the vfork is done). Until the child is done with the shared
2291 memory region, do not insert breakpoints in the parent, otherwise
2292 the child could still trip on the parent's breakpoints. Since
2293 the parent is blocked anyway, it won't miss any breakpoint. */
2294 if (bl
->pspace
->breakpoints_not_allowed
)
2297 /* Don't insert a breakpoint if we're trying to step past its
2298 location, except if the breakpoint is a single-step breakpoint,
2299 and the breakpoint's thread is the thread which is stepping past
2301 if ((bl
->loc_type
== bp_loc_software_breakpoint
2302 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2303 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2305 /* The single-step breakpoint may be inserted at the location
2306 we're trying to step if the instruction branches to itself.
2307 However, the instruction won't be executed at all and it may
2308 break the semantics of the instruction, for example, the
2309 instruction is a conditional branch or updates some flags.
2310 We can't fix it unless GDB is able to emulate the instruction
2311 or switch to displaced stepping. */
2312 && !(bl
->owner
->type
== bp_single_step
2313 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2315 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2316 paddress (bl
->gdbarch
, bl
->address
));
2320 /* Don't insert watchpoints if we're trying to step past the
2321 instruction that triggered one. */
2322 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2323 && stepping_past_nonsteppable_watchpoint ())
2325 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2326 "skipping watchpoint at %s:%d",
2327 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2334 /* Same as should_be_inserted but does the check assuming
2335 that the location is not duplicated. */
2338 unduplicated_should_be_inserted (struct bp_location
*bl
)
2340 scoped_restore restore_bl_duplicate
2341 = make_scoped_restore (&bl
->duplicate
, 0);
2343 return should_be_inserted (bl
);
2346 /* Parses a conditional described by an expression COND into an
2347 agent expression bytecode suitable for evaluation
2348 by the bytecode interpreter. Return NULL if there was
2349 any error during parsing. */
2351 static agent_expr_up
2352 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2357 agent_expr_up aexpr
;
2359 /* We don't want to stop processing, so catch any errors
2360 that may show up. */
2363 aexpr
= gen_eval_for_expr (scope
, cond
);
2366 catch (const gdb_exception_error
&ex
)
2368 /* If we got here, it means the condition could not be parsed to a valid
2369 bytecode expression and thus can't be evaluated on the target's side.
2370 It's no use iterating through the conditions. */
2373 /* We have a valid agent expression. */
2377 /* Based on location BL, create a list of breakpoint conditions to be
2378 passed on to the target. If we have duplicated locations with different
2379 conditions, we will add such conditions to the list. The idea is that the
2380 target will evaluate the list of conditions and will only notify GDB when
2381 one of them is true. */
2384 build_target_condition_list (struct bp_location
*bl
)
2386 bool null_condition_or_parse_error
= false;
2387 int modified
= bl
->needs_update
;
2389 /* Release conditions left over from a previous insert. */
2390 bl
->target_info
.conditions
.clear ();
2392 /* This is only meaningful if the target is
2393 evaluating conditions and if the user has
2394 opted for condition evaluation on the target's
2396 if (gdb_evaluates_breakpoint_condition_p ()
2397 || !target_supports_evaluation_of_breakpoint_conditions ())
2400 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2402 /* Do a first pass to check for locations with no assigned
2403 conditions or conditions that fail to parse to a valid agent
2404 expression bytecode. If any of these happen, then it's no use to
2405 send conditions to the target since this location will always
2406 trigger and generate a response back to GDB. Note we consider
2407 all locations at the same address irrespective of type, i.e.,
2408 even if the locations aren't considered duplicates (e.g.,
2409 software breakpoint and hardware breakpoint at the same
2411 for (bp_location
*loc
: loc_range
)
2413 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2417 /* Re-parse the conditions since something changed. In that
2418 case we already freed the condition bytecodes (see
2419 force_breakpoint_reinsertion). We just
2420 need to parse the condition to bytecodes again. */
2421 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2425 /* If we have a NULL bytecode expression, it means something
2426 went wrong or we have a null condition expression. */
2427 if (!loc
->cond_bytecode
)
2429 null_condition_or_parse_error
= true;
2435 /* If any of these happened, it means we will have to evaluate the conditions
2436 for the location's address on gdb's side. It is no use keeping bytecodes
2437 for all the other duplicate locations, thus we free all of them here.
2439 This is so we have a finer control over which locations' conditions are
2440 being evaluated by GDB or the remote stub. */
2441 if (null_condition_or_parse_error
)
2443 for (bp_location
*loc
: loc_range
)
2445 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2447 /* Only go as far as the first NULL bytecode is
2449 if (!loc
->cond_bytecode
)
2452 loc
->cond_bytecode
.reset ();
2457 /* No NULL conditions or failed bytecode generation. Build a
2458 condition list for this location's address. If we have software
2459 and hardware locations at the same address, they aren't
2460 considered duplicates, but we still marge all the conditions
2461 anyway, as it's simpler, and doesn't really make a practical
2463 for (bp_location
*loc
: loc_range
)
2465 && is_breakpoint (loc
->owner
)
2466 && loc
->pspace
->num
== bl
->pspace
->num
2467 && loc
->owner
->enable_state
== bp_enabled
2469 && !loc
->disabled_by_cond
)
2471 /* Add the condition to the vector. This will be used later
2472 to send the conditions to the target. */
2473 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2479 /* Parses a command described by string CMD into an agent expression
2480 bytecode suitable for evaluation by the bytecode interpreter.
2481 Return NULL if there was any error during parsing. */
2483 static agent_expr_up
2484 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2486 const char *cmdrest
;
2487 const char *format_start
, *format_end
;
2488 struct gdbarch
*gdbarch
= get_current_arch ();
2495 if (*cmdrest
== ',')
2497 cmdrest
= skip_spaces (cmdrest
);
2499 if (*cmdrest
++ != '"')
2500 error (_("No format string following the location"));
2502 format_start
= cmdrest
;
2504 format_pieces
fpieces (&cmdrest
);
2506 format_end
= cmdrest
;
2508 if (*cmdrest
++ != '"')
2509 error (_("Bad format string, non-terminated '\"'."));
2511 cmdrest
= skip_spaces (cmdrest
);
2513 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2514 error (_("Invalid argument syntax"));
2516 if (*cmdrest
== ',')
2518 cmdrest
= skip_spaces (cmdrest
);
2520 /* For each argument, make an expression. */
2522 std::vector
<struct expression
*> argvec
;
2523 while (*cmdrest
!= '\0')
2528 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2529 argvec
.push_back (expr
.release ());
2531 if (*cmdrest
== ',')
2535 agent_expr_up aexpr
;
2537 /* We don't want to stop processing, so catch any errors
2538 that may show up. */
2541 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2542 format_start
, format_end
- format_start
,
2543 argvec
.size (), argvec
.data ());
2545 catch (const gdb_exception_error
&ex
)
2547 /* If we got here, it means the command could not be parsed to a valid
2548 bytecode expression and thus can't be evaluated on the target's side.
2549 It's no use iterating through the other commands. */
2552 /* We have a valid agent expression, return it. */
2556 /* Based on location BL, create a list of breakpoint commands to be
2557 passed on to the target. If we have duplicated locations with
2558 different commands, we will add any such to the list. */
2561 build_target_command_list (struct bp_location
*bl
)
2563 bool null_command_or_parse_error
= false;
2564 int modified
= bl
->needs_update
;
2566 /* Clear commands left over from a previous insert. */
2567 bl
->target_info
.tcommands
.clear ();
2569 if (!target_can_run_breakpoint_commands ())
2572 /* For now, limit to agent-style dprintf breakpoints. */
2573 if (dprintf_style
!= dprintf_style_agent
)
2576 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2578 /* For now, if we have any location at the same address that isn't a
2579 dprintf, don't install the target-side commands, as that would
2580 make the breakpoint not be reported to the core, and we'd lose
2582 for (bp_location
*loc
: loc_range
)
2583 if (is_breakpoint (loc
->owner
)
2584 && loc
->pspace
->num
== bl
->pspace
->num
2585 && loc
->owner
->type
!= bp_dprintf
)
2588 /* Do a first pass to check for locations with no assigned
2589 conditions or conditions that fail to parse to a valid agent expression
2590 bytecode. If any of these happen, then it's no use to send conditions
2591 to the target since this location will always trigger and generate a
2592 response back to GDB. */
2593 for (bp_location
*loc
: loc_range
)
2595 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2599 /* Re-parse the commands since something changed. In that
2600 case we already freed the command bytecodes (see
2601 force_breakpoint_reinsertion). We just
2602 need to parse the command to bytecodes again. */
2604 = parse_cmd_to_aexpr (bl
->address
,
2605 loc
->owner
->extra_string
.get ());
2608 /* If we have a NULL bytecode expression, it means something
2609 went wrong or we have a null command expression. */
2610 if (!loc
->cmd_bytecode
)
2612 null_command_or_parse_error
= true;
2618 /* If anything failed, then we're not doing target-side commands,
2620 if (null_command_or_parse_error
)
2622 for (bp_location
*loc
: loc_range
)
2623 if (is_breakpoint (loc
->owner
)
2624 && loc
->pspace
->num
== bl
->pspace
->num
)
2626 /* Only go as far as the first NULL bytecode is
2628 if (loc
->cmd_bytecode
== NULL
)
2631 loc
->cmd_bytecode
.reset ();
2635 /* No NULL commands or failed bytecode generation. Build a command
2636 list for all duplicate locations at this location's address.
2637 Note that here we must care for whether the breakpoint location
2638 types are considered duplicates, otherwise, say, if we have a
2639 software and hardware location at the same address, the target
2640 could end up running the commands twice. For the moment, we only
2641 support targets-side commands with dprintf, but it doesn't hurt
2642 to be pedantically correct in case that changes. */
2643 for (bp_location
*loc
: loc_range
)
2644 if (breakpoint_locations_match (bl
, loc
)
2645 && loc
->owner
->extra_string
2646 && is_breakpoint (loc
->owner
)
2647 && loc
->pspace
->num
== bl
->pspace
->num
2648 && loc
->owner
->enable_state
== bp_enabled
2650 && !loc
->disabled_by_cond
)
2652 /* Add the command to the vector. This will be used later
2653 to send the commands to the target. */
2654 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2657 bl
->target_info
.persist
= 0;
2658 /* Maybe flag this location as persistent. */
2659 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2660 bl
->target_info
.persist
= 1;
2663 /* Return the kind of breakpoint on address *ADDR. Get the kind
2664 of breakpoint according to ADDR except single-step breakpoint.
2665 Get the kind of single-step breakpoint according to the current
2669 breakpoint_kind (const struct bp_location
*bl
, CORE_ADDR
*addr
)
2671 if (bl
->owner
->type
== bp_single_step
)
2673 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2674 struct regcache
*regcache
;
2676 regcache
= get_thread_regcache (thr
);
2678 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2682 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2685 /* Rethrow the currently handled exception, if it's a TARGET_CLOSE_ERROR.
2686 E is either the currently handled exception, or a copy, or a sliced copy,
2687 so we can't rethrow that one, but we can use it to inspect the properties
2688 of the currently handled exception. */
2691 rethrow_on_target_close_error (const gdb_exception
&e
)
2695 /* Can't set the breakpoint. */
2697 if (e
.error
!= TARGET_CLOSE_ERROR
)
2700 /* If the target has closed then it will have deleted any breakpoints
2701 inserted within the target inferior, as a result any further attempts
2702 to interact with the breakpoint objects is not possible. Just rethrow
2703 the error. Don't use e to rethrow, to prevent object slicing of the
2708 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2709 location. Any error messages are printed to TMP_ERROR_STREAM; and
2710 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2711 Returns 0 for success, 1 if the bp_location type is not supported or
2714 NOTE drow/2003-09-09: This routine could be broken down to an
2715 object-style method for each breakpoint or catchpoint type. */
2717 insert_bp_location (struct bp_location
*bl
,
2718 struct ui_file
*tmp_error_stream
,
2719 int *disabled_breaks
,
2720 int *hw_breakpoint_error
,
2721 int *hw_bp_error_explained_already
)
2723 gdb_exception bp_excpt
;
2725 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2728 /* Note we don't initialize bl->target_info, as that wipes out
2729 the breakpoint location's shadow_contents if the breakpoint
2730 is still inserted at that location. This in turn breaks
2731 target_read_memory which depends on these buffers when
2732 a memory read is requested at the breakpoint location:
2733 Once the target_info has been wiped, we fail to see that
2734 we have a breakpoint inserted at that address and thus
2735 read the breakpoint instead of returning the data saved in
2736 the breakpoint location's shadow contents. */
2737 bl
->target_info
.reqstd_address
= bl
->address
;
2738 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2739 bl
->target_info
.length
= bl
->length
;
2741 /* When working with target-side conditions, we must pass all the conditions
2742 for the same breakpoint address down to the target since GDB will not
2743 insert those locations. With a list of breakpoint conditions, the target
2744 can decide when to stop and notify GDB. */
2746 if (is_breakpoint (bl
->owner
))
2748 build_target_condition_list (bl
);
2749 build_target_command_list (bl
);
2750 /* Reset the modification marker. */
2751 bl
->needs_update
= 0;
2754 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2755 set at a read-only address, then a breakpoint location will have
2756 been changed to hardware breakpoint before we get here. If it is
2757 "off" however, error out before actually trying to insert the
2758 breakpoint, with a nicer error message. */
2759 if (bl
->loc_type
== bp_loc_software_breakpoint
2760 && !automatic_hardware_breakpoints
)
2762 mem_region
*mr
= lookup_mem_region (bl
->address
);
2764 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2766 gdb_printf (tmp_error_stream
,
2767 _("Cannot insert breakpoint %d.\n"
2768 "Cannot set software breakpoint "
2769 "at read-only address %s\n"),
2771 paddress (bl
->gdbarch
, bl
->address
));
2776 if (bl
->loc_type
== bp_loc_software_breakpoint
2777 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2779 /* First check to see if we have to handle an overlay. */
2780 if (overlay_debugging
== ovly_off
2781 || bl
->section
== NULL
2782 || !(section_is_overlay (bl
->section
)))
2784 /* No overlay handling: just set the breakpoint. */
2789 val
= bl
->owner
->insert_location (bl
);
2791 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2793 catch (gdb_exception
&e
)
2795 rethrow_on_target_close_error (e
);
2796 bp_excpt
= std::move (e
);
2801 /* This breakpoint is in an overlay section.
2802 Shall we set a breakpoint at the LMA? */
2803 if (!overlay_events_enabled
)
2805 /* Yes -- overlay event support is not active,
2806 so we must try to set a breakpoint at the LMA.
2807 This will not work for a hardware breakpoint. */
2808 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2809 warning (_("hardware breakpoint %d not supported in overlay!"),
2813 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2815 /* Set a software (trap) breakpoint at the LMA. */
2816 bl
->overlay_target_info
= bl
->target_info
;
2817 bl
->overlay_target_info
.reqstd_address
= addr
;
2819 /* No overlay handling: just set the breakpoint. */
2824 bl
->overlay_target_info
.kind
2825 = breakpoint_kind (bl
, &addr
);
2826 bl
->overlay_target_info
.placed_address
= addr
;
2827 val
= target_insert_breakpoint (bl
->gdbarch
,
2828 &bl
->overlay_target_info
);
2831 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2833 catch (gdb_exception
&e
)
2835 rethrow_on_target_close_error (e
);
2836 bp_excpt
= std::move (e
);
2839 if (bp_excpt
.reason
!= 0)
2840 gdb_printf (tmp_error_stream
,
2841 "Overlay breakpoint %d "
2842 "failed: in ROM?\n",
2846 /* Shall we set a breakpoint at the VMA? */
2847 if (section_is_mapped (bl
->section
))
2849 /* Yes. This overlay section is mapped into memory. */
2854 val
= bl
->owner
->insert_location (bl
);
2856 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2858 catch (gdb_exception_error
&e
)
2860 rethrow_on_target_close_error (e
);
2861 bp_excpt
= std::move (e
);
2866 /* No. This breakpoint will not be inserted.
2867 No error, but do not mark the bp as 'inserted'. */
2872 if (bp_excpt
.reason
!= 0)
2874 /* Can't set the breakpoint. */
2875 gdb_assert (bl
->owner
!= nullptr);
2877 /* In some cases, we might not be able to insert a
2878 breakpoint in a shared library that has already been
2879 removed, but we have not yet processed the shlib unload
2880 event. Unfortunately, some targets that implement
2881 breakpoint insertion themselves can't tell why the
2882 breakpoint insertion failed (e.g., the remote target
2883 doesn't define error codes), so we must treat generic
2884 errors as memory errors. */
2885 if (bp_excpt
.reason
== RETURN_ERROR
2886 && (bp_excpt
.error
== GENERIC_ERROR
2887 || bp_excpt
.error
== MEMORY_ERROR
)
2888 && bl
->loc_type
== bp_loc_software_breakpoint
2889 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2890 || shared_objfile_contains_address_p (bl
->pspace
,
2893 /* See also: disable_breakpoints_in_shlibs. */
2894 bl
->shlib_disabled
= 1;
2895 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2896 if (!*disabled_breaks
)
2898 gdb_printf (tmp_error_stream
,
2899 "Cannot insert breakpoint %d.\n",
2901 gdb_printf (tmp_error_stream
,
2902 "Temporarily disabling shared "
2903 "library breakpoints:\n");
2905 *disabled_breaks
= 1;
2906 gdb_printf (tmp_error_stream
,
2907 "breakpoint #%d\n", bl
->owner
->number
);
2912 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2914 *hw_breakpoint_error
= 1;
2915 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2916 gdb_printf (tmp_error_stream
,
2917 "Cannot insert hardware breakpoint %d%s",
2919 bp_excpt
.message
? ":" : ".\n");
2920 if (bp_excpt
.message
!= NULL
)
2921 gdb_printf (tmp_error_stream
, "%s.\n",
2926 if (bp_excpt
.message
== NULL
)
2929 = memory_error_message (TARGET_XFER_E_IO
,
2930 bl
->gdbarch
, bl
->address
);
2932 gdb_printf (tmp_error_stream
,
2933 "Cannot insert breakpoint %d.\n"
2935 bl
->owner
->number
, message
.c_str ());
2939 gdb_printf (tmp_error_stream
,
2940 "Cannot insert breakpoint %d: %s\n",
2955 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2956 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2960 val
= bl
->owner
->insert_location (bl
);
2962 /* If trying to set a read-watchpoint, and it turns out it's not
2963 supported, try emulating one with an access watchpoint. */
2964 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2966 /* But don't try to insert it, if there's already another
2967 hw_access location that would be considered a duplicate
2969 for (bp_location
*loc
: all_bp_locations ())
2971 && loc
->watchpoint_type
== hw_access
2972 && watchpoint_locations_match (bl
, loc
))
2976 bl
->target_info
= loc
->target_info
;
2977 bl
->watchpoint_type
= hw_access
;
2984 bl
->watchpoint_type
= hw_access
;
2985 val
= bl
->owner
->insert_location (bl
);
2988 /* Back to the original value. */
2989 bl
->watchpoint_type
= hw_read
;
2993 bl
->inserted
= (val
== 0);
2996 else if (bl
->owner
->type
== bp_catchpoint
)
3000 val
= bl
->owner
->insert_location (bl
);
3003 bl
->owner
->enable_state
= bp_disabled
;
3007 Error inserting catchpoint %d: Your system does not support this type\n\
3008 of catchpoint."), bl
->owner
->number
);
3010 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
3013 bl
->inserted
= (val
== 0);
3015 /* We've already printed an error message if there was a problem
3016 inserting this catchpoint, and we've disabled the catchpoint,
3017 so just return success. */
3024 /* This function is called when program space PSPACE is about to be
3025 deleted. It takes care of updating breakpoints to not reference
3029 breakpoint_program_space_exit (struct program_space
*pspace
)
3031 /* Remove any breakpoint that was set through this program space. */
3032 for (breakpoint
*b
: all_breakpoints_safe ())
3033 if (b
->pspace
== pspace
)
3034 delete_breakpoint (b
);
3036 /* Breakpoints set through other program spaces could have locations
3037 bound to PSPACE as well. Remove those. */
3038 for (bp_location
*loc
: all_bp_locations ())
3040 struct bp_location
*tmp
;
3042 if (loc
->pspace
== pspace
)
3044 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3045 if (loc
->owner
->loc
== loc
)
3046 loc
->owner
->loc
= loc
->next
;
3048 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3049 if (tmp
->next
== loc
)
3051 tmp
->next
= loc
->next
;
3057 /* Now update the global location list to permanently delete the
3058 removed locations above. */
3059 update_global_location_list (UGLL_DONT_INSERT
);
3062 /* Make sure all breakpoints are inserted in inferior.
3063 Throws exception on any error.
3064 A breakpoint that is already inserted won't be inserted
3065 again, so calling this function twice is safe. */
3067 insert_breakpoints (void)
3069 for (breakpoint
*bpt
: all_breakpoints ())
3070 if (is_hardware_watchpoint (bpt
))
3072 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3074 update_watchpoint (w
, false /* don't reparse. */);
3077 /* Updating watchpoints creates new locations, so update the global
3078 location list. Explicitly tell ugll to insert locations and
3079 ignore breakpoints_always_inserted_mode. Also,
3080 update_global_location_list tries to "upgrade" software
3081 breakpoints to hardware breakpoints to handle "set breakpoint
3082 auto-hw", so we need to call it even if we don't have new
3084 update_global_location_list (UGLL_INSERT
);
3087 /* This is used when we need to synch breakpoint conditions between GDB and the
3088 target. It is the case with deleting and disabling of breakpoints when using
3089 always-inserted mode. */
3092 update_inserted_breakpoint_locations (void)
3096 int disabled_breaks
= 0;
3097 int hw_breakpoint_error
= 0;
3098 int hw_bp_details_reported
= 0;
3100 string_file tmp_error_stream
;
3102 /* Explicitly mark the warning -- this will only be printed if
3103 there was an error. */
3104 tmp_error_stream
.puts ("Warning:\n");
3106 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3108 for (bp_location
*bl
: all_bp_locations ())
3110 /* We only want to update software breakpoints and hardware
3112 if (!is_breakpoint (bl
->owner
))
3115 /* We only want to update locations that are already inserted
3116 and need updating. This is to avoid unwanted insertion during
3117 deletion of breakpoints. */
3118 if (!bl
->inserted
|| !bl
->needs_update
)
3121 switch_to_program_space_and_thread (bl
->pspace
);
3123 /* For targets that support global breakpoints, there's no need
3124 to select an inferior to insert breakpoint to. In fact, even
3125 if we aren't attached to any process yet, we should still
3126 insert breakpoints. */
3127 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3128 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3131 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3132 &hw_breakpoint_error
, &hw_bp_details_reported
);
3139 target_terminal::ours_for_output ();
3140 error_stream (tmp_error_stream
);
3144 /* Used when starting or continuing the program. */
3147 insert_breakpoint_locations (void)
3151 int disabled_breaks
= 0;
3152 int hw_breakpoint_error
= 0;
3153 int hw_bp_error_explained_already
= 0;
3155 string_file tmp_error_stream
;
3157 /* Explicitly mark the warning -- this will only be printed if
3158 there was an error. */
3159 tmp_error_stream
.puts ("Warning:\n");
3161 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3163 for (bp_location
*bl
: all_bp_locations ())
3165 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3168 /* There is no point inserting thread-specific breakpoints if
3169 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3170 has BL->OWNER always non-NULL. */
3171 if (bl
->owner
->thread
!= -1
3172 && !valid_global_thread_id (bl
->owner
->thread
))
3175 switch_to_program_space_and_thread (bl
->pspace
);
3177 /* For targets that support global breakpoints, there's no need
3178 to select an inferior to insert breakpoint to. In fact, even
3179 if we aren't attached to any process yet, we should still
3180 insert breakpoints. */
3181 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3182 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3185 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3186 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3191 /* If we failed to insert all locations of a watchpoint, remove
3192 them, as half-inserted watchpoint is of limited use. */
3193 for (breakpoint
*bpt
: all_breakpoints ())
3195 bool some_failed
= false;
3197 if (!is_hardware_watchpoint (bpt
))
3200 if (!breakpoint_enabled (bpt
))
3203 if (bpt
->disposition
== disp_del_at_next_stop
)
3206 for (bp_location
*loc
: bpt
->locations ())
3207 if (!loc
->inserted
&& should_be_inserted (loc
))
3215 for (bp_location
*loc
: bpt
->locations ())
3217 remove_breakpoint (loc
);
3219 hw_breakpoint_error
= 1;
3220 tmp_error_stream
.printf ("Could not insert "
3221 "hardware watchpoint %d.\n",
3229 /* If a hardware breakpoint or watchpoint was inserted, add a
3230 message about possibly exhausted resources. */
3231 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3233 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3234 You may have requested too many hardware breakpoints/watchpoints.\n");
3236 target_terminal::ours_for_output ();
3237 error_stream (tmp_error_stream
);
3241 /* Used when the program stops.
3242 Returns zero if successful, or non-zero if there was a problem
3243 removing a breakpoint location. */
3246 remove_breakpoints (void)
3250 for (bp_location
*bl
: all_bp_locations ())
3251 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3252 val
|= remove_breakpoint (bl
);
3257 /* When a thread exits, remove breakpoints that are related to
3261 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3263 for (breakpoint
*b
: all_breakpoints_safe ())
3265 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3268 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3269 b
->number
, print_thread_id (tp
));
3270 delete_breakpoint (b
);
3275 /* See breakpoint.h. */
3278 remove_breakpoints_inf (inferior
*inf
)
3282 for (bp_location
*bl
: all_bp_locations ())
3284 if (bl
->pspace
!= inf
->pspace
)
3287 if (bl
->inserted
&& !bl
->target_info
.persist
)
3289 val
= remove_breakpoint (bl
);
3296 static int internal_breakpoint_number
= -1;
3298 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3299 If INTERNAL is non-zero, the breakpoint number will be populated
3300 from internal_breakpoint_number and that variable decremented.
3301 Otherwise the breakpoint number will be populated from
3302 breakpoint_count and that value incremented. Internal breakpoints
3303 do not set the internal var bpnum. */
3305 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3308 b
->number
= internal_breakpoint_number
--;
3311 set_breakpoint_count (breakpoint_count
+ 1);
3312 b
->number
= breakpoint_count
;
3316 /* Create a TYPE breakpoint on ADDRESS from an object file with GDBARCH. */
3318 static struct breakpoint
*
3319 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3320 CORE_ADDR address
, enum bptype type
)
3322 std::unique_ptr
<internal_breakpoint
> b
3323 (new internal_breakpoint (gdbarch
, type
, address
));
3325 b
->number
= internal_breakpoint_number
--;
3327 return add_to_breakpoint_chain (std::move (b
));
3330 /* Create a TYPE breakpoint on minimal symbol MSYM from an object file with
3333 static struct breakpoint
*
3334 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3335 struct bound_minimal_symbol
&msym
, enum bptype type
)
3339 address
= msym
.value_address ();
3341 address
= gdbarch_convert_from_func_ptr_addr
3342 (gdbarch
, address
, current_inferior ()->top_target ());
3344 /* Note that we're not using gdbarch_addr_bits_remove here, because that's
3345 related to addresses in $pc. We're getting the address from the
3346 minimal symbol table. */
3348 /* Is gdbarch_deprecated_function_start_offset needed here? Or is that dealt
3349 with elsewhere? Needs testing on vax. */
3351 if (gdbarch_skip_entrypoint_p (gdbarch
))
3352 address
= gdbarch_skip_entrypoint (gdbarch
, address
);
3354 return create_internal_breakpoint (gdbarch
, address
, type
);
3357 static const char *const longjmp_names
[] =
3359 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3361 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3363 /* Per-objfile data private to breakpoint.c. */
3364 struct breakpoint_objfile_data
3366 /* Minimal symbol for "_ovly_debug_event" (if any). */
3367 struct bound_minimal_symbol overlay_msym
;
3369 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3370 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3372 /* True if we have looked for longjmp probes. */
3373 int longjmp_searched
= 0;
3375 /* SystemTap probe points for longjmp (if any). These are non-owning
3377 std::vector
<probe
*> longjmp_probes
;
3379 /* Minimal symbol for "std::terminate()" (if any). */
3380 struct bound_minimal_symbol terminate_msym
;
3382 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3383 struct bound_minimal_symbol exception_msym
;
3385 /* True if we have looked for exception probes. */
3386 int exception_searched
= 0;
3388 /* SystemTap probe points for unwinding (if any). These are non-owning
3390 std::vector
<probe
*> exception_probes
;
3393 static const registry
<objfile
>::key
<breakpoint_objfile_data
>
3394 breakpoint_objfile_key
;
3396 /* Minimal symbol not found sentinel. */
3397 static struct minimal_symbol msym_not_found
;
3399 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3402 msym_not_found_p (const struct minimal_symbol
*msym
)
3404 return msym
== &msym_not_found
;
3407 /* Return per-objfile data needed by breakpoint.c.
3408 Allocate the data if necessary. */
3410 static struct breakpoint_objfile_data
*
3411 get_breakpoint_objfile_data (struct objfile
*objfile
)
3413 struct breakpoint_objfile_data
*bp_objfile_data
;
3415 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3416 if (bp_objfile_data
== NULL
)
3417 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3418 return bp_objfile_data
;
3422 create_overlay_event_breakpoint (void)
3424 const char *const func_name
= "_ovly_debug_event";
3426 for (objfile
*objfile
: current_program_space
->objfiles ())
3428 struct breakpoint
*b
;
3429 struct breakpoint_objfile_data
*bp_objfile_data
;
3432 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3434 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3437 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3439 struct bound_minimal_symbol m
;
3441 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3442 if (m
.minsym
== NULL
)
3444 /* Avoid future lookups in this objfile. */
3445 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3448 bp_objfile_data
->overlay_msym
= m
;
3451 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3452 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3454 b
->locspec
= new_explicit_location_spec_function (func_name
);
3456 if (overlay_debugging
== ovly_auto
)
3458 b
->enable_state
= bp_enabled
;
3459 overlay_events_enabled
= 1;
3463 b
->enable_state
= bp_disabled
;
3464 overlay_events_enabled
= 0;
3469 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3470 true if a breakpoint was installed. */
3473 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3475 struct gdbarch
*gdbarch
= objfile
->arch ();
3476 struct breakpoint_objfile_data
*bp_objfile_data
3477 = get_breakpoint_objfile_data (objfile
);
3479 if (!bp_objfile_data
->longjmp_searched
)
3481 std::vector
<probe
*> ret
3482 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3486 /* We are only interested in checking one element. */
3489 if (!p
->can_evaluate_arguments ())
3491 /* We cannot use the probe interface here,
3492 because it does not know how to evaluate
3497 bp_objfile_data
->longjmp_probes
= ret
;
3498 bp_objfile_data
->longjmp_searched
= 1;
3501 if (bp_objfile_data
->longjmp_probes
.empty ())
3504 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3506 struct breakpoint
*b
;
3508 b
= create_internal_breakpoint (gdbarch
,
3509 p
->get_relocated_address (objfile
),
3511 b
->locspec
= new_probe_location_spec ("-probe-stap libc:longjmp");
3512 b
->enable_state
= bp_disabled
;
3518 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3519 Return true if at least one breakpoint was installed. */
3522 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3524 struct gdbarch
*gdbarch
= objfile
->arch ();
3525 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3528 struct breakpoint_objfile_data
*bp_objfile_data
3529 = get_breakpoint_objfile_data (objfile
);
3530 unsigned int installed_bp
= 0;
3532 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3534 struct breakpoint
*b
;
3535 const char *func_name
;
3538 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3541 func_name
= longjmp_names
[i
];
3542 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3544 struct bound_minimal_symbol m
;
3546 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3547 if (m
.minsym
== NULL
)
3549 /* Prevent future lookups in this objfile. */
3550 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3553 bp_objfile_data
->longjmp_msym
[i
] = m
;
3556 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3557 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3558 b
->locspec
= new_explicit_location_spec_function (func_name
);
3559 b
->enable_state
= bp_disabled
;
3563 return installed_bp
> 0;
3566 /* Create a master longjmp breakpoint. */
3569 create_longjmp_master_breakpoint (void)
3571 scoped_restore_current_program_space restore_pspace
;
3573 for (struct program_space
*pspace
: program_spaces
)
3575 set_current_program_space (pspace
);
3577 for (objfile
*obj
: current_program_space
->objfiles ())
3579 /* Skip separate debug object, it's handled in the loop below. */
3580 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3583 /* Try a probe kind breakpoint on main objfile. */
3584 if (create_longjmp_master_breakpoint_probe (obj
))
3587 /* Try longjmp_names kind breakpoints on main and separate_debug
3589 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3590 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3596 /* Create a master std::terminate breakpoint. */
3598 create_std_terminate_master_breakpoint (void)
3600 const char *const func_name
= "std::terminate()";
3602 scoped_restore_current_program_space restore_pspace
;
3604 for (struct program_space
*pspace
: program_spaces
)
3606 set_current_program_space (pspace
);
3608 for (objfile
*objfile
: current_program_space
->objfiles ())
3610 struct breakpoint
*b
;
3611 struct breakpoint_objfile_data
*bp_objfile_data
;
3613 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3615 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3618 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3620 struct bound_minimal_symbol m
;
3622 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3623 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3624 && m
.minsym
->type () != mst_file_text
))
3626 /* Prevent future lookups in this objfile. */
3627 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3630 bp_objfile_data
->terminate_msym
= m
;
3633 b
= create_internal_breakpoint (objfile
->arch (),
3634 bp_objfile_data
->terminate_msym
,
3635 bp_std_terminate_master
);
3636 b
->locspec
= new_explicit_location_spec_function (func_name
);
3637 b
->enable_state
= bp_disabled
;
3642 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3643 probe. Return true if a breakpoint was installed. */
3646 create_exception_master_breakpoint_probe (objfile
*objfile
)
3648 struct breakpoint
*b
;
3649 struct gdbarch
*gdbarch
;
3650 struct breakpoint_objfile_data
*bp_objfile_data
;
3652 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3654 /* We prefer the SystemTap probe point if it exists. */
3655 if (!bp_objfile_data
->exception_searched
)
3657 std::vector
<probe
*> ret
3658 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3662 /* We are only interested in checking one element. */
3665 if (!p
->can_evaluate_arguments ())
3667 /* We cannot use the probe interface here, because it does
3668 not know how to evaluate arguments. */
3672 bp_objfile_data
->exception_probes
= ret
;
3673 bp_objfile_data
->exception_searched
= 1;
3676 if (bp_objfile_data
->exception_probes
.empty ())
3679 gdbarch
= objfile
->arch ();
3681 for (probe
*p
: bp_objfile_data
->exception_probes
)
3683 b
= create_internal_breakpoint (gdbarch
,
3684 p
->get_relocated_address (objfile
),
3685 bp_exception_master
);
3686 b
->locspec
= new_probe_location_spec ("-probe-stap libgcc:unwind");
3687 b
->enable_state
= bp_disabled
;
3693 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3694 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3697 create_exception_master_breakpoint_hook (objfile
*objfile
)
3699 const char *const func_name
= "_Unwind_DebugHook";
3700 struct breakpoint
*b
;
3701 struct gdbarch
*gdbarch
;
3702 struct breakpoint_objfile_data
*bp_objfile_data
;
3704 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3706 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3709 gdbarch
= objfile
->arch ();
3711 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3713 struct bound_minimal_symbol debug_hook
;
3715 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3716 if (debug_hook
.minsym
== NULL
)
3718 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3722 bp_objfile_data
->exception_msym
= debug_hook
;
3725 b
= create_internal_breakpoint (gdbarch
, bp_objfile_data
->exception_msym
,
3726 bp_exception_master
);
3727 b
->locspec
= new_explicit_location_spec_function (func_name
);
3728 b
->enable_state
= bp_disabled
;
3733 /* Install a master breakpoint on the unwinder's debug hook. */
3736 create_exception_master_breakpoint (void)
3738 for (objfile
*obj
: current_program_space
->objfiles ())
3740 /* Skip separate debug object. */
3741 if (obj
->separate_debug_objfile_backlink
)
3744 /* Try a probe kind breakpoint. */
3745 if (create_exception_master_breakpoint_probe (obj
))
3748 /* Iterate over main and separate debug objects and try an
3749 _Unwind_DebugHook kind breakpoint. */
3750 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3751 if (create_exception_master_breakpoint_hook (debug_objfile
))
3756 /* Does B have a location spec? */
3759 breakpoint_location_spec_empty_p (const struct breakpoint
*b
)
3761 return (b
->locspec
!= nullptr && b
->locspec
->empty_p ());
3765 update_breakpoints_after_exec (void)
3767 /* We're about to delete breakpoints from GDB's lists. If the
3768 INSERTED flag is true, GDB will try to lift the breakpoints by
3769 writing the breakpoints' "shadow contents" back into memory. The
3770 "shadow contents" are NOT valid after an exec, so GDB should not
3771 do that. Instead, the target is responsible from marking
3772 breakpoints out as soon as it detects an exec. We don't do that
3773 here instead, because there may be other attempts to delete
3774 breakpoints after detecting an exec and before reaching here. */
3775 for (bp_location
*bploc
: all_bp_locations ())
3776 if (bploc
->pspace
== current_program_space
)
3777 gdb_assert (!bploc
->inserted
);
3779 for (breakpoint
*b
: all_breakpoints_safe ())
3781 if (b
->pspace
!= current_program_space
)
3784 /* Solib breakpoints must be explicitly reset after an exec(). */
3785 if (b
->type
== bp_shlib_event
)
3787 delete_breakpoint (b
);
3791 /* JIT breakpoints must be explicitly reset after an exec(). */
3792 if (b
->type
== bp_jit_event
)
3794 delete_breakpoint (b
);
3798 /* Thread event breakpoints must be set anew after an exec(),
3799 as must overlay event and longjmp master breakpoints. */
3800 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3801 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3802 || b
->type
== bp_exception_master
)
3804 delete_breakpoint (b
);
3808 /* Step-resume breakpoints are meaningless after an exec(). */
3809 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3811 delete_breakpoint (b
);
3815 /* Just like single-step breakpoints. */
3816 if (b
->type
== bp_single_step
)
3818 delete_breakpoint (b
);
3822 /* Longjmp and longjmp-resume breakpoints are also meaningless
3824 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3825 || b
->type
== bp_longjmp_call_dummy
3826 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3828 delete_breakpoint (b
);
3832 if (b
->type
== bp_catchpoint
)
3834 /* For now, none of the bp_catchpoint breakpoints need to
3835 do anything at this point. In the future, if some of
3836 the catchpoints need to something, we will need to add
3837 a new method, and call this method from here. */
3841 /* bp_finish is a special case. The only way we ought to be able
3842 to see one of these when an exec() has happened, is if the user
3843 caught a vfork, and then said "finish". Ordinarily a finish just
3844 carries them to the call-site of the current callee, by setting
3845 a temporary bp there and resuming. But in this case, the finish
3846 will carry them entirely through the vfork & exec.
3848 We don't want to allow a bp_finish to remain inserted now. But
3849 we can't safely delete it, 'cause finish_command has a handle to
3850 the bp on a bpstat, and will later want to delete it. There's a
3851 chance (and I've seen it happen) that if we delete the bp_finish
3852 here, that its storage will get reused by the time finish_command
3853 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3854 We really must allow finish_command to delete a bp_finish.
3856 In the absence of a general solution for the "how do we know
3857 it's safe to delete something others may have handles to?"
3858 problem, what we'll do here is just uninsert the bp_finish, and
3859 let finish_command delete it.
3861 (We know the bp_finish is "doomed" in the sense that it's
3862 momentary, and will be deleted as soon as finish_command sees
3863 the inferior stopped. So it doesn't matter that the bp's
3864 address is probably bogus in the new a.out, unlike e.g., the
3865 solib breakpoints.) */
3867 if (b
->type
== bp_finish
)
3872 /* Without a symbolic address, we have little hope of the
3873 pre-exec() address meaning the same thing in the post-exec()
3875 if (breakpoint_location_spec_empty_p (b
))
3877 delete_breakpoint (b
);
3884 detach_breakpoints (ptid_t ptid
)
3887 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3888 struct inferior
*inf
= current_inferior ();
3890 if (ptid
.pid () == inferior_ptid
.pid ())
3891 error (_("Cannot detach breakpoints of inferior_ptid"));
3893 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3894 inferior_ptid
= ptid
;
3895 for (bp_location
*bl
: all_bp_locations ())
3897 if (bl
->pspace
!= inf
->pspace
)
3900 /* This function must physically remove breakpoints locations
3901 from the specified ptid, without modifying the breakpoint
3902 package's state. Locations of type bp_loc_other and
3903 bp_loc_software_watchpoint are only maintained at GDB side,
3904 so there is no need to remove them. Moreover, removing these
3905 would modify the breakpoint package's state. */
3906 if (bl
->loc_type
== bp_loc_other
3907 || bl
->loc_type
== bp_loc_software_watchpoint
)
3911 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3917 /* Remove the breakpoint location BL from the current address space.
3918 Note that this is used to detach breakpoints from a child fork.
3919 When we get here, the child isn't in the inferior list, and neither
3920 do we have objects to represent its address space --- we should
3921 *not* look at bl->pspace->aspace here. */
3924 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3928 /* BL is never in moribund_locations by our callers. */
3929 gdb_assert (bl
->owner
!= NULL
);
3931 /* The type of none suggests that owner is actually deleted.
3932 This should not ever happen. */
3933 gdb_assert (bl
->owner
->type
!= bp_none
);
3935 if (bl
->loc_type
== bp_loc_software_breakpoint
3936 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3938 /* "Normal" instruction breakpoint: either the standard
3939 trap-instruction bp (bp_breakpoint), or a
3940 bp_hardware_breakpoint. */
3942 /* First check to see if we have to handle an overlay. */
3943 if (overlay_debugging
== ovly_off
3944 || bl
->section
== NULL
3945 || !(section_is_overlay (bl
->section
)))
3947 /* No overlay handling: just remove the breakpoint. */
3949 /* If we're trying to uninsert a memory breakpoint that we
3950 know is set in a dynamic object that is marked
3951 shlib_disabled, then either the dynamic object was
3952 removed with "remove-symbol-file" or with
3953 "nosharedlibrary". In the former case, we don't know
3954 whether another dynamic object might have loaded over the
3955 breakpoint's address -- the user might well let us know
3956 about it next with add-symbol-file (the whole point of
3957 add-symbol-file is letting the user manually maintain a
3958 list of dynamically loaded objects). If we have the
3959 breakpoint's shadow memory, that is, this is a software
3960 breakpoint managed by GDB, check whether the breakpoint
3961 is still inserted in memory, to avoid overwriting wrong
3962 code with stale saved shadow contents. Note that HW
3963 breakpoints don't have shadow memory, as they're
3964 implemented using a mechanism that is not dependent on
3965 being able to modify the target's memory, and as such
3966 they should always be removed. */
3967 if (bl
->shlib_disabled
3968 && bl
->target_info
.shadow_len
!= 0
3969 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3972 val
= bl
->owner
->remove_location (bl
, reason
);
3976 /* This breakpoint is in an overlay section.
3977 Did we set a breakpoint at the LMA? */
3978 if (!overlay_events_enabled
)
3980 /* Yes -- overlay event support is not active, so we
3981 should have set a breakpoint at the LMA. Remove it.
3983 /* Ignore any failures: if the LMA is in ROM, we will
3984 have already warned when we failed to insert it. */
3985 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3986 target_remove_hw_breakpoint (bl
->gdbarch
,
3987 &bl
->overlay_target_info
);
3989 target_remove_breakpoint (bl
->gdbarch
,
3990 &bl
->overlay_target_info
,
3993 /* Did we set a breakpoint at the VMA?
3994 If so, we will have marked the breakpoint 'inserted'. */
3997 /* Yes -- remove it. Previously we did not bother to
3998 remove the breakpoint if the section had been
3999 unmapped, but let's not rely on that being safe. We
4000 don't know what the overlay manager might do. */
4002 /* However, we should remove *software* breakpoints only
4003 if the section is still mapped, or else we overwrite
4004 wrong code with the saved shadow contents. */
4005 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4006 || section_is_mapped (bl
->section
))
4007 val
= bl
->owner
->remove_location (bl
, reason
);
4013 /* No -- not inserted, so no need to remove. No error. */
4018 /* In some cases, we might not be able to remove a breakpoint in
4019 a shared library that has already been removed, but we have
4020 not yet processed the shlib unload event. Similarly for an
4021 unloaded add-symbol-file object - the user might not yet have
4022 had the chance to remove-symbol-file it. shlib_disabled will
4023 be set if the library/object has already been removed, but
4024 the breakpoint hasn't been uninserted yet, e.g., after
4025 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4026 always-inserted mode. */
4028 && (bl
->loc_type
== bp_loc_software_breakpoint
4029 && (bl
->shlib_disabled
4030 || solib_name_from_address (bl
->pspace
, bl
->address
)
4031 || shared_objfile_contains_address_p (bl
->pspace
,
4037 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4039 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4041 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4042 bl
->owner
->remove_location (bl
, reason
);
4044 /* Failure to remove any of the hardware watchpoints comes here. */
4045 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4046 warning (_("Could not remove hardware watchpoint %d."),
4049 else if (bl
->owner
->type
== bp_catchpoint
4050 && breakpoint_enabled (bl
->owner
)
4053 val
= bl
->owner
->remove_location (bl
, reason
);
4057 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4064 remove_breakpoint (struct bp_location
*bl
)
4066 /* BL is never in moribund_locations by our callers. */
4067 gdb_assert (bl
->owner
!= NULL
);
4069 /* The type of none suggests that owner is actually deleted.
4070 This should not ever happen. */
4071 gdb_assert (bl
->owner
->type
!= bp_none
);
4073 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4075 switch_to_program_space_and_thread (bl
->pspace
);
4077 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4080 /* Clear the "inserted" flag in all breakpoints. */
4083 mark_breakpoints_out (void)
4085 for (bp_location
*bl
: all_bp_locations ())
4086 if (bl
->pspace
== current_program_space
)
4090 /* Clear the "inserted" flag in all breakpoints and delete any
4091 breakpoints which should go away between runs of the program.
4093 Plus other such housekeeping that has to be done for breakpoints
4096 Note: this function gets called at the end of a run (by
4097 generic_mourn_inferior) and when a run begins (by
4098 init_wait_for_inferior). */
4103 breakpoint_init_inferior (enum inf_context context
)
4105 struct program_space
*pspace
= current_program_space
;
4107 /* If breakpoint locations are shared across processes, then there's
4109 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4112 mark_breakpoints_out ();
4114 for (breakpoint
*b
: all_breakpoints_safe ())
4116 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4122 case bp_longjmp_call_dummy
:
4124 /* If the call dummy breakpoint is at the entry point it will
4125 cause problems when the inferior is rerun, so we better get
4128 case bp_watchpoint_scope
:
4130 /* Also get rid of scope breakpoints. */
4132 case bp_shlib_event
:
4134 /* Also remove solib event breakpoints. Their addresses may
4135 have changed since the last time we ran the program.
4136 Actually we may now be debugging against different target;
4137 and so the solib backend that installed this breakpoint may
4138 not be used in by the target. E.g.,
4140 (gdb) file prog-linux
4141 (gdb) run # native linux target
4144 (gdb) file prog-win.exe
4145 (gdb) tar rem :9999 # remote Windows gdbserver.
4148 case bp_step_resume
:
4150 /* Also remove step-resume breakpoints. */
4152 case bp_single_step
:
4154 /* Also remove single-step breakpoints. */
4156 delete_breakpoint (b
);
4160 case bp_hardware_watchpoint
:
4161 case bp_read_watchpoint
:
4162 case bp_access_watchpoint
:
4164 struct watchpoint
*w
= (struct watchpoint
*) b
;
4166 /* Likewise for watchpoints on local expressions. */
4167 if (w
->exp_valid_block
!= NULL
)
4168 delete_breakpoint (b
);
4171 /* Get rid of existing locations, which are no longer
4172 valid. New ones will be created in
4173 update_watchpoint, when the inferior is restarted.
4174 The next update_global_location_list call will
4175 garbage collect them. */
4178 if (context
== inf_starting
)
4180 /* Reset val field to force reread of starting value in
4181 insert_breakpoints. */
4182 w
->val
.reset (nullptr);
4183 w
->val_valid
= false;
4193 /* Get rid of the moribund locations. */
4194 for (bp_location
*bl
: moribund_locations
)
4195 decref_bp_location (&bl
);
4196 moribund_locations
.clear ();
4199 /* These functions concern about actual breakpoints inserted in the
4200 target --- to e.g. check if we need to do decr_pc adjustment or if
4201 we need to hop over the bkpt --- so we check for address space
4202 match, not program space. */
4204 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4205 exists at PC. It returns ordinary_breakpoint_here if it's an
4206 ordinary breakpoint, or permanent_breakpoint_here if it's a
4207 permanent breakpoint.
4208 - When continuing from a location with an ordinary breakpoint, we
4209 actually single step once before calling insert_breakpoints.
4210 - When continuing from a location with a permanent breakpoint, we
4211 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4212 the target, to advance the PC past the breakpoint. */
4214 enum breakpoint_here
4215 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4217 bool any_breakpoint_here
= false;
4219 for (bp_location
*bl
: all_bp_locations ())
4221 if (bl
->loc_type
!= bp_loc_software_breakpoint
4222 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4225 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4226 if ((breakpoint_enabled (bl
->owner
)
4228 && breakpoint_location_address_match (bl
, aspace
, pc
))
4230 if (overlay_debugging
4231 && section_is_overlay (bl
->section
)
4232 && !section_is_mapped (bl
->section
))
4233 continue; /* unmapped overlay -- can't be a match */
4234 else if (bl
->permanent
)
4235 return permanent_breakpoint_here
;
4237 any_breakpoint_here
= true;
4241 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4244 /* See breakpoint.h. */
4247 breakpoint_in_range_p (const address_space
*aspace
,
4248 CORE_ADDR addr
, ULONGEST len
)
4250 for (bp_location
*bl
: all_bp_locations ())
4252 if (bl
->loc_type
!= bp_loc_software_breakpoint
4253 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4256 if ((breakpoint_enabled (bl
->owner
)
4258 && breakpoint_location_address_range_overlap (bl
, aspace
,
4261 if (overlay_debugging
4262 && section_is_overlay (bl
->section
)
4263 && !section_is_mapped (bl
->section
))
4265 /* Unmapped overlay -- can't be a match. */
4276 /* Return true if there's a moribund breakpoint at PC. */
4279 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4281 for (bp_location
*loc
: moribund_locations
)
4282 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4288 /* Returns true iff BL is inserted at PC, in address space ASPACE. */
4291 bp_location_inserted_here_p (const struct bp_location
*bl
,
4292 const address_space
*aspace
, CORE_ADDR pc
)
4295 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4298 /* An unmapped overlay can't be a match. */
4299 return !(overlay_debugging
4300 && section_is_overlay (bl
->section
)
4301 && !section_is_mapped (bl
->section
));
4306 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4309 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4311 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4313 if (bl
->loc_type
!= bp_loc_software_breakpoint
4314 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4317 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4323 /* This function returns non-zero iff there is a software breakpoint
4327 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4330 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4332 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4335 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4342 /* See breakpoint.h. */
4345 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4348 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4350 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4353 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4361 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4362 CORE_ADDR addr
, ULONGEST len
)
4364 for (breakpoint
*bpt
: all_breakpoints ())
4366 if (bpt
->type
!= bp_hardware_watchpoint
4367 && bpt
->type
!= bp_access_watchpoint
)
4370 if (!breakpoint_enabled (bpt
))
4373 for (bp_location
*loc
: bpt
->locations ())
4374 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4378 /* Check for intersection. */
4379 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4380 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4388 /* See breakpoint.h. */
4391 is_catchpoint (struct breakpoint
*b
)
4393 return (b
->type
== bp_catchpoint
);
4396 /* Clear a bpstat so that it says we are not at any breakpoint.
4397 Also free any storage that is part of a bpstat. */
4400 bpstat_clear (bpstat
**bsp
)
4417 bpstat::bpstat (const bpstat
&other
)
4419 bp_location_at (other
.bp_location_at
),
4420 breakpoint_at (other
.breakpoint_at
),
4421 commands (other
.commands
),
4422 print (other
.print
),
4424 print_it (other
.print_it
)
4426 if (other
.old_val
!= NULL
)
4427 old_val
= release_value (other
.old_val
->copy ());
4430 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4431 is part of the bpstat is copied as well. */
4434 bpstat_copy (bpstat
*bs
)
4436 bpstat
*p
= nullptr;
4438 bpstat
*retval
= nullptr;
4443 for (; bs
!= NULL
; bs
= bs
->next
)
4445 tmp
= new bpstat (*bs
);
4448 /* This is the first thing in the chain. */
4458 /* Find the bpstat associated with this breakpoint. */
4461 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4466 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4468 if (bsp
->breakpoint_at
== breakpoint
)
4474 /* See breakpoint.h. */
4477 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4479 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4481 if (bsp
->breakpoint_at
== NULL
)
4483 /* A moribund location can never explain a signal other than
4485 if (sig
== GDB_SIGNAL_TRAP
)
4490 if (bsp
->breakpoint_at
->explains_signal (sig
))
4498 /* See breakpoint.h. */
4501 bpstat_num (bpstat
**bsp
, int *num
)
4503 struct breakpoint
*b
;
4506 return 0; /* No more breakpoint values */
4508 /* We assume we'll never have several bpstats that correspond to a
4509 single breakpoint -- otherwise, this function might return the
4510 same number more than once and this will look ugly. */
4511 b
= (*bsp
)->breakpoint_at
;
4512 *bsp
= (*bsp
)->next
;
4514 return -1; /* breakpoint that's been deleted since */
4516 *num
= b
->number
; /* We have its number */
4520 /* See breakpoint.h */
4523 bpstat_locno (const bpstat
*bs
)
4525 const struct breakpoint
*b
= bs
->breakpoint_at
;
4526 const struct bp_location
*bl
= bs
->bp_location_at
.get ();
4530 if (b
!= nullptr && b
->loc
!= nullptr && b
->loc
->next
!= nullptr)
4532 const bp_location
*bl_i
;
4535 bl_i
!= bl
&& bl_i
->next
!= nullptr;
4543 warning (_("location number not found for breakpoint %d address %s."),
4544 b
->number
, paddress (bl
->gdbarch
, bl
->address
));
4552 /* See breakpoint.h. */
4555 print_num_locno (const bpstat
*bs
, struct ui_out
*uiout
)
4557 struct breakpoint
*b
= bs
->breakpoint_at
;
4560 uiout
->text (_("deleted breakpoint"));
4563 uiout
->field_signed ("bkptno", b
->number
);
4565 int locno
= bpstat_locno (bs
);
4567 uiout
->message (".%pF", signed_field ("locno", locno
));
4571 /* See breakpoint.h. */
4574 bpstat_clear_actions (void)
4578 if (inferior_ptid
== null_ptid
)
4581 thread_info
*tp
= inferior_thread ();
4582 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4584 bs
->commands
= NULL
;
4585 bs
->old_val
.reset (nullptr);
4589 /* Called when a command is about to proceed the inferior. */
4592 breakpoint_about_to_proceed (void)
4594 if (inferior_ptid
!= null_ptid
)
4596 struct thread_info
*tp
= inferior_thread ();
4598 /* Allow inferior function calls in breakpoint commands to not
4599 interrupt the command list. When the call finishes
4600 successfully, the inferior will be standing at the same
4601 breakpoint as if nothing happened. */
4602 if (tp
->control
.in_infcall
)
4606 breakpoint_proceeded
= 1;
4609 /* Return true iff CMD as the first line of a command sequence is `silent'
4610 or its equivalent. */
4613 command_line_is_silent (struct command_line
*cmd
)
4615 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4618 /* Sets the $_hit_bpnum and $_hit_locno to bpnum and locno.
4619 A locno 0 is changed to 1 to e.g. let the user do
4620 (gdb) disable $_hit_bpnum.$_hit_locno
4621 for a single location breakpoint. */
4624 set_hit_convenience_vars (int bpnum
, int locno
)
4626 set_internalvar_integer (lookup_internalvar ("_hit_bpnum"), bpnum
);
4627 set_internalvar_integer (lookup_internalvar ("_hit_locno"),
4628 (locno
> 0 ? locno
: 1));
4631 /* Execute all the commands associated with all the breakpoints at
4632 this location. Any of these commands could cause the process to
4633 proceed beyond this point, etc. We look out for such changes by
4634 checking the global "breakpoint_proceeded" after each command.
4636 Returns true if a breakpoint command resumed the inferior. In that
4637 case, it is the caller's responsibility to recall it again with the
4638 bpstat of the current thread. */
4641 bpstat_do_actions_1 (bpstat
**bsp
)
4646 /* Avoid endless recursion if a `source' command is contained
4648 if (executing_breakpoint_commands
)
4651 scoped_restore save_executing
4652 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4654 scoped_restore preventer
= prevent_dont_repeat ();
4656 /* This pointer will iterate over the list of bpstat's. */
4659 /* The $_hit_* convenience variables are set before running the
4660 commands of BS. In case we have several bs, after the loop,
4661 we set again the variables to the first printed bpnum and locno.
4662 For multiple breakpoints, this ensures the variables are set to the
4663 breakpoint printed for the user. */
4664 int printed_hit_bpnum
= -1;
4665 int printed_hit_locno
= -1;
4667 breakpoint_proceeded
= 0;
4668 for (; bs
!= NULL
; bs
= bs
->next
)
4670 struct command_line
*cmd
= NULL
;
4672 /* Set the _hit_* convenience variables before running BS's commands. */
4674 const struct breakpoint
*b
= bs
->breakpoint_at
;
4677 int locno
= bpstat_locno (bs
);
4679 set_hit_convenience_vars (b
->number
, locno
);
4680 if (printed_hit_locno
== -1 && bs
->print
)
4682 printed_hit_bpnum
= b
->number
;
4683 printed_hit_locno
= locno
;
4688 /* Take ownership of the BSP's command tree, if it has one.
4690 The command tree could legitimately contain commands like
4691 'step' and 'next', which call clear_proceed_status, which
4692 frees the bpstat BS and its command tree. To make sure this doesn't
4693 free the tree we're executing out from under us, we need to
4694 take ownership of the tree ourselves. Since a given bpstat's
4695 commands are only executed once, we don't need to copy it; we
4696 can clear the pointer in the bpstat, and make sure we free
4697 the tree when we're done. */
4698 counted_command_line ccmd
= bs
->commands
;
4699 bs
->commands
= NULL
;
4702 if (command_line_is_silent (cmd
))
4704 /* The action has been already done by bpstat_stop_status. */
4710 execute_control_command (cmd
);
4711 /* After execute_control_command, if breakpoint_proceeded is true,
4712 BS has been freed and cannot be accessed anymore. */
4714 if (breakpoint_proceeded
)
4720 if (breakpoint_proceeded
)
4722 if (current_ui
->async
)
4723 /* If we are in async mode, then the target might be still
4724 running, not stopped at any breakpoint, so nothing for
4725 us to do here -- just return to the event loop. */
4728 /* In sync mode, when execute_control_command returns
4729 we're already standing on the next breakpoint.
4730 Breakpoint commands for that stop were not run, since
4731 execute_command does not run breakpoint commands --
4732 only command_line_handler does, but that one is not
4733 involved in execution of breakpoint commands. So, we
4734 can now execute breakpoint commands. It should be
4735 noted that making execute_command do bpstat actions is
4736 not an option -- in this case we'll have recursive
4737 invocation of bpstat for each breakpoint with a
4738 command, and can easily blow up GDB stack. Instead, we
4739 return true, which will trigger the caller to recall us
4740 with the new stop_bpstat. */
4746 /* Now that we have executed the commands of all bs, set the _hit_*
4747 convenience variables to the printed values. */
4748 if (printed_hit_locno
!= -1)
4749 set_hit_convenience_vars (printed_hit_bpnum
, printed_hit_locno
);
4754 /* Helper for bpstat_do_actions. Get the current thread, if there's
4755 one, is alive and has execution. Return NULL otherwise. */
4757 static thread_info
*
4758 get_bpstat_thread ()
4760 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4763 thread_info
*tp
= inferior_thread ();
4764 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4770 bpstat_do_actions (void)
4772 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4775 /* Do any commands attached to breakpoint we are stopped at. */
4776 while ((tp
= get_bpstat_thread ()) != NULL
)
4778 /* Since in sync mode, bpstat_do_actions may resume the
4779 inferior, and only return when it is stopped at the next
4780 breakpoint, we keep doing breakpoint actions until it returns
4781 false to indicate the inferior was not resumed. */
4782 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4786 cleanup_if_error
.release ();
4789 /* Print out the (old or new) value associated with a watchpoint. */
4792 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4795 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4798 struct value_print_options opts
;
4799 get_user_print_options (&opts
);
4800 value_print (val
, stream
, &opts
);
4804 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4805 debugging multiple threads. */
4808 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4810 if (uiout
->is_mi_like_p ())
4815 if (show_thread_that_caused_stop ())
4817 struct thread_info
*thr
= inferior_thread ();
4819 uiout
->text ("Thread ");
4820 uiout
->field_string ("thread-id", print_thread_id (thr
));
4822 const char *name
= thread_name (thr
);
4825 uiout
->text (" \"");
4826 uiout
->field_string ("name", name
);
4830 uiout
->text (" hit ");
4834 /* Generic routine for printing messages indicating why we
4835 stopped. The behavior of this function depends on the value
4836 'print_it' in the bpstat structure. Under some circumstances we
4837 may decide not to print anything here and delegate the task to
4840 static enum print_stop_action
4841 print_bp_stop_message (bpstat
*bs
)
4843 switch (bs
->print_it
)
4846 /* Nothing should be printed for this bpstat entry. */
4847 return PRINT_UNKNOWN
;
4851 /* We still want to print the frame, but we already printed the
4852 relevant messages. */
4853 return PRINT_SRC_AND_LOC
;
4856 case print_it_normal
:
4858 struct breakpoint
*b
= bs
->breakpoint_at
;
4860 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4861 which has since been deleted. */
4863 return PRINT_UNKNOWN
;
4865 /* Normal case. Call the breakpoint's print_it method. */
4866 return b
->print_it (bs
);
4871 internal_error (_("print_bp_stop_message: unrecognized enum value"));
4876 /* See breakpoint.h. */
4879 print_solib_event (bool is_catchpoint
)
4881 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4882 bool any_added
= !current_program_space
->added_solibs
.empty ();
4886 if (any_added
|| any_deleted
)
4887 current_uiout
->text (_("Stopped due to shared library event:\n"));
4889 current_uiout
->text (_("Stopped due to shared library event (no "
4890 "libraries added or removed)\n"));
4893 if (current_uiout
->is_mi_like_p ())
4894 current_uiout
->field_string ("reason",
4895 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4899 current_uiout
->text (_(" Inferior unloaded "));
4900 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4901 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4903 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4906 current_uiout
->text (" ");
4907 current_uiout
->field_string ("library", name
);
4908 current_uiout
->text ("\n");
4914 current_uiout
->text (_(" Inferior loaded "));
4915 ui_out_emit_list
list_emitter (current_uiout
, "added");
4917 for (so_list
*iter
: current_program_space
->added_solibs
)
4920 current_uiout
->text (" ");
4922 current_uiout
->field_string ("library", iter
->so_name
);
4923 current_uiout
->text ("\n");
4928 /* Print a message indicating what happened. This is called from
4929 normal_stop(). The input to this routine is the head of the bpstat
4930 list - a list of the eventpoints that caused this stop. KIND is
4931 the target_waitkind for the stopping event. This
4932 routine calls the generic print routine for printing a message
4933 about reasons for stopping. This will print (for example) the
4934 "Breakpoint n," part of the output. The return value of this
4937 PRINT_UNKNOWN: Means we printed nothing.
4938 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4939 code to print the location. An example is
4940 "Breakpoint 1, " which should be followed by
4942 PRINT_SRC_ONLY: Means we printed something, but there is no need
4943 to also print the location part of the message.
4944 An example is the catch/throw messages, which
4945 don't require a location appended to the end.
4946 PRINT_NOTHING: We have done some printing and we don't need any
4947 further info to be printed. */
4949 enum print_stop_action
4950 bpstat_print (bpstat
*bs
, target_waitkind kind
)
4952 enum print_stop_action val
;
4954 /* Maybe another breakpoint in the chain caused us to stop.
4955 (Currently all watchpoints go on the bpstat whether hit or not.
4956 That probably could (should) be changed, provided care is taken
4957 with respect to bpstat_explains_signal). */
4958 for (; bs
; bs
= bs
->next
)
4960 val
= print_bp_stop_message (bs
);
4961 if (val
== PRINT_SRC_ONLY
4962 || val
== PRINT_SRC_AND_LOC
4963 || val
== PRINT_NOTHING
)
4967 /* If we had hit a shared library event breakpoint,
4968 print_bp_stop_message would print out this message. If we hit an
4969 OS-level shared library event, do the same thing. */
4970 if (kind
== TARGET_WAITKIND_LOADED
)
4972 print_solib_event (false);
4973 return PRINT_NOTHING
;
4976 /* We reached the end of the chain, or we got a null BS to start
4977 with and nothing was printed. */
4978 return PRINT_UNKNOWN
;
4981 /* Evaluate the boolean expression EXP and return the result. */
4984 breakpoint_cond_eval (expression
*exp
)
4986 scoped_value_mark mark
;
4987 return value_true (evaluate_expression (exp
));
4990 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4992 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4994 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4995 breakpoint_at (bl
->owner
),
4999 print_it (print_it_normal
)
5001 **bs_link_pointer
= this;
5002 *bs_link_pointer
= &next
;
5007 breakpoint_at (NULL
),
5011 print_it (print_it_normal
)
5015 /* The target has stopped with waitstatus WS. Check if any hardware
5016 watchpoints have triggered, according to the target. */
5019 watchpoints_triggered (const target_waitstatus
&ws
)
5021 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5024 if (!stopped_by_watchpoint
)
5026 /* We were not stopped by a watchpoint. Mark all watchpoints
5027 as not triggered. */
5028 for (breakpoint
*b
: all_breakpoints ())
5029 if (is_hardware_watchpoint (b
))
5031 struct watchpoint
*w
= (struct watchpoint
*) b
;
5033 w
->watchpoint_triggered
= watch_triggered_no
;
5039 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
5041 /* We were stopped by a watchpoint, but we don't know where.
5042 Mark all watchpoints as unknown. */
5043 for (breakpoint
*b
: all_breakpoints ())
5044 if (is_hardware_watchpoint (b
))
5046 struct watchpoint
*w
= (struct watchpoint
*) b
;
5048 w
->watchpoint_triggered
= watch_triggered_unknown
;
5054 /* The target could report the data address. Mark watchpoints
5055 affected by this data address as triggered, and all others as not
5058 for (breakpoint
*b
: all_breakpoints ())
5059 if (is_hardware_watchpoint (b
))
5061 struct watchpoint
*w
= (struct watchpoint
*) b
;
5063 w
->watchpoint_triggered
= watch_triggered_no
;
5064 for (bp_location
*loc
: b
->locations ())
5066 if (is_masked_watchpoint (b
))
5068 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5069 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5071 if (newaddr
== start
)
5073 w
->watchpoint_triggered
= watch_triggered_yes
;
5077 /* Exact match not required. Within range is sufficient. */
5078 else if (target_watchpoint_addr_within_range
5079 (current_inferior ()->top_target (), addr
, loc
->address
,
5082 w
->watchpoint_triggered
= watch_triggered_yes
;
5091 /* Possible return values for watchpoint_check. */
5092 enum wp_check_result
5094 /* The watchpoint has been deleted. */
5097 /* The value has changed. */
5098 WP_VALUE_CHANGED
= 2,
5100 /* The value has not changed. */
5101 WP_VALUE_NOT_CHANGED
= 3,
5103 /* Ignore this watchpoint, no matter if the value changed or not. */
5107 #define BP_TEMPFLAG 1
5108 #define BP_HARDWAREFLAG 2
5110 /* Evaluate watchpoint condition expression and check if its value
5113 static wp_check_result
5114 watchpoint_check (bpstat
*bs
)
5116 struct watchpoint
*b
;
5118 bool within_current_scope
;
5120 /* BS is built from an existing struct breakpoint. */
5121 gdb_assert (bs
->breakpoint_at
!= NULL
);
5122 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5124 /* If this is a local watchpoint, we only want to check if the
5125 watchpoint frame is in scope if the current thread is the thread
5126 that was used to create the watchpoint. */
5127 if (!watchpoint_in_thread_scope (b
))
5130 if (b
->exp_valid_block
== NULL
)
5131 within_current_scope
= true;
5134 frame_info_ptr frame
= get_current_frame ();
5135 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5136 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5138 /* stack_frame_destroyed_p() returns a non-zero value if we're
5139 still in the function but the stack frame has already been
5140 invalidated. Since we can't rely on the values of local
5141 variables after the stack has been destroyed, we are treating
5142 the watchpoint in that state as `not changed' without further
5143 checking. Don't mark watchpoints as changed if the current
5144 frame is in an epilogue - even if they are in some other
5145 frame, our view of the stack is likely to be wrong and
5146 frame_find_by_id could error out. */
5147 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5150 fr
= frame_find_by_id (b
->watchpoint_frame
);
5151 within_current_scope
= (fr
!= NULL
);
5153 /* If we've gotten confused in the unwinder, we might have
5154 returned a frame that can't describe this variable. */
5155 if (within_current_scope
)
5157 struct symbol
*function
;
5159 function
= get_frame_function (fr
);
5160 if (function
== NULL
5161 || !function
->value_block ()->contains (b
->exp_valid_block
))
5162 within_current_scope
= false;
5165 if (within_current_scope
)
5166 /* If we end up stopping, the current frame will get selected
5167 in normal_stop. So this call to select_frame won't affect
5172 if (within_current_scope
)
5174 /* We use value_{,free_to_}mark because it could be a *long*
5175 time before we return to the command level and call
5176 free_all_values. We can't call free_all_values because we
5177 might be in the middle of evaluating a function call. */
5180 struct value
*new_val
;
5182 if (is_masked_watchpoint (b
))
5183 /* Since we don't know the exact trigger address (from
5184 stopped_data_address), just tell the user we've triggered
5185 a mask watchpoint. */
5186 return WP_VALUE_CHANGED
;
5188 mark
= value_mark ();
5189 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5192 if (b
->val_bitsize
!= 0)
5193 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5195 /* We use value_equal_contents instead of value_equal because
5196 the latter coerces an array to a pointer, thus comparing just
5197 the address of the array instead of its contents. This is
5198 not what we want. */
5199 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5200 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5203 bs
->old_val
= b
->val
;
5204 b
->val
= release_value (new_val
);
5205 b
->val_valid
= true;
5206 if (new_val
!= NULL
)
5207 value_free_to_mark (mark
);
5208 return WP_VALUE_CHANGED
;
5212 /* Nothing changed. */
5213 value_free_to_mark (mark
);
5214 return WP_VALUE_NOT_CHANGED
;
5219 /* This seems like the only logical thing to do because
5220 if we temporarily ignored the watchpoint, then when
5221 we reenter the block in which it is valid it contains
5222 garbage (in the case of a function, it may have two
5223 garbage values, one before and one after the prologue).
5224 So we can't even detect the first assignment to it and
5225 watch after that (since the garbage may or may not equal
5226 the first value assigned). */
5227 /* We print all the stop information in
5228 breakpointprint_it, but in this case, by the time we
5229 call breakpoint->print_it this bp will be deleted
5230 already. So we have no choice but print the information
5233 SWITCH_THRU_ALL_UIS ()
5235 struct ui_out
*uiout
= current_uiout
;
5237 if (uiout
->is_mi_like_p ())
5239 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5240 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5241 "left the block in\n"
5242 "which its expression is valid.\n",
5243 signed_field ("wpnum", b
->number
));
5246 /* Make sure the watchpoint's commands aren't executed. */
5248 watchpoint_del_at_next_stop (b
);
5254 /* Return true if it looks like target has stopped due to hitting
5255 breakpoint location BL. This function does not check if we should
5256 stop, only if BL explains the stop. */
5259 bpstat_check_location (const struct bp_location
*bl
,
5260 const address_space
*aspace
, CORE_ADDR bp_addr
,
5261 const target_waitstatus
&ws
)
5263 struct breakpoint
*b
= bl
->owner
;
5265 /* BL is from an existing breakpoint. */
5266 gdb_assert (b
!= NULL
);
5268 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5271 /* Determine if the watched values have actually changed, and we
5272 should stop. If not, set BS->stop to false. */
5275 bpstat_check_watchpoint (bpstat
*bs
)
5277 const struct bp_location
*bl
;
5278 struct watchpoint
*b
;
5280 /* BS is built for existing struct breakpoint. */
5281 bl
= bs
->bp_location_at
.get ();
5282 gdb_assert (bl
!= NULL
);
5283 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5284 gdb_assert (b
!= NULL
);
5287 bool must_check_value
= false;
5289 if (b
->type
== bp_watchpoint
)
5290 /* For a software watchpoint, we must always check the
5292 must_check_value
= true;
5293 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5294 /* We have a hardware watchpoint (read, write, or access)
5295 and the target earlier reported an address watched by
5297 must_check_value
= true;
5298 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5299 && b
->type
== bp_hardware_watchpoint
)
5300 /* We were stopped by a hardware watchpoint, but the target could
5301 not report the data address. We must check the watchpoint's
5302 value. Access and read watchpoints are out of luck; without
5303 a data address, we can't figure it out. */
5304 must_check_value
= true;
5306 if (must_check_value
)
5312 e
= watchpoint_check (bs
);
5314 catch (const gdb_exception_error
&ex
)
5316 exception_fprintf (gdb_stderr
, ex
,
5317 "Error evaluating expression "
5318 "for watchpoint %d\n",
5321 SWITCH_THRU_ALL_UIS ()
5323 gdb_printf (_("Watchpoint %d deleted.\n"),
5326 watchpoint_del_at_next_stop (b
);
5333 /* We've already printed what needs to be printed. */
5334 bs
->print_it
= print_it_done
;
5338 bs
->print_it
= print_it_noop
;
5341 case WP_VALUE_CHANGED
:
5342 if (b
->type
== bp_read_watchpoint
)
5344 /* There are two cases to consider here:
5346 1. We're watching the triggered memory for reads.
5347 In that case, trust the target, and always report
5348 the watchpoint hit to the user. Even though
5349 reads don't cause value changes, the value may
5350 have changed since the last time it was read, and
5351 since we're not trapping writes, we will not see
5352 those, and as such we should ignore our notion of
5355 2. We're watching the triggered memory for both
5356 reads and writes. There are two ways this may
5359 2.1. This is a target that can't break on data
5360 reads only, but can break on accesses (reads or
5361 writes), such as e.g., x86. We detect this case
5362 at the time we try to insert read watchpoints.
5364 2.2. Otherwise, the target supports read
5365 watchpoints, but, the user set an access or write
5366 watchpoint watching the same memory as this read
5369 If we're watching memory writes as well as reads,
5370 ignore watchpoint hits when we find that the
5371 value hasn't changed, as reads don't cause
5372 changes. This still gives false positives when
5373 the program writes the same value to memory as
5374 what there was already in memory (we will confuse
5375 it for a read), but it's much better than
5378 int other_write_watchpoint
= 0;
5380 if (bl
->watchpoint_type
== hw_read
)
5382 for (breakpoint
*other_b
: all_breakpoints ())
5383 if (other_b
->type
== bp_hardware_watchpoint
5384 || other_b
->type
== bp_access_watchpoint
)
5386 struct watchpoint
*other_w
=
5387 (struct watchpoint
*) other_b
;
5389 if (other_w
->watchpoint_triggered
5390 == watch_triggered_yes
)
5392 other_write_watchpoint
= 1;
5398 if (other_write_watchpoint
5399 || bl
->watchpoint_type
== hw_access
)
5401 /* We're watching the same memory for writes,
5402 and the value changed since the last time we
5403 updated it, so this trap must be for a write.
5405 bs
->print_it
= print_it_noop
;
5410 case WP_VALUE_NOT_CHANGED
:
5411 if (b
->type
== bp_hardware_watchpoint
5412 || b
->type
== bp_watchpoint
)
5414 /* Don't stop: write watchpoints shouldn't fire if
5415 the value hasn't changed. */
5416 bs
->print_it
= print_it_noop
;
5426 else /* !must_check_value */
5428 /* This is a case where some watchpoint(s) triggered, but
5429 not at the address of this watchpoint, or else no
5430 watchpoint triggered after all. So don't print
5431 anything for this watchpoint. */
5432 bs
->print_it
= print_it_noop
;
5438 /* For breakpoints that are currently marked as telling gdb to stop,
5439 check conditions (condition proper, frame, thread and ignore count)
5440 of breakpoint referred to by BS. If we should not stop for this
5441 breakpoint, set BS->stop to 0. */
5444 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5446 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
5448 const struct bp_location
*bl
;
5449 struct breakpoint
*b
;
5451 bool condition_result
= true;
5452 struct expression
*cond
;
5454 gdb_assert (bs
->stop
);
5456 /* BS is built for existing struct breakpoint. */
5457 bl
= bs
->bp_location_at
.get ();
5458 gdb_assert (bl
!= NULL
);
5459 b
= bs
->breakpoint_at
;
5460 gdb_assert (b
!= NULL
);
5462 infrun_debug_printf ("thread = %s, breakpoint %d.%d",
5463 thread
->ptid
.to_string ().c_str (),
5464 b
->number
, find_loc_num_by_location (bl
));
5466 /* Even if the target evaluated the condition on its end and notified GDB, we
5467 need to do so again since GDB does not know if we stopped due to a
5468 breakpoint or a single step breakpoint. */
5470 if (frame_id_p (b
->frame_id
)
5471 && b
->frame_id
!= get_stack_frame_id (get_current_frame ()))
5473 infrun_debug_printf ("incorrect frame %s not %s, not stopping",
5474 get_stack_frame_id (get_current_frame ()).to_string ().c_str (),
5475 b
->frame_id
.to_string ().c_str ());
5480 /* If this is a thread/task-specific breakpoint, don't waste cpu
5481 evaluating the condition if this isn't the specified
5483 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5484 || (b
->task
!= -1 && b
->task
!= ada_get_task_number (thread
)))
5486 infrun_debug_printf ("incorrect thread or task, not stopping");
5491 /* Evaluate extension language breakpoints that have a "stop" method
5493 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5495 if (is_watchpoint (b
))
5497 struct watchpoint
*w
= (struct watchpoint
*) b
;
5499 cond
= w
->cond_exp
.get ();
5502 cond
= bl
->cond
.get ();
5504 if (cond
!= nullptr && b
->disposition
!= disp_del_at_next_stop
)
5506 bool within_current_scope
= true;
5507 struct watchpoint
* w
;
5509 /* We use scoped_value_mark because it could be a long time
5510 before we return to the command level and call
5511 free_all_values. We can't call free_all_values because we
5512 might be in the middle of evaluating a function call. */
5513 scoped_value_mark mark
;
5515 if (is_watchpoint (b
))
5516 w
= (struct watchpoint
*) b
;
5520 /* Need to select the frame, with all that implies so that
5521 the conditions will have the right context. Because we
5522 use the frame, we will not see an inlined function's
5523 variables when we arrive at a breakpoint at the start
5524 of the inlined function; the current frame will be the
5526 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5527 select_frame (get_current_frame ());
5530 frame_info_ptr frame
;
5532 /* For local watchpoint expressions, which particular
5533 instance of a local is being watched matters, so we
5534 keep track of the frame to evaluate the expression
5535 in. To evaluate the condition however, it doesn't
5536 really matter which instantiation of the function
5537 where the condition makes sense triggers the
5538 watchpoint. This allows an expression like "watch
5539 global if q > 10" set in `func', catch writes to
5540 global on all threads that call `func', or catch
5541 writes on all recursive calls of `func' by a single
5542 thread. We simply always evaluate the condition in
5543 the innermost frame that's executing where it makes
5544 sense to evaluate the condition. It seems
5546 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5548 select_frame (frame
);
5550 within_current_scope
= false;
5552 CORE_ADDR pc_before_check
= get_frame_pc (get_selected_frame (nullptr));
5553 if (within_current_scope
)
5557 condition_result
= breakpoint_cond_eval (cond
);
5559 catch (const gdb_exception_error
&ex
)
5561 exception_fprintf (gdb_stderr
, ex
,
5562 "Error in testing condition for breakpoint %d:\n",
5565 /* If the pc value changed as a result of evaluating the
5566 condition then we probably stopped within an inferior
5567 function call due to some unexpected stop, e.g. the thread
5568 hit another breakpoint, or the thread received an
5569 unexpected signal. In this case we don't want to also
5570 print the information about this breakpoint. */
5571 CORE_ADDR pc_after_check
5572 = get_frame_pc (get_selected_frame (nullptr));
5573 if (pc_before_check
!= pc_after_check
)
5579 warning (_("Watchpoint condition cannot be tested "
5580 "in the current scope"));
5581 /* If we failed to set the right context for this
5582 watchpoint, unconditionally report it. */
5584 /* FIXME-someday, should give breakpoint #. */
5587 if (cond
!= nullptr && !condition_result
)
5589 infrun_debug_printf ("condition_result = false, not stopping");
5593 else if (b
->ignore_count
> 0)
5595 infrun_debug_printf ("ignore count %d, not stopping",
5599 /* Increase the hit count even though we don't stop. */
5601 gdb::observers::breakpoint_modified
.notify (b
);
5606 infrun_debug_printf ("stopping at this breakpoint");
5608 infrun_debug_printf ("not stopping at this breakpoint");
5611 /* Returns true if we need to track moribund locations of LOC's type
5612 on the current target. */
5615 need_moribund_for_location_type (const struct bp_location
*loc
)
5617 return ((loc
->loc_type
== bp_loc_software_breakpoint
5618 && !target_supports_stopped_by_sw_breakpoint ())
5619 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5620 && !target_supports_stopped_by_hw_breakpoint ()));
5623 /* See breakpoint.h. */
5626 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5627 const target_waitstatus
&ws
)
5629 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5631 for (breakpoint
*b
: all_breakpoints ())
5633 if (!breakpoint_enabled (b
))
5636 for (bp_location
*bl
: b
->locations ())
5638 /* For hardware watchpoints, we look only at the first
5639 location. The watchpoint_check function will work on the
5640 entire expression, not the individual locations. For
5641 read watchpoints, the watchpoints_triggered function has
5642 checked all locations already. */
5643 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5646 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5649 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5652 /* Come here if it's a watchpoint, or if the break address
5655 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5658 /* Assume we stop. Should we find a watchpoint that is not
5659 actually triggered, or if the condition of the breakpoint
5660 evaluates as false, we'll reset 'stop' to 0. */
5664 /* If this is a scope breakpoint, mark the associated
5665 watchpoint as triggered so that we will handle the
5666 out-of-scope event. We'll get to the watchpoint next
5668 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5670 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5672 w
->watchpoint_triggered
= watch_triggered_yes
;
5677 /* Check if a moribund breakpoint explains the stop. */
5678 if (!target_supports_stopped_by_sw_breakpoint ()
5679 || !target_supports_stopped_by_hw_breakpoint ())
5681 for (bp_location
*loc
: moribund_locations
)
5683 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5684 && need_moribund_for_location_type (loc
))
5686 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5687 /* For hits of moribund locations, we should just proceed. */
5690 bs
->print_it
= print_it_noop
;
5698 /* See breakpoint.h. */
5701 bpstat_stop_status (const address_space
*aspace
,
5702 CORE_ADDR bp_addr
, thread_info
*thread
,
5703 const target_waitstatus
&ws
,
5706 struct breakpoint
*b
= NULL
;
5707 /* First item of allocated bpstat's. */
5708 bpstat
*bs_head
= stop_chain
;
5710 int need_remove_insert
;
5713 /* First, build the bpstat chain with locations that explain a
5714 target stop, while being careful to not set the target running,
5715 as that may invalidate locations (in particular watchpoint
5716 locations are recreated). Resuming will happen here with
5717 breakpoint conditions or watchpoint expressions that include
5718 inferior function calls. */
5719 if (bs_head
== NULL
)
5720 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5722 /* A bit of special processing for shlib breakpoints. We need to
5723 process solib loading here, so that the lists of loaded and
5724 unloaded libraries are correct before we handle "catch load" and
5726 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5728 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5730 handle_solib_event ();
5735 /* Now go through the locations that caused the target to stop, and
5736 check whether we're interested in reporting this stop to higher
5737 layers, or whether we should resume the target transparently. */
5741 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5746 b
= bs
->breakpoint_at
;
5747 b
->check_status (bs
);
5750 bpstat_check_breakpoint_conditions (bs
, thread
);
5756 /* We will stop here. */
5757 if (b
->disposition
== disp_disable
)
5759 --(b
->enable_count
);
5760 if (b
->enable_count
<= 0)
5761 b
->enable_state
= bp_disabled
;
5764 gdb::observers::breakpoint_modified
.notify (b
);
5767 bs
->commands
= b
->commands
;
5768 if (command_line_is_silent (bs
->commands
5769 ? bs
->commands
.get () : NULL
))
5772 b
->after_condition_true (bs
);
5777 /* Print nothing for this entry if we don't stop or don't
5779 if (!bs
->stop
|| !bs
->print
)
5780 bs
->print_it
= print_it_noop
;
5783 /* If we aren't stopping, the value of some hardware watchpoint may
5784 not have changed, but the intermediate memory locations we are
5785 watching may have. Don't bother if we're stopping; this will get
5787 need_remove_insert
= 0;
5788 if (! bpstat_causes_stop (bs_head
))
5789 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5791 && bs
->breakpoint_at
5792 && is_hardware_watchpoint (bs
->breakpoint_at
))
5794 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5796 update_watchpoint (w
, false /* don't reparse. */);
5797 need_remove_insert
= 1;
5800 if (need_remove_insert
)
5801 update_global_location_list (UGLL_MAY_INSERT
);
5802 else if (removed_any
)
5803 update_global_location_list (UGLL_DONT_INSERT
);
5808 /* See breakpoint.h. */
5811 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5812 thread_info
*thread
, const target_waitstatus
&ws
)
5814 gdb_assert (!target_stopped_by_watchpoint ());
5816 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5817 previous stop to avoid confusing bpstat_stop_status. */
5818 watchpoints_triggered (ws
);
5820 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5824 handle_jit_event (CORE_ADDR address
)
5826 struct gdbarch
*gdbarch
;
5828 infrun_debug_printf ("handling bp_jit_event");
5830 /* Switch terminal for any messages produced by
5831 breakpoint_re_set. */
5832 target_terminal::ours_for_output ();
5834 gdbarch
= get_frame_arch (get_current_frame ());
5835 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5836 thus it is expected that its objectfile can be found through
5837 minimal symbol lookup. If it doesn't work (and assert fails), it
5838 most likely means that `jit_breakpoint_re_set` was changes and this
5839 function needs to be updated too. */
5840 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5841 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5842 objfile
*objfile
= jit_bp_sym
.objfile
;
5843 if (objfile
->separate_debug_objfile_backlink
)
5844 objfile
= objfile
->separate_debug_objfile_backlink
;
5845 jit_event_handler (gdbarch
, objfile
);
5847 target_terminal::inferior ();
5850 /* Prepare WHAT final decision for infrun. */
5852 /* Decide what infrun needs to do with this bpstat. */
5855 bpstat_what (bpstat
*bs_head
)
5857 struct bpstat_what retval
;
5860 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5861 retval
.call_dummy
= STOP_NONE
;
5862 retval
.is_longjmp
= false;
5864 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5866 /* Extract this BS's action. After processing each BS, we check
5867 if its action overrides all we've seem so far. */
5868 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5871 if (bs
->breakpoint_at
== NULL
)
5873 /* I suspect this can happen if it was a momentary
5874 breakpoint which has since been deleted. */
5878 bptype
= bs
->breakpoint_at
->type
;
5885 case bp_hardware_breakpoint
:
5886 case bp_single_step
:
5889 case bp_shlib_event
:
5893 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5895 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5898 this_action
= BPSTAT_WHAT_SINGLE
;
5901 case bp_hardware_watchpoint
:
5902 case bp_read_watchpoint
:
5903 case bp_access_watchpoint
:
5907 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5909 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5913 /* There was a watchpoint, but we're not stopping.
5914 This requires no further action. */
5918 case bp_longjmp_call_dummy
:
5922 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5923 retval
.is_longjmp
= bptype
!= bp_exception
;
5926 this_action
= BPSTAT_WHAT_SINGLE
;
5928 case bp_longjmp_resume
:
5929 case bp_exception_resume
:
5932 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5933 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5936 this_action
= BPSTAT_WHAT_SINGLE
;
5938 case bp_step_resume
:
5940 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5943 /* It is for the wrong frame. */
5944 this_action
= BPSTAT_WHAT_SINGLE
;
5947 case bp_hp_step_resume
:
5949 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5952 /* It is for the wrong frame. */
5953 this_action
= BPSTAT_WHAT_SINGLE
;
5956 case bp_watchpoint_scope
:
5957 case bp_thread_event
:
5958 case bp_overlay_event
:
5959 case bp_longjmp_master
:
5960 case bp_std_terminate_master
:
5961 case bp_exception_master
:
5962 this_action
= BPSTAT_WHAT_SINGLE
;
5968 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5970 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5974 /* Some catchpoints are implemented with breakpoints.
5975 For those, we need to step over the breakpoint. */
5976 if (bs
->bp_location_at
->loc_type
== bp_loc_software_breakpoint
5977 || bs
->bp_location_at
->loc_type
== bp_loc_hardware_breakpoint
)
5978 this_action
= BPSTAT_WHAT_SINGLE
;
5982 this_action
= BPSTAT_WHAT_SINGLE
;
5985 /* Make sure the action is stop (silent or noisy),
5986 so infrun.c pops the dummy frame. */
5987 retval
.call_dummy
= STOP_STACK_DUMMY
;
5988 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5990 case bp_std_terminate
:
5991 /* Make sure the action is stop (silent or noisy),
5992 so infrun.c pops the dummy frame. */
5993 retval
.call_dummy
= STOP_STD_TERMINATE
;
5994 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5997 case bp_fast_tracepoint
:
5998 case bp_static_tracepoint
:
5999 case bp_static_marker_tracepoint
:
6000 /* Tracepoint hits should not be reported back to GDB, and
6001 if one got through somehow, it should have been filtered
6003 internal_error (_("bpstat_what: tracepoint encountered"));
6005 case bp_gnu_ifunc_resolver
:
6006 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
6007 this_action
= BPSTAT_WHAT_SINGLE
;
6009 case bp_gnu_ifunc_resolver_return
:
6010 /* The breakpoint will be removed, execution will restart from the
6011 PC of the former breakpoint. */
6012 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
6017 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6019 this_action
= BPSTAT_WHAT_SINGLE
;
6023 internal_error (_("bpstat_what: unhandled bptype %d"), (int) bptype
);
6026 retval
.main_action
= std::max (retval
.main_action
, this_action
);
6033 bpstat_run_callbacks (bpstat
*bs_head
)
6037 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6039 struct breakpoint
*b
= bs
->breakpoint_at
;
6046 handle_jit_event (bs
->bp_location_at
->address
);
6048 case bp_gnu_ifunc_resolver
:
6049 gnu_ifunc_resolver_stop ((code_breakpoint
*) b
);
6051 case bp_gnu_ifunc_resolver_return
:
6052 gnu_ifunc_resolver_return_stop ((code_breakpoint
*) b
);
6058 /* See breakpoint.h. */
6061 bpstat_should_step ()
6063 for (breakpoint
*b
: all_breakpoints ())
6064 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6070 /* See breakpoint.h. */
6073 bpstat_causes_stop (bpstat
*bs
)
6075 for (; bs
!= NULL
; bs
= bs
->next
)
6084 /* Compute a number of spaces suitable to indent the next line
6085 so it starts at the position corresponding to the table column
6086 named COL_NAME in the currently active table of UIOUT. */
6089 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6091 int i
, total_width
, width
, align
;
6095 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6097 if (strcmp (text
, col_name
) == 0)
6100 total_width
+= width
+ 1;
6106 /* Determine if the locations of this breakpoint will have their conditions
6107 evaluated by the target, host or a mix of both. Returns the following:
6109 "host": Host evals condition.
6110 "host or target": Host or Target evals condition.
6111 "target": Target evals condition.
6115 bp_condition_evaluator (const breakpoint
*b
)
6117 char host_evals
= 0;
6118 char target_evals
= 0;
6123 if (!is_breakpoint (b
))
6126 if (gdb_evaluates_breakpoint_condition_p ()
6127 || !target_supports_evaluation_of_breakpoint_conditions ())
6128 return condition_evaluation_host
;
6130 for (bp_location
*bl
: b
->locations ())
6132 if (bl
->cond_bytecode
)
6138 if (host_evals
&& target_evals
)
6139 return condition_evaluation_both
;
6140 else if (target_evals
)
6141 return condition_evaluation_target
;
6143 return condition_evaluation_host
;
6146 /* Determine the breakpoint location's condition evaluator. This is
6147 similar to bp_condition_evaluator, but for locations. */
6150 bp_location_condition_evaluator (const struct bp_location
*bl
)
6152 if (bl
&& !is_breakpoint (bl
->owner
))
6155 if (gdb_evaluates_breakpoint_condition_p ()
6156 || !target_supports_evaluation_of_breakpoint_conditions ())
6157 return condition_evaluation_host
;
6159 if (bl
&& bl
->cond_bytecode
)
6160 return condition_evaluation_target
;
6162 return condition_evaluation_host
;
6165 /* Print the LOC location out of the list of B->LOC locations. */
6168 print_breakpoint_location (const breakpoint
*b
,
6169 struct bp_location
*loc
)
6171 struct ui_out
*uiout
= current_uiout
;
6173 scoped_restore_current_program_space restore_pspace
;
6175 if (loc
!= NULL
&& loc
->shlib_disabled
)
6179 set_current_program_space (loc
->pspace
);
6181 if (b
->display_canonical
)
6182 uiout
->field_string ("what", b
->locspec
->to_string ());
6183 else if (loc
&& loc
->symtab
)
6185 const struct symbol
*sym
= loc
->symbol
;
6189 uiout
->text ("in ");
6190 uiout
->field_string ("func", sym
->print_name (),
6191 function_name_style
.style ());
6193 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6194 uiout
->text ("at ");
6196 uiout
->field_string ("file",
6197 symtab_to_filename_for_display (loc
->symtab
),
6198 file_name_style
.style ());
6201 if (uiout
->is_mi_like_p ())
6202 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6204 uiout
->field_signed ("line", loc
->line_number
);
6210 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6212 uiout
->field_stream ("at", stb
);
6216 uiout
->field_string ("pending", b
->locspec
->to_string ());
6217 /* If extra_string is available, it could be holding a condition
6218 or dprintf arguments. In either case, make sure it is printed,
6219 too, but only for non-MI streams. */
6220 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6222 if (b
->type
== bp_dprintf
)
6226 uiout
->text (b
->extra_string
.get ());
6230 if (loc
&& is_breakpoint (b
)
6231 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6232 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6235 uiout
->field_string ("evaluated-by",
6236 bp_location_condition_evaluator (loc
));
6242 bptype_string (enum bptype type
)
6244 struct ep_type_description
6247 const char *description
;
6249 static struct ep_type_description bptypes
[] =
6251 {bp_none
, "?deleted?"},
6252 {bp_breakpoint
, "breakpoint"},
6253 {bp_hardware_breakpoint
, "hw breakpoint"},
6254 {bp_single_step
, "sw single-step"},
6255 {bp_until
, "until"},
6256 {bp_finish
, "finish"},
6257 {bp_watchpoint
, "watchpoint"},
6258 {bp_hardware_watchpoint
, "hw watchpoint"},
6259 {bp_read_watchpoint
, "read watchpoint"},
6260 {bp_access_watchpoint
, "acc watchpoint"},
6261 {bp_longjmp
, "longjmp"},
6262 {bp_longjmp_resume
, "longjmp resume"},
6263 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6264 {bp_exception
, "exception"},
6265 {bp_exception_resume
, "exception resume"},
6266 {bp_step_resume
, "step resume"},
6267 {bp_hp_step_resume
, "high-priority step resume"},
6268 {bp_watchpoint_scope
, "watchpoint scope"},
6269 {bp_call_dummy
, "call dummy"},
6270 {bp_std_terminate
, "std::terminate"},
6271 {bp_shlib_event
, "shlib events"},
6272 {bp_thread_event
, "thread events"},
6273 {bp_overlay_event
, "overlay events"},
6274 {bp_longjmp_master
, "longjmp master"},
6275 {bp_std_terminate_master
, "std::terminate master"},
6276 {bp_exception_master
, "exception master"},
6277 {bp_catchpoint
, "catchpoint"},
6278 {bp_tracepoint
, "tracepoint"},
6279 {bp_fast_tracepoint
, "fast tracepoint"},
6280 {bp_static_tracepoint
, "static tracepoint"},
6281 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6282 {bp_dprintf
, "dprintf"},
6283 {bp_jit_event
, "jit events"},
6284 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6285 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6288 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6289 || ((int) type
!= bptypes
[(int) type
].type
))
6290 internal_error (_("bptypes table does not describe type #%d."),
6293 return bptypes
[(int) type
].description
;
6296 /* For MI, output a field named 'thread-groups' with a list as the value.
6297 For CLI, prefix the list with the string 'inf'. */
6300 output_thread_groups (struct ui_out
*uiout
,
6301 const char *field_name
,
6302 const std::vector
<int> &inf_nums
,
6305 int is_mi
= uiout
->is_mi_like_p ();
6307 /* For backward compatibility, don't display inferiors in CLI unless
6308 there are several. Always display them for MI. */
6309 if (!is_mi
&& mi_only
)
6312 ui_out_emit_list
list_emitter (uiout
, field_name
);
6314 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6320 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6321 uiout
->field_string (NULL
, mi_group
);
6326 uiout
->text (" inf ");
6330 uiout
->text (plongest (inf_nums
[i
]));
6335 /* See breakpoint.h. */
6337 bool fix_breakpoint_script_output_globally
= false;
6339 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6340 instead of going via breakpoint_ops::print_one. This makes "maint
6341 info breakpoints" show the software breakpoint locations of
6342 catchpoints, which are considered internal implementation
6343 detail. Returns true if RAW_LOC is false and if the breakpoint's
6344 print_one method did something; false otherwise. */
6347 print_one_breakpoint_location (struct breakpoint
*b
,
6348 struct bp_location
*loc
,
6350 struct bp_location
**last_loc
,
6351 int allflag
, bool raw_loc
)
6353 struct command_line
*l
;
6354 static char bpenables
[] = "nynny";
6356 struct ui_out
*uiout
= current_uiout
;
6357 bool header_of_multiple
= false;
6358 bool part_of_multiple
= (loc
!= NULL
);
6359 struct value_print_options opts
;
6361 get_user_print_options (&opts
);
6363 gdb_assert (!loc
|| loc_number
!= 0);
6364 /* See comment in print_one_breakpoint concerning treatment of
6365 breakpoints with single disabled location. */
6368 && (b
->loc
->next
!= NULL
6369 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6370 header_of_multiple
= true;
6378 if (part_of_multiple
)
6379 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6381 uiout
->field_signed ("number", b
->number
);
6385 if (part_of_multiple
)
6386 uiout
->field_skip ("type");
6388 uiout
->field_string ("type", bptype_string (b
->type
));
6392 if (part_of_multiple
)
6393 uiout
->field_skip ("disp");
6395 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6399 if (part_of_multiple
)
6401 /* For locations that are disabled because of an invalid
6402 condition, display "N*" on the CLI, where "*" refers to a
6403 footnote below the table. For MI, simply display a "N"
6404 without a footnote. On the CLI, for enabled locations whose
6405 breakpoint is disabled, display "y-". */
6406 auto get_enable_state
= [uiout
, loc
] () -> const char *
6408 if (uiout
->is_mi_like_p ())
6410 if (loc
->disabled_by_cond
)
6412 else if (!loc
->enabled
)
6419 if (loc
->disabled_by_cond
)
6421 else if (!loc
->enabled
)
6423 else if (!breakpoint_enabled (loc
->owner
))
6429 uiout
->field_string ("enabled", get_enable_state ());
6432 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6435 bool result
= false;
6436 if (!raw_loc
&& b
->print_one (last_loc
))
6440 if (is_watchpoint (b
))
6442 struct watchpoint
*w
= (struct watchpoint
*) b
;
6444 /* Field 4, the address, is omitted (which makes the columns
6445 not line up too nicely with the headers, but the effect
6446 is relatively readable). */
6447 if (opts
.addressprint
)
6448 uiout
->field_skip ("addr");
6450 uiout
->field_string ("what", w
->exp_string
.get ());
6452 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6453 || is_ada_exception_catchpoint (b
))
6455 if (opts
.addressprint
)
6458 if (header_of_multiple
)
6459 uiout
->field_string ("addr", "<MULTIPLE>",
6460 metadata_style
.style ());
6461 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6462 uiout
->field_string ("addr", "<PENDING>",
6463 metadata_style
.style ());
6465 uiout
->field_core_addr ("addr",
6466 loc
->gdbarch
, loc
->address
);
6469 if (!header_of_multiple
)
6470 print_breakpoint_location (b
, loc
);
6476 if (loc
!= NULL
&& !header_of_multiple
)
6478 std::vector
<int> inf_nums
;
6481 for (inferior
*inf
: all_inferiors ())
6483 if (inf
->pspace
== loc
->pspace
)
6484 inf_nums
.push_back (inf
->num
);
6487 /* For backward compatibility, don't display inferiors in CLI unless
6488 there are several. Always display for MI. */
6490 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6491 && (program_spaces
.size () > 1
6492 || number_of_inferiors () > 1)
6493 /* LOC is for existing B, it cannot be in
6494 moribund_locations and thus having NULL OWNER. */
6495 && loc
->owner
->type
!= bp_catchpoint
))
6497 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6500 /* In the MI output, each location of a thread or task specific
6501 breakpoint includes the relevant thread or task ID. This is done for
6502 backwards compatibility reasons.
6504 For the CLI output, the thread/task information is printed on a
6505 separate line, see the 'stop only in thread' and 'stop only in task'
6507 if (part_of_multiple
&& uiout
->is_mi_like_p ())
6509 if (b
->thread
!= -1)
6510 uiout
->field_signed ("thread", b
->thread
);
6511 else if (b
->task
!= -1)
6512 uiout
->field_signed ("task", b
->task
);
6517 if (!part_of_multiple
)
6518 b
->print_one_detail (uiout
);
6520 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6523 uiout
->text ("\tstop only in stack frame at ");
6524 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6526 uiout
->field_core_addr ("frame",
6527 b
->gdbarch
, b
->frame_id
.stack_addr
);
6531 if (!part_of_multiple
&& b
->cond_string
)
6534 if (is_tracepoint (b
))
6535 uiout
->text ("\ttrace only if ");
6537 uiout
->text ("\tstop only if ");
6538 uiout
->field_string ("cond", b
->cond_string
.get ());
6540 /* Print whether the target is doing the breakpoint's condition
6541 evaluation. If GDB is doing the evaluation, don't print anything. */
6542 if (is_breakpoint (b
)
6543 && breakpoint_condition_evaluation_mode ()
6544 == condition_evaluation_target
)
6546 uiout
->message (" (%pF evals)",
6547 string_field ("evaluated-by",
6548 bp_condition_evaluator (b
)));
6553 if (!part_of_multiple
&& b
->thread
!= -1)
6555 /* FIXME should make an annotation for this. */
6556 uiout
->text ("\tstop only in thread ");
6557 if (uiout
->is_mi_like_p ())
6558 uiout
->field_signed ("thread", b
->thread
);
6561 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6563 uiout
->field_string ("thread", print_thread_id (thr
));
6568 if (!part_of_multiple
&& b
->task
!= -1)
6570 uiout
->text ("\tstop only in task ");
6571 uiout
->field_signed ("task", b
->task
);
6575 if (!part_of_multiple
)
6579 /* FIXME should make an annotation for this. */
6580 if (is_catchpoint (b
))
6581 uiout
->text ("\tcatchpoint");
6582 else if (is_tracepoint (b
))
6583 uiout
->text ("\ttracepoint");
6585 uiout
->text ("\tbreakpoint");
6586 uiout
->text (" already hit ");
6587 uiout
->field_signed ("times", b
->hit_count
);
6588 if (b
->hit_count
== 1)
6589 uiout
->text (" time\n");
6591 uiout
->text (" times\n");
6595 /* Output the count also if it is zero, but only if this is mi. */
6596 if (uiout
->is_mi_like_p ())
6597 uiout
->field_signed ("times", b
->hit_count
);
6601 if (!part_of_multiple
&& b
->ignore_count
)
6604 uiout
->message ("\tignore next %pF hits\n",
6605 signed_field ("ignore", b
->ignore_count
));
6608 /* Note that an enable count of 1 corresponds to "enable once"
6609 behavior, which is reported by the combination of enablement and
6610 disposition, so we don't need to mention it here. */
6611 if (!part_of_multiple
&& b
->enable_count
> 1)
6614 uiout
->text ("\tdisable after ");
6615 /* Tweak the wording to clarify that ignore and enable counts
6616 are distinct, and have additive effect. */
6617 if (b
->ignore_count
)
6618 uiout
->text ("additional ");
6620 uiout
->text ("next ");
6621 uiout
->field_signed ("enable", b
->enable_count
);
6622 uiout
->text (" hits\n");
6625 if (!part_of_multiple
&& is_tracepoint (b
))
6627 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6629 if (tp
->traceframe_usage
)
6631 uiout
->text ("\ttrace buffer usage ");
6632 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6633 uiout
->text (" bytes\n");
6637 l
= b
->commands
? b
->commands
.get () : NULL
;
6638 if (!part_of_multiple
&& l
)
6642 bool use_fixed_output
=
6643 (uiout
->test_flags (fix_breakpoint_script_output
)
6644 || fix_breakpoint_script_output_globally
);
6646 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
6647 gdb::optional
<ui_out_emit_list
> list_emitter
;
6649 if (use_fixed_output
)
6650 list_emitter
.emplace (uiout
, "script");
6652 tuple_emitter
.emplace (uiout
, "script");
6654 print_command_lines (uiout
, l
, 4);
6657 if (is_tracepoint (b
))
6659 struct tracepoint
*t
= (struct tracepoint
*) b
;
6661 if (!part_of_multiple
&& t
->pass_count
)
6663 annotate_field (10);
6664 uiout
->text ("\tpass count ");
6665 uiout
->field_signed ("pass", t
->pass_count
);
6666 uiout
->text (" \n");
6669 /* Don't display it when tracepoint or tracepoint location is
6671 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6673 annotate_field (11);
6675 if (uiout
->is_mi_like_p ())
6676 uiout
->field_string ("installed",
6677 loc
->inserted
? "y" : "n");
6683 uiout
->text ("\tnot ");
6684 uiout
->text ("installed on target\n");
6689 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6691 if (is_watchpoint (b
))
6693 struct watchpoint
*w
= (struct watchpoint
*) b
;
6695 uiout
->field_string ("original-location", w
->exp_string
.get ());
6697 else if (b
->locspec
!= nullptr)
6699 const char *str
= b
->locspec
->to_string ();
6701 uiout
->field_string ("original-location", str
);
6708 /* See breakpoint.h. */
6710 bool fix_multi_location_breakpoint_output_globally
= false;
6713 print_one_breakpoint (struct breakpoint
*b
,
6714 struct bp_location
**last_loc
,
6717 struct ui_out
*uiout
= current_uiout
;
6718 bool use_fixed_output
6719 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6720 || fix_multi_location_breakpoint_output_globally
);
6722 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6723 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6726 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6728 if (!use_fixed_output
)
6729 bkpt_tuple_emitter
.reset ();
6731 /* If this breakpoint has custom print function,
6732 it's already printed. Otherwise, print individual
6733 locations, if any. */
6734 if (!printed
|| allflag
)
6736 /* If breakpoint has a single location that is disabled, we
6737 print it as if it had several locations, since otherwise it's
6738 hard to represent "breakpoint enabled, location disabled"
6741 Note that while hardware watchpoints have several locations
6742 internally, that's not a property exposed to users.
6744 Likewise, while catchpoints may be implemented with
6745 breakpoints (e.g., catch throw), that's not a property
6746 exposed to users. We do however display the internal
6747 breakpoint locations with "maint info breakpoints". */
6748 if (!is_hardware_watchpoint (b
)
6749 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6750 || is_ada_exception_catchpoint (b
))
6752 || (b
->loc
&& (b
->loc
->next
6754 || b
->loc
->disabled_by_cond
))))
6756 gdb::optional
<ui_out_emit_list
> locations_list
;
6758 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6759 MI record. For later versions, place breakpoint locations in a
6761 if (uiout
->is_mi_like_p () && use_fixed_output
)
6762 locations_list
.emplace (uiout
, "locations");
6765 for (bp_location
*loc
: b
->locations ())
6767 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6768 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6777 breakpoint_address_bits (struct breakpoint
*b
)
6779 int print_address_bits
= 0;
6781 for (bp_location
*loc
: b
->locations ())
6783 if (!bl_address_is_meaningful (loc
))
6786 int addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6787 if (addr_bit
> print_address_bits
)
6788 print_address_bits
= addr_bit
;
6791 return print_address_bits
;
6794 /* See breakpoint.h. */
6797 print_breakpoint (breakpoint
*b
)
6799 struct bp_location
*dummy_loc
= NULL
;
6800 print_one_breakpoint (b
, &dummy_loc
, 0);
6803 /* Return true if this breakpoint was set by the user, false if it is
6804 internal or momentary. */
6807 user_breakpoint_p (struct breakpoint
*b
)
6809 return b
->number
> 0;
6812 /* See breakpoint.h. */
6815 pending_breakpoint_p (struct breakpoint
*b
)
6817 return b
->loc
== NULL
;
6820 /* Print information on breakpoints (including watchpoints and tracepoints).
6822 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6823 understood by number_or_range_parser. Only breakpoints included in this
6824 list are then printed.
6826 If SHOW_INTERNAL is true, print internal breakpoints.
6828 If FILTER is non-NULL, call it on each breakpoint and only include the
6829 ones for which it returns true.
6831 Return the total number of breakpoints listed. */
6834 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6835 bool (*filter
) (const struct breakpoint
*))
6837 struct bp_location
*last_loc
= NULL
;
6838 int nr_printable_breakpoints
;
6839 struct value_print_options opts
;
6840 int print_address_bits
= 0;
6841 int print_type_col_width
= 14;
6842 struct ui_out
*uiout
= current_uiout
;
6843 bool has_disabled_by_cond_location
= false;
6845 get_user_print_options (&opts
);
6847 /* Compute the number of rows in the table, as well as the size
6848 required for address fields. */
6849 nr_printable_breakpoints
= 0;
6850 for (breakpoint
*b
: all_breakpoints ())
6852 /* If we have a filter, only list the breakpoints it accepts. */
6853 if (filter
&& !filter (b
))
6856 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6857 accept. Skip the others. */
6858 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6860 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6862 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6866 if (show_internal
|| user_breakpoint_p (b
))
6868 int addr_bit
, type_len
;
6870 addr_bit
= breakpoint_address_bits (b
);
6871 if (addr_bit
> print_address_bits
)
6872 print_address_bits
= addr_bit
;
6874 type_len
= strlen (bptype_string (b
->type
));
6875 if (type_len
> print_type_col_width
)
6876 print_type_col_width
= type_len
;
6878 nr_printable_breakpoints
++;
6883 ui_out_emit_table
table_emitter (uiout
,
6884 opts
.addressprint
? 6 : 5,
6885 nr_printable_breakpoints
,
6888 if (nr_printable_breakpoints
> 0)
6889 annotate_breakpoints_headers ();
6890 if (nr_printable_breakpoints
> 0)
6892 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6893 if (nr_printable_breakpoints
> 0)
6895 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6896 if (nr_printable_breakpoints
> 0)
6898 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6899 if (nr_printable_breakpoints
> 0)
6901 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6902 if (opts
.addressprint
)
6904 if (nr_printable_breakpoints
> 0)
6906 if (print_address_bits
<= 32)
6907 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6909 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6911 if (nr_printable_breakpoints
> 0)
6913 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6914 uiout
->table_body ();
6915 if (nr_printable_breakpoints
> 0)
6916 annotate_breakpoints_table ();
6918 for (breakpoint
*b
: all_breakpoints ())
6921 /* If we have a filter, only list the breakpoints it accepts. */
6922 if (filter
&& !filter (b
))
6925 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6926 accept. Skip the others. */
6928 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6930 if (show_internal
) /* maintenance info breakpoint */
6932 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6935 else /* all others */
6937 if (!number_is_in_list (bp_num_list
, b
->number
))
6941 /* We only print out user settable breakpoints unless the
6942 show_internal is set. */
6943 if (show_internal
|| user_breakpoint_p (b
))
6945 print_one_breakpoint (b
, &last_loc
, show_internal
);
6946 for (bp_location
*loc
: b
->locations ())
6947 if (loc
->disabled_by_cond
)
6948 has_disabled_by_cond_location
= true;
6953 if (nr_printable_breakpoints
== 0)
6955 /* If there's a filter, let the caller decide how to report
6959 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6960 uiout
->message ("No breakpoints or watchpoints.\n");
6962 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6968 if (last_loc
&& !server_command
)
6969 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6971 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6972 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6976 /* FIXME? Should this be moved up so that it is only called when
6977 there have been breakpoints? */
6978 annotate_breakpoints_table_end ();
6980 return nr_printable_breakpoints
;
6983 /* Display the value of default-collect in a way that is generally
6984 compatible with the breakpoint list. */
6987 default_collect_info (void)
6989 struct ui_out
*uiout
= current_uiout
;
6991 /* If it has no value (which is frequently the case), say nothing; a
6992 message like "No default-collect." gets in user's face when it's
6994 if (default_collect
.empty ())
6997 /* The following phrase lines up nicely with per-tracepoint collect
6999 uiout
->text ("default collect ");
7000 uiout
->field_string ("default-collect", default_collect
);
7001 uiout
->text (" \n");
7005 info_breakpoints_command (const char *args
, int from_tty
)
7007 breakpoint_1 (args
, false, NULL
);
7009 default_collect_info ();
7013 info_watchpoints_command (const char *args
, int from_tty
)
7015 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
7016 struct ui_out
*uiout
= current_uiout
;
7018 if (num_printed
== 0)
7020 if (args
== NULL
|| *args
== '\0')
7021 uiout
->message ("No watchpoints.\n");
7023 uiout
->message ("No watchpoint matching '%s'.\n", args
);
7028 maintenance_info_breakpoints (const char *args
, int from_tty
)
7030 breakpoint_1 (args
, true, NULL
);
7032 default_collect_info ();
7036 breakpoint_has_pc (struct breakpoint
*b
,
7037 struct program_space
*pspace
,
7038 CORE_ADDR pc
, struct obj_section
*section
)
7040 for (bp_location
*bl
: b
->locations ())
7042 if (bl
->pspace
== pspace
7043 && bl
->address
== pc
7044 && (!overlay_debugging
|| bl
->section
== section
))
7050 /* See breakpoint.h. */
7053 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7054 struct program_space
*pspace
, CORE_ADDR pc
,
7055 struct obj_section
*section
, int thread
)
7059 for (breakpoint
*b
: all_breakpoints ())
7060 others
+= (user_breakpoint_p (b
)
7061 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7066 gdb_printf (_("Note: breakpoint "));
7067 else /* if (others == ???) */
7068 gdb_printf (_("Note: breakpoints "));
7069 for (breakpoint
*b
: all_breakpoints ())
7070 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7073 gdb_printf ("%d", b
->number
);
7074 if (b
->thread
== -1 && thread
!= -1)
7075 gdb_printf (" (all threads)");
7076 else if (b
->thread
!= -1)
7078 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
7079 gdb_printf (" (thread %s)", print_thread_id (thr
));
7081 else if (b
->task
!= -1)
7082 gdb_printf (" (task %d)", b
->task
);
7083 gdb_printf ("%s%s ",
7084 ((b
->enable_state
== bp_disabled
7085 || b
->enable_state
== bp_call_disabled
)
7089 : ((others
== 1) ? " and" : ""));
7091 current_uiout
->message (_("also set at pc %ps.\n"),
7092 styled_string (address_style
.style (),
7093 paddress (gdbarch
, pc
)));
7098 /* Return true iff it is meaningful to use the address member of LOC.
7099 For some breakpoint types, the locations' address members are
7100 irrelevant and it makes no sense to attempt to compare them to
7101 other addresses (or use them for any other purpose either).
7103 More specifically, software watchpoints and catchpoints that are
7104 not backed by breakpoints always have a zero valued location
7105 address and we don't want to mark breakpoints of any of these types
7106 to be a duplicate of an actual breakpoint location at address
7110 bl_address_is_meaningful (bp_location
*loc
)
7112 return loc
->loc_type
!= bp_loc_other
;
7115 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7116 true if LOC1 and LOC2 represent the same watchpoint location. */
7119 watchpoint_locations_match (const struct bp_location
*loc1
,
7120 const struct bp_location
*loc2
)
7122 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7123 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7125 /* Both of them must exist. */
7126 gdb_assert (w1
!= NULL
);
7127 gdb_assert (w2
!= NULL
);
7129 /* If the target can evaluate the condition expression in hardware,
7130 then we we need to insert both watchpoints even if they are at
7131 the same place. Otherwise the watchpoint will only trigger when
7132 the condition of whichever watchpoint was inserted evaluates to
7133 true, not giving a chance for GDB to check the condition of the
7134 other watchpoint. */
7136 && target_can_accel_watchpoint_condition (loc1
->address
,
7138 loc1
->watchpoint_type
,
7139 w1
->cond_exp
.get ()))
7141 && target_can_accel_watchpoint_condition (loc2
->address
,
7143 loc2
->watchpoint_type
,
7144 w2
->cond_exp
.get ())))
7147 /* Note that this checks the owner's type, not the location's. In
7148 case the target does not support read watchpoints, but does
7149 support access watchpoints, we'll have bp_read_watchpoint
7150 watchpoints with hw_access locations. Those should be considered
7151 duplicates of hw_read locations. The hw_read locations will
7152 become hw_access locations later. */
7153 return (loc1
->owner
->type
== loc2
->owner
->type
7154 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7155 && loc1
->address
== loc2
->address
7156 && loc1
->length
== loc2
->length
);
7159 /* See breakpoint.h. */
7162 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
7163 const address_space
*aspace2
, CORE_ADDR addr2
)
7165 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7166 || aspace1
== aspace2
)
7170 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7171 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7172 matches ASPACE2. On targets that have global breakpoints, the address
7173 space doesn't really matter. */
7176 breakpoint_address_match_range (const address_space
*aspace1
,
7178 int len1
, const address_space
*aspace2
,
7181 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7182 || aspace1
== aspace2
)
7183 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7186 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7187 a ranged breakpoint. In most targets, a match happens only if ASPACE
7188 matches the breakpoint's address space. On targets that have global
7189 breakpoints, the address space doesn't really matter. */
7192 breakpoint_location_address_match (struct bp_location
*bl
,
7193 const address_space
*aspace
,
7196 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7199 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7200 bl
->address
, bl
->length
,
7204 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7205 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7206 match happens only if ASPACE matches the breakpoint's address
7207 space. On targets that have global breakpoints, the address space
7208 doesn't really matter. */
7211 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7212 const address_space
*aspace
,
7213 CORE_ADDR addr
, int len
)
7215 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7216 || bl
->pspace
->aspace
== aspace
)
7218 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7220 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7226 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7227 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7228 true, otherwise returns false. */
7231 tracepoint_locations_match (const struct bp_location
*loc1
,
7232 const struct bp_location
*loc2
)
7234 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7235 /* Since tracepoint locations are never duplicated with others', tracepoint
7236 locations at the same address of different tracepoints are regarded as
7237 different locations. */
7238 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7243 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7244 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7245 the same location. If SW_HW_BPS_MATCH is true, then software
7246 breakpoint locations and hardware breakpoint locations match,
7247 otherwise they don't. */
7250 breakpoint_locations_match (const struct bp_location
*loc1
,
7251 const struct bp_location
*loc2
,
7252 bool sw_hw_bps_match
)
7254 int hw_point1
, hw_point2
;
7256 /* Both of them must not be in moribund_locations. */
7257 gdb_assert (loc1
->owner
!= NULL
);
7258 gdb_assert (loc2
->owner
!= NULL
);
7260 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7261 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7263 if (hw_point1
!= hw_point2
)
7266 return watchpoint_locations_match (loc1
, loc2
);
7267 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7268 return tracepoint_locations_match (loc1
, loc2
);
7270 /* We compare bp_location.length in order to cover ranged
7271 breakpoints. Keep this in sync with
7272 bp_location_is_less_than. */
7273 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7274 loc2
->pspace
->aspace
, loc2
->address
)
7275 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7276 && loc1
->length
== loc2
->length
);
7280 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7281 int bnum
, bool have_bnum
)
7283 /* The longest string possibly returned by hex_string_custom
7284 is 50 chars. These must be at least that big for safety. */
7288 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7289 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7291 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7292 bnum
, astr1
, astr2
);
7294 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7297 /* Adjust a breakpoint's address to account for architectural
7298 constraints on breakpoint placement. Return the adjusted address.
7299 Note: Very few targets require this kind of adjustment. For most
7300 targets, this function is simply the identity function. */
7303 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7304 CORE_ADDR bpaddr
, enum bptype bptype
,
7305 struct program_space
*pspace
)
7307 gdb_assert (pspace
!= nullptr);
7309 if (bptype
== bp_watchpoint
7310 || bptype
== bp_hardware_watchpoint
7311 || bptype
== bp_read_watchpoint
7312 || bptype
== bp_access_watchpoint
7313 || bptype
== bp_catchpoint
)
7315 /* Watchpoints and the various bp_catch_* eventpoints should not
7316 have their addresses modified. */
7319 else if (bptype
== bp_single_step
)
7321 /* Single-step breakpoints should not have their addresses
7322 modified. If there's any architectural constrain that
7323 applies to this address, then it should have already been
7324 taken into account when the breakpoint was created in the
7325 first place. If we didn't do this, stepping through e.g.,
7326 Thumb-2 IT blocks would break. */
7331 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7333 /* Some targets have architectural constraints on the placement
7334 of breakpoint instructions. Obtain the adjusted address. */
7335 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7337 /* Targets that implement this adjustment function will likely
7338 inspect either the symbol table, target memory at BPADDR, or
7339 even state registers, so ensure a suitable thread (and its
7340 associated program space) are currently selected. */
7341 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
7342 switch_to_program_space_and_thread (pspace
);
7344 = gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7348 = gdbarch_remove_non_address_bits (gdbarch
, adjusted_bpaddr
);
7350 /* An adjusted breakpoint address can significantly alter
7351 a user's expectations. Print a warning if an adjustment
7353 if (adjusted_bpaddr
!= bpaddr
)
7354 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, false);
7356 return adjusted_bpaddr
;
7361 bp_location_from_bp_type (bptype type
)
7366 case bp_single_step
:
7370 case bp_longjmp_resume
:
7371 case bp_longjmp_call_dummy
:
7373 case bp_exception_resume
:
7374 case bp_step_resume
:
7375 case bp_hp_step_resume
:
7376 case bp_watchpoint_scope
:
7378 case bp_std_terminate
:
7379 case bp_shlib_event
:
7380 case bp_thread_event
:
7381 case bp_overlay_event
:
7383 case bp_longjmp_master
:
7384 case bp_std_terminate_master
:
7385 case bp_exception_master
:
7386 case bp_gnu_ifunc_resolver
:
7387 case bp_gnu_ifunc_resolver_return
:
7389 return bp_loc_software_breakpoint
;
7391 case bp_hardware_breakpoint
:
7392 return bp_loc_hardware_breakpoint
;
7394 case bp_hardware_watchpoint
:
7395 case bp_read_watchpoint
:
7396 case bp_access_watchpoint
:
7397 return bp_loc_hardware_watchpoint
;
7400 return bp_loc_software_watchpoint
;
7403 case bp_fast_tracepoint
:
7404 case bp_static_tracepoint
:
7405 case bp_static_marker_tracepoint
:
7406 return bp_loc_tracepoint
;
7409 return bp_loc_other
;
7412 internal_error (_("unknown breakpoint type"));
7416 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7418 this->owner
= owner
;
7419 this->cond_bytecode
= NULL
;
7420 this->shlib_disabled
= 0;
7422 this->disabled_by_cond
= false;
7424 this->loc_type
= type
;
7426 if (this->loc_type
== bp_loc_software_breakpoint
7427 || this->loc_type
== bp_loc_hardware_breakpoint
)
7428 mark_breakpoint_location_modified (this);
7433 bp_location::bp_location (breakpoint
*owner
)
7434 : bp_location::bp_location (owner
,
7435 bp_location_from_bp_type (owner
->type
))
7439 /* Decrement reference count. If the reference count reaches 0,
7440 destroy the bp_location. Sets *BLP to NULL. */
7443 decref_bp_location (struct bp_location
**blp
)
7445 bp_location_ref_policy::decref (*blp
);
7449 /* Add breakpoint B at the end of the global breakpoint chain. */
7452 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7454 struct breakpoint
*b1
;
7455 struct breakpoint
*result
= b
.get ();
7457 /* Add this breakpoint to the end of the chain so that a list of
7458 breakpoints will come out in order of increasing numbers. */
7460 b1
= breakpoint_chain
;
7462 breakpoint_chain
= b
.release ();
7467 b1
->next
= b
.release ();
7473 /* Initialize loc->function_name. */
7476 set_breakpoint_location_function (struct bp_location
*loc
)
7478 gdb_assert (loc
->owner
!= NULL
);
7480 if (loc
->owner
->type
== bp_breakpoint
7481 || loc
->owner
->type
== bp_hardware_breakpoint
7482 || is_tracepoint (loc
->owner
))
7484 const char *function_name
;
7486 if (loc
->msymbol
!= NULL
7487 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7488 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7490 struct breakpoint
*b
= loc
->owner
;
7492 function_name
= loc
->msymbol
->linkage_name ();
7494 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7495 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7497 /* Create only the whole new breakpoint of this type but do not
7498 mess more complicated breakpoints with multiple locations. */
7499 b
->type
= bp_gnu_ifunc_resolver
;
7500 /* Remember the resolver's address for use by the return
7502 loc
->related_address
= loc
->address
;
7506 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7509 loc
->function_name
= make_unique_xstrdup (function_name
);
7513 /* Attempt to determine architecture of location identified by SAL. */
7515 get_sal_arch (struct symtab_and_line sal
)
7518 return sal
.section
->objfile
->arch ();
7520 return sal
.symtab
->compunit ()->objfile ()->arch ();
7525 /* Call this routine when stepping and nexting to enable a breakpoint
7526 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7527 initiated the operation. */
7530 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7532 int thread
= tp
->global_num
;
7534 /* To avoid having to rescan all objfile symbols at every step,
7535 we maintain a list of continually-inserted but always disabled
7536 longjmp "master" breakpoints. Here, we simply create momentary
7537 clones of those and enable them for the requested thread. */
7538 for (breakpoint
*b
: all_breakpoints_safe ())
7539 if (b
->pspace
== current_program_space
7540 && (b
->type
== bp_longjmp_master
7541 || b
->type
== bp_exception_master
))
7543 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7544 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7545 after their removal. */
7546 momentary_breakpoint_from_master (b
, type
, 1, thread
);
7549 tp
->initiating_frame
= frame
;
7552 /* Delete all longjmp breakpoints from THREAD. */
7554 delete_longjmp_breakpoint (int thread
)
7556 for (breakpoint
*b
: all_breakpoints_safe ())
7557 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7559 if (b
->thread
== thread
)
7560 delete_breakpoint (b
);
7565 delete_longjmp_breakpoint_at_next_stop (int thread
)
7567 for (breakpoint
*b
: all_breakpoints_safe ())
7568 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7570 if (b
->thread
== thread
)
7571 b
->disposition
= disp_del_at_next_stop
;
7575 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7576 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7577 pointer to any of them. Return NULL if this system cannot place longjmp
7581 set_longjmp_breakpoint_for_call_dummy (void)
7583 breakpoint
*retval
= nullptr;
7585 for (breakpoint
*b
: all_breakpoints ())
7586 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7588 int thread
= inferior_thread ()->global_num
;
7590 = momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7593 /* Link NEW_B into the chain of RETVAL breakpoints. */
7595 gdb_assert (new_b
->related_breakpoint
== new_b
);
7598 new_b
->related_breakpoint
= retval
;
7599 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7600 retval
= retval
->related_breakpoint
;
7601 retval
->related_breakpoint
= new_b
;
7607 /* Verify all existing dummy frames and their associated breakpoints for
7608 TP. Remove those which can no longer be found in the current frame
7611 If the unwind fails then there is not sufficient information to discard
7612 dummy frames. In this case, elide the clean up and the dummy frames will
7613 be cleaned up next time this function is called from a location where
7614 unwinding is possible. */
7617 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7619 struct breakpoint
*b
, *b_tmp
;
7621 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7622 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7624 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7626 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7627 chained off b->related_breakpoint. */
7628 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7629 dummy_b
= dummy_b
->related_breakpoint
;
7631 /* If there was no bp_call_dummy breakpoint then there's nothing
7632 more to do. Or, if the dummy frame associated with the
7633 bp_call_dummy is still on the stack then we need to leave this
7634 bp_call_dummy in place. */
7635 if (dummy_b
->type
!= bp_call_dummy
7636 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7639 /* We didn't find the dummy frame on the stack, this could be
7640 because we have longjmp'd to a stack frame that is previous to
7641 the dummy frame, or it could be because the stack unwind is
7642 broken at some point between the longjmp frame and the dummy
7645 Next we figure out why the stack unwind stopped. If it looks
7646 like the unwind is complete then we assume the dummy frame has
7647 been jumped over, however, if the unwind stopped for an
7648 unexpected reason then we assume the stack unwind is currently
7649 broken, and that we will (eventually) return to the dummy
7652 It might be tempting to consider using frame_id_inner here, but
7653 that is not safe. There is no guarantee that the stack frames
7654 we are looking at here are even on the same stack as the
7655 original dummy frame, hence frame_id_inner can't be used. See
7656 the comments on frame_id_inner for more details. */
7657 bool unwind_finished_unexpectedly
= false;
7658 for (frame_info_ptr fi
= get_current_frame (); fi
!= nullptr; )
7660 frame_info_ptr prev
= get_prev_frame (fi
);
7661 if (prev
== nullptr)
7663 /* FI is the last stack frame. Why did this frame not
7665 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7666 if (stop_reason
!= UNWIND_NO_REASON
7667 && stop_reason
!= UNWIND_OUTERMOST
)
7668 unwind_finished_unexpectedly
= true;
7672 if (unwind_finished_unexpectedly
)
7675 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7677 while (b
->related_breakpoint
!= b
)
7679 if (b_tmp
== b
->related_breakpoint
)
7680 b_tmp
= b
->related_breakpoint
->next
;
7681 delete_breakpoint (b
->related_breakpoint
);
7683 delete_breakpoint (b
);
7688 enable_overlay_breakpoints (void)
7690 for (breakpoint
*b
: all_breakpoints ())
7691 if (b
->type
== bp_overlay_event
)
7693 b
->enable_state
= bp_enabled
;
7694 update_global_location_list (UGLL_MAY_INSERT
);
7695 overlay_events_enabled
= 1;
7700 disable_overlay_breakpoints (void)
7702 for (breakpoint
*b
: all_breakpoints ())
7703 if (b
->type
== bp_overlay_event
)
7705 b
->enable_state
= bp_disabled
;
7706 update_global_location_list (UGLL_DONT_INSERT
);
7707 overlay_events_enabled
= 0;
7711 /* Set an active std::terminate breakpoint for each std::terminate
7712 master breakpoint. */
7714 set_std_terminate_breakpoint (void)
7716 for (breakpoint
*b
: all_breakpoints_safe ())
7717 if (b
->pspace
== current_program_space
7718 && b
->type
== bp_std_terminate_master
)
7720 momentary_breakpoint_from_master (b
, bp_std_terminate
, 1,
7721 inferior_thread ()->global_num
);
7725 /* Delete all the std::terminate breakpoints. */
7727 delete_std_terminate_breakpoint (void)
7729 for (breakpoint
*b
: all_breakpoints_safe ())
7730 if (b
->type
== bp_std_terminate
)
7731 delete_breakpoint (b
);
7735 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7737 struct breakpoint
*b
;
7739 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7741 b
->enable_state
= bp_enabled
;
7742 /* locspec has to be used or breakpoint_re_set will delete me. */
7743 b
->locspec
= new_address_location_spec (b
->loc
->address
, NULL
, 0);
7745 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7750 struct lang_and_radix
7756 /* Create a breakpoint for JIT code registration and unregistration. */
7759 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7761 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7764 /* Remove JIT code registration and unregistration breakpoint(s). */
7767 remove_jit_event_breakpoints (void)
7769 for (breakpoint
*b
: all_breakpoints_safe ())
7770 if (b
->type
== bp_jit_event
7771 && b
->loc
->pspace
== current_program_space
)
7772 delete_breakpoint (b
);
7776 remove_solib_event_breakpoints (void)
7778 for (breakpoint
*b
: all_breakpoints_safe ())
7779 if (b
->type
== bp_shlib_event
7780 && b
->loc
->pspace
== current_program_space
)
7781 delete_breakpoint (b
);
7784 /* See breakpoint.h. */
7787 remove_solib_event_breakpoints_at_next_stop (void)
7789 for (breakpoint
*b
: all_breakpoints_safe ())
7790 if (b
->type
== bp_shlib_event
7791 && b
->loc
->pspace
== current_program_space
)
7792 b
->disposition
= disp_del_at_next_stop
;
7795 /* Helper for create_solib_event_breakpoint /
7796 create_and_insert_solib_event_breakpoint. Allows specifying which
7797 INSERT_MODE to pass through to update_global_location_list. */
7799 static struct breakpoint
*
7800 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7801 enum ugll_insert_mode insert_mode
)
7803 struct breakpoint
*b
;
7805 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
7806 update_global_location_list_nothrow (insert_mode
);
7811 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7813 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7816 /* See breakpoint.h. */
7819 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7821 struct breakpoint
*b
;
7823 /* Explicitly tell update_global_location_list to insert
7825 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7826 if (!b
->loc
->inserted
)
7828 delete_breakpoint (b
);
7834 /* Disable any breakpoints that are on code in shared libraries. Only
7835 apply to enabled breakpoints, disabled ones can just stay disabled. */
7838 disable_breakpoints_in_shlibs (void)
7840 for (bp_location
*loc
: all_bp_locations ())
7842 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7843 struct breakpoint
*b
= loc
->owner
;
7845 /* We apply the check to all breakpoints, including disabled for
7846 those with loc->duplicate set. This is so that when breakpoint
7847 becomes enabled, or the duplicate is removed, gdb will try to
7848 insert all breakpoints. If we don't set shlib_disabled here,
7849 we'll try to insert those breakpoints and fail. */
7850 if (((b
->type
== bp_breakpoint
)
7851 || (b
->type
== bp_jit_event
)
7852 || (b
->type
== bp_hardware_breakpoint
)
7853 || (is_tracepoint (b
)))
7854 && loc
->pspace
== current_program_space
7855 && !loc
->shlib_disabled
7856 && solib_name_from_address (loc
->pspace
, loc
->address
)
7859 loc
->shlib_disabled
= 1;
7864 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7865 notification of unloaded_shlib. Only apply to enabled breakpoints,
7866 disabled ones can just stay disabled. */
7869 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7871 bool disabled_shlib_breaks
= false;
7873 for (bp_location
*loc
: all_bp_locations ())
7875 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7876 struct breakpoint
*b
= loc
->owner
;
7878 if (solib
->pspace
== loc
->pspace
7879 && !loc
->shlib_disabled
7880 && (((b
->type
== bp_breakpoint
7881 || b
->type
== bp_jit_event
7882 || b
->type
== bp_hardware_breakpoint
)
7883 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7884 || loc
->loc_type
== bp_loc_software_breakpoint
))
7885 || is_tracepoint (b
))
7886 && solib_contains_address_p (solib
, loc
->address
))
7888 loc
->shlib_disabled
= 1;
7889 /* At this point, we cannot rely on remove_breakpoint
7890 succeeding so we must mark the breakpoint as not inserted
7891 to prevent future errors occurring in remove_breakpoints. */
7894 /* This may cause duplicate notifications for the same breakpoint. */
7895 gdb::observers::breakpoint_modified
.notify (b
);
7897 if (!disabled_shlib_breaks
)
7899 target_terminal::ours_for_output ();
7900 warning (_("Temporarily disabling breakpoints "
7901 "for unloaded shared library \"%s\""),
7904 disabled_shlib_breaks
= true;
7909 /* Disable any breakpoints and tracepoints in OBJFILE upon
7910 notification of free_objfile. Only apply to enabled breakpoints,
7911 disabled ones can just stay disabled. */
7914 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7916 if (objfile
== NULL
)
7919 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7920 managed by the user with add-symbol-file/remove-symbol-file.
7921 Similarly to how breakpoints in shared libraries are handled in
7922 response to "nosharedlibrary", mark breakpoints in such modules
7923 shlib_disabled so they end up uninserted on the next global
7924 location list update. Shared libraries not loaded by the user
7925 aren't handled here -- they're already handled in
7926 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7927 solib_unloaded observer. We skip objfiles that are not
7928 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7930 if ((objfile
->flags
& OBJF_SHARED
) == 0
7931 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7934 for (breakpoint
*b
: all_breakpoints ())
7936 bool bp_modified
= false;
7938 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7941 for (bp_location
*loc
: b
->locations ())
7943 CORE_ADDR loc_addr
= loc
->address
;
7945 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7946 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7949 if (loc
->shlib_disabled
!= 0)
7952 if (objfile
->pspace
!= loc
->pspace
)
7955 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7956 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7959 if (is_addr_in_objfile (loc_addr
, objfile
))
7961 loc
->shlib_disabled
= 1;
7962 /* At this point, we don't know whether the object was
7963 unmapped from the inferior or not, so leave the
7964 inserted flag alone. We'll handle failure to
7965 uninsert quietly, in case the object was indeed
7968 mark_breakpoint_location_modified (loc
);
7975 gdb::observers::breakpoint_modified
.notify (b
);
7979 /* See breakpoint.h. */
7981 breakpoint::breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
7982 bool temp
, const char *cond_string_
)
7984 disposition (temp
? disp_del
: disp_donttouch
),
7986 language (current_language
->la_language
),
7987 input_radix (::input_radix
),
7988 cond_string (cond_string_
!= nullptr
7989 ? make_unique_xstrdup (cond_string_
)
7991 related_breakpoint (this)
7995 /* See breakpoint.h. */
7997 catchpoint::catchpoint (struct gdbarch
*gdbarch
, bool temp
,
7998 const char *cond_string
)
7999 : breakpoint (gdbarch
, bp_catchpoint
, temp
, cond_string
)
8001 add_dummy_location (this, current_program_space
);
8003 pspace
= current_program_space
;
8007 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8009 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8010 set_breakpoint_number (internal
, b
);
8011 if (is_tracepoint (b
))
8012 set_tracepoint_count (breakpoint_count
);
8015 gdb::observers::breakpoint_created
.notify (b
);
8018 update_global_location_list (UGLL_MAY_INSERT
);
8024 hw_breakpoint_used_count (void)
8028 for (breakpoint
*b
: all_breakpoints ())
8029 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8030 for (bp_location
*bl
: b
->locations ())
8032 /* Special types of hardware breakpoints may use more than
8034 i
+= b
->resources_needed (bl
);
8040 /* Returns the resources B would use if it were a hardware
8044 hw_watchpoint_use_count (struct breakpoint
*b
)
8048 if (!breakpoint_enabled (b
))
8051 for (bp_location
*bl
: b
->locations ())
8053 /* Special types of hardware watchpoints may use more than
8055 i
+= b
->resources_needed (bl
);
8061 /* Returns the sum the used resources of all hardware watchpoints of
8062 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8063 the sum of the used resources of all hardware watchpoints of other
8064 types _not_ TYPE. */
8067 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8068 enum bptype type
, int *other_type_used
)
8072 *other_type_used
= 0;
8073 for (breakpoint
*b
: all_breakpoints ())
8077 if (!breakpoint_enabled (b
))
8080 if (b
->type
== type
)
8081 i
+= hw_watchpoint_use_count (b
);
8082 else if (is_hardware_watchpoint (b
))
8083 *other_type_used
= 1;
8090 disable_watchpoints_before_interactive_call_start (void)
8092 for (breakpoint
*b
: all_breakpoints ())
8093 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8095 b
->enable_state
= bp_call_disabled
;
8096 update_global_location_list (UGLL_DONT_INSERT
);
8101 enable_watchpoints_after_interactive_call_stop (void)
8103 for (breakpoint
*b
: all_breakpoints ())
8104 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8106 b
->enable_state
= bp_enabled
;
8107 update_global_location_list (UGLL_MAY_INSERT
);
8112 disable_breakpoints_before_startup (void)
8114 current_program_space
->executing_startup
= 1;
8115 update_global_location_list (UGLL_DONT_INSERT
);
8119 enable_breakpoints_after_startup (void)
8121 current_program_space
->executing_startup
= 0;
8122 breakpoint_re_set ();
8125 /* Allocate a new momentary breakpoint. */
8127 template<typename
... Arg
>
8128 static momentary_breakpoint
*
8129 new_momentary_breakpoint (struct gdbarch
*gdbarch
, enum bptype type
,
8132 if (type
== bp_longjmp
|| type
== bp_exception
)
8133 return new longjmp_breakpoint (gdbarch
, type
,
8134 std::forward
<Arg
> (args
)...);
8136 return new momentary_breakpoint (gdbarch
, type
,
8137 std::forward
<Arg
> (args
)...);
8140 /* Set a momentary breakpoint of type TYPE at address specified by
8141 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8145 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8146 struct frame_id frame_id
, enum bptype type
)
8148 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8150 gdb_assert (!frame_id_artificial_p (frame_id
));
8152 std::unique_ptr
<momentary_breakpoint
> b
8153 (new_momentary_breakpoint (gdbarch
, type
, sal
.pspace
, frame_id
,
8154 inferior_thread ()->global_num
));
8156 b
->add_location (sal
);
8158 breakpoint_up
bp (add_to_breakpoint_chain (std::move (b
)));
8160 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8165 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8166 The new breakpoint will have type TYPE, use OPS as its
8167 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8169 static struct breakpoint
*
8170 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8175 std::unique_ptr
<breakpoint
> copy
8176 (new_momentary_breakpoint (orig
->gdbarch
, type
, orig
->pspace
,
8177 orig
->frame_id
, thread
));
8178 copy
->loc
= copy
->allocate_location ();
8179 set_breakpoint_location_function (copy
->loc
);
8181 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8182 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8183 copy
->loc
->address
= orig
->loc
->address
;
8184 copy
->loc
->section
= orig
->loc
->section
;
8185 copy
->loc
->pspace
= orig
->loc
->pspace
;
8186 copy
->loc
->probe
= orig
->loc
->probe
;
8187 copy
->loc
->line_number
= orig
->loc
->line_number
;
8188 copy
->loc
->symtab
= orig
->loc
->symtab
;
8189 copy
->loc
->enabled
= loc_enabled
;
8191 breakpoint
*b
= add_to_breakpoint_chain (std::move (copy
));
8192 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8196 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8200 clone_momentary_breakpoint (struct breakpoint
*orig
)
8202 /* If there's nothing to clone, then return nothing. */
8206 return momentary_breakpoint_from_master (orig
, orig
->type
, 0,
8211 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8214 struct symtab_and_line sal
;
8216 sal
= find_pc_line (pc
, 0);
8218 sal
.section
= find_pc_overlay (pc
);
8219 sal
.explicit_pc
= 1;
8221 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8225 /* Tell the user we have just set a breakpoint B. */
8228 mention (const breakpoint
*b
)
8230 b
->print_mention ();
8231 current_uiout
->text ("\n");
8235 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8237 /* Handle "set breakpoint auto-hw on".
8239 If the explicitly specified breakpoint type is not hardware
8240 breakpoint, check the memory map to see whether the breakpoint
8241 address is in read-only memory.
8243 - location type is not hardware breakpoint, memory is read-only.
8244 We change the type of the location to hardware breakpoint.
8246 - location type is hardware breakpoint, memory is read-write. This
8247 means we've previously made the location hardware one, but then the
8248 memory map changed, so we undo.
8252 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8254 if (automatic_hardware_breakpoints
8255 && bl
->owner
->type
!= bp_hardware_breakpoint
8256 && (bl
->loc_type
== bp_loc_software_breakpoint
8257 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8259 /* When breakpoints are removed, remove_breakpoints will use
8260 location types we've just set here, the only possible problem
8261 is that memory map has changed during running program, but
8262 it's not going to work anyway with current gdb. */
8263 mem_region
*mr
= lookup_mem_region (bl
->address
);
8267 enum bp_loc_type new_type
;
8269 if (mr
->attrib
.mode
!= MEM_RW
)
8270 new_type
= bp_loc_hardware_breakpoint
;
8272 new_type
= bp_loc_software_breakpoint
;
8274 if (new_type
!= bl
->loc_type
)
8276 static bool said
= false;
8278 bl
->loc_type
= new_type
;
8281 gdb_printf (_("Note: automatically using "
8282 "hardware breakpoints for "
8283 "read-only addresses.\n"));
8292 code_breakpoint::add_location (const symtab_and_line
&sal
)
8294 struct bp_location
*new_loc
, **tmp
;
8295 CORE_ADDR adjusted_address
;
8296 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8298 if (loc_gdbarch
== NULL
)
8299 loc_gdbarch
= gdbarch
;
8301 /* Adjust the breakpoint's address prior to allocating a location.
8302 Once we call allocate_location(), that mostly uninitialized
8303 location will be placed on the location chain. Adjustment of the
8304 breakpoint may cause target_read_memory() to be called and we do
8305 not want its scan of the location chain to find a breakpoint and
8306 location that's only been partially initialized. */
8307 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8311 /* Sort the locations by their ADDRESS. */
8312 new_loc
= allocate_location ();
8313 for (tmp
= &(loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8314 tmp
= &((*tmp
)->next
))
8316 new_loc
->next
= *tmp
;
8319 new_loc
->requested_address
= sal
.pc
;
8320 new_loc
->address
= adjusted_address
;
8321 new_loc
->pspace
= sal
.pspace
;
8322 new_loc
->probe
.prob
= sal
.prob
;
8323 new_loc
->probe
.objfile
= sal
.objfile
;
8324 gdb_assert (new_loc
->pspace
!= NULL
);
8325 new_loc
->section
= sal
.section
;
8326 new_loc
->gdbarch
= loc_gdbarch
;
8327 new_loc
->line_number
= sal
.line
;
8328 new_loc
->symtab
= sal
.symtab
;
8329 new_loc
->symbol
= sal
.symbol
;
8330 new_loc
->msymbol
= sal
.msymbol
;
8331 new_loc
->objfile
= sal
.objfile
;
8333 set_breakpoint_location_function (new_loc
);
8335 /* While by definition, permanent breakpoints are already present in the
8336 code, we don't mark the location as inserted. Normally one would expect
8337 that GDB could rely on that breakpoint instruction to stop the program,
8338 thus removing the need to insert its own breakpoint, except that executing
8339 the breakpoint instruction can kill the target instead of reporting a
8340 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8341 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8342 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8343 breakpoint be inserted normally results in QEMU knowing about the GDB
8344 breakpoint, and thus trap before the breakpoint instruction is executed.
8345 (If GDB later needs to continue execution past the permanent breakpoint,
8346 it manually increments the PC, thus avoiding executing the breakpoint
8348 if (bp_loc_is_permanent (new_loc
))
8349 new_loc
->permanent
= 1;
8355 /* Return true if LOC is pointing to a permanent breakpoint,
8356 return false otherwise. */
8359 bp_loc_is_permanent (struct bp_location
*loc
)
8361 gdb_assert (loc
!= NULL
);
8363 /* If we have a non-breakpoint-backed catchpoint or a software
8364 watchpoint, just return 0. We should not attempt to read from
8365 the addresses the locations of these breakpoint types point to.
8366 gdbarch_program_breakpoint_here_p, below, will attempt to read
8368 if (!bl_address_is_meaningful (loc
))
8371 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8372 switch_to_program_space_and_thread (loc
->pspace
);
8373 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8376 /* Build a command list for the dprintf corresponding to the current
8377 settings of the dprintf style options. */
8380 update_dprintf_command_list (struct breakpoint
*b
)
8382 const char *dprintf_args
= b
->extra_string
.get ();
8383 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8388 dprintf_args
= skip_spaces (dprintf_args
);
8390 /* Allow a comma, as it may have terminated a location, but don't
8392 if (*dprintf_args
== ',')
8394 dprintf_args
= skip_spaces (dprintf_args
);
8396 if (*dprintf_args
!= '"')
8397 error (_("Bad format string, missing '\"'."));
8399 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8400 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8401 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8403 if (dprintf_function
.empty ())
8404 error (_("No function supplied for dprintf call"));
8406 if (!dprintf_channel
.empty ())
8407 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8408 dprintf_function
.c_str (),
8409 dprintf_channel
.c_str (),
8412 printf_line
= xstrprintf ("call (void) %s (%s)",
8413 dprintf_function
.c_str (),
8416 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8418 if (target_can_run_breakpoint_commands ())
8419 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8422 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8423 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8427 internal_error (_("Invalid dprintf style."));
8429 gdb_assert (printf_line
!= NULL
);
8431 /* Manufacture a printf sequence. */
8432 struct command_line
*printf_cmd_line
8433 = new struct command_line (simple_control
, printf_line
.release ());
8434 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8435 command_lines_deleter ()));
8438 /* Update all dprintf commands, making their command lists reflect
8439 current style settings. */
8442 update_dprintf_commands (const char *args
, int from_tty
,
8443 struct cmd_list_element
*c
)
8445 for (breakpoint
*b
: all_breakpoints ())
8446 if (b
->type
== bp_dprintf
)
8447 update_dprintf_command_list (b
);
8450 code_breakpoint::code_breakpoint (struct gdbarch
*gdbarch_
,
8452 gdb::array_view
<const symtab_and_line
> sals
,
8453 location_spec_up
&&locspec_
,
8454 gdb::unique_xmalloc_ptr
<char> filter_
,
8455 gdb::unique_xmalloc_ptr
<char> cond_string_
,
8456 gdb::unique_xmalloc_ptr
<char> extra_string_
,
8457 enum bpdisp disposition_
,
8458 int thread_
, int task_
, int ignore_count_
,
8460 int enabled_
, unsigned flags
,
8461 int display_canonical_
)
8462 : breakpoint (gdbarch_
, type_
)
8466 if (type
== bp_hardware_breakpoint
)
8468 int target_resources_ok
;
8470 i
= hw_breakpoint_used_count ();
8471 target_resources_ok
=
8472 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8474 if (target_resources_ok
== 0)
8475 error (_("No hardware breakpoint support in the target."));
8476 else if (target_resources_ok
< 0)
8477 error (_("Hardware breakpoints used exceeds limit."));
8480 gdb_assert (!sals
.empty ());
8482 /* At most one of thread or task can be set on any breakpoint. */
8483 gdb_assert (thread
== -1 || task
== -1);
8487 cond_string
= std::move (cond_string_
);
8488 extra_string
= std::move (extra_string_
);
8489 ignore_count
= ignore_count_
;
8490 enable_state
= enabled_
? bp_enabled
: bp_disabled
;
8491 disposition
= disposition_
;
8493 if (type
== bp_static_tracepoint
8494 || type
== bp_static_marker_tracepoint
)
8496 auto *t
= gdb::checked_static_cast
<struct tracepoint
*> (this);
8497 struct static_tracepoint_marker marker
;
8499 if (strace_marker_p (this))
8501 /* We already know the marker exists, otherwise, we wouldn't
8502 see a sal for it. */
8503 const char *p
= &locspec_
->to_string ()[3];
8506 p
= skip_spaces (p
);
8508 endp
= skip_to_space (p
);
8510 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8512 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8513 t
->static_trace_marker_id
.c_str ());
8515 else if (target_static_tracepoint_marker_at (sals
[0].pc
, &marker
))
8517 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8519 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8520 t
->static_trace_marker_id
.c_str ());
8523 warning (_("Couldn't determine the static tracepoint marker to probe"));
8526 for (const auto &sal
: sals
)
8530 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8531 if (loc_gdbarch
== nullptr)
8532 loc_gdbarch
= gdbarch
;
8534 describe_other_breakpoints (loc_gdbarch
,
8535 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8538 bp_location
*new_loc
= add_location (sal
);
8539 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8540 new_loc
->inserted
= 1;
8542 /* Do not set breakpoint locations conditions yet. As locations
8543 are inserted, they get sorted based on their addresses. Let
8544 the list stabilize to have reliable location numbers. */
8546 /* Dynamic printf requires and uses additional arguments on the
8547 command line, otherwise it's an error. */
8548 if (type
== bp_dprintf
)
8550 if (extra_string
!= nullptr)
8551 update_dprintf_command_list (this);
8553 error (_("Format string required"));
8555 else if (extra_string
!= nullptr)
8556 error (_("Garbage '%s' at end of command"), extra_string
.get ());
8559 /* The order of the locations is now stable. Set the location
8560 condition using the location's number. */
8562 for (bp_location
*bl
: locations ())
8564 if (cond_string
!= nullptr)
8565 set_breakpoint_location_condition (cond_string
.get (), bl
,
8571 display_canonical
= display_canonical_
;
8572 if (locspec_
!= nullptr)
8573 locspec
= std::move (locspec_
);
8575 locspec
= new_address_location_spec (this->loc
->address
, NULL
, 0);
8576 filter
= std::move (filter_
);
8580 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8581 gdb::array_view
<const symtab_and_line
> sals
,
8582 location_spec_up
&&locspec
,
8583 gdb::unique_xmalloc_ptr
<char> filter
,
8584 gdb::unique_xmalloc_ptr
<char> cond_string
,
8585 gdb::unique_xmalloc_ptr
<char> extra_string
,
8586 enum bptype type
, enum bpdisp disposition
,
8587 int thread
, int task
, int ignore_count
,
8589 int enabled
, int internal
, unsigned flags
,
8590 int display_canonical
)
8592 std::unique_ptr
<code_breakpoint
> b
8593 = new_breakpoint_from_type (gdbarch
,
8596 std::move (locspec
),
8598 std::move (cond_string
),
8599 std::move (extra_string
),
8601 thread
, task
, ignore_count
,
8606 install_breakpoint (internal
, std::move (b
), 0);
8609 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8610 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8611 value. COND_STRING, if not NULL, specified the condition to be
8612 used for all breakpoints. Essentially the only case where
8613 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8614 function. In that case, it's still not possible to specify
8615 separate conditions for different overloaded functions, so
8616 we take just a single condition string.
8618 NOTE: If the function succeeds, the caller is expected to cleanup
8619 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8620 array contents). If the function fails (error() is called), the
8621 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8622 COND and SALS arrays and each of those arrays contents. */
8625 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8626 struct linespec_result
*canonical
,
8627 gdb::unique_xmalloc_ptr
<char> cond_string
,
8628 gdb::unique_xmalloc_ptr
<char> extra_string
,
8629 enum bptype type
, enum bpdisp disposition
,
8630 int thread
, int task
, int ignore_count
,
8632 int enabled
, int internal
, unsigned flags
)
8634 if (canonical
->pre_expanded
)
8635 gdb_assert (canonical
->lsals
.size () == 1);
8637 for (const auto &lsal
: canonical
->lsals
)
8639 /* Note that 'location' can be NULL in the case of a plain
8640 'break', without arguments. */
8641 location_spec_up locspec
8642 = (canonical
->locspec
!= nullptr
8643 ? canonical
->locspec
->clone ()
8645 gdb::unique_xmalloc_ptr
<char> filter_string
8646 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8648 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8649 std::move (locspec
),
8650 std::move (filter_string
),
8651 std::move (cond_string
),
8652 std::move (extra_string
),
8654 thread
, task
, ignore_count
,
8655 from_tty
, enabled
, internal
, flags
,
8656 canonical
->special_display
);
8660 /* Parse LOCSPEC which is assumed to be a SAL specification possibly
8661 followed by conditionals. On return, SALS contains an array of SAL
8662 addresses found. LOCSPEC points to the end of the SAL (for
8665 The array and the line spec strings are allocated on the heap, it is
8666 the caller's responsibility to free them. */
8669 parse_breakpoint_sals (location_spec
*locspec
,
8670 struct linespec_result
*canonical
)
8672 struct symtab_and_line cursal
;
8674 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8676 const char *spec
= as_linespec_location_spec (locspec
)->spec_string
;
8680 /* The last displayed codepoint, if it's valid, is our default
8681 breakpoint address. */
8682 if (last_displayed_sal_is_valid ())
8684 /* Set sal's pspace, pc, symtab, and line to the values
8685 corresponding to the last call to print_frame_info.
8686 Be sure to reinitialize LINE with NOTCURRENT == 0
8687 as the breakpoint line number is inappropriate otherwise.
8688 find_pc_line would adjust PC, re-set it back. */
8689 symtab_and_line sal
= get_last_displayed_sal ();
8690 CORE_ADDR pc
= sal
.pc
;
8692 sal
= find_pc_line (pc
, 0);
8694 /* "break" without arguments is equivalent to "break *PC"
8695 where PC is the last displayed codepoint's address. So
8696 make sure to set sal.explicit_pc to prevent GDB from
8697 trying to expand the list of sals to include all other
8698 instances with the same symtab and line. */
8700 sal
.explicit_pc
= 1;
8702 struct linespec_sals lsal
;
8704 lsal
.canonical
= NULL
;
8706 canonical
->lsals
.push_back (std::move (lsal
));
8710 error (_("No default breakpoint address now."));
8714 /* Force almost all breakpoints to be in terms of the
8715 current_source_symtab (which is decode_line_1's default).
8716 This should produce the results we want almost all of the
8717 time while leaving default_breakpoint_* alone.
8719 ObjC: However, don't match an Objective-C method name which
8720 may have a '+' or '-' succeeded by a '['. */
8721 cursal
= get_current_source_symtab_and_line ();
8722 if (last_displayed_sal_is_valid ())
8724 const char *spec
= NULL
;
8726 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8727 spec
= as_linespec_location_spec (locspec
)->spec_string
;
8731 && strchr ("+-", spec
[0]) != NULL
8734 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8735 get_last_displayed_symtab (),
8736 get_last_displayed_line (),
8737 canonical
, NULL
, NULL
);
8742 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8743 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8747 /* Convert each SAL into a real PC. Verify that the PC can be
8748 inserted as a breakpoint. If it can't throw an error. */
8751 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8753 for (auto &sal
: sals
)
8754 resolve_sal_pc (&sal
);
8757 /* Fast tracepoints may have restrictions on valid locations. For
8758 instance, a fast tracepoint using a jump instead of a trap will
8759 likely have to overwrite more bytes than a trap would, and so can
8760 only be placed where the instruction is longer than the jump, or a
8761 multi-instruction sequence does not have a jump into the middle of
8765 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8766 gdb::array_view
<const symtab_and_line
> sals
)
8768 for (const auto &sal
: sals
)
8770 struct gdbarch
*sarch
;
8772 sarch
= get_sal_arch (sal
);
8773 /* We fall back to GDBARCH if there is no architecture
8774 associated with SAL. */
8778 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8779 error (_("May not have a fast tracepoint at %s%s"),
8780 paddress (sarch
, sal
.pc
), msg
.c_str ());
8784 /* Given TOK, a string specification of condition and thread, as
8785 accepted by the 'break' command, extract the condition
8786 string and thread number and set *COND_STRING and *THREAD.
8787 PC identifies the context at which the condition should be parsed.
8788 If no condition is found, *COND_STRING is set to NULL.
8789 If no thread is found, *THREAD is set to -1. */
8792 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8793 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8794 int *thread
, int *task
,
8795 gdb::unique_xmalloc_ptr
<char> *rest
)
8797 cond_string
->reset ();
8805 const char *end_tok
;
8807 const char *cond_start
= NULL
;
8808 const char *cond_end
= NULL
;
8810 tok
= skip_spaces (tok
);
8812 if ((*tok
== '"' || *tok
== ',') && rest
)
8814 rest
->reset (savestring (tok
, strlen (tok
)));
8818 end_tok
= skip_to_space (tok
);
8820 toklen
= end_tok
- tok
;
8822 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8824 tok
= cond_start
= end_tok
+ 1;
8827 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8829 catch (const gdb_exception_error
&)
8834 tok
= tok
+ strlen (tok
);
8837 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8839 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8844 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8847 struct thread_info
*thr
;
8850 error(_("You can specify only one thread."));
8853 error (_("You can specify only one of thread or task."));
8856 thr
= parse_thread_id (tok
, &tmptok
);
8858 error (_("Junk after thread keyword."));
8859 *thread
= thr
->global_num
;
8862 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8867 error(_("You can specify only one task."));
8870 error (_("You can specify only one of thread or task."));
8873 *task
= strtol (tok
, &tmptok
, 0);
8875 error (_("Junk after task keyword."));
8876 if (!valid_task_id (*task
))
8877 error (_("Unknown task %d."), *task
);
8882 rest
->reset (savestring (tok
, strlen (tok
)));
8886 error (_("Junk at end of arguments."));
8890 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8891 succeeds. The parsed values are written to COND_STRING, THREAD,
8892 TASK, and REST. See the comment of 'find_condition_and_thread'
8893 for the description of these parameters and INPUT. */
8896 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8898 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8899 int *thread
, int *task
,
8900 gdb::unique_xmalloc_ptr
<char> *rest
)
8902 int num_failures
= 0;
8903 for (auto &sal
: sals
)
8905 gdb::unique_xmalloc_ptr
<char> cond
;
8908 gdb::unique_xmalloc_ptr
<char> remaining
;
8910 /* Here we want to parse 'arg' to separate condition from thread
8911 number. But because parsing happens in a context and the
8912 contexts of sals might be different, try each until there is
8913 success. Finding one successful parse is sufficient for our
8914 goal. When setting the breakpoint we'll re-parse the
8915 condition in the context of each sal. */
8918 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8919 &task_id
, &remaining
);
8920 *cond_string
= std::move (cond
);
8921 /* At most one of thread or task can be set. */
8922 gdb_assert (thread_id
== -1 || task_id
== -1);
8923 *thread
= thread_id
;
8925 *rest
= std::move (remaining
);
8928 catch (const gdb_exception_error
&e
)
8931 /* If no sal remains, do not continue. */
8932 if (num_failures
== sals
.size ())
8938 /* Decode a static tracepoint marker spec. */
8940 static std::vector
<symtab_and_line
>
8941 decode_static_tracepoint_spec (const char **arg_p
)
8943 const char *p
= &(*arg_p
)[3];
8946 p
= skip_spaces (p
);
8948 endp
= skip_to_space (p
);
8950 std::string
marker_str (p
, endp
- p
);
8952 std::vector
<static_tracepoint_marker
> markers
8953 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8954 if (markers
.empty ())
8955 error (_("No known static tracepoint marker named %s"),
8956 marker_str
.c_str ());
8958 std::vector
<symtab_and_line
> sals
;
8959 sals
.reserve (markers
.size ());
8961 for (const static_tracepoint_marker
&marker
: markers
)
8963 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8964 sal
.pc
= marker
.address
;
8965 sals
.push_back (sal
);
8972 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8973 according to IS_TRACEPOINT. */
8975 static const struct breakpoint_ops
*
8976 breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type
,
8981 if (locspec_type
== PROBE_LOCATION_SPEC
)
8982 return &tracepoint_probe_breakpoint_ops
;
8984 return &code_breakpoint_ops
;
8988 if (locspec_type
== PROBE_LOCATION_SPEC
)
8989 return &bkpt_probe_breakpoint_ops
;
8991 return &code_breakpoint_ops
;
8995 /* See breakpoint.h. */
8997 const struct breakpoint_ops
*
8998 breakpoint_ops_for_location_spec (const location_spec
*locspec
,
9001 if (locspec
!= nullptr)
9002 return (breakpoint_ops_for_location_spec_type
9003 (locspec
->type (), is_tracepoint
));
9004 return &code_breakpoint_ops
;
9007 /* See breakpoint.h. */
9010 create_breakpoint (struct gdbarch
*gdbarch
,
9011 location_spec
*locspec
,
9012 const char *cond_string
,
9013 int thread
, const char *extra_string
,
9014 bool force_condition
, int parse_extra
,
9015 int tempflag
, enum bptype type_wanted
,
9017 enum auto_boolean pending_break_support
,
9018 const struct breakpoint_ops
*ops
,
9019 int from_tty
, int enabled
, int internal
,
9022 struct linespec_result canonical
;
9023 bool pending
= false;
9025 int prev_bkpt_count
= breakpoint_count
;
9027 gdb_assert (ops
!= NULL
);
9029 /* If extra_string isn't useful, set it to NULL. */
9030 if (extra_string
!= NULL
&& *extra_string
== '\0')
9031 extra_string
= NULL
;
9035 ops
->create_sals_from_location_spec (locspec
, &canonical
);
9037 catch (const gdb_exception_error
&e
)
9039 /* If caller is interested in rc value from parse, set
9041 if (e
.error
== NOT_FOUND_ERROR
)
9043 /* If pending breakpoint support is turned off, throw
9046 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9049 exception_print (gdb_stderr
, e
);
9051 /* If pending breakpoint support is auto query and the user
9052 selects no, then simply return the error code. */
9053 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9054 && !nquery (_("Make %s pending on future shared library load? "),
9055 bptype_string (type_wanted
)))
9058 /* At this point, either the user was queried about setting
9059 a pending breakpoint and selected yes, or pending
9060 breakpoint behavior is on and thus a pending breakpoint
9061 is defaulted on behalf of the user. */
9068 if (!pending
&& canonical
.lsals
.empty ())
9071 /* Resolve all line numbers to PC's and verify that the addresses
9072 are ok for the target. */
9075 for (auto &lsal
: canonical
.lsals
)
9076 breakpoint_sals_to_pc (lsal
.sals
);
9079 /* Fast tracepoints may have additional restrictions on location. */
9080 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9082 for (const auto &lsal
: canonical
.lsals
)
9083 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9086 /* Verify that condition can be parsed, before setting any
9087 breakpoints. Allocate a separate condition expression for each
9091 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9092 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9096 gdb::unique_xmalloc_ptr
<char> rest
;
9097 gdb::unique_xmalloc_ptr
<char> cond
;
9099 const linespec_sals
&lsal
= canonical
.lsals
[0];
9101 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9102 &cond
, &thread
, &task
, &rest
);
9103 cond_string_copy
= std::move (cond
);
9104 extra_string_copy
= std::move (rest
);
9108 if (type_wanted
!= bp_dprintf
9109 && extra_string
!= NULL
&& *extra_string
!= '\0')
9110 error (_("Garbage '%s' at end of location"), extra_string
);
9112 /* Check the validity of the condition. We should error out
9113 if the condition is invalid at all of the locations and
9114 if it is not forced. In the PARSE_EXTRA case above, this
9115 check is done when parsing the EXTRA_STRING. */
9116 if (cond_string
!= nullptr && !force_condition
)
9118 int num_failures
= 0;
9119 const linespec_sals
&lsal
= canonical
.lsals
[0];
9120 for (const auto &sal
: lsal
.sals
)
9122 const char *cond
= cond_string
;
9125 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9126 /* One success is sufficient to keep going. */
9129 catch (const gdb_exception_error
&)
9132 /* If this is the last sal, error out. */
9133 if (num_failures
== lsal
.sals
.size ())
9139 /* Create a private copy of condition string. */
9141 cond_string_copy
.reset (xstrdup (cond_string
));
9142 /* Create a private copy of any extra string. */
9144 extra_string_copy
.reset (xstrdup (extra_string
));
9147 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9148 std::move (cond_string_copy
),
9149 std::move (extra_string_copy
),
9151 tempflag
? disp_del
: disp_donttouch
,
9152 thread
, task
, ignore_count
,
9153 from_tty
, enabled
, internal
, flags
);
9157 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
,
9159 b
->locspec
= locspec
->clone ();
9162 b
->cond_string
= NULL
;
9165 /* Create a private copy of condition string. */
9166 b
->cond_string
.reset (cond_string
!= NULL
9167 ? xstrdup (cond_string
)
9172 /* Create a private copy of any extra string. */
9173 b
->extra_string
.reset (extra_string
!= NULL
9174 ? xstrdup (extra_string
)
9176 b
->ignore_count
= ignore_count
;
9177 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9178 b
->condition_not_parsed
= 1;
9179 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9180 if ((type_wanted
!= bp_breakpoint
9181 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9182 b
->pspace
= current_program_space
;
9184 install_breakpoint (internal
, std::move (b
), 0);
9187 if (canonical
.lsals
.size () > 1)
9189 warning (_("Multiple breakpoints were set.\nUse the "
9190 "\"delete\" command to delete unwanted breakpoints."));
9191 prev_breakpoint_count
= prev_bkpt_count
;
9194 update_global_location_list (UGLL_MAY_INSERT
);
9199 /* Set a breakpoint.
9200 ARG is a string describing breakpoint address,
9201 condition, and thread.
9202 FLAG specifies if a breakpoint is hardware on,
9203 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9207 break_command_1 (const char *arg
, int flag
, int from_tty
)
9209 int tempflag
= flag
& BP_TEMPFLAG
;
9210 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9211 ? bp_hardware_breakpoint
9214 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9215 const struct breakpoint_ops
*ops
9216 = breakpoint_ops_for_location_spec (locspec
.get (),
9217 false /* is_tracepoint */);
9219 create_breakpoint (get_current_arch (),
9221 NULL
, 0, arg
, false, 1 /* parse arg */,
9222 tempflag
, type_wanted
,
9223 0 /* Ignore count */,
9224 pending_break_support
,
9232 /* Helper function for break_command_1 and disassemble_command. */
9235 resolve_sal_pc (struct symtab_and_line
*sal
)
9239 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9241 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9242 error (_("No line %d in file \"%s\"."),
9243 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9246 /* If this SAL corresponds to a breakpoint inserted using a line
9247 number, then skip the function prologue if necessary. */
9248 if (sal
->explicit_line
)
9249 skip_prologue_sal (sal
);
9252 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9254 const struct blockvector
*bv
;
9255 const struct block
*b
;
9258 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9259 sal
->symtab
->compunit ());
9262 sym
= b
->linkage_function ();
9265 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9268 /* It really is worthwhile to have the section, so we'll
9269 just have to look harder. This case can be executed
9270 if we have line numbers but no functions (as can
9271 happen in assembly source). */
9273 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9274 switch_to_program_space_and_thread (sal
->pspace
);
9276 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9278 sal
->section
= msym
.obj_section ();
9285 break_command (const char *arg
, int from_tty
)
9287 break_command_1 (arg
, 0, from_tty
);
9291 tbreak_command (const char *arg
, int from_tty
)
9293 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9297 hbreak_command (const char *arg
, int from_tty
)
9299 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9303 thbreak_command (const char *arg
, int from_tty
)
9305 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9308 /* The dynamic printf command is mostly like a regular breakpoint, but
9309 with a prewired command list consisting of a single output command,
9310 built from extra arguments supplied on the dprintf command
9314 dprintf_command (const char *arg
, int from_tty
)
9316 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9318 /* If non-NULL, ARG should have been advanced past the location;
9319 the next character must be ','. */
9322 if (arg
[0] != ',' || arg
[1] == '\0')
9323 error (_("Format string required"));
9326 /* Skip the comma. */
9331 create_breakpoint (get_current_arch (),
9333 NULL
, 0, arg
, false, 1 /* parse arg */,
9335 0 /* Ignore count */,
9336 pending_break_support
,
9337 &code_breakpoint_ops
,
9345 agent_printf_command (const char *arg
, int from_tty
)
9347 error (_("May only run agent-printf on the target"));
9350 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9353 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9354 const address_space
*aspace
,
9356 const target_waitstatus
&ws
)
9358 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9359 || ws
.sig () != GDB_SIGNAL_TRAP
)
9362 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9363 bl
->length
, aspace
, bp_addr
);
9366 /* Implement the "resources_needed" method for ranged breakpoints. */
9369 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9371 return target_ranged_break_num_registers ();
9374 /* Implement the "print_it" method for ranged breakpoints. */
9376 enum print_stop_action
9377 ranged_breakpoint::print_it (const bpstat
*bs
) const
9379 struct bp_location
*bl
= loc
;
9380 struct ui_out
*uiout
= current_uiout
;
9382 gdb_assert (type
== bp_hardware_breakpoint
);
9384 /* Ranged breakpoints have only one location. */
9385 gdb_assert (bl
&& bl
->next
== NULL
);
9387 annotate_breakpoint (number
);
9389 maybe_print_thread_hit_breakpoint (uiout
);
9391 if (disposition
== disp_del
)
9392 uiout
->text ("Temporary ranged breakpoint ");
9394 uiout
->text ("Ranged breakpoint ");
9395 if (uiout
->is_mi_like_p ())
9397 uiout
->field_string ("reason",
9398 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9399 uiout
->field_string ("disp", bpdisp_text (disposition
));
9401 print_num_locno (bs
, uiout
);
9404 return PRINT_SRC_AND_LOC
;
9407 /* Implement the "print_one" method for ranged breakpoints. */
9410 ranged_breakpoint::print_one (bp_location
**last_loc
) const
9412 struct bp_location
*bl
= loc
;
9413 struct value_print_options opts
;
9414 struct ui_out
*uiout
= current_uiout
;
9416 /* Ranged breakpoints have only one location. */
9417 gdb_assert (bl
&& bl
->next
== NULL
);
9419 get_user_print_options (&opts
);
9421 if (opts
.addressprint
)
9422 /* We don't print the address range here, it will be printed later
9423 by ranged_breakpoint::print_one_detail. */
9424 uiout
->field_skip ("addr");
9426 print_breakpoint_location (this, bl
);
9432 /* Implement the "print_one_detail" method for ranged breakpoints. */
9435 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9437 CORE_ADDR address_start
, address_end
;
9438 struct bp_location
*bl
= loc
;
9443 address_start
= bl
->address
;
9444 address_end
= address_start
+ bl
->length
- 1;
9446 uiout
->text ("\taddress range: ");
9447 stb
.printf ("[%s, %s]",
9448 print_core_address (bl
->gdbarch
, address_start
),
9449 print_core_address (bl
->gdbarch
, address_end
));
9450 uiout
->field_stream ("addr", stb
);
9454 /* Implement the "print_mention" method for ranged breakpoints. */
9457 ranged_breakpoint::print_mention () const
9459 struct bp_location
*bl
= loc
;
9460 struct ui_out
*uiout
= current_uiout
;
9463 gdb_assert (type
== bp_hardware_breakpoint
);
9465 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9466 number
, paddress (bl
->gdbarch
, bl
->address
),
9467 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9470 /* Implement the "print_recreate" method for ranged breakpoints. */
9473 ranged_breakpoint::print_recreate (struct ui_file
*fp
) const
9475 gdb_printf (fp
, "break-range %s, %s",
9476 locspec
->to_string (),
9477 locspec_range_end
->to_string ());
9478 print_recreate_thread (fp
);
9481 /* Find the address where the end of the breakpoint range should be
9482 placed, given the SAL of the end of the range. This is so that if
9483 the user provides a line number, the end of the range is set to the
9484 last instruction of the given line. */
9487 find_breakpoint_range_end (struct symtab_and_line sal
)
9491 /* If the user provided a PC value, use it. Otherwise,
9492 find the address of the end of the given location. */
9493 if (sal
.explicit_pc
)
9500 ret
= find_line_pc_range (sal
, &start
, &end
);
9502 error (_("Could not find location of the end of the range."));
9504 /* find_line_pc_range returns the start of the next line. */
9511 /* Implement the "break-range" CLI command. */
9514 break_range_command (const char *arg
, int from_tty
)
9516 const char *arg_start
;
9517 struct linespec_result canonical_start
, canonical_end
;
9518 int bp_count
, can_use_bp
, length
;
9521 /* We don't support software ranged breakpoints. */
9522 if (target_ranged_break_num_registers () < 0)
9523 error (_("This target does not support hardware ranged breakpoints."));
9525 bp_count
= hw_breakpoint_used_count ();
9526 bp_count
+= target_ranged_break_num_registers ();
9527 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9530 error (_("Hardware breakpoints used exceeds limit."));
9532 arg
= skip_spaces (arg
);
9533 if (arg
== NULL
|| arg
[0] == '\0')
9534 error(_("No address range specified."));
9537 location_spec_up start_locspec
9538 = string_to_location_spec (&arg
, current_language
);
9539 parse_breakpoint_sals (start_locspec
.get (), &canonical_start
);
9542 error (_("Too few arguments."));
9543 else if (canonical_start
.lsals
.empty ())
9544 error (_("Could not find location of the beginning of the range."));
9546 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9548 if (canonical_start
.lsals
.size () > 1
9549 || lsal_start
.sals
.size () != 1)
9550 error (_("Cannot create a ranged breakpoint with multiple locations."));
9552 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9553 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9555 arg
++; /* Skip the comma. */
9556 arg
= skip_spaces (arg
);
9558 /* Parse the end location specification. */
9562 /* We call decode_line_full directly here instead of using
9563 parse_breakpoint_sals because we need to specify the start
9564 location spec's symtab and line as the default symtab and line
9565 for the end of the range. This makes it possible to have ranges
9566 like "foo.c:27, +14", where +14 means 14 lines from the start
9568 location_spec_up end_locspec
9569 = string_to_location_spec (&arg
, current_language
);
9570 decode_line_full (end_locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9571 sal_start
.symtab
, sal_start
.line
,
9572 &canonical_end
, NULL
, NULL
);
9574 if (canonical_end
.lsals
.empty ())
9575 error (_("Could not find location of the end of the range."));
9577 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9578 if (canonical_end
.lsals
.size () > 1
9579 || lsal_end
.sals
.size () != 1)
9580 error (_("Cannot create a ranged breakpoint with multiple locations."));
9582 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9584 end
= find_breakpoint_range_end (sal_end
);
9585 if (sal_start
.pc
> end
)
9586 error (_("Invalid address range, end precedes start."));
9588 length
= end
- sal_start
.pc
+ 1;
9590 /* Length overflowed. */
9591 error (_("Address range too large."));
9592 else if (length
== 1)
9594 /* This range is simple enough to be handled by
9595 the `hbreak' command. */
9596 hbreak_command (&addr_string_start
[0], 1);
9601 /* Now set up the breakpoint and install it. */
9603 std::unique_ptr
<breakpoint
> br
9604 (new ranged_breakpoint (get_current_arch (),
9606 std::move (start_locspec
),
9607 std::move (end_locspec
)));
9609 install_breakpoint (false, std::move (br
), true);
9612 /* Return non-zero if EXP is verified as constant. Returned zero
9613 means EXP is variable. Also the constant detection may fail for
9614 some constant expressions and in such case still falsely return
9618 watchpoint_exp_is_const (const struct expression
*exp
)
9620 return exp
->op
->constant_p ();
9623 /* Implement the "re_set" method for watchpoints. */
9626 watchpoint::re_set ()
9628 /* Watchpoint can be either on expression using entirely global
9629 variables, or it can be on local variables.
9631 Watchpoints of the first kind are never auto-deleted, and even
9632 persist across program restarts. Since they can use variables
9633 from shared libraries, we need to reparse expression as libraries
9634 are loaded and unloaded.
9636 Watchpoints on local variables can also change meaning as result
9637 of solib event. For example, if a watchpoint uses both a local
9638 and a global variables in expression, it's a local watchpoint,
9639 but unloading of a shared library will make the expression
9640 invalid. This is not a very common use case, but we still
9641 re-evaluate expression, to avoid surprises to the user.
9643 Note that for local watchpoints, we re-evaluate it only if
9644 watchpoints frame id is still valid. If it's not, it means the
9645 watchpoint is out of scope and will be deleted soon. In fact,
9646 I'm not sure we'll ever be called in this case.
9648 If a local watchpoint's frame id is still valid, then
9649 exp_valid_block is likewise valid, and we can safely use it.
9651 Don't do anything about disabled watchpoints, since they will be
9652 reevaluated again when enabled. */
9653 update_watchpoint (this, true /* reparse */);
9656 /* Implement the "insert" method for hardware watchpoints. */
9659 watchpoint::insert_location (struct bp_location
*bl
)
9661 int length
= exact
? 1 : bl
->length
;
9663 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9667 /* Implement the "remove" method for hardware watchpoints. */
9670 watchpoint::remove_location (struct bp_location
*bl
,
9671 enum remove_bp_reason reason
)
9673 int length
= exact
? 1 : bl
->length
;
9675 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9680 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9681 const address_space
*aspace
, CORE_ADDR bp_addr
,
9682 const target_waitstatus
&ws
)
9684 struct breakpoint
*b
= bl
->owner
;
9686 /* Continuable hardware watchpoints are treated as non-existent if the
9687 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9688 some data address). Otherwise gdb won't stop on a break instruction
9689 in the code (not from a breakpoint) when a hardware watchpoint has
9690 been defined. Also skip watchpoints which we know did not trigger
9691 (did not match the data address). */
9692 if (is_hardware_watchpoint (b
)
9693 && watchpoint_triggered
== watch_triggered_no
)
9700 watchpoint::check_status (bpstat
*bs
)
9702 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9704 bpstat_check_watchpoint (bs
);
9707 /* Implement the "resources_needed" method for hardware
9711 watchpoint::resources_needed (const struct bp_location
*bl
)
9713 int length
= exact
? 1 : bl
->length
;
9715 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9718 /* Implement the "works_in_software_mode" method for hardware
9722 watchpoint::works_in_software_mode () const
9724 /* Read and access watchpoints only work with hardware support. */
9725 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9728 enum print_stop_action
9729 watchpoint::print_it (const bpstat
*bs
) const
9731 struct breakpoint
*b
;
9732 enum print_stop_action result
;
9733 struct ui_out
*uiout
= current_uiout
;
9735 gdb_assert (bs
->bp_location_at
!= NULL
);
9737 b
= bs
->breakpoint_at
;
9739 annotate_watchpoint (b
->number
);
9740 maybe_print_thread_hit_breakpoint (uiout
);
9744 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9748 case bp_hardware_watchpoint
:
9749 if (uiout
->is_mi_like_p ())
9751 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9753 tuple_emitter
.emplace (uiout
, "value");
9754 uiout
->text ("\nOld value = ");
9755 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9756 uiout
->field_stream ("old", stb
);
9757 uiout
->text ("\nNew value = ");
9758 watchpoint_value_print (val
.get (), &stb
);
9759 uiout
->field_stream ("new", stb
);
9761 /* More than one watchpoint may have been triggered. */
9762 result
= PRINT_UNKNOWN
;
9765 case bp_read_watchpoint
:
9766 if (uiout
->is_mi_like_p ())
9768 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9770 tuple_emitter
.emplace (uiout
, "value");
9771 uiout
->text ("\nValue = ");
9772 watchpoint_value_print (val
.get (), &stb
);
9773 uiout
->field_stream ("value", stb
);
9775 result
= PRINT_UNKNOWN
;
9778 case bp_access_watchpoint
:
9779 if (bs
->old_val
!= NULL
)
9781 if (uiout
->is_mi_like_p ())
9784 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9786 tuple_emitter
.emplace (uiout
, "value");
9787 uiout
->text ("\nOld value = ");
9788 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9789 uiout
->field_stream ("old", stb
);
9790 uiout
->text ("\nNew value = ");
9795 if (uiout
->is_mi_like_p ())
9798 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9799 tuple_emitter
.emplace (uiout
, "value");
9800 uiout
->text ("\nValue = ");
9802 watchpoint_value_print (val
.get (), &stb
);
9803 uiout
->field_stream ("new", stb
);
9805 result
= PRINT_UNKNOWN
;
9808 result
= PRINT_UNKNOWN
;
9814 /* Implement the "print_mention" method for hardware watchpoints. */
9817 watchpoint::print_mention () const
9819 struct ui_out
*uiout
= current_uiout
;
9820 const char *tuple_name
;
9825 uiout
->text ("Watchpoint ");
9828 case bp_hardware_watchpoint
:
9829 uiout
->text ("Hardware watchpoint ");
9832 case bp_read_watchpoint
:
9833 uiout
->text ("Hardware read watchpoint ");
9834 tuple_name
= "hw-rwpt";
9836 case bp_access_watchpoint
:
9837 uiout
->text ("Hardware access (read/write) watchpoint ");
9838 tuple_name
= "hw-awpt";
9841 internal_error (_("Invalid hardware watchpoint type."));
9844 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9845 uiout
->field_signed ("number", number
);
9847 uiout
->field_string ("exp", exp_string
.get ());
9850 /* Implement the "print_recreate" method for watchpoints. */
9853 watchpoint::print_recreate (struct ui_file
*fp
) const
9858 case bp_hardware_watchpoint
:
9859 gdb_printf (fp
, "watch");
9861 case bp_read_watchpoint
:
9862 gdb_printf (fp
, "rwatch");
9864 case bp_access_watchpoint
:
9865 gdb_printf (fp
, "awatch");
9868 internal_error (_("Invalid watchpoint type."));
9871 gdb_printf (fp
, " %s", exp_string
.get ());
9872 print_recreate_thread (fp
);
9875 /* Implement the "explains_signal" method for watchpoints. */
9878 watchpoint::explains_signal (enum gdb_signal sig
)
9880 /* A software watchpoint cannot cause a signal other than
9882 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9888 struct masked_watchpoint
: public watchpoint
9890 using watchpoint::watchpoint
;
9892 int insert_location (struct bp_location
*) override
;
9893 int remove_location (struct bp_location
*,
9894 enum remove_bp_reason reason
) override
;
9895 int resources_needed (const struct bp_location
*) override
;
9896 bool works_in_software_mode () const override
;
9897 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
9898 void print_one_detail (struct ui_out
*) const override
;
9899 void print_mention () const override
;
9900 void print_recreate (struct ui_file
*fp
) const override
;
9903 /* Implement the "insert" method for masked hardware watchpoints. */
9906 masked_watchpoint::insert_location (struct bp_location
*bl
)
9908 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9909 bl
->watchpoint_type
);
9912 /* Implement the "remove" method for masked hardware watchpoints. */
9915 masked_watchpoint::remove_location (struct bp_location
*bl
,
9916 enum remove_bp_reason reason
)
9918 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9919 bl
->watchpoint_type
);
9922 /* Implement the "resources_needed" method for masked hardware
9926 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9928 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9931 /* Implement the "works_in_software_mode" method for masked hardware
9935 masked_watchpoint::works_in_software_mode () const
9940 /* Implement the "print_it" method for masked hardware
9943 enum print_stop_action
9944 masked_watchpoint::print_it (const bpstat
*bs
) const
9946 struct breakpoint
*b
= bs
->breakpoint_at
;
9947 struct ui_out
*uiout
= current_uiout
;
9949 /* Masked watchpoints have only one location. */
9950 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9952 annotate_watchpoint (b
->number
);
9953 maybe_print_thread_hit_breakpoint (uiout
);
9957 case bp_hardware_watchpoint
:
9958 if (uiout
->is_mi_like_p ())
9960 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9963 case bp_read_watchpoint
:
9964 if (uiout
->is_mi_like_p ())
9966 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9969 case bp_access_watchpoint
:
9970 if (uiout
->is_mi_like_p ())
9973 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9976 internal_error (_("Invalid hardware watchpoint type."));
9981 Check the underlying instruction at PC for the memory\n\
9982 address and value which triggered this watchpoint.\n"));
9985 /* More than one watchpoint may have been triggered. */
9986 return PRINT_UNKNOWN
;
9989 /* Implement the "print_one_detail" method for masked hardware
9993 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9995 /* Masked watchpoints have only one location. */
9996 gdb_assert (loc
&& loc
->next
== NULL
);
9998 uiout
->text ("\tmask ");
9999 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
10000 uiout
->text ("\n");
10003 /* Implement the "print_mention" method for masked hardware
10007 masked_watchpoint::print_mention () const
10009 struct ui_out
*uiout
= current_uiout
;
10010 const char *tuple_name
;
10014 case bp_hardware_watchpoint
:
10015 uiout
->text ("Masked hardware watchpoint ");
10016 tuple_name
= "wpt";
10018 case bp_read_watchpoint
:
10019 uiout
->text ("Masked hardware read watchpoint ");
10020 tuple_name
= "hw-rwpt";
10022 case bp_access_watchpoint
:
10023 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10024 tuple_name
= "hw-awpt";
10027 internal_error (_("Invalid hardware watchpoint type."));
10030 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10031 uiout
->field_signed ("number", number
);
10032 uiout
->text (": ");
10033 uiout
->field_string ("exp", exp_string
.get ());
10036 /* Implement the "print_recreate" method for masked hardware
10040 masked_watchpoint::print_recreate (struct ui_file
*fp
) const
10044 case bp_hardware_watchpoint
:
10045 gdb_printf (fp
, "watch");
10047 case bp_read_watchpoint
:
10048 gdb_printf (fp
, "rwatch");
10050 case bp_access_watchpoint
:
10051 gdb_printf (fp
, "awatch");
10054 internal_error (_("Invalid hardware watchpoint type."));
10057 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
10058 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
10059 print_recreate_thread (fp
);
10062 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10065 is_masked_watchpoint (const struct breakpoint
*b
)
10067 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
10070 /* accessflag: hw_write: watch write,
10071 hw_read: watch read,
10072 hw_access: watch access (read or write) */
10074 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10075 bool just_location
, bool internal
)
10077 struct breakpoint
*scope_breakpoint
= NULL
;
10078 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10079 struct value
*result
;
10080 int saved_bitpos
= 0, saved_bitsize
= 0;
10081 const char *exp_start
= NULL
;
10082 const char *exp_end
= NULL
;
10083 const char *tok
, *end_tok
;
10085 const char *cond_start
= NULL
;
10086 const char *cond_end
= NULL
;
10087 enum bptype bp_type
;
10089 /* Flag to indicate whether we are going to use masks for
10090 the hardware watchpoint. */
10091 bool use_mask
= false;
10092 CORE_ADDR mask
= 0;
10095 /* Make sure that we actually have parameters to parse. */
10096 if (arg
!= NULL
&& arg
[0] != '\0')
10098 const char *value_start
;
10100 exp_end
= arg
+ strlen (arg
);
10102 /* Look for "parameter value" pairs at the end
10103 of the arguments string. */
10104 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10106 /* Skip whitespace at the end of the argument list. */
10107 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10110 /* Find the beginning of the last token.
10111 This is the value of the parameter. */
10112 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10114 value_start
= tok
+ 1;
10116 /* Skip whitespace. */
10117 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10122 /* Find the beginning of the second to last token.
10123 This is the parameter itself. */
10124 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10127 toklen
= end_tok
- tok
+ 1;
10129 if (toklen
== 6 && startswith (tok
, "thread"))
10131 struct thread_info
*thr
;
10132 /* At this point we've found a "thread" token, which means
10133 the user is trying to set a watchpoint that triggers
10134 only in a specific thread. */
10138 error(_("You can specify only one thread."));
10141 error (_("You can specify only one of thread or task."));
10143 /* Extract the thread ID from the next token. */
10144 thr
= parse_thread_id (value_start
, &endp
);
10146 /* Check if the user provided a valid thread ID. */
10147 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10148 invalid_thread_id_error (value_start
);
10150 thread
= thr
->global_num
;
10152 else if (toklen
== 4 && startswith (tok
, "task"))
10157 error(_("You can specify only one task."));
10160 error (_("You can specify only one of thread or task."));
10162 task
= strtol (value_start
, &tmp
, 0);
10163 if (tmp
== value_start
)
10164 error (_("Junk after task keyword."));
10165 if (!valid_task_id (task
))
10166 error (_("Unknown task %d."), task
);
10168 else if (toklen
== 4 && startswith (tok
, "mask"))
10170 /* We've found a "mask" token, which means the user wants to
10171 create a hardware watchpoint that is going to have the mask
10173 struct value
*mask_value
;
10176 error(_("You can specify only one mask."));
10178 use_mask
= just_location
= true;
10180 scoped_value_mark mark
;
10181 mask_value
= parse_to_comma_and_eval (&value_start
);
10182 mask
= value_as_address (mask_value
);
10185 /* We didn't recognize what we found. We should stop here. */
10188 /* Truncate the string and get rid of the "parameter value" pair before
10189 the arguments string is parsed by the parse_exp_1 function. */
10196 /* Parse the rest of the arguments. From here on out, everything
10197 is in terms of a newly allocated string instead of the original
10199 std::string
expression (arg
, exp_end
- arg
);
10200 exp_start
= arg
= expression
.c_str ();
10201 innermost_block_tracker tracker
;
10202 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10204 /* Remove trailing whitespace from the expression before saving it.
10205 This makes the eventual display of the expression string a bit
10207 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10210 /* Checking if the expression is not constant. */
10211 if (watchpoint_exp_is_const (exp
.get ()))
10215 len
= exp_end
- exp_start
;
10216 while (len
> 0 && isspace (exp_start
[len
- 1]))
10218 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10221 exp_valid_block
= tracker
.block ();
10222 struct value
*mark
= value_mark ();
10223 struct value
*val_as_value
= nullptr;
10224 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10227 if (val_as_value
!= NULL
&& just_location
)
10229 saved_bitpos
= val_as_value
->bitpos ();
10230 saved_bitsize
= val_as_value
->bitsize ();
10238 exp_valid_block
= NULL
;
10239 val
= release_value (value_addr (result
));
10240 value_free_to_mark (mark
);
10244 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10247 error (_("This target does not support masked watchpoints."));
10248 else if (ret
== -2)
10249 error (_("Invalid mask or memory region."));
10252 else if (val_as_value
!= NULL
)
10253 val
= release_value (val_as_value
);
10255 tok
= skip_spaces (arg
);
10256 end_tok
= skip_to_space (tok
);
10258 toklen
= end_tok
- tok
;
10259 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10261 tok
= cond_start
= end_tok
+ 1;
10262 innermost_block_tracker if_tracker
;
10263 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10265 /* The watchpoint expression may not be local, but the condition
10266 may still be. E.g.: `watch global if local > 0'. */
10267 cond_exp_valid_block
= if_tracker
.block ();
10272 error (_("Junk at end of command."));
10274 frame_info_ptr wp_frame
= block_innermost_frame (exp_valid_block
);
10276 /* Save this because create_internal_breakpoint below invalidates
10278 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10280 /* If the expression is "local", then set up a "watchpoint scope"
10281 breakpoint at the point where we've left the scope of the watchpoint
10282 expression. Create the scope breakpoint before the watchpoint, so
10283 that we will encounter it first in bpstat_stop_status. */
10284 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10286 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10288 if (frame_id_p (caller_frame_id
))
10290 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10291 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10294 = create_internal_breakpoint (caller_arch
, caller_pc
,
10295 bp_watchpoint_scope
);
10297 /* create_internal_breakpoint could invalidate WP_FRAME. */
10300 scope_breakpoint
->enable_state
= bp_enabled
;
10302 /* Automatically delete the breakpoint when it hits. */
10303 scope_breakpoint
->disposition
= disp_del
;
10305 /* Only break in the proper frame (help with recursion). */
10306 scope_breakpoint
->frame_id
= caller_frame_id
;
10308 /* Set the address at which we will stop. */
10309 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10310 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10311 scope_breakpoint
->loc
->address
10312 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10313 scope_breakpoint
->loc
->requested_address
,
10314 scope_breakpoint
->type
,
10315 current_program_space
);
10319 /* Now set up the breakpoint. We create all watchpoints as hardware
10320 watchpoints here even if hardware watchpoints are turned off, a call
10321 to update_watchpoint later in this function will cause the type to
10322 drop back to bp_watchpoint (software watchpoint) if required. */
10324 if (accessflag
== hw_read
)
10325 bp_type
= bp_read_watchpoint
;
10326 else if (accessflag
== hw_access
)
10327 bp_type
= bp_access_watchpoint
;
10329 bp_type
= bp_hardware_watchpoint
;
10331 std::unique_ptr
<watchpoint
> w
;
10333 w
.reset (new masked_watchpoint (nullptr, bp_type
));
10335 w
.reset (new watchpoint (nullptr, bp_type
));
10337 /* At most one of thread or task can be set on a watchpoint. */
10338 gdb_assert (thread
== -1 || task
== -1);
10339 w
->thread
= thread
;
10341 w
->disposition
= disp_donttouch
;
10342 w
->pspace
= current_program_space
;
10343 w
->exp
= std::move (exp
);
10344 w
->exp_valid_block
= exp_valid_block
;
10345 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10348 struct type
*t
= val
->type ();
10349 CORE_ADDR addr
= value_as_address (val
.get ());
10351 w
->exp_string_reparse
10352 = current_language
->watch_location_expression (t
, addr
);
10354 w
->exp_string
= xstrprintf ("-location %.*s",
10355 (int) (exp_end
- exp_start
), exp_start
);
10358 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10362 w
->hw_wp_mask
= mask
;
10367 w
->val_bitpos
= saved_bitpos
;
10368 w
->val_bitsize
= saved_bitsize
;
10369 w
->val_valid
= true;
10373 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10375 w
->cond_string
= 0;
10377 if (frame_id_p (watchpoint_frame
))
10379 w
->watchpoint_frame
= watchpoint_frame
;
10380 w
->watchpoint_thread
= inferior_ptid
;
10384 w
->watchpoint_frame
= null_frame_id
;
10385 w
->watchpoint_thread
= null_ptid
;
10388 if (scope_breakpoint
!= NULL
)
10390 /* The scope breakpoint is related to the watchpoint. We will
10391 need to act on them together. */
10392 w
->related_breakpoint
= scope_breakpoint
;
10393 scope_breakpoint
->related_breakpoint
= w
.get ();
10396 if (!just_location
)
10397 value_free_to_mark (mark
);
10399 /* Finally update the new watchpoint. This creates the locations
10400 that should be inserted. */
10401 update_watchpoint (w
.get (), true /* reparse */);
10403 install_breakpoint (internal
, std::move (w
), 1);
10406 /* Return count of debug registers needed to watch the given expression.
10407 If the watchpoint cannot be handled in hardware return zero. */
10410 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10412 int found_memory_cnt
= 0;
10414 /* Did the user specifically forbid us to use hardware watchpoints? */
10415 if (!can_use_hw_watchpoints
)
10418 gdb_assert (!vals
.empty ());
10419 struct value
*head
= vals
[0].get ();
10421 /* Make sure that the value of the expression depends only upon
10422 memory contents, and values computed from them within GDB. If we
10423 find any register references or function calls, we can't use a
10424 hardware watchpoint.
10426 The idea here is that evaluating an expression generates a series
10427 of values, one holding the value of every subexpression. (The
10428 expression a*b+c has five subexpressions: a, b, a*b, c, and
10429 a*b+c.) GDB's values hold almost enough information to establish
10430 the criteria given above --- they identify memory lvalues,
10431 register lvalues, computed values, etcetera. So we can evaluate
10432 the expression, and then scan the chain of values that leaves
10433 behind to decide whether we can detect any possible change to the
10434 expression's final value using only hardware watchpoints.
10436 However, I don't think that the values returned by inferior
10437 function calls are special in any way. So this function may not
10438 notice that an expression involving an inferior function call
10439 can't be watched with hardware watchpoints. FIXME. */
10440 for (const value_ref_ptr
&iter
: vals
)
10442 struct value
*v
= iter
.get ();
10444 if (v
->lval () == lval_memory
)
10446 if (v
!= head
&& v
->lazy ())
10447 /* A lazy memory lvalue in the chain is one that GDB never
10448 needed to fetch; we either just used its address (e.g.,
10449 `a' in `a.b') or we never needed it at all (e.g., `a'
10450 in `a,b'). This doesn't apply to HEAD; if that is
10451 lazy then it was not readable, but watch it anyway. */
10455 /* Ahh, memory we actually used! Check if we can cover
10456 it with hardware watchpoints. */
10457 struct type
*vtype
= check_typedef (v
->type ());
10459 /* We only watch structs and arrays if user asked for it
10460 explicitly, never if they just happen to appear in a
10461 middle of some value chain. */
10463 || (vtype
->code () != TYPE_CODE_STRUCT
10464 && vtype
->code () != TYPE_CODE_ARRAY
))
10466 CORE_ADDR vaddr
= v
->address ();
10470 len
= (target_exact_watchpoints
10471 && is_scalar_type_recursive (vtype
))?
10472 1 : v
->type ()->length ();
10474 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10478 found_memory_cnt
+= num_regs
;
10482 else if (v
->lval () != not_lval
&& !v
->deprecated_modifiable ())
10483 return 0; /* These are values from the history (e.g., $1). */
10484 else if (v
->lval () == lval_register
)
10485 return 0; /* Cannot watch a register with a HW watchpoint. */
10488 /* The expression itself looks suitable for using a hardware
10489 watchpoint, but give the target machine a chance to reject it. */
10490 return found_memory_cnt
;
10494 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10496 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10499 /* Options for the watch, awatch, and rwatch commands. */
10501 struct watch_options
10503 /* For -location. */
10504 bool location
= false;
10507 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10509 Historically GDB always accepted both '-location' and '-l' flags for
10510 these commands (both flags being synonyms). When converting to the
10511 newer option scheme only '-location' is added here. That's fine (for
10512 backward compatibility) as any non-ambiguous prefix of a flag will be
10513 accepted, so '-l', '-loc', are now all accepted.
10515 What this means is that, if in the future, we add any new flag here
10516 that starts with '-l' then this will break backward compatibility, so
10517 please, don't do that! */
10519 static const gdb::option::option_def watch_option_defs
[] = {
10520 gdb::option::flag_option_def
<watch_options
> {
10522 [] (watch_options
*opt
) { return &opt
->location
; },
10524 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10525 -l can be used as a short form of -location."),
10529 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10532 static gdb::option::option_def_group
10533 make_watch_options_def_group (watch_options
*opts
)
10535 return {{watch_option_defs
}, opts
};
10538 /* A helper function that looks for the "-location" argument and then
10539 calls watch_command_1. */
10542 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10544 watch_options opts
;
10545 auto grp
= make_watch_options_def_group (&opts
);
10546 gdb::option::process_options
10547 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10548 if (arg
!= nullptr && *arg
== '\0')
10551 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10554 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10556 watch_command_completer (struct cmd_list_element
*ignore
,
10557 completion_tracker
&tracker
,
10558 const char *text
, const char * /*word*/)
10560 const auto group
= make_watch_options_def_group (nullptr);
10561 if (gdb::option::complete_options
10562 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10565 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10566 expression_completer (ignore
, tracker
, text
, word
);
10570 watch_command (const char *arg
, int from_tty
)
10572 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10576 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10578 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10582 rwatch_command (const char *arg
, int from_tty
)
10584 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10588 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10590 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10594 awatch_command (const char *arg
, int from_tty
)
10596 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10600 /* Data for the FSM that manages the until(location)/advance commands
10601 in infcmd.c. Here because it uses the mechanisms of
10604 struct until_break_fsm
: public thread_fsm
10606 /* The thread that was current when the command was executed. */
10609 /* The breakpoint set at the return address in the caller frame,
10610 plus breakpoints at all the destination locations. */
10611 std::vector
<breakpoint_up
> breakpoints
;
10613 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10614 std::vector
<breakpoint_up
> &&breakpoints
)
10615 : thread_fsm (cmd_interp
),
10617 breakpoints (std::move (breakpoints
))
10621 void clean_up (struct thread_info
*thread
) override
;
10622 bool should_stop (struct thread_info
*thread
) override
;
10623 enum async_reply_reason
do_async_reply_reason () override
;
10626 /* Implementation of the 'should_stop' FSM method for the
10627 until(location)/advance commands. */
10630 until_break_fsm::should_stop (struct thread_info
*tp
)
10632 for (const breakpoint_up
&bp
: breakpoints
)
10633 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10634 bp
.get ()) != NULL
)
10643 /* Implementation of the 'clean_up' FSM method for the
10644 until(location)/advance commands. */
10647 until_break_fsm::clean_up (struct thread_info
*)
10649 /* Clean up our temporary breakpoints. */
10650 breakpoints
.clear ();
10651 delete_longjmp_breakpoint (thread
);
10654 /* Implementation of the 'async_reply_reason' FSM method for the
10655 until(location)/advance commands. */
10657 enum async_reply_reason
10658 until_break_fsm::do_async_reply_reason ()
10660 return EXEC_ASYNC_LOCATION_REACHED
;
10664 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10666 frame_info_ptr frame
;
10667 struct gdbarch
*frame_gdbarch
;
10668 struct frame_id stack_frame_id
;
10669 struct frame_id caller_frame_id
;
10671 struct thread_info
*tp
;
10673 clear_proceed_status (0);
10675 /* Set a breakpoint where the user wants it and at return from
10678 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
10680 std::vector
<symtab_and_line
> sals
10681 = (last_displayed_sal_is_valid ()
10682 ? decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10683 get_last_displayed_symtab (),
10684 get_last_displayed_line ())
10685 : decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
,
10689 error (_("Couldn't get information on specified line."));
10692 error (_("Junk at end of arguments."));
10694 tp
= inferior_thread ();
10695 thread
= tp
->global_num
;
10697 /* Note linespec handling above invalidates the frame chain.
10698 Installing a breakpoint also invalidates the frame chain (as it
10699 may need to switch threads), so do any frame handling before
10702 frame
= get_selected_frame (NULL
);
10703 frame_gdbarch
= get_frame_arch (frame
);
10704 stack_frame_id
= get_stack_frame_id (frame
);
10705 caller_frame_id
= frame_unwind_caller_id (frame
);
10707 /* Keep within the current frame, or in frames called by the current
10710 std::vector
<breakpoint_up
> breakpoints
;
10712 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10714 if (frame_id_p (caller_frame_id
))
10716 struct symtab_and_line sal2
;
10717 struct gdbarch
*caller_gdbarch
;
10719 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10720 sal2
.pc
= frame_unwind_caller_pc (frame
);
10721 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10723 breakpoint_up caller_breakpoint
10724 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10725 caller_frame_id
, bp_until
);
10726 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10728 set_longjmp_breakpoint (tp
, stack_frame_id
);
10729 lj_deleter
.emplace (thread
);
10732 /* set_momentary_breakpoint could invalidate FRAME. */
10735 /* If the user told us to continue until a specified location, we
10736 don't specify a frame at which we need to stop. Otherwise,
10737 specify the selected frame, because we want to stop only at the
10738 very same frame. */
10739 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10741 for (symtab_and_line
&sal
: sals
)
10743 resolve_sal_pc (&sal
);
10745 breakpoint_up location_breakpoint
10746 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10747 stop_frame_id
, bp_until
);
10748 breakpoints
.emplace_back (std::move (location_breakpoint
));
10752 (std::unique_ptr
<thread_fsm
>
10753 (new until_break_fsm (command_interp (), tp
->global_num
,
10754 std::move (breakpoints
))));
10757 lj_deleter
->release ();
10759 proceed (-1, GDB_SIGNAL_DEFAULT
);
10764 /* Compare two breakpoints and return a strcmp-like result. */
10767 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10769 uintptr_t ua
= (uintptr_t) a
;
10770 uintptr_t ub
= (uintptr_t) b
;
10772 if (a
->number
< b
->number
)
10774 else if (a
->number
> b
->number
)
10777 /* Now sort by address, in case we see, e..g, two breakpoints with
10781 return ua
> ub
? 1 : 0;
10784 /* Delete breakpoints by address or line. */
10787 clear_command (const char *arg
, int from_tty
)
10791 std::vector
<symtab_and_line
> decoded_sals
;
10792 symtab_and_line last_sal
;
10793 gdb::array_view
<symtab_and_line
> sals
;
10797 = decode_line_with_current_source (arg
,
10798 (DECODE_LINE_FUNFIRSTLINE
10799 | DECODE_LINE_LIST_MODE
));
10801 sals
= decoded_sals
;
10805 /* Set sal's line, symtab, pc, and pspace to the values
10806 corresponding to the last call to print_frame_info. If the
10807 codepoint is not valid, this will set all the fields to 0. */
10808 last_sal
= get_last_displayed_sal ();
10809 if (last_sal
.symtab
== 0)
10810 error (_("No source file specified."));
10816 /* We don't call resolve_sal_pc here. That's not as bad as it
10817 seems, because all existing breakpoints typically have both
10818 file/line and pc set. So, if clear is given file/line, we can
10819 match this to existing breakpoint without obtaining pc at all.
10821 We only support clearing given the address explicitly
10822 present in breakpoint table. Say, we've set breakpoint
10823 at file:line. There were several PC values for that file:line,
10824 due to optimization, all in one block.
10826 We've picked one PC value. If "clear" is issued with another
10827 PC corresponding to the same file:line, the breakpoint won't
10828 be cleared. We probably can still clear the breakpoint, but
10829 since the other PC value is never presented to user, user
10830 can only find it by guessing, and it does not seem important
10831 to support that. */
10833 /* For each line spec given, delete bps which correspond to it. Do
10834 it in two passes, solely to preserve the current behavior that
10835 from_tty is forced true if we delete more than one
10838 std::vector
<struct breakpoint
*> found
;
10839 for (const auto &sal
: sals
)
10841 const char *sal_fullname
;
10843 /* If exact pc given, clear bpts at that pc.
10844 If line given (pc == 0), clear all bpts on specified line.
10845 If defaulting, clear all bpts on default line
10848 defaulting sal.pc != 0 tests to do
10853 1 0 <can't happen> */
10855 sal_fullname
= (sal
.symtab
== NULL
10856 ? NULL
: symtab_to_fullname (sal
.symtab
));
10858 /* Find all matching breakpoints and add them to 'found'. */
10859 for (breakpoint
*b
: all_breakpoints ())
10862 /* Are we going to delete b? */
10863 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10864 && user_breakpoint_p (b
))
10866 for (bp_location
*loc
: b
->locations ())
10868 /* If the user specified file:line, don't allow a PC
10869 match. This matches historical gdb behavior. */
10870 int pc_match
= (!sal
.explicit_line
10872 && (loc
->pspace
== sal
.pspace
)
10873 && (loc
->address
== sal
.pc
)
10874 && (!section_is_overlay (loc
->section
)
10875 || loc
->section
== sal
.section
));
10876 int line_match
= 0;
10878 if ((default_match
|| sal
.explicit_line
)
10879 && loc
->symtab
!= NULL
10880 && sal_fullname
!= NULL
10881 && sal
.pspace
== loc
->pspace
10882 && loc
->line_number
== sal
.line
10883 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10884 sal_fullname
) == 0)
10887 if (pc_match
|| line_match
)
10896 found
.push_back (b
);
10900 /* Now go thru the 'found' chain and delete them. */
10901 if (found
.empty ())
10904 error (_("No breakpoint at %s."), arg
);
10906 error (_("No breakpoint at this line."));
10909 /* Remove duplicates from the vec. */
10910 std::sort (found
.begin (), found
.end (),
10911 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10913 return compare_breakpoints (bp_a
, bp_b
) < 0;
10915 found
.erase (std::unique (found
.begin (), found
.end (),
10916 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10918 return compare_breakpoints (bp_a
, bp_b
) == 0;
10922 if (found
.size () > 1)
10923 from_tty
= 1; /* Always report if deleted more than one. */
10926 if (found
.size () == 1)
10927 gdb_printf (_("Deleted breakpoint "));
10929 gdb_printf (_("Deleted breakpoints "));
10932 for (breakpoint
*iter
: found
)
10935 gdb_printf ("%d ", iter
->number
);
10936 delete_breakpoint (iter
);
10942 /* Delete breakpoint in BS if they are `delete' breakpoints and
10943 all breakpoints that are marked for deletion, whether hit or not.
10944 This is called after any breakpoint is hit, or after errors. */
10947 breakpoint_auto_delete (bpstat
*bs
)
10949 for (; bs
; bs
= bs
->next
)
10950 if (bs
->breakpoint_at
10951 && bs
->breakpoint_at
->disposition
== disp_del
10953 delete_breakpoint (bs
->breakpoint_at
);
10955 for (breakpoint
*b
: all_breakpoints_safe ())
10956 if (b
->disposition
== disp_del_at_next_stop
)
10957 delete_breakpoint (b
);
10960 /* A comparison function for bp_location AP and BP being interfaced to
10961 std::sort. Sort elements primarily by their ADDRESS (no matter what
10962 bl_address_is_meaningful says), secondarily by ordering first
10963 permanent elements and terciarily just ensuring the array is sorted
10964 stable way despite std::sort being an unstable algorithm. */
10967 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10969 if (a
->address
!= b
->address
)
10970 return a
->address
< b
->address
;
10972 /* Sort locations at the same address by their pspace number, keeping
10973 locations of the same inferior (in a multi-inferior environment)
10976 if (a
->pspace
->num
!= b
->pspace
->num
)
10977 return a
->pspace
->num
< b
->pspace
->num
;
10979 /* Sort permanent breakpoints first. */
10980 if (a
->permanent
!= b
->permanent
)
10981 return a
->permanent
> b
->permanent
;
10983 /* Sort by type in order to make duplicate determination easier.
10984 See update_global_location_list. This is kept in sync with
10985 breakpoint_locations_match. */
10986 if (a
->loc_type
< b
->loc_type
)
10989 /* Likewise, for range-breakpoints, sort by length. */
10990 if (a
->loc_type
== bp_loc_hardware_breakpoint
10991 && b
->loc_type
== bp_loc_hardware_breakpoint
10992 && a
->length
< b
->length
)
10995 /* Make the internal GDB representation stable across GDB runs
10996 where A and B memory inside GDB can differ. Breakpoint locations of
10997 the same type at the same address can be sorted in arbitrary order. */
10999 if (a
->owner
->number
!= b
->owner
->number
)
11000 return a
->owner
->number
< b
->owner
->number
;
11005 /* Set bp_locations_placed_address_before_address_max and
11006 bp_locations_shadow_len_after_address_max according to the current
11007 content of the bp_locations array. */
11010 bp_locations_target_extensions_update (void)
11012 bp_locations_placed_address_before_address_max
= 0;
11013 bp_locations_shadow_len_after_address_max
= 0;
11015 for (bp_location
*bl
: all_bp_locations ())
11017 CORE_ADDR start
, end
, addr
;
11019 if (!bp_location_has_shadow (bl
))
11022 start
= bl
->target_info
.placed_address
;
11023 end
= start
+ bl
->target_info
.shadow_len
;
11025 gdb_assert (bl
->address
>= start
);
11026 addr
= bl
->address
- start
;
11027 if (addr
> bp_locations_placed_address_before_address_max
)
11028 bp_locations_placed_address_before_address_max
= addr
;
11030 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11032 gdb_assert (bl
->address
< end
);
11033 addr
= end
- bl
->address
;
11034 if (addr
> bp_locations_shadow_len_after_address_max
)
11035 bp_locations_shadow_len_after_address_max
= addr
;
11039 /* Download tracepoint locations if they haven't been. */
11042 download_tracepoint_locations (void)
11044 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11046 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11048 for (breakpoint
*b
: all_tracepoints ())
11050 struct tracepoint
*t
;
11051 bool bp_location_downloaded
= false;
11053 if ((b
->type
== bp_fast_tracepoint
11054 ? !may_insert_fast_tracepoints
11055 : !may_insert_tracepoints
))
11058 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11060 if (target_can_download_tracepoint ())
11061 can_download_tracepoint
= TRIBOOL_TRUE
;
11063 can_download_tracepoint
= TRIBOOL_FALSE
;
11066 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11069 for (bp_location
*bl
: b
->locations ())
11071 /* In tracepoint, locations are _never_ duplicated, so
11072 should_be_inserted is equivalent to
11073 unduplicated_should_be_inserted. */
11074 if (!should_be_inserted (bl
) || bl
->inserted
)
11077 switch_to_program_space_and_thread (bl
->pspace
);
11079 target_download_tracepoint (bl
);
11082 bp_location_downloaded
= true;
11084 t
= (struct tracepoint
*) b
;
11085 t
->number_on_target
= b
->number
;
11086 if (bp_location_downloaded
)
11087 gdb::observers::breakpoint_modified
.notify (b
);
11091 /* Swap the insertion/duplication state between two locations. */
11094 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11096 const int left_inserted
= left
->inserted
;
11097 const int left_duplicate
= left
->duplicate
;
11098 const int left_needs_update
= left
->needs_update
;
11099 const struct bp_target_info left_target_info
= left
->target_info
;
11101 /* Locations of tracepoints can never be duplicated. */
11102 if (is_tracepoint (left
->owner
))
11103 gdb_assert (!left
->duplicate
);
11104 if (is_tracepoint (right
->owner
))
11105 gdb_assert (!right
->duplicate
);
11107 left
->inserted
= right
->inserted
;
11108 left
->duplicate
= right
->duplicate
;
11109 left
->needs_update
= right
->needs_update
;
11110 left
->target_info
= right
->target_info
;
11111 right
->inserted
= left_inserted
;
11112 right
->duplicate
= left_duplicate
;
11113 right
->needs_update
= left_needs_update
;
11114 right
->target_info
= left_target_info
;
11117 /* Force the re-insertion of the locations at ADDRESS. This is called
11118 once a new/deleted/modified duplicate location is found and we are evaluating
11119 conditions on the target's side. Such conditions need to be updated on
11123 force_breakpoint_reinsertion (struct bp_location
*bl
)
11125 CORE_ADDR address
= 0;
11128 address
= bl
->address
;
11129 pspace_num
= bl
->pspace
->num
;
11131 /* This is only meaningful if the target is
11132 evaluating conditions and if the user has
11133 opted for condition evaluation on the target's
11135 if (gdb_evaluates_breakpoint_condition_p ()
11136 || !target_supports_evaluation_of_breakpoint_conditions ())
11139 /* Flag all breakpoint locations with this address and
11140 the same program space as the location
11141 as "its condition has changed". We need to
11142 update the conditions on the target's side. */
11143 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11145 if (!is_breakpoint (loc
->owner
)
11146 || pspace_num
!= loc
->pspace
->num
)
11149 /* Flag the location appropriately. We use a different state to
11150 let everyone know that we already updated the set of locations
11151 with addr bl->address and program space bl->pspace. This is so
11152 we don't have to keep calling these functions just to mark locations
11153 that have already been marked. */
11154 loc
->condition_changed
= condition_updated
;
11156 /* Free the agent expression bytecode as well. We will compute
11158 loc
->cond_bytecode
.reset ();
11162 /* Called whether new breakpoints are created, or existing breakpoints
11163 deleted, to update the global location list and recompute which
11164 locations are duplicate of which.
11166 The INSERT_MODE flag determines whether locations may not, may, or
11167 shall be inserted now. See 'enum ugll_insert_mode' for more
11171 update_global_location_list (enum ugll_insert_mode insert_mode
)
11173 /* Last breakpoint location address that was marked for update. */
11174 CORE_ADDR last_addr
= 0;
11175 /* Last breakpoint location program space that was marked for update. */
11176 int last_pspace_num
= -1;
11178 /* Used in the duplicates detection below. When iterating over all
11179 bp_locations, points to the first bp_location of a given address.
11180 Breakpoints and watchpoints of different types are never
11181 duplicates of each other. Keep one pointer for each type of
11182 breakpoint/watchpoint, so we only need to loop over all locations
11184 struct bp_location
*bp_loc_first
; /* breakpoint */
11185 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11186 struct bp_location
*awp_loc_first
; /* access watchpoint */
11187 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11189 /* Saved former bp_locations array which we compare against the newly
11190 built bp_locations from the current state of ALL_BREAKPOINTS. */
11191 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11192 bp_locations
.clear ();
11194 for (breakpoint
*b
: all_breakpoints ())
11195 for (bp_location
*loc
: b
->locations ())
11196 bp_locations
.push_back (loc
);
11198 /* See if we need to "upgrade" a software breakpoint to a hardware
11199 breakpoint. Do this before deciding whether locations are
11200 duplicates. Also do this before sorting because sorting order
11201 depends on location type. */
11202 for (bp_location
*loc
: bp_locations
)
11203 if (!loc
->inserted
&& should_be_inserted (loc
))
11204 handle_automatic_hardware_breakpoints (loc
);
11206 std::sort (bp_locations
.begin (), bp_locations
.end (),
11207 bp_location_is_less_than
);
11209 bp_locations_target_extensions_update ();
11211 /* Identify bp_location instances that are no longer present in the
11212 new list, and therefore should be freed. Note that it's not
11213 necessary that those locations should be removed from inferior --
11214 if there's another location at the same address (previously
11215 marked as duplicate), we don't need to remove/insert the
11218 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11219 and former bp_location array state respectively. */
11222 for (bp_location
*old_loc
: old_locations
)
11224 /* Tells if 'old_loc' is found among the new locations. If
11225 not, we have to free it. */
11226 bool found_object
= false;
11227 /* Tells if the location should remain inserted in the target. */
11228 bool keep_in_target
= false;
11229 bool removed
= false;
11231 /* Skip LOCP entries which will definitely never be needed.
11232 Stop either at or being the one matching OLD_LOC. */
11233 while (loc_i
< bp_locations
.size ()
11234 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11237 for (size_t loc2_i
= loc_i
;
11238 (loc2_i
< bp_locations
.size ()
11239 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11242 /* Check if this is a new/duplicated location or a duplicated
11243 location that had its condition modified. If so, we want to send
11244 its condition to the target if evaluation of conditions is taking
11246 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11247 && (last_addr
!= old_loc
->address
11248 || last_pspace_num
!= old_loc
->pspace
->num
))
11250 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11251 last_pspace_num
= old_loc
->pspace
->num
;
11254 if (bp_locations
[loc2_i
] == old_loc
)
11255 found_object
= true;
11258 /* We have already handled this address, update it so that we don't
11259 have to go through updates again. */
11260 last_addr
= old_loc
->address
;
11262 /* Target-side condition evaluation: Handle deleted locations. */
11264 force_breakpoint_reinsertion (old_loc
);
11266 /* If this location is no longer present, and inserted, look if
11267 there's maybe a new location at the same address. If so,
11268 mark that one inserted, and don't remove this one. This is
11269 needed so that we don't have a time window where a breakpoint
11270 at certain location is not inserted. */
11272 if (old_loc
->inserted
)
11274 /* If the location is inserted now, we might have to remove
11277 if (found_object
&& should_be_inserted (old_loc
))
11279 /* The location is still present in the location list,
11280 and still should be inserted. Don't do anything. */
11281 keep_in_target
= true;
11285 /* This location still exists, but it won't be kept in the
11286 target since it may have been disabled. We proceed to
11287 remove its target-side condition. */
11289 /* The location is either no longer present, or got
11290 disabled. See if there's another location at the
11291 same address, in which case we don't need to remove
11292 this one from the target. */
11294 /* OLD_LOC comes from existing struct breakpoint. */
11295 if (bl_address_is_meaningful (old_loc
))
11297 for (size_t loc2_i
= loc_i
;
11298 (loc2_i
< bp_locations
.size ()
11299 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11302 bp_location
*loc2
= bp_locations
[loc2_i
];
11304 if (loc2
== old_loc
)
11307 if (breakpoint_locations_match (loc2
, old_loc
))
11309 /* Read watchpoint locations are switched to
11310 access watchpoints, if the former are not
11311 supported, but the latter are. */
11312 if (is_hardware_watchpoint (old_loc
->owner
))
11314 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11315 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11318 /* loc2 is a duplicated location. We need to check
11319 if it should be inserted in case it will be
11321 if (unduplicated_should_be_inserted (loc2
))
11323 swap_insertion (old_loc
, loc2
);
11324 keep_in_target
= true;
11332 if (!keep_in_target
)
11334 if (remove_breakpoint (old_loc
))
11336 /* This is just about all we can do. We could keep
11337 this location on the global list, and try to
11338 remove it next time, but there's no particular
11339 reason why we will succeed next time.
11341 Note that at this point, old_loc->owner is still
11342 valid, as delete_breakpoint frees the breakpoint
11343 only after calling us. */
11344 gdb_printf (_("warning: Error removing "
11345 "breakpoint %d\n"),
11346 old_loc
->owner
->number
);
11354 if (removed
&& target_is_non_stop_p ()
11355 && need_moribund_for_location_type (old_loc
))
11357 /* This location was removed from the target. In
11358 non-stop mode, a race condition is possible where
11359 we've removed a breakpoint, but stop events for that
11360 breakpoint are already queued and will arrive later.
11361 We apply an heuristic to be able to distinguish such
11362 SIGTRAPs from other random SIGTRAPs: we keep this
11363 breakpoint location for a bit, and will retire it
11364 after we see some number of events. The theory here
11365 is that reporting of events should, "on the average",
11366 be fair, so after a while we'll see events from all
11367 threads that have anything of interest, and no longer
11368 need to keep this breakpoint location around. We
11369 don't hold locations forever so to reduce chances of
11370 mistaking a non-breakpoint SIGTRAP for a breakpoint
11373 The heuristic failing can be disastrous on
11374 decr_pc_after_break targets.
11376 On decr_pc_after_break targets, like e.g., x86-linux,
11377 if we fail to recognize a late breakpoint SIGTRAP,
11378 because events_till_retirement has reached 0 too
11379 soon, we'll fail to do the PC adjustment, and report
11380 a random SIGTRAP to the user. When the user resumes
11381 the inferior, it will most likely immediately crash
11382 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11383 corrupted, because of being resumed e.g., in the
11384 middle of a multi-byte instruction, or skipped a
11385 one-byte instruction. This was actually seen happen
11386 on native x86-linux, and should be less rare on
11387 targets that do not support new thread events, like
11388 remote, due to the heuristic depending on
11391 Mistaking a random SIGTRAP for a breakpoint trap
11392 causes similar symptoms (PC adjustment applied when
11393 it shouldn't), but then again, playing with SIGTRAPs
11394 behind the debugger's back is asking for trouble.
11396 Since hardware watchpoint traps are always
11397 distinguishable from other traps, so we don't need to
11398 apply keep hardware watchpoint moribund locations
11399 around. We simply always ignore hardware watchpoint
11400 traps we can no longer explain. */
11402 process_stratum_target
*proc_target
= nullptr;
11403 for (inferior
*inf
: all_inferiors ())
11404 if (inf
->pspace
== old_loc
->pspace
)
11406 proc_target
= inf
->process_target ();
11409 if (proc_target
!= nullptr)
11410 old_loc
->events_till_retirement
11411 = 3 * (thread_count (proc_target
) + 1);
11413 old_loc
->events_till_retirement
= 1;
11414 old_loc
->owner
= NULL
;
11416 moribund_locations
.push_back (old_loc
);
11420 old_loc
->owner
= NULL
;
11421 decref_bp_location (&old_loc
);
11426 /* Rescan breakpoints at the same address and section, marking the
11427 first one as "first" and any others as "duplicates". This is so
11428 that the bpt instruction is only inserted once. If we have a
11429 permanent breakpoint at the same place as BPT, make that one the
11430 official one, and the rest as duplicates. Permanent breakpoints
11431 are sorted first for the same address.
11433 Do the same for hardware watchpoints, but also considering the
11434 watchpoint's type (regular/access/read) and length. */
11436 bp_loc_first
= NULL
;
11437 wp_loc_first
= NULL
;
11438 awp_loc_first
= NULL
;
11439 rwp_loc_first
= NULL
;
11441 for (bp_location
*loc
: all_bp_locations ())
11443 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11445 struct bp_location
**loc_first_p
;
11446 breakpoint
*b
= loc
->owner
;
11448 if (!unduplicated_should_be_inserted (loc
)
11449 || !bl_address_is_meaningful (loc
)
11450 /* Don't detect duplicate for tracepoint locations because they are
11451 never duplicated. See the comments in field `duplicate' of
11452 `struct bp_location'. */
11453 || is_tracepoint (b
))
11455 /* Clear the condition modification flag. */
11456 loc
->condition_changed
= condition_unchanged
;
11460 if (b
->type
== bp_hardware_watchpoint
)
11461 loc_first_p
= &wp_loc_first
;
11462 else if (b
->type
== bp_read_watchpoint
)
11463 loc_first_p
= &rwp_loc_first
;
11464 else if (b
->type
== bp_access_watchpoint
)
11465 loc_first_p
= &awp_loc_first
;
11467 loc_first_p
= &bp_loc_first
;
11469 if (*loc_first_p
== NULL
11470 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11471 || !breakpoint_locations_match (loc
, *loc_first_p
))
11473 *loc_first_p
= loc
;
11474 loc
->duplicate
= 0;
11476 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11478 loc
->needs_update
= 1;
11479 /* Clear the condition modification flag. */
11480 loc
->condition_changed
= condition_unchanged
;
11486 /* This and the above ensure the invariant that the first location
11487 is not duplicated, and is the inserted one.
11488 All following are marked as duplicated, and are not inserted. */
11490 swap_insertion (loc
, *loc_first_p
);
11491 loc
->duplicate
= 1;
11493 /* Clear the condition modification flag. */
11494 loc
->condition_changed
= condition_unchanged
;
11497 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11499 if (insert_mode
!= UGLL_DONT_INSERT
)
11500 insert_breakpoint_locations ();
11503 /* Even though the caller told us to not insert new
11504 locations, we may still need to update conditions on the
11505 target's side of breakpoints that were already inserted
11506 if the target is evaluating breakpoint conditions. We
11507 only update conditions for locations that are marked
11509 update_inserted_breakpoint_locations ();
11513 if (insert_mode
!= UGLL_DONT_INSERT
)
11514 download_tracepoint_locations ();
11518 breakpoint_retire_moribund (void)
11520 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11522 struct bp_location
*loc
= moribund_locations
[ix
];
11523 if (--(loc
->events_till_retirement
) == 0)
11525 decref_bp_location (&loc
);
11526 unordered_remove (moribund_locations
, ix
);
11533 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11538 update_global_location_list (insert_mode
);
11540 catch (const gdb_exception_error
&e
)
11545 /* Clear BKP from a BPS. */
11548 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11552 for (bs
= bps
; bs
; bs
= bs
->next
)
11553 if (bs
->breakpoint_at
== bpt
)
11555 bs
->breakpoint_at
= NULL
;
11556 bs
->old_val
= NULL
;
11557 /* bs->commands will be freed later. */
11561 /* Callback for iterate_over_threads. */
11563 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11565 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11567 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11571 /* See breakpoint.h. */
11574 code_breakpoint::say_where () const
11576 struct value_print_options opts
;
11578 get_user_print_options (&opts
);
11580 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11584 /* For pending locations, the output differs slightly based
11585 on extra_string. If this is non-NULL, it contains either
11586 a condition or dprintf arguments. */
11587 if (extra_string
== NULL
)
11589 gdb_printf (_(" (%s) pending."), locspec
->to_string ());
11591 else if (type
== bp_dprintf
)
11593 gdb_printf (_(" (%s,%s) pending."),
11594 locspec
->to_string (),
11595 extra_string
.get ());
11599 gdb_printf (_(" (%s %s) pending."),
11600 locspec
->to_string (),
11601 extra_string
.get ());
11606 if (opts
.addressprint
|| loc
->symtab
== NULL
)
11607 gdb_printf (" at %ps",
11608 styled_string (address_style
.style (),
11609 paddress (loc
->gdbarch
,
11611 if (loc
->symtab
!= NULL
)
11613 /* If there is a single location, we can print the location
11615 if (loc
->next
== NULL
)
11617 const char *filename
11618 = symtab_to_filename_for_display (loc
->symtab
);
11619 gdb_printf (": file %ps, line %d.",
11620 styled_string (file_name_style
.style (),
11625 /* This is not ideal, but each location may have a
11626 different file name, and this at least reflects the
11627 real situation somewhat. */
11628 gdb_printf (": %s.", locspec
->to_string ());
11633 struct bp_location
*iter
= loc
;
11635 for (; iter
; iter
= iter
->next
)
11637 gdb_printf (" (%d locations)", n
);
11642 /* See breakpoint.h. */
11644 bp_location_range
breakpoint::locations () const
11646 return bp_location_range (this->loc
);
11649 struct bp_location
*
11650 breakpoint::allocate_location ()
11652 return new bp_location (this);
11655 #define internal_error_pure_virtual_called() \
11656 gdb_assert_not_reached ("pure virtual function called")
11659 breakpoint::insert_location (struct bp_location
*bl
)
11661 internal_error_pure_virtual_called ();
11665 breakpoint::remove_location (struct bp_location
*bl
,
11666 enum remove_bp_reason reason
)
11668 internal_error_pure_virtual_called ();
11672 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11673 const address_space
*aspace
,
11675 const target_waitstatus
&ws
)
11677 internal_error_pure_virtual_called ();
11681 breakpoint::resources_needed (const struct bp_location
*bl
)
11683 internal_error_pure_virtual_called ();
11686 enum print_stop_action
11687 breakpoint::print_it (const bpstat
*bs
) const
11689 internal_error_pure_virtual_called ();
11693 breakpoint::print_mention () const
11695 internal_error_pure_virtual_called ();
11699 breakpoint::print_recreate (struct ui_file
*fp
) const
11701 internal_error_pure_virtual_called ();
11704 /* Default breakpoint_ops methods. */
11707 code_breakpoint::re_set ()
11709 /* FIXME: is this still reachable? */
11710 if (breakpoint_location_spec_empty_p (this))
11712 /* Anything without a location can't be re-set. */
11713 delete_breakpoint (this);
11721 code_breakpoint::insert_location (struct bp_location
*bl
)
11723 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11725 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11726 bl
->target_info
.placed_address
= addr
;
11729 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11730 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11732 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11734 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11736 /* The insertion was successful, now let's set the probe's semaphore
11738 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11745 code_breakpoint::remove_location (struct bp_location
*bl
,
11746 enum remove_bp_reason reason
)
11748 if (bl
->probe
.prob
!= nullptr)
11750 /* Let's clear the semaphore before removing the location. */
11751 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11754 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11755 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11757 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11761 code_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11762 const address_space
*aspace
,
11764 const target_waitstatus
&ws
)
11766 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11767 || ws
.sig () != GDB_SIGNAL_TRAP
)
11770 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11774 if (overlay_debugging
/* unmapped overlay section */
11775 && section_is_overlay (bl
->section
)
11776 && !section_is_mapped (bl
->section
))
11783 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11784 const address_space
*aspace
,
11786 const target_waitstatus
&ws
)
11788 if (dprintf_style
== dprintf_style_agent
11789 && target_can_run_breakpoint_commands ())
11791 /* An agent-style dprintf never causes a stop. If we see a trap
11792 for this address it must be for a breakpoint that happens to
11793 be set at the same address. */
11797 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11801 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
11803 gdb_assert (type
== bp_hardware_breakpoint
);
11808 enum print_stop_action
11809 ordinary_breakpoint::print_it (const bpstat
*bs
) const
11811 const struct bp_location
*bl
;
11813 struct ui_out
*uiout
= current_uiout
;
11815 bl
= bs
->bp_location_at
.get ();
11817 bp_temp
= disposition
== disp_del
;
11818 if (bl
->address
!= bl
->requested_address
)
11819 breakpoint_adjustment_warning (bl
->requested_address
,
11822 annotate_breakpoint (number
);
11823 maybe_print_thread_hit_breakpoint (uiout
);
11825 if (uiout
->is_mi_like_p ())
11827 uiout
->field_string ("reason",
11828 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11829 uiout
->field_string ("disp", bpdisp_text (disposition
));
11833 uiout
->text ("Temporary breakpoint ");
11835 uiout
->text ("Breakpoint ");
11836 print_num_locno (bs
, uiout
);
11837 uiout
->text (", ");
11839 return PRINT_SRC_AND_LOC
;
11843 ordinary_breakpoint::print_mention () const
11845 if (current_uiout
->is_mi_like_p ())
11850 case bp_breakpoint
:
11851 case bp_gnu_ifunc_resolver
:
11852 if (disposition
== disp_del
)
11853 gdb_printf (_("Temporary breakpoint"));
11855 gdb_printf (_("Breakpoint"));
11856 gdb_printf (_(" %d"), number
);
11857 if (type
== bp_gnu_ifunc_resolver
)
11858 gdb_printf (_(" at gnu-indirect-function resolver"));
11860 case bp_hardware_breakpoint
:
11861 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
11864 gdb_printf (_("Dprintf %d"), number
);
11872 ordinary_breakpoint::print_recreate (struct ui_file
*fp
) const
11874 if (type
== bp_breakpoint
&& disposition
== disp_del
)
11875 gdb_printf (fp
, "tbreak");
11876 else if (type
== bp_breakpoint
)
11877 gdb_printf (fp
, "break");
11878 else if (type
== bp_hardware_breakpoint
11879 && disposition
== disp_del
)
11880 gdb_printf (fp
, "thbreak");
11881 else if (type
== bp_hardware_breakpoint
)
11882 gdb_printf (fp
, "hbreak");
11884 internal_error (_("unhandled breakpoint type %d"), (int) type
);
11886 gdb_printf (fp
, " %s", locspec
->to_string ());
11888 /* Print out extra_string if this breakpoint is pending. It might
11889 contain, for example, conditions that were set by the user. */
11890 if (loc
== NULL
&& extra_string
!= NULL
)
11891 gdb_printf (fp
, " %s", extra_string
.get ());
11893 print_recreate_thread (fp
);
11896 std::vector
<symtab_and_line
>
11897 code_breakpoint::decode_location_spec (location_spec
*locspec
,
11898 program_space
*search_pspace
)
11900 if (locspec
->type () == PROBE_LOCATION_SPEC
)
11901 return bkpt_probe_decode_location_spec (this, locspec
, search_pspace
);
11903 struct linespec_result canonical
;
11905 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
11906 NULL
, 0, &canonical
, multiple_symbols_all
,
11909 /* We should get 0 or 1 resulting SALs. */
11910 gdb_assert (canonical
.lsals
.size () < 2);
11912 if (!canonical
.lsals
.empty ())
11914 const linespec_sals
&lsal
= canonical
.lsals
[0];
11915 return std::move (lsal
.sals
);
11920 /* Virtual table for internal breakpoints. */
11923 internal_breakpoint::re_set ()
11927 /* Delete overlay event and longjmp master breakpoints; they
11928 will be reset later by breakpoint_re_set. */
11929 case bp_overlay_event
:
11930 case bp_longjmp_master
:
11931 case bp_std_terminate_master
:
11932 case bp_exception_master
:
11933 delete_breakpoint (this);
11936 /* This breakpoint is special, it's set up when the inferior
11937 starts and we really don't want to touch it. */
11938 case bp_shlib_event
:
11940 /* Like bp_shlib_event, this breakpoint type is special. Once
11941 it is set up, we do not want to touch it. */
11942 case bp_thread_event
:
11948 internal_breakpoint::check_status (bpstat
*bs
)
11950 if (type
== bp_shlib_event
)
11952 /* If requested, stop when the dynamic linker notifies GDB of
11953 events. This allows the user to get control and place
11954 breakpoints in initializer routines for dynamically loaded
11955 objects (among other things). */
11956 bs
->stop
= stop_on_solib_events
!= 0;
11957 bs
->print
= stop_on_solib_events
!= 0;
11963 enum print_stop_action
11964 internal_breakpoint::print_it (const bpstat
*bs
) const
11968 case bp_shlib_event
:
11969 /* Did we stop because the user set the stop_on_solib_events
11970 variable? (If so, we report this as a generic, "Stopped due
11971 to shlib event" message.) */
11972 print_solib_event (false);
11975 case bp_thread_event
:
11976 /* Not sure how we will get here.
11977 GDB should not stop for these breakpoints. */
11978 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
11981 case bp_overlay_event
:
11982 /* By analogy with the thread event, GDB should not stop for these. */
11983 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11986 case bp_longjmp_master
:
11987 /* These should never be enabled. */
11988 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11991 case bp_std_terminate_master
:
11992 /* These should never be enabled. */
11993 gdb_printf (_("std::terminate Master Breakpoint: "
11994 "gdb should not stop!\n"));
11997 case bp_exception_master
:
11998 /* These should never be enabled. */
11999 gdb_printf (_("Exception Master Breakpoint: "
12000 "gdb should not stop!\n"));
12004 return PRINT_NOTHING
;
12008 internal_breakpoint::print_mention () const
12010 /* Nothing to mention. These breakpoints are internal. */
12013 /* Virtual table for momentary breakpoints */
12016 momentary_breakpoint::re_set ()
12018 /* Keep temporary breakpoints, which can be encountered when we step
12019 over a dlopen call and solib_add is resetting the breakpoints.
12020 Otherwise these should have been blown away via the cleanup chain
12021 or by breakpoint_init_inferior when we rerun the executable. */
12025 momentary_breakpoint::check_status (bpstat
*bs
)
12027 /* Nothing. The point of these breakpoints is causing a stop. */
12030 enum print_stop_action
12031 momentary_breakpoint::print_it (const bpstat
*bs
) const
12033 return PRINT_UNKNOWN
;
12037 momentary_breakpoint::print_mention () const
12039 /* Nothing to mention. These breakpoints are internal. */
12042 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12044 It gets cleared already on the removal of the first one of such placed
12045 breakpoints. This is OK as they get all removed altogether. */
12047 longjmp_breakpoint::~longjmp_breakpoint ()
12049 thread_info
*tp
= find_thread_global_id (this->thread
);
12052 tp
->initiating_frame
= null_frame_id
;
12056 bkpt_probe_create_sals_from_location_spec (location_spec
*locspec
,
12057 struct linespec_result
*canonical
)
12060 struct linespec_sals lsal
;
12062 lsal
.sals
= parse_probes (locspec
, NULL
, canonical
);
12063 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12064 canonical
->lsals
.push_back (std::move (lsal
));
12067 static std::vector
<symtab_and_line
>
12068 bkpt_probe_decode_location_spec (struct breakpoint
*b
,
12069 location_spec
*locspec
,
12070 program_space
*search_pspace
)
12072 std::vector
<symtab_and_line
> sals
12073 = parse_probes (locspec
, search_pspace
, NULL
);
12075 error (_("probe not found"));
12080 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
12081 const address_space
*aspace
, CORE_ADDR bp_addr
,
12082 const target_waitstatus
&ws
)
12084 /* By definition, the inferior does not report stops at
12090 tracepoint::print_one_detail (struct ui_out
*uiout
) const
12092 if (!static_trace_marker_id
.empty ())
12094 gdb_assert (type
== bp_static_tracepoint
12095 || type
== bp_static_marker_tracepoint
);
12097 uiout
->message ("\tmarker id is %pF\n",
12098 string_field ("static-tracepoint-marker-string-id",
12099 static_trace_marker_id
.c_str ()));
12104 tracepoint::print_mention () const
12106 if (current_uiout
->is_mi_like_p ())
12111 case bp_tracepoint
:
12112 gdb_printf (_("Tracepoint"));
12113 gdb_printf (_(" %d"), number
);
12115 case bp_fast_tracepoint
:
12116 gdb_printf (_("Fast tracepoint"));
12117 gdb_printf (_(" %d"), number
);
12119 case bp_static_tracepoint
:
12120 case bp_static_marker_tracepoint
:
12121 gdb_printf (_("Static tracepoint"));
12122 gdb_printf (_(" %d"), number
);
12125 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12132 tracepoint::print_recreate (struct ui_file
*fp
) const
12134 if (type
== bp_fast_tracepoint
)
12135 gdb_printf (fp
, "ftrace");
12136 else if (type
== bp_static_tracepoint
12137 || type
== bp_static_marker_tracepoint
)
12138 gdb_printf (fp
, "strace");
12139 else if (type
== bp_tracepoint
)
12140 gdb_printf (fp
, "trace");
12142 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12144 gdb_printf (fp
, " %s", locspec
->to_string ());
12145 print_recreate_thread (fp
);
12148 gdb_printf (fp
, " passcount %d\n", pass_count
);
12151 /* Virtual table for tracepoints on static probes. */
12154 tracepoint_probe_create_sals_from_location_spec
12155 (location_spec
*locspec
,
12156 struct linespec_result
*canonical
)
12158 /* We use the same method for breakpoint on probes. */
12159 bkpt_probe_create_sals_from_location_spec (locspec
, canonical
);
12163 dprintf_breakpoint::re_set ()
12167 /* extra_string should never be non-NULL for dprintf. */
12168 gdb_assert (extra_string
!= NULL
);
12170 /* 1 - connect to target 1, that can run breakpoint commands.
12171 2 - create a dprintf, which resolves fine.
12172 3 - disconnect from target 1
12173 4 - connect to target 2, that can NOT run breakpoint commands.
12175 After steps #3/#4, you'll want the dprintf command list to
12176 be updated, because target 1 and 2 may well return different
12177 answers for target_can_run_breakpoint_commands().
12178 Given absence of finer grained resetting, we get to do
12179 it all the time. */
12180 if (extra_string
!= NULL
)
12181 update_dprintf_command_list (this);
12184 /* Implement the "print_recreate" method for dprintf. */
12187 dprintf_breakpoint::print_recreate (struct ui_file
*fp
) const
12189 gdb_printf (fp
, "dprintf %s,%s", locspec
->to_string (), extra_string
.get ());
12190 print_recreate_thread (fp
);
12193 /* Implement the "after_condition_true" method for dprintf.
12195 dprintf's are implemented with regular commands in their command
12196 list, but we run the commands here instead of before presenting the
12197 stop to the user, as dprintf's don't actually cause a stop. This
12198 also makes it so that the commands of multiple dprintfs at the same
12199 address are all handled. */
12202 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
12204 /* dprintf's never cause a stop. This wasn't set in the
12205 check_status hook instead because that would make the dprintf's
12206 condition not be evaluated. */
12209 /* Run the command list here. Take ownership of it instead of
12210 copying. We never want these commands to run later in
12211 bpstat_do_actions, if a breakpoint that causes a stop happens to
12212 be set at same address as this dprintf, or even if running the
12213 commands here throws. */
12214 counted_command_line cmds
= std::move (bs
->commands
);
12215 gdb_assert (cmds
!= nullptr);
12216 execute_control_commands (cmds
.get (), 0);
12219 /* The breakpoint_ops structure to be used on static tracepoints with
12223 strace_marker_create_sals_from_location_spec (location_spec
*locspec
,
12224 struct linespec_result
*canonical
)
12226 struct linespec_sals lsal
;
12227 const char *arg_start
, *arg
;
12229 arg
= arg_start
= as_linespec_location_spec (locspec
)->spec_string
;
12230 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12232 std::string
str (arg_start
, arg
- arg_start
);
12233 const char *ptr
= str
.c_str ();
12235 = new_linespec_location_spec (&ptr
, symbol_name_match_type::FULL
);
12237 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12238 canonical
->lsals
.push_back (std::move (lsal
));
12242 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12243 struct linespec_result
*canonical
,
12244 gdb::unique_xmalloc_ptr
<char> cond_string
,
12245 gdb::unique_xmalloc_ptr
<char> extra_string
,
12246 enum bptype type_wanted
,
12247 enum bpdisp disposition
,
12249 int task
, int ignore_count
,
12250 int from_tty
, int enabled
,
12251 int internal
, unsigned flags
)
12253 const linespec_sals
&lsal
= canonical
->lsals
[0];
12255 /* If the user is creating a static tracepoint by marker id
12256 (strace -m MARKER_ID), then store the sals index, so that
12257 breakpoint_re_set can try to match up which of the newly
12258 found markers corresponds to this one, and, don't try to
12259 expand multiple locations for each sal, given than SALS
12260 already should contain all sals for MARKER_ID. */
12262 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12264 location_spec_up locspec
= canonical
->locspec
->clone ();
12266 std::unique_ptr
<tracepoint
> tp
12267 (new tracepoint (gdbarch
,
12270 std::move (locspec
),
12272 std::move (cond_string
),
12273 std::move (extra_string
),
12275 thread
, task
, ignore_count
,
12276 from_tty
, enabled
, flags
,
12277 canonical
->special_display
));
12279 /* Given that its possible to have multiple markers with
12280 the same string id, if the user is creating a static
12281 tracepoint by marker id ("strace -m MARKER_ID"), then
12282 store the sals index, so that breakpoint_re_set can
12283 try to match up which of the newly found markers
12284 corresponds to this one */
12285 tp
->static_trace_marker_id_idx
= i
;
12287 install_breakpoint (internal
, std::move (tp
), 0);
12291 std::vector
<symtab_and_line
>
12292 static_marker_tracepoint::decode_location_spec (location_spec
*locspec
,
12293 program_space
*search_pspace
)
12295 const char *s
= as_linespec_location_spec (locspec
)->spec_string
;
12297 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12298 if (sals
.size () > static_trace_marker_id_idx
)
12300 sals
[0] = sals
[static_trace_marker_id_idx
];
12305 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12308 /* Static tracepoints with marker (`-m'). */
12309 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12311 strace_marker_create_sals_from_location_spec
,
12312 strace_marker_create_breakpoints_sal
,
12316 strace_marker_p (struct breakpoint
*b
)
12318 return b
->type
== bp_static_marker_tracepoint
;
12321 /* Delete a breakpoint and clean up all traces of it in the data
12325 delete_breakpoint (struct breakpoint
*bpt
)
12327 gdb_assert (bpt
!= NULL
);
12329 /* Has this bp already been deleted? This can happen because
12330 multiple lists can hold pointers to bp's. bpstat lists are
12333 One example of this happening is a watchpoint's scope bp. When
12334 the scope bp triggers, we notice that the watchpoint is out of
12335 scope, and delete it. We also delete its scope bp. But the
12336 scope bp is marked "auto-deleting", and is already on a bpstat.
12337 That bpstat is then checked for auto-deleting bp's, which are
12340 A real solution to this problem might involve reference counts in
12341 bp's, and/or giving them pointers back to their referencing
12342 bpstat's, and teaching delete_breakpoint to only free a bp's
12343 storage when no more references were extent. A cheaper bandaid
12345 if (bpt
->type
== bp_none
)
12348 /* At least avoid this stale reference until the reference counting
12349 of breakpoints gets resolved. */
12350 if (bpt
->related_breakpoint
!= bpt
)
12352 struct breakpoint
*related
;
12353 struct watchpoint
*w
;
12355 if (bpt
->type
== bp_watchpoint_scope
)
12356 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12357 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12358 w
= (struct watchpoint
*) bpt
;
12362 watchpoint_del_at_next_stop (w
);
12364 /* Unlink bpt from the bpt->related_breakpoint ring. */
12365 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12366 related
= related
->related_breakpoint
);
12367 related
->related_breakpoint
= bpt
->related_breakpoint
;
12368 bpt
->related_breakpoint
= bpt
;
12371 /* watch_command_1 creates a watchpoint but only sets its number if
12372 update_watchpoint succeeds in creating its bp_locations. If there's
12373 a problem in that process, we'll be asked to delete the half-created
12374 watchpoint. In that case, don't announce the deletion. */
12376 gdb::observers::breakpoint_deleted
.notify (bpt
);
12378 if (breakpoint_chain
== bpt
)
12379 breakpoint_chain
= bpt
->next
;
12381 for (breakpoint
*b
: all_breakpoints ())
12382 if (b
->next
== bpt
)
12384 b
->next
= bpt
->next
;
12388 /* Be sure no bpstat's are pointing at the breakpoint after it's
12390 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12391 in all threads for now. Note that we cannot just remove bpstats
12392 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12393 commands are associated with the bpstat; if we remove it here,
12394 then the later call to bpstat_do_actions (&stop_bpstat); in
12395 event-top.c won't do anything, and temporary breakpoints with
12396 commands won't work. */
12398 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12400 /* Now that breakpoint is removed from breakpoint list, update the
12401 global location list. This will remove locations that used to
12402 belong to this breakpoint. Do this before freeing the breakpoint
12403 itself, since remove_breakpoint looks at location's owner. It
12404 might be better design to have location completely
12405 self-contained, but it's not the case now. */
12406 update_global_location_list (UGLL_DONT_INSERT
);
12408 /* On the chance that someone will soon try again to delete this
12409 same bp, we mark it as deleted before freeing its storage. */
12410 bpt
->type
= bp_none
;
12414 /* Iterator function to call a user-provided callback function once
12415 for each of B and its related breakpoints. */
12418 iterate_over_related_breakpoints (struct breakpoint
*b
,
12419 gdb::function_view
<void (breakpoint
*)> function
)
12421 struct breakpoint
*related
;
12426 struct breakpoint
*next
;
12428 /* FUNCTION may delete RELATED. */
12429 next
= related
->related_breakpoint
;
12431 if (next
== related
)
12433 /* RELATED is the last ring entry. */
12434 function (related
);
12436 /* FUNCTION may have deleted it, so we'd never reach back to
12437 B. There's nothing left to do anyway, so just break
12442 function (related
);
12446 while (related
!= b
);
12450 delete_command (const char *arg
, int from_tty
)
12456 int breaks_to_delete
= 0;
12458 /* Delete all breakpoints if no argument. Do not delete
12459 internal breakpoints, these have to be deleted with an
12460 explicit breakpoint number argument. */
12461 for (breakpoint
*b
: all_breakpoints ())
12462 if (user_breakpoint_p (b
))
12464 breaks_to_delete
= 1;
12468 /* Ask user only if there are some breakpoints to delete. */
12470 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12471 for (breakpoint
*b
: all_breakpoints_safe ())
12472 if (user_breakpoint_p (b
))
12473 delete_breakpoint (b
);
12476 map_breakpoint_numbers
12477 (arg
, [&] (breakpoint
*br
)
12479 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12483 /* Return true if all locations of B bound to PSPACE are pending. If
12484 PSPACE is NULL, all locations of all program spaces are
12488 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12490 for (bp_location
*loc
: b
->locations ())
12491 if ((pspace
== NULL
12492 || loc
->pspace
== pspace
)
12493 && !loc
->shlib_disabled
12494 && !loc
->pspace
->executing_startup
)
12499 /* Subroutine of update_breakpoint_locations to simplify it.
12500 Return true if multiple fns in list LOC have the same name.
12501 Null names are ignored. */
12504 ambiguous_names_p (struct bp_location
*loc
)
12506 struct bp_location
*l
;
12507 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12510 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12513 const char *name
= l
->function_name
.get ();
12515 /* Allow for some names to be NULL, ignore them. */
12519 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12521 /* NOTE: We can assume slot != NULL here because xcalloc never
12531 /* When symbols change, it probably means the sources changed as well,
12532 and it might mean the static tracepoint markers are no longer at
12533 the same address or line numbers they used to be at last we
12534 checked. Losing your static tracepoints whenever you rebuild is
12535 undesirable. This function tries to resync/rematch gdb static
12536 tracepoints with the markers on the target, for static tracepoints
12537 that have not been set by marker id. Static tracepoint that have
12538 been set by marker id are reset by marker id in breakpoint_re_set.
12541 1) For a tracepoint set at a specific address, look for a marker at
12542 the old PC. If one is found there, assume to be the same marker.
12543 If the name / string id of the marker found is different from the
12544 previous known name, assume that means the user renamed the marker
12545 in the sources, and output a warning.
12547 2) For a tracepoint set at a given line number, look for a marker
12548 at the new address of the old line number. If one is found there,
12549 assume to be the same marker. If the name / string id of the
12550 marker found is different from the previous known name, assume that
12551 means the user renamed the marker in the sources, and output a
12554 3) If a marker is no longer found at the same address or line, it
12555 may mean the marker no longer exists. But it may also just mean
12556 the code changed a bit. Maybe the user added a few lines of code
12557 that made the marker move up or down (in line number terms). Ask
12558 the target for info about the marker with the string id as we knew
12559 it. If found, update line number and address in the matching
12560 static tracepoint. This will get confused if there's more than one
12561 marker with the same ID (possible in UST, although unadvised
12562 precisely because it confuses tools). */
12564 static struct symtab_and_line
12565 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12567 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12568 struct static_tracepoint_marker marker
;
12573 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12575 if (target_static_tracepoint_marker_at (pc
, &marker
))
12577 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12578 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12579 b
->number
, tp
->static_trace_marker_id
.c_str (),
12580 marker
.str_id
.c_str ());
12582 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12587 /* Old marker wasn't found on target at lineno. Try looking it up
12589 if (!sal
.explicit_pc
12591 && sal
.symtab
!= NULL
12592 && !tp
->static_trace_marker_id
.empty ())
12594 std::vector
<static_tracepoint_marker
> markers
12595 = target_static_tracepoint_markers_by_strid
12596 (tp
->static_trace_marker_id
.c_str ());
12598 if (!markers
.empty ())
12600 struct symbol
*sym
;
12601 struct static_tracepoint_marker
*tpmarker
;
12602 struct ui_out
*uiout
= current_uiout
;
12604 tpmarker
= &markers
[0];
12606 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12608 warning (_("marker for static tracepoint %d (%s) not "
12609 "found at previous line number"),
12610 b
->number
, tp
->static_trace_marker_id
.c_str ());
12612 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12613 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12614 uiout
->text ("Now in ");
12617 uiout
->field_string ("func", sym
->print_name (),
12618 function_name_style
.style ());
12619 uiout
->text (" at ");
12621 uiout
->field_string ("file",
12622 symtab_to_filename_for_display (sal2
.symtab
),
12623 file_name_style
.style ());
12626 if (uiout
->is_mi_like_p ())
12628 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12630 uiout
->field_string ("fullname", fullname
);
12633 uiout
->field_signed ("line", sal2
.line
);
12634 uiout
->text ("\n");
12636 b
->loc
->line_number
= sal2
.line
;
12637 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12639 std::unique_ptr
<explicit_location_spec
> els
12640 (new explicit_location_spec ());
12641 els
->source_filename
12642 = xstrdup (symtab_to_filename_for_display (sal2
.symtab
));
12643 els
->line_offset
.offset
= b
->loc
->line_number
;
12644 els
->line_offset
.sign
= LINE_OFFSET_NONE
;
12646 b
->locspec
= std::move (els
);
12648 /* Might be nice to check if function changed, and warn if
12655 /* Returns true iff locations A and B are sufficiently same that
12656 we don't need to report breakpoint as changed. */
12659 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12663 if (a
->address
!= b
->address
)
12666 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12669 if (a
->enabled
!= b
->enabled
)
12672 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12679 if ((a
== NULL
) != (b
== NULL
))
12685 /* Split all locations of B that are bound to PSPACE out of B's
12686 location list to a separate list and return that list's head. If
12687 PSPACE is NULL, hoist out all locations of B. */
12689 static struct bp_location
*
12690 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12692 struct bp_location head
;
12693 struct bp_location
*i
= b
->loc
;
12694 struct bp_location
**i_link
= &b
->loc
;
12695 struct bp_location
*hoisted
= &head
;
12697 if (pspace
== NULL
)
12708 if (i
->pspace
== pspace
)
12723 /* Create new breakpoint locations for B (a hardware or software
12724 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12725 zero, then B is a ranged breakpoint. Only recreates locations for
12726 FILTER_PSPACE. Locations of other program spaces are left
12730 update_breakpoint_locations (code_breakpoint
*b
,
12731 struct program_space
*filter_pspace
,
12732 gdb::array_view
<const symtab_and_line
> sals
,
12733 gdb::array_view
<const symtab_and_line
> sals_end
)
12735 struct bp_location
*existing_locations
;
12737 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12739 /* Ranged breakpoints have only one start location and one end
12741 b
->enable_state
= bp_disabled
;
12742 gdb_printf (gdb_stderr
,
12743 _("Could not reset ranged breakpoint %d: "
12744 "multiple locations found\n"),
12749 /* If there's no new locations, and all existing locations are
12750 pending, don't do anything. This optimizes the common case where
12751 all locations are in the same shared library, that was unloaded.
12752 We'd like to retain the location, so that when the library is
12753 loaded again, we don't loose the enabled/disabled status of the
12754 individual locations. */
12755 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12758 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12760 for (const auto &sal
: sals
)
12762 struct bp_location
*new_loc
;
12764 switch_to_program_space_and_thread (sal
.pspace
);
12766 new_loc
= b
->add_location (sal
);
12768 /* Reparse conditions, they might contain references to the
12770 if (b
->cond_string
!= NULL
)
12774 s
= b
->cond_string
.get ();
12777 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12778 block_for_pc (sal
.pc
),
12781 catch (const gdb_exception_error
&e
)
12783 new_loc
->disabled_by_cond
= true;
12787 if (!sals_end
.empty ())
12789 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12791 new_loc
->length
= end
- sals
[0].pc
+ 1;
12795 /* If possible, carry over 'disable' status from existing
12798 struct bp_location
*e
= existing_locations
;
12799 /* If there are multiple breakpoints with the same function name,
12800 e.g. for inline functions, comparing function names won't work.
12801 Instead compare pc addresses; this is just a heuristic as things
12802 may have moved, but in practice it gives the correct answer
12803 often enough until a better solution is found. */
12804 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12806 for (; e
; e
= e
->next
)
12808 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12810 if (have_ambiguous_names
)
12812 for (bp_location
*l
: b
->locations ())
12814 /* Ignore software vs hardware location type at
12815 this point, because with "set breakpoint
12816 auto-hw", after a re-set, locations that were
12817 hardware can end up as software, or vice versa.
12818 As mentioned above, this is an heuristic and in
12819 practice should give the correct answer often
12821 if (breakpoint_locations_match (e
, l
, true))
12823 l
->enabled
= e
->enabled
;
12824 l
->disabled_by_cond
= e
->disabled_by_cond
;
12831 for (bp_location
*l
: b
->locations ())
12832 if (l
->function_name
12833 && strcmp (e
->function_name
.get (),
12834 l
->function_name
.get ()) == 0)
12836 l
->enabled
= e
->enabled
;
12837 l
->disabled_by_cond
= e
->disabled_by_cond
;
12845 if (!locations_are_equal (existing_locations
, b
->loc
))
12846 gdb::observers::breakpoint_modified
.notify (b
);
12849 /* Find the SaL locations corresponding to the given LOCSPEC.
12850 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12852 std::vector
<symtab_and_line
>
12853 code_breakpoint::location_spec_to_sals (location_spec
*locspec
,
12854 struct program_space
*search_pspace
,
12857 struct gdb_exception exception
;
12859 std::vector
<symtab_and_line
> sals
;
12863 sals
= decode_location_spec (locspec
, search_pspace
);
12865 catch (gdb_exception_error
&e
)
12867 int not_found_and_ok
= false;
12869 /* For pending breakpoints, it's expected that parsing will
12870 fail until the right shared library is loaded. User has
12871 already told to create pending breakpoints and don't need
12872 extra messages. If breakpoint is in bp_shlib_disabled
12873 state, then user already saw the message about that
12874 breakpoint being disabled, and don't want to see more
12876 if (e
.error
== NOT_FOUND_ERROR
12877 && (condition_not_parsed
12879 && search_pspace
!= NULL
12880 && loc
->pspace
!= search_pspace
)
12881 || (loc
&& loc
->shlib_disabled
)
12882 || (loc
&& loc
->pspace
->executing_startup
)
12883 || enable_state
== bp_disabled
))
12884 not_found_and_ok
= true;
12886 if (!not_found_and_ok
)
12888 /* We surely don't want to warn about the same breakpoint
12889 10 times. One solution, implemented here, is disable
12890 the breakpoint on error. Another solution would be to
12891 have separate 'warning emitted' flag. Since this
12892 happens only when a binary has changed, I don't know
12893 which approach is better. */
12894 enable_state
= bp_disabled
;
12898 exception
= std::move (e
);
12901 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
12903 for (auto &sal
: sals
)
12904 resolve_sal_pc (&sal
);
12905 if (condition_not_parsed
&& extra_string
!= NULL
)
12907 gdb::unique_xmalloc_ptr
<char> local_cond
, local_extra
;
12908 int local_thread
, local_task
;
12910 find_condition_and_thread_for_sals (sals
, extra_string
.get (),
12911 &local_cond
, &local_thread
,
12912 &local_task
, &local_extra
);
12913 gdb_assert (cond_string
== nullptr);
12914 if (local_cond
!= nullptr)
12915 cond_string
= std::move (local_cond
);
12916 thread
= local_thread
;
12918 if (local_extra
!= nullptr)
12919 extra_string
= std::move (local_extra
);
12920 condition_not_parsed
= 0;
12923 if (type
== bp_static_tracepoint
)
12924 sals
[0] = update_static_tracepoint (this, sals
[0]);
12934 /* The default re_set method, for typical hardware or software
12935 breakpoints. Reevaluate the breakpoint and recreate its
12939 code_breakpoint::re_set_default ()
12941 struct program_space
*filter_pspace
= current_program_space
;
12942 std::vector
<symtab_and_line
> expanded
, expanded_end
;
12945 std::vector
<symtab_and_line
> sals
= location_spec_to_sals (locspec
.get (),
12949 expanded
= std::move (sals
);
12951 if (locspec_range_end
!= nullptr)
12953 std::vector
<symtab_and_line
> sals_end
12954 = location_spec_to_sals (locspec_range_end
.get (),
12955 filter_pspace
, &found
);
12957 expanded_end
= std::move (sals_end
);
12960 update_breakpoint_locations (this, filter_pspace
, expanded
, expanded_end
);
12963 /* Default method for creating SALs from an address string. It basically
12964 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12967 create_sals_from_location_spec_default (location_spec
*locspec
,
12968 struct linespec_result
*canonical
)
12970 parse_breakpoint_sals (locspec
, canonical
);
12973 /* Reset a breakpoint. */
12976 breakpoint_re_set_one (breakpoint
*b
)
12978 input_radix
= b
->input_radix
;
12979 set_language (b
->language
);
12984 /* Re-set breakpoint locations for the current program space.
12985 Locations bound to other program spaces are left untouched. */
12988 breakpoint_re_set (void)
12991 scoped_restore_current_language save_language
;
12992 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
12993 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12995 /* breakpoint_re_set_one sets the current_language to the language
12996 of the breakpoint it is resetting (see prepare_re_set_context)
12997 before re-evaluating the breakpoint's location. This change can
12998 unfortunately get undone by accident if the language_mode is set
12999 to auto, and we either switch frames, or more likely in this context,
13000 we select the current frame.
13002 We prevent this by temporarily turning the language_mode to
13003 language_mode_manual. We restore it once all breakpoints
13004 have been reset. */
13005 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13006 language_mode
= language_mode_manual
;
13008 /* Note: we must not try to insert locations until after all
13009 breakpoints have been re-set. Otherwise, e.g., when re-setting
13010 breakpoint 1, we'd insert the locations of breakpoint 2, which
13011 hadn't been re-set yet, and thus may have stale locations. */
13013 for (breakpoint
*b
: all_breakpoints_safe ())
13017 breakpoint_re_set_one (b
);
13019 catch (const gdb_exception
&ex
)
13021 exception_fprintf (gdb_stderr
, ex
,
13022 "Error in re-setting breakpoint %d: ",
13027 jit_breakpoint_re_set ();
13030 create_overlay_event_breakpoint ();
13031 create_longjmp_master_breakpoint ();
13032 create_std_terminate_master_breakpoint ();
13033 create_exception_master_breakpoint ();
13035 /* Now we can insert. */
13036 update_global_location_list (UGLL_MAY_INSERT
);
13039 /* Reset the thread number of this breakpoint:
13041 - If the breakpoint is for all threads, leave it as-is.
13042 - Else, reset it to the current thread for inferior_ptid. */
13044 breakpoint_re_set_thread (struct breakpoint
*b
)
13046 if (b
->thread
!= -1)
13048 b
->thread
= inferior_thread ()->global_num
;
13050 /* We're being called after following a fork. The new fork is
13051 selected as current, and unless this was a vfork will have a
13052 different program space from the original thread. Reset that
13054 b
->loc
->pspace
= current_program_space
;
13058 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13059 If from_tty is nonzero, it prints a message to that effect,
13060 which ends with a period (no newline). */
13063 set_ignore_count (int bptnum
, int count
, int from_tty
)
13068 for (breakpoint
*b
: all_breakpoints ())
13069 if (b
->number
== bptnum
)
13071 if (is_tracepoint (b
))
13073 if (from_tty
&& count
!= 0)
13074 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13079 b
->ignore_count
= count
;
13083 gdb_printf (_("Will stop next time "
13084 "breakpoint %d is reached."),
13086 else if (count
== 1)
13087 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13090 gdb_printf (_("Will ignore next %d "
13091 "crossings of breakpoint %d."),
13094 gdb::observers::breakpoint_modified
.notify (b
);
13098 error (_("No breakpoint number %d."), bptnum
);
13101 /* Command to set ignore-count of breakpoint N to COUNT. */
13104 ignore_command (const char *args
, int from_tty
)
13106 const char *p
= args
;
13110 error_no_arg (_("a breakpoint number"));
13112 num
= get_number (&p
);
13114 error (_("bad breakpoint number: '%s'"), args
);
13116 error (_("Second argument (specified ignore-count) is missing."));
13118 set_ignore_count (num
,
13119 longest_to_int (value_as_long (parse_and_eval (p
))),
13126 /* Call FUNCTION on each of the breakpoints with numbers in the range
13127 defined by BP_NUM_RANGE (an inclusive range). */
13130 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13131 gdb::function_view
<void (breakpoint
*)> function
)
13133 if (bp_num_range
.first
== 0)
13135 warning (_("bad breakpoint number at or near '%d'"),
13136 bp_num_range
.first
);
13140 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13142 bool match
= false;
13144 for (breakpoint
*b
: all_breakpoints_safe ())
13145 if (b
->number
== i
)
13152 gdb_printf (_("No breakpoint number %d.\n"), i
);
13157 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13161 map_breakpoint_numbers (const char *args
,
13162 gdb::function_view
<void (breakpoint
*)> function
)
13164 if (args
== NULL
|| *args
== '\0')
13165 error_no_arg (_("one or more breakpoint numbers"));
13167 number_or_range_parser
parser (args
);
13169 while (!parser
.finished ())
13171 int num
= parser
.get_number ();
13172 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13176 /* Return the breakpoint location structure corresponding to the
13177 BP_NUM and LOC_NUM values. */
13179 static struct bp_location
*
13180 find_location_by_number (int bp_num
, int loc_num
)
13182 breakpoint
*b
= get_breakpoint (bp_num
);
13184 if (!b
|| b
->number
!= bp_num
)
13185 error (_("Bad breakpoint number '%d'"), bp_num
);
13188 error (_("Bad breakpoint location number '%d'"), loc_num
);
13191 for (bp_location
*loc
: b
->locations ())
13192 if (++n
== loc_num
)
13195 error (_("Bad breakpoint location number '%d'"), loc_num
);
13198 /* Modes of operation for extract_bp_num. */
13199 enum class extract_bp_kind
13201 /* Extracting a breakpoint number. */
13204 /* Extracting a location number. */
13208 /* Extract a breakpoint or location number (as determined by KIND)
13209 from the string starting at START. TRAILER is a character which
13210 can be found after the number. If you don't want a trailer, use
13211 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13212 string. This always returns a positive integer. */
13215 extract_bp_num (extract_bp_kind kind
, const char *start
,
13216 int trailer
, const char **end_out
= NULL
)
13218 const char *end
= start
;
13219 int num
= get_number_trailer (&end
, trailer
);
13221 error (kind
== extract_bp_kind::bp
13222 ? _("Negative breakpoint number '%.*s'")
13223 : _("Negative breakpoint location number '%.*s'"),
13224 int (end
- start
), start
);
13226 error (kind
== extract_bp_kind::bp
13227 ? _("Bad breakpoint number '%.*s'")
13228 : _("Bad breakpoint location number '%.*s'"),
13229 int (end
- start
), start
);
13231 if (end_out
!= NULL
)
13236 /* Extract a breakpoint or location range (as determined by KIND) in
13237 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13238 representing the (inclusive) range. The returned pair's elements
13239 are always positive integers. */
13241 static std::pair
<int, int>
13242 extract_bp_or_bp_range (extract_bp_kind kind
,
13243 const std::string
&arg
,
13244 std::string::size_type arg_offset
)
13246 std::pair
<int, int> range
;
13247 const char *bp_loc
= &arg
[arg_offset
];
13248 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13249 if (dash
!= std::string::npos
)
13251 /* bp_loc is a range (x-z). */
13252 if (arg
.length () == dash
+ 1)
13253 error (kind
== extract_bp_kind::bp
13254 ? _("Bad breakpoint number at or near: '%s'")
13255 : _("Bad breakpoint location number at or near: '%s'"),
13259 const char *start_first
= bp_loc
;
13260 const char *start_second
= &arg
[dash
+ 1];
13261 range
.first
= extract_bp_num (kind
, start_first
, '-');
13262 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13264 if (range
.first
> range
.second
)
13265 error (kind
== extract_bp_kind::bp
13266 ? _("Inverted breakpoint range at '%.*s'")
13267 : _("Inverted breakpoint location range at '%.*s'"),
13268 int (end
- start_first
), start_first
);
13272 /* bp_loc is a single value. */
13273 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13274 range
.second
= range
.first
;
13279 /* Extract the breakpoint/location range specified by ARG. Returns
13280 the breakpoint range in BP_NUM_RANGE, and the location range in
13283 ARG may be in any of the following forms:
13285 x where 'x' is a breakpoint number.
13286 x-y where 'x' and 'y' specify a breakpoint numbers range.
13287 x.y where 'x' is a breakpoint number and 'y' a location number.
13288 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13289 location number range.
13293 extract_bp_number_and_location (const std::string
&arg
,
13294 std::pair
<int, int> &bp_num_range
,
13295 std::pair
<int, int> &bp_loc_range
)
13297 std::string::size_type dot
= arg
.find ('.');
13299 if (dot
!= std::string::npos
)
13301 /* Handle 'x.y' and 'x.y-z' cases. */
13303 if (arg
.length () == dot
+ 1 || dot
== 0)
13304 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13307 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13308 bp_num_range
.second
= bp_num_range
.first
;
13310 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13315 /* Handle x and x-y cases. */
13317 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13318 bp_loc_range
.first
= 0;
13319 bp_loc_range
.second
= 0;
13323 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13324 specifies whether to enable or disable. */
13327 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13329 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13332 if (loc
->disabled_by_cond
&& enable
)
13333 error (_("Breakpoint %d's condition is invalid at location %d, "
13334 "cannot enable."), bp_num
, loc_num
);
13336 if (loc
->enabled
!= enable
)
13338 loc
->enabled
= enable
;
13339 mark_breakpoint_location_modified (loc
);
13341 if (target_supports_enable_disable_tracepoint ()
13342 && current_trace_status ()->running
&& loc
->owner
13343 && is_tracepoint (loc
->owner
))
13344 target_disable_tracepoint (loc
);
13346 update_global_location_list (UGLL_DONT_INSERT
);
13348 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13351 /* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
13352 owner. 1-based indexing. -1 signals NOT FOUND. */
13355 find_loc_num_by_location (const bp_location
*loc
)
13357 if (loc
!= nullptr && loc
->owner
!= nullptr)
13359 /* Locations use 1-based indexing. */
13361 for (bp_location
*it
: loc
->owner
->locations ())
13371 /* Enable or disable a breakpoint location LOC. ENABLE
13372 specifies whether to enable or disable. */
13375 enable_disable_bp_location (bp_location
*loc
, bool enable
)
13377 if (loc
== nullptr)
13378 error (_("Breakpoint location is invalid."));
13380 if (loc
->owner
== nullptr)
13381 error (_("Breakpoint location does not have an owner breakpoint."));
13383 if (loc
->disabled_by_cond
&& enable
)
13385 int loc_num
= find_loc_num_by_location (loc
);
13387 error (_("Breakpoint location LOC_NUM could not be found."));
13389 error (_("Breakpoint %d's condition is invalid at location %d, "
13390 "cannot enable."), loc
->owner
->number
, loc_num
);
13393 if (loc
->enabled
!= enable
)
13395 loc
->enabled
= enable
;
13396 mark_breakpoint_location_modified (loc
);
13399 if (target_supports_enable_disable_tracepoint ()
13400 && current_trace_status ()->running
&& loc
->owner
13401 && is_tracepoint (loc
->owner
))
13402 target_disable_tracepoint (loc
);
13404 update_global_location_list (UGLL_DONT_INSERT
);
13405 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13408 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13409 number of the breakpoint, and BP_LOC_RANGE specifies the
13410 (inclusive) range of location numbers of that breakpoint to
13411 enable/disable. ENABLE specifies whether to enable or disable the
13415 enable_disable_breakpoint_location_range (int bp_num
,
13416 std::pair
<int, int> &bp_loc_range
,
13419 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13420 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13423 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13424 If from_tty is nonzero, it prints a message to that effect,
13425 which ends with a period (no newline). */
13428 disable_breakpoint (struct breakpoint
*bpt
)
13430 /* Never disable a watchpoint scope breakpoint; we want to
13431 hit them when we leave scope so we can delete both the
13432 watchpoint and its scope breakpoint at that time. */
13433 if (bpt
->type
== bp_watchpoint_scope
)
13436 bpt
->enable_state
= bp_disabled
;
13438 /* Mark breakpoint locations modified. */
13439 mark_breakpoint_modified (bpt
);
13441 if (target_supports_enable_disable_tracepoint ()
13442 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13444 for (bp_location
*location
: bpt
->locations ())
13445 target_disable_tracepoint (location
);
13448 update_global_location_list (UGLL_DONT_INSERT
);
13450 gdb::observers::breakpoint_modified
.notify (bpt
);
13453 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13454 specified in ARGS. ARGS may be in any of the formats handled by
13455 extract_bp_number_and_location. ENABLE specifies whether to enable
13456 or disable the breakpoints/locations. */
13459 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13463 for (breakpoint
*bpt
: all_breakpoints ())
13464 if (user_breakpoint_p (bpt
))
13467 enable_breakpoint (bpt
);
13469 disable_breakpoint (bpt
);
13474 std::string num
= extract_arg (&args
);
13476 while (!num
.empty ())
13478 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13480 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13482 if (bp_loc_range
.first
== bp_loc_range
.second
13483 && (bp_loc_range
.first
== 0
13484 || (bp_loc_range
.first
== 1
13485 && bp_num_range
.first
== bp_num_range
.second
13486 && !has_multiple_locations (bp_num_range
.first
))))
13488 /* Handle breakpoint ids with formats 'x' or 'x-z'
13489 or 'y.1' where y has only one code location. */
13490 map_breakpoint_number_range (bp_num_range
,
13492 ? enable_breakpoint
13493 : disable_breakpoint
);
13497 /* Handle breakpoint ids with formats 'x.y' or
13499 enable_disable_breakpoint_location_range
13500 (bp_num_range
.first
, bp_loc_range
, enable
);
13502 num
= extract_arg (&args
);
13507 /* The disable command disables the specified breakpoints/locations
13508 (or all defined breakpoints) so they're no longer effective in
13509 stopping the inferior. ARGS may be in any of the forms defined in
13510 extract_bp_number_and_location. */
13513 disable_command (const char *args
, int from_tty
)
13515 enable_disable_command (args
, from_tty
, false);
13519 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13522 int target_resources_ok
;
13524 if (bpt
->type
== bp_hardware_breakpoint
)
13527 i
= hw_breakpoint_used_count ();
13528 target_resources_ok
=
13529 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13531 if (target_resources_ok
== 0)
13532 error (_("No hardware breakpoint support in the target."));
13533 else if (target_resources_ok
< 0)
13534 error (_("Hardware breakpoints used exceeds limit."));
13537 if (is_watchpoint (bpt
))
13539 /* Initialize it just to avoid a GCC false warning. */
13540 enum enable_state orig_enable_state
= bp_disabled
;
13544 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13546 orig_enable_state
= bpt
->enable_state
;
13547 bpt
->enable_state
= bp_enabled
;
13548 update_watchpoint (w
, true /* reparse */);
13550 catch (const gdb_exception_error
&e
)
13552 bpt
->enable_state
= orig_enable_state
;
13553 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13559 bpt
->enable_state
= bp_enabled
;
13561 /* Mark breakpoint locations modified. */
13562 mark_breakpoint_modified (bpt
);
13564 if (target_supports_enable_disable_tracepoint ()
13565 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13567 for (bp_location
*location
: bpt
->locations ())
13568 target_enable_tracepoint (location
);
13571 bpt
->disposition
= disposition
;
13572 bpt
->enable_count
= count
;
13573 update_global_location_list (UGLL_MAY_INSERT
);
13575 gdb::observers::breakpoint_modified
.notify (bpt
);
13580 enable_breakpoint (struct breakpoint
*bpt
)
13582 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13585 /* The enable command enables the specified breakpoints/locations (or
13586 all defined breakpoints) so they once again become (or continue to
13587 be) effective in stopping the inferior. ARGS may be in any of the
13588 forms defined in extract_bp_number_and_location. */
13591 enable_command (const char *args
, int from_tty
)
13593 enable_disable_command (args
, from_tty
, true);
13597 enable_once_command (const char *args
, int from_tty
)
13599 map_breakpoint_numbers
13600 (args
, [&] (breakpoint
*b
)
13602 iterate_over_related_breakpoints
13603 (b
, [&] (breakpoint
*bpt
)
13605 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13611 enable_count_command (const char *args
, int from_tty
)
13616 error_no_arg (_("hit count"));
13618 count
= get_number (&args
);
13620 map_breakpoint_numbers
13621 (args
, [&] (breakpoint
*b
)
13623 iterate_over_related_breakpoints
13624 (b
, [&] (breakpoint
*bpt
)
13626 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13632 enable_delete_command (const char *args
, int from_tty
)
13634 map_breakpoint_numbers
13635 (args
, [&] (breakpoint
*b
)
13637 iterate_over_related_breakpoints
13638 (b
, [&] (breakpoint
*bpt
)
13640 enable_breakpoint_disp (bpt
, disp_del
, 1);
13645 /* Invalidate last known value of any hardware watchpoint if
13646 the memory which that value represents has been written to by
13650 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13651 CORE_ADDR addr
, ssize_t len
,
13652 const bfd_byte
*data
)
13654 for (breakpoint
*bp
: all_breakpoints ())
13655 if (bp
->enable_state
== bp_enabled
13656 && bp
->type
== bp_hardware_watchpoint
)
13658 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13660 if (wp
->val_valid
&& wp
->val
!= nullptr)
13662 for (bp_location
*loc
: bp
->locations ())
13663 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13664 && loc
->address
+ loc
->length
> addr
13665 && addr
+ len
> loc
->address
)
13668 wp
->val_valid
= false;
13674 /* Create and insert a breakpoint for software single step. */
13677 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13678 const address_space
*aspace
,
13681 struct thread_info
*tp
= inferior_thread ();
13682 struct symtab_and_line sal
;
13683 CORE_ADDR pc
= next_pc
;
13685 if (tp
->control
.single_step_breakpoints
== NULL
)
13687 std::unique_ptr
<breakpoint
> b
13688 (new momentary_breakpoint (gdbarch
, bp_single_step
,
13689 current_program_space
,
13693 tp
->control
.single_step_breakpoints
13694 = add_to_breakpoint_chain (std::move (b
));
13697 sal
= find_pc_line (pc
, 0);
13699 sal
.section
= find_pc_overlay (pc
);
13700 sal
.explicit_pc
= 1;
13703 = (gdb::checked_static_cast
<momentary_breakpoint
*>
13704 (tp
->control
.single_step_breakpoints
));
13705 ss_bp
->add_location (sal
);
13707 update_global_location_list (UGLL_INSERT
);
13710 /* Insert single step breakpoints according to the current state. */
13713 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13715 struct regcache
*regcache
= get_current_regcache ();
13716 std::vector
<CORE_ADDR
> next_pcs
;
13718 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13720 if (!next_pcs
.empty ())
13722 frame_info_ptr frame
= get_current_frame ();
13723 const address_space
*aspace
= get_frame_address_space (frame
);
13725 for (CORE_ADDR pc
: next_pcs
)
13726 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13734 /* See breakpoint.h. */
13737 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13738 const address_space
*aspace
,
13741 for (bp_location
*loc
: bp
->locations ())
13743 && breakpoint_location_address_match (loc
, aspace
, pc
))
13749 /* Check whether a software single-step breakpoint is inserted at
13753 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13756 for (breakpoint
*bpt
: all_breakpoints ())
13758 if (bpt
->type
== bp_single_step
13759 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13765 /* Tracepoint-specific operations. */
13767 /* Set tracepoint count to NUM. */
13769 set_tracepoint_count (int num
)
13771 tracepoint_count
= num
;
13772 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13776 trace_command (const char *arg
, int from_tty
)
13778 location_spec_up locspec
= string_to_location_spec (&arg
,
13780 const struct breakpoint_ops
*ops
= breakpoint_ops_for_location_spec
13781 (locspec
.get (), true /* is_tracepoint */);
13783 create_breakpoint (get_current_arch (),
13785 NULL
, 0, arg
, false, 1 /* parse arg */,
13787 bp_tracepoint
/* type_wanted */,
13788 0 /* Ignore count */,
13789 pending_break_support
,
13793 0 /* internal */, 0);
13797 ftrace_command (const char *arg
, int from_tty
)
13799 location_spec_up locspec
= string_to_location_spec (&arg
,
13801 create_breakpoint (get_current_arch (),
13803 NULL
, 0, arg
, false, 1 /* parse arg */,
13805 bp_fast_tracepoint
/* type_wanted */,
13806 0 /* Ignore count */,
13807 pending_break_support
,
13808 &code_breakpoint_ops
,
13811 0 /* internal */, 0);
13814 /* strace command implementation. Creates a static tracepoint. */
13817 strace_command (const char *arg
, int from_tty
)
13819 const struct breakpoint_ops
*ops
;
13820 location_spec_up locspec
;
13823 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13824 or with a normal static tracepoint. */
13825 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13827 ops
= &strace_marker_breakpoint_ops
;
13828 locspec
= new_linespec_location_spec (&arg
,
13829 symbol_name_match_type::FULL
);
13830 type
= bp_static_marker_tracepoint
;
13834 ops
= &code_breakpoint_ops
;
13835 locspec
= string_to_location_spec (&arg
, current_language
);
13836 type
= bp_static_tracepoint
;
13839 create_breakpoint (get_current_arch (),
13841 NULL
, 0, arg
, false, 1 /* parse arg */,
13843 type
/* type_wanted */,
13844 0 /* Ignore count */,
13845 pending_break_support
,
13849 0 /* internal */, 0);
13852 /* Set up a fake reader function that gets command lines from a linked
13853 list that was acquired during tracepoint uploading. */
13855 static struct uploaded_tp
*this_utp
;
13856 static int next_cmd
;
13858 static const char *
13859 read_uploaded_action (std::string
&buffer
)
13861 char *rslt
= nullptr;
13863 if (next_cmd
< this_utp
->cmd_strings
.size ())
13865 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13872 /* Given information about a tracepoint as recorded on a target (which
13873 can be either a live system or a trace file), attempt to create an
13874 equivalent GDB tracepoint. This is not a reliable process, since
13875 the target does not necessarily have all the information used when
13876 the tracepoint was originally defined. */
13878 struct tracepoint
*
13879 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13881 const char *addr_str
;
13882 char small_buf
[100];
13883 struct tracepoint
*tp
;
13885 if (utp
->at_string
)
13886 addr_str
= utp
->at_string
.get ();
13889 /* In the absence of a source location, fall back to raw
13890 address. Since there is no way to confirm that the address
13891 means the same thing as when the trace was started, warn the
13893 warning (_("Uploaded tracepoint %d has no "
13894 "source location, using raw address"),
13896 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13897 addr_str
= small_buf
;
13900 /* There's not much we can do with a sequence of bytecodes. */
13901 if (utp
->cond
&& !utp
->cond_string
)
13902 warning (_("Uploaded tracepoint %d condition "
13903 "has no source form, ignoring it"),
13906 location_spec_up locspec
= string_to_location_spec (&addr_str
,
13908 if (!create_breakpoint (get_current_arch (),
13910 utp
->cond_string
.get (), -1, addr_str
,
13911 false /* force_condition */,
13912 0 /* parse cond/thread */,
13914 utp
->type
/* type_wanted */,
13915 0 /* Ignore count */,
13916 pending_break_support
,
13917 &code_breakpoint_ops
,
13919 utp
->enabled
/* enabled */,
13921 CREATE_BREAKPOINT_FLAGS_INSERTED
))
13924 /* Get the tracepoint we just created. */
13925 tp
= get_tracepoint (tracepoint_count
);
13926 gdb_assert (tp
!= NULL
);
13930 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
13933 trace_pass_command (small_buf
, 0);
13936 /* If we have uploaded versions of the original commands, set up a
13937 special-purpose "reader" function and call the usual command line
13938 reader, then pass the result to the breakpoint command-setting
13940 if (!utp
->cmd_strings
.empty ())
13942 counted_command_line cmd_list
;
13947 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
13949 breakpoint_set_commands (tp
, std::move (cmd_list
));
13951 else if (!utp
->actions
.empty ()
13952 || !utp
->step_actions
.empty ())
13953 warning (_("Uploaded tracepoint %d actions "
13954 "have no source form, ignoring them"),
13957 /* Copy any status information that might be available. */
13958 tp
->hit_count
= utp
->hit_count
;
13959 tp
->traceframe_usage
= utp
->traceframe_usage
;
13964 /* Print information on tracepoint number TPNUM_EXP, or all if
13968 info_tracepoints_command (const char *args
, int from_tty
)
13970 struct ui_out
*uiout
= current_uiout
;
13973 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
13975 if (num_printed
== 0)
13977 if (args
== NULL
|| *args
== '\0')
13978 uiout
->message ("No tracepoints.\n");
13980 uiout
->message ("No tracepoint matching '%s'.\n", args
);
13983 default_collect_info ();
13986 /* The 'enable trace' command enables tracepoints.
13987 Not supported by all targets. */
13989 enable_trace_command (const char *args
, int from_tty
)
13991 enable_command (args
, from_tty
);
13994 /* The 'disable trace' command disables tracepoints.
13995 Not supported by all targets. */
13997 disable_trace_command (const char *args
, int from_tty
)
13999 disable_command (args
, from_tty
);
14002 /* Remove a tracepoint (or all if no argument). */
14004 delete_trace_command (const char *arg
, int from_tty
)
14010 int breaks_to_delete
= 0;
14012 /* Delete all breakpoints if no argument.
14013 Do not delete internal or call-dummy breakpoints, these
14014 have to be deleted with an explicit breakpoint number
14016 for (breakpoint
*tp
: all_tracepoints ())
14017 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14019 breaks_to_delete
= 1;
14023 /* Ask user only if there are some breakpoints to delete. */
14025 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14027 for (breakpoint
*b
: all_breakpoints_safe ())
14028 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14029 delete_breakpoint (b
);
14033 map_breakpoint_numbers
14034 (arg
, [&] (breakpoint
*br
)
14036 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14040 /* Helper function for trace_pass_command. */
14043 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14045 tp
->pass_count
= count
;
14046 gdb::observers::breakpoint_modified
.notify (tp
);
14048 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14049 tp
->number
, count
);
14052 /* Set passcount for tracepoint.
14054 First command argument is passcount, second is tracepoint number.
14055 If tracepoint number omitted, apply to most recently defined.
14056 Also accepts special argument "all". */
14059 trace_pass_command (const char *args
, int from_tty
)
14061 struct tracepoint
*t1
;
14064 if (args
== 0 || *args
== 0)
14065 error (_("passcount command requires an "
14066 "argument (count + optional TP num)"));
14068 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14070 args
= skip_spaces (args
);
14071 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14073 args
+= 3; /* Skip special argument "all". */
14075 error (_("Junk at end of arguments."));
14077 for (breakpoint
*b
: all_tracepoints ())
14079 t1
= (struct tracepoint
*) b
;
14080 trace_pass_set_count (t1
, count
, from_tty
);
14083 else if (*args
== '\0')
14085 t1
= get_tracepoint_by_number (&args
, NULL
);
14087 trace_pass_set_count (t1
, count
, from_tty
);
14091 number_or_range_parser
parser (args
);
14092 while (!parser
.finished ())
14094 t1
= get_tracepoint_by_number (&args
, &parser
);
14096 trace_pass_set_count (t1
, count
, from_tty
);
14101 struct tracepoint
*
14102 get_tracepoint (int num
)
14104 for (breakpoint
*t
: all_tracepoints ())
14105 if (t
->number
== num
)
14106 return (struct tracepoint
*) t
;
14111 /* Find the tracepoint with the given target-side number (which may be
14112 different from the tracepoint number after disconnecting and
14115 struct tracepoint
*
14116 get_tracepoint_by_number_on_target (int num
)
14118 for (breakpoint
*b
: all_tracepoints ())
14120 struct tracepoint
*t
= (struct tracepoint
*) b
;
14122 if (t
->number_on_target
== num
)
14129 /* Utility: parse a tracepoint number and look it up in the list.
14130 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14131 If the argument is missing, the most recent tracepoint
14132 (tracepoint_count) is returned. */
14134 struct tracepoint
*
14135 get_tracepoint_by_number (const char **arg
,
14136 number_or_range_parser
*parser
)
14139 const char *instring
= arg
== NULL
? NULL
: *arg
;
14141 if (parser
!= NULL
)
14143 gdb_assert (!parser
->finished ());
14144 tpnum
= parser
->get_number ();
14146 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14147 tpnum
= tracepoint_count
;
14149 tpnum
= get_number (arg
);
14153 if (instring
&& *instring
)
14154 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14157 gdb_printf (_("No previous tracepoint\n"));
14161 for (breakpoint
*t
: all_tracepoints ())
14162 if (t
->number
== tpnum
)
14163 return (struct tracepoint
*) t
;
14165 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14170 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
14174 struct thread_info
*thr
= find_thread_global_id (thread
);
14175 gdb_printf (fp
, " thread %s", print_full_thread_id (thr
));
14179 gdb_printf (fp
, " task %d", task
);
14181 gdb_printf (fp
, "\n");
14184 /* Save information on user settable breakpoints (watchpoints, etc) to
14185 a new script file named FILENAME. If FILTER is non-NULL, call it
14186 on each breakpoint and only include the ones for which it returns
14190 save_breakpoints (const char *filename
, int from_tty
,
14191 bool (*filter
) (const struct breakpoint
*))
14194 int extra_trace_bits
= 0;
14196 if (filename
== 0 || *filename
== 0)
14197 error (_("Argument required (file name in which to save)"));
14199 /* See if we have anything to save. */
14200 for (breakpoint
*tp
: all_breakpoints ())
14202 /* Skip internal and momentary breakpoints. */
14203 if (!user_breakpoint_p (tp
))
14206 /* If we have a filter, only save the breakpoints it accepts. */
14207 if (filter
&& !filter (tp
))
14212 if (is_tracepoint (tp
))
14214 extra_trace_bits
= 1;
14216 /* We can stop searching. */
14223 warning (_("Nothing to save."));
14227 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14231 if (!fp
.open (expanded_filename
.get (), "w"))
14232 error (_("Unable to open file '%s' for saving (%s)"),
14233 expanded_filename
.get (), safe_strerror (errno
));
14235 if (extra_trace_bits
)
14236 save_trace_state_variables (&fp
);
14238 for (breakpoint
*tp
: all_breakpoints ())
14240 /* Skip internal and momentary breakpoints. */
14241 if (!user_breakpoint_p (tp
))
14244 /* If we have a filter, only save the breakpoints it accepts. */
14245 if (filter
&& !filter (tp
))
14248 tp
->print_recreate (&fp
);
14250 /* Note, we can't rely on tp->number for anything, as we can't
14251 assume the recreated breakpoint numbers will match. Use $bpnum
14254 if (tp
->cond_string
)
14255 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14257 if (tp
->ignore_count
)
14258 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14260 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14262 fp
.puts (" commands\n");
14264 ui_out_redirect_pop
redir (current_uiout
, &fp
);
14265 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14267 fp
.puts (" end\n");
14270 if (tp
->enable_state
== bp_disabled
)
14271 fp
.puts ("disable $bpnum\n");
14273 /* If this is a multi-location breakpoint, check if the locations
14274 should be individually disabled. Watchpoint locations are
14275 special, and not user visible. */
14276 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14280 for (bp_location
*loc
: tp
->locations ())
14283 fp
.printf ("disable $bpnum.%d\n", n
);
14290 if (extra_trace_bits
&& !default_collect
.empty ())
14291 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14294 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14297 /* The `save breakpoints' command. */
14300 save_breakpoints_command (const char *args
, int from_tty
)
14302 save_breakpoints (args
, from_tty
, NULL
);
14305 /* The `save tracepoints' command. */
14308 save_tracepoints_command (const char *args
, int from_tty
)
14310 save_breakpoints (args
, from_tty
, is_tracepoint
);
14314 /* This help string is used to consolidate all the help string for specifying
14315 locations used by several commands. */
14317 #define LOCATION_SPEC_HELP_STRING \
14318 "Linespecs are colon-separated lists of location parameters, such as\n\
14319 source filename, function name, label name, and line number.\n\
14320 Example: To specify the start of a label named \"the_top\" in the\n\
14321 function \"fact\" in the file \"factorial.c\", use\n\
14322 \"factorial.c:fact:the_top\".\n\
14324 Address locations begin with \"*\" and specify an exact address in the\n\
14325 program. Example: To specify the fourth byte past the start function\n\
14326 \"main\", use \"*main + 4\".\n\
14328 Explicit locations are similar to linespecs but use an option/argument\n\
14329 syntax to specify location parameters.\n\
14330 Example: To specify the start of the label named \"the_top\" in the\n\
14331 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14332 -function fact -label the_top\".\n\
14334 By default, a specified function is matched against the program's\n\
14335 functions in all scopes. For C++, this means in all namespaces and\n\
14336 classes. For Ada, this means in all packages. E.g., in C++,\n\
14337 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14338 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14339 specified name as a complete fully-qualified name instead."
14341 /* This help string is used for the break, hbreak, tbreak and thbreak
14342 commands. It is defined as a macro to prevent duplication.
14343 COMMAND should be a string constant containing the name of the
14346 #define BREAK_ARGS_HELP(command) \
14347 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14348 \t[-force-condition] [if CONDITION]\n\
14349 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14350 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14351 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14352 `-probe-dtrace' (for a DTrace probe).\n\
14353 LOCATION may be a linespec, address, or explicit location as described\n\
14356 With no LOCATION, uses current execution address of the selected\n\
14357 stack frame. This is useful for breaking on return to a stack frame.\n\
14359 THREADNUM is the number from \"info threads\".\n\
14360 CONDITION is a boolean expression.\n\
14362 With the \"-force-condition\" flag, the condition is defined even when\n\
14363 it is invalid for all current locations.\n\
14364 \n" LOCATION_SPEC_HELP_STRING "\n\n\
14365 Multiple breakpoints at one place are permitted, and useful if their\n\
14366 conditions are different.\n\
14368 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14370 /* List of subcommands for "catch". */
14371 static struct cmd_list_element
*catch_cmdlist
;
14373 /* List of subcommands for "tcatch". */
14374 static struct cmd_list_element
*tcatch_cmdlist
;
14377 add_catch_command (const char *name
, const char *docstring
,
14378 cmd_func_ftype
*func
,
14379 completer_ftype
*completer
,
14380 void *user_data_catch
,
14381 void *user_data_tcatch
)
14383 struct cmd_list_element
*command
;
14385 command
= add_cmd (name
, class_breakpoint
, docstring
,
14387 command
->func
= func
;
14388 command
->set_context (user_data_catch
);
14389 set_cmd_completer (command
, completer
);
14391 command
= add_cmd (name
, class_breakpoint
, docstring
,
14393 command
->func
= func
;
14394 command
->set_context (user_data_tcatch
);
14395 set_cmd_completer (command
, completer
);
14398 /* False if any of the breakpoint's locations could be a location where
14399 functions have been inlined, true otherwise. */
14402 is_non_inline_function (struct breakpoint
*b
)
14404 /* The shared library event breakpoint is set on the address of a
14405 non-inline function. */
14406 return (b
->type
== bp_shlib_event
);
14409 /* Nonzero if the specified PC cannot be a location where functions
14410 have been inlined. */
14413 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14414 const target_waitstatus
&ws
)
14416 for (breakpoint
*b
: all_breakpoints ())
14418 if (!is_non_inline_function (b
))
14421 for (bp_location
*bl
: b
->locations ())
14423 if (!bl
->shlib_disabled
14424 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14432 /* Remove any references to OBJFILE which is going to be freed. */
14435 breakpoint_free_objfile (struct objfile
*objfile
)
14437 for (bp_location
*loc
: all_bp_locations ())
14438 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14439 loc
->symtab
= NULL
;
14442 /* Chain containing all defined "enable breakpoint" subcommands. */
14444 static struct cmd_list_element
*enablebreaklist
= NULL
;
14446 /* See breakpoint.h. */
14448 cmd_list_element
*commands_cmd_element
= nullptr;
14450 void _initialize_breakpoint ();
14452 _initialize_breakpoint ()
14454 struct cmd_list_element
*c
;
14456 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14458 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14460 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14463 breakpoint_chain
= 0;
14464 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14465 before a breakpoint is set. */
14466 breakpoint_count
= 0;
14468 tracepoint_count
= 0;
14470 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14471 Set ignore-count of breakpoint number N to COUNT.\n\
14472 Usage is `ignore N COUNT'."));
14474 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14475 commands_command
, _("\
14476 Set commands to be executed when the given breakpoints are hit.\n\
14477 Give a space-separated breakpoint list as argument after \"commands\".\n\
14478 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14480 With no argument, the targeted breakpoint is the last one set.\n\
14481 The commands themselves follow starting on the next line.\n\
14482 Type a line containing \"end\" to indicate the end of them.\n\
14483 Give \"silent\" as the first line to make the breakpoint silent;\n\
14484 then no output is printed when it is hit, except what the commands print."));
14486 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14487 static std::string condition_command_help
14488 = gdb::option::build_help (_("\
14489 Specify breakpoint number N to break only if COND is true.\n\
14490 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14491 is an expression to be evaluated whenever breakpoint N is reached.\n\
14494 %OPTIONS%"), cc_opts
);
14496 c
= add_com ("condition", class_breakpoint
, condition_command
,
14497 condition_command_help
.c_str ());
14498 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14500 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14501 Set a temporary breakpoint.\n\
14502 Like \"break\" except the breakpoint is only temporary,\n\
14503 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14504 by using \"enable delete\" on the breakpoint number.\n\
14506 BREAK_ARGS_HELP ("tbreak")));
14507 set_cmd_completer (c
, location_completer
);
14509 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14510 Set a hardware assisted breakpoint.\n\
14511 Like \"break\" except the breakpoint requires hardware support,\n\
14512 some target hardware may not have this support.\n\
14514 BREAK_ARGS_HELP ("hbreak")));
14515 set_cmd_completer (c
, location_completer
);
14517 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14518 Set a temporary hardware assisted breakpoint.\n\
14519 Like \"hbreak\" except the breakpoint is only temporary,\n\
14520 so it will be deleted when hit.\n\
14522 BREAK_ARGS_HELP ("thbreak")));
14523 set_cmd_completer (c
, location_completer
);
14525 cmd_list_element
*enable_cmd
14526 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14527 Enable all or some breakpoints.\n\
14528 Usage: enable [BREAKPOINTNUM]...\n\
14529 Give breakpoint numbers (separated by spaces) as arguments.\n\
14530 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14531 This is used to cancel the effect of the \"disable\" command.\n\
14532 With a subcommand you can enable temporarily."),
14533 &enablelist
, 1, &cmdlist
);
14535 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14537 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14538 Enable all or some breakpoints.\n\
14539 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14540 Give breakpoint numbers (separated by spaces) as arguments.\n\
14541 This is used to cancel the effect of the \"disable\" command.\n\
14542 May be abbreviated to simply \"enable\"."),
14543 &enablebreaklist
, 1, &enablelist
);
14545 add_cmd ("once", no_class
, enable_once_command
, _("\
14546 Enable some breakpoints for one hit.\n\
14547 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14548 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14551 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14552 Enable some breakpoints and delete when hit.\n\
14553 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14554 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14557 add_cmd ("count", no_class
, enable_count_command
, _("\
14558 Enable some breakpoints for COUNT hits.\n\
14559 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14560 If a breakpoint is hit while enabled in this fashion,\n\
14561 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14564 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14565 Enable some breakpoints and delete when hit.\n\
14566 Usage: enable delete BREAKPOINTNUM...\n\
14567 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14570 add_cmd ("once", no_class
, enable_once_command
, _("\
14571 Enable some breakpoints for one hit.\n\
14572 Usage: enable once BREAKPOINTNUM...\n\
14573 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14576 add_cmd ("count", no_class
, enable_count_command
, _("\
14577 Enable some breakpoints for COUNT hits.\n\
14578 Usage: enable count COUNT BREAKPOINTNUM...\n\
14579 If a breakpoint is hit while enabled in this fashion,\n\
14580 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14583 cmd_list_element
*disable_cmd
14584 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14585 Disable all or some breakpoints.\n\
14586 Usage: disable [BREAKPOINTNUM]...\n\
14587 Arguments are breakpoint numbers with spaces in between.\n\
14588 To disable all breakpoints, give no argument.\n\
14589 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14590 &disablelist
, 1, &cmdlist
);
14591 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14592 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14594 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14595 Disable all or some breakpoints.\n\
14596 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14597 Arguments are breakpoint numbers with spaces in between.\n\
14598 To disable all breakpoints, give no argument.\n\
14599 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14600 This command may be abbreviated \"disable\"."),
14603 cmd_list_element
*delete_cmd
14604 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14605 Delete all or some breakpoints.\n\
14606 Usage: delete [BREAKPOINTNUM]...\n\
14607 Arguments are breakpoint numbers with spaces in between.\n\
14608 To delete all breakpoints, give no argument.\n\
14610 Also a prefix command for deletion of other GDB objects."),
14611 &deletelist
, 1, &cmdlist
);
14612 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14613 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14615 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14616 Delete all or some breakpoints or auto-display expressions.\n\
14617 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14618 Arguments are breakpoint numbers with spaces in between.\n\
14619 To delete all breakpoints, give no argument.\n\
14620 This command may be abbreviated \"delete\"."),
14623 cmd_list_element
*clear_cmd
14624 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14625 Clear breakpoint at specified location.\n\
14626 Argument may be a linespec, explicit, or address location as described below.\n\
14628 With no argument, clears all breakpoints in the line that the selected frame\n\
14629 is executing in.\n"
14630 "\n" LOCATION_SPEC_HELP_STRING
"\n\n\
14631 See also the \"delete\" command which clears breakpoints by number."));
14632 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14634 cmd_list_element
*break_cmd
14635 = add_com ("break", class_breakpoint
, break_command
, _("\
14636 Set breakpoint at specified location.\n"
14637 BREAK_ARGS_HELP ("break")));
14638 set_cmd_completer (break_cmd
, location_completer
);
14640 add_com_alias ("b", break_cmd
, class_run
, 1);
14641 add_com_alias ("br", break_cmd
, class_run
, 1);
14642 add_com_alias ("bre", break_cmd
, class_run
, 1);
14643 add_com_alias ("brea", break_cmd
, class_run
, 1);
14645 cmd_list_element
*info_breakpoints_cmd
14646 = add_info ("breakpoints", info_breakpoints_command
, _("\
14647 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14648 The \"Type\" column indicates one of:\n\
14649 \tbreakpoint - normal breakpoint\n\
14650 \twatchpoint - watchpoint\n\
14651 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14652 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14653 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14654 address and file/line number respectively.\n\
14656 Convenience variable \"$_\" and default examine address for \"x\"\n\
14657 are set to the address of the last breakpoint listed unless the command\n\
14658 is prefixed with \"server \".\n\n\
14659 Convenience variable \"$bpnum\" contains the number of the last\n\
14660 breakpoint set."));
14662 add_info_alias ("b", info_breakpoints_cmd
, 1);
14664 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14665 Status of all breakpoints, or breakpoint number NUMBER.\n\
14666 The \"Type\" column indicates one of:\n\
14667 \tbreakpoint - normal breakpoint\n\
14668 \twatchpoint - watchpoint\n\
14669 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14670 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14671 \tuntil - internal breakpoint used by the \"until\" command\n\
14672 \tfinish - internal breakpoint used by the \"finish\" command\n\
14673 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14674 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14675 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14676 address and file/line number respectively.\n\
14678 Convenience variable \"$_\" and default examine address for \"x\"\n\
14679 are set to the address of the last breakpoint listed unless the command\n\
14680 is prefixed with \"server \".\n\n\
14681 Convenience variable \"$bpnum\" contains the number of the last\n\
14683 &maintenanceinfolist
);
14685 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14686 Set catchpoints to catch events."),
14688 0/*allow-unknown*/, &cmdlist
);
14690 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14691 Set temporary catchpoints to catch events."),
14693 0/*allow-unknown*/, &cmdlist
);
14695 const auto opts
= make_watch_options_def_group (nullptr);
14697 static const std::string watch_help
= gdb::option::build_help (_("\
14698 Set a watchpoint for EXPRESSION.\n\
14699 Usage: watch [-location] EXPRESSION\n\
14704 A watchpoint stops execution of your program whenever the value of\n\
14705 an expression changes."), opts
);
14706 c
= add_com ("watch", class_breakpoint
, watch_command
,
14707 watch_help
.c_str ());
14708 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14710 static const std::string rwatch_help
= gdb::option::build_help (_("\
14711 Set a read watchpoint for EXPRESSION.\n\
14712 Usage: rwatch [-location] EXPRESSION\n\
14717 A read watchpoint stops execution of your program whenever the value of\n\
14718 an expression is read."), opts
);
14719 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14720 rwatch_help
.c_str ());
14721 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14723 static const std::string awatch_help
= gdb::option::build_help (_("\
14724 Set an access watchpoint for EXPRESSION.\n\
14725 Usage: awatch [-location] EXPRESSION\n\
14730 An access watchpoint stops execution of your program whenever the value\n\
14731 of an expression is either read or written."), opts
);
14732 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14733 awatch_help
.c_str ());
14734 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14736 add_info ("watchpoints", info_watchpoints_command
, _("\
14737 Status of specified watchpoints (all watchpoints if no argument)."));
14739 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14740 respond to changes - contrary to the description. */
14741 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14742 &can_use_hw_watchpoints
, _("\
14743 Set debugger's willingness to use watchpoint hardware."), _("\
14744 Show debugger's willingness to use watchpoint hardware."), _("\
14745 If zero, gdb will not use hardware for new watchpoints, even if\n\
14746 such is available. (However, any hardware watchpoints that were\n\
14747 created before setting this to nonzero, will continue to use watchpoint\n\
14750 show_can_use_hw_watchpoints
,
14751 &setlist
, &showlist
);
14753 can_use_hw_watchpoints
= 1;
14755 /* Tracepoint manipulation commands. */
14757 cmd_list_element
*trace_cmd
14758 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14759 Set a tracepoint at specified location.\n\
14761 BREAK_ARGS_HELP ("trace") "\n\
14762 Do \"help tracepoints\" for info on other tracepoint commands."));
14763 set_cmd_completer (trace_cmd
, location_completer
);
14765 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14766 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14767 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14768 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14770 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14771 Set a fast tracepoint at specified location.\n\
14773 BREAK_ARGS_HELP ("ftrace") "\n\
14774 Do \"help tracepoints\" for info on other tracepoint commands."));
14775 set_cmd_completer (c
, location_completer
);
14777 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14778 Set a static tracepoint at location or marker.\n\
14780 strace [LOCATION] [if CONDITION]\n\
14781 LOCATION may be a linespec, explicit, or address location (described below) \n\
14782 or -m MARKER_ID.\n\n\
14783 If a marker id is specified, probe the marker with that name. With\n\
14784 no LOCATION, uses current execution address of the selected stack frame.\n\
14785 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14786 This collects arbitrary user data passed in the probe point call to the\n\
14787 tracing library. You can inspect it when analyzing the trace buffer,\n\
14788 by printing the $_sdata variable like any other convenience variable.\n\
14790 CONDITION is a boolean expression.\n\
14791 \n" LOCATION_SPEC_HELP_STRING
"\n\n\
14792 Multiple tracepoints at one place are permitted, and useful if their\n\
14793 conditions are different.\n\
14795 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14796 Do \"help tracepoints\" for info on other tracepoint commands."));
14797 set_cmd_completer (c
, location_completer
);
14799 cmd_list_element
*info_tracepoints_cmd
14800 = add_info ("tracepoints", info_tracepoints_command
, _("\
14801 Status of specified tracepoints (all tracepoints if no argument).\n\
14802 Convenience variable \"$tpnum\" contains the number of the\n\
14803 last tracepoint set."));
14805 add_info_alias ("tp", info_tracepoints_cmd
, 1);
14807 cmd_list_element
*delete_tracepoints_cmd
14808 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14809 Delete specified tracepoints.\n\
14810 Arguments are tracepoint numbers, separated by spaces.\n\
14811 No argument means delete all tracepoints."),
14813 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
14815 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14816 Disable specified tracepoints.\n\
14817 Arguments are tracepoint numbers, separated by spaces.\n\
14818 No argument means disable all tracepoints."),
14820 deprecate_cmd (c
, "disable");
14822 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14823 Enable specified tracepoints.\n\
14824 Arguments are tracepoint numbers, separated by spaces.\n\
14825 No argument means enable all tracepoints."),
14827 deprecate_cmd (c
, "enable");
14829 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14830 Set the passcount for a tracepoint.\n\
14831 The trace will end when the tracepoint has been passed 'count' times.\n\
14832 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14833 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14835 add_basic_prefix_cmd ("save", class_breakpoint
,
14836 _("Save breakpoint definitions as a script."),
14838 0/*allow-unknown*/, &cmdlist
);
14840 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14841 Save current breakpoint definitions as a script.\n\
14842 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14843 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14844 session to restore them."),
14846 set_cmd_completer (c
, filename_completer
);
14848 cmd_list_element
*save_tracepoints_cmd
14849 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14850 Save current tracepoint definitions as a script.\n\
14851 Use the 'source' command in another debug session to restore them."),
14853 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
14855 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
14856 deprecate_cmd (c
, "save tracepoints");
14858 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
14860 Breakpoint specific settings.\n\
14861 Configure various breakpoint-specific variables such as\n\
14862 pending breakpoint behavior."),
14864 Breakpoint specific settings.\n\
14865 Configure various breakpoint-specific variables such as\n\
14866 pending breakpoint behavior."),
14867 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
14868 &setlist
, &showlist
);
14870 add_setshow_auto_boolean_cmd ("pending", no_class
,
14871 &pending_break_support
, _("\
14872 Set debugger's behavior regarding pending breakpoints."), _("\
14873 Show debugger's behavior regarding pending breakpoints."), _("\
14874 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14875 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14876 an error. If auto, an unrecognized breakpoint location results in a\n\
14877 user-query to see if a pending breakpoint should be created."),
14879 show_pending_break_support
,
14880 &breakpoint_set_cmdlist
,
14881 &breakpoint_show_cmdlist
);
14883 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14885 add_setshow_boolean_cmd ("auto-hw", no_class
,
14886 &automatic_hardware_breakpoints
, _("\
14887 Set automatic usage of hardware breakpoints."), _("\
14888 Show automatic usage of hardware breakpoints."), _("\
14889 If set, the debugger will automatically use hardware breakpoints for\n\
14890 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14891 a warning will be emitted for such breakpoints."),
14893 show_automatic_hardware_breakpoints
,
14894 &breakpoint_set_cmdlist
,
14895 &breakpoint_show_cmdlist
);
14897 add_setshow_boolean_cmd ("always-inserted", class_support
,
14898 &always_inserted_mode
, _("\
14899 Set mode for inserting breakpoints."), _("\
14900 Show mode for inserting breakpoints."), _("\
14901 When this mode is on, breakpoints are inserted immediately as soon as\n\
14902 they're created, kept inserted even when execution stops, and removed\n\
14903 only when the user deletes them. When this mode is off (the default),\n\
14904 breakpoints are inserted only when execution continues, and removed\n\
14905 when execution stops."),
14907 &show_always_inserted_mode
,
14908 &breakpoint_set_cmdlist
,
14909 &breakpoint_show_cmdlist
);
14911 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
14912 condition_evaluation_enums
,
14913 &condition_evaluation_mode_1
, _("\
14914 Set mode of breakpoint condition evaluation."), _("\
14915 Show mode of breakpoint condition evaluation."), _("\
14916 When this is set to \"host\", breakpoint conditions will be\n\
14917 evaluated on the host's side by GDB. When it is set to \"target\",\n\
14918 breakpoint conditions will be downloaded to the target (if the target\n\
14919 supports such feature) and conditions will be evaluated on the target's side.\n\
14920 If this is set to \"auto\" (default), this will be automatically set to\n\
14921 \"target\" if it supports condition evaluation, otherwise it will\n\
14922 be set to \"host\"."),
14923 &set_condition_evaluation_mode
,
14924 &show_condition_evaluation_mode
,
14925 &breakpoint_set_cmdlist
,
14926 &breakpoint_show_cmdlist
);
14928 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14929 Set a breakpoint for an address range.\n\
14930 break-range START-LOCATION, END-LOCATION\n\
14931 where START-LOCATION and END-LOCATION can be one of the following:\n\
14932 LINENUM, for that line in the current file,\n\
14933 FILE:LINENUM, for that line in that file,\n\
14934 +OFFSET, for that number of lines after the current line\n\
14935 or the start of the range\n\
14936 FUNCTION, for the first line in that function,\n\
14937 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14938 *ADDRESS, for the instruction at that address.\n\
14940 The breakpoint will stop execution of the inferior whenever it executes\n\
14941 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14942 range (including START-LOCATION and END-LOCATION)."));
14944 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
14945 Set a dynamic printf at specified location.\n\
14946 dprintf location,format string,arg1,arg2,...\n\
14947 location may be a linespec, explicit, or address location.\n"
14948 "\n" LOCATION_SPEC_HELP_STRING
));
14949 set_cmd_completer (c
, location_completer
);
14951 add_setshow_enum_cmd ("dprintf-style", class_support
,
14952 dprintf_style_enums
, &dprintf_style
, _("\
14953 Set the style of usage for dynamic printf."), _("\
14954 Show the style of usage for dynamic printf."), _("\
14955 This setting chooses how GDB will do a dynamic printf.\n\
14956 If the value is \"gdb\", then the printing is done by GDB to its own\n\
14957 console, as with the \"printf\" command.\n\
14958 If the value is \"call\", the print is done by calling a function in your\n\
14959 program; by default printf(), but you can choose a different function or\n\
14960 output stream by setting dprintf-function and dprintf-channel."),
14961 update_dprintf_commands
, NULL
,
14962 &setlist
, &showlist
);
14964 add_setshow_string_cmd ("dprintf-function", class_support
,
14965 &dprintf_function
, _("\
14966 Set the function to use for dynamic printf."), _("\
14967 Show the function to use for dynamic printf."), NULL
,
14968 update_dprintf_commands
, NULL
,
14969 &setlist
, &showlist
);
14971 add_setshow_string_cmd ("dprintf-channel", class_support
,
14972 &dprintf_channel
, _("\
14973 Set the channel to use for dynamic printf."), _("\
14974 Show the channel to use for dynamic printf."), NULL
,
14975 update_dprintf_commands
, NULL
,
14976 &setlist
, &showlist
);
14978 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
14979 &disconnected_dprintf
, _("\
14980 Set whether dprintf continues after GDB disconnects."), _("\
14981 Show whether dprintf continues after GDB disconnects."), _("\
14982 Use this to let dprintf commands continue to hit and produce output\n\
14983 even if GDB disconnects or detaches from the target."),
14986 &setlist
, &showlist
);
14988 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
14989 Target agent only formatted printing, like the C \"printf\" function.\n\
14990 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
14991 This supports most C printf format specifications, like %s, %d, etc.\n\
14992 This is useful for formatted output in user-defined commands."));
14994 automatic_hardware_breakpoints
= true;
14996 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
14998 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,