1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdbsupport/gdb_regex.h"
61 #include "cli/cli-utils.h"
64 #include "dummy-frame.h"
66 #include "gdbsupport/format.h"
67 #include "thread-fsm.h"
68 #include "tid-parse.h"
69 #include "cli/cli-style.h"
70 #include "cli/cli-decode.h"
72 /* readline include files */
73 #include "readline/tilde.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "extension.h"
81 #include "progspace-and-thread.h"
82 #include "gdbsupport/array-view.h"
83 #include "gdbsupport/gdb_optional.h"
85 /* Prototypes for local functions. */
87 static void map_breakpoint_numbers (const char *,
88 gdb::function_view
<void (breakpoint
*)>);
91 create_sals_from_location_spec_default (location_spec
*locspec
,
92 linespec_result
*canonical
);
94 static void create_breakpoints_sal (struct gdbarch
*,
95 struct linespec_result
*,
96 gdb::unique_xmalloc_ptr
<char>,
97 gdb::unique_xmalloc_ptr
<char>,
99 enum bpdisp
, int, int,
101 int, int, int, unsigned);
103 static int can_use_hardware_watchpoint
104 (const std::vector
<value_ref_ptr
> &vals
);
106 static void mention (const breakpoint
*);
108 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
110 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
112 static struct breakpoint
*
113 momentary_breakpoint_from_master (struct breakpoint
*orig
,
115 int loc_enabled
, int thread
);
117 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
119 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
122 struct program_space
*pspace
);
124 static int watchpoint_locations_match (struct bp_location
*loc1
,
125 struct bp_location
*loc2
);
127 static int breakpoint_locations_match (struct bp_location
*loc1
,
128 struct bp_location
*loc2
,
129 bool sw_hw_bps_match
= false);
131 static int breakpoint_location_address_match (struct bp_location
*bl
,
132 const struct address_space
*aspace
,
135 static int breakpoint_location_address_range_overlap (struct bp_location
*,
136 const address_space
*,
139 static int remove_breakpoint (struct bp_location
*);
140 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
142 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
144 static int hw_breakpoint_used_count (void);
146 static int hw_watchpoint_use_count (struct breakpoint
*);
148 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
150 int *other_type_used
);
152 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
155 static void decref_bp_location (struct bp_location
**loc
);
157 static std::vector
<symtab_and_line
> bkpt_probe_decode_location_spec
158 (struct breakpoint
*b
,
159 location_spec
*locspec
,
160 struct program_space
*search_pspace
);
162 static bool bl_address_is_meaningful (bp_location
*loc
);
164 static int find_loc_num_by_location (const bp_location
*loc
);
166 /* update_global_location_list's modes of operation wrt to whether to
167 insert locations now. */
168 enum ugll_insert_mode
170 /* Don't insert any breakpoint locations into the inferior, only
171 remove already-inserted locations that no longer should be
172 inserted. Functions that delete a breakpoint or breakpoints
173 should specify this mode, so that deleting a breakpoint doesn't
174 have the side effect of inserting the locations of other
175 breakpoints that are marked not-inserted, but should_be_inserted
176 returns true on them.
178 This behavior is useful is situations close to tear-down -- e.g.,
179 after an exec, while the target still has execution, but
180 breakpoint shadows of the previous executable image should *NOT*
181 be restored to the new image; or before detaching, where the
182 target still has execution and wants to delete breakpoints from
183 GDB's lists, and all breakpoints had already been removed from
187 /* May insert breakpoints iff breakpoints_should_be_inserted_now
188 claims breakpoints should be inserted now. */
191 /* Insert locations now, irrespective of
192 breakpoints_should_be_inserted_now. E.g., say all threads are
193 stopped right now, and the user did "continue". We need to
194 insert breakpoints _before_ resuming the target, but
195 UGLL_MAY_INSERT wouldn't insert them, because
196 breakpoints_should_be_inserted_now returns false at that point,
197 as no thread is running yet. */
201 static void update_global_location_list (enum ugll_insert_mode
);
203 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
205 static void insert_breakpoint_locations (void);
207 static void trace_pass_command (const char *, int);
209 static void set_tracepoint_count (int num
);
211 static bool is_masked_watchpoint (const struct breakpoint
*b
);
213 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
216 static int strace_marker_p (struct breakpoint
*b
);
218 static void bkpt_probe_create_sals_from_location_spec
219 (location_spec
*locspec
,
220 struct linespec_result
*canonical
);
221 static void tracepoint_probe_create_sals_from_location_spec
222 (location_spec
*locspec
,
223 struct linespec_result
*canonical
);
225 const struct breakpoint_ops code_breakpoint_ops
=
227 create_sals_from_location_spec_default
,
228 create_breakpoints_sal
,
231 /* Breakpoints set on probes. */
232 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
234 bkpt_probe_create_sals_from_location_spec
,
235 create_breakpoints_sal
,
238 /* Tracepoints set on probes. */
239 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
241 tracepoint_probe_create_sals_from_location_spec
,
242 create_breakpoints_sal
,
245 /* Implementation of abstract dtors. These must exist to satisfy the
248 breakpoint::~breakpoint ()
252 code_breakpoint::~code_breakpoint ()
256 catchpoint::~catchpoint ()
260 /* The structure to be used in regular breakpoints. */
261 struct ordinary_breakpoint
: public code_breakpoint
263 using code_breakpoint::code_breakpoint
;
265 int resources_needed (const struct bp_location
*) override
;
266 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
267 void print_mention () const override
;
268 void print_recreate (struct ui_file
*fp
) const override
;
271 /* Internal breakpoints. These typically have a lifetime the same as
272 the program, and they end up installed on the breakpoint chain with
273 a negative breakpoint number. They're visible in "maint info
274 breakpoints", but not "info breakpoints". */
275 struct internal_breakpoint
: public code_breakpoint
277 internal_breakpoint (struct gdbarch
*gdbarch
,
278 enum bptype type
, CORE_ADDR address
)
279 : code_breakpoint (gdbarch
, type
)
283 sal
.section
= find_pc_overlay (sal
.pc
);
284 sal
.pspace
= current_program_space
;
287 pspace
= current_program_space
;
288 disposition
= disp_donttouch
;
291 void re_set () override
;
292 void check_status (struct bpstat
*bs
) override
;
293 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
294 void print_mention () const override
;
297 /* Momentary breakpoints. These typically have a lifetime of some run
298 control command only, are always thread-specific, and have 0 for
299 breakpoint number. I.e., there can be many momentary breakpoints
300 on the breakpoint chain and they all same the same number (zero).
301 They're visible in "maint info breakpoints", but not "info
303 struct momentary_breakpoint
: public code_breakpoint
305 momentary_breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
306 program_space
*pspace_
,
307 const struct frame_id
&frame_id_
,
309 : code_breakpoint (gdbarch_
, bptype
)
311 /* If FRAME_ID is valid, it should be a real frame, not an inlined
312 or tail-called one. */
313 gdb_assert (!frame_id_artificial_p (frame_id
));
315 /* Momentary breakpoints are always thread-specific. */
316 gdb_assert (thread_
> 0);
319 enable_state
= bp_enabled
;
320 disposition
= disp_donttouch
;
321 frame_id
= frame_id_
;
325 void re_set () override
;
326 void check_status (struct bpstat
*bs
) override
;
327 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
328 void print_mention () const override
;
331 /* DPrintf breakpoints. */
332 struct dprintf_breakpoint
: public ordinary_breakpoint
334 using ordinary_breakpoint::ordinary_breakpoint
;
336 void re_set () override
;
337 int breakpoint_hit (const struct bp_location
*bl
,
338 const address_space
*aspace
,
340 const target_waitstatus
&ws
) override
;
341 void print_recreate (struct ui_file
*fp
) const override
;
342 void after_condition_true (struct bpstat
*bs
) override
;
345 /* Ranged breakpoints. */
346 struct ranged_breakpoint
: public ordinary_breakpoint
348 explicit ranged_breakpoint (struct gdbarch
*gdbarch
,
349 const symtab_and_line
&sal_start
,
351 location_spec_up start_locspec
,
352 location_spec_up end_locspec
)
353 : ordinary_breakpoint (gdbarch
, bp_hardware_breakpoint
)
355 bp_location
*bl
= add_location (sal_start
);
358 disposition
= disp_donttouch
;
360 locspec
= std::move (start_locspec
);
361 locspec_range_end
= std::move (end_locspec
);
364 int breakpoint_hit (const struct bp_location
*bl
,
365 const address_space
*aspace
,
367 const target_waitstatus
&ws
) override
;
368 int resources_needed (const struct bp_location
*) override
;
369 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
370 bool print_one (bp_location
**) const override
;
371 void print_one_detail (struct ui_out
*) const override
;
372 void print_mention () const override
;
373 void print_recreate (struct ui_file
*fp
) const override
;
376 /* Static tracepoints with marker (`-m'). */
377 struct static_marker_tracepoint
: public tracepoint
379 using tracepoint::tracepoint
;
381 std::vector
<symtab_and_line
> decode_location_spec
382 (struct location_spec
*locspec
,
383 struct program_space
*search_pspace
) override
;
386 /* The style in which to perform a dynamic printf. This is a user
387 option because different output options have different tradeoffs;
388 if GDB does the printing, there is better error handling if there
389 is a problem with any of the arguments, but using an inferior
390 function lets you have special-purpose printers and sending of
391 output to the same place as compiled-in print functions. */
393 static const char dprintf_style_gdb
[] = "gdb";
394 static const char dprintf_style_call
[] = "call";
395 static const char dprintf_style_agent
[] = "agent";
396 static const char *const dprintf_style_enums
[] = {
402 static const char *dprintf_style
= dprintf_style_gdb
;
404 /* The function to use for dynamic printf if the preferred style is to
405 call into the inferior. The value is simply a string that is
406 copied into the command, so it can be anything that GDB can
407 evaluate to a callable address, not necessarily a function name. */
409 static std::string dprintf_function
= "printf";
411 /* The channel to use for dynamic printf if the preferred style is to
412 call into the inferior; if a nonempty string, it will be passed to
413 the call as the first argument, with the format string as the
414 second. As with the dprintf function, this can be anything that
415 GDB knows how to evaluate, so in addition to common choices like
416 "stderr", this could be an app-specific expression like
417 "mystreams[curlogger]". */
419 static std::string dprintf_channel
;
421 /* True if dprintf commands should continue to operate even if GDB
423 static bool disconnected_dprintf
= true;
425 struct command_line
*
426 breakpoint_commands (struct breakpoint
*b
)
428 return b
->commands
? b
->commands
.get () : NULL
;
431 /* Flag indicating that a command has proceeded the inferior past the
432 current breakpoint. */
434 static bool breakpoint_proceeded
;
437 bpdisp_text (enum bpdisp disp
)
439 /* NOTE: the following values are a part of MI protocol and
440 represent values of 'disp' field returned when inferior stops at
442 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
444 return bpdisps
[(int) disp
];
447 /* Prototypes for exported functions. */
448 /* If FALSE, gdb will not use hardware support for watchpoints, even
449 if such is available. */
450 static int can_use_hw_watchpoints
;
453 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
454 struct cmd_list_element
*c
,
458 _("Debugger's willingness to use "
459 "watchpoint hardware is %s.\n"),
463 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
464 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
465 for unrecognized breakpoint locations.
466 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
467 static enum auto_boolean pending_break_support
;
469 show_pending_break_support (struct ui_file
*file
, int from_tty
,
470 struct cmd_list_element
*c
,
474 _("Debugger's behavior regarding "
475 "pending breakpoints is %s.\n"),
479 /* If true, gdb will automatically use hardware breakpoints for breakpoints
480 set with "break" but falling in read-only memory.
481 If false, gdb will warn about such breakpoints, but won't automatically
482 use hardware breakpoints. */
483 static bool automatic_hardware_breakpoints
;
485 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
486 struct cmd_list_element
*c
,
490 _("Automatic usage of hardware breakpoints is %s.\n"),
494 /* If on, GDB keeps breakpoints inserted even if the inferior is
495 stopped, and immediately inserts any new breakpoints as soon as
496 they're created. If off (default), GDB keeps breakpoints off of
497 the target as long as possible. That is, it delays inserting
498 breakpoints until the next resume, and removes them again when the
499 target fully stops. This is a bit safer in case GDB crashes while
500 processing user input. */
501 static bool always_inserted_mode
= false;
504 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
505 struct cmd_list_element
*c
, const char *value
)
507 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
511 /* See breakpoint.h. */
514 breakpoints_should_be_inserted_now (void)
516 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
518 /* If breakpoints are global, they should be inserted even if no
519 thread under gdb's control is running, or even if there are
520 no threads under GDB's control yet. */
525 if (always_inserted_mode
)
527 /* The user wants breakpoints inserted even if all threads
532 for (inferior
*inf
: all_inferiors ())
533 if (inf
->has_execution ()
534 && threads_are_executing (inf
->process_target ()))
537 /* Don't remove breakpoints yet if, even though all threads are
538 stopped, we still have events to process. */
539 for (thread_info
*tp
: all_non_exited_threads ())
540 if (tp
->resumed () && tp
->has_pending_waitstatus ())
546 static const char condition_evaluation_both
[] = "host or target";
548 /* Modes for breakpoint condition evaluation. */
549 static const char condition_evaluation_auto
[] = "auto";
550 static const char condition_evaluation_host
[] = "host";
551 static const char condition_evaluation_target
[] = "target";
552 static const char *const condition_evaluation_enums
[] = {
553 condition_evaluation_auto
,
554 condition_evaluation_host
,
555 condition_evaluation_target
,
559 /* Global that holds the current mode for breakpoint condition evaluation. */
560 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
562 /* Global that we use to display information to the user (gets its value from
563 condition_evaluation_mode_1. */
564 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
566 /* Translate a condition evaluation mode MODE into either "host"
567 or "target". This is used mostly to translate from "auto" to the
568 real setting that is being used. It returns the translated
572 translate_condition_evaluation_mode (const char *mode
)
574 if (mode
== condition_evaluation_auto
)
576 if (target_supports_evaluation_of_breakpoint_conditions ())
577 return condition_evaluation_target
;
579 return condition_evaluation_host
;
585 /* Discovers what condition_evaluation_auto translates to. */
588 breakpoint_condition_evaluation_mode (void)
590 return translate_condition_evaluation_mode (condition_evaluation_mode
);
593 /* Return true if GDB should evaluate breakpoint conditions or false
597 gdb_evaluates_breakpoint_condition_p (void)
599 const char *mode
= breakpoint_condition_evaluation_mode ();
601 return (mode
== condition_evaluation_host
);
604 /* Are we executing breakpoint commands? */
605 static int executing_breakpoint_commands
;
607 /* Are overlay event breakpoints enabled? */
608 static int overlay_events_enabled
;
610 /* See description in breakpoint.h. */
611 bool target_exact_watchpoints
= false;
613 /* Walk the following statement or block through all breakpoints.
614 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
615 current breakpoint. */
617 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
618 for (B = breakpoint_chain; \
619 B ? (TMP=B->next, 1): 0; \
622 /* Chains of all breakpoints defined. */
624 static struct breakpoint
*breakpoint_chain
;
626 /* See breakpoint.h. */
631 return breakpoint_range (breakpoint_chain
);
634 /* See breakpoint.h. */
636 breakpoint_safe_range
637 all_breakpoints_safe ()
639 return breakpoint_safe_range (all_breakpoints ());
642 /* See breakpoint.h. */
647 return tracepoint_range (breakpoint_chain
);
650 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
652 static std::vector
<bp_location
*> bp_locations
;
654 /* See breakpoint.h. */
656 const std::vector
<bp_location
*> &
662 /* Range to iterate over breakpoint locations at a given address. */
664 struct bp_locations_at_addr_range
666 using iterator
= std::vector
<bp_location
*>::iterator
;
668 bp_locations_at_addr_range (CORE_ADDR addr
)
672 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
673 { return loc
->address
< addr_
; }
675 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
676 { return addr_
< loc
->address
; }
679 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
682 m_begin
= it_pair
.first
;
683 m_end
= it_pair
.second
;
686 iterator
begin () const
689 iterator
end () const
697 /* Return a range to iterate over all breakpoint locations exactly at address
700 If it's needed to iterate multiple times on the same range, it's possible
701 to save the range in a local variable and use it multiple times:
703 auto range = all_bp_locations_at_addr (addr);
705 for (bp_location *loc : range)
708 for (bp_location *loc : range)
711 This saves a bit of time, as it avoids re-doing the binary searches to find
712 the range's boundaries. Just remember not to change the bp_locations vector
713 in the mean time, as it could make the range's iterators stale. */
715 static bp_locations_at_addr_range
716 all_bp_locations_at_addr (CORE_ADDR addr
)
718 return bp_locations_at_addr_range (addr
);
721 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
722 ADDRESS for the current elements of BP_LOCATIONS which get a valid
723 result from bp_location_has_shadow. You can use it for roughly
724 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
725 an address you need to read. */
727 static CORE_ADDR bp_locations_placed_address_before_address_max
;
729 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
730 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
731 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
732 You can use it for roughly limiting the subrange of BP_LOCATIONS to
733 scan for shadow bytes for an address you need to read. */
735 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
737 /* The locations that no longer correspond to any breakpoint, unlinked
738 from the bp_locations array, but for which a hit may still be
739 reported by a target. */
740 static std::vector
<bp_location
*> moribund_locations
;
742 /* Number of last breakpoint made. */
744 static int breakpoint_count
;
746 /* The value of `breakpoint_count' before the last command that
747 created breakpoints. If the last (break-like) command created more
748 than one breakpoint, then the difference between BREAKPOINT_COUNT
749 and PREV_BREAKPOINT_COUNT is more than one. */
750 static int prev_breakpoint_count
;
752 /* Number of last tracepoint made. */
754 static int tracepoint_count
;
756 static struct cmd_list_element
*breakpoint_set_cmdlist
;
757 static struct cmd_list_element
*breakpoint_show_cmdlist
;
758 struct cmd_list_element
*save_cmdlist
;
760 /* Return whether a breakpoint is an active enabled breakpoint. */
762 breakpoint_enabled (struct breakpoint
*b
)
764 return (b
->enable_state
== bp_enabled
);
767 /* Set breakpoint count to NUM. */
770 set_breakpoint_count (int num
)
772 prev_breakpoint_count
= breakpoint_count
;
773 breakpoint_count
= num
;
774 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
777 /* Used by `start_rbreak_breakpoints' below, to record the current
778 breakpoint count before "rbreak" creates any breakpoint. */
779 static int rbreak_start_breakpoint_count
;
781 /* Called at the start an "rbreak" command to record the first
784 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
786 rbreak_start_breakpoint_count
= breakpoint_count
;
789 /* Called at the end of an "rbreak" command to record the last
792 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
794 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
797 /* Used in run_command to zero the hit count when a new run starts. */
800 clear_breakpoint_hit_counts (void)
802 for (breakpoint
*b
: all_breakpoints ())
807 /* Return the breakpoint with the specified number, or NULL
808 if the number does not refer to an existing breakpoint. */
811 get_breakpoint (int num
)
813 for (breakpoint
*b
: all_breakpoints ())
814 if (b
->number
== num
)
822 /* Mark locations as "conditions have changed" in case the target supports
823 evaluating conditions on its side. */
826 mark_breakpoint_modified (struct breakpoint
*b
)
828 /* This is only meaningful if the target is
829 evaluating conditions and if the user has
830 opted for condition evaluation on the target's
832 if (gdb_evaluates_breakpoint_condition_p ()
833 || !target_supports_evaluation_of_breakpoint_conditions ())
836 if (!is_breakpoint (b
))
839 for (bp_location
*loc
: b
->locations ())
840 loc
->condition_changed
= condition_modified
;
843 /* Mark location as "conditions have changed" in case the target supports
844 evaluating conditions on its side. */
847 mark_breakpoint_location_modified (struct bp_location
*loc
)
849 /* This is only meaningful if the target is
850 evaluating conditions and if the user has
851 opted for condition evaluation on the target's
853 if (gdb_evaluates_breakpoint_condition_p ()
854 || !target_supports_evaluation_of_breakpoint_conditions ())
858 if (!is_breakpoint (loc
->owner
))
861 loc
->condition_changed
= condition_modified
;
864 /* Sets the condition-evaluation mode using the static global
865 condition_evaluation_mode. */
868 set_condition_evaluation_mode (const char *args
, int from_tty
,
869 struct cmd_list_element
*c
)
871 const char *old_mode
, *new_mode
;
873 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
874 && !target_supports_evaluation_of_breakpoint_conditions ())
876 condition_evaluation_mode_1
= condition_evaluation_mode
;
877 warning (_("Target does not support breakpoint condition evaluation.\n"
878 "Using host evaluation mode instead."));
882 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
883 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
885 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
886 settings was "auto". */
887 condition_evaluation_mode
= condition_evaluation_mode_1
;
889 /* Only update the mode if the user picked a different one. */
890 if (new_mode
!= old_mode
)
892 /* If the user switched to a different evaluation mode, we
893 need to synch the changes with the target as follows:
895 "host" -> "target": Send all (valid) conditions to the target.
896 "target" -> "host": Remove all the conditions from the target.
899 if (new_mode
== condition_evaluation_target
)
901 /* Mark everything modified and synch conditions with the
903 for (bp_location
*loc
: all_bp_locations ())
904 mark_breakpoint_location_modified (loc
);
908 /* Manually mark non-duplicate locations to synch conditions
909 with the target. We do this to remove all the conditions the
910 target knows about. */
911 for (bp_location
*loc
: all_bp_locations ())
912 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
913 loc
->needs_update
= 1;
917 update_global_location_list (UGLL_MAY_INSERT
);
923 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
924 what "auto" is translating to. */
927 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
928 struct cmd_list_element
*c
, const char *value
)
930 if (condition_evaluation_mode
== condition_evaluation_auto
)
932 _("Breakpoint condition evaluation "
933 "mode is %s (currently %s).\n"),
935 breakpoint_condition_evaluation_mode ());
937 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
941 /* Parse COND_STRING in the context of LOC and set as the condition
942 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
943 the number of LOC within its owner. In case of parsing error, mark
944 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
947 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
948 int bp_num
, int loc_num
)
950 bool has_junk
= false;
953 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
954 block_for_pc (loc
->address
), 0);
955 if (*cond_string
!= 0)
959 loc
->cond
= std::move (new_exp
);
960 if (loc
->disabled_by_cond
&& loc
->enabled
)
961 gdb_printf (_("Breakpoint %d's condition is now valid at "
962 "location %d, enabling.\n"),
965 loc
->disabled_by_cond
= false;
968 catch (const gdb_exception_error
&e
)
972 /* Warn if a user-enabled location is now becoming disabled-by-cond.
973 BP_NUM is 0 if the breakpoint is being defined for the first
974 time using the "break ... if ..." command, and non-zero if
977 warning (_("failed to validate condition at location %d.%d, "
978 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
980 warning (_("failed to validate condition at location %d, "
981 "disabling:\n %s"), loc_num
, e
.what ());
984 loc
->disabled_by_cond
= true;
988 error (_("Garbage '%s' follows condition"), cond_string
);
992 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
993 int from_tty
, bool force
)
997 b
->cond_string
.reset ();
999 if (is_watchpoint (b
))
1000 gdb::checked_static_cast
<watchpoint
*> (b
)->cond_exp
.reset ();
1004 for (bp_location
*loc
: b
->locations ())
1007 if (loc
->disabled_by_cond
&& loc
->enabled
)
1008 gdb_printf (_("Breakpoint %d's condition is now valid at "
1009 "location %d, enabling.\n"),
1010 b
->number
, loc_num
);
1011 loc
->disabled_by_cond
= false;
1014 /* No need to free the condition agent expression
1015 bytecode (if we have one). We will handle this
1016 when we go through update_global_location_list. */
1021 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
1025 if (is_watchpoint (b
))
1027 innermost_block_tracker tracker
;
1028 const char *arg
= exp
;
1029 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
1031 error (_("Junk at end of expression"));
1032 watchpoint
*w
= gdb::checked_static_cast
<watchpoint
*> (b
);
1033 w
->cond_exp
= std::move (new_exp
);
1034 w
->cond_exp_valid_block
= tracker
.block ();
1038 /* Parse and set condition expressions. We make two passes.
1039 In the first, we parse the condition string to see if it
1040 is valid in at least one location. If so, the condition
1041 would be accepted. So we go ahead and set the locations'
1042 conditions. In case no valid case is found, we throw
1043 the error and the condition string will be rejected.
1044 This two-pass approach is taken to avoid setting the
1045 state of locations in case of a reject. */
1046 for (bp_location
*loc
: b
->locations ())
1050 const char *arg
= exp
;
1051 parse_exp_1 (&arg
, loc
->address
,
1052 block_for_pc (loc
->address
), 0);
1054 error (_("Junk at end of expression"));
1057 catch (const gdb_exception_error
&e
)
1059 /* Condition string is invalid. If this happens to
1060 be the last loc, abandon (if not forced) or continue
1062 if (loc
->next
== nullptr && !force
)
1067 /* If we reach here, the condition is valid at some locations. */
1069 for (bp_location
*loc
: b
->locations ())
1071 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
1076 /* We know that the new condition parsed successfully. The
1077 condition string of the breakpoint can be safely updated. */
1078 b
->cond_string
= make_unique_xstrdup (exp
);
1079 b
->condition_not_parsed
= 0;
1081 mark_breakpoint_modified (b
);
1083 gdb::observers::breakpoint_modified
.notify (b
);
1086 /* See breakpoint.h. */
1089 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1092 for (breakpoint
*b
: all_breakpoints ())
1093 if (b
->number
== bpnum
)
1095 /* Check if this breakpoint has a "stop" method implemented in an
1096 extension language. This method and conditions entered into GDB
1097 from the CLI are mutually exclusive. */
1098 const struct extension_language_defn
*extlang
1099 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1101 if (extlang
!= NULL
)
1103 error (_("Only one stop condition allowed. There is currently"
1104 " a %s stop condition defined for this breakpoint."),
1105 ext_lang_capitalized_name (extlang
));
1107 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1109 if (is_breakpoint (b
))
1110 update_global_location_list (UGLL_MAY_INSERT
);
1115 error (_("No breakpoint number %d."), bpnum
);
1118 /* The options for the "condition" command. */
1120 struct condition_command_opts
1123 bool force_condition
= false;
1126 static const gdb::option::option_def condition_command_option_defs
[] = {
1128 gdb::option::flag_option_def
<condition_command_opts
> {
1130 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1131 N_("Set the condition even if it is invalid for all current locations."),
1136 /* Create an option_def_group for the "condition" options, with
1137 CC_OPTS as context. */
1139 static inline gdb::option::option_def_group
1140 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1142 return {{condition_command_option_defs
}, cc_opts
};
1145 /* Completion for the "condition" command. */
1148 condition_completer (struct cmd_list_element
*cmd
,
1149 completion_tracker
&tracker
,
1150 const char *text
, const char * /*word*/)
1152 bool has_no_arguments
= (*text
== '\0');
1153 condition_command_opts cc_opts
;
1154 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1155 if (gdb::option::complete_options
1156 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1159 text
= skip_spaces (text
);
1160 const char *space
= skip_to_space (text
);
1167 tracker
.advance_custom_word_point_by (1);
1168 /* We don't support completion of history indices. */
1169 if (!isdigit (text
[1]))
1170 complete_internalvar (tracker
, &text
[1]);
1174 /* Suggest the "-force" flag if no arguments are given. If
1175 arguments were passed, they either already include the flag,
1176 or we are beyond the point of suggesting it because it's
1177 positionally the first argument. */
1178 if (has_no_arguments
)
1179 gdb::option::complete_on_all_options (tracker
, group
);
1181 /* We're completing the breakpoint number. */
1182 len
= strlen (text
);
1184 for (breakpoint
*b
: all_breakpoints ())
1188 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1190 if (strncmp (number
, text
, len
) == 0)
1191 tracker
.add_completion (make_unique_xstrdup (number
));
1197 /* We're completing the expression part. Skip the breakpoint num. */
1198 const char *exp_start
= skip_spaces (space
);
1199 tracker
.advance_custom_word_point_by (exp_start
- text
);
1201 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1202 expression_completer (cmd
, tracker
, text
, word
);
1205 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1208 condition_command (const char *arg
, int from_tty
)
1214 error_no_arg (_("breakpoint number"));
1218 /* Check if the "-force" flag was passed. */
1219 condition_command_opts cc_opts
;
1220 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1221 gdb::option::process_options
1222 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1224 bnum
= get_number (&p
);
1226 error (_("Bad breakpoint argument: '%s'"), arg
);
1228 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1231 /* Check that COMMAND do not contain commands that are suitable
1232 only for tracepoints and not suitable for ordinary breakpoints.
1233 Throw if any such commands is found. */
1236 check_no_tracepoint_commands (struct command_line
*commands
)
1238 struct command_line
*c
;
1240 for (c
= commands
; c
; c
= c
->next
)
1242 if (c
->control_type
== while_stepping_control
)
1243 error (_("The 'while-stepping' command can "
1244 "only be used for tracepoints"));
1246 check_no_tracepoint_commands (c
->body_list_0
.get ());
1247 check_no_tracepoint_commands (c
->body_list_1
.get ());
1249 /* Not that command parsing removes leading whitespace and comment
1250 lines and also empty lines. So, we only need to check for
1251 command directly. */
1252 if (strstr (c
->line
, "collect ") == c
->line
)
1253 error (_("The 'collect' command can only be used for tracepoints"));
1255 if (strstr (c
->line
, "teval ") == c
->line
)
1256 error (_("The 'teval' command can only be used for tracepoints"));
1260 struct longjmp_breakpoint
: public momentary_breakpoint
1262 using momentary_breakpoint::momentary_breakpoint
;
1264 ~longjmp_breakpoint () override
;
1267 /* Encapsulate tests for different types of tracepoints. */
1270 is_tracepoint_type (bptype type
)
1272 return (type
== bp_tracepoint
1273 || type
== bp_fast_tracepoint
1274 || type
== bp_static_tracepoint
1275 || type
== bp_static_marker_tracepoint
);
1278 /* See breakpoint.h. */
1281 is_tracepoint (const struct breakpoint
*b
)
1283 return is_tracepoint_type (b
->type
);
1286 /* Factory function to create an appropriate instance of breakpoint given
1289 template<typename
... Arg
>
1290 static std::unique_ptr
<code_breakpoint
>
1291 new_breakpoint_from_type (struct gdbarch
*gdbarch
, bptype type
,
1299 case bp_hardware_breakpoint
:
1300 b
= new ordinary_breakpoint (gdbarch
, type
,
1301 std::forward
<Arg
> (args
)...);
1304 case bp_fast_tracepoint
:
1305 case bp_static_tracepoint
:
1307 b
= new tracepoint (gdbarch
, type
,
1308 std::forward
<Arg
> (args
)...);
1311 case bp_static_marker_tracepoint
:
1312 b
= new static_marker_tracepoint (gdbarch
, type
,
1313 std::forward
<Arg
> (args
)...);
1317 b
= new dprintf_breakpoint (gdbarch
, type
,
1318 std::forward
<Arg
> (args
)...);
1322 gdb_assert_not_reached ("invalid type");
1325 return std::unique_ptr
<code_breakpoint
> (b
);
1328 /* A helper function that validates that COMMANDS are valid for a
1329 breakpoint. This function will throw an exception if a problem is
1333 validate_commands_for_breakpoint (struct breakpoint
*b
,
1334 struct command_line
*commands
)
1336 if (is_tracepoint (b
))
1338 struct tracepoint
*t
= (struct tracepoint
*) b
;
1339 struct command_line
*c
;
1340 struct command_line
*while_stepping
= 0;
1342 /* Reset the while-stepping step count. The previous commands
1343 might have included a while-stepping action, while the new
1347 /* We need to verify that each top-level element of commands is
1348 valid for tracepoints, that there's at most one
1349 while-stepping element, and that the while-stepping's body
1350 has valid tracing commands excluding nested while-stepping.
1351 We also need to validate the tracepoint action line in the
1352 context of the tracepoint --- validate_actionline actually
1353 has side effects, like setting the tracepoint's
1354 while-stepping STEP_COUNT, in addition to checking if the
1355 collect/teval actions parse and make sense in the
1356 tracepoint's context. */
1357 for (c
= commands
; c
; c
= c
->next
)
1359 if (c
->control_type
== while_stepping_control
)
1361 if (b
->type
== bp_fast_tracepoint
)
1362 error (_("The 'while-stepping' command "
1363 "cannot be used for fast tracepoint"));
1364 else if (b
->type
== bp_static_tracepoint
1365 || b
->type
== bp_static_marker_tracepoint
)
1366 error (_("The 'while-stepping' command "
1367 "cannot be used for static tracepoint"));
1370 error (_("The 'while-stepping' command "
1371 "can be used only once"));
1376 validate_actionline (c
->line
, b
);
1380 struct command_line
*c2
;
1382 gdb_assert (while_stepping
->body_list_1
== nullptr);
1383 c2
= while_stepping
->body_list_0
.get ();
1384 for (; c2
; c2
= c2
->next
)
1386 if (c2
->control_type
== while_stepping_control
)
1387 error (_("The 'while-stepping' command cannot be nested"));
1393 check_no_tracepoint_commands (commands
);
1397 /* Return a vector of all the static tracepoints set at ADDR. The
1398 caller is responsible for releasing the vector. */
1400 std::vector
<breakpoint
*>
1401 static_tracepoints_here (CORE_ADDR addr
)
1403 std::vector
<breakpoint
*> found
;
1405 for (breakpoint
*b
: all_breakpoints ())
1406 if (b
->type
== bp_static_tracepoint
1407 || b
->type
== bp_static_marker_tracepoint
)
1409 for (bp_location
*loc
: b
->locations ())
1410 if (loc
->address
== addr
)
1411 found
.push_back (b
);
1417 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1418 validate that only allowed commands are included. */
1421 breakpoint_set_commands (struct breakpoint
*b
,
1422 counted_command_line
&&commands
)
1424 validate_commands_for_breakpoint (b
, commands
.get ());
1426 b
->commands
= std::move (commands
);
1427 gdb::observers::breakpoint_modified
.notify (b
);
1430 /* Set the internal `silent' flag on the breakpoint. Note that this
1431 is not the same as the "silent" that may appear in the breakpoint's
1435 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1437 int old_silent
= b
->silent
;
1440 if (old_silent
!= silent
)
1441 gdb::observers::breakpoint_modified
.notify (b
);
1444 /* Set the thread for this breakpoint. If THREAD is -1, make the
1445 breakpoint work for any thread. */
1448 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1450 int old_thread
= b
->thread
;
1453 if (old_thread
!= thread
)
1454 gdb::observers::breakpoint_modified
.notify (b
);
1457 /* Set the task for this breakpoint. If TASK is 0, make the
1458 breakpoint work for any task. */
1461 breakpoint_set_task (struct breakpoint
*b
, int task
)
1463 int old_task
= b
->task
;
1466 if (old_task
!= task
)
1467 gdb::observers::breakpoint_modified
.notify (b
);
1471 commands_command_1 (const char *arg
, int from_tty
,
1472 struct command_line
*control
)
1474 counted_command_line cmd
;
1475 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1476 NULL after the call to read_command_lines if the user provides an empty
1477 list of command by just typing "end". */
1478 bool cmd_read
= false;
1480 std::string new_arg
;
1482 if (arg
== NULL
|| !*arg
)
1484 /* Argument not explicitly given. Synthesize it. */
1485 if (breakpoint_count
- prev_breakpoint_count
> 1)
1486 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1488 else if (breakpoint_count
> 0)
1489 new_arg
= string_printf ("%d", breakpoint_count
);
1493 /* Create a copy of ARG. This is needed because the "commands"
1494 command may be coming from a script. In that case, the read
1495 line buffer is going to be overwritten in the lambda of
1496 'map_breakpoint_numbers' below when reading the next line
1497 before we are are done parsing the breakpoint numbers. */
1500 arg
= new_arg
.c_str ();
1502 map_breakpoint_numbers
1503 (arg
, [&] (breakpoint
*b
)
1507 gdb_assert (cmd
== NULL
);
1508 if (control
!= NULL
)
1509 cmd
= control
->body_list_0
;
1513 = string_printf (_("Type commands for breakpoint(s) "
1514 "%s, one per line."),
1517 auto do_validate
= [=] (const char *line
)
1519 validate_actionline (line
, b
);
1521 gdb::function_view
<void (const char *)> validator
;
1522 if (is_tracepoint (b
))
1523 validator
= do_validate
;
1525 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1530 /* If a breakpoint was on the list more than once, we don't need to
1532 if (b
->commands
!= cmd
)
1534 validate_commands_for_breakpoint (b
, cmd
.get ());
1536 gdb::observers::breakpoint_modified
.notify (b
);
1542 commands_command (const char *arg
, int from_tty
)
1544 commands_command_1 (arg
, from_tty
, NULL
);
1547 /* Like commands_command, but instead of reading the commands from
1548 input stream, takes them from an already parsed command structure.
1550 This is used by cli-script.c to DTRT with breakpoint commands
1551 that are part of if and while bodies. */
1552 enum command_control_type
1553 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1555 commands_command_1 (arg
, 0, cmd
);
1556 return simple_control
;
1559 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1562 bp_location_has_shadow (struct bp_location
*bl
)
1564 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1568 if (bl
->target_info
.shadow_len
== 0)
1569 /* BL isn't valid, or doesn't shadow memory. */
1574 /* Update BUF, which is LEN bytes read from the target address
1575 MEMADDR, by replacing a memory breakpoint with its shadowed
1578 If READBUF is not NULL, this buffer must not overlap with the of
1579 the breakpoint location's shadow_contents buffer. Otherwise, a
1580 failed assertion internal error will be raised. */
1583 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1584 const gdb_byte
*writebuf_org
,
1585 ULONGEST memaddr
, LONGEST len
,
1586 struct bp_target_info
*target_info
,
1587 struct gdbarch
*gdbarch
)
1589 /* Now do full processing of the found relevant range of elements. */
1590 CORE_ADDR bp_addr
= 0;
1594 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1595 current_program_space
->aspace
, 0))
1597 /* The breakpoint is inserted in a different address space. */
1601 /* Addresses and length of the part of the breakpoint that
1603 bp_addr
= target_info
->placed_address
;
1604 bp_size
= target_info
->shadow_len
;
1606 if (bp_addr
+ bp_size
<= memaddr
)
1608 /* The breakpoint is entirely before the chunk of memory we are
1613 if (bp_addr
>= memaddr
+ len
)
1615 /* The breakpoint is entirely after the chunk of memory we are
1620 /* Offset within shadow_contents. */
1621 if (bp_addr
< memaddr
)
1623 /* Only copy the second part of the breakpoint. */
1624 bp_size
-= memaddr
- bp_addr
;
1625 bptoffset
= memaddr
- bp_addr
;
1629 if (bp_addr
+ bp_size
> memaddr
+ len
)
1631 /* Only copy the first part of the breakpoint. */
1632 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1635 if (readbuf
!= NULL
)
1637 /* Verify that the readbuf buffer does not overlap with the
1638 shadow_contents buffer. */
1639 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1640 || readbuf
>= (target_info
->shadow_contents
1641 + target_info
->shadow_len
));
1643 /* Update the read buffer with this inserted breakpoint's
1645 memcpy (readbuf
+ bp_addr
- memaddr
,
1646 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1650 const unsigned char *bp
;
1651 CORE_ADDR addr
= target_info
->reqstd_address
;
1654 /* Update the shadow with what we want to write to memory. */
1655 memcpy (target_info
->shadow_contents
+ bptoffset
,
1656 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1658 /* Determine appropriate breakpoint contents and size for this
1660 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1662 /* Update the final write buffer with this inserted
1663 breakpoint's INSN. */
1664 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1668 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1669 by replacing any memory breakpoints with their shadowed contents.
1671 If READBUF is not NULL, this buffer must not overlap with any of
1672 the breakpoint location's shadow_contents buffers. Otherwise,
1673 a failed assertion internal error will be raised.
1675 The range of shadowed area by each bp_location is:
1676 bl->address - bp_locations_placed_address_before_address_max
1677 up to bl->address + bp_locations_shadow_len_after_address_max
1678 The range we were requested to resolve shadows for is:
1679 memaddr ... memaddr + len
1680 Thus the safe cutoff boundaries for performance optimization are
1681 memaddr + len <= (bl->address
1682 - bp_locations_placed_address_before_address_max)
1684 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1687 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1688 const gdb_byte
*writebuf_org
,
1689 ULONGEST memaddr
, LONGEST len
)
1691 /* Left boundary, right boundary and median element of our binary
1693 unsigned bc_l
, bc_r
, bc
;
1695 /* Find BC_L which is a leftmost element which may affect BUF
1696 content. It is safe to report lower value but a failure to
1697 report higher one. */
1700 bc_r
= bp_locations
.size ();
1701 while (bc_l
+ 1 < bc_r
)
1703 struct bp_location
*bl
;
1705 bc
= (bc_l
+ bc_r
) / 2;
1706 bl
= bp_locations
[bc
];
1708 /* Check first BL->ADDRESS will not overflow due to the added
1709 constant. Then advance the left boundary only if we are sure
1710 the BC element can in no way affect the BUF content (MEMADDR
1711 to MEMADDR + LEN range).
1713 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1714 offset so that we cannot miss a breakpoint with its shadow
1715 range tail still reaching MEMADDR. */
1717 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1719 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1726 /* Due to the binary search above, we need to make sure we pick the
1727 first location that's at BC_L's address. E.g., if there are
1728 multiple locations at the same address, BC_L may end up pointing
1729 at a duplicate location, and miss the "master"/"inserted"
1730 location. Say, given locations L1, L2 and L3 at addresses A and
1733 L1@A, L2@A, L3@B, ...
1735 BC_L could end up pointing at location L2, while the "master"
1736 location could be L1. Since the `loc->inserted' flag is only set
1737 on "master" locations, we'd forget to restore the shadow of L1
1740 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1743 /* Now do full processing of the found relevant range of elements. */
1745 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1747 struct bp_location
*bl
= bp_locations
[bc
];
1749 /* bp_location array has BL->OWNER always non-NULL. */
1750 if (bl
->owner
->type
== bp_none
)
1751 warning (_("reading through apparently deleted breakpoint #%d?"),
1754 /* Performance optimization: any further element can no longer affect BUF
1757 if (bl
->address
>= bp_locations_placed_address_before_address_max
1760 - bp_locations_placed_address_before_address_max
)))
1763 if (!bp_location_has_shadow (bl
))
1766 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1767 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1771 /* See breakpoint.h. */
1774 is_breakpoint (const struct breakpoint
*bpt
)
1776 return (bpt
->type
== bp_breakpoint
1777 || bpt
->type
== bp_hardware_breakpoint
1778 || bpt
->type
== bp_dprintf
);
1781 /* Return true if BPT is of any hardware watchpoint kind. */
1784 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1786 return (bpt
->type
== bp_hardware_watchpoint
1787 || bpt
->type
== bp_read_watchpoint
1788 || bpt
->type
== bp_access_watchpoint
);
1791 /* See breakpoint.h. */
1794 is_watchpoint (const struct breakpoint
*bpt
)
1796 return (is_hardware_watchpoint (bpt
)
1797 || bpt
->type
== bp_watchpoint
);
1800 /* Returns true if the current thread and its running state are safe
1801 to evaluate or update watchpoint B. Watchpoints on local
1802 expressions need to be evaluated in the context of the thread that
1803 was current when the watchpoint was created, and, that thread needs
1804 to be stopped to be able to select the correct frame context.
1805 Watchpoints on global expressions can be evaluated on any thread,
1806 and in any state. It is presently left to the target allowing
1807 memory accesses when threads are running. */
1810 watchpoint_in_thread_scope (struct watchpoint
*b
)
1812 return (b
->pspace
== current_program_space
1813 && (b
->watchpoint_thread
== null_ptid
1814 || (inferior_ptid
== b
->watchpoint_thread
1815 && !inferior_thread ()->executing ())));
1818 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1819 associated bp_watchpoint_scope breakpoint. */
1822 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1824 if (w
->related_breakpoint
!= w
)
1826 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1827 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1828 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1829 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1830 w
->related_breakpoint
= w
;
1832 w
->disposition
= disp_del_at_next_stop
;
1835 /* Extract a bitfield value from value VAL using the bit parameters contained in
1838 static struct value
*
1839 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1841 struct value
*bit_val
;
1846 bit_val
= allocate_value (value_type (val
));
1848 unpack_value_bitfield (bit_val
,
1851 value_contents_for_printing (val
).data (),
1858 /* Allocate a dummy location and add it to B. This is required
1859 because bpstat_stop_status requires a location to be able to report
1863 add_dummy_location (struct breakpoint
*b
,
1864 struct program_space
*pspace
)
1866 gdb_assert (b
->loc
== NULL
);
1868 b
->loc
= new bp_location (b
, bp_loc_other
);
1869 b
->loc
->pspace
= pspace
;
1872 /* Assuming that B is a watchpoint:
1873 - Reparse watchpoint expression, if REPARSE is non-zero
1874 - Evaluate expression and store the result in B->val
1875 - Evaluate the condition if there is one, and store the result
1877 - Update the list of values that must be watched in B->loc.
1879 If the watchpoint disposition is disp_del_at_next_stop, then do
1880 nothing. If this is local watchpoint that is out of scope, delete
1883 Even with `set breakpoint always-inserted on' the watchpoints are
1884 removed + inserted on each stop here. Normal breakpoints must
1885 never be removed because they might be missed by a running thread
1886 when debugging in non-stop mode. On the other hand, hardware
1887 watchpoints (is_hardware_watchpoint; processed here) are specific
1888 to each LWP since they are stored in each LWP's hardware debug
1889 registers. Therefore, such LWP must be stopped first in order to
1890 be able to modify its hardware watchpoints.
1892 Hardware watchpoints must be reset exactly once after being
1893 presented to the user. It cannot be done sooner, because it would
1894 reset the data used to present the watchpoint hit to the user. And
1895 it must not be done later because it could display the same single
1896 watchpoint hit during multiple GDB stops. Note that the latter is
1897 relevant only to the hardware watchpoint types bp_read_watchpoint
1898 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1899 not user-visible - its hit is suppressed if the memory content has
1902 The following constraints influence the location where we can reset
1903 hardware watchpoints:
1905 * target_stopped_by_watchpoint and target_stopped_data_address are
1906 called several times when GDB stops.
1909 * Multiple hardware watchpoints can be hit at the same time,
1910 causing GDB to stop. GDB only presents one hardware watchpoint
1911 hit at a time as the reason for stopping, and all the other hits
1912 are presented later, one after the other, each time the user
1913 requests the execution to be resumed. Execution is not resumed
1914 for the threads still having pending hit event stored in
1915 LWP_INFO->STATUS. While the watchpoint is already removed from
1916 the inferior on the first stop the thread hit event is kept being
1917 reported from its cached value by linux_nat_stopped_data_address
1918 until the real thread resume happens after the watchpoint gets
1919 presented and thus its LWP_INFO->STATUS gets reset.
1921 Therefore the hardware watchpoint hit can get safely reset on the
1922 watchpoint removal from inferior. */
1925 update_watchpoint (struct watchpoint
*b
, int reparse
)
1927 int within_current_scope
;
1928 struct frame_id saved_frame_id
;
1931 /* If this is a local watchpoint, we only want to check if the
1932 watchpoint frame is in scope if the current thread is the thread
1933 that was used to create the watchpoint. */
1934 if (!watchpoint_in_thread_scope (b
))
1937 if (b
->disposition
== disp_del_at_next_stop
)
1942 /* Determine if the watchpoint is within scope. */
1943 if (b
->exp_valid_block
== NULL
)
1944 within_current_scope
= 1;
1947 frame_info_ptr fi
= get_current_frame ();
1948 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1949 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1951 /* If we're at a point where the stack has been destroyed
1952 (e.g. in a function epilogue), unwinding may not work
1953 properly. Do not attempt to recreate locations at this
1954 point. See similar comments in watchpoint_check. */
1955 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1958 /* Save the current frame's ID so we can restore it after
1959 evaluating the watchpoint expression on its own frame. */
1960 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1961 took a frame parameter, so that we didn't have to change the
1964 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1966 fi
= frame_find_by_id (b
->watchpoint_frame
);
1967 within_current_scope
= (fi
!= NULL
);
1968 if (within_current_scope
)
1972 /* We don't free locations. They are stored in the bp_location array
1973 and update_global_location_list will eventually delete them and
1974 remove breakpoints if needed. */
1977 if (within_current_scope
&& reparse
)
1982 s
= (b
->exp_string_reparse
1983 ? b
->exp_string_reparse
.get ()
1984 : b
->exp_string
.get ());
1985 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1986 /* If the meaning of expression itself changed, the old value is
1987 no longer relevant. We don't want to report a watchpoint hit
1988 to the user when the old value and the new value may actually
1989 be completely different objects. */
1991 b
->val_valid
= false;
1993 /* Note that unlike with breakpoints, the watchpoint's condition
1994 expression is stored in the breakpoint object, not in the
1995 locations (re)created below. */
1996 if (b
->cond_string
!= NULL
)
1998 b
->cond_exp
.reset ();
2000 s
= b
->cond_string
.get ();
2001 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
2005 /* If we failed to parse the expression, for example because
2006 it refers to a global variable in a not-yet-loaded shared library,
2007 don't try to insert watchpoint. We don't automatically delete
2008 such watchpoint, though, since failure to parse expression
2009 is different from out-of-scope watchpoint. */
2010 if (!target_has_execution ())
2012 /* Without execution, memory can't change. No use to try and
2013 set watchpoint locations. The watchpoint will be reset when
2014 the target gains execution, through breakpoint_re_set. */
2015 if (!can_use_hw_watchpoints
)
2017 if (b
->works_in_software_mode ())
2018 b
->type
= bp_watchpoint
;
2020 error (_("Can't set read/access watchpoint when "
2021 "hardware watchpoints are disabled."));
2024 else if (within_current_scope
&& b
->exp
)
2026 std::vector
<value_ref_ptr
> val_chain
;
2027 struct value
*v
, *result
;
2028 struct program_space
*frame_pspace
;
2030 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2033 /* Avoid setting b->val if it's already set. The meaning of
2034 b->val is 'the last value' user saw, and we should update
2035 it only if we reported that last value to user. As it
2036 happens, the code that reports it updates b->val directly.
2037 We don't keep track of the memory value for masked
2039 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2041 if (b
->val_bitsize
!= 0)
2042 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2043 b
->val
= release_value (v
);
2044 b
->val_valid
= true;
2047 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2049 /* Look at each value on the value chain. */
2050 gdb_assert (!val_chain
.empty ());
2051 for (const value_ref_ptr
&iter
: val_chain
)
2055 /* If it's a memory location, and GDB actually needed
2056 its contents to evaluate the expression, then we
2057 must watch it. If the first value returned is
2058 still lazy, that means an error occurred reading it;
2059 watch it anyway in case it becomes readable. */
2060 if (VALUE_LVAL (v
) == lval_memory
2061 && (v
== val_chain
[0] || ! value_lazy (v
)))
2063 struct type
*vtype
= check_typedef (value_type (v
));
2065 /* We only watch structs and arrays if user asked
2066 for it explicitly, never if they just happen to
2067 appear in the middle of some value chain. */
2069 || (vtype
->code () != TYPE_CODE_STRUCT
2070 && vtype
->code () != TYPE_CODE_ARRAY
))
2073 enum target_hw_bp_type type
;
2074 struct bp_location
*loc
, **tmp
;
2075 int bitpos
= 0, bitsize
= 0;
2077 if (value_bitsize (v
) != 0)
2079 /* Extract the bit parameters out from the bitfield
2081 bitpos
= value_bitpos (v
);
2082 bitsize
= value_bitsize (v
);
2084 else if (v
== result
&& b
->val_bitsize
!= 0)
2086 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2087 lvalue whose bit parameters are saved in the fields
2088 VAL_BITPOS and VAL_BITSIZE. */
2089 bitpos
= b
->val_bitpos
;
2090 bitsize
= b
->val_bitsize
;
2093 addr
= value_address (v
);
2096 /* Skip the bytes that don't contain the bitfield. */
2101 if (b
->type
== bp_read_watchpoint
)
2103 else if (b
->type
== bp_access_watchpoint
)
2106 loc
= b
->allocate_location ();
2107 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2110 loc
->gdbarch
= value_type (v
)->arch ();
2112 loc
->pspace
= frame_pspace
;
2113 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2117 /* Just cover the bytes that make up the bitfield. */
2118 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2121 loc
->length
= value_type (v
)->length ();
2123 loc
->watchpoint_type
= type
;
2128 /* Change the type of breakpoint between hardware assisted or
2129 an ordinary watchpoint depending on the hardware support
2130 and free hardware slots. REPARSE is set when the inferior
2135 enum bp_loc_type loc_type
;
2137 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2141 int i
, target_resources_ok
, other_type_used
;
2144 /* Use an exact watchpoint when there's only one memory region to be
2145 watched, and only one debug register is needed to watch it. */
2146 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2148 /* We need to determine how many resources are already
2149 used for all other hardware watchpoints plus this one
2150 to see if we still have enough resources to also fit
2151 this watchpoint in as well. */
2153 /* If this is a software watchpoint, we try to turn it
2154 to a hardware one -- count resources as if B was of
2155 hardware watchpoint type. */
2157 if (type
== bp_watchpoint
)
2158 type
= bp_hardware_watchpoint
;
2160 /* This watchpoint may or may not have been placed on
2161 the list yet at this point (it won't be in the list
2162 if we're trying to create it for the first time,
2163 through watch_command), so always account for it
2166 /* Count resources used by all watchpoints except B. */
2167 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2169 /* Add in the resources needed for B. */
2170 i
+= hw_watchpoint_use_count (b
);
2173 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2174 if (target_resources_ok
<= 0)
2176 bool sw_mode
= b
->works_in_software_mode ();
2178 if (target_resources_ok
== 0 && !sw_mode
)
2179 error (_("Target does not support this type of "
2180 "hardware watchpoint."));
2181 else if (target_resources_ok
< 0 && !sw_mode
)
2182 error (_("There are not enough available hardware "
2183 "resources for this watchpoint."));
2185 /* Downgrade to software watchpoint. */
2186 b
->type
= bp_watchpoint
;
2190 /* If this was a software watchpoint, we've just
2191 found we have enough resources to turn it to a
2192 hardware watchpoint. Otherwise, this is a
2197 else if (!b
->works_in_software_mode ())
2199 if (!can_use_hw_watchpoints
)
2200 error (_("Can't set read/access watchpoint when "
2201 "hardware watchpoints are disabled."));
2203 error (_("Expression cannot be implemented with "
2204 "read/access watchpoint."));
2207 b
->type
= bp_watchpoint
;
2209 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_software_watchpoint
2210 : bp_loc_hardware_watchpoint
);
2211 for (bp_location
*bl
: b
->locations ())
2212 bl
->loc_type
= loc_type
;
2215 /* If a software watchpoint is not watching any memory, then the
2216 above left it without any location set up. But,
2217 bpstat_stop_status requires a location to be able to report
2218 stops, so make sure there's at least a dummy one. */
2219 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2220 add_dummy_location (b
, frame_pspace
);
2222 else if (!within_current_scope
)
2225 Watchpoint %d deleted because the program has left the block\n\
2226 in which its expression is valid.\n"),
2228 watchpoint_del_at_next_stop (b
);
2231 /* Restore the selected frame. */
2233 select_frame (frame_find_by_id (saved_frame_id
));
2237 /* Returns 1 iff breakpoint location should be
2238 inserted in the inferior. We don't differentiate the type of BL's owner
2239 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2240 breakpoint_ops is not defined, because in insert_bp_location,
2241 tracepoint's insert_location will not be called. */
2243 should_be_inserted (struct bp_location
*bl
)
2245 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2248 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2251 if (!bl
->enabled
|| bl
->disabled_by_cond
2252 || bl
->shlib_disabled
|| bl
->duplicate
)
2255 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2258 /* This is set for example, when we're attached to the parent of a
2259 vfork, and have detached from the child. The child is running
2260 free, and we expect it to do an exec or exit, at which point the
2261 OS makes the parent schedulable again (and the target reports
2262 that the vfork is done). Until the child is done with the shared
2263 memory region, do not insert breakpoints in the parent, otherwise
2264 the child could still trip on the parent's breakpoints. Since
2265 the parent is blocked anyway, it won't miss any breakpoint. */
2266 if (bl
->pspace
->breakpoints_not_allowed
)
2269 /* Don't insert a breakpoint if we're trying to step past its
2270 location, except if the breakpoint is a single-step breakpoint,
2271 and the breakpoint's thread is the thread which is stepping past
2273 if ((bl
->loc_type
== bp_loc_software_breakpoint
2274 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2275 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2277 /* The single-step breakpoint may be inserted at the location
2278 we're trying to step if the instruction branches to itself.
2279 However, the instruction won't be executed at all and it may
2280 break the semantics of the instruction, for example, the
2281 instruction is a conditional branch or updates some flags.
2282 We can't fix it unless GDB is able to emulate the instruction
2283 or switch to displaced stepping. */
2284 && !(bl
->owner
->type
== bp_single_step
2285 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2287 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2288 paddress (bl
->gdbarch
, bl
->address
));
2292 /* Don't insert watchpoints if we're trying to step past the
2293 instruction that triggered one. */
2294 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2295 && stepping_past_nonsteppable_watchpoint ())
2297 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2298 "skipping watchpoint at %s:%d",
2299 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2306 /* Same as should_be_inserted but does the check assuming
2307 that the location is not duplicated. */
2310 unduplicated_should_be_inserted (struct bp_location
*bl
)
2313 const int save_duplicate
= bl
->duplicate
;
2316 result
= should_be_inserted (bl
);
2317 bl
->duplicate
= save_duplicate
;
2321 /* Parses a conditional described by an expression COND into an
2322 agent expression bytecode suitable for evaluation
2323 by the bytecode interpreter. Return NULL if there was
2324 any error during parsing. */
2326 static agent_expr_up
2327 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2332 agent_expr_up aexpr
;
2334 /* We don't want to stop processing, so catch any errors
2335 that may show up. */
2338 aexpr
= gen_eval_for_expr (scope
, cond
);
2341 catch (const gdb_exception_error
&ex
)
2343 /* If we got here, it means the condition could not be parsed to a valid
2344 bytecode expression and thus can't be evaluated on the target's side.
2345 It's no use iterating through the conditions. */
2348 /* We have a valid agent expression. */
2352 /* Based on location BL, create a list of breakpoint conditions to be
2353 passed on to the target. If we have duplicated locations with different
2354 conditions, we will add such conditions to the list. The idea is that the
2355 target will evaluate the list of conditions and will only notify GDB when
2356 one of them is true. */
2359 build_target_condition_list (struct bp_location
*bl
)
2361 int null_condition_or_parse_error
= 0;
2362 int modified
= bl
->needs_update
;
2364 /* Release conditions left over from a previous insert. */
2365 bl
->target_info
.conditions
.clear ();
2367 /* This is only meaningful if the target is
2368 evaluating conditions and if the user has
2369 opted for condition evaluation on the target's
2371 if (gdb_evaluates_breakpoint_condition_p ()
2372 || !target_supports_evaluation_of_breakpoint_conditions ())
2375 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2377 /* Do a first pass to check for locations with no assigned
2378 conditions or conditions that fail to parse to a valid agent
2379 expression bytecode. If any of these happen, then it's no use to
2380 send conditions to the target since this location will always
2381 trigger and generate a response back to GDB. Note we consider
2382 all locations at the same address irrespective of type, i.e.,
2383 even if the locations aren't considered duplicates (e.g.,
2384 software breakpoint and hardware breakpoint at the same
2386 for (bp_location
*loc
: loc_range
)
2388 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2392 /* Re-parse the conditions since something changed. In that
2393 case we already freed the condition bytecodes (see
2394 force_breakpoint_reinsertion). We just
2395 need to parse the condition to bytecodes again. */
2396 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2400 /* If we have a NULL bytecode expression, it means something
2401 went wrong or we have a null condition expression. */
2402 if (!loc
->cond_bytecode
)
2404 null_condition_or_parse_error
= 1;
2410 /* If any of these happened, it means we will have to evaluate the conditions
2411 for the location's address on gdb's side. It is no use keeping bytecodes
2412 for all the other duplicate locations, thus we free all of them here.
2414 This is so we have a finer control over which locations' conditions are
2415 being evaluated by GDB or the remote stub. */
2416 if (null_condition_or_parse_error
)
2418 for (bp_location
*loc
: loc_range
)
2420 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2422 /* Only go as far as the first NULL bytecode is
2424 if (!loc
->cond_bytecode
)
2427 loc
->cond_bytecode
.reset ();
2432 /* No NULL conditions or failed bytecode generation. Build a
2433 condition list for this location's address. If we have software
2434 and hardware locations at the same address, they aren't
2435 considered duplicates, but we still marge all the conditions
2436 anyway, as it's simpler, and doesn't really make a practical
2438 for (bp_location
*loc
: loc_range
)
2440 && is_breakpoint (loc
->owner
)
2441 && loc
->pspace
->num
== bl
->pspace
->num
2442 && loc
->owner
->enable_state
== bp_enabled
2444 && !loc
->disabled_by_cond
)
2446 /* Add the condition to the vector. This will be used later
2447 to send the conditions to the target. */
2448 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2454 /* Parses a command described by string CMD into an agent expression
2455 bytecode suitable for evaluation by the bytecode interpreter.
2456 Return NULL if there was any error during parsing. */
2458 static agent_expr_up
2459 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2461 const char *cmdrest
;
2462 const char *format_start
, *format_end
;
2463 struct gdbarch
*gdbarch
= get_current_arch ();
2470 if (*cmdrest
== ',')
2472 cmdrest
= skip_spaces (cmdrest
);
2474 if (*cmdrest
++ != '"')
2475 error (_("No format string following the location"));
2477 format_start
= cmdrest
;
2479 format_pieces
fpieces (&cmdrest
);
2481 format_end
= cmdrest
;
2483 if (*cmdrest
++ != '"')
2484 error (_("Bad format string, non-terminated '\"'."));
2486 cmdrest
= skip_spaces (cmdrest
);
2488 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2489 error (_("Invalid argument syntax"));
2491 if (*cmdrest
== ',')
2493 cmdrest
= skip_spaces (cmdrest
);
2495 /* For each argument, make an expression. */
2497 std::vector
<struct expression
*> argvec
;
2498 while (*cmdrest
!= '\0')
2503 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2504 argvec
.push_back (expr
.release ());
2506 if (*cmdrest
== ',')
2510 agent_expr_up aexpr
;
2512 /* We don't want to stop processing, so catch any errors
2513 that may show up. */
2516 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2517 format_start
, format_end
- format_start
,
2518 argvec
.size (), argvec
.data ());
2520 catch (const gdb_exception_error
&ex
)
2522 /* If we got here, it means the command could not be parsed to a valid
2523 bytecode expression and thus can't be evaluated on the target's side.
2524 It's no use iterating through the other commands. */
2527 /* We have a valid agent expression, return it. */
2531 /* Based on location BL, create a list of breakpoint commands to be
2532 passed on to the target. If we have duplicated locations with
2533 different commands, we will add any such to the list. */
2536 build_target_command_list (struct bp_location
*bl
)
2538 int null_command_or_parse_error
= 0;
2539 int modified
= bl
->needs_update
;
2541 /* Clear commands left over from a previous insert. */
2542 bl
->target_info
.tcommands
.clear ();
2544 if (!target_can_run_breakpoint_commands ())
2547 /* For now, limit to agent-style dprintf breakpoints. */
2548 if (dprintf_style
!= dprintf_style_agent
)
2551 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2553 /* For now, if we have any location at the same address that isn't a
2554 dprintf, don't install the target-side commands, as that would
2555 make the breakpoint not be reported to the core, and we'd lose
2557 for (bp_location
*loc
: loc_range
)
2558 if (is_breakpoint (loc
->owner
)
2559 && loc
->pspace
->num
== bl
->pspace
->num
2560 && loc
->owner
->type
!= bp_dprintf
)
2563 /* Do a first pass to check for locations with no assigned
2564 conditions or conditions that fail to parse to a valid agent expression
2565 bytecode. If any of these happen, then it's no use to send conditions
2566 to the target since this location will always trigger and generate a
2567 response back to GDB. */
2568 for (bp_location
*loc
: loc_range
)
2570 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2574 /* Re-parse the commands since something changed. In that
2575 case we already freed the command bytecodes (see
2576 force_breakpoint_reinsertion). We just
2577 need to parse the command to bytecodes again. */
2579 = parse_cmd_to_aexpr (bl
->address
,
2580 loc
->owner
->extra_string
.get ());
2583 /* If we have a NULL bytecode expression, it means something
2584 went wrong or we have a null command expression. */
2585 if (!loc
->cmd_bytecode
)
2587 null_command_or_parse_error
= 1;
2593 /* If anything failed, then we're not doing target-side commands,
2595 if (null_command_or_parse_error
)
2597 for (bp_location
*loc
: loc_range
)
2598 if (is_breakpoint (loc
->owner
)
2599 && loc
->pspace
->num
== bl
->pspace
->num
)
2601 /* Only go as far as the first NULL bytecode is
2603 if (loc
->cmd_bytecode
== NULL
)
2606 loc
->cmd_bytecode
.reset ();
2610 /* No NULL commands or failed bytecode generation. Build a command
2611 list for all duplicate locations at this location's address.
2612 Note that here we must care for whether the breakpoint location
2613 types are considered duplicates, otherwise, say, if we have a
2614 software and hardware location at the same address, the target
2615 could end up running the commands twice. For the moment, we only
2616 support targets-side commands with dprintf, but it doesn't hurt
2617 to be pedantically correct in case that changes. */
2618 for (bp_location
*loc
: loc_range
)
2619 if (breakpoint_locations_match (bl
, loc
)
2620 && loc
->owner
->extra_string
2621 && is_breakpoint (loc
->owner
)
2622 && loc
->pspace
->num
== bl
->pspace
->num
2623 && loc
->owner
->enable_state
== bp_enabled
2625 && !loc
->disabled_by_cond
)
2627 /* Add the command to the vector. This will be used later
2628 to send the commands to the target. */
2629 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2632 bl
->target_info
.persist
= 0;
2633 /* Maybe flag this location as persistent. */
2634 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2635 bl
->target_info
.persist
= 1;
2638 /* Return the kind of breakpoint on address *ADDR. Get the kind
2639 of breakpoint according to ADDR except single-step breakpoint.
2640 Get the kind of single-step breakpoint according to the current
2644 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2646 if (bl
->owner
->type
== bp_single_step
)
2648 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2649 struct regcache
*regcache
;
2651 regcache
= get_thread_regcache (thr
);
2653 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2657 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2660 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2661 location. Any error messages are printed to TMP_ERROR_STREAM; and
2662 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2663 Returns 0 for success, 1 if the bp_location type is not supported or
2666 NOTE drow/2003-09-09: This routine could be broken down to an
2667 object-style method for each breakpoint or catchpoint type. */
2669 insert_bp_location (struct bp_location
*bl
,
2670 struct ui_file
*tmp_error_stream
,
2671 int *disabled_breaks
,
2672 int *hw_breakpoint_error
,
2673 int *hw_bp_error_explained_already
)
2675 gdb_exception bp_excpt
;
2677 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2680 /* Note we don't initialize bl->target_info, as that wipes out
2681 the breakpoint location's shadow_contents if the breakpoint
2682 is still inserted at that location. This in turn breaks
2683 target_read_memory which depends on these buffers when
2684 a memory read is requested at the breakpoint location:
2685 Once the target_info has been wiped, we fail to see that
2686 we have a breakpoint inserted at that address and thus
2687 read the breakpoint instead of returning the data saved in
2688 the breakpoint location's shadow contents. */
2689 bl
->target_info
.reqstd_address
= bl
->address
;
2690 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2691 bl
->target_info
.length
= bl
->length
;
2693 /* When working with target-side conditions, we must pass all the conditions
2694 for the same breakpoint address down to the target since GDB will not
2695 insert those locations. With a list of breakpoint conditions, the target
2696 can decide when to stop and notify GDB. */
2698 if (is_breakpoint (bl
->owner
))
2700 build_target_condition_list (bl
);
2701 build_target_command_list (bl
);
2702 /* Reset the modification marker. */
2703 bl
->needs_update
= 0;
2706 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2707 set at a read-only address, then a breakpoint location will have
2708 been changed to hardware breakpoint before we get here. If it is
2709 "off" however, error out before actually trying to insert the
2710 breakpoint, with a nicer error message. */
2711 if (bl
->loc_type
== bp_loc_software_breakpoint
2712 && !automatic_hardware_breakpoints
)
2714 mem_region
*mr
= lookup_mem_region (bl
->address
);
2716 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2718 gdb_printf (tmp_error_stream
,
2719 _("Cannot insert breakpoint %d.\n"
2720 "Cannot set software breakpoint "
2721 "at read-only address %s\n"),
2723 paddress (bl
->gdbarch
, bl
->address
));
2728 if (bl
->loc_type
== bp_loc_software_breakpoint
2729 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2731 /* First check to see if we have to handle an overlay. */
2732 if (overlay_debugging
== ovly_off
2733 || bl
->section
== NULL
2734 || !(section_is_overlay (bl
->section
)))
2736 /* No overlay handling: just set the breakpoint. */
2741 val
= bl
->owner
->insert_location (bl
);
2743 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2745 catch (gdb_exception
&e
)
2747 bp_excpt
= std::move (e
);
2752 /* This breakpoint is in an overlay section.
2753 Shall we set a breakpoint at the LMA? */
2754 if (!overlay_events_enabled
)
2756 /* Yes -- overlay event support is not active,
2757 so we must try to set a breakpoint at the LMA.
2758 This will not work for a hardware breakpoint. */
2759 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2760 warning (_("hardware breakpoint %d not supported in overlay!"),
2764 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2766 /* Set a software (trap) breakpoint at the LMA. */
2767 bl
->overlay_target_info
= bl
->target_info
;
2768 bl
->overlay_target_info
.reqstd_address
= addr
;
2770 /* No overlay handling: just set the breakpoint. */
2775 bl
->overlay_target_info
.kind
2776 = breakpoint_kind (bl
, &addr
);
2777 bl
->overlay_target_info
.placed_address
= addr
;
2778 val
= target_insert_breakpoint (bl
->gdbarch
,
2779 &bl
->overlay_target_info
);
2782 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2784 catch (gdb_exception
&e
)
2786 bp_excpt
= std::move (e
);
2789 if (bp_excpt
.reason
!= 0)
2790 gdb_printf (tmp_error_stream
,
2791 "Overlay breakpoint %d "
2792 "failed: in ROM?\n",
2796 /* Shall we set a breakpoint at the VMA? */
2797 if (section_is_mapped (bl
->section
))
2799 /* Yes. This overlay section is mapped into memory. */
2804 val
= bl
->owner
->insert_location (bl
);
2806 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2808 catch (gdb_exception
&e
)
2810 bp_excpt
= std::move (e
);
2815 /* No. This breakpoint will not be inserted.
2816 No error, but do not mark the bp as 'inserted'. */
2821 if (bp_excpt
.reason
!= 0)
2823 /* Can't set the breakpoint. */
2825 /* If the target has closed then it will have deleted any
2826 breakpoints inserted within the target inferior, as a result
2827 any further attempts to interact with the breakpoint objects
2828 is not possible. Just rethrow the error. */
2829 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2831 gdb_assert (bl
->owner
!= nullptr);
2833 /* In some cases, we might not be able to insert a
2834 breakpoint in a shared library that has already been
2835 removed, but we have not yet processed the shlib unload
2836 event. Unfortunately, some targets that implement
2837 breakpoint insertion themselves can't tell why the
2838 breakpoint insertion failed (e.g., the remote target
2839 doesn't define error codes), so we must treat generic
2840 errors as memory errors. */
2841 if (bp_excpt
.reason
== RETURN_ERROR
2842 && (bp_excpt
.error
== GENERIC_ERROR
2843 || bp_excpt
.error
== MEMORY_ERROR
)
2844 && bl
->loc_type
== bp_loc_software_breakpoint
2845 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2846 || shared_objfile_contains_address_p (bl
->pspace
,
2849 /* See also: disable_breakpoints_in_shlibs. */
2850 bl
->shlib_disabled
= 1;
2851 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2852 if (!*disabled_breaks
)
2854 gdb_printf (tmp_error_stream
,
2855 "Cannot insert breakpoint %d.\n",
2857 gdb_printf (tmp_error_stream
,
2858 "Temporarily disabling shared "
2859 "library breakpoints:\n");
2861 *disabled_breaks
= 1;
2862 gdb_printf (tmp_error_stream
,
2863 "breakpoint #%d\n", bl
->owner
->number
);
2868 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2870 *hw_breakpoint_error
= 1;
2871 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2872 gdb_printf (tmp_error_stream
,
2873 "Cannot insert hardware breakpoint %d%s",
2875 bp_excpt
.message
? ":" : ".\n");
2876 if (bp_excpt
.message
!= NULL
)
2877 gdb_printf (tmp_error_stream
, "%s.\n",
2882 if (bp_excpt
.message
== NULL
)
2885 = memory_error_message (TARGET_XFER_E_IO
,
2886 bl
->gdbarch
, bl
->address
);
2888 gdb_printf (tmp_error_stream
,
2889 "Cannot insert breakpoint %d.\n"
2891 bl
->owner
->number
, message
.c_str ());
2895 gdb_printf (tmp_error_stream
,
2896 "Cannot insert breakpoint %d: %s\n",
2911 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2912 /* NOTE drow/2003-09-08: This state only exists for removing
2913 watchpoints. It's not clear that it's necessary... */
2914 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2918 val
= bl
->owner
->insert_location (bl
);
2920 /* If trying to set a read-watchpoint, and it turns out it's not
2921 supported, try emulating one with an access watchpoint. */
2922 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2924 /* But don't try to insert it, if there's already another
2925 hw_access location that would be considered a duplicate
2927 for (bp_location
*loc
: all_bp_locations ())
2929 && loc
->watchpoint_type
== hw_access
2930 && watchpoint_locations_match (bl
, loc
))
2934 bl
->target_info
= loc
->target_info
;
2935 bl
->watchpoint_type
= hw_access
;
2942 bl
->watchpoint_type
= hw_access
;
2943 val
= bl
->owner
->insert_location (bl
);
2946 /* Back to the original value. */
2947 bl
->watchpoint_type
= hw_read
;
2951 bl
->inserted
= (val
== 0);
2954 else if (bl
->owner
->type
== bp_catchpoint
)
2958 val
= bl
->owner
->insert_location (bl
);
2961 bl
->owner
->enable_state
= bp_disabled
;
2965 Error inserting catchpoint %d: Your system does not support this type\n\
2966 of catchpoint."), bl
->owner
->number
);
2968 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2971 bl
->inserted
= (val
== 0);
2973 /* We've already printed an error message if there was a problem
2974 inserting this catchpoint, and we've disabled the catchpoint,
2975 so just return success. */
2982 /* This function is called when program space PSPACE is about to be
2983 deleted. It takes care of updating breakpoints to not reference
2987 breakpoint_program_space_exit (struct program_space
*pspace
)
2989 /* Remove any breakpoint that was set through this program space. */
2990 for (breakpoint
*b
: all_breakpoints_safe ())
2991 if (b
->pspace
== pspace
)
2992 delete_breakpoint (b
);
2994 /* Breakpoints set through other program spaces could have locations
2995 bound to PSPACE as well. Remove those. */
2996 for (bp_location
*loc
: all_bp_locations ())
2998 struct bp_location
*tmp
;
3000 if (loc
->pspace
== pspace
)
3002 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3003 if (loc
->owner
->loc
== loc
)
3004 loc
->owner
->loc
= loc
->next
;
3006 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3007 if (tmp
->next
== loc
)
3009 tmp
->next
= loc
->next
;
3015 /* Now update the global location list to permanently delete the
3016 removed locations above. */
3017 update_global_location_list (UGLL_DONT_INSERT
);
3020 /* Make sure all breakpoints are inserted in inferior.
3021 Throws exception on any error.
3022 A breakpoint that is already inserted won't be inserted
3023 again, so calling this function twice is safe. */
3025 insert_breakpoints (void)
3027 for (breakpoint
*bpt
: all_breakpoints ())
3028 if (is_hardware_watchpoint (bpt
))
3030 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3032 update_watchpoint (w
, 0 /* don't reparse. */);
3035 /* Updating watchpoints creates new locations, so update the global
3036 location list. Explicitly tell ugll to insert locations and
3037 ignore breakpoints_always_inserted_mode. Also,
3038 update_global_location_list tries to "upgrade" software
3039 breakpoints to hardware breakpoints to handle "set breakpoint
3040 auto-hw", so we need to call it even if we don't have new
3042 update_global_location_list (UGLL_INSERT
);
3045 /* This is used when we need to synch breakpoint conditions between GDB and the
3046 target. It is the case with deleting and disabling of breakpoints when using
3047 always-inserted mode. */
3050 update_inserted_breakpoint_locations (void)
3054 int disabled_breaks
= 0;
3055 int hw_breakpoint_error
= 0;
3056 int hw_bp_details_reported
= 0;
3058 string_file tmp_error_stream
;
3060 /* Explicitly mark the warning -- this will only be printed if
3061 there was an error. */
3062 tmp_error_stream
.puts ("Warning:\n");
3064 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3066 for (bp_location
*bl
: all_bp_locations ())
3068 /* We only want to update software breakpoints and hardware
3070 if (!is_breakpoint (bl
->owner
))
3073 /* We only want to update locations that are already inserted
3074 and need updating. This is to avoid unwanted insertion during
3075 deletion of breakpoints. */
3076 if (!bl
->inserted
|| !bl
->needs_update
)
3079 switch_to_program_space_and_thread (bl
->pspace
);
3081 /* For targets that support global breakpoints, there's no need
3082 to select an inferior to insert breakpoint to. In fact, even
3083 if we aren't attached to any process yet, we should still
3084 insert breakpoints. */
3085 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3086 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3089 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3090 &hw_breakpoint_error
, &hw_bp_details_reported
);
3097 target_terminal::ours_for_output ();
3098 error_stream (tmp_error_stream
);
3102 /* Used when starting or continuing the program. */
3105 insert_breakpoint_locations (void)
3109 int disabled_breaks
= 0;
3110 int hw_breakpoint_error
= 0;
3111 int hw_bp_error_explained_already
= 0;
3113 string_file tmp_error_stream
;
3115 /* Explicitly mark the warning -- this will only be printed if
3116 there was an error. */
3117 tmp_error_stream
.puts ("Warning:\n");
3119 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3121 for (bp_location
*bl
: all_bp_locations ())
3123 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3126 /* There is no point inserting thread-specific breakpoints if
3127 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3128 has BL->OWNER always non-NULL. */
3129 if (bl
->owner
->thread
!= -1
3130 && !valid_global_thread_id (bl
->owner
->thread
))
3133 switch_to_program_space_and_thread (bl
->pspace
);
3135 /* For targets that support global breakpoints, there's no need
3136 to select an inferior to insert breakpoint to. In fact, even
3137 if we aren't attached to any process yet, we should still
3138 insert breakpoints. */
3139 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3140 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3143 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3144 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3149 /* If we failed to insert all locations of a watchpoint, remove
3150 them, as half-inserted watchpoint is of limited use. */
3151 for (breakpoint
*bpt
: all_breakpoints ())
3153 int some_failed
= 0;
3155 if (!is_hardware_watchpoint (bpt
))
3158 if (!breakpoint_enabled (bpt
))
3161 if (bpt
->disposition
== disp_del_at_next_stop
)
3164 for (bp_location
*loc
: bpt
->locations ())
3165 if (!loc
->inserted
&& should_be_inserted (loc
))
3173 for (bp_location
*loc
: bpt
->locations ())
3175 remove_breakpoint (loc
);
3177 hw_breakpoint_error
= 1;
3178 tmp_error_stream
.printf ("Could not insert "
3179 "hardware watchpoint %d.\n",
3187 /* If a hardware breakpoint or watchpoint was inserted, add a
3188 message about possibly exhausted resources. */
3189 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3191 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3192 You may have requested too many hardware breakpoints/watchpoints.\n");
3194 target_terminal::ours_for_output ();
3195 error_stream (tmp_error_stream
);
3199 /* Used when the program stops.
3200 Returns zero if successful, or non-zero if there was a problem
3201 removing a breakpoint location. */
3204 remove_breakpoints (void)
3208 for (bp_location
*bl
: all_bp_locations ())
3209 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3210 val
|= remove_breakpoint (bl
);
3215 /* When a thread exits, remove breakpoints that are related to
3219 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3221 for (breakpoint
*b
: all_breakpoints_safe ())
3223 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3225 b
->disposition
= disp_del_at_next_stop
;
3228 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3229 b
->number
, print_thread_id (tp
));
3231 /* Hide it from the user. */
3237 /* See breakpoint.h. */
3240 remove_breakpoints_inf (inferior
*inf
)
3244 for (bp_location
*bl
: all_bp_locations ())
3246 if (bl
->pspace
!= inf
->pspace
)
3249 if (bl
->inserted
&& !bl
->target_info
.persist
)
3251 val
= remove_breakpoint (bl
);
3258 static int internal_breakpoint_number
= -1;
3260 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3261 If INTERNAL is non-zero, the breakpoint number will be populated
3262 from internal_breakpoint_number and that variable decremented.
3263 Otherwise the breakpoint number will be populated from
3264 breakpoint_count and that value incremented. Internal breakpoints
3265 do not set the internal var bpnum. */
3267 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3270 b
->number
= internal_breakpoint_number
--;
3273 set_breakpoint_count (breakpoint_count
+ 1);
3274 b
->number
= breakpoint_count
;
3278 static struct breakpoint
*
3279 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3280 CORE_ADDR address
, enum bptype type
)
3282 std::unique_ptr
<internal_breakpoint
> b
3283 (new internal_breakpoint (gdbarch
, type
, address
));
3285 b
->number
= internal_breakpoint_number
--;
3287 return add_to_breakpoint_chain (std::move (b
));
3290 static const char *const longjmp_names
[] =
3292 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3294 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3296 /* Per-objfile data private to breakpoint.c. */
3297 struct breakpoint_objfile_data
3299 /* Minimal symbol for "_ovly_debug_event" (if any). */
3300 struct bound_minimal_symbol overlay_msym
;
3302 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3303 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3305 /* True if we have looked for longjmp probes. */
3306 int longjmp_searched
= 0;
3308 /* SystemTap probe points for longjmp (if any). These are non-owning
3310 std::vector
<probe
*> longjmp_probes
;
3312 /* Minimal symbol for "std::terminate()" (if any). */
3313 struct bound_minimal_symbol terminate_msym
;
3315 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3316 struct bound_minimal_symbol exception_msym
;
3318 /* True if we have looked for exception probes. */
3319 int exception_searched
= 0;
3321 /* SystemTap probe points for unwinding (if any). These are non-owning
3323 std::vector
<probe
*> exception_probes
;
3326 static const registry
<objfile
>::key
<breakpoint_objfile_data
>
3327 breakpoint_objfile_key
;
3329 /* Minimal symbol not found sentinel. */
3330 static struct minimal_symbol msym_not_found
;
3332 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3335 msym_not_found_p (const struct minimal_symbol
*msym
)
3337 return msym
== &msym_not_found
;
3340 /* Return per-objfile data needed by breakpoint.c.
3341 Allocate the data if necessary. */
3343 static struct breakpoint_objfile_data
*
3344 get_breakpoint_objfile_data (struct objfile
*objfile
)
3346 struct breakpoint_objfile_data
*bp_objfile_data
;
3348 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3349 if (bp_objfile_data
== NULL
)
3350 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3351 return bp_objfile_data
;
3355 create_overlay_event_breakpoint (void)
3357 const char *const func_name
= "_ovly_debug_event";
3359 for (objfile
*objfile
: current_program_space
->objfiles ())
3361 struct breakpoint
*b
;
3362 struct breakpoint_objfile_data
*bp_objfile_data
;
3365 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3367 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3370 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3372 struct bound_minimal_symbol m
;
3374 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3375 if (m
.minsym
== NULL
)
3377 /* Avoid future lookups in this objfile. */
3378 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3381 bp_objfile_data
->overlay_msym
= m
;
3384 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3385 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3387 b
->locspec
= new_explicit_location_spec_function (func_name
);
3389 if (overlay_debugging
== ovly_auto
)
3391 b
->enable_state
= bp_enabled
;
3392 overlay_events_enabled
= 1;
3396 b
->enable_state
= bp_disabled
;
3397 overlay_events_enabled
= 0;
3402 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3403 true if a breakpoint was installed. */
3406 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3408 struct gdbarch
*gdbarch
= objfile
->arch ();
3409 struct breakpoint_objfile_data
*bp_objfile_data
3410 = get_breakpoint_objfile_data (objfile
);
3412 if (!bp_objfile_data
->longjmp_searched
)
3414 std::vector
<probe
*> ret
3415 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3419 /* We are only interested in checking one element. */
3422 if (!p
->can_evaluate_arguments ())
3424 /* We cannot use the probe interface here,
3425 because it does not know how to evaluate
3430 bp_objfile_data
->longjmp_probes
= ret
;
3431 bp_objfile_data
->longjmp_searched
= 1;
3434 if (bp_objfile_data
->longjmp_probes
.empty ())
3437 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3439 struct breakpoint
*b
;
3441 b
= create_internal_breakpoint (gdbarch
,
3442 p
->get_relocated_address (objfile
),
3444 b
->locspec
= new_probe_location_spec ("-probe-stap libc:longjmp");
3445 b
->enable_state
= bp_disabled
;
3451 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3452 Return true if at least one breakpoint was installed. */
3455 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3457 struct gdbarch
*gdbarch
= objfile
->arch ();
3458 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3461 struct breakpoint_objfile_data
*bp_objfile_data
3462 = get_breakpoint_objfile_data (objfile
);
3463 unsigned int installed_bp
= 0;
3465 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3467 struct breakpoint
*b
;
3468 const char *func_name
;
3471 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3474 func_name
= longjmp_names
[i
];
3475 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3477 struct bound_minimal_symbol m
;
3479 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3480 if (m
.minsym
== NULL
)
3482 /* Prevent future lookups in this objfile. */
3483 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3486 bp_objfile_data
->longjmp_msym
[i
] = m
;
3489 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3490 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3491 b
->locspec
= new_explicit_location_spec_function (func_name
);
3492 b
->enable_state
= bp_disabled
;
3496 return installed_bp
> 0;
3499 /* Create a master longjmp breakpoint. */
3502 create_longjmp_master_breakpoint (void)
3504 scoped_restore_current_program_space restore_pspace
;
3506 for (struct program_space
*pspace
: program_spaces
)
3508 set_current_program_space (pspace
);
3510 for (objfile
*obj
: current_program_space
->objfiles ())
3512 /* Skip separate debug object, it's handled in the loop below. */
3513 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3516 /* Try a probe kind breakpoint on main objfile. */
3517 if (create_longjmp_master_breakpoint_probe (obj
))
3520 /* Try longjmp_names kind breakpoints on main and separate_debug
3522 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3523 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3529 /* Create a master std::terminate breakpoint. */
3531 create_std_terminate_master_breakpoint (void)
3533 const char *const func_name
= "std::terminate()";
3535 scoped_restore_current_program_space restore_pspace
;
3537 for (struct program_space
*pspace
: program_spaces
)
3541 set_current_program_space (pspace
);
3543 for (objfile
*objfile
: current_program_space
->objfiles ())
3545 struct breakpoint
*b
;
3546 struct breakpoint_objfile_data
*bp_objfile_data
;
3548 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3550 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3553 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3555 struct bound_minimal_symbol m
;
3557 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3558 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3559 && m
.minsym
->type () != mst_file_text
))
3561 /* Prevent future lookups in this objfile. */
3562 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3565 bp_objfile_data
->terminate_msym
= m
;
3568 addr
= bp_objfile_data
->terminate_msym
.value_address ();
3569 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3570 bp_std_terminate_master
);
3571 b
->locspec
= new_explicit_location_spec_function (func_name
);
3572 b
->enable_state
= bp_disabled
;
3577 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3578 probe. Return true if a breakpoint was installed. */
3581 create_exception_master_breakpoint_probe (objfile
*objfile
)
3583 struct breakpoint
*b
;
3584 struct gdbarch
*gdbarch
;
3585 struct breakpoint_objfile_data
*bp_objfile_data
;
3587 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3589 /* We prefer the SystemTap probe point if it exists. */
3590 if (!bp_objfile_data
->exception_searched
)
3592 std::vector
<probe
*> ret
3593 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3597 /* We are only interested in checking one element. */
3600 if (!p
->can_evaluate_arguments ())
3602 /* We cannot use the probe interface here, because it does
3603 not know how to evaluate arguments. */
3607 bp_objfile_data
->exception_probes
= ret
;
3608 bp_objfile_data
->exception_searched
= 1;
3611 if (bp_objfile_data
->exception_probes
.empty ())
3614 gdbarch
= objfile
->arch ();
3616 for (probe
*p
: bp_objfile_data
->exception_probes
)
3618 b
= create_internal_breakpoint (gdbarch
,
3619 p
->get_relocated_address (objfile
),
3620 bp_exception_master
);
3621 b
->locspec
= new_probe_location_spec ("-probe-stap libgcc:unwind");
3622 b
->enable_state
= bp_disabled
;
3628 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3629 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3632 create_exception_master_breakpoint_hook (objfile
*objfile
)
3634 const char *const func_name
= "_Unwind_DebugHook";
3635 struct breakpoint
*b
;
3636 struct gdbarch
*gdbarch
;
3637 struct breakpoint_objfile_data
*bp_objfile_data
;
3640 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3642 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3645 gdbarch
= objfile
->arch ();
3647 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3649 struct bound_minimal_symbol debug_hook
;
3651 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3652 if (debug_hook
.minsym
== NULL
)
3654 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3658 bp_objfile_data
->exception_msym
= debug_hook
;
3661 addr
= bp_objfile_data
->exception_msym
.value_address ();
3662 addr
= gdbarch_convert_from_func_ptr_addr
3663 (gdbarch
, addr
, current_inferior ()->top_target ());
3664 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
3665 b
->locspec
= new_explicit_location_spec_function (func_name
);
3666 b
->enable_state
= bp_disabled
;
3671 /* Install a master breakpoint on the unwinder's debug hook. */
3674 create_exception_master_breakpoint (void)
3676 for (objfile
*obj
: current_program_space
->objfiles ())
3678 /* Skip separate debug object. */
3679 if (obj
->separate_debug_objfile_backlink
)
3682 /* Try a probe kind breakpoint. */
3683 if (create_exception_master_breakpoint_probe (obj
))
3686 /* Iterate over main and separate debug objects and try an
3687 _Unwind_DebugHook kind breakpoint. */
3688 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3689 if (create_exception_master_breakpoint_hook (debug_objfile
))
3694 /* Does B have a location spec? */
3697 breakpoint_location_spec_empty_p (const struct breakpoint
*b
)
3699 return (b
->locspec
!= nullptr && b
->locspec
->empty_p ());
3703 update_breakpoints_after_exec (void)
3705 /* We're about to delete breakpoints from GDB's lists. If the
3706 INSERTED flag is true, GDB will try to lift the breakpoints by
3707 writing the breakpoints' "shadow contents" back into memory. The
3708 "shadow contents" are NOT valid after an exec, so GDB should not
3709 do that. Instead, the target is responsible from marking
3710 breakpoints out as soon as it detects an exec. We don't do that
3711 here instead, because there may be other attempts to delete
3712 breakpoints after detecting an exec and before reaching here. */
3713 for (bp_location
*bploc
: all_bp_locations ())
3714 if (bploc
->pspace
== current_program_space
)
3715 gdb_assert (!bploc
->inserted
);
3717 for (breakpoint
*b
: all_breakpoints_safe ())
3719 if (b
->pspace
!= current_program_space
)
3722 /* Solib breakpoints must be explicitly reset after an exec(). */
3723 if (b
->type
== bp_shlib_event
)
3725 delete_breakpoint (b
);
3729 /* JIT breakpoints must be explicitly reset after an exec(). */
3730 if (b
->type
== bp_jit_event
)
3732 delete_breakpoint (b
);
3736 /* Thread event breakpoints must be set anew after an exec(),
3737 as must overlay event and longjmp master breakpoints. */
3738 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3739 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3740 || b
->type
== bp_exception_master
)
3742 delete_breakpoint (b
);
3746 /* Step-resume breakpoints are meaningless after an exec(). */
3747 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3749 delete_breakpoint (b
);
3753 /* Just like single-step breakpoints. */
3754 if (b
->type
== bp_single_step
)
3756 delete_breakpoint (b
);
3760 /* Longjmp and longjmp-resume breakpoints are also meaningless
3762 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3763 || b
->type
== bp_longjmp_call_dummy
3764 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3766 delete_breakpoint (b
);
3770 if (b
->type
== bp_catchpoint
)
3772 /* For now, none of the bp_catchpoint breakpoints need to
3773 do anything at this point. In the future, if some of
3774 the catchpoints need to something, we will need to add
3775 a new method, and call this method from here. */
3779 /* bp_finish is a special case. The only way we ought to be able
3780 to see one of these when an exec() has happened, is if the user
3781 caught a vfork, and then said "finish". Ordinarily a finish just
3782 carries them to the call-site of the current callee, by setting
3783 a temporary bp there and resuming. But in this case, the finish
3784 will carry them entirely through the vfork & exec.
3786 We don't want to allow a bp_finish to remain inserted now. But
3787 we can't safely delete it, 'cause finish_command has a handle to
3788 the bp on a bpstat, and will later want to delete it. There's a
3789 chance (and I've seen it happen) that if we delete the bp_finish
3790 here, that its storage will get reused by the time finish_command
3791 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3792 We really must allow finish_command to delete a bp_finish.
3794 In the absence of a general solution for the "how do we know
3795 it's safe to delete something others may have handles to?"
3796 problem, what we'll do here is just uninsert the bp_finish, and
3797 let finish_command delete it.
3799 (We know the bp_finish is "doomed" in the sense that it's
3800 momentary, and will be deleted as soon as finish_command sees
3801 the inferior stopped. So it doesn't matter that the bp's
3802 address is probably bogus in the new a.out, unlike e.g., the
3803 solib breakpoints.) */
3805 if (b
->type
== bp_finish
)
3810 /* Without a symbolic address, we have little hope of the
3811 pre-exec() address meaning the same thing in the post-exec()
3813 if (breakpoint_location_spec_empty_p (b
))
3815 delete_breakpoint (b
);
3822 detach_breakpoints (ptid_t ptid
)
3825 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3826 struct inferior
*inf
= current_inferior ();
3828 if (ptid
.pid () == inferior_ptid
.pid ())
3829 error (_("Cannot detach breakpoints of inferior_ptid"));
3831 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3832 inferior_ptid
= ptid
;
3833 for (bp_location
*bl
: all_bp_locations ())
3835 if (bl
->pspace
!= inf
->pspace
)
3838 /* This function must physically remove breakpoints locations
3839 from the specified ptid, without modifying the breakpoint
3840 package's state. Locations of type bp_loc_other and
3841 bp_loc_software_watchpoint are only maintained at GDB side,
3842 so there is no need to remove them. Moreover, removing these
3843 would modify the breakpoint package's state. */
3844 if (bl
->loc_type
== bp_loc_other
3845 || bl
->loc_type
== bp_loc_software_watchpoint
)
3849 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3855 /* Remove the breakpoint location BL from the current address space.
3856 Note that this is used to detach breakpoints from a child fork.
3857 When we get here, the child isn't in the inferior list, and neither
3858 do we have objects to represent its address space --- we should
3859 *not* look at bl->pspace->aspace here. */
3862 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3866 /* BL is never in moribund_locations by our callers. */
3867 gdb_assert (bl
->owner
!= NULL
);
3869 /* The type of none suggests that owner is actually deleted.
3870 This should not ever happen. */
3871 gdb_assert (bl
->owner
->type
!= bp_none
);
3873 if (bl
->loc_type
== bp_loc_software_breakpoint
3874 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3876 /* "Normal" instruction breakpoint: either the standard
3877 trap-instruction bp (bp_breakpoint), or a
3878 bp_hardware_breakpoint. */
3880 /* First check to see if we have to handle an overlay. */
3881 if (overlay_debugging
== ovly_off
3882 || bl
->section
== NULL
3883 || !(section_is_overlay (bl
->section
)))
3885 /* No overlay handling: just remove the breakpoint. */
3887 /* If we're trying to uninsert a memory breakpoint that we
3888 know is set in a dynamic object that is marked
3889 shlib_disabled, then either the dynamic object was
3890 removed with "remove-symbol-file" or with
3891 "nosharedlibrary". In the former case, we don't know
3892 whether another dynamic object might have loaded over the
3893 breakpoint's address -- the user might well let us know
3894 about it next with add-symbol-file (the whole point of
3895 add-symbol-file is letting the user manually maintain a
3896 list of dynamically loaded objects). If we have the
3897 breakpoint's shadow memory, that is, this is a software
3898 breakpoint managed by GDB, check whether the breakpoint
3899 is still inserted in memory, to avoid overwriting wrong
3900 code with stale saved shadow contents. Note that HW
3901 breakpoints don't have shadow memory, as they're
3902 implemented using a mechanism that is not dependent on
3903 being able to modify the target's memory, and as such
3904 they should always be removed. */
3905 if (bl
->shlib_disabled
3906 && bl
->target_info
.shadow_len
!= 0
3907 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3910 val
= bl
->owner
->remove_location (bl
, reason
);
3914 /* This breakpoint is in an overlay section.
3915 Did we set a breakpoint at the LMA? */
3916 if (!overlay_events_enabled
)
3918 /* Yes -- overlay event support is not active, so we
3919 should have set a breakpoint at the LMA. Remove it.
3921 /* Ignore any failures: if the LMA is in ROM, we will
3922 have already warned when we failed to insert it. */
3923 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3924 target_remove_hw_breakpoint (bl
->gdbarch
,
3925 &bl
->overlay_target_info
);
3927 target_remove_breakpoint (bl
->gdbarch
,
3928 &bl
->overlay_target_info
,
3931 /* Did we set a breakpoint at the VMA?
3932 If so, we will have marked the breakpoint 'inserted'. */
3935 /* Yes -- remove it. Previously we did not bother to
3936 remove the breakpoint if the section had been
3937 unmapped, but let's not rely on that being safe. We
3938 don't know what the overlay manager might do. */
3940 /* However, we should remove *software* breakpoints only
3941 if the section is still mapped, or else we overwrite
3942 wrong code with the saved shadow contents. */
3943 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3944 || section_is_mapped (bl
->section
))
3945 val
= bl
->owner
->remove_location (bl
, reason
);
3951 /* No -- not inserted, so no need to remove. No error. */
3956 /* In some cases, we might not be able to remove a breakpoint in
3957 a shared library that has already been removed, but we have
3958 not yet processed the shlib unload event. Similarly for an
3959 unloaded add-symbol-file object - the user might not yet have
3960 had the chance to remove-symbol-file it. shlib_disabled will
3961 be set if the library/object has already been removed, but
3962 the breakpoint hasn't been uninserted yet, e.g., after
3963 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3964 always-inserted mode. */
3966 && (bl
->loc_type
== bp_loc_software_breakpoint
3967 && (bl
->shlib_disabled
3968 || solib_name_from_address (bl
->pspace
, bl
->address
)
3969 || shared_objfile_contains_address_p (bl
->pspace
,
3975 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3977 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3979 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3980 bl
->owner
->remove_location (bl
, reason
);
3982 /* Failure to remove any of the hardware watchpoints comes here. */
3983 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3984 warning (_("Could not remove hardware watchpoint %d."),
3987 else if (bl
->owner
->type
== bp_catchpoint
3988 && breakpoint_enabled (bl
->owner
)
3991 val
= bl
->owner
->remove_location (bl
, reason
);
3995 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4002 remove_breakpoint (struct bp_location
*bl
)
4004 /* BL is never in moribund_locations by our callers. */
4005 gdb_assert (bl
->owner
!= NULL
);
4007 /* The type of none suggests that owner is actually deleted.
4008 This should not ever happen. */
4009 gdb_assert (bl
->owner
->type
!= bp_none
);
4011 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4013 switch_to_program_space_and_thread (bl
->pspace
);
4015 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4018 /* Clear the "inserted" flag in all breakpoints. */
4021 mark_breakpoints_out (void)
4023 for (bp_location
*bl
: all_bp_locations ())
4024 if (bl
->pspace
== current_program_space
)
4028 /* Clear the "inserted" flag in all breakpoints and delete any
4029 breakpoints which should go away between runs of the program.
4031 Plus other such housekeeping that has to be done for breakpoints
4034 Note: this function gets called at the end of a run (by
4035 generic_mourn_inferior) and when a run begins (by
4036 init_wait_for_inferior). */
4041 breakpoint_init_inferior (enum inf_context context
)
4043 struct program_space
*pspace
= current_program_space
;
4045 /* If breakpoint locations are shared across processes, then there's
4047 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4050 mark_breakpoints_out ();
4052 for (breakpoint
*b
: all_breakpoints_safe ())
4054 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4060 case bp_longjmp_call_dummy
:
4062 /* If the call dummy breakpoint is at the entry point it will
4063 cause problems when the inferior is rerun, so we better get
4066 case bp_watchpoint_scope
:
4068 /* Also get rid of scope breakpoints. */
4070 case bp_shlib_event
:
4072 /* Also remove solib event breakpoints. Their addresses may
4073 have changed since the last time we ran the program.
4074 Actually we may now be debugging against different target;
4075 and so the solib backend that installed this breakpoint may
4076 not be used in by the target. E.g.,
4078 (gdb) file prog-linux
4079 (gdb) run # native linux target
4082 (gdb) file prog-win.exe
4083 (gdb) tar rem :9999 # remote Windows gdbserver.
4086 case bp_step_resume
:
4088 /* Also remove step-resume breakpoints. */
4090 case bp_single_step
:
4092 /* Also remove single-step breakpoints. */
4094 delete_breakpoint (b
);
4098 case bp_hardware_watchpoint
:
4099 case bp_read_watchpoint
:
4100 case bp_access_watchpoint
:
4102 struct watchpoint
*w
= (struct watchpoint
*) b
;
4104 /* Likewise for watchpoints on local expressions. */
4105 if (w
->exp_valid_block
!= NULL
)
4106 delete_breakpoint (b
);
4109 /* Get rid of existing locations, which are no longer
4110 valid. New ones will be created in
4111 update_watchpoint, when the inferior is restarted.
4112 The next update_global_location_list call will
4113 garbage collect them. */
4116 if (context
== inf_starting
)
4118 /* Reset val field to force reread of starting value in
4119 insert_breakpoints. */
4120 w
->val
.reset (nullptr);
4121 w
->val_valid
= false;
4131 /* Get rid of the moribund locations. */
4132 for (bp_location
*bl
: moribund_locations
)
4133 decref_bp_location (&bl
);
4134 moribund_locations
.clear ();
4137 /* These functions concern about actual breakpoints inserted in the
4138 target --- to e.g. check if we need to do decr_pc adjustment or if
4139 we need to hop over the bkpt --- so we check for address space
4140 match, not program space. */
4142 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4143 exists at PC. It returns ordinary_breakpoint_here if it's an
4144 ordinary breakpoint, or permanent_breakpoint_here if it's a
4145 permanent breakpoint.
4146 - When continuing from a location with an ordinary breakpoint, we
4147 actually single step once before calling insert_breakpoints.
4148 - When continuing from a location with a permanent breakpoint, we
4149 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4150 the target, to advance the PC past the breakpoint. */
4152 enum breakpoint_here
4153 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4155 int any_breakpoint_here
= 0;
4157 for (bp_location
*bl
: all_bp_locations ())
4159 if (bl
->loc_type
!= bp_loc_software_breakpoint
4160 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4163 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4164 if ((breakpoint_enabled (bl
->owner
)
4166 && breakpoint_location_address_match (bl
, aspace
, pc
))
4168 if (overlay_debugging
4169 && section_is_overlay (bl
->section
)
4170 && !section_is_mapped (bl
->section
))
4171 continue; /* unmapped overlay -- can't be a match */
4172 else if (bl
->permanent
)
4173 return permanent_breakpoint_here
;
4175 any_breakpoint_here
= 1;
4179 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4182 /* See breakpoint.h. */
4185 breakpoint_in_range_p (const address_space
*aspace
,
4186 CORE_ADDR addr
, ULONGEST len
)
4188 for (bp_location
*bl
: all_bp_locations ())
4190 if (bl
->loc_type
!= bp_loc_software_breakpoint
4191 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4194 if ((breakpoint_enabled (bl
->owner
)
4196 && breakpoint_location_address_range_overlap (bl
, aspace
,
4199 if (overlay_debugging
4200 && section_is_overlay (bl
->section
)
4201 && !section_is_mapped (bl
->section
))
4203 /* Unmapped overlay -- can't be a match. */
4214 /* Return true if there's a moribund breakpoint at PC. */
4217 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4219 for (bp_location
*loc
: moribund_locations
)
4220 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4226 /* Returns non-zero iff BL is inserted at PC, in address space
4230 bp_location_inserted_here_p (struct bp_location
*bl
,
4231 const address_space
*aspace
, CORE_ADDR pc
)
4234 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4237 if (overlay_debugging
4238 && section_is_overlay (bl
->section
)
4239 && !section_is_mapped (bl
->section
))
4240 return 0; /* unmapped overlay -- can't be a match */
4247 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4250 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4252 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4254 if (bl
->loc_type
!= bp_loc_software_breakpoint
4255 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4258 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4264 /* This function returns non-zero iff there is a software breakpoint
4268 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4271 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4273 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4276 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4283 /* See breakpoint.h. */
4286 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4289 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4291 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4294 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4302 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4303 CORE_ADDR addr
, ULONGEST len
)
4305 for (breakpoint
*bpt
: all_breakpoints ())
4307 if (bpt
->type
!= bp_hardware_watchpoint
4308 && bpt
->type
!= bp_access_watchpoint
)
4311 if (!breakpoint_enabled (bpt
))
4314 for (bp_location
*loc
: bpt
->locations ())
4315 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4319 /* Check for intersection. */
4320 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4321 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4329 /* See breakpoint.h. */
4332 is_catchpoint (struct breakpoint
*b
)
4334 return (b
->type
== bp_catchpoint
);
4337 /* Clear a bpstat so that it says we are not at any breakpoint.
4338 Also free any storage that is part of a bpstat. */
4341 bpstat_clear (bpstat
**bsp
)
4358 bpstat::bpstat (const bpstat
&other
)
4360 bp_location_at (other
.bp_location_at
),
4361 breakpoint_at (other
.breakpoint_at
),
4362 commands (other
.commands
),
4363 print (other
.print
),
4365 print_it (other
.print_it
)
4367 if (other
.old_val
!= NULL
)
4368 old_val
= release_value (value_copy (other
.old_val
.get ()));
4371 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4372 is part of the bpstat is copied as well. */
4375 bpstat_copy (bpstat
*bs
)
4377 bpstat
*p
= nullptr;
4379 bpstat
*retval
= nullptr;
4384 for (; bs
!= NULL
; bs
= bs
->next
)
4386 tmp
= new bpstat (*bs
);
4389 /* This is the first thing in the chain. */
4399 /* Find the bpstat associated with this breakpoint. */
4402 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4407 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4409 if (bsp
->breakpoint_at
== breakpoint
)
4415 /* See breakpoint.h. */
4418 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4420 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4422 if (bsp
->breakpoint_at
== NULL
)
4424 /* A moribund location can never explain a signal other than
4426 if (sig
== GDB_SIGNAL_TRAP
)
4431 if (bsp
->breakpoint_at
->explains_signal (sig
))
4439 /* Put in *NUM the breakpoint number of the first breakpoint we are
4440 stopped at. *BSP upon return is a bpstat which points to the
4441 remaining breakpoints stopped at (but which is not guaranteed to be
4442 good for anything but further calls to bpstat_num).
4444 Return 0 if passed a bpstat which does not indicate any breakpoints.
4445 Return -1 if stopped at a breakpoint that has been deleted since
4447 Return 1 otherwise. */
4450 bpstat_num (bpstat
**bsp
, int *num
)
4452 struct breakpoint
*b
;
4455 return 0; /* No more breakpoint values */
4457 /* We assume we'll never have several bpstats that correspond to a
4458 single breakpoint -- otherwise, this function might return the
4459 same number more than once and this will look ugly. */
4460 b
= (*bsp
)->breakpoint_at
;
4461 *bsp
= (*bsp
)->next
;
4463 return -1; /* breakpoint that's been deleted since */
4465 *num
= b
->number
; /* We have its number */
4469 /* See breakpoint.h. */
4472 bpstat_clear_actions (void)
4476 if (inferior_ptid
== null_ptid
)
4479 thread_info
*tp
= inferior_thread ();
4480 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4482 bs
->commands
= NULL
;
4483 bs
->old_val
.reset (nullptr);
4487 /* Called when a command is about to proceed the inferior. */
4490 breakpoint_about_to_proceed (void)
4492 if (inferior_ptid
!= null_ptid
)
4494 struct thread_info
*tp
= inferior_thread ();
4496 /* Allow inferior function calls in breakpoint commands to not
4497 interrupt the command list. When the call finishes
4498 successfully, the inferior will be standing at the same
4499 breakpoint as if nothing happened. */
4500 if (tp
->control
.in_infcall
)
4504 breakpoint_proceeded
= 1;
4507 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4508 or its equivalent. */
4511 command_line_is_silent (struct command_line
*cmd
)
4513 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4516 /* Execute all the commands associated with all the breakpoints at
4517 this location. Any of these commands could cause the process to
4518 proceed beyond this point, etc. We look out for such changes by
4519 checking the global "breakpoint_proceeded" after each command.
4521 Returns true if a breakpoint command resumed the inferior. In that
4522 case, it is the caller's responsibility to recall it again with the
4523 bpstat of the current thread. */
4526 bpstat_do_actions_1 (bpstat
**bsp
)
4531 /* Avoid endless recursion if a `source' command is contained
4533 if (executing_breakpoint_commands
)
4536 scoped_restore save_executing
4537 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4539 scoped_restore preventer
= prevent_dont_repeat ();
4541 /* This pointer will iterate over the list of bpstat's. */
4544 breakpoint_proceeded
= 0;
4545 for (; bs
!= NULL
; bs
= bs
->next
)
4547 struct command_line
*cmd
= NULL
;
4549 /* Take ownership of the BSP's command tree, if it has one.
4551 The command tree could legitimately contain commands like
4552 'step' and 'next', which call clear_proceed_status, which
4553 frees stop_bpstat's command tree. To make sure this doesn't
4554 free the tree we're executing out from under us, we need to
4555 take ownership of the tree ourselves. Since a given bpstat's
4556 commands are only executed once, we don't need to copy it; we
4557 can clear the pointer in the bpstat, and make sure we free
4558 the tree when we're done. */
4559 counted_command_line ccmd
= bs
->commands
;
4560 bs
->commands
= NULL
;
4563 if (command_line_is_silent (cmd
))
4565 /* The action has been already done by bpstat_stop_status. */
4571 execute_control_command (cmd
);
4573 if (breakpoint_proceeded
)
4579 if (breakpoint_proceeded
)
4581 if (current_ui
->async
)
4582 /* If we are in async mode, then the target might be still
4583 running, not stopped at any breakpoint, so nothing for
4584 us to do here -- just return to the event loop. */
4587 /* In sync mode, when execute_control_command returns
4588 we're already standing on the next breakpoint.
4589 Breakpoint commands for that stop were not run, since
4590 execute_command does not run breakpoint commands --
4591 only command_line_handler does, but that one is not
4592 involved in execution of breakpoint commands. So, we
4593 can now execute breakpoint commands. It should be
4594 noted that making execute_command do bpstat actions is
4595 not an option -- in this case we'll have recursive
4596 invocation of bpstat for each breakpoint with a
4597 command, and can easily blow up GDB stack. Instead, we
4598 return true, which will trigger the caller to recall us
4599 with the new stop_bpstat. */
4607 /* Helper for bpstat_do_actions. Get the current thread, if there's
4608 one, is alive and has execution. Return NULL otherwise. */
4610 static thread_info
*
4611 get_bpstat_thread ()
4613 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4616 thread_info
*tp
= inferior_thread ();
4617 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4623 bpstat_do_actions (void)
4625 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4628 /* Do any commands attached to breakpoint we are stopped at. */
4629 while ((tp
= get_bpstat_thread ()) != NULL
)
4631 /* Since in sync mode, bpstat_do_actions may resume the
4632 inferior, and only return when it is stopped at the next
4633 breakpoint, we keep doing breakpoint actions until it returns
4634 false to indicate the inferior was not resumed. */
4635 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4639 cleanup_if_error
.release ();
4642 /* Print out the (old or new) value associated with a watchpoint. */
4645 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4648 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4651 struct value_print_options opts
;
4652 get_user_print_options (&opts
);
4653 value_print (val
, stream
, &opts
);
4657 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4658 debugging multiple threads. */
4661 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4663 if (uiout
->is_mi_like_p ())
4668 if (show_thread_that_caused_stop ())
4670 struct thread_info
*thr
= inferior_thread ();
4672 uiout
->text ("Thread ");
4673 uiout
->field_string ("thread-id", print_thread_id (thr
));
4675 const char *name
= thread_name (thr
);
4678 uiout
->text (" \"");
4679 uiout
->field_string ("name", name
);
4683 uiout
->text (" hit ");
4687 /* Generic routine for printing messages indicating why we
4688 stopped. The behavior of this function depends on the value
4689 'print_it' in the bpstat structure. Under some circumstances we
4690 may decide not to print anything here and delegate the task to
4693 static enum print_stop_action
4694 print_bp_stop_message (bpstat
*bs
)
4696 switch (bs
->print_it
)
4699 /* Nothing should be printed for this bpstat entry. */
4700 return PRINT_UNKNOWN
;
4704 /* We still want to print the frame, but we already printed the
4705 relevant messages. */
4706 return PRINT_SRC_AND_LOC
;
4709 case print_it_normal
:
4711 struct breakpoint
*b
= bs
->breakpoint_at
;
4713 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4714 which has since been deleted. */
4716 return PRINT_UNKNOWN
;
4718 /* Normal case. Call the breakpoint's print_it method. */
4719 return b
->print_it (bs
);
4724 internal_error (_("print_bp_stop_message: unrecognized enum value"));
4729 /* See breakpoint.h. */
4732 print_solib_event (bool is_catchpoint
)
4734 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4735 bool any_added
= !current_program_space
->added_solibs
.empty ();
4739 if (any_added
|| any_deleted
)
4740 current_uiout
->text (_("Stopped due to shared library event:\n"));
4742 current_uiout
->text (_("Stopped due to shared library event (no "
4743 "libraries added or removed)\n"));
4746 if (current_uiout
->is_mi_like_p ())
4747 current_uiout
->field_string ("reason",
4748 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4752 current_uiout
->text (_(" Inferior unloaded "));
4753 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4754 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4756 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4759 current_uiout
->text (" ");
4760 current_uiout
->field_string ("library", name
);
4761 current_uiout
->text ("\n");
4767 current_uiout
->text (_(" Inferior loaded "));
4768 ui_out_emit_list
list_emitter (current_uiout
, "added");
4770 for (so_list
*iter
: current_program_space
->added_solibs
)
4773 current_uiout
->text (" ");
4775 current_uiout
->field_string ("library", iter
->so_name
);
4776 current_uiout
->text ("\n");
4781 /* Print a message indicating what happened. This is called from
4782 normal_stop(). The input to this routine is the head of the bpstat
4783 list - a list of the eventpoints that caused this stop. KIND is
4784 the target_waitkind for the stopping event. This
4785 routine calls the generic print routine for printing a message
4786 about reasons for stopping. This will print (for example) the
4787 "Breakpoint n," part of the output. The return value of this
4790 PRINT_UNKNOWN: Means we printed nothing.
4791 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4792 code to print the location. An example is
4793 "Breakpoint 1, " which should be followed by
4795 PRINT_SRC_ONLY: Means we printed something, but there is no need
4796 to also print the location part of the message.
4797 An example is the catch/throw messages, which
4798 don't require a location appended to the end.
4799 PRINT_NOTHING: We have done some printing and we don't need any
4800 further info to be printed. */
4802 enum print_stop_action
4803 bpstat_print (bpstat
*bs
, target_waitkind kind
)
4805 enum print_stop_action val
;
4807 /* Maybe another breakpoint in the chain caused us to stop.
4808 (Currently all watchpoints go on the bpstat whether hit or not.
4809 That probably could (should) be changed, provided care is taken
4810 with respect to bpstat_explains_signal). */
4811 for (; bs
; bs
= bs
->next
)
4813 val
= print_bp_stop_message (bs
);
4814 if (val
== PRINT_SRC_ONLY
4815 || val
== PRINT_SRC_AND_LOC
4816 || val
== PRINT_NOTHING
)
4820 /* If we had hit a shared library event breakpoint,
4821 print_bp_stop_message would print out this message. If we hit an
4822 OS-level shared library event, do the same thing. */
4823 if (kind
== TARGET_WAITKIND_LOADED
)
4825 print_solib_event (false);
4826 return PRINT_NOTHING
;
4829 /* We reached the end of the chain, or we got a null BS to start
4830 with and nothing was printed. */
4831 return PRINT_UNKNOWN
;
4834 /* Evaluate the boolean expression EXP and return the result. */
4837 breakpoint_cond_eval (expression
*exp
)
4839 scoped_value_mark mark
;
4840 return value_true (evaluate_expression (exp
));
4843 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4845 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4847 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4848 breakpoint_at (bl
->owner
),
4852 print_it (print_it_normal
)
4854 **bs_link_pointer
= this;
4855 *bs_link_pointer
= &next
;
4860 breakpoint_at (NULL
),
4864 print_it (print_it_normal
)
4868 /* The target has stopped with waitstatus WS. Check if any hardware
4869 watchpoints have triggered, according to the target. */
4872 watchpoints_triggered (const target_waitstatus
&ws
)
4874 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4877 if (!stopped_by_watchpoint
)
4879 /* We were not stopped by a watchpoint. Mark all watchpoints
4880 as not triggered. */
4881 for (breakpoint
*b
: all_breakpoints ())
4882 if (is_hardware_watchpoint (b
))
4884 struct watchpoint
*w
= (struct watchpoint
*) b
;
4886 w
->watchpoint_triggered
= watch_triggered_no
;
4892 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4894 /* We were stopped by a watchpoint, but we don't know where.
4895 Mark all watchpoints as unknown. */
4896 for (breakpoint
*b
: all_breakpoints ())
4897 if (is_hardware_watchpoint (b
))
4899 struct watchpoint
*w
= (struct watchpoint
*) b
;
4901 w
->watchpoint_triggered
= watch_triggered_unknown
;
4907 /* The target could report the data address. Mark watchpoints
4908 affected by this data address as triggered, and all others as not
4911 for (breakpoint
*b
: all_breakpoints ())
4912 if (is_hardware_watchpoint (b
))
4914 struct watchpoint
*w
= (struct watchpoint
*) b
;
4916 w
->watchpoint_triggered
= watch_triggered_no
;
4917 for (bp_location
*loc
: b
->locations ())
4919 if (is_masked_watchpoint (b
))
4921 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4922 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4924 if (newaddr
== start
)
4926 w
->watchpoint_triggered
= watch_triggered_yes
;
4930 /* Exact match not required. Within range is sufficient. */
4931 else if (target_watchpoint_addr_within_range
4932 (current_inferior ()->top_target (), addr
, loc
->address
,
4935 w
->watchpoint_triggered
= watch_triggered_yes
;
4944 /* Possible return values for watchpoint_check. */
4945 enum wp_check_result
4947 /* The watchpoint has been deleted. */
4950 /* The value has changed. */
4951 WP_VALUE_CHANGED
= 2,
4953 /* The value has not changed. */
4954 WP_VALUE_NOT_CHANGED
= 3,
4956 /* Ignore this watchpoint, no matter if the value changed or not. */
4960 #define BP_TEMPFLAG 1
4961 #define BP_HARDWAREFLAG 2
4963 /* Evaluate watchpoint condition expression and check if its value
4966 static wp_check_result
4967 watchpoint_check (bpstat
*bs
)
4969 struct watchpoint
*b
;
4971 int within_current_scope
;
4973 /* BS is built from an existing struct breakpoint. */
4974 gdb_assert (bs
->breakpoint_at
!= NULL
);
4975 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4977 /* If this is a local watchpoint, we only want to check if the
4978 watchpoint frame is in scope if the current thread is the thread
4979 that was used to create the watchpoint. */
4980 if (!watchpoint_in_thread_scope (b
))
4983 if (b
->exp_valid_block
== NULL
)
4984 within_current_scope
= 1;
4987 frame_info_ptr frame
= get_current_frame ();
4988 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4989 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4991 /* stack_frame_destroyed_p() returns a non-zero value if we're
4992 still in the function but the stack frame has already been
4993 invalidated. Since we can't rely on the values of local
4994 variables after the stack has been destroyed, we are treating
4995 the watchpoint in that state as `not changed' without further
4996 checking. Don't mark watchpoints as changed if the current
4997 frame is in an epilogue - even if they are in some other
4998 frame, our view of the stack is likely to be wrong and
4999 frame_find_by_id could error out. */
5000 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5003 fr
= frame_find_by_id (b
->watchpoint_frame
);
5004 within_current_scope
= (fr
!= NULL
);
5006 /* If we've gotten confused in the unwinder, we might have
5007 returned a frame that can't describe this variable. */
5008 if (within_current_scope
)
5010 struct symbol
*function
;
5012 function
= get_frame_function (fr
);
5013 if (function
== NULL
5014 || !contained_in (b
->exp_valid_block
, function
->value_block ()))
5015 within_current_scope
= 0;
5018 if (within_current_scope
)
5019 /* If we end up stopping, the current frame will get selected
5020 in normal_stop. So this call to select_frame won't affect
5025 if (within_current_scope
)
5027 /* We use value_{,free_to_}mark because it could be a *long*
5028 time before we return to the command level and call
5029 free_all_values. We can't call free_all_values because we
5030 might be in the middle of evaluating a function call. */
5033 struct value
*new_val
;
5035 if (is_masked_watchpoint (b
))
5036 /* Since we don't know the exact trigger address (from
5037 stopped_data_address), just tell the user we've triggered
5038 a mask watchpoint. */
5039 return WP_VALUE_CHANGED
;
5041 mark
= value_mark ();
5042 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5045 if (b
->val_bitsize
!= 0)
5046 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5048 /* We use value_equal_contents instead of value_equal because
5049 the latter coerces an array to a pointer, thus comparing just
5050 the address of the array instead of its contents. This is
5051 not what we want. */
5052 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5053 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5056 bs
->old_val
= b
->val
;
5057 b
->val
= release_value (new_val
);
5058 b
->val_valid
= true;
5059 if (new_val
!= NULL
)
5060 value_free_to_mark (mark
);
5061 return WP_VALUE_CHANGED
;
5065 /* Nothing changed. */
5066 value_free_to_mark (mark
);
5067 return WP_VALUE_NOT_CHANGED
;
5072 /* This seems like the only logical thing to do because
5073 if we temporarily ignored the watchpoint, then when
5074 we reenter the block in which it is valid it contains
5075 garbage (in the case of a function, it may have two
5076 garbage values, one before and one after the prologue).
5077 So we can't even detect the first assignment to it and
5078 watch after that (since the garbage may or may not equal
5079 the first value assigned). */
5080 /* We print all the stop information in
5081 breakpointprint_it, but in this case, by the time we
5082 call breakpoint->print_it this bp will be deleted
5083 already. So we have no choice but print the information
5086 SWITCH_THRU_ALL_UIS ()
5088 struct ui_out
*uiout
= current_uiout
;
5090 if (uiout
->is_mi_like_p ())
5092 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5093 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5094 "left the block in\n"
5095 "which its expression is valid.\n",
5096 signed_field ("wpnum", b
->number
));
5099 /* Make sure the watchpoint's commands aren't executed. */
5101 watchpoint_del_at_next_stop (b
);
5107 /* Return true if it looks like target has stopped due to hitting
5108 breakpoint location BL. This function does not check if we should
5109 stop, only if BL explains the stop. */
5112 bpstat_check_location (const struct bp_location
*bl
,
5113 const address_space
*aspace
, CORE_ADDR bp_addr
,
5114 const target_waitstatus
&ws
)
5116 struct breakpoint
*b
= bl
->owner
;
5118 /* BL is from an existing breakpoint. */
5119 gdb_assert (b
!= NULL
);
5121 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5124 /* Determine if the watched values have actually changed, and we
5125 should stop. If not, set BS->stop to 0. */
5128 bpstat_check_watchpoint (bpstat
*bs
)
5130 const struct bp_location
*bl
;
5131 struct watchpoint
*b
;
5133 /* BS is built for existing struct breakpoint. */
5134 bl
= bs
->bp_location_at
.get ();
5135 gdb_assert (bl
!= NULL
);
5136 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5137 gdb_assert (b
!= NULL
);
5140 int must_check_value
= 0;
5142 if (b
->type
== bp_watchpoint
)
5143 /* For a software watchpoint, we must always check the
5145 must_check_value
= 1;
5146 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5147 /* We have a hardware watchpoint (read, write, or access)
5148 and the target earlier reported an address watched by
5150 must_check_value
= 1;
5151 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5152 && b
->type
== bp_hardware_watchpoint
)
5153 /* We were stopped by a hardware watchpoint, but the target could
5154 not report the data address. We must check the watchpoint's
5155 value. Access and read watchpoints are out of luck; without
5156 a data address, we can't figure it out. */
5157 must_check_value
= 1;
5159 if (must_check_value
)
5165 e
= watchpoint_check (bs
);
5167 catch (const gdb_exception
&ex
)
5169 exception_fprintf (gdb_stderr
, ex
,
5170 "Error evaluating expression "
5171 "for watchpoint %d\n",
5174 SWITCH_THRU_ALL_UIS ()
5176 gdb_printf (_("Watchpoint %d deleted.\n"),
5179 watchpoint_del_at_next_stop (b
);
5186 /* We've already printed what needs to be printed. */
5187 bs
->print_it
= print_it_done
;
5191 bs
->print_it
= print_it_noop
;
5194 case WP_VALUE_CHANGED
:
5195 if (b
->type
== bp_read_watchpoint
)
5197 /* There are two cases to consider here:
5199 1. We're watching the triggered memory for reads.
5200 In that case, trust the target, and always report
5201 the watchpoint hit to the user. Even though
5202 reads don't cause value changes, the value may
5203 have changed since the last time it was read, and
5204 since we're not trapping writes, we will not see
5205 those, and as such we should ignore our notion of
5208 2. We're watching the triggered memory for both
5209 reads and writes. There are two ways this may
5212 2.1. This is a target that can't break on data
5213 reads only, but can break on accesses (reads or
5214 writes), such as e.g., x86. We detect this case
5215 at the time we try to insert read watchpoints.
5217 2.2. Otherwise, the target supports read
5218 watchpoints, but, the user set an access or write
5219 watchpoint watching the same memory as this read
5222 If we're watching memory writes as well as reads,
5223 ignore watchpoint hits when we find that the
5224 value hasn't changed, as reads don't cause
5225 changes. This still gives false positives when
5226 the program writes the same value to memory as
5227 what there was already in memory (we will confuse
5228 it for a read), but it's much better than
5231 int other_write_watchpoint
= 0;
5233 if (bl
->watchpoint_type
== hw_read
)
5235 for (breakpoint
*other_b
: all_breakpoints ())
5236 if (other_b
->type
== bp_hardware_watchpoint
5237 || other_b
->type
== bp_access_watchpoint
)
5239 struct watchpoint
*other_w
=
5240 (struct watchpoint
*) other_b
;
5242 if (other_w
->watchpoint_triggered
5243 == watch_triggered_yes
)
5245 other_write_watchpoint
= 1;
5251 if (other_write_watchpoint
5252 || bl
->watchpoint_type
== hw_access
)
5254 /* We're watching the same memory for writes,
5255 and the value changed since the last time we
5256 updated it, so this trap must be for a write.
5258 bs
->print_it
= print_it_noop
;
5263 case WP_VALUE_NOT_CHANGED
:
5264 if (b
->type
== bp_hardware_watchpoint
5265 || b
->type
== bp_watchpoint
)
5267 /* Don't stop: write watchpoints shouldn't fire if
5268 the value hasn't changed. */
5269 bs
->print_it
= print_it_noop
;
5279 else /* must_check_value == 0 */
5281 /* This is a case where some watchpoint(s) triggered, but
5282 not at the address of this watchpoint, or else no
5283 watchpoint triggered after all. So don't print
5284 anything for this watchpoint. */
5285 bs
->print_it
= print_it_noop
;
5291 /* For breakpoints that are currently marked as telling gdb to stop,
5292 check conditions (condition proper, frame, thread and ignore count)
5293 of breakpoint referred to by BS. If we should not stop for this
5294 breakpoint, set BS->stop to 0. */
5297 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5299 INFRUN_SCOPED_DEBUG_ENTER_EXIT
;
5301 const struct bp_location
*bl
;
5302 struct breakpoint
*b
;
5304 bool condition_result
= true;
5305 struct expression
*cond
;
5307 gdb_assert (bs
->stop
);
5309 /* BS is built for existing struct breakpoint. */
5310 bl
= bs
->bp_location_at
.get ();
5311 gdb_assert (bl
!= NULL
);
5312 b
= bs
->breakpoint_at
;
5313 gdb_assert (b
!= NULL
);
5315 infrun_debug_printf ("thread = %s, breakpoint %d.%d",
5316 thread
->ptid
.to_string ().c_str (),
5317 b
->number
, find_loc_num_by_location (bl
));
5319 /* Even if the target evaluated the condition on its end and notified GDB, we
5320 need to do so again since GDB does not know if we stopped due to a
5321 breakpoint or a single step breakpoint. */
5323 if (frame_id_p (b
->frame_id
)
5324 && b
->frame_id
!= get_stack_frame_id (get_current_frame ()))
5326 infrun_debug_printf ("incorrect frame %s not %s, not stopping",
5327 get_stack_frame_id (get_current_frame ()).to_string ().c_str (),
5328 b
->frame_id
.to_string ().c_str ());
5333 /* If this is a thread/task-specific breakpoint, don't waste cpu
5334 evaluating the condition if this isn't the specified
5336 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5337 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5339 infrun_debug_printf ("incorrect thread or task, not stopping");
5344 /* Evaluate extension language breakpoints that have a "stop" method
5346 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5348 if (is_watchpoint (b
))
5350 struct watchpoint
*w
= (struct watchpoint
*) b
;
5352 cond
= w
->cond_exp
.get ();
5355 cond
= bl
->cond
.get ();
5357 if (cond
!= nullptr && b
->disposition
!= disp_del_at_next_stop
)
5359 int within_current_scope
= 1;
5360 struct watchpoint
* w
;
5362 /* We use scoped_value_mark because it could be a long time
5363 before we return to the command level and call
5364 free_all_values. We can't call free_all_values because we
5365 might be in the middle of evaluating a function call. */
5366 scoped_value_mark mark
;
5368 if (is_watchpoint (b
))
5369 w
= (struct watchpoint
*) b
;
5373 /* Need to select the frame, with all that implies so that
5374 the conditions will have the right context. Because we
5375 use the frame, we will not see an inlined function's
5376 variables when we arrive at a breakpoint at the start
5377 of the inlined function; the current frame will be the
5379 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5380 select_frame (get_current_frame ());
5383 frame_info_ptr frame
;
5385 /* For local watchpoint expressions, which particular
5386 instance of a local is being watched matters, so we
5387 keep track of the frame to evaluate the expression
5388 in. To evaluate the condition however, it doesn't
5389 really matter which instantiation of the function
5390 where the condition makes sense triggers the
5391 watchpoint. This allows an expression like "watch
5392 global if q > 10" set in `func', catch writes to
5393 global on all threads that call `func', or catch
5394 writes on all recursive calls of `func' by a single
5395 thread. We simply always evaluate the condition in
5396 the innermost frame that's executing where it makes
5397 sense to evaluate the condition. It seems
5399 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5401 select_frame (frame
);
5403 within_current_scope
= 0;
5405 if (within_current_scope
)
5409 condition_result
= breakpoint_cond_eval (cond
);
5411 catch (const gdb_exception
&ex
)
5413 exception_fprintf (gdb_stderr
, ex
,
5414 "Error in testing breakpoint condition:\n");
5419 warning (_("Watchpoint condition cannot be tested "
5420 "in the current scope"));
5421 /* If we failed to set the right context for this
5422 watchpoint, unconditionally report it. */
5424 /* FIXME-someday, should give breakpoint #. */
5427 if (cond
!= nullptr && !condition_result
)
5429 infrun_debug_printf ("condition_result = false, not stopping");
5433 else if (b
->ignore_count
> 0)
5435 infrun_debug_printf ("ignore count %d, not stopping",
5439 /* Increase the hit count even though we don't stop. */
5441 gdb::observers::breakpoint_modified
.notify (b
);
5446 infrun_debug_printf ("stopping at this breakpoint");
5448 infrun_debug_printf ("not stopping at this breakpoint");
5451 /* Returns true if we need to track moribund locations of LOC's type
5452 on the current target. */
5455 need_moribund_for_location_type (struct bp_location
*loc
)
5457 return ((loc
->loc_type
== bp_loc_software_breakpoint
5458 && !target_supports_stopped_by_sw_breakpoint ())
5459 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5460 && !target_supports_stopped_by_hw_breakpoint ()));
5463 /* See breakpoint.h. */
5466 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5467 const target_waitstatus
&ws
)
5469 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5471 for (breakpoint
*b
: all_breakpoints ())
5473 if (!breakpoint_enabled (b
))
5476 for (bp_location
*bl
: b
->locations ())
5478 /* For hardware watchpoints, we look only at the first
5479 location. The watchpoint_check function will work on the
5480 entire expression, not the individual locations. For
5481 read watchpoints, the watchpoints_triggered function has
5482 checked all locations already. */
5483 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5486 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5489 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5492 /* Come here if it's a watchpoint, or if the break address
5495 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5498 /* Assume we stop. Should we find a watchpoint that is not
5499 actually triggered, or if the condition of the breakpoint
5500 evaluates as false, we'll reset 'stop' to 0. */
5504 /* If this is a scope breakpoint, mark the associated
5505 watchpoint as triggered so that we will handle the
5506 out-of-scope event. We'll get to the watchpoint next
5508 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5510 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5512 w
->watchpoint_triggered
= watch_triggered_yes
;
5517 /* Check if a moribund breakpoint explains the stop. */
5518 if (!target_supports_stopped_by_sw_breakpoint ()
5519 || !target_supports_stopped_by_hw_breakpoint ())
5521 for (bp_location
*loc
: moribund_locations
)
5523 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5524 && need_moribund_for_location_type (loc
))
5526 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5527 /* For hits of moribund locations, we should just proceed. */
5530 bs
->print_it
= print_it_noop
;
5538 /* See breakpoint.h. */
5541 bpstat_stop_status (const address_space
*aspace
,
5542 CORE_ADDR bp_addr
, thread_info
*thread
,
5543 const target_waitstatus
&ws
,
5546 struct breakpoint
*b
= NULL
;
5547 /* First item of allocated bpstat's. */
5548 bpstat
*bs_head
= stop_chain
;
5550 int need_remove_insert
;
5553 /* First, build the bpstat chain with locations that explain a
5554 target stop, while being careful to not set the target running,
5555 as that may invalidate locations (in particular watchpoint
5556 locations are recreated). Resuming will happen here with
5557 breakpoint conditions or watchpoint expressions that include
5558 inferior function calls. */
5559 if (bs_head
== NULL
)
5560 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5562 /* A bit of special processing for shlib breakpoints. We need to
5563 process solib loading here, so that the lists of loaded and
5564 unloaded libraries are correct before we handle "catch load" and
5566 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5568 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5570 handle_solib_event ();
5575 /* Now go through the locations that caused the target to stop, and
5576 check whether we're interested in reporting this stop to higher
5577 layers, or whether we should resume the target transparently. */
5581 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5586 b
= bs
->breakpoint_at
;
5587 b
->check_status (bs
);
5590 bpstat_check_breakpoint_conditions (bs
, thread
);
5596 /* We will stop here. */
5597 if (b
->disposition
== disp_disable
)
5599 --(b
->enable_count
);
5600 if (b
->enable_count
<= 0)
5601 b
->enable_state
= bp_disabled
;
5604 gdb::observers::breakpoint_modified
.notify (b
);
5607 bs
->commands
= b
->commands
;
5608 if (command_line_is_silent (bs
->commands
5609 ? bs
->commands
.get () : NULL
))
5612 b
->after_condition_true (bs
);
5617 /* Print nothing for this entry if we don't stop or don't
5619 if (!bs
->stop
|| !bs
->print
)
5620 bs
->print_it
= print_it_noop
;
5623 /* If we aren't stopping, the value of some hardware watchpoint may
5624 not have changed, but the intermediate memory locations we are
5625 watching may have. Don't bother if we're stopping; this will get
5627 need_remove_insert
= 0;
5628 if (! bpstat_causes_stop (bs_head
))
5629 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5631 && bs
->breakpoint_at
5632 && is_hardware_watchpoint (bs
->breakpoint_at
))
5634 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5636 update_watchpoint (w
, 0 /* don't reparse. */);
5637 need_remove_insert
= 1;
5640 if (need_remove_insert
)
5641 update_global_location_list (UGLL_MAY_INSERT
);
5642 else if (removed_any
)
5643 update_global_location_list (UGLL_DONT_INSERT
);
5648 /* See breakpoint.h. */
5651 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5652 thread_info
*thread
, const target_waitstatus
&ws
)
5654 gdb_assert (!target_stopped_by_watchpoint ());
5656 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5657 previous stop to avoid confusing bpstat_stop_status. */
5658 watchpoints_triggered (ws
);
5660 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5664 handle_jit_event (CORE_ADDR address
)
5666 struct gdbarch
*gdbarch
;
5668 infrun_debug_printf ("handling bp_jit_event");
5670 /* Switch terminal for any messages produced by
5671 breakpoint_re_set. */
5672 target_terminal::ours_for_output ();
5674 gdbarch
= get_frame_arch (get_current_frame ());
5675 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5676 thus it is expected that its objectfile can be found through
5677 minimal symbol lookup. If it doesn't work (and assert fails), it
5678 most likely means that `jit_breakpoint_re_set` was changes and this
5679 function needs to be updated too. */
5680 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5681 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5682 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5684 target_terminal::inferior ();
5687 /* Prepare WHAT final decision for infrun. */
5689 /* Decide what infrun needs to do with this bpstat. */
5692 bpstat_what (bpstat
*bs_head
)
5694 struct bpstat_what retval
;
5697 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5698 retval
.call_dummy
= STOP_NONE
;
5699 retval
.is_longjmp
= false;
5701 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5703 /* Extract this BS's action. After processing each BS, we check
5704 if its action overrides all we've seem so far. */
5705 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5708 if (bs
->breakpoint_at
== NULL
)
5710 /* I suspect this can happen if it was a momentary
5711 breakpoint which has since been deleted. */
5715 bptype
= bs
->breakpoint_at
->type
;
5722 case bp_hardware_breakpoint
:
5723 case bp_single_step
:
5726 case bp_shlib_event
:
5730 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5732 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5735 this_action
= BPSTAT_WHAT_SINGLE
;
5738 case bp_hardware_watchpoint
:
5739 case bp_read_watchpoint
:
5740 case bp_access_watchpoint
:
5744 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5746 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5750 /* There was a watchpoint, but we're not stopping.
5751 This requires no further action. */
5755 case bp_longjmp_call_dummy
:
5759 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5760 retval
.is_longjmp
= bptype
!= bp_exception
;
5763 this_action
= BPSTAT_WHAT_SINGLE
;
5765 case bp_longjmp_resume
:
5766 case bp_exception_resume
:
5769 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5770 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5773 this_action
= BPSTAT_WHAT_SINGLE
;
5775 case bp_step_resume
:
5777 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5780 /* It is for the wrong frame. */
5781 this_action
= BPSTAT_WHAT_SINGLE
;
5784 case bp_hp_step_resume
:
5786 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5789 /* It is for the wrong frame. */
5790 this_action
= BPSTAT_WHAT_SINGLE
;
5793 case bp_watchpoint_scope
:
5794 case bp_thread_event
:
5795 case bp_overlay_event
:
5796 case bp_longjmp_master
:
5797 case bp_std_terminate_master
:
5798 case bp_exception_master
:
5799 this_action
= BPSTAT_WHAT_SINGLE
;
5805 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5807 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5811 /* Some catchpoints are implemented with breakpoints.
5812 For those, we need to step over the breakpoint. */
5813 if (bs
->bp_location_at
->loc_type
== bp_loc_software_breakpoint
5814 || bs
->bp_location_at
->loc_type
== bp_loc_hardware_breakpoint
)
5815 this_action
= BPSTAT_WHAT_SINGLE
;
5819 this_action
= BPSTAT_WHAT_SINGLE
;
5822 /* Make sure the action is stop (silent or noisy),
5823 so infrun.c pops the dummy frame. */
5824 retval
.call_dummy
= STOP_STACK_DUMMY
;
5825 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5827 case bp_std_terminate
:
5828 /* Make sure the action is stop (silent or noisy),
5829 so infrun.c pops the dummy frame. */
5830 retval
.call_dummy
= STOP_STD_TERMINATE
;
5831 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5834 case bp_fast_tracepoint
:
5835 case bp_static_tracepoint
:
5836 case bp_static_marker_tracepoint
:
5837 /* Tracepoint hits should not be reported back to GDB, and
5838 if one got through somehow, it should have been filtered
5840 internal_error (_("bpstat_what: tracepoint encountered"));
5842 case bp_gnu_ifunc_resolver
:
5843 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5844 this_action
= BPSTAT_WHAT_SINGLE
;
5846 case bp_gnu_ifunc_resolver_return
:
5847 /* The breakpoint will be removed, execution will restart from the
5848 PC of the former breakpoint. */
5849 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5854 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5856 this_action
= BPSTAT_WHAT_SINGLE
;
5860 internal_error (_("bpstat_what: unhandled bptype %d"), (int) bptype
);
5863 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5870 bpstat_run_callbacks (bpstat
*bs_head
)
5874 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5876 struct breakpoint
*b
= bs
->breakpoint_at
;
5883 handle_jit_event (bs
->bp_location_at
->address
);
5885 case bp_gnu_ifunc_resolver
:
5886 gnu_ifunc_resolver_stop ((code_breakpoint
*) b
);
5888 case bp_gnu_ifunc_resolver_return
:
5889 gnu_ifunc_resolver_return_stop ((code_breakpoint
*) b
);
5895 /* See breakpoint.h. */
5898 bpstat_should_step ()
5900 for (breakpoint
*b
: all_breakpoints ())
5901 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5907 /* See breakpoint.h. */
5910 bpstat_causes_stop (bpstat
*bs
)
5912 for (; bs
!= NULL
; bs
= bs
->next
)
5921 /* Compute a number of spaces suitable to indent the next line
5922 so it starts at the position corresponding to the table column
5923 named COL_NAME in the currently active table of UIOUT. */
5926 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5928 int i
, total_width
, width
, align
;
5932 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5934 if (strcmp (text
, col_name
) == 0)
5937 total_width
+= width
+ 1;
5943 /* Determine if the locations of this breakpoint will have their conditions
5944 evaluated by the target, host or a mix of both. Returns the following:
5946 "host": Host evals condition.
5947 "host or target": Host or Target evals condition.
5948 "target": Target evals condition.
5952 bp_condition_evaluator (const breakpoint
*b
)
5954 char host_evals
= 0;
5955 char target_evals
= 0;
5960 if (!is_breakpoint (b
))
5963 if (gdb_evaluates_breakpoint_condition_p ()
5964 || !target_supports_evaluation_of_breakpoint_conditions ())
5965 return condition_evaluation_host
;
5967 for (bp_location
*bl
: b
->locations ())
5969 if (bl
->cond_bytecode
)
5975 if (host_evals
&& target_evals
)
5976 return condition_evaluation_both
;
5977 else if (target_evals
)
5978 return condition_evaluation_target
;
5980 return condition_evaluation_host
;
5983 /* Determine the breakpoint location's condition evaluator. This is
5984 similar to bp_condition_evaluator, but for locations. */
5987 bp_location_condition_evaluator (struct bp_location
*bl
)
5989 if (bl
&& !is_breakpoint (bl
->owner
))
5992 if (gdb_evaluates_breakpoint_condition_p ()
5993 || !target_supports_evaluation_of_breakpoint_conditions ())
5994 return condition_evaluation_host
;
5996 if (bl
&& bl
->cond_bytecode
)
5997 return condition_evaluation_target
;
5999 return condition_evaluation_host
;
6002 /* Print the LOC location out of the list of B->LOC locations. */
6005 print_breakpoint_location (const breakpoint
*b
,
6006 struct bp_location
*loc
)
6008 struct ui_out
*uiout
= current_uiout
;
6010 scoped_restore_current_program_space restore_pspace
;
6012 if (loc
!= NULL
&& loc
->shlib_disabled
)
6016 set_current_program_space (loc
->pspace
);
6018 if (b
->display_canonical
)
6019 uiout
->field_string ("what", b
->locspec
->to_string ());
6020 else if (loc
&& loc
->symtab
)
6022 const struct symbol
*sym
= loc
->symbol
;
6026 uiout
->text ("in ");
6027 uiout
->field_string ("func", sym
->print_name (),
6028 function_name_style
.style ());
6030 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6031 uiout
->text ("at ");
6033 uiout
->field_string ("file",
6034 symtab_to_filename_for_display (loc
->symtab
),
6035 file_name_style
.style ());
6038 if (uiout
->is_mi_like_p ())
6039 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6041 uiout
->field_signed ("line", loc
->line_number
);
6047 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6049 uiout
->field_stream ("at", stb
);
6053 uiout
->field_string ("pending", b
->locspec
->to_string ());
6054 /* If extra_string is available, it could be holding a condition
6055 or dprintf arguments. In either case, make sure it is printed,
6056 too, but only for non-MI streams. */
6057 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6059 if (b
->type
== bp_dprintf
)
6063 uiout
->text (b
->extra_string
.get ());
6067 if (loc
&& is_breakpoint (b
)
6068 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6069 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6072 uiout
->field_string ("evaluated-by",
6073 bp_location_condition_evaluator (loc
));
6079 bptype_string (enum bptype type
)
6081 struct ep_type_description
6084 const char *description
;
6086 static struct ep_type_description bptypes
[] =
6088 {bp_none
, "?deleted?"},
6089 {bp_breakpoint
, "breakpoint"},
6090 {bp_hardware_breakpoint
, "hw breakpoint"},
6091 {bp_single_step
, "sw single-step"},
6092 {bp_until
, "until"},
6093 {bp_finish
, "finish"},
6094 {bp_watchpoint
, "watchpoint"},
6095 {bp_hardware_watchpoint
, "hw watchpoint"},
6096 {bp_read_watchpoint
, "read watchpoint"},
6097 {bp_access_watchpoint
, "acc watchpoint"},
6098 {bp_longjmp
, "longjmp"},
6099 {bp_longjmp_resume
, "longjmp resume"},
6100 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6101 {bp_exception
, "exception"},
6102 {bp_exception_resume
, "exception resume"},
6103 {bp_step_resume
, "step resume"},
6104 {bp_hp_step_resume
, "high-priority step resume"},
6105 {bp_watchpoint_scope
, "watchpoint scope"},
6106 {bp_call_dummy
, "call dummy"},
6107 {bp_std_terminate
, "std::terminate"},
6108 {bp_shlib_event
, "shlib events"},
6109 {bp_thread_event
, "thread events"},
6110 {bp_overlay_event
, "overlay events"},
6111 {bp_longjmp_master
, "longjmp master"},
6112 {bp_std_terminate_master
, "std::terminate master"},
6113 {bp_exception_master
, "exception master"},
6114 {bp_catchpoint
, "catchpoint"},
6115 {bp_tracepoint
, "tracepoint"},
6116 {bp_fast_tracepoint
, "fast tracepoint"},
6117 {bp_static_tracepoint
, "static tracepoint"},
6118 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6119 {bp_dprintf
, "dprintf"},
6120 {bp_jit_event
, "jit events"},
6121 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6122 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6125 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6126 || ((int) type
!= bptypes
[(int) type
].type
))
6127 internal_error (_("bptypes table does not describe type #%d."),
6130 return bptypes
[(int) type
].description
;
6133 /* For MI, output a field named 'thread-groups' with a list as the value.
6134 For CLI, prefix the list with the string 'inf'. */
6137 output_thread_groups (struct ui_out
*uiout
,
6138 const char *field_name
,
6139 const std::vector
<int> &inf_nums
,
6142 int is_mi
= uiout
->is_mi_like_p ();
6144 /* For backward compatibility, don't display inferiors in CLI unless
6145 there are several. Always display them for MI. */
6146 if (!is_mi
&& mi_only
)
6149 ui_out_emit_list
list_emitter (uiout
, field_name
);
6151 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6157 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6158 uiout
->field_string (NULL
, mi_group
);
6163 uiout
->text (" inf ");
6167 uiout
->text (plongest (inf_nums
[i
]));
6172 /* See breakpoint.h. */
6174 bool fix_breakpoint_script_output_globally
= false;
6176 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6177 instead of going via breakpoint_ops::print_one. This makes "maint
6178 info breakpoints" show the software breakpoint locations of
6179 catchpoints, which are considered internal implementation
6180 detail. Returns true if RAW_LOC is false and if the breakpoint's
6181 print_one method did something; false otherwise. */
6184 print_one_breakpoint_location (struct breakpoint
*b
,
6185 struct bp_location
*loc
,
6187 struct bp_location
**last_loc
,
6188 int allflag
, bool raw_loc
)
6190 struct command_line
*l
;
6191 static char bpenables
[] = "nynny";
6193 struct ui_out
*uiout
= current_uiout
;
6194 int header_of_multiple
= 0;
6195 int part_of_multiple
= (loc
!= NULL
);
6196 struct value_print_options opts
;
6198 get_user_print_options (&opts
);
6200 gdb_assert (!loc
|| loc_number
!= 0);
6201 /* See comment in print_one_breakpoint concerning treatment of
6202 breakpoints with single disabled location. */
6205 && (b
->loc
->next
!= NULL
6206 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6207 header_of_multiple
= 1;
6215 if (part_of_multiple
)
6216 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6218 uiout
->field_signed ("number", b
->number
);
6222 if (part_of_multiple
)
6223 uiout
->field_skip ("type");
6225 uiout
->field_string ("type", bptype_string (b
->type
));
6229 if (part_of_multiple
)
6230 uiout
->field_skip ("disp");
6232 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6236 if (part_of_multiple
)
6238 /* For locations that are disabled because of an invalid
6239 condition, display "N*" on the CLI, where "*" refers to a
6240 footnote below the table. For MI, simply display a "N"
6241 without a footnote. On the CLI, for enabled locations whose
6242 breakpoint is disabled, display "y-". */
6243 auto get_enable_state
= [uiout
, loc
] () -> const char *
6245 if (uiout
->is_mi_like_p ())
6247 if (loc
->disabled_by_cond
)
6249 else if (!loc
->enabled
)
6256 if (loc
->disabled_by_cond
)
6258 else if (!loc
->enabled
)
6260 else if (!breakpoint_enabled (loc
->owner
))
6266 uiout
->field_string ("enabled", get_enable_state ());
6269 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6272 bool result
= false;
6273 if (!raw_loc
&& b
->print_one (last_loc
))
6277 if (is_watchpoint (b
))
6279 struct watchpoint
*w
= (struct watchpoint
*) b
;
6281 /* Field 4, the address, is omitted (which makes the columns
6282 not line up too nicely with the headers, but the effect
6283 is relatively readable). */
6284 if (opts
.addressprint
)
6285 uiout
->field_skip ("addr");
6287 uiout
->field_string ("what", w
->exp_string
.get ());
6289 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6290 || is_ada_exception_catchpoint (b
))
6292 if (opts
.addressprint
)
6295 if (header_of_multiple
)
6296 uiout
->field_string ("addr", "<MULTIPLE>",
6297 metadata_style
.style ());
6298 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6299 uiout
->field_string ("addr", "<PENDING>",
6300 metadata_style
.style ());
6302 uiout
->field_core_addr ("addr",
6303 loc
->gdbarch
, loc
->address
);
6306 if (!header_of_multiple
)
6307 print_breakpoint_location (b
, loc
);
6313 if (loc
!= NULL
&& !header_of_multiple
)
6315 std::vector
<int> inf_nums
;
6318 for (inferior
*inf
: all_inferiors ())
6320 if (inf
->pspace
== loc
->pspace
)
6321 inf_nums
.push_back (inf
->num
);
6324 /* For backward compatibility, don't display inferiors in CLI unless
6325 there are several. Always display for MI. */
6327 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6328 && (program_spaces
.size () > 1
6329 || number_of_inferiors () > 1)
6330 /* LOC is for existing B, it cannot be in
6331 moribund_locations and thus having NULL OWNER. */
6332 && loc
->owner
->type
!= bp_catchpoint
))
6334 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6337 if (!part_of_multiple
)
6339 if (b
->thread
!= -1)
6341 /* FIXME: This seems to be redundant and lost here; see the
6342 "stop only in" line a little further down. */
6343 uiout
->text (" thread ");
6344 uiout
->field_signed ("thread", b
->thread
);
6346 else if (b
->task
!= 0)
6348 uiout
->text (" task ");
6349 uiout
->field_signed ("task", b
->task
);
6355 if (!part_of_multiple
)
6356 b
->print_one_detail (uiout
);
6358 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6361 uiout
->text ("\tstop only in stack frame at ");
6362 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6364 uiout
->field_core_addr ("frame",
6365 b
->gdbarch
, b
->frame_id
.stack_addr
);
6369 if (!part_of_multiple
&& b
->cond_string
)
6372 if (is_tracepoint (b
))
6373 uiout
->text ("\ttrace only if ");
6375 uiout
->text ("\tstop only if ");
6376 uiout
->field_string ("cond", b
->cond_string
.get ());
6378 /* Print whether the target is doing the breakpoint's condition
6379 evaluation. If GDB is doing the evaluation, don't print anything. */
6380 if (is_breakpoint (b
)
6381 && breakpoint_condition_evaluation_mode ()
6382 == condition_evaluation_target
)
6384 uiout
->message (" (%pF evals)",
6385 string_field ("evaluated-by",
6386 bp_condition_evaluator (b
)));
6391 if (!part_of_multiple
&& b
->thread
!= -1)
6393 /* FIXME should make an annotation for this. */
6394 uiout
->text ("\tstop only in thread ");
6395 if (uiout
->is_mi_like_p ())
6396 uiout
->field_signed ("thread", b
->thread
);
6399 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6401 uiout
->field_string ("thread", print_thread_id (thr
));
6406 if (!part_of_multiple
)
6410 /* FIXME should make an annotation for this. */
6411 if (is_catchpoint (b
))
6412 uiout
->text ("\tcatchpoint");
6413 else if (is_tracepoint (b
))
6414 uiout
->text ("\ttracepoint");
6416 uiout
->text ("\tbreakpoint");
6417 uiout
->text (" already hit ");
6418 uiout
->field_signed ("times", b
->hit_count
);
6419 if (b
->hit_count
== 1)
6420 uiout
->text (" time\n");
6422 uiout
->text (" times\n");
6426 /* Output the count also if it is zero, but only if this is mi. */
6427 if (uiout
->is_mi_like_p ())
6428 uiout
->field_signed ("times", b
->hit_count
);
6432 if (!part_of_multiple
&& b
->ignore_count
)
6435 uiout
->message ("\tignore next %pF hits\n",
6436 signed_field ("ignore", b
->ignore_count
));
6439 /* Note that an enable count of 1 corresponds to "enable once"
6440 behavior, which is reported by the combination of enablement and
6441 disposition, so we don't need to mention it here. */
6442 if (!part_of_multiple
&& b
->enable_count
> 1)
6445 uiout
->text ("\tdisable after ");
6446 /* Tweak the wording to clarify that ignore and enable counts
6447 are distinct, and have additive effect. */
6448 if (b
->ignore_count
)
6449 uiout
->text ("additional ");
6451 uiout
->text ("next ");
6452 uiout
->field_signed ("enable", b
->enable_count
);
6453 uiout
->text (" hits\n");
6456 if (!part_of_multiple
&& is_tracepoint (b
))
6458 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6460 if (tp
->traceframe_usage
)
6462 uiout
->text ("\ttrace buffer usage ");
6463 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6464 uiout
->text (" bytes\n");
6468 l
= b
->commands
? b
->commands
.get () : NULL
;
6469 if (!part_of_multiple
&& l
)
6473 bool use_fixed_output
=
6474 (uiout
->test_flags (fix_breakpoint_script_output
)
6475 || fix_breakpoint_script_output_globally
);
6477 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
6478 gdb::optional
<ui_out_emit_list
> list_emitter
;
6480 if (use_fixed_output
)
6481 list_emitter
.emplace (uiout
, "script");
6483 tuple_emitter
.emplace (uiout
, "script");
6485 print_command_lines (uiout
, l
, 4);
6488 if (is_tracepoint (b
))
6490 struct tracepoint
*t
= (struct tracepoint
*) b
;
6492 if (!part_of_multiple
&& t
->pass_count
)
6494 annotate_field (10);
6495 uiout
->text ("\tpass count ");
6496 uiout
->field_signed ("pass", t
->pass_count
);
6497 uiout
->text (" \n");
6500 /* Don't display it when tracepoint or tracepoint location is
6502 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6504 annotate_field (11);
6506 if (uiout
->is_mi_like_p ())
6507 uiout
->field_string ("installed",
6508 loc
->inserted
? "y" : "n");
6514 uiout
->text ("\tnot ");
6515 uiout
->text ("installed on target\n");
6520 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6522 if (is_watchpoint (b
))
6524 struct watchpoint
*w
= (struct watchpoint
*) b
;
6526 uiout
->field_string ("original-location", w
->exp_string
.get ());
6528 else if (b
->locspec
!= nullptr)
6530 const char *str
= b
->locspec
->to_string ();
6532 uiout
->field_string ("original-location", str
);
6539 /* See breakpoint.h. */
6541 bool fix_multi_location_breakpoint_output_globally
= false;
6544 print_one_breakpoint (struct breakpoint
*b
,
6545 struct bp_location
**last_loc
,
6548 struct ui_out
*uiout
= current_uiout
;
6549 bool use_fixed_output
6550 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6551 || fix_multi_location_breakpoint_output_globally
);
6553 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6554 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6557 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6559 if (!use_fixed_output
)
6560 bkpt_tuple_emitter
.reset ();
6562 /* If this breakpoint has custom print function,
6563 it's already printed. Otherwise, print individual
6564 locations, if any. */
6565 if (!printed
|| allflag
)
6567 /* If breakpoint has a single location that is disabled, we
6568 print it as if it had several locations, since otherwise it's
6569 hard to represent "breakpoint enabled, location disabled"
6572 Note that while hardware watchpoints have several locations
6573 internally, that's not a property exposed to users.
6575 Likewise, while catchpoints may be implemented with
6576 breakpoints (e.g., catch throw), that's not a property
6577 exposed to users. We do however display the internal
6578 breakpoint locations with "maint info breakpoints". */
6579 if (!is_hardware_watchpoint (b
)
6580 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6581 || is_ada_exception_catchpoint (b
))
6583 || (b
->loc
&& (b
->loc
->next
6585 || b
->loc
->disabled_by_cond
))))
6587 gdb::optional
<ui_out_emit_list
> locations_list
;
6589 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6590 MI record. For later versions, place breakpoint locations in a
6592 if (uiout
->is_mi_like_p () && use_fixed_output
)
6593 locations_list
.emplace (uiout
, "locations");
6596 for (bp_location
*loc
: b
->locations ())
6598 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6599 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6608 breakpoint_address_bits (struct breakpoint
*b
)
6610 int print_address_bits
= 0;
6612 for (bp_location
*loc
: b
->locations ())
6614 if (!bl_address_is_meaningful (loc
))
6617 int addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6618 if (addr_bit
> print_address_bits
)
6619 print_address_bits
= addr_bit
;
6622 return print_address_bits
;
6625 /* See breakpoint.h. */
6628 print_breakpoint (breakpoint
*b
)
6630 struct bp_location
*dummy_loc
= NULL
;
6631 print_one_breakpoint (b
, &dummy_loc
, 0);
6634 /* Return true if this breakpoint was set by the user, false if it is
6635 internal or momentary. */
6638 user_breakpoint_p (struct breakpoint
*b
)
6640 return b
->number
> 0;
6643 /* See breakpoint.h. */
6646 pending_breakpoint_p (struct breakpoint
*b
)
6648 return b
->loc
== NULL
;
6651 /* Print information on breakpoints (including watchpoints and tracepoints).
6653 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6654 understood by number_or_range_parser. Only breakpoints included in this
6655 list are then printed.
6657 If SHOW_INTERNAL is true, print internal breakpoints.
6659 If FILTER is non-NULL, call it on each breakpoint and only include the
6660 ones for which it returns true.
6662 Return the total number of breakpoints listed. */
6665 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6666 bool (*filter
) (const struct breakpoint
*))
6668 struct bp_location
*last_loc
= NULL
;
6669 int nr_printable_breakpoints
;
6670 struct value_print_options opts
;
6671 int print_address_bits
= 0;
6672 int print_type_col_width
= 14;
6673 struct ui_out
*uiout
= current_uiout
;
6674 bool has_disabled_by_cond_location
= false;
6676 get_user_print_options (&opts
);
6678 /* Compute the number of rows in the table, as well as the size
6679 required for address fields. */
6680 nr_printable_breakpoints
= 0;
6681 for (breakpoint
*b
: all_breakpoints ())
6683 /* If we have a filter, only list the breakpoints it accepts. */
6684 if (filter
&& !filter (b
))
6687 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6688 accept. Skip the others. */
6689 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6691 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6693 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6697 if (show_internal
|| user_breakpoint_p (b
))
6699 int addr_bit
, type_len
;
6701 addr_bit
= breakpoint_address_bits (b
);
6702 if (addr_bit
> print_address_bits
)
6703 print_address_bits
= addr_bit
;
6705 type_len
= strlen (bptype_string (b
->type
));
6706 if (type_len
> print_type_col_width
)
6707 print_type_col_width
= type_len
;
6709 nr_printable_breakpoints
++;
6714 ui_out_emit_table
table_emitter (uiout
,
6715 opts
.addressprint
? 6 : 5,
6716 nr_printable_breakpoints
,
6719 if (nr_printable_breakpoints
> 0)
6720 annotate_breakpoints_headers ();
6721 if (nr_printable_breakpoints
> 0)
6723 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6724 if (nr_printable_breakpoints
> 0)
6726 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6727 if (nr_printable_breakpoints
> 0)
6729 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6730 if (nr_printable_breakpoints
> 0)
6732 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6733 if (opts
.addressprint
)
6735 if (nr_printable_breakpoints
> 0)
6737 if (print_address_bits
<= 32)
6738 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6740 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6742 if (nr_printable_breakpoints
> 0)
6744 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6745 uiout
->table_body ();
6746 if (nr_printable_breakpoints
> 0)
6747 annotate_breakpoints_table ();
6749 for (breakpoint
*b
: all_breakpoints ())
6752 /* If we have a filter, only list the breakpoints it accepts. */
6753 if (filter
&& !filter (b
))
6756 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6757 accept. Skip the others. */
6759 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6761 if (show_internal
) /* maintenance info breakpoint */
6763 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6766 else /* all others */
6768 if (!number_is_in_list (bp_num_list
, b
->number
))
6772 /* We only print out user settable breakpoints unless the
6773 show_internal is set. */
6774 if (show_internal
|| user_breakpoint_p (b
))
6776 print_one_breakpoint (b
, &last_loc
, show_internal
);
6777 for (bp_location
*loc
: b
->locations ())
6778 if (loc
->disabled_by_cond
)
6779 has_disabled_by_cond_location
= true;
6784 if (nr_printable_breakpoints
== 0)
6786 /* If there's a filter, let the caller decide how to report
6790 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6791 uiout
->message ("No breakpoints or watchpoints.\n");
6793 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6799 if (last_loc
&& !server_command
)
6800 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6802 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6803 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6807 /* FIXME? Should this be moved up so that it is only called when
6808 there have been breakpoints? */
6809 annotate_breakpoints_table_end ();
6811 return nr_printable_breakpoints
;
6814 /* Display the value of default-collect in a way that is generally
6815 compatible with the breakpoint list. */
6818 default_collect_info (void)
6820 struct ui_out
*uiout
= current_uiout
;
6822 /* If it has no value (which is frequently the case), say nothing; a
6823 message like "No default-collect." gets in user's face when it's
6825 if (default_collect
.empty ())
6828 /* The following phrase lines up nicely with per-tracepoint collect
6830 uiout
->text ("default collect ");
6831 uiout
->field_string ("default-collect", default_collect
);
6832 uiout
->text (" \n");
6836 info_breakpoints_command (const char *args
, int from_tty
)
6838 breakpoint_1 (args
, false, NULL
);
6840 default_collect_info ();
6844 info_watchpoints_command (const char *args
, int from_tty
)
6846 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6847 struct ui_out
*uiout
= current_uiout
;
6849 if (num_printed
== 0)
6851 if (args
== NULL
|| *args
== '\0')
6852 uiout
->message ("No watchpoints.\n");
6854 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6859 maintenance_info_breakpoints (const char *args
, int from_tty
)
6861 breakpoint_1 (args
, true, NULL
);
6863 default_collect_info ();
6867 breakpoint_has_pc (struct breakpoint
*b
,
6868 struct program_space
*pspace
,
6869 CORE_ADDR pc
, struct obj_section
*section
)
6871 for (bp_location
*bl
: b
->locations ())
6873 if (bl
->pspace
== pspace
6874 && bl
->address
== pc
6875 && (!overlay_debugging
|| bl
->section
== section
))
6881 /* See breakpoint.h. */
6884 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6885 struct program_space
*pspace
, CORE_ADDR pc
,
6886 struct obj_section
*section
, int thread
)
6890 for (breakpoint
*b
: all_breakpoints ())
6891 others
+= (user_breakpoint_p (b
)
6892 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6897 gdb_printf (_("Note: breakpoint "));
6898 else /* if (others == ???) */
6899 gdb_printf (_("Note: breakpoints "));
6900 for (breakpoint
*b
: all_breakpoints ())
6901 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6904 gdb_printf ("%d", b
->number
);
6905 if (b
->thread
== -1 && thread
!= -1)
6906 gdb_printf (" (all threads)");
6907 else if (b
->thread
!= -1)
6908 gdb_printf (" (thread %d)", b
->thread
);
6909 gdb_printf ("%s%s ",
6910 ((b
->enable_state
== bp_disabled
6911 || b
->enable_state
== bp_call_disabled
)
6915 : ((others
== 1) ? " and" : ""));
6917 current_uiout
->message (_("also set at pc %ps.\n"),
6918 styled_string (address_style
.style (),
6919 paddress (gdbarch
, pc
)));
6924 /* Return true iff it is meaningful to use the address member of LOC.
6925 For some breakpoint types, the locations' address members are
6926 irrelevant and it makes no sense to attempt to compare them to
6927 other addresses (or use them for any other purpose either).
6929 More specifically, software watchpoints and catchpoints that are
6930 not backed by breakpoints always have a zero valued location
6931 address and we don't want to mark breakpoints of any of these types
6932 to be a duplicate of an actual breakpoint location at address
6936 bl_address_is_meaningful (bp_location
*loc
)
6938 return loc
->loc_type
!= bp_loc_other
;
6941 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6942 true if LOC1 and LOC2 represent the same watchpoint location. */
6945 watchpoint_locations_match (struct bp_location
*loc1
,
6946 struct bp_location
*loc2
)
6948 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6949 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6951 /* Both of them must exist. */
6952 gdb_assert (w1
!= NULL
);
6953 gdb_assert (w2
!= NULL
);
6955 /* If the target can evaluate the condition expression in hardware,
6956 then we we need to insert both watchpoints even if they are at
6957 the same place. Otherwise the watchpoint will only trigger when
6958 the condition of whichever watchpoint was inserted evaluates to
6959 true, not giving a chance for GDB to check the condition of the
6960 other watchpoint. */
6962 && target_can_accel_watchpoint_condition (loc1
->address
,
6964 loc1
->watchpoint_type
,
6965 w1
->cond_exp
.get ()))
6967 && target_can_accel_watchpoint_condition (loc2
->address
,
6969 loc2
->watchpoint_type
,
6970 w2
->cond_exp
.get ())))
6973 /* Note that this checks the owner's type, not the location's. In
6974 case the target does not support read watchpoints, but does
6975 support access watchpoints, we'll have bp_read_watchpoint
6976 watchpoints with hw_access locations. Those should be considered
6977 duplicates of hw_read locations. The hw_read locations will
6978 become hw_access locations later. */
6979 return (loc1
->owner
->type
== loc2
->owner
->type
6980 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6981 && loc1
->address
== loc2
->address
6982 && loc1
->length
== loc2
->length
);
6985 /* See breakpoint.h. */
6988 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6989 const address_space
*aspace2
, CORE_ADDR addr2
)
6991 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6992 || aspace1
== aspace2
)
6996 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6997 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6998 matches ASPACE2. On targets that have global breakpoints, the address
6999 space doesn't really matter. */
7002 breakpoint_address_match_range (const address_space
*aspace1
,
7004 int len1
, const address_space
*aspace2
,
7007 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7008 || aspace1
== aspace2
)
7009 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7012 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7013 a ranged breakpoint. In most targets, a match happens only if ASPACE
7014 matches the breakpoint's address space. On targets that have global
7015 breakpoints, the address space doesn't really matter. */
7018 breakpoint_location_address_match (struct bp_location
*bl
,
7019 const address_space
*aspace
,
7022 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7025 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7026 bl
->address
, bl
->length
,
7030 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7031 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7032 match happens only if ASPACE matches the breakpoint's address
7033 space. On targets that have global breakpoints, the address space
7034 doesn't really matter. */
7037 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7038 const address_space
*aspace
,
7039 CORE_ADDR addr
, int len
)
7041 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7042 || bl
->pspace
->aspace
== aspace
)
7044 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7046 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7052 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7053 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7054 true, otherwise returns false. */
7057 tracepoint_locations_match (struct bp_location
*loc1
,
7058 struct bp_location
*loc2
)
7060 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7061 /* Since tracepoint locations are never duplicated with others', tracepoint
7062 locations at the same address of different tracepoints are regarded as
7063 different locations. */
7064 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7069 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7070 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7071 the same location. If SW_HW_BPS_MATCH is true, then software
7072 breakpoint locations and hardware breakpoint locations match,
7073 otherwise they don't. */
7076 breakpoint_locations_match (struct bp_location
*loc1
,
7077 struct bp_location
*loc2
,
7078 bool sw_hw_bps_match
)
7080 int hw_point1
, hw_point2
;
7082 /* Both of them must not be in moribund_locations. */
7083 gdb_assert (loc1
->owner
!= NULL
);
7084 gdb_assert (loc2
->owner
!= NULL
);
7086 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7087 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7089 if (hw_point1
!= hw_point2
)
7092 return watchpoint_locations_match (loc1
, loc2
);
7093 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7094 return tracepoint_locations_match (loc1
, loc2
);
7096 /* We compare bp_location.length in order to cover ranged
7097 breakpoints. Keep this in sync with
7098 bp_location_is_less_than. */
7099 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7100 loc2
->pspace
->aspace
, loc2
->address
)
7101 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7102 && loc1
->length
== loc2
->length
);
7106 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7107 int bnum
, int have_bnum
)
7109 /* The longest string possibly returned by hex_string_custom
7110 is 50 chars. These must be at least that big for safety. */
7114 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7115 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7117 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7118 bnum
, astr1
, astr2
);
7120 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7123 /* Adjust a breakpoint's address to account for architectural
7124 constraints on breakpoint placement. Return the adjusted address.
7125 Note: Very few targets require this kind of adjustment. For most
7126 targets, this function is simply the identity function. */
7129 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7130 CORE_ADDR bpaddr
, enum bptype bptype
,
7131 struct program_space
*pspace
)
7133 gdb_assert (pspace
!= nullptr);
7135 if (bptype
== bp_watchpoint
7136 || bptype
== bp_hardware_watchpoint
7137 || bptype
== bp_read_watchpoint
7138 || bptype
== bp_access_watchpoint
7139 || bptype
== bp_catchpoint
)
7141 /* Watchpoints and the various bp_catch_* eventpoints should not
7142 have their addresses modified. */
7145 else if (bptype
== bp_single_step
)
7147 /* Single-step breakpoints should not have their addresses
7148 modified. If there's any architectural constrain that
7149 applies to this address, then it should have already been
7150 taken into account when the breakpoint was created in the
7151 first place. If we didn't do this, stepping through e.g.,
7152 Thumb-2 IT blocks would break. */
7157 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7159 /* Some targets have architectural constraints on the placement
7160 of breakpoint instructions. Obtain the adjusted address. */
7161 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7163 /* Targets that implement this adjustment function will likely
7164 inspect either the symbol table, target memory at BPADDR, or
7165 even state registers, so ensure a suitable thread (and its
7166 associated program space) are currently selected. */
7167 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
7168 switch_to_program_space_and_thread (pspace
);
7170 = gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7173 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7175 /* An adjusted breakpoint address can significantly alter
7176 a user's expectations. Print a warning if an adjustment
7178 if (adjusted_bpaddr
!= bpaddr
)
7179 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7181 return adjusted_bpaddr
;
7186 bp_location_from_bp_type (bptype type
)
7191 case bp_single_step
:
7195 case bp_longjmp_resume
:
7196 case bp_longjmp_call_dummy
:
7198 case bp_exception_resume
:
7199 case bp_step_resume
:
7200 case bp_hp_step_resume
:
7201 case bp_watchpoint_scope
:
7203 case bp_std_terminate
:
7204 case bp_shlib_event
:
7205 case bp_thread_event
:
7206 case bp_overlay_event
:
7208 case bp_longjmp_master
:
7209 case bp_std_terminate_master
:
7210 case bp_exception_master
:
7211 case bp_gnu_ifunc_resolver
:
7212 case bp_gnu_ifunc_resolver_return
:
7214 return bp_loc_software_breakpoint
;
7215 case bp_hardware_breakpoint
:
7216 return bp_loc_hardware_breakpoint
;
7217 case bp_hardware_watchpoint
:
7218 case bp_read_watchpoint
:
7219 case bp_access_watchpoint
:
7220 return bp_loc_hardware_watchpoint
;
7222 return bp_loc_software_watchpoint
;
7225 case bp_fast_tracepoint
:
7226 case bp_static_tracepoint
:
7227 case bp_static_marker_tracepoint
:
7228 return bp_loc_other
;
7230 internal_error (_("unknown breakpoint type"));
7234 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7236 this->owner
= owner
;
7237 this->cond_bytecode
= NULL
;
7238 this->shlib_disabled
= 0;
7240 this->disabled_by_cond
= false;
7242 this->loc_type
= type
;
7244 if (this->loc_type
== bp_loc_software_breakpoint
7245 || this->loc_type
== bp_loc_hardware_breakpoint
)
7246 mark_breakpoint_location_modified (this);
7251 bp_location::bp_location (breakpoint
*owner
)
7252 : bp_location::bp_location (owner
,
7253 bp_location_from_bp_type (owner
->type
))
7257 /* Decrement reference count. If the reference count reaches 0,
7258 destroy the bp_location. Sets *BLP to NULL. */
7261 decref_bp_location (struct bp_location
**blp
)
7263 bp_location_ref_policy::decref (*blp
);
7267 /* Add breakpoint B at the end of the global breakpoint chain. */
7270 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7272 struct breakpoint
*b1
;
7273 struct breakpoint
*result
= b
.get ();
7275 /* Add this breakpoint to the end of the chain so that a list of
7276 breakpoints will come out in order of increasing numbers. */
7278 b1
= breakpoint_chain
;
7280 breakpoint_chain
= b
.release ();
7285 b1
->next
= b
.release ();
7291 /* Initialize loc->function_name. */
7294 set_breakpoint_location_function (struct bp_location
*loc
)
7296 gdb_assert (loc
->owner
!= NULL
);
7298 if (loc
->owner
->type
== bp_breakpoint
7299 || loc
->owner
->type
== bp_hardware_breakpoint
7300 || is_tracepoint (loc
->owner
))
7302 const char *function_name
;
7304 if (loc
->msymbol
!= NULL
7305 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7306 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7308 struct breakpoint
*b
= loc
->owner
;
7310 function_name
= loc
->msymbol
->linkage_name ();
7312 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7313 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7315 /* Create only the whole new breakpoint of this type but do not
7316 mess more complicated breakpoints with multiple locations. */
7317 b
->type
= bp_gnu_ifunc_resolver
;
7318 /* Remember the resolver's address for use by the return
7320 loc
->related_address
= loc
->address
;
7324 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7327 loc
->function_name
= make_unique_xstrdup (function_name
);
7331 /* Attempt to determine architecture of location identified by SAL. */
7333 get_sal_arch (struct symtab_and_line sal
)
7336 return sal
.section
->objfile
->arch ();
7338 return sal
.symtab
->compunit ()->objfile ()->arch ();
7343 /* Call this routine when stepping and nexting to enable a breakpoint
7344 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7345 initiated the operation. */
7348 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7350 int thread
= tp
->global_num
;
7352 /* To avoid having to rescan all objfile symbols at every step,
7353 we maintain a list of continually-inserted but always disabled
7354 longjmp "master" breakpoints. Here, we simply create momentary
7355 clones of those and enable them for the requested thread. */
7356 for (breakpoint
*b
: all_breakpoints_safe ())
7357 if (b
->pspace
== current_program_space
7358 && (b
->type
== bp_longjmp_master
7359 || b
->type
== bp_exception_master
))
7361 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7362 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7363 after their removal. */
7364 momentary_breakpoint_from_master (b
, type
, 1, thread
);
7367 tp
->initiating_frame
= frame
;
7370 /* Delete all longjmp breakpoints from THREAD. */
7372 delete_longjmp_breakpoint (int thread
)
7374 for (breakpoint
*b
: all_breakpoints_safe ())
7375 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7377 if (b
->thread
== thread
)
7378 delete_breakpoint (b
);
7383 delete_longjmp_breakpoint_at_next_stop (int thread
)
7385 for (breakpoint
*b
: all_breakpoints_safe ())
7386 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7388 if (b
->thread
== thread
)
7389 b
->disposition
= disp_del_at_next_stop
;
7393 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7394 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7395 pointer to any of them. Return NULL if this system cannot place longjmp
7399 set_longjmp_breakpoint_for_call_dummy (void)
7401 breakpoint
*retval
= nullptr;
7403 for (breakpoint
*b
: all_breakpoints ())
7404 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7406 int thread
= inferior_thread ()->global_num
;
7408 = momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7411 /* Link NEW_B into the chain of RETVAL breakpoints. */
7413 gdb_assert (new_b
->related_breakpoint
== new_b
);
7416 new_b
->related_breakpoint
= retval
;
7417 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7418 retval
= retval
->related_breakpoint
;
7419 retval
->related_breakpoint
= new_b
;
7425 /* Verify all existing dummy frames and their associated breakpoints for
7426 TP. Remove those which can no longer be found in the current frame
7429 If the unwind fails then there is not sufficient information to discard
7430 dummy frames. In this case, elide the clean up and the dummy frames will
7431 be cleaned up next time this function is called from a location where
7432 unwinding is possible. */
7435 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7437 struct breakpoint
*b
, *b_tmp
;
7439 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7440 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7442 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7444 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7445 chained off b->related_breakpoint. */
7446 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7447 dummy_b
= dummy_b
->related_breakpoint
;
7449 /* If there was no bp_call_dummy breakpoint then there's nothing
7450 more to do. Or, if the dummy frame associated with the
7451 bp_call_dummy is still on the stack then we need to leave this
7452 bp_call_dummy in place. */
7453 if (dummy_b
->type
!= bp_call_dummy
7454 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7457 /* We didn't find the dummy frame on the stack, this could be
7458 because we have longjmp'd to a stack frame that is previous to
7459 the dummy frame, or it could be because the stack unwind is
7460 broken at some point between the longjmp frame and the dummy
7463 Next we figure out why the stack unwind stopped. If it looks
7464 like the unwind is complete then we assume the dummy frame has
7465 been jumped over, however, if the unwind stopped for an
7466 unexpected reason then we assume the stack unwind is currently
7467 broken, and that we will (eventually) return to the dummy
7470 It might be tempting to consider using frame_id_inner here, but
7471 that is not safe. There is no guarantee that the stack frames
7472 we are looking at here are even on the same stack as the
7473 original dummy frame, hence frame_id_inner can't be used. See
7474 the comments on frame_id_inner for more details. */
7475 bool unwind_finished_unexpectedly
= false;
7476 for (frame_info_ptr fi
= get_current_frame (); fi
!= nullptr; )
7478 frame_info_ptr prev
= get_prev_frame (fi
);
7479 if (prev
== nullptr)
7481 /* FI is the last stack frame. Why did this frame not
7483 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7484 if (stop_reason
!= UNWIND_NO_REASON
7485 && stop_reason
!= UNWIND_OUTERMOST
)
7486 unwind_finished_unexpectedly
= true;
7490 if (unwind_finished_unexpectedly
)
7493 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7495 while (b
->related_breakpoint
!= b
)
7497 if (b_tmp
== b
->related_breakpoint
)
7498 b_tmp
= b
->related_breakpoint
->next
;
7499 delete_breakpoint (b
->related_breakpoint
);
7501 delete_breakpoint (b
);
7506 enable_overlay_breakpoints (void)
7508 for (breakpoint
*b
: all_breakpoints ())
7509 if (b
->type
== bp_overlay_event
)
7511 b
->enable_state
= bp_enabled
;
7512 update_global_location_list (UGLL_MAY_INSERT
);
7513 overlay_events_enabled
= 1;
7518 disable_overlay_breakpoints (void)
7520 for (breakpoint
*b
: all_breakpoints ())
7521 if (b
->type
== bp_overlay_event
)
7523 b
->enable_state
= bp_disabled
;
7524 update_global_location_list (UGLL_DONT_INSERT
);
7525 overlay_events_enabled
= 0;
7529 /* Set an active std::terminate breakpoint for each std::terminate
7530 master breakpoint. */
7532 set_std_terminate_breakpoint (void)
7534 for (breakpoint
*b
: all_breakpoints_safe ())
7535 if (b
->pspace
== current_program_space
7536 && b
->type
== bp_std_terminate_master
)
7538 momentary_breakpoint_from_master (b
, bp_std_terminate
, 1,
7539 inferior_thread ()->global_num
);
7543 /* Delete all the std::terminate breakpoints. */
7545 delete_std_terminate_breakpoint (void)
7547 for (breakpoint
*b
: all_breakpoints_safe ())
7548 if (b
->type
== bp_std_terminate
)
7549 delete_breakpoint (b
);
7553 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7555 struct breakpoint
*b
;
7557 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7559 b
->enable_state
= bp_enabled
;
7560 /* locspec has to be used or breakpoint_re_set will delete me. */
7561 b
->locspec
= new_address_location_spec (b
->loc
->address
, NULL
, 0);
7563 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7568 struct lang_and_radix
7574 /* Create a breakpoint for JIT code registration and unregistration. */
7577 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7579 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7582 /* Remove JIT code registration and unregistration breakpoint(s). */
7585 remove_jit_event_breakpoints (void)
7587 for (breakpoint
*b
: all_breakpoints_safe ())
7588 if (b
->type
== bp_jit_event
7589 && b
->loc
->pspace
== current_program_space
)
7590 delete_breakpoint (b
);
7594 remove_solib_event_breakpoints (void)
7596 for (breakpoint
*b
: all_breakpoints_safe ())
7597 if (b
->type
== bp_shlib_event
7598 && b
->loc
->pspace
== current_program_space
)
7599 delete_breakpoint (b
);
7602 /* See breakpoint.h. */
7605 remove_solib_event_breakpoints_at_next_stop (void)
7607 for (breakpoint
*b
: all_breakpoints_safe ())
7608 if (b
->type
== bp_shlib_event
7609 && b
->loc
->pspace
== current_program_space
)
7610 b
->disposition
= disp_del_at_next_stop
;
7613 /* Helper for create_solib_event_breakpoint /
7614 create_and_insert_solib_event_breakpoint. Allows specifying which
7615 INSERT_MODE to pass through to update_global_location_list. */
7617 static struct breakpoint
*
7618 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7619 enum ugll_insert_mode insert_mode
)
7621 struct breakpoint
*b
;
7623 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
7624 update_global_location_list_nothrow (insert_mode
);
7629 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7631 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7634 /* See breakpoint.h. */
7637 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7639 struct breakpoint
*b
;
7641 /* Explicitly tell update_global_location_list to insert
7643 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7644 if (!b
->loc
->inserted
)
7646 delete_breakpoint (b
);
7652 /* Disable any breakpoints that are on code in shared libraries. Only
7653 apply to enabled breakpoints, disabled ones can just stay disabled. */
7656 disable_breakpoints_in_shlibs (void)
7658 for (bp_location
*loc
: all_bp_locations ())
7660 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7661 struct breakpoint
*b
= loc
->owner
;
7663 /* We apply the check to all breakpoints, including disabled for
7664 those with loc->duplicate set. This is so that when breakpoint
7665 becomes enabled, or the duplicate is removed, gdb will try to
7666 insert all breakpoints. If we don't set shlib_disabled here,
7667 we'll try to insert those breakpoints and fail. */
7668 if (((b
->type
== bp_breakpoint
)
7669 || (b
->type
== bp_jit_event
)
7670 || (b
->type
== bp_hardware_breakpoint
)
7671 || (is_tracepoint (b
)))
7672 && loc
->pspace
== current_program_space
7673 && !loc
->shlib_disabled
7674 && solib_name_from_address (loc
->pspace
, loc
->address
)
7677 loc
->shlib_disabled
= 1;
7682 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7683 notification of unloaded_shlib. Only apply to enabled breakpoints,
7684 disabled ones can just stay disabled. */
7687 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7689 int disabled_shlib_breaks
= 0;
7691 for (bp_location
*loc
: all_bp_locations ())
7693 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7694 struct breakpoint
*b
= loc
->owner
;
7696 if (solib
->pspace
== loc
->pspace
7697 && !loc
->shlib_disabled
7698 && (((b
->type
== bp_breakpoint
7699 || b
->type
== bp_jit_event
7700 || b
->type
== bp_hardware_breakpoint
)
7701 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7702 || loc
->loc_type
== bp_loc_software_breakpoint
))
7703 || is_tracepoint (b
))
7704 && solib_contains_address_p (solib
, loc
->address
))
7706 loc
->shlib_disabled
= 1;
7707 /* At this point, we cannot rely on remove_breakpoint
7708 succeeding so we must mark the breakpoint as not inserted
7709 to prevent future errors occurring in remove_breakpoints. */
7712 /* This may cause duplicate notifications for the same breakpoint. */
7713 gdb::observers::breakpoint_modified
.notify (b
);
7715 if (!disabled_shlib_breaks
)
7717 target_terminal::ours_for_output ();
7718 warning (_("Temporarily disabling breakpoints "
7719 "for unloaded shared library \"%s\""),
7722 disabled_shlib_breaks
= 1;
7727 /* Disable any breakpoints and tracepoints in OBJFILE upon
7728 notification of free_objfile. Only apply to enabled breakpoints,
7729 disabled ones can just stay disabled. */
7732 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7734 if (objfile
== NULL
)
7737 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7738 managed by the user with add-symbol-file/remove-symbol-file.
7739 Similarly to how breakpoints in shared libraries are handled in
7740 response to "nosharedlibrary", mark breakpoints in such modules
7741 shlib_disabled so they end up uninserted on the next global
7742 location list update. Shared libraries not loaded by the user
7743 aren't handled here -- they're already handled in
7744 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7745 solib_unloaded observer. We skip objfiles that are not
7746 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7748 if ((objfile
->flags
& OBJF_SHARED
) == 0
7749 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7752 for (breakpoint
*b
: all_breakpoints ())
7754 int bp_modified
= 0;
7756 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7759 for (bp_location
*loc
: b
->locations ())
7761 CORE_ADDR loc_addr
= loc
->address
;
7763 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7764 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7767 if (loc
->shlib_disabled
!= 0)
7770 if (objfile
->pspace
!= loc
->pspace
)
7773 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7774 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7777 if (is_addr_in_objfile (loc_addr
, objfile
))
7779 loc
->shlib_disabled
= 1;
7780 /* At this point, we don't know whether the object was
7781 unmapped from the inferior or not, so leave the
7782 inserted flag alone. We'll handle failure to
7783 uninsert quietly, in case the object was indeed
7786 mark_breakpoint_location_modified (loc
);
7793 gdb::observers::breakpoint_modified
.notify (b
);
7797 /* See breakpoint.h. */
7799 breakpoint::breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
7800 bool temp
, const char *cond_string_
)
7802 disposition (temp
? disp_del
: disp_donttouch
),
7804 language (current_language
->la_language
),
7805 input_radix (::input_radix
),
7806 cond_string (cond_string_
!= nullptr
7807 ? make_unique_xstrdup (cond_string_
)
7809 related_breakpoint (this)
7813 /* See breakpoint.h. */
7815 catchpoint::catchpoint (struct gdbarch
*gdbarch
, bool temp
,
7816 const char *cond_string
)
7817 : breakpoint (gdbarch
, bp_catchpoint
, temp
, cond_string
)
7819 add_dummy_location (this, current_program_space
);
7821 pspace
= current_program_space
;
7825 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
7827 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
7828 set_breakpoint_number (internal
, b
);
7829 if (is_tracepoint (b
))
7830 set_tracepoint_count (breakpoint_count
);
7833 gdb::observers::breakpoint_created
.notify (b
);
7836 update_global_location_list (UGLL_MAY_INSERT
);
7840 hw_breakpoint_used_count (void)
7844 for (breakpoint
*b
: all_breakpoints ())
7845 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7846 for (bp_location
*bl
: b
->locations ())
7848 /* Special types of hardware breakpoints may use more than
7850 i
+= b
->resources_needed (bl
);
7856 /* Returns the resources B would use if it were a hardware
7860 hw_watchpoint_use_count (struct breakpoint
*b
)
7864 if (!breakpoint_enabled (b
))
7867 for (bp_location
*bl
: b
->locations ())
7869 /* Special types of hardware watchpoints may use more than
7871 i
+= b
->resources_needed (bl
);
7877 /* Returns the sum the used resources of all hardware watchpoints of
7878 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7879 the sum of the used resources of all hardware watchpoints of other
7880 types _not_ TYPE. */
7883 hw_watchpoint_used_count_others (struct breakpoint
*except
,
7884 enum bptype type
, int *other_type_used
)
7888 *other_type_used
= 0;
7889 for (breakpoint
*b
: all_breakpoints ())
7893 if (!breakpoint_enabled (b
))
7896 if (b
->type
== type
)
7897 i
+= hw_watchpoint_use_count (b
);
7898 else if (is_hardware_watchpoint (b
))
7899 *other_type_used
= 1;
7906 disable_watchpoints_before_interactive_call_start (void)
7908 for (breakpoint
*b
: all_breakpoints ())
7909 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7911 b
->enable_state
= bp_call_disabled
;
7912 update_global_location_list (UGLL_DONT_INSERT
);
7917 enable_watchpoints_after_interactive_call_stop (void)
7919 for (breakpoint
*b
: all_breakpoints ())
7920 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7922 b
->enable_state
= bp_enabled
;
7923 update_global_location_list (UGLL_MAY_INSERT
);
7928 disable_breakpoints_before_startup (void)
7930 current_program_space
->executing_startup
= 1;
7931 update_global_location_list (UGLL_DONT_INSERT
);
7935 enable_breakpoints_after_startup (void)
7937 current_program_space
->executing_startup
= 0;
7938 breakpoint_re_set ();
7941 /* Allocate a new momentary breakpoint. */
7943 template<typename
... Arg
>
7944 static momentary_breakpoint
*
7945 new_momentary_breakpoint (struct gdbarch
*gdbarch
, enum bptype type
,
7948 if (type
== bp_longjmp
|| type
== bp_exception
)
7949 return new longjmp_breakpoint (gdbarch
, type
,
7950 std::forward
<Arg
> (args
)...);
7952 return new momentary_breakpoint (gdbarch
, type
,
7953 std::forward
<Arg
> (args
)...);
7956 /* Set a momentary breakpoint of type TYPE at address specified by
7957 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
7961 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7962 struct frame_id frame_id
, enum bptype type
)
7964 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
7966 gdb_assert (!frame_id_artificial_p (frame_id
));
7968 std::unique_ptr
<momentary_breakpoint
> b
7969 (new_momentary_breakpoint (gdbarch
, type
, sal
.pspace
, frame_id
,
7970 inferior_thread ()->global_num
));
7972 b
->add_location (sal
);
7974 breakpoint_up
bp (add_to_breakpoint_chain (std::move (b
)));
7976 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7981 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7982 The new breakpoint will have type TYPE, use OPS as its
7983 breakpoint_ops, and will set enabled to LOC_ENABLED. */
7985 static struct breakpoint
*
7986 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7991 std::unique_ptr
<breakpoint
> copy
7992 (new_momentary_breakpoint (orig
->gdbarch
, type
, orig
->pspace
,
7993 orig
->frame_id
, thread
));
7994 copy
->loc
= copy
->allocate_location ();
7995 set_breakpoint_location_function (copy
->loc
);
7997 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7998 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7999 copy
->loc
->address
= orig
->loc
->address
;
8000 copy
->loc
->section
= orig
->loc
->section
;
8001 copy
->loc
->pspace
= orig
->loc
->pspace
;
8002 copy
->loc
->probe
= orig
->loc
->probe
;
8003 copy
->loc
->line_number
= orig
->loc
->line_number
;
8004 copy
->loc
->symtab
= orig
->loc
->symtab
;
8005 copy
->loc
->enabled
= loc_enabled
;
8007 breakpoint
*b
= add_to_breakpoint_chain (std::move (copy
));
8008 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8012 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8016 clone_momentary_breakpoint (struct breakpoint
*orig
)
8018 /* If there's nothing to clone, then return nothing. */
8022 return momentary_breakpoint_from_master (orig
, orig
->type
, 0,
8027 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8030 struct symtab_and_line sal
;
8032 sal
= find_pc_line (pc
, 0);
8034 sal
.section
= find_pc_overlay (pc
);
8035 sal
.explicit_pc
= 1;
8037 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8041 /* Tell the user we have just set a breakpoint B. */
8044 mention (const breakpoint
*b
)
8046 b
->print_mention ();
8047 current_uiout
->text ("\n");
8051 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8053 /* Handle "set breakpoint auto-hw on".
8055 If the explicitly specified breakpoint type is not hardware
8056 breakpoint, check the memory map to see whether the breakpoint
8057 address is in read-only memory.
8059 - location type is not hardware breakpoint, memory is read-only.
8060 We change the type of the location to hardware breakpoint.
8062 - location type is hardware breakpoint, memory is read-write. This
8063 means we've previously made the location hardware one, but then the
8064 memory map changed, so we undo.
8068 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8070 if (automatic_hardware_breakpoints
8071 && bl
->owner
->type
!= bp_hardware_breakpoint
8072 && (bl
->loc_type
== bp_loc_software_breakpoint
8073 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8075 /* When breakpoints are removed, remove_breakpoints will use
8076 location types we've just set here, the only possible problem
8077 is that memory map has changed during running program, but
8078 it's not going to work anyway with current gdb. */
8079 mem_region
*mr
= lookup_mem_region (bl
->address
);
8083 enum bp_loc_type new_type
;
8085 if (mr
->attrib
.mode
!= MEM_RW
)
8086 new_type
= bp_loc_hardware_breakpoint
;
8088 new_type
= bp_loc_software_breakpoint
;
8090 if (new_type
!= bl
->loc_type
)
8092 static bool said
= false;
8094 bl
->loc_type
= new_type
;
8097 gdb_printf (_("Note: automatically using "
8098 "hardware breakpoints for "
8099 "read-only addresses.\n"));
8108 code_breakpoint::add_location (const symtab_and_line
&sal
)
8110 struct bp_location
*new_loc
, **tmp
;
8111 CORE_ADDR adjusted_address
;
8112 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8114 if (loc_gdbarch
== NULL
)
8115 loc_gdbarch
= gdbarch
;
8117 /* Adjust the breakpoint's address prior to allocating a location.
8118 Once we call allocate_location(), that mostly uninitialized
8119 location will be placed on the location chain. Adjustment of the
8120 breakpoint may cause target_read_memory() to be called and we do
8121 not want its scan of the location chain to find a breakpoint and
8122 location that's only been partially initialized. */
8123 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8127 /* Sort the locations by their ADDRESS. */
8128 new_loc
= allocate_location ();
8129 for (tmp
= &(loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8130 tmp
= &((*tmp
)->next
))
8132 new_loc
->next
= *tmp
;
8135 new_loc
->requested_address
= sal
.pc
;
8136 new_loc
->address
= adjusted_address
;
8137 new_loc
->pspace
= sal
.pspace
;
8138 new_loc
->probe
.prob
= sal
.prob
;
8139 new_loc
->probe
.objfile
= sal
.objfile
;
8140 gdb_assert (new_loc
->pspace
!= NULL
);
8141 new_loc
->section
= sal
.section
;
8142 new_loc
->gdbarch
= loc_gdbarch
;
8143 new_loc
->line_number
= sal
.line
;
8144 new_loc
->symtab
= sal
.symtab
;
8145 new_loc
->symbol
= sal
.symbol
;
8146 new_loc
->msymbol
= sal
.msymbol
;
8147 new_loc
->objfile
= sal
.objfile
;
8149 set_breakpoint_location_function (new_loc
);
8151 /* While by definition, permanent breakpoints are already present in the
8152 code, we don't mark the location as inserted. Normally one would expect
8153 that GDB could rely on that breakpoint instruction to stop the program,
8154 thus removing the need to insert its own breakpoint, except that executing
8155 the breakpoint instruction can kill the target instead of reporting a
8156 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8157 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8158 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8159 breakpoint be inserted normally results in QEMU knowing about the GDB
8160 breakpoint, and thus trap before the breakpoint instruction is executed.
8161 (If GDB later needs to continue execution past the permanent breakpoint,
8162 it manually increments the PC, thus avoiding executing the breakpoint
8164 if (bp_loc_is_permanent (new_loc
))
8165 new_loc
->permanent
= 1;
8171 /* Return true if LOC is pointing to a permanent breakpoint,
8172 return false otherwise. */
8175 bp_loc_is_permanent (struct bp_location
*loc
)
8177 gdb_assert (loc
!= NULL
);
8179 /* If we have a non-breakpoint-backed catchpoint or a software
8180 watchpoint, just return 0. We should not attempt to read from
8181 the addresses the locations of these breakpoint types point to.
8182 gdbarch_program_breakpoint_here_p, below, will attempt to read
8184 if (!bl_address_is_meaningful (loc
))
8187 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8188 switch_to_program_space_and_thread (loc
->pspace
);
8189 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8192 /* Build a command list for the dprintf corresponding to the current
8193 settings of the dprintf style options. */
8196 update_dprintf_command_list (struct breakpoint
*b
)
8198 const char *dprintf_args
= b
->extra_string
.get ();
8199 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8204 dprintf_args
= skip_spaces (dprintf_args
);
8206 /* Allow a comma, as it may have terminated a location, but don't
8208 if (*dprintf_args
== ',')
8210 dprintf_args
= skip_spaces (dprintf_args
);
8212 if (*dprintf_args
!= '"')
8213 error (_("Bad format string, missing '\"'."));
8215 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8216 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8217 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8219 if (dprintf_function
.empty ())
8220 error (_("No function supplied for dprintf call"));
8222 if (!dprintf_channel
.empty ())
8223 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8224 dprintf_function
.c_str (),
8225 dprintf_channel
.c_str (),
8228 printf_line
= xstrprintf ("call (void) %s (%s)",
8229 dprintf_function
.c_str (),
8232 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8234 if (target_can_run_breakpoint_commands ())
8235 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8238 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8239 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8243 internal_error (_("Invalid dprintf style."));
8245 gdb_assert (printf_line
!= NULL
);
8247 /* Manufacture a printf sequence. */
8248 struct command_line
*printf_cmd_line
8249 = new struct command_line (simple_control
, printf_line
.release ());
8250 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8251 command_lines_deleter ()));
8254 /* Update all dprintf commands, making their command lists reflect
8255 current style settings. */
8258 update_dprintf_commands (const char *args
, int from_tty
,
8259 struct cmd_list_element
*c
)
8261 for (breakpoint
*b
: all_breakpoints ())
8262 if (b
->type
== bp_dprintf
)
8263 update_dprintf_command_list (b
);
8266 code_breakpoint::code_breakpoint (struct gdbarch
*gdbarch_
,
8268 gdb::array_view
<const symtab_and_line
> sals
,
8269 location_spec_up
&&locspec_
,
8270 gdb::unique_xmalloc_ptr
<char> filter_
,
8271 gdb::unique_xmalloc_ptr
<char> cond_string_
,
8272 gdb::unique_xmalloc_ptr
<char> extra_string_
,
8273 enum bpdisp disposition_
,
8274 int thread_
, int task_
, int ignore_count_
,
8276 int enabled_
, unsigned flags
,
8277 int display_canonical_
)
8278 : breakpoint (gdbarch_
, type_
)
8282 if (type
== bp_hardware_breakpoint
)
8284 int target_resources_ok
;
8286 i
= hw_breakpoint_used_count ();
8287 target_resources_ok
=
8288 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8290 if (target_resources_ok
== 0)
8291 error (_("No hardware breakpoint support in the target."));
8292 else if (target_resources_ok
< 0)
8293 error (_("Hardware breakpoints used exceeds limit."));
8296 gdb_assert (!sals
.empty ());
8301 cond_string
= std::move (cond_string_
);
8302 extra_string
= std::move (extra_string_
);
8303 ignore_count
= ignore_count_
;
8304 enable_state
= enabled_
? bp_enabled
: bp_disabled
;
8305 disposition
= disposition_
;
8307 if (type
== bp_static_tracepoint
8308 || type
== bp_static_marker_tracepoint
)
8310 auto *t
= gdb::checked_static_cast
<struct tracepoint
*> (this);
8311 struct static_tracepoint_marker marker
;
8313 if (strace_marker_p (this))
8315 /* We already know the marker exists, otherwise, we wouldn't
8316 see a sal for it. */
8317 const char *p
= &locspec_
->to_string ()[3];
8320 p
= skip_spaces (p
);
8322 endp
= skip_to_space (p
);
8324 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8326 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8327 t
->static_trace_marker_id
.c_str ());
8329 else if (target_static_tracepoint_marker_at (sals
[0].pc
, &marker
))
8331 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8333 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8334 t
->static_trace_marker_id
.c_str ());
8337 warning (_("Couldn't determine the static tracepoint marker to probe"));
8340 for (const auto &sal
: sals
)
8344 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8345 if (loc_gdbarch
== nullptr)
8346 loc_gdbarch
= gdbarch
;
8348 describe_other_breakpoints (loc_gdbarch
,
8349 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8352 bp_location
*new_loc
= add_location (sal
);
8353 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8354 new_loc
->inserted
= 1;
8356 /* Do not set breakpoint locations conditions yet. As locations
8357 are inserted, they get sorted based on their addresses. Let
8358 the list stabilize to have reliable location numbers. */
8360 /* Dynamic printf requires and uses additional arguments on the
8361 command line, otherwise it's an error. */
8362 if (type
== bp_dprintf
)
8364 if (extra_string
!= nullptr)
8365 update_dprintf_command_list (this);
8367 error (_("Format string required"));
8369 else if (extra_string
!= nullptr)
8370 error (_("Garbage '%s' at end of command"), extra_string
.get ());
8373 /* The order of the locations is now stable. Set the location
8374 condition using the location's number. */
8376 for (bp_location
*bl
: locations ())
8378 if (cond_string
!= nullptr)
8379 set_breakpoint_location_condition (cond_string
.get (), bl
,
8385 display_canonical
= display_canonical_
;
8386 if (locspec_
!= nullptr)
8387 locspec
= std::move (locspec_
);
8389 locspec
= new_address_location_spec (this->loc
->address
, NULL
, 0);
8390 filter
= std::move (filter_
);
8394 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8395 gdb::array_view
<const symtab_and_line
> sals
,
8396 location_spec_up
&&locspec
,
8397 gdb::unique_xmalloc_ptr
<char> filter
,
8398 gdb::unique_xmalloc_ptr
<char> cond_string
,
8399 gdb::unique_xmalloc_ptr
<char> extra_string
,
8400 enum bptype type
, enum bpdisp disposition
,
8401 int thread
, int task
, int ignore_count
,
8403 int enabled
, int internal
, unsigned flags
,
8404 int display_canonical
)
8406 std::unique_ptr
<code_breakpoint
> b
8407 = new_breakpoint_from_type (gdbarch
,
8410 std::move (locspec
),
8412 std::move (cond_string
),
8413 std::move (extra_string
),
8415 thread
, task
, ignore_count
,
8420 install_breakpoint (internal
, std::move (b
), 0);
8423 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8424 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8425 value. COND_STRING, if not NULL, specified the condition to be
8426 used for all breakpoints. Essentially the only case where
8427 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8428 function. In that case, it's still not possible to specify
8429 separate conditions for different overloaded functions, so
8430 we take just a single condition string.
8432 NOTE: If the function succeeds, the caller is expected to cleanup
8433 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8434 array contents). If the function fails (error() is called), the
8435 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8436 COND and SALS arrays and each of those arrays contents. */
8439 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8440 struct linespec_result
*canonical
,
8441 gdb::unique_xmalloc_ptr
<char> cond_string
,
8442 gdb::unique_xmalloc_ptr
<char> extra_string
,
8443 enum bptype type
, enum bpdisp disposition
,
8444 int thread
, int task
, int ignore_count
,
8446 int enabled
, int internal
, unsigned flags
)
8448 if (canonical
->pre_expanded
)
8449 gdb_assert (canonical
->lsals
.size () == 1);
8451 for (const auto &lsal
: canonical
->lsals
)
8453 /* Note that 'location' can be NULL in the case of a plain
8454 'break', without arguments. */
8455 location_spec_up locspec
8456 = (canonical
->locspec
!= nullptr
8457 ? canonical
->locspec
->clone ()
8459 gdb::unique_xmalloc_ptr
<char> filter_string
8460 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8462 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8463 std::move (locspec
),
8464 std::move (filter_string
),
8465 std::move (cond_string
),
8466 std::move (extra_string
),
8468 thread
, task
, ignore_count
,
8469 from_tty
, enabled
, internal
, flags
,
8470 canonical
->special_display
);
8474 /* Parse LOCSPEC which is assumed to be a SAL specification possibly
8475 followed by conditionals. On return, SALS contains an array of SAL
8476 addresses found. LOCSPEC points to the end of the SAL (for
8479 The array and the line spec strings are allocated on the heap, it is
8480 the caller's responsibility to free them. */
8483 parse_breakpoint_sals (location_spec
*locspec
,
8484 struct linespec_result
*canonical
)
8486 struct symtab_and_line cursal
;
8488 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8490 const char *spec
= as_linespec_location_spec (locspec
)->spec_string
;
8494 /* The last displayed codepoint, if it's valid, is our default
8495 breakpoint address. */
8496 if (last_displayed_sal_is_valid ())
8498 /* Set sal's pspace, pc, symtab, and line to the values
8499 corresponding to the last call to print_frame_info.
8500 Be sure to reinitialize LINE with NOTCURRENT == 0
8501 as the breakpoint line number is inappropriate otherwise.
8502 find_pc_line would adjust PC, re-set it back. */
8503 symtab_and_line sal
= get_last_displayed_sal ();
8504 CORE_ADDR pc
= sal
.pc
;
8506 sal
= find_pc_line (pc
, 0);
8508 /* "break" without arguments is equivalent to "break *PC"
8509 where PC is the last displayed codepoint's address. So
8510 make sure to set sal.explicit_pc to prevent GDB from
8511 trying to expand the list of sals to include all other
8512 instances with the same symtab and line. */
8514 sal
.explicit_pc
= 1;
8516 struct linespec_sals lsal
;
8518 lsal
.canonical
= NULL
;
8520 canonical
->lsals
.push_back (std::move (lsal
));
8524 error (_("No default breakpoint address now."));
8528 /* Force almost all breakpoints to be in terms of the
8529 current_source_symtab (which is decode_line_1's default).
8530 This should produce the results we want almost all of the
8531 time while leaving default_breakpoint_* alone.
8533 ObjC: However, don't match an Objective-C method name which
8534 may have a '+' or '-' succeeded by a '['. */
8535 cursal
= get_current_source_symtab_and_line ();
8536 if (last_displayed_sal_is_valid ())
8538 const char *spec
= NULL
;
8540 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8541 spec
= as_linespec_location_spec (locspec
)->spec_string
;
8545 && strchr ("+-", spec
[0]) != NULL
8548 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8549 get_last_displayed_symtab (),
8550 get_last_displayed_line (),
8551 canonical
, NULL
, NULL
);
8556 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8557 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8561 /* Convert each SAL into a real PC. Verify that the PC can be
8562 inserted as a breakpoint. If it can't throw an error. */
8565 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8567 for (auto &sal
: sals
)
8568 resolve_sal_pc (&sal
);
8571 /* Fast tracepoints may have restrictions on valid locations. For
8572 instance, a fast tracepoint using a jump instead of a trap will
8573 likely have to overwrite more bytes than a trap would, and so can
8574 only be placed where the instruction is longer than the jump, or a
8575 multi-instruction sequence does not have a jump into the middle of
8579 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8580 gdb::array_view
<const symtab_and_line
> sals
)
8582 for (const auto &sal
: sals
)
8584 struct gdbarch
*sarch
;
8586 sarch
= get_sal_arch (sal
);
8587 /* We fall back to GDBARCH if there is no architecture
8588 associated with SAL. */
8592 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8593 error (_("May not have a fast tracepoint at %s%s"),
8594 paddress (sarch
, sal
.pc
), msg
.c_str ());
8598 /* Given TOK, a string specification of condition and thread, as
8599 accepted by the 'break' command, extract the condition
8600 string and thread number and set *COND_STRING and *THREAD.
8601 PC identifies the context at which the condition should be parsed.
8602 If no condition is found, *COND_STRING is set to NULL.
8603 If no thread is found, *THREAD is set to -1. */
8606 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8607 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8608 int *thread
, int *task
,
8609 gdb::unique_xmalloc_ptr
<char> *rest
)
8611 cond_string
->reset ();
8619 const char *end_tok
;
8621 const char *cond_start
= NULL
;
8622 const char *cond_end
= NULL
;
8624 tok
= skip_spaces (tok
);
8626 if ((*tok
== '"' || *tok
== ',') && rest
)
8628 rest
->reset (savestring (tok
, strlen (tok
)));
8632 end_tok
= skip_to_space (tok
);
8634 toklen
= end_tok
- tok
;
8636 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8638 tok
= cond_start
= end_tok
+ 1;
8641 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8643 catch (const gdb_exception_error
&)
8648 tok
= tok
+ strlen (tok
);
8651 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8653 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8658 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8661 struct thread_info
*thr
;
8664 thr
= parse_thread_id (tok
, &tmptok
);
8666 error (_("Junk after thread keyword."));
8667 *thread
= thr
->global_num
;
8670 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8675 *task
= strtol (tok
, &tmptok
, 0);
8677 error (_("Junk after task keyword."));
8678 if (!valid_task_id (*task
))
8679 error (_("Unknown task %d."), *task
);
8684 rest
->reset (savestring (tok
, strlen (tok
)));
8688 error (_("Junk at end of arguments."));
8692 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8693 succeeds. The parsed values are written to COND_STRING, THREAD,
8694 TASK, and REST. See the comment of 'find_condition_and_thread'
8695 for the description of these parameters and INPUT. */
8698 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8700 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8701 int *thread
, int *task
,
8702 gdb::unique_xmalloc_ptr
<char> *rest
)
8704 int num_failures
= 0;
8705 for (auto &sal
: sals
)
8707 gdb::unique_xmalloc_ptr
<char> cond
;
8710 gdb::unique_xmalloc_ptr
<char> remaining
;
8712 /* Here we want to parse 'arg' to separate condition from thread
8713 number. But because parsing happens in a context and the
8714 contexts of sals might be different, try each until there is
8715 success. Finding one successful parse is sufficient for our
8716 goal. When setting the breakpoint we'll re-parse the
8717 condition in the context of each sal. */
8720 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8721 &task_id
, &remaining
);
8722 *cond_string
= std::move (cond
);
8723 *thread
= thread_id
;
8725 *rest
= std::move (remaining
);
8728 catch (const gdb_exception_error
&e
)
8731 /* If no sal remains, do not continue. */
8732 if (num_failures
== sals
.size ())
8738 /* Decode a static tracepoint marker spec. */
8740 static std::vector
<symtab_and_line
>
8741 decode_static_tracepoint_spec (const char **arg_p
)
8743 const char *p
= &(*arg_p
)[3];
8746 p
= skip_spaces (p
);
8748 endp
= skip_to_space (p
);
8750 std::string
marker_str (p
, endp
- p
);
8752 std::vector
<static_tracepoint_marker
> markers
8753 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8754 if (markers
.empty ())
8755 error (_("No known static tracepoint marker named %s"),
8756 marker_str
.c_str ());
8758 std::vector
<symtab_and_line
> sals
;
8759 sals
.reserve (markers
.size ());
8761 for (const static_tracepoint_marker
&marker
: markers
)
8763 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8764 sal
.pc
= marker
.address
;
8765 sals
.push_back (sal
);
8772 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8773 according to IS_TRACEPOINT. */
8775 static const struct breakpoint_ops
*
8776 breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type
,
8781 if (locspec_type
== PROBE_LOCATION_SPEC
)
8782 return &tracepoint_probe_breakpoint_ops
;
8784 return &code_breakpoint_ops
;
8788 if (locspec_type
== PROBE_LOCATION_SPEC
)
8789 return &bkpt_probe_breakpoint_ops
;
8791 return &code_breakpoint_ops
;
8795 /* See breakpoint.h. */
8797 const struct breakpoint_ops
*
8798 breakpoint_ops_for_location_spec (const location_spec
*locspec
,
8801 if (locspec
!= nullptr)
8802 return (breakpoint_ops_for_location_spec_type
8803 (locspec
->type (), is_tracepoint
));
8804 return &code_breakpoint_ops
;
8807 /* See breakpoint.h. */
8810 create_breakpoint (struct gdbarch
*gdbarch
,
8811 location_spec
*locspec
,
8812 const char *cond_string
,
8813 int thread
, const char *extra_string
,
8814 bool force_condition
, int parse_extra
,
8815 int tempflag
, enum bptype type_wanted
,
8817 enum auto_boolean pending_break_support
,
8818 const struct breakpoint_ops
*ops
,
8819 int from_tty
, int enabled
, int internal
,
8822 struct linespec_result canonical
;
8825 int prev_bkpt_count
= breakpoint_count
;
8827 gdb_assert (ops
!= NULL
);
8829 /* If extra_string isn't useful, set it to NULL. */
8830 if (extra_string
!= NULL
&& *extra_string
== '\0')
8831 extra_string
= NULL
;
8835 ops
->create_sals_from_location_spec (locspec
, &canonical
);
8837 catch (const gdb_exception_error
&e
)
8839 /* If caller is interested in rc value from parse, set
8841 if (e
.error
== NOT_FOUND_ERROR
)
8843 /* If pending breakpoint support is turned off, throw
8846 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8849 exception_print (gdb_stderr
, e
);
8851 /* If pending breakpoint support is auto query and the user
8852 selects no, then simply return the error code. */
8853 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8854 && !nquery (_("Make %s pending on future shared library load? "),
8855 bptype_string (type_wanted
)))
8858 /* At this point, either the user was queried about setting
8859 a pending breakpoint and selected yes, or pending
8860 breakpoint behavior is on and thus a pending breakpoint
8861 is defaulted on behalf of the user. */
8868 if (!pending
&& canonical
.lsals
.empty ())
8871 /* Resolve all line numbers to PC's and verify that the addresses
8872 are ok for the target. */
8875 for (auto &lsal
: canonical
.lsals
)
8876 breakpoint_sals_to_pc (lsal
.sals
);
8879 /* Fast tracepoints may have additional restrictions on location. */
8880 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8882 for (const auto &lsal
: canonical
.lsals
)
8883 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
8886 /* Verify that condition can be parsed, before setting any
8887 breakpoints. Allocate a separate condition expression for each
8891 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
8892 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
8896 gdb::unique_xmalloc_ptr
<char> rest
;
8897 gdb::unique_xmalloc_ptr
<char> cond
;
8899 const linespec_sals
&lsal
= canonical
.lsals
[0];
8901 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
8902 &cond
, &thread
, &task
, &rest
);
8903 cond_string_copy
= std::move (cond
);
8904 extra_string_copy
= std::move (rest
);
8908 if (type_wanted
!= bp_dprintf
8909 && extra_string
!= NULL
&& *extra_string
!= '\0')
8910 error (_("Garbage '%s' at end of location"), extra_string
);
8912 /* Check the validity of the condition. We should error out
8913 if the condition is invalid at all of the locations and
8914 if it is not forced. In the PARSE_EXTRA case above, this
8915 check is done when parsing the EXTRA_STRING. */
8916 if (cond_string
!= nullptr && !force_condition
)
8918 int num_failures
= 0;
8919 const linespec_sals
&lsal
= canonical
.lsals
[0];
8920 for (const auto &sal
: lsal
.sals
)
8922 const char *cond
= cond_string
;
8925 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
8926 /* One success is sufficient to keep going. */
8929 catch (const gdb_exception_error
&)
8932 /* If this is the last sal, error out. */
8933 if (num_failures
== lsal
.sals
.size ())
8939 /* Create a private copy of condition string. */
8941 cond_string_copy
.reset (xstrdup (cond_string
));
8942 /* Create a private copy of any extra string. */
8944 extra_string_copy
.reset (xstrdup (extra_string
));
8947 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
8948 std::move (cond_string_copy
),
8949 std::move (extra_string_copy
),
8951 tempflag
? disp_del
: disp_donttouch
,
8952 thread
, task
, ignore_count
,
8953 from_tty
, enabled
, internal
, flags
);
8957 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
,
8959 b
->locspec
= locspec
->clone ();
8962 b
->cond_string
= NULL
;
8965 /* Create a private copy of condition string. */
8966 b
->cond_string
.reset (cond_string
!= NULL
8967 ? xstrdup (cond_string
)
8972 /* Create a private copy of any extra string. */
8973 b
->extra_string
.reset (extra_string
!= NULL
8974 ? xstrdup (extra_string
)
8976 b
->ignore_count
= ignore_count
;
8977 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8978 b
->condition_not_parsed
= 1;
8979 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8980 if ((type_wanted
!= bp_breakpoint
8981 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
8982 b
->pspace
= current_program_space
;
8984 install_breakpoint (internal
, std::move (b
), 0);
8987 if (canonical
.lsals
.size () > 1)
8989 warning (_("Multiple breakpoints were set.\nUse the "
8990 "\"delete\" command to delete unwanted breakpoints."));
8991 prev_breakpoint_count
= prev_bkpt_count
;
8994 update_global_location_list (UGLL_MAY_INSERT
);
8999 /* Set a breakpoint.
9000 ARG is a string describing breakpoint address,
9001 condition, and thread.
9002 FLAG specifies if a breakpoint is hardware on,
9003 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9007 break_command_1 (const char *arg
, int flag
, int from_tty
)
9009 int tempflag
= flag
& BP_TEMPFLAG
;
9010 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9011 ? bp_hardware_breakpoint
9014 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9015 const struct breakpoint_ops
*ops
9016 = breakpoint_ops_for_location_spec (locspec
.get (),
9017 false /* is_tracepoint */);
9019 create_breakpoint (get_current_arch (),
9021 NULL
, 0, arg
, false, 1 /* parse arg */,
9022 tempflag
, type_wanted
,
9023 0 /* Ignore count */,
9024 pending_break_support
,
9032 /* Helper function for break_command_1 and disassemble_command. */
9035 resolve_sal_pc (struct symtab_and_line
*sal
)
9039 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9041 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9042 error (_("No line %d in file \"%s\"."),
9043 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9046 /* If this SAL corresponds to a breakpoint inserted using a line
9047 number, then skip the function prologue if necessary. */
9048 if (sal
->explicit_line
)
9049 skip_prologue_sal (sal
);
9052 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9054 const struct blockvector
*bv
;
9055 const struct block
*b
;
9058 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9059 sal
->symtab
->compunit ());
9062 sym
= block_linkage_function (b
);
9065 fixup_symbol_section (sym
, sal
->symtab
->compunit ()->objfile ());
9067 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9071 /* It really is worthwhile to have the section, so we'll
9072 just have to look harder. This case can be executed
9073 if we have line numbers but no functions (as can
9074 happen in assembly source). */
9076 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9077 switch_to_program_space_and_thread (sal
->pspace
);
9079 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9081 sal
->section
= msym
.obj_section ();
9088 break_command (const char *arg
, int from_tty
)
9090 break_command_1 (arg
, 0, from_tty
);
9094 tbreak_command (const char *arg
, int from_tty
)
9096 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9100 hbreak_command (const char *arg
, int from_tty
)
9102 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9106 thbreak_command (const char *arg
, int from_tty
)
9108 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9111 /* The dynamic printf command is mostly like a regular breakpoint, but
9112 with a prewired command list consisting of a single output command,
9113 built from extra arguments supplied on the dprintf command
9117 dprintf_command (const char *arg
, int from_tty
)
9119 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9121 /* If non-NULL, ARG should have been advanced past the location;
9122 the next character must be ','. */
9125 if (arg
[0] != ',' || arg
[1] == '\0')
9126 error (_("Format string required"));
9129 /* Skip the comma. */
9134 create_breakpoint (get_current_arch (),
9136 NULL
, 0, arg
, false, 1 /* parse arg */,
9138 0 /* Ignore count */,
9139 pending_break_support
,
9140 &code_breakpoint_ops
,
9148 agent_printf_command (const char *arg
, int from_tty
)
9150 error (_("May only run agent-printf on the target"));
9153 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9156 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9157 const address_space
*aspace
,
9159 const target_waitstatus
&ws
)
9161 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9162 || ws
.sig () != GDB_SIGNAL_TRAP
)
9165 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9166 bl
->length
, aspace
, bp_addr
);
9169 /* Implement the "resources_needed" method for ranged breakpoints. */
9172 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9174 return target_ranged_break_num_registers ();
9177 /* Implement the "print_it" method for ranged breakpoints. */
9179 enum print_stop_action
9180 ranged_breakpoint::print_it (const bpstat
*bs
) const
9182 struct bp_location
*bl
= loc
;
9183 struct ui_out
*uiout
= current_uiout
;
9185 gdb_assert (type
== bp_hardware_breakpoint
);
9187 /* Ranged breakpoints have only one location. */
9188 gdb_assert (bl
&& bl
->next
== NULL
);
9190 annotate_breakpoint (number
);
9192 maybe_print_thread_hit_breakpoint (uiout
);
9194 if (disposition
== disp_del
)
9195 uiout
->text ("Temporary ranged breakpoint ");
9197 uiout
->text ("Ranged breakpoint ");
9198 if (uiout
->is_mi_like_p ())
9200 uiout
->field_string ("reason",
9201 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9202 uiout
->field_string ("disp", bpdisp_text (disposition
));
9204 uiout
->field_signed ("bkptno", number
);
9207 return PRINT_SRC_AND_LOC
;
9210 /* Implement the "print_one" method for ranged breakpoints. */
9213 ranged_breakpoint::print_one (bp_location
**last_loc
) const
9215 struct bp_location
*bl
= loc
;
9216 struct value_print_options opts
;
9217 struct ui_out
*uiout
= current_uiout
;
9219 /* Ranged breakpoints have only one location. */
9220 gdb_assert (bl
&& bl
->next
== NULL
);
9222 get_user_print_options (&opts
);
9224 if (opts
.addressprint
)
9225 /* We don't print the address range here, it will be printed later
9226 by ranged_breakpoint::print_one_detail. */
9227 uiout
->field_skip ("addr");
9229 print_breakpoint_location (this, bl
);
9235 /* Implement the "print_one_detail" method for ranged breakpoints. */
9238 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9240 CORE_ADDR address_start
, address_end
;
9241 struct bp_location
*bl
= loc
;
9246 address_start
= bl
->address
;
9247 address_end
= address_start
+ bl
->length
- 1;
9249 uiout
->text ("\taddress range: ");
9250 stb
.printf ("[%s, %s]",
9251 print_core_address (bl
->gdbarch
, address_start
),
9252 print_core_address (bl
->gdbarch
, address_end
));
9253 uiout
->field_stream ("addr", stb
);
9257 /* Implement the "print_mention" method for ranged breakpoints. */
9260 ranged_breakpoint::print_mention () const
9262 struct bp_location
*bl
= loc
;
9263 struct ui_out
*uiout
= current_uiout
;
9266 gdb_assert (type
== bp_hardware_breakpoint
);
9268 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9269 number
, paddress (bl
->gdbarch
, bl
->address
),
9270 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9273 /* Implement the "print_recreate" method for ranged breakpoints. */
9276 ranged_breakpoint::print_recreate (struct ui_file
*fp
) const
9278 gdb_printf (fp
, "break-range %s, %s",
9279 locspec
->to_string (),
9280 locspec_range_end
->to_string ());
9281 print_recreate_thread (fp
);
9284 /* Find the address where the end of the breakpoint range should be
9285 placed, given the SAL of the end of the range. This is so that if
9286 the user provides a line number, the end of the range is set to the
9287 last instruction of the given line. */
9290 find_breakpoint_range_end (struct symtab_and_line sal
)
9294 /* If the user provided a PC value, use it. Otherwise,
9295 find the address of the end of the given location. */
9296 if (sal
.explicit_pc
)
9303 ret
= find_line_pc_range (sal
, &start
, &end
);
9305 error (_("Could not find location of the end of the range."));
9307 /* find_line_pc_range returns the start of the next line. */
9314 /* Implement the "break-range" CLI command. */
9317 break_range_command (const char *arg
, int from_tty
)
9319 const char *arg_start
;
9320 struct linespec_result canonical_start
, canonical_end
;
9321 int bp_count
, can_use_bp
, length
;
9324 /* We don't support software ranged breakpoints. */
9325 if (target_ranged_break_num_registers () < 0)
9326 error (_("This target does not support hardware ranged breakpoints."));
9328 bp_count
= hw_breakpoint_used_count ();
9329 bp_count
+= target_ranged_break_num_registers ();
9330 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9333 error (_("Hardware breakpoints used exceeds limit."));
9335 arg
= skip_spaces (arg
);
9336 if (arg
== NULL
|| arg
[0] == '\0')
9337 error(_("No address range specified."));
9340 location_spec_up start_locspec
9341 = string_to_location_spec (&arg
, current_language
);
9342 parse_breakpoint_sals (start_locspec
.get (), &canonical_start
);
9345 error (_("Too few arguments."));
9346 else if (canonical_start
.lsals
.empty ())
9347 error (_("Could not find location of the beginning of the range."));
9349 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9351 if (canonical_start
.lsals
.size () > 1
9352 || lsal_start
.sals
.size () != 1)
9353 error (_("Cannot create a ranged breakpoint with multiple locations."));
9355 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9356 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9358 arg
++; /* Skip the comma. */
9359 arg
= skip_spaces (arg
);
9361 /* Parse the end location specification. */
9365 /* We call decode_line_full directly here instead of using
9366 parse_breakpoint_sals because we need to specify the start
9367 location spec's symtab and line as the default symtab and line
9368 for the end of the range. This makes it possible to have ranges
9369 like "foo.c:27, +14", where +14 means 14 lines from the start
9371 location_spec_up end_locspec
9372 = string_to_location_spec (&arg
, current_language
);
9373 decode_line_full (end_locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9374 sal_start
.symtab
, sal_start
.line
,
9375 &canonical_end
, NULL
, NULL
);
9377 if (canonical_end
.lsals
.empty ())
9378 error (_("Could not find location of the end of the range."));
9380 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9381 if (canonical_end
.lsals
.size () > 1
9382 || lsal_end
.sals
.size () != 1)
9383 error (_("Cannot create a ranged breakpoint with multiple locations."));
9385 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9387 end
= find_breakpoint_range_end (sal_end
);
9388 if (sal_start
.pc
> end
)
9389 error (_("Invalid address range, end precedes start."));
9391 length
= end
- sal_start
.pc
+ 1;
9393 /* Length overflowed. */
9394 error (_("Address range too large."));
9395 else if (length
== 1)
9397 /* This range is simple enough to be handled by
9398 the `hbreak' command. */
9399 hbreak_command (&addr_string_start
[0], 1);
9404 /* Now set up the breakpoint and install it. */
9406 std::unique_ptr
<breakpoint
> br
9407 (new ranged_breakpoint (get_current_arch (),
9409 std::move (start_locspec
),
9410 std::move (end_locspec
)));
9412 install_breakpoint (false, std::move (br
), true);
9415 /* Return non-zero if EXP is verified as constant. Returned zero
9416 means EXP is variable. Also the constant detection may fail for
9417 some constant expressions and in such case still falsely return
9421 watchpoint_exp_is_const (const struct expression
*exp
)
9423 return exp
->op
->constant_p ();
9426 /* Implement the "re_set" method for watchpoints. */
9429 watchpoint::re_set ()
9431 /* Watchpoint can be either on expression using entirely global
9432 variables, or it can be on local variables.
9434 Watchpoints of the first kind are never auto-deleted, and even
9435 persist across program restarts. Since they can use variables
9436 from shared libraries, we need to reparse expression as libraries
9437 are loaded and unloaded.
9439 Watchpoints on local variables can also change meaning as result
9440 of solib event. For example, if a watchpoint uses both a local
9441 and a global variables in expression, it's a local watchpoint,
9442 but unloading of a shared library will make the expression
9443 invalid. This is not a very common use case, but we still
9444 re-evaluate expression, to avoid surprises to the user.
9446 Note that for local watchpoints, we re-evaluate it only if
9447 watchpoints frame id is still valid. If it's not, it means the
9448 watchpoint is out of scope and will be deleted soon. In fact,
9449 I'm not sure we'll ever be called in this case.
9451 If a local watchpoint's frame id is still valid, then
9452 exp_valid_block is likewise valid, and we can safely use it.
9454 Don't do anything about disabled watchpoints, since they will be
9455 reevaluated again when enabled. */
9456 update_watchpoint (this, 1 /* reparse */);
9459 /* Implement the "insert" method for hardware watchpoints. */
9462 watchpoint::insert_location (struct bp_location
*bl
)
9464 int length
= exact
? 1 : bl
->length
;
9466 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9470 /* Implement the "remove" method for hardware watchpoints. */
9473 watchpoint::remove_location (struct bp_location
*bl
,
9474 enum remove_bp_reason reason
)
9476 int length
= exact
? 1 : bl
->length
;
9478 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9483 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9484 const address_space
*aspace
, CORE_ADDR bp_addr
,
9485 const target_waitstatus
&ws
)
9487 struct breakpoint
*b
= bl
->owner
;
9489 /* Continuable hardware watchpoints are treated as non-existent if the
9490 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9491 some data address). Otherwise gdb won't stop on a break instruction
9492 in the code (not from a breakpoint) when a hardware watchpoint has
9493 been defined. Also skip watchpoints which we know did not trigger
9494 (did not match the data address). */
9495 if (is_hardware_watchpoint (b
)
9496 && watchpoint_triggered
== watch_triggered_no
)
9503 watchpoint::check_status (bpstat
*bs
)
9505 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9507 bpstat_check_watchpoint (bs
);
9510 /* Implement the "resources_needed" method for hardware
9514 watchpoint::resources_needed (const struct bp_location
*bl
)
9516 int length
= exact
? 1 : bl
->length
;
9518 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9521 /* Implement the "works_in_software_mode" method for hardware
9525 watchpoint::works_in_software_mode () const
9527 /* Read and access watchpoints only work with hardware support. */
9528 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9531 enum print_stop_action
9532 watchpoint::print_it (const bpstat
*bs
) const
9534 struct breakpoint
*b
;
9535 enum print_stop_action result
;
9536 struct ui_out
*uiout
= current_uiout
;
9538 gdb_assert (bs
->bp_location_at
!= NULL
);
9540 b
= bs
->breakpoint_at
;
9542 annotate_watchpoint (b
->number
);
9543 maybe_print_thread_hit_breakpoint (uiout
);
9547 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9551 case bp_hardware_watchpoint
:
9552 if (uiout
->is_mi_like_p ())
9554 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9556 tuple_emitter
.emplace (uiout
, "value");
9557 uiout
->text ("\nOld value = ");
9558 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9559 uiout
->field_stream ("old", stb
);
9560 uiout
->text ("\nNew value = ");
9561 watchpoint_value_print (val
.get (), &stb
);
9562 uiout
->field_stream ("new", stb
);
9564 /* More than one watchpoint may have been triggered. */
9565 result
= PRINT_UNKNOWN
;
9568 case bp_read_watchpoint
:
9569 if (uiout
->is_mi_like_p ())
9571 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9573 tuple_emitter
.emplace (uiout
, "value");
9574 uiout
->text ("\nValue = ");
9575 watchpoint_value_print (val
.get (), &stb
);
9576 uiout
->field_stream ("value", stb
);
9578 result
= PRINT_UNKNOWN
;
9581 case bp_access_watchpoint
:
9582 if (bs
->old_val
!= NULL
)
9584 if (uiout
->is_mi_like_p ())
9587 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9589 tuple_emitter
.emplace (uiout
, "value");
9590 uiout
->text ("\nOld value = ");
9591 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9592 uiout
->field_stream ("old", stb
);
9593 uiout
->text ("\nNew value = ");
9598 if (uiout
->is_mi_like_p ())
9601 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9602 tuple_emitter
.emplace (uiout
, "value");
9603 uiout
->text ("\nValue = ");
9605 watchpoint_value_print (val
.get (), &stb
);
9606 uiout
->field_stream ("new", stb
);
9608 result
= PRINT_UNKNOWN
;
9611 result
= PRINT_UNKNOWN
;
9617 /* Implement the "print_mention" method for hardware watchpoints. */
9620 watchpoint::print_mention () const
9622 struct ui_out
*uiout
= current_uiout
;
9623 const char *tuple_name
;
9628 uiout
->text ("Watchpoint ");
9631 case bp_hardware_watchpoint
:
9632 uiout
->text ("Hardware watchpoint ");
9635 case bp_read_watchpoint
:
9636 uiout
->text ("Hardware read watchpoint ");
9637 tuple_name
= "hw-rwpt";
9639 case bp_access_watchpoint
:
9640 uiout
->text ("Hardware access (read/write) watchpoint ");
9641 tuple_name
= "hw-awpt";
9644 internal_error (_("Invalid hardware watchpoint type."));
9647 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9648 uiout
->field_signed ("number", number
);
9650 uiout
->field_string ("exp", exp_string
.get ());
9653 /* Implement the "print_recreate" method for watchpoints. */
9656 watchpoint::print_recreate (struct ui_file
*fp
) const
9661 case bp_hardware_watchpoint
:
9662 gdb_printf (fp
, "watch");
9664 case bp_read_watchpoint
:
9665 gdb_printf (fp
, "rwatch");
9667 case bp_access_watchpoint
:
9668 gdb_printf (fp
, "awatch");
9671 internal_error (_("Invalid watchpoint type."));
9674 gdb_printf (fp
, " %s", exp_string
.get ());
9675 print_recreate_thread (fp
);
9678 /* Implement the "explains_signal" method for watchpoints. */
9681 watchpoint::explains_signal (enum gdb_signal sig
)
9683 /* A software watchpoint cannot cause a signal other than
9685 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9691 struct masked_watchpoint
: public watchpoint
9693 using watchpoint::watchpoint
;
9695 int insert_location (struct bp_location
*) override
;
9696 int remove_location (struct bp_location
*,
9697 enum remove_bp_reason reason
) override
;
9698 int resources_needed (const struct bp_location
*) override
;
9699 bool works_in_software_mode () const override
;
9700 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
9701 void print_one_detail (struct ui_out
*) const override
;
9702 void print_mention () const override
;
9703 void print_recreate (struct ui_file
*fp
) const override
;
9706 /* Implement the "insert" method for masked hardware watchpoints. */
9709 masked_watchpoint::insert_location (struct bp_location
*bl
)
9711 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9712 bl
->watchpoint_type
);
9715 /* Implement the "remove" method for masked hardware watchpoints. */
9718 masked_watchpoint::remove_location (struct bp_location
*bl
,
9719 enum remove_bp_reason reason
)
9721 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9722 bl
->watchpoint_type
);
9725 /* Implement the "resources_needed" method for masked hardware
9729 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9731 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9734 /* Implement the "works_in_software_mode" method for masked hardware
9738 masked_watchpoint::works_in_software_mode () const
9743 /* Implement the "print_it" method for masked hardware
9746 enum print_stop_action
9747 masked_watchpoint::print_it (const bpstat
*bs
) const
9749 struct breakpoint
*b
= bs
->breakpoint_at
;
9750 struct ui_out
*uiout
= current_uiout
;
9752 /* Masked watchpoints have only one location. */
9753 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9755 annotate_watchpoint (b
->number
);
9756 maybe_print_thread_hit_breakpoint (uiout
);
9760 case bp_hardware_watchpoint
:
9761 if (uiout
->is_mi_like_p ())
9763 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9766 case bp_read_watchpoint
:
9767 if (uiout
->is_mi_like_p ())
9769 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9772 case bp_access_watchpoint
:
9773 if (uiout
->is_mi_like_p ())
9776 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9779 internal_error (_("Invalid hardware watchpoint type."));
9784 Check the underlying instruction at PC for the memory\n\
9785 address and value which triggered this watchpoint.\n"));
9788 /* More than one watchpoint may have been triggered. */
9789 return PRINT_UNKNOWN
;
9792 /* Implement the "print_one_detail" method for masked hardware
9796 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9798 /* Masked watchpoints have only one location. */
9799 gdb_assert (loc
&& loc
->next
== NULL
);
9801 uiout
->text ("\tmask ");
9802 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
9806 /* Implement the "print_mention" method for masked hardware
9810 masked_watchpoint::print_mention () const
9812 struct ui_out
*uiout
= current_uiout
;
9813 const char *tuple_name
;
9817 case bp_hardware_watchpoint
:
9818 uiout
->text ("Masked hardware watchpoint ");
9821 case bp_read_watchpoint
:
9822 uiout
->text ("Masked hardware read watchpoint ");
9823 tuple_name
= "hw-rwpt";
9825 case bp_access_watchpoint
:
9826 uiout
->text ("Masked hardware access (read/write) watchpoint ");
9827 tuple_name
= "hw-awpt";
9830 internal_error (_("Invalid hardware watchpoint type."));
9833 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9834 uiout
->field_signed ("number", number
);
9836 uiout
->field_string ("exp", exp_string
.get ());
9839 /* Implement the "print_recreate" method for masked hardware
9843 masked_watchpoint::print_recreate (struct ui_file
*fp
) const
9847 case bp_hardware_watchpoint
:
9848 gdb_printf (fp
, "watch");
9850 case bp_read_watchpoint
:
9851 gdb_printf (fp
, "rwatch");
9853 case bp_access_watchpoint
:
9854 gdb_printf (fp
, "awatch");
9857 internal_error (_("Invalid hardware watchpoint type."));
9860 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
9861 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
9862 print_recreate_thread (fp
);
9865 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9868 is_masked_watchpoint (const struct breakpoint
*b
)
9870 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
9873 /* accessflag: hw_write: watch write,
9874 hw_read: watch read,
9875 hw_access: watch access (read or write) */
9877 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
9878 bool just_location
, bool internal
)
9880 struct breakpoint
*scope_breakpoint
= NULL
;
9881 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9882 struct value
*result
;
9883 int saved_bitpos
= 0, saved_bitsize
= 0;
9884 const char *exp_start
= NULL
;
9885 const char *exp_end
= NULL
;
9886 const char *tok
, *end_tok
;
9888 const char *cond_start
= NULL
;
9889 const char *cond_end
= NULL
;
9890 enum bptype bp_type
;
9892 /* Flag to indicate whether we are going to use masks for
9893 the hardware watchpoint. */
9894 bool use_mask
= false;
9898 /* Make sure that we actually have parameters to parse. */
9899 if (arg
!= NULL
&& arg
[0] != '\0')
9901 const char *value_start
;
9903 exp_end
= arg
+ strlen (arg
);
9905 /* Look for "parameter value" pairs at the end
9906 of the arguments string. */
9907 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
9909 /* Skip whitespace at the end of the argument list. */
9910 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9913 /* Find the beginning of the last token.
9914 This is the value of the parameter. */
9915 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9917 value_start
= tok
+ 1;
9919 /* Skip whitespace. */
9920 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9925 /* Find the beginning of the second to last token.
9926 This is the parameter itself. */
9927 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9930 toklen
= end_tok
- tok
+ 1;
9932 if (toklen
== 6 && startswith (tok
, "thread"))
9934 struct thread_info
*thr
;
9935 /* At this point we've found a "thread" token, which means
9936 the user is trying to set a watchpoint that triggers
9937 only in a specific thread. */
9941 error(_("You can specify only one thread."));
9943 /* Extract the thread ID from the next token. */
9944 thr
= parse_thread_id (value_start
, &endp
);
9946 /* Check if the user provided a valid thread ID. */
9947 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9948 invalid_thread_id_error (value_start
);
9950 thread
= thr
->global_num
;
9952 else if (toklen
== 4 && startswith (tok
, "task"))
9956 task
= strtol (value_start
, &tmp
, 0);
9957 if (tmp
== value_start
)
9958 error (_("Junk after task keyword."));
9959 if (!valid_task_id (task
))
9960 error (_("Unknown task %d."), task
);
9962 else if (toklen
== 4 && startswith (tok
, "mask"))
9964 /* We've found a "mask" token, which means the user wants to
9965 create a hardware watchpoint that is going to have the mask
9967 struct value
*mask_value
;
9970 error(_("You can specify only one mask."));
9972 use_mask
= just_location
= true;
9974 scoped_value_mark mark
;
9975 mask_value
= parse_to_comma_and_eval (&value_start
);
9976 mask
= value_as_address (mask_value
);
9979 /* We didn't recognize what we found. We should stop here. */
9982 /* Truncate the string and get rid of the "parameter value" pair before
9983 the arguments string is parsed by the parse_exp_1 function. */
9990 /* Parse the rest of the arguments. From here on out, everything
9991 is in terms of a newly allocated string instead of the original
9993 std::string
expression (arg
, exp_end
- arg
);
9994 exp_start
= arg
= expression
.c_str ();
9995 innermost_block_tracker tracker
;
9996 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
9998 /* Remove trailing whitespace from the expression before saving it.
9999 This makes the eventual display of the expression string a bit
10001 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10004 /* Checking if the expression is not constant. */
10005 if (watchpoint_exp_is_const (exp
.get ()))
10009 len
= exp_end
- exp_start
;
10010 while (len
> 0 && isspace (exp_start
[len
- 1]))
10012 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10015 exp_valid_block
= tracker
.block ();
10016 struct value
*mark
= value_mark ();
10017 struct value
*val_as_value
= nullptr;
10018 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10021 if (val_as_value
!= NULL
&& just_location
)
10023 saved_bitpos
= value_bitpos (val_as_value
);
10024 saved_bitsize
= value_bitsize (val_as_value
);
10032 exp_valid_block
= NULL
;
10033 val
= release_value (value_addr (result
));
10034 value_free_to_mark (mark
);
10038 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10041 error (_("This target does not support masked watchpoints."));
10042 else if (ret
== -2)
10043 error (_("Invalid mask or memory region."));
10046 else if (val_as_value
!= NULL
)
10047 val
= release_value (val_as_value
);
10049 tok
= skip_spaces (arg
);
10050 end_tok
= skip_to_space (tok
);
10052 toklen
= end_tok
- tok
;
10053 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10055 tok
= cond_start
= end_tok
+ 1;
10056 innermost_block_tracker if_tracker
;
10057 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10059 /* The watchpoint expression may not be local, but the condition
10060 may still be. E.g.: `watch global if local > 0'. */
10061 cond_exp_valid_block
= if_tracker
.block ();
10066 error (_("Junk at end of command."));
10068 frame_info_ptr wp_frame
= block_innermost_frame (exp_valid_block
);
10070 /* Save this because create_internal_breakpoint below invalidates
10072 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10074 /* If the expression is "local", then set up a "watchpoint scope"
10075 breakpoint at the point where we've left the scope of the watchpoint
10076 expression. Create the scope breakpoint before the watchpoint, so
10077 that we will encounter it first in bpstat_stop_status. */
10078 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10080 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10082 if (frame_id_p (caller_frame_id
))
10084 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10085 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10088 = create_internal_breakpoint (caller_arch
, caller_pc
,
10089 bp_watchpoint_scope
);
10091 /* create_internal_breakpoint could invalidate WP_FRAME. */
10094 scope_breakpoint
->enable_state
= bp_enabled
;
10096 /* Automatically delete the breakpoint when it hits. */
10097 scope_breakpoint
->disposition
= disp_del
;
10099 /* Only break in the proper frame (help with recursion). */
10100 scope_breakpoint
->frame_id
= caller_frame_id
;
10102 /* Set the address at which we will stop. */
10103 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10104 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10105 scope_breakpoint
->loc
->address
10106 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10107 scope_breakpoint
->loc
->requested_address
,
10108 scope_breakpoint
->type
,
10109 current_program_space
);
10113 /* Now set up the breakpoint. We create all watchpoints as hardware
10114 watchpoints here even if hardware watchpoints are turned off, a call
10115 to update_watchpoint later in this function will cause the type to
10116 drop back to bp_watchpoint (software watchpoint) if required. */
10118 if (accessflag
== hw_read
)
10119 bp_type
= bp_read_watchpoint
;
10120 else if (accessflag
== hw_access
)
10121 bp_type
= bp_access_watchpoint
;
10123 bp_type
= bp_hardware_watchpoint
;
10125 std::unique_ptr
<watchpoint
> w
;
10127 w
.reset (new masked_watchpoint (nullptr, bp_type
));
10129 w
.reset (new watchpoint (nullptr, bp_type
));
10131 w
->thread
= thread
;
10133 w
->disposition
= disp_donttouch
;
10134 w
->pspace
= current_program_space
;
10135 w
->exp
= std::move (exp
);
10136 w
->exp_valid_block
= exp_valid_block
;
10137 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10140 struct type
*t
= value_type (val
.get ());
10141 CORE_ADDR addr
= value_as_address (val
.get ());
10143 w
->exp_string_reparse
10144 = current_language
->watch_location_expression (t
, addr
);
10146 w
->exp_string
= xstrprintf ("-location %.*s",
10147 (int) (exp_end
- exp_start
), exp_start
);
10150 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10154 w
->hw_wp_mask
= mask
;
10159 w
->val_bitpos
= saved_bitpos
;
10160 w
->val_bitsize
= saved_bitsize
;
10161 w
->val_valid
= true;
10165 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10167 w
->cond_string
= 0;
10169 if (frame_id_p (watchpoint_frame
))
10171 w
->watchpoint_frame
= watchpoint_frame
;
10172 w
->watchpoint_thread
= inferior_ptid
;
10176 w
->watchpoint_frame
= null_frame_id
;
10177 w
->watchpoint_thread
= null_ptid
;
10180 if (scope_breakpoint
!= NULL
)
10182 /* The scope breakpoint is related to the watchpoint. We will
10183 need to act on them together. */
10184 w
->related_breakpoint
= scope_breakpoint
;
10185 scope_breakpoint
->related_breakpoint
= w
.get ();
10188 if (!just_location
)
10189 value_free_to_mark (mark
);
10191 /* Finally update the new watchpoint. This creates the locations
10192 that should be inserted. */
10193 update_watchpoint (w
.get (), 1);
10195 install_breakpoint (internal
, std::move (w
), 1);
10198 /* Return count of debug registers needed to watch the given expression.
10199 If the watchpoint cannot be handled in hardware return zero. */
10202 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10204 int found_memory_cnt
= 0;
10206 /* Did the user specifically forbid us to use hardware watchpoints? */
10207 if (!can_use_hw_watchpoints
)
10210 gdb_assert (!vals
.empty ());
10211 struct value
*head
= vals
[0].get ();
10213 /* Make sure that the value of the expression depends only upon
10214 memory contents, and values computed from them within GDB. If we
10215 find any register references or function calls, we can't use a
10216 hardware watchpoint.
10218 The idea here is that evaluating an expression generates a series
10219 of values, one holding the value of every subexpression. (The
10220 expression a*b+c has five subexpressions: a, b, a*b, c, and
10221 a*b+c.) GDB's values hold almost enough information to establish
10222 the criteria given above --- they identify memory lvalues,
10223 register lvalues, computed values, etcetera. So we can evaluate
10224 the expression, and then scan the chain of values that leaves
10225 behind to decide whether we can detect any possible change to the
10226 expression's final value using only hardware watchpoints.
10228 However, I don't think that the values returned by inferior
10229 function calls are special in any way. So this function may not
10230 notice that an expression involving an inferior function call
10231 can't be watched with hardware watchpoints. FIXME. */
10232 for (const value_ref_ptr
&iter
: vals
)
10234 struct value
*v
= iter
.get ();
10236 if (VALUE_LVAL (v
) == lval_memory
)
10238 if (v
!= head
&& value_lazy (v
))
10239 /* A lazy memory lvalue in the chain is one that GDB never
10240 needed to fetch; we either just used its address (e.g.,
10241 `a' in `a.b') or we never needed it at all (e.g., `a'
10242 in `a,b'). This doesn't apply to HEAD; if that is
10243 lazy then it was not readable, but watch it anyway. */
10247 /* Ahh, memory we actually used! Check if we can cover
10248 it with hardware watchpoints. */
10249 struct type
*vtype
= check_typedef (value_type (v
));
10251 /* We only watch structs and arrays if user asked for it
10252 explicitly, never if they just happen to appear in a
10253 middle of some value chain. */
10255 || (vtype
->code () != TYPE_CODE_STRUCT
10256 && vtype
->code () != TYPE_CODE_ARRAY
))
10258 CORE_ADDR vaddr
= value_address (v
);
10262 len
= (target_exact_watchpoints
10263 && is_scalar_type_recursive (vtype
))?
10264 1 : value_type (v
)->length ();
10266 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10270 found_memory_cnt
+= num_regs
;
10274 else if (VALUE_LVAL (v
) != not_lval
10275 && deprecated_value_modifiable (v
) == 0)
10276 return 0; /* These are values from the history (e.g., $1). */
10277 else if (VALUE_LVAL (v
) == lval_register
)
10278 return 0; /* Cannot watch a register with a HW watchpoint. */
10281 /* The expression itself looks suitable for using a hardware
10282 watchpoint, but give the target machine a chance to reject it. */
10283 return found_memory_cnt
;
10287 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10289 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10292 /* Options for the watch, awatch, and rwatch commands. */
10294 struct watch_options
10296 /* For -location. */
10297 bool location
= false;
10300 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10302 Historically GDB always accepted both '-location' and '-l' flags for
10303 these commands (both flags being synonyms). When converting to the
10304 newer option scheme only '-location' is added here. That's fine (for
10305 backward compatibility) as any non-ambiguous prefix of a flag will be
10306 accepted, so '-l', '-loc', are now all accepted.
10308 What this means is that, if in the future, we add any new flag here
10309 that starts with '-l' then this will break backward compatibility, so
10310 please, don't do that! */
10312 static const gdb::option::option_def watch_option_defs
[] = {
10313 gdb::option::flag_option_def
<watch_options
> {
10315 [] (watch_options
*opt
) { return &opt
->location
; },
10317 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10318 -l can be used as a short form of -location."),
10322 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10325 static gdb::option::option_def_group
10326 make_watch_options_def_group (watch_options
*opts
)
10328 return {{watch_option_defs
}, opts
};
10331 /* A helper function that looks for the "-location" argument and then
10332 calls watch_command_1. */
10335 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10337 watch_options opts
;
10338 auto grp
= make_watch_options_def_group (&opts
);
10339 gdb::option::process_options
10340 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10341 if (arg
!= nullptr && *arg
== '\0')
10344 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10347 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10349 watch_command_completer (struct cmd_list_element
*ignore
,
10350 completion_tracker
&tracker
,
10351 const char *text
, const char * /*word*/)
10353 const auto group
= make_watch_options_def_group (nullptr);
10354 if (gdb::option::complete_options
10355 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10358 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10359 expression_completer (ignore
, tracker
, text
, word
);
10363 watch_command (const char *arg
, int from_tty
)
10365 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10369 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10371 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10375 rwatch_command (const char *arg
, int from_tty
)
10377 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10381 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10383 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10387 awatch_command (const char *arg
, int from_tty
)
10389 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10393 /* Data for the FSM that manages the until(location)/advance commands
10394 in infcmd.c. Here because it uses the mechanisms of
10397 struct until_break_fsm
: public thread_fsm
10399 /* The thread that was current when the command was executed. */
10402 /* The breakpoint set at the return address in the caller frame,
10403 plus breakpoints at all the destination locations. */
10404 std::vector
<breakpoint_up
> breakpoints
;
10406 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10407 std::vector
<breakpoint_up
> &&breakpoints
)
10408 : thread_fsm (cmd_interp
),
10410 breakpoints (std::move (breakpoints
))
10414 void clean_up (struct thread_info
*thread
) override
;
10415 bool should_stop (struct thread_info
*thread
) override
;
10416 enum async_reply_reason
do_async_reply_reason () override
;
10419 /* Implementation of the 'should_stop' FSM method for the
10420 until(location)/advance commands. */
10423 until_break_fsm::should_stop (struct thread_info
*tp
)
10425 for (const breakpoint_up
&bp
: breakpoints
)
10426 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10427 bp
.get ()) != NULL
)
10436 /* Implementation of the 'clean_up' FSM method for the
10437 until(location)/advance commands. */
10440 until_break_fsm::clean_up (struct thread_info
*)
10442 /* Clean up our temporary breakpoints. */
10443 breakpoints
.clear ();
10444 delete_longjmp_breakpoint (thread
);
10447 /* Implementation of the 'async_reply_reason' FSM method for the
10448 until(location)/advance commands. */
10450 enum async_reply_reason
10451 until_break_fsm::do_async_reply_reason ()
10453 return EXEC_ASYNC_LOCATION_REACHED
;
10457 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10459 frame_info_ptr frame
;
10460 struct gdbarch
*frame_gdbarch
;
10461 struct frame_id stack_frame_id
;
10462 struct frame_id caller_frame_id
;
10464 struct thread_info
*tp
;
10466 clear_proceed_status (0);
10468 /* Set a breakpoint where the user wants it and at return from
10471 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
10473 std::vector
<symtab_and_line
> sals
10474 = (last_displayed_sal_is_valid ()
10475 ? decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10476 get_last_displayed_symtab (),
10477 get_last_displayed_line ())
10478 : decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
,
10482 error (_("Couldn't get information on specified line."));
10485 error (_("Junk at end of arguments."));
10487 tp
= inferior_thread ();
10488 thread
= tp
->global_num
;
10490 /* Note linespec handling above invalidates the frame chain.
10491 Installing a breakpoint also invalidates the frame chain (as it
10492 may need to switch threads), so do any frame handling before
10495 frame
= get_selected_frame (NULL
);
10496 frame_gdbarch
= get_frame_arch (frame
);
10497 stack_frame_id
= get_stack_frame_id (frame
);
10498 caller_frame_id
= frame_unwind_caller_id (frame
);
10500 /* Keep within the current frame, or in frames called by the current
10503 std::vector
<breakpoint_up
> breakpoints
;
10505 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10507 if (frame_id_p (caller_frame_id
))
10509 struct symtab_and_line sal2
;
10510 struct gdbarch
*caller_gdbarch
;
10512 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10513 sal2
.pc
= frame_unwind_caller_pc (frame
);
10514 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10516 breakpoint_up caller_breakpoint
10517 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10518 caller_frame_id
, bp_until
);
10519 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10521 set_longjmp_breakpoint (tp
, stack_frame_id
);
10522 lj_deleter
.emplace (thread
);
10525 /* set_momentary_breakpoint could invalidate FRAME. */
10528 /* If the user told us to continue until a specified location, we
10529 don't specify a frame at which we need to stop. Otherwise,
10530 specify the selected frame, because we want to stop only at the
10531 very same frame. */
10532 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10534 for (symtab_and_line
&sal
: sals
)
10536 resolve_sal_pc (&sal
);
10538 breakpoint_up location_breakpoint
10539 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10540 stop_frame_id
, bp_until
);
10541 breakpoints
.emplace_back (std::move (location_breakpoint
));
10545 (std::unique_ptr
<thread_fsm
>
10546 (new until_break_fsm (command_interp (), tp
->global_num
,
10547 std::move (breakpoints
))));
10550 lj_deleter
->release ();
10552 proceed (-1, GDB_SIGNAL_DEFAULT
);
10557 /* Compare two breakpoints and return a strcmp-like result. */
10560 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10562 uintptr_t ua
= (uintptr_t) a
;
10563 uintptr_t ub
= (uintptr_t) b
;
10565 if (a
->number
< b
->number
)
10567 else if (a
->number
> b
->number
)
10570 /* Now sort by address, in case we see, e..g, two breakpoints with
10574 return ua
> ub
? 1 : 0;
10577 /* Delete breakpoints by address or line. */
10580 clear_command (const char *arg
, int from_tty
)
10584 std::vector
<symtab_and_line
> decoded_sals
;
10585 symtab_and_line last_sal
;
10586 gdb::array_view
<symtab_and_line
> sals
;
10590 = decode_line_with_current_source (arg
,
10591 (DECODE_LINE_FUNFIRSTLINE
10592 | DECODE_LINE_LIST_MODE
));
10594 sals
= decoded_sals
;
10598 /* Set sal's line, symtab, pc, and pspace to the values
10599 corresponding to the last call to print_frame_info. If the
10600 codepoint is not valid, this will set all the fields to 0. */
10601 last_sal
= get_last_displayed_sal ();
10602 if (last_sal
.symtab
== 0)
10603 error (_("No source file specified."));
10609 /* We don't call resolve_sal_pc here. That's not as bad as it
10610 seems, because all existing breakpoints typically have both
10611 file/line and pc set. So, if clear is given file/line, we can
10612 match this to existing breakpoint without obtaining pc at all.
10614 We only support clearing given the address explicitly
10615 present in breakpoint table. Say, we've set breakpoint
10616 at file:line. There were several PC values for that file:line,
10617 due to optimization, all in one block.
10619 We've picked one PC value. If "clear" is issued with another
10620 PC corresponding to the same file:line, the breakpoint won't
10621 be cleared. We probably can still clear the breakpoint, but
10622 since the other PC value is never presented to user, user
10623 can only find it by guessing, and it does not seem important
10624 to support that. */
10626 /* For each line spec given, delete bps which correspond to it. Do
10627 it in two passes, solely to preserve the current behavior that
10628 from_tty is forced true if we delete more than one
10631 std::vector
<struct breakpoint
*> found
;
10632 for (const auto &sal
: sals
)
10634 const char *sal_fullname
;
10636 /* If exact pc given, clear bpts at that pc.
10637 If line given (pc == 0), clear all bpts on specified line.
10638 If defaulting, clear all bpts on default line
10641 defaulting sal.pc != 0 tests to do
10646 1 0 <can't happen> */
10648 sal_fullname
= (sal
.symtab
== NULL
10649 ? NULL
: symtab_to_fullname (sal
.symtab
));
10651 /* Find all matching breakpoints and add them to 'found'. */
10652 for (breakpoint
*b
: all_breakpoints ())
10655 /* Are we going to delete b? */
10656 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10657 && user_breakpoint_p (b
))
10659 for (bp_location
*loc
: b
->locations ())
10661 /* If the user specified file:line, don't allow a PC
10662 match. This matches historical gdb behavior. */
10663 int pc_match
= (!sal
.explicit_line
10665 && (loc
->pspace
== sal
.pspace
)
10666 && (loc
->address
== sal
.pc
)
10667 && (!section_is_overlay (loc
->section
)
10668 || loc
->section
== sal
.section
));
10669 int line_match
= 0;
10671 if ((default_match
|| sal
.explicit_line
)
10672 && loc
->symtab
!= NULL
10673 && sal_fullname
!= NULL
10674 && sal
.pspace
== loc
->pspace
10675 && loc
->line_number
== sal
.line
10676 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10677 sal_fullname
) == 0)
10680 if (pc_match
|| line_match
)
10689 found
.push_back (b
);
10693 /* Now go thru the 'found' chain and delete them. */
10694 if (found
.empty ())
10697 error (_("No breakpoint at %s."), arg
);
10699 error (_("No breakpoint at this line."));
10702 /* Remove duplicates from the vec. */
10703 std::sort (found
.begin (), found
.end (),
10704 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10706 return compare_breakpoints (bp_a
, bp_b
) < 0;
10708 found
.erase (std::unique (found
.begin (), found
.end (),
10709 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10711 return compare_breakpoints (bp_a
, bp_b
) == 0;
10715 if (found
.size () > 1)
10716 from_tty
= 1; /* Always report if deleted more than one. */
10719 if (found
.size () == 1)
10720 gdb_printf (_("Deleted breakpoint "));
10722 gdb_printf (_("Deleted breakpoints "));
10725 for (breakpoint
*iter
: found
)
10728 gdb_printf ("%d ", iter
->number
);
10729 delete_breakpoint (iter
);
10735 /* Delete breakpoint in BS if they are `delete' breakpoints and
10736 all breakpoints that are marked for deletion, whether hit or not.
10737 This is called after any breakpoint is hit, or after errors. */
10740 breakpoint_auto_delete (bpstat
*bs
)
10742 for (; bs
; bs
= bs
->next
)
10743 if (bs
->breakpoint_at
10744 && bs
->breakpoint_at
->disposition
== disp_del
10746 delete_breakpoint (bs
->breakpoint_at
);
10748 for (breakpoint
*b
: all_breakpoints_safe ())
10749 if (b
->disposition
== disp_del_at_next_stop
)
10750 delete_breakpoint (b
);
10753 /* A comparison function for bp_location AP and BP being interfaced to
10754 std::sort. Sort elements primarily by their ADDRESS (no matter what
10755 bl_address_is_meaningful says), secondarily by ordering first
10756 permanent elements and terciarily just ensuring the array is sorted
10757 stable way despite std::sort being an unstable algorithm. */
10760 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10762 if (a
->address
!= b
->address
)
10763 return a
->address
< b
->address
;
10765 /* Sort locations at the same address by their pspace number, keeping
10766 locations of the same inferior (in a multi-inferior environment)
10769 if (a
->pspace
->num
!= b
->pspace
->num
)
10770 return a
->pspace
->num
< b
->pspace
->num
;
10772 /* Sort permanent breakpoints first. */
10773 if (a
->permanent
!= b
->permanent
)
10774 return a
->permanent
> b
->permanent
;
10776 /* Sort by type in order to make duplicate determination easier.
10777 See update_global_location_list. This is kept in sync with
10778 breakpoint_locations_match. */
10779 if (a
->loc_type
< b
->loc_type
)
10782 /* Likewise, for range-breakpoints, sort by length. */
10783 if (a
->loc_type
== bp_loc_hardware_breakpoint
10784 && b
->loc_type
== bp_loc_hardware_breakpoint
10785 && a
->length
< b
->length
)
10788 /* Make the internal GDB representation stable across GDB runs
10789 where A and B memory inside GDB can differ. Breakpoint locations of
10790 the same type at the same address can be sorted in arbitrary order. */
10792 if (a
->owner
->number
!= b
->owner
->number
)
10793 return a
->owner
->number
< b
->owner
->number
;
10798 /* Set bp_locations_placed_address_before_address_max and
10799 bp_locations_shadow_len_after_address_max according to the current
10800 content of the bp_locations array. */
10803 bp_locations_target_extensions_update (void)
10805 bp_locations_placed_address_before_address_max
= 0;
10806 bp_locations_shadow_len_after_address_max
= 0;
10808 for (bp_location
*bl
: all_bp_locations ())
10810 CORE_ADDR start
, end
, addr
;
10812 if (!bp_location_has_shadow (bl
))
10815 start
= bl
->target_info
.placed_address
;
10816 end
= start
+ bl
->target_info
.shadow_len
;
10818 gdb_assert (bl
->address
>= start
);
10819 addr
= bl
->address
- start
;
10820 if (addr
> bp_locations_placed_address_before_address_max
)
10821 bp_locations_placed_address_before_address_max
= addr
;
10823 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10825 gdb_assert (bl
->address
< end
);
10826 addr
= end
- bl
->address
;
10827 if (addr
> bp_locations_shadow_len_after_address_max
)
10828 bp_locations_shadow_len_after_address_max
= addr
;
10832 /* Download tracepoint locations if they haven't been. */
10835 download_tracepoint_locations (void)
10837 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
10839 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
10841 for (breakpoint
*b
: all_tracepoints ())
10843 struct tracepoint
*t
;
10844 int bp_location_downloaded
= 0;
10846 if ((b
->type
== bp_fast_tracepoint
10847 ? !may_insert_fast_tracepoints
10848 : !may_insert_tracepoints
))
10851 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
10853 if (target_can_download_tracepoint ())
10854 can_download_tracepoint
= TRIBOOL_TRUE
;
10856 can_download_tracepoint
= TRIBOOL_FALSE
;
10859 if (can_download_tracepoint
== TRIBOOL_FALSE
)
10862 for (bp_location
*bl
: b
->locations ())
10864 /* In tracepoint, locations are _never_ duplicated, so
10865 should_be_inserted is equivalent to
10866 unduplicated_should_be_inserted. */
10867 if (!should_be_inserted (bl
) || bl
->inserted
)
10870 switch_to_program_space_and_thread (bl
->pspace
);
10872 target_download_tracepoint (bl
);
10875 bp_location_downloaded
= 1;
10877 t
= (struct tracepoint
*) b
;
10878 t
->number_on_target
= b
->number
;
10879 if (bp_location_downloaded
)
10880 gdb::observers::breakpoint_modified
.notify (b
);
10884 /* Swap the insertion/duplication state between two locations. */
10887 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10889 const int left_inserted
= left
->inserted
;
10890 const int left_duplicate
= left
->duplicate
;
10891 const int left_needs_update
= left
->needs_update
;
10892 const struct bp_target_info left_target_info
= left
->target_info
;
10894 /* Locations of tracepoints can never be duplicated. */
10895 if (is_tracepoint (left
->owner
))
10896 gdb_assert (!left
->duplicate
);
10897 if (is_tracepoint (right
->owner
))
10898 gdb_assert (!right
->duplicate
);
10900 left
->inserted
= right
->inserted
;
10901 left
->duplicate
= right
->duplicate
;
10902 left
->needs_update
= right
->needs_update
;
10903 left
->target_info
= right
->target_info
;
10904 right
->inserted
= left_inserted
;
10905 right
->duplicate
= left_duplicate
;
10906 right
->needs_update
= left_needs_update
;
10907 right
->target_info
= left_target_info
;
10910 /* Force the re-insertion of the locations at ADDRESS. This is called
10911 once a new/deleted/modified duplicate location is found and we are evaluating
10912 conditions on the target's side. Such conditions need to be updated on
10916 force_breakpoint_reinsertion (struct bp_location
*bl
)
10918 CORE_ADDR address
= 0;
10921 address
= bl
->address
;
10922 pspace_num
= bl
->pspace
->num
;
10924 /* This is only meaningful if the target is
10925 evaluating conditions and if the user has
10926 opted for condition evaluation on the target's
10928 if (gdb_evaluates_breakpoint_condition_p ()
10929 || !target_supports_evaluation_of_breakpoint_conditions ())
10932 /* Flag all breakpoint locations with this address and
10933 the same program space as the location
10934 as "its condition has changed". We need to
10935 update the conditions on the target's side. */
10936 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
10938 if (!is_breakpoint (loc
->owner
)
10939 || pspace_num
!= loc
->pspace
->num
)
10942 /* Flag the location appropriately. We use a different state to
10943 let everyone know that we already updated the set of locations
10944 with addr bl->address and program space bl->pspace. This is so
10945 we don't have to keep calling these functions just to mark locations
10946 that have already been marked. */
10947 loc
->condition_changed
= condition_updated
;
10949 /* Free the agent expression bytecode as well. We will compute
10951 loc
->cond_bytecode
.reset ();
10955 /* Called whether new breakpoints are created, or existing breakpoints
10956 deleted, to update the global location list and recompute which
10957 locations are duplicate of which.
10959 The INSERT_MODE flag determines whether locations may not, may, or
10960 shall be inserted now. See 'enum ugll_insert_mode' for more
10964 update_global_location_list (enum ugll_insert_mode insert_mode
)
10966 /* Last breakpoint location address that was marked for update. */
10967 CORE_ADDR last_addr
= 0;
10968 /* Last breakpoint location program space that was marked for update. */
10969 int last_pspace_num
= -1;
10971 /* Used in the duplicates detection below. When iterating over all
10972 bp_locations, points to the first bp_location of a given address.
10973 Breakpoints and watchpoints of different types are never
10974 duplicates of each other. Keep one pointer for each type of
10975 breakpoint/watchpoint, so we only need to loop over all locations
10977 struct bp_location
*bp_loc_first
; /* breakpoint */
10978 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10979 struct bp_location
*awp_loc_first
; /* access watchpoint */
10980 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10982 /* Saved former bp_locations array which we compare against the newly
10983 built bp_locations from the current state of ALL_BREAKPOINTS. */
10984 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
10985 bp_locations
.clear ();
10987 for (breakpoint
*b
: all_breakpoints ())
10988 for (bp_location
*loc
: b
->locations ())
10989 bp_locations
.push_back (loc
);
10991 /* See if we need to "upgrade" a software breakpoint to a hardware
10992 breakpoint. Do this before deciding whether locations are
10993 duplicates. Also do this before sorting because sorting order
10994 depends on location type. */
10995 for (bp_location
*loc
: bp_locations
)
10996 if (!loc
->inserted
&& should_be_inserted (loc
))
10997 handle_automatic_hardware_breakpoints (loc
);
10999 std::sort (bp_locations
.begin (), bp_locations
.end (),
11000 bp_location_is_less_than
);
11002 bp_locations_target_extensions_update ();
11004 /* Identify bp_location instances that are no longer present in the
11005 new list, and therefore should be freed. Note that it's not
11006 necessary that those locations should be removed from inferior --
11007 if there's another location at the same address (previously
11008 marked as duplicate), we don't need to remove/insert the
11011 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11012 and former bp_location array state respectively. */
11015 for (bp_location
*old_loc
: old_locations
)
11017 /* Tells if 'old_loc' is found among the new locations. If
11018 not, we have to free it. */
11019 int found_object
= 0;
11020 /* Tells if the location should remain inserted in the target. */
11021 int keep_in_target
= 0;
11024 /* Skip LOCP entries which will definitely never be needed.
11025 Stop either at or being the one matching OLD_LOC. */
11026 while (loc_i
< bp_locations
.size ()
11027 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11030 for (size_t loc2_i
= loc_i
;
11031 (loc2_i
< bp_locations
.size ()
11032 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11035 /* Check if this is a new/duplicated location or a duplicated
11036 location that had its condition modified. If so, we want to send
11037 its condition to the target if evaluation of conditions is taking
11039 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11040 && (last_addr
!= old_loc
->address
11041 || last_pspace_num
!= old_loc
->pspace
->num
))
11043 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11044 last_pspace_num
= old_loc
->pspace
->num
;
11047 if (bp_locations
[loc2_i
] == old_loc
)
11051 /* We have already handled this address, update it so that we don't
11052 have to go through updates again. */
11053 last_addr
= old_loc
->address
;
11055 /* Target-side condition evaluation: Handle deleted locations. */
11057 force_breakpoint_reinsertion (old_loc
);
11059 /* If this location is no longer present, and inserted, look if
11060 there's maybe a new location at the same address. If so,
11061 mark that one inserted, and don't remove this one. This is
11062 needed so that we don't have a time window where a breakpoint
11063 at certain location is not inserted. */
11065 if (old_loc
->inserted
)
11067 /* If the location is inserted now, we might have to remove
11070 if (found_object
&& should_be_inserted (old_loc
))
11072 /* The location is still present in the location list,
11073 and still should be inserted. Don't do anything. */
11074 keep_in_target
= 1;
11078 /* This location still exists, but it won't be kept in the
11079 target since it may have been disabled. We proceed to
11080 remove its target-side condition. */
11082 /* The location is either no longer present, or got
11083 disabled. See if there's another location at the
11084 same address, in which case we don't need to remove
11085 this one from the target. */
11087 /* OLD_LOC comes from existing struct breakpoint. */
11088 if (bl_address_is_meaningful (old_loc
))
11090 for (size_t loc2_i
= loc_i
;
11091 (loc2_i
< bp_locations
.size ()
11092 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11095 bp_location
*loc2
= bp_locations
[loc2_i
];
11097 if (loc2
== old_loc
)
11100 if (breakpoint_locations_match (loc2
, old_loc
))
11102 /* Read watchpoint locations are switched to
11103 access watchpoints, if the former are not
11104 supported, but the latter are. */
11105 if (is_hardware_watchpoint (old_loc
->owner
))
11107 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11108 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11111 /* loc2 is a duplicated location. We need to check
11112 if it should be inserted in case it will be
11114 if (unduplicated_should_be_inserted (loc2
))
11116 swap_insertion (old_loc
, loc2
);
11117 keep_in_target
= 1;
11125 if (!keep_in_target
)
11127 if (remove_breakpoint (old_loc
))
11129 /* This is just about all we can do. We could keep
11130 this location on the global list, and try to
11131 remove it next time, but there's no particular
11132 reason why we will succeed next time.
11134 Note that at this point, old_loc->owner is still
11135 valid, as delete_breakpoint frees the breakpoint
11136 only after calling us. */
11137 gdb_printf (_("warning: Error removing "
11138 "breakpoint %d\n"),
11139 old_loc
->owner
->number
);
11147 if (removed
&& target_is_non_stop_p ()
11148 && need_moribund_for_location_type (old_loc
))
11150 /* This location was removed from the target. In
11151 non-stop mode, a race condition is possible where
11152 we've removed a breakpoint, but stop events for that
11153 breakpoint are already queued and will arrive later.
11154 We apply an heuristic to be able to distinguish such
11155 SIGTRAPs from other random SIGTRAPs: we keep this
11156 breakpoint location for a bit, and will retire it
11157 after we see some number of events. The theory here
11158 is that reporting of events should, "on the average",
11159 be fair, so after a while we'll see events from all
11160 threads that have anything of interest, and no longer
11161 need to keep this breakpoint location around. We
11162 don't hold locations forever so to reduce chances of
11163 mistaking a non-breakpoint SIGTRAP for a breakpoint
11166 The heuristic failing can be disastrous on
11167 decr_pc_after_break targets.
11169 On decr_pc_after_break targets, like e.g., x86-linux,
11170 if we fail to recognize a late breakpoint SIGTRAP,
11171 because events_till_retirement has reached 0 too
11172 soon, we'll fail to do the PC adjustment, and report
11173 a random SIGTRAP to the user. When the user resumes
11174 the inferior, it will most likely immediately crash
11175 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11176 corrupted, because of being resumed e.g., in the
11177 middle of a multi-byte instruction, or skipped a
11178 one-byte instruction. This was actually seen happen
11179 on native x86-linux, and should be less rare on
11180 targets that do not support new thread events, like
11181 remote, due to the heuristic depending on
11184 Mistaking a random SIGTRAP for a breakpoint trap
11185 causes similar symptoms (PC adjustment applied when
11186 it shouldn't), but then again, playing with SIGTRAPs
11187 behind the debugger's back is asking for trouble.
11189 Since hardware watchpoint traps are always
11190 distinguishable from other traps, so we don't need to
11191 apply keep hardware watchpoint moribund locations
11192 around. We simply always ignore hardware watchpoint
11193 traps we can no longer explain. */
11195 process_stratum_target
*proc_target
= nullptr;
11196 for (inferior
*inf
: all_inferiors ())
11197 if (inf
->pspace
== old_loc
->pspace
)
11199 proc_target
= inf
->process_target ();
11202 if (proc_target
!= nullptr)
11203 old_loc
->events_till_retirement
11204 = 3 * (thread_count (proc_target
) + 1);
11206 old_loc
->events_till_retirement
= 1;
11207 old_loc
->owner
= NULL
;
11209 moribund_locations
.push_back (old_loc
);
11213 old_loc
->owner
= NULL
;
11214 decref_bp_location (&old_loc
);
11219 /* Rescan breakpoints at the same address and section, marking the
11220 first one as "first" and any others as "duplicates". This is so
11221 that the bpt instruction is only inserted once. If we have a
11222 permanent breakpoint at the same place as BPT, make that one the
11223 official one, and the rest as duplicates. Permanent breakpoints
11224 are sorted first for the same address.
11226 Do the same for hardware watchpoints, but also considering the
11227 watchpoint's type (regular/access/read) and length. */
11229 bp_loc_first
= NULL
;
11230 wp_loc_first
= NULL
;
11231 awp_loc_first
= NULL
;
11232 rwp_loc_first
= NULL
;
11234 for (bp_location
*loc
: all_bp_locations ())
11236 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11238 struct bp_location
**loc_first_p
;
11239 breakpoint
*b
= loc
->owner
;
11241 if (!unduplicated_should_be_inserted (loc
)
11242 || !bl_address_is_meaningful (loc
)
11243 /* Don't detect duplicate for tracepoint locations because they are
11244 never duplicated. See the comments in field `duplicate' of
11245 `struct bp_location'. */
11246 || is_tracepoint (b
))
11248 /* Clear the condition modification flag. */
11249 loc
->condition_changed
= condition_unchanged
;
11253 if (b
->type
== bp_hardware_watchpoint
)
11254 loc_first_p
= &wp_loc_first
;
11255 else if (b
->type
== bp_read_watchpoint
)
11256 loc_first_p
= &rwp_loc_first
;
11257 else if (b
->type
== bp_access_watchpoint
)
11258 loc_first_p
= &awp_loc_first
;
11260 loc_first_p
= &bp_loc_first
;
11262 if (*loc_first_p
== NULL
11263 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11264 || !breakpoint_locations_match (loc
, *loc_first_p
))
11266 *loc_first_p
= loc
;
11267 loc
->duplicate
= 0;
11269 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11271 loc
->needs_update
= 1;
11272 /* Clear the condition modification flag. */
11273 loc
->condition_changed
= condition_unchanged
;
11279 /* This and the above ensure the invariant that the first location
11280 is not duplicated, and is the inserted one.
11281 All following are marked as duplicated, and are not inserted. */
11283 swap_insertion (loc
, *loc_first_p
);
11284 loc
->duplicate
= 1;
11286 /* Clear the condition modification flag. */
11287 loc
->condition_changed
= condition_unchanged
;
11290 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11292 if (insert_mode
!= UGLL_DONT_INSERT
)
11293 insert_breakpoint_locations ();
11296 /* Even though the caller told us to not insert new
11297 locations, we may still need to update conditions on the
11298 target's side of breakpoints that were already inserted
11299 if the target is evaluating breakpoint conditions. We
11300 only update conditions for locations that are marked
11302 update_inserted_breakpoint_locations ();
11306 if (insert_mode
!= UGLL_DONT_INSERT
)
11307 download_tracepoint_locations ();
11311 breakpoint_retire_moribund (void)
11313 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11315 struct bp_location
*loc
= moribund_locations
[ix
];
11316 if (--(loc
->events_till_retirement
) == 0)
11318 decref_bp_location (&loc
);
11319 unordered_remove (moribund_locations
, ix
);
11326 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11331 update_global_location_list (insert_mode
);
11333 catch (const gdb_exception_error
&e
)
11338 /* Clear BKP from a BPS. */
11341 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11345 for (bs
= bps
; bs
; bs
= bs
->next
)
11346 if (bs
->breakpoint_at
== bpt
)
11348 bs
->breakpoint_at
= NULL
;
11349 bs
->old_val
= NULL
;
11350 /* bs->commands will be freed later. */
11354 /* Callback for iterate_over_threads. */
11356 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11358 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11360 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11364 /* Helper for breakpoint and tracepoint breakpoint->mention
11368 say_where (const breakpoint
*b
)
11370 struct value_print_options opts
;
11372 get_user_print_options (&opts
);
11374 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11376 if (b
->loc
== NULL
)
11378 /* For pending locations, the output differs slightly based
11379 on b->extra_string. If this is non-NULL, it contains either
11380 a condition or dprintf arguments. */
11381 if (b
->extra_string
== NULL
)
11383 gdb_printf (_(" (%s) pending."), b
->locspec
->to_string ());
11385 else if (b
->type
== bp_dprintf
)
11387 gdb_printf (_(" (%s,%s) pending."),
11388 b
->locspec
->to_string (),
11389 b
->extra_string
.get ());
11393 gdb_printf (_(" (%s %s) pending."),
11394 b
->locspec
->to_string (),
11395 b
->extra_string
.get ());
11400 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
11401 gdb_printf (" at %ps",
11402 styled_string (address_style
.style (),
11403 paddress (b
->loc
->gdbarch
,
11404 b
->loc
->address
)));
11405 if (b
->loc
->symtab
!= NULL
)
11407 /* If there is a single location, we can print the location
11409 if (b
->loc
->next
== NULL
)
11411 const char *filename
11412 = symtab_to_filename_for_display (b
->loc
->symtab
);
11413 gdb_printf (": file %ps, line %d.",
11414 styled_string (file_name_style
.style (),
11416 b
->loc
->line_number
);
11419 /* This is not ideal, but each location may have a
11420 different file name, and this at least reflects the
11421 real situation somewhat. */
11422 gdb_printf (": %s.", b
->locspec
->to_string ());
11427 struct bp_location
*loc
= b
->loc
;
11429 for (; loc
; loc
= loc
->next
)
11431 gdb_printf (" (%d locations)", n
);
11436 /* See breakpoint.h. */
11438 bp_location_range
breakpoint::locations () const
11440 return bp_location_range (this->loc
);
11443 struct bp_location
*
11444 breakpoint::allocate_location ()
11446 return new bp_location (this);
11449 #define internal_error_pure_virtual_called() \
11450 gdb_assert_not_reached ("pure virtual function called")
11453 breakpoint::insert_location (struct bp_location
*bl
)
11455 internal_error_pure_virtual_called ();
11459 breakpoint::remove_location (struct bp_location
*bl
,
11460 enum remove_bp_reason reason
)
11462 internal_error_pure_virtual_called ();
11466 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11467 const address_space
*aspace
,
11469 const target_waitstatus
&ws
)
11471 internal_error_pure_virtual_called ();
11475 breakpoint::resources_needed (const struct bp_location
*bl
)
11477 internal_error_pure_virtual_called ();
11480 enum print_stop_action
11481 breakpoint::print_it (const bpstat
*bs
) const
11483 internal_error_pure_virtual_called ();
11487 breakpoint::print_mention () const
11489 internal_error_pure_virtual_called ();
11493 breakpoint::print_recreate (struct ui_file
*fp
) const
11495 internal_error_pure_virtual_called ();
11498 /* Default breakpoint_ops methods. */
11501 code_breakpoint::re_set ()
11503 /* FIXME: is this still reachable? */
11504 if (breakpoint_location_spec_empty_p (this))
11506 /* Anything without a location can't be re-set. */
11507 delete_breakpoint (this);
11515 code_breakpoint::insert_location (struct bp_location
*bl
)
11517 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11519 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11520 bl
->target_info
.placed_address
= addr
;
11523 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11524 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11526 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11528 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11530 /* The insertion was successful, now let's set the probe's semaphore
11532 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11539 code_breakpoint::remove_location (struct bp_location
*bl
,
11540 enum remove_bp_reason reason
)
11542 if (bl
->probe
.prob
!= nullptr)
11544 /* Let's clear the semaphore before removing the location. */
11545 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11548 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11549 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11551 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11555 code_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11556 const address_space
*aspace
,
11558 const target_waitstatus
&ws
)
11560 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11561 || ws
.sig () != GDB_SIGNAL_TRAP
)
11564 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11568 if (overlay_debugging
/* unmapped overlay section */
11569 && section_is_overlay (bl
->section
)
11570 && !section_is_mapped (bl
->section
))
11577 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11578 const address_space
*aspace
,
11580 const target_waitstatus
&ws
)
11582 if (dprintf_style
== dprintf_style_agent
11583 && target_can_run_breakpoint_commands ())
11585 /* An agent-style dprintf never causes a stop. If we see a trap
11586 for this address it must be for a breakpoint that happens to
11587 be set at the same address. */
11591 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11595 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
11597 gdb_assert (type
== bp_hardware_breakpoint
);
11602 enum print_stop_action
11603 ordinary_breakpoint::print_it (const bpstat
*bs
) const
11605 const struct bp_location
*bl
;
11607 struct ui_out
*uiout
= current_uiout
;
11609 bl
= bs
->bp_location_at
.get ();
11611 bp_temp
= disposition
== disp_del
;
11612 if (bl
->address
!= bl
->requested_address
)
11613 breakpoint_adjustment_warning (bl
->requested_address
,
11616 annotate_breakpoint (number
);
11617 maybe_print_thread_hit_breakpoint (uiout
);
11619 if (uiout
->is_mi_like_p ())
11621 uiout
->field_string ("reason",
11622 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11623 uiout
->field_string ("disp", bpdisp_text (disposition
));
11626 uiout
->message ("Temporary breakpoint %pF, ",
11627 signed_field ("bkptno", number
));
11629 uiout
->message ("Breakpoint %pF, ",
11630 signed_field ("bkptno", number
));
11632 return PRINT_SRC_AND_LOC
;
11636 ordinary_breakpoint::print_mention () const
11638 if (current_uiout
->is_mi_like_p ())
11643 case bp_breakpoint
:
11644 case bp_gnu_ifunc_resolver
:
11645 if (disposition
== disp_del
)
11646 gdb_printf (_("Temporary breakpoint"));
11648 gdb_printf (_("Breakpoint"));
11649 gdb_printf (_(" %d"), number
);
11650 if (type
== bp_gnu_ifunc_resolver
)
11651 gdb_printf (_(" at gnu-indirect-function resolver"));
11653 case bp_hardware_breakpoint
:
11654 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
11657 gdb_printf (_("Dprintf %d"), number
);
11665 ordinary_breakpoint::print_recreate (struct ui_file
*fp
) const
11667 if (type
== bp_breakpoint
&& disposition
== disp_del
)
11668 gdb_printf (fp
, "tbreak");
11669 else if (type
== bp_breakpoint
)
11670 gdb_printf (fp
, "break");
11671 else if (type
== bp_hardware_breakpoint
11672 && disposition
== disp_del
)
11673 gdb_printf (fp
, "thbreak");
11674 else if (type
== bp_hardware_breakpoint
)
11675 gdb_printf (fp
, "hbreak");
11677 internal_error (_("unhandled breakpoint type %d"), (int) type
);
11679 gdb_printf (fp
, " %s", locspec
->to_string ());
11681 /* Print out extra_string if this breakpoint is pending. It might
11682 contain, for example, conditions that were set by the user. */
11683 if (loc
== NULL
&& extra_string
!= NULL
)
11684 gdb_printf (fp
, " %s", extra_string
.get ());
11686 print_recreate_thread (fp
);
11689 std::vector
<symtab_and_line
>
11690 code_breakpoint::decode_location_spec (location_spec
*locspec
,
11691 program_space
*search_pspace
)
11693 if (locspec
->type () == PROBE_LOCATION_SPEC
)
11694 return bkpt_probe_decode_location_spec (this, locspec
, search_pspace
);
11696 struct linespec_result canonical
;
11698 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
11699 NULL
, 0, &canonical
, multiple_symbols_all
,
11702 /* We should get 0 or 1 resulting SALs. */
11703 gdb_assert (canonical
.lsals
.size () < 2);
11705 if (!canonical
.lsals
.empty ())
11707 const linespec_sals
&lsal
= canonical
.lsals
[0];
11708 return std::move (lsal
.sals
);
11713 /* Virtual table for internal breakpoints. */
11716 internal_breakpoint::re_set ()
11720 /* Delete overlay event and longjmp master breakpoints; they
11721 will be reset later by breakpoint_re_set. */
11722 case bp_overlay_event
:
11723 case bp_longjmp_master
:
11724 case bp_std_terminate_master
:
11725 case bp_exception_master
:
11726 delete_breakpoint (this);
11729 /* This breakpoint is special, it's set up when the inferior
11730 starts and we really don't want to touch it. */
11731 case bp_shlib_event
:
11733 /* Like bp_shlib_event, this breakpoint type is special. Once
11734 it is set up, we do not want to touch it. */
11735 case bp_thread_event
:
11741 internal_breakpoint::check_status (bpstat
*bs
)
11743 if (type
== bp_shlib_event
)
11745 /* If requested, stop when the dynamic linker notifies GDB of
11746 events. This allows the user to get control and place
11747 breakpoints in initializer routines for dynamically loaded
11748 objects (among other things). */
11749 bs
->stop
= stop_on_solib_events
;
11750 bs
->print
= stop_on_solib_events
;
11756 enum print_stop_action
11757 internal_breakpoint::print_it (const bpstat
*bs
) const
11761 case bp_shlib_event
:
11762 /* Did we stop because the user set the stop_on_solib_events
11763 variable? (If so, we report this as a generic, "Stopped due
11764 to shlib event" message.) */
11765 print_solib_event (false);
11768 case bp_thread_event
:
11769 /* Not sure how we will get here.
11770 GDB should not stop for these breakpoints. */
11771 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
11774 case bp_overlay_event
:
11775 /* By analogy with the thread event, GDB should not stop for these. */
11776 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11779 case bp_longjmp_master
:
11780 /* These should never be enabled. */
11781 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11784 case bp_std_terminate_master
:
11785 /* These should never be enabled. */
11786 gdb_printf (_("std::terminate Master Breakpoint: "
11787 "gdb should not stop!\n"));
11790 case bp_exception_master
:
11791 /* These should never be enabled. */
11792 gdb_printf (_("Exception Master Breakpoint: "
11793 "gdb should not stop!\n"));
11797 return PRINT_NOTHING
;
11801 internal_breakpoint::print_mention () const
11803 /* Nothing to mention. These breakpoints are internal. */
11806 /* Virtual table for momentary breakpoints */
11809 momentary_breakpoint::re_set ()
11811 /* Keep temporary breakpoints, which can be encountered when we step
11812 over a dlopen call and solib_add is resetting the breakpoints.
11813 Otherwise these should have been blown away via the cleanup chain
11814 or by breakpoint_init_inferior when we rerun the executable. */
11818 momentary_breakpoint::check_status (bpstat
*bs
)
11820 /* Nothing. The point of these breakpoints is causing a stop. */
11823 enum print_stop_action
11824 momentary_breakpoint::print_it (const bpstat
*bs
) const
11826 return PRINT_UNKNOWN
;
11830 momentary_breakpoint::print_mention () const
11832 /* Nothing to mention. These breakpoints are internal. */
11835 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
11837 It gets cleared already on the removal of the first one of such placed
11838 breakpoints. This is OK as they get all removed altogether. */
11840 longjmp_breakpoint::~longjmp_breakpoint ()
11842 thread_info
*tp
= find_thread_global_id (this->thread
);
11845 tp
->initiating_frame
= null_frame_id
;
11849 bkpt_probe_create_sals_from_location_spec (location_spec
*locspec
,
11850 struct linespec_result
*canonical
)
11853 struct linespec_sals lsal
;
11855 lsal
.sals
= parse_probes (locspec
, NULL
, canonical
);
11856 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
11857 canonical
->lsals
.push_back (std::move (lsal
));
11860 static std::vector
<symtab_and_line
>
11861 bkpt_probe_decode_location_spec (struct breakpoint
*b
,
11862 location_spec
*locspec
,
11863 program_space
*search_pspace
)
11865 std::vector
<symtab_and_line
> sals
11866 = parse_probes (locspec
, search_pspace
, NULL
);
11868 error (_("probe not found"));
11873 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
11874 const address_space
*aspace
, CORE_ADDR bp_addr
,
11875 const target_waitstatus
&ws
)
11877 /* By definition, the inferior does not report stops at
11883 tracepoint::print_one_detail (struct ui_out
*uiout
) const
11885 if (!static_trace_marker_id
.empty ())
11887 gdb_assert (type
== bp_static_tracepoint
11888 || type
== bp_static_marker_tracepoint
);
11890 uiout
->message ("\tmarker id is %pF\n",
11891 string_field ("static-tracepoint-marker-string-id",
11892 static_trace_marker_id
.c_str ()));
11897 tracepoint::print_mention () const
11899 if (current_uiout
->is_mi_like_p ())
11904 case bp_tracepoint
:
11905 gdb_printf (_("Tracepoint"));
11906 gdb_printf (_(" %d"), number
);
11908 case bp_fast_tracepoint
:
11909 gdb_printf (_("Fast tracepoint"));
11910 gdb_printf (_(" %d"), number
);
11912 case bp_static_tracepoint
:
11913 case bp_static_marker_tracepoint
:
11914 gdb_printf (_("Static tracepoint"));
11915 gdb_printf (_(" %d"), number
);
11918 internal_error (_("unhandled tracepoint type %d"), (int) type
);
11925 tracepoint::print_recreate (struct ui_file
*fp
) const
11927 if (type
== bp_fast_tracepoint
)
11928 gdb_printf (fp
, "ftrace");
11929 else if (type
== bp_static_tracepoint
11930 || type
== bp_static_marker_tracepoint
)
11931 gdb_printf (fp
, "strace");
11932 else if (type
== bp_tracepoint
)
11933 gdb_printf (fp
, "trace");
11935 internal_error (_("unhandled tracepoint type %d"), (int) type
);
11937 gdb_printf (fp
, " %s", locspec
->to_string ());
11938 print_recreate_thread (fp
);
11941 gdb_printf (fp
, " passcount %d\n", pass_count
);
11944 /* Virtual table for tracepoints on static probes. */
11947 tracepoint_probe_create_sals_from_location_spec
11948 (location_spec
*locspec
,
11949 struct linespec_result
*canonical
)
11951 /* We use the same method for breakpoint on probes. */
11952 bkpt_probe_create_sals_from_location_spec (locspec
, canonical
);
11956 dprintf_breakpoint::re_set ()
11960 /* extra_string should never be non-NULL for dprintf. */
11961 gdb_assert (extra_string
!= NULL
);
11963 /* 1 - connect to target 1, that can run breakpoint commands.
11964 2 - create a dprintf, which resolves fine.
11965 3 - disconnect from target 1
11966 4 - connect to target 2, that can NOT run breakpoint commands.
11968 After steps #3/#4, you'll want the dprintf command list to
11969 be updated, because target 1 and 2 may well return different
11970 answers for target_can_run_breakpoint_commands().
11971 Given absence of finer grained resetting, we get to do
11972 it all the time. */
11973 if (extra_string
!= NULL
)
11974 update_dprintf_command_list (this);
11977 /* Implement the "print_recreate" method for dprintf. */
11980 dprintf_breakpoint::print_recreate (struct ui_file
*fp
) const
11982 gdb_printf (fp
, "dprintf %s,%s", locspec
->to_string (), extra_string
.get ());
11983 print_recreate_thread (fp
);
11986 /* Implement the "after_condition_true" method for dprintf.
11988 dprintf's are implemented with regular commands in their command
11989 list, but we run the commands here instead of before presenting the
11990 stop to the user, as dprintf's don't actually cause a stop. This
11991 also makes it so that the commands of multiple dprintfs at the same
11992 address are all handled. */
11995 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
11997 /* dprintf's never cause a stop. This wasn't set in the
11998 check_status hook instead because that would make the dprintf's
11999 condition not be evaluated. */
12002 /* Run the command list here. Take ownership of it instead of
12003 copying. We never want these commands to run later in
12004 bpstat_do_actions, if a breakpoint that causes a stop happens to
12005 be set at same address as this dprintf, or even if running the
12006 commands here throws. */
12007 counted_command_line cmds
= std::move (bs
->commands
);
12008 gdb_assert (cmds
!= nullptr);
12009 execute_control_commands (cmds
.get (), 0);
12012 /* The breakpoint_ops structure to be used on static tracepoints with
12016 strace_marker_create_sals_from_location_spec (location_spec
*locspec
,
12017 struct linespec_result
*canonical
)
12019 struct linespec_sals lsal
;
12020 const char *arg_start
, *arg
;
12022 arg
= arg_start
= as_linespec_location_spec (locspec
)->spec_string
;
12023 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12025 std::string
str (arg_start
, arg
- arg_start
);
12026 const char *ptr
= str
.c_str ();
12028 = new_linespec_location_spec (&ptr
, symbol_name_match_type::FULL
);
12030 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12031 canonical
->lsals
.push_back (std::move (lsal
));
12035 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12036 struct linespec_result
*canonical
,
12037 gdb::unique_xmalloc_ptr
<char> cond_string
,
12038 gdb::unique_xmalloc_ptr
<char> extra_string
,
12039 enum bptype type_wanted
,
12040 enum bpdisp disposition
,
12042 int task
, int ignore_count
,
12043 int from_tty
, int enabled
,
12044 int internal
, unsigned flags
)
12046 const linespec_sals
&lsal
= canonical
->lsals
[0];
12048 /* If the user is creating a static tracepoint by marker id
12049 (strace -m MARKER_ID), then store the sals index, so that
12050 breakpoint_re_set can try to match up which of the newly
12051 found markers corresponds to this one, and, don't try to
12052 expand multiple locations for each sal, given than SALS
12053 already should contain all sals for MARKER_ID. */
12055 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12057 location_spec_up locspec
= canonical
->locspec
->clone ();
12059 std::unique_ptr
<tracepoint
> tp
12060 (new tracepoint (gdbarch
,
12063 std::move (locspec
),
12065 std::move (cond_string
),
12066 std::move (extra_string
),
12068 thread
, task
, ignore_count
,
12069 from_tty
, enabled
, flags
,
12070 canonical
->special_display
));
12072 /* Given that its possible to have multiple markers with
12073 the same string id, if the user is creating a static
12074 tracepoint by marker id ("strace -m MARKER_ID"), then
12075 store the sals index, so that breakpoint_re_set can
12076 try to match up which of the newly found markers
12077 corresponds to this one */
12078 tp
->static_trace_marker_id_idx
= i
;
12080 install_breakpoint (internal
, std::move (tp
), 0);
12084 std::vector
<symtab_and_line
>
12085 static_marker_tracepoint::decode_location_spec (location_spec
*locspec
,
12086 program_space
*search_pspace
)
12088 const char *s
= as_linespec_location_spec (locspec
)->spec_string
;
12090 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12091 if (sals
.size () > static_trace_marker_id_idx
)
12093 sals
[0] = sals
[static_trace_marker_id_idx
];
12098 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12101 /* Static tracepoints with marker (`-m'). */
12102 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12104 strace_marker_create_sals_from_location_spec
,
12105 strace_marker_create_breakpoints_sal
,
12109 strace_marker_p (struct breakpoint
*b
)
12111 return b
->type
== bp_static_marker_tracepoint
;
12114 /* Delete a breakpoint and clean up all traces of it in the data
12118 delete_breakpoint (struct breakpoint
*bpt
)
12120 gdb_assert (bpt
!= NULL
);
12122 /* Has this bp already been deleted? This can happen because
12123 multiple lists can hold pointers to bp's. bpstat lists are
12126 One example of this happening is a watchpoint's scope bp. When
12127 the scope bp triggers, we notice that the watchpoint is out of
12128 scope, and delete it. We also delete its scope bp. But the
12129 scope bp is marked "auto-deleting", and is already on a bpstat.
12130 That bpstat is then checked for auto-deleting bp's, which are
12133 A real solution to this problem might involve reference counts in
12134 bp's, and/or giving them pointers back to their referencing
12135 bpstat's, and teaching delete_breakpoint to only free a bp's
12136 storage when no more references were extent. A cheaper bandaid
12138 if (bpt
->type
== bp_none
)
12141 /* At least avoid this stale reference until the reference counting
12142 of breakpoints gets resolved. */
12143 if (bpt
->related_breakpoint
!= bpt
)
12145 struct breakpoint
*related
;
12146 struct watchpoint
*w
;
12148 if (bpt
->type
== bp_watchpoint_scope
)
12149 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12150 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12151 w
= (struct watchpoint
*) bpt
;
12155 watchpoint_del_at_next_stop (w
);
12157 /* Unlink bpt from the bpt->related_breakpoint ring. */
12158 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12159 related
= related
->related_breakpoint
);
12160 related
->related_breakpoint
= bpt
->related_breakpoint
;
12161 bpt
->related_breakpoint
= bpt
;
12164 /* watch_command_1 creates a watchpoint but only sets its number if
12165 update_watchpoint succeeds in creating its bp_locations. If there's
12166 a problem in that process, we'll be asked to delete the half-created
12167 watchpoint. In that case, don't announce the deletion. */
12169 gdb::observers::breakpoint_deleted
.notify (bpt
);
12171 if (breakpoint_chain
== bpt
)
12172 breakpoint_chain
= bpt
->next
;
12174 for (breakpoint
*b
: all_breakpoints ())
12175 if (b
->next
== bpt
)
12177 b
->next
= bpt
->next
;
12181 /* Be sure no bpstat's are pointing at the breakpoint after it's
12183 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12184 in all threads for now. Note that we cannot just remove bpstats
12185 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12186 commands are associated with the bpstat; if we remove it here,
12187 then the later call to bpstat_do_actions (&stop_bpstat); in
12188 event-top.c won't do anything, and temporary breakpoints with
12189 commands won't work. */
12191 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12193 /* Now that breakpoint is removed from breakpoint list, update the
12194 global location list. This will remove locations that used to
12195 belong to this breakpoint. Do this before freeing the breakpoint
12196 itself, since remove_breakpoint looks at location's owner. It
12197 might be better design to have location completely
12198 self-contained, but it's not the case now. */
12199 update_global_location_list (UGLL_DONT_INSERT
);
12201 /* On the chance that someone will soon try again to delete this
12202 same bp, we mark it as deleted before freeing its storage. */
12203 bpt
->type
= bp_none
;
12207 /* Iterator function to call a user-provided callback function once
12208 for each of B and its related breakpoints. */
12211 iterate_over_related_breakpoints (struct breakpoint
*b
,
12212 gdb::function_view
<void (breakpoint
*)> function
)
12214 struct breakpoint
*related
;
12219 struct breakpoint
*next
;
12221 /* FUNCTION may delete RELATED. */
12222 next
= related
->related_breakpoint
;
12224 if (next
== related
)
12226 /* RELATED is the last ring entry. */
12227 function (related
);
12229 /* FUNCTION may have deleted it, so we'd never reach back to
12230 B. There's nothing left to do anyway, so just break
12235 function (related
);
12239 while (related
!= b
);
12243 delete_command (const char *arg
, int from_tty
)
12249 int breaks_to_delete
= 0;
12251 /* Delete all breakpoints if no argument. Do not delete
12252 internal breakpoints, these have to be deleted with an
12253 explicit breakpoint number argument. */
12254 for (breakpoint
*b
: all_breakpoints ())
12255 if (user_breakpoint_p (b
))
12257 breaks_to_delete
= 1;
12261 /* Ask user only if there are some breakpoints to delete. */
12263 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12264 for (breakpoint
*b
: all_breakpoints_safe ())
12265 if (user_breakpoint_p (b
))
12266 delete_breakpoint (b
);
12269 map_breakpoint_numbers
12270 (arg
, [&] (breakpoint
*br
)
12272 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12276 /* Return true if all locations of B bound to PSPACE are pending. If
12277 PSPACE is NULL, all locations of all program spaces are
12281 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12283 for (bp_location
*loc
: b
->locations ())
12284 if ((pspace
== NULL
12285 || loc
->pspace
== pspace
)
12286 && !loc
->shlib_disabled
12287 && !loc
->pspace
->executing_startup
)
12292 /* Subroutine of update_breakpoint_locations to simplify it.
12293 Return non-zero if multiple fns in list LOC have the same name.
12294 Null names are ignored. */
12297 ambiguous_names_p (struct bp_location
*loc
)
12299 struct bp_location
*l
;
12300 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12303 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12306 const char *name
= l
->function_name
.get ();
12308 /* Allow for some names to be NULL, ignore them. */
12312 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12314 /* NOTE: We can assume slot != NULL here because xcalloc never
12324 /* When symbols change, it probably means the sources changed as well,
12325 and it might mean the static tracepoint markers are no longer at
12326 the same address or line numbers they used to be at last we
12327 checked. Losing your static tracepoints whenever you rebuild is
12328 undesirable. This function tries to resync/rematch gdb static
12329 tracepoints with the markers on the target, for static tracepoints
12330 that have not been set by marker id. Static tracepoint that have
12331 been set by marker id are reset by marker id in breakpoint_re_set.
12334 1) For a tracepoint set at a specific address, look for a marker at
12335 the old PC. If one is found there, assume to be the same marker.
12336 If the name / string id of the marker found is different from the
12337 previous known name, assume that means the user renamed the marker
12338 in the sources, and output a warning.
12340 2) For a tracepoint set at a given line number, look for a marker
12341 at the new address of the old line number. If one is found there,
12342 assume to be the same marker. If the name / string id of the
12343 marker found is different from the previous known name, assume that
12344 means the user renamed the marker in the sources, and output a
12347 3) If a marker is no longer found at the same address or line, it
12348 may mean the marker no longer exists. But it may also just mean
12349 the code changed a bit. Maybe the user added a few lines of code
12350 that made the marker move up or down (in line number terms). Ask
12351 the target for info about the marker with the string id as we knew
12352 it. If found, update line number and address in the matching
12353 static tracepoint. This will get confused if there's more than one
12354 marker with the same ID (possible in UST, although unadvised
12355 precisely because it confuses tools). */
12357 static struct symtab_and_line
12358 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12360 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12361 struct static_tracepoint_marker marker
;
12366 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12368 if (target_static_tracepoint_marker_at (pc
, &marker
))
12370 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12371 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12372 b
->number
, tp
->static_trace_marker_id
.c_str (),
12373 marker
.str_id
.c_str ());
12375 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12380 /* Old marker wasn't found on target at lineno. Try looking it up
12382 if (!sal
.explicit_pc
12384 && sal
.symtab
!= NULL
12385 && !tp
->static_trace_marker_id
.empty ())
12387 std::vector
<static_tracepoint_marker
> markers
12388 = target_static_tracepoint_markers_by_strid
12389 (tp
->static_trace_marker_id
.c_str ());
12391 if (!markers
.empty ())
12393 struct symbol
*sym
;
12394 struct static_tracepoint_marker
*tpmarker
;
12395 struct ui_out
*uiout
= current_uiout
;
12397 tpmarker
= &markers
[0];
12399 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12401 warning (_("marker for static tracepoint %d (%s) not "
12402 "found at previous line number"),
12403 b
->number
, tp
->static_trace_marker_id
.c_str ());
12405 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12406 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12407 uiout
->text ("Now in ");
12410 uiout
->field_string ("func", sym
->print_name (),
12411 function_name_style
.style ());
12412 uiout
->text (" at ");
12414 uiout
->field_string ("file",
12415 symtab_to_filename_for_display (sal2
.symtab
),
12416 file_name_style
.style ());
12419 if (uiout
->is_mi_like_p ())
12421 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12423 uiout
->field_string ("fullname", fullname
);
12426 uiout
->field_signed ("line", sal2
.line
);
12427 uiout
->text ("\n");
12429 b
->loc
->line_number
= sal2
.line
;
12430 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12432 std::unique_ptr
<explicit_location_spec
> els
12433 (new explicit_location_spec ());
12434 els
->source_filename
12435 = xstrdup (symtab_to_filename_for_display (sal2
.symtab
));
12436 els
->line_offset
.offset
= b
->loc
->line_number
;
12437 els
->line_offset
.sign
= LINE_OFFSET_NONE
;
12439 b
->locspec
= std::move (els
);
12441 /* Might be nice to check if function changed, and warn if
12448 /* Returns 1 iff locations A and B are sufficiently same that
12449 we don't need to report breakpoint as changed. */
12452 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12456 if (a
->address
!= b
->address
)
12459 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12462 if (a
->enabled
!= b
->enabled
)
12465 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12472 if ((a
== NULL
) != (b
== NULL
))
12478 /* Split all locations of B that are bound to PSPACE out of B's
12479 location list to a separate list and return that list's head. If
12480 PSPACE is NULL, hoist out all locations of B. */
12482 static struct bp_location
*
12483 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12485 struct bp_location head
;
12486 struct bp_location
*i
= b
->loc
;
12487 struct bp_location
**i_link
= &b
->loc
;
12488 struct bp_location
*hoisted
= &head
;
12490 if (pspace
== NULL
)
12501 if (i
->pspace
== pspace
)
12516 /* Create new breakpoint locations for B (a hardware or software
12517 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12518 zero, then B is a ranged breakpoint. Only recreates locations for
12519 FILTER_PSPACE. Locations of other program spaces are left
12523 update_breakpoint_locations (code_breakpoint
*b
,
12524 struct program_space
*filter_pspace
,
12525 gdb::array_view
<const symtab_and_line
> sals
,
12526 gdb::array_view
<const symtab_and_line
> sals_end
)
12528 struct bp_location
*existing_locations
;
12530 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12532 /* Ranged breakpoints have only one start location and one end
12534 b
->enable_state
= bp_disabled
;
12535 gdb_printf (gdb_stderr
,
12536 _("Could not reset ranged breakpoint %d: "
12537 "multiple locations found\n"),
12542 /* If there's no new locations, and all existing locations are
12543 pending, don't do anything. This optimizes the common case where
12544 all locations are in the same shared library, that was unloaded.
12545 We'd like to retain the location, so that when the library is
12546 loaded again, we don't loose the enabled/disabled status of the
12547 individual locations. */
12548 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12551 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12553 for (const auto &sal
: sals
)
12555 struct bp_location
*new_loc
;
12557 switch_to_program_space_and_thread (sal
.pspace
);
12559 new_loc
= b
->add_location (sal
);
12561 /* Reparse conditions, they might contain references to the
12563 if (b
->cond_string
!= NULL
)
12567 s
= b
->cond_string
.get ();
12570 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12571 block_for_pc (sal
.pc
),
12574 catch (const gdb_exception_error
&e
)
12576 new_loc
->disabled_by_cond
= true;
12580 if (!sals_end
.empty ())
12582 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12584 new_loc
->length
= end
- sals
[0].pc
+ 1;
12588 /* If possible, carry over 'disable' status from existing
12591 struct bp_location
*e
= existing_locations
;
12592 /* If there are multiple breakpoints with the same function name,
12593 e.g. for inline functions, comparing function names won't work.
12594 Instead compare pc addresses; this is just a heuristic as things
12595 may have moved, but in practice it gives the correct answer
12596 often enough until a better solution is found. */
12597 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12599 for (; e
; e
= e
->next
)
12601 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12603 if (have_ambiguous_names
)
12605 for (bp_location
*l
: b
->locations ())
12607 /* Ignore software vs hardware location type at
12608 this point, because with "set breakpoint
12609 auto-hw", after a re-set, locations that were
12610 hardware can end up as software, or vice versa.
12611 As mentioned above, this is an heuristic and in
12612 practice should give the correct answer often
12614 if (breakpoint_locations_match (e
, l
, true))
12616 l
->enabled
= e
->enabled
;
12617 l
->disabled_by_cond
= e
->disabled_by_cond
;
12624 for (bp_location
*l
: b
->locations ())
12625 if (l
->function_name
12626 && strcmp (e
->function_name
.get (),
12627 l
->function_name
.get ()) == 0)
12629 l
->enabled
= e
->enabled
;
12630 l
->disabled_by_cond
= e
->disabled_by_cond
;
12638 if (!locations_are_equal (existing_locations
, b
->loc
))
12639 gdb::observers::breakpoint_modified
.notify (b
);
12642 /* Find the SaL locations corresponding to the given LOCSPEC.
12643 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12645 std::vector
<symtab_and_line
>
12646 code_breakpoint::location_spec_to_sals (location_spec
*locspec
,
12647 struct program_space
*search_pspace
,
12650 struct gdb_exception exception
;
12652 std::vector
<symtab_and_line
> sals
;
12656 sals
= decode_location_spec (locspec
, search_pspace
);
12658 catch (gdb_exception_error
&e
)
12660 int not_found_and_ok
= 0;
12662 /* For pending breakpoints, it's expected that parsing will
12663 fail until the right shared library is loaded. User has
12664 already told to create pending breakpoints and don't need
12665 extra messages. If breakpoint is in bp_shlib_disabled
12666 state, then user already saw the message about that
12667 breakpoint being disabled, and don't want to see more
12669 if (e
.error
== NOT_FOUND_ERROR
12670 && (condition_not_parsed
12672 && search_pspace
!= NULL
12673 && loc
->pspace
!= search_pspace
)
12674 || (loc
&& loc
->shlib_disabled
)
12675 || (loc
&& loc
->pspace
->executing_startup
)
12676 || enable_state
== bp_disabled
))
12677 not_found_and_ok
= 1;
12679 if (!not_found_and_ok
)
12681 /* We surely don't want to warn about the same breakpoint
12682 10 times. One solution, implemented here, is disable
12683 the breakpoint on error. Another solution would be to
12684 have separate 'warning emitted' flag. Since this
12685 happens only when a binary has changed, I don't know
12686 which approach is better. */
12687 enable_state
= bp_disabled
;
12691 exception
= std::move (e
);
12694 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
12696 for (auto &sal
: sals
)
12697 resolve_sal_pc (&sal
);
12698 if (condition_not_parsed
&& extra_string
!= NULL
)
12700 gdb::unique_xmalloc_ptr
<char> local_cond
, local_extra
;
12701 int local_thread
, local_task
;
12703 find_condition_and_thread_for_sals (sals
, extra_string
.get (),
12704 &local_cond
, &local_thread
,
12705 &local_task
, &local_extra
);
12706 gdb_assert (cond_string
== nullptr);
12707 if (local_cond
!= nullptr)
12708 cond_string
= std::move (local_cond
);
12709 thread
= local_thread
;
12711 if (local_extra
!= nullptr)
12712 extra_string
= std::move (local_extra
);
12713 condition_not_parsed
= 0;
12716 if (type
== bp_static_tracepoint
)
12717 sals
[0] = update_static_tracepoint (this, sals
[0]);
12727 /* The default re_set method, for typical hardware or software
12728 breakpoints. Reevaluate the breakpoint and recreate its
12732 code_breakpoint::re_set_default ()
12734 struct program_space
*filter_pspace
= current_program_space
;
12735 std::vector
<symtab_and_line
> expanded
, expanded_end
;
12738 std::vector
<symtab_and_line
> sals
= location_spec_to_sals (locspec
.get (),
12742 expanded
= std::move (sals
);
12744 if (locspec_range_end
!= nullptr)
12746 std::vector
<symtab_and_line
> sals_end
12747 = location_spec_to_sals (locspec_range_end
.get (),
12748 filter_pspace
, &found
);
12750 expanded_end
= std::move (sals_end
);
12753 update_breakpoint_locations (this, filter_pspace
, expanded
, expanded_end
);
12756 /* Default method for creating SALs from an address string. It basically
12757 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12760 create_sals_from_location_spec_default (location_spec
*locspec
,
12761 struct linespec_result
*canonical
)
12763 parse_breakpoint_sals (locspec
, canonical
);
12766 /* Reset a breakpoint. */
12769 breakpoint_re_set_one (breakpoint
*b
)
12771 input_radix
= b
->input_radix
;
12772 set_language (b
->language
);
12777 /* Re-set breakpoint locations for the current program space.
12778 Locations bound to other program spaces are left untouched. */
12781 breakpoint_re_set (void)
12784 scoped_restore_current_language save_language
;
12785 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
12786 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12788 /* breakpoint_re_set_one sets the current_language to the language
12789 of the breakpoint it is resetting (see prepare_re_set_context)
12790 before re-evaluating the breakpoint's location. This change can
12791 unfortunately get undone by accident if the language_mode is set
12792 to auto, and we either switch frames, or more likely in this context,
12793 we select the current frame.
12795 We prevent this by temporarily turning the language_mode to
12796 language_mode_manual. We restore it once all breakpoints
12797 have been reset. */
12798 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
12799 language_mode
= language_mode_manual
;
12801 /* Note: we must not try to insert locations until after all
12802 breakpoints have been re-set. Otherwise, e.g., when re-setting
12803 breakpoint 1, we'd insert the locations of breakpoint 2, which
12804 hadn't been re-set yet, and thus may have stale locations. */
12806 for (breakpoint
*b
: all_breakpoints_safe ())
12810 breakpoint_re_set_one (b
);
12812 catch (const gdb_exception
&ex
)
12814 exception_fprintf (gdb_stderr
, ex
,
12815 "Error in re-setting breakpoint %d: ",
12820 jit_breakpoint_re_set ();
12823 create_overlay_event_breakpoint ();
12824 create_longjmp_master_breakpoint ();
12825 create_std_terminate_master_breakpoint ();
12826 create_exception_master_breakpoint ();
12828 /* Now we can insert. */
12829 update_global_location_list (UGLL_MAY_INSERT
);
12832 /* Reset the thread number of this breakpoint:
12834 - If the breakpoint is for all threads, leave it as-is.
12835 - Else, reset it to the current thread for inferior_ptid. */
12837 breakpoint_re_set_thread (struct breakpoint
*b
)
12839 if (b
->thread
!= -1)
12841 b
->thread
= inferior_thread ()->global_num
;
12843 /* We're being called after following a fork. The new fork is
12844 selected as current, and unless this was a vfork will have a
12845 different program space from the original thread. Reset that
12847 b
->loc
->pspace
= current_program_space
;
12851 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12852 If from_tty is nonzero, it prints a message to that effect,
12853 which ends with a period (no newline). */
12856 set_ignore_count (int bptnum
, int count
, int from_tty
)
12861 for (breakpoint
*b
: all_breakpoints ())
12862 if (b
->number
== bptnum
)
12864 if (is_tracepoint (b
))
12866 if (from_tty
&& count
!= 0)
12867 gdb_printf (_("Ignore count ignored for tracepoint %d."),
12872 b
->ignore_count
= count
;
12876 gdb_printf (_("Will stop next time "
12877 "breakpoint %d is reached."),
12879 else if (count
== 1)
12880 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
12883 gdb_printf (_("Will ignore next %d "
12884 "crossings of breakpoint %d."),
12887 gdb::observers::breakpoint_modified
.notify (b
);
12891 error (_("No breakpoint number %d."), bptnum
);
12894 /* Command to set ignore-count of breakpoint N to COUNT. */
12897 ignore_command (const char *args
, int from_tty
)
12899 const char *p
= args
;
12903 error_no_arg (_("a breakpoint number"));
12905 num
= get_number (&p
);
12907 error (_("bad breakpoint number: '%s'"), args
);
12909 error (_("Second argument (specified ignore-count) is missing."));
12911 set_ignore_count (num
,
12912 longest_to_int (value_as_long (parse_and_eval (p
))),
12919 /* Call FUNCTION on each of the breakpoints with numbers in the range
12920 defined by BP_NUM_RANGE (an inclusive range). */
12923 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
12924 gdb::function_view
<void (breakpoint
*)> function
)
12926 if (bp_num_range
.first
== 0)
12928 warning (_("bad breakpoint number at or near '%d'"),
12929 bp_num_range
.first
);
12933 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
12935 bool match
= false;
12937 for (breakpoint
*b
: all_breakpoints_safe ())
12938 if (b
->number
== i
)
12945 gdb_printf (_("No breakpoint number %d.\n"), i
);
12950 /* Call FUNCTION on each of the breakpoints whose numbers are given in
12954 map_breakpoint_numbers (const char *args
,
12955 gdb::function_view
<void (breakpoint
*)> function
)
12957 if (args
== NULL
|| *args
== '\0')
12958 error_no_arg (_("one or more breakpoint numbers"));
12960 number_or_range_parser
parser (args
);
12962 while (!parser
.finished ())
12964 int num
= parser
.get_number ();
12965 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
12969 /* Return the breakpoint location structure corresponding to the
12970 BP_NUM and LOC_NUM values. */
12972 static struct bp_location
*
12973 find_location_by_number (int bp_num
, int loc_num
)
12975 breakpoint
*b
= get_breakpoint (bp_num
);
12977 if (!b
|| b
->number
!= bp_num
)
12978 error (_("Bad breakpoint number '%d'"), bp_num
);
12981 error (_("Bad breakpoint location number '%d'"), loc_num
);
12984 for (bp_location
*loc
: b
->locations ())
12985 if (++n
== loc_num
)
12988 error (_("Bad breakpoint location number '%d'"), loc_num
);
12991 /* Modes of operation for extract_bp_num. */
12992 enum class extract_bp_kind
12994 /* Extracting a breakpoint number. */
12997 /* Extracting a location number. */
13001 /* Extract a breakpoint or location number (as determined by KIND)
13002 from the string starting at START. TRAILER is a character which
13003 can be found after the number. If you don't want a trailer, use
13004 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13005 string. This always returns a positive integer. */
13008 extract_bp_num (extract_bp_kind kind
, const char *start
,
13009 int trailer
, const char **end_out
= NULL
)
13011 const char *end
= start
;
13012 int num
= get_number_trailer (&end
, trailer
);
13014 error (kind
== extract_bp_kind::bp
13015 ? _("Negative breakpoint number '%.*s'")
13016 : _("Negative breakpoint location number '%.*s'"),
13017 int (end
- start
), start
);
13019 error (kind
== extract_bp_kind::bp
13020 ? _("Bad breakpoint number '%.*s'")
13021 : _("Bad breakpoint location number '%.*s'"),
13022 int (end
- start
), start
);
13024 if (end_out
!= NULL
)
13029 /* Extract a breakpoint or location range (as determined by KIND) in
13030 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13031 representing the (inclusive) range. The returned pair's elements
13032 are always positive integers. */
13034 static std::pair
<int, int>
13035 extract_bp_or_bp_range (extract_bp_kind kind
,
13036 const std::string
&arg
,
13037 std::string::size_type arg_offset
)
13039 std::pair
<int, int> range
;
13040 const char *bp_loc
= &arg
[arg_offset
];
13041 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13042 if (dash
!= std::string::npos
)
13044 /* bp_loc is a range (x-z). */
13045 if (arg
.length () == dash
+ 1)
13046 error (kind
== extract_bp_kind::bp
13047 ? _("Bad breakpoint number at or near: '%s'")
13048 : _("Bad breakpoint location number at or near: '%s'"),
13052 const char *start_first
= bp_loc
;
13053 const char *start_second
= &arg
[dash
+ 1];
13054 range
.first
= extract_bp_num (kind
, start_first
, '-');
13055 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13057 if (range
.first
> range
.second
)
13058 error (kind
== extract_bp_kind::bp
13059 ? _("Inverted breakpoint range at '%.*s'")
13060 : _("Inverted breakpoint location range at '%.*s'"),
13061 int (end
- start_first
), start_first
);
13065 /* bp_loc is a single value. */
13066 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13067 range
.second
= range
.first
;
13072 /* Extract the breakpoint/location range specified by ARG. Returns
13073 the breakpoint range in BP_NUM_RANGE, and the location range in
13076 ARG may be in any of the following forms:
13078 x where 'x' is a breakpoint number.
13079 x-y where 'x' and 'y' specify a breakpoint numbers range.
13080 x.y where 'x' is a breakpoint number and 'y' a location number.
13081 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13082 location number range.
13086 extract_bp_number_and_location (const std::string
&arg
,
13087 std::pair
<int, int> &bp_num_range
,
13088 std::pair
<int, int> &bp_loc_range
)
13090 std::string::size_type dot
= arg
.find ('.');
13092 if (dot
!= std::string::npos
)
13094 /* Handle 'x.y' and 'x.y-z' cases. */
13096 if (arg
.length () == dot
+ 1 || dot
== 0)
13097 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13100 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13101 bp_num_range
.second
= bp_num_range
.first
;
13103 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13108 /* Handle x and x-y cases. */
13110 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13111 bp_loc_range
.first
= 0;
13112 bp_loc_range
.second
= 0;
13116 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13117 specifies whether to enable or disable. */
13120 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13122 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13125 if (loc
->disabled_by_cond
&& enable
)
13126 error (_("Breakpoint %d's condition is invalid at location %d, "
13127 "cannot enable."), bp_num
, loc_num
);
13129 if (loc
->enabled
!= enable
)
13131 loc
->enabled
= enable
;
13132 mark_breakpoint_location_modified (loc
);
13134 if (target_supports_enable_disable_tracepoint ()
13135 && current_trace_status ()->running
&& loc
->owner
13136 && is_tracepoint (loc
->owner
))
13137 target_disable_tracepoint (loc
);
13139 update_global_location_list (UGLL_DONT_INSERT
);
13141 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13144 /* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
13145 owner. 1-based indexing. -1 signals NOT FOUND. */
13148 find_loc_num_by_location (const bp_location
*loc
)
13150 if (loc
!= nullptr && loc
->owner
!= nullptr)
13152 /* Locations use 1-based indexing. */
13154 for (bp_location
*it
: loc
->owner
->locations ())
13164 /* Enable or disable a breakpoint location LOC. ENABLE
13165 specifies whether to enable or disable. */
13168 enable_disable_bp_location (bp_location
*loc
, bool enable
)
13170 if (loc
== nullptr)
13171 error (_("Breakpoint location is invalid."));
13173 if (loc
->owner
== nullptr)
13174 error (_("Breakpoint location does not have an owner breakpoint."));
13176 if (loc
->disabled_by_cond
&& enable
)
13178 int loc_num
= find_loc_num_by_location (loc
);
13180 error (_("Breakpoint location LOC_NUM could not be found."));
13182 error (_("Breakpoint %d's condition is invalid at location %d, "
13183 "cannot enable."), loc
->owner
->number
, loc_num
);
13186 if (loc
->enabled
!= enable
)
13188 loc
->enabled
= enable
;
13189 mark_breakpoint_location_modified (loc
);
13192 if (target_supports_enable_disable_tracepoint ()
13193 && current_trace_status ()->running
&& loc
->owner
13194 && is_tracepoint (loc
->owner
))
13195 target_disable_tracepoint (loc
);
13197 update_global_location_list (UGLL_DONT_INSERT
);
13198 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13201 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13202 number of the breakpoint, and BP_LOC_RANGE specifies the
13203 (inclusive) range of location numbers of that breakpoint to
13204 enable/disable. ENABLE specifies whether to enable or disable the
13208 enable_disable_breakpoint_location_range (int bp_num
,
13209 std::pair
<int, int> &bp_loc_range
,
13212 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13213 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13216 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13217 If from_tty is nonzero, it prints a message to that effect,
13218 which ends with a period (no newline). */
13221 disable_breakpoint (struct breakpoint
*bpt
)
13223 /* Never disable a watchpoint scope breakpoint; we want to
13224 hit them when we leave scope so we can delete both the
13225 watchpoint and its scope breakpoint at that time. */
13226 if (bpt
->type
== bp_watchpoint_scope
)
13229 bpt
->enable_state
= bp_disabled
;
13231 /* Mark breakpoint locations modified. */
13232 mark_breakpoint_modified (bpt
);
13234 if (target_supports_enable_disable_tracepoint ()
13235 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13237 for (bp_location
*location
: bpt
->locations ())
13238 target_disable_tracepoint (location
);
13241 update_global_location_list (UGLL_DONT_INSERT
);
13243 gdb::observers::breakpoint_modified
.notify (bpt
);
13246 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13247 specified in ARGS. ARGS may be in any of the formats handled by
13248 extract_bp_number_and_location. ENABLE specifies whether to enable
13249 or disable the breakpoints/locations. */
13252 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13256 for (breakpoint
*bpt
: all_breakpoints ())
13257 if (user_breakpoint_p (bpt
))
13260 enable_breakpoint (bpt
);
13262 disable_breakpoint (bpt
);
13267 std::string num
= extract_arg (&args
);
13269 while (!num
.empty ())
13271 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13273 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13275 if (bp_loc_range
.first
== bp_loc_range
.second
13276 && bp_loc_range
.first
== 0)
13278 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
13279 map_breakpoint_number_range (bp_num_range
,
13281 ? enable_breakpoint
13282 : disable_breakpoint
);
13286 /* Handle breakpoint ids with formats 'x.y' or
13288 enable_disable_breakpoint_location_range
13289 (bp_num_range
.first
, bp_loc_range
, enable
);
13291 num
= extract_arg (&args
);
13296 /* The disable command disables the specified breakpoints/locations
13297 (or all defined breakpoints) so they're no longer effective in
13298 stopping the inferior. ARGS may be in any of the forms defined in
13299 extract_bp_number_and_location. */
13302 disable_command (const char *args
, int from_tty
)
13304 enable_disable_command (args
, from_tty
, false);
13308 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13311 int target_resources_ok
;
13313 if (bpt
->type
== bp_hardware_breakpoint
)
13316 i
= hw_breakpoint_used_count ();
13317 target_resources_ok
=
13318 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13320 if (target_resources_ok
== 0)
13321 error (_("No hardware breakpoint support in the target."));
13322 else if (target_resources_ok
< 0)
13323 error (_("Hardware breakpoints used exceeds limit."));
13326 if (is_watchpoint (bpt
))
13328 /* Initialize it just to avoid a GCC false warning. */
13329 enum enable_state orig_enable_state
= bp_disabled
;
13333 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13335 orig_enable_state
= bpt
->enable_state
;
13336 bpt
->enable_state
= bp_enabled
;
13337 update_watchpoint (w
, 1 /* reparse */);
13339 catch (const gdb_exception
&e
)
13341 bpt
->enable_state
= orig_enable_state
;
13342 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13348 bpt
->enable_state
= bp_enabled
;
13350 /* Mark breakpoint locations modified. */
13351 mark_breakpoint_modified (bpt
);
13353 if (target_supports_enable_disable_tracepoint ()
13354 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13356 for (bp_location
*location
: bpt
->locations ())
13357 target_enable_tracepoint (location
);
13360 bpt
->disposition
= disposition
;
13361 bpt
->enable_count
= count
;
13362 update_global_location_list (UGLL_MAY_INSERT
);
13364 gdb::observers::breakpoint_modified
.notify (bpt
);
13369 enable_breakpoint (struct breakpoint
*bpt
)
13371 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13374 /* The enable command enables the specified breakpoints/locations (or
13375 all defined breakpoints) so they once again become (or continue to
13376 be) effective in stopping the inferior. ARGS may be in any of the
13377 forms defined in extract_bp_number_and_location. */
13380 enable_command (const char *args
, int from_tty
)
13382 enable_disable_command (args
, from_tty
, true);
13386 enable_once_command (const char *args
, int from_tty
)
13388 map_breakpoint_numbers
13389 (args
, [&] (breakpoint
*b
)
13391 iterate_over_related_breakpoints
13392 (b
, [&] (breakpoint
*bpt
)
13394 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13400 enable_count_command (const char *args
, int from_tty
)
13405 error_no_arg (_("hit count"));
13407 count
= get_number (&args
);
13409 map_breakpoint_numbers
13410 (args
, [&] (breakpoint
*b
)
13412 iterate_over_related_breakpoints
13413 (b
, [&] (breakpoint
*bpt
)
13415 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13421 enable_delete_command (const char *args
, int from_tty
)
13423 map_breakpoint_numbers
13424 (args
, [&] (breakpoint
*b
)
13426 iterate_over_related_breakpoints
13427 (b
, [&] (breakpoint
*bpt
)
13429 enable_breakpoint_disp (bpt
, disp_del
, 1);
13434 /* Invalidate last known value of any hardware watchpoint if
13435 the memory which that value represents has been written to by
13439 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13440 CORE_ADDR addr
, ssize_t len
,
13441 const bfd_byte
*data
)
13443 for (breakpoint
*bp
: all_breakpoints ())
13444 if (bp
->enable_state
== bp_enabled
13445 && bp
->type
== bp_hardware_watchpoint
)
13447 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13449 if (wp
->val_valid
&& wp
->val
!= nullptr)
13451 for (bp_location
*loc
: bp
->locations ())
13452 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13453 && loc
->address
+ loc
->length
> addr
13454 && addr
+ len
> loc
->address
)
13457 wp
->val_valid
= false;
13463 /* Create and insert a breakpoint for software single step. */
13466 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13467 const address_space
*aspace
,
13470 struct thread_info
*tp
= inferior_thread ();
13471 struct symtab_and_line sal
;
13472 CORE_ADDR pc
= next_pc
;
13474 if (tp
->control
.single_step_breakpoints
== NULL
)
13476 std::unique_ptr
<breakpoint
> b
13477 (new momentary_breakpoint (gdbarch
, bp_single_step
,
13478 current_program_space
,
13482 tp
->control
.single_step_breakpoints
13483 = add_to_breakpoint_chain (std::move (b
));
13486 sal
= find_pc_line (pc
, 0);
13488 sal
.section
= find_pc_overlay (pc
);
13489 sal
.explicit_pc
= 1;
13492 = (gdb::checked_static_cast
<momentary_breakpoint
*>
13493 (tp
->control
.single_step_breakpoints
));
13494 ss_bp
->add_location (sal
);
13496 update_global_location_list (UGLL_INSERT
);
13499 /* Insert single step breakpoints according to the current state. */
13502 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13504 struct regcache
*regcache
= get_current_regcache ();
13505 std::vector
<CORE_ADDR
> next_pcs
;
13507 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13509 if (!next_pcs
.empty ())
13511 frame_info_ptr frame
= get_current_frame ();
13512 const address_space
*aspace
= get_frame_address_space (frame
);
13514 for (CORE_ADDR pc
: next_pcs
)
13515 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13523 /* See breakpoint.h. */
13526 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13527 const address_space
*aspace
,
13530 for (bp_location
*loc
: bp
->locations ())
13532 && breakpoint_location_address_match (loc
, aspace
, pc
))
13538 /* Check whether a software single-step breakpoint is inserted at
13542 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13545 for (breakpoint
*bpt
: all_breakpoints ())
13547 if (bpt
->type
== bp_single_step
13548 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13554 /* Tracepoint-specific operations. */
13556 /* Set tracepoint count to NUM. */
13558 set_tracepoint_count (int num
)
13560 tracepoint_count
= num
;
13561 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13565 trace_command (const char *arg
, int from_tty
)
13567 location_spec_up locspec
= string_to_location_spec (&arg
,
13569 const struct breakpoint_ops
*ops
= breakpoint_ops_for_location_spec
13570 (locspec
.get (), true /* is_tracepoint */);
13572 create_breakpoint (get_current_arch (),
13574 NULL
, 0, arg
, false, 1 /* parse arg */,
13576 bp_tracepoint
/* type_wanted */,
13577 0 /* Ignore count */,
13578 pending_break_support
,
13582 0 /* internal */, 0);
13586 ftrace_command (const char *arg
, int from_tty
)
13588 location_spec_up locspec
= string_to_location_spec (&arg
,
13590 create_breakpoint (get_current_arch (),
13592 NULL
, 0, arg
, false, 1 /* parse arg */,
13594 bp_fast_tracepoint
/* type_wanted */,
13595 0 /* Ignore count */,
13596 pending_break_support
,
13597 &code_breakpoint_ops
,
13600 0 /* internal */, 0);
13603 /* strace command implementation. Creates a static tracepoint. */
13606 strace_command (const char *arg
, int from_tty
)
13608 const struct breakpoint_ops
*ops
;
13609 location_spec_up locspec
;
13612 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13613 or with a normal static tracepoint. */
13614 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13616 ops
= &strace_marker_breakpoint_ops
;
13617 locspec
= new_linespec_location_spec (&arg
,
13618 symbol_name_match_type::FULL
);
13619 type
= bp_static_marker_tracepoint
;
13623 ops
= &code_breakpoint_ops
;
13624 locspec
= string_to_location_spec (&arg
, current_language
);
13625 type
= bp_static_tracepoint
;
13628 create_breakpoint (get_current_arch (),
13630 NULL
, 0, arg
, false, 1 /* parse arg */,
13632 type
/* type_wanted */,
13633 0 /* Ignore count */,
13634 pending_break_support
,
13638 0 /* internal */, 0);
13641 /* Set up a fake reader function that gets command lines from a linked
13642 list that was acquired during tracepoint uploading. */
13644 static struct uploaded_tp
*this_utp
;
13645 static int next_cmd
;
13648 read_uploaded_action (void)
13650 char *rslt
= nullptr;
13652 if (next_cmd
< this_utp
->cmd_strings
.size ())
13654 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13661 /* Given information about a tracepoint as recorded on a target (which
13662 can be either a live system or a trace file), attempt to create an
13663 equivalent GDB tracepoint. This is not a reliable process, since
13664 the target does not necessarily have all the information used when
13665 the tracepoint was originally defined. */
13667 struct tracepoint
*
13668 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13670 const char *addr_str
;
13671 char small_buf
[100];
13672 struct tracepoint
*tp
;
13674 if (utp
->at_string
)
13675 addr_str
= utp
->at_string
.get ();
13678 /* In the absence of a source location, fall back to raw
13679 address. Since there is no way to confirm that the address
13680 means the same thing as when the trace was started, warn the
13682 warning (_("Uploaded tracepoint %d has no "
13683 "source location, using raw address"),
13685 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13686 addr_str
= small_buf
;
13689 /* There's not much we can do with a sequence of bytecodes. */
13690 if (utp
->cond
&& !utp
->cond_string
)
13691 warning (_("Uploaded tracepoint %d condition "
13692 "has no source form, ignoring it"),
13695 location_spec_up locspec
= string_to_location_spec (&addr_str
,
13697 if (!create_breakpoint (get_current_arch (),
13699 utp
->cond_string
.get (), -1, addr_str
,
13700 false /* force_condition */,
13701 0 /* parse cond/thread */,
13703 utp
->type
/* type_wanted */,
13704 0 /* Ignore count */,
13705 pending_break_support
,
13706 &code_breakpoint_ops
,
13708 utp
->enabled
/* enabled */,
13710 CREATE_BREAKPOINT_FLAGS_INSERTED
))
13713 /* Get the tracepoint we just created. */
13714 tp
= get_tracepoint (tracepoint_count
);
13715 gdb_assert (tp
!= NULL
);
13719 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
13722 trace_pass_command (small_buf
, 0);
13725 /* If we have uploaded versions of the original commands, set up a
13726 special-purpose "reader" function and call the usual command line
13727 reader, then pass the result to the breakpoint command-setting
13729 if (!utp
->cmd_strings
.empty ())
13731 counted_command_line cmd_list
;
13736 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
13738 breakpoint_set_commands (tp
, std::move (cmd_list
));
13740 else if (!utp
->actions
.empty ()
13741 || !utp
->step_actions
.empty ())
13742 warning (_("Uploaded tracepoint %d actions "
13743 "have no source form, ignoring them"),
13746 /* Copy any status information that might be available. */
13747 tp
->hit_count
= utp
->hit_count
;
13748 tp
->traceframe_usage
= utp
->traceframe_usage
;
13753 /* Print information on tracepoint number TPNUM_EXP, or all if
13757 info_tracepoints_command (const char *args
, int from_tty
)
13759 struct ui_out
*uiout
= current_uiout
;
13762 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
13764 if (num_printed
== 0)
13766 if (args
== NULL
|| *args
== '\0')
13767 uiout
->message ("No tracepoints.\n");
13769 uiout
->message ("No tracepoint matching '%s'.\n", args
);
13772 default_collect_info ();
13775 /* The 'enable trace' command enables tracepoints.
13776 Not supported by all targets. */
13778 enable_trace_command (const char *args
, int from_tty
)
13780 enable_command (args
, from_tty
);
13783 /* The 'disable trace' command disables tracepoints.
13784 Not supported by all targets. */
13786 disable_trace_command (const char *args
, int from_tty
)
13788 disable_command (args
, from_tty
);
13791 /* Remove a tracepoint (or all if no argument). */
13793 delete_trace_command (const char *arg
, int from_tty
)
13799 int breaks_to_delete
= 0;
13801 /* Delete all breakpoints if no argument.
13802 Do not delete internal or call-dummy breakpoints, these
13803 have to be deleted with an explicit breakpoint number
13805 for (breakpoint
*tp
: all_tracepoints ())
13806 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
13808 breaks_to_delete
= 1;
13812 /* Ask user only if there are some breakpoints to delete. */
13814 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13816 for (breakpoint
*b
: all_breakpoints_safe ())
13817 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13818 delete_breakpoint (b
);
13822 map_breakpoint_numbers
13823 (arg
, [&] (breakpoint
*br
)
13825 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13829 /* Helper function for trace_pass_command. */
13832 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13834 tp
->pass_count
= count
;
13835 gdb::observers::breakpoint_modified
.notify (tp
);
13837 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
13838 tp
->number
, count
);
13841 /* Set passcount for tracepoint.
13843 First command argument is passcount, second is tracepoint number.
13844 If tracepoint number omitted, apply to most recently defined.
13845 Also accepts special argument "all". */
13848 trace_pass_command (const char *args
, int from_tty
)
13850 struct tracepoint
*t1
;
13853 if (args
== 0 || *args
== 0)
13854 error (_("passcount command requires an "
13855 "argument (count + optional TP num)"));
13857 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
13859 args
= skip_spaces (args
);
13860 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13862 args
+= 3; /* Skip special argument "all". */
13864 error (_("Junk at end of arguments."));
13866 for (breakpoint
*b
: all_tracepoints ())
13868 t1
= (struct tracepoint
*) b
;
13869 trace_pass_set_count (t1
, count
, from_tty
);
13872 else if (*args
== '\0')
13874 t1
= get_tracepoint_by_number (&args
, NULL
);
13876 trace_pass_set_count (t1
, count
, from_tty
);
13880 number_or_range_parser
parser (args
);
13881 while (!parser
.finished ())
13883 t1
= get_tracepoint_by_number (&args
, &parser
);
13885 trace_pass_set_count (t1
, count
, from_tty
);
13890 struct tracepoint
*
13891 get_tracepoint (int num
)
13893 for (breakpoint
*t
: all_tracepoints ())
13894 if (t
->number
== num
)
13895 return (struct tracepoint
*) t
;
13900 /* Find the tracepoint with the given target-side number (which may be
13901 different from the tracepoint number after disconnecting and
13904 struct tracepoint
*
13905 get_tracepoint_by_number_on_target (int num
)
13907 for (breakpoint
*b
: all_tracepoints ())
13909 struct tracepoint
*t
= (struct tracepoint
*) b
;
13911 if (t
->number_on_target
== num
)
13918 /* Utility: parse a tracepoint number and look it up in the list.
13919 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13920 If the argument is missing, the most recent tracepoint
13921 (tracepoint_count) is returned. */
13923 struct tracepoint
*
13924 get_tracepoint_by_number (const char **arg
,
13925 number_or_range_parser
*parser
)
13928 const char *instring
= arg
== NULL
? NULL
: *arg
;
13930 if (parser
!= NULL
)
13932 gdb_assert (!parser
->finished ());
13933 tpnum
= parser
->get_number ();
13935 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13936 tpnum
= tracepoint_count
;
13938 tpnum
= get_number (arg
);
13942 if (instring
&& *instring
)
13943 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
13946 gdb_printf (_("No previous tracepoint\n"));
13950 for (breakpoint
*t
: all_tracepoints ())
13951 if (t
->number
== tpnum
)
13952 return (struct tracepoint
*) t
;
13954 gdb_printf ("No tracepoint number %d.\n", tpnum
);
13959 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
13962 gdb_printf (fp
, " thread %d", thread
);
13965 gdb_printf (fp
, " task %d", task
);
13967 gdb_printf (fp
, "\n");
13970 /* Save information on user settable breakpoints (watchpoints, etc) to
13971 a new script file named FILENAME. If FILTER is non-NULL, call it
13972 on each breakpoint and only include the ones for which it returns
13976 save_breakpoints (const char *filename
, int from_tty
,
13977 bool (*filter
) (const struct breakpoint
*))
13980 int extra_trace_bits
= 0;
13982 if (filename
== 0 || *filename
== 0)
13983 error (_("Argument required (file name in which to save)"));
13985 /* See if we have anything to save. */
13986 for (breakpoint
*tp
: all_breakpoints ())
13988 /* Skip internal and momentary breakpoints. */
13989 if (!user_breakpoint_p (tp
))
13992 /* If we have a filter, only save the breakpoints it accepts. */
13993 if (filter
&& !filter (tp
))
13998 if (is_tracepoint (tp
))
14000 extra_trace_bits
= 1;
14002 /* We can stop searching. */
14009 warning (_("Nothing to save."));
14013 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14017 if (!fp
.open (expanded_filename
.get (), "w"))
14018 error (_("Unable to open file '%s' for saving (%s)"),
14019 expanded_filename
.get (), safe_strerror (errno
));
14021 if (extra_trace_bits
)
14022 save_trace_state_variables (&fp
);
14024 for (breakpoint
*tp
: all_breakpoints ())
14026 /* Skip internal and momentary breakpoints. */
14027 if (!user_breakpoint_p (tp
))
14030 /* If we have a filter, only save the breakpoints it accepts. */
14031 if (filter
&& !filter (tp
))
14034 tp
->print_recreate (&fp
);
14036 /* Note, we can't rely on tp->number for anything, as we can't
14037 assume the recreated breakpoint numbers will match. Use $bpnum
14040 if (tp
->cond_string
)
14041 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14043 if (tp
->ignore_count
)
14044 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14046 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14048 fp
.puts (" commands\n");
14050 ui_out_redirect_pop
redir (current_uiout
, &fp
);
14051 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14053 fp
.puts (" end\n");
14056 if (tp
->enable_state
== bp_disabled
)
14057 fp
.puts ("disable $bpnum\n");
14059 /* If this is a multi-location breakpoint, check if the locations
14060 should be individually disabled. Watchpoint locations are
14061 special, and not user visible. */
14062 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14066 for (bp_location
*loc
: tp
->locations ())
14069 fp
.printf ("disable $bpnum.%d\n", n
);
14076 if (extra_trace_bits
&& !default_collect
.empty ())
14077 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14080 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14083 /* The `save breakpoints' command. */
14086 save_breakpoints_command (const char *args
, int from_tty
)
14088 save_breakpoints (args
, from_tty
, NULL
);
14091 /* The `save tracepoints' command. */
14094 save_tracepoints_command (const char *args
, int from_tty
)
14096 save_breakpoints (args
, from_tty
, is_tracepoint
);
14100 /* This help string is used to consolidate all the help string for specifying
14101 locations used by several commands. */
14103 #define LOCATION_SPEC_HELP_STRING \
14104 "Linespecs are colon-separated lists of location parameters, such as\n\
14105 source filename, function name, label name, and line number.\n\
14106 Example: To specify the start of a label named \"the_top\" in the\n\
14107 function \"fact\" in the file \"factorial.c\", use\n\
14108 \"factorial.c:fact:the_top\".\n\
14110 Address locations begin with \"*\" and specify an exact address in the\n\
14111 program. Example: To specify the fourth byte past the start function\n\
14112 \"main\", use \"*main + 4\".\n\
14114 Explicit locations are similar to linespecs but use an option/argument\n\
14115 syntax to specify location parameters.\n\
14116 Example: To specify the start of the label named \"the_top\" in the\n\
14117 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14118 -function fact -label the_top\".\n\
14120 By default, a specified function is matched against the program's\n\
14121 functions in all scopes. For C++, this means in all namespaces and\n\
14122 classes. For Ada, this means in all packages. E.g., in C++,\n\
14123 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14124 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14125 specified name as a complete fully-qualified name instead."
14127 /* This help string is used for the break, hbreak, tbreak and thbreak
14128 commands. It is defined as a macro to prevent duplication.
14129 COMMAND should be a string constant containing the name of the
14132 #define BREAK_ARGS_HELP(command) \
14133 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14134 \t[-force-condition] [if CONDITION]\n\
14135 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14136 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14137 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14138 `-probe-dtrace' (for a DTrace probe).\n\
14139 LOCATION may be a linespec, address, or explicit location as described\n\
14142 With no LOCATION, uses current execution address of the selected\n\
14143 stack frame. This is useful for breaking on return to a stack frame.\n\
14145 THREADNUM is the number from \"info threads\".\n\
14146 CONDITION is a boolean expression.\n\
14148 With the \"-force-condition\" flag, the condition is defined even when\n\
14149 it is invalid for all current locations.\n\
14150 \n" LOCATION_SPEC_HELP_STRING "\n\n\
14151 Multiple breakpoints at one place are permitted, and useful if their\n\
14152 conditions are different.\n\
14154 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14156 /* List of subcommands for "catch". */
14157 static struct cmd_list_element
*catch_cmdlist
;
14159 /* List of subcommands for "tcatch". */
14160 static struct cmd_list_element
*tcatch_cmdlist
;
14163 add_catch_command (const char *name
, const char *docstring
,
14164 cmd_func_ftype
*func
,
14165 completer_ftype
*completer
,
14166 void *user_data_catch
,
14167 void *user_data_tcatch
)
14169 struct cmd_list_element
*command
;
14171 command
= add_cmd (name
, class_breakpoint
, docstring
,
14173 command
->func
= func
;
14174 command
->set_context (user_data_catch
);
14175 set_cmd_completer (command
, completer
);
14177 command
= add_cmd (name
, class_breakpoint
, docstring
,
14179 command
->func
= func
;
14180 command
->set_context (user_data_tcatch
);
14181 set_cmd_completer (command
, completer
);
14184 /* Zero if any of the breakpoint's locations could be a location where
14185 functions have been inlined, nonzero otherwise. */
14188 is_non_inline_function (struct breakpoint
*b
)
14190 /* The shared library event breakpoint is set on the address of a
14191 non-inline function. */
14192 if (b
->type
== bp_shlib_event
)
14198 /* Nonzero if the specified PC cannot be a location where functions
14199 have been inlined. */
14202 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14203 const target_waitstatus
&ws
)
14205 for (breakpoint
*b
: all_breakpoints ())
14207 if (!is_non_inline_function (b
))
14210 for (bp_location
*bl
: b
->locations ())
14212 if (!bl
->shlib_disabled
14213 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14221 /* Remove any references to OBJFILE which is going to be freed. */
14224 breakpoint_free_objfile (struct objfile
*objfile
)
14226 for (bp_location
*loc
: all_bp_locations ())
14227 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14228 loc
->symtab
= NULL
;
14231 /* Chain containing all defined "enable breakpoint" subcommands. */
14233 static struct cmd_list_element
*enablebreaklist
= NULL
;
14235 /* See breakpoint.h. */
14237 cmd_list_element
*commands_cmd_element
= nullptr;
14239 void _initialize_breakpoint ();
14241 _initialize_breakpoint ()
14243 struct cmd_list_element
*c
;
14245 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14247 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14249 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14252 breakpoint_chain
= 0;
14253 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14254 before a breakpoint is set. */
14255 breakpoint_count
= 0;
14257 tracepoint_count
= 0;
14259 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14260 Set ignore-count of breakpoint number N to COUNT.\n\
14261 Usage is `ignore N COUNT'."));
14263 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14264 commands_command
, _("\
14265 Set commands to be executed when the given breakpoints are hit.\n\
14266 Give a space-separated breakpoint list as argument after \"commands\".\n\
14267 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14269 With no argument, the targeted breakpoint is the last one set.\n\
14270 The commands themselves follow starting on the next line.\n\
14271 Type a line containing \"end\" to indicate the end of them.\n\
14272 Give \"silent\" as the first line to make the breakpoint silent;\n\
14273 then no output is printed when it is hit, except what the commands print."));
14275 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14276 static std::string condition_command_help
14277 = gdb::option::build_help (_("\
14278 Specify breakpoint number N to break only if COND is true.\n\
14279 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14280 is an expression to be evaluated whenever breakpoint N is reached.\n\
14283 %OPTIONS%"), cc_opts
);
14285 c
= add_com ("condition", class_breakpoint
, condition_command
,
14286 condition_command_help
.c_str ());
14287 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14289 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14290 Set a temporary breakpoint.\n\
14291 Like \"break\" except the breakpoint is only temporary,\n\
14292 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14293 by using \"enable delete\" on the breakpoint number.\n\
14295 BREAK_ARGS_HELP ("tbreak")));
14296 set_cmd_completer (c
, location_completer
);
14298 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14299 Set a hardware assisted breakpoint.\n\
14300 Like \"break\" except the breakpoint requires hardware support,\n\
14301 some target hardware may not have this support.\n\
14303 BREAK_ARGS_HELP ("hbreak")));
14304 set_cmd_completer (c
, location_completer
);
14306 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14307 Set a temporary hardware assisted breakpoint.\n\
14308 Like \"hbreak\" except the breakpoint is only temporary,\n\
14309 so it will be deleted when hit.\n\
14311 BREAK_ARGS_HELP ("thbreak")));
14312 set_cmd_completer (c
, location_completer
);
14314 cmd_list_element
*enable_cmd
14315 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14316 Enable all or some breakpoints.\n\
14317 Usage: enable [BREAKPOINTNUM]...\n\
14318 Give breakpoint numbers (separated by spaces) as arguments.\n\
14319 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14320 This is used to cancel the effect of the \"disable\" command.\n\
14321 With a subcommand you can enable temporarily."),
14322 &enablelist
, 1, &cmdlist
);
14324 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14326 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14327 Enable all or some breakpoints.\n\
14328 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14329 Give breakpoint numbers (separated by spaces) as arguments.\n\
14330 This is used to cancel the effect of the \"disable\" command.\n\
14331 May be abbreviated to simply \"enable\"."),
14332 &enablebreaklist
, 1, &enablelist
);
14334 add_cmd ("once", no_class
, enable_once_command
, _("\
14335 Enable some breakpoints for one hit.\n\
14336 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14337 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14340 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14341 Enable some breakpoints and delete when hit.\n\
14342 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14343 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14346 add_cmd ("count", no_class
, enable_count_command
, _("\
14347 Enable some breakpoints for COUNT hits.\n\
14348 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14349 If a breakpoint is hit while enabled in this fashion,\n\
14350 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14353 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14354 Enable some breakpoints and delete when hit.\n\
14355 Usage: enable delete BREAKPOINTNUM...\n\
14356 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14359 add_cmd ("once", no_class
, enable_once_command
, _("\
14360 Enable some breakpoints for one hit.\n\
14361 Usage: enable once BREAKPOINTNUM...\n\
14362 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14365 add_cmd ("count", no_class
, enable_count_command
, _("\
14366 Enable some breakpoints for COUNT hits.\n\
14367 Usage: enable count COUNT BREAKPOINTNUM...\n\
14368 If a breakpoint is hit while enabled in this fashion,\n\
14369 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14372 cmd_list_element
*disable_cmd
14373 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14374 Disable all or some breakpoints.\n\
14375 Usage: disable [BREAKPOINTNUM]...\n\
14376 Arguments are breakpoint numbers with spaces in between.\n\
14377 To disable all breakpoints, give no argument.\n\
14378 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14379 &disablelist
, 1, &cmdlist
);
14380 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14381 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14383 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14384 Disable all or some breakpoints.\n\
14385 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14386 Arguments are breakpoint numbers with spaces in between.\n\
14387 To disable all breakpoints, give no argument.\n\
14388 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14389 This command may be abbreviated \"disable\"."),
14392 cmd_list_element
*delete_cmd
14393 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14394 Delete all or some breakpoints.\n\
14395 Usage: delete [BREAKPOINTNUM]...\n\
14396 Arguments are breakpoint numbers with spaces in between.\n\
14397 To delete all breakpoints, give no argument.\n\
14399 Also a prefix command for deletion of other GDB objects."),
14400 &deletelist
, 1, &cmdlist
);
14401 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14402 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14404 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14405 Delete all or some breakpoints or auto-display expressions.\n\
14406 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14407 Arguments are breakpoint numbers with spaces in between.\n\
14408 To delete all breakpoints, give no argument.\n\
14409 This command may be abbreviated \"delete\"."),
14412 cmd_list_element
*clear_cmd
14413 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14414 Clear breakpoint at specified location.\n\
14415 Argument may be a linespec, explicit, or address location as described below.\n\
14417 With no argument, clears all breakpoints in the line that the selected frame\n\
14418 is executing in.\n"
14419 "\n" LOCATION_SPEC_HELP_STRING
"\n\n\
14420 See also the \"delete\" command which clears breakpoints by number."));
14421 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14423 cmd_list_element
*break_cmd
14424 = add_com ("break", class_breakpoint
, break_command
, _("\
14425 Set breakpoint at specified location.\n"
14426 BREAK_ARGS_HELP ("break")));
14427 set_cmd_completer (break_cmd
, location_completer
);
14429 add_com_alias ("b", break_cmd
, class_run
, 1);
14430 add_com_alias ("br", break_cmd
, class_run
, 1);
14431 add_com_alias ("bre", break_cmd
, class_run
, 1);
14432 add_com_alias ("brea", break_cmd
, class_run
, 1);
14434 cmd_list_element
*info_breakpoints_cmd
14435 = add_info ("breakpoints", info_breakpoints_command
, _("\
14436 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14437 The \"Type\" column indicates one of:\n\
14438 \tbreakpoint - normal breakpoint\n\
14439 \twatchpoint - watchpoint\n\
14440 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14441 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14442 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14443 address and file/line number respectively.\n\
14445 Convenience variable \"$_\" and default examine address for \"x\"\n\
14446 are set to the address of the last breakpoint listed unless the command\n\
14447 is prefixed with \"server \".\n\n\
14448 Convenience variable \"$bpnum\" contains the number of the last\n\
14449 breakpoint set."));
14451 add_info_alias ("b", info_breakpoints_cmd
, 1);
14453 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14454 Status of all breakpoints, or breakpoint number NUMBER.\n\
14455 The \"Type\" column indicates one of:\n\
14456 \tbreakpoint - normal breakpoint\n\
14457 \twatchpoint - watchpoint\n\
14458 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14459 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14460 \tuntil - internal breakpoint used by the \"until\" command\n\
14461 \tfinish - internal breakpoint used by the \"finish\" command\n\
14462 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14463 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14464 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14465 address and file/line number respectively.\n\
14467 Convenience variable \"$_\" and default examine address for \"x\"\n\
14468 are set to the address of the last breakpoint listed unless the command\n\
14469 is prefixed with \"server \".\n\n\
14470 Convenience variable \"$bpnum\" contains the number of the last\n\
14472 &maintenanceinfolist
);
14474 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14475 Set catchpoints to catch events."),
14477 0/*allow-unknown*/, &cmdlist
);
14479 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14480 Set temporary catchpoints to catch events."),
14482 0/*allow-unknown*/, &cmdlist
);
14484 const auto opts
= make_watch_options_def_group (nullptr);
14486 static const std::string watch_help
= gdb::option::build_help (_("\
14487 Set a watchpoint for EXPRESSION.\n\
14488 Usage: watch [-location] EXPRESSION\n\
14493 A watchpoint stops execution of your program whenever the value of\n\
14494 an expression changes."), opts
);
14495 c
= add_com ("watch", class_breakpoint
, watch_command
,
14496 watch_help
.c_str ());
14497 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14499 static const std::string rwatch_help
= gdb::option::build_help (_("\
14500 Set a read watchpoint for EXPRESSION.\n\
14501 Usage: rwatch [-location] EXPRESSION\n\
14506 A read watchpoint stops execution of your program whenever the value of\n\
14507 an expression is read."), opts
);
14508 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14509 rwatch_help
.c_str ());
14510 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14512 static const std::string awatch_help
= gdb::option::build_help (_("\
14513 Set an access watchpoint for EXPRESSION.\n\
14514 Usage: awatch [-location] EXPRESSION\n\
14519 An access watchpoint stops execution of your program whenever the value\n\
14520 of an expression is either read or written."), opts
);
14521 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14522 awatch_help
.c_str ());
14523 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14525 add_info ("watchpoints", info_watchpoints_command
, _("\
14526 Status of specified watchpoints (all watchpoints if no argument)."));
14528 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14529 respond to changes - contrary to the description. */
14530 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14531 &can_use_hw_watchpoints
, _("\
14532 Set debugger's willingness to use watchpoint hardware."), _("\
14533 Show debugger's willingness to use watchpoint hardware."), _("\
14534 If zero, gdb will not use hardware for new watchpoints, even if\n\
14535 such is available. (However, any hardware watchpoints that were\n\
14536 created before setting this to nonzero, will continue to use watchpoint\n\
14539 show_can_use_hw_watchpoints
,
14540 &setlist
, &showlist
);
14542 can_use_hw_watchpoints
= 1;
14544 /* Tracepoint manipulation commands. */
14546 cmd_list_element
*trace_cmd
14547 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14548 Set a tracepoint at specified location.\n\
14550 BREAK_ARGS_HELP ("trace") "\n\
14551 Do \"help tracepoints\" for info on other tracepoint commands."));
14552 set_cmd_completer (trace_cmd
, location_completer
);
14554 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14555 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14556 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14557 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14559 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14560 Set a fast tracepoint at specified location.\n\
14562 BREAK_ARGS_HELP ("ftrace") "\n\
14563 Do \"help tracepoints\" for info on other tracepoint commands."));
14564 set_cmd_completer (c
, location_completer
);
14566 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14567 Set a static tracepoint at location or marker.\n\
14569 strace [LOCATION] [if CONDITION]\n\
14570 LOCATION may be a linespec, explicit, or address location (described below) \n\
14571 or -m MARKER_ID.\n\n\
14572 If a marker id is specified, probe the marker with that name. With\n\
14573 no LOCATION, uses current execution address of the selected stack frame.\n\
14574 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14575 This collects arbitrary user data passed in the probe point call to the\n\
14576 tracing library. You can inspect it when analyzing the trace buffer,\n\
14577 by printing the $_sdata variable like any other convenience variable.\n\
14579 CONDITION is a boolean expression.\n\
14580 \n" LOCATION_SPEC_HELP_STRING
"\n\n\
14581 Multiple tracepoints at one place are permitted, and useful if their\n\
14582 conditions are different.\n\
14584 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14585 Do \"help tracepoints\" for info on other tracepoint commands."));
14586 set_cmd_completer (c
, location_completer
);
14588 cmd_list_element
*info_tracepoints_cmd
14589 = add_info ("tracepoints", info_tracepoints_command
, _("\
14590 Status of specified tracepoints (all tracepoints if no argument).\n\
14591 Convenience variable \"$tpnum\" contains the number of the\n\
14592 last tracepoint set."));
14594 add_info_alias ("tp", info_tracepoints_cmd
, 1);
14596 cmd_list_element
*delete_tracepoints_cmd
14597 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14598 Delete specified tracepoints.\n\
14599 Arguments are tracepoint numbers, separated by spaces.\n\
14600 No argument means delete all tracepoints."),
14602 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
14604 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14605 Disable specified tracepoints.\n\
14606 Arguments are tracepoint numbers, separated by spaces.\n\
14607 No argument means disable all tracepoints."),
14609 deprecate_cmd (c
, "disable");
14611 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14612 Enable specified tracepoints.\n\
14613 Arguments are tracepoint numbers, separated by spaces.\n\
14614 No argument means enable all tracepoints."),
14616 deprecate_cmd (c
, "enable");
14618 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14619 Set the passcount for a tracepoint.\n\
14620 The trace will end when the tracepoint has been passed 'count' times.\n\
14621 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14622 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14624 add_basic_prefix_cmd ("save", class_breakpoint
,
14625 _("Save breakpoint definitions as a script."),
14627 0/*allow-unknown*/, &cmdlist
);
14629 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14630 Save current breakpoint definitions as a script.\n\
14631 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14632 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14633 session to restore them."),
14635 set_cmd_completer (c
, filename_completer
);
14637 cmd_list_element
*save_tracepoints_cmd
14638 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14639 Save current tracepoint definitions as a script.\n\
14640 Use the 'source' command in another debug session to restore them."),
14642 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
14644 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
14645 deprecate_cmd (c
, "save tracepoints");
14647 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
14649 Breakpoint specific settings.\n\
14650 Configure various breakpoint-specific variables such as\n\
14651 pending breakpoint behavior."),
14653 Breakpoint specific settings.\n\
14654 Configure various breakpoint-specific variables such as\n\
14655 pending breakpoint behavior."),
14656 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
14657 &setlist
, &showlist
);
14659 add_setshow_auto_boolean_cmd ("pending", no_class
,
14660 &pending_break_support
, _("\
14661 Set debugger's behavior regarding pending breakpoints."), _("\
14662 Show debugger's behavior regarding pending breakpoints."), _("\
14663 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14664 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14665 an error. If auto, an unrecognized breakpoint location results in a\n\
14666 user-query to see if a pending breakpoint should be created."),
14668 show_pending_break_support
,
14669 &breakpoint_set_cmdlist
,
14670 &breakpoint_show_cmdlist
);
14672 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14674 add_setshow_boolean_cmd ("auto-hw", no_class
,
14675 &automatic_hardware_breakpoints
, _("\
14676 Set automatic usage of hardware breakpoints."), _("\
14677 Show automatic usage of hardware breakpoints."), _("\
14678 If set, the debugger will automatically use hardware breakpoints for\n\
14679 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14680 a warning will be emitted for such breakpoints."),
14682 show_automatic_hardware_breakpoints
,
14683 &breakpoint_set_cmdlist
,
14684 &breakpoint_show_cmdlist
);
14686 add_setshow_boolean_cmd ("always-inserted", class_support
,
14687 &always_inserted_mode
, _("\
14688 Set mode for inserting breakpoints."), _("\
14689 Show mode for inserting breakpoints."), _("\
14690 When this mode is on, breakpoints are inserted immediately as soon as\n\
14691 they're created, kept inserted even when execution stops, and removed\n\
14692 only when the user deletes them. When this mode is off (the default),\n\
14693 breakpoints are inserted only when execution continues, and removed\n\
14694 when execution stops."),
14696 &show_always_inserted_mode
,
14697 &breakpoint_set_cmdlist
,
14698 &breakpoint_show_cmdlist
);
14700 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
14701 condition_evaluation_enums
,
14702 &condition_evaluation_mode_1
, _("\
14703 Set mode of breakpoint condition evaluation."), _("\
14704 Show mode of breakpoint condition evaluation."), _("\
14705 When this is set to \"host\", breakpoint conditions will be\n\
14706 evaluated on the host's side by GDB. When it is set to \"target\",\n\
14707 breakpoint conditions will be downloaded to the target (if the target\n\
14708 supports such feature) and conditions will be evaluated on the target's side.\n\
14709 If this is set to \"auto\" (default), this will be automatically set to\n\
14710 \"target\" if it supports condition evaluation, otherwise it will\n\
14711 be set to \"host\"."),
14712 &set_condition_evaluation_mode
,
14713 &show_condition_evaluation_mode
,
14714 &breakpoint_set_cmdlist
,
14715 &breakpoint_show_cmdlist
);
14717 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14718 Set a breakpoint for an address range.\n\
14719 break-range START-LOCATION, END-LOCATION\n\
14720 where START-LOCATION and END-LOCATION can be one of the following:\n\
14721 LINENUM, for that line in the current file,\n\
14722 FILE:LINENUM, for that line in that file,\n\
14723 +OFFSET, for that number of lines after the current line\n\
14724 or the start of the range\n\
14725 FUNCTION, for the first line in that function,\n\
14726 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14727 *ADDRESS, for the instruction at that address.\n\
14729 The breakpoint will stop execution of the inferior whenever it executes\n\
14730 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14731 range (including START-LOCATION and END-LOCATION)."));
14733 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
14734 Set a dynamic printf at specified location.\n\
14735 dprintf location,format string,arg1,arg2,...\n\
14736 location may be a linespec, explicit, or address location.\n"
14737 "\n" LOCATION_SPEC_HELP_STRING
));
14738 set_cmd_completer (c
, location_completer
);
14740 add_setshow_enum_cmd ("dprintf-style", class_support
,
14741 dprintf_style_enums
, &dprintf_style
, _("\
14742 Set the style of usage for dynamic printf."), _("\
14743 Show the style of usage for dynamic printf."), _("\
14744 This setting chooses how GDB will do a dynamic printf.\n\
14745 If the value is \"gdb\", then the printing is done by GDB to its own\n\
14746 console, as with the \"printf\" command.\n\
14747 If the value is \"call\", the print is done by calling a function in your\n\
14748 program; by default printf(), but you can choose a different function or\n\
14749 output stream by setting dprintf-function and dprintf-channel."),
14750 update_dprintf_commands
, NULL
,
14751 &setlist
, &showlist
);
14753 add_setshow_string_cmd ("dprintf-function", class_support
,
14754 &dprintf_function
, _("\
14755 Set the function to use for dynamic printf."), _("\
14756 Show the function to use for dynamic printf."), NULL
,
14757 update_dprintf_commands
, NULL
,
14758 &setlist
, &showlist
);
14760 add_setshow_string_cmd ("dprintf-channel", class_support
,
14761 &dprintf_channel
, _("\
14762 Set the channel to use for dynamic printf."), _("\
14763 Show the channel to use for dynamic printf."), NULL
,
14764 update_dprintf_commands
, NULL
,
14765 &setlist
, &showlist
);
14767 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
14768 &disconnected_dprintf
, _("\
14769 Set whether dprintf continues after GDB disconnects."), _("\
14770 Show whether dprintf continues after GDB disconnects."), _("\
14771 Use this to let dprintf commands continue to hit and produce output\n\
14772 even if GDB disconnects or detaches from the target."),
14775 &setlist
, &showlist
);
14777 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
14778 Target agent only formatted printing, like the C \"printf\" function.\n\
14779 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
14780 This supports most C printf format specifications, like %s, %d, etc.\n\
14781 This is useful for formatted output in user-defined commands."));
14783 automatic_hardware_breakpoints
= true;
14785 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
14787 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,