1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
59 #include "parser-defs.h"
60 #include "gdbsupport/gdb_regex.h"
62 #include "cli/cli-utils.h"
65 #include "dummy-frame.h"
67 #include "gdbsupport/format.h"
68 #include "thread-fsm.h"
69 #include "tid-parse.h"
70 #include "cli/cli-style.h"
71 #include "cli/cli-decode.h"
72 #include <unordered_set>
74 /* readline include files */
75 #include "readline/tilde.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 #include "progspace-and-thread.h"
84 #include "gdbsupport/array-view.h"
85 #include "gdbsupport/gdb_optional.h"
86 #include "gdbsupport/common-utils.h"
88 /* Prototypes for local functions. */
90 static void map_breakpoint_numbers (const char *,
91 gdb::function_view
<void (breakpoint
*)>);
94 create_sals_from_location_spec_default (location_spec
*locspec
,
95 linespec_result
*canonical
);
97 static void create_breakpoints_sal (struct gdbarch
*,
98 struct linespec_result
*,
99 gdb::unique_xmalloc_ptr
<char>,
100 gdb::unique_xmalloc_ptr
<char>,
102 enum bpdisp
, int, int, int,
104 int, int, int, unsigned);
106 static int can_use_hardware_watchpoint
107 (const std::vector
<value_ref_ptr
> &vals
);
109 static void mention (const breakpoint
*);
111 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
113 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
115 static struct breakpoint
*
116 momentary_breakpoint_from_master (struct breakpoint
*orig
,
118 int loc_enabled
, int thread
);
120 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, bool);
122 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
125 struct program_space
*pspace
);
127 static bool watchpoint_locations_match (const struct bp_location
*loc1
,
128 const struct bp_location
*loc2
);
130 static bool breakpoint_locations_match (const struct bp_location
*loc1
,
131 const struct bp_location
*loc2
,
132 bool sw_hw_bps_match
= false);
134 static bool breakpoint_location_address_match (struct bp_location
*bl
,
135 const struct address_space
*aspace
,
138 static bool breakpoint_location_address_range_overlap (struct bp_location
*,
139 const address_space
*,
142 static int remove_breakpoint (struct bp_location
*);
143 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
145 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
147 static int hw_breakpoint_used_count (void);
149 static int hw_watchpoint_use_count (struct breakpoint
*);
151 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
153 int *other_type_used
);
155 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
158 static void decref_bp_location (struct bp_location
**loc
);
160 static std::vector
<symtab_and_line
> bkpt_probe_decode_location_spec
161 (struct breakpoint
*b
,
162 location_spec
*locspec
,
163 struct program_space
*search_pspace
);
165 static bool bl_address_is_meaningful (bp_location
*loc
);
167 static int find_loc_num_by_location (const bp_location
*loc
);
169 /* update_global_location_list's modes of operation wrt to whether to
170 insert locations now. */
171 enum ugll_insert_mode
173 /* Don't insert any breakpoint locations into the inferior, only
174 remove already-inserted locations that no longer should be
175 inserted. Functions that delete a breakpoint or breakpoints
176 should specify this mode, so that deleting a breakpoint doesn't
177 have the side effect of inserting the locations of other
178 breakpoints that are marked not-inserted, but should_be_inserted
179 returns true on them.
181 This behavior is useful is situations close to tear-down -- e.g.,
182 after an exec, while the target still has execution, but
183 breakpoint shadows of the previous executable image should *NOT*
184 be restored to the new image; or before detaching, where the
185 target still has execution and wants to delete breakpoints from
186 GDB's lists, and all breakpoints had already been removed from
190 /* May insert breakpoints iff breakpoints_should_be_inserted_now
191 claims breakpoints should be inserted now. */
194 /* Insert locations now, irrespective of
195 breakpoints_should_be_inserted_now. E.g., say all threads are
196 stopped right now, and the user did "continue". We need to
197 insert breakpoints _before_ resuming the target, but
198 UGLL_MAY_INSERT wouldn't insert them, because
199 breakpoints_should_be_inserted_now returns false at that point,
200 as no thread is running yet. */
204 /* Return a textual version of INSERT_MODE. */
207 ugll_insert_mode_text (ugll_insert_mode insert_mode
)
209 /* Make sure the compiler warns if a new ugll_insert_mode enumerator is added
210 but not handled here. */
212 DIAGNOSTIC_ERROR_SWITCH
215 case UGLL_DONT_INSERT
:
216 return "UGLL_DONT_INSERT";
217 case UGLL_MAY_INSERT
:
218 return "UGLL_MAY_INSERT";
220 return "UGLL_INSERT";
224 gdb_assert_not_reached ("must handle all enum values");
227 /* Return a textual version of REASON. */
230 remove_bp_reason_str (remove_bp_reason reason
)
232 /* Make sure the compiler warns if a new remove_bp_reason enumerator is added
233 but not handled here. */
235 DIAGNOSTIC_ERROR_SWITCH
238 case REMOVE_BREAKPOINT
:
239 return "regular remove";
240 case DETACH_BREAKPOINT
:
245 gdb_assert_not_reached ("must handle all enum values");
248 /* Return a textual version of breakpoint location BL describing number,
249 location and address. */
252 breakpoint_location_address_str (const bp_location
*bl
)
254 std::string str
= string_printf ("Breakpoint %d (%s) at address %s",
256 host_address_to_string (bl
),
257 paddress (bl
->gdbarch
, bl
->address
));
259 std::string loc_string
= bl
->to_string ();
260 if (!loc_string
.empty ())
261 str
+= string_printf (" %s", loc_string
.c_str ());
266 static void update_global_location_list (enum ugll_insert_mode
);
268 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
270 static void insert_breakpoint_locations (void);
272 static void trace_pass_command (const char *, int);
274 static void set_tracepoint_count (int num
);
276 static bool is_masked_watchpoint (const struct breakpoint
*b
);
278 /* Return true if B refers to a static tracepoint set by marker ("-m"),
281 static bool strace_marker_p (struct breakpoint
*b
);
283 static void bkpt_probe_create_sals_from_location_spec
284 (location_spec
*locspec
,
285 struct linespec_result
*canonical
);
286 static void tracepoint_probe_create_sals_from_location_spec
287 (location_spec
*locspec
,
288 struct linespec_result
*canonical
);
290 const struct breakpoint_ops code_breakpoint_ops
=
292 create_sals_from_location_spec_default
,
293 create_breakpoints_sal
,
296 /* Breakpoints set on probes. */
297 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
299 bkpt_probe_create_sals_from_location_spec
,
300 create_breakpoints_sal
,
303 /* Tracepoints set on probes. */
304 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
306 tracepoint_probe_create_sals_from_location_spec
,
307 create_breakpoints_sal
,
310 /* Implementation of abstract dtors. These must exist to satisfy the
313 breakpoint::~breakpoint ()
317 code_breakpoint::~code_breakpoint ()
321 catchpoint::~catchpoint ()
325 /* The structure to be used in regular breakpoints. */
326 struct ordinary_breakpoint
: public code_breakpoint
328 using code_breakpoint::code_breakpoint
;
330 int resources_needed (const struct bp_location
*) override
;
331 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
332 void print_mention () const override
;
333 void print_recreate (struct ui_file
*fp
) const override
;
336 /* Internal breakpoints. These typically have a lifetime the same as
337 the program, and they end up installed on the breakpoint chain with
338 a negative breakpoint number. They're visible in "maint info
339 breakpoints", but not "info breakpoints". */
340 struct internal_breakpoint
: public code_breakpoint
342 internal_breakpoint (struct gdbarch
*gdbarch
,
343 enum bptype type
, CORE_ADDR address
)
344 : code_breakpoint (gdbarch
, type
)
348 sal
.section
= find_pc_overlay (sal
.pc
);
349 sal
.pspace
= current_program_space
;
352 pspace
= current_program_space
;
353 disposition
= disp_donttouch
;
356 void re_set () override
;
357 void check_status (struct bpstat
*bs
) override
;
358 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
359 void print_mention () const override
;
362 /* Momentary breakpoints. These typically have a lifetime of some run
363 control command only, are always thread-specific, and have 0 for
364 breakpoint number. I.e., there can be many momentary breakpoints
365 on the breakpoint chain and they all same the same number (zero).
366 They're visible in "maint info breakpoints", but not "info
368 struct momentary_breakpoint
: public code_breakpoint
370 momentary_breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
371 program_space
*pspace_
,
372 const struct frame_id
&frame_id_
,
374 : code_breakpoint (gdbarch_
, bptype
)
376 /* If FRAME_ID is valid, it should be a real frame, not an inlined
377 or tail-called one. */
378 gdb_assert (!frame_id_artificial_p (frame_id
));
380 /* Momentary breakpoints are always thread-specific. */
381 gdb_assert (thread_
> 0);
384 enable_state
= bp_enabled
;
385 disposition
= disp_donttouch
;
386 frame_id
= frame_id_
;
389 /* The inferior should have been set by the parent constructor. */
390 gdb_assert (inferior
== -1);
393 void re_set () override
;
394 void check_status (struct bpstat
*bs
) override
;
395 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
396 void print_mention () const override
;
399 /* DPrintf breakpoints. */
400 struct dprintf_breakpoint
: public ordinary_breakpoint
402 using ordinary_breakpoint::ordinary_breakpoint
;
404 void re_set () override
;
405 int breakpoint_hit (const struct bp_location
*bl
,
406 const address_space
*aspace
,
408 const target_waitstatus
&ws
) override
;
409 void print_recreate (struct ui_file
*fp
) const override
;
410 void after_condition_true (struct bpstat
*bs
) override
;
413 /* Ranged breakpoints. */
414 struct ranged_breakpoint
: public ordinary_breakpoint
416 explicit ranged_breakpoint (struct gdbarch
*gdbarch
,
417 const symtab_and_line
&sal_start
,
419 location_spec_up start_locspec
,
420 location_spec_up end_locspec
)
421 : ordinary_breakpoint (gdbarch
, bp_hardware_breakpoint
)
423 bp_location
*bl
= add_location (sal_start
);
426 disposition
= disp_donttouch
;
428 locspec
= std::move (start_locspec
);
429 locspec_range_end
= std::move (end_locspec
);
432 int breakpoint_hit (const struct bp_location
*bl
,
433 const address_space
*aspace
,
435 const target_waitstatus
&ws
) override
;
436 int resources_needed (const struct bp_location
*) override
;
437 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
438 bool print_one (const bp_location
**) const override
;
439 void print_one_detail (struct ui_out
*) const override
;
440 void print_mention () const override
;
441 void print_recreate (struct ui_file
*fp
) const override
;
444 /* Static tracepoints with marker (`-m'). */
445 struct static_marker_tracepoint
: public tracepoint
447 using tracepoint::tracepoint
;
449 std::vector
<symtab_and_line
> decode_location_spec
450 (struct location_spec
*locspec
,
451 struct program_space
*search_pspace
) override
;
454 /* The style in which to perform a dynamic printf. This is a user
455 option because different output options have different tradeoffs;
456 if GDB does the printing, there is better error handling if there
457 is a problem with any of the arguments, but using an inferior
458 function lets you have special-purpose printers and sending of
459 output to the same place as compiled-in print functions. */
461 static const char dprintf_style_gdb
[] = "gdb";
462 static const char dprintf_style_call
[] = "call";
463 static const char dprintf_style_agent
[] = "agent";
464 static const char *const dprintf_style_enums
[] = {
470 static const char *dprintf_style
= dprintf_style_gdb
;
472 /* The function to use for dynamic printf if the preferred style is to
473 call into the inferior. The value is simply a string that is
474 copied into the command, so it can be anything that GDB can
475 evaluate to a callable address, not necessarily a function name. */
477 static std::string dprintf_function
= "printf";
479 /* The channel to use for dynamic printf if the preferred style is to
480 call into the inferior; if a nonempty string, it will be passed to
481 the call as the first argument, with the format string as the
482 second. As with the dprintf function, this can be anything that
483 GDB knows how to evaluate, so in addition to common choices like
484 "stderr", this could be an app-specific expression like
485 "mystreams[curlogger]". */
487 static std::string dprintf_channel
;
489 /* True if dprintf commands should continue to operate even if GDB
491 static bool disconnected_dprintf
= true;
493 struct command_line
*
494 breakpoint_commands (struct breakpoint
*b
)
496 return b
->commands
? b
->commands
.get () : NULL
;
499 /* Flag indicating that a command has proceeded the inferior past the
500 current breakpoint. */
502 static bool breakpoint_proceeded
;
505 bpdisp_text (enum bpdisp disp
)
507 /* NOTE: the following values are a part of MI protocol and
508 represent values of 'disp' field returned when inferior stops at
510 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
512 return bpdisps
[(int) disp
];
515 /* Prototypes for exported functions. */
516 /* If FALSE, gdb will not use hardware support for watchpoints, even
517 if such is available. */
518 static int can_use_hw_watchpoints
;
521 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
522 struct cmd_list_element
*c
,
526 _("Debugger's willingness to use "
527 "watchpoint hardware is %s.\n"),
531 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
532 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
533 for unrecognized breakpoint locations.
534 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
535 static enum auto_boolean pending_break_support
;
537 show_pending_break_support (struct ui_file
*file
, int from_tty
,
538 struct cmd_list_element
*c
,
542 _("Debugger's behavior regarding "
543 "pending breakpoints is %s.\n"),
547 /* If true, gdb will automatically use hardware breakpoints for breakpoints
548 set with "break" but falling in read-only memory.
549 If false, gdb will warn about such breakpoints, but won't automatically
550 use hardware breakpoints. */
551 static bool automatic_hardware_breakpoints
;
553 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
554 struct cmd_list_element
*c
,
558 _("Automatic usage of hardware breakpoints is %s.\n"),
562 /* If on, GDB keeps breakpoints inserted even if the inferior is
563 stopped, and immediately inserts any new breakpoints as soon as
564 they're created. If off (default), GDB keeps breakpoints off of
565 the target as long as possible. That is, it delays inserting
566 breakpoints until the next resume, and removes them again when the
567 target fully stops. This is a bit safer in case GDB crashes while
568 processing user input. */
569 static bool always_inserted_mode
= false;
572 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
573 struct cmd_list_element
*c
, const char *value
)
575 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
579 /* True if breakpoint debug output is enabled. */
580 static bool debug_breakpoint
= false;
582 /* Print a "breakpoint" debug statement. */
583 #define breakpoint_debug_printf(fmt, ...) \
584 debug_prefixed_printf_cond (debug_breakpoint, "breakpoint", fmt, \
587 /* "show debug breakpoint" implementation. */
589 show_debug_breakpoint (struct ui_file
*file
, int from_tty
,
590 struct cmd_list_element
*c
, const char *value
)
592 gdb_printf (file
, _("Breakpoint location debugging is %s.\n"), value
);
595 /* See breakpoint.h. */
598 breakpoints_should_be_inserted_now (void)
600 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
602 /* If breakpoints are global, they should be inserted even if no
603 thread under gdb's control is running, or even if there are
604 no threads under GDB's control yet. */
609 if (always_inserted_mode
)
611 /* The user wants breakpoints inserted even if all threads
616 for (inferior
*inf
: all_inferiors ())
617 if (inf
->has_execution ()
618 && threads_are_executing (inf
->process_target ()))
621 /* Don't remove breakpoints yet if, even though all threads are
622 stopped, we still have events to process. */
623 for (thread_info
*tp
: all_non_exited_threads ())
624 if (tp
->resumed () && tp
->has_pending_waitstatus ())
630 static const char condition_evaluation_both
[] = "host or target";
632 /* Modes for breakpoint condition evaluation. */
633 static const char condition_evaluation_auto
[] = "auto";
634 static const char condition_evaluation_host
[] = "host";
635 static const char condition_evaluation_target
[] = "target";
636 static const char *const condition_evaluation_enums
[] = {
637 condition_evaluation_auto
,
638 condition_evaluation_host
,
639 condition_evaluation_target
,
643 /* Global that holds the current mode for breakpoint condition evaluation. */
644 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
646 /* Global that we use to display information to the user (gets its value from
647 condition_evaluation_mode_1. */
648 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
650 /* Translate a condition evaluation mode MODE into either "host"
651 or "target". This is used mostly to translate from "auto" to the
652 real setting that is being used. It returns the translated
656 translate_condition_evaluation_mode (const char *mode
)
658 if (mode
== condition_evaluation_auto
)
660 if (target_supports_evaluation_of_breakpoint_conditions ())
661 return condition_evaluation_target
;
663 return condition_evaluation_host
;
669 /* Discovers what condition_evaluation_auto translates to. */
672 breakpoint_condition_evaluation_mode (void)
674 return translate_condition_evaluation_mode (condition_evaluation_mode
);
677 /* Return true if GDB should evaluate breakpoint conditions or false
681 gdb_evaluates_breakpoint_condition_p (void)
683 const char *mode
= breakpoint_condition_evaluation_mode ();
685 return (mode
== condition_evaluation_host
);
688 /* Are we executing breakpoint commands? */
689 static int executing_breakpoint_commands
;
691 /* Are overlay event breakpoints enabled? */
692 static int overlay_events_enabled
;
694 /* See description in breakpoint.h. */
695 bool target_exact_watchpoints
= false;
697 /* Chains of all breakpoints defined. */
699 static intrusive_list
<breakpoint
> breakpoint_chain
;
701 /* See breakpoint.h. */
706 return breakpoint_range (breakpoint_chain
.begin (), breakpoint_chain
.end ());
709 /* See breakpoint.h. */
711 breakpoint_safe_range
712 all_breakpoints_safe ()
714 return breakpoint_safe_range (all_breakpoints ());
717 /* See breakpoint.h. */
722 return tracepoint_range (tracepoint_iterator (breakpoint_chain
.begin ()),
723 tracepoint_iterator (breakpoint_chain
.end ()));
726 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
728 static std::vector
<bp_location
*> bp_locations
;
730 /* See breakpoint.h. */
732 const std::vector
<bp_location
*> &
738 /* Range to iterate over breakpoint locations at a given address. */
740 struct bp_locations_at_addr_range
742 using iterator
= std::vector
<bp_location
*>::iterator
;
744 bp_locations_at_addr_range (CORE_ADDR addr
)
748 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
749 { return loc
->address
< addr_
; }
751 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
752 { return addr_
< loc
->address
; }
755 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
758 m_begin
= it_pair
.first
;
759 m_end
= it_pair
.second
;
762 iterator
begin () const
765 iterator
end () const
773 /* Return a range to iterate over all breakpoint locations exactly at address
776 If it's needed to iterate multiple times on the same range, it's possible
777 to save the range in a local variable and use it multiple times:
779 auto range = all_bp_locations_at_addr (addr);
781 for (bp_location *loc : range)
784 for (bp_location *loc : range)
787 This saves a bit of time, as it avoids re-doing the binary searches to find
788 the range's boundaries. Just remember not to change the bp_locations vector
789 in the mean time, as it could make the range's iterators stale. */
791 static bp_locations_at_addr_range
792 all_bp_locations_at_addr (CORE_ADDR addr
)
794 return bp_locations_at_addr_range (addr
);
797 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
798 ADDRESS for the current elements of BP_LOCATIONS which get a valid
799 result from bp_location_has_shadow. You can use it for roughly
800 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
801 an address you need to read. */
803 static CORE_ADDR bp_locations_placed_address_before_address_max
;
805 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
806 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
807 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
808 You can use it for roughly limiting the subrange of BP_LOCATIONS to
809 scan for shadow bytes for an address you need to read. */
811 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
813 /* The locations that no longer correspond to any breakpoint, unlinked
814 from the bp_locations array, but for which a hit may still be
815 reported by a target. */
816 static std::vector
<bp_location
*> moribund_locations
;
818 /* Number of last breakpoint made. */
820 static int breakpoint_count
;
822 /* The value of `breakpoint_count' before the last command that
823 created breakpoints. If the last (break-like) command created more
824 than one breakpoint, then the difference between BREAKPOINT_COUNT
825 and PREV_BREAKPOINT_COUNT is more than one. */
826 static int prev_breakpoint_count
;
828 /* Number of last tracepoint made. */
830 static int tracepoint_count
;
832 static struct cmd_list_element
*breakpoint_set_cmdlist
;
833 static struct cmd_list_element
*breakpoint_show_cmdlist
;
834 struct cmd_list_element
*save_cmdlist
;
836 /* Return whether a breakpoint is an active enabled breakpoint. */
838 breakpoint_enabled (struct breakpoint
*b
)
840 return (b
->enable_state
== bp_enabled
);
843 /* Set breakpoint count to NUM. */
846 set_breakpoint_count (int num
)
848 prev_breakpoint_count
= breakpoint_count
;
849 breakpoint_count
= num
;
850 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
853 /* Used by `start_rbreak_breakpoints' below, to record the current
854 breakpoint count before "rbreak" creates any breakpoint. */
855 static int rbreak_start_breakpoint_count
;
857 /* Called at the start an "rbreak" command to record the first
860 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
862 rbreak_start_breakpoint_count
= breakpoint_count
;
865 /* Called at the end of an "rbreak" command to record the last
868 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
870 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
873 /* Used in run_command to zero the hit count when a new run starts. */
876 clear_breakpoint_hit_counts (void)
878 for (breakpoint
&b
: all_breakpoints ())
883 /* Return the breakpoint with the specified number, or NULL
884 if the number does not refer to an existing breakpoint. */
887 get_breakpoint (int num
)
889 for (breakpoint
&b
: all_breakpoints ())
896 /* Return TRUE if NUM refer to an existing breakpoint that has
897 multiple code locations. */
900 has_multiple_locations (int num
)
902 for (breakpoint
&b
: all_breakpoints ())
904 return b
.has_multiple_locations ();
911 /* Mark locations as "conditions have changed" in case the target supports
912 evaluating conditions on its side. */
915 mark_breakpoint_modified (struct breakpoint
*b
)
917 /* This is only meaningful if the target is
918 evaluating conditions and if the user has
919 opted for condition evaluation on the target's
921 if (gdb_evaluates_breakpoint_condition_p ()
922 || !target_supports_evaluation_of_breakpoint_conditions ())
925 if (!is_breakpoint (b
))
928 for (bp_location
&loc
: b
->locations ())
929 loc
.condition_changed
= condition_modified
;
932 /* Mark location as "conditions have changed" in case the target supports
933 evaluating conditions on its side. */
936 mark_breakpoint_location_modified (struct bp_location
*loc
)
938 /* This is only meaningful if the target is
939 evaluating conditions and if the user has
940 opted for condition evaluation on the target's
942 if (gdb_evaluates_breakpoint_condition_p ()
943 || !target_supports_evaluation_of_breakpoint_conditions ())
947 if (!is_breakpoint (loc
->owner
))
950 loc
->condition_changed
= condition_modified
;
953 /* Sets the condition-evaluation mode using the static global
954 condition_evaluation_mode. */
957 set_condition_evaluation_mode (const char *args
, int from_tty
,
958 struct cmd_list_element
*c
)
960 const char *old_mode
, *new_mode
;
962 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
963 && !target_supports_evaluation_of_breakpoint_conditions ())
965 condition_evaluation_mode_1
= condition_evaluation_mode
;
966 warning (_("Target does not support breakpoint condition evaluation.\n"
967 "Using host evaluation mode instead."));
971 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
972 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
974 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
975 settings was "auto". */
976 condition_evaluation_mode
= condition_evaluation_mode_1
;
978 /* Only update the mode if the user picked a different one. */
979 if (new_mode
!= old_mode
)
981 /* If the user switched to a different evaluation mode, we
982 need to synch the changes with the target as follows:
984 "host" -> "target": Send all (valid) conditions to the target.
985 "target" -> "host": Remove all the conditions from the target.
988 if (new_mode
== condition_evaluation_target
)
990 /* Mark everything modified and synch conditions with the
992 for (bp_location
*loc
: all_bp_locations ())
993 mark_breakpoint_location_modified (loc
);
997 /* Manually mark non-duplicate locations to synch conditions
998 with the target. We do this to remove all the conditions the
999 target knows about. */
1000 for (bp_location
*loc
: all_bp_locations ())
1001 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
1002 loc
->needs_update
= 1;
1005 /* Do the update. */
1006 update_global_location_list (UGLL_MAY_INSERT
);
1012 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
1013 what "auto" is translating to. */
1016 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
1017 struct cmd_list_element
*c
, const char *value
)
1019 if (condition_evaluation_mode
== condition_evaluation_auto
)
1021 _("Breakpoint condition evaluation "
1022 "mode is %s (currently %s).\n"),
1024 breakpoint_condition_evaluation_mode ());
1026 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
1030 /* Parse COND_STRING in the context of LOC and set as the condition
1031 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
1032 the number of LOC within its owner. In case of parsing error, mark
1033 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
1036 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
1037 int bp_num
, int loc_num
)
1039 bool has_junk
= false;
1042 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
1043 block_for_pc (loc
->address
), 0);
1044 if (*cond_string
!= 0)
1048 loc
->cond
= std::move (new_exp
);
1049 if (loc
->disabled_by_cond
&& loc
->enabled
)
1050 gdb_printf (_("Breakpoint %d's condition is now valid at "
1051 "location %d, enabling.\n"),
1054 loc
->disabled_by_cond
= false;
1057 catch (const gdb_exception_error
&e
)
1061 /* Warn if a user-enabled location is now becoming disabled-by-cond.
1062 BP_NUM is 0 if the breakpoint is being defined for the first
1063 time using the "break ... if ..." command, and non-zero if
1066 warning (_("failed to validate condition at location %d.%d, "
1067 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
1069 warning (_("failed to validate condition at location %d, "
1070 "disabling:\n %s"), loc_num
, e
.what ());
1073 loc
->disabled_by_cond
= true;
1077 error (_("Garbage '%s' follows condition"), cond_string
);
1080 /* See breakpoint.h. */
1083 notify_breakpoint_modified (breakpoint
*b
)
1085 interps_notify_breakpoint_modified (b
);
1086 gdb::observers::breakpoint_modified
.notify (b
);
1090 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
1091 int from_tty
, bool force
)
1095 b
->cond_string
.reset ();
1097 if (is_watchpoint (b
))
1098 gdb::checked_static_cast
<watchpoint
*> (b
)->cond_exp
.reset ();
1102 for (bp_location
&loc
: b
->locations ())
1105 if (loc
.disabled_by_cond
&& loc
.enabled
)
1106 gdb_printf (_("Breakpoint %d's condition is now valid at "
1107 "location %d, enabling.\n"),
1108 b
->number
, loc_num
);
1109 loc
.disabled_by_cond
= false;
1112 /* No need to free the condition agent expression
1113 bytecode (if we have one). We will handle this
1114 when we go through update_global_location_list. */
1119 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
1123 if (is_watchpoint (b
))
1125 innermost_block_tracker tracker
;
1126 const char *arg
= exp
;
1127 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
1129 error (_("Junk at end of expression"));
1130 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
1131 w
->cond_exp
= std::move (new_exp
);
1132 w
->cond_exp_valid_block
= tracker
.block ();
1136 /* Parse and set condition expressions. We make two passes.
1137 In the first, we parse the condition string to see if it
1138 is valid in at least one location. If so, the condition
1139 would be accepted. So we go ahead and set the locations'
1140 conditions. In case no valid case is found, we throw
1141 the error and the condition string will be rejected.
1142 This two-pass approach is taken to avoid setting the
1143 state of locations in case of a reject. */
1144 for (const bp_location
&loc
: b
->locations ())
1148 const char *arg
= exp
;
1149 parse_exp_1 (&arg
, loc
.address
,
1150 block_for_pc (loc
.address
), 0);
1152 error (_("Junk at end of expression"));
1155 catch (const gdb_exception_error
&e
)
1157 /* Condition string is invalid. If this happens to
1158 be the last loc, abandon (if not forced) or continue
1160 if (&loc
== &b
->last_loc () && !force
)
1165 /* If we reach here, the condition is valid at some locations. */
1167 for (bp_location
&loc
: b
->locations ())
1169 set_breakpoint_location_condition (exp
, &loc
, b
->number
, loc_num
);
1174 /* We know that the new condition parsed successfully. The
1175 condition string of the breakpoint can be safely updated. */
1176 b
->cond_string
= make_unique_xstrdup (exp
);
1177 b
->condition_not_parsed
= 0;
1179 mark_breakpoint_modified (b
);
1181 notify_breakpoint_modified (b
);
1184 /* See breakpoint.h. */
1187 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1190 for (breakpoint
&b
: all_breakpoints ())
1191 if (b
.number
== bpnum
)
1193 /* Check if this breakpoint has a "stop" method implemented in an
1194 extension language. This method and conditions entered into GDB
1195 from the CLI are mutually exclusive. */
1196 const struct extension_language_defn
*extlang
1197 = get_breakpoint_cond_ext_lang (&b
, EXT_LANG_NONE
);
1199 if (extlang
!= NULL
)
1201 error (_("Only one stop condition allowed. There is currently"
1202 " a %s stop condition defined for this breakpoint."),
1203 ext_lang_capitalized_name (extlang
));
1205 set_breakpoint_condition (&b
, exp
, from_tty
, force
);
1207 if (is_breakpoint (&b
))
1208 update_global_location_list (UGLL_MAY_INSERT
);
1213 error (_("No breakpoint number %d."), bpnum
);
1216 /* The options for the "condition" command. */
1218 struct condition_command_opts
1221 bool force_condition
= false;
1224 static const gdb::option::option_def condition_command_option_defs
[] = {
1226 gdb::option::flag_option_def
<condition_command_opts
> {
1228 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1229 N_("Set the condition even if it is invalid for all current locations."),
1234 /* Create an option_def_group for the "condition" options, with
1235 CC_OPTS as context. */
1237 static inline gdb::option::option_def_group
1238 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1240 return {{condition_command_option_defs
}, cc_opts
};
1243 /* Completion for the "condition" command. */
1246 condition_completer (struct cmd_list_element
*cmd
,
1247 completion_tracker
&tracker
,
1248 const char *text
, const char * /*word*/)
1250 bool has_no_arguments
= (*text
== '\0');
1251 condition_command_opts cc_opts
;
1252 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1253 if (gdb::option::complete_options
1254 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1257 text
= skip_spaces (text
);
1258 const char *space
= skip_to_space (text
);
1265 tracker
.advance_custom_word_point_by (1);
1266 /* We don't support completion of history indices. */
1267 if (!isdigit (text
[1]))
1268 complete_internalvar (tracker
, &text
[1]);
1272 /* Suggest the "-force" flag if no arguments are given. If
1273 arguments were passed, they either already include the flag,
1274 or we are beyond the point of suggesting it because it's
1275 positionally the first argument. */
1276 if (has_no_arguments
)
1277 gdb::option::complete_on_all_options (tracker
, group
);
1279 /* We're completing the breakpoint number. */
1280 len
= strlen (text
);
1282 for (breakpoint
&b
: all_breakpoints ())
1286 xsnprintf (number
, sizeof (number
), "%d", b
.number
);
1288 if (strncmp (number
, text
, len
) == 0)
1289 tracker
.add_completion (make_unique_xstrdup (number
));
1295 /* We're completing the expression part. Skip the breakpoint num. */
1296 const char *exp_start
= skip_spaces (space
);
1297 tracker
.advance_custom_word_point_by (exp_start
- text
);
1299 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1300 expression_completer (cmd
, tracker
, text
, word
);
1303 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1306 condition_command (const char *arg
, int from_tty
)
1312 error_no_arg (_("breakpoint number"));
1316 /* Check if the "-force" flag was passed. */
1317 condition_command_opts cc_opts
;
1318 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1319 gdb::option::process_options
1320 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1322 bnum
= get_number (&p
);
1324 error (_("Bad breakpoint argument: '%s'"), arg
);
1326 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1329 /* Check that COMMAND do not contain commands that are suitable
1330 only for tracepoints and not suitable for ordinary breakpoints.
1331 Throw if any such commands is found. */
1334 check_no_tracepoint_commands (struct command_line
*commands
)
1336 struct command_line
*c
;
1338 for (c
= commands
; c
; c
= c
->next
)
1340 if (c
->control_type
== while_stepping_control
)
1341 error (_("The 'while-stepping' command can "
1342 "only be used for tracepoints"));
1344 check_no_tracepoint_commands (c
->body_list_0
.get ());
1345 check_no_tracepoint_commands (c
->body_list_1
.get ());
1347 /* Not that command parsing removes leading whitespace and comment
1348 lines and also empty lines. So, we only need to check for
1349 command directly. */
1350 if (strstr (c
->line
, "collect ") == c
->line
)
1351 error (_("The 'collect' command can only be used for tracepoints"));
1353 if (strstr (c
->line
, "teval ") == c
->line
)
1354 error (_("The 'teval' command can only be used for tracepoints"));
1358 struct longjmp_breakpoint
: public momentary_breakpoint
1360 using momentary_breakpoint::momentary_breakpoint
;
1362 ~longjmp_breakpoint () override
;
1365 /* Encapsulate tests for different types of tracepoints. */
1368 is_tracepoint_type (bptype type
)
1370 return (type
== bp_tracepoint
1371 || type
== bp_fast_tracepoint
1372 || type
== bp_static_tracepoint
1373 || type
== bp_static_marker_tracepoint
);
1376 /* See breakpoint.h. */
1379 is_tracepoint (const struct breakpoint
*b
)
1381 return is_tracepoint_type (b
->type
);
1384 /* Factory function to create an appropriate instance of breakpoint given
1387 template<typename
... Arg
>
1388 static std::unique_ptr
<code_breakpoint
>
1389 new_breakpoint_from_type (struct gdbarch
*gdbarch
, bptype type
,
1397 case bp_hardware_breakpoint
:
1398 b
= new ordinary_breakpoint (gdbarch
, type
,
1399 std::forward
<Arg
> (args
)...);
1402 case bp_fast_tracepoint
:
1403 case bp_static_tracepoint
:
1405 b
= new tracepoint (gdbarch
, type
,
1406 std::forward
<Arg
> (args
)...);
1409 case bp_static_marker_tracepoint
:
1410 b
= new static_marker_tracepoint (gdbarch
, type
,
1411 std::forward
<Arg
> (args
)...);
1415 b
= new dprintf_breakpoint (gdbarch
, type
,
1416 std::forward
<Arg
> (args
)...);
1420 gdb_assert_not_reached ("invalid type");
1423 return std::unique_ptr
<code_breakpoint
> (b
);
1426 /* A helper function that validates that COMMANDS are valid for a
1427 breakpoint. This function will throw an exception if a problem is
1431 validate_commands_for_breakpoint (struct breakpoint
*b
,
1432 struct command_line
*commands
)
1434 if (is_tracepoint (b
))
1436 struct tracepoint
*t
= (struct tracepoint
*) b
;
1437 struct command_line
*c
;
1438 struct command_line
*while_stepping
= 0;
1440 /* Reset the while-stepping step count. The previous commands
1441 might have included a while-stepping action, while the new
1445 /* We need to verify that each top-level element of commands is
1446 valid for tracepoints, that there's at most one
1447 while-stepping element, and that the while-stepping's body
1448 has valid tracing commands excluding nested while-stepping.
1449 We also need to validate the tracepoint action line in the
1450 context of the tracepoint --- validate_actionline actually
1451 has side effects, like setting the tracepoint's
1452 while-stepping STEP_COUNT, in addition to checking if the
1453 collect/teval actions parse and make sense in the
1454 tracepoint's context. */
1455 for (c
= commands
; c
; c
= c
->next
)
1457 if (c
->control_type
== while_stepping_control
)
1459 if (b
->type
== bp_fast_tracepoint
)
1460 error (_("The 'while-stepping' command "
1461 "cannot be used for fast tracepoint"));
1462 else if (b
->type
== bp_static_tracepoint
1463 || b
->type
== bp_static_marker_tracepoint
)
1464 error (_("The 'while-stepping' command "
1465 "cannot be used for static tracepoint"));
1468 error (_("The 'while-stepping' command "
1469 "can be used only once"));
1474 validate_actionline (c
->line
, b
);
1478 struct command_line
*c2
;
1480 gdb_assert (while_stepping
->body_list_1
== nullptr);
1481 c2
= while_stepping
->body_list_0
.get ();
1482 for (; c2
; c2
= c2
->next
)
1484 if (c2
->control_type
== while_stepping_control
)
1485 error (_("The 'while-stepping' command cannot be nested"));
1491 check_no_tracepoint_commands (commands
);
1495 /* Return a vector of all the static tracepoints set at ADDR. The
1496 caller is responsible for releasing the vector. */
1498 std::vector
<breakpoint
*>
1499 static_tracepoints_here (CORE_ADDR addr
)
1501 std::vector
<breakpoint
*> found
;
1503 for (breakpoint
&b
: all_breakpoints ())
1504 if (b
.type
== bp_static_tracepoint
1505 || b
.type
== bp_static_marker_tracepoint
)
1507 for (bp_location
&loc
: b
.locations ())
1508 if (loc
.address
== addr
)
1509 found
.push_back (&b
);
1515 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1516 validate that only allowed commands are included. */
1519 breakpoint_set_commands (struct breakpoint
*b
,
1520 counted_command_line
&&commands
)
1522 validate_commands_for_breakpoint (b
, commands
.get ());
1524 b
->commands
= std::move (commands
);
1525 notify_breakpoint_modified (b
);
1528 /* Set the internal `silent' flag on the breakpoint. Note that this
1529 is not the same as the "silent" that may appear in the breakpoint's
1533 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1535 int old_silent
= b
->silent
;
1538 if (old_silent
!= silent
)
1539 notify_breakpoint_modified (b
);
1542 /* See breakpoint.h. */
1545 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1547 /* THREAD should be -1, meaning no thread restriction, or it should be a
1548 valid global thread-id, which are greater than zero. */
1549 gdb_assert (thread
== -1 || thread
> 0);
1551 /* It is not valid to set a thread restriction for a breakpoint that
1552 already has task or inferior restriction. */
1553 gdb_assert (thread
== -1 || (b
->task
== -1 && b
->inferior
== -1));
1555 int old_thread
= b
->thread
;
1557 if (old_thread
!= thread
)
1558 notify_breakpoint_modified (b
);
1561 /* See breakpoint.h. */
1564 breakpoint_set_inferior (struct breakpoint
*b
, int inferior
)
1566 /* INFERIOR should be -1, meaning no inferior restriction, or it should
1567 be a valid inferior number, which are greater than zero. */
1568 gdb_assert (inferior
== -1 || inferior
> 0);
1570 /* It is not valid to set an inferior restriction for a breakpoint that
1571 already has a task or thread restriction. */
1572 gdb_assert (inferior
== -1 || (b
->task
== -1 && b
->thread
== -1));
1574 int old_inferior
= b
->inferior
;
1575 b
->inferior
= inferior
;
1576 if (old_inferior
!= inferior
)
1577 notify_breakpoint_modified (b
);
1580 /* See breakpoint.h. */
1583 breakpoint_set_task (struct breakpoint
*b
, int task
)
1585 /* TASK should be -1, meaning no task restriction, or it should be a
1586 valid task-id, which are greater than zero. */
1587 gdb_assert (task
== -1 || task
> 0);
1589 /* It is not valid to set a task restriction for a breakpoint that
1590 already has a thread or inferior restriction. */
1591 gdb_assert (task
== -1 || (b
->thread
== -1 && b
->inferior
== -1));
1593 int old_task
= b
->task
;
1595 if (old_task
!= task
)
1596 notify_breakpoint_modified (b
);
1600 commands_command_1 (const char *arg
, int from_tty
,
1601 struct command_line
*control
)
1603 counted_command_line cmd
;
1604 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1605 NULL after the call to read_command_lines if the user provides an empty
1606 list of command by just typing "end". */
1607 bool cmd_read
= false;
1609 std::string new_arg
;
1611 if (arg
== NULL
|| !*arg
)
1613 /* Argument not explicitly given. Synthesize it. */
1614 if (breakpoint_count
- prev_breakpoint_count
> 1)
1615 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1617 else if (breakpoint_count
> 0)
1618 new_arg
= string_printf ("%d", breakpoint_count
);
1622 /* Create a copy of ARG. This is needed because the "commands"
1623 command may be coming from a script. In that case, the read
1624 line buffer is going to be overwritten in the lambda of
1625 'map_breakpoint_numbers' below when reading the next line
1626 before we are are done parsing the breakpoint numbers. */
1629 arg
= new_arg
.c_str ();
1631 map_breakpoint_numbers
1632 (arg
, [&] (breakpoint
*b
)
1636 gdb_assert (cmd
== NULL
);
1637 if (control
!= NULL
)
1638 cmd
= control
->body_list_0
;
1642 = string_printf (_("Type commands for breakpoint(s) "
1643 "%s, one per line."),
1646 auto do_validate
= [=] (const char *line
)
1648 validate_actionline (line
, b
);
1650 gdb::function_view
<void (const char *)> validator
;
1651 if (is_tracepoint (b
))
1652 validator
= do_validate
;
1654 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1659 /* If a breakpoint was on the list more than once, we don't need to
1661 if (b
->commands
!= cmd
)
1663 validate_commands_for_breakpoint (b
, cmd
.get ());
1665 notify_breakpoint_modified (b
);
1671 commands_command (const char *arg
, int from_tty
)
1673 commands_command_1 (arg
, from_tty
, NULL
);
1676 /* Like commands_command, but instead of reading the commands from
1677 input stream, takes them from an already parsed command structure.
1679 This is used by cli-script.c to DTRT with breakpoint commands
1680 that are part of if and while bodies. */
1681 enum command_control_type
1682 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1684 commands_command_1 (arg
, 0, cmd
);
1685 return simple_control
;
1688 /* Return true if BL->TARGET_INFO contains valid information. */
1691 bp_location_has_shadow (struct bp_location
*bl
)
1693 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1697 if (bl
->target_info
.shadow_len
== 0)
1698 /* BL isn't valid, or doesn't shadow memory. */
1703 /* Update BUF, which is LEN bytes read from the target address
1704 MEMADDR, by replacing a memory breakpoint with its shadowed
1707 If READBUF is not NULL, this buffer must not overlap with the of
1708 the breakpoint location's shadow_contents buffer. Otherwise, a
1709 failed assertion internal error will be raised. */
1712 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1713 const gdb_byte
*writebuf_org
,
1714 ULONGEST memaddr
, LONGEST len
,
1715 struct bp_target_info
*target_info
,
1716 struct gdbarch
*gdbarch
)
1718 /* Now do full processing of the found relevant range of elements. */
1719 CORE_ADDR bp_addr
= 0;
1723 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1724 current_program_space
->aspace
, 0))
1726 /* The breakpoint is inserted in a different address space. */
1730 /* Addresses and length of the part of the breakpoint that
1732 bp_addr
= target_info
->placed_address
;
1733 bp_size
= target_info
->shadow_len
;
1735 if (bp_addr
+ bp_size
<= memaddr
)
1737 /* The breakpoint is entirely before the chunk of memory we are
1742 if (bp_addr
>= memaddr
+ len
)
1744 /* The breakpoint is entirely after the chunk of memory we are
1749 /* Offset within shadow_contents. */
1750 if (bp_addr
< memaddr
)
1752 /* Only copy the second part of the breakpoint. */
1753 bp_size
-= memaddr
- bp_addr
;
1754 bptoffset
= memaddr
- bp_addr
;
1758 if (bp_addr
+ bp_size
> memaddr
+ len
)
1760 /* Only copy the first part of the breakpoint. */
1761 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1764 if (readbuf
!= NULL
)
1766 /* Verify that the readbuf buffer does not overlap with the
1767 shadow_contents buffer. */
1768 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1769 || readbuf
>= (target_info
->shadow_contents
1770 + target_info
->shadow_len
));
1772 /* Update the read buffer with this inserted breakpoint's
1774 memcpy (readbuf
+ bp_addr
- memaddr
,
1775 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1779 const unsigned char *bp
;
1780 CORE_ADDR addr
= target_info
->reqstd_address
;
1783 /* Update the shadow with what we want to write to memory. */
1784 memcpy (target_info
->shadow_contents
+ bptoffset
,
1785 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1787 /* Determine appropriate breakpoint contents and size for this
1789 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1791 /* Update the final write buffer with this inserted
1792 breakpoint's INSN. */
1793 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1797 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1798 by replacing any memory breakpoints with their shadowed contents.
1800 If READBUF is not NULL, this buffer must not overlap with any of
1801 the breakpoint location's shadow_contents buffers. Otherwise,
1802 a failed assertion internal error will be raised.
1804 The range of shadowed area by each bp_location is:
1805 bl->address - bp_locations_placed_address_before_address_max
1806 up to bl->address + bp_locations_shadow_len_after_address_max
1807 The range we were requested to resolve shadows for is:
1808 memaddr ... memaddr + len
1809 Thus the safe cutoff boundaries for performance optimization are
1810 memaddr + len <= (bl->address
1811 - bp_locations_placed_address_before_address_max)
1813 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1816 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1817 const gdb_byte
*writebuf_org
,
1818 ULONGEST memaddr
, LONGEST len
)
1820 /* Left boundary, right boundary and median element of our binary
1822 unsigned bc_l
, bc_r
, bc
;
1824 /* Find BC_L which is a leftmost element which may affect BUF
1825 content. It is safe to report lower value but a failure to
1826 report higher one. */
1829 bc_r
= bp_locations
.size ();
1830 while (bc_l
+ 1 < bc_r
)
1832 struct bp_location
*bl
;
1834 bc
= (bc_l
+ bc_r
) / 2;
1835 bl
= bp_locations
[bc
];
1837 /* Check first BL->ADDRESS will not overflow due to the added
1838 constant. Then advance the left boundary only if we are sure
1839 the BC element can in no way affect the BUF content (MEMADDR
1840 to MEMADDR + LEN range).
1842 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1843 offset so that we cannot miss a breakpoint with its shadow
1844 range tail still reaching MEMADDR. */
1846 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1848 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1855 /* Due to the binary search above, we need to make sure we pick the
1856 first location that's at BC_L's address. E.g., if there are
1857 multiple locations at the same address, BC_L may end up pointing
1858 at a duplicate location, and miss the "master"/"inserted"
1859 location. Say, given locations L1, L2 and L3 at addresses A and
1862 L1@A, L2@A, L3@B, ...
1864 BC_L could end up pointing at location L2, while the "master"
1865 location could be L1. Since the `loc->inserted' flag is only set
1866 on "master" locations, we'd forget to restore the shadow of L1
1869 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1872 /* Now do full processing of the found relevant range of elements. */
1874 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1876 struct bp_location
*bl
= bp_locations
[bc
];
1878 /* bp_location array has BL->OWNER always non-NULL. */
1879 if (bl
->owner
->type
== bp_none
)
1880 warning (_("reading through apparently deleted breakpoint #%d?"),
1883 /* Performance optimization: any further element can no longer affect BUF
1886 if (bl
->address
>= bp_locations_placed_address_before_address_max
1889 - bp_locations_placed_address_before_address_max
)))
1892 if (!bp_location_has_shadow (bl
))
1895 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1896 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1900 /* See breakpoint.h. */
1903 is_breakpoint (const struct breakpoint
*bpt
)
1905 return (bpt
->type
== bp_breakpoint
1906 || bpt
->type
== bp_hardware_breakpoint
1907 || bpt
->type
== bp_dprintf
);
1910 /* Return true if BPT is of any hardware watchpoint kind. */
1913 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1915 return (bpt
->type
== bp_hardware_watchpoint
1916 || bpt
->type
== bp_read_watchpoint
1917 || bpt
->type
== bp_access_watchpoint
);
1920 /* See breakpoint.h. */
1923 is_watchpoint (const struct breakpoint
*bpt
)
1925 return (is_hardware_watchpoint (bpt
)
1926 || bpt
->type
== bp_watchpoint
);
1929 /* Returns true if the current thread and its running state are safe
1930 to evaluate or update watchpoint B. Watchpoints on local
1931 expressions need to be evaluated in the context of the thread that
1932 was current when the watchpoint was created, and, that thread needs
1933 to be stopped to be able to select the correct frame context.
1934 Watchpoints on global expressions can be evaluated on any thread,
1935 and in any state. It is presently left to the target allowing
1936 memory accesses when threads are running. */
1939 watchpoint_in_thread_scope (struct watchpoint
*b
)
1941 return (b
->pspace
== current_program_space
1942 && (b
->watchpoint_thread
== null_ptid
1943 || (inferior_ptid
== b
->watchpoint_thread
1944 && !inferior_thread ()->executing ())));
1947 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1948 associated bp_watchpoint_scope breakpoint. */
1951 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1953 if (w
->related_breakpoint
!= w
)
1955 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1956 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1957 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1958 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1959 w
->related_breakpoint
= w
;
1961 w
->disposition
= disp_del_at_next_stop
;
1962 disable_breakpoint (w
);
1965 /* Extract a bitfield value from value VAL using the bit parameters contained in
1968 static struct value
*
1969 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1971 struct value
*bit_val
;
1976 bit_val
= value::allocate (val
->type ());
1978 val
->unpack_bitfield (bit_val
,
1981 val
->contents_for_printing ().data (),
1987 /* Allocate a dummy location and add it to B. This is required
1988 because bpstat_stop_status requires a location to be able to report
1992 add_dummy_location (struct breakpoint
*b
,
1993 struct program_space
*pspace
)
1995 gdb_assert (!b
->has_locations ());
1997 bp_location
*loc
= new bp_location (b
, bp_loc_other
);
1998 loc
->pspace
= pspace
;
1999 b
->add_location (*loc
);
2002 /* Assuming that B is a watchpoint:
2003 - Reparse watchpoint expression, if REPARSE is true
2004 - Evaluate expression and store the result in B->val
2005 - Evaluate the condition if there is one, and store the result
2007 - Update the list of values that must be watched in B->loc.
2009 If the watchpoint disposition is disp_del_at_next_stop, then do
2010 nothing. If this is local watchpoint that is out of scope, delete
2013 Even with `set breakpoint always-inserted on' the watchpoints are
2014 removed + inserted on each stop here. Normal breakpoints must
2015 never be removed because they might be missed by a running thread
2016 when debugging in non-stop mode. On the other hand, hardware
2017 watchpoints (is_hardware_watchpoint; processed here) are specific
2018 to each LWP since they are stored in each LWP's hardware debug
2019 registers. Therefore, such LWP must be stopped first in order to
2020 be able to modify its hardware watchpoints.
2022 Hardware watchpoints must be reset exactly once after being
2023 presented to the user. It cannot be done sooner, because it would
2024 reset the data used to present the watchpoint hit to the user. And
2025 it must not be done later because it could display the same single
2026 watchpoint hit during multiple GDB stops. Note that the latter is
2027 relevant only to the hardware watchpoint types bp_read_watchpoint
2028 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
2029 not user-visible - its hit is suppressed if the memory content has
2032 The following constraints influence the location where we can reset
2033 hardware watchpoints:
2035 * target_stopped_by_watchpoint and target_stopped_data_address are
2036 called several times when GDB stops.
2039 * Multiple hardware watchpoints can be hit at the same time,
2040 causing GDB to stop. GDB only presents one hardware watchpoint
2041 hit at a time as the reason for stopping, and all the other hits
2042 are presented later, one after the other, each time the user
2043 requests the execution to be resumed. Execution is not resumed
2044 for the threads still having pending hit event stored in
2045 LWP_INFO->STATUS. While the watchpoint is already removed from
2046 the inferior on the first stop the thread hit event is kept being
2047 reported from its cached value by linux_nat_stopped_data_address
2048 until the real thread resume happens after the watchpoint gets
2049 presented and thus its LWP_INFO->STATUS gets reset.
2051 Therefore the hardware watchpoint hit can get safely reset on the
2052 watchpoint removal from inferior. */
2055 update_watchpoint (struct watchpoint
*b
, bool reparse
)
2057 bool within_current_scope
;
2059 /* If this is a local watchpoint, we only want to check if the
2060 watchpoint frame is in scope if the current thread is the thread
2061 that was used to create the watchpoint. */
2062 if (!watchpoint_in_thread_scope (b
))
2065 if (b
->disposition
== disp_del_at_next_stop
)
2068 gdb::optional
<scoped_restore_selected_frame
> restore_frame
;
2070 /* Determine if the watchpoint is within scope. */
2071 if (b
->exp_valid_block
== NULL
)
2072 within_current_scope
= true;
2075 frame_info_ptr fi
= get_current_frame ();
2076 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
2077 CORE_ADDR frame_pc
= get_frame_pc (fi
);
2079 /* If we're at a point where the stack has been destroyed
2080 (e.g. in a function epilogue), unwinding may not work
2081 properly. Do not attempt to recreate locations at this
2082 point. See similar comments in watchpoint_check. */
2083 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
2086 /* Save the current frame's ID so we can restore it after
2087 evaluating the watchpoint expression on its own frame. */
2088 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
2089 took a frame parameter, so that we didn't have to change the
2091 restore_frame
.emplace ();
2093 fi
= frame_find_by_id (b
->watchpoint_frame
);
2094 within_current_scope
= (fi
!= NULL
);
2095 if (within_current_scope
)
2099 /* We don't free locations. They are stored in the bp_location array
2100 and update_global_location_list will eventually delete them and
2101 remove breakpoints if needed. */
2102 b
->clear_locations ();
2104 if (within_current_scope
&& reparse
)
2109 s
= (b
->exp_string_reparse
2110 ? b
->exp_string_reparse
.get ()
2111 : b
->exp_string
.get ());
2112 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
2113 /* If the meaning of expression itself changed, the old value is
2114 no longer relevant. We don't want to report a watchpoint hit
2115 to the user when the old value and the new value may actually
2116 be completely different objects. */
2118 b
->val_valid
= false;
2120 /* Note that unlike with breakpoints, the watchpoint's condition
2121 expression is stored in the breakpoint object, not in the
2122 locations (re)created below. */
2123 if (b
->cond_string
!= NULL
)
2125 b
->cond_exp
.reset ();
2127 s
= b
->cond_string
.get ();
2128 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
2132 /* If we failed to parse the expression, for example because
2133 it refers to a global variable in a not-yet-loaded shared library,
2134 don't try to insert watchpoint. We don't automatically delete
2135 such watchpoint, though, since failure to parse expression
2136 is different from out-of-scope watchpoint. */
2137 if (!target_has_execution ())
2139 /* Without execution, memory can't change. No use to try and
2140 set watchpoint locations. The watchpoint will be reset when
2141 the target gains execution, through breakpoint_re_set. */
2142 if (!can_use_hw_watchpoints
)
2144 if (b
->works_in_software_mode ())
2145 b
->type
= bp_watchpoint
;
2147 error (_("Can't set read/access watchpoint when "
2148 "hardware watchpoints are disabled."));
2151 else if (within_current_scope
&& b
->exp
)
2153 std::vector
<value_ref_ptr
> val_chain
;
2154 struct value
*v
, *result
;
2155 struct program_space
*frame_pspace
;
2157 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2160 /* Avoid setting b->val if it's already set. The meaning of
2161 b->val is 'the last value' user saw, and we should update
2162 it only if we reported that last value to user. As it
2163 happens, the code that reports it updates b->val directly.
2164 We don't keep track of the memory value for masked
2166 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2168 if (b
->val_bitsize
!= 0)
2169 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2170 b
->val
= release_value (v
);
2171 b
->val_valid
= true;
2174 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2176 /* Look at each value on the value chain. */
2177 gdb_assert (!val_chain
.empty ());
2178 for (const value_ref_ptr
&iter
: val_chain
)
2182 /* If it's a memory location, and GDB actually needed
2183 its contents to evaluate the expression, then we
2184 must watch it. If the first value returned is
2185 still lazy, that means an error occurred reading it;
2186 watch it anyway in case it becomes readable. */
2187 if (v
->lval () == lval_memory
2188 && (v
== val_chain
[0] || ! v
->lazy ()))
2190 struct type
*vtype
= check_typedef (v
->type ());
2192 /* We only watch structs and arrays if user asked
2193 for it explicitly, never if they just happen to
2194 appear in the middle of some value chain. */
2196 || (vtype
->code () != TYPE_CODE_STRUCT
2197 && vtype
->code () != TYPE_CODE_ARRAY
))
2200 enum target_hw_bp_type type
;
2201 int bitpos
= 0, bitsize
= 0;
2203 if (v
->bitsize () != 0)
2205 /* Extract the bit parameters out from the bitfield
2207 bitpos
= v
->bitpos ();
2208 bitsize
= v
->bitsize ();
2210 else if (v
== result
&& b
->val_bitsize
!= 0)
2212 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2213 lvalue whose bit parameters are saved in the fields
2214 VAL_BITPOS and VAL_BITSIZE. */
2215 bitpos
= b
->val_bitpos
;
2216 bitsize
= b
->val_bitsize
;
2219 addr
= v
->address ();
2222 /* Skip the bytes that don't contain the bitfield. */
2227 if (b
->type
== bp_read_watchpoint
)
2229 else if (b
->type
== bp_access_watchpoint
)
2232 bp_location
*loc
= b
->allocate_location ();
2233 loc
->gdbarch
= v
->type ()->arch ();
2234 loc
->pspace
= frame_pspace
;
2236 = gdbarch_remove_non_address_bits (loc
->gdbarch
, addr
);
2237 b
->add_location (*loc
);
2241 /* Just cover the bytes that make up the bitfield. */
2242 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2245 loc
->length
= v
->type ()->length ();
2247 loc
->watchpoint_type
= type
;
2252 /* Helper function to bundle possibly emitting a warning along with
2253 changing the type of B to bp_watchpoint. */
2254 auto change_type_to_bp_watchpoint
= [] (breakpoint
*bp
)
2256 /* Only warn for breakpoints that have been assigned a +ve number,
2257 anything else is either an internal watchpoint (which we don't
2258 currently create) or has not yet been finalized, in which case
2259 this change of type will be occurring before the user is told
2260 the type of this watchpoint. */
2261 if (bp
->type
== bp_hardware_watchpoint
&& bp
->number
> 0)
2262 warning (_("watchpoint %d downgraded to software watchpoint"),
2264 bp
->type
= bp_watchpoint
;
2267 /* Change the type of breakpoint between hardware assisted or
2268 an ordinary watchpoint depending on the hardware support and
2269 free hardware slots. Recheck the number of free hardware slots
2270 as the value chain may have changed. */
2273 enum bp_loc_type loc_type
;
2275 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2279 int i
, target_resources_ok
, other_type_used
;
2282 /* Use an exact watchpoint when there's only one memory region to be
2283 watched, and only one debug register is needed to watch it. */
2284 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2286 /* We need to determine how many resources are already
2287 used for all other hardware watchpoints plus this one
2288 to see if we still have enough resources to also fit
2289 this watchpoint in as well. */
2291 /* If this is a software watchpoint, we try to turn it
2292 to a hardware one -- count resources as if B was of
2293 hardware watchpoint type. */
2295 if (type
== bp_watchpoint
)
2296 type
= bp_hardware_watchpoint
;
2298 /* This watchpoint may or may not have been placed on
2299 the list yet at this point (it won't be in the list
2300 if we're trying to create it for the first time,
2301 through watch_command), so always account for it
2304 /* Count resources used by all watchpoints except B. */
2305 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2307 /* Add in the resources needed for B. */
2308 i
+= hw_watchpoint_use_count (b
);
2311 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2312 if (target_resources_ok
<= 0)
2314 bool sw_mode
= b
->works_in_software_mode ();
2316 if (target_resources_ok
== 0 && !sw_mode
)
2317 error (_("Target does not support this type of "
2318 "hardware watchpoint."));
2319 else if (target_resources_ok
< 0 && !sw_mode
)
2320 error (_("There are not enough available hardware "
2321 "resources for this watchpoint."));
2323 /* Downgrade to software watchpoint. */
2324 change_type_to_bp_watchpoint (b
);
2328 /* If this was a software watchpoint, we've just
2329 found we have enough resources to turn it to a
2330 hardware watchpoint. Otherwise, this is a
2335 else if (!b
->works_in_software_mode ())
2337 if (!can_use_hw_watchpoints
)
2338 error (_("Can't set read/access watchpoint when "
2339 "hardware watchpoints are disabled."));
2341 error (_("Expression cannot be implemented with "
2342 "read/access watchpoint."));
2345 change_type_to_bp_watchpoint (b
);
2347 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_software_watchpoint
2348 : bp_loc_hardware_watchpoint
);
2350 for (bp_location
&bl
: b
->locations ())
2351 bl
.loc_type
= loc_type
;
2354 /* If a software watchpoint is not watching any memory, then the
2355 above left it without any location set up. But,
2356 bpstat_stop_status requires a location to be able to report
2357 stops, so make sure there's at least a dummy one. */
2358 if (b
->type
== bp_watchpoint
&& !b
->has_locations ())
2359 add_dummy_location (b
, frame_pspace
);
2361 else if (!within_current_scope
)
2364 Watchpoint %d deleted because the program has left the block\n\
2365 in which its expression is valid.\n"),
2367 watchpoint_del_at_next_stop (b
);
2371 /* Returns true iff breakpoint location should be
2372 inserted in the inferior. We don't differentiate the type of BL's owner
2373 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2374 breakpoint_ops is not defined, because in insert_bp_location,
2375 tracepoint's insert_location will not be called. */
2378 should_be_inserted (struct bp_location
*bl
)
2380 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2383 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2386 if (!bl
->enabled
|| bl
->disabled_by_cond
2387 || bl
->shlib_disabled
|| bl
->duplicate
)
2390 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2393 /* This is set for example, when we're attached to the parent of a
2394 vfork, and have detached from the child. The child is running
2395 free, and we expect it to do an exec or exit, at which point the
2396 OS makes the parent schedulable again (and the target reports
2397 that the vfork is done). Until the child is done with the shared
2398 memory region, do not insert breakpoints in the parent, otherwise
2399 the child could still trip on the parent's breakpoints. Since
2400 the parent is blocked anyway, it won't miss any breakpoint. */
2401 if (bl
->pspace
->breakpoints_not_allowed
)
2404 /* Don't insert a breakpoint if we're trying to step past its
2405 location, except if the breakpoint is a single-step breakpoint,
2406 and the breakpoint's thread is the thread which is stepping past
2408 if ((bl
->loc_type
== bp_loc_software_breakpoint
2409 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2410 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2412 /* The single-step breakpoint may be inserted at the location
2413 we're trying to step if the instruction branches to itself.
2414 However, the instruction won't be executed at all and it may
2415 break the semantics of the instruction, for example, the
2416 instruction is a conditional branch or updates some flags.
2417 We can't fix it unless GDB is able to emulate the instruction
2418 or switch to displaced stepping. */
2419 && !(bl
->owner
->type
== bp_single_step
2420 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2422 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2423 paddress (bl
->gdbarch
, bl
->address
));
2427 /* Don't insert watchpoints if we're trying to step past the
2428 instruction that triggered one. */
2429 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2430 && stepping_past_nonsteppable_watchpoint ())
2432 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2433 "skipping watchpoint at %s:%d",
2434 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2441 /* Same as should_be_inserted but does the check assuming
2442 that the location is not duplicated. */
2445 unduplicated_should_be_inserted (struct bp_location
*bl
)
2447 scoped_restore restore_bl_duplicate
2448 = make_scoped_restore (&bl
->duplicate
, 0);
2450 return should_be_inserted (bl
);
2453 /* Parses a conditional described by an expression COND into an
2454 agent expression bytecode suitable for evaluation
2455 by the bytecode interpreter. Return NULL if there was
2456 any error during parsing. */
2458 static agent_expr_up
2459 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2464 agent_expr_up aexpr
;
2466 /* We don't want to stop processing, so catch any errors
2467 that may show up. */
2470 aexpr
= gen_eval_for_expr (scope
, cond
);
2473 catch (const gdb_exception_error
&ex
)
2475 /* If we got here, it means the condition could not be parsed to a valid
2476 bytecode expression and thus can't be evaluated on the target's side.
2477 It's no use iterating through the conditions. */
2480 /* We have a valid agent expression. */
2484 /* Based on location BL, create a list of breakpoint conditions to be
2485 passed on to the target. If we have duplicated locations with different
2486 conditions, we will add such conditions to the list. The idea is that the
2487 target will evaluate the list of conditions and will only notify GDB when
2488 one of them is true. */
2491 build_target_condition_list (struct bp_location
*bl
)
2493 bool null_condition_or_parse_error
= false;
2494 int modified
= bl
->needs_update
;
2496 /* Release conditions left over from a previous insert. */
2497 bl
->target_info
.conditions
.clear ();
2499 /* This is only meaningful if the target is
2500 evaluating conditions and if the user has
2501 opted for condition evaluation on the target's
2503 if (gdb_evaluates_breakpoint_condition_p ()
2504 || !target_supports_evaluation_of_breakpoint_conditions ())
2507 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2509 /* Do a first pass to check for locations with no assigned
2510 conditions or conditions that fail to parse to a valid agent
2511 expression bytecode. If any of these happen, then it's no use to
2512 send conditions to the target since this location will always
2513 trigger and generate a response back to GDB. Note we consider
2514 all locations at the same address irrespective of type, i.e.,
2515 even if the locations aren't considered duplicates (e.g.,
2516 software breakpoint and hardware breakpoint at the same
2518 for (bp_location
*loc
: loc_range
)
2520 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2524 /* Re-parse the conditions since something changed. In that
2525 case we already freed the condition bytecodes (see
2526 force_breakpoint_reinsertion). We just
2527 need to parse the condition to bytecodes again. */
2528 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2532 /* If we have a NULL bytecode expression, it means something
2533 went wrong or we have a null condition expression. */
2534 if (!loc
->cond_bytecode
)
2536 null_condition_or_parse_error
= true;
2542 /* If any of these happened, it means we will have to evaluate the conditions
2543 for the location's address on gdb's side. It is no use keeping bytecodes
2544 for all the other duplicate locations, thus we free all of them here.
2546 This is so we have a finer control over which locations' conditions are
2547 being evaluated by GDB or the remote stub. */
2548 if (null_condition_or_parse_error
)
2550 for (bp_location
*loc
: loc_range
)
2552 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2554 /* Only go as far as the first NULL bytecode is
2556 if (!loc
->cond_bytecode
)
2559 loc
->cond_bytecode
.reset ();
2564 /* No NULL conditions or failed bytecode generation. Build a
2565 condition list for this location's address. If we have software
2566 and hardware locations at the same address, they aren't
2567 considered duplicates, but we still merge all the conditions
2568 anyway, as it's simpler, and doesn't really make a practical
2570 for (bp_location
*loc
: loc_range
)
2572 && is_breakpoint (loc
->owner
)
2573 && loc
->pspace
->num
== bl
->pspace
->num
2574 && loc
->owner
->enable_state
== bp_enabled
2576 && !loc
->disabled_by_cond
)
2578 /* Add the condition to the vector. This will be used later
2579 to send the conditions to the target. */
2580 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2586 /* Parses a command described by string CMD into an agent expression
2587 bytecode suitable for evaluation by the bytecode interpreter.
2588 Return NULL if there was any error during parsing. */
2590 static agent_expr_up
2591 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2593 const char *cmdrest
;
2594 const char *format_start
, *format_end
;
2595 struct gdbarch
*gdbarch
= get_current_arch ();
2602 if (*cmdrest
== ',')
2604 cmdrest
= skip_spaces (cmdrest
);
2606 if (*cmdrest
++ != '"')
2607 error (_("No format string following the location"));
2609 format_start
= cmdrest
;
2611 format_pieces
fpieces (&cmdrest
);
2613 format_end
= cmdrest
;
2615 if (*cmdrest
++ != '"')
2616 error (_("Bad format string, non-terminated '\"'."));
2618 cmdrest
= skip_spaces (cmdrest
);
2620 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2621 error (_("Invalid argument syntax"));
2623 if (*cmdrest
== ',')
2625 cmdrest
= skip_spaces (cmdrest
);
2627 /* For each argument, make an expression. */
2629 std::vector
<struct expression
*> argvec
;
2630 while (*cmdrest
!= '\0')
2635 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
),
2636 PARSER_COMMA_TERMINATES
);
2637 argvec
.push_back (expr
.release ());
2639 if (*cmdrest
== ',')
2643 agent_expr_up aexpr
;
2645 /* We don't want to stop processing, so catch any errors
2646 that may show up. */
2649 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2650 format_start
, format_end
- format_start
,
2651 argvec
.size (), argvec
.data ());
2653 catch (const gdb_exception_error
&ex
)
2655 /* If we got here, it means the command could not be parsed to a valid
2656 bytecode expression and thus can't be evaluated on the target's side.
2657 It's no use iterating through the other commands. */
2660 /* We have a valid agent expression, return it. */
2664 /* Based on location BL, create a list of breakpoint commands to be
2665 passed on to the target. If we have duplicated locations with
2666 different commands, we will add any such to the list. */
2669 build_target_command_list (struct bp_location
*bl
)
2671 bool null_command_or_parse_error
= false;
2672 int modified
= bl
->needs_update
;
2674 /* Clear commands left over from a previous insert. */
2675 bl
->target_info
.tcommands
.clear ();
2677 if (!target_can_run_breakpoint_commands ())
2680 /* For now, limit to agent-style dprintf breakpoints. */
2681 if (dprintf_style
!= dprintf_style_agent
)
2684 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2686 /* For now, if we have any location at the same address that isn't a
2687 dprintf, don't install the target-side commands, as that would
2688 make the breakpoint not be reported to the core, and we'd lose
2690 for (bp_location
*loc
: loc_range
)
2691 if (is_breakpoint (loc
->owner
)
2692 && loc
->pspace
->num
== bl
->pspace
->num
2693 && loc
->owner
->type
!= bp_dprintf
)
2696 /* Do a first pass to check for locations with no assigned
2697 conditions or conditions that fail to parse to a valid agent expression
2698 bytecode. If any of these happen, then it's no use to send conditions
2699 to the target since this location will always trigger and generate a
2700 response back to GDB. */
2701 for (bp_location
*loc
: loc_range
)
2703 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2707 /* Re-parse the commands since something changed. In that
2708 case we already freed the command bytecodes (see
2709 force_breakpoint_reinsertion). We just
2710 need to parse the command to bytecodes again. */
2712 = parse_cmd_to_aexpr (bl
->address
,
2713 loc
->owner
->extra_string
.get ());
2716 /* If we have a NULL bytecode expression, it means something
2717 went wrong or we have a null command expression. */
2718 if (!loc
->cmd_bytecode
)
2720 null_command_or_parse_error
= true;
2726 /* If anything failed, then we're not doing target-side commands,
2728 if (null_command_or_parse_error
)
2730 for (bp_location
*loc
: loc_range
)
2731 if (is_breakpoint (loc
->owner
)
2732 && loc
->pspace
->num
== bl
->pspace
->num
)
2734 /* Only go as far as the first NULL bytecode is
2736 if (loc
->cmd_bytecode
== NULL
)
2739 loc
->cmd_bytecode
.reset ();
2743 /* No NULL commands or failed bytecode generation. Build a command
2744 list for all duplicate locations at this location's address.
2745 Note that here we must care for whether the breakpoint location
2746 types are considered duplicates, otherwise, say, if we have a
2747 software and hardware location at the same address, the target
2748 could end up running the commands twice. For the moment, we only
2749 support targets-side commands with dprintf, but it doesn't hurt
2750 to be pedantically correct in case that changes. */
2751 for (bp_location
*loc
: loc_range
)
2752 if (breakpoint_locations_match (bl
, loc
)
2753 && loc
->owner
->extra_string
2754 && is_breakpoint (loc
->owner
)
2755 && loc
->pspace
->num
== bl
->pspace
->num
2756 && loc
->owner
->enable_state
== bp_enabled
2758 && !loc
->disabled_by_cond
)
2760 /* Add the command to the vector. This will be used later
2761 to send the commands to the target. */
2762 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2765 bl
->target_info
.persist
= 0;
2766 /* Maybe flag this location as persistent. */
2767 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2768 bl
->target_info
.persist
= 1;
2771 /* Return the kind of breakpoint on address *ADDR. Get the kind
2772 of breakpoint according to ADDR except single-step breakpoint.
2773 Get the kind of single-step breakpoint according to the current
2777 breakpoint_kind (const struct bp_location
*bl
, CORE_ADDR
*addr
)
2779 if (bl
->owner
->type
== bp_single_step
)
2781 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2782 struct regcache
*regcache
;
2784 regcache
= get_thread_regcache (thr
);
2786 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2790 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2793 /* Rethrow the currently handled exception, if it's a TARGET_CLOSE_ERROR.
2794 E is either the currently handled exception, or a copy, or a sliced copy,
2795 so we can't rethrow that one, but we can use it to inspect the properties
2796 of the currently handled exception. */
2799 rethrow_on_target_close_error (const gdb_exception
&e
)
2803 /* Can't set the breakpoint. */
2805 if (e
.error
!= TARGET_CLOSE_ERROR
)
2808 /* If the target has closed then it will have deleted any breakpoints
2809 inserted within the target inferior, as a result any further attempts
2810 to interact with the breakpoint objects is not possible. Just rethrow
2811 the error. Don't use e to rethrow, to prevent object slicing of the
2816 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2817 location. Any error messages are printed to TMP_ERROR_STREAM; and
2818 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2819 Returns 0 for success, 1 if the bp_location type is not supported or
2822 NOTE drow/2003-09-09: This routine could be broken down to an
2823 object-style method for each breakpoint or catchpoint type. */
2825 insert_bp_location (struct bp_location
*bl
,
2826 struct ui_file
*tmp_error_stream
,
2827 int *disabled_breaks
,
2828 int *hw_breakpoint_error
,
2829 int *hw_bp_error_explained_already
)
2831 gdb_exception bp_excpt
;
2833 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2836 breakpoint_debug_printf ("%s", breakpoint_location_address_str (bl
).c_str ());
2838 /* Note we don't initialize bl->target_info, as that wipes out
2839 the breakpoint location's shadow_contents if the breakpoint
2840 is still inserted at that location. This in turn breaks
2841 target_read_memory which depends on these buffers when
2842 a memory read is requested at the breakpoint location:
2843 Once the target_info has been wiped, we fail to see that
2844 we have a breakpoint inserted at that address and thus
2845 read the breakpoint instead of returning the data saved in
2846 the breakpoint location's shadow contents. */
2847 bl
->target_info
.reqstd_address
= bl
->address
;
2848 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2849 bl
->target_info
.length
= bl
->length
;
2851 /* When working with target-side conditions, we must pass all the conditions
2852 for the same breakpoint address down to the target since GDB will not
2853 insert those locations. With a list of breakpoint conditions, the target
2854 can decide when to stop and notify GDB. */
2856 if (is_breakpoint (bl
->owner
))
2858 build_target_condition_list (bl
);
2859 build_target_command_list (bl
);
2860 /* Reset the modification marker. */
2861 bl
->needs_update
= 0;
2864 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2865 set at a read-only address, then a breakpoint location will have
2866 been changed to hardware breakpoint before we get here. If it is
2867 "off" however, error out before actually trying to insert the
2868 breakpoint, with a nicer error message. */
2869 if (bl
->loc_type
== bp_loc_software_breakpoint
2870 && !automatic_hardware_breakpoints
)
2872 mem_region
*mr
= lookup_mem_region (bl
->address
);
2874 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2876 gdb_printf (tmp_error_stream
,
2877 _("Cannot insert breakpoint %d.\n"
2878 "Cannot set software breakpoint "
2879 "at read-only address %s\n"),
2881 paddress (bl
->gdbarch
, bl
->address
));
2886 if (bl
->loc_type
== bp_loc_software_breakpoint
2887 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2889 /* First check to see if we have to handle an overlay. */
2890 if (overlay_debugging
== ovly_off
2891 || bl
->section
== NULL
2892 || !(section_is_overlay (bl
->section
)))
2894 /* No overlay handling: just set the breakpoint. */
2899 val
= bl
->owner
->insert_location (bl
);
2901 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2903 catch (gdb_exception
&e
)
2905 rethrow_on_target_close_error (e
);
2906 bp_excpt
= std::move (e
);
2911 /* This breakpoint is in an overlay section.
2912 Shall we set a breakpoint at the LMA? */
2913 if (!overlay_events_enabled
)
2915 /* Yes -- overlay event support is not active,
2916 so we must try to set a breakpoint at the LMA.
2917 This will not work for a hardware breakpoint. */
2918 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2919 warning (_("hardware breakpoint %d not supported in overlay!"),
2923 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2925 /* Set a software (trap) breakpoint at the LMA. */
2926 bl
->overlay_target_info
= bl
->target_info
;
2927 bl
->overlay_target_info
.reqstd_address
= addr
;
2929 /* No overlay handling: just set the breakpoint. */
2934 bl
->overlay_target_info
.kind
2935 = breakpoint_kind (bl
, &addr
);
2936 bl
->overlay_target_info
.placed_address
= addr
;
2937 val
= target_insert_breakpoint (bl
->gdbarch
,
2938 &bl
->overlay_target_info
);
2941 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2943 catch (gdb_exception
&e
)
2945 rethrow_on_target_close_error (e
);
2946 bp_excpt
= std::move (e
);
2949 if (bp_excpt
.reason
!= 0)
2950 gdb_printf (tmp_error_stream
,
2951 "Overlay breakpoint %d "
2952 "failed: in ROM?\n",
2956 /* Shall we set a breakpoint at the VMA? */
2957 if (section_is_mapped (bl
->section
))
2959 /* Yes. This overlay section is mapped into memory. */
2964 val
= bl
->owner
->insert_location (bl
);
2966 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2968 catch (gdb_exception_error
&e
)
2970 rethrow_on_target_close_error (e
);
2971 bp_excpt
= std::move (e
);
2976 /* No. This breakpoint will not be inserted.
2977 No error, but do not mark the bp as 'inserted'. */
2982 if (bp_excpt
.reason
!= 0)
2984 /* Can't set the breakpoint. */
2985 gdb_assert (bl
->owner
!= nullptr);
2987 /* In some cases, we might not be able to insert a
2988 breakpoint in a shared library that has already been
2989 removed, but we have not yet processed the shlib unload
2990 event. Unfortunately, some targets that implement
2991 breakpoint insertion themselves can't tell why the
2992 breakpoint insertion failed (e.g., the remote target
2993 doesn't define error codes), so we must treat generic
2994 errors as memory errors. */
2995 if (bp_excpt
.reason
== RETURN_ERROR
2996 && (bp_excpt
.error
== GENERIC_ERROR
2997 || bp_excpt
.error
== MEMORY_ERROR
)
2998 && bl
->loc_type
== bp_loc_software_breakpoint
2999 && (solib_name_from_address (bl
->pspace
, bl
->address
)
3000 || shared_objfile_contains_address_p (bl
->pspace
,
3003 /* See also: disable_breakpoints_in_shlibs. */
3004 bl
->shlib_disabled
= 1;
3005 notify_breakpoint_modified (bl
->owner
);
3006 if (!*disabled_breaks
)
3008 gdb_printf (tmp_error_stream
,
3009 "Cannot insert breakpoint %d.\n",
3011 gdb_printf (tmp_error_stream
,
3012 "Temporarily disabling shared "
3013 "library breakpoints:\n");
3015 *disabled_breaks
= 1;
3016 gdb_printf (tmp_error_stream
,
3017 "breakpoint #%d\n", bl
->owner
->number
);
3022 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3024 *hw_breakpoint_error
= 1;
3025 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
3026 gdb_printf (tmp_error_stream
,
3027 "Cannot insert hardware breakpoint %d%s",
3029 bp_excpt
.message
? ":" : ".\n");
3030 if (bp_excpt
.message
!= NULL
)
3031 gdb_printf (tmp_error_stream
, "%s.\n",
3036 if (bp_excpt
.message
== NULL
)
3039 = memory_error_message (TARGET_XFER_E_IO
,
3040 bl
->gdbarch
, bl
->address
);
3042 gdb_printf (tmp_error_stream
,
3043 "Cannot insert breakpoint %d.\n"
3045 bl
->owner
->number
, message
.c_str ());
3049 gdb_printf (tmp_error_stream
,
3050 "Cannot insert breakpoint %d: %s\n",
3065 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
3066 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
3070 val
= bl
->owner
->insert_location (bl
);
3072 /* If trying to set a read-watchpoint, and it turns out it's not
3073 supported, try emulating one with an access watchpoint. */
3074 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
3076 /* But don't try to insert it, if there's already another
3077 hw_access location that would be considered a duplicate
3079 for (bp_location
*loc
: all_bp_locations ())
3081 && loc
->watchpoint_type
== hw_access
3082 && watchpoint_locations_match (bl
, loc
))
3086 bl
->target_info
= loc
->target_info
;
3087 bl
->watchpoint_type
= hw_access
;
3094 bl
->watchpoint_type
= hw_access
;
3095 val
= bl
->owner
->insert_location (bl
);
3098 /* Back to the original value. */
3099 bl
->watchpoint_type
= hw_read
;
3103 bl
->inserted
= (val
== 0);
3106 else if (bl
->owner
->type
== bp_catchpoint
)
3110 val
= bl
->owner
->insert_location (bl
);
3113 bl
->owner
->enable_state
= bp_disabled
;
3117 Error inserting catchpoint %d: Your system does not support this type\n\
3118 of catchpoint."), bl
->owner
->number
);
3120 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
3123 bl
->inserted
= (val
== 0);
3125 /* We've already printed an error message if there was a problem
3126 inserting this catchpoint, and we've disabled the catchpoint,
3127 so just return success. */
3134 /* This function is called when program space PSPACE is about to be
3135 deleted. It takes care of updating breakpoints to not reference
3139 breakpoint_program_space_exit (struct program_space
*pspace
)
3141 /* Remove any breakpoint that was set through this program space. */
3142 for (breakpoint
&b
: all_breakpoints_safe ())
3143 if (b
.pspace
== pspace
)
3144 delete_breakpoint (&b
);
3146 /* Breakpoints set through other program spaces could have locations
3147 bound to PSPACE as well. Remove those. */
3148 for (bp_location
*loc
: all_bp_locations ())
3149 if (loc
->pspace
== pspace
)
3151 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3152 loc
->owner
->unadd_location (*loc
);
3155 /* Now update the global location list to permanently delete the
3156 removed locations above. */
3157 update_global_location_list (UGLL_DONT_INSERT
);
3160 /* Make sure all breakpoints are inserted in inferior.
3161 Throws exception on any error.
3162 A breakpoint that is already inserted won't be inserted
3163 again, so calling this function twice is safe. */
3165 insert_breakpoints (void)
3167 for (breakpoint
&bpt
: all_breakpoints ())
3168 if (is_hardware_watchpoint (&bpt
))
3170 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (bpt
);
3172 update_watchpoint (&w
, false /* don't reparse. */);
3175 /* Updating watchpoints creates new locations, so update the global
3176 location list. Explicitly tell ugll to insert locations and
3177 ignore breakpoints_always_inserted_mode. Also,
3178 update_global_location_list tries to "upgrade" software
3179 breakpoints to hardware breakpoints to handle "set breakpoint
3180 auto-hw", so we need to call it even if we don't have new
3182 update_global_location_list (UGLL_INSERT
);
3185 /* This is used when we need to synch breakpoint conditions between GDB and the
3186 target. It is the case with deleting and disabling of breakpoints when using
3187 always-inserted mode. */
3190 update_inserted_breakpoint_locations (void)
3194 int disabled_breaks
= 0;
3195 int hw_breakpoint_error
= 0;
3196 int hw_bp_details_reported
= 0;
3198 string_file tmp_error_stream
;
3200 /* Explicitly mark the warning -- this will only be printed if
3201 there was an error. */
3202 tmp_error_stream
.puts ("Warning:\n");
3204 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3206 for (bp_location
*bl
: all_bp_locations ())
3208 /* We only want to update software breakpoints and hardware
3210 if (!is_breakpoint (bl
->owner
))
3213 /* We only want to update locations that are already inserted
3214 and need updating. This is to avoid unwanted insertion during
3215 deletion of breakpoints. */
3216 if (!bl
->inserted
|| !bl
->needs_update
)
3219 switch_to_program_space_and_thread (bl
->pspace
);
3221 /* For targets that support global breakpoints, there's no need
3222 to select an inferior to insert breakpoint to. In fact, even
3223 if we aren't attached to any process yet, we should still
3224 insert breakpoints. */
3225 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3226 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3229 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3230 &hw_breakpoint_error
, &hw_bp_details_reported
);
3237 target_terminal::ours_for_output ();
3238 error (("%s"), tmp_error_stream
.c_str ());
3242 /* Used when starting or continuing the program. */
3245 insert_breakpoint_locations (void)
3249 int disabled_breaks
= 0;
3250 int hw_breakpoint_error
= 0;
3251 int hw_bp_error_explained_already
= 0;
3253 string_file tmp_error_stream
;
3255 /* Explicitly mark the warning -- this will only be printed if
3256 there was an error. */
3257 tmp_error_stream
.puts ("Warning:\n");
3259 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3261 for (bp_location
*bl
: all_bp_locations ())
3263 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3266 /* There is no point inserting thread-specific breakpoints if
3267 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3268 has BL->OWNER always non-NULL. */
3269 if (bl
->owner
->thread
!= -1
3270 && !valid_global_thread_id (bl
->owner
->thread
))
3273 /* Or inferior specific breakpoints if the inferior no longer
3275 if (bl
->owner
->inferior
!= -1
3276 && !valid_global_inferior_id (bl
->owner
->inferior
))
3279 switch_to_program_space_and_thread (bl
->pspace
);
3281 /* For targets that support global breakpoints, there's no need
3282 to select an inferior to insert breakpoint to. In fact, even
3283 if we aren't attached to any process yet, we should still
3284 insert breakpoints. */
3285 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3286 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3289 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3290 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3295 /* If we failed to insert all locations of a watchpoint, remove
3296 them, as half-inserted watchpoint is of limited use. */
3297 for (breakpoint
&bpt
: all_breakpoints ())
3299 bool some_failed
= false;
3301 if (!is_hardware_watchpoint (&bpt
))
3304 if (!breakpoint_enabled (&bpt
))
3307 if (bpt
.disposition
== disp_del_at_next_stop
)
3310 for (bp_location
&loc
: bpt
.locations ())
3311 if (!loc
.inserted
&& should_be_inserted (&loc
))
3319 for (bp_location
&loc
: bpt
.locations ())
3321 remove_breakpoint (&loc
);
3323 hw_breakpoint_error
= 1;
3324 tmp_error_stream
.printf ("Could not insert "
3325 "hardware watchpoint %d.\n",
3333 /* If a hardware breakpoint or watchpoint was inserted, add a
3334 message about possibly exhausted resources. */
3335 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3337 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3338 You may have requested too many hardware breakpoints/watchpoints.\n");
3340 target_terminal::ours_for_output ();
3341 error (("%s"), tmp_error_stream
.c_str ());
3345 /* Used when the program stops.
3346 Returns zero if successful, or non-zero if there was a problem
3347 removing a breakpoint location. */
3350 remove_breakpoints (void)
3354 for (bp_location
*bl
: all_bp_locations ())
3355 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3356 val
|= remove_breakpoint (bl
);
3361 /* When a thread exits, remove breakpoints that are related to
3365 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3367 for (breakpoint
&b
: all_breakpoints_safe ())
3369 if (b
.thread
== tp
->global_num
&& user_breakpoint_p (&b
))
3372 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3373 b
.number
, print_thread_id (tp
));
3374 delete_breakpoint (&b
);
3379 /* Called when inferior INF has been removed from GDB. Remove associated
3380 per-inferior breakpoints. */
3383 remove_inferior_breakpoints (struct inferior
*inf
)
3385 for (breakpoint
&b
: all_breakpoints_safe ())
3387 if (b
.inferior
== inf
->num
&& user_breakpoint_p (&b
))
3389 /* Tell the user the breakpoint has been deleted. But only for
3390 breakpoints that would not normally have been deleted at the
3391 next stop anyway. */
3392 if (b
.disposition
!= disp_del
3393 && b
.disposition
!= disp_del_at_next_stop
)
3395 Inferior-specific breakpoint %d deleted - inferior %d has been removed.\n"),
3396 b
.number
, inf
->num
);
3397 delete_breakpoint (&b
);
3402 /* See breakpoint.h. */
3405 remove_breakpoints_inf (inferior
*inf
)
3409 breakpoint_debug_printf ("inf->num = %d", inf
->num
);
3411 for (bp_location
*bl
: all_bp_locations ())
3413 if (bl
->pspace
!= inf
->pspace
)
3416 if (bl
->inserted
&& !bl
->target_info
.persist
)
3418 val
= remove_breakpoint (bl
);
3425 static int internal_breakpoint_number
= -1;
3427 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3428 If INTERNAL is non-zero, the breakpoint number will be populated
3429 from internal_breakpoint_number and that variable decremented.
3430 Otherwise the breakpoint number will be populated from
3431 breakpoint_count and that value incremented. Internal breakpoints
3432 do not set the internal var bpnum. */
3434 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3437 b
->number
= internal_breakpoint_number
--;
3440 set_breakpoint_count (breakpoint_count
+ 1);
3441 b
->number
= breakpoint_count
;
3445 /* Create a TYPE breakpoint on ADDRESS from an object file with GDBARCH. */
3447 static struct breakpoint
*
3448 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3449 CORE_ADDR address
, enum bptype type
)
3451 std::unique_ptr
<internal_breakpoint
> b
3452 (new internal_breakpoint (gdbarch
, type
, address
));
3454 b
->number
= internal_breakpoint_number
--;
3456 return add_to_breakpoint_chain (std::move (b
));
3459 /* Create a TYPE breakpoint on minimal symbol MSYM from an object file with
3462 static struct breakpoint
*
3463 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3464 struct bound_minimal_symbol
&msym
, enum bptype type
)
3468 address
= msym
.value_address ();
3470 address
= gdbarch_convert_from_func_ptr_addr
3471 (gdbarch
, address
, current_inferior ()->top_target ());
3473 /* Note that we're not using gdbarch_addr_bits_remove here, because that's
3474 related to addresses in $pc. We're getting the address from the
3475 minimal symbol table. */
3477 /* Is gdbarch_deprecated_function_start_offset needed here? Or is that dealt
3478 with elsewhere? Needs testing on vax. */
3480 if (gdbarch_skip_entrypoint_p (gdbarch
))
3481 address
= gdbarch_skip_entrypoint (gdbarch
, address
);
3483 return create_internal_breakpoint (gdbarch
, address
, type
);
3486 static const char *const longjmp_names
[] =
3488 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3490 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3492 /* Per-objfile data private to breakpoint.c. */
3493 struct breakpoint_objfile_data
3495 /* Minimal symbol for "_ovly_debug_event" (if any). */
3496 struct bound_minimal_symbol overlay_msym
;
3498 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3499 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3501 /* True if we have looked for longjmp probes. */
3502 int longjmp_searched
= 0;
3504 /* SystemTap probe points for longjmp (if any). These are non-owning
3506 std::vector
<probe
*> longjmp_probes
;
3508 /* Minimal symbol for "std::terminate()" (if any). */
3509 struct bound_minimal_symbol terminate_msym
;
3511 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3512 struct bound_minimal_symbol exception_msym
;
3514 /* True if we have looked for exception probes. */
3515 int exception_searched
= 0;
3517 /* SystemTap probe points for unwinding (if any). These are non-owning
3519 std::vector
<probe
*> exception_probes
;
3522 static const registry
<objfile
>::key
<breakpoint_objfile_data
>
3523 breakpoint_objfile_key
;
3525 /* Minimal symbol not found sentinel. */
3526 static struct minimal_symbol msym_not_found
;
3528 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3531 msym_not_found_p (const struct minimal_symbol
*msym
)
3533 return msym
== &msym_not_found
;
3536 /* Return per-objfile data needed by breakpoint.c.
3537 Allocate the data if necessary. */
3539 static struct breakpoint_objfile_data
*
3540 get_breakpoint_objfile_data (struct objfile
*objfile
)
3542 struct breakpoint_objfile_data
*bp_objfile_data
;
3544 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3545 if (bp_objfile_data
== NULL
)
3546 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3547 return bp_objfile_data
;
3551 create_overlay_event_breakpoint (void)
3553 const char *const func_name
= "_ovly_debug_event";
3555 for (objfile
*objfile
: current_program_space
->objfiles ())
3557 struct breakpoint
*b
;
3558 struct breakpoint_objfile_data
*bp_objfile_data
;
3561 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3563 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3566 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3568 struct bound_minimal_symbol m
;
3570 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3571 if (m
.minsym
== NULL
)
3573 /* Avoid future lookups in this objfile. */
3574 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3577 bp_objfile_data
->overlay_msym
= m
;
3580 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3581 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3583 b
->locspec
= new_explicit_location_spec_function (func_name
);
3585 if (overlay_debugging
== ovly_auto
)
3587 b
->enable_state
= bp_enabled
;
3588 overlay_events_enabled
= 1;
3592 b
->enable_state
= bp_disabled
;
3593 overlay_events_enabled
= 0;
3598 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3599 true if a breakpoint was installed. */
3602 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3604 struct gdbarch
*gdbarch
= objfile
->arch ();
3605 struct breakpoint_objfile_data
*bp_objfile_data
3606 = get_breakpoint_objfile_data (objfile
);
3608 if (!bp_objfile_data
->longjmp_searched
)
3610 std::vector
<probe
*> ret
3611 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3615 /* We are only interested in checking one element. */
3618 if (!p
->can_evaluate_arguments ())
3620 /* We cannot use the probe interface here,
3621 because it does not know how to evaluate
3626 bp_objfile_data
->longjmp_probes
= ret
;
3627 bp_objfile_data
->longjmp_searched
= 1;
3630 if (bp_objfile_data
->longjmp_probes
.empty ())
3633 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3635 struct breakpoint
*b
;
3637 b
= create_internal_breakpoint (gdbarch
,
3638 p
->get_relocated_address (objfile
),
3640 b
->locspec
= new_probe_location_spec ("-probe-stap libc:longjmp");
3641 b
->enable_state
= bp_disabled
;
3647 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3648 Return true if at least one breakpoint was installed. */
3651 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3653 struct gdbarch
*gdbarch
= objfile
->arch ();
3654 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3657 struct breakpoint_objfile_data
*bp_objfile_data
3658 = get_breakpoint_objfile_data (objfile
);
3659 unsigned int installed_bp
= 0;
3661 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3663 struct breakpoint
*b
;
3664 const char *func_name
;
3667 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3670 func_name
= longjmp_names
[i
];
3671 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3673 struct bound_minimal_symbol m
;
3675 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3676 if (m
.minsym
== NULL
)
3678 /* Prevent future lookups in this objfile. */
3679 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3682 bp_objfile_data
->longjmp_msym
[i
] = m
;
3685 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3686 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3687 b
->locspec
= new_explicit_location_spec_function (func_name
);
3688 b
->enable_state
= bp_disabled
;
3692 return installed_bp
> 0;
3695 /* Create a master longjmp breakpoint. */
3698 create_longjmp_master_breakpoint (void)
3700 scoped_restore_current_program_space restore_pspace
;
3702 for (struct program_space
*pspace
: program_spaces
)
3704 set_current_program_space (pspace
);
3706 for (objfile
*obj
: current_program_space
->objfiles ())
3708 /* Skip separate debug object, it's handled in the loop below. */
3709 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3712 /* Try a probe kind breakpoint on main objfile. */
3713 if (create_longjmp_master_breakpoint_probe (obj
))
3716 /* Try longjmp_names kind breakpoints on main and separate_debug
3718 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3719 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3725 /* Create a master std::terminate breakpoint. */
3727 create_std_terminate_master_breakpoint (void)
3729 const char *const func_name
= "std::terminate()";
3731 scoped_restore_current_program_space restore_pspace
;
3733 for (struct program_space
*pspace
: program_spaces
)
3735 set_current_program_space (pspace
);
3737 for (objfile
*objfile
: current_program_space
->objfiles ())
3739 struct breakpoint
*b
;
3740 struct breakpoint_objfile_data
*bp_objfile_data
;
3742 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3744 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3747 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3749 struct bound_minimal_symbol m
;
3751 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3752 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3753 && m
.minsym
->type () != mst_file_text
))
3755 /* Prevent future lookups in this objfile. */
3756 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3759 bp_objfile_data
->terminate_msym
= m
;
3762 b
= create_internal_breakpoint (objfile
->arch (),
3763 bp_objfile_data
->terminate_msym
,
3764 bp_std_terminate_master
);
3765 b
->locspec
= new_explicit_location_spec_function (func_name
);
3766 b
->enable_state
= bp_disabled
;
3771 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3772 probe. Return true if a breakpoint was installed. */
3775 create_exception_master_breakpoint_probe (objfile
*objfile
)
3777 struct breakpoint
*b
;
3778 struct gdbarch
*gdbarch
;
3779 struct breakpoint_objfile_data
*bp_objfile_data
;
3781 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3783 /* We prefer the SystemTap probe point if it exists. */
3784 if (!bp_objfile_data
->exception_searched
)
3786 std::vector
<probe
*> ret
3787 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3791 /* We are only interested in checking one element. */
3794 if (!p
->can_evaluate_arguments ())
3796 /* We cannot use the probe interface here, because it does
3797 not know how to evaluate arguments. */
3801 bp_objfile_data
->exception_probes
= ret
;
3802 bp_objfile_data
->exception_searched
= 1;
3805 if (bp_objfile_data
->exception_probes
.empty ())
3808 gdbarch
= objfile
->arch ();
3810 for (probe
*p
: bp_objfile_data
->exception_probes
)
3812 b
= create_internal_breakpoint (gdbarch
,
3813 p
->get_relocated_address (objfile
),
3814 bp_exception_master
);
3815 b
->locspec
= new_probe_location_spec ("-probe-stap libgcc:unwind");
3816 b
->enable_state
= bp_disabled
;
3822 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3823 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3826 create_exception_master_breakpoint_hook (objfile
*objfile
)
3828 const char *const func_name
= "_Unwind_DebugHook";
3829 struct breakpoint
*b
;
3830 struct gdbarch
*gdbarch
;
3831 struct breakpoint_objfile_data
*bp_objfile_data
;
3833 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3835 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3838 gdbarch
= objfile
->arch ();
3840 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3842 struct bound_minimal_symbol debug_hook
;
3844 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3845 if (debug_hook
.minsym
== NULL
)
3847 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3851 bp_objfile_data
->exception_msym
= debug_hook
;
3854 b
= create_internal_breakpoint (gdbarch
, bp_objfile_data
->exception_msym
,
3855 bp_exception_master
);
3856 b
->locspec
= new_explicit_location_spec_function (func_name
);
3857 b
->enable_state
= bp_disabled
;
3862 /* Install a master breakpoint on the unwinder's debug hook. */
3865 create_exception_master_breakpoint (void)
3867 for (objfile
*obj
: current_program_space
->objfiles ())
3869 /* Skip separate debug object. */
3870 if (obj
->separate_debug_objfile_backlink
)
3873 /* Try a probe kind breakpoint. */
3874 if (create_exception_master_breakpoint_probe (obj
))
3877 /* Iterate over main and separate debug objects and try an
3878 _Unwind_DebugHook kind breakpoint. */
3879 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3880 if (create_exception_master_breakpoint_hook (debug_objfile
))
3885 /* Does B have a location spec? */
3888 breakpoint_location_spec_empty_p (const struct breakpoint
*b
)
3890 return (b
->locspec
!= nullptr && b
->locspec
->empty_p ());
3894 update_breakpoints_after_exec (void)
3896 /* We're about to delete breakpoints from GDB's lists. If the
3897 INSERTED flag is true, GDB will try to lift the breakpoints by
3898 writing the breakpoints' "shadow contents" back into memory. The
3899 "shadow contents" are NOT valid after an exec, so GDB should not
3900 do that. Instead, the target is responsible from marking
3901 breakpoints out as soon as it detects an exec. We don't do that
3902 here instead, because there may be other attempts to delete
3903 breakpoints after detecting an exec and before reaching here. */
3904 for (bp_location
*bploc
: all_bp_locations ())
3905 if (bploc
->pspace
== current_program_space
)
3906 gdb_assert (!bploc
->inserted
);
3908 for (breakpoint
&b
: all_breakpoints_safe ())
3910 if (b
.pspace
!= current_program_space
)
3913 /* Solib breakpoints must be explicitly reset after an exec(). */
3914 if (b
.type
== bp_shlib_event
)
3916 delete_breakpoint (&b
);
3920 /* JIT breakpoints must be explicitly reset after an exec(). */
3921 if (b
.type
== bp_jit_event
)
3923 delete_breakpoint (&b
);
3927 /* Thread event breakpoints must be set anew after an exec(),
3928 as must overlay event and longjmp master breakpoints. */
3929 if (b
.type
== bp_thread_event
|| b
.type
== bp_overlay_event
3930 || b
.type
== bp_longjmp_master
|| b
.type
== bp_std_terminate_master
3931 || b
.type
== bp_exception_master
)
3933 delete_breakpoint (&b
);
3937 /* Step-resume breakpoints are meaningless after an exec(). */
3938 if (b
.type
== bp_step_resume
|| b
.type
== bp_hp_step_resume
)
3940 delete_breakpoint (&b
);
3944 /* Just like single-step breakpoints. */
3945 if (b
.type
== bp_single_step
)
3947 delete_breakpoint (&b
);
3951 /* Longjmp and longjmp-resume breakpoints are also meaningless
3953 if (b
.type
== bp_longjmp
|| b
.type
== bp_longjmp_resume
3954 || b
.type
== bp_longjmp_call_dummy
3955 || b
.type
== bp_exception
|| b
.type
== bp_exception_resume
)
3957 delete_breakpoint (&b
);
3961 if (b
.type
== bp_catchpoint
)
3963 /* For now, none of the bp_catchpoint breakpoints need to
3964 do anything at this point. In the future, if some of
3965 the catchpoints need to something, we will need to add
3966 a new method, and call this method from here. */
3970 /* bp_finish is a special case. The only way we ought to be able
3971 to see one of these when an exec() has happened, is if the user
3972 caught a vfork, and then said "finish". Ordinarily a finish just
3973 carries them to the call-site of the current callee, by setting
3974 a temporary bp there and resuming. But in this case, the finish
3975 will carry them entirely through the vfork & exec.
3977 We don't want to allow a bp_finish to remain inserted now. But
3978 we can't safely delete it, 'cause finish_command has a handle to
3979 the bp on a bpstat, and will later want to delete it. There's a
3980 chance (and I've seen it happen) that if we delete the bp_finish
3981 here, that its storage will get reused by the time finish_command
3982 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3983 We really must allow finish_command to delete a bp_finish.
3985 In the absence of a general solution for the "how do we know
3986 it's safe to delete something others may have handles to?"
3987 problem, what we'll do here is just uninsert the bp_finish, and
3988 let finish_command delete it.
3990 (We know the bp_finish is "doomed" in the sense that it's
3991 momentary, and will be deleted as soon as finish_command sees
3992 the inferior stopped. So it doesn't matter that the bp's
3993 address is probably bogus in the new a.out, unlike e.g., the
3994 solib breakpoints.) */
3996 if (b
.type
== bp_finish
)
4001 /* Without a symbolic address, we have little hope of the
4002 pre-exec() address meaning the same thing in the post-exec()
4004 if (breakpoint_location_spec_empty_p (&b
))
4006 delete_breakpoint (&b
);
4013 detach_breakpoints (ptid_t ptid
)
4016 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
4017 struct inferior
*inf
= current_inferior ();
4019 if (ptid
.pid () == inferior_ptid
.pid ())
4020 error (_("Cannot detach breakpoints of inferior_ptid"));
4022 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
4023 inferior_ptid
= ptid
;
4024 for (bp_location
*bl
: all_bp_locations ())
4026 if (bl
->pspace
!= inf
->pspace
)
4029 /* This function must physically remove breakpoints locations
4030 from the specified ptid, without modifying the breakpoint
4031 package's state. Locations of type bp_loc_other and
4032 bp_loc_software_watchpoint are only maintained at GDB side,
4033 so there is no need to remove them. Moreover, removing these
4034 would modify the breakpoint package's state. */
4035 if (bl
->loc_type
== bp_loc_other
4036 || bl
->loc_type
== bp_loc_software_watchpoint
)
4040 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
4046 /* Remove the breakpoint location BL from the current address space.
4047 Note that this is used to detach breakpoints from a child fork.
4048 When we get here, the child isn't in the inferior list, and neither
4049 do we have objects to represent its address space --- we should
4050 *not* look at bl->pspace->aspace here. */
4053 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
4055 breakpoint_debug_printf ("%s due to %s",
4056 breakpoint_location_address_str (bl
).c_str (),
4057 remove_bp_reason_str (reason
));
4061 /* BL is never in moribund_locations by our callers. */
4062 gdb_assert (bl
->owner
!= NULL
);
4064 /* The type of none suggests that owner is actually deleted.
4065 This should not ever happen. */
4066 gdb_assert (bl
->owner
->type
!= bp_none
);
4068 if (bl
->loc_type
== bp_loc_software_breakpoint
4069 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
4071 /* "Normal" instruction breakpoint: either the standard
4072 trap-instruction bp (bp_breakpoint), or a
4073 bp_hardware_breakpoint. */
4075 /* First check to see if we have to handle an overlay. */
4076 if (overlay_debugging
== ovly_off
4077 || bl
->section
== NULL
4078 || !(section_is_overlay (bl
->section
)))
4080 /* No overlay handling: just remove the breakpoint. */
4082 /* If we're trying to uninsert a memory breakpoint that we
4083 know is set in a dynamic object that is marked
4084 shlib_disabled, then either the dynamic object was
4085 removed with "remove-symbol-file" or with
4086 "nosharedlibrary". In the former case, we don't know
4087 whether another dynamic object might have loaded over the
4088 breakpoint's address -- the user might well let us know
4089 about it next with add-symbol-file (the whole point of
4090 add-symbol-file is letting the user manually maintain a
4091 list of dynamically loaded objects). If we have the
4092 breakpoint's shadow memory, that is, this is a software
4093 breakpoint managed by GDB, check whether the breakpoint
4094 is still inserted in memory, to avoid overwriting wrong
4095 code with stale saved shadow contents. Note that HW
4096 breakpoints don't have shadow memory, as they're
4097 implemented using a mechanism that is not dependent on
4098 being able to modify the target's memory, and as such
4099 they should always be removed. */
4100 if (bl
->shlib_disabled
4101 && bl
->target_info
.shadow_len
!= 0
4102 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
4105 val
= bl
->owner
->remove_location (bl
, reason
);
4109 /* This breakpoint is in an overlay section.
4110 Did we set a breakpoint at the LMA? */
4111 if (!overlay_events_enabled
)
4113 /* Yes -- overlay event support is not active, so we
4114 should have set a breakpoint at the LMA. Remove it.
4116 /* Ignore any failures: if the LMA is in ROM, we will
4117 have already warned when we failed to insert it. */
4118 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4119 target_remove_hw_breakpoint (bl
->gdbarch
,
4120 &bl
->overlay_target_info
);
4122 target_remove_breakpoint (bl
->gdbarch
,
4123 &bl
->overlay_target_info
,
4126 /* Did we set a breakpoint at the VMA?
4127 If so, we will have marked the breakpoint 'inserted'. */
4130 /* Yes -- remove it. Previously we did not bother to
4131 remove the breakpoint if the section had been
4132 unmapped, but let's not rely on that being safe. We
4133 don't know what the overlay manager might do. */
4135 /* However, we should remove *software* breakpoints only
4136 if the section is still mapped, or else we overwrite
4137 wrong code with the saved shadow contents. */
4138 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4139 || section_is_mapped (bl
->section
))
4140 val
= bl
->owner
->remove_location (bl
, reason
);
4146 /* No -- not inserted, so no need to remove. No error. */
4151 /* In some cases, we might not be able to remove a breakpoint in
4152 a shared library that has already been removed, but we have
4153 not yet processed the shlib unload event. Similarly for an
4154 unloaded add-symbol-file object - the user might not yet have
4155 had the chance to remove-symbol-file it. shlib_disabled will
4156 be set if the library/object has already been removed, but
4157 the breakpoint hasn't been uninserted yet, e.g., after
4158 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4159 always-inserted mode. */
4161 && (bl
->loc_type
== bp_loc_software_breakpoint
4162 && (bl
->shlib_disabled
4163 || solib_name_from_address (bl
->pspace
, bl
->address
)
4164 || shared_objfile_contains_address_p (bl
->pspace
,
4170 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4172 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4174 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4175 bl
->owner
->remove_location (bl
, reason
);
4177 /* Failure to remove any of the hardware watchpoints comes here. */
4178 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
4179 warning (_("Could not remove hardware watchpoint %d."),
4182 else if (bl
->owner
->type
== bp_catchpoint
4183 && breakpoint_enabled (bl
->owner
)
4186 val
= bl
->owner
->remove_location (bl
, reason
);
4190 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4197 remove_breakpoint (struct bp_location
*bl
)
4199 /* BL is never in moribund_locations by our callers. */
4200 gdb_assert (bl
->owner
!= NULL
);
4202 /* The type of none suggests that owner is actually deleted.
4203 This should not ever happen. */
4204 gdb_assert (bl
->owner
->type
!= bp_none
);
4206 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4208 switch_to_program_space_and_thread (bl
->pspace
);
4210 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4213 /* Clear the "inserted" flag in all breakpoints. */
4216 mark_breakpoints_out (void)
4218 for (bp_location
*bl
: all_bp_locations ())
4219 if (bl
->pspace
== current_program_space
)
4223 /* Clear the "inserted" flag in all breakpoints and delete any
4224 breakpoints which should go away between runs of the program.
4226 Plus other such housekeeping that has to be done for breakpoints
4229 Note: this function gets called at the end of a run (by
4230 generic_mourn_inferior) and when a run begins (by
4231 init_wait_for_inferior). */
4236 breakpoint_init_inferior (enum inf_context context
)
4238 struct program_space
*pspace
= current_program_space
;
4240 /* If breakpoint locations are shared across processes, then there's
4242 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4245 mark_breakpoints_out ();
4247 for (breakpoint
&b
: all_breakpoints_safe ())
4249 if (b
.has_locations () && b
.first_loc ().pspace
!= pspace
)
4255 case bp_longjmp_call_dummy
:
4257 /* If the call dummy breakpoint is at the entry point it will
4258 cause problems when the inferior is rerun, so we better get
4261 case bp_watchpoint_scope
:
4263 /* Also get rid of scope breakpoints. */
4265 case bp_shlib_event
:
4267 /* Also remove solib event breakpoints. Their addresses may
4268 have changed since the last time we ran the program.
4269 Actually we may now be debugging against different target;
4270 and so the solib backend that installed this breakpoint may
4271 not be used in by the target. E.g.,
4273 (gdb) file prog-linux
4274 (gdb) run # native linux target
4277 (gdb) file prog-win.exe
4278 (gdb) tar rem :9999 # remote Windows gdbserver.
4281 case bp_step_resume
:
4283 /* Also remove step-resume breakpoints. */
4285 case bp_single_step
:
4287 /* Also remove single-step breakpoints. */
4289 delete_breakpoint (&b
);
4293 case bp_hardware_watchpoint
:
4294 case bp_read_watchpoint
:
4295 case bp_access_watchpoint
:
4297 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
4299 /* Likewise for watchpoints on local expressions. */
4300 if (w
.exp_valid_block
!= NULL
)
4301 delete_breakpoint (&b
);
4304 /* Get rid of existing locations, which are no longer
4305 valid. New ones will be created in
4306 update_watchpoint, when the inferior is restarted.
4307 The next update_global_location_list call will
4308 garbage collect them. */
4309 b
.clear_locations ();
4311 if (context
== inf_starting
)
4313 /* Reset val field to force reread of starting value in
4314 insert_breakpoints. */
4315 w
.val
.reset (nullptr);
4316 w
.val_valid
= false;
4326 /* Get rid of the moribund locations. */
4327 for (bp_location
*bl
: moribund_locations
)
4328 decref_bp_location (&bl
);
4329 moribund_locations
.clear ();
4332 /* These functions concern about actual breakpoints inserted in the
4333 target --- to e.g. check if we need to do decr_pc adjustment or if
4334 we need to hop over the bkpt --- so we check for address space
4335 match, not program space. */
4337 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4338 exists at PC. It returns ordinary_breakpoint_here if it's an
4339 ordinary breakpoint, or permanent_breakpoint_here if it's a
4340 permanent breakpoint.
4341 - When continuing from a location with an ordinary breakpoint, we
4342 actually single step once before calling insert_breakpoints.
4343 - When continuing from a location with a permanent breakpoint, we
4344 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4345 the target, to advance the PC past the breakpoint. */
4347 enum breakpoint_here
4348 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4350 bool any_breakpoint_here
= false;
4352 for (bp_location
*bl
: all_bp_locations ())
4354 if (bl
->loc_type
!= bp_loc_software_breakpoint
4355 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4358 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4359 if ((breakpoint_enabled (bl
->owner
)
4361 && breakpoint_location_address_match (bl
, aspace
, pc
))
4363 if (overlay_debugging
4364 && section_is_overlay (bl
->section
)
4365 && !section_is_mapped (bl
->section
))
4366 continue; /* unmapped overlay -- can't be a match */
4367 else if (bl
->permanent
)
4368 return permanent_breakpoint_here
;
4370 any_breakpoint_here
= true;
4374 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4377 /* See breakpoint.h. */
4380 breakpoint_in_range_p (const address_space
*aspace
,
4381 CORE_ADDR addr
, ULONGEST len
)
4383 for (bp_location
*bl
: all_bp_locations ())
4385 if (bl
->loc_type
!= bp_loc_software_breakpoint
4386 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4389 if ((breakpoint_enabled (bl
->owner
)
4391 && breakpoint_location_address_range_overlap (bl
, aspace
,
4394 if (overlay_debugging
4395 && section_is_overlay (bl
->section
)
4396 && !section_is_mapped (bl
->section
))
4398 /* Unmapped overlay -- can't be a match. */
4409 /* Return true if there's a moribund breakpoint at PC. */
4412 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4414 for (bp_location
*loc
: moribund_locations
)
4415 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4421 /* Returns true iff BL is inserted at PC, in address space ASPACE. */
4424 bp_location_inserted_here_p (const struct bp_location
*bl
,
4425 const address_space
*aspace
, CORE_ADDR pc
)
4428 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4431 /* An unmapped overlay can't be a match. */
4432 return !(overlay_debugging
4433 && section_is_overlay (bl
->section
)
4434 && !section_is_mapped (bl
->section
));
4439 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4442 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4444 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4446 if (bl
->loc_type
!= bp_loc_software_breakpoint
4447 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4450 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4456 /* This function returns non-zero iff there is a software breakpoint
4460 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4463 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4465 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4468 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4475 /* See breakpoint.h. */
4478 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4481 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4483 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4486 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4494 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4495 CORE_ADDR addr
, ULONGEST len
)
4497 for (breakpoint
&bpt
: all_breakpoints ())
4499 if (bpt
.type
!= bp_hardware_watchpoint
4500 && bpt
.type
!= bp_access_watchpoint
)
4503 if (!breakpoint_enabled (&bpt
))
4506 for (bp_location
&loc
: bpt
.locations ())
4507 if (loc
.pspace
->aspace
== aspace
&& loc
.inserted
)
4511 /* Check for intersection. */
4512 l
= std::max
<CORE_ADDR
> (loc
.address
, addr
);
4513 h
= std::min
<CORE_ADDR
> (loc
.address
+ loc
.length
, addr
+ len
);
4521 /* See breakpoint.h. */
4524 is_catchpoint (struct breakpoint
*b
)
4526 return (b
->type
== bp_catchpoint
);
4529 /* Clear a bpstat so that it says we are not at any breakpoint.
4530 Also free any storage that is part of a bpstat. */
4533 bpstat_clear (bpstat
**bsp
)
4550 bpstat::bpstat (const bpstat
&other
)
4552 bp_location_at (other
.bp_location_at
),
4553 breakpoint_at (other
.breakpoint_at
),
4554 commands (other
.commands
),
4555 print (other
.print
),
4557 print_it (other
.print_it
)
4559 if (other
.old_val
!= NULL
)
4560 old_val
= release_value (other
.old_val
->copy ());
4563 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4564 is part of the bpstat is copied as well. */
4567 bpstat_copy (bpstat
*bs
)
4569 bpstat
*p
= nullptr;
4571 bpstat
*retval
= nullptr;
4576 for (; bs
!= NULL
; bs
= bs
->next
)
4578 tmp
= new bpstat (*bs
);
4581 /* This is the first thing in the chain. */
4591 /* Find the bpstat associated with this breakpoint. */
4594 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4599 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4601 if (bsp
->breakpoint_at
== breakpoint
)
4607 /* See breakpoint.h. */
4610 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4612 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4614 if (bsp
->breakpoint_at
== NULL
)
4616 /* A moribund location can never explain a signal other than
4618 if (sig
== GDB_SIGNAL_TRAP
)
4623 if (bsp
->breakpoint_at
->explains_signal (sig
))
4631 /* See breakpoint.h. */
4634 bpstat_num (bpstat
**bsp
, int *num
)
4636 struct breakpoint
*b
;
4639 return 0; /* No more breakpoint values */
4641 /* We assume we'll never have several bpstats that correspond to a
4642 single breakpoint -- otherwise, this function might return the
4643 same number more than once and this will look ugly. */
4644 b
= (*bsp
)->breakpoint_at
;
4645 *bsp
= (*bsp
)->next
;
4647 return -1; /* breakpoint that's been deleted since */
4649 *num
= b
->number
; /* We have its number */
4653 /* See breakpoint.h */
4656 bpstat_locno (const bpstat
*bs
)
4658 const struct breakpoint
*b
= bs
->breakpoint_at
;
4659 const struct bp_location
*bl
= bs
->bp_location_at
.get ();
4661 if (b
!= nullptr && b
->has_multiple_locations ())
4665 for (bp_location
&loc
: b
->locations ())
4673 warning (_("location number not found for breakpoint %d address %s."),
4674 b
->number
, paddress (bl
->gdbarch
, bl
->address
));
4680 /* See breakpoint.h. */
4683 print_num_locno (const bpstat
*bs
, struct ui_out
*uiout
)
4685 struct breakpoint
*b
= bs
->breakpoint_at
;
4688 uiout
->text (_("deleted breakpoint"));
4691 uiout
->field_signed ("bkptno", b
->number
);
4693 int locno
= bpstat_locno (bs
);
4695 uiout
->message (".%pF", signed_field ("locno", locno
));
4699 /* See breakpoint.h. */
4702 bpstat_clear_actions (void)
4706 if (inferior_ptid
== null_ptid
)
4709 thread_info
*tp
= inferior_thread ();
4710 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4712 bs
->commands
= NULL
;
4713 bs
->old_val
.reset (nullptr);
4717 /* Called when a command is about to proceed the inferior. */
4720 breakpoint_about_to_proceed (void)
4722 if (inferior_ptid
!= null_ptid
)
4724 struct thread_info
*tp
= inferior_thread ();
4726 /* Allow inferior function calls in breakpoint commands to not
4727 interrupt the command list. When the call finishes
4728 successfully, the inferior will be standing at the same
4729 breakpoint as if nothing happened. */
4730 if (tp
->control
.in_infcall
)
4734 breakpoint_proceeded
= 1;
4737 /* Return true iff CMD as the first line of a command sequence is `silent'
4738 or its equivalent. */
4741 command_line_is_silent (struct command_line
*cmd
)
4743 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4746 /* Sets the $_hit_bpnum and $_hit_locno to bpnum and locno.
4747 A locno 0 is changed to 1 to e.g. let the user do
4748 (gdb) disable $_hit_bpnum.$_hit_locno
4749 for a single location breakpoint. */
4752 set_hit_convenience_vars (int bpnum
, int locno
)
4754 set_internalvar_integer (lookup_internalvar ("_hit_bpnum"), bpnum
);
4755 set_internalvar_integer (lookup_internalvar ("_hit_locno"),
4756 (locno
> 0 ? locno
: 1));
4759 /* Execute all the commands associated with all the breakpoints at
4760 this location. Any of these commands could cause the process to
4761 proceed beyond this point, etc. We look out for such changes by
4762 checking the global "breakpoint_proceeded" after each command.
4764 Returns true if a breakpoint command resumed the inferior. In that
4765 case, it is the caller's responsibility to recall it again with the
4766 bpstat of the current thread. */
4769 bpstat_do_actions_1 (bpstat
**bsp
)
4774 /* Avoid endless recursion if a `source' command is contained
4776 if (executing_breakpoint_commands
)
4779 scoped_restore save_executing
4780 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4782 scoped_restore preventer
= prevent_dont_repeat ();
4784 /* This pointer will iterate over the list of bpstat's. */
4787 /* The $_hit_* convenience variables are set before running the
4788 commands of BS. In case we have several bs, after the loop,
4789 we set again the variables to the first printed bpnum and locno.
4790 For multiple breakpoints, this ensures the variables are set to the
4791 breakpoint printed for the user. */
4792 int printed_hit_bpnum
= -1;
4793 int printed_hit_locno
= -1;
4795 breakpoint_proceeded
= 0;
4796 for (; bs
!= NULL
; bs
= bs
->next
)
4798 struct command_line
*cmd
= NULL
;
4800 /* Set the _hit_* convenience variables before running BS's commands. */
4802 const struct breakpoint
*b
= bs
->breakpoint_at
;
4805 int locno
= bpstat_locno (bs
);
4807 set_hit_convenience_vars (b
->number
, locno
);
4808 if (printed_hit_locno
== -1 && bs
->print
)
4810 printed_hit_bpnum
= b
->number
;
4811 printed_hit_locno
= locno
;
4816 /* Take ownership of the BSP's command tree, if it has one.
4818 The command tree could legitimately contain commands like
4819 'step' and 'next', which call clear_proceed_status, which
4820 frees the bpstat BS and its command tree. To make sure this doesn't
4821 free the tree we're executing out from under us, we need to
4822 take ownership of the tree ourselves. Since a given bpstat's
4823 commands are only executed once, we don't need to copy it; we
4824 can clear the pointer in the bpstat, and make sure we free
4825 the tree when we're done. */
4826 counted_command_line ccmd
= bs
->commands
;
4827 bs
->commands
= NULL
;
4830 if (command_line_is_silent (cmd
))
4832 /* The action has been already done by bpstat_stop_status. */
4838 execute_control_command (cmd
);
4839 /* After execute_control_command, if breakpoint_proceeded is true,
4840 BS has been freed and cannot be accessed anymore. */
4842 if (breakpoint_proceeded
)
4848 if (breakpoint_proceeded
)
4850 if (current_ui
->async
)
4851 /* If we are in async mode, then the target might be still
4852 running, not stopped at any breakpoint, so nothing for
4853 us to do here -- just return to the event loop. */
4856 /* In sync mode, when execute_control_command returns
4857 we're already standing on the next breakpoint.
4858 Breakpoint commands for that stop were not run, since
4859 execute_command does not run breakpoint commands --
4860 only command_line_handler does, but that one is not
4861 involved in execution of breakpoint commands. So, we
4862 can now execute breakpoint commands. It should be
4863 noted that making execute_command do bpstat actions is
4864 not an option -- in this case we'll have recursive
4865 invocation of bpstat for each breakpoint with a
4866 command, and can easily blow up GDB stack. Instead, we
4867 return true, which will trigger the caller to recall us
4868 with the new stop_bpstat. */
4874 /* Now that we have executed the commands of all bs, set the _hit_*
4875 convenience variables to the printed values. */
4876 if (printed_hit_locno
!= -1)
4877 set_hit_convenience_vars (printed_hit_bpnum
, printed_hit_locno
);
4882 /* Helper for bpstat_do_actions. Get the current thread, if there's
4883 one, is alive and has execution. Return NULL otherwise. */
4885 static thread_info
*
4886 get_bpstat_thread ()
4888 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4891 thread_info
*tp
= inferior_thread ();
4892 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4898 bpstat_do_actions (void)
4900 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4903 /* Do any commands attached to breakpoint we are stopped at. */
4904 while ((tp
= get_bpstat_thread ()) != NULL
)
4906 /* Since in sync mode, bpstat_do_actions may resume the
4907 inferior, and only return when it is stopped at the next
4908 breakpoint, we keep doing breakpoint actions until it returns
4909 false to indicate the inferior was not resumed. */
4910 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4914 cleanup_if_error
.release ();
4917 /* Print out the (old or new) value associated with a watchpoint. */
4920 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4923 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4926 struct value_print_options opts
;
4927 get_user_print_options (&opts
);
4928 value_print (val
, stream
, &opts
);
4932 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4933 debugging multiple threads. */
4936 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4938 if (uiout
->is_mi_like_p ())
4943 if (show_thread_that_caused_stop ())
4945 struct thread_info
*thr
= inferior_thread ();
4947 uiout
->text ("Thread ");
4948 uiout
->field_string ("thread-id", print_thread_id (thr
));
4950 const char *name
= thread_name (thr
);
4953 uiout
->text (" \"");
4954 uiout
->field_string ("name", name
);
4958 uiout
->text (" hit ");
4962 /* Generic routine for printing messages indicating why we
4963 stopped. The behavior of this function depends on the value
4964 'print_it' in the bpstat structure. Under some circumstances we
4965 may decide not to print anything here and delegate the task to
4968 static enum print_stop_action
4969 print_bp_stop_message (bpstat
*bs
)
4971 switch (bs
->print_it
)
4974 /* Nothing should be printed for this bpstat entry. */
4975 return PRINT_UNKNOWN
;
4979 /* We still want to print the frame, but we already printed the
4980 relevant messages. */
4981 return PRINT_SRC_AND_LOC
;
4984 case print_it_normal
:
4986 struct breakpoint
*b
= bs
->breakpoint_at
;
4988 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4989 which has since been deleted. */
4991 return PRINT_UNKNOWN
;
4993 /* Normal case. Call the breakpoint's print_it method. */
4994 return b
->print_it (bs
);
4999 internal_error (_("print_bp_stop_message: unrecognized enum value"));
5004 /* See breakpoint.h. */
5007 print_solib_event (bool is_catchpoint
)
5009 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
5010 bool any_added
= !current_program_space
->added_solibs
.empty ();
5014 if (any_added
|| any_deleted
)
5015 current_uiout
->text (_("Stopped due to shared library event:\n"));
5017 current_uiout
->text (_("Stopped due to shared library event (no "
5018 "libraries added or removed)\n"));
5021 if (current_uiout
->is_mi_like_p ())
5022 current_uiout
->field_string ("reason",
5023 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
5027 current_uiout
->text (_(" Inferior unloaded "));
5028 ui_out_emit_list
list_emitter (current_uiout
, "removed");
5029 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
5031 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
5034 current_uiout
->text (" ");
5035 current_uiout
->field_string ("library", name
);
5036 current_uiout
->text ("\n");
5042 current_uiout
->text (_(" Inferior loaded "));
5043 ui_out_emit_list
list_emitter (current_uiout
, "added");
5045 for (so_list
*iter
: current_program_space
->added_solibs
)
5048 current_uiout
->text (" ");
5050 current_uiout
->field_string ("library", iter
->so_name
);
5051 current_uiout
->text ("\n");
5056 /* Print a message indicating what happened. This is called from
5057 normal_stop(). The input to this routine is the head of the bpstat
5058 list - a list of the eventpoints that caused this stop. KIND is
5059 the target_waitkind for the stopping event. This
5060 routine calls the generic print routine for printing a message
5061 about reasons for stopping. This will print (for example) the
5062 "Breakpoint n," part of the output. The return value of this
5065 PRINT_UNKNOWN: Means we printed nothing.
5066 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
5067 code to print the location. An example is
5068 "Breakpoint 1, " which should be followed by
5070 PRINT_SRC_ONLY: Means we printed something, but there is no need
5071 to also print the location part of the message.
5072 An example is the catch/throw messages, which
5073 don't require a location appended to the end.
5074 PRINT_NOTHING: We have done some printing and we don't need any
5075 further info to be printed. */
5077 enum print_stop_action
5078 bpstat_print (bpstat
*bs
, target_waitkind kind
)
5080 enum print_stop_action val
;
5082 /* Maybe another breakpoint in the chain caused us to stop.
5083 (Currently all watchpoints go on the bpstat whether hit or not.
5084 That probably could (should) be changed, provided care is taken
5085 with respect to bpstat_explains_signal). */
5086 for (; bs
; bs
= bs
->next
)
5088 val
= print_bp_stop_message (bs
);
5089 if (val
== PRINT_SRC_ONLY
5090 || val
== PRINT_SRC_AND_LOC
5091 || val
== PRINT_NOTHING
)
5095 /* If we had hit a shared library event breakpoint,
5096 print_bp_stop_message would print out this message. If we hit an
5097 OS-level shared library event, do the same thing. */
5098 if (kind
== TARGET_WAITKIND_LOADED
)
5100 print_solib_event (false);
5101 return PRINT_NOTHING
;
5104 /* We reached the end of the chain, or we got a null BS to start
5105 with and nothing was printed. */
5106 return PRINT_UNKNOWN
;
5109 /* Evaluate the boolean expression EXP and return the result. */
5112 breakpoint_cond_eval (expression
*exp
)
5114 scoped_value_mark mark
;
5115 return value_true (exp
->evaluate ());
5118 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
5120 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
5122 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
5123 breakpoint_at (bl
->owner
),
5127 print_it (print_it_normal
)
5129 **bs_link_pointer
= this;
5130 *bs_link_pointer
= &next
;
5135 breakpoint_at (NULL
),
5139 print_it (print_it_normal
)
5143 /* The target has stopped with waitstatus WS. Check if any hardware
5144 watchpoints have triggered, according to the target. */
5147 watchpoints_triggered (const target_waitstatus
&ws
)
5149 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5152 if (!stopped_by_watchpoint
)
5154 /* We were not stopped by a watchpoint. Mark all watchpoints
5155 as not triggered. */
5156 for (breakpoint
&b
: all_breakpoints ())
5157 if (is_hardware_watchpoint (&b
))
5159 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
5161 w
.watchpoint_triggered
= watch_triggered_no
;
5167 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
5169 /* We were stopped by a watchpoint, but we don't know where.
5170 Mark all watchpoints as unknown. */
5171 for (breakpoint
&b
: all_breakpoints ())
5172 if (is_hardware_watchpoint (&b
))
5174 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
5176 w
.watchpoint_triggered
= watch_triggered_unknown
;
5182 /* The target could report the data address. Mark watchpoints
5183 affected by this data address as triggered, and all others as not
5186 for (breakpoint
&b
: all_breakpoints ())
5187 if (is_hardware_watchpoint (&b
))
5189 watchpoint
&w
= gdb::checked_static_cast
<watchpoint
&> (b
);
5191 w
.watchpoint_triggered
= watch_triggered_no
;
5192 for (bp_location
&loc
: b
.locations ())
5194 if (is_masked_watchpoint (&b
))
5196 CORE_ADDR newaddr
= addr
& w
.hw_wp_mask
;
5197 CORE_ADDR start
= loc
.address
& w
.hw_wp_mask
;
5199 if (newaddr
== start
)
5201 w
.watchpoint_triggered
= watch_triggered_yes
;
5205 /* Exact match not required. Within range is sufficient. */
5206 else if (target_watchpoint_addr_within_range
5207 (current_inferior ()->top_target (), addr
, loc
.address
,
5210 w
.watchpoint_triggered
= watch_triggered_yes
;
5219 /* Possible return values for watchpoint_check. */
5220 enum wp_check_result
5222 /* The watchpoint has been deleted. */
5225 /* The value has changed. */
5226 WP_VALUE_CHANGED
= 2,
5228 /* The value has not changed. */
5229 WP_VALUE_NOT_CHANGED
= 3,
5231 /* Ignore this watchpoint, no matter if the value changed or not. */
5235 #define BP_TEMPFLAG 1
5236 #define BP_HARDWAREFLAG 2
5238 /* Evaluate watchpoint condition expression and check if its value
5241 static wp_check_result
5242 watchpoint_check (bpstat
*bs
)
5244 struct watchpoint
*b
;
5246 bool within_current_scope
;
5248 /* BS is built from an existing struct breakpoint. */
5249 gdb_assert (bs
->breakpoint_at
!= NULL
);
5250 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5252 /* If this is a local watchpoint, we only want to check if the
5253 watchpoint frame is in scope if the current thread is the thread
5254 that was used to create the watchpoint. */
5255 if (!watchpoint_in_thread_scope (b
))
5258 if (b
->exp_valid_block
== NULL
)
5259 within_current_scope
= true;
5262 frame_info_ptr frame
= get_current_frame ();
5263 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5264 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5266 /* stack_frame_destroyed_p() returns a non-zero value if we're
5267 still in the function but the stack frame has already been
5268 invalidated. Since we can't rely on the values of local
5269 variables after the stack has been destroyed, we are treating
5270 the watchpoint in that state as `not changed' without further
5271 checking. Don't mark watchpoints as changed if the current
5272 frame is in an epilogue - even if they are in some other
5273 frame, our view of the stack is likely to be wrong and
5274 frame_find_by_id could error out. */
5275 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5278 fr
= frame_find_by_id (b
->watchpoint_frame
);
5279 within_current_scope
= (fr
!= NULL
);
5281 /* If we've gotten confused in the unwinder, we might have
5282 returned a frame that can't describe this variable. */
5283 if (within_current_scope
)
5285 struct symbol
*function
;
5287 function
= get_frame_function (fr
);
5288 if (function
== NULL
5289 || !function
->value_block ()->contains (b
->exp_valid_block
))
5290 within_current_scope
= false;
5293 if (within_current_scope
)
5294 /* If we end up stopping, the current frame will get selected
5295 in normal_stop. So this call to select_frame won't affect
5300 if (within_current_scope
)
5302 /* We use value_{,free_to_}mark because it could be a *long*
5303 time before we return to the command level and call
5304 free_all_values. We can't call free_all_values because we
5305 might be in the middle of evaluating a function call. */
5308 struct value
*new_val
;
5310 if (is_masked_watchpoint (b
))
5311 /* Since we don't know the exact trigger address (from
5312 stopped_data_address), just tell the user we've triggered
5313 a mask watchpoint. */
5314 return WP_VALUE_CHANGED
;
5316 mark
= value_mark ();
5317 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5320 if (b
->val_bitsize
!= 0)
5321 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5323 /* We use value_equal_contents instead of value_equal because
5324 the latter coerces an array to a pointer, thus comparing just
5325 the address of the array instead of its contents. This is
5326 not what we want. */
5327 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5328 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5331 bs
->old_val
= b
->val
;
5332 b
->val
= release_value (new_val
);
5333 b
->val_valid
= true;
5334 if (new_val
!= NULL
)
5335 value_free_to_mark (mark
);
5336 return WP_VALUE_CHANGED
;
5340 /* Nothing changed. */
5341 value_free_to_mark (mark
);
5342 return WP_VALUE_NOT_CHANGED
;
5347 /* This seems like the only logical thing to do because
5348 if we temporarily ignored the watchpoint, then when
5349 we reenter the block in which it is valid it contains
5350 garbage (in the case of a function, it may have two
5351 garbage values, one before and one after the prologue).
5352 So we can't even detect the first assignment to it and
5353 watch after that (since the garbage may or may not equal
5354 the first value assigned). */
5355 /* We print all the stop information in
5356 breakpointprint_it, but in this case, by the time we
5357 call breakpoint->print_it this bp will be deleted
5358 already. So we have no choice but print the information
5361 SWITCH_THRU_ALL_UIS ()
5363 struct ui_out
*uiout
= current_uiout
;
5365 if (uiout
->is_mi_like_p ())
5367 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5368 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5369 "left the block in\n"
5370 "which its expression is valid.\n",
5371 signed_field ("wpnum", b
->number
));
5374 /* Make sure the watchpoint's commands aren't executed. */
5376 watchpoint_del_at_next_stop (b
);
5382 /* Return true if it looks like target has stopped due to hitting
5383 breakpoint location BL. This function does not check if we should
5384 stop, only if BL explains the stop. */
5387 bpstat_check_location (const struct bp_location
*bl
,
5388 const address_space
*aspace
, CORE_ADDR bp_addr
,
5389 const target_waitstatus
&ws
)
5391 struct breakpoint
*b
= bl
->owner
;
5393 /* BL is from an existing breakpoint. */
5394 gdb_assert (b
!= NULL
);
5396 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5399 /* Determine if the watched values have actually changed, and we
5400 should stop. If not, set BS->stop to false. */
5403 bpstat_check_watchpoint (bpstat
*bs
)
5405 const struct bp_location
*bl
;
5406 struct watchpoint
*b
;
5408 /* BS is built for existing struct breakpoint. */
5409 bl
= bs
->bp_location_at
.get ();
5410 gdb_assert (bl
!= NULL
);
5411 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5412 gdb_assert (b
!= NULL
);
5415 bool must_check_value
= false;
5417 if (b
->type
== bp_watchpoint
)
5418 /* For a software watchpoint, we must always check the
5420 must_check_value
= true;
5421 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5422 /* We have a hardware watchpoint (read, write, or access)
5423 and the target earlier reported an address watched by
5425 must_check_value
= true;
5426 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5427 && b
->type
== bp_hardware_watchpoint
)
5428 /* We were stopped by a hardware watchpoint, but the target could
5429 not report the data address. We must check the watchpoint's
5430 value. Access and read watchpoints are out of luck; without
5431 a data address, we can't figure it out. */
5432 must_check_value
= true;
5434 if (must_check_value
)
5440 e
= watchpoint_check (bs
);
5442 catch (const gdb_exception_error
&ex
)
5444 exception_fprintf (gdb_stderr
, ex
,
5445 "Error evaluating expression "
5446 "for watchpoint %d\n",
5449 SWITCH_THRU_ALL_UIS ()
5451 gdb_printf (_("Watchpoint %d deleted.\n"),
5454 watchpoint_del_at_next_stop (b
);
5461 /* We've already printed what needs to be printed. */
5462 bs
->print_it
= print_it_done
;
5466 bs
->print_it
= print_it_noop
;
5469 case WP_VALUE_CHANGED
:
5470 if (b
->type
== bp_read_watchpoint
)
5472 /* There are two cases to consider here:
5474 1. We're watching the triggered memory for reads.
5475 In that case, trust the target, and always report
5476 the watchpoint hit to the user. Even though
5477 reads don't cause value changes, the value may
5478 have changed since the last time it was read, and
5479 since we're not trapping writes, we will not see
5480 those, and as such we should ignore our notion of
5483 2. We're watching the triggered memory for both
5484 reads and writes. There are two ways this may
5487 2.1. This is a target that can't break on data
5488 reads only, but can break on accesses (reads or
5489 writes), such as e.g., x86. We detect this case
5490 at the time we try to insert read watchpoints.
5492 2.2. Otherwise, the target supports read
5493 watchpoints, but, the user set an access or write
5494 watchpoint watching the same memory as this read
5497 If we're watching memory writes as well as reads,
5498 ignore watchpoint hits when we find that the
5499 value hasn't changed, as reads don't cause
5500 changes. This still gives false positives when
5501 the program writes the same value to memory as
5502 what there was already in memory (we will confuse
5503 it for a read), but it's much better than
5506 int other_write_watchpoint
= 0;
5508 if (bl
->watchpoint_type
== hw_read
)
5510 for (breakpoint
&other_b
: all_breakpoints ())
5511 if (other_b
.type
== bp_hardware_watchpoint
5512 || other_b
.type
== bp_access_watchpoint
)
5514 watchpoint
&other_w
=
5515 gdb::checked_static_cast
<watchpoint
&> (other_b
);
5517 if (other_w
.watchpoint_triggered
5518 == watch_triggered_yes
)
5520 other_write_watchpoint
= 1;
5526 if (other_write_watchpoint
5527 || bl
->watchpoint_type
== hw_access
)
5529 /* We're watching the same memory for writes,
5530 and the value changed since the last time we
5531 updated it, so this trap must be for a write.
5533 bs
->print_it
= print_it_noop
;
5538 case WP_VALUE_NOT_CHANGED
:
5539 if (b
->type
== bp_hardware_watchpoint
5540 || b
->type
== bp_watchpoint
)
5542 /* Don't stop: write watchpoints shouldn't fire if
5543 the value hasn't changed. */
5544 bs
->print_it
= print_it_noop
;
5554 else /* !must_check_value */
5556 /* This is a case where some watchpoint(s) triggered, but
5557 not at the address of this watchpoint, or else no
5558 watchpoint triggered after all. So don't print
5559 anything for this watchpoint. */
5560 bs
->print_it
= print_it_noop
;
5566 /* For breakpoints that are currently marked as telling gdb to stop,
5567 check conditions (condition proper, frame, thread and ignore count)
5568 of breakpoint referred to by BS. If we should not stop for this
5569 breakpoint, set BS->stop to 0. */
5572 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5574 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
5576 const struct bp_location
*bl
;
5577 struct breakpoint
*b
;
5579 bool condition_result
= true;
5580 struct expression
*cond
;
5582 gdb_assert (bs
->stop
);
5584 /* BS is built for existing struct breakpoint. */
5585 bl
= bs
->bp_location_at
.get ();
5586 gdb_assert (bl
!= NULL
);
5587 b
= bs
->breakpoint_at
;
5588 gdb_assert (b
!= NULL
);
5590 infrun_debug_printf ("thread = %s, breakpoint %d.%d",
5591 thread
->ptid
.to_string ().c_str (),
5592 b
->number
, find_loc_num_by_location (bl
));
5594 /* Even if the target evaluated the condition on its end and notified GDB, we
5595 need to do so again since GDB does not know if we stopped due to a
5596 breakpoint or a single step breakpoint. */
5598 if (frame_id_p (b
->frame_id
)
5599 && b
->frame_id
!= get_stack_frame_id (get_current_frame ()))
5601 infrun_debug_printf ("incorrect frame %s not %s, not stopping",
5602 get_stack_frame_id (get_current_frame ()).to_string ().c_str (),
5603 b
->frame_id
.to_string ().c_str ());
5608 /* If this is a thread/task-specific breakpoint, don't waste cpu
5609 evaluating the condition if this isn't the specified
5611 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5612 || (b
->inferior
!= -1 && b
->inferior
!= thread
->inf
->num
)
5613 || (b
->task
!= -1 && b
->task
!= ada_get_task_number (thread
)))
5615 infrun_debug_printf ("incorrect thread or task, not stopping");
5620 /* Evaluate extension language breakpoints that have a "stop" method
5622 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5624 if (is_watchpoint (b
))
5626 struct watchpoint
*w
= (struct watchpoint
*) b
;
5628 cond
= w
->cond_exp
.get ();
5631 cond
= bl
->cond
.get ();
5633 if (cond
!= nullptr && b
->disposition
!= disp_del_at_next_stop
)
5635 bool within_current_scope
= true;
5636 struct watchpoint
* w
;
5638 /* We use scoped_value_mark because it could be a long time
5639 before we return to the command level and call
5640 free_all_values. We can't call free_all_values because we
5641 might be in the middle of evaluating a function call. */
5642 scoped_value_mark mark
;
5644 if (is_watchpoint (b
))
5645 w
= (struct watchpoint
*) b
;
5649 /* Need to select the frame, with all that implies so that
5650 the conditions will have the right context. Because we
5651 use the frame, we will not see an inlined function's
5652 variables when we arrive at a breakpoint at the start
5653 of the inlined function; the current frame will be the
5655 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5656 select_frame (get_current_frame ());
5659 frame_info_ptr frame
;
5661 /* For local watchpoint expressions, which particular
5662 instance of a local is being watched matters, so we
5663 keep track of the frame to evaluate the expression
5664 in. To evaluate the condition however, it doesn't
5665 really matter which instantiation of the function
5666 where the condition makes sense triggers the
5667 watchpoint. This allows an expression like "watch
5668 global if q > 10" set in `func', catch writes to
5669 global on all threads that call `func', or catch
5670 writes on all recursive calls of `func' by a single
5671 thread. We simply always evaluate the condition in
5672 the innermost frame that's executing where it makes
5673 sense to evaluate the condition. It seems
5675 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5677 select_frame (frame
);
5679 within_current_scope
= false;
5681 if (within_current_scope
)
5685 condition_result
= breakpoint_cond_eval (cond
);
5687 catch (const gdb_exception_error
&ex
)
5689 int locno
= bpstat_locno (bs
);
5693 "Error in testing condition for breakpoint %d.%d:\n",
5698 "Error in testing condition for breakpoint %d:\n",
5704 warning (_("Watchpoint condition cannot be tested "
5705 "in the current scope"));
5706 /* If we failed to set the right context for this
5707 watchpoint, unconditionally report it. */
5709 /* FIXME-someday, should give breakpoint #. */
5712 if (cond
!= nullptr && !condition_result
)
5714 infrun_debug_printf ("condition_result = false, not stopping");
5718 else if (b
->ignore_count
> 0)
5720 infrun_debug_printf ("ignore count %d, not stopping",
5724 /* Increase the hit count even though we don't stop. */
5726 notify_breakpoint_modified (b
);
5731 infrun_debug_printf ("stopping at this breakpoint");
5733 infrun_debug_printf ("not stopping at this breakpoint");
5736 /* Returns true if we need to track moribund locations of LOC's type
5737 on the current target. */
5740 need_moribund_for_location_type (const struct bp_location
*loc
)
5742 return ((loc
->loc_type
== bp_loc_software_breakpoint
5743 && !target_supports_stopped_by_sw_breakpoint ())
5744 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5745 && !target_supports_stopped_by_hw_breakpoint ()));
5748 /* See breakpoint.h. */
5751 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5752 const target_waitstatus
&ws
)
5754 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5756 for (breakpoint
&b
: all_breakpoints ())
5758 if (!breakpoint_enabled (&b
))
5761 for (bp_location
&bl
: b
.locations ())
5763 /* For hardware watchpoints, we look only at the first
5764 location. The watchpoint_check function will work on the
5765 entire expression, not the individual locations. For
5766 read watchpoints, the watchpoints_triggered function has
5767 checked all locations already. */
5768 if (b
.type
== bp_hardware_watchpoint
&& &bl
!= &b
.first_loc ())
5771 if (!bl
.enabled
|| bl
.disabled_by_cond
|| bl
.shlib_disabled
)
5774 if (!bpstat_check_location (&bl
, aspace
, bp_addr
, ws
))
5777 /* Come here if it's a watchpoint, or if the break address
5780 bpstat
*bs
= new bpstat (&bl
, &bs_link
); /* Alloc a bpstat to
5783 /* Assume we stop. Should we find a watchpoint that is not
5784 actually triggered, or if the condition of the breakpoint
5785 evaluates as false, we'll reset 'stop' to 0. */
5789 /* If this is a scope breakpoint, mark the associated
5790 watchpoint as triggered so that we will handle the
5791 out-of-scope event. We'll get to the watchpoint next
5793 if (b
.type
== bp_watchpoint_scope
&& b
.related_breakpoint
!= &b
)
5795 struct watchpoint
*w
= (struct watchpoint
*) b
.related_breakpoint
;
5797 w
->watchpoint_triggered
= watch_triggered_yes
;
5802 /* Check if a moribund breakpoint explains the stop. */
5803 if (!target_supports_stopped_by_sw_breakpoint ()
5804 || !target_supports_stopped_by_hw_breakpoint ())
5806 for (bp_location
*loc
: moribund_locations
)
5808 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5809 && need_moribund_for_location_type (loc
))
5811 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5812 /* For hits of moribund locations, we should just proceed. */
5815 bs
->print_it
= print_it_noop
;
5823 /* See breakpoint.h. */
5826 bpstat_stop_status (const address_space
*aspace
,
5827 CORE_ADDR bp_addr
, thread_info
*thread
,
5828 const target_waitstatus
&ws
,
5831 struct breakpoint
*b
= NULL
;
5832 /* First item of allocated bpstat's. */
5833 bpstat
*bs_head
= stop_chain
;
5835 int need_remove_insert
;
5838 /* First, build the bpstat chain with locations that explain a
5839 target stop, while being careful to not set the target running,
5840 as that may invalidate locations (in particular watchpoint
5841 locations are recreated). Resuming will happen here with
5842 breakpoint conditions or watchpoint expressions that include
5843 inferior function calls. */
5844 if (bs_head
== NULL
)
5845 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5847 /* A bit of special processing for shlib breakpoints. We need to
5848 process solib loading here, so that the lists of loaded and
5849 unloaded libraries are correct before we handle "catch load" and
5851 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5853 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5855 handle_solib_event ();
5860 /* Now go through the locations that caused the target to stop, and
5861 check whether we're interested in reporting this stop to higher
5862 layers, or whether we should resume the target transparently. */
5866 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5871 b
= bs
->breakpoint_at
;
5872 b
->check_status (bs
);
5875 bpstat_check_breakpoint_conditions (bs
, thread
);
5881 /* We will stop here. */
5882 if (b
->disposition
== disp_disable
)
5884 --(b
->enable_count
);
5885 if (b
->enable_count
<= 0)
5886 b
->enable_state
= bp_disabled
;
5889 notify_breakpoint_modified (b
);
5892 bs
->commands
= b
->commands
;
5893 if (command_line_is_silent (bs
->commands
5894 ? bs
->commands
.get () : NULL
))
5897 b
->after_condition_true (bs
);
5902 /* Print nothing for this entry if we don't stop or don't
5904 if (!bs
->stop
|| !bs
->print
)
5905 bs
->print_it
= print_it_noop
;
5908 /* If we aren't stopping, the value of some hardware watchpoint may
5909 not have changed, but the intermediate memory locations we are
5910 watching may have. Don't bother if we're stopping; this will get
5912 need_remove_insert
= 0;
5913 if (! bpstat_causes_stop (bs_head
))
5914 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5916 && bs
->breakpoint_at
5917 && is_hardware_watchpoint (bs
->breakpoint_at
))
5919 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5921 update_watchpoint (w
, false /* don't reparse. */);
5922 need_remove_insert
= 1;
5925 if (need_remove_insert
)
5926 update_global_location_list (UGLL_MAY_INSERT
);
5927 else if (removed_any
)
5928 update_global_location_list (UGLL_DONT_INSERT
);
5933 /* See breakpoint.h. */
5936 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5937 thread_info
*thread
, const target_waitstatus
&ws
)
5939 gdb_assert (!target_stopped_by_watchpoint ());
5941 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5942 previous stop to avoid confusing bpstat_stop_status. */
5943 watchpoints_triggered (ws
);
5945 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5949 handle_jit_event (CORE_ADDR address
)
5951 struct gdbarch
*gdbarch
;
5953 infrun_debug_printf ("handling bp_jit_event");
5955 /* Switch terminal for any messages produced by
5956 breakpoint_re_set. */
5957 target_terminal::ours_for_output ();
5959 gdbarch
= get_frame_arch (get_current_frame ());
5960 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5961 thus it is expected that its objectfile can be found through
5962 minimal symbol lookup. If it doesn't work (and assert fails), it
5963 most likely means that `jit_breakpoint_re_set` was changes and this
5964 function needs to be updated too. */
5965 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5966 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5967 objfile
*objfile
= jit_bp_sym
.objfile
;
5968 if (objfile
->separate_debug_objfile_backlink
)
5969 objfile
= objfile
->separate_debug_objfile_backlink
;
5970 jit_event_handler (gdbarch
, objfile
);
5972 target_terminal::inferior ();
5975 /* Prepare WHAT final decision for infrun. */
5977 /* Decide what infrun needs to do with this bpstat. */
5980 bpstat_what (bpstat
*bs_head
)
5982 struct bpstat_what retval
;
5985 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5986 retval
.call_dummy
= STOP_NONE
;
5987 retval
.is_longjmp
= false;
5989 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5991 /* Extract this BS's action. After processing each BS, we check
5992 if its action overrides all we've seem so far. */
5993 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5996 if (bs
->breakpoint_at
== NULL
)
5998 /* I suspect this can happen if it was a momentary
5999 breakpoint which has since been deleted. */
6003 bptype
= bs
->breakpoint_at
->type
;
6010 case bp_hardware_breakpoint
:
6011 case bp_single_step
:
6014 case bp_shlib_event
:
6018 this_action
= BPSTAT_WHAT_STOP_NOISY
;
6020 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6023 this_action
= BPSTAT_WHAT_SINGLE
;
6026 case bp_hardware_watchpoint
:
6027 case bp_read_watchpoint
:
6028 case bp_access_watchpoint
:
6032 this_action
= BPSTAT_WHAT_STOP_NOISY
;
6034 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6038 /* There was a watchpoint, but we're not stopping.
6039 This requires no further action. */
6043 case bp_longjmp_call_dummy
:
6047 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
6048 retval
.is_longjmp
= bptype
!= bp_exception
;
6051 this_action
= BPSTAT_WHAT_SINGLE
;
6053 case bp_longjmp_resume
:
6054 case bp_exception_resume
:
6057 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
6058 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
6061 this_action
= BPSTAT_WHAT_SINGLE
;
6063 case bp_step_resume
:
6065 this_action
= BPSTAT_WHAT_STEP_RESUME
;
6068 /* It is for the wrong frame. */
6069 this_action
= BPSTAT_WHAT_SINGLE
;
6072 case bp_hp_step_resume
:
6074 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
6077 /* It is for the wrong frame. */
6078 this_action
= BPSTAT_WHAT_SINGLE
;
6081 case bp_watchpoint_scope
:
6082 case bp_thread_event
:
6083 case bp_overlay_event
:
6084 case bp_longjmp_master
:
6085 case bp_std_terminate_master
:
6086 case bp_exception_master
:
6087 this_action
= BPSTAT_WHAT_SINGLE
;
6093 this_action
= BPSTAT_WHAT_STOP_NOISY
;
6095 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6099 /* Some catchpoints are implemented with breakpoints.
6100 For those, we need to step over the breakpoint. */
6101 if (bs
->bp_location_at
->loc_type
== bp_loc_software_breakpoint
6102 || bs
->bp_location_at
->loc_type
== bp_loc_hardware_breakpoint
)
6103 this_action
= BPSTAT_WHAT_SINGLE
;
6107 this_action
= BPSTAT_WHAT_SINGLE
;
6110 /* Make sure the action is stop (silent or noisy),
6111 so infrun.c pops the dummy frame. */
6112 retval
.call_dummy
= STOP_STACK_DUMMY
;
6113 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6115 case bp_std_terminate
:
6116 /* Make sure the action is stop (silent or noisy),
6117 so infrun.c pops the dummy frame. */
6118 retval
.call_dummy
= STOP_STD_TERMINATE
;
6119 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6122 case bp_fast_tracepoint
:
6123 case bp_static_tracepoint
:
6124 case bp_static_marker_tracepoint
:
6125 /* Tracepoint hits should not be reported back to GDB, and
6126 if one got through somehow, it should have been filtered
6128 internal_error (_("bpstat_what: tracepoint encountered"));
6130 case bp_gnu_ifunc_resolver
:
6131 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
6132 this_action
= BPSTAT_WHAT_SINGLE
;
6134 case bp_gnu_ifunc_resolver_return
:
6135 /* The breakpoint will be removed, execution will restart from the
6136 PC of the former breakpoint. */
6137 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
6142 this_action
= BPSTAT_WHAT_STOP_SILENT
;
6144 this_action
= BPSTAT_WHAT_SINGLE
;
6148 internal_error (_("bpstat_what: unhandled bptype %d"), (int) bptype
);
6151 retval
.main_action
= std::max (retval
.main_action
, this_action
);
6158 bpstat_run_callbacks (bpstat
*bs_head
)
6162 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
6164 struct breakpoint
*b
= bs
->breakpoint_at
;
6171 handle_jit_event (bs
->bp_location_at
->address
);
6173 case bp_gnu_ifunc_resolver
:
6174 gnu_ifunc_resolver_stop ((code_breakpoint
*) b
);
6176 case bp_gnu_ifunc_resolver_return
:
6177 gnu_ifunc_resolver_return_stop ((code_breakpoint
*) b
);
6183 /* See breakpoint.h. */
6186 bpstat_should_step ()
6188 for (breakpoint
&b
: all_breakpoints ())
6189 if (breakpoint_enabled (&b
)
6190 && b
.type
== bp_watchpoint
6191 && b
.has_locations ())
6197 /* See breakpoint.h. */
6200 bpstat_causes_stop (bpstat
*bs
)
6202 for (; bs
!= NULL
; bs
= bs
->next
)
6211 /* Compute a number of spaces suitable to indent the next line
6212 so it starts at the position corresponding to the table column
6213 named COL_NAME in the currently active table of UIOUT. */
6216 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6218 int i
, total_width
, width
, align
;
6222 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
6224 if (strcmp (text
, col_name
) == 0)
6227 total_width
+= width
+ 1;
6233 /* Determine if the locations of this breakpoint will have their conditions
6234 evaluated by the target, host or a mix of both. Returns the following:
6236 "host": Host evals condition.
6237 "host or target": Host or Target evals condition.
6238 "target": Target evals condition.
6242 bp_condition_evaluator (const breakpoint
*b
)
6244 char host_evals
= 0;
6245 char target_evals
= 0;
6250 if (!is_breakpoint (b
))
6253 if (gdb_evaluates_breakpoint_condition_p ()
6254 || !target_supports_evaluation_of_breakpoint_conditions ())
6255 return condition_evaluation_host
;
6257 for (bp_location
&bl
: b
->locations ())
6259 if (bl
.cond_bytecode
)
6265 if (host_evals
&& target_evals
)
6266 return condition_evaluation_both
;
6267 else if (target_evals
)
6268 return condition_evaluation_target
;
6270 return condition_evaluation_host
;
6273 /* Determine the breakpoint location's condition evaluator. This is
6274 similar to bp_condition_evaluator, but for locations. */
6277 bp_location_condition_evaluator (const struct bp_location
*bl
)
6279 if (bl
&& !is_breakpoint (bl
->owner
))
6282 if (gdb_evaluates_breakpoint_condition_p ()
6283 || !target_supports_evaluation_of_breakpoint_conditions ())
6284 return condition_evaluation_host
;
6286 if (bl
&& bl
->cond_bytecode
)
6287 return condition_evaluation_target
;
6289 return condition_evaluation_host
;
6292 /* Print the LOC location out of the list of B->LOC locations. */
6295 print_breakpoint_location (const breakpoint
*b
, const bp_location
*loc
)
6297 struct ui_out
*uiout
= current_uiout
;
6299 scoped_restore_current_program_space restore_pspace
;
6301 if (loc
!= NULL
&& loc
->shlib_disabled
)
6305 set_current_program_space (loc
->pspace
);
6307 if (b
->display_canonical
)
6308 uiout
->field_string ("what", b
->locspec
->to_string ());
6309 else if (loc
&& loc
->symtab
)
6311 const struct symbol
*sym
= loc
->symbol
;
6315 uiout
->text ("in ");
6316 uiout
->field_string ("func", sym
->print_name (),
6317 function_name_style
.style ());
6319 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6320 uiout
->text ("at ");
6322 uiout
->field_string ("file",
6323 symtab_to_filename_for_display (loc
->symtab
),
6324 file_name_style
.style ());
6327 if (uiout
->is_mi_like_p ())
6328 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6330 uiout
->field_signed ("line", loc
->line_number
);
6336 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6338 uiout
->field_stream ("at", stb
);
6342 uiout
->field_string ("pending", b
->locspec
->to_string ());
6343 /* If extra_string is available, it could be holding a condition
6344 or dprintf arguments. In either case, make sure it is printed,
6345 too, but only for non-MI streams. */
6346 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6348 if (b
->type
== bp_dprintf
)
6352 uiout
->text (b
->extra_string
.get ());
6356 if (loc
&& is_breakpoint (b
)
6357 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6358 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6361 uiout
->field_string ("evaluated-by",
6362 bp_location_condition_evaluator (loc
));
6368 bptype_string (enum bptype type
)
6370 struct ep_type_description
6373 const char *description
;
6375 static struct ep_type_description bptypes
[] =
6377 {bp_none
, "?deleted?"},
6378 {bp_breakpoint
, "breakpoint"},
6379 {bp_hardware_breakpoint
, "hw breakpoint"},
6380 {bp_single_step
, "sw single-step"},
6381 {bp_until
, "until"},
6382 {bp_finish
, "finish"},
6383 {bp_watchpoint
, "watchpoint"},
6384 {bp_hardware_watchpoint
, "hw watchpoint"},
6385 {bp_read_watchpoint
, "read watchpoint"},
6386 {bp_access_watchpoint
, "acc watchpoint"},
6387 {bp_longjmp
, "longjmp"},
6388 {bp_longjmp_resume
, "longjmp resume"},
6389 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6390 {bp_exception
, "exception"},
6391 {bp_exception_resume
, "exception resume"},
6392 {bp_step_resume
, "step resume"},
6393 {bp_hp_step_resume
, "high-priority step resume"},
6394 {bp_watchpoint_scope
, "watchpoint scope"},
6395 {bp_call_dummy
, "call dummy"},
6396 {bp_std_terminate
, "std::terminate"},
6397 {bp_shlib_event
, "shlib events"},
6398 {bp_thread_event
, "thread events"},
6399 {bp_overlay_event
, "overlay events"},
6400 {bp_longjmp_master
, "longjmp master"},
6401 {bp_std_terminate_master
, "std::terminate master"},
6402 {bp_exception_master
, "exception master"},
6403 {bp_catchpoint
, "catchpoint"},
6404 {bp_tracepoint
, "tracepoint"},
6405 {bp_fast_tracepoint
, "fast tracepoint"},
6406 {bp_static_tracepoint
, "static tracepoint"},
6407 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6408 {bp_dprintf
, "dprintf"},
6409 {bp_jit_event
, "jit events"},
6410 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6411 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6414 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6415 || ((int) type
!= bptypes
[(int) type
].type
))
6416 internal_error (_("bptypes table does not describe type #%d."),
6419 return bptypes
[(int) type
].description
;
6422 /* For MI, output a field named 'thread-groups' with a list as the value.
6423 For CLI, prefix the list with the string 'inf'. */
6426 output_thread_groups (struct ui_out
*uiout
,
6427 const char *field_name
,
6428 const std::vector
<int> &inf_nums
,
6431 int is_mi
= uiout
->is_mi_like_p ();
6433 /* For backward compatibility, don't display inferiors in CLI unless
6434 there are several. Always display them for MI. */
6435 if (!is_mi
&& mi_only
)
6438 ui_out_emit_list
list_emitter (uiout
, field_name
);
6440 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6446 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6447 uiout
->field_string (NULL
, mi_group
);
6452 uiout
->text (" inf ");
6456 uiout
->text (plongest (inf_nums
[i
]));
6461 /* See breakpoint.h. */
6463 bool fix_breakpoint_script_output_globally
= false;
6465 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6466 instead of going via breakpoint_ops::print_one. This makes "maint
6467 info breakpoints" show the software breakpoint locations of
6468 catchpoints, which are considered internal implementation
6469 detail. Returns true if RAW_LOC is false and if the breakpoint's
6470 print_one method did something; false otherwise. */
6473 print_one_breakpoint_location (struct breakpoint
*b
,
6474 struct bp_location
*loc
,
6476 const bp_location
**last_loc
,
6477 int allflag
, bool raw_loc
)
6479 struct command_line
*l
;
6480 static char bpenables
[] = "nynny";
6482 struct ui_out
*uiout
= current_uiout
;
6483 bool header_of_multiple
= false;
6484 bool part_of_multiple
= (loc
!= NULL
);
6485 struct value_print_options opts
;
6487 get_user_print_options (&opts
);
6489 gdb_assert (!loc
|| loc_number
!= 0);
6490 /* See comment in print_one_breakpoint concerning treatment of
6491 breakpoints with single disabled location. */
6493 && (b
->has_locations ()
6494 && (b
->has_multiple_locations ()
6495 || !b
->first_loc ().enabled
|| b
->first_loc ().disabled_by_cond
)))
6496 header_of_multiple
= true;
6498 if (loc
== NULL
&& b
->has_locations ())
6499 loc
= &b
->first_loc ();
6505 if (part_of_multiple
)
6506 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6508 uiout
->field_signed ("number", b
->number
);
6512 if (part_of_multiple
)
6513 uiout
->field_skip ("type");
6515 uiout
->field_string ("type", bptype_string (b
->type
));
6519 if (part_of_multiple
)
6520 uiout
->field_skip ("disp");
6522 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6526 if (part_of_multiple
)
6528 /* For locations that are disabled because of an invalid
6529 condition, display "N*" on the CLI, where "*" refers to a
6530 footnote below the table. For MI, simply display a "N"
6531 without a footnote. On the CLI, for enabled locations whose
6532 breakpoint is disabled, display "y-". */
6533 auto get_enable_state
= [uiout
, loc
] () -> const char *
6535 if (uiout
->is_mi_like_p ())
6537 if (loc
->disabled_by_cond
)
6539 else if (!loc
->enabled
)
6546 if (loc
->disabled_by_cond
)
6548 else if (!loc
->enabled
)
6550 else if (!breakpoint_enabled (loc
->owner
))
6556 uiout
->field_string ("enabled", get_enable_state ());
6559 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6562 bool result
= false;
6563 if (!raw_loc
&& b
->print_one (last_loc
))
6567 if (is_watchpoint (b
))
6569 struct watchpoint
*w
= (struct watchpoint
*) b
;
6571 /* Field 4, the address, is omitted (which makes the columns
6572 not line up too nicely with the headers, but the effect
6573 is relatively readable). */
6574 if (opts
.addressprint
)
6575 uiout
->field_skip ("addr");
6577 uiout
->field_string ("what", w
->exp_string
.get ());
6579 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6580 || is_ada_exception_catchpoint (b
))
6582 if (opts
.addressprint
)
6585 if (header_of_multiple
)
6586 uiout
->field_string ("addr", "<MULTIPLE>",
6587 metadata_style
.style ());
6588 else if (!b
->has_locations () || loc
->shlib_disabled
)
6589 uiout
->field_string ("addr", "<PENDING>",
6590 metadata_style
.style ());
6592 uiout
->field_core_addr ("addr",
6593 loc
->gdbarch
, loc
->address
);
6596 if (!header_of_multiple
)
6597 print_breakpoint_location (b
, loc
);
6598 if (b
->has_locations ())
6599 *last_loc
= &b
->first_loc ();
6603 if (loc
!= NULL
&& !header_of_multiple
)
6605 std::vector
<int> inf_nums
;
6608 for (inferior
*inf
: all_inferiors ())
6610 if (inf
->pspace
== loc
->pspace
)
6611 inf_nums
.push_back (inf
->num
);
6614 /* For backward compatibility, don't display inferiors in CLI unless
6615 there are several. Always display for MI. */
6617 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6618 && (program_spaces
.size () > 1
6619 || number_of_inferiors () > 1)
6620 /* LOC is for existing B, it cannot be in
6621 moribund_locations and thus having NULL OWNER. */
6622 && loc
->owner
->type
!= bp_catchpoint
))
6624 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6627 /* In the MI output, each location of a thread or task specific
6628 breakpoint includes the relevant thread or task ID. This is done for
6629 backwards compatibility reasons.
6631 For the CLI output, the thread/task information is printed on a
6632 separate line, see the 'stop only in thread' and 'stop only in task'
6634 if (part_of_multiple
&& uiout
->is_mi_like_p ())
6636 if (b
->thread
!= -1)
6637 uiout
->field_signed ("thread", b
->thread
);
6638 else if (b
->task
!= -1)
6639 uiout
->field_signed ("task", b
->task
);
6640 else if (b
->inferior
!= -1)
6641 uiout
->field_signed ("inferior", b
->inferior
);
6646 if (!part_of_multiple
)
6647 b
->print_one_detail (uiout
);
6649 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6652 uiout
->text ("\tstop only in stack frame at ");
6653 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6655 uiout
->field_core_addr ("frame",
6656 b
->gdbarch
, b
->frame_id
.stack_addr
);
6660 if (!part_of_multiple
&& b
->cond_string
)
6663 if (is_tracepoint (b
))
6664 uiout
->text ("\ttrace only if ");
6666 uiout
->text ("\tstop only if ");
6667 uiout
->field_string ("cond", b
->cond_string
.get ());
6669 /* Print whether the target is doing the breakpoint's condition
6670 evaluation. If GDB is doing the evaluation, don't print anything. */
6671 if (is_breakpoint (b
)
6672 && breakpoint_condition_evaluation_mode ()
6673 == condition_evaluation_target
)
6675 uiout
->message (" (%pF evals)",
6676 string_field ("evaluated-by",
6677 bp_condition_evaluator (b
)));
6682 if (!part_of_multiple
&& b
->thread
!= -1)
6684 /* FIXME should make an annotation for this. */
6685 uiout
->text ("\tstop only in thread ");
6686 if (uiout
->is_mi_like_p ())
6687 uiout
->field_signed ("thread", b
->thread
);
6690 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6692 uiout
->field_string ("thread", print_thread_id (thr
));
6697 if (!part_of_multiple
&& b
->task
!= -1)
6699 uiout
->text ("\tstop only in task ");
6700 uiout
->field_signed ("task", b
->task
);
6704 if (!part_of_multiple
&& b
->inferior
!= -1)
6706 uiout
->text ("\tstop only in inferior ");
6707 uiout
->field_signed ("inferior", b
->inferior
);
6711 if (!part_of_multiple
)
6715 /* FIXME should make an annotation for this. */
6716 if (is_catchpoint (b
))
6717 uiout
->text ("\tcatchpoint");
6718 else if (is_tracepoint (b
))
6719 uiout
->text ("\ttracepoint");
6721 uiout
->text ("\tbreakpoint");
6722 uiout
->text (" already hit ");
6723 uiout
->field_signed ("times", b
->hit_count
);
6724 if (b
->hit_count
== 1)
6725 uiout
->text (" time\n");
6727 uiout
->text (" times\n");
6731 /* Output the count also if it is zero, but only if this is mi. */
6732 if (uiout
->is_mi_like_p ())
6733 uiout
->field_signed ("times", b
->hit_count
);
6737 if (!part_of_multiple
&& b
->ignore_count
)
6740 uiout
->message ("\tignore next %pF hits\n",
6741 signed_field ("ignore", b
->ignore_count
));
6744 /* Note that an enable count of 1 corresponds to "enable once"
6745 behavior, which is reported by the combination of enablement and
6746 disposition, so we don't need to mention it here. */
6747 if (!part_of_multiple
&& b
->enable_count
> 1)
6750 uiout
->text ("\tdisable after ");
6751 /* Tweak the wording to clarify that ignore and enable counts
6752 are distinct, and have additive effect. */
6753 if (b
->ignore_count
)
6754 uiout
->text ("additional ");
6756 uiout
->text ("next ");
6757 uiout
->field_signed ("enable", b
->enable_count
);
6758 uiout
->text (" hits\n");
6761 if (!part_of_multiple
&& is_tracepoint (b
))
6763 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6765 if (tp
->traceframe_usage
)
6767 uiout
->text ("\ttrace buffer usage ");
6768 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6769 uiout
->text (" bytes\n");
6773 l
= b
->commands
? b
->commands
.get () : NULL
;
6774 if (!part_of_multiple
&& l
)
6778 bool use_fixed_output
=
6779 (uiout
->test_flags (fix_breakpoint_script_output
)
6780 || fix_breakpoint_script_output_globally
);
6782 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
6783 gdb::optional
<ui_out_emit_list
> list_emitter
;
6785 if (use_fixed_output
)
6786 list_emitter
.emplace (uiout
, "script");
6788 tuple_emitter
.emplace (uiout
, "script");
6790 print_command_lines (uiout
, l
, 4);
6793 if (is_tracepoint (b
))
6795 struct tracepoint
*t
= (struct tracepoint
*) b
;
6797 if (!part_of_multiple
&& t
->pass_count
)
6799 annotate_field (10);
6800 uiout
->text ("\tpass count ");
6801 uiout
->field_signed ("pass", t
->pass_count
);
6802 uiout
->text (" \n");
6805 /* Don't display it when tracepoint or tracepoint location is
6807 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6809 annotate_field (11);
6811 if (uiout
->is_mi_like_p ())
6812 uiout
->field_string ("installed",
6813 loc
->inserted
? "y" : "n");
6819 uiout
->text ("\tnot ");
6820 uiout
->text ("installed on target\n");
6825 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6827 if (is_watchpoint (b
))
6829 struct watchpoint
*w
= (struct watchpoint
*) b
;
6831 uiout
->field_string ("original-location", w
->exp_string
.get ());
6833 else if (b
->locspec
!= nullptr)
6835 const char *str
= b
->locspec
->to_string ();
6837 uiout
->field_string ("original-location", str
);
6844 /* See breakpoint.h. */
6846 bool fix_multi_location_breakpoint_output_globally
= false;
6849 print_one_breakpoint (breakpoint
*b
, const bp_location
**last_loc
, int allflag
)
6851 struct ui_out
*uiout
= current_uiout
;
6852 bool use_fixed_output
6853 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6854 || fix_multi_location_breakpoint_output_globally
);
6856 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6857 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6860 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6862 if (!use_fixed_output
)
6863 bkpt_tuple_emitter
.reset ();
6865 /* If this breakpoint has custom print function,
6866 it's already printed. Otherwise, print individual
6867 locations, if any. */
6868 if (!printed
|| allflag
)
6870 /* If breakpoint has a single location that is disabled, we
6871 print it as if it had several locations, since otherwise it's
6872 hard to represent "breakpoint enabled, location disabled"
6875 Note that while hardware watchpoints have several locations
6876 internally, that's not a property exposed to users.
6878 Likewise, while catchpoints may be implemented with
6879 breakpoints (e.g., catch throw), that's not a property
6880 exposed to users. We do however display the internal
6881 breakpoint locations with "maint info breakpoints". */
6882 if (!is_hardware_watchpoint (b
)
6883 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6884 || is_ada_exception_catchpoint (b
))
6886 || (b
->has_locations ()
6887 && (b
->has_multiple_locations ()
6888 || !b
->first_loc ().enabled
6889 || b
->first_loc ().disabled_by_cond
))))
6891 gdb::optional
<ui_out_emit_list
> locations_list
;
6893 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6894 MI record. For later versions, place breakpoint locations in a
6896 if (uiout
->is_mi_like_p () && use_fixed_output
)
6897 locations_list
.emplace (uiout
, "locations");
6900 for (bp_location
&loc
: b
->locations ())
6902 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6903 print_one_breakpoint_location (b
, &loc
, n
, last_loc
,
6912 breakpoint_address_bits (struct breakpoint
*b
)
6914 int print_address_bits
= 0;
6916 for (bp_location
&loc
: b
->locations ())
6918 if (!bl_address_is_meaningful (&loc
))
6921 int addr_bit
= gdbarch_addr_bit (loc
.gdbarch
);
6922 if (addr_bit
> print_address_bits
)
6923 print_address_bits
= addr_bit
;
6926 return print_address_bits
;
6929 /* See breakpoint.h. */
6932 print_breakpoint (breakpoint
*b
)
6934 const bp_location
*dummy_loc
= nullptr;
6935 print_one_breakpoint (b
, &dummy_loc
, 0);
6938 /* Return true if this breakpoint was set by the user, false if it is
6939 internal or momentary. */
6942 user_breakpoint_p (struct breakpoint
*b
)
6944 return b
->number
> 0;
6947 /* See breakpoint.h. */
6950 pending_breakpoint_p (struct breakpoint
*b
)
6952 return !b
->has_locations ();
6955 /* Print information on breakpoints (including watchpoints and tracepoints).
6957 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6958 understood by number_or_range_parser. Only breakpoints included in this
6959 list are then printed.
6961 If SHOW_INTERNAL is true, print internal breakpoints.
6963 If FILTER is non-NULL, call it on each breakpoint and only include the
6964 ones for which it returns true.
6966 Return the total number of breakpoints listed. */
6969 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6970 bool (*filter
) (const struct breakpoint
*))
6972 const bp_location
*last_loc
= nullptr;
6973 int nr_printable_breakpoints
;
6974 struct value_print_options opts
;
6975 int print_address_bits
= 0;
6976 int print_type_col_width
= 14;
6977 struct ui_out
*uiout
= current_uiout
;
6978 bool has_disabled_by_cond_location
= false;
6980 get_user_print_options (&opts
);
6982 /* Compute the number of rows in the table, as well as the size
6983 required for address fields. */
6984 nr_printable_breakpoints
= 0;
6985 for (breakpoint
&b
: all_breakpoints ())
6987 /* If we have a filter, only list the breakpoints it accepts. */
6988 if (filter
&& !filter (&b
))
6991 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6992 accept. Skip the others. */
6993 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6995 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
.number
)
6997 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
.number
))
7001 if (show_internal
|| user_breakpoint_p (&b
))
7003 int addr_bit
, type_len
;
7005 addr_bit
= breakpoint_address_bits (&b
);
7006 if (addr_bit
> print_address_bits
)
7007 print_address_bits
= addr_bit
;
7009 type_len
= strlen (bptype_string (b
.type
));
7010 if (type_len
> print_type_col_width
)
7011 print_type_col_width
= type_len
;
7013 nr_printable_breakpoints
++;
7018 ui_out_emit_table
table_emitter (uiout
,
7019 opts
.addressprint
? 6 : 5,
7020 nr_printable_breakpoints
,
7023 if (nr_printable_breakpoints
> 0)
7024 annotate_breakpoints_headers ();
7025 if (nr_printable_breakpoints
> 0)
7027 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
7028 if (nr_printable_breakpoints
> 0)
7030 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
7031 if (nr_printable_breakpoints
> 0)
7033 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
7034 if (nr_printable_breakpoints
> 0)
7036 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
7037 if (opts
.addressprint
)
7039 if (nr_printable_breakpoints
> 0)
7041 if (print_address_bits
<= 32)
7042 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
7044 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
7046 if (nr_printable_breakpoints
> 0)
7048 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
7049 uiout
->table_body ();
7050 if (nr_printable_breakpoints
> 0)
7051 annotate_breakpoints_table ();
7053 for (breakpoint
&b
: all_breakpoints ())
7056 /* If we have a filter, only list the breakpoints it accepts. */
7057 if (filter
&& !filter (&b
))
7060 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
7061 accept. Skip the others. */
7063 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
7065 if (show_internal
) /* maintenance info breakpoint */
7067 if (parse_and_eval_long (bp_num_list
) != b
.number
)
7070 else /* all others */
7072 if (!number_is_in_list (bp_num_list
, b
.number
))
7076 /* We only print out user settable breakpoints unless the
7077 show_internal is set. */
7078 if (show_internal
|| user_breakpoint_p (&b
))
7080 print_one_breakpoint (&b
, &last_loc
, show_internal
);
7081 for (bp_location
&loc
: b
.locations ())
7082 if (loc
.disabled_by_cond
)
7083 has_disabled_by_cond_location
= true;
7088 if (nr_printable_breakpoints
== 0)
7090 /* If there's a filter, let the caller decide how to report
7094 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
7095 uiout
->message ("No breakpoints or watchpoints.\n");
7097 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
7103 if (last_loc
&& !server_command
)
7104 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
7106 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
7107 uiout
->message (_("(*): Breakpoint condition is invalid at this "
7111 /* FIXME? Should this be moved up so that it is only called when
7112 there have been breakpoints? */
7113 annotate_breakpoints_table_end ();
7115 return nr_printable_breakpoints
;
7118 /* Display the value of default-collect in a way that is generally
7119 compatible with the breakpoint list. */
7122 default_collect_info (void)
7124 struct ui_out
*uiout
= current_uiout
;
7126 /* If it has no value (which is frequently the case), say nothing; a
7127 message like "No default-collect." gets in user's face when it's
7129 if (default_collect
.empty ())
7132 /* The following phrase lines up nicely with per-tracepoint collect
7134 uiout
->text ("default collect ");
7135 uiout
->field_string ("default-collect", default_collect
);
7136 uiout
->text (" \n");
7140 info_breakpoints_command (const char *args
, int from_tty
)
7142 breakpoint_1 (args
, false, NULL
);
7144 default_collect_info ();
7148 info_watchpoints_command (const char *args
, int from_tty
)
7150 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
7151 struct ui_out
*uiout
= current_uiout
;
7153 if (num_printed
== 0)
7155 if (args
== NULL
|| *args
== '\0')
7156 uiout
->message ("No watchpoints.\n");
7158 uiout
->message ("No watchpoint matching '%s'.\n", args
);
7163 maintenance_info_breakpoints (const char *args
, int from_tty
)
7165 breakpoint_1 (args
, true, NULL
);
7167 default_collect_info ();
7171 breakpoint_has_pc (struct breakpoint
*b
,
7172 struct program_space
*pspace
,
7173 CORE_ADDR pc
, struct obj_section
*section
)
7175 for (bp_location
&bl
: b
->locations ())
7177 if (bl
.pspace
== pspace
7179 && (!overlay_debugging
|| bl
.section
== section
))
7185 /* See breakpoint.h. */
7188 describe_other_breakpoints (struct gdbarch
*gdbarch
,
7189 struct program_space
*pspace
, CORE_ADDR pc
,
7190 struct obj_section
*section
, int thread
)
7194 for (breakpoint
&b
: all_breakpoints ())
7195 others
+= (user_breakpoint_p (&b
)
7196 && breakpoint_has_pc (&b
, pspace
, pc
, section
));
7201 gdb_printf (_("Note: breakpoint "));
7202 else /* if (others == ???) */
7203 gdb_printf (_("Note: breakpoints "));
7204 for (breakpoint
&b
: all_breakpoints ())
7205 if (user_breakpoint_p (&b
)
7206 && breakpoint_has_pc (&b
, pspace
, pc
, section
))
7209 gdb_printf ("%d", b
.number
);
7210 if (b
.thread
== -1 && thread
!= -1)
7211 gdb_printf (" (all threads)");
7212 else if (b
.thread
!= -1)
7214 struct thread_info
*thr
= find_thread_global_id (b
.thread
);
7215 gdb_printf (" (thread %s)", print_thread_id (thr
));
7217 else if (b
.task
!= -1)
7218 gdb_printf (" (task %d)", b
.task
);
7219 gdb_printf ("%s%s ",
7220 ((b
.enable_state
== bp_disabled
7221 || b
.enable_state
== bp_call_disabled
)
7225 : ((others
== 1) ? " and" : ""));
7227 current_uiout
->message (_("also set at pc %ps.\n"),
7228 styled_string (address_style
.style (),
7229 paddress (gdbarch
, pc
)));
7234 /* Return true iff it is meaningful to use the address member of LOC.
7235 For some breakpoint types, the locations' address members are
7236 irrelevant and it makes no sense to attempt to compare them to
7237 other addresses (or use them for any other purpose either).
7239 More specifically, software watchpoints and catchpoints that are
7240 not backed by breakpoints always have a zero valued location
7241 address and we don't want to mark breakpoints of any of these types
7242 to be a duplicate of an actual breakpoint location at address
7246 bl_address_is_meaningful (bp_location
*loc
)
7248 return loc
->loc_type
!= bp_loc_other
;
7251 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7252 true if LOC1 and LOC2 represent the same watchpoint location. */
7255 watchpoint_locations_match (const struct bp_location
*loc1
,
7256 const struct bp_location
*loc2
)
7258 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7259 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7261 /* Both of them must exist. */
7262 gdb_assert (w1
!= NULL
);
7263 gdb_assert (w2
!= NULL
);
7265 /* If the target can evaluate the condition expression in hardware,
7266 then we we need to insert both watchpoints even if they are at
7267 the same place. Otherwise the watchpoint will only trigger when
7268 the condition of whichever watchpoint was inserted evaluates to
7269 true, not giving a chance for GDB to check the condition of the
7270 other watchpoint. */
7272 && target_can_accel_watchpoint_condition (loc1
->address
,
7274 loc1
->watchpoint_type
,
7275 w1
->cond_exp
.get ()))
7277 && target_can_accel_watchpoint_condition (loc2
->address
,
7279 loc2
->watchpoint_type
,
7280 w2
->cond_exp
.get ())))
7283 /* Note that this checks the owner's type, not the location's. In
7284 case the target does not support read watchpoints, but does
7285 support access watchpoints, we'll have bp_read_watchpoint
7286 watchpoints with hw_access locations. Those should be considered
7287 duplicates of hw_read locations. The hw_read locations will
7288 become hw_access locations later. */
7289 return (loc1
->owner
->type
== loc2
->owner
->type
7290 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7291 && loc1
->address
== loc2
->address
7292 && loc1
->length
== loc2
->length
);
7295 /* See breakpoint.h. */
7298 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
7299 const address_space
*aspace2
, CORE_ADDR addr2
)
7301 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7302 || aspace1
== aspace2
)
7306 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7307 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7308 matches ASPACE2. On targets that have global breakpoints, the address
7309 space doesn't really matter. */
7312 breakpoint_address_match_range (const address_space
*aspace1
,
7314 int len1
, const address_space
*aspace2
,
7317 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7318 || aspace1
== aspace2
)
7319 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7322 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7323 a ranged breakpoint. In most targets, a match happens only if ASPACE
7324 matches the breakpoint's address space. On targets that have global
7325 breakpoints, the address space doesn't really matter. */
7328 breakpoint_location_address_match (struct bp_location
*bl
,
7329 const address_space
*aspace
,
7332 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7335 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7336 bl
->address
, bl
->length
,
7340 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7341 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7342 match happens only if ASPACE matches the breakpoint's address
7343 space. On targets that have global breakpoints, the address space
7344 doesn't really matter. */
7347 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7348 const address_space
*aspace
,
7349 CORE_ADDR addr
, int len
)
7351 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7352 || bl
->pspace
->aspace
== aspace
)
7354 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7356 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7362 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7363 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7364 true, otherwise returns false. */
7367 tracepoint_locations_match (const struct bp_location
*loc1
,
7368 const struct bp_location
*loc2
)
7370 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7371 /* Since tracepoint locations are never duplicated with others', tracepoint
7372 locations at the same address of different tracepoints are regarded as
7373 different locations. */
7374 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7379 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7380 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7381 the same location. If SW_HW_BPS_MATCH is true, then software
7382 breakpoint locations and hardware breakpoint locations match,
7383 otherwise they don't. */
7386 breakpoint_locations_match (const struct bp_location
*loc1
,
7387 const struct bp_location
*loc2
,
7388 bool sw_hw_bps_match
)
7390 int hw_point1
, hw_point2
;
7392 /* Both of them must not be in moribund_locations. */
7393 gdb_assert (loc1
->owner
!= NULL
);
7394 gdb_assert (loc2
->owner
!= NULL
);
7396 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7397 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7399 if (hw_point1
!= hw_point2
)
7402 return watchpoint_locations_match (loc1
, loc2
);
7403 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7404 return tracepoint_locations_match (loc1
, loc2
);
7406 /* We compare bp_location.length in order to cover ranged
7407 breakpoints. Keep this in sync with
7408 bp_location_is_less_than. */
7409 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7410 loc2
->pspace
->aspace
, loc2
->address
)
7411 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7412 && loc1
->length
== loc2
->length
);
7416 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7417 int bnum
, bool have_bnum
)
7419 /* The longest string possibly returned by hex_string_custom
7420 is 50 chars. These must be at least that big for safety. */
7424 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7425 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7427 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7428 bnum
, astr1
, astr2
);
7430 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7433 /* Adjust a breakpoint's address to account for architectural
7434 constraints on breakpoint placement. Return the adjusted address.
7435 Note: Very few targets require this kind of adjustment. For most
7436 targets, this function is simply the identity function. */
7439 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7440 CORE_ADDR bpaddr
, enum bptype bptype
,
7441 struct program_space
*pspace
)
7443 gdb_assert (pspace
!= nullptr);
7445 if (bptype
== bp_watchpoint
7446 || bptype
== bp_hardware_watchpoint
7447 || bptype
== bp_read_watchpoint
7448 || bptype
== bp_access_watchpoint
7449 || bptype
== bp_catchpoint
)
7451 /* Watchpoints and the various bp_catch_* eventpoints should not
7452 have their addresses modified. */
7455 else if (bptype
== bp_single_step
)
7457 /* Single-step breakpoints should not have their addresses
7458 modified. If there's any architectural constrain that
7459 applies to this address, then it should have already been
7460 taken into account when the breakpoint was created in the
7461 first place. If we didn't do this, stepping through e.g.,
7462 Thumb-2 IT blocks would break. */
7467 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7469 /* Some targets have architectural constraints on the placement
7470 of breakpoint instructions. Obtain the adjusted address. */
7471 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7473 /* Targets that implement this adjustment function will likely
7474 inspect either the symbol table, target memory at BPADDR, or
7475 even state registers, so ensure a suitable thread (and its
7476 associated program space) are currently selected. */
7477 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
7478 switch_to_program_space_and_thread (pspace
);
7480 = gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7484 = gdbarch_remove_non_address_bits (gdbarch
, adjusted_bpaddr
);
7486 /* An adjusted breakpoint address can significantly alter
7487 a user's expectations. Print a warning if an adjustment
7489 if (adjusted_bpaddr
!= bpaddr
)
7490 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, false);
7492 return adjusted_bpaddr
;
7497 bp_location_from_bp_type (bptype type
)
7502 case bp_single_step
:
7506 case bp_longjmp_resume
:
7507 case bp_longjmp_call_dummy
:
7509 case bp_exception_resume
:
7510 case bp_step_resume
:
7511 case bp_hp_step_resume
:
7512 case bp_watchpoint_scope
:
7514 case bp_std_terminate
:
7515 case bp_shlib_event
:
7516 case bp_thread_event
:
7517 case bp_overlay_event
:
7519 case bp_longjmp_master
:
7520 case bp_std_terminate_master
:
7521 case bp_exception_master
:
7522 case bp_gnu_ifunc_resolver
:
7523 case bp_gnu_ifunc_resolver_return
:
7525 return bp_loc_software_breakpoint
;
7527 case bp_hardware_breakpoint
:
7528 return bp_loc_hardware_breakpoint
;
7530 case bp_hardware_watchpoint
:
7531 case bp_read_watchpoint
:
7532 case bp_access_watchpoint
:
7533 return bp_loc_hardware_watchpoint
;
7536 return bp_loc_software_watchpoint
;
7539 case bp_fast_tracepoint
:
7540 case bp_static_tracepoint
:
7541 case bp_static_marker_tracepoint
:
7542 return bp_loc_tracepoint
;
7545 return bp_loc_other
;
7548 internal_error (_("unknown breakpoint type"));
7552 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7554 this->owner
= owner
;
7555 this->cond_bytecode
= NULL
;
7556 this->shlib_disabled
= 0;
7558 this->disabled_by_cond
= false;
7560 this->loc_type
= type
;
7562 if (this->loc_type
== bp_loc_software_breakpoint
7563 || this->loc_type
== bp_loc_hardware_breakpoint
)
7564 mark_breakpoint_location_modified (this);
7569 bp_location::bp_location (breakpoint
*owner
)
7570 : bp_location::bp_location (owner
,
7571 bp_location_from_bp_type (owner
->type
))
7575 /* See breakpoint.h. */
7578 bp_location::to_string () const
7581 ui_out_redirect_pop
redir (current_uiout
, &stb
);
7582 print_breakpoint_location (this->owner
, this);
7583 return stb
.string ();
7586 /* Decrement reference count. If the reference count reaches 0,
7587 destroy the bp_location. Sets *BLP to NULL. */
7590 decref_bp_location (struct bp_location
**blp
)
7592 bp_location_ref_policy::decref (*blp
);
7596 /* Add breakpoint B at the end of the global breakpoint chain. */
7599 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7601 /* Add this breakpoint to the end of the chain so that a list of
7602 breakpoints will come out in order of increasing numbers. */
7604 breakpoint_chain
.push_back (*b
.release ());
7606 return &breakpoint_chain
.back ();
7609 /* Initialize loc->function_name. */
7612 set_breakpoint_location_function (struct bp_location
*loc
)
7614 gdb_assert (loc
->owner
!= NULL
);
7616 if (loc
->owner
->type
== bp_breakpoint
7617 || loc
->owner
->type
== bp_hardware_breakpoint
7618 || is_tracepoint (loc
->owner
))
7620 const char *function_name
;
7622 if (loc
->msymbol
!= NULL
7623 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7624 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7626 struct breakpoint
*b
= loc
->owner
;
7628 function_name
= loc
->msymbol
->linkage_name ();
7630 if (b
->type
== bp_breakpoint
7631 && b
->has_single_location ()
7632 && b
->related_breakpoint
== b
)
7634 /* Create only the whole new breakpoint of this type but do not
7635 mess more complicated breakpoints with multiple locations. */
7636 b
->type
= bp_gnu_ifunc_resolver
;
7637 /* Remember the resolver's address for use by the return
7639 loc
->related_address
= loc
->address
;
7643 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7646 loc
->function_name
= make_unique_xstrdup (function_name
);
7650 /* Attempt to determine architecture of location identified by SAL. */
7652 get_sal_arch (struct symtab_and_line sal
)
7655 return sal
.section
->objfile
->arch ();
7657 return sal
.symtab
->compunit ()->objfile ()->arch ();
7662 /* Call this routine when stepping and nexting to enable a breakpoint
7663 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7664 initiated the operation. */
7667 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7669 int thread
= tp
->global_num
;
7671 /* To avoid having to rescan all objfile symbols at every step,
7672 we maintain a list of continually-inserted but always disabled
7673 longjmp "master" breakpoints. Here, we simply create momentary
7674 clones of those and enable them for the requested thread. */
7675 for (breakpoint
&b
: all_breakpoints_safe ())
7676 if (b
.pspace
== current_program_space
7677 && (b
.type
== bp_longjmp_master
7678 || b
.type
== bp_exception_master
))
7680 bptype type
= b
.type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7681 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7682 after their removal. */
7683 momentary_breakpoint_from_master (&b
, type
, 1, thread
);
7686 tp
->initiating_frame
= frame
;
7689 /* Delete all longjmp breakpoints from THREAD. */
7691 delete_longjmp_breakpoint (int thread
)
7693 for (breakpoint
&b
: all_breakpoints_safe ())
7694 if (b
.type
== bp_longjmp
|| b
.type
== bp_exception
)
7696 if (b
.thread
== thread
)
7698 gdb_assert (b
.inferior
== -1);
7699 delete_breakpoint (&b
);
7705 delete_longjmp_breakpoint_at_next_stop (int thread
)
7707 for (breakpoint
&b
: all_breakpoints_safe ())
7708 if (b
.type
== bp_longjmp
|| b
.type
== bp_exception
)
7710 if (b
.thread
== thread
)
7712 gdb_assert (b
.inferior
== -1);
7713 b
.disposition
= disp_del_at_next_stop
;
7718 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7719 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7720 pointer to any of them. Return NULL if this system cannot place longjmp
7724 set_longjmp_breakpoint_for_call_dummy (void)
7726 breakpoint
*retval
= nullptr;
7728 for (breakpoint
&b
: all_breakpoints ())
7729 if (b
.pspace
== current_program_space
&& b
.type
== bp_longjmp_master
)
7731 int thread
= inferior_thread ()->global_num
;
7733 = momentary_breakpoint_from_master (&b
, bp_longjmp_call_dummy
,
7736 /* Link NEW_B into the chain of RETVAL breakpoints. */
7738 gdb_assert (new_b
->related_breakpoint
== new_b
);
7741 new_b
->related_breakpoint
= retval
;
7742 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7743 retval
= retval
->related_breakpoint
;
7744 retval
->related_breakpoint
= new_b
;
7750 /* Verify all existing dummy frames and their associated breakpoints for
7751 TP. Remove those which can no longer be found in the current frame
7754 If the unwind fails then there is not sufficient information to discard
7755 dummy frames. In this case, elide the clean up and the dummy frames will
7756 be cleaned up next time this function is called from a location where
7757 unwinding is possible. */
7760 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7762 /* We would need to delete breakpoints other than the current one while
7763 iterating, so all_breakpoints_safe is not sufficient to make that safe.
7764 Save all breakpoints to delete in that set and delete them at the end. */
7765 std::unordered_set
<breakpoint
*> to_delete
;
7767 for (struct breakpoint
&b
: all_breakpoints ())
7769 if (b
.type
== bp_longjmp_call_dummy
&& b
.thread
== tp
->global_num
)
7771 gdb_assert (b
.inferior
== -1);
7772 struct breakpoint
*dummy_b
= b
.related_breakpoint
;
7774 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7775 chained off b->related_breakpoint. */
7776 while (dummy_b
!= &b
&& dummy_b
->type
!= bp_call_dummy
)
7777 dummy_b
= dummy_b
->related_breakpoint
;
7779 /* If there was no bp_call_dummy breakpoint then there's nothing
7780 more to do. Or, if the dummy frame associated with the
7781 bp_call_dummy is still on the stack then we need to leave this
7782 bp_call_dummy in place. */
7783 if (dummy_b
->type
!= bp_call_dummy
7784 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7787 /* We didn't find the dummy frame on the stack, this could be
7788 because we have longjmp'd to a stack frame that is previous to
7789 the dummy frame, or it could be because the stack unwind is
7790 broken at some point between the longjmp frame and the dummy
7793 Next we figure out why the stack unwind stopped. If it looks
7794 like the unwind is complete then we assume the dummy frame has
7795 been jumped over, however, if the unwind stopped for an
7796 unexpected reason then we assume the stack unwind is currently
7797 broken, and that we will (eventually) return to the dummy
7800 It might be tempting to consider using frame_id_inner here, but
7801 that is not safe. There is no guarantee that the stack frames
7802 we are looking at here are even on the same stack as the
7803 original dummy frame, hence frame_id_inner can't be used. See
7804 the comments on frame_id_inner for more details. */
7805 bool unwind_finished_unexpectedly
= false;
7806 for (frame_info_ptr fi
= get_current_frame (); fi
!= nullptr; )
7808 frame_info_ptr prev
= get_prev_frame (fi
);
7809 if (prev
== nullptr)
7811 /* FI is the last stack frame. Why did this frame not
7813 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7814 if (stop_reason
!= UNWIND_NO_REASON
7815 && stop_reason
!= UNWIND_OUTERMOST
)
7816 unwind_finished_unexpectedly
= true;
7820 if (unwind_finished_unexpectedly
)
7823 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7825 for (breakpoint
*related_breakpoint
= b
.related_breakpoint
;
7826 related_breakpoint
!= &b
;
7827 related_breakpoint
= related_breakpoint
->related_breakpoint
)
7828 to_delete
.insert (b
.related_breakpoint
);
7830 to_delete
.insert (&b
);
7834 for (breakpoint
*b
: to_delete
)
7835 delete_breakpoint (b
);
7839 enable_overlay_breakpoints (void)
7841 for (breakpoint
&b
: all_breakpoints ())
7842 if (b
.type
== bp_overlay_event
)
7844 b
.enable_state
= bp_enabled
;
7845 update_global_location_list (UGLL_MAY_INSERT
);
7846 overlay_events_enabled
= 1;
7851 disable_overlay_breakpoints (void)
7853 for (breakpoint
&b
: all_breakpoints ())
7854 if (b
.type
== bp_overlay_event
)
7856 b
.enable_state
= bp_disabled
;
7857 update_global_location_list (UGLL_DONT_INSERT
);
7858 overlay_events_enabled
= 0;
7862 /* Set an active std::terminate breakpoint for each std::terminate
7863 master breakpoint. */
7865 set_std_terminate_breakpoint (void)
7867 for (breakpoint
&b
: all_breakpoints_safe ())
7868 if (b
.pspace
== current_program_space
7869 && b
.type
== bp_std_terminate_master
)
7871 momentary_breakpoint_from_master (&b
, bp_std_terminate
, 1,
7872 inferior_thread ()->global_num
);
7876 /* Delete all the std::terminate breakpoints. */
7878 delete_std_terminate_breakpoint (void)
7880 for (breakpoint
&b
: all_breakpoints_safe ())
7881 if (b
.type
== bp_std_terminate
)
7882 delete_breakpoint (&b
);
7886 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7888 struct breakpoint
*b
;
7890 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7892 b
->enable_state
= bp_enabled
;
7893 /* locspec has to be used or breakpoint_re_set will delete me. */
7894 b
->locspec
= new_address_location_spec (b
->first_loc ().address
, NULL
, 0);
7896 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7901 struct lang_and_radix
7907 /* Create a breakpoint for JIT code registration and unregistration. */
7910 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7912 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7915 /* Remove JIT code registration and unregistration breakpoint(s). */
7918 remove_jit_event_breakpoints (void)
7920 for (breakpoint
&b
: all_breakpoints_safe ())
7921 if (b
.type
== bp_jit_event
7922 && b
.first_loc ().pspace
== current_program_space
)
7923 delete_breakpoint (&b
);
7927 remove_solib_event_breakpoints (void)
7929 for (breakpoint
&b
: all_breakpoints_safe ())
7930 if (b
.type
== bp_shlib_event
7931 && b
.first_loc ().pspace
== current_program_space
)
7932 delete_breakpoint (&b
);
7935 /* See breakpoint.h. */
7938 remove_solib_event_breakpoints_at_next_stop (void)
7940 for (breakpoint
&b
: all_breakpoints_safe ())
7941 if (b
.type
== bp_shlib_event
7942 && b
.first_loc ().pspace
== current_program_space
)
7943 b
.disposition
= disp_del_at_next_stop
;
7946 /* Helper for create_solib_event_breakpoint /
7947 create_and_insert_solib_event_breakpoint. Allows specifying which
7948 INSERT_MODE to pass through to update_global_location_list. */
7950 static struct breakpoint
*
7951 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7952 enum ugll_insert_mode insert_mode
)
7954 struct breakpoint
*b
;
7956 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
7957 update_global_location_list_nothrow (insert_mode
);
7962 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7964 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7967 /* See breakpoint.h. */
7970 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7972 struct breakpoint
*b
;
7974 /* Explicitly tell update_global_location_list to insert
7976 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7977 if (!b
->first_loc ().inserted
)
7979 delete_breakpoint (b
);
7985 /* Disable any breakpoints that are on code in shared libraries. Only
7986 apply to enabled breakpoints, disabled ones can just stay disabled. */
7989 disable_breakpoints_in_shlibs (void)
7991 for (bp_location
*loc
: all_bp_locations ())
7993 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7994 struct breakpoint
*b
= loc
->owner
;
7996 /* We apply the check to all breakpoints, including disabled for
7997 those with loc->duplicate set. This is so that when breakpoint
7998 becomes enabled, or the duplicate is removed, gdb will try to
7999 insert all breakpoints. If we don't set shlib_disabled here,
8000 we'll try to insert those breakpoints and fail. */
8001 if (((b
->type
== bp_breakpoint
)
8002 || (b
->type
== bp_jit_event
)
8003 || (b
->type
== bp_hardware_breakpoint
)
8004 || (is_tracepoint (b
)))
8005 && loc
->pspace
== current_program_space
8006 && !loc
->shlib_disabled
8007 && solib_name_from_address (loc
->pspace
, loc
->address
)
8010 loc
->shlib_disabled
= 1;
8015 /* Disable any breakpoints and tracepoints that are in SOLIB upon
8016 notification of unloaded_shlib. Only apply to enabled breakpoints,
8017 disabled ones can just stay disabled. */
8020 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
8022 bool disabled_shlib_breaks
= false;
8024 for (bp_location
*loc
: all_bp_locations ())
8026 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
8027 struct breakpoint
*b
= loc
->owner
;
8029 if (solib
->pspace
== loc
->pspace
8030 && !loc
->shlib_disabled
8031 && (((b
->type
== bp_breakpoint
8032 || b
->type
== bp_jit_event
8033 || b
->type
== bp_hardware_breakpoint
)
8034 && (loc
->loc_type
== bp_loc_hardware_breakpoint
8035 || loc
->loc_type
== bp_loc_software_breakpoint
))
8036 || is_tracepoint (b
))
8037 && solib_contains_address_p (solib
, loc
->address
))
8039 loc
->shlib_disabled
= 1;
8040 /* At this point, we cannot rely on remove_breakpoint
8041 succeeding so we must mark the breakpoint as not inserted
8042 to prevent future errors occurring in remove_breakpoints. */
8045 /* This may cause duplicate notifications for the same breakpoint. */
8046 notify_breakpoint_modified (b
);
8048 if (!disabled_shlib_breaks
)
8050 target_terminal::ours_for_output ();
8051 warning (_("Temporarily disabling breakpoints "
8052 "for unloaded shared library \"%s\""),
8055 disabled_shlib_breaks
= true;
8060 /* Disable any breakpoints and tracepoints in OBJFILE upon
8061 notification of free_objfile. Only apply to enabled breakpoints,
8062 disabled ones can just stay disabled. */
8065 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
8067 if (objfile
== NULL
)
8070 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
8071 managed by the user with add-symbol-file/remove-symbol-file.
8072 Similarly to how breakpoints in shared libraries are handled in
8073 response to "nosharedlibrary", mark breakpoints in such modules
8074 shlib_disabled so they end up uninserted on the next global
8075 location list update. Shared libraries not loaded by the user
8076 aren't handled here -- they're already handled in
8077 disable_breakpoints_in_unloaded_shlib, called by solib.c's
8078 solib_unloaded observer. We skip objfiles that are not
8079 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
8081 if ((objfile
->flags
& OBJF_SHARED
) == 0
8082 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
8085 for (breakpoint
&b
: all_breakpoints ())
8087 bool bp_modified
= false;
8089 if (!is_breakpoint (&b
) && !is_tracepoint (&b
))
8092 for (bp_location
&loc
: b
.locations ())
8094 CORE_ADDR loc_addr
= loc
.address
;
8096 if (loc
.loc_type
!= bp_loc_hardware_breakpoint
8097 && loc
.loc_type
!= bp_loc_software_breakpoint
)
8100 if (loc
.shlib_disabled
!= 0)
8103 if (objfile
->pspace
!= loc
.pspace
)
8106 if (loc
.loc_type
!= bp_loc_hardware_breakpoint
8107 && loc
.loc_type
!= bp_loc_software_breakpoint
)
8110 if (is_addr_in_objfile (loc_addr
, objfile
))
8112 loc
.shlib_disabled
= 1;
8113 /* At this point, we don't know whether the object was
8114 unmapped from the inferior or not, so leave the
8115 inserted flag alone. We'll handle failure to
8116 uninsert quietly, in case the object was indeed
8119 mark_breakpoint_location_modified (&loc
);
8126 notify_breakpoint_modified (&b
);
8130 /* See breakpoint.h. */
8132 breakpoint::breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
8133 bool temp
, const char *cond_string_
)
8135 disposition (temp
? disp_del
: disp_donttouch
),
8137 language (current_language
->la_language
),
8138 input_radix (::input_radix
),
8139 cond_string (cond_string_
!= nullptr
8140 ? make_unique_xstrdup (cond_string_
)
8142 related_breakpoint (this)
8146 /* See breakpoint.h. */
8148 catchpoint::catchpoint (struct gdbarch
*gdbarch
, bool temp
,
8149 const char *cond_string
)
8150 : breakpoint (gdbarch
, bp_catchpoint
, temp
, cond_string
)
8152 add_dummy_location (this, current_program_space
);
8154 pspace
= current_program_space
;
8157 /* Notify interpreters and observers that breakpoint B was created. */
8160 notify_breakpoint_created (breakpoint
*b
)
8162 interps_notify_breakpoint_created (b
);
8163 gdb::observers::breakpoint_created
.notify (b
);
8167 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8169 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8170 set_breakpoint_number (internal
, b
);
8171 if (is_tracepoint (b
))
8172 set_tracepoint_count (breakpoint_count
);
8176 notify_breakpoint_created (b
);
8179 update_global_location_list (UGLL_MAY_INSERT
);
8185 hw_breakpoint_used_count (void)
8189 for (breakpoint
&b
: all_breakpoints ())
8190 if (b
.type
== bp_hardware_breakpoint
&& breakpoint_enabled (&b
))
8191 for (bp_location
&bl
: b
.locations ())
8193 /* Special types of hardware breakpoints may use more than
8195 i
+= b
.resources_needed (&bl
);
8201 /* Returns the resources B would use if it were a hardware
8205 hw_watchpoint_use_count (struct breakpoint
*b
)
8209 if (!breakpoint_enabled (b
))
8212 for (bp_location
&bl
: b
->locations ())
8214 /* Special types of hardware watchpoints may use more than
8216 i
+= b
->resources_needed (&bl
);
8222 /* Returns the sum the used resources of all hardware watchpoints of
8223 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8224 the sum of the used resources of all hardware watchpoints of other
8225 types _not_ TYPE. */
8228 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8229 enum bptype type
, int *other_type_used
)
8233 *other_type_used
= 0;
8234 for (breakpoint
&b
: all_breakpoints ())
8238 if (!breakpoint_enabled (&b
))
8242 i
+= hw_watchpoint_use_count (&b
);
8243 else if (is_hardware_watchpoint (&b
))
8244 *other_type_used
= 1;
8251 disable_watchpoints_before_interactive_call_start (void)
8253 for (breakpoint
&b
: all_breakpoints ())
8254 if (is_watchpoint (&b
) && breakpoint_enabled (&b
))
8256 b
.enable_state
= bp_call_disabled
;
8257 update_global_location_list (UGLL_DONT_INSERT
);
8262 enable_watchpoints_after_interactive_call_stop (void)
8264 for (breakpoint
&b
: all_breakpoints ())
8265 if (is_watchpoint (&b
) && b
.enable_state
== bp_call_disabled
)
8267 b
.enable_state
= bp_enabled
;
8268 update_global_location_list (UGLL_MAY_INSERT
);
8273 disable_breakpoints_before_startup (void)
8275 current_program_space
->executing_startup
= 1;
8276 update_global_location_list (UGLL_DONT_INSERT
);
8280 enable_breakpoints_after_startup (void)
8282 current_program_space
->executing_startup
= 0;
8283 breakpoint_re_set ();
8286 /* Allocate a new momentary breakpoint. */
8288 template<typename
... Arg
>
8289 static momentary_breakpoint
*
8290 new_momentary_breakpoint (struct gdbarch
*gdbarch
, enum bptype type
,
8293 if (type
== bp_longjmp
|| type
== bp_exception
)
8294 return new longjmp_breakpoint (gdbarch
, type
,
8295 std::forward
<Arg
> (args
)...);
8297 return new momentary_breakpoint (gdbarch
, type
,
8298 std::forward
<Arg
> (args
)...);
8301 /* Set a momentary breakpoint of type TYPE at address specified by
8302 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8306 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8307 struct frame_id frame_id
, enum bptype type
)
8309 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8311 gdb_assert (!frame_id_artificial_p (frame_id
));
8313 std::unique_ptr
<momentary_breakpoint
> b
8314 (new_momentary_breakpoint (gdbarch
, type
, sal
.pspace
, frame_id
,
8315 inferior_thread ()->global_num
));
8317 b
->add_location (sal
);
8319 breakpoint_up
bp (add_to_breakpoint_chain (std::move (b
)));
8321 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8326 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8327 The new breakpoint will have type TYPE, use OPS as its
8328 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8330 static struct breakpoint
*
8331 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8336 std::unique_ptr
<breakpoint
> copy
8337 (new_momentary_breakpoint (orig
->gdbarch
, type
, orig
->pspace
,
8338 orig
->frame_id
, thread
));
8339 const bp_location
&orig_loc
= orig
->first_loc ();
8340 bp_location
*copy_loc
= copy
->allocate_location ();
8341 copy
->add_location (*copy_loc
);
8342 set_breakpoint_location_function (copy_loc
);
8344 copy_loc
->gdbarch
= orig_loc
.gdbarch
;
8345 copy_loc
->requested_address
= orig_loc
.requested_address
;
8346 copy_loc
->address
= orig_loc
.address
;
8347 copy_loc
->section
= orig_loc
.section
;
8348 copy_loc
->pspace
= orig_loc
.pspace
;
8349 copy_loc
->probe
= orig_loc
.probe
;
8350 copy_loc
->line_number
= orig_loc
.line_number
;
8351 copy_loc
->symtab
= orig_loc
.symtab
;
8352 copy_loc
->enabled
= loc_enabled
;
8354 breakpoint
*b
= add_to_breakpoint_chain (std::move (copy
));
8355 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8359 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8363 clone_momentary_breakpoint (struct breakpoint
*orig
)
8365 /* If there's nothing to clone, then return nothing. */
8369 return momentary_breakpoint_from_master (orig
, orig
->type
, 0,
8374 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8377 struct symtab_and_line sal
;
8379 sal
= find_pc_line (pc
, 0);
8381 sal
.section
= find_pc_overlay (pc
);
8382 sal
.explicit_pc
= 1;
8384 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8388 /* Tell the user we have just set a breakpoint B. */
8391 mention (const breakpoint
*b
)
8393 b
->print_mention ();
8394 current_uiout
->text ("\n");
8398 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8400 /* Handle "set breakpoint auto-hw on".
8402 If the explicitly specified breakpoint type is not hardware
8403 breakpoint, check the memory map to see whether the breakpoint
8404 address is in read-only memory.
8406 - location type is not hardware breakpoint, memory is read-only.
8407 We change the type of the location to hardware breakpoint.
8409 - location type is hardware breakpoint, memory is read-write. This
8410 means we've previously made the location hardware one, but then the
8411 memory map changed, so we undo.
8415 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8417 if (automatic_hardware_breakpoints
8418 && bl
->owner
->type
!= bp_hardware_breakpoint
8419 && (bl
->loc_type
== bp_loc_software_breakpoint
8420 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8422 /* When breakpoints are removed, remove_breakpoints will use
8423 location types we've just set here, the only possible problem
8424 is that memory map has changed during running program, but
8425 it's not going to work anyway with current gdb. */
8426 mem_region
*mr
= lookup_mem_region (bl
->address
);
8430 enum bp_loc_type new_type
;
8432 if (mr
->attrib
.mode
!= MEM_RW
)
8433 new_type
= bp_loc_hardware_breakpoint
;
8435 new_type
= bp_loc_software_breakpoint
;
8437 if (new_type
!= bl
->loc_type
)
8439 static bool said
= false;
8441 bl
->loc_type
= new_type
;
8444 gdb_printf (_("Note: automatically using "
8445 "hardware breakpoints for "
8446 "read-only addresses.\n"));
8455 code_breakpoint::add_location (const symtab_and_line
&sal
)
8457 CORE_ADDR adjusted_address
;
8458 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8460 if (loc_gdbarch
== NULL
)
8461 loc_gdbarch
= gdbarch
;
8463 /* Adjust the breakpoint's address prior to allocating a location.
8464 Once we call allocate_location(), that mostly uninitialized
8465 location will be placed on the location chain. Adjustment of the
8466 breakpoint may cause target_read_memory() to be called and we do
8467 not want its scan of the location chain to find a breakpoint and
8468 location that's only been partially initialized. */
8469 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8473 /* Sort the locations by their ADDRESS. */
8474 bp_location
*new_loc
= this->allocate_location ();
8476 new_loc
->requested_address
= sal
.pc
;
8477 new_loc
->address
= adjusted_address
;
8478 new_loc
->pspace
= sal
.pspace
;
8479 new_loc
->probe
.prob
= sal
.prob
;
8480 new_loc
->probe
.objfile
= sal
.objfile
;
8481 gdb_assert (new_loc
->pspace
!= NULL
);
8482 new_loc
->section
= sal
.section
;
8483 new_loc
->gdbarch
= loc_gdbarch
;
8484 new_loc
->line_number
= sal
.line
;
8485 new_loc
->symtab
= sal
.symtab
;
8486 new_loc
->symbol
= sal
.symbol
;
8487 new_loc
->msymbol
= sal
.msymbol
;
8488 new_loc
->objfile
= sal
.objfile
;
8490 breakpoint::add_location (*new_loc
);
8492 set_breakpoint_location_function (new_loc
);
8494 /* While by definition, permanent breakpoints are already present in the
8495 code, we don't mark the location as inserted. Normally one would expect
8496 that GDB could rely on that breakpoint instruction to stop the program,
8497 thus removing the need to insert its own breakpoint, except that executing
8498 the breakpoint instruction can kill the target instead of reporting a
8499 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8500 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8501 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8502 breakpoint be inserted normally results in QEMU knowing about the GDB
8503 breakpoint, and thus trap before the breakpoint instruction is executed.
8504 (If GDB later needs to continue execution past the permanent breakpoint,
8505 it manually increments the PC, thus avoiding executing the breakpoint
8507 if (bp_loc_is_permanent (new_loc
))
8508 new_loc
->permanent
= 1;
8514 /* Return true if LOC is pointing to a permanent breakpoint,
8515 return false otherwise. */
8518 bp_loc_is_permanent (struct bp_location
*loc
)
8520 gdb_assert (loc
!= NULL
);
8522 /* If we have a non-breakpoint-backed catchpoint or a software
8523 watchpoint, just return 0. We should not attempt to read from
8524 the addresses the locations of these breakpoint types point to.
8525 gdbarch_program_breakpoint_here_p, below, will attempt to read
8527 if (!bl_address_is_meaningful (loc
))
8530 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8531 switch_to_program_space_and_thread (loc
->pspace
);
8532 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8535 /* Build a command list for the dprintf corresponding to the current
8536 settings of the dprintf style options. */
8539 update_dprintf_command_list (struct breakpoint
*b
)
8541 const char *dprintf_args
= b
->extra_string
.get ();
8542 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8547 dprintf_args
= skip_spaces (dprintf_args
);
8549 /* Allow a comma, as it may have terminated a location, but don't
8551 if (*dprintf_args
== ',')
8553 dprintf_args
= skip_spaces (dprintf_args
);
8555 if (*dprintf_args
!= '"')
8556 error (_("Bad format string, missing '\"'."));
8558 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8559 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8560 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8562 if (dprintf_function
.empty ())
8563 error (_("No function supplied for dprintf call"));
8565 if (!dprintf_channel
.empty ())
8566 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8567 dprintf_function
.c_str (),
8568 dprintf_channel
.c_str (),
8571 printf_line
= xstrprintf ("call (void) %s (%s)",
8572 dprintf_function
.c_str (),
8575 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8577 if (target_can_run_breakpoint_commands ())
8578 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8581 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8582 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8586 internal_error (_("Invalid dprintf style."));
8588 gdb_assert (printf_line
!= NULL
);
8590 /* Manufacture a printf sequence. */
8591 struct command_line
*printf_cmd_line
8592 = new struct command_line (simple_control
, printf_line
.release ());
8593 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8594 command_lines_deleter ()));
8597 /* Update all dprintf commands, making their command lists reflect
8598 current style settings. */
8601 update_dprintf_commands (const char *args
, int from_tty
,
8602 struct cmd_list_element
*c
)
8604 for (breakpoint
&b
: all_breakpoints ())
8605 if (b
.type
== bp_dprintf
)
8606 update_dprintf_command_list (&b
);
8609 code_breakpoint::code_breakpoint (struct gdbarch
*gdbarch_
,
8611 gdb::array_view
<const symtab_and_line
> sals
,
8612 location_spec_up
&&locspec_
,
8613 gdb::unique_xmalloc_ptr
<char> filter_
,
8614 gdb::unique_xmalloc_ptr
<char> cond_string_
,
8615 gdb::unique_xmalloc_ptr
<char> extra_string_
,
8616 enum bpdisp disposition_
,
8617 int thread_
, int task_
, int inferior_
,
8620 int enabled_
, unsigned flags
,
8621 int display_canonical_
)
8622 : breakpoint (gdbarch_
, type_
)
8626 if (type
== bp_hardware_breakpoint
)
8628 int target_resources_ok
;
8630 i
= hw_breakpoint_used_count ();
8631 target_resources_ok
=
8632 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8634 if (target_resources_ok
== 0)
8635 error (_("No hardware breakpoint support in the target."));
8636 else if (target_resources_ok
< 0)
8637 error (_("Hardware breakpoints used exceeds limit."));
8640 gdb_assert (!sals
.empty ());
8642 /* At most one of thread, task, or inferior can be set on any breakpoint. */
8643 gdb_assert (((thread
== -1 ? 0 : 1)
8644 + (task
== -1 ? 0 : 1)
8645 + (inferior
== -1 ? 0 : 1)) <= 1);
8649 inferior
= inferior_
;
8651 cond_string
= std::move (cond_string_
);
8652 extra_string
= std::move (extra_string_
);
8653 ignore_count
= ignore_count_
;
8654 enable_state
= enabled_
? bp_enabled
: bp_disabled
;
8655 disposition
= disposition_
;
8657 if (type
== bp_static_tracepoint
8658 || type
== bp_static_marker_tracepoint
)
8660 auto *t
= gdb::checked_static_cast
<struct tracepoint
*> (this);
8661 struct static_tracepoint_marker marker
;
8663 if (strace_marker_p (this))
8665 /* We already know the marker exists, otherwise, we wouldn't
8666 see a sal for it. */
8667 const char *p
= &locspec_
->to_string ()[3];
8670 p
= skip_spaces (p
);
8672 endp
= skip_to_space (p
);
8674 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8676 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8677 t
->static_trace_marker_id
.c_str ());
8679 else if (target_static_tracepoint_marker_at (sals
[0].pc
, &marker
))
8681 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8683 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8684 t
->static_trace_marker_id
.c_str ());
8687 warning (_("Couldn't determine the static tracepoint marker to probe"));
8690 for (const auto &sal
: sals
)
8694 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8695 if (loc_gdbarch
== nullptr)
8696 loc_gdbarch
= gdbarch
;
8698 describe_other_breakpoints (loc_gdbarch
,
8699 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8702 bp_location
*new_loc
= add_location (sal
);
8703 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8704 new_loc
->inserted
= 1;
8706 /* Do not set breakpoint locations conditions yet. As locations
8707 are inserted, they get sorted based on their addresses. Let
8708 the list stabilize to have reliable location numbers. */
8710 /* Dynamic printf requires and uses additional arguments on the
8711 command line, otherwise it's an error. */
8712 if (type
== bp_dprintf
)
8714 if (extra_string
!= nullptr)
8715 update_dprintf_command_list (this);
8717 error (_("Format string required"));
8719 else if (extra_string
!= nullptr)
8720 error (_("Garbage '%s' at end of command"), extra_string
.get ());
8723 /* The order of the locations is now stable. Set the location
8724 condition using the location's number. */
8726 for (bp_location
&bl
: locations ())
8728 if (cond_string
!= nullptr)
8729 set_breakpoint_location_condition (cond_string
.get (), &bl
,
8735 display_canonical
= display_canonical_
;
8736 if (locspec_
!= nullptr)
8737 locspec
= std::move (locspec_
);
8739 locspec
= new_address_location_spec (this->first_loc ().address
, NULL
, 0);
8740 filter
= std::move (filter_
);
8744 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8745 gdb::array_view
<const symtab_and_line
> sals
,
8746 location_spec_up
&&locspec
,
8747 gdb::unique_xmalloc_ptr
<char> filter
,
8748 gdb::unique_xmalloc_ptr
<char> cond_string
,
8749 gdb::unique_xmalloc_ptr
<char> extra_string
,
8750 enum bptype type
, enum bpdisp disposition
,
8751 int thread
, int task
, int inferior
, int ignore_count
,
8753 int enabled
, int internal
, unsigned flags
,
8754 int display_canonical
)
8756 std::unique_ptr
<code_breakpoint
> b
8757 = new_breakpoint_from_type (gdbarch
,
8760 std::move (locspec
),
8762 std::move (cond_string
),
8763 std::move (extra_string
),
8765 thread
, task
, inferior
, ignore_count
,
8770 install_breakpoint (internal
, std::move (b
), 0);
8773 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8774 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8775 value. COND_STRING, if not NULL, specified the condition to be
8776 used for all breakpoints. Essentially the only case where
8777 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8778 function. In that case, it's still not possible to specify
8779 separate conditions for different overloaded functions, so
8780 we take just a single condition string.
8782 NOTE: If the function succeeds, the caller is expected to cleanup
8783 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8784 array contents). If the function fails (error() is called), the
8785 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8786 COND and SALS arrays and each of those arrays contents. */
8789 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8790 struct linespec_result
*canonical
,
8791 gdb::unique_xmalloc_ptr
<char> cond_string
,
8792 gdb::unique_xmalloc_ptr
<char> extra_string
,
8793 enum bptype type
, enum bpdisp disposition
,
8794 int thread
, int task
, int inferior
,
8797 int enabled
, int internal
, unsigned flags
)
8799 if (canonical
->pre_expanded
)
8800 gdb_assert (canonical
->lsals
.size () == 1);
8802 for (const auto &lsal
: canonical
->lsals
)
8804 /* Note that 'location' can be NULL in the case of a plain
8805 'break', without arguments. */
8806 location_spec_up locspec
8807 = (canonical
->locspec
!= nullptr
8808 ? canonical
->locspec
->clone ()
8810 gdb::unique_xmalloc_ptr
<char> filter_string
8811 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8813 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8814 std::move (locspec
),
8815 std::move (filter_string
),
8816 std::move (cond_string
),
8817 std::move (extra_string
),
8819 thread
, task
, inferior
, ignore_count
,
8820 from_tty
, enabled
, internal
, flags
,
8821 canonical
->special_display
);
8825 /* Parse LOCSPEC which is assumed to be a SAL specification possibly
8826 followed by conditionals. On return, SALS contains an array of SAL
8827 addresses found. LOCSPEC points to the end of the SAL (for
8830 The array and the line spec strings are allocated on the heap, it is
8831 the caller's responsibility to free them. */
8834 parse_breakpoint_sals (location_spec
*locspec
,
8835 struct linespec_result
*canonical
)
8837 struct symtab_and_line cursal
;
8839 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8841 const char *spec
= as_linespec_location_spec (locspec
)->spec_string
;
8845 /* The last displayed codepoint, if it's valid, is our default
8846 breakpoint address. */
8847 if (last_displayed_sal_is_valid ())
8849 /* Set sal's pspace, pc, symtab, and line to the values
8850 corresponding to the last call to print_frame_info.
8851 Be sure to reinitialize LINE with NOTCURRENT == 0
8852 as the breakpoint line number is inappropriate otherwise.
8853 find_pc_line would adjust PC, re-set it back. */
8854 symtab_and_line sal
= get_last_displayed_sal ();
8855 CORE_ADDR pc
= sal
.pc
;
8857 sal
= find_pc_line (pc
, 0);
8859 /* "break" without arguments is equivalent to "break *PC"
8860 where PC is the last displayed codepoint's address. So
8861 make sure to set sal.explicit_pc to prevent GDB from
8862 trying to expand the list of sals to include all other
8863 instances with the same symtab and line. */
8865 sal
.explicit_pc
= 1;
8867 struct linespec_sals lsal
;
8869 lsal
.canonical
= NULL
;
8871 canonical
->lsals
.push_back (std::move (lsal
));
8875 error (_("No default breakpoint address now."));
8879 /* Force almost all breakpoints to be in terms of the
8880 current_source_symtab (which is decode_line_1's default).
8881 This should produce the results we want almost all of the
8882 time while leaving default_breakpoint_* alone.
8884 ObjC: However, don't match an Objective-C method name which
8885 may have a '+' or '-' succeeded by a '['. */
8886 cursal
= get_current_source_symtab_and_line ();
8887 if (last_displayed_sal_is_valid ())
8889 const char *spec
= NULL
;
8891 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8892 spec
= as_linespec_location_spec (locspec
)->spec_string
;
8896 && strchr ("+-", spec
[0]) != NULL
8899 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8900 get_last_displayed_symtab (),
8901 get_last_displayed_line (),
8902 canonical
, NULL
, NULL
);
8907 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8908 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8912 /* Convert each SAL into a real PC. Verify that the PC can be
8913 inserted as a breakpoint. If it can't throw an error. */
8916 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8918 for (auto &sal
: sals
)
8919 resolve_sal_pc (&sal
);
8922 /* Fast tracepoints may have restrictions on valid locations. For
8923 instance, a fast tracepoint using a jump instead of a trap will
8924 likely have to overwrite more bytes than a trap would, and so can
8925 only be placed where the instruction is longer than the jump, or a
8926 multi-instruction sequence does not have a jump into the middle of
8930 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8931 gdb::array_view
<const symtab_and_line
> sals
)
8933 for (const auto &sal
: sals
)
8935 struct gdbarch
*sarch
;
8937 sarch
= get_sal_arch (sal
);
8938 /* We fall back to GDBARCH if there is no architecture
8939 associated with SAL. */
8943 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8944 error (_("May not have a fast tracepoint at %s%s"),
8945 paddress (sarch
, sal
.pc
), msg
.c_str ());
8949 /* Given TOK, a string specification of condition and thread, as accepted
8950 by the 'break' command, extract the condition string into *COND_STRING.
8951 If no condition string is found then *COND_STRING is set to nullptr.
8953 If the breakpoint specification has an associated thread, task, or
8954 inferior, these are extracted into *THREAD, *TASK, and *INFERIOR
8955 respectively, otherwise these arguments are set to -1 (for THREAD and
8956 INFERIOR) or 0 (for TASK).
8958 PC identifies the context at which the condition should be parsed. */
8961 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8962 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8963 int *thread
, int *inferior
, int *task
,
8964 gdb::unique_xmalloc_ptr
<char> *rest
)
8966 cond_string
->reset ();
8975 const char *end_tok
;
8977 const char *cond_start
= NULL
;
8978 const char *cond_end
= NULL
;
8980 tok
= skip_spaces (tok
);
8982 if ((*tok
== '"' || *tok
== ',') && rest
)
8984 rest
->reset (savestring (tok
, strlen (tok
)));
8988 end_tok
= skip_to_space (tok
);
8990 toklen
= end_tok
- tok
;
8992 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8994 tok
= cond_start
= end_tok
+ 1;
8997 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8999 catch (const gdb_exception_error
&)
9004 tok
= tok
+ strlen (tok
);
9007 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
9009 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9014 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9017 struct thread_info
*thr
;
9020 error(_("You can specify only one thread."));
9023 error (_("You can specify only one of thread or task."));
9025 if (*inferior
!= -1)
9026 error (_("You can specify only one of inferior or thread."));
9029 thr
= parse_thread_id (tok
, &tmptok
);
9031 error (_("Junk after thread keyword."));
9032 *thread
= thr
->global_num
;
9035 else if (toklen
>= 1 && strncmp (tok
, "inferior", toklen
) == 0)
9037 if (*inferior
!= -1)
9038 error(_("You can specify only one inferior."));
9041 error (_("You can specify only one of inferior or task."));
9044 error (_("You can specify only one of inferior or thread."));
9048 *inferior
= strtol (tok
, &tmptok
, 0);
9050 error (_("Junk after inferior keyword."));
9051 if (!valid_global_inferior_id (*inferior
))
9052 error (_("Unknown inferior number %d."), *inferior
);
9055 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9060 error(_("You can specify only one task."));
9063 error (_("You can specify only one of thread or task."));
9065 if (*inferior
!= -1)
9066 error (_("You can specify only one of inferior or task."));
9069 *task
= strtol (tok
, &tmptok
, 0);
9071 error (_("Junk after task keyword."));
9072 if (!valid_task_id (*task
))
9073 error (_("Unknown task %d."), *task
);
9078 rest
->reset (savestring (tok
, strlen (tok
)));
9082 error (_("Junk at end of arguments."));
9086 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9087 succeeds. The parsed values are written to COND_STRING, THREAD,
9088 TASK, and REST. See the comment of 'find_condition_and_thread'
9089 for the description of these parameters and INPUT. */
9092 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9094 gdb::unique_xmalloc_ptr
<char> *cond_string
,
9095 int *thread
, int *inferior
, int *task
,
9096 gdb::unique_xmalloc_ptr
<char> *rest
)
9098 int num_failures
= 0;
9099 for (auto &sal
: sals
)
9101 gdb::unique_xmalloc_ptr
<char> cond
;
9103 int inferior_id
= -1;
9105 gdb::unique_xmalloc_ptr
<char> remaining
;
9107 /* Here we want to parse 'arg' to separate condition from thread
9108 number. But because parsing happens in a context and the
9109 contexts of sals might be different, try each until there is
9110 success. Finding one successful parse is sufficient for our
9111 goal. When setting the breakpoint we'll re-parse the
9112 condition in the context of each sal. */
9115 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9116 &inferior_id
, &task_id
, &remaining
);
9117 *cond_string
= std::move (cond
);
9118 /* A value of -1 indicates that these fields are unset. At most
9119 one of these fields should be set (to a value other than -1)
9121 gdb_assert (((thread_id
== -1 ? 1 : 0)
9122 + (task_id
== -1 ? 1 : 0)
9123 + (inferior_id
== -1 ? 1 : 0)) >= 2);
9124 *thread
= thread_id
;
9125 *inferior
= inferior_id
;
9127 *rest
= std::move (remaining
);
9130 catch (const gdb_exception_error
&e
)
9133 /* If no sal remains, do not continue. */
9134 if (num_failures
== sals
.size ())
9140 /* Decode a static tracepoint marker spec. */
9142 static std::vector
<symtab_and_line
>
9143 decode_static_tracepoint_spec (const char **arg_p
)
9145 const char *p
= &(*arg_p
)[3];
9148 p
= skip_spaces (p
);
9150 endp
= skip_to_space (p
);
9152 std::string
marker_str (p
, endp
- p
);
9154 std::vector
<static_tracepoint_marker
> markers
9155 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9156 if (markers
.empty ())
9157 error (_("No known static tracepoint marker named %s"),
9158 marker_str
.c_str ());
9160 std::vector
<symtab_and_line
> sals
;
9161 sals
.reserve (markers
.size ());
9163 for (const static_tracepoint_marker
&marker
: markers
)
9165 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9166 sal
.pc
= marker
.address
;
9167 sals
.push_back (sal
);
9174 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9175 according to IS_TRACEPOINT. */
9177 static const struct breakpoint_ops
*
9178 breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type
,
9183 if (locspec_type
== PROBE_LOCATION_SPEC
)
9184 return &tracepoint_probe_breakpoint_ops
;
9186 return &code_breakpoint_ops
;
9190 if (locspec_type
== PROBE_LOCATION_SPEC
)
9191 return &bkpt_probe_breakpoint_ops
;
9193 return &code_breakpoint_ops
;
9197 /* See breakpoint.h. */
9199 const struct breakpoint_ops
*
9200 breakpoint_ops_for_location_spec (const location_spec
*locspec
,
9203 if (locspec
!= nullptr)
9204 return (breakpoint_ops_for_location_spec_type
9205 (locspec
->type (), is_tracepoint
));
9206 return &code_breakpoint_ops
;
9209 /* See breakpoint.h. */
9212 create_breakpoint (struct gdbarch
*gdbarch
,
9213 location_spec
*locspec
,
9214 const char *cond_string
,
9215 int thread
, int inferior
,
9216 const char *extra_string
,
9217 bool force_condition
, int parse_extra
,
9218 int tempflag
, enum bptype type_wanted
,
9220 enum auto_boolean pending_break_support
,
9221 const struct breakpoint_ops
*ops
,
9222 int from_tty
, int enabled
, int internal
,
9225 struct linespec_result canonical
;
9226 bool pending
= false;
9228 int prev_bkpt_count
= breakpoint_count
;
9230 gdb_assert (thread
== -1 || thread
> 0);
9231 gdb_assert (inferior
== -1 || inferior
> 0);
9232 gdb_assert (thread
== -1 || inferior
== -1);
9234 gdb_assert (ops
!= NULL
);
9236 /* If extra_string isn't useful, set it to NULL. */
9237 if (extra_string
!= NULL
&& *extra_string
== '\0')
9238 extra_string
= NULL
;
9242 ops
->create_sals_from_location_spec (locspec
, &canonical
);
9244 catch (const gdb_exception_error
&e
)
9246 /* If caller is interested in rc value from parse, set
9248 if (e
.error
== NOT_FOUND_ERROR
)
9250 /* If pending breakpoint support is turned off, throw
9253 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9256 exception_print (gdb_stderr
, e
);
9258 /* If pending breakpoint support is auto query and the user
9259 selects no, then simply return the error code. */
9260 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9261 && !nquery (_("Make %s pending on future shared library load? "),
9262 bptype_string (type_wanted
)))
9265 /* At this point, either the user was queried about setting
9266 a pending breakpoint and selected yes, or pending
9267 breakpoint behavior is on and thus a pending breakpoint
9268 is defaulted on behalf of the user. */
9275 if (!pending
&& canonical
.lsals
.empty ())
9278 /* Resolve all line numbers to PC's and verify that the addresses
9279 are ok for the target. */
9282 for (auto &lsal
: canonical
.lsals
)
9283 breakpoint_sals_to_pc (lsal
.sals
);
9286 /* Fast tracepoints may have additional restrictions on location. */
9287 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9289 for (const auto &lsal
: canonical
.lsals
)
9290 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9293 /* Verify that condition can be parsed, before setting any
9294 breakpoints. Allocate a separate condition expression for each
9298 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9299 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9303 gdb::unique_xmalloc_ptr
<char> rest
;
9304 gdb::unique_xmalloc_ptr
<char> cond
;
9306 const linespec_sals
&lsal
= canonical
.lsals
[0];
9308 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9309 &cond
, &thread
, &inferior
,
9311 cond_string_copy
= std::move (cond
);
9312 extra_string_copy
= std::move (rest
);
9316 if (type_wanted
!= bp_dprintf
9317 && extra_string
!= NULL
&& *extra_string
!= '\0')
9318 error (_("Garbage '%s' at end of location"), extra_string
);
9320 /* Check the validity of the condition. We should error out
9321 if the condition is invalid at all of the locations and
9322 if it is not forced. In the PARSE_EXTRA case above, this
9323 check is done when parsing the EXTRA_STRING. */
9324 if (cond_string
!= nullptr && !force_condition
)
9326 int num_failures
= 0;
9327 const linespec_sals
&lsal
= canonical
.lsals
[0];
9328 for (const auto &sal
: lsal
.sals
)
9330 const char *cond
= cond_string
;
9333 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9334 /* One success is sufficient to keep going. */
9337 catch (const gdb_exception_error
&)
9340 /* If this is the last sal, error out. */
9341 if (num_failures
== lsal
.sals
.size ())
9347 /* Create a private copy of condition string. */
9349 cond_string_copy
.reset (xstrdup (cond_string
));
9350 /* Create a private copy of any extra string. */
9352 extra_string_copy
.reset (xstrdup (extra_string
));
9355 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9356 std::move (cond_string_copy
),
9357 std::move (extra_string_copy
),
9359 tempflag
? disp_del
: disp_donttouch
,
9360 thread
, task
, inferior
, ignore_count
,
9361 from_tty
, enabled
, internal
, flags
);
9365 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
,
9367 b
->locspec
= locspec
->clone ();
9370 b
->cond_string
= NULL
;
9373 /* Create a private copy of condition string. */
9374 b
->cond_string
.reset (cond_string
!= NULL
9375 ? xstrdup (cond_string
)
9380 /* Create a private copy of any extra string. */
9381 b
->extra_string
.reset (extra_string
!= NULL
9382 ? xstrdup (extra_string
)
9384 b
->ignore_count
= ignore_count
;
9385 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9386 b
->condition_not_parsed
= 1;
9387 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9388 if ((type_wanted
!= bp_breakpoint
9389 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9390 b
->pspace
= current_program_space
;
9392 install_breakpoint (internal
, std::move (b
), 0);
9395 if (canonical
.lsals
.size () > 1)
9397 warning (_("Multiple breakpoints were set.\nUse the "
9398 "\"delete\" command to delete unwanted breakpoints."));
9399 prev_breakpoint_count
= prev_bkpt_count
;
9402 update_global_location_list (UGLL_MAY_INSERT
);
9407 /* Set a breakpoint.
9408 ARG is a string describing breakpoint address,
9409 condition, and thread.
9410 FLAG specifies if a breakpoint is hardware on,
9411 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9415 break_command_1 (const char *arg
, int flag
, int from_tty
)
9417 int tempflag
= flag
& BP_TEMPFLAG
;
9418 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9419 ? bp_hardware_breakpoint
9422 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9423 const struct breakpoint_ops
*ops
9424 = breakpoint_ops_for_location_spec (locspec
.get (),
9425 false /* is_tracepoint */);
9427 create_breakpoint (get_current_arch (),
9430 -1 /* thread */, -1 /* inferior */,
9431 arg
, false, 1 /* parse arg */,
9432 tempflag
, type_wanted
,
9433 0 /* Ignore count */,
9434 pending_break_support
,
9442 /* Helper function for break_command_1 and disassemble_command. */
9445 resolve_sal_pc (struct symtab_and_line
*sal
)
9449 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9451 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9452 error (_("No line %d in file \"%s\"."),
9453 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9456 /* If this SAL corresponds to a breakpoint inserted using a line
9457 number, then skip the function prologue if necessary. */
9458 if (sal
->explicit_line
)
9459 skip_prologue_sal (sal
);
9462 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9464 const struct blockvector
*bv
;
9465 const struct block
*b
;
9468 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9469 sal
->symtab
->compunit ());
9472 sym
= b
->linkage_function ();
9475 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9478 /* It really is worthwhile to have the section, so we'll
9479 just have to look harder. This case can be executed
9480 if we have line numbers but no functions (as can
9481 happen in assembly source). */
9483 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9484 switch_to_program_space_and_thread (sal
->pspace
);
9486 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9488 sal
->section
= msym
.obj_section ();
9495 break_command (const char *arg
, int from_tty
)
9497 break_command_1 (arg
, 0, from_tty
);
9501 tbreak_command (const char *arg
, int from_tty
)
9503 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9507 hbreak_command (const char *arg
, int from_tty
)
9509 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9513 thbreak_command (const char *arg
, int from_tty
)
9515 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9518 /* The dynamic printf command is mostly like a regular breakpoint, but
9519 with a prewired command list consisting of a single output command,
9520 built from extra arguments supplied on the dprintf command
9524 dprintf_command (const char *arg
, int from_tty
)
9526 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9528 /* If non-NULL, ARG should have been advanced past the location;
9529 the next character must be ','. */
9532 if (arg
[0] != ',' || arg
[1] == '\0')
9533 error (_("Format string required"));
9536 /* Skip the comma. */
9541 create_breakpoint (get_current_arch (),
9544 arg
, false, 1 /* parse arg */,
9546 0 /* Ignore count */,
9547 pending_break_support
,
9548 &code_breakpoint_ops
,
9556 agent_printf_command (const char *arg
, int from_tty
)
9558 error (_("May only run agent-printf on the target"));
9561 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9564 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9565 const address_space
*aspace
,
9567 const target_waitstatus
&ws
)
9569 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9570 || ws
.sig () != GDB_SIGNAL_TRAP
)
9573 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9574 bl
->length
, aspace
, bp_addr
);
9577 /* Implement the "resources_needed" method for ranged breakpoints. */
9580 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9582 return target_ranged_break_num_registers ();
9585 /* Implement the "print_it" method for ranged breakpoints. */
9587 enum print_stop_action
9588 ranged_breakpoint::print_it (const bpstat
*bs
) const
9590 struct ui_out
*uiout
= current_uiout
;
9592 gdb_assert (type
== bp_hardware_breakpoint
);
9594 /* Ranged breakpoints have only one location. */
9595 gdb_assert (this->has_single_location ());
9597 annotate_breakpoint (number
);
9599 maybe_print_thread_hit_breakpoint (uiout
);
9601 if (disposition
== disp_del
)
9602 uiout
->text ("Temporary ranged breakpoint ");
9604 uiout
->text ("Ranged breakpoint ");
9605 if (uiout
->is_mi_like_p ())
9607 uiout
->field_string ("reason",
9608 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9609 uiout
->field_string ("disp", bpdisp_text (disposition
));
9611 print_num_locno (bs
, uiout
);
9614 return PRINT_SRC_AND_LOC
;
9617 /* Implement the "print_one" method for ranged breakpoints. */
9620 ranged_breakpoint::print_one (const bp_location
**last_loc
) const
9622 struct value_print_options opts
;
9623 struct ui_out
*uiout
= current_uiout
;
9625 /* Ranged breakpoints have only one location. */
9626 gdb_assert (this->has_single_location ());
9628 get_user_print_options (&opts
);
9630 if (opts
.addressprint
)
9631 /* We don't print the address range here, it will be printed later
9632 by ranged_breakpoint::print_one_detail. */
9633 uiout
->field_skip ("addr");
9635 print_breakpoint_location (this, &this->first_loc ());
9636 *last_loc
= &this->first_loc ();
9641 /* Implement the "print_one_detail" method for ranged breakpoints. */
9644 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9646 CORE_ADDR address_start
, address_end
;
9647 const bp_location
&bl
= this->first_loc ();
9650 address_start
= bl
.address
;
9651 address_end
= address_start
+ bl
.length
- 1;
9653 uiout
->text ("\taddress range: ");
9654 stb
.printf ("[%s, %s]",
9655 print_core_address (bl
.gdbarch
, address_start
),
9656 print_core_address (bl
.gdbarch
, address_end
));
9657 uiout
->field_stream ("addr", stb
);
9661 /* Implement the "print_mention" method for ranged breakpoints. */
9664 ranged_breakpoint::print_mention () const
9666 const bp_location
&bl
= this->first_loc ();
9667 struct ui_out
*uiout
= current_uiout
;
9669 gdb_assert (type
== bp_hardware_breakpoint
);
9671 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9672 number
, paddress (bl
.gdbarch
, bl
.address
),
9673 paddress (bl
.gdbarch
, bl
.address
+ bl
.length
- 1));
9676 /* Implement the "print_recreate" method for ranged breakpoints. */
9679 ranged_breakpoint::print_recreate (struct ui_file
*fp
) const
9681 gdb_printf (fp
, "break-range %s, %s",
9682 locspec
->to_string (),
9683 locspec_range_end
->to_string ());
9684 print_recreate_thread (fp
);
9687 /* Find the address where the end of the breakpoint range should be
9688 placed, given the SAL of the end of the range. This is so that if
9689 the user provides a line number, the end of the range is set to the
9690 last instruction of the given line. */
9693 find_breakpoint_range_end (struct symtab_and_line sal
)
9697 /* If the user provided a PC value, use it. Otherwise,
9698 find the address of the end of the given location. */
9699 if (sal
.explicit_pc
)
9706 ret
= find_line_pc_range (sal
, &start
, &end
);
9708 error (_("Could not find location of the end of the range."));
9710 /* find_line_pc_range returns the start of the next line. */
9717 /* Implement the "break-range" CLI command. */
9720 break_range_command (const char *arg
, int from_tty
)
9722 const char *arg_start
;
9723 struct linespec_result canonical_start
, canonical_end
;
9724 int bp_count
, can_use_bp
, length
;
9727 /* We don't support software ranged breakpoints. */
9728 if (target_ranged_break_num_registers () < 0)
9729 error (_("This target does not support hardware ranged breakpoints."));
9731 bp_count
= hw_breakpoint_used_count ();
9732 bp_count
+= target_ranged_break_num_registers ();
9733 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9736 error (_("Hardware breakpoints used exceeds limit."));
9738 arg
= skip_spaces (arg
);
9739 if (arg
== NULL
|| arg
[0] == '\0')
9740 error(_("No address range specified."));
9743 location_spec_up start_locspec
9744 = string_to_location_spec (&arg
, current_language
);
9745 parse_breakpoint_sals (start_locspec
.get (), &canonical_start
);
9748 error (_("Too few arguments."));
9749 else if (canonical_start
.lsals
.empty ())
9750 error (_("Could not find location of the beginning of the range."));
9752 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9754 if (canonical_start
.lsals
.size () > 1
9755 || lsal_start
.sals
.size () != 1)
9756 error (_("Cannot create a ranged breakpoint with multiple locations."));
9758 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9759 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9761 arg
++; /* Skip the comma. */
9762 arg
= skip_spaces (arg
);
9764 /* Parse the end location specification. */
9768 /* We call decode_line_full directly here instead of using
9769 parse_breakpoint_sals because we need to specify the start
9770 location spec's symtab and line as the default symtab and line
9771 for the end of the range. This makes it possible to have ranges
9772 like "foo.c:27, +14", where +14 means 14 lines from the start
9774 location_spec_up end_locspec
9775 = string_to_location_spec (&arg
, current_language
);
9776 decode_line_full (end_locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9777 sal_start
.symtab
, sal_start
.line
,
9778 &canonical_end
, NULL
, NULL
);
9780 if (canonical_end
.lsals
.empty ())
9781 error (_("Could not find location of the end of the range."));
9783 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9784 if (canonical_end
.lsals
.size () > 1
9785 || lsal_end
.sals
.size () != 1)
9786 error (_("Cannot create a ranged breakpoint with multiple locations."));
9788 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9790 end
= find_breakpoint_range_end (sal_end
);
9791 if (sal_start
.pc
> end
)
9792 error (_("Invalid address range, end precedes start."));
9794 length
= end
- sal_start
.pc
+ 1;
9796 /* Length overflowed. */
9797 error (_("Address range too large."));
9798 else if (length
== 1)
9800 /* This range is simple enough to be handled by
9801 the `hbreak' command. */
9802 hbreak_command (&addr_string_start
[0], 1);
9807 /* Now set up the breakpoint and install it. */
9809 std::unique_ptr
<breakpoint
> br
9810 (new ranged_breakpoint (get_current_arch (),
9812 std::move (start_locspec
),
9813 std::move (end_locspec
)));
9815 install_breakpoint (false, std::move (br
), true);
9818 /* Return non-zero if EXP is verified as constant. Returned zero
9819 means EXP is variable. Also the constant detection may fail for
9820 some constant expressions and in such case still falsely return
9824 watchpoint_exp_is_const (const struct expression
*exp
)
9826 return exp
->op
->constant_p ();
9829 /* Implement the "re_set" method for watchpoints. */
9832 watchpoint::re_set ()
9834 /* Watchpoint can be either on expression using entirely global
9835 variables, or it can be on local variables.
9837 Watchpoints of the first kind are never auto-deleted, and even
9838 persist across program restarts. Since they can use variables
9839 from shared libraries, we need to reparse expression as libraries
9840 are loaded and unloaded.
9842 Watchpoints on local variables can also change meaning as result
9843 of solib event. For example, if a watchpoint uses both a local
9844 and a global variables in expression, it's a local watchpoint,
9845 but unloading of a shared library will make the expression
9846 invalid. This is not a very common use case, but we still
9847 re-evaluate expression, to avoid surprises to the user.
9849 Note that for local watchpoints, we re-evaluate it only if
9850 watchpoints frame id is still valid. If it's not, it means the
9851 watchpoint is out of scope and will be deleted soon. In fact,
9852 I'm not sure we'll ever be called in this case.
9854 If a local watchpoint's frame id is still valid, then
9855 exp_valid_block is likewise valid, and we can safely use it.
9857 Don't do anything about disabled watchpoints, since they will be
9858 reevaluated again when enabled. */
9859 update_watchpoint (this, true /* reparse */);
9862 /* Implement the "insert" method for hardware watchpoints. */
9865 watchpoint::insert_location (struct bp_location
*bl
)
9867 int length
= exact
? 1 : bl
->length
;
9869 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9873 /* Implement the "remove" method for hardware watchpoints. */
9876 watchpoint::remove_location (struct bp_location
*bl
,
9877 enum remove_bp_reason reason
)
9879 int length
= exact
? 1 : bl
->length
;
9881 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9886 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9887 const address_space
*aspace
, CORE_ADDR bp_addr
,
9888 const target_waitstatus
&ws
)
9890 struct breakpoint
*b
= bl
->owner
;
9892 /* Continuable hardware watchpoints are treated as non-existent if the
9893 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9894 some data address). Otherwise gdb won't stop on a break instruction
9895 in the code (not from a breakpoint) when a hardware watchpoint has
9896 been defined. Also skip watchpoints which we know did not trigger
9897 (did not match the data address). */
9898 if (is_hardware_watchpoint (b
)
9899 && watchpoint_triggered
== watch_triggered_no
)
9906 watchpoint::check_status (bpstat
*bs
)
9908 bpstat_check_watchpoint (bs
);
9911 /* Implement the "resources_needed" method for hardware
9915 watchpoint::resources_needed (const struct bp_location
*bl
)
9917 int length
= exact
? 1 : bl
->length
;
9919 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9922 /* Implement the "works_in_software_mode" method for hardware
9926 watchpoint::works_in_software_mode () const
9928 /* Read and access watchpoints only work with hardware support. */
9929 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9932 enum print_stop_action
9933 watchpoint::print_it (const bpstat
*bs
) const
9935 enum print_stop_action result
;
9936 struct ui_out
*uiout
= current_uiout
;
9938 gdb_assert (bs
->bp_location_at
!= NULL
);
9940 annotate_watchpoint (this->number
);
9941 maybe_print_thread_hit_breakpoint (uiout
);
9945 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9949 case bp_hardware_watchpoint
:
9950 if (uiout
->is_mi_like_p ())
9952 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9954 tuple_emitter
.emplace (uiout
, "value");
9955 uiout
->text ("\nOld value = ");
9956 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9957 uiout
->field_stream ("old", stb
);
9958 uiout
->text ("\nNew value = ");
9959 watchpoint_value_print (val
.get (), &stb
);
9960 uiout
->field_stream ("new", stb
);
9962 /* More than one watchpoint may have been triggered. */
9963 result
= PRINT_UNKNOWN
;
9966 case bp_read_watchpoint
:
9967 if (uiout
->is_mi_like_p ())
9969 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9971 tuple_emitter
.emplace (uiout
, "value");
9972 uiout
->text ("\nValue = ");
9973 watchpoint_value_print (val
.get (), &stb
);
9974 uiout
->field_stream ("value", stb
);
9976 result
= PRINT_UNKNOWN
;
9979 case bp_access_watchpoint
:
9980 if (bs
->old_val
!= NULL
)
9982 if (uiout
->is_mi_like_p ())
9985 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9987 tuple_emitter
.emplace (uiout
, "value");
9988 uiout
->text ("\nOld value = ");
9989 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9990 uiout
->field_stream ("old", stb
);
9991 uiout
->text ("\nNew value = ");
9996 if (uiout
->is_mi_like_p ())
9999 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10000 tuple_emitter
.emplace (uiout
, "value");
10001 uiout
->text ("\nValue = ");
10003 watchpoint_value_print (val
.get (), &stb
);
10004 uiout
->field_stream ("new", stb
);
10005 uiout
->text ("\n");
10006 result
= PRINT_UNKNOWN
;
10009 result
= PRINT_UNKNOWN
;
10015 /* Implement the "print_mention" method for hardware watchpoints. */
10018 watchpoint::print_mention () const
10020 struct ui_out
*uiout
= current_uiout
;
10021 const char *tuple_name
;
10025 case bp_watchpoint
:
10026 uiout
->text ("Watchpoint ");
10027 tuple_name
= "wpt";
10029 case bp_hardware_watchpoint
:
10030 uiout
->text ("Hardware watchpoint ");
10031 tuple_name
= "wpt";
10033 case bp_read_watchpoint
:
10034 uiout
->text ("Hardware read watchpoint ");
10035 tuple_name
= "hw-rwpt";
10037 case bp_access_watchpoint
:
10038 uiout
->text ("Hardware access (read/write) watchpoint ");
10039 tuple_name
= "hw-awpt";
10042 internal_error (_("Invalid hardware watchpoint type."));
10045 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10046 uiout
->field_signed ("number", number
);
10047 uiout
->text (": ");
10048 uiout
->field_string ("exp", exp_string
.get ());
10051 /* Implement the "print_recreate" method for watchpoints. */
10054 watchpoint::print_recreate (struct ui_file
*fp
) const
10058 case bp_watchpoint
:
10059 case bp_hardware_watchpoint
:
10060 gdb_printf (fp
, "watch");
10062 case bp_read_watchpoint
:
10063 gdb_printf (fp
, "rwatch");
10065 case bp_access_watchpoint
:
10066 gdb_printf (fp
, "awatch");
10069 internal_error (_("Invalid watchpoint type."));
10072 gdb_printf (fp
, " %s", exp_string
.get ());
10073 print_recreate_thread (fp
);
10076 /* Implement the "explains_signal" method for watchpoints. */
10079 watchpoint::explains_signal (enum gdb_signal sig
)
10081 /* A software watchpoint cannot cause a signal other than
10082 GDB_SIGNAL_TRAP. */
10083 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10089 struct masked_watchpoint
: public watchpoint
10091 using watchpoint::watchpoint
;
10093 int insert_location (struct bp_location
*) override
;
10094 int remove_location (struct bp_location
*,
10095 enum remove_bp_reason reason
) override
;
10096 int resources_needed (const struct bp_location
*) override
;
10097 bool works_in_software_mode () const override
;
10098 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
10099 void print_one_detail (struct ui_out
*) const override
;
10100 void print_mention () const override
;
10101 void print_recreate (struct ui_file
*fp
) const override
;
10104 /* Implement the "insert" method for masked hardware watchpoints. */
10107 masked_watchpoint::insert_location (struct bp_location
*bl
)
10109 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
10110 bl
->watchpoint_type
);
10113 /* Implement the "remove" method for masked hardware watchpoints. */
10116 masked_watchpoint::remove_location (struct bp_location
*bl
,
10117 enum remove_bp_reason reason
)
10119 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
10120 bl
->watchpoint_type
);
10123 /* Implement the "resources_needed" method for masked hardware
10127 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
10129 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
10132 /* Implement the "works_in_software_mode" method for masked hardware
10136 masked_watchpoint::works_in_software_mode () const
10141 /* Implement the "print_it" method for masked hardware
10144 enum print_stop_action
10145 masked_watchpoint::print_it (const bpstat
*bs
) const
10147 struct ui_out
*uiout
= current_uiout
;
10149 /* Masked watchpoints have only one location. */
10150 gdb_assert (this->has_single_location ());
10152 annotate_watchpoint (this->number
);
10153 maybe_print_thread_hit_breakpoint (uiout
);
10155 switch (this->type
)
10157 case bp_hardware_watchpoint
:
10158 if (uiout
->is_mi_like_p ())
10159 uiout
->field_string
10160 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10163 case bp_read_watchpoint
:
10164 if (uiout
->is_mi_like_p ())
10165 uiout
->field_string
10166 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10169 case bp_access_watchpoint
:
10170 if (uiout
->is_mi_like_p ())
10171 uiout
->field_string
10173 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10176 internal_error (_("Invalid hardware watchpoint type."));
10180 uiout
->text (_("\n\
10181 Check the underlying instruction at PC for the memory\n\
10182 address and value which triggered this watchpoint.\n"));
10183 uiout
->text ("\n");
10185 /* More than one watchpoint may have been triggered. */
10186 return PRINT_UNKNOWN
;
10189 /* Implement the "print_one_detail" method for masked hardware
10193 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
10195 /* Masked watchpoints have only one location. */
10196 gdb_assert (this->has_single_location ());
10198 uiout
->text ("\tmask ");
10199 uiout
->field_core_addr ("mask", this->first_loc ().gdbarch
, hw_wp_mask
);
10200 uiout
->text ("\n");
10203 /* Implement the "print_mention" method for masked hardware
10207 masked_watchpoint::print_mention () const
10209 struct ui_out
*uiout
= current_uiout
;
10210 const char *tuple_name
;
10214 case bp_hardware_watchpoint
:
10215 uiout
->text ("Masked hardware watchpoint ");
10216 tuple_name
= "wpt";
10218 case bp_read_watchpoint
:
10219 uiout
->text ("Masked hardware read watchpoint ");
10220 tuple_name
= "hw-rwpt";
10222 case bp_access_watchpoint
:
10223 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10224 tuple_name
= "hw-awpt";
10227 internal_error (_("Invalid hardware watchpoint type."));
10230 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10231 uiout
->field_signed ("number", number
);
10232 uiout
->text (": ");
10233 uiout
->field_string ("exp", exp_string
.get ());
10236 /* Implement the "print_recreate" method for masked hardware
10240 masked_watchpoint::print_recreate (struct ui_file
*fp
) const
10244 case bp_hardware_watchpoint
:
10245 gdb_printf (fp
, "watch");
10247 case bp_read_watchpoint
:
10248 gdb_printf (fp
, "rwatch");
10250 case bp_access_watchpoint
:
10251 gdb_printf (fp
, "awatch");
10254 internal_error (_("Invalid hardware watchpoint type."));
10257 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
10258 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
10259 print_recreate_thread (fp
);
10262 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10265 is_masked_watchpoint (const struct breakpoint
*b
)
10267 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
10270 /* accessflag: hw_write: watch write,
10271 hw_read: watch read,
10272 hw_access: watch access (read or write) */
10274 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10275 bool just_location
, bool internal
)
10277 struct breakpoint
*scope_breakpoint
= NULL
;
10278 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10279 struct value
*result
;
10280 int saved_bitpos
= 0, saved_bitsize
= 0;
10281 const char *exp_start
= NULL
;
10282 const char *exp_end
= NULL
;
10283 const char *tok
, *end_tok
;
10285 const char *cond_start
= NULL
;
10286 const char *cond_end
= NULL
;
10287 enum bptype bp_type
;
10290 /* Flag to indicate whether we are going to use masks for
10291 the hardware watchpoint. */
10292 bool use_mask
= false;
10293 CORE_ADDR mask
= 0;
10296 /* Make sure that we actually have parameters to parse. */
10297 if (arg
!= NULL
&& arg
[0] != '\0')
10299 const char *value_start
;
10301 exp_end
= arg
+ strlen (arg
);
10303 /* Look for "parameter value" pairs at the end
10304 of the arguments string. */
10305 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10307 /* Skip whitespace at the end of the argument list. */
10308 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10311 /* Find the beginning of the last token.
10312 This is the value of the parameter. */
10313 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10315 value_start
= tok
+ 1;
10317 /* Skip whitespace. */
10318 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10323 /* Find the beginning of the second to last token.
10324 This is the parameter itself. */
10325 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10328 toklen
= end_tok
- tok
+ 1;
10330 if (toklen
== 6 && startswith (tok
, "thread"))
10332 struct thread_info
*thr
;
10333 /* At this point we've found a "thread" token, which means
10334 the user is trying to set a watchpoint that triggers
10335 only in a specific thread. */
10339 error(_("You can specify only one thread."));
10342 error (_("You can specify only one of thread or task."));
10344 if (inferior
!= -1)
10345 error (_("You can specify only one of inferior or thread."));
10347 /* Extract the thread ID from the next token. */
10348 thr
= parse_thread_id (value_start
, &endp
);
10349 if (value_start
== endp
)
10350 error (_("Junk after thread keyword."));
10352 thread
= thr
->global_num
;
10354 else if (toklen
== 4 && startswith (tok
, "task"))
10359 error(_("You can specify only one task."));
10362 error (_("You can specify only one of thread or task."));
10364 if (inferior
!= -1)
10365 error (_("You can specify only one of inferior or task."));
10367 task
= strtol (value_start
, &tmp
, 0);
10368 if (tmp
== value_start
)
10369 error (_("Junk after task keyword."));
10370 if (!valid_task_id (task
))
10371 error (_("Unknown task %d."), task
);
10373 else if (toklen
== 8 && startswith (tok
, "inferior"))
10375 /* Support for watchpoints will be added in a later commit. */
10376 error (_("Cannot use 'inferior' keyword with watchpoints"));
10378 else if (toklen
== 4 && startswith (tok
, "mask"))
10380 /* We've found a "mask" token, which means the user wants to
10381 create a hardware watchpoint that is going to have the mask
10383 struct value
*mask_value
;
10386 error(_("You can specify only one mask."));
10388 use_mask
= just_location
= true;
10390 scoped_value_mark mark
;
10391 mask_value
= parse_to_comma_and_eval (&value_start
);
10392 mask
= value_as_address (mask_value
);
10395 /* We didn't recognize what we found. We should stop here. */
10398 /* Truncate the string and get rid of the "parameter value" pair before
10399 the arguments string is parsed by the parse_exp_1 function. */
10406 /* Parse the rest of the arguments. From here on out, everything
10407 is in terms of a newly allocated string instead of the original
10409 std::string
expression (arg
, exp_end
- arg
);
10410 exp_start
= arg
= expression
.c_str ();
10411 innermost_block_tracker tracker
;
10412 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10414 /* Remove trailing whitespace from the expression before saving it.
10415 This makes the eventual display of the expression string a bit
10417 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10420 /* Checking if the expression is not constant. */
10421 if (watchpoint_exp_is_const (exp
.get ()))
10425 len
= exp_end
- exp_start
;
10426 while (len
> 0 && isspace (exp_start
[len
- 1]))
10428 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10431 exp_valid_block
= tracker
.block ();
10432 struct value
*mark
= value_mark ();
10433 struct value
*val_as_value
= nullptr;
10434 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10437 if (val_as_value
!= NULL
&& just_location
)
10439 saved_bitpos
= val_as_value
->bitpos ();
10440 saved_bitsize
= val_as_value
->bitsize ();
10448 exp_valid_block
= NULL
;
10449 val
= release_value (value_addr (result
));
10450 value_free_to_mark (mark
);
10454 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10457 error (_("This target does not support masked watchpoints."));
10458 else if (ret
== -2)
10459 error (_("Invalid mask or memory region."));
10462 else if (val_as_value
!= NULL
)
10463 val
= release_value (val_as_value
);
10465 tok
= skip_spaces (arg
);
10466 end_tok
= skip_to_space (tok
);
10468 toklen
= end_tok
- tok
;
10469 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10471 tok
= cond_start
= end_tok
+ 1;
10472 innermost_block_tracker if_tracker
;
10473 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10475 /* The watchpoint expression may not be local, but the condition
10476 may still be. E.g.: `watch global if local > 0'. */
10477 cond_exp_valid_block
= if_tracker
.block ();
10482 error (_("Junk at end of command."));
10484 frame_info_ptr wp_frame
= block_innermost_frame (exp_valid_block
);
10486 /* Save this because create_internal_breakpoint below invalidates
10488 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10490 /* If the expression is "local", then set up a "watchpoint scope"
10491 breakpoint at the point where we've left the scope of the watchpoint
10492 expression. Create the scope breakpoint before the watchpoint, so
10493 that we will encounter it first in bpstat_stop_status. */
10494 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10496 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10498 if (frame_id_p (caller_frame_id
))
10500 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10501 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10504 = create_internal_breakpoint (caller_arch
, caller_pc
,
10505 bp_watchpoint_scope
);
10507 /* create_internal_breakpoint could invalidate WP_FRAME. */
10510 scope_breakpoint
->enable_state
= bp_enabled
;
10512 /* Automatically delete the breakpoint when it hits. */
10513 scope_breakpoint
->disposition
= disp_del
;
10515 /* Only break in the proper frame (help with recursion). */
10516 scope_breakpoint
->frame_id
= caller_frame_id
;
10518 /* Set the address at which we will stop. */
10519 bp_location
&loc
= scope_breakpoint
->first_loc ();
10520 loc
.gdbarch
= caller_arch
;
10521 loc
.requested_address
= caller_pc
;
10523 = adjust_breakpoint_address (loc
.gdbarch
, loc
.requested_address
,
10524 scope_breakpoint
->type
,
10525 current_program_space
);
10529 /* Now set up the breakpoint. We create all watchpoints as hardware
10530 watchpoints here even if hardware watchpoints are turned off, a call
10531 to update_watchpoint later in this function will cause the type to
10532 drop back to bp_watchpoint (software watchpoint) if required. */
10534 if (accessflag
== hw_read
)
10535 bp_type
= bp_read_watchpoint
;
10536 else if (accessflag
== hw_access
)
10537 bp_type
= bp_access_watchpoint
;
10539 bp_type
= bp_hardware_watchpoint
;
10541 std::unique_ptr
<watchpoint
> w
;
10543 w
.reset (new masked_watchpoint (nullptr, bp_type
));
10545 w
.reset (new watchpoint (nullptr, bp_type
));
10547 /* At most one of thread or task can be set on a watchpoint. */
10548 gdb_assert (thread
== -1 || task
== -1);
10549 w
->thread
= thread
;
10550 w
->inferior
= inferior
;
10552 w
->disposition
= disp_donttouch
;
10553 w
->pspace
= current_program_space
;
10554 w
->exp
= std::move (exp
);
10555 w
->exp_valid_block
= exp_valid_block
;
10556 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10559 struct type
*t
= val
->type ();
10560 CORE_ADDR addr
= value_as_address (val
.get ());
10562 w
->exp_string_reparse
10563 = current_language
->watch_location_expression (t
, addr
);
10565 w
->exp_string
= xstrprintf ("-location %.*s",
10566 (int) (exp_end
- exp_start
), exp_start
);
10569 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10573 w
->hw_wp_mask
= mask
;
10578 w
->val_bitpos
= saved_bitpos
;
10579 w
->val_bitsize
= saved_bitsize
;
10580 w
->val_valid
= true;
10584 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10586 w
->cond_string
= 0;
10588 if (frame_id_p (watchpoint_frame
))
10590 w
->watchpoint_frame
= watchpoint_frame
;
10591 w
->watchpoint_thread
= inferior_ptid
;
10595 w
->watchpoint_frame
= null_frame_id
;
10596 w
->watchpoint_thread
= null_ptid
;
10599 if (scope_breakpoint
!= NULL
)
10601 /* The scope breakpoint is related to the watchpoint. We will
10602 need to act on them together. */
10603 w
->related_breakpoint
= scope_breakpoint
;
10604 scope_breakpoint
->related_breakpoint
= w
.get ();
10607 if (!just_location
)
10608 value_free_to_mark (mark
);
10610 /* Finally update the new watchpoint. This creates the locations
10611 that should be inserted. */
10612 update_watchpoint (w
.get (), true /* reparse */);
10614 install_breakpoint (internal
, std::move (w
), 1);
10617 /* Return count of debug registers needed to watch the given expression.
10618 If the watchpoint cannot be handled in hardware return zero. */
10621 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10623 int found_memory_cnt
= 0;
10625 /* Did the user specifically forbid us to use hardware watchpoints? */
10626 if (!can_use_hw_watchpoints
)
10629 gdb_assert (!vals
.empty ());
10630 struct value
*head
= vals
[0].get ();
10632 /* Make sure that the value of the expression depends only upon
10633 memory contents, and values computed from them within GDB. If we
10634 find any register references or function calls, we can't use a
10635 hardware watchpoint.
10637 The idea here is that evaluating an expression generates a series
10638 of values, one holding the value of every subexpression. (The
10639 expression a*b+c has five subexpressions: a, b, a*b, c, and
10640 a*b+c.) GDB's values hold almost enough information to establish
10641 the criteria given above --- they identify memory lvalues,
10642 register lvalues, computed values, etcetera. So we can evaluate
10643 the expression, and then scan the chain of values that leaves
10644 behind to decide whether we can detect any possible change to the
10645 expression's final value using only hardware watchpoints.
10647 However, I don't think that the values returned by inferior
10648 function calls are special in any way. So this function may not
10649 notice that an expression involving an inferior function call
10650 can't be watched with hardware watchpoints. FIXME. */
10651 for (const value_ref_ptr
&iter
: vals
)
10653 struct value
*v
= iter
.get ();
10655 if (v
->lval () == lval_memory
)
10657 if (v
!= head
&& v
->lazy ())
10658 /* A lazy memory lvalue in the chain is one that GDB never
10659 needed to fetch; we either just used its address (e.g.,
10660 `a' in `a.b') or we never needed it at all (e.g., `a'
10661 in `a,b'). This doesn't apply to HEAD; if that is
10662 lazy then it was not readable, but watch it anyway. */
10666 /* Ahh, memory we actually used! Check if we can cover
10667 it with hardware watchpoints. */
10668 struct type
*vtype
= check_typedef (v
->type ());
10670 /* We only watch structs and arrays if user asked for it
10671 explicitly, never if they just happen to appear in a
10672 middle of some value chain. */
10674 || (vtype
->code () != TYPE_CODE_STRUCT
10675 && vtype
->code () != TYPE_CODE_ARRAY
))
10677 CORE_ADDR vaddr
= v
->address ();
10681 len
= (target_exact_watchpoints
10682 && is_scalar_type_recursive (vtype
))?
10683 1 : v
->type ()->length ();
10685 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10689 found_memory_cnt
+= num_regs
;
10693 else if (v
->lval () != not_lval
&& !v
->deprecated_modifiable ())
10694 return 0; /* These are values from the history (e.g., $1). */
10695 else if (v
->lval () == lval_register
)
10696 return 0; /* Cannot watch a register with a HW watchpoint. */
10699 /* The expression itself looks suitable for using a hardware
10700 watchpoint, but give the target machine a chance to reject it. */
10701 return found_memory_cnt
;
10705 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10707 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10710 /* Options for the watch, awatch, and rwatch commands. */
10712 struct watch_options
10714 /* For -location. */
10715 bool location
= false;
10718 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10720 Historically GDB always accepted both '-location' and '-l' flags for
10721 these commands (both flags being synonyms). When converting to the
10722 newer option scheme only '-location' is added here. That's fine (for
10723 backward compatibility) as any non-ambiguous prefix of a flag will be
10724 accepted, so '-l', '-loc', are now all accepted.
10726 What this means is that, if in the future, we add any new flag here
10727 that starts with '-l' then this will break backward compatibility, so
10728 please, don't do that! */
10730 static const gdb::option::option_def watch_option_defs
[] = {
10731 gdb::option::flag_option_def
<watch_options
> {
10733 [] (watch_options
*opt
) { return &opt
->location
; },
10735 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10736 -l can be used as a short form of -location."),
10740 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10743 static gdb::option::option_def_group
10744 make_watch_options_def_group (watch_options
*opts
)
10746 return {{watch_option_defs
}, opts
};
10749 /* A helper function that looks for the "-location" argument and then
10750 calls watch_command_1. */
10753 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10755 watch_options opts
;
10756 auto grp
= make_watch_options_def_group (&opts
);
10757 gdb::option::process_options
10758 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10759 if (arg
!= nullptr && *arg
== '\0')
10762 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10765 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10767 watch_command_completer (struct cmd_list_element
*ignore
,
10768 completion_tracker
&tracker
,
10769 const char *text
, const char * /*word*/)
10771 const auto group
= make_watch_options_def_group (nullptr);
10772 if (gdb::option::complete_options
10773 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10776 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10777 expression_completer (ignore
, tracker
, text
, word
);
10781 watch_command (const char *arg
, int from_tty
)
10783 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10787 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10789 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10793 rwatch_command (const char *arg
, int from_tty
)
10795 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10799 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10801 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10805 awatch_command (const char *arg
, int from_tty
)
10807 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10811 /* Data for the FSM that manages the until(location)/advance commands
10812 in infcmd.c. Here because it uses the mechanisms of
10815 struct until_break_fsm
: public thread_fsm
10817 /* The thread that was current when the command was executed. */
10820 /* The breakpoint set at the return address in the caller frame,
10821 plus breakpoints at all the destination locations. */
10822 std::vector
<breakpoint_up
> breakpoints
;
10824 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10825 std::vector
<breakpoint_up
> &&breakpoints
)
10826 : thread_fsm (cmd_interp
),
10828 breakpoints (std::move (breakpoints
))
10832 void clean_up (struct thread_info
*thread
) override
;
10833 bool should_stop (struct thread_info
*thread
) override
;
10834 enum async_reply_reason
do_async_reply_reason () override
;
10837 /* Implementation of the 'should_stop' FSM method for the
10838 until(location)/advance commands. */
10841 until_break_fsm::should_stop (struct thread_info
*tp
)
10843 for (const breakpoint_up
&bp
: breakpoints
)
10844 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10845 bp
.get ()) != NULL
)
10854 /* Implementation of the 'clean_up' FSM method for the
10855 until(location)/advance commands. */
10858 until_break_fsm::clean_up (struct thread_info
*)
10860 /* Clean up our temporary breakpoints. */
10861 breakpoints
.clear ();
10862 delete_longjmp_breakpoint (thread
);
10865 /* Implementation of the 'async_reply_reason' FSM method for the
10866 until(location)/advance commands. */
10868 enum async_reply_reason
10869 until_break_fsm::do_async_reply_reason ()
10871 return EXEC_ASYNC_LOCATION_REACHED
;
10875 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10877 frame_info_ptr frame
;
10878 struct gdbarch
*frame_gdbarch
;
10879 struct frame_id stack_frame_id
;
10880 struct frame_id caller_frame_id
;
10882 struct thread_info
*tp
;
10884 clear_proceed_status (0);
10886 /* Set a breakpoint where the user wants it and at return from
10889 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
10891 std::vector
<symtab_and_line
> sals
10892 = (last_displayed_sal_is_valid ()
10893 ? decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10894 get_last_displayed_symtab (),
10895 get_last_displayed_line ())
10896 : decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
,
10900 error (_("Couldn't get information on specified line."));
10903 error (_("Junk at end of arguments."));
10905 tp
= inferior_thread ();
10906 thread
= tp
->global_num
;
10908 /* Note linespec handling above invalidates the frame chain.
10909 Installing a breakpoint also invalidates the frame chain (as it
10910 may need to switch threads), so do any frame handling before
10913 frame
= get_selected_frame (NULL
);
10914 frame_gdbarch
= get_frame_arch (frame
);
10915 stack_frame_id
= get_stack_frame_id (frame
);
10916 caller_frame_id
= frame_unwind_caller_id (frame
);
10918 /* Keep within the current frame, or in frames called by the current
10921 std::vector
<breakpoint_up
> breakpoints
;
10923 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10925 if (frame_id_p (caller_frame_id
))
10927 struct symtab_and_line sal2
;
10928 struct gdbarch
*caller_gdbarch
;
10930 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10931 sal2
.pc
= frame_unwind_caller_pc (frame
);
10932 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10934 breakpoint_up caller_breakpoint
10935 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10936 caller_frame_id
, bp_until
);
10937 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10939 set_longjmp_breakpoint (tp
, stack_frame_id
);
10940 lj_deleter
.emplace (thread
);
10943 /* set_momentary_breakpoint could invalidate FRAME. */
10946 /* If the user told us to continue until a specified location, we
10947 don't specify a frame at which we need to stop. Otherwise,
10948 specify the selected frame, because we want to stop only at the
10949 very same frame. */
10950 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10952 for (symtab_and_line
&sal
: sals
)
10954 resolve_sal_pc (&sal
);
10956 breakpoint_up location_breakpoint
10957 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10958 stop_frame_id
, bp_until
);
10959 breakpoints
.emplace_back (std::move (location_breakpoint
));
10963 (std::unique_ptr
<thread_fsm
>
10964 (new until_break_fsm (command_interp (), tp
->global_num
,
10965 std::move (breakpoints
))));
10968 lj_deleter
->release ();
10970 proceed (-1, GDB_SIGNAL_DEFAULT
);
10975 /* Compare two breakpoints and return a strcmp-like result. */
10978 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10980 uintptr_t ua
= (uintptr_t) a
;
10981 uintptr_t ub
= (uintptr_t) b
;
10983 if (a
->number
< b
->number
)
10985 else if (a
->number
> b
->number
)
10988 /* Now sort by address, in case we see, e..g, two breakpoints with
10992 return ua
> ub
? 1 : 0;
10995 /* Delete breakpoints by address or line. */
10998 clear_command (const char *arg
, int from_tty
)
11002 std::vector
<symtab_and_line
> decoded_sals
;
11003 symtab_and_line last_sal
;
11004 gdb::array_view
<symtab_and_line
> sals
;
11008 = decode_line_with_current_source (arg
,
11009 (DECODE_LINE_FUNFIRSTLINE
11010 | DECODE_LINE_LIST_MODE
));
11012 sals
= decoded_sals
;
11016 /* Set sal's line, symtab, pc, and pspace to the values
11017 corresponding to the last call to print_frame_info. If the
11018 codepoint is not valid, this will set all the fields to 0. */
11019 last_sal
= get_last_displayed_sal ();
11020 if (last_sal
.symtab
== 0)
11021 error (_("No source file specified."));
11027 /* We don't call resolve_sal_pc here. That's not as bad as it
11028 seems, because all existing breakpoints typically have both
11029 file/line and pc set. So, if clear is given file/line, we can
11030 match this to existing breakpoint without obtaining pc at all.
11032 We only support clearing given the address explicitly
11033 present in breakpoint table. Say, we've set breakpoint
11034 at file:line. There were several PC values for that file:line,
11035 due to optimization, all in one block.
11037 We've picked one PC value. If "clear" is issued with another
11038 PC corresponding to the same file:line, the breakpoint won't
11039 be cleared. We probably can still clear the breakpoint, but
11040 since the other PC value is never presented to user, user
11041 can only find it by guessing, and it does not seem important
11042 to support that. */
11044 /* For each line spec given, delete bps which correspond to it. Do
11045 it in two passes, solely to preserve the current behavior that
11046 from_tty is forced true if we delete more than one
11049 std::vector
<struct breakpoint
*> found
;
11050 for (const auto &sal
: sals
)
11052 const char *sal_fullname
;
11054 /* If exact pc given, clear bpts at that pc.
11055 If line given (pc == 0), clear all bpts on specified line.
11056 If defaulting, clear all bpts on default line
11059 defaulting sal.pc != 0 tests to do
11064 1 0 <can't happen> */
11066 sal_fullname
= (sal
.symtab
== NULL
11067 ? NULL
: symtab_to_fullname (sal
.symtab
));
11069 /* Find all matching breakpoints and add them to 'found'. */
11070 for (breakpoint
&b
: all_breakpoints ())
11073 /* Are we going to delete b? */
11074 if (b
.type
!= bp_none
&& !is_watchpoint (&b
)
11075 && user_breakpoint_p (&b
))
11077 for (bp_location
&loc
: b
.locations ())
11079 /* If the user specified file:line, don't allow a PC
11080 match. This matches historical gdb behavior. */
11081 int pc_match
= (!sal
.explicit_line
11083 && (loc
.pspace
== sal
.pspace
)
11084 && (loc
.address
== sal
.pc
)
11085 && (!section_is_overlay (loc
.section
)
11086 || loc
.section
== sal
.section
));
11087 int line_match
= 0;
11089 if ((default_match
|| sal
.explicit_line
)
11090 && loc
.symtab
!= NULL
11091 && sal_fullname
!= NULL
11092 && sal
.pspace
== loc
.pspace
11093 && loc
.line_number
== sal
.line
11094 && filename_cmp (symtab_to_fullname (loc
.symtab
),
11095 sal_fullname
) == 0)
11098 if (pc_match
|| line_match
)
11107 found
.push_back (&b
);
11111 /* Now go thru the 'found' chain and delete them. */
11112 if (found
.empty ())
11115 error (_("No breakpoint at %s."), arg
);
11117 error (_("No breakpoint at this line."));
11120 /* Remove duplicates from the vec. */
11121 std::sort (found
.begin (), found
.end (),
11122 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11124 return compare_breakpoints (bp_a
, bp_b
) < 0;
11126 found
.erase (std::unique (found
.begin (), found
.end (),
11127 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11129 return compare_breakpoints (bp_a
, bp_b
) == 0;
11133 if (found
.size () > 1)
11134 from_tty
= 1; /* Always report if deleted more than one. */
11137 if (found
.size () == 1)
11138 gdb_printf (_("Deleted breakpoint "));
11140 gdb_printf (_("Deleted breakpoints "));
11143 for (breakpoint
*iter
: found
)
11146 gdb_printf ("%d ", iter
->number
);
11147 delete_breakpoint (iter
);
11153 /* Delete breakpoint in BS if they are `delete' breakpoints and
11154 all breakpoints that are marked for deletion, whether hit or not.
11155 This is called after any breakpoint is hit, or after errors. */
11158 breakpoint_auto_delete (bpstat
*bs
)
11160 for (; bs
; bs
= bs
->next
)
11161 if (bs
->breakpoint_at
11162 && bs
->breakpoint_at
->disposition
== disp_del
11164 delete_breakpoint (bs
->breakpoint_at
);
11166 for (breakpoint
&b
: all_breakpoints_safe ())
11167 if (b
.disposition
== disp_del_at_next_stop
)
11168 delete_breakpoint (&b
);
11171 /* A comparison function for bp_location AP and BP being interfaced to
11172 std::sort. Sort elements primarily by their ADDRESS (no matter what
11173 bl_address_is_meaningful says), secondarily by ordering first
11174 permanent elements and tertiarily just ensuring the array is sorted
11175 stable way despite std::sort being an unstable algorithm. */
11178 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11180 if (a
->address
!= b
->address
)
11181 return a
->address
< b
->address
;
11183 /* Sort locations at the same address by their pspace number, keeping
11184 locations of the same inferior (in a multi-inferior environment)
11187 if (a
->pspace
->num
!= b
->pspace
->num
)
11188 return a
->pspace
->num
< b
->pspace
->num
;
11190 /* Sort permanent breakpoints first. */
11191 if (a
->permanent
!= b
->permanent
)
11192 return a
->permanent
> b
->permanent
;
11194 /* Sort by type in order to make duplicate determination easier.
11195 See update_global_location_list. This is kept in sync with
11196 breakpoint_locations_match. */
11197 if (a
->loc_type
< b
->loc_type
)
11200 /* Likewise, for range-breakpoints, sort by length. */
11201 if (a
->loc_type
== bp_loc_hardware_breakpoint
11202 && b
->loc_type
== bp_loc_hardware_breakpoint
11203 && a
->length
< b
->length
)
11206 /* Make the internal GDB representation stable across GDB runs
11207 where A and B memory inside GDB can differ. Breakpoint locations of
11208 the same type at the same address can be sorted in arbitrary order. */
11210 if (a
->owner
->number
!= b
->owner
->number
)
11211 return a
->owner
->number
< b
->owner
->number
;
11216 /* Set bp_locations_placed_address_before_address_max and
11217 bp_locations_shadow_len_after_address_max according to the current
11218 content of the bp_locations array. */
11221 bp_locations_target_extensions_update (void)
11223 bp_locations_placed_address_before_address_max
= 0;
11224 bp_locations_shadow_len_after_address_max
= 0;
11226 for (bp_location
*bl
: all_bp_locations ())
11228 CORE_ADDR start
, end
, addr
;
11230 if (!bp_location_has_shadow (bl
))
11233 start
= bl
->target_info
.placed_address
;
11234 end
= start
+ bl
->target_info
.shadow_len
;
11236 gdb_assert (bl
->address
>= start
);
11237 addr
= bl
->address
- start
;
11238 if (addr
> bp_locations_placed_address_before_address_max
)
11239 bp_locations_placed_address_before_address_max
= addr
;
11241 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11243 gdb_assert (bl
->address
< end
);
11244 addr
= end
- bl
->address
;
11245 if (addr
> bp_locations_shadow_len_after_address_max
)
11246 bp_locations_shadow_len_after_address_max
= addr
;
11250 /* Download tracepoint locations if they haven't been. */
11253 download_tracepoint_locations (void)
11255 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11257 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11259 for (breakpoint
&b
: all_tracepoints ())
11261 bool bp_location_downloaded
= false;
11263 if ((b
.type
== bp_fast_tracepoint
11264 ? !may_insert_fast_tracepoints
11265 : !may_insert_tracepoints
))
11268 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11270 if (target_can_download_tracepoint ())
11271 can_download_tracepoint
= TRIBOOL_TRUE
;
11273 can_download_tracepoint
= TRIBOOL_FALSE
;
11276 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11279 for (bp_location
&bl
: b
.locations ())
11281 /* In tracepoint, locations are _never_ duplicated, so
11282 should_be_inserted is equivalent to
11283 unduplicated_should_be_inserted. */
11284 if (!should_be_inserted (&bl
) || bl
.inserted
)
11287 switch_to_program_space_and_thread (bl
.pspace
);
11289 target_download_tracepoint (&bl
);
11292 bp_location_downloaded
= true;
11295 tracepoint
&t
= gdb::checked_static_cast
<tracepoint
&> (b
);
11296 t
.number_on_target
= b
.number
;
11297 if (bp_location_downloaded
)
11298 notify_breakpoint_modified (&b
);
11302 /* Swap the insertion/duplication state between two locations. */
11305 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11307 const int left_inserted
= left
->inserted
;
11308 const int left_duplicate
= left
->duplicate
;
11309 const int left_needs_update
= left
->needs_update
;
11310 const struct bp_target_info left_target_info
= left
->target_info
;
11312 /* Locations of tracepoints can never be duplicated. */
11313 if (is_tracepoint (left
->owner
))
11314 gdb_assert (!left
->duplicate
);
11315 if (is_tracepoint (right
->owner
))
11316 gdb_assert (!right
->duplicate
);
11318 left
->inserted
= right
->inserted
;
11319 left
->duplicate
= right
->duplicate
;
11320 left
->needs_update
= right
->needs_update
;
11321 left
->target_info
= right
->target_info
;
11322 right
->inserted
= left_inserted
;
11323 right
->duplicate
= left_duplicate
;
11324 right
->needs_update
= left_needs_update
;
11325 right
->target_info
= left_target_info
;
11328 /* Force the re-insertion of the locations at ADDRESS. This is called
11329 once a new/deleted/modified duplicate location is found and we are evaluating
11330 conditions on the target's side. Such conditions need to be updated on
11334 force_breakpoint_reinsertion (struct bp_location
*bl
)
11336 CORE_ADDR address
= 0;
11339 address
= bl
->address
;
11340 pspace_num
= bl
->pspace
->num
;
11342 /* This is only meaningful if the target is
11343 evaluating conditions and if the user has
11344 opted for condition evaluation on the target's
11346 if (gdb_evaluates_breakpoint_condition_p ()
11347 || !target_supports_evaluation_of_breakpoint_conditions ())
11350 /* Flag all breakpoint locations with this address and
11351 the same program space as the location
11352 as "its condition has changed". We need to
11353 update the conditions on the target's side. */
11354 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11356 if (!is_breakpoint (loc
->owner
)
11357 || pspace_num
!= loc
->pspace
->num
)
11360 /* Flag the location appropriately. We use a different state to
11361 let everyone know that we already updated the set of locations
11362 with addr bl->address and program space bl->pspace. This is so
11363 we don't have to keep calling these functions just to mark locations
11364 that have already been marked. */
11365 loc
->condition_changed
= condition_updated
;
11367 /* Free the agent expression bytecode as well. We will compute
11369 loc
->cond_bytecode
.reset ();
11373 /* Called whether new breakpoints are created, or existing breakpoints
11374 deleted, to update the global location list and recompute which
11375 locations are duplicate of which.
11377 The INSERT_MODE flag determines whether locations may not, may, or
11378 shall be inserted now. See 'enum ugll_insert_mode' for more
11382 update_global_location_list (enum ugll_insert_mode insert_mode
)
11384 /* Last breakpoint location address that was marked for update. */
11385 CORE_ADDR last_addr
= 0;
11386 /* Last breakpoint location program space that was marked for update. */
11387 int last_pspace_num
= -1;
11389 breakpoint_debug_printf ("insert_mode = %s",
11390 ugll_insert_mode_text (insert_mode
));
11392 /* Used in the duplicates detection below. When iterating over all
11393 bp_locations, points to the first bp_location of a given address.
11394 Breakpoints and watchpoints of different types are never
11395 duplicates of each other. Keep one pointer for each type of
11396 breakpoint/watchpoint, so we only need to loop over all locations
11398 struct bp_location
*bp_loc_first
; /* breakpoint */
11399 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11400 struct bp_location
*awp_loc_first
; /* access watchpoint */
11401 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11403 /* Saved former bp_locations array which we compare against the newly
11404 built bp_locations from the current state of ALL_BREAKPOINTS. */
11405 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11406 bp_locations
.clear ();
11408 for (breakpoint
&b
: all_breakpoints ())
11409 for (bp_location
&loc
: b
.locations ())
11410 bp_locations
.push_back (&loc
);
11412 /* See if we need to "upgrade" a software breakpoint to a hardware
11413 breakpoint. Do this before deciding whether locations are
11414 duplicates. Also do this before sorting because sorting order
11415 depends on location type. */
11416 for (bp_location
*loc
: bp_locations
)
11417 if (!loc
->inserted
&& should_be_inserted (loc
))
11418 handle_automatic_hardware_breakpoints (loc
);
11420 std::sort (bp_locations
.begin (), bp_locations
.end (),
11421 bp_location_is_less_than
);
11423 bp_locations_target_extensions_update ();
11425 /* Identify bp_location instances that are no longer present in the
11426 new list, and therefore should be freed. Note that it's not
11427 necessary that those locations should be removed from inferior --
11428 if there's another location at the same address (previously
11429 marked as duplicate), we don't need to remove/insert the
11432 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11433 and former bp_location array state respectively. */
11436 for (bp_location
*old_loc
: old_locations
)
11438 /* Tells if 'old_loc' is found among the new locations. If
11439 not, we have to free it. */
11440 bool found_object
= false;
11441 /* Tells if the location should remain inserted in the target. */
11442 bool keep_in_target
= false;
11443 bool removed
= false;
11445 /* Skip LOCP entries which will definitely never be needed.
11446 Stop either at or being the one matching OLD_LOC. */
11447 while (loc_i
< bp_locations
.size ()
11448 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11451 for (size_t loc2_i
= loc_i
;
11452 (loc2_i
< bp_locations
.size ()
11453 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11456 /* Check if this is a new/duplicated location or a duplicated
11457 location that had its condition modified. If so, we want to send
11458 its condition to the target if evaluation of conditions is taking
11460 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11461 && (last_addr
!= old_loc
->address
11462 || last_pspace_num
!= old_loc
->pspace
->num
))
11464 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11465 last_pspace_num
= old_loc
->pspace
->num
;
11468 if (bp_locations
[loc2_i
] == old_loc
)
11469 found_object
= true;
11472 /* We have already handled this address, update it so that we don't
11473 have to go through updates again. */
11474 last_addr
= old_loc
->address
;
11476 /* Target-side condition evaluation: Handle deleted locations. */
11478 force_breakpoint_reinsertion (old_loc
);
11480 /* If this location is no longer present, and inserted, look if
11481 there's maybe a new location at the same address. If so,
11482 mark that one inserted, and don't remove this one. This is
11483 needed so that we don't have a time window where a breakpoint
11484 at certain location is not inserted. */
11486 if (old_loc
->inserted
)
11488 /* If the location is inserted now, we might have to remove
11491 if (found_object
&& should_be_inserted (old_loc
))
11493 /* The location is still present in the location list,
11494 and still should be inserted. Don't do anything. */
11495 keep_in_target
= true;
11499 /* This location still exists, but it won't be kept in the
11500 target since it may have been disabled. We proceed to
11501 remove its target-side condition. */
11503 /* The location is either no longer present, or got
11504 disabled. See if there's another location at the
11505 same address, in which case we don't need to remove
11506 this one from the target. */
11508 /* OLD_LOC comes from existing struct breakpoint. */
11509 if (bl_address_is_meaningful (old_loc
))
11511 for (size_t loc2_i
= loc_i
;
11512 (loc2_i
< bp_locations
.size ()
11513 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11516 bp_location
*loc2
= bp_locations
[loc2_i
];
11518 if (loc2
== old_loc
)
11521 if (breakpoint_locations_match (loc2
, old_loc
))
11523 /* Read watchpoint locations are switched to
11524 access watchpoints, if the former are not
11525 supported, but the latter are. */
11526 if (is_hardware_watchpoint (old_loc
->owner
))
11528 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11529 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11532 /* loc2 is a duplicated location. We need to check
11533 if it should be inserted in case it will be
11535 if (unduplicated_should_be_inserted (loc2
))
11537 swap_insertion (old_loc
, loc2
);
11538 keep_in_target
= true;
11546 if (!keep_in_target
)
11548 if (remove_breakpoint (old_loc
))
11550 /* This is just about all we can do. We could keep
11551 this location on the global list, and try to
11552 remove it next time, but there's no particular
11553 reason why we will succeed next time.
11555 Note that at this point, old_loc->owner is still
11556 valid, as delete_breakpoint frees the breakpoint
11557 only after calling us. */
11558 warning (_("error removing breakpoint %d at %s"),
11559 old_loc
->owner
->number
,
11560 paddress (old_loc
->gdbarch
, old_loc
->address
));
11568 if (removed
&& target_is_non_stop_p ()
11569 && need_moribund_for_location_type (old_loc
))
11571 /* This location was removed from the target. In
11572 non-stop mode, a race condition is possible where
11573 we've removed a breakpoint, but stop events for that
11574 breakpoint are already queued and will arrive later.
11575 We apply an heuristic to be able to distinguish such
11576 SIGTRAPs from other random SIGTRAPs: we keep this
11577 breakpoint location for a bit, and will retire it
11578 after we see some number of events. The theory here
11579 is that reporting of events should, "on the average",
11580 be fair, so after a while we'll see events from all
11581 threads that have anything of interest, and no longer
11582 need to keep this breakpoint location around. We
11583 don't hold locations forever so to reduce chances of
11584 mistaking a non-breakpoint SIGTRAP for a breakpoint
11587 The heuristic failing can be disastrous on
11588 decr_pc_after_break targets.
11590 On decr_pc_after_break targets, like e.g., x86-linux,
11591 if we fail to recognize a late breakpoint SIGTRAP,
11592 because events_till_retirement has reached 0 too
11593 soon, we'll fail to do the PC adjustment, and report
11594 a random SIGTRAP to the user. When the user resumes
11595 the inferior, it will most likely immediately crash
11596 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11597 corrupted, because of being resumed e.g., in the
11598 middle of a multi-byte instruction, or skipped a
11599 one-byte instruction. This was actually seen happen
11600 on native x86-linux, and should be less rare on
11601 targets that do not support new thread events, like
11602 remote, due to the heuristic depending on
11605 Mistaking a random SIGTRAP for a breakpoint trap
11606 causes similar symptoms (PC adjustment applied when
11607 it shouldn't), but then again, playing with SIGTRAPs
11608 behind the debugger's back is asking for trouble.
11610 Since hardware watchpoint traps are always
11611 distinguishable from other traps, so we don't need to
11612 apply keep hardware watchpoint moribund locations
11613 around. We simply always ignore hardware watchpoint
11614 traps we can no longer explain. */
11616 process_stratum_target
*proc_target
= nullptr;
11617 for (inferior
*inf
: all_inferiors ())
11618 if (inf
->pspace
== old_loc
->pspace
)
11620 proc_target
= inf
->process_target ();
11623 if (proc_target
!= nullptr)
11624 old_loc
->events_till_retirement
11625 = 3 * (thread_count (proc_target
) + 1);
11627 old_loc
->events_till_retirement
= 1;
11628 old_loc
->owner
= NULL
;
11630 moribund_locations
.push_back (old_loc
);
11634 old_loc
->owner
= NULL
;
11635 decref_bp_location (&old_loc
);
11640 /* Rescan breakpoints at the same address and section, marking the
11641 first one as "first" and any others as "duplicates". This is so
11642 that the bpt instruction is only inserted once. If we have a
11643 permanent breakpoint at the same place as BPT, make that one the
11644 official one, and the rest as duplicates. Permanent breakpoints
11645 are sorted first for the same address.
11647 Do the same for hardware watchpoints, but also considering the
11648 watchpoint's type (regular/access/read) and length. */
11650 bp_loc_first
= NULL
;
11651 wp_loc_first
= NULL
;
11652 awp_loc_first
= NULL
;
11653 rwp_loc_first
= NULL
;
11655 for (bp_location
*loc
: all_bp_locations ())
11657 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11659 struct bp_location
**loc_first_p
;
11660 breakpoint
*b
= loc
->owner
;
11662 if (!unduplicated_should_be_inserted (loc
)
11663 || !bl_address_is_meaningful (loc
)
11664 /* Don't detect duplicate for tracepoint locations because they are
11665 never duplicated. See the comments in field `duplicate' of
11666 `struct bp_location'. */
11667 || is_tracepoint (b
))
11669 /* Clear the condition modification flag. */
11670 loc
->condition_changed
= condition_unchanged
;
11674 if (b
->type
== bp_hardware_watchpoint
)
11675 loc_first_p
= &wp_loc_first
;
11676 else if (b
->type
== bp_read_watchpoint
)
11677 loc_first_p
= &rwp_loc_first
;
11678 else if (b
->type
== bp_access_watchpoint
)
11679 loc_first_p
= &awp_loc_first
;
11681 loc_first_p
= &bp_loc_first
;
11683 if (*loc_first_p
== NULL
11684 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11685 || !breakpoint_locations_match (loc
, *loc_first_p
))
11687 *loc_first_p
= loc
;
11688 loc
->duplicate
= 0;
11690 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11692 loc
->needs_update
= 1;
11693 /* Clear the condition modification flag. */
11694 loc
->condition_changed
= condition_unchanged
;
11700 /* This and the above ensure the invariant that the first location
11701 is not duplicated, and is the inserted one.
11702 All following are marked as duplicated, and are not inserted. */
11704 swap_insertion (loc
, *loc_first_p
);
11705 loc
->duplicate
= 1;
11707 /* Clear the condition modification flag. */
11708 loc
->condition_changed
= condition_unchanged
;
11711 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11713 if (insert_mode
!= UGLL_DONT_INSERT
)
11714 insert_breakpoint_locations ();
11717 /* Even though the caller told us to not insert new
11718 locations, we may still need to update conditions on the
11719 target's side of breakpoints that were already inserted
11720 if the target is evaluating breakpoint conditions. We
11721 only update conditions for locations that are marked
11723 update_inserted_breakpoint_locations ();
11727 if (insert_mode
!= UGLL_DONT_INSERT
)
11728 download_tracepoint_locations ();
11732 breakpoint_retire_moribund (void)
11734 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11736 struct bp_location
*loc
= moribund_locations
[ix
];
11737 if (--(loc
->events_till_retirement
) == 0)
11739 decref_bp_location (&loc
);
11740 unordered_remove (moribund_locations
, ix
);
11747 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11752 update_global_location_list (insert_mode
);
11754 catch (const gdb_exception_error
&e
)
11759 /* Clear BKP from a BPS. */
11762 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11766 for (bs
= bps
; bs
; bs
= bs
->next
)
11767 if (bs
->breakpoint_at
== bpt
)
11769 bs
->breakpoint_at
= NULL
;
11770 bs
->old_val
= NULL
;
11771 /* bs->commands will be freed later. */
11775 /* Callback for iterate_over_threads. */
11777 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11779 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11781 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11785 /* See breakpoint.h. */
11788 code_breakpoint::say_where () const
11790 struct value_print_options opts
;
11792 get_user_print_options (&opts
);
11794 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11796 if (!this->has_locations ())
11798 /* For pending locations, the output differs slightly based
11799 on extra_string. If this is non-NULL, it contains either
11800 a condition or dprintf arguments. */
11801 if (extra_string
== NULL
)
11803 gdb_printf (_(" (%s) pending."), locspec
->to_string ());
11805 else if (type
== bp_dprintf
)
11807 gdb_printf (_(" (%s,%s) pending."),
11808 locspec
->to_string (),
11809 extra_string
.get ());
11813 gdb_printf (_(" (%s %s) pending."),
11814 locspec
->to_string (),
11815 extra_string
.get ());
11820 const bp_location
&bl
= this->first_loc ();
11821 if (opts
.addressprint
|| bl
.symtab
== nullptr)
11822 gdb_printf (" at %ps",
11823 styled_string (address_style
.style (),
11824 paddress (bl
.gdbarch
,
11826 if (bl
.symtab
!= NULL
)
11828 /* If there is a single location, we can print the location
11830 if (!this->has_multiple_locations ())
11832 const char *filename
11833 = symtab_to_filename_for_display (bl
.symtab
);
11834 gdb_printf (": file %ps, line %d.",
11835 styled_string (file_name_style
.style (),
11840 /* This is not ideal, but each location may have a
11841 different file name, and this at least reflects the
11842 real situation somewhat. */
11843 gdb_printf (": %s.", locspec
->to_string ());
11846 if (this->has_multiple_locations ())
11848 int n
= std::distance (m_locations
.begin (), m_locations
.end ());
11849 gdb_printf (" (%d locations)", n
);
11854 /* See breakpoint.h. */
11856 bp_location_range
breakpoint::locations () const
11858 return bp_location_range (m_locations
.begin (), m_locations
.end ());
11861 struct bp_location
*
11862 breakpoint::allocate_location ()
11864 return new bp_location (this);
11867 /* See breakpoint.h. */
11870 breakpoint::add_location (bp_location
&loc
)
11872 gdb_assert (loc
.owner
== this);
11873 gdb_assert (!loc
.is_linked ());
11875 auto ub
= std::upper_bound (m_locations
.begin (), m_locations
.end (),
11877 [] (const bp_location
&left
,
11878 const bp_location
&right
)
11879 { return left
.address
< right
.address
; });
11880 m_locations
.insert (ub
, loc
);
11883 /* See breakpoint.h. */
11886 breakpoint::unadd_location (bp_location
&loc
)
11888 gdb_assert (loc
.owner
== this);
11889 gdb_assert (loc
.is_linked ());
11891 m_locations
.erase (m_locations
.iterator_to (loc
));
11894 #define internal_error_pure_virtual_called() \
11895 gdb_assert_not_reached ("pure virtual function called")
11898 breakpoint::insert_location (struct bp_location
*bl
)
11900 internal_error_pure_virtual_called ();
11904 breakpoint::remove_location (struct bp_location
*bl
,
11905 enum remove_bp_reason reason
)
11907 internal_error_pure_virtual_called ();
11911 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11912 const address_space
*aspace
,
11914 const target_waitstatus
&ws
)
11916 internal_error_pure_virtual_called ();
11920 breakpoint::resources_needed (const struct bp_location
*bl
)
11922 internal_error_pure_virtual_called ();
11925 enum print_stop_action
11926 breakpoint::print_it (const bpstat
*bs
) const
11928 internal_error_pure_virtual_called ();
11932 breakpoint::print_mention () const
11934 internal_error_pure_virtual_called ();
11938 breakpoint::print_recreate (struct ui_file
*fp
) const
11940 internal_error_pure_virtual_called ();
11943 /* Default breakpoint_ops methods. */
11946 code_breakpoint::re_set ()
11948 /* FIXME: is this still reachable? */
11949 if (breakpoint_location_spec_empty_p (this))
11951 /* Anything without a location can't be re-set. */
11952 delete_breakpoint (this);
11960 code_breakpoint::insert_location (struct bp_location
*bl
)
11962 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11964 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11965 bl
->target_info
.placed_address
= addr
;
11968 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11969 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11971 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11973 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11975 /* The insertion was successful, now let's set the probe's semaphore
11977 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11984 code_breakpoint::remove_location (struct bp_location
*bl
,
11985 enum remove_bp_reason reason
)
11987 if (bl
->probe
.prob
!= nullptr)
11989 /* Let's clear the semaphore before removing the location. */
11990 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11993 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11994 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11996 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12000 code_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
12001 const address_space
*aspace
,
12003 const target_waitstatus
&ws
)
12005 if (ws
.kind () != TARGET_WAITKIND_STOPPED
12006 || ws
.sig () != GDB_SIGNAL_TRAP
)
12009 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12013 if (overlay_debugging
/* unmapped overlay section */
12014 && section_is_overlay (bl
->section
)
12015 && !section_is_mapped (bl
->section
))
12022 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
12023 const address_space
*aspace
,
12025 const target_waitstatus
&ws
)
12027 if (dprintf_style
== dprintf_style_agent
12028 && target_can_run_breakpoint_commands ())
12030 /* An agent-style dprintf never causes a stop. If we see a trap
12031 for this address it must be for a breakpoint that happens to
12032 be set at the same address. */
12036 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12040 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
12042 gdb_assert (type
== bp_hardware_breakpoint
);
12047 enum print_stop_action
12048 ordinary_breakpoint::print_it (const bpstat
*bs
) const
12050 const struct bp_location
*bl
;
12052 struct ui_out
*uiout
= current_uiout
;
12054 bl
= bs
->bp_location_at
.get ();
12056 bp_temp
= disposition
== disp_del
;
12057 if (bl
->address
!= bl
->requested_address
)
12058 breakpoint_adjustment_warning (bl
->requested_address
,
12061 annotate_breakpoint (number
);
12062 maybe_print_thread_hit_breakpoint (uiout
);
12064 if (uiout
->is_mi_like_p ())
12066 uiout
->field_string ("reason",
12067 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12068 uiout
->field_string ("disp", bpdisp_text (disposition
));
12072 uiout
->text ("Temporary breakpoint ");
12074 uiout
->text ("Breakpoint ");
12075 print_num_locno (bs
, uiout
);
12076 uiout
->text (", ");
12078 return PRINT_SRC_AND_LOC
;
12082 ordinary_breakpoint::print_mention () const
12084 if (current_uiout
->is_mi_like_p ())
12089 case bp_breakpoint
:
12090 case bp_gnu_ifunc_resolver
:
12091 if (disposition
== disp_del
)
12092 gdb_printf (_("Temporary breakpoint"));
12094 gdb_printf (_("Breakpoint"));
12095 gdb_printf (_(" %d"), number
);
12096 if (type
== bp_gnu_ifunc_resolver
)
12097 gdb_printf (_(" at gnu-indirect-function resolver"));
12099 case bp_hardware_breakpoint
:
12100 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
12103 gdb_printf (_("Dprintf %d"), number
);
12111 ordinary_breakpoint::print_recreate (struct ui_file
*fp
) const
12113 if (type
== bp_breakpoint
&& disposition
== disp_del
)
12114 gdb_printf (fp
, "tbreak");
12115 else if (type
== bp_breakpoint
)
12116 gdb_printf (fp
, "break");
12117 else if (type
== bp_hardware_breakpoint
12118 && disposition
== disp_del
)
12119 gdb_printf (fp
, "thbreak");
12120 else if (type
== bp_hardware_breakpoint
)
12121 gdb_printf (fp
, "hbreak");
12123 internal_error (_("unhandled breakpoint type %d"), (int) type
);
12125 gdb_printf (fp
, " %s", locspec
->to_string ());
12127 /* Print out extra_string if this breakpoint is pending. It might
12128 contain, for example, conditions that were set by the user. */
12129 if (!this->has_locations () && extra_string
!= NULL
)
12130 gdb_printf (fp
, " %s", extra_string
.get ());
12132 print_recreate_thread (fp
);
12135 std::vector
<symtab_and_line
>
12136 code_breakpoint::decode_location_spec (location_spec
*locspec
,
12137 program_space
*search_pspace
)
12139 if (locspec
->type () == PROBE_LOCATION_SPEC
)
12140 return bkpt_probe_decode_location_spec (this, locspec
, search_pspace
);
12142 struct linespec_result canonical
;
12144 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
12145 NULL
, 0, &canonical
, multiple_symbols_all
,
12148 /* We should get 0 or 1 resulting SALs. */
12149 gdb_assert (canonical
.lsals
.size () < 2);
12151 if (!canonical
.lsals
.empty ())
12153 const linespec_sals
&lsal
= canonical
.lsals
[0];
12154 return std::move (lsal
.sals
);
12159 /* Virtual table for internal breakpoints. */
12162 internal_breakpoint::re_set ()
12166 /* Delete overlay event and longjmp master breakpoints; they
12167 will be reset later by breakpoint_re_set. */
12168 case bp_overlay_event
:
12169 case bp_longjmp_master
:
12170 case bp_std_terminate_master
:
12171 case bp_exception_master
:
12172 delete_breakpoint (this);
12175 /* This breakpoint is special, it's set up when the inferior
12176 starts and we really don't want to touch it. */
12177 case bp_shlib_event
:
12179 /* Like bp_shlib_event, this breakpoint type is special. Once
12180 it is set up, we do not want to touch it. */
12181 case bp_thread_event
:
12187 internal_breakpoint::check_status (bpstat
*bs
)
12189 if (type
== bp_shlib_event
)
12191 /* If requested, stop when the dynamic linker notifies GDB of
12192 events. This allows the user to get control and place
12193 breakpoints in initializer routines for dynamically loaded
12194 objects (among other things). */
12195 bs
->stop
= stop_on_solib_events
!= 0;
12196 bs
->print
= stop_on_solib_events
!= 0;
12202 enum print_stop_action
12203 internal_breakpoint::print_it (const bpstat
*bs
) const
12207 case bp_shlib_event
:
12208 /* Did we stop because the user set the stop_on_solib_events
12209 variable? (If so, we report this as a generic, "Stopped due
12210 to shlib event" message.) */
12211 print_solib_event (false);
12214 case bp_thread_event
:
12215 /* Not sure how we will get here.
12216 GDB should not stop for these breakpoints. */
12217 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
12220 case bp_overlay_event
:
12221 /* By analogy with the thread event, GDB should not stop for these. */
12222 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12225 case bp_longjmp_master
:
12226 /* These should never be enabled. */
12227 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12230 case bp_std_terminate_master
:
12231 /* These should never be enabled. */
12232 gdb_printf (_("std::terminate Master Breakpoint: "
12233 "gdb should not stop!\n"));
12236 case bp_exception_master
:
12237 /* These should never be enabled. */
12238 gdb_printf (_("Exception Master Breakpoint: "
12239 "gdb should not stop!\n"));
12243 return PRINT_NOTHING
;
12247 internal_breakpoint::print_mention () const
12249 /* Nothing to mention. These breakpoints are internal. */
12252 /* Virtual table for momentary breakpoints */
12255 momentary_breakpoint::re_set ()
12257 /* Keep temporary breakpoints, which can be encountered when we step
12258 over a dlopen call and solib_add is resetting the breakpoints.
12259 Otherwise these should have been blown away via the cleanup chain
12260 or by breakpoint_init_inferior when we rerun the executable. */
12264 momentary_breakpoint::check_status (bpstat
*bs
)
12266 /* Nothing. The point of these breakpoints is causing a stop. */
12269 enum print_stop_action
12270 momentary_breakpoint::print_it (const bpstat
*bs
) const
12272 return PRINT_UNKNOWN
;
12276 momentary_breakpoint::print_mention () const
12278 /* Nothing to mention. These breakpoints are internal. */
12281 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12283 It gets cleared already on the removal of the first one of such placed
12284 breakpoints. This is OK as they get all removed altogether. */
12286 longjmp_breakpoint::~longjmp_breakpoint ()
12288 thread_info
*tp
= find_thread_global_id (this->thread
);
12291 tp
->initiating_frame
= null_frame_id
;
12295 bkpt_probe_create_sals_from_location_spec (location_spec
*locspec
,
12296 struct linespec_result
*canonical
)
12299 struct linespec_sals lsal
;
12301 lsal
.sals
= parse_probes (locspec
, NULL
, canonical
);
12302 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12303 canonical
->lsals
.push_back (std::move (lsal
));
12306 static std::vector
<symtab_and_line
>
12307 bkpt_probe_decode_location_spec (struct breakpoint
*b
,
12308 location_spec
*locspec
,
12309 program_space
*search_pspace
)
12311 std::vector
<symtab_and_line
> sals
12312 = parse_probes (locspec
, search_pspace
, NULL
);
12314 error (_("probe not found"));
12319 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
12320 const address_space
*aspace
, CORE_ADDR bp_addr
,
12321 const target_waitstatus
&ws
)
12323 /* By definition, the inferior does not report stops at
12329 tracepoint::print_one_detail (struct ui_out
*uiout
) const
12331 if (!static_trace_marker_id
.empty ())
12333 gdb_assert (type
== bp_static_tracepoint
12334 || type
== bp_static_marker_tracepoint
);
12336 uiout
->message ("\tmarker id is %pF\n",
12337 string_field ("static-tracepoint-marker-string-id",
12338 static_trace_marker_id
.c_str ()));
12343 tracepoint::print_mention () const
12345 if (current_uiout
->is_mi_like_p ())
12350 case bp_tracepoint
:
12351 gdb_printf (_("Tracepoint"));
12352 gdb_printf (_(" %d"), number
);
12354 case bp_fast_tracepoint
:
12355 gdb_printf (_("Fast tracepoint"));
12356 gdb_printf (_(" %d"), number
);
12358 case bp_static_tracepoint
:
12359 case bp_static_marker_tracepoint
:
12360 gdb_printf (_("Static tracepoint"));
12361 gdb_printf (_(" %d"), number
);
12364 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12371 tracepoint::print_recreate (struct ui_file
*fp
) const
12373 if (type
== bp_fast_tracepoint
)
12374 gdb_printf (fp
, "ftrace");
12375 else if (type
== bp_static_tracepoint
12376 || type
== bp_static_marker_tracepoint
)
12377 gdb_printf (fp
, "strace");
12378 else if (type
== bp_tracepoint
)
12379 gdb_printf (fp
, "trace");
12381 internal_error (_("unhandled tracepoint type %d"), (int) type
);
12383 gdb_printf (fp
, " %s", locspec
->to_string ());
12384 print_recreate_thread (fp
);
12387 gdb_printf (fp
, " passcount %d\n", pass_count
);
12390 /* Virtual table for tracepoints on static probes. */
12393 tracepoint_probe_create_sals_from_location_spec
12394 (location_spec
*locspec
,
12395 struct linespec_result
*canonical
)
12397 /* We use the same method for breakpoint on probes. */
12398 bkpt_probe_create_sals_from_location_spec (locspec
, canonical
);
12402 dprintf_breakpoint::re_set ()
12406 /* extra_string should never be non-NULL for dprintf. */
12407 gdb_assert (extra_string
!= NULL
);
12409 /* 1 - connect to target 1, that can run breakpoint commands.
12410 2 - create a dprintf, which resolves fine.
12411 3 - disconnect from target 1
12412 4 - connect to target 2, that can NOT run breakpoint commands.
12414 After steps #3/#4, you'll want the dprintf command list to
12415 be updated, because target 1 and 2 may well return different
12416 answers for target_can_run_breakpoint_commands().
12417 Given absence of finer grained resetting, we get to do
12418 it all the time. */
12419 if (extra_string
!= NULL
)
12420 update_dprintf_command_list (this);
12423 /* Implement the "print_recreate" method for dprintf. */
12426 dprintf_breakpoint::print_recreate (struct ui_file
*fp
) const
12428 gdb_printf (fp
, "dprintf %s,%s", locspec
->to_string (), extra_string
.get ());
12429 print_recreate_thread (fp
);
12432 /* Implement the "after_condition_true" method for dprintf.
12434 dprintf's are implemented with regular commands in their command
12435 list, but we run the commands here instead of before presenting the
12436 stop to the user, as dprintf's don't actually cause a stop. This
12437 also makes it so that the commands of multiple dprintfs at the same
12438 address are all handled. */
12441 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
12443 /* dprintf's never cause a stop. This wasn't set in the
12444 check_status hook instead because that would make the dprintf's
12445 condition not be evaluated. */
12448 /* Run the command list here. Take ownership of it instead of
12449 copying. We never want these commands to run later in
12450 bpstat_do_actions, if a breakpoint that causes a stop happens to
12451 be set at same address as this dprintf, or even if running the
12452 commands here throws. */
12453 counted_command_line cmds
= std::move (bs
->commands
);
12454 gdb_assert (cmds
!= nullptr);
12455 execute_control_commands (cmds
.get (), 0);
12458 /* The breakpoint_ops structure to be used on static tracepoints with
12462 strace_marker_create_sals_from_location_spec (location_spec
*locspec
,
12463 struct linespec_result
*canonical
)
12465 struct linespec_sals lsal
;
12466 const char *arg_start
, *arg
;
12468 arg
= arg_start
= as_linespec_location_spec (locspec
)->spec_string
;
12469 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12471 std::string
str (arg_start
, arg
- arg_start
);
12472 const char *ptr
= str
.c_str ();
12474 = new_linespec_location_spec (&ptr
, symbol_name_match_type::FULL
);
12476 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12477 canonical
->lsals
.push_back (std::move (lsal
));
12481 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12482 struct linespec_result
*canonical
,
12483 gdb::unique_xmalloc_ptr
<char> cond_string
,
12484 gdb::unique_xmalloc_ptr
<char> extra_string
,
12485 enum bptype type_wanted
,
12486 enum bpdisp disposition
,
12488 int task
, int inferior
,
12490 int from_tty
, int enabled
,
12491 int internal
, unsigned flags
)
12493 const linespec_sals
&lsal
= canonical
->lsals
[0];
12495 /* If the user is creating a static tracepoint by marker id
12496 (strace -m MARKER_ID), then store the sals index, so that
12497 breakpoint_re_set can try to match up which of the newly
12498 found markers corresponds to this one, and, don't try to
12499 expand multiple locations for each sal, given than SALS
12500 already should contain all sals for MARKER_ID. */
12502 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12504 location_spec_up locspec
= canonical
->locspec
->clone ();
12506 std::unique_ptr
<tracepoint
> tp
12507 (new tracepoint (gdbarch
,
12510 std::move (locspec
),
12512 std::move (cond_string
),
12513 std::move (extra_string
),
12515 thread
, task
, inferior
, ignore_count
,
12516 from_tty
, enabled
, flags
,
12517 canonical
->special_display
));
12519 /* Given that its possible to have multiple markers with
12520 the same string id, if the user is creating a static
12521 tracepoint by marker id ("strace -m MARKER_ID"), then
12522 store the sals index, so that breakpoint_re_set can
12523 try to match up which of the newly found markers
12524 corresponds to this one */
12525 tp
->static_trace_marker_id_idx
= i
;
12527 install_breakpoint (internal
, std::move (tp
), 0);
12531 std::vector
<symtab_and_line
>
12532 static_marker_tracepoint::decode_location_spec (location_spec
*locspec
,
12533 program_space
*search_pspace
)
12535 const char *s
= as_linespec_location_spec (locspec
)->spec_string
;
12537 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12538 if (sals
.size () > static_trace_marker_id_idx
)
12540 sals
[0] = sals
[static_trace_marker_id_idx
];
12545 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12548 /* Static tracepoints with marker (`-m'). */
12549 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12551 strace_marker_create_sals_from_location_spec
,
12552 strace_marker_create_breakpoints_sal
,
12556 strace_marker_p (struct breakpoint
*b
)
12558 return b
->type
== bp_static_marker_tracepoint
;
12561 /* Notify interpreters and observers that breakpoint B was deleted. */
12564 notify_breakpoint_deleted (breakpoint
*b
)
12566 interps_notify_breakpoint_deleted (b
);
12567 gdb::observers::breakpoint_deleted
.notify (b
);
12570 /* Delete a breakpoint and clean up all traces of it in the data
12574 delete_breakpoint (struct breakpoint
*bpt
)
12576 gdb_assert (bpt
!= NULL
);
12578 /* Has this bp already been deleted? This can happen because
12579 multiple lists can hold pointers to bp's. bpstat lists are
12582 One example of this happening is a watchpoint's scope bp. When
12583 the scope bp triggers, we notice that the watchpoint is out of
12584 scope, and delete it. We also delete its scope bp. But the
12585 scope bp is marked "auto-deleting", and is already on a bpstat.
12586 That bpstat is then checked for auto-deleting bp's, which are
12589 A real solution to this problem might involve reference counts in
12590 bp's, and/or giving them pointers back to their referencing
12591 bpstat's, and teaching delete_breakpoint to only free a bp's
12592 storage when no more references were extent. A cheaper bandaid
12594 if (bpt
->type
== bp_none
)
12597 /* At least avoid this stale reference until the reference counting
12598 of breakpoints gets resolved. */
12599 if (bpt
->related_breakpoint
!= bpt
)
12601 struct breakpoint
*related
;
12602 struct watchpoint
*w
;
12604 if (bpt
->type
== bp_watchpoint_scope
)
12605 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12606 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12607 w
= (struct watchpoint
*) bpt
;
12611 watchpoint_del_at_next_stop (w
);
12613 /* Unlink bpt from the bpt->related_breakpoint ring. */
12614 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12615 related
= related
->related_breakpoint
);
12616 related
->related_breakpoint
= bpt
->related_breakpoint
;
12617 bpt
->related_breakpoint
= bpt
;
12620 /* watch_command_1 creates a watchpoint but only sets its number if
12621 update_watchpoint succeeds in creating its bp_locations. If there's
12622 a problem in that process, we'll be asked to delete the half-created
12623 watchpoint. In that case, don't announce the deletion. */
12625 notify_breakpoint_deleted (bpt
);
12627 breakpoint_chain
.erase (breakpoint_chain
.iterator_to (*bpt
));
12629 /* Be sure no bpstat's are pointing at the breakpoint after it's
12631 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12632 in all threads for now. Note that we cannot just remove bpstats
12633 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12634 commands are associated with the bpstat; if we remove it here,
12635 then the later call to bpstat_do_actions (&stop_bpstat); in
12636 event-top.c won't do anything, and temporary breakpoints with
12637 commands won't work. */
12639 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12641 /* Now that breakpoint is removed from breakpoint list, update the
12642 global location list. This will remove locations that used to
12643 belong to this breakpoint. Do this before freeing the breakpoint
12644 itself, since remove_breakpoint looks at location's owner. It
12645 might be better design to have location completely
12646 self-contained, but it's not the case now.
12648 Clear the location linked list first, otherwise, the intrusive_list
12649 destructor accesses the locations after they are freed. */
12650 bpt
->clear_locations ();
12651 update_global_location_list (UGLL_DONT_INSERT
);
12653 /* On the chance that someone will soon try again to delete this
12654 same bp, we mark it as deleted before freeing its storage. */
12655 bpt
->type
= bp_none
;
12659 /* Iterator function to call a user-provided callback function once
12660 for each of B and its related breakpoints. */
12663 iterate_over_related_breakpoints (struct breakpoint
*b
,
12664 gdb::function_view
<void (breakpoint
*)> function
)
12666 struct breakpoint
*related
;
12671 struct breakpoint
*next
;
12673 /* FUNCTION may delete RELATED. */
12674 next
= related
->related_breakpoint
;
12676 if (next
== related
)
12678 /* RELATED is the last ring entry. */
12679 function (related
);
12681 /* FUNCTION may have deleted it, so we'd never reach back to
12682 B. There's nothing left to do anyway, so just break
12687 function (related
);
12691 while (related
!= b
);
12695 delete_command (const char *arg
, int from_tty
)
12701 int breaks_to_delete
= 0;
12703 /* Delete all breakpoints if no argument. Do not delete
12704 internal breakpoints, these have to be deleted with an
12705 explicit breakpoint number argument. */
12706 for (breakpoint
&b
: all_breakpoints ())
12707 if (user_breakpoint_p (&b
))
12709 breaks_to_delete
= 1;
12713 /* Ask user only if there are some breakpoints to delete. */
12715 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12716 for (breakpoint
&b
: all_breakpoints_safe ())
12717 if (user_breakpoint_p (&b
))
12718 delete_breakpoint (&b
);
12721 map_breakpoint_numbers
12722 (arg
, [&] (breakpoint
*br
)
12724 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12728 /* Return true if all locations of B bound to PSPACE are pending. If
12729 PSPACE is NULL, all locations of all program spaces are
12733 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12735 for (bp_location
&loc
: b
->locations ())
12736 if ((pspace
== NULL
12737 || loc
.pspace
== pspace
)
12738 && !loc
.shlib_disabled
12739 && !loc
.pspace
->executing_startup
)
12744 /* Subroutine of update_breakpoint_locations to simplify it.
12745 Return true if multiple fns in list LOCS have the same name.
12746 Null names are ignored. */
12749 ambiguous_names_p (const bp_location_range
&locs
)
12751 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12754 for (const bp_location
&l
: locs
)
12757 const char *name
= l
.function_name
.get ();
12759 /* Allow for some names to be NULL, ignore them. */
12763 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12765 /* NOTE: We can assume slot != NULL here because xcalloc never
12775 /* When symbols change, it probably means the sources changed as well,
12776 and it might mean the static tracepoint markers are no longer at
12777 the same address or line numbers they used to be at last we
12778 checked. Losing your static tracepoints whenever you rebuild is
12779 undesirable. This function tries to resync/rematch gdb static
12780 tracepoints with the markers on the target, for static tracepoints
12781 that have not been set by marker id. Static tracepoint that have
12782 been set by marker id are reset by marker id in breakpoint_re_set.
12785 1) For a tracepoint set at a specific address, look for a marker at
12786 the old PC. If one is found there, assume to be the same marker.
12787 If the name / string id of the marker found is different from the
12788 previous known name, assume that means the user renamed the marker
12789 in the sources, and output a warning.
12791 2) For a tracepoint set at a given line number, look for a marker
12792 at the new address of the old line number. If one is found there,
12793 assume to be the same marker. If the name / string id of the
12794 marker found is different from the previous known name, assume that
12795 means the user renamed the marker in the sources, and output a
12798 3) If a marker is no longer found at the same address or line, it
12799 may mean the marker no longer exists. But it may also just mean
12800 the code changed a bit. Maybe the user added a few lines of code
12801 that made the marker move up or down (in line number terms). Ask
12802 the target for info about the marker with the string id as we knew
12803 it. If found, update line number and address in the matching
12804 static tracepoint. This will get confused if there's more than one
12805 marker with the same ID (possible in UST, although unadvised
12806 precisely because it confuses tools). */
12808 static struct symtab_and_line
12809 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12811 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12812 struct static_tracepoint_marker marker
;
12817 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12819 if (target_static_tracepoint_marker_at (pc
, &marker
))
12821 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12822 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12823 b
->number
, tp
->static_trace_marker_id
.c_str (),
12824 marker
.str_id
.c_str ());
12826 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12831 /* Old marker wasn't found on target at lineno. Try looking it up
12833 if (!sal
.explicit_pc
12835 && sal
.symtab
!= NULL
12836 && !tp
->static_trace_marker_id
.empty ())
12838 std::vector
<static_tracepoint_marker
> markers
12839 = target_static_tracepoint_markers_by_strid
12840 (tp
->static_trace_marker_id
.c_str ());
12842 if (!markers
.empty ())
12844 struct symbol
*sym
;
12845 struct static_tracepoint_marker
*tpmarker
;
12846 struct ui_out
*uiout
= current_uiout
;
12848 tpmarker
= &markers
[0];
12850 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12852 warning (_("marker for static tracepoint %d (%s) not "
12853 "found at previous line number"),
12854 b
->number
, tp
->static_trace_marker_id
.c_str ());
12856 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12857 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12858 uiout
->text ("Now in ");
12861 uiout
->field_string ("func", sym
->print_name (),
12862 function_name_style
.style ());
12863 uiout
->text (" at ");
12865 uiout
->field_string ("file",
12866 symtab_to_filename_for_display (sal2
.symtab
),
12867 file_name_style
.style ());
12870 if (uiout
->is_mi_like_p ())
12872 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12874 uiout
->field_string ("fullname", fullname
);
12877 uiout
->field_signed ("line", sal2
.line
);
12878 uiout
->text ("\n");
12880 b
->first_loc ().line_number
= sal2
.line
;
12881 b
->first_loc ().symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12883 std::unique_ptr
<explicit_location_spec
> els
12884 (new explicit_location_spec ());
12885 els
->source_filename
12886 = xstrdup (symtab_to_filename_for_display (sal2
.symtab
));
12887 els
->line_offset
.offset
= b
->first_loc ().line_number
;
12888 els
->line_offset
.sign
= LINE_OFFSET_NONE
;
12890 b
->locspec
= std::move (els
);
12892 /* Might be nice to check if function changed, and warn if
12899 /* Returns true iff location lists A and B are sufficiently same that
12900 we don't need to report breakpoint as changed. */
12903 locations_are_equal (const bp_location_list
&a
, const bp_location_range
&b
)
12905 auto a_iter
= a
.begin ();
12906 auto b_iter
= b
.begin ();
12908 for (; a_iter
!= a
.end () && b_iter
!= b
.end (); ++a_iter
, ++b_iter
)
12910 if (a_iter
->address
!= b_iter
->address
)
12913 if (a_iter
->shlib_disabled
!= b_iter
->shlib_disabled
)
12916 if (a_iter
->enabled
!= b_iter
->enabled
)
12919 if (a_iter
->disabled_by_cond
!= b_iter
->disabled_by_cond
)
12923 return (a_iter
== a
.end ()) == (b_iter
== b
.end ());
12926 /* See breakpoint.h. */
12929 breakpoint::steal_locations (program_space
*pspace
)
12931 if (pspace
== NULL
)
12932 return std::move (m_locations
);
12934 bp_location_list ret
;
12936 for (auto it
= m_locations
.begin (); it
!= m_locations
.end (); )
12938 if (it
->pspace
== pspace
)
12940 bp_location
&loc
= *it
;
12941 it
= m_locations
.erase (it
);
12942 ret
.push_back (loc
);
12951 /* Create new breakpoint locations for B (a hardware or software
12952 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12953 zero, then B is a ranged breakpoint. Only recreates locations for
12954 FILTER_PSPACE. Locations of other program spaces are left
12958 update_breakpoint_locations (code_breakpoint
*b
,
12959 struct program_space
*filter_pspace
,
12960 gdb::array_view
<const symtab_and_line
> sals
,
12961 gdb::array_view
<const symtab_and_line
> sals_end
)
12963 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12965 /* Ranged breakpoints have only one start location and one end
12967 b
->enable_state
= bp_disabled
;
12968 gdb_printf (gdb_stderr
,
12969 _("Could not reset ranged breakpoint %d: "
12970 "multiple locations found\n"),
12975 /* If there's no new locations, and all existing locations are
12976 pending, don't do anything. This optimizes the common case where
12977 all locations are in the same shared library, that was unloaded.
12978 We'd like to retain the location, so that when the library is
12979 loaded again, we don't loose the enabled/disabled status of the
12980 individual locations. */
12981 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12984 bp_location_list existing_locations
= b
->steal_locations (filter_pspace
);
12986 for (const auto &sal
: sals
)
12988 struct bp_location
*new_loc
;
12990 switch_to_program_space_and_thread (sal
.pspace
);
12992 new_loc
= b
->add_location (sal
);
12994 /* Reparse conditions, they might contain references to the
12996 if (b
->cond_string
!= NULL
)
13000 s
= b
->cond_string
.get ();
13003 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13004 block_for_pc (sal
.pc
),
13007 catch (const gdb_exception_error
&e
)
13009 new_loc
->disabled_by_cond
= true;
13013 if (!sals_end
.empty ())
13015 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13017 new_loc
->length
= end
- sals
[0].pc
+ 1;
13021 /* If possible, carry over 'disable' status from existing
13024 /* If there are multiple breakpoints with the same function name,
13025 e.g. for inline functions, comparing function names won't work.
13026 Instead compare pc addresses; this is just a heuristic as things
13027 may have moved, but in practice it gives the correct answer
13028 often enough until a better solution is found. */
13029 int have_ambiguous_names
= ambiguous_names_p (b
->locations ());
13031 for (const bp_location
&e
: existing_locations
)
13033 if ((!e
.enabled
|| e
.disabled_by_cond
) && e
.function_name
)
13035 if (have_ambiguous_names
)
13037 for (bp_location
&l
: b
->locations ())
13039 /* Ignore software vs hardware location type at
13040 this point, because with "set breakpoint
13041 auto-hw", after a re-set, locations that were
13042 hardware can end up as software, or vice versa.
13043 As mentioned above, this is an heuristic and in
13044 practice should give the correct answer often
13046 if (breakpoint_locations_match (&e
, &l
, true))
13048 l
.enabled
= e
.enabled
;
13049 l
.disabled_by_cond
= e
.disabled_by_cond
;
13056 for (bp_location
&l
: b
->locations ())
13057 if (l
.function_name
13058 && strcmp (e
.function_name
.get (),
13059 l
.function_name
.get ()) == 0)
13061 l
.enabled
= e
.enabled
;
13062 l
.disabled_by_cond
= e
.disabled_by_cond
;
13070 if (!locations_are_equal (existing_locations
, b
->locations ()))
13071 notify_breakpoint_modified (b
);
13074 /* Find the SaL locations corresponding to the given LOCSPEC.
13075 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13077 std::vector
<symtab_and_line
>
13078 code_breakpoint::location_spec_to_sals (location_spec
*locspec
,
13079 struct program_space
*search_pspace
,
13082 struct gdb_exception exception
;
13084 std::vector
<symtab_and_line
> sals
;
13088 sals
= decode_location_spec (locspec
, search_pspace
);
13090 catch (gdb_exception_error
&e
)
13092 int not_found_and_ok
= false;
13094 /* For pending breakpoints, it's expected that parsing will
13095 fail until the right shared library is loaded. User has
13096 already told to create pending breakpoints and don't need
13097 extra messages. If breakpoint is in bp_shlib_disabled
13098 state, then user already saw the message about that
13099 breakpoint being disabled, and don't want to see more
13101 if (e
.error
== NOT_FOUND_ERROR
13102 && (condition_not_parsed
13103 || (this->has_locations ()
13104 && search_pspace
!= NULL
13105 && this->first_loc ().pspace
!= search_pspace
)
13106 || (this->has_locations () && this->first_loc ().shlib_disabled
)
13107 || (this->has_locations ()
13108 && this->first_loc ().pspace
->executing_startup
)
13109 || enable_state
== bp_disabled
))
13110 not_found_and_ok
= true;
13112 if (!not_found_and_ok
)
13114 /* We surely don't want to warn about the same breakpoint
13115 10 times. One solution, implemented here, is disable
13116 the breakpoint on error. Another solution would be to
13117 have separate 'warning emitted' flag. Since this
13118 happens only when a binary has changed, I don't know
13119 which approach is better. */
13120 enable_state
= bp_disabled
;
13124 exception
= std::move (e
);
13127 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13129 for (auto &sal
: sals
)
13130 resolve_sal_pc (&sal
);
13131 if (condition_not_parsed
&& extra_string
!= NULL
)
13133 gdb::unique_xmalloc_ptr
<char> local_cond
, local_extra
;
13134 int local_thread
, local_task
, local_inferior
;
13136 find_condition_and_thread_for_sals (sals
, extra_string
.get (),
13137 &local_cond
, &local_thread
,
13139 &local_task
, &local_extra
);
13140 gdb_assert (cond_string
== nullptr);
13141 if (local_cond
!= nullptr)
13142 cond_string
= std::move (local_cond
);
13143 thread
= local_thread
;
13145 if (local_extra
!= nullptr)
13146 extra_string
= std::move (local_extra
);
13147 condition_not_parsed
= 0;
13150 if (type
== bp_static_tracepoint
)
13151 sals
[0] = update_static_tracepoint (this, sals
[0]);
13161 /* The default re_set method, for typical hardware or software
13162 breakpoints. Reevaluate the breakpoint and recreate its
13166 code_breakpoint::re_set_default ()
13168 struct program_space
*filter_pspace
= current_program_space
;
13169 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13172 std::vector
<symtab_and_line
> sals
= location_spec_to_sals (locspec
.get (),
13176 expanded
= std::move (sals
);
13178 if (locspec_range_end
!= nullptr)
13180 std::vector
<symtab_and_line
> sals_end
13181 = location_spec_to_sals (locspec_range_end
.get (),
13182 filter_pspace
, &found
);
13184 expanded_end
= std::move (sals_end
);
13187 update_breakpoint_locations (this, filter_pspace
, expanded
, expanded_end
);
13190 /* Default method for creating SALs from an address string. It basically
13191 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13194 create_sals_from_location_spec_default (location_spec
*locspec
,
13195 struct linespec_result
*canonical
)
13197 parse_breakpoint_sals (locspec
, canonical
);
13200 /* Reset a breakpoint. */
13203 breakpoint_re_set_one (breakpoint
*b
)
13205 input_radix
= b
->input_radix
;
13206 set_language (b
->language
);
13211 /* Re-set breakpoint locations for the current program space.
13212 Locations bound to other program spaces are left untouched. */
13215 breakpoint_re_set (void)
13218 scoped_restore_current_language save_language
;
13219 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13220 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13222 /* breakpoint_re_set_one sets the current_language to the language
13223 of the breakpoint it is resetting (see prepare_re_set_context)
13224 before re-evaluating the breakpoint's location. This change can
13225 unfortunately get undone by accident if the language_mode is set
13226 to auto, and we either switch frames, or more likely in this context,
13227 we select the current frame.
13229 We prevent this by temporarily turning the language_mode to
13230 language_mode_manual. We restore it once all breakpoints
13231 have been reset. */
13232 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13233 language_mode
= language_mode_manual
;
13235 /* Note: we must not try to insert locations until after all
13236 breakpoints have been re-set. Otherwise, e.g., when re-setting
13237 breakpoint 1, we'd insert the locations of breakpoint 2, which
13238 hadn't been re-set yet, and thus may have stale locations. */
13240 for (breakpoint
&b
: all_breakpoints_safe ())
13244 breakpoint_re_set_one (&b
);
13246 catch (const gdb_exception
&ex
)
13248 exception_fprintf (gdb_stderr
, ex
,
13249 "Error in re-setting breakpoint %d: ",
13254 jit_breakpoint_re_set ();
13257 create_overlay_event_breakpoint ();
13258 create_longjmp_master_breakpoint ();
13259 create_std_terminate_master_breakpoint ();
13260 create_exception_master_breakpoint ();
13262 /* Now we can insert. */
13263 update_global_location_list (UGLL_MAY_INSERT
);
13266 /* Reset the thread number of this breakpoint:
13268 - If the breakpoint is for all threads, leave it as-is.
13269 - Else, reset it to the current thread for inferior_ptid. */
13271 breakpoint_re_set_thread (struct breakpoint
*b
)
13273 if (b
->thread
!= -1)
13275 b
->thread
= inferior_thread ()->global_num
;
13277 /* We're being called after following a fork. The new fork is
13278 selected as current, and unless this was a vfork will have a
13279 different program space from the original thread. Reset that
13281 b
->first_loc ().pspace
= current_program_space
;
13285 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13286 If from_tty is nonzero, it prints a message to that effect,
13287 which ends with a period (no newline). */
13290 set_ignore_count (int bptnum
, int count
, int from_tty
)
13295 for (breakpoint
&b
: all_breakpoints ())
13296 if (b
.number
== bptnum
)
13298 if (is_tracepoint (&b
))
13300 if (from_tty
&& count
!= 0)
13301 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13306 b
.ignore_count
= count
;
13310 gdb_printf (_("Will stop next time "
13311 "breakpoint %d is reached."),
13313 else if (count
== 1)
13314 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13317 gdb_printf (_("Will ignore next %d "
13318 "crossings of breakpoint %d."),
13321 notify_breakpoint_modified (&b
);
13325 error (_("No breakpoint number %d."), bptnum
);
13328 /* Command to set ignore-count of breakpoint N to COUNT. */
13331 ignore_command (const char *args
, int from_tty
)
13333 const char *p
= args
;
13337 error_no_arg (_("a breakpoint number"));
13339 num
= get_number (&p
);
13341 error (_("bad breakpoint number: '%s'"), args
);
13343 error (_("Second argument (specified ignore-count) is missing."));
13345 set_ignore_count (num
,
13346 longest_to_int (value_as_long (parse_and_eval (p
))),
13353 /* Call FUNCTION on each of the breakpoints with numbers in the range
13354 defined by BP_NUM_RANGE (an inclusive range). */
13357 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13358 gdb::function_view
<void (breakpoint
*)> function
)
13360 if (bp_num_range
.first
== 0)
13362 warning (_("bad breakpoint number at or near '%d'"),
13363 bp_num_range
.first
);
13367 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13369 bool match
= false;
13371 for (breakpoint
&b
: all_breakpoints_safe ())
13379 gdb_printf (_("No breakpoint number %d.\n"), i
);
13384 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13388 map_breakpoint_numbers (const char *args
,
13389 gdb::function_view
<void (breakpoint
*)> function
)
13391 if (args
== NULL
|| *args
== '\0')
13392 error_no_arg (_("one or more breakpoint numbers"));
13394 number_or_range_parser
parser (args
);
13396 while (!parser
.finished ())
13398 int num
= parser
.get_number ();
13399 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13403 /* Return the breakpoint location structure corresponding to the
13404 BP_NUM and LOC_NUM values. */
13406 static struct bp_location
*
13407 find_location_by_number (int bp_num
, int loc_num
)
13409 breakpoint
*b
= get_breakpoint (bp_num
);
13411 if (!b
|| b
->number
!= bp_num
)
13412 error (_("Bad breakpoint number '%d'"), bp_num
);
13415 error (_("Bad breakpoint location number '%d'"), loc_num
);
13418 for (bp_location
&loc
: b
->locations ())
13419 if (++n
== loc_num
)
13422 error (_("Bad breakpoint location number '%d'"), loc_num
);
13425 /* Modes of operation for extract_bp_num. */
13426 enum class extract_bp_kind
13428 /* Extracting a breakpoint number. */
13431 /* Extracting a location number. */
13435 /* Extract a breakpoint or location number (as determined by KIND)
13436 from the string starting at START. TRAILER is a character which
13437 can be found after the number. If you don't want a trailer, use
13438 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13439 string. This always returns a positive integer. */
13442 extract_bp_num (extract_bp_kind kind
, const char *start
,
13443 int trailer
, const char **end_out
= NULL
)
13445 const char *end
= start
;
13446 int num
= get_number_trailer (&end
, trailer
);
13448 error (kind
== extract_bp_kind::bp
13449 ? _("Negative breakpoint number '%.*s'")
13450 : _("Negative breakpoint location number '%.*s'"),
13451 int (end
- start
), start
);
13453 error (kind
== extract_bp_kind::bp
13454 ? _("Bad breakpoint number '%.*s'")
13455 : _("Bad breakpoint location number '%.*s'"),
13456 int (end
- start
), start
);
13458 if (end_out
!= NULL
)
13463 /* Extract a breakpoint or location range (as determined by KIND) in
13464 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13465 representing the (inclusive) range. The returned pair's elements
13466 are always positive integers. */
13468 static std::pair
<int, int>
13469 extract_bp_or_bp_range (extract_bp_kind kind
,
13470 const std::string
&arg
,
13471 std::string::size_type arg_offset
)
13473 std::pair
<int, int> range
;
13474 const char *bp_loc
= &arg
[arg_offset
];
13475 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13476 if (dash
!= std::string::npos
)
13478 /* bp_loc is a range (x-z). */
13479 if (arg
.length () == dash
+ 1)
13480 error (kind
== extract_bp_kind::bp
13481 ? _("Bad breakpoint number at or near: '%s'")
13482 : _("Bad breakpoint location number at or near: '%s'"),
13486 const char *start_first
= bp_loc
;
13487 const char *start_second
= &arg
[dash
+ 1];
13488 range
.first
= extract_bp_num (kind
, start_first
, '-');
13489 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13491 if (range
.first
> range
.second
)
13492 error (kind
== extract_bp_kind::bp
13493 ? _("Inverted breakpoint range at '%.*s'")
13494 : _("Inverted breakpoint location range at '%.*s'"),
13495 int (end
- start_first
), start_first
);
13499 /* bp_loc is a single value. */
13500 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13501 range
.second
= range
.first
;
13506 /* Extract the breakpoint/location range specified by ARG. Returns
13507 the breakpoint range in BP_NUM_RANGE, and the location range in
13510 ARG may be in any of the following forms:
13512 x where 'x' is a breakpoint number.
13513 x-y where 'x' and 'y' specify a breakpoint numbers range.
13514 x.y where 'x' is a breakpoint number and 'y' a location number.
13515 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13516 location number range.
13520 extract_bp_number_and_location (const std::string
&arg
,
13521 std::pair
<int, int> &bp_num_range
,
13522 std::pair
<int, int> &bp_loc_range
)
13524 std::string::size_type dot
= arg
.find ('.');
13526 if (dot
!= std::string::npos
)
13528 /* Handle 'x.y' and 'x.y-z' cases. */
13530 if (arg
.length () == dot
+ 1 || dot
== 0)
13531 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13534 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13535 bp_num_range
.second
= bp_num_range
.first
;
13537 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13542 /* Handle x and x-y cases. */
13544 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13545 bp_loc_range
.first
= 0;
13546 bp_loc_range
.second
= 0;
13550 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13551 specifies whether to enable or disable. */
13554 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13556 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13559 if (loc
->disabled_by_cond
&& enable
)
13560 error (_("Breakpoint %d's condition is invalid at location %d, "
13561 "cannot enable."), bp_num
, loc_num
);
13563 if (loc
->enabled
!= enable
)
13565 loc
->enabled
= enable
;
13566 mark_breakpoint_location_modified (loc
);
13568 if (target_supports_enable_disable_tracepoint ()
13569 && current_trace_status ()->running
&& loc
->owner
13570 && is_tracepoint (loc
->owner
))
13571 target_disable_tracepoint (loc
);
13573 update_global_location_list (UGLL_DONT_INSERT
);
13575 notify_breakpoint_modified (loc
->owner
);
13578 /* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
13579 owner. 1-based indexing. -1 signals NOT FOUND. */
13582 find_loc_num_by_location (const bp_location
*loc
)
13584 if (loc
!= nullptr && loc
->owner
!= nullptr)
13586 /* Locations use 1-based indexing. */
13588 for (bp_location
&it
: loc
->owner
->locations ())
13598 /* Enable or disable a breakpoint location LOC. ENABLE
13599 specifies whether to enable or disable. */
13602 enable_disable_bp_location (bp_location
*loc
, bool enable
)
13604 if (loc
== nullptr)
13605 error (_("Breakpoint location is invalid."));
13607 if (loc
->owner
== nullptr)
13608 error (_("Breakpoint location does not have an owner breakpoint."));
13610 if (loc
->disabled_by_cond
&& enable
)
13612 int loc_num
= find_loc_num_by_location (loc
);
13614 error (_("Breakpoint location LOC_NUM could not be found."));
13616 error (_("Breakpoint %d's condition is invalid at location %d, "
13617 "cannot enable."), loc
->owner
->number
, loc_num
);
13620 if (loc
->enabled
!= enable
)
13622 loc
->enabled
= enable
;
13623 mark_breakpoint_location_modified (loc
);
13626 if (target_supports_enable_disable_tracepoint ()
13627 && current_trace_status ()->running
&& loc
->owner
13628 && is_tracepoint (loc
->owner
))
13629 target_disable_tracepoint (loc
);
13631 update_global_location_list (UGLL_DONT_INSERT
);
13632 notify_breakpoint_modified (loc
->owner
);
13635 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13636 number of the breakpoint, and BP_LOC_RANGE specifies the
13637 (inclusive) range of location numbers of that breakpoint to
13638 enable/disable. ENABLE specifies whether to enable or disable the
13642 enable_disable_breakpoint_location_range (int bp_num
,
13643 std::pair
<int, int> &bp_loc_range
,
13646 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13647 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13650 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13651 If from_tty is nonzero, it prints a message to that effect,
13652 which ends with a period (no newline). */
13655 disable_breakpoint (struct breakpoint
*bpt
)
13657 /* Never disable a watchpoint scope breakpoint; we want to
13658 hit them when we leave scope so we can delete both the
13659 watchpoint and its scope breakpoint at that time. */
13660 if (bpt
->type
== bp_watchpoint_scope
)
13663 bpt
->enable_state
= bp_disabled
;
13665 /* Mark breakpoint locations modified. */
13666 mark_breakpoint_modified (bpt
);
13668 if (target_supports_enable_disable_tracepoint ()
13669 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13671 for (bp_location
&location
: bpt
->locations ())
13672 target_disable_tracepoint (&location
);
13675 update_global_location_list (UGLL_DONT_INSERT
);
13677 notify_breakpoint_modified (bpt
);
13680 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13681 specified in ARGS. ARGS may be in any of the formats handled by
13682 extract_bp_number_and_location. ENABLE specifies whether to enable
13683 or disable the breakpoints/locations. */
13686 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13690 for (breakpoint
&bpt
: all_breakpoints ())
13691 if (user_breakpoint_p (&bpt
))
13694 enable_breakpoint (&bpt
);
13696 disable_breakpoint (&bpt
);
13701 std::string num
= extract_arg (&args
);
13703 while (!num
.empty ())
13705 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13707 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13709 if (bp_loc_range
.first
== bp_loc_range
.second
13710 && (bp_loc_range
.first
== 0
13711 || (bp_loc_range
.first
== 1
13712 && bp_num_range
.first
== bp_num_range
.second
13713 && !has_multiple_locations (bp_num_range
.first
))))
13715 /* Handle breakpoint ids with formats 'x' or 'x-z'
13716 or 'y.1' where y has only one code location. */
13717 map_breakpoint_number_range (bp_num_range
,
13719 ? enable_breakpoint
13720 : disable_breakpoint
);
13724 /* Handle breakpoint ids with formats 'x.y' or
13726 enable_disable_breakpoint_location_range
13727 (bp_num_range
.first
, bp_loc_range
, enable
);
13729 num
= extract_arg (&args
);
13734 /* The disable command disables the specified breakpoints/locations
13735 (or all defined breakpoints) so they're no longer effective in
13736 stopping the inferior. ARGS may be in any of the forms defined in
13737 extract_bp_number_and_location. */
13740 disable_command (const char *args
, int from_tty
)
13742 enable_disable_command (args
, from_tty
, false);
13746 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13749 int target_resources_ok
;
13751 if (bpt
->type
== bp_hardware_breakpoint
)
13754 i
= hw_breakpoint_used_count ();
13755 target_resources_ok
=
13756 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13758 if (target_resources_ok
== 0)
13759 error (_("No hardware breakpoint support in the target."));
13760 else if (target_resources_ok
< 0)
13761 error (_("Hardware breakpoints used exceeds limit."));
13764 if (is_watchpoint (bpt
))
13766 /* Initialize it just to avoid a GCC false warning. */
13767 enum enable_state orig_enable_state
= bp_disabled
;
13771 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13773 orig_enable_state
= bpt
->enable_state
;
13774 bpt
->enable_state
= bp_enabled
;
13775 update_watchpoint (w
, true /* reparse */);
13777 catch (const gdb_exception_error
&e
)
13779 bpt
->enable_state
= orig_enable_state
;
13780 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13786 bpt
->enable_state
= bp_enabled
;
13788 /* Mark breakpoint locations modified. */
13789 mark_breakpoint_modified (bpt
);
13791 if (target_supports_enable_disable_tracepoint ()
13792 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13794 for (bp_location
&location
: bpt
->locations ())
13795 target_enable_tracepoint (&location
);
13798 bpt
->disposition
= disposition
;
13799 bpt
->enable_count
= count
;
13800 update_global_location_list (UGLL_MAY_INSERT
);
13802 notify_breakpoint_modified (bpt
);
13807 enable_breakpoint (struct breakpoint
*bpt
)
13809 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13812 /* The enable command enables the specified breakpoints/locations (or
13813 all defined breakpoints) so they once again become (or continue to
13814 be) effective in stopping the inferior. ARGS may be in any of the
13815 forms defined in extract_bp_number_and_location. */
13818 enable_command (const char *args
, int from_tty
)
13820 enable_disable_command (args
, from_tty
, true);
13824 enable_once_command (const char *args
, int from_tty
)
13826 map_breakpoint_numbers
13827 (args
, [&] (breakpoint
*b
)
13829 iterate_over_related_breakpoints
13830 (b
, [&] (breakpoint
*bpt
)
13832 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13838 enable_count_command (const char *args
, int from_tty
)
13843 error_no_arg (_("hit count"));
13845 count
= get_number (&args
);
13847 map_breakpoint_numbers
13848 (args
, [&] (breakpoint
*b
)
13850 iterate_over_related_breakpoints
13851 (b
, [&] (breakpoint
*bpt
)
13853 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13859 enable_delete_command (const char *args
, int from_tty
)
13861 map_breakpoint_numbers
13862 (args
, [&] (breakpoint
*b
)
13864 iterate_over_related_breakpoints
13865 (b
, [&] (breakpoint
*bpt
)
13867 enable_breakpoint_disp (bpt
, disp_del
, 1);
13872 /* Invalidate last known value of any hardware watchpoint if
13873 the memory which that value represents has been written to by
13877 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13878 CORE_ADDR addr
, ssize_t len
,
13879 const bfd_byte
*data
)
13881 for (breakpoint
&bp
: all_breakpoints ())
13882 if (bp
.enable_state
== bp_enabled
13883 && bp
.type
== bp_hardware_watchpoint
)
13885 watchpoint
&wp
= gdb::checked_static_cast
<watchpoint
&> (bp
);
13887 if (wp
.val_valid
&& wp
.val
!= nullptr)
13889 for (bp_location
&loc
: bp
.locations ())
13890 if (loc
.loc_type
== bp_loc_hardware_watchpoint
13891 && loc
.address
+ loc
.length
> addr
13892 && addr
+ len
> loc
.address
)
13895 wp
.val_valid
= false;
13901 /* Create and insert a breakpoint for software single step. */
13904 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13905 const address_space
*aspace
,
13908 struct thread_info
*tp
= inferior_thread ();
13909 struct symtab_and_line sal
;
13910 CORE_ADDR pc
= next_pc
;
13912 if (tp
->control
.single_step_breakpoints
== NULL
)
13914 std::unique_ptr
<breakpoint
> b
13915 (new momentary_breakpoint (gdbarch
, bp_single_step
,
13916 current_program_space
,
13920 tp
->control
.single_step_breakpoints
13921 = add_to_breakpoint_chain (std::move (b
));
13924 sal
= find_pc_line (pc
, 0);
13926 sal
.section
= find_pc_overlay (pc
);
13927 sal
.explicit_pc
= 1;
13930 = (gdb::checked_static_cast
<momentary_breakpoint
*>
13931 (tp
->control
.single_step_breakpoints
));
13932 ss_bp
->add_location (sal
);
13934 update_global_location_list (UGLL_INSERT
);
13937 /* Insert single step breakpoints according to the current state. */
13940 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13942 struct regcache
*regcache
= get_current_regcache ();
13943 std::vector
<CORE_ADDR
> next_pcs
;
13945 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13947 if (!next_pcs
.empty ())
13949 frame_info_ptr frame
= get_current_frame ();
13950 const address_space
*aspace
= get_frame_address_space (frame
);
13952 for (CORE_ADDR pc
: next_pcs
)
13953 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13961 /* See breakpoint.h. */
13964 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13965 const address_space
*aspace
,
13968 for (bp_location
&loc
: bp
->locations ())
13970 && breakpoint_location_address_match (&loc
, aspace
, pc
))
13976 /* Check whether a software single-step breakpoint is inserted at
13980 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13983 for (breakpoint
&bpt
: all_breakpoints ())
13985 if (bpt
.type
== bp_single_step
13986 && breakpoint_has_location_inserted_here (&bpt
, aspace
, pc
))
13992 /* Tracepoint-specific operations. */
13994 /* Set tracepoint count to NUM. */
13996 set_tracepoint_count (int num
)
13998 tracepoint_count
= num
;
13999 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14003 trace_command (const char *arg
, int from_tty
)
14005 location_spec_up locspec
= string_to_location_spec (&arg
,
14007 const struct breakpoint_ops
*ops
= breakpoint_ops_for_location_spec
14008 (locspec
.get (), true /* is_tracepoint */);
14010 create_breakpoint (get_current_arch (),
14012 NULL
, -1, -1, arg
, false, 1 /* parse arg */,
14014 bp_tracepoint
/* type_wanted */,
14015 0 /* Ignore count */,
14016 pending_break_support
,
14020 0 /* internal */, 0);
14024 ftrace_command (const char *arg
, int from_tty
)
14026 location_spec_up locspec
= string_to_location_spec (&arg
,
14028 create_breakpoint (get_current_arch (),
14030 NULL
, -1, -1, arg
, false, 1 /* parse arg */,
14032 bp_fast_tracepoint
/* type_wanted */,
14033 0 /* Ignore count */,
14034 pending_break_support
,
14035 &code_breakpoint_ops
,
14038 0 /* internal */, 0);
14041 /* strace command implementation. Creates a static tracepoint. */
14044 strace_command (const char *arg
, int from_tty
)
14046 const struct breakpoint_ops
*ops
;
14047 location_spec_up locspec
;
14050 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14051 or with a normal static tracepoint. */
14052 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14054 ops
= &strace_marker_breakpoint_ops
;
14055 locspec
= new_linespec_location_spec (&arg
,
14056 symbol_name_match_type::FULL
);
14057 type
= bp_static_marker_tracepoint
;
14061 ops
= &code_breakpoint_ops
;
14062 locspec
= string_to_location_spec (&arg
, current_language
);
14063 type
= bp_static_tracepoint
;
14066 create_breakpoint (get_current_arch (),
14068 NULL
, -1, -1, arg
, false, 1 /* parse arg */,
14070 type
/* type_wanted */,
14071 0 /* Ignore count */,
14072 pending_break_support
,
14076 0 /* internal */, 0);
14079 /* Set up a fake reader function that gets command lines from a linked
14080 list that was acquired during tracepoint uploading. */
14082 static struct uploaded_tp
*this_utp
;
14083 static int next_cmd
;
14085 static const char *
14086 read_uploaded_action (std::string
&buffer
)
14088 char *rslt
= nullptr;
14090 if (next_cmd
< this_utp
->cmd_strings
.size ())
14092 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14099 /* Given information about a tracepoint as recorded on a target (which
14100 can be either a live system or a trace file), attempt to create an
14101 equivalent GDB tracepoint. This is not a reliable process, since
14102 the target does not necessarily have all the information used when
14103 the tracepoint was originally defined. */
14105 struct tracepoint
*
14106 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14108 const char *addr_str
;
14109 char small_buf
[100];
14110 struct tracepoint
*tp
;
14112 if (utp
->at_string
)
14113 addr_str
= utp
->at_string
.get ();
14116 /* In the absence of a source location, fall back to raw
14117 address. Since there is no way to confirm that the address
14118 means the same thing as when the trace was started, warn the
14120 warning (_("Uploaded tracepoint %d has no "
14121 "source location, using raw address"),
14123 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14124 addr_str
= small_buf
;
14127 /* There's not much we can do with a sequence of bytecodes. */
14128 if (utp
->cond
&& !utp
->cond_string
)
14129 warning (_("Uploaded tracepoint %d condition "
14130 "has no source form, ignoring it"),
14133 location_spec_up locspec
= string_to_location_spec (&addr_str
,
14135 if (!create_breakpoint (get_current_arch (),
14137 utp
->cond_string
.get (), -1, -1, addr_str
,
14138 false /* force_condition */,
14139 0 /* parse cond/thread */,
14141 utp
->type
/* type_wanted */,
14142 0 /* Ignore count */,
14143 pending_break_support
,
14144 &code_breakpoint_ops
,
14146 utp
->enabled
/* enabled */,
14148 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14151 /* Get the tracepoint we just created. */
14152 tp
= get_tracepoint (tracepoint_count
);
14153 gdb_assert (tp
!= NULL
);
14157 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14160 trace_pass_command (small_buf
, 0);
14163 /* If we have uploaded versions of the original commands, set up a
14164 special-purpose "reader" function and call the usual command line
14165 reader, then pass the result to the breakpoint command-setting
14167 if (!utp
->cmd_strings
.empty ())
14169 counted_command_line cmd_list
;
14174 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14176 breakpoint_set_commands (tp
, std::move (cmd_list
));
14178 else if (!utp
->actions
.empty ()
14179 || !utp
->step_actions
.empty ())
14180 warning (_("Uploaded tracepoint %d actions "
14181 "have no source form, ignoring them"),
14184 /* Copy any status information that might be available. */
14185 tp
->hit_count
= utp
->hit_count
;
14186 tp
->traceframe_usage
= utp
->traceframe_usage
;
14191 /* Print information on tracepoint number TPNUM_EXP, or all if
14195 info_tracepoints_command (const char *args
, int from_tty
)
14197 struct ui_out
*uiout
= current_uiout
;
14200 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14202 if (num_printed
== 0)
14204 if (args
== NULL
|| *args
== '\0')
14205 uiout
->message ("No tracepoints.\n");
14207 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14210 default_collect_info ();
14213 /* The 'enable trace' command enables tracepoints.
14214 Not supported by all targets. */
14216 enable_trace_command (const char *args
, int from_tty
)
14218 enable_command (args
, from_tty
);
14221 /* The 'disable trace' command disables tracepoints.
14222 Not supported by all targets. */
14224 disable_trace_command (const char *args
, int from_tty
)
14226 disable_command (args
, from_tty
);
14229 /* Remove a tracepoint (or all if no argument). */
14231 delete_trace_command (const char *arg
, int from_tty
)
14237 int breaks_to_delete
= 0;
14239 /* Delete all breakpoints if no argument.
14240 Do not delete internal or call-dummy breakpoints, these
14241 have to be deleted with an explicit breakpoint number
14243 for (breakpoint
&tp
: all_tracepoints ())
14244 if (is_tracepoint (&tp
) && user_breakpoint_p (&tp
))
14246 breaks_to_delete
= 1;
14250 /* Ask user only if there are some breakpoints to delete. */
14252 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14254 for (breakpoint
&b
: all_breakpoints_safe ())
14255 if (is_tracepoint (&b
) && user_breakpoint_p (&b
))
14256 delete_breakpoint (&b
);
14260 map_breakpoint_numbers
14261 (arg
, [&] (breakpoint
*br
)
14263 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14267 /* Helper function for trace_pass_command. */
14270 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14272 tp
->pass_count
= count
;
14273 notify_breakpoint_modified (tp
);
14275 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14276 tp
->number
, count
);
14279 /* Set passcount for tracepoint.
14281 First command argument is passcount, second is tracepoint number.
14282 If tracepoint number omitted, apply to most recently defined.
14283 Also accepts special argument "all". */
14286 trace_pass_command (const char *args
, int from_tty
)
14290 if (args
== 0 || *args
== 0)
14291 error (_("passcount command requires an "
14292 "argument (count + optional TP num)"));
14294 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14296 args
= skip_spaces (args
);
14297 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14299 args
+= 3; /* Skip special argument "all". */
14301 error (_("Junk at end of arguments."));
14303 for (breakpoint
&b
: all_tracepoints ())
14305 tracepoint
&t1
= gdb::checked_static_cast
<tracepoint
&> (b
);
14306 trace_pass_set_count (&t1
, count
, from_tty
);
14309 else if (*args
== '\0')
14311 tracepoint
*t1
= get_tracepoint_by_number (&args
, NULL
);
14313 trace_pass_set_count (t1
, count
, from_tty
);
14317 number_or_range_parser
parser (args
);
14318 while (!parser
.finished ())
14320 tracepoint
*t1
= get_tracepoint_by_number (&args
, &parser
);
14322 trace_pass_set_count (t1
, count
, from_tty
);
14327 struct tracepoint
*
14328 get_tracepoint (int num
)
14330 for (breakpoint
&t
: all_tracepoints ())
14331 if (t
.number
== num
)
14332 return gdb::checked_static_cast
<tracepoint
*> (&t
);
14337 /* Find the tracepoint with the given target-side number (which may be
14338 different from the tracepoint number after disconnecting and
14341 struct tracepoint
*
14342 get_tracepoint_by_number_on_target (int num
)
14344 for (breakpoint
&b
: all_tracepoints ())
14346 tracepoint
&t
= gdb::checked_static_cast
<tracepoint
&> (b
);
14348 if (t
.number_on_target
== num
)
14355 /* Utility: parse a tracepoint number and look it up in the list.
14356 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14357 If the argument is missing, the most recent tracepoint
14358 (tracepoint_count) is returned. */
14360 struct tracepoint
*
14361 get_tracepoint_by_number (const char **arg
,
14362 number_or_range_parser
*parser
)
14365 const char *instring
= arg
== NULL
? NULL
: *arg
;
14367 if (parser
!= NULL
)
14369 gdb_assert (!parser
->finished ());
14370 tpnum
= parser
->get_number ();
14372 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14373 tpnum
= tracepoint_count
;
14375 tpnum
= get_number (arg
);
14379 if (instring
&& *instring
)
14380 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14383 gdb_printf (_("No previous tracepoint\n"));
14387 for (breakpoint
&t
: all_tracepoints ())
14388 if (t
.number
== tpnum
)
14389 return gdb::checked_static_cast
<tracepoint
*> (&t
);
14391 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14396 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
14400 struct thread_info
*thr
= find_thread_global_id (thread
);
14401 gdb_printf (fp
, " thread %s", print_full_thread_id (thr
));
14405 gdb_printf (fp
, " task %d", task
);
14407 gdb_printf (fp
, "\n");
14410 /* Save information on user settable breakpoints (watchpoints, etc) to
14411 a new script file named FILENAME. If FILTER is non-NULL, call it
14412 on each breakpoint and only include the ones for which it returns
14416 save_breakpoints (const char *filename
, int from_tty
,
14417 bool (*filter
) (const struct breakpoint
*))
14420 int extra_trace_bits
= 0;
14422 if (filename
== 0 || *filename
== 0)
14423 error (_("Argument required (file name in which to save)"));
14425 /* See if we have anything to save. */
14426 for (breakpoint
&tp
: all_breakpoints ())
14428 /* Skip internal and momentary breakpoints. */
14429 if (!user_breakpoint_p (&tp
))
14432 /* If we have a filter, only save the breakpoints it accepts. */
14433 if (filter
&& !filter (&tp
))
14438 if (is_tracepoint (&tp
))
14440 extra_trace_bits
= 1;
14442 /* We can stop searching. */
14449 warning (_("Nothing to save."));
14453 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14457 if (!fp
.open (expanded_filename
.get (), "w"))
14458 error (_("Unable to open file '%s' for saving (%s)"),
14459 expanded_filename
.get (), safe_strerror (errno
));
14461 if (extra_trace_bits
)
14462 save_trace_state_variables (&fp
);
14464 for (breakpoint
&tp
: all_breakpoints ())
14466 /* Skip internal and momentary breakpoints. */
14467 if (!user_breakpoint_p (&tp
))
14470 /* If we have a filter, only save the breakpoints it accepts. */
14471 if (filter
&& !filter (&tp
))
14474 tp
.print_recreate (&fp
);
14476 /* Note, we can't rely on tp->number for anything, as we can't
14477 assume the recreated breakpoint numbers will match. Use $bpnum
14480 if (tp
.cond_string
)
14481 fp
.printf (" condition $bpnum %s\n", tp
.cond_string
.get ());
14483 if (tp
.ignore_count
)
14484 fp
.printf (" ignore $bpnum %d\n", tp
.ignore_count
);
14486 if (tp
.type
!= bp_dprintf
&& tp
.commands
)
14488 fp
.puts (" commands\n");
14490 ui_out_redirect_pop
redir (current_uiout
, &fp
);
14491 print_command_lines (current_uiout
, tp
.commands
.get (), 2);
14493 fp
.puts (" end\n");
14496 if (tp
.enable_state
== bp_disabled
)
14497 fp
.puts ("disable $bpnum\n");
14499 /* If this is a multi-location breakpoint, check if the locations
14500 should be individually disabled. Watchpoint locations are
14501 special, and not user visible. */
14502 if (!is_watchpoint (&tp
) && tp
.has_multiple_locations ())
14506 for (bp_location
&loc
: tp
.locations ())
14509 fp
.printf ("disable $bpnum.%d\n", n
);
14516 if (extra_trace_bits
&& !default_collect
.empty ())
14517 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14520 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14523 /* The `save breakpoints' command. */
14526 save_breakpoints_command (const char *args
, int from_tty
)
14528 save_breakpoints (args
, from_tty
, NULL
);
14531 /* The `save tracepoints' command. */
14534 save_tracepoints_command (const char *args
, int from_tty
)
14536 save_breakpoints (args
, from_tty
, is_tracepoint
);
14540 /* This help string is used to consolidate all the help string for specifying
14541 locations used by several commands. */
14543 #define LOCATION_SPEC_HELP_STRING \
14544 "Linespecs are colon-separated lists of location parameters, such as\n\
14545 source filename, function name, label name, and line number.\n\
14546 Example: To specify the start of a label named \"the_top\" in the\n\
14547 function \"fact\" in the file \"factorial.c\", use\n\
14548 \"factorial.c:fact:the_top\".\n\
14550 Address locations begin with \"*\" and specify an exact address in the\n\
14551 program. Example: To specify the fourth byte past the start function\n\
14552 \"main\", use \"*main + 4\".\n\
14554 Explicit locations are similar to linespecs but use an option/argument\n\
14555 syntax to specify location parameters.\n\
14556 Example: To specify the start of the label named \"the_top\" in the\n\
14557 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14558 -function fact -label the_top\".\n\
14560 By default, a specified function is matched against the program's\n\
14561 functions in all scopes. For C++, this means in all namespaces and\n\
14562 classes. For Ada, this means in all packages. E.g., in C++,\n\
14563 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14564 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14565 specified name as a complete fully-qualified name instead."
14567 /* This help string is used for the break, hbreak, tbreak and thbreak
14568 commands. It is defined as a macro to prevent duplication.
14569 COMMAND should be a string constant containing the name of the
14572 #define BREAK_ARGS_HELP(command) \
14573 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14574 \t[-force-condition] [if CONDITION]\n\
14575 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14576 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14577 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14578 `-probe-dtrace' (for a DTrace probe).\n\
14579 LOCATION may be a linespec, address, or explicit location as described\n\
14582 With no LOCATION, uses current execution address of the selected\n\
14583 stack frame. This is useful for breaking on return to a stack frame.\n\
14585 THREADNUM is the number from \"info threads\".\n\
14586 CONDITION is a boolean expression.\n\
14588 With the \"-force-condition\" flag, the condition is defined even when\n\
14589 it is invalid for all current locations.\n\
14590 \n" LOCATION_SPEC_HELP_STRING "\n\n\
14591 Multiple breakpoints at one place are permitted, and useful if their\n\
14592 conditions are different.\n\
14594 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14596 /* List of subcommands for "catch". */
14597 static struct cmd_list_element
*catch_cmdlist
;
14599 /* List of subcommands for "tcatch". */
14600 static struct cmd_list_element
*tcatch_cmdlist
;
14603 add_catch_command (const char *name
, const char *docstring
,
14604 cmd_func_ftype
*func
,
14605 completer_ftype
*completer
,
14606 void *user_data_catch
,
14607 void *user_data_tcatch
)
14609 struct cmd_list_element
*command
;
14611 command
= add_cmd (name
, class_breakpoint
, docstring
,
14613 command
->func
= func
;
14614 command
->set_context (user_data_catch
);
14615 set_cmd_completer (command
, completer
);
14617 command
= add_cmd (name
, class_breakpoint
, docstring
,
14619 command
->func
= func
;
14620 command
->set_context (user_data_tcatch
);
14621 set_cmd_completer (command
, completer
);
14624 /* False if any of the breakpoint's locations could be a location where
14625 functions have been inlined, true otherwise. */
14628 is_non_inline_function (struct breakpoint
*b
)
14630 /* The shared library event breakpoint is set on the address of a
14631 non-inline function. */
14632 return (b
->type
== bp_shlib_event
);
14635 /* Nonzero if the specified PC cannot be a location where functions
14636 have been inlined. */
14639 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14640 const target_waitstatus
&ws
)
14642 for (breakpoint
&b
: all_breakpoints ())
14644 if (!is_non_inline_function (&b
))
14647 for (bp_location
&bl
: b
.locations ())
14649 if (!bl
.shlib_disabled
14650 && bpstat_check_location (&bl
, aspace
, pc
, ws
))
14658 /* Remove any references to OBJFILE which is going to be freed. */
14661 breakpoint_free_objfile (struct objfile
*objfile
)
14663 for (bp_location
*loc
: all_bp_locations ())
14664 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14665 loc
->symtab
= NULL
;
14668 /* Chain containing all defined "enable breakpoint" subcommands. */
14670 static struct cmd_list_element
*enablebreaklist
= NULL
;
14672 /* See breakpoint.h. */
14674 cmd_list_element
*commands_cmd_element
= nullptr;
14676 void _initialize_breakpoint ();
14678 _initialize_breakpoint ()
14680 struct cmd_list_element
*c
;
14682 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14684 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14686 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14689 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14690 before a breakpoint is set. */
14691 breakpoint_count
= 0;
14693 tracepoint_count
= 0;
14695 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14696 Set ignore-count of breakpoint number N to COUNT.\n\
14697 Usage is `ignore N COUNT'."));
14699 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14700 commands_command
, _("\
14701 Set commands to be executed when the given breakpoints are hit.\n\
14702 Give a space-separated breakpoint list as argument after \"commands\".\n\
14703 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14705 With no argument, the targeted breakpoint is the last one set.\n\
14706 The commands themselves follow starting on the next line.\n\
14707 Type a line containing \"end\" to indicate the end of them.\n\
14708 Give \"silent\" as the first line to make the breakpoint silent;\n\
14709 then no output is printed when it is hit, except what the commands print."));
14711 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14712 static std::string condition_command_help
14713 = gdb::option::build_help (_("\
14714 Specify breakpoint number N to break only if COND is true.\n\
14715 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14716 is an expression to be evaluated whenever breakpoint N is reached.\n\
14719 %OPTIONS%"), cc_opts
);
14721 c
= add_com ("condition", class_breakpoint
, condition_command
,
14722 condition_command_help
.c_str ());
14723 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14725 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14726 Set a temporary breakpoint.\n\
14727 Like \"break\" except the breakpoint is only temporary,\n\
14728 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14729 by using \"enable delete\" on the breakpoint number.\n\
14731 BREAK_ARGS_HELP ("tbreak")));
14732 set_cmd_completer (c
, location_completer
);
14734 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14735 Set a hardware assisted breakpoint.\n\
14736 Like \"break\" except the breakpoint requires hardware support,\n\
14737 some target hardware may not have this support.\n\
14739 BREAK_ARGS_HELP ("hbreak")));
14740 set_cmd_completer (c
, location_completer
);
14742 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14743 Set a temporary hardware assisted breakpoint.\n\
14744 Like \"hbreak\" except the breakpoint is only temporary,\n\
14745 so it will be deleted when hit.\n\
14747 BREAK_ARGS_HELP ("thbreak")));
14748 set_cmd_completer (c
, location_completer
);
14750 cmd_list_element
*enable_cmd
14751 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14752 Enable all or some breakpoints.\n\
14753 Usage: enable [BREAKPOINTNUM]...\n\
14754 Give breakpoint numbers (separated by spaces) as arguments.\n\
14755 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14756 This is used to cancel the effect of the \"disable\" command.\n\
14757 With a subcommand you can enable temporarily."),
14758 &enablelist
, 1, &cmdlist
);
14760 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14762 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14763 Enable all or some breakpoints.\n\
14764 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14765 Give breakpoint numbers (separated by spaces) as arguments.\n\
14766 This is used to cancel the effect of the \"disable\" command.\n\
14767 May be abbreviated to simply \"enable\"."),
14768 &enablebreaklist
, 1, &enablelist
);
14770 add_cmd ("once", no_class
, enable_once_command
, _("\
14771 Enable some breakpoints for one hit.\n\
14772 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14773 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14776 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14777 Enable some breakpoints and delete when hit.\n\
14778 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14779 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14782 add_cmd ("count", no_class
, enable_count_command
, _("\
14783 Enable some breakpoints for COUNT hits.\n\
14784 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14785 If a breakpoint is hit while enabled in this fashion,\n\
14786 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14789 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14790 Enable some breakpoints and delete when hit.\n\
14791 Usage: enable delete BREAKPOINTNUM...\n\
14792 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14795 add_cmd ("once", no_class
, enable_once_command
, _("\
14796 Enable some breakpoints for one hit.\n\
14797 Usage: enable once BREAKPOINTNUM...\n\
14798 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14801 add_cmd ("count", no_class
, enable_count_command
, _("\
14802 Enable some breakpoints for COUNT hits.\n\
14803 Usage: enable count COUNT BREAKPOINTNUM...\n\
14804 If a breakpoint is hit while enabled in this fashion,\n\
14805 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14808 cmd_list_element
*disable_cmd
14809 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14810 Disable all or some breakpoints.\n\
14811 Usage: disable [BREAKPOINTNUM]...\n\
14812 Arguments are breakpoint numbers with spaces in between.\n\
14813 To disable all breakpoints, give no argument.\n\
14814 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14815 &disablelist
, 1, &cmdlist
);
14816 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14817 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14819 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14820 Disable all or some breakpoints.\n\
14821 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14822 Arguments are breakpoint numbers with spaces in between.\n\
14823 To disable all breakpoints, give no argument.\n\
14824 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14825 This command may be abbreviated \"disable\"."),
14828 cmd_list_element
*delete_cmd
14829 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14830 Delete all or some breakpoints.\n\
14831 Usage: delete [BREAKPOINTNUM]...\n\
14832 Arguments are breakpoint numbers with spaces in between.\n\
14833 To delete all breakpoints, give no argument.\n\
14835 Also a prefix command for deletion of other GDB objects."),
14836 &deletelist
, 1, &cmdlist
);
14837 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14838 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14840 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14841 Delete all or some breakpoints or auto-display expressions.\n\
14842 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14843 Arguments are breakpoint numbers with spaces in between.\n\
14844 To delete all breakpoints, give no argument.\n\
14845 This command may be abbreviated \"delete\"."),
14848 cmd_list_element
*clear_cmd
14849 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14850 Clear breakpoint at specified location.\n\
14851 Argument may be a linespec, explicit, or address location as described below.\n\
14853 With no argument, clears all breakpoints in the line that the selected frame\n\
14854 is executing in.\n"
14855 "\n" LOCATION_SPEC_HELP_STRING
"\n\n\
14856 See also the \"delete\" command which clears breakpoints by number."));
14857 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14859 cmd_list_element
*break_cmd
14860 = add_com ("break", class_breakpoint
, break_command
, _("\
14861 Set breakpoint at specified location.\n"
14862 BREAK_ARGS_HELP ("break")));
14863 set_cmd_completer (break_cmd
, location_completer
);
14865 add_com_alias ("b", break_cmd
, class_run
, 1);
14866 add_com_alias ("br", break_cmd
, class_run
, 1);
14867 add_com_alias ("bre", break_cmd
, class_run
, 1);
14868 add_com_alias ("brea", break_cmd
, class_run
, 1);
14870 cmd_list_element
*info_breakpoints_cmd
14871 = add_info ("breakpoints", info_breakpoints_command
, _("\
14872 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14873 The \"Type\" column indicates one of:\n\
14874 \tbreakpoint - normal breakpoint\n\
14875 \twatchpoint - watchpoint\n\
14876 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14877 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14878 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14879 address and file/line number respectively.\n\
14881 Convenience variable \"$_\" and default examine address for \"x\"\n\
14882 are set to the address of the last breakpoint listed unless the command\n\
14883 is prefixed with \"server \".\n\n\
14884 Convenience variable \"$bpnum\" contains the number of the last\n\
14885 breakpoint set."));
14887 add_info_alias ("b", info_breakpoints_cmd
, 1);
14889 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14890 Status of all breakpoints, or breakpoint number NUMBER.\n\
14891 The \"Type\" column indicates one of:\n\
14892 \tbreakpoint - normal breakpoint\n\
14893 \twatchpoint - watchpoint\n\
14894 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14895 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14896 \tuntil - internal breakpoint used by the \"until\" command\n\
14897 \tfinish - internal breakpoint used by the \"finish\" command\n\
14898 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14899 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14900 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14901 address and file/line number respectively.\n\
14903 Convenience variable \"$_\" and default examine address for \"x\"\n\
14904 are set to the address of the last breakpoint listed unless the command\n\
14905 is prefixed with \"server \".\n\n\
14906 Convenience variable \"$bpnum\" contains the number of the last\n\
14908 &maintenanceinfolist
);
14910 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14911 Set catchpoints to catch events."),
14913 0/*allow-unknown*/, &cmdlist
);
14915 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14916 Set temporary catchpoints to catch events."),
14918 0/*allow-unknown*/, &cmdlist
);
14920 const auto opts
= make_watch_options_def_group (nullptr);
14922 static const std::string watch_help
= gdb::option::build_help (_("\
14923 Set a watchpoint for EXPRESSION.\n\
14924 Usage: watch [-location] EXPRESSION\n\
14929 A watchpoint stops execution of your program whenever the value of\n\
14930 an expression changes."), opts
);
14931 c
= add_com ("watch", class_breakpoint
, watch_command
,
14932 watch_help
.c_str ());
14933 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14935 static const std::string rwatch_help
= gdb::option::build_help (_("\
14936 Set a read watchpoint for EXPRESSION.\n\
14937 Usage: rwatch [-location] EXPRESSION\n\
14942 A read watchpoint stops execution of your program whenever the value of\n\
14943 an expression is read."), opts
);
14944 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14945 rwatch_help
.c_str ());
14946 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14948 static const std::string awatch_help
= gdb::option::build_help (_("\
14949 Set an access watchpoint for EXPRESSION.\n\
14950 Usage: awatch [-location] EXPRESSION\n\
14955 An access watchpoint stops execution of your program whenever the value\n\
14956 of an expression is either read or written."), opts
);
14957 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14958 awatch_help
.c_str ());
14959 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14961 add_info ("watchpoints", info_watchpoints_command
, _("\
14962 Status of specified watchpoints (all watchpoints if no argument)."));
14964 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14965 respond to changes - contrary to the description. */
14966 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14967 &can_use_hw_watchpoints
, _("\
14968 Set debugger's willingness to use watchpoint hardware."), _("\
14969 Show debugger's willingness to use watchpoint hardware."), _("\
14970 If zero, gdb will not use hardware for new watchpoints, even if\n\
14971 such is available. (However, any hardware watchpoints that were\n\
14972 created before setting this to nonzero, will continue to use watchpoint\n\
14975 show_can_use_hw_watchpoints
,
14976 &setlist
, &showlist
);
14978 can_use_hw_watchpoints
= 1;
14980 /* Tracepoint manipulation commands. */
14982 cmd_list_element
*trace_cmd
14983 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14984 Set a tracepoint at specified location.\n\
14986 BREAK_ARGS_HELP ("trace") "\n\
14987 Do \"help tracepoints\" for info on other tracepoint commands."));
14988 set_cmd_completer (trace_cmd
, location_completer
);
14990 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14991 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14992 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14993 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14995 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14996 Set a fast tracepoint at specified location.\n\
14998 BREAK_ARGS_HELP ("ftrace") "\n\
14999 Do \"help tracepoints\" for info on other tracepoint commands."));
15000 set_cmd_completer (c
, location_completer
);
15002 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15003 Set a static tracepoint at location or marker.\n\
15005 strace [LOCATION] [if CONDITION]\n\
15006 LOCATION may be a linespec, explicit, or address location (described below) \n\
15007 or -m MARKER_ID.\n\n\
15008 If a marker id is specified, probe the marker with that name. With\n\
15009 no LOCATION, uses current execution address of the selected stack frame.\n\
15010 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15011 This collects arbitrary user data passed in the probe point call to the\n\
15012 tracing library. You can inspect it when analyzing the trace buffer,\n\
15013 by printing the $_sdata variable like any other convenience variable.\n\
15015 CONDITION is a boolean expression.\n\
15016 \n" LOCATION_SPEC_HELP_STRING
"\n\n\
15017 Multiple tracepoints at one place are permitted, and useful if their\n\
15018 conditions are different.\n\
15020 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15021 Do \"help tracepoints\" for info on other tracepoint commands."));
15022 set_cmd_completer (c
, location_completer
);
15024 cmd_list_element
*info_tracepoints_cmd
15025 = add_info ("tracepoints", info_tracepoints_command
, _("\
15026 Status of specified tracepoints (all tracepoints if no argument).\n\
15027 Convenience variable \"$tpnum\" contains the number of the\n\
15028 last tracepoint set."));
15030 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15032 cmd_list_element
*delete_tracepoints_cmd
15033 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15034 Delete specified tracepoints.\n\
15035 Arguments are tracepoint numbers, separated by spaces.\n\
15036 No argument means delete all tracepoints."),
15038 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15040 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15041 Disable specified tracepoints.\n\
15042 Arguments are tracepoint numbers, separated by spaces.\n\
15043 No argument means disable all tracepoints."),
15045 deprecate_cmd (c
, "disable");
15047 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15048 Enable specified tracepoints.\n\
15049 Arguments are tracepoint numbers, separated by spaces.\n\
15050 No argument means enable all tracepoints."),
15052 deprecate_cmd (c
, "enable");
15054 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15055 Set the passcount for a tracepoint.\n\
15056 The trace will end when the tracepoint has been passed 'count' times.\n\
15057 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15058 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15060 add_basic_prefix_cmd ("save", class_breakpoint
,
15061 _("Save breakpoint definitions as a script."),
15063 0/*allow-unknown*/, &cmdlist
);
15065 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15066 Save current breakpoint definitions as a script.\n\
15067 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15068 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15069 session to restore them."),
15071 set_cmd_completer (c
, filename_completer
);
15073 cmd_list_element
*save_tracepoints_cmd
15074 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15075 Save current tracepoint definitions as a script.\n\
15076 Use the 'source' command in another debug session to restore them."),
15078 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15080 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15081 deprecate_cmd (c
, "save tracepoints");
15083 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
15085 Breakpoint specific settings.\n\
15086 Configure various breakpoint-specific variables such as\n\
15087 pending breakpoint behavior."),
15089 Breakpoint specific settings.\n\
15090 Configure various breakpoint-specific variables such as\n\
15091 pending breakpoint behavior."),
15092 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
15093 &setlist
, &showlist
);
15095 add_setshow_auto_boolean_cmd ("pending", no_class
,
15096 &pending_break_support
, _("\
15097 Set debugger's behavior regarding pending breakpoints."), _("\
15098 Show debugger's behavior regarding pending breakpoints."), _("\
15099 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15100 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15101 an error. If auto, an unrecognized breakpoint location results in a\n\
15102 user-query to see if a pending breakpoint should be created."),
15104 show_pending_break_support
,
15105 &breakpoint_set_cmdlist
,
15106 &breakpoint_show_cmdlist
);
15108 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15110 add_setshow_boolean_cmd ("auto-hw", no_class
,
15111 &automatic_hardware_breakpoints
, _("\
15112 Set automatic usage of hardware breakpoints."), _("\
15113 Show automatic usage of hardware breakpoints."), _("\
15114 If set, the debugger will automatically use hardware breakpoints for\n\
15115 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15116 a warning will be emitted for such breakpoints."),
15118 show_automatic_hardware_breakpoints
,
15119 &breakpoint_set_cmdlist
,
15120 &breakpoint_show_cmdlist
);
15122 add_setshow_boolean_cmd ("always-inserted", class_support
,
15123 &always_inserted_mode
, _("\
15124 Set mode for inserting breakpoints."), _("\
15125 Show mode for inserting breakpoints."), _("\
15126 When this mode is on, breakpoints are inserted immediately as soon as\n\
15127 they're created, kept inserted even when execution stops, and removed\n\
15128 only when the user deletes them. When this mode is off (the default),\n\
15129 breakpoints are inserted only when execution continues, and removed\n\
15130 when execution stops."),
15132 &show_always_inserted_mode
,
15133 &breakpoint_set_cmdlist
,
15134 &breakpoint_show_cmdlist
);
15136 add_setshow_boolean_cmd ("breakpoint", class_maintenance
,
15137 &debug_breakpoint
, _("\
15138 Set breakpoint location debugging."), _("\
15139 Show breakpoint location debugging."), _("\
15140 When on, breakpoint location specific debugging is enabled."),
15142 show_debug_breakpoint
,
15143 &setdebuglist
, &showdebuglist
);
15145 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15146 condition_evaluation_enums
,
15147 &condition_evaluation_mode_1
, _("\
15148 Set mode of breakpoint condition evaluation."), _("\
15149 Show mode of breakpoint condition evaluation."), _("\
15150 When this is set to \"host\", breakpoint conditions will be\n\
15151 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15152 breakpoint conditions will be downloaded to the target (if the target\n\
15153 supports such feature) and conditions will be evaluated on the target's side.\n\
15154 If this is set to \"auto\" (default), this will be automatically set to\n\
15155 \"target\" if it supports condition evaluation, otherwise it will\n\
15156 be set to \"host\"."),
15157 &set_condition_evaluation_mode
,
15158 &show_condition_evaluation_mode
,
15159 &breakpoint_set_cmdlist
,
15160 &breakpoint_show_cmdlist
);
15162 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15163 Set a breakpoint for an address range.\n\
15164 break-range START-LOCATION, END-LOCATION\n\
15165 where START-LOCATION and END-LOCATION can be one of the following:\n\
15166 LINENUM, for that line in the current file,\n\
15167 FILE:LINENUM, for that line in that file,\n\
15168 +OFFSET, for that number of lines after the current line\n\
15169 or the start of the range\n\
15170 FUNCTION, for the first line in that function,\n\
15171 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15172 *ADDRESS, for the instruction at that address.\n\
15174 The breakpoint will stop execution of the inferior whenever it executes\n\
15175 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15176 range (including START-LOCATION and END-LOCATION)."));
15178 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15179 Set a dynamic printf at specified location.\n\
15180 dprintf location,format string,arg1,arg2,...\n\
15181 location may be a linespec, explicit, or address location.\n"
15182 "\n" LOCATION_SPEC_HELP_STRING
));
15183 set_cmd_completer (c
, location_completer
);
15185 add_setshow_enum_cmd ("dprintf-style", class_support
,
15186 dprintf_style_enums
, &dprintf_style
, _("\
15187 Set the style of usage for dynamic printf."), _("\
15188 Show the style of usage for dynamic printf."), _("\
15189 This setting chooses how GDB will do a dynamic printf.\n\
15190 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15191 console, as with the \"printf\" command.\n\
15192 If the value is \"call\", the print is done by calling a function in your\n\
15193 program; by default printf(), but you can choose a different function or\n\
15194 output stream by setting dprintf-function and dprintf-channel."),
15195 update_dprintf_commands
, NULL
,
15196 &setlist
, &showlist
);
15198 add_setshow_string_cmd ("dprintf-function", class_support
,
15199 &dprintf_function
, _("\
15200 Set the function to use for dynamic printf."), _("\
15201 Show the function to use for dynamic printf."), NULL
,
15202 update_dprintf_commands
, NULL
,
15203 &setlist
, &showlist
);
15205 add_setshow_string_cmd ("dprintf-channel", class_support
,
15206 &dprintf_channel
, _("\
15207 Set the channel to use for dynamic printf."), _("\
15208 Show the channel to use for dynamic printf."), NULL
,
15209 update_dprintf_commands
, NULL
,
15210 &setlist
, &showlist
);
15212 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15213 &disconnected_dprintf
, _("\
15214 Set whether dprintf continues after GDB disconnects."), _("\
15215 Show whether dprintf continues after GDB disconnects."), _("\
15216 Use this to let dprintf commands continue to hit and produce output\n\
15217 even if GDB disconnects or detaches from the target."),
15220 &setlist
, &showlist
);
15222 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15223 Target agent only formatted printing, like the C \"printf\" function.\n\
15224 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15225 This supports most C printf format specifications, like %s, %d, etc.\n\
15226 This is useful for formatted output in user-defined commands."));
15228 automatic_hardware_breakpoints
= true;
15230 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
15232 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,
15234 gdb::observers::inferior_removed
.attach (remove_inferior_breakpoints
,