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 std::vector
<symtab_and_line
> decode_location_spec_default
104 (struct breakpoint
*b
, struct location_spec
*locspec
,
105 struct program_space
*search_pspace
);
107 static int can_use_hardware_watchpoint
108 (const std::vector
<value_ref_ptr
> &vals
);
110 static void mention (const breakpoint
*);
112 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
114 static breakpoint
*add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
);
116 static struct breakpoint
*
117 momentary_breakpoint_from_master (struct breakpoint
*orig
,
119 int loc_enabled
, int thread
);
121 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
123 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
126 struct program_space
*pspace
);
128 static int watchpoint_locations_match (struct bp_location
*loc1
,
129 struct bp_location
*loc2
);
131 static int breakpoint_locations_match (struct bp_location
*loc1
,
132 struct bp_location
*loc2
,
133 bool sw_hw_bps_match
= false);
135 static int breakpoint_location_address_match (struct bp_location
*bl
,
136 const struct address_space
*aspace
,
139 static int breakpoint_location_address_range_overlap (struct bp_location
*,
140 const address_space
*,
143 static int remove_breakpoint (struct bp_location
*);
144 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
146 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
148 static int hw_breakpoint_used_count (void);
150 static int hw_watchpoint_use_count (struct breakpoint
*);
152 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
154 int *other_type_used
);
156 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
159 static void decref_bp_location (struct bp_location
**loc
);
161 static std::vector
<symtab_and_line
> bkpt_probe_decode_location_spec
162 (struct breakpoint
*b
,
163 location_spec
*locspec
,
164 struct program_space
*search_pspace
);
166 static bool bl_address_is_meaningful (bp_location
*loc
);
168 /* update_global_location_list's modes of operation wrt to whether to
169 insert locations now. */
170 enum ugll_insert_mode
172 /* Don't insert any breakpoint locations into the inferior, only
173 remove already-inserted locations that no longer should be
174 inserted. Functions that delete a breakpoint or breakpoints
175 should specify this mode, so that deleting a breakpoint doesn't
176 have the side effect of inserting the locations of other
177 breakpoints that are marked not-inserted, but should_be_inserted
178 returns true on them.
180 This behavior is useful is situations close to tear-down -- e.g.,
181 after an exec, while the target still has execution, but
182 breakpoint shadows of the previous executable image should *NOT*
183 be restored to the new image; or before detaching, where the
184 target still has execution and wants to delete breakpoints from
185 GDB's lists, and all breakpoints had already been removed from
189 /* May insert breakpoints iff breakpoints_should_be_inserted_now
190 claims breakpoints should be inserted now. */
193 /* Insert locations now, irrespective of
194 breakpoints_should_be_inserted_now. E.g., say all threads are
195 stopped right now, and the user did "continue". We need to
196 insert breakpoints _before_ resuming the target, but
197 UGLL_MAY_INSERT wouldn't insert them, because
198 breakpoints_should_be_inserted_now returns false at that point,
199 as no thread is running yet. */
203 static void update_global_location_list (enum ugll_insert_mode
);
205 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
207 static void insert_breakpoint_locations (void);
209 static void trace_pass_command (const char *, int);
211 static void set_tracepoint_count (int num
);
213 static bool is_masked_watchpoint (const struct breakpoint
*b
);
215 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
218 static int strace_marker_p (struct breakpoint
*b
);
220 static void bkpt_probe_create_sals_from_location_spec
221 (location_spec
*locspec
,
222 struct linespec_result
*canonical
);
223 static void tracepoint_probe_create_sals_from_location_spec
224 (location_spec
*locspec
,
225 struct linespec_result
*canonical
);
227 const struct breakpoint_ops code_breakpoint_ops
=
229 create_sals_from_location_spec_default
,
230 create_breakpoints_sal
,
233 /* Breakpoints set on probes. */
234 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
236 bkpt_probe_create_sals_from_location_spec
,
237 create_breakpoints_sal
,
240 /* Tracepoints set on probes. */
241 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
243 tracepoint_probe_create_sals_from_location_spec
,
244 create_breakpoints_sal
,
247 /* Implementation of abstract dtors. These must exist to satisfy the
250 breakpoint::~breakpoint ()
254 code_breakpoint::~code_breakpoint ()
258 catchpoint::~catchpoint ()
262 /* The structure to be used in regular breakpoints. */
263 struct ordinary_breakpoint
: public code_breakpoint
265 using code_breakpoint::code_breakpoint
;
267 int resources_needed (const struct bp_location
*) override
;
268 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
269 void print_mention () const override
;
270 void print_recreate (struct ui_file
*fp
) const override
;
273 /* Internal breakpoints. These typically have a lifetime the same as
274 the program, and they end up installed on the breakpoint chain with
275 a negative breakpoint number. They're visible in "maint info
276 breakpoints", but not "info breakpoints". */
277 struct internal_breakpoint
: public code_breakpoint
279 internal_breakpoint (struct gdbarch
*gdbarch
,
280 enum bptype type
, CORE_ADDR address
)
281 : code_breakpoint (gdbarch
, type
)
285 sal
.section
= find_pc_overlay (sal
.pc
);
286 sal
.pspace
= current_program_space
;
289 pspace
= current_program_space
;
290 disposition
= disp_donttouch
;
293 void re_set () override
;
294 void check_status (struct bpstat
*bs
) override
;
295 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
296 void print_mention () const override
;
299 /* Momentary breakpoints. These typically have a lifetime of some run
300 control command only, are always thread-specific, and have 0 for
301 breakpoint number. I.e., there can be many momentary breakpoints
302 on the breakpoint chain and they all same the same number (zero).
303 They're visible in "maint info breakpoints", but not "info
305 struct momentary_breakpoint
: public code_breakpoint
307 momentary_breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
308 program_space
*pspace_
,
309 const struct frame_id
&frame_id_
,
311 : code_breakpoint (gdbarch_
, bptype
)
313 /* If FRAME_ID is valid, it should be a real frame, not an inlined
314 or tail-called one. */
315 gdb_assert (!frame_id_artificial_p (frame_id
));
317 /* Momentary breakpoints are always thread-specific. */
318 gdb_assert (thread_
> 0);
321 enable_state
= bp_enabled
;
322 disposition
= disp_donttouch
;
323 frame_id
= frame_id_
;
327 void re_set () override
;
328 void check_status (struct bpstat
*bs
) override
;
329 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
330 void print_mention () const override
;
333 /* DPrintf breakpoints. */
334 struct dprintf_breakpoint
: public ordinary_breakpoint
336 using ordinary_breakpoint::ordinary_breakpoint
;
338 void re_set () override
;
339 int breakpoint_hit (const struct bp_location
*bl
,
340 const address_space
*aspace
,
342 const target_waitstatus
&ws
) override
;
343 void print_recreate (struct ui_file
*fp
) const override
;
344 void after_condition_true (struct bpstat
*bs
) override
;
347 /* Ranged breakpoints. */
348 struct ranged_breakpoint
: public ordinary_breakpoint
350 explicit ranged_breakpoint (struct gdbarch
*gdbarch
,
351 const symtab_and_line
&sal_start
,
353 location_spec_up start_locspec
,
354 location_spec_up end_locspec
)
355 : ordinary_breakpoint (gdbarch
, bp_hardware_breakpoint
)
357 bp_location
*bl
= add_location (sal_start
);
360 disposition
= disp_donttouch
;
362 locspec
= std::move (start_locspec
);
363 locspec_range_end
= std::move (end_locspec
);
366 int breakpoint_hit (const struct bp_location
*bl
,
367 const address_space
*aspace
,
369 const target_waitstatus
&ws
) override
;
370 int resources_needed (const struct bp_location
*) override
;
371 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
372 bool print_one (bp_location
**) const override
;
373 void print_one_detail (struct ui_out
*) const override
;
374 void print_mention () const override
;
375 void print_recreate (struct ui_file
*fp
) const override
;
378 /* Static tracepoints with marker (`-m'). */
379 struct static_marker_tracepoint
: public tracepoint
381 using tracepoint::tracepoint
;
383 std::vector
<symtab_and_line
> decode_location_spec
384 (struct location_spec
*locspec
,
385 struct program_space
*search_pspace
) override
;
388 /* The style in which to perform a dynamic printf. This is a user
389 option because different output options have different tradeoffs;
390 if GDB does the printing, there is better error handling if there
391 is a problem with any of the arguments, but using an inferior
392 function lets you have special-purpose printers and sending of
393 output to the same place as compiled-in print functions. */
395 static const char dprintf_style_gdb
[] = "gdb";
396 static const char dprintf_style_call
[] = "call";
397 static const char dprintf_style_agent
[] = "agent";
398 static const char *const dprintf_style_enums
[] = {
404 static const char *dprintf_style
= dprintf_style_gdb
;
406 /* The function to use for dynamic printf if the preferred style is to
407 call into the inferior. The value is simply a string that is
408 copied into the command, so it can be anything that GDB can
409 evaluate to a callable address, not necessarily a function name. */
411 static std::string dprintf_function
= "printf";
413 /* The channel to use for dynamic printf if the preferred style is to
414 call into the inferior; if a nonempty string, it will be passed to
415 the call as the first argument, with the format string as the
416 second. As with the dprintf function, this can be anything that
417 GDB knows how to evaluate, so in addition to common choices like
418 "stderr", this could be an app-specific expression like
419 "mystreams[curlogger]". */
421 static std::string dprintf_channel
;
423 /* True if dprintf commands should continue to operate even if GDB
425 static bool disconnected_dprintf
= true;
427 struct command_line
*
428 breakpoint_commands (struct breakpoint
*b
)
430 return b
->commands
? b
->commands
.get () : NULL
;
433 /* Flag indicating that a command has proceeded the inferior past the
434 current breakpoint. */
436 static bool breakpoint_proceeded
;
439 bpdisp_text (enum bpdisp disp
)
441 /* NOTE: the following values are a part of MI protocol and
442 represent values of 'disp' field returned when inferior stops at
444 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
446 return bpdisps
[(int) disp
];
449 /* Prototypes for exported functions. */
450 /* If FALSE, gdb will not use hardware support for watchpoints, even
451 if such is available. */
452 static int can_use_hw_watchpoints
;
455 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
456 struct cmd_list_element
*c
,
460 _("Debugger's willingness to use "
461 "watchpoint hardware is %s.\n"),
465 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
466 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
467 for unrecognized breakpoint locations.
468 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
469 static enum auto_boolean pending_break_support
;
471 show_pending_break_support (struct ui_file
*file
, int from_tty
,
472 struct cmd_list_element
*c
,
476 _("Debugger's behavior regarding "
477 "pending breakpoints is %s.\n"),
481 /* If true, gdb will automatically use hardware breakpoints for breakpoints
482 set with "break" but falling in read-only memory.
483 If false, gdb will warn about such breakpoints, but won't automatically
484 use hardware breakpoints. */
485 static bool automatic_hardware_breakpoints
;
487 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
488 struct cmd_list_element
*c
,
492 _("Automatic usage of hardware breakpoints is %s.\n"),
496 /* If on, GDB keeps breakpoints inserted even if the inferior is
497 stopped, and immediately inserts any new breakpoints as soon as
498 they're created. If off (default), GDB keeps breakpoints off of
499 the target as long as possible. That is, it delays inserting
500 breakpoints until the next resume, and removes them again when the
501 target fully stops. This is a bit safer in case GDB crashes while
502 processing user input. */
503 static bool always_inserted_mode
= false;
506 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
507 struct cmd_list_element
*c
, const char *value
)
509 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
513 /* See breakpoint.h. */
516 breakpoints_should_be_inserted_now (void)
518 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
520 /* If breakpoints are global, they should be inserted even if no
521 thread under gdb's control is running, or even if there are
522 no threads under GDB's control yet. */
527 if (always_inserted_mode
)
529 /* The user wants breakpoints inserted even if all threads
534 for (inferior
*inf
: all_inferiors ())
535 if (inf
->has_execution ()
536 && threads_are_executing (inf
->process_target ()))
539 /* Don't remove breakpoints yet if, even though all threads are
540 stopped, we still have events to process. */
541 for (thread_info
*tp
: all_non_exited_threads ())
542 if (tp
->resumed () && tp
->has_pending_waitstatus ())
548 static const char condition_evaluation_both
[] = "host or target";
550 /* Modes for breakpoint condition evaluation. */
551 static const char condition_evaluation_auto
[] = "auto";
552 static const char condition_evaluation_host
[] = "host";
553 static const char condition_evaluation_target
[] = "target";
554 static const char *const condition_evaluation_enums
[] = {
555 condition_evaluation_auto
,
556 condition_evaluation_host
,
557 condition_evaluation_target
,
561 /* Global that holds the current mode for breakpoint condition evaluation. */
562 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
564 /* Global that we use to display information to the user (gets its value from
565 condition_evaluation_mode_1. */
566 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
568 /* Translate a condition evaluation mode MODE into either "host"
569 or "target". This is used mostly to translate from "auto" to the
570 real setting that is being used. It returns the translated
574 translate_condition_evaluation_mode (const char *mode
)
576 if (mode
== condition_evaluation_auto
)
578 if (target_supports_evaluation_of_breakpoint_conditions ())
579 return condition_evaluation_target
;
581 return condition_evaluation_host
;
587 /* Discovers what condition_evaluation_auto translates to. */
590 breakpoint_condition_evaluation_mode (void)
592 return translate_condition_evaluation_mode (condition_evaluation_mode
);
595 /* Return true if GDB should evaluate breakpoint conditions or false
599 gdb_evaluates_breakpoint_condition_p (void)
601 const char *mode
= breakpoint_condition_evaluation_mode ();
603 return (mode
== condition_evaluation_host
);
606 /* Are we executing breakpoint commands? */
607 static int executing_breakpoint_commands
;
609 /* Are overlay event breakpoints enabled? */
610 static int overlay_events_enabled
;
612 /* See description in breakpoint.h. */
613 bool target_exact_watchpoints
= false;
615 /* Walk the following statement or block through all breakpoints.
616 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
617 current breakpoint. */
619 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
620 for (B = breakpoint_chain; \
621 B ? (TMP=B->next, 1): 0; \
624 /* Chains of all breakpoints defined. */
626 static struct breakpoint
*breakpoint_chain
;
628 /* See breakpoint.h. */
633 return breakpoint_range (breakpoint_chain
);
636 /* See breakpoint.h. */
638 breakpoint_safe_range
639 all_breakpoints_safe ()
641 return breakpoint_safe_range (all_breakpoints ());
644 /* See breakpoint.h. */
649 return tracepoint_range (breakpoint_chain
);
652 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
654 static std::vector
<bp_location
*> bp_locations
;
656 /* See breakpoint.h. */
658 const std::vector
<bp_location
*> &
664 /* Range to iterate over breakpoint locations at a given address. */
666 struct bp_locations_at_addr_range
668 using iterator
= std::vector
<bp_location
*>::iterator
;
670 bp_locations_at_addr_range (CORE_ADDR addr
)
674 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
675 { return loc
->address
< addr_
; }
677 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
678 { return addr_
< loc
->address
; }
681 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
684 m_begin
= it_pair
.first
;
685 m_end
= it_pair
.second
;
688 iterator
begin () const
691 iterator
end () const
699 /* Return a range to iterate over all breakpoint locations exactly at address
702 If it's needed to iterate multiple times on the same range, it's possible
703 to save the range in a local variable and use it multiple times:
705 auto range = all_bp_locations_at_addr (addr);
707 for (bp_location *loc : range)
710 for (bp_location *loc : range)
713 This saves a bit of time, as it avoids re-doing the binary searches to find
714 the range's boundaries. Just remember not to change the bp_locations vector
715 in the mean time, as it could make the range's iterators stale. */
717 static bp_locations_at_addr_range
718 all_bp_locations_at_addr (CORE_ADDR addr
)
720 return bp_locations_at_addr_range (addr
);
723 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
724 ADDRESS for the current elements of BP_LOCATIONS which get a valid
725 result from bp_location_has_shadow. You can use it for roughly
726 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
727 an address you need to read. */
729 static CORE_ADDR bp_locations_placed_address_before_address_max
;
731 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
732 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
733 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
734 You can use it for roughly limiting the subrange of BP_LOCATIONS to
735 scan for shadow bytes for an address you need to read. */
737 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
739 /* The locations that no longer correspond to any breakpoint, unlinked
740 from the bp_locations array, but for which a hit may still be
741 reported by a target. */
742 static std::vector
<bp_location
*> moribund_locations
;
744 /* Number of last breakpoint made. */
746 static int breakpoint_count
;
748 /* The value of `breakpoint_count' before the last command that
749 created breakpoints. If the last (break-like) command created more
750 than one breakpoint, then the difference between BREAKPOINT_COUNT
751 and PREV_BREAKPOINT_COUNT is more than one. */
752 static int prev_breakpoint_count
;
754 /* Number of last tracepoint made. */
756 static int tracepoint_count
;
758 static struct cmd_list_element
*breakpoint_set_cmdlist
;
759 static struct cmd_list_element
*breakpoint_show_cmdlist
;
760 struct cmd_list_element
*save_cmdlist
;
762 /* Return whether a breakpoint is an active enabled breakpoint. */
764 breakpoint_enabled (struct breakpoint
*b
)
766 return (b
->enable_state
== bp_enabled
);
769 /* Set breakpoint count to NUM. */
772 set_breakpoint_count (int num
)
774 prev_breakpoint_count
= breakpoint_count
;
775 breakpoint_count
= num
;
776 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
779 /* Used by `start_rbreak_breakpoints' below, to record the current
780 breakpoint count before "rbreak" creates any breakpoint. */
781 static int rbreak_start_breakpoint_count
;
783 /* Called at the start an "rbreak" command to record the first
786 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
788 rbreak_start_breakpoint_count
= breakpoint_count
;
791 /* Called at the end of an "rbreak" command to record the last
794 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
796 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
799 /* Used in run_command to zero the hit count when a new run starts. */
802 clear_breakpoint_hit_counts (void)
804 for (breakpoint
*b
: all_breakpoints ())
809 /* Return the breakpoint with the specified number, or NULL
810 if the number does not refer to an existing breakpoint. */
813 get_breakpoint (int num
)
815 for (breakpoint
*b
: all_breakpoints ())
816 if (b
->number
== num
)
824 /* Mark locations as "conditions have changed" in case the target supports
825 evaluating conditions on its side. */
828 mark_breakpoint_modified (struct breakpoint
*b
)
830 /* This is only meaningful if the target is
831 evaluating conditions and if the user has
832 opted for condition evaluation on the target's
834 if (gdb_evaluates_breakpoint_condition_p ()
835 || !target_supports_evaluation_of_breakpoint_conditions ())
838 if (!is_breakpoint (b
))
841 for (bp_location
*loc
: b
->locations ())
842 loc
->condition_changed
= condition_modified
;
845 /* Mark location as "conditions have changed" in case the target supports
846 evaluating conditions on its side. */
849 mark_breakpoint_location_modified (struct bp_location
*loc
)
851 /* This is only meaningful if the target is
852 evaluating conditions and if the user has
853 opted for condition evaluation on the target's
855 if (gdb_evaluates_breakpoint_condition_p ()
856 || !target_supports_evaluation_of_breakpoint_conditions ())
860 if (!is_breakpoint (loc
->owner
))
863 loc
->condition_changed
= condition_modified
;
866 /* Sets the condition-evaluation mode using the static global
867 condition_evaluation_mode. */
870 set_condition_evaluation_mode (const char *args
, int from_tty
,
871 struct cmd_list_element
*c
)
873 const char *old_mode
, *new_mode
;
875 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
876 && !target_supports_evaluation_of_breakpoint_conditions ())
878 condition_evaluation_mode_1
= condition_evaluation_mode
;
879 warning (_("Target does not support breakpoint condition evaluation.\n"
880 "Using host evaluation mode instead."));
884 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
885 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
887 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
888 settings was "auto". */
889 condition_evaluation_mode
= condition_evaluation_mode_1
;
891 /* Only update the mode if the user picked a different one. */
892 if (new_mode
!= old_mode
)
894 /* If the user switched to a different evaluation mode, we
895 need to synch the changes with the target as follows:
897 "host" -> "target": Send all (valid) conditions to the target.
898 "target" -> "host": Remove all the conditions from the target.
901 if (new_mode
== condition_evaluation_target
)
903 /* Mark everything modified and synch conditions with the
905 for (bp_location
*loc
: all_bp_locations ())
906 mark_breakpoint_location_modified (loc
);
910 /* Manually mark non-duplicate locations to synch conditions
911 with the target. We do this to remove all the conditions the
912 target knows about. */
913 for (bp_location
*loc
: all_bp_locations ())
914 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
915 loc
->needs_update
= 1;
919 update_global_location_list (UGLL_MAY_INSERT
);
925 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
926 what "auto" is translating to. */
929 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
930 struct cmd_list_element
*c
, const char *value
)
932 if (condition_evaluation_mode
== condition_evaluation_auto
)
934 _("Breakpoint condition evaluation "
935 "mode is %s (currently %s).\n"),
937 breakpoint_condition_evaluation_mode ());
939 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
943 /* Parse COND_STRING in the context of LOC and set as the condition
944 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
945 the number of LOC within its owner. In case of parsing error, mark
946 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
949 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
950 int bp_num
, int loc_num
)
952 bool has_junk
= false;
955 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
956 block_for_pc (loc
->address
), 0);
957 if (*cond_string
!= 0)
961 loc
->cond
= std::move (new_exp
);
962 if (loc
->disabled_by_cond
&& loc
->enabled
)
963 gdb_printf (_("Breakpoint %d's condition is now valid at "
964 "location %d, enabling.\n"),
967 loc
->disabled_by_cond
= false;
970 catch (const gdb_exception_error
&e
)
974 /* Warn if a user-enabled location is now becoming disabled-by-cond.
975 BP_NUM is 0 if the breakpoint is being defined for the first
976 time using the "break ... if ..." command, and non-zero if
979 warning (_("failed to validate condition at location %d.%d, "
980 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
982 warning (_("failed to validate condition at location %d, "
983 "disabling:\n %s"), loc_num
, e
.what ());
986 loc
->disabled_by_cond
= true;
990 error (_("Garbage '%s' follows condition"), cond_string
);
994 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
995 int from_tty
, bool force
)
999 b
->cond_string
.reset ();
1001 if (is_watchpoint (b
))
1002 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
1006 for (bp_location
*loc
: b
->locations ())
1009 if (loc
->disabled_by_cond
&& loc
->enabled
)
1010 gdb_printf (_("Breakpoint %d's condition is now valid at "
1011 "location %d, enabling.\n"),
1012 b
->number
, loc_num
);
1013 loc
->disabled_by_cond
= false;
1016 /* No need to free the condition agent expression
1017 bytecode (if we have one). We will handle this
1018 when we go through update_global_location_list. */
1023 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
1027 if (is_watchpoint (b
))
1029 innermost_block_tracker tracker
;
1030 const char *arg
= exp
;
1031 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
1033 error (_("Junk at end of expression"));
1034 watchpoint
*w
= static_cast<watchpoint
*> (b
);
1035 w
->cond_exp
= std::move (new_exp
);
1036 w
->cond_exp_valid_block
= tracker
.block ();
1040 /* Parse and set condition expressions. We make two passes.
1041 In the first, we parse the condition string to see if it
1042 is valid in at least one location. If so, the condition
1043 would be accepted. So we go ahead and set the locations'
1044 conditions. In case no valid case is found, we throw
1045 the error and the condition string will be rejected.
1046 This two-pass approach is taken to avoid setting the
1047 state of locations in case of a reject. */
1048 for (bp_location
*loc
: b
->locations ())
1052 const char *arg
= exp
;
1053 parse_exp_1 (&arg
, loc
->address
,
1054 block_for_pc (loc
->address
), 0);
1056 error (_("Junk at end of expression"));
1059 catch (const gdb_exception_error
&e
)
1061 /* Condition string is invalid. If this happens to
1062 be the last loc, abandon (if not forced) or continue
1064 if (loc
->next
== nullptr && !force
)
1069 /* If we reach here, the condition is valid at some locations. */
1071 for (bp_location
*loc
: b
->locations ())
1073 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
1078 /* We know that the new condition parsed successfully. The
1079 condition string of the breakpoint can be safely updated. */
1080 b
->cond_string
= make_unique_xstrdup (exp
);
1081 b
->condition_not_parsed
= 0;
1083 mark_breakpoint_modified (b
);
1085 gdb::observers::breakpoint_modified
.notify (b
);
1088 /* See breakpoint.h. */
1091 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1094 for (breakpoint
*b
: all_breakpoints ())
1095 if (b
->number
== bpnum
)
1097 /* Check if this breakpoint has a "stop" method implemented in an
1098 extension language. This method and conditions entered into GDB
1099 from the CLI are mutually exclusive. */
1100 const struct extension_language_defn
*extlang
1101 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1103 if (extlang
!= NULL
)
1105 error (_("Only one stop condition allowed. There is currently"
1106 " a %s stop condition defined for this breakpoint."),
1107 ext_lang_capitalized_name (extlang
));
1109 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1111 if (is_breakpoint (b
))
1112 update_global_location_list (UGLL_MAY_INSERT
);
1117 error (_("No breakpoint number %d."), bpnum
);
1120 /* The options for the "condition" command. */
1122 struct condition_command_opts
1125 bool force_condition
= false;
1128 static const gdb::option::option_def condition_command_option_defs
[] = {
1130 gdb::option::flag_option_def
<condition_command_opts
> {
1132 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1133 N_("Set the condition even if it is invalid for all current locations."),
1138 /* Create an option_def_group for the "condition" options, with
1139 CC_OPTS as context. */
1141 static inline gdb::option::option_def_group
1142 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1144 return {{condition_command_option_defs
}, cc_opts
};
1147 /* Completion for the "condition" command. */
1150 condition_completer (struct cmd_list_element
*cmd
,
1151 completion_tracker
&tracker
,
1152 const char *text
, const char * /*word*/)
1154 bool has_no_arguments
= (*text
== '\0');
1155 condition_command_opts cc_opts
;
1156 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1157 if (gdb::option::complete_options
1158 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1161 text
= skip_spaces (text
);
1162 const char *space
= skip_to_space (text
);
1169 tracker
.advance_custom_word_point_by (1);
1170 /* We don't support completion of history indices. */
1171 if (!isdigit (text
[1]))
1172 complete_internalvar (tracker
, &text
[1]);
1176 /* Suggest the "-force" flag if no arguments are given. If
1177 arguments were passed, they either already include the flag,
1178 or we are beyond the point of suggesting it because it's
1179 positionally the first argument. */
1180 if (has_no_arguments
)
1181 gdb::option::complete_on_all_options (tracker
, group
);
1183 /* We're completing the breakpoint number. */
1184 len
= strlen (text
);
1186 for (breakpoint
*b
: all_breakpoints ())
1190 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1192 if (strncmp (number
, text
, len
) == 0)
1193 tracker
.add_completion (make_unique_xstrdup (number
));
1199 /* We're completing the expression part. Skip the breakpoint num. */
1200 const char *exp_start
= skip_spaces (space
);
1201 tracker
.advance_custom_word_point_by (exp_start
- text
);
1203 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1204 expression_completer (cmd
, tracker
, text
, word
);
1207 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1210 condition_command (const char *arg
, int from_tty
)
1216 error_no_arg (_("breakpoint number"));
1220 /* Check if the "-force" flag was passed. */
1221 condition_command_opts cc_opts
;
1222 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1223 gdb::option::process_options
1224 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1226 bnum
= get_number (&p
);
1228 error (_("Bad breakpoint argument: '%s'"), arg
);
1230 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1233 /* Check that COMMAND do not contain commands that are suitable
1234 only for tracepoints and not suitable for ordinary breakpoints.
1235 Throw if any such commands is found. */
1238 check_no_tracepoint_commands (struct command_line
*commands
)
1240 struct command_line
*c
;
1242 for (c
= commands
; c
; c
= c
->next
)
1244 if (c
->control_type
== while_stepping_control
)
1245 error (_("The 'while-stepping' command can "
1246 "only be used for tracepoints"));
1248 check_no_tracepoint_commands (c
->body_list_0
.get ());
1249 check_no_tracepoint_commands (c
->body_list_1
.get ());
1251 /* Not that command parsing removes leading whitespace and comment
1252 lines and also empty lines. So, we only need to check for
1253 command directly. */
1254 if (strstr (c
->line
, "collect ") == c
->line
)
1255 error (_("The 'collect' command can only be used for tracepoints"));
1257 if (strstr (c
->line
, "teval ") == c
->line
)
1258 error (_("The 'teval' command can only be used for tracepoints"));
1262 struct longjmp_breakpoint
: public momentary_breakpoint
1264 using momentary_breakpoint::momentary_breakpoint
;
1266 ~longjmp_breakpoint () override
;
1269 /* Encapsulate tests for different types of tracepoints. */
1272 is_tracepoint_type (bptype type
)
1274 return (type
== bp_tracepoint
1275 || type
== bp_fast_tracepoint
1276 || type
== bp_static_tracepoint
1277 || type
== bp_static_marker_tracepoint
);
1280 /* See breakpoint.h. */
1283 is_tracepoint (const struct breakpoint
*b
)
1285 return is_tracepoint_type (b
->type
);
1288 /* Factory function to create an appropriate instance of breakpoint given
1291 template<typename
... Arg
>
1292 static std::unique_ptr
<code_breakpoint
>
1293 new_breakpoint_from_type (struct gdbarch
*gdbarch
, bptype type
,
1301 case bp_hardware_breakpoint
:
1302 b
= new ordinary_breakpoint (gdbarch
, type
,
1303 std::forward
<Arg
> (args
)...);
1306 case bp_fast_tracepoint
:
1307 case bp_static_tracepoint
:
1309 b
= new tracepoint (gdbarch
, type
,
1310 std::forward
<Arg
> (args
)...);
1313 case bp_static_marker_tracepoint
:
1314 b
= new static_marker_tracepoint (gdbarch
, type
,
1315 std::forward
<Arg
> (args
)...);
1319 b
= new dprintf_breakpoint (gdbarch
, type
,
1320 std::forward
<Arg
> (args
)...);
1324 gdb_assert_not_reached ("invalid type");
1327 return std::unique_ptr
<code_breakpoint
> (b
);
1330 /* A helper function that validates that COMMANDS are valid for a
1331 breakpoint. This function will throw an exception if a problem is
1335 validate_commands_for_breakpoint (struct breakpoint
*b
,
1336 struct command_line
*commands
)
1338 if (is_tracepoint (b
))
1340 struct tracepoint
*t
= (struct tracepoint
*) b
;
1341 struct command_line
*c
;
1342 struct command_line
*while_stepping
= 0;
1344 /* Reset the while-stepping step count. The previous commands
1345 might have included a while-stepping action, while the new
1349 /* We need to verify that each top-level element of commands is
1350 valid for tracepoints, that there's at most one
1351 while-stepping element, and that the while-stepping's body
1352 has valid tracing commands excluding nested while-stepping.
1353 We also need to validate the tracepoint action line in the
1354 context of the tracepoint --- validate_actionline actually
1355 has side effects, like setting the tracepoint's
1356 while-stepping STEP_COUNT, in addition to checking if the
1357 collect/teval actions parse and make sense in the
1358 tracepoint's context. */
1359 for (c
= commands
; c
; c
= c
->next
)
1361 if (c
->control_type
== while_stepping_control
)
1363 if (b
->type
== bp_fast_tracepoint
)
1364 error (_("The 'while-stepping' command "
1365 "cannot be used for fast tracepoint"));
1366 else if (b
->type
== bp_static_tracepoint
1367 || b
->type
== bp_static_marker_tracepoint
)
1368 error (_("The 'while-stepping' command "
1369 "cannot be used for static tracepoint"));
1372 error (_("The 'while-stepping' command "
1373 "can be used only once"));
1378 validate_actionline (c
->line
, b
);
1382 struct command_line
*c2
;
1384 gdb_assert (while_stepping
->body_list_1
== nullptr);
1385 c2
= while_stepping
->body_list_0
.get ();
1386 for (; c2
; c2
= c2
->next
)
1388 if (c2
->control_type
== while_stepping_control
)
1389 error (_("The 'while-stepping' command cannot be nested"));
1395 check_no_tracepoint_commands (commands
);
1399 /* Return a vector of all the static tracepoints set at ADDR. The
1400 caller is responsible for releasing the vector. */
1402 std::vector
<breakpoint
*>
1403 static_tracepoints_here (CORE_ADDR addr
)
1405 std::vector
<breakpoint
*> found
;
1407 for (breakpoint
*b
: all_breakpoints ())
1408 if (b
->type
== bp_static_tracepoint
1409 || b
->type
== bp_static_marker_tracepoint
)
1411 for (bp_location
*loc
: b
->locations ())
1412 if (loc
->address
== addr
)
1413 found
.push_back (b
);
1419 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1420 validate that only allowed commands are included. */
1423 breakpoint_set_commands (struct breakpoint
*b
,
1424 counted_command_line
&&commands
)
1426 validate_commands_for_breakpoint (b
, commands
.get ());
1428 b
->commands
= std::move (commands
);
1429 gdb::observers::breakpoint_modified
.notify (b
);
1432 /* Set the internal `silent' flag on the breakpoint. Note that this
1433 is not the same as the "silent" that may appear in the breakpoint's
1437 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1439 int old_silent
= b
->silent
;
1442 if (old_silent
!= silent
)
1443 gdb::observers::breakpoint_modified
.notify (b
);
1446 /* Set the thread for this breakpoint. If THREAD is -1, make the
1447 breakpoint work for any thread. */
1450 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1452 int old_thread
= b
->thread
;
1455 if (old_thread
!= thread
)
1456 gdb::observers::breakpoint_modified
.notify (b
);
1459 /* Set the task for this breakpoint. If TASK is 0, make the
1460 breakpoint work for any task. */
1463 breakpoint_set_task (struct breakpoint
*b
, int task
)
1465 int old_task
= b
->task
;
1468 if (old_task
!= task
)
1469 gdb::observers::breakpoint_modified
.notify (b
);
1473 commands_command_1 (const char *arg
, int from_tty
,
1474 struct command_line
*control
)
1476 counted_command_line cmd
;
1477 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1478 NULL after the call to read_command_lines if the user provides an empty
1479 list of command by just typing "end". */
1480 bool cmd_read
= false;
1482 std::string new_arg
;
1484 if (arg
== NULL
|| !*arg
)
1486 /* Argument not explicitly given. Synthesize it. */
1487 if (breakpoint_count
- prev_breakpoint_count
> 1)
1488 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1490 else if (breakpoint_count
> 0)
1491 new_arg
= string_printf ("%d", breakpoint_count
);
1495 /* Create a copy of ARG. This is needed because the "commands"
1496 command may be coming from a script. In that case, the read
1497 line buffer is going to be overwritten in the lambda of
1498 'map_breakpoint_numbers' below when reading the next line
1499 before we are are done parsing the breakpoint numbers. */
1502 arg
= new_arg
.c_str ();
1504 map_breakpoint_numbers
1505 (arg
, [&] (breakpoint
*b
)
1509 gdb_assert (cmd
== NULL
);
1510 if (control
!= NULL
)
1511 cmd
= control
->body_list_0
;
1515 = string_printf (_("Type commands for breakpoint(s) "
1516 "%s, one per line."),
1519 auto do_validate
= [=] (const char *line
)
1521 validate_actionline (line
, b
);
1523 gdb::function_view
<void (const char *)> validator
;
1524 if (is_tracepoint (b
))
1525 validator
= do_validate
;
1527 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1532 /* If a breakpoint was on the list more than once, we don't need to
1534 if (b
->commands
!= cmd
)
1536 validate_commands_for_breakpoint (b
, cmd
.get ());
1538 gdb::observers::breakpoint_modified
.notify (b
);
1544 commands_command (const char *arg
, int from_tty
)
1546 commands_command_1 (arg
, from_tty
, NULL
);
1549 /* Like commands_command, but instead of reading the commands from
1550 input stream, takes them from an already parsed command structure.
1552 This is used by cli-script.c to DTRT with breakpoint commands
1553 that are part of if and while bodies. */
1554 enum command_control_type
1555 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1557 commands_command_1 (arg
, 0, cmd
);
1558 return simple_control
;
1561 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1564 bp_location_has_shadow (struct bp_location
*bl
)
1566 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1570 if (bl
->target_info
.shadow_len
== 0)
1571 /* BL isn't valid, or doesn't shadow memory. */
1576 /* Update BUF, which is LEN bytes read from the target address
1577 MEMADDR, by replacing a memory breakpoint with its shadowed
1580 If READBUF is not NULL, this buffer must not overlap with the of
1581 the breakpoint location's shadow_contents buffer. Otherwise, a
1582 failed assertion internal error will be raised. */
1585 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1586 const gdb_byte
*writebuf_org
,
1587 ULONGEST memaddr
, LONGEST len
,
1588 struct bp_target_info
*target_info
,
1589 struct gdbarch
*gdbarch
)
1591 /* Now do full processing of the found relevant range of elements. */
1592 CORE_ADDR bp_addr
= 0;
1596 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1597 current_program_space
->aspace
, 0))
1599 /* The breakpoint is inserted in a different address space. */
1603 /* Addresses and length of the part of the breakpoint that
1605 bp_addr
= target_info
->placed_address
;
1606 bp_size
= target_info
->shadow_len
;
1608 if (bp_addr
+ bp_size
<= memaddr
)
1610 /* The breakpoint is entirely before the chunk of memory we are
1615 if (bp_addr
>= memaddr
+ len
)
1617 /* The breakpoint is entirely after the chunk of memory we are
1622 /* Offset within shadow_contents. */
1623 if (bp_addr
< memaddr
)
1625 /* Only copy the second part of the breakpoint. */
1626 bp_size
-= memaddr
- bp_addr
;
1627 bptoffset
= memaddr
- bp_addr
;
1631 if (bp_addr
+ bp_size
> memaddr
+ len
)
1633 /* Only copy the first part of the breakpoint. */
1634 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1637 if (readbuf
!= NULL
)
1639 /* Verify that the readbuf buffer does not overlap with the
1640 shadow_contents buffer. */
1641 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1642 || readbuf
>= (target_info
->shadow_contents
1643 + target_info
->shadow_len
));
1645 /* Update the read buffer with this inserted breakpoint's
1647 memcpy (readbuf
+ bp_addr
- memaddr
,
1648 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1652 const unsigned char *bp
;
1653 CORE_ADDR addr
= target_info
->reqstd_address
;
1656 /* Update the shadow with what we want to write to memory. */
1657 memcpy (target_info
->shadow_contents
+ bptoffset
,
1658 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1660 /* Determine appropriate breakpoint contents and size for this
1662 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1664 /* Update the final write buffer with this inserted
1665 breakpoint's INSN. */
1666 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1670 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1671 by replacing any memory breakpoints with their shadowed contents.
1673 If READBUF is not NULL, this buffer must not overlap with any of
1674 the breakpoint location's shadow_contents buffers. Otherwise,
1675 a failed assertion internal error will be raised.
1677 The range of shadowed area by each bp_location is:
1678 bl->address - bp_locations_placed_address_before_address_max
1679 up to bl->address + bp_locations_shadow_len_after_address_max
1680 The range we were requested to resolve shadows for is:
1681 memaddr ... memaddr + len
1682 Thus the safe cutoff boundaries for performance optimization are
1683 memaddr + len <= (bl->address
1684 - bp_locations_placed_address_before_address_max)
1686 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1689 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1690 const gdb_byte
*writebuf_org
,
1691 ULONGEST memaddr
, LONGEST len
)
1693 /* Left boundary, right boundary and median element of our binary
1695 unsigned bc_l
, bc_r
, bc
;
1697 /* Find BC_L which is a leftmost element which may affect BUF
1698 content. It is safe to report lower value but a failure to
1699 report higher one. */
1702 bc_r
= bp_locations
.size ();
1703 while (bc_l
+ 1 < bc_r
)
1705 struct bp_location
*bl
;
1707 bc
= (bc_l
+ bc_r
) / 2;
1708 bl
= bp_locations
[bc
];
1710 /* Check first BL->ADDRESS will not overflow due to the added
1711 constant. Then advance the left boundary only if we are sure
1712 the BC element can in no way affect the BUF content (MEMADDR
1713 to MEMADDR + LEN range).
1715 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1716 offset so that we cannot miss a breakpoint with its shadow
1717 range tail still reaching MEMADDR. */
1719 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1721 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1728 /* Due to the binary search above, we need to make sure we pick the
1729 first location that's at BC_L's address. E.g., if there are
1730 multiple locations at the same address, BC_L may end up pointing
1731 at a duplicate location, and miss the "master"/"inserted"
1732 location. Say, given locations L1, L2 and L3 at addresses A and
1735 L1@A, L2@A, L3@B, ...
1737 BC_L could end up pointing at location L2, while the "master"
1738 location could be L1. Since the `loc->inserted' flag is only set
1739 on "master" locations, we'd forget to restore the shadow of L1
1742 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1745 /* Now do full processing of the found relevant range of elements. */
1747 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1749 struct bp_location
*bl
= bp_locations
[bc
];
1751 /* bp_location array has BL->OWNER always non-NULL. */
1752 if (bl
->owner
->type
== bp_none
)
1753 warning (_("reading through apparently deleted breakpoint #%d?"),
1756 /* Performance optimization: any further element can no longer affect BUF
1759 if (bl
->address
>= bp_locations_placed_address_before_address_max
1762 - bp_locations_placed_address_before_address_max
)))
1765 if (!bp_location_has_shadow (bl
))
1768 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1769 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1773 /* See breakpoint.h. */
1776 is_breakpoint (const struct breakpoint
*bpt
)
1778 return (bpt
->type
== bp_breakpoint
1779 || bpt
->type
== bp_hardware_breakpoint
1780 || bpt
->type
== bp_dprintf
);
1783 /* Return true if BPT is of any hardware watchpoint kind. */
1786 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1788 return (bpt
->type
== bp_hardware_watchpoint
1789 || bpt
->type
== bp_read_watchpoint
1790 || bpt
->type
== bp_access_watchpoint
);
1793 /* See breakpoint.h. */
1796 is_watchpoint (const struct breakpoint
*bpt
)
1798 return (is_hardware_watchpoint (bpt
)
1799 || bpt
->type
== bp_watchpoint
);
1802 /* Returns true if the current thread and its running state are safe
1803 to evaluate or update watchpoint B. Watchpoints on local
1804 expressions need to be evaluated in the context of the thread that
1805 was current when the watchpoint was created, and, that thread needs
1806 to be stopped to be able to select the correct frame context.
1807 Watchpoints on global expressions can be evaluated on any thread,
1808 and in any state. It is presently left to the target allowing
1809 memory accesses when threads are running. */
1812 watchpoint_in_thread_scope (struct watchpoint
*b
)
1814 return (b
->pspace
== current_program_space
1815 && (b
->watchpoint_thread
== null_ptid
1816 || (inferior_ptid
== b
->watchpoint_thread
1817 && !inferior_thread ()->executing ())));
1820 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1821 associated bp_watchpoint_scope breakpoint. */
1824 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1826 if (w
->related_breakpoint
!= w
)
1828 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1829 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1830 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1831 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1832 w
->related_breakpoint
= w
;
1834 w
->disposition
= disp_del_at_next_stop
;
1837 /* Extract a bitfield value from value VAL using the bit parameters contained in
1840 static struct value
*
1841 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1843 struct value
*bit_val
;
1848 bit_val
= allocate_value (value_type (val
));
1850 unpack_value_bitfield (bit_val
,
1853 value_contents_for_printing (val
).data (),
1860 /* Allocate a dummy location and add it to B. This is required
1861 because bpstat_stop_status requires a location to be able to report
1865 add_dummy_location (struct breakpoint
*b
,
1866 struct program_space
*pspace
)
1868 gdb_assert (b
->loc
== NULL
);
1870 b
->loc
= new bp_location (b
, bp_loc_other
);
1871 b
->loc
->pspace
= pspace
;
1874 /* Assuming that B is a watchpoint:
1875 - Reparse watchpoint expression, if REPARSE is non-zero
1876 - Evaluate expression and store the result in B->val
1877 - Evaluate the condition if there is one, and store the result
1879 - Update the list of values that must be watched in B->loc.
1881 If the watchpoint disposition is disp_del_at_next_stop, then do
1882 nothing. If this is local watchpoint that is out of scope, delete
1885 Even with `set breakpoint always-inserted on' the watchpoints are
1886 removed + inserted on each stop here. Normal breakpoints must
1887 never be removed because they might be missed by a running thread
1888 when debugging in non-stop mode. On the other hand, hardware
1889 watchpoints (is_hardware_watchpoint; processed here) are specific
1890 to each LWP since they are stored in each LWP's hardware debug
1891 registers. Therefore, such LWP must be stopped first in order to
1892 be able to modify its hardware watchpoints.
1894 Hardware watchpoints must be reset exactly once after being
1895 presented to the user. It cannot be done sooner, because it would
1896 reset the data used to present the watchpoint hit to the user. And
1897 it must not be done later because it could display the same single
1898 watchpoint hit during multiple GDB stops. Note that the latter is
1899 relevant only to the hardware watchpoint types bp_read_watchpoint
1900 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1901 not user-visible - its hit is suppressed if the memory content has
1904 The following constraints influence the location where we can reset
1905 hardware watchpoints:
1907 * target_stopped_by_watchpoint and target_stopped_data_address are
1908 called several times when GDB stops.
1911 * Multiple hardware watchpoints can be hit at the same time,
1912 causing GDB to stop. GDB only presents one hardware watchpoint
1913 hit at a time as the reason for stopping, and all the other hits
1914 are presented later, one after the other, each time the user
1915 requests the execution to be resumed. Execution is not resumed
1916 for the threads still having pending hit event stored in
1917 LWP_INFO->STATUS. While the watchpoint is already removed from
1918 the inferior on the first stop the thread hit event is kept being
1919 reported from its cached value by linux_nat_stopped_data_address
1920 until the real thread resume happens after the watchpoint gets
1921 presented and thus its LWP_INFO->STATUS gets reset.
1923 Therefore the hardware watchpoint hit can get safely reset on the
1924 watchpoint removal from inferior. */
1927 update_watchpoint (struct watchpoint
*b
, int reparse
)
1929 int within_current_scope
;
1930 struct frame_id saved_frame_id
;
1933 /* If this is a local watchpoint, we only want to check if the
1934 watchpoint frame is in scope if the current thread is the thread
1935 that was used to create the watchpoint. */
1936 if (!watchpoint_in_thread_scope (b
))
1939 if (b
->disposition
== disp_del_at_next_stop
)
1944 /* Determine if the watchpoint is within scope. */
1945 if (b
->exp_valid_block
== NULL
)
1946 within_current_scope
= 1;
1949 struct frame_info
*fi
= get_current_frame ();
1950 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1951 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1953 /* If we're at a point where the stack has been destroyed
1954 (e.g. in a function epilogue), unwinding may not work
1955 properly. Do not attempt to recreate locations at this
1956 point. See similar comments in watchpoint_check. */
1957 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1960 /* Save the current frame's ID so we can restore it after
1961 evaluating the watchpoint expression on its own frame. */
1962 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1963 took a frame parameter, so that we didn't have to change the
1966 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1968 fi
= frame_find_by_id (b
->watchpoint_frame
);
1969 within_current_scope
= (fi
!= NULL
);
1970 if (within_current_scope
)
1974 /* We don't free locations. They are stored in the bp_location array
1975 and update_global_location_list will eventually delete them and
1976 remove breakpoints if needed. */
1979 if (within_current_scope
&& reparse
)
1984 s
= (b
->exp_string_reparse
1985 ? b
->exp_string_reparse
.get ()
1986 : b
->exp_string
.get ());
1987 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1988 /* If the meaning of expression itself changed, the old value is
1989 no longer relevant. We don't want to report a watchpoint hit
1990 to the user when the old value and the new value may actually
1991 be completely different objects. */
1993 b
->val_valid
= false;
1995 /* Note that unlike with breakpoints, the watchpoint's condition
1996 expression is stored in the breakpoint object, not in the
1997 locations (re)created below. */
1998 if (b
->cond_string
!= NULL
)
2000 b
->cond_exp
.reset ();
2002 s
= b
->cond_string
.get ();
2003 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
2007 /* If we failed to parse the expression, for example because
2008 it refers to a global variable in a not-yet-loaded shared library,
2009 don't try to insert watchpoint. We don't automatically delete
2010 such watchpoint, though, since failure to parse expression
2011 is different from out-of-scope watchpoint. */
2012 if (!target_has_execution ())
2014 /* Without execution, memory can't change. No use to try and
2015 set watchpoint locations. The watchpoint will be reset when
2016 the target gains execution, through breakpoint_re_set. */
2017 if (!can_use_hw_watchpoints
)
2019 if (b
->works_in_software_mode ())
2020 b
->type
= bp_watchpoint
;
2022 error (_("Can't set read/access watchpoint when "
2023 "hardware watchpoints are disabled."));
2026 else if (within_current_scope
&& b
->exp
)
2028 std::vector
<value_ref_ptr
> val_chain
;
2029 struct value
*v
, *result
;
2030 struct program_space
*frame_pspace
;
2032 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2035 /* Avoid setting b->val if it's already set. The meaning of
2036 b->val is 'the last value' user saw, and we should update
2037 it only if we reported that last value to user. As it
2038 happens, the code that reports it updates b->val directly.
2039 We don't keep track of the memory value for masked
2041 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2043 if (b
->val_bitsize
!= 0)
2044 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2045 b
->val
= release_value (v
);
2046 b
->val_valid
= true;
2049 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2051 /* Look at each value on the value chain. */
2052 gdb_assert (!val_chain
.empty ());
2053 for (const value_ref_ptr
&iter
: val_chain
)
2057 /* If it's a memory location, and GDB actually needed
2058 its contents to evaluate the expression, then we
2059 must watch it. If the first value returned is
2060 still lazy, that means an error occurred reading it;
2061 watch it anyway in case it becomes readable. */
2062 if (VALUE_LVAL (v
) == lval_memory
2063 && (v
== val_chain
[0] || ! value_lazy (v
)))
2065 struct type
*vtype
= check_typedef (value_type (v
));
2067 /* We only watch structs and arrays if user asked
2068 for it explicitly, never if they just happen to
2069 appear in the middle of some value chain. */
2071 || (vtype
->code () != TYPE_CODE_STRUCT
2072 && vtype
->code () != TYPE_CODE_ARRAY
))
2075 enum target_hw_bp_type type
;
2076 struct bp_location
*loc
, **tmp
;
2077 int bitpos
= 0, bitsize
= 0;
2079 if (value_bitsize (v
) != 0)
2081 /* Extract the bit parameters out from the bitfield
2083 bitpos
= value_bitpos (v
);
2084 bitsize
= value_bitsize (v
);
2086 else if (v
== result
&& b
->val_bitsize
!= 0)
2088 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2089 lvalue whose bit parameters are saved in the fields
2090 VAL_BITPOS and VAL_BITSIZE. */
2091 bitpos
= b
->val_bitpos
;
2092 bitsize
= b
->val_bitsize
;
2095 addr
= value_address (v
);
2098 /* Skip the bytes that don't contain the bitfield. */
2103 if (b
->type
== bp_read_watchpoint
)
2105 else if (b
->type
== bp_access_watchpoint
)
2108 loc
= b
->allocate_location ();
2109 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2112 loc
->gdbarch
= value_type (v
)->arch ();
2114 loc
->pspace
= frame_pspace
;
2115 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2119 /* Just cover the bytes that make up the bitfield. */
2120 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2123 loc
->length
= TYPE_LENGTH (value_type (v
));
2125 loc
->watchpoint_type
= type
;
2130 /* Change the type of breakpoint between hardware assisted or
2131 an ordinary watchpoint depending on the hardware support
2132 and free hardware slots. REPARSE is set when the inferior
2137 enum bp_loc_type loc_type
;
2139 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2143 int i
, target_resources_ok
, other_type_used
;
2146 /* Use an exact watchpoint when there's only one memory region to be
2147 watched, and only one debug register is needed to watch it. */
2148 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2150 /* We need to determine how many resources are already
2151 used for all other hardware watchpoints plus this one
2152 to see if we still have enough resources to also fit
2153 this watchpoint in as well. */
2155 /* If this is a software watchpoint, we try to turn it
2156 to a hardware one -- count resources as if B was of
2157 hardware watchpoint type. */
2159 if (type
== bp_watchpoint
)
2160 type
= bp_hardware_watchpoint
;
2162 /* This watchpoint may or may not have been placed on
2163 the list yet at this point (it won't be in the list
2164 if we're trying to create it for the first time,
2165 through watch_command), so always account for it
2168 /* Count resources used by all watchpoints except B. */
2169 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2171 /* Add in the resources needed for B. */
2172 i
+= hw_watchpoint_use_count (b
);
2175 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2176 if (target_resources_ok
<= 0)
2178 bool sw_mode
= b
->works_in_software_mode ();
2180 if (target_resources_ok
== 0 && !sw_mode
)
2181 error (_("Target does not support this type of "
2182 "hardware watchpoint."));
2183 else if (target_resources_ok
< 0 && !sw_mode
)
2184 error (_("There are not enough available hardware "
2185 "resources for this watchpoint."));
2187 /* Downgrade to software watchpoint. */
2188 b
->type
= bp_watchpoint
;
2192 /* If this was a software watchpoint, we've just
2193 found we have enough resources to turn it to a
2194 hardware watchpoint. Otherwise, this is a
2199 else if (!b
->works_in_software_mode ())
2201 if (!can_use_hw_watchpoints
)
2202 error (_("Can't set read/access watchpoint when "
2203 "hardware watchpoints are disabled."));
2205 error (_("Expression cannot be implemented with "
2206 "read/access watchpoint."));
2209 b
->type
= bp_watchpoint
;
2211 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_software_watchpoint
2212 : bp_loc_hardware_watchpoint
);
2213 for (bp_location
*bl
: b
->locations ())
2214 bl
->loc_type
= loc_type
;
2217 /* If a software watchpoint is not watching any memory, then the
2218 above left it without any location set up. But,
2219 bpstat_stop_status requires a location to be able to report
2220 stops, so make sure there's at least a dummy one. */
2221 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2222 add_dummy_location (b
, frame_pspace
);
2224 else if (!within_current_scope
)
2227 Watchpoint %d deleted because the program has left the block\n\
2228 in which its expression is valid.\n"),
2230 watchpoint_del_at_next_stop (b
);
2233 /* Restore the selected frame. */
2235 select_frame (frame_find_by_id (saved_frame_id
));
2239 /* Returns 1 iff breakpoint location should be
2240 inserted in the inferior. We don't differentiate the type of BL's owner
2241 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2242 breakpoint_ops is not defined, because in insert_bp_location,
2243 tracepoint's insert_location will not be called. */
2245 should_be_inserted (struct bp_location
*bl
)
2247 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2250 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2253 if (!bl
->enabled
|| bl
->disabled_by_cond
2254 || bl
->shlib_disabled
|| bl
->duplicate
)
2257 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2260 /* This is set for example, when we're attached to the parent of a
2261 vfork, and have detached from the child. The child is running
2262 free, and we expect it to do an exec or exit, at which point the
2263 OS makes the parent schedulable again (and the target reports
2264 that the vfork is done). Until the child is done with the shared
2265 memory region, do not insert breakpoints in the parent, otherwise
2266 the child could still trip on the parent's breakpoints. Since
2267 the parent is blocked anyway, it won't miss any breakpoint. */
2268 if (bl
->pspace
->breakpoints_not_allowed
)
2271 /* Don't insert a breakpoint if we're trying to step past its
2272 location, except if the breakpoint is a single-step breakpoint,
2273 and the breakpoint's thread is the thread which is stepping past
2275 if ((bl
->loc_type
== bp_loc_software_breakpoint
2276 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2277 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2279 /* The single-step breakpoint may be inserted at the location
2280 we're trying to step if the instruction branches to itself.
2281 However, the instruction won't be executed at all and it may
2282 break the semantics of the instruction, for example, the
2283 instruction is a conditional branch or updates some flags.
2284 We can't fix it unless GDB is able to emulate the instruction
2285 or switch to displaced stepping. */
2286 && !(bl
->owner
->type
== bp_single_step
2287 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2289 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2290 paddress (bl
->gdbarch
, bl
->address
));
2294 /* Don't insert watchpoints if we're trying to step past the
2295 instruction that triggered one. */
2296 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2297 && stepping_past_nonsteppable_watchpoint ())
2299 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2300 "skipping watchpoint at %s:%d",
2301 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2308 /* Same as should_be_inserted but does the check assuming
2309 that the location is not duplicated. */
2312 unduplicated_should_be_inserted (struct bp_location
*bl
)
2315 const int save_duplicate
= bl
->duplicate
;
2318 result
= should_be_inserted (bl
);
2319 bl
->duplicate
= save_duplicate
;
2323 /* Parses a conditional described by an expression COND into an
2324 agent expression bytecode suitable for evaluation
2325 by the bytecode interpreter. Return NULL if there was
2326 any error during parsing. */
2328 static agent_expr_up
2329 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2334 agent_expr_up aexpr
;
2336 /* We don't want to stop processing, so catch any errors
2337 that may show up. */
2340 aexpr
= gen_eval_for_expr (scope
, cond
);
2343 catch (const gdb_exception_error
&ex
)
2345 /* If we got here, it means the condition could not be parsed to a valid
2346 bytecode expression and thus can't be evaluated on the target's side.
2347 It's no use iterating through the conditions. */
2350 /* We have a valid agent expression. */
2354 /* Based on location BL, create a list of breakpoint conditions to be
2355 passed on to the target. If we have duplicated locations with different
2356 conditions, we will add such conditions to the list. The idea is that the
2357 target will evaluate the list of conditions and will only notify GDB when
2358 one of them is true. */
2361 build_target_condition_list (struct bp_location
*bl
)
2363 int null_condition_or_parse_error
= 0;
2364 int modified
= bl
->needs_update
;
2366 /* Release conditions left over from a previous insert. */
2367 bl
->target_info
.conditions
.clear ();
2369 /* This is only meaningful if the target is
2370 evaluating conditions and if the user has
2371 opted for condition evaluation on the target's
2373 if (gdb_evaluates_breakpoint_condition_p ()
2374 || !target_supports_evaluation_of_breakpoint_conditions ())
2377 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2379 /* Do a first pass to check for locations with no assigned
2380 conditions or conditions that fail to parse to a valid agent
2381 expression bytecode. If any of these happen, then it's no use to
2382 send conditions to the target since this location will always
2383 trigger and generate a response back to GDB. Note we consider
2384 all locations at the same address irrespective of type, i.e.,
2385 even if the locations aren't considered duplicates (e.g.,
2386 software breakpoint and hardware breakpoint at the same
2388 for (bp_location
*loc
: loc_range
)
2390 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2394 /* Re-parse the conditions since something changed. In that
2395 case we already freed the condition bytecodes (see
2396 force_breakpoint_reinsertion). We just
2397 need to parse the condition to bytecodes again. */
2398 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2402 /* If we have a NULL bytecode expression, it means something
2403 went wrong or we have a null condition expression. */
2404 if (!loc
->cond_bytecode
)
2406 null_condition_or_parse_error
= 1;
2412 /* If any of these happened, it means we will have to evaluate the conditions
2413 for the location's address on gdb's side. It is no use keeping bytecodes
2414 for all the other duplicate locations, thus we free all of them here.
2416 This is so we have a finer control over which locations' conditions are
2417 being evaluated by GDB or the remote stub. */
2418 if (null_condition_or_parse_error
)
2420 for (bp_location
*loc
: loc_range
)
2422 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2424 /* Only go as far as the first NULL bytecode is
2426 if (!loc
->cond_bytecode
)
2429 loc
->cond_bytecode
.reset ();
2434 /* No NULL conditions or failed bytecode generation. Build a
2435 condition list for this location's address. If we have software
2436 and hardware locations at the same address, they aren't
2437 considered duplicates, but we still marge all the conditions
2438 anyway, as it's simpler, and doesn't really make a practical
2440 for (bp_location
*loc
: loc_range
)
2442 && is_breakpoint (loc
->owner
)
2443 && loc
->pspace
->num
== bl
->pspace
->num
2444 && loc
->owner
->enable_state
== bp_enabled
2446 && !loc
->disabled_by_cond
)
2448 /* Add the condition to the vector. This will be used later
2449 to send the conditions to the target. */
2450 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2456 /* Parses a command described by string CMD into an agent expression
2457 bytecode suitable for evaluation by the bytecode interpreter.
2458 Return NULL if there was any error during parsing. */
2460 static agent_expr_up
2461 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2463 const char *cmdrest
;
2464 const char *format_start
, *format_end
;
2465 struct gdbarch
*gdbarch
= get_current_arch ();
2472 if (*cmdrest
== ',')
2474 cmdrest
= skip_spaces (cmdrest
);
2476 if (*cmdrest
++ != '"')
2477 error (_("No format string following the location"));
2479 format_start
= cmdrest
;
2481 format_pieces
fpieces (&cmdrest
);
2483 format_end
= cmdrest
;
2485 if (*cmdrest
++ != '"')
2486 error (_("Bad format string, non-terminated '\"'."));
2488 cmdrest
= skip_spaces (cmdrest
);
2490 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2491 error (_("Invalid argument syntax"));
2493 if (*cmdrest
== ',')
2495 cmdrest
= skip_spaces (cmdrest
);
2497 /* For each argument, make an expression. */
2499 std::vector
<struct expression
*> argvec
;
2500 while (*cmdrest
!= '\0')
2505 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2506 argvec
.push_back (expr
.release ());
2508 if (*cmdrest
== ',')
2512 agent_expr_up aexpr
;
2514 /* We don't want to stop processing, so catch any errors
2515 that may show up. */
2518 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2519 format_start
, format_end
- format_start
,
2520 argvec
.size (), argvec
.data ());
2522 catch (const gdb_exception_error
&ex
)
2524 /* If we got here, it means the command could not be parsed to a valid
2525 bytecode expression and thus can't be evaluated on the target's side.
2526 It's no use iterating through the other commands. */
2529 /* We have a valid agent expression, return it. */
2533 /* Based on location BL, create a list of breakpoint commands to be
2534 passed on to the target. If we have duplicated locations with
2535 different commands, we will add any such to the list. */
2538 build_target_command_list (struct bp_location
*bl
)
2540 int null_command_or_parse_error
= 0;
2541 int modified
= bl
->needs_update
;
2543 /* Clear commands left over from a previous insert. */
2544 bl
->target_info
.tcommands
.clear ();
2546 if (!target_can_run_breakpoint_commands ())
2549 /* For now, limit to agent-style dprintf breakpoints. */
2550 if (dprintf_style
!= dprintf_style_agent
)
2553 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2555 /* For now, if we have any location at the same address that isn't a
2556 dprintf, don't install the target-side commands, as that would
2557 make the breakpoint not be reported to the core, and we'd lose
2559 for (bp_location
*loc
: loc_range
)
2560 if (is_breakpoint (loc
->owner
)
2561 && loc
->pspace
->num
== bl
->pspace
->num
2562 && loc
->owner
->type
!= bp_dprintf
)
2565 /* Do a first pass to check for locations with no assigned
2566 conditions or conditions that fail to parse to a valid agent expression
2567 bytecode. If any of these happen, then it's no use to send conditions
2568 to the target since this location will always trigger and generate a
2569 response back to GDB. */
2570 for (bp_location
*loc
: loc_range
)
2572 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2576 /* Re-parse the commands since something changed. In that
2577 case we already freed the command bytecodes (see
2578 force_breakpoint_reinsertion). We just
2579 need to parse the command to bytecodes again. */
2581 = parse_cmd_to_aexpr (bl
->address
,
2582 loc
->owner
->extra_string
.get ());
2585 /* If we have a NULL bytecode expression, it means something
2586 went wrong or we have a null command expression. */
2587 if (!loc
->cmd_bytecode
)
2589 null_command_or_parse_error
= 1;
2595 /* If anything failed, then we're not doing target-side commands,
2597 if (null_command_or_parse_error
)
2599 for (bp_location
*loc
: loc_range
)
2600 if (is_breakpoint (loc
->owner
)
2601 && loc
->pspace
->num
== bl
->pspace
->num
)
2603 /* Only go as far as the first NULL bytecode is
2605 if (loc
->cmd_bytecode
== NULL
)
2608 loc
->cmd_bytecode
.reset ();
2612 /* No NULL commands or failed bytecode generation. Build a command
2613 list for all duplicate locations at this location's address.
2614 Note that here we must care for whether the breakpoint location
2615 types are considered duplicates, otherwise, say, if we have a
2616 software and hardware location at the same address, the target
2617 could end up running the commands twice. For the moment, we only
2618 support targets-side commands with dprintf, but it doesn't hurt
2619 to be pedantically correct in case that changes. */
2620 for (bp_location
*loc
: loc_range
)
2621 if (breakpoint_locations_match (bl
, loc
)
2622 && loc
->owner
->extra_string
2623 && is_breakpoint (loc
->owner
)
2624 && loc
->pspace
->num
== bl
->pspace
->num
2625 && loc
->owner
->enable_state
== bp_enabled
2627 && !loc
->disabled_by_cond
)
2629 /* Add the command to the vector. This will be used later
2630 to send the commands to the target. */
2631 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2634 bl
->target_info
.persist
= 0;
2635 /* Maybe flag this location as persistent. */
2636 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2637 bl
->target_info
.persist
= 1;
2640 /* Return the kind of breakpoint on address *ADDR. Get the kind
2641 of breakpoint according to ADDR except single-step breakpoint.
2642 Get the kind of single-step breakpoint according to the current
2646 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2648 if (bl
->owner
->type
== bp_single_step
)
2650 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2651 struct regcache
*regcache
;
2653 regcache
= get_thread_regcache (thr
);
2655 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2659 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2662 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2663 location. Any error messages are printed to TMP_ERROR_STREAM; and
2664 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2665 Returns 0 for success, 1 if the bp_location type is not supported or
2668 NOTE drow/2003-09-09: This routine could be broken down to an
2669 object-style method for each breakpoint or catchpoint type. */
2671 insert_bp_location (struct bp_location
*bl
,
2672 struct ui_file
*tmp_error_stream
,
2673 int *disabled_breaks
,
2674 int *hw_breakpoint_error
,
2675 int *hw_bp_error_explained_already
)
2677 gdb_exception bp_excpt
;
2679 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2682 /* Note we don't initialize bl->target_info, as that wipes out
2683 the breakpoint location's shadow_contents if the breakpoint
2684 is still inserted at that location. This in turn breaks
2685 target_read_memory which depends on these buffers when
2686 a memory read is requested at the breakpoint location:
2687 Once the target_info has been wiped, we fail to see that
2688 we have a breakpoint inserted at that address and thus
2689 read the breakpoint instead of returning the data saved in
2690 the breakpoint location's shadow contents. */
2691 bl
->target_info
.reqstd_address
= bl
->address
;
2692 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2693 bl
->target_info
.length
= bl
->length
;
2695 /* When working with target-side conditions, we must pass all the conditions
2696 for the same breakpoint address down to the target since GDB will not
2697 insert those locations. With a list of breakpoint conditions, the target
2698 can decide when to stop and notify GDB. */
2700 if (is_breakpoint (bl
->owner
))
2702 build_target_condition_list (bl
);
2703 build_target_command_list (bl
);
2704 /* Reset the modification marker. */
2705 bl
->needs_update
= 0;
2708 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2709 set at a read-only address, then a breakpoint location will have
2710 been changed to hardware breakpoint before we get here. If it is
2711 "off" however, error out before actually trying to insert the
2712 breakpoint, with a nicer error message. */
2713 if (bl
->loc_type
== bp_loc_software_breakpoint
2714 && !automatic_hardware_breakpoints
)
2716 mem_region
*mr
= lookup_mem_region (bl
->address
);
2718 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2720 gdb_printf (tmp_error_stream
,
2721 _("Cannot insert breakpoint %d.\n"
2722 "Cannot set software breakpoint "
2723 "at read-only address %s\n"),
2725 paddress (bl
->gdbarch
, bl
->address
));
2730 if (bl
->loc_type
== bp_loc_software_breakpoint
2731 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2733 /* First check to see if we have to handle an overlay. */
2734 if (overlay_debugging
== ovly_off
2735 || bl
->section
== NULL
2736 || !(section_is_overlay (bl
->section
)))
2738 /* No overlay handling: just set the breakpoint. */
2743 val
= bl
->owner
->insert_location (bl
);
2745 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2747 catch (gdb_exception
&e
)
2749 bp_excpt
= std::move (e
);
2754 /* This breakpoint is in an overlay section.
2755 Shall we set a breakpoint at the LMA? */
2756 if (!overlay_events_enabled
)
2758 /* Yes -- overlay event support is not active,
2759 so we must try to set a breakpoint at the LMA.
2760 This will not work for a hardware breakpoint. */
2761 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2762 warning (_("hardware breakpoint %d not supported in overlay!"),
2766 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2768 /* Set a software (trap) breakpoint at the LMA. */
2769 bl
->overlay_target_info
= bl
->target_info
;
2770 bl
->overlay_target_info
.reqstd_address
= addr
;
2772 /* No overlay handling: just set the breakpoint. */
2777 bl
->overlay_target_info
.kind
2778 = breakpoint_kind (bl
, &addr
);
2779 bl
->overlay_target_info
.placed_address
= addr
;
2780 val
= target_insert_breakpoint (bl
->gdbarch
,
2781 &bl
->overlay_target_info
);
2784 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2786 catch (gdb_exception
&e
)
2788 bp_excpt
= std::move (e
);
2791 if (bp_excpt
.reason
!= 0)
2792 gdb_printf (tmp_error_stream
,
2793 "Overlay breakpoint %d "
2794 "failed: in ROM?\n",
2798 /* Shall we set a breakpoint at the VMA? */
2799 if (section_is_mapped (bl
->section
))
2801 /* Yes. This overlay section is mapped into memory. */
2806 val
= bl
->owner
->insert_location (bl
);
2808 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2810 catch (gdb_exception
&e
)
2812 bp_excpt
= std::move (e
);
2817 /* No. This breakpoint will not be inserted.
2818 No error, but do not mark the bp as 'inserted'. */
2823 if (bp_excpt
.reason
!= 0)
2825 /* Can't set the breakpoint. */
2827 /* If the target has closed then it will have deleted any
2828 breakpoints inserted within the target inferior, as a result
2829 any further attempts to interact with the breakpoint objects
2830 is not possible. Just rethrow the error. */
2831 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2833 gdb_assert (bl
->owner
!= nullptr);
2835 /* In some cases, we might not be able to insert a
2836 breakpoint in a shared library that has already been
2837 removed, but we have not yet processed the shlib unload
2838 event. Unfortunately, some targets that implement
2839 breakpoint insertion themselves can't tell why the
2840 breakpoint insertion failed (e.g., the remote target
2841 doesn't define error codes), so we must treat generic
2842 errors as memory errors. */
2843 if (bp_excpt
.reason
== RETURN_ERROR
2844 && (bp_excpt
.error
== GENERIC_ERROR
2845 || bp_excpt
.error
== MEMORY_ERROR
)
2846 && bl
->loc_type
== bp_loc_software_breakpoint
2847 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2848 || shared_objfile_contains_address_p (bl
->pspace
,
2851 /* See also: disable_breakpoints_in_shlibs. */
2852 bl
->shlib_disabled
= 1;
2853 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2854 if (!*disabled_breaks
)
2856 gdb_printf (tmp_error_stream
,
2857 "Cannot insert breakpoint %d.\n",
2859 gdb_printf (tmp_error_stream
,
2860 "Temporarily disabling shared "
2861 "library breakpoints:\n");
2863 *disabled_breaks
= 1;
2864 gdb_printf (tmp_error_stream
,
2865 "breakpoint #%d\n", bl
->owner
->number
);
2870 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2872 *hw_breakpoint_error
= 1;
2873 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2874 gdb_printf (tmp_error_stream
,
2875 "Cannot insert hardware breakpoint %d%s",
2877 bp_excpt
.message
? ":" : ".\n");
2878 if (bp_excpt
.message
!= NULL
)
2879 gdb_printf (tmp_error_stream
, "%s.\n",
2884 if (bp_excpt
.message
== NULL
)
2887 = memory_error_message (TARGET_XFER_E_IO
,
2888 bl
->gdbarch
, bl
->address
);
2890 gdb_printf (tmp_error_stream
,
2891 "Cannot insert breakpoint %d.\n"
2893 bl
->owner
->number
, message
.c_str ());
2897 gdb_printf (tmp_error_stream
,
2898 "Cannot insert breakpoint %d: %s\n",
2913 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2914 /* NOTE drow/2003-09-08: This state only exists for removing
2915 watchpoints. It's not clear that it's necessary... */
2916 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2920 val
= bl
->owner
->insert_location (bl
);
2922 /* If trying to set a read-watchpoint, and it turns out it's not
2923 supported, try emulating one with an access watchpoint. */
2924 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2926 /* But don't try to insert it, if there's already another
2927 hw_access location that would be considered a duplicate
2929 for (bp_location
*loc
: all_bp_locations ())
2931 && loc
->watchpoint_type
== hw_access
2932 && watchpoint_locations_match (bl
, loc
))
2936 bl
->target_info
= loc
->target_info
;
2937 bl
->watchpoint_type
= hw_access
;
2944 bl
->watchpoint_type
= hw_access
;
2945 val
= bl
->owner
->insert_location (bl
);
2948 /* Back to the original value. */
2949 bl
->watchpoint_type
= hw_read
;
2953 bl
->inserted
= (val
== 0);
2956 else if (bl
->owner
->type
== bp_catchpoint
)
2960 val
= bl
->owner
->insert_location (bl
);
2963 bl
->owner
->enable_state
= bp_disabled
;
2967 Error inserting catchpoint %d: Your system does not support this type\n\
2968 of catchpoint."), bl
->owner
->number
);
2970 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2973 bl
->inserted
= (val
== 0);
2975 /* We've already printed an error message if there was a problem
2976 inserting this catchpoint, and we've disabled the catchpoint,
2977 so just return success. */
2984 /* This function is called when program space PSPACE is about to be
2985 deleted. It takes care of updating breakpoints to not reference
2989 breakpoint_program_space_exit (struct program_space
*pspace
)
2991 /* Remove any breakpoint that was set through this program space. */
2992 for (breakpoint
*b
: all_breakpoints_safe ())
2993 if (b
->pspace
== pspace
)
2994 delete_breakpoint (b
);
2996 /* Breakpoints set through other program spaces could have locations
2997 bound to PSPACE as well. Remove those. */
2998 for (bp_location
*loc
: all_bp_locations ())
3000 struct bp_location
*tmp
;
3002 if (loc
->pspace
== pspace
)
3004 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3005 if (loc
->owner
->loc
== loc
)
3006 loc
->owner
->loc
= loc
->next
;
3008 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3009 if (tmp
->next
== loc
)
3011 tmp
->next
= loc
->next
;
3017 /* Now update the global location list to permanently delete the
3018 removed locations above. */
3019 update_global_location_list (UGLL_DONT_INSERT
);
3022 /* Make sure all breakpoints are inserted in inferior.
3023 Throws exception on any error.
3024 A breakpoint that is already inserted won't be inserted
3025 again, so calling this function twice is safe. */
3027 insert_breakpoints (void)
3029 for (breakpoint
*bpt
: all_breakpoints ())
3030 if (is_hardware_watchpoint (bpt
))
3032 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3034 update_watchpoint (w
, 0 /* don't reparse. */);
3037 /* Updating watchpoints creates new locations, so update the global
3038 location list. Explicitly tell ugll to insert locations and
3039 ignore breakpoints_always_inserted_mode. Also,
3040 update_global_location_list tries to "upgrade" software
3041 breakpoints to hardware breakpoints to handle "set breakpoint
3042 auto-hw", so we need to call it even if we don't have new
3044 update_global_location_list (UGLL_INSERT
);
3047 /* This is used when we need to synch breakpoint conditions between GDB and the
3048 target. It is the case with deleting and disabling of breakpoints when using
3049 always-inserted mode. */
3052 update_inserted_breakpoint_locations (void)
3056 int disabled_breaks
= 0;
3057 int hw_breakpoint_error
= 0;
3058 int hw_bp_details_reported
= 0;
3060 string_file tmp_error_stream
;
3062 /* Explicitly mark the warning -- this will only be printed if
3063 there was an error. */
3064 tmp_error_stream
.puts ("Warning:\n");
3066 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3068 for (bp_location
*bl
: all_bp_locations ())
3070 /* We only want to update software breakpoints and hardware
3072 if (!is_breakpoint (bl
->owner
))
3075 /* We only want to update locations that are already inserted
3076 and need updating. This is to avoid unwanted insertion during
3077 deletion of breakpoints. */
3078 if (!bl
->inserted
|| !bl
->needs_update
)
3081 switch_to_program_space_and_thread (bl
->pspace
);
3083 /* For targets that support global breakpoints, there's no need
3084 to select an inferior to insert breakpoint to. In fact, even
3085 if we aren't attached to any process yet, we should still
3086 insert breakpoints. */
3087 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3088 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3091 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3092 &hw_breakpoint_error
, &hw_bp_details_reported
);
3099 target_terminal::ours_for_output ();
3100 error_stream (tmp_error_stream
);
3104 /* Used when starting or continuing the program. */
3107 insert_breakpoint_locations (void)
3111 int disabled_breaks
= 0;
3112 int hw_breakpoint_error
= 0;
3113 int hw_bp_error_explained_already
= 0;
3115 string_file tmp_error_stream
;
3117 /* Explicitly mark the warning -- this will only be printed if
3118 there was an error. */
3119 tmp_error_stream
.puts ("Warning:\n");
3121 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3123 for (bp_location
*bl
: all_bp_locations ())
3125 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3128 /* There is no point inserting thread-specific breakpoints if
3129 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3130 has BL->OWNER always non-NULL. */
3131 if (bl
->owner
->thread
!= -1
3132 && !valid_global_thread_id (bl
->owner
->thread
))
3135 switch_to_program_space_and_thread (bl
->pspace
);
3137 /* For targets that support global breakpoints, there's no need
3138 to select an inferior to insert breakpoint to. In fact, even
3139 if we aren't attached to any process yet, we should still
3140 insert breakpoints. */
3141 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3142 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3145 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3146 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3151 /* If we failed to insert all locations of a watchpoint, remove
3152 them, as half-inserted watchpoint is of limited use. */
3153 for (breakpoint
*bpt
: all_breakpoints ())
3155 int some_failed
= 0;
3157 if (!is_hardware_watchpoint (bpt
))
3160 if (!breakpoint_enabled (bpt
))
3163 if (bpt
->disposition
== disp_del_at_next_stop
)
3166 for (bp_location
*loc
: bpt
->locations ())
3167 if (!loc
->inserted
&& should_be_inserted (loc
))
3175 for (bp_location
*loc
: bpt
->locations ())
3177 remove_breakpoint (loc
);
3179 hw_breakpoint_error
= 1;
3180 tmp_error_stream
.printf ("Could not insert "
3181 "hardware watchpoint %d.\n",
3189 /* If a hardware breakpoint or watchpoint was inserted, add a
3190 message about possibly exhausted resources. */
3191 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3193 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3194 You may have requested too many hardware breakpoints/watchpoints.\n");
3196 target_terminal::ours_for_output ();
3197 error_stream (tmp_error_stream
);
3201 /* Used when the program stops.
3202 Returns zero if successful, or non-zero if there was a problem
3203 removing a breakpoint location. */
3206 remove_breakpoints (void)
3210 for (bp_location
*bl
: all_bp_locations ())
3211 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3212 val
|= remove_breakpoint (bl
);
3217 /* When a thread exits, remove breakpoints that are related to
3221 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3223 for (breakpoint
*b
: all_breakpoints_safe ())
3225 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3227 b
->disposition
= disp_del_at_next_stop
;
3230 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3231 b
->number
, print_thread_id (tp
));
3233 /* Hide it from the user. */
3239 /* See breakpoint.h. */
3242 remove_breakpoints_inf (inferior
*inf
)
3246 for (bp_location
*bl
: all_bp_locations ())
3248 if (bl
->pspace
!= inf
->pspace
)
3251 if (bl
->inserted
&& !bl
->target_info
.persist
)
3253 val
= remove_breakpoint (bl
);
3260 static int internal_breakpoint_number
= -1;
3262 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3263 If INTERNAL is non-zero, the breakpoint number will be populated
3264 from internal_breakpoint_number and that variable decremented.
3265 Otherwise the breakpoint number will be populated from
3266 breakpoint_count and that value incremented. Internal breakpoints
3267 do not set the internal var bpnum. */
3269 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3272 b
->number
= internal_breakpoint_number
--;
3275 set_breakpoint_count (breakpoint_count
+ 1);
3276 b
->number
= breakpoint_count
;
3280 static struct breakpoint
*
3281 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3282 CORE_ADDR address
, enum bptype type
)
3284 std::unique_ptr
<internal_breakpoint
> b
3285 (new internal_breakpoint (gdbarch
, type
, address
));
3287 b
->number
= internal_breakpoint_number
--;
3289 return add_to_breakpoint_chain (std::move (b
));
3292 static const char *const longjmp_names
[] =
3294 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3296 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3298 /* Per-objfile data private to breakpoint.c. */
3299 struct breakpoint_objfile_data
3301 /* Minimal symbol for "_ovly_debug_event" (if any). */
3302 struct bound_minimal_symbol overlay_msym
;
3304 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3305 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3307 /* True if we have looked for longjmp probes. */
3308 int longjmp_searched
= 0;
3310 /* SystemTap probe points for longjmp (if any). These are non-owning
3312 std::vector
<probe
*> longjmp_probes
;
3314 /* Minimal symbol for "std::terminate()" (if any). */
3315 struct bound_minimal_symbol terminate_msym
;
3317 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3318 struct bound_minimal_symbol exception_msym
;
3320 /* True if we have looked for exception probes. */
3321 int exception_searched
= 0;
3323 /* SystemTap probe points for unwinding (if any). These are non-owning
3325 std::vector
<probe
*> exception_probes
;
3328 static const registry
<objfile
>::key
<breakpoint_objfile_data
>
3329 breakpoint_objfile_key
;
3331 /* Minimal symbol not found sentinel. */
3332 static struct minimal_symbol msym_not_found
;
3334 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3337 msym_not_found_p (const struct minimal_symbol
*msym
)
3339 return msym
== &msym_not_found
;
3342 /* Return per-objfile data needed by breakpoint.c.
3343 Allocate the data if necessary. */
3345 static struct breakpoint_objfile_data
*
3346 get_breakpoint_objfile_data (struct objfile
*objfile
)
3348 struct breakpoint_objfile_data
*bp_objfile_data
;
3350 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3351 if (bp_objfile_data
== NULL
)
3352 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3353 return bp_objfile_data
;
3357 create_overlay_event_breakpoint (void)
3359 const char *const func_name
= "_ovly_debug_event";
3361 for (objfile
*objfile
: current_program_space
->objfiles ())
3363 struct breakpoint
*b
;
3364 struct breakpoint_objfile_data
*bp_objfile_data
;
3367 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3369 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3372 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3374 struct bound_minimal_symbol m
;
3376 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3377 if (m
.minsym
== NULL
)
3379 /* Avoid future lookups in this objfile. */
3380 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3383 bp_objfile_data
->overlay_msym
= m
;
3386 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3387 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3389 b
->locspec
= new_explicit_location_spec_function (func_name
);
3391 if (overlay_debugging
== ovly_auto
)
3393 b
->enable_state
= bp_enabled
;
3394 overlay_events_enabled
= 1;
3398 b
->enable_state
= bp_disabled
;
3399 overlay_events_enabled
= 0;
3404 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3405 true if a breakpoint was installed. */
3408 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3410 struct gdbarch
*gdbarch
= objfile
->arch ();
3411 struct breakpoint_objfile_data
*bp_objfile_data
3412 = get_breakpoint_objfile_data (objfile
);
3414 if (!bp_objfile_data
->longjmp_searched
)
3416 std::vector
<probe
*> ret
3417 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3421 /* We are only interested in checking one element. */
3424 if (!p
->can_evaluate_arguments ())
3426 /* We cannot use the probe interface here,
3427 because it does not know how to evaluate
3432 bp_objfile_data
->longjmp_probes
= ret
;
3433 bp_objfile_data
->longjmp_searched
= 1;
3436 if (bp_objfile_data
->longjmp_probes
.empty ())
3439 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3441 struct breakpoint
*b
;
3443 b
= create_internal_breakpoint (gdbarch
,
3444 p
->get_relocated_address (objfile
),
3446 b
->locspec
= new_probe_location_spec ("-probe-stap libc:longjmp");
3447 b
->enable_state
= bp_disabled
;
3453 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3454 Return true if at least one breakpoint was installed. */
3457 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3459 struct gdbarch
*gdbarch
= objfile
->arch ();
3460 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3463 struct breakpoint_objfile_data
*bp_objfile_data
3464 = get_breakpoint_objfile_data (objfile
);
3465 unsigned int installed_bp
= 0;
3467 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3469 struct breakpoint
*b
;
3470 const char *func_name
;
3473 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3476 func_name
= longjmp_names
[i
];
3477 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3479 struct bound_minimal_symbol m
;
3481 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3482 if (m
.minsym
== NULL
)
3484 /* Prevent future lookups in this objfile. */
3485 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3488 bp_objfile_data
->longjmp_msym
[i
] = m
;
3491 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3492 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3493 b
->locspec
= new_explicit_location_spec_function (func_name
);
3494 b
->enable_state
= bp_disabled
;
3498 return installed_bp
> 0;
3501 /* Create a master longjmp breakpoint. */
3504 create_longjmp_master_breakpoint (void)
3506 scoped_restore_current_program_space restore_pspace
;
3508 for (struct program_space
*pspace
: program_spaces
)
3510 set_current_program_space (pspace
);
3512 for (objfile
*obj
: current_program_space
->objfiles ())
3514 /* Skip separate debug object, it's handled in the loop below. */
3515 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3518 /* Try a probe kind breakpoint on main objfile. */
3519 if (create_longjmp_master_breakpoint_probe (obj
))
3522 /* Try longjmp_names kind breakpoints on main and separate_debug
3524 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3525 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3531 /* Create a master std::terminate breakpoint. */
3533 create_std_terminate_master_breakpoint (void)
3535 const char *const func_name
= "std::terminate()";
3537 scoped_restore_current_program_space restore_pspace
;
3539 for (struct program_space
*pspace
: program_spaces
)
3543 set_current_program_space (pspace
);
3545 for (objfile
*objfile
: current_program_space
->objfiles ())
3547 struct breakpoint
*b
;
3548 struct breakpoint_objfile_data
*bp_objfile_data
;
3550 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3552 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3555 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3557 struct bound_minimal_symbol m
;
3559 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3560 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3561 && m
.minsym
->type () != mst_file_text
))
3563 /* Prevent future lookups in this objfile. */
3564 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3567 bp_objfile_data
->terminate_msym
= m
;
3570 addr
= bp_objfile_data
->terminate_msym
.value_address ();
3571 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3572 bp_std_terminate_master
);
3573 b
->locspec
= new_explicit_location_spec_function (func_name
);
3574 b
->enable_state
= bp_disabled
;
3579 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3580 probe. Return true if a breakpoint was installed. */
3583 create_exception_master_breakpoint_probe (objfile
*objfile
)
3585 struct breakpoint
*b
;
3586 struct gdbarch
*gdbarch
;
3587 struct breakpoint_objfile_data
*bp_objfile_data
;
3589 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3591 /* We prefer the SystemTap probe point if it exists. */
3592 if (!bp_objfile_data
->exception_searched
)
3594 std::vector
<probe
*> ret
3595 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3599 /* We are only interested in checking one element. */
3602 if (!p
->can_evaluate_arguments ())
3604 /* We cannot use the probe interface here, because it does
3605 not know how to evaluate arguments. */
3609 bp_objfile_data
->exception_probes
= ret
;
3610 bp_objfile_data
->exception_searched
= 1;
3613 if (bp_objfile_data
->exception_probes
.empty ())
3616 gdbarch
= objfile
->arch ();
3618 for (probe
*p
: bp_objfile_data
->exception_probes
)
3620 b
= create_internal_breakpoint (gdbarch
,
3621 p
->get_relocated_address (objfile
),
3622 bp_exception_master
);
3623 b
->locspec
= new_probe_location_spec ("-probe-stap libgcc:unwind");
3624 b
->enable_state
= bp_disabled
;
3630 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3631 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3634 create_exception_master_breakpoint_hook (objfile
*objfile
)
3636 const char *const func_name
= "_Unwind_DebugHook";
3637 struct breakpoint
*b
;
3638 struct gdbarch
*gdbarch
;
3639 struct breakpoint_objfile_data
*bp_objfile_data
;
3642 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3644 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3647 gdbarch
= objfile
->arch ();
3649 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3651 struct bound_minimal_symbol debug_hook
;
3653 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3654 if (debug_hook
.minsym
== NULL
)
3656 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3660 bp_objfile_data
->exception_msym
= debug_hook
;
3663 addr
= bp_objfile_data
->exception_msym
.value_address ();
3664 addr
= gdbarch_convert_from_func_ptr_addr
3665 (gdbarch
, addr
, current_inferior ()->top_target ());
3666 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
3667 b
->locspec
= new_explicit_location_spec_function (func_name
);
3668 b
->enable_state
= bp_disabled
;
3673 /* Install a master breakpoint on the unwinder's debug hook. */
3676 create_exception_master_breakpoint (void)
3678 for (objfile
*obj
: current_program_space
->objfiles ())
3680 /* Skip separate debug object. */
3681 if (obj
->separate_debug_objfile_backlink
)
3684 /* Try a probe kind breakpoint. */
3685 if (create_exception_master_breakpoint_probe (obj
))
3688 /* Iterate over main and separate debug objects and try an
3689 _Unwind_DebugHook kind breakpoint. */
3690 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3691 if (create_exception_master_breakpoint_hook (debug_objfile
))
3696 /* Does B have a location spec? */
3699 breakpoint_location_spec_empty_p (const struct breakpoint
*b
)
3701 return (b
->locspec
!= nullptr && b
->locspec
->empty_p ());
3705 update_breakpoints_after_exec (void)
3707 /* We're about to delete breakpoints from GDB's lists. If the
3708 INSERTED flag is true, GDB will try to lift the breakpoints by
3709 writing the breakpoints' "shadow contents" back into memory. The
3710 "shadow contents" are NOT valid after an exec, so GDB should not
3711 do that. Instead, the target is responsible from marking
3712 breakpoints out as soon as it detects an exec. We don't do that
3713 here instead, because there may be other attempts to delete
3714 breakpoints after detecting an exec and before reaching here. */
3715 for (bp_location
*bploc
: all_bp_locations ())
3716 if (bploc
->pspace
== current_program_space
)
3717 gdb_assert (!bploc
->inserted
);
3719 for (breakpoint
*b
: all_breakpoints_safe ())
3721 if (b
->pspace
!= current_program_space
)
3724 /* Solib breakpoints must be explicitly reset after an exec(). */
3725 if (b
->type
== bp_shlib_event
)
3727 delete_breakpoint (b
);
3731 /* JIT breakpoints must be explicitly reset after an exec(). */
3732 if (b
->type
== bp_jit_event
)
3734 delete_breakpoint (b
);
3738 /* Thread event breakpoints must be set anew after an exec(),
3739 as must overlay event and longjmp master breakpoints. */
3740 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3741 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3742 || b
->type
== bp_exception_master
)
3744 delete_breakpoint (b
);
3748 /* Step-resume breakpoints are meaningless after an exec(). */
3749 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3751 delete_breakpoint (b
);
3755 /* Just like single-step breakpoints. */
3756 if (b
->type
== bp_single_step
)
3758 delete_breakpoint (b
);
3762 /* Longjmp and longjmp-resume breakpoints are also meaningless
3764 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3765 || b
->type
== bp_longjmp_call_dummy
3766 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3768 delete_breakpoint (b
);
3772 if (b
->type
== bp_catchpoint
)
3774 /* For now, none of the bp_catchpoint breakpoints need to
3775 do anything at this point. In the future, if some of
3776 the catchpoints need to something, we will need to add
3777 a new method, and call this method from here. */
3781 /* bp_finish is a special case. The only way we ought to be able
3782 to see one of these when an exec() has happened, is if the user
3783 caught a vfork, and then said "finish". Ordinarily a finish just
3784 carries them to the call-site of the current callee, by setting
3785 a temporary bp there and resuming. But in this case, the finish
3786 will carry them entirely through the vfork & exec.
3788 We don't want to allow a bp_finish to remain inserted now. But
3789 we can't safely delete it, 'cause finish_command has a handle to
3790 the bp on a bpstat, and will later want to delete it. There's a
3791 chance (and I've seen it happen) that if we delete the bp_finish
3792 here, that its storage will get reused by the time finish_command
3793 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3794 We really must allow finish_command to delete a bp_finish.
3796 In the absence of a general solution for the "how do we know
3797 it's safe to delete something others may have handles to?"
3798 problem, what we'll do here is just uninsert the bp_finish, and
3799 let finish_command delete it.
3801 (We know the bp_finish is "doomed" in the sense that it's
3802 momentary, and will be deleted as soon as finish_command sees
3803 the inferior stopped. So it doesn't matter that the bp's
3804 address is probably bogus in the new a.out, unlike e.g., the
3805 solib breakpoints.) */
3807 if (b
->type
== bp_finish
)
3812 /* Without a symbolic address, we have little hope of the
3813 pre-exec() address meaning the same thing in the post-exec()
3815 if (breakpoint_location_spec_empty_p (b
))
3817 delete_breakpoint (b
);
3824 detach_breakpoints (ptid_t ptid
)
3827 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3828 struct inferior
*inf
= current_inferior ();
3830 if (ptid
.pid () == inferior_ptid
.pid ())
3831 error (_("Cannot detach breakpoints of inferior_ptid"));
3833 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3834 inferior_ptid
= ptid
;
3835 for (bp_location
*bl
: all_bp_locations ())
3837 if (bl
->pspace
!= inf
->pspace
)
3840 /* This function must physically remove breakpoints locations
3841 from the specified ptid, without modifying the breakpoint
3842 package's state. Locations of type bp_loc_other and
3843 bp_loc_software_watchpoint are only maintained at GDB side,
3844 so there is no need to remove them. Moreover, removing these
3845 would modify the breakpoint package's state. */
3846 if (bl
->loc_type
== bp_loc_other
3847 || bl
->loc_type
== bp_loc_software_watchpoint
)
3851 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3857 /* Remove the breakpoint location BL from the current address space.
3858 Note that this is used to detach breakpoints from a child fork.
3859 When we get here, the child isn't in the inferior list, and neither
3860 do we have objects to represent its address space --- we should
3861 *not* look at bl->pspace->aspace here. */
3864 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3868 /* BL is never in moribund_locations by our callers. */
3869 gdb_assert (bl
->owner
!= NULL
);
3871 /* The type of none suggests that owner is actually deleted.
3872 This should not ever happen. */
3873 gdb_assert (bl
->owner
->type
!= bp_none
);
3875 if (bl
->loc_type
== bp_loc_software_breakpoint
3876 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3878 /* "Normal" instruction breakpoint: either the standard
3879 trap-instruction bp (bp_breakpoint), or a
3880 bp_hardware_breakpoint. */
3882 /* First check to see if we have to handle an overlay. */
3883 if (overlay_debugging
== ovly_off
3884 || bl
->section
== NULL
3885 || !(section_is_overlay (bl
->section
)))
3887 /* No overlay handling: just remove the breakpoint. */
3889 /* If we're trying to uninsert a memory breakpoint that we
3890 know is set in a dynamic object that is marked
3891 shlib_disabled, then either the dynamic object was
3892 removed with "remove-symbol-file" or with
3893 "nosharedlibrary". In the former case, we don't know
3894 whether another dynamic object might have loaded over the
3895 breakpoint's address -- the user might well let us know
3896 about it next with add-symbol-file (the whole point of
3897 add-symbol-file is letting the user manually maintain a
3898 list of dynamically loaded objects). If we have the
3899 breakpoint's shadow memory, that is, this is a software
3900 breakpoint managed by GDB, check whether the breakpoint
3901 is still inserted in memory, to avoid overwriting wrong
3902 code with stale saved shadow contents. Note that HW
3903 breakpoints don't have shadow memory, as they're
3904 implemented using a mechanism that is not dependent on
3905 being able to modify the target's memory, and as such
3906 they should always be removed. */
3907 if (bl
->shlib_disabled
3908 && bl
->target_info
.shadow_len
!= 0
3909 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3912 val
= bl
->owner
->remove_location (bl
, reason
);
3916 /* This breakpoint is in an overlay section.
3917 Did we set a breakpoint at the LMA? */
3918 if (!overlay_events_enabled
)
3920 /* Yes -- overlay event support is not active, so we
3921 should have set a breakpoint at the LMA. Remove it.
3923 /* Ignore any failures: if the LMA is in ROM, we will
3924 have already warned when we failed to insert it. */
3925 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3926 target_remove_hw_breakpoint (bl
->gdbarch
,
3927 &bl
->overlay_target_info
);
3929 target_remove_breakpoint (bl
->gdbarch
,
3930 &bl
->overlay_target_info
,
3933 /* Did we set a breakpoint at the VMA?
3934 If so, we will have marked the breakpoint 'inserted'. */
3937 /* Yes -- remove it. Previously we did not bother to
3938 remove the breakpoint if the section had been
3939 unmapped, but let's not rely on that being safe. We
3940 don't know what the overlay manager might do. */
3942 /* However, we should remove *software* breakpoints only
3943 if the section is still mapped, or else we overwrite
3944 wrong code with the saved shadow contents. */
3945 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3946 || section_is_mapped (bl
->section
))
3947 val
= bl
->owner
->remove_location (bl
, reason
);
3953 /* No -- not inserted, so no need to remove. No error. */
3958 /* In some cases, we might not be able to remove a breakpoint in
3959 a shared library that has already been removed, but we have
3960 not yet processed the shlib unload event. Similarly for an
3961 unloaded add-symbol-file object - the user might not yet have
3962 had the chance to remove-symbol-file it. shlib_disabled will
3963 be set if the library/object has already been removed, but
3964 the breakpoint hasn't been uninserted yet, e.g., after
3965 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3966 always-inserted mode. */
3968 && (bl
->loc_type
== bp_loc_software_breakpoint
3969 && (bl
->shlib_disabled
3970 || solib_name_from_address (bl
->pspace
, bl
->address
)
3971 || shared_objfile_contains_address_p (bl
->pspace
,
3977 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3979 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3981 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3982 bl
->owner
->remove_location (bl
, reason
);
3984 /* Failure to remove any of the hardware watchpoints comes here. */
3985 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3986 warning (_("Could not remove hardware watchpoint %d."),
3989 else if (bl
->owner
->type
== bp_catchpoint
3990 && breakpoint_enabled (bl
->owner
)
3993 val
= bl
->owner
->remove_location (bl
, reason
);
3997 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4004 remove_breakpoint (struct bp_location
*bl
)
4006 /* BL is never in moribund_locations by our callers. */
4007 gdb_assert (bl
->owner
!= NULL
);
4009 /* The type of none suggests that owner is actually deleted.
4010 This should not ever happen. */
4011 gdb_assert (bl
->owner
->type
!= bp_none
);
4013 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4015 switch_to_program_space_and_thread (bl
->pspace
);
4017 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4020 /* Clear the "inserted" flag in all breakpoints. */
4023 mark_breakpoints_out (void)
4025 for (bp_location
*bl
: all_bp_locations ())
4026 if (bl
->pspace
== current_program_space
)
4030 /* Clear the "inserted" flag in all breakpoints and delete any
4031 breakpoints which should go away between runs of the program.
4033 Plus other such housekeeping that has to be done for breakpoints
4036 Note: this function gets called at the end of a run (by
4037 generic_mourn_inferior) and when a run begins (by
4038 init_wait_for_inferior). */
4043 breakpoint_init_inferior (enum inf_context context
)
4045 struct program_space
*pspace
= current_program_space
;
4047 /* If breakpoint locations are shared across processes, then there's
4049 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4052 mark_breakpoints_out ();
4054 for (breakpoint
*b
: all_breakpoints_safe ())
4056 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4062 case bp_longjmp_call_dummy
:
4064 /* If the call dummy breakpoint is at the entry point it will
4065 cause problems when the inferior is rerun, so we better get
4068 case bp_watchpoint_scope
:
4070 /* Also get rid of scope breakpoints. */
4072 case bp_shlib_event
:
4074 /* Also remove solib event breakpoints. Their addresses may
4075 have changed since the last time we ran the program.
4076 Actually we may now be debugging against different target;
4077 and so the solib backend that installed this breakpoint may
4078 not be used in by the target. E.g.,
4080 (gdb) file prog-linux
4081 (gdb) run # native linux target
4084 (gdb) file prog-win.exe
4085 (gdb) tar rem :9999 # remote Windows gdbserver.
4088 case bp_step_resume
:
4090 /* Also remove step-resume breakpoints. */
4092 case bp_single_step
:
4094 /* Also remove single-step breakpoints. */
4096 delete_breakpoint (b
);
4100 case bp_hardware_watchpoint
:
4101 case bp_read_watchpoint
:
4102 case bp_access_watchpoint
:
4104 struct watchpoint
*w
= (struct watchpoint
*) b
;
4106 /* Likewise for watchpoints on local expressions. */
4107 if (w
->exp_valid_block
!= NULL
)
4108 delete_breakpoint (b
);
4111 /* Get rid of existing locations, which are no longer
4112 valid. New ones will be created in
4113 update_watchpoint, when the inferior is restarted.
4114 The next update_global_location_list call will
4115 garbage collect them. */
4118 if (context
== inf_starting
)
4120 /* Reset val field to force reread of starting value in
4121 insert_breakpoints. */
4122 w
->val
.reset (nullptr);
4123 w
->val_valid
= false;
4133 /* Get rid of the moribund locations. */
4134 for (bp_location
*bl
: moribund_locations
)
4135 decref_bp_location (&bl
);
4136 moribund_locations
.clear ();
4139 /* These functions concern about actual breakpoints inserted in the
4140 target --- to e.g. check if we need to do decr_pc adjustment or if
4141 we need to hop over the bkpt --- so we check for address space
4142 match, not program space. */
4144 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4145 exists at PC. It returns ordinary_breakpoint_here if it's an
4146 ordinary breakpoint, or permanent_breakpoint_here if it's a
4147 permanent breakpoint.
4148 - When continuing from a location with an ordinary breakpoint, we
4149 actually single step once before calling insert_breakpoints.
4150 - When continuing from a location with a permanent breakpoint, we
4151 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4152 the target, to advance the PC past the breakpoint. */
4154 enum breakpoint_here
4155 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4157 int any_breakpoint_here
= 0;
4159 for (bp_location
*bl
: all_bp_locations ())
4161 if (bl
->loc_type
!= bp_loc_software_breakpoint
4162 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4165 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4166 if ((breakpoint_enabled (bl
->owner
)
4168 && breakpoint_location_address_match (bl
, aspace
, pc
))
4170 if (overlay_debugging
4171 && section_is_overlay (bl
->section
)
4172 && !section_is_mapped (bl
->section
))
4173 continue; /* unmapped overlay -- can't be a match */
4174 else if (bl
->permanent
)
4175 return permanent_breakpoint_here
;
4177 any_breakpoint_here
= 1;
4181 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4184 /* See breakpoint.h. */
4187 breakpoint_in_range_p (const address_space
*aspace
,
4188 CORE_ADDR addr
, ULONGEST len
)
4190 for (bp_location
*bl
: all_bp_locations ())
4192 if (bl
->loc_type
!= bp_loc_software_breakpoint
4193 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4196 if ((breakpoint_enabled (bl
->owner
)
4198 && breakpoint_location_address_range_overlap (bl
, aspace
,
4201 if (overlay_debugging
4202 && section_is_overlay (bl
->section
)
4203 && !section_is_mapped (bl
->section
))
4205 /* Unmapped overlay -- can't be a match. */
4216 /* Return true if there's a moribund breakpoint at PC. */
4219 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4221 for (bp_location
*loc
: moribund_locations
)
4222 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4228 /* Returns non-zero iff BL is inserted at PC, in address space
4232 bp_location_inserted_here_p (struct bp_location
*bl
,
4233 const address_space
*aspace
, CORE_ADDR pc
)
4236 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4239 if (overlay_debugging
4240 && section_is_overlay (bl
->section
)
4241 && !section_is_mapped (bl
->section
))
4242 return 0; /* unmapped overlay -- can't be a match */
4249 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4252 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4254 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4256 if (bl
->loc_type
!= bp_loc_software_breakpoint
4257 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4260 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4266 /* This function returns non-zero iff there is a software breakpoint
4270 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4273 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4275 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4278 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4285 /* See breakpoint.h. */
4288 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4291 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4293 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4296 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4304 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4305 CORE_ADDR addr
, ULONGEST len
)
4307 for (breakpoint
*bpt
: all_breakpoints ())
4309 if (bpt
->type
!= bp_hardware_watchpoint
4310 && bpt
->type
!= bp_access_watchpoint
)
4313 if (!breakpoint_enabled (bpt
))
4316 for (bp_location
*loc
: bpt
->locations ())
4317 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4321 /* Check for intersection. */
4322 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4323 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4331 /* See breakpoint.h. */
4334 is_catchpoint (struct breakpoint
*b
)
4336 return (b
->type
== bp_catchpoint
);
4339 /* Clear a bpstat so that it says we are not at any breakpoint.
4340 Also free any storage that is part of a bpstat. */
4343 bpstat_clear (bpstat
**bsp
)
4360 bpstat::bpstat (const bpstat
&other
)
4362 bp_location_at (other
.bp_location_at
),
4363 breakpoint_at (other
.breakpoint_at
),
4364 commands (other
.commands
),
4365 print (other
.print
),
4367 print_it (other
.print_it
)
4369 if (other
.old_val
!= NULL
)
4370 old_val
= release_value (value_copy (other
.old_val
.get ()));
4373 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4374 is part of the bpstat is copied as well. */
4377 bpstat_copy (bpstat
*bs
)
4379 bpstat
*p
= nullptr;
4381 bpstat
*retval
= nullptr;
4386 for (; bs
!= NULL
; bs
= bs
->next
)
4388 tmp
= new bpstat (*bs
);
4391 /* This is the first thing in the chain. */
4401 /* Find the bpstat associated with this breakpoint. */
4404 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4409 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4411 if (bsp
->breakpoint_at
== breakpoint
)
4417 /* See breakpoint.h. */
4420 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4422 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4424 if (bsp
->breakpoint_at
== NULL
)
4426 /* A moribund location can never explain a signal other than
4428 if (sig
== GDB_SIGNAL_TRAP
)
4433 if (bsp
->breakpoint_at
->explains_signal (sig
))
4441 /* Put in *NUM the breakpoint number of the first breakpoint we are
4442 stopped at. *BSP upon return is a bpstat which points to the
4443 remaining breakpoints stopped at (but which is not guaranteed to be
4444 good for anything but further calls to bpstat_num).
4446 Return 0 if passed a bpstat which does not indicate any breakpoints.
4447 Return -1 if stopped at a breakpoint that has been deleted since
4449 Return 1 otherwise. */
4452 bpstat_num (bpstat
**bsp
, int *num
)
4454 struct breakpoint
*b
;
4457 return 0; /* No more breakpoint values */
4459 /* We assume we'll never have several bpstats that correspond to a
4460 single breakpoint -- otherwise, this function might return the
4461 same number more than once and this will look ugly. */
4462 b
= (*bsp
)->breakpoint_at
;
4463 *bsp
= (*bsp
)->next
;
4465 return -1; /* breakpoint that's been deleted since */
4467 *num
= b
->number
; /* We have its number */
4471 /* See breakpoint.h. */
4474 bpstat_clear_actions (void)
4478 if (inferior_ptid
== null_ptid
)
4481 thread_info
*tp
= inferior_thread ();
4482 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4484 bs
->commands
= NULL
;
4485 bs
->old_val
.reset (nullptr);
4489 /* Called when a command is about to proceed the inferior. */
4492 breakpoint_about_to_proceed (void)
4494 if (inferior_ptid
!= null_ptid
)
4496 struct thread_info
*tp
= inferior_thread ();
4498 /* Allow inferior function calls in breakpoint commands to not
4499 interrupt the command list. When the call finishes
4500 successfully, the inferior will be standing at the same
4501 breakpoint as if nothing happened. */
4502 if (tp
->control
.in_infcall
)
4506 breakpoint_proceeded
= 1;
4509 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4510 or its equivalent. */
4513 command_line_is_silent (struct command_line
*cmd
)
4515 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4518 /* Execute all the commands associated with all the breakpoints at
4519 this location. Any of these commands could cause the process to
4520 proceed beyond this point, etc. We look out for such changes by
4521 checking the global "breakpoint_proceeded" after each command.
4523 Returns true if a breakpoint command resumed the inferior. In that
4524 case, it is the caller's responsibility to recall it again with the
4525 bpstat of the current thread. */
4528 bpstat_do_actions_1 (bpstat
**bsp
)
4533 /* Avoid endless recursion if a `source' command is contained
4535 if (executing_breakpoint_commands
)
4538 scoped_restore save_executing
4539 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4541 scoped_restore preventer
= prevent_dont_repeat ();
4543 /* This pointer will iterate over the list of bpstat's. */
4546 breakpoint_proceeded
= 0;
4547 for (; bs
!= NULL
; bs
= bs
->next
)
4549 struct command_line
*cmd
= NULL
;
4551 /* Take ownership of the BSP's command tree, if it has one.
4553 The command tree could legitimately contain commands like
4554 'step' and 'next', which call clear_proceed_status, which
4555 frees stop_bpstat's command tree. To make sure this doesn't
4556 free the tree we're executing out from under us, we need to
4557 take ownership of the tree ourselves. Since a given bpstat's
4558 commands are only executed once, we don't need to copy it; we
4559 can clear the pointer in the bpstat, and make sure we free
4560 the tree when we're done. */
4561 counted_command_line ccmd
= bs
->commands
;
4562 bs
->commands
= NULL
;
4565 if (command_line_is_silent (cmd
))
4567 /* The action has been already done by bpstat_stop_status. */
4573 execute_control_command (cmd
);
4575 if (breakpoint_proceeded
)
4581 if (breakpoint_proceeded
)
4583 if (current_ui
->async
)
4584 /* If we are in async mode, then the target might be still
4585 running, not stopped at any breakpoint, so nothing for
4586 us to do here -- just return to the event loop. */
4589 /* In sync mode, when execute_control_command returns
4590 we're already standing on the next breakpoint.
4591 Breakpoint commands for that stop were not run, since
4592 execute_command does not run breakpoint commands --
4593 only command_line_handler does, but that one is not
4594 involved in execution of breakpoint commands. So, we
4595 can now execute breakpoint commands. It should be
4596 noted that making execute_command do bpstat actions is
4597 not an option -- in this case we'll have recursive
4598 invocation of bpstat for each breakpoint with a
4599 command, and can easily blow up GDB stack. Instead, we
4600 return true, which will trigger the caller to recall us
4601 with the new stop_bpstat. */
4609 /* Helper for bpstat_do_actions. Get the current thread, if there's
4610 one, is alive and has execution. Return NULL otherwise. */
4612 static thread_info
*
4613 get_bpstat_thread ()
4615 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4618 thread_info
*tp
= inferior_thread ();
4619 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4625 bpstat_do_actions (void)
4627 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4630 /* Do any commands attached to breakpoint we are stopped at. */
4631 while ((tp
= get_bpstat_thread ()) != NULL
)
4633 /* Since in sync mode, bpstat_do_actions may resume the
4634 inferior, and only return when it is stopped at the next
4635 breakpoint, we keep doing breakpoint actions until it returns
4636 false to indicate the inferior was not resumed. */
4637 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4641 cleanup_if_error
.release ();
4644 /* Print out the (old or new) value associated with a watchpoint. */
4647 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4650 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4653 struct value_print_options opts
;
4654 get_user_print_options (&opts
);
4655 value_print (val
, stream
, &opts
);
4659 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4660 debugging multiple threads. */
4663 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4665 if (uiout
->is_mi_like_p ())
4670 if (show_thread_that_caused_stop ())
4672 struct thread_info
*thr
= inferior_thread ();
4674 uiout
->text ("Thread ");
4675 uiout
->field_string ("thread-id", print_thread_id (thr
));
4677 const char *name
= thread_name (thr
);
4680 uiout
->text (" \"");
4681 uiout
->field_string ("name", name
);
4685 uiout
->text (" hit ");
4689 /* Generic routine for printing messages indicating why we
4690 stopped. The behavior of this function depends on the value
4691 'print_it' in the bpstat structure. Under some circumstances we
4692 may decide not to print anything here and delegate the task to
4695 static enum print_stop_action
4696 print_bp_stop_message (bpstat
*bs
)
4698 switch (bs
->print_it
)
4701 /* Nothing should be printed for this bpstat entry. */
4702 return PRINT_UNKNOWN
;
4706 /* We still want to print the frame, but we already printed the
4707 relevant messages. */
4708 return PRINT_SRC_AND_LOC
;
4711 case print_it_normal
:
4713 struct breakpoint
*b
= bs
->breakpoint_at
;
4715 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4716 which has since been deleted. */
4718 return PRINT_UNKNOWN
;
4720 /* Normal case. Call the breakpoint's print_it method. */
4721 return b
->print_it (bs
);
4726 internal_error (__FILE__
, __LINE__
,
4727 _("print_bp_stop_message: unrecognized enum value"));
4732 /* See breakpoint.h. */
4735 print_solib_event (bool is_catchpoint
)
4737 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4738 bool any_added
= !current_program_space
->added_solibs
.empty ();
4742 if (any_added
|| any_deleted
)
4743 current_uiout
->text (_("Stopped due to shared library event:\n"));
4745 current_uiout
->text (_("Stopped due to shared library event (no "
4746 "libraries added or removed)\n"));
4749 if (current_uiout
->is_mi_like_p ())
4750 current_uiout
->field_string ("reason",
4751 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4755 current_uiout
->text (_(" Inferior unloaded "));
4756 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4757 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4759 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4762 current_uiout
->text (" ");
4763 current_uiout
->field_string ("library", name
);
4764 current_uiout
->text ("\n");
4770 current_uiout
->text (_(" Inferior loaded "));
4771 ui_out_emit_list
list_emitter (current_uiout
, "added");
4773 for (so_list
*iter
: current_program_space
->added_solibs
)
4776 current_uiout
->text (" ");
4778 current_uiout
->field_string ("library", iter
->so_name
);
4779 current_uiout
->text ("\n");
4784 /* Print a message indicating what happened. This is called from
4785 normal_stop(). The input to this routine is the head of the bpstat
4786 list - a list of the eventpoints that caused this stop. KIND is
4787 the target_waitkind for the stopping event. This
4788 routine calls the generic print routine for printing a message
4789 about reasons for stopping. This will print (for example) the
4790 "Breakpoint n," part of the output. The return value of this
4793 PRINT_UNKNOWN: Means we printed nothing.
4794 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4795 code to print the location. An example is
4796 "Breakpoint 1, " which should be followed by
4798 PRINT_SRC_ONLY: Means we printed something, but there is no need
4799 to also print the location part of the message.
4800 An example is the catch/throw messages, which
4801 don't require a location appended to the end.
4802 PRINT_NOTHING: We have done some printing and we don't need any
4803 further info to be printed. */
4805 enum print_stop_action
4806 bpstat_print (bpstat
*bs
, target_waitkind kind
)
4808 enum print_stop_action val
;
4810 /* Maybe another breakpoint in the chain caused us to stop.
4811 (Currently all watchpoints go on the bpstat whether hit or not.
4812 That probably could (should) be changed, provided care is taken
4813 with respect to bpstat_explains_signal). */
4814 for (; bs
; bs
= bs
->next
)
4816 val
= print_bp_stop_message (bs
);
4817 if (val
== PRINT_SRC_ONLY
4818 || val
== PRINT_SRC_AND_LOC
4819 || val
== PRINT_NOTHING
)
4823 /* If we had hit a shared library event breakpoint,
4824 print_bp_stop_message would print out this message. If we hit an
4825 OS-level shared library event, do the same thing. */
4826 if (kind
== TARGET_WAITKIND_LOADED
)
4828 print_solib_event (false);
4829 return PRINT_NOTHING
;
4832 /* We reached the end of the chain, or we got a null BS to start
4833 with and nothing was printed. */
4834 return PRINT_UNKNOWN
;
4837 /* Evaluate the boolean expression EXP and return the result. */
4840 breakpoint_cond_eval (expression
*exp
)
4842 struct value
*mark
= value_mark ();
4843 bool res
= value_true (evaluate_expression (exp
));
4845 value_free_to_mark (mark
);
4849 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4851 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4853 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4854 breakpoint_at (bl
->owner
),
4858 print_it (print_it_normal
)
4860 **bs_link_pointer
= this;
4861 *bs_link_pointer
= &next
;
4866 breakpoint_at (NULL
),
4870 print_it (print_it_normal
)
4874 /* The target has stopped with waitstatus WS. Check if any hardware
4875 watchpoints have triggered, according to the target. */
4878 watchpoints_triggered (const target_waitstatus
&ws
)
4880 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4883 if (!stopped_by_watchpoint
)
4885 /* We were not stopped by a watchpoint. Mark all watchpoints
4886 as not triggered. */
4887 for (breakpoint
*b
: all_breakpoints ())
4888 if (is_hardware_watchpoint (b
))
4890 struct watchpoint
*w
= (struct watchpoint
*) b
;
4892 w
->watchpoint_triggered
= watch_triggered_no
;
4898 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4900 /* We were stopped by a watchpoint, but we don't know where.
4901 Mark all watchpoints as unknown. */
4902 for (breakpoint
*b
: all_breakpoints ())
4903 if (is_hardware_watchpoint (b
))
4905 struct watchpoint
*w
= (struct watchpoint
*) b
;
4907 w
->watchpoint_triggered
= watch_triggered_unknown
;
4913 /* The target could report the data address. Mark watchpoints
4914 affected by this data address as triggered, and all others as not
4917 for (breakpoint
*b
: all_breakpoints ())
4918 if (is_hardware_watchpoint (b
))
4920 struct watchpoint
*w
= (struct watchpoint
*) b
;
4922 w
->watchpoint_triggered
= watch_triggered_no
;
4923 for (bp_location
*loc
: b
->locations ())
4925 if (is_masked_watchpoint (b
))
4927 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4928 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4930 if (newaddr
== start
)
4932 w
->watchpoint_triggered
= watch_triggered_yes
;
4936 /* Exact match not required. Within range is sufficient. */
4937 else if (target_watchpoint_addr_within_range
4938 (current_inferior ()->top_target (), addr
, loc
->address
,
4941 w
->watchpoint_triggered
= watch_triggered_yes
;
4950 /* Possible return values for watchpoint_check. */
4951 enum wp_check_result
4953 /* The watchpoint has been deleted. */
4956 /* The value has changed. */
4957 WP_VALUE_CHANGED
= 2,
4959 /* The value has not changed. */
4960 WP_VALUE_NOT_CHANGED
= 3,
4962 /* Ignore this watchpoint, no matter if the value changed or not. */
4966 #define BP_TEMPFLAG 1
4967 #define BP_HARDWAREFLAG 2
4969 /* Evaluate watchpoint condition expression and check if its value
4972 static wp_check_result
4973 watchpoint_check (bpstat
*bs
)
4975 struct watchpoint
*b
;
4976 struct frame_info
*fr
;
4977 int within_current_scope
;
4979 /* BS is built from an existing struct breakpoint. */
4980 gdb_assert (bs
->breakpoint_at
!= NULL
);
4981 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4983 /* If this is a local watchpoint, we only want to check if the
4984 watchpoint frame is in scope if the current thread is the thread
4985 that was used to create the watchpoint. */
4986 if (!watchpoint_in_thread_scope (b
))
4989 if (b
->exp_valid_block
== NULL
)
4990 within_current_scope
= 1;
4993 struct frame_info
*frame
= get_current_frame ();
4994 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4995 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4997 /* stack_frame_destroyed_p() returns a non-zero value if we're
4998 still in the function but the stack frame has already been
4999 invalidated. Since we can't rely on the values of local
5000 variables after the stack has been destroyed, we are treating
5001 the watchpoint in that state as `not changed' without further
5002 checking. Don't mark watchpoints as changed if the current
5003 frame is in an epilogue - even if they are in some other
5004 frame, our view of the stack is likely to be wrong and
5005 frame_find_by_id could error out. */
5006 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5009 fr
= frame_find_by_id (b
->watchpoint_frame
);
5010 within_current_scope
= (fr
!= NULL
);
5012 /* If we've gotten confused in the unwinder, we might have
5013 returned a frame that can't describe this variable. */
5014 if (within_current_scope
)
5016 struct symbol
*function
;
5018 function
= get_frame_function (fr
);
5019 if (function
== NULL
5020 || !contained_in (b
->exp_valid_block
, function
->value_block ()))
5021 within_current_scope
= 0;
5024 if (within_current_scope
)
5025 /* If we end up stopping, the current frame will get selected
5026 in normal_stop. So this call to select_frame won't affect
5031 if (within_current_scope
)
5033 /* We use value_{,free_to_}mark because it could be a *long*
5034 time before we return to the command level and call
5035 free_all_values. We can't call free_all_values because we
5036 might be in the middle of evaluating a function call. */
5039 struct value
*new_val
;
5041 if (is_masked_watchpoint (b
))
5042 /* Since we don't know the exact trigger address (from
5043 stopped_data_address), just tell the user we've triggered
5044 a mask watchpoint. */
5045 return WP_VALUE_CHANGED
;
5047 mark
= value_mark ();
5048 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5051 if (b
->val_bitsize
!= 0)
5052 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5054 /* We use value_equal_contents instead of value_equal because
5055 the latter coerces an array to a pointer, thus comparing just
5056 the address of the array instead of its contents. This is
5057 not what we want. */
5058 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5059 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5062 bs
->old_val
= b
->val
;
5063 b
->val
= release_value (new_val
);
5064 b
->val_valid
= true;
5065 if (new_val
!= NULL
)
5066 value_free_to_mark (mark
);
5067 return WP_VALUE_CHANGED
;
5071 /* Nothing changed. */
5072 value_free_to_mark (mark
);
5073 return WP_VALUE_NOT_CHANGED
;
5078 /* This seems like the only logical thing to do because
5079 if we temporarily ignored the watchpoint, then when
5080 we reenter the block in which it is valid it contains
5081 garbage (in the case of a function, it may have two
5082 garbage values, one before and one after the prologue).
5083 So we can't even detect the first assignment to it and
5084 watch after that (since the garbage may or may not equal
5085 the first value assigned). */
5086 /* We print all the stop information in
5087 breakpointprint_it, but in this case, by the time we
5088 call breakpoint->print_it this bp will be deleted
5089 already. So we have no choice but print the information
5092 SWITCH_THRU_ALL_UIS ()
5094 struct ui_out
*uiout
= current_uiout
;
5096 if (uiout
->is_mi_like_p ())
5098 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5099 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5100 "left the block in\n"
5101 "which its expression is valid.\n",
5102 signed_field ("wpnum", b
->number
));
5105 /* Make sure the watchpoint's commands aren't executed. */
5107 watchpoint_del_at_next_stop (b
);
5113 /* Return true if it looks like target has stopped due to hitting
5114 breakpoint location BL. This function does not check if we should
5115 stop, only if BL explains the stop. */
5118 bpstat_check_location (const struct bp_location
*bl
,
5119 const address_space
*aspace
, CORE_ADDR bp_addr
,
5120 const target_waitstatus
&ws
)
5122 struct breakpoint
*b
= bl
->owner
;
5124 /* BL is from an existing breakpoint. */
5125 gdb_assert (b
!= NULL
);
5127 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5130 /* Determine if the watched values have actually changed, and we
5131 should stop. If not, set BS->stop to 0. */
5134 bpstat_check_watchpoint (bpstat
*bs
)
5136 const struct bp_location
*bl
;
5137 struct watchpoint
*b
;
5139 /* BS is built for existing struct breakpoint. */
5140 bl
= bs
->bp_location_at
.get ();
5141 gdb_assert (bl
!= NULL
);
5142 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5143 gdb_assert (b
!= NULL
);
5146 int must_check_value
= 0;
5148 if (b
->type
== bp_watchpoint
)
5149 /* For a software watchpoint, we must always check the
5151 must_check_value
= 1;
5152 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5153 /* We have a hardware watchpoint (read, write, or access)
5154 and the target earlier reported an address watched by
5156 must_check_value
= 1;
5157 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5158 && b
->type
== bp_hardware_watchpoint
)
5159 /* We were stopped by a hardware watchpoint, but the target could
5160 not report the data address. We must check the watchpoint's
5161 value. Access and read watchpoints are out of luck; without
5162 a data address, we can't figure it out. */
5163 must_check_value
= 1;
5165 if (must_check_value
)
5171 e
= watchpoint_check (bs
);
5173 catch (const gdb_exception
&ex
)
5175 exception_fprintf (gdb_stderr
, ex
,
5176 "Error evaluating expression "
5177 "for watchpoint %d\n",
5180 SWITCH_THRU_ALL_UIS ()
5182 gdb_printf (_("Watchpoint %d deleted.\n"),
5185 watchpoint_del_at_next_stop (b
);
5192 /* We've already printed what needs to be printed. */
5193 bs
->print_it
= print_it_done
;
5197 bs
->print_it
= print_it_noop
;
5200 case WP_VALUE_CHANGED
:
5201 if (b
->type
== bp_read_watchpoint
)
5203 /* There are two cases to consider here:
5205 1. We're watching the triggered memory for reads.
5206 In that case, trust the target, and always report
5207 the watchpoint hit to the user. Even though
5208 reads don't cause value changes, the value may
5209 have changed since the last time it was read, and
5210 since we're not trapping writes, we will not see
5211 those, and as such we should ignore our notion of
5214 2. We're watching the triggered memory for both
5215 reads and writes. There are two ways this may
5218 2.1. This is a target that can't break on data
5219 reads only, but can break on accesses (reads or
5220 writes), such as e.g., x86. We detect this case
5221 at the time we try to insert read watchpoints.
5223 2.2. Otherwise, the target supports read
5224 watchpoints, but, the user set an access or write
5225 watchpoint watching the same memory as this read
5228 If we're watching memory writes as well as reads,
5229 ignore watchpoint hits when we find that the
5230 value hasn't changed, as reads don't cause
5231 changes. This still gives false positives when
5232 the program writes the same value to memory as
5233 what there was already in memory (we will confuse
5234 it for a read), but it's much better than
5237 int other_write_watchpoint
= 0;
5239 if (bl
->watchpoint_type
== hw_read
)
5241 for (breakpoint
*other_b
: all_breakpoints ())
5242 if (other_b
->type
== bp_hardware_watchpoint
5243 || other_b
->type
== bp_access_watchpoint
)
5245 struct watchpoint
*other_w
=
5246 (struct watchpoint
*) other_b
;
5248 if (other_w
->watchpoint_triggered
5249 == watch_triggered_yes
)
5251 other_write_watchpoint
= 1;
5257 if (other_write_watchpoint
5258 || bl
->watchpoint_type
== hw_access
)
5260 /* We're watching the same memory for writes,
5261 and the value changed since the last time we
5262 updated it, so this trap must be for a write.
5264 bs
->print_it
= print_it_noop
;
5269 case WP_VALUE_NOT_CHANGED
:
5270 if (b
->type
== bp_hardware_watchpoint
5271 || b
->type
== bp_watchpoint
)
5273 /* Don't stop: write watchpoints shouldn't fire if
5274 the value hasn't changed. */
5275 bs
->print_it
= print_it_noop
;
5285 else /* must_check_value == 0 */
5287 /* This is a case where some watchpoint(s) triggered, but
5288 not at the address of this watchpoint, or else no
5289 watchpoint triggered after all. So don't print
5290 anything for this watchpoint. */
5291 bs
->print_it
= print_it_noop
;
5297 /* For breakpoints that are currently marked as telling gdb to stop,
5298 check conditions (condition proper, frame, thread and ignore count)
5299 of breakpoint referred to by BS. If we should not stop for this
5300 breakpoint, set BS->stop to 0. */
5303 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5305 const struct bp_location
*bl
;
5306 struct breakpoint
*b
;
5308 bool condition_result
= true;
5309 struct expression
*cond
;
5311 gdb_assert (bs
->stop
);
5313 /* BS is built for existing struct breakpoint. */
5314 bl
= bs
->bp_location_at
.get ();
5315 gdb_assert (bl
!= NULL
);
5316 b
= bs
->breakpoint_at
;
5317 gdb_assert (b
!= NULL
);
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 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5330 /* If this is a thread/task-specific breakpoint, don't waste cpu
5331 evaluating the condition if this isn't the specified
5333 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5334 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5340 /* Evaluate extension language breakpoints that have a "stop" method
5342 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5344 if (is_watchpoint (b
))
5346 struct watchpoint
*w
= (struct watchpoint
*) b
;
5348 cond
= w
->cond_exp
.get ();
5351 cond
= bl
->cond
.get ();
5353 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5355 int within_current_scope
= 1;
5356 struct watchpoint
* w
;
5358 /* We use value_mark and value_free_to_mark because it could
5359 be a long time before we return to the command level and
5360 call free_all_values. We can't call free_all_values
5361 because we might be in the middle of evaluating a
5363 struct value
*mark
= value_mark ();
5365 if (is_watchpoint (b
))
5366 w
= (struct watchpoint
*) b
;
5370 /* Need to select the frame, with all that implies so that
5371 the conditions will have the right context. Because we
5372 use the frame, we will not see an inlined function's
5373 variables when we arrive at a breakpoint at the start
5374 of the inlined function; the current frame will be the
5376 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5377 select_frame (get_current_frame ());
5380 struct frame_info
*frame
;
5382 /* For local watchpoint expressions, which particular
5383 instance of a local is being watched matters, so we
5384 keep track of the frame to evaluate the expression
5385 in. To evaluate the condition however, it doesn't
5386 really matter which instantiation of the function
5387 where the condition makes sense triggers the
5388 watchpoint. This allows an expression like "watch
5389 global if q > 10" set in `func', catch writes to
5390 global on all threads that call `func', or catch
5391 writes on all recursive calls of `func' by a single
5392 thread. We simply always evaluate the condition in
5393 the innermost frame that's executing where it makes
5394 sense to evaluate the condition. It seems
5396 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5398 select_frame (frame
);
5400 within_current_scope
= 0;
5402 if (within_current_scope
)
5406 condition_result
= breakpoint_cond_eval (cond
);
5408 catch (const gdb_exception
&ex
)
5410 exception_fprintf (gdb_stderr
, ex
,
5411 "Error in testing breakpoint condition:\n");
5416 warning (_("Watchpoint condition cannot be tested "
5417 "in the current scope"));
5418 /* If we failed to set the right context for this
5419 watchpoint, unconditionally report it. */
5421 /* FIXME-someday, should give breakpoint #. */
5422 value_free_to_mark (mark
);
5425 if (cond
&& !condition_result
)
5429 else if (b
->ignore_count
> 0)
5433 /* Increase the hit count even though we don't stop. */
5435 gdb::observers::breakpoint_modified
.notify (b
);
5439 /* Returns true if we need to track moribund locations of LOC's type
5440 on the current target. */
5443 need_moribund_for_location_type (struct bp_location
*loc
)
5445 return ((loc
->loc_type
== bp_loc_software_breakpoint
5446 && !target_supports_stopped_by_sw_breakpoint ())
5447 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5448 && !target_supports_stopped_by_hw_breakpoint ()));
5451 /* See breakpoint.h. */
5454 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5455 const target_waitstatus
&ws
)
5457 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5459 for (breakpoint
*b
: all_breakpoints ())
5461 if (!breakpoint_enabled (b
))
5464 for (bp_location
*bl
: b
->locations ())
5466 /* For hardware watchpoints, we look only at the first
5467 location. The watchpoint_check function will work on the
5468 entire expression, not the individual locations. For
5469 read watchpoints, the watchpoints_triggered function has
5470 checked all locations already. */
5471 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5474 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5477 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5480 /* Come here if it's a watchpoint, or if the break address
5483 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5486 /* Assume we stop. Should we find a watchpoint that is not
5487 actually triggered, or if the condition of the breakpoint
5488 evaluates as false, we'll reset 'stop' to 0. */
5492 /* If this is a scope breakpoint, mark the associated
5493 watchpoint as triggered so that we will handle the
5494 out-of-scope event. We'll get to the watchpoint next
5496 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5498 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5500 w
->watchpoint_triggered
= watch_triggered_yes
;
5505 /* Check if a moribund breakpoint explains the stop. */
5506 if (!target_supports_stopped_by_sw_breakpoint ()
5507 || !target_supports_stopped_by_hw_breakpoint ())
5509 for (bp_location
*loc
: moribund_locations
)
5511 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5512 && need_moribund_for_location_type (loc
))
5514 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5515 /* For hits of moribund locations, we should just proceed. */
5518 bs
->print_it
= print_it_noop
;
5526 /* See breakpoint.h. */
5529 bpstat_stop_status (const address_space
*aspace
,
5530 CORE_ADDR bp_addr
, thread_info
*thread
,
5531 const target_waitstatus
&ws
,
5534 struct breakpoint
*b
= NULL
;
5535 /* First item of allocated bpstat's. */
5536 bpstat
*bs_head
= stop_chain
;
5538 int need_remove_insert
;
5541 /* First, build the bpstat chain with locations that explain a
5542 target stop, while being careful to not set the target running,
5543 as that may invalidate locations (in particular watchpoint
5544 locations are recreated). Resuming will happen here with
5545 breakpoint conditions or watchpoint expressions that include
5546 inferior function calls. */
5547 if (bs_head
== NULL
)
5548 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5550 /* A bit of special processing for shlib breakpoints. We need to
5551 process solib loading here, so that the lists of loaded and
5552 unloaded libraries are correct before we handle "catch load" and
5554 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5556 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5558 handle_solib_event ();
5563 /* Now go through the locations that caused the target to stop, and
5564 check whether we're interested in reporting this stop to higher
5565 layers, or whether we should resume the target transparently. */
5569 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5574 b
= bs
->breakpoint_at
;
5575 b
->check_status (bs
);
5578 bpstat_check_breakpoint_conditions (bs
, thread
);
5584 /* We will stop here. */
5585 if (b
->disposition
== disp_disable
)
5587 --(b
->enable_count
);
5588 if (b
->enable_count
<= 0)
5589 b
->enable_state
= bp_disabled
;
5592 gdb::observers::breakpoint_modified
.notify (b
);
5595 bs
->commands
= b
->commands
;
5596 if (command_line_is_silent (bs
->commands
5597 ? bs
->commands
.get () : NULL
))
5600 b
->after_condition_true (bs
);
5605 /* Print nothing for this entry if we don't stop or don't
5607 if (!bs
->stop
|| !bs
->print
)
5608 bs
->print_it
= print_it_noop
;
5611 /* If we aren't stopping, the value of some hardware watchpoint may
5612 not have changed, but the intermediate memory locations we are
5613 watching may have. Don't bother if we're stopping; this will get
5615 need_remove_insert
= 0;
5616 if (! bpstat_causes_stop (bs_head
))
5617 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5619 && bs
->breakpoint_at
5620 && is_hardware_watchpoint (bs
->breakpoint_at
))
5622 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5624 update_watchpoint (w
, 0 /* don't reparse. */);
5625 need_remove_insert
= 1;
5628 if (need_remove_insert
)
5629 update_global_location_list (UGLL_MAY_INSERT
);
5630 else if (removed_any
)
5631 update_global_location_list (UGLL_DONT_INSERT
);
5636 /* See breakpoint.h. */
5639 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5640 thread_info
*thread
, const target_waitstatus
&ws
)
5642 gdb_assert (!target_stopped_by_watchpoint ());
5644 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5645 previous stop to avoid confusing bpstat_stop_status. */
5646 watchpoints_triggered (ws
);
5648 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5652 handle_jit_event (CORE_ADDR address
)
5654 struct gdbarch
*gdbarch
;
5656 infrun_debug_printf ("handling bp_jit_event");
5658 /* Switch terminal for any messages produced by
5659 breakpoint_re_set. */
5660 target_terminal::ours_for_output ();
5662 gdbarch
= get_frame_arch (get_current_frame ());
5663 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5664 thus it is expected that its objectfile can be found through
5665 minimal symbol lookup. If it doesn't work (and assert fails), it
5666 most likely means that `jit_breakpoint_re_set` was changes and this
5667 function needs to be updated too. */
5668 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5669 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5670 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5672 target_terminal::inferior ();
5675 /* Prepare WHAT final decision for infrun. */
5677 /* Decide what infrun needs to do with this bpstat. */
5680 bpstat_what (bpstat
*bs_head
)
5682 struct bpstat_what retval
;
5685 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5686 retval
.call_dummy
= STOP_NONE
;
5687 retval
.is_longjmp
= false;
5689 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5691 /* Extract this BS's action. After processing each BS, we check
5692 if its action overrides all we've seem so far. */
5693 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5696 if (bs
->breakpoint_at
== NULL
)
5698 /* I suspect this can happen if it was a momentary
5699 breakpoint which has since been deleted. */
5703 bptype
= bs
->breakpoint_at
->type
;
5710 case bp_hardware_breakpoint
:
5711 case bp_single_step
:
5714 case bp_shlib_event
:
5718 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5720 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5723 this_action
= BPSTAT_WHAT_SINGLE
;
5726 case bp_hardware_watchpoint
:
5727 case bp_read_watchpoint
:
5728 case bp_access_watchpoint
:
5732 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5734 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5738 /* There was a watchpoint, but we're not stopping.
5739 This requires no further action. */
5743 case bp_longjmp_call_dummy
:
5747 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5748 retval
.is_longjmp
= bptype
!= bp_exception
;
5751 this_action
= BPSTAT_WHAT_SINGLE
;
5753 case bp_longjmp_resume
:
5754 case bp_exception_resume
:
5757 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5758 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5761 this_action
= BPSTAT_WHAT_SINGLE
;
5763 case bp_step_resume
:
5765 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5768 /* It is for the wrong frame. */
5769 this_action
= BPSTAT_WHAT_SINGLE
;
5772 case bp_hp_step_resume
:
5774 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5777 /* It is for the wrong frame. */
5778 this_action
= BPSTAT_WHAT_SINGLE
;
5781 case bp_watchpoint_scope
:
5782 case bp_thread_event
:
5783 case bp_overlay_event
:
5784 case bp_longjmp_master
:
5785 case bp_std_terminate_master
:
5786 case bp_exception_master
:
5787 this_action
= BPSTAT_WHAT_SINGLE
;
5793 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5795 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5799 /* Some catchpoints are implemented with breakpoints.
5800 For those, we need to step over the breakpoint. */
5801 if (bs
->bp_location_at
->loc_type
== bp_loc_software_breakpoint
5802 || bs
->bp_location_at
->loc_type
== bp_loc_hardware_breakpoint
)
5803 this_action
= BPSTAT_WHAT_SINGLE
;
5807 this_action
= BPSTAT_WHAT_SINGLE
;
5810 /* Make sure the action is stop (silent or noisy),
5811 so infrun.c pops the dummy frame. */
5812 retval
.call_dummy
= STOP_STACK_DUMMY
;
5813 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5815 case bp_std_terminate
:
5816 /* Make sure the action is stop (silent or noisy),
5817 so infrun.c pops the dummy frame. */
5818 retval
.call_dummy
= STOP_STD_TERMINATE
;
5819 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5822 case bp_fast_tracepoint
:
5823 case bp_static_tracepoint
:
5824 case bp_static_marker_tracepoint
:
5825 /* Tracepoint hits should not be reported back to GDB, and
5826 if one got through somehow, it should have been filtered
5828 internal_error (__FILE__
, __LINE__
,
5829 _("bpstat_what: tracepoint encountered"));
5831 case bp_gnu_ifunc_resolver
:
5832 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5833 this_action
= BPSTAT_WHAT_SINGLE
;
5835 case bp_gnu_ifunc_resolver_return
:
5836 /* The breakpoint will be removed, execution will restart from the
5837 PC of the former breakpoint. */
5838 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5843 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5845 this_action
= BPSTAT_WHAT_SINGLE
;
5849 internal_error (__FILE__
, __LINE__
,
5850 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5853 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5860 bpstat_run_callbacks (bpstat
*bs_head
)
5864 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5866 struct breakpoint
*b
= bs
->breakpoint_at
;
5873 handle_jit_event (bs
->bp_location_at
->address
);
5875 case bp_gnu_ifunc_resolver
:
5876 gnu_ifunc_resolver_stop ((code_breakpoint
*) b
);
5878 case bp_gnu_ifunc_resolver_return
:
5879 gnu_ifunc_resolver_return_stop ((code_breakpoint
*) b
);
5885 /* See breakpoint.h. */
5888 bpstat_should_step ()
5890 for (breakpoint
*b
: all_breakpoints ())
5891 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5897 /* See breakpoint.h. */
5900 bpstat_causes_stop (bpstat
*bs
)
5902 for (; bs
!= NULL
; bs
= bs
->next
)
5911 /* Compute a number of spaces suitable to indent the next line
5912 so it starts at the position corresponding to the table column
5913 named COL_NAME in the currently active table of UIOUT. */
5916 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5918 int i
, total_width
, width
, align
;
5922 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5924 if (strcmp (text
, col_name
) == 0)
5927 total_width
+= width
+ 1;
5933 /* Determine if the locations of this breakpoint will have their conditions
5934 evaluated by the target, host or a mix of both. Returns the following:
5936 "host": Host evals condition.
5937 "host or target": Host or Target evals condition.
5938 "target": Target evals condition.
5942 bp_condition_evaluator (const breakpoint
*b
)
5944 char host_evals
= 0;
5945 char target_evals
= 0;
5950 if (!is_breakpoint (b
))
5953 if (gdb_evaluates_breakpoint_condition_p ()
5954 || !target_supports_evaluation_of_breakpoint_conditions ())
5955 return condition_evaluation_host
;
5957 for (bp_location
*bl
: b
->locations ())
5959 if (bl
->cond_bytecode
)
5965 if (host_evals
&& target_evals
)
5966 return condition_evaluation_both
;
5967 else if (target_evals
)
5968 return condition_evaluation_target
;
5970 return condition_evaluation_host
;
5973 /* Determine the breakpoint location's condition evaluator. This is
5974 similar to bp_condition_evaluator, but for locations. */
5977 bp_location_condition_evaluator (struct bp_location
*bl
)
5979 if (bl
&& !is_breakpoint (bl
->owner
))
5982 if (gdb_evaluates_breakpoint_condition_p ()
5983 || !target_supports_evaluation_of_breakpoint_conditions ())
5984 return condition_evaluation_host
;
5986 if (bl
&& bl
->cond_bytecode
)
5987 return condition_evaluation_target
;
5989 return condition_evaluation_host
;
5992 /* Print the LOC location out of the list of B->LOC locations. */
5995 print_breakpoint_location (const breakpoint
*b
,
5996 struct bp_location
*loc
)
5998 struct ui_out
*uiout
= current_uiout
;
6000 scoped_restore_current_program_space restore_pspace
;
6002 if (loc
!= NULL
&& loc
->shlib_disabled
)
6006 set_current_program_space (loc
->pspace
);
6008 if (b
->display_canonical
)
6009 uiout
->field_string ("what", b
->locspec
->to_string ());
6010 else if (loc
&& loc
->symtab
)
6012 const struct symbol
*sym
= loc
->symbol
;
6016 uiout
->text ("in ");
6017 uiout
->field_string ("func", sym
->print_name (),
6018 function_name_style
.style ());
6020 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6021 uiout
->text ("at ");
6023 uiout
->field_string ("file",
6024 symtab_to_filename_for_display (loc
->symtab
),
6025 file_name_style
.style ());
6028 if (uiout
->is_mi_like_p ())
6029 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6031 uiout
->field_signed ("line", loc
->line_number
);
6037 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6039 uiout
->field_stream ("at", stb
);
6043 uiout
->field_string ("pending", b
->locspec
->to_string ());
6044 /* If extra_string is available, it could be holding a condition
6045 or dprintf arguments. In either case, make sure it is printed,
6046 too, but only for non-MI streams. */
6047 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6049 if (b
->type
== bp_dprintf
)
6053 uiout
->text (b
->extra_string
.get ());
6057 if (loc
&& is_breakpoint (b
)
6058 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6059 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6062 uiout
->field_string ("evaluated-by",
6063 bp_location_condition_evaluator (loc
));
6069 bptype_string (enum bptype type
)
6071 struct ep_type_description
6074 const char *description
;
6076 static struct ep_type_description bptypes
[] =
6078 {bp_none
, "?deleted?"},
6079 {bp_breakpoint
, "breakpoint"},
6080 {bp_hardware_breakpoint
, "hw breakpoint"},
6081 {bp_single_step
, "sw single-step"},
6082 {bp_until
, "until"},
6083 {bp_finish
, "finish"},
6084 {bp_watchpoint
, "watchpoint"},
6085 {bp_hardware_watchpoint
, "hw watchpoint"},
6086 {bp_read_watchpoint
, "read watchpoint"},
6087 {bp_access_watchpoint
, "acc watchpoint"},
6088 {bp_longjmp
, "longjmp"},
6089 {bp_longjmp_resume
, "longjmp resume"},
6090 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6091 {bp_exception
, "exception"},
6092 {bp_exception_resume
, "exception resume"},
6093 {bp_step_resume
, "step resume"},
6094 {bp_hp_step_resume
, "high-priority step resume"},
6095 {bp_watchpoint_scope
, "watchpoint scope"},
6096 {bp_call_dummy
, "call dummy"},
6097 {bp_std_terminate
, "std::terminate"},
6098 {bp_shlib_event
, "shlib events"},
6099 {bp_thread_event
, "thread events"},
6100 {bp_overlay_event
, "overlay events"},
6101 {bp_longjmp_master
, "longjmp master"},
6102 {bp_std_terminate_master
, "std::terminate master"},
6103 {bp_exception_master
, "exception master"},
6104 {bp_catchpoint
, "catchpoint"},
6105 {bp_tracepoint
, "tracepoint"},
6106 {bp_fast_tracepoint
, "fast tracepoint"},
6107 {bp_static_tracepoint
, "static tracepoint"},
6108 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6109 {bp_dprintf
, "dprintf"},
6110 {bp_jit_event
, "jit events"},
6111 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6112 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6115 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6116 || ((int) type
!= bptypes
[(int) type
].type
))
6117 internal_error (__FILE__
, __LINE__
,
6118 _("bptypes table does not describe type #%d."),
6121 return bptypes
[(int) type
].description
;
6124 /* For MI, output a field named 'thread-groups' with a list as the value.
6125 For CLI, prefix the list with the string 'inf'. */
6128 output_thread_groups (struct ui_out
*uiout
,
6129 const char *field_name
,
6130 const std::vector
<int> &inf_nums
,
6133 int is_mi
= uiout
->is_mi_like_p ();
6135 /* For backward compatibility, don't display inferiors in CLI unless
6136 there are several. Always display them for MI. */
6137 if (!is_mi
&& mi_only
)
6140 ui_out_emit_list
list_emitter (uiout
, field_name
);
6142 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6148 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6149 uiout
->field_string (NULL
, mi_group
);
6154 uiout
->text (" inf ");
6158 uiout
->text (plongest (inf_nums
[i
]));
6163 /* See breakpoint.h. */
6165 bool fix_breakpoint_script_output_globally
= false;
6167 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6168 instead of going via breakpoint_ops::print_one. This makes "maint
6169 info breakpoints" show the software breakpoint locations of
6170 catchpoints, which are considered internal implementation
6171 detail. Returns true if RAW_LOC is false and if the breakpoint's
6172 print_one method did something; false otherwise. */
6175 print_one_breakpoint_location (struct breakpoint
*b
,
6176 struct bp_location
*loc
,
6178 struct bp_location
**last_loc
,
6179 int allflag
, bool raw_loc
)
6181 struct command_line
*l
;
6182 static char bpenables
[] = "nynny";
6184 struct ui_out
*uiout
= current_uiout
;
6185 int header_of_multiple
= 0;
6186 int part_of_multiple
= (loc
!= NULL
);
6187 struct value_print_options opts
;
6189 get_user_print_options (&opts
);
6191 gdb_assert (!loc
|| loc_number
!= 0);
6192 /* See comment in print_one_breakpoint concerning treatment of
6193 breakpoints with single disabled location. */
6196 && (b
->loc
->next
!= NULL
6197 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6198 header_of_multiple
= 1;
6206 if (part_of_multiple
)
6207 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6209 uiout
->field_signed ("number", b
->number
);
6213 if (part_of_multiple
)
6214 uiout
->field_skip ("type");
6216 uiout
->field_string ("type", bptype_string (b
->type
));
6220 if (part_of_multiple
)
6221 uiout
->field_skip ("disp");
6223 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6227 if (part_of_multiple
)
6229 /* For locations that are disabled because of an invalid
6230 condition, display "N*" on the CLI, where "*" refers to a
6231 footnote below the table. For MI, simply display a "N"
6232 without a footnote. On the CLI, for enabled locations whose
6233 breakpoint is disabled, display "y-". */
6234 auto get_enable_state
= [uiout
, loc
] () -> const char *
6236 if (uiout
->is_mi_like_p ())
6238 if (loc
->disabled_by_cond
)
6240 else if (!loc
->enabled
)
6247 if (loc
->disabled_by_cond
)
6249 else if (!loc
->enabled
)
6251 else if (!breakpoint_enabled (loc
->owner
))
6257 uiout
->field_string ("enabled", get_enable_state ());
6260 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6263 bool result
= false;
6264 if (!raw_loc
&& b
->print_one (last_loc
))
6268 if (is_watchpoint (b
))
6270 struct watchpoint
*w
= (struct watchpoint
*) b
;
6272 /* Field 4, the address, is omitted (which makes the columns
6273 not line up too nicely with the headers, but the effect
6274 is relatively readable). */
6275 if (opts
.addressprint
)
6276 uiout
->field_skip ("addr");
6278 uiout
->field_string ("what", w
->exp_string
.get ());
6280 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6281 || is_ada_exception_catchpoint (b
))
6283 if (opts
.addressprint
)
6286 if (header_of_multiple
)
6287 uiout
->field_string ("addr", "<MULTIPLE>",
6288 metadata_style
.style ());
6289 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6290 uiout
->field_string ("addr", "<PENDING>",
6291 metadata_style
.style ());
6293 uiout
->field_core_addr ("addr",
6294 loc
->gdbarch
, loc
->address
);
6297 if (!header_of_multiple
)
6298 print_breakpoint_location (b
, loc
);
6304 if (loc
!= NULL
&& !header_of_multiple
)
6306 std::vector
<int> inf_nums
;
6309 for (inferior
*inf
: all_inferiors ())
6311 if (inf
->pspace
== loc
->pspace
)
6312 inf_nums
.push_back (inf
->num
);
6315 /* For backward compatibility, don't display inferiors in CLI unless
6316 there are several. Always display for MI. */
6318 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6319 && (program_spaces
.size () > 1
6320 || number_of_inferiors () > 1)
6321 /* LOC is for existing B, it cannot be in
6322 moribund_locations and thus having NULL OWNER. */
6323 && loc
->owner
->type
!= bp_catchpoint
))
6325 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6328 if (!part_of_multiple
)
6330 if (b
->thread
!= -1)
6332 /* FIXME: This seems to be redundant and lost here; see the
6333 "stop only in" line a little further down. */
6334 uiout
->text (" thread ");
6335 uiout
->field_signed ("thread", b
->thread
);
6337 else if (b
->task
!= 0)
6339 uiout
->text (" task ");
6340 uiout
->field_signed ("task", b
->task
);
6346 if (!part_of_multiple
)
6347 b
->print_one_detail (uiout
);
6349 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6352 uiout
->text ("\tstop only in stack frame at ");
6353 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6355 uiout
->field_core_addr ("frame",
6356 b
->gdbarch
, b
->frame_id
.stack_addr
);
6360 if (!part_of_multiple
&& b
->cond_string
)
6363 if (is_tracepoint (b
))
6364 uiout
->text ("\ttrace only if ");
6366 uiout
->text ("\tstop only if ");
6367 uiout
->field_string ("cond", b
->cond_string
.get ());
6369 /* Print whether the target is doing the breakpoint's condition
6370 evaluation. If GDB is doing the evaluation, don't print anything. */
6371 if (is_breakpoint (b
)
6372 && breakpoint_condition_evaluation_mode ()
6373 == condition_evaluation_target
)
6375 uiout
->message (" (%pF evals)",
6376 string_field ("evaluated-by",
6377 bp_condition_evaluator (b
)));
6382 if (!part_of_multiple
&& b
->thread
!= -1)
6384 /* FIXME should make an annotation for this. */
6385 uiout
->text ("\tstop only in thread ");
6386 if (uiout
->is_mi_like_p ())
6387 uiout
->field_signed ("thread", b
->thread
);
6390 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6392 uiout
->field_string ("thread", print_thread_id (thr
));
6397 if (!part_of_multiple
)
6401 /* FIXME should make an annotation for this. */
6402 if (is_catchpoint (b
))
6403 uiout
->text ("\tcatchpoint");
6404 else if (is_tracepoint (b
))
6405 uiout
->text ("\ttracepoint");
6407 uiout
->text ("\tbreakpoint");
6408 uiout
->text (" already hit ");
6409 uiout
->field_signed ("times", b
->hit_count
);
6410 if (b
->hit_count
== 1)
6411 uiout
->text (" time\n");
6413 uiout
->text (" times\n");
6417 /* Output the count also if it is zero, but only if this is mi. */
6418 if (uiout
->is_mi_like_p ())
6419 uiout
->field_signed ("times", b
->hit_count
);
6423 if (!part_of_multiple
&& b
->ignore_count
)
6426 uiout
->message ("\tignore next %pF hits\n",
6427 signed_field ("ignore", b
->ignore_count
));
6430 /* Note that an enable count of 1 corresponds to "enable once"
6431 behavior, which is reported by the combination of enablement and
6432 disposition, so we don't need to mention it here. */
6433 if (!part_of_multiple
&& b
->enable_count
> 1)
6436 uiout
->text ("\tdisable after ");
6437 /* Tweak the wording to clarify that ignore and enable counts
6438 are distinct, and have additive effect. */
6439 if (b
->ignore_count
)
6440 uiout
->text ("additional ");
6442 uiout
->text ("next ");
6443 uiout
->field_signed ("enable", b
->enable_count
);
6444 uiout
->text (" hits\n");
6447 if (!part_of_multiple
&& is_tracepoint (b
))
6449 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6451 if (tp
->traceframe_usage
)
6453 uiout
->text ("\ttrace buffer usage ");
6454 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6455 uiout
->text (" bytes\n");
6459 l
= b
->commands
? b
->commands
.get () : NULL
;
6460 if (!part_of_multiple
&& l
)
6464 bool use_fixed_output
=
6465 (uiout
->test_flags (fix_breakpoint_script_output
)
6466 || fix_breakpoint_script_output_globally
);
6468 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
6469 gdb::optional
<ui_out_emit_list
> list_emitter
;
6471 if (use_fixed_output
)
6472 list_emitter
.emplace (uiout
, "script");
6474 tuple_emitter
.emplace (uiout
, "script");
6476 print_command_lines (uiout
, l
, 4);
6479 if (is_tracepoint (b
))
6481 struct tracepoint
*t
= (struct tracepoint
*) b
;
6483 if (!part_of_multiple
&& t
->pass_count
)
6485 annotate_field (10);
6486 uiout
->text ("\tpass count ");
6487 uiout
->field_signed ("pass", t
->pass_count
);
6488 uiout
->text (" \n");
6491 /* Don't display it when tracepoint or tracepoint location is
6493 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6495 annotate_field (11);
6497 if (uiout
->is_mi_like_p ())
6498 uiout
->field_string ("installed",
6499 loc
->inserted
? "y" : "n");
6505 uiout
->text ("\tnot ");
6506 uiout
->text ("installed on target\n");
6511 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6513 if (is_watchpoint (b
))
6515 struct watchpoint
*w
= (struct watchpoint
*) b
;
6517 uiout
->field_string ("original-location", w
->exp_string
.get ());
6519 else if (b
->locspec
!= nullptr)
6521 const char *str
= b
->locspec
->to_string ();
6523 uiout
->field_string ("original-location", str
);
6530 /* See breakpoint.h. */
6532 bool fix_multi_location_breakpoint_output_globally
= false;
6535 print_one_breakpoint (struct breakpoint
*b
,
6536 struct bp_location
**last_loc
,
6539 struct ui_out
*uiout
= current_uiout
;
6540 bool use_fixed_output
6541 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6542 || fix_multi_location_breakpoint_output_globally
);
6544 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6545 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6548 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6550 if (!use_fixed_output
)
6551 bkpt_tuple_emitter
.reset ();
6553 /* If this breakpoint has custom print function,
6554 it's already printed. Otherwise, print individual
6555 locations, if any. */
6556 if (!printed
|| allflag
)
6558 /* If breakpoint has a single location that is disabled, we
6559 print it as if it had several locations, since otherwise it's
6560 hard to represent "breakpoint enabled, location disabled"
6563 Note that while hardware watchpoints have several locations
6564 internally, that's not a property exposed to users.
6566 Likewise, while catchpoints may be implemented with
6567 breakpoints (e.g., catch throw), that's not a property
6568 exposed to users. We do however display the internal
6569 breakpoint locations with "maint info breakpoints". */
6570 if (!is_hardware_watchpoint (b
)
6571 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6572 || is_ada_exception_catchpoint (b
))
6574 || (b
->loc
&& (b
->loc
->next
6576 || b
->loc
->disabled_by_cond
))))
6578 gdb::optional
<ui_out_emit_list
> locations_list
;
6580 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6581 MI record. For later versions, place breakpoint locations in a
6583 if (uiout
->is_mi_like_p () && use_fixed_output
)
6584 locations_list
.emplace (uiout
, "locations");
6587 for (bp_location
*loc
: b
->locations ())
6589 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6590 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6599 breakpoint_address_bits (struct breakpoint
*b
)
6601 int print_address_bits
= 0;
6603 for (bp_location
*loc
: b
->locations ())
6605 if (!bl_address_is_meaningful (loc
))
6608 int addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6609 if (addr_bit
> print_address_bits
)
6610 print_address_bits
= addr_bit
;
6613 return print_address_bits
;
6616 /* See breakpoint.h. */
6619 print_breakpoint (breakpoint
*b
)
6621 struct bp_location
*dummy_loc
= NULL
;
6622 print_one_breakpoint (b
, &dummy_loc
, 0);
6625 /* Return true if this breakpoint was set by the user, false if it is
6626 internal or momentary. */
6629 user_breakpoint_p (struct breakpoint
*b
)
6631 return b
->number
> 0;
6634 /* See breakpoint.h. */
6637 pending_breakpoint_p (struct breakpoint
*b
)
6639 return b
->loc
== NULL
;
6642 /* Print information on breakpoints (including watchpoints and tracepoints).
6644 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6645 understood by number_or_range_parser. Only breakpoints included in this
6646 list are then printed.
6648 If SHOW_INTERNAL is true, print internal breakpoints.
6650 If FILTER is non-NULL, call it on each breakpoint and only include the
6651 ones for which it returns true.
6653 Return the total number of breakpoints listed. */
6656 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6657 bool (*filter
) (const struct breakpoint
*))
6659 struct bp_location
*last_loc
= NULL
;
6660 int nr_printable_breakpoints
;
6661 struct value_print_options opts
;
6662 int print_address_bits
= 0;
6663 int print_type_col_width
= 14;
6664 struct ui_out
*uiout
= current_uiout
;
6665 bool has_disabled_by_cond_location
= false;
6667 get_user_print_options (&opts
);
6669 /* Compute the number of rows in the table, as well as the size
6670 required for address fields. */
6671 nr_printable_breakpoints
= 0;
6672 for (breakpoint
*b
: all_breakpoints ())
6674 /* If we have a filter, only list the breakpoints it accepts. */
6675 if (filter
&& !filter (b
))
6678 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6679 accept. Skip the others. */
6680 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6682 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6684 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6688 if (show_internal
|| user_breakpoint_p (b
))
6690 int addr_bit
, type_len
;
6692 addr_bit
= breakpoint_address_bits (b
);
6693 if (addr_bit
> print_address_bits
)
6694 print_address_bits
= addr_bit
;
6696 type_len
= strlen (bptype_string (b
->type
));
6697 if (type_len
> print_type_col_width
)
6698 print_type_col_width
= type_len
;
6700 nr_printable_breakpoints
++;
6705 ui_out_emit_table
table_emitter (uiout
,
6706 opts
.addressprint
? 6 : 5,
6707 nr_printable_breakpoints
,
6710 if (nr_printable_breakpoints
> 0)
6711 annotate_breakpoints_headers ();
6712 if (nr_printable_breakpoints
> 0)
6714 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6715 if (nr_printable_breakpoints
> 0)
6717 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6718 if (nr_printable_breakpoints
> 0)
6720 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6721 if (nr_printable_breakpoints
> 0)
6723 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6724 if (opts
.addressprint
)
6726 if (nr_printable_breakpoints
> 0)
6728 if (print_address_bits
<= 32)
6729 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6731 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6733 if (nr_printable_breakpoints
> 0)
6735 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6736 uiout
->table_body ();
6737 if (nr_printable_breakpoints
> 0)
6738 annotate_breakpoints_table ();
6740 for (breakpoint
*b
: all_breakpoints ())
6743 /* If we have a filter, only list the breakpoints it accepts. */
6744 if (filter
&& !filter (b
))
6747 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6748 accept. Skip the others. */
6750 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6752 if (show_internal
) /* maintenance info breakpoint */
6754 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6757 else /* all others */
6759 if (!number_is_in_list (bp_num_list
, b
->number
))
6763 /* We only print out user settable breakpoints unless the
6764 show_internal is set. */
6765 if (show_internal
|| user_breakpoint_p (b
))
6767 print_one_breakpoint (b
, &last_loc
, show_internal
);
6768 for (bp_location
*loc
: b
->locations ())
6769 if (loc
->disabled_by_cond
)
6770 has_disabled_by_cond_location
= true;
6775 if (nr_printable_breakpoints
== 0)
6777 /* If there's a filter, let the caller decide how to report
6781 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6782 uiout
->message ("No breakpoints or watchpoints.\n");
6784 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6790 if (last_loc
&& !server_command
)
6791 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6793 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6794 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6798 /* FIXME? Should this be moved up so that it is only called when
6799 there have been breakpoints? */
6800 annotate_breakpoints_table_end ();
6802 return nr_printable_breakpoints
;
6805 /* Display the value of default-collect in a way that is generally
6806 compatible with the breakpoint list. */
6809 default_collect_info (void)
6811 struct ui_out
*uiout
= current_uiout
;
6813 /* If it has no value (which is frequently the case), say nothing; a
6814 message like "No default-collect." gets in user's face when it's
6816 if (default_collect
.empty ())
6819 /* The following phrase lines up nicely with per-tracepoint collect
6821 uiout
->text ("default collect ");
6822 uiout
->field_string ("default-collect", default_collect
);
6823 uiout
->text (" \n");
6827 info_breakpoints_command (const char *args
, int from_tty
)
6829 breakpoint_1 (args
, false, NULL
);
6831 default_collect_info ();
6835 info_watchpoints_command (const char *args
, int from_tty
)
6837 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6838 struct ui_out
*uiout
= current_uiout
;
6840 if (num_printed
== 0)
6842 if (args
== NULL
|| *args
== '\0')
6843 uiout
->message ("No watchpoints.\n");
6845 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6850 maintenance_info_breakpoints (const char *args
, int from_tty
)
6852 breakpoint_1 (args
, true, NULL
);
6854 default_collect_info ();
6858 breakpoint_has_pc (struct breakpoint
*b
,
6859 struct program_space
*pspace
,
6860 CORE_ADDR pc
, struct obj_section
*section
)
6862 for (bp_location
*bl
: b
->locations ())
6864 if (bl
->pspace
== pspace
6865 && bl
->address
== pc
6866 && (!overlay_debugging
|| bl
->section
== section
))
6872 /* See breakpoint.h. */
6875 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6876 struct program_space
*pspace
, CORE_ADDR pc
,
6877 struct obj_section
*section
, int thread
)
6881 for (breakpoint
*b
: all_breakpoints ())
6882 others
+= (user_breakpoint_p (b
)
6883 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6888 gdb_printf (_("Note: breakpoint "));
6889 else /* if (others == ???) */
6890 gdb_printf (_("Note: breakpoints "));
6891 for (breakpoint
*b
: all_breakpoints ())
6892 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6895 gdb_printf ("%d", b
->number
);
6896 if (b
->thread
== -1 && thread
!= -1)
6897 gdb_printf (" (all threads)");
6898 else if (b
->thread
!= -1)
6899 gdb_printf (" (thread %d)", b
->thread
);
6900 gdb_printf ("%s%s ",
6901 ((b
->enable_state
== bp_disabled
6902 || b
->enable_state
== bp_call_disabled
)
6906 : ((others
== 1) ? " and" : ""));
6908 current_uiout
->message (_("also set at pc %ps.\n"),
6909 styled_string (address_style
.style (),
6910 paddress (gdbarch
, pc
)));
6915 /* Return true iff it is meaningful to use the address member of LOC.
6916 For some breakpoint types, the locations' address members are
6917 irrelevant and it makes no sense to attempt to compare them to
6918 other addresses (or use them for any other purpose either).
6920 More specifically, software watchpoints and catchpoints that are
6921 not backed by breakpoints always have a zero valued location
6922 address and we don't want to mark breakpoints of any of these types
6923 to be a duplicate of an actual breakpoint location at address
6927 bl_address_is_meaningful (bp_location
*loc
)
6929 return loc
->loc_type
!= bp_loc_other
;
6932 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6933 true if LOC1 and LOC2 represent the same watchpoint location. */
6936 watchpoint_locations_match (struct bp_location
*loc1
,
6937 struct bp_location
*loc2
)
6939 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6940 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6942 /* Both of them must exist. */
6943 gdb_assert (w1
!= NULL
);
6944 gdb_assert (w2
!= NULL
);
6946 /* If the target can evaluate the condition expression in hardware,
6947 then we we need to insert both watchpoints even if they are at
6948 the same place. Otherwise the watchpoint will only trigger when
6949 the condition of whichever watchpoint was inserted evaluates to
6950 true, not giving a chance for GDB to check the condition of the
6951 other watchpoint. */
6953 && target_can_accel_watchpoint_condition (loc1
->address
,
6955 loc1
->watchpoint_type
,
6956 w1
->cond_exp
.get ()))
6958 && target_can_accel_watchpoint_condition (loc2
->address
,
6960 loc2
->watchpoint_type
,
6961 w2
->cond_exp
.get ())))
6964 /* Note that this checks the owner's type, not the location's. In
6965 case the target does not support read watchpoints, but does
6966 support access watchpoints, we'll have bp_read_watchpoint
6967 watchpoints with hw_access locations. Those should be considered
6968 duplicates of hw_read locations. The hw_read locations will
6969 become hw_access locations later. */
6970 return (loc1
->owner
->type
== loc2
->owner
->type
6971 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6972 && loc1
->address
== loc2
->address
6973 && loc1
->length
== loc2
->length
);
6976 /* See breakpoint.h. */
6979 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6980 const address_space
*aspace2
, CORE_ADDR addr2
)
6982 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6983 || aspace1
== aspace2
)
6987 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6988 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6989 matches ASPACE2. On targets that have global breakpoints, the address
6990 space doesn't really matter. */
6993 breakpoint_address_match_range (const address_space
*aspace1
,
6995 int len1
, const address_space
*aspace2
,
6998 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6999 || aspace1
== aspace2
)
7000 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7003 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7004 a ranged breakpoint. In most targets, a match happens only if ASPACE
7005 matches the breakpoint's address space. On targets that have global
7006 breakpoints, the address space doesn't really matter. */
7009 breakpoint_location_address_match (struct bp_location
*bl
,
7010 const address_space
*aspace
,
7013 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7016 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7017 bl
->address
, bl
->length
,
7021 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7022 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7023 match happens only if ASPACE matches the breakpoint's address
7024 space. On targets that have global breakpoints, the address space
7025 doesn't really matter. */
7028 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7029 const address_space
*aspace
,
7030 CORE_ADDR addr
, int len
)
7032 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7033 || bl
->pspace
->aspace
== aspace
)
7035 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7037 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7043 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7044 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7045 true, otherwise returns false. */
7048 tracepoint_locations_match (struct bp_location
*loc1
,
7049 struct bp_location
*loc2
)
7051 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7052 /* Since tracepoint locations are never duplicated with others', tracepoint
7053 locations at the same address of different tracepoints are regarded as
7054 different locations. */
7055 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7060 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7061 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7062 the same location. If SW_HW_BPS_MATCH is true, then software
7063 breakpoint locations and hardware breakpoint locations match,
7064 otherwise they don't. */
7067 breakpoint_locations_match (struct bp_location
*loc1
,
7068 struct bp_location
*loc2
,
7069 bool sw_hw_bps_match
)
7071 int hw_point1
, hw_point2
;
7073 /* Both of them must not be in moribund_locations. */
7074 gdb_assert (loc1
->owner
!= NULL
);
7075 gdb_assert (loc2
->owner
!= NULL
);
7077 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7078 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7080 if (hw_point1
!= hw_point2
)
7083 return watchpoint_locations_match (loc1
, loc2
);
7084 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7085 return tracepoint_locations_match (loc1
, loc2
);
7087 /* We compare bp_location.length in order to cover ranged
7088 breakpoints. Keep this in sync with
7089 bp_location_is_less_than. */
7090 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7091 loc2
->pspace
->aspace
, loc2
->address
)
7092 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7093 && loc1
->length
== loc2
->length
);
7097 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7098 int bnum
, int have_bnum
)
7100 /* The longest string possibly returned by hex_string_custom
7101 is 50 chars. These must be at least that big for safety. */
7105 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7106 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7108 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7109 bnum
, astr1
, astr2
);
7111 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7114 /* Adjust a breakpoint's address to account for architectural
7115 constraints on breakpoint placement. Return the adjusted address.
7116 Note: Very few targets require this kind of adjustment. For most
7117 targets, this function is simply the identity function. */
7120 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7121 CORE_ADDR bpaddr
, enum bptype bptype
,
7122 struct program_space
*pspace
)
7124 gdb_assert (pspace
!= nullptr);
7126 if (bptype
== bp_watchpoint
7127 || bptype
== bp_hardware_watchpoint
7128 || bptype
== bp_read_watchpoint
7129 || bptype
== bp_access_watchpoint
7130 || bptype
== bp_catchpoint
)
7132 /* Watchpoints and the various bp_catch_* eventpoints should not
7133 have their addresses modified. */
7136 else if (bptype
== bp_single_step
)
7138 /* Single-step breakpoints should not have their addresses
7139 modified. If there's any architectural constrain that
7140 applies to this address, then it should have already been
7141 taken into account when the breakpoint was created in the
7142 first place. If we didn't do this, stepping through e.g.,
7143 Thumb-2 IT blocks would break. */
7148 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7150 /* Some targets have architectural constraints on the placement
7151 of breakpoint instructions. Obtain the adjusted address. */
7152 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7154 /* Targets that implement this adjustment function will likely
7155 inspect either the symbol table, target memory at BPADDR, or
7156 even state registers, so ensure a suitable thread (and its
7157 associated program space) are currently selected. */
7158 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
7159 switch_to_program_space_and_thread (pspace
);
7161 = gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7164 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7166 /* An adjusted breakpoint address can significantly alter
7167 a user's expectations. Print a warning if an adjustment
7169 if (adjusted_bpaddr
!= bpaddr
)
7170 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7172 return adjusted_bpaddr
;
7177 bp_location_from_bp_type (bptype type
)
7182 case bp_single_step
:
7186 case bp_longjmp_resume
:
7187 case bp_longjmp_call_dummy
:
7189 case bp_exception_resume
:
7190 case bp_step_resume
:
7191 case bp_hp_step_resume
:
7192 case bp_watchpoint_scope
:
7194 case bp_std_terminate
:
7195 case bp_shlib_event
:
7196 case bp_thread_event
:
7197 case bp_overlay_event
:
7199 case bp_longjmp_master
:
7200 case bp_std_terminate_master
:
7201 case bp_exception_master
:
7202 case bp_gnu_ifunc_resolver
:
7203 case bp_gnu_ifunc_resolver_return
:
7205 return bp_loc_software_breakpoint
;
7206 case bp_hardware_breakpoint
:
7207 return bp_loc_hardware_breakpoint
;
7208 case bp_hardware_watchpoint
:
7209 case bp_read_watchpoint
:
7210 case bp_access_watchpoint
:
7211 return bp_loc_hardware_watchpoint
;
7213 return bp_loc_software_watchpoint
;
7216 case bp_fast_tracepoint
:
7217 case bp_static_tracepoint
:
7218 case bp_static_marker_tracepoint
:
7219 return bp_loc_other
;
7221 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7225 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7227 this->owner
= owner
;
7228 this->cond_bytecode
= NULL
;
7229 this->shlib_disabled
= 0;
7231 this->disabled_by_cond
= false;
7233 this->loc_type
= type
;
7235 if (this->loc_type
== bp_loc_software_breakpoint
7236 || this->loc_type
== bp_loc_hardware_breakpoint
)
7237 mark_breakpoint_location_modified (this);
7242 bp_location::bp_location (breakpoint
*owner
)
7243 : bp_location::bp_location (owner
,
7244 bp_location_from_bp_type (owner
->type
))
7248 /* Decrement reference count. If the reference count reaches 0,
7249 destroy the bp_location. Sets *BLP to NULL. */
7252 decref_bp_location (struct bp_location
**blp
)
7254 bp_location_ref_policy::decref (*blp
);
7258 /* Add breakpoint B at the end of the global breakpoint chain. */
7261 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7263 struct breakpoint
*b1
;
7264 struct breakpoint
*result
= b
.get ();
7266 /* Add this breakpoint to the end of the chain so that a list of
7267 breakpoints will come out in order of increasing numbers. */
7269 b1
= breakpoint_chain
;
7271 breakpoint_chain
= b
.release ();
7276 b1
->next
= b
.release ();
7282 /* Initialize loc->function_name. */
7285 set_breakpoint_location_function (struct bp_location
*loc
)
7287 gdb_assert (loc
->owner
!= NULL
);
7289 if (loc
->owner
->type
== bp_breakpoint
7290 || loc
->owner
->type
== bp_hardware_breakpoint
7291 || is_tracepoint (loc
->owner
))
7293 const char *function_name
;
7295 if (loc
->msymbol
!= NULL
7296 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7297 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7299 struct breakpoint
*b
= loc
->owner
;
7301 function_name
= loc
->msymbol
->linkage_name ();
7303 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7304 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7306 /* Create only the whole new breakpoint of this type but do not
7307 mess more complicated breakpoints with multiple locations. */
7308 b
->type
= bp_gnu_ifunc_resolver
;
7309 /* Remember the resolver's address for use by the return
7311 loc
->related_address
= loc
->address
;
7315 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7318 loc
->function_name
= make_unique_xstrdup (function_name
);
7322 /* Attempt to determine architecture of location identified by SAL. */
7324 get_sal_arch (struct symtab_and_line sal
)
7327 return sal
.section
->objfile
->arch ();
7329 return sal
.symtab
->compunit ()->objfile ()->arch ();
7334 /* Call this routine when stepping and nexting to enable a breakpoint
7335 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7336 initiated the operation. */
7339 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7341 int thread
= tp
->global_num
;
7343 /* To avoid having to rescan all objfile symbols at every step,
7344 we maintain a list of continually-inserted but always disabled
7345 longjmp "master" breakpoints. Here, we simply create momentary
7346 clones of those and enable them for the requested thread. */
7347 for (breakpoint
*b
: all_breakpoints_safe ())
7348 if (b
->pspace
== current_program_space
7349 && (b
->type
== bp_longjmp_master
7350 || b
->type
== bp_exception_master
))
7352 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7353 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7354 after their removal. */
7355 momentary_breakpoint_from_master (b
, type
, 1, thread
);
7358 tp
->initiating_frame
= frame
;
7361 /* Delete all longjmp breakpoints from THREAD. */
7363 delete_longjmp_breakpoint (int thread
)
7365 for (breakpoint
*b
: all_breakpoints_safe ())
7366 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7368 if (b
->thread
== thread
)
7369 delete_breakpoint (b
);
7374 delete_longjmp_breakpoint_at_next_stop (int thread
)
7376 for (breakpoint
*b
: all_breakpoints_safe ())
7377 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7379 if (b
->thread
== thread
)
7380 b
->disposition
= disp_del_at_next_stop
;
7384 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7385 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7386 pointer to any of them. Return NULL if this system cannot place longjmp
7390 set_longjmp_breakpoint_for_call_dummy (void)
7392 breakpoint
*retval
= nullptr;
7394 for (breakpoint
*b
: all_breakpoints ())
7395 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7397 int thread
= inferior_thread ()->global_num
;
7399 = momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7402 /* Link NEW_B into the chain of RETVAL breakpoints. */
7404 gdb_assert (new_b
->related_breakpoint
== new_b
);
7407 new_b
->related_breakpoint
= retval
;
7408 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7409 retval
= retval
->related_breakpoint
;
7410 retval
->related_breakpoint
= new_b
;
7416 /* Verify all existing dummy frames and their associated breakpoints for
7417 TP. Remove those which can no longer be found in the current frame
7420 If the unwind fails then there is not sufficient information to discard
7421 dummy frames. In this case, elide the clean up and the dummy frames will
7422 be cleaned up next time this function is called from a location where
7423 unwinding is possible. */
7426 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7428 struct breakpoint
*b
, *b_tmp
;
7430 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7431 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7433 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7435 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7436 chained off b->related_breakpoint. */
7437 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7438 dummy_b
= dummy_b
->related_breakpoint
;
7440 /* If there was no bp_call_dummy breakpoint then there's nothing
7441 more to do. Or, if the dummy frame associated with the
7442 bp_call_dummy is still on the stack then we need to leave this
7443 bp_call_dummy in place. */
7444 if (dummy_b
->type
!= bp_call_dummy
7445 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7448 /* We didn't find the dummy frame on the stack, this could be
7449 because we have longjmp'd to a stack frame that is previous to
7450 the dummy frame, or it could be because the stack unwind is
7451 broken at some point between the longjmp frame and the dummy
7454 Next we figure out why the stack unwind stopped. If it looks
7455 like the unwind is complete then we assume the dummy frame has
7456 been jumped over, however, if the unwind stopped for an
7457 unexpected reason then we assume the stack unwind is currently
7458 broken, and that we will (eventually) return to the dummy
7461 It might be tempting to consider using frame_id_inner here, but
7462 that is not safe. There is no guarantee that the stack frames
7463 we are looking at here are even on the same stack as the
7464 original dummy frame, hence frame_id_inner can't be used. See
7465 the comments on frame_id_inner for more details. */
7466 bool unwind_finished_unexpectedly
= false;
7467 for (struct frame_info
*fi
= get_current_frame (); fi
!= nullptr; )
7469 struct frame_info
*prev
= get_prev_frame (fi
);
7470 if (prev
== nullptr)
7472 /* FI is the last stack frame. Why did this frame not
7474 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7475 if (stop_reason
!= UNWIND_NO_REASON
7476 && stop_reason
!= UNWIND_OUTERMOST
)
7477 unwind_finished_unexpectedly
= true;
7481 if (unwind_finished_unexpectedly
)
7484 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7486 while (b
->related_breakpoint
!= b
)
7488 if (b_tmp
== b
->related_breakpoint
)
7489 b_tmp
= b
->related_breakpoint
->next
;
7490 delete_breakpoint (b
->related_breakpoint
);
7492 delete_breakpoint (b
);
7497 enable_overlay_breakpoints (void)
7499 for (breakpoint
*b
: all_breakpoints ())
7500 if (b
->type
== bp_overlay_event
)
7502 b
->enable_state
= bp_enabled
;
7503 update_global_location_list (UGLL_MAY_INSERT
);
7504 overlay_events_enabled
= 1;
7509 disable_overlay_breakpoints (void)
7511 for (breakpoint
*b
: all_breakpoints ())
7512 if (b
->type
== bp_overlay_event
)
7514 b
->enable_state
= bp_disabled
;
7515 update_global_location_list (UGLL_DONT_INSERT
);
7516 overlay_events_enabled
= 0;
7520 /* Set an active std::terminate breakpoint for each std::terminate
7521 master breakpoint. */
7523 set_std_terminate_breakpoint (void)
7525 for (breakpoint
*b
: all_breakpoints_safe ())
7526 if (b
->pspace
== current_program_space
7527 && b
->type
== bp_std_terminate_master
)
7529 momentary_breakpoint_from_master (b
, bp_std_terminate
, 1,
7530 inferior_thread ()->global_num
);
7534 /* Delete all the std::terminate breakpoints. */
7536 delete_std_terminate_breakpoint (void)
7538 for (breakpoint
*b
: all_breakpoints_safe ())
7539 if (b
->type
== bp_std_terminate
)
7540 delete_breakpoint (b
);
7544 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7546 struct breakpoint
*b
;
7548 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7550 b
->enable_state
= bp_enabled
;
7551 /* locspec has to be used or breakpoint_re_set will delete me. */
7552 b
->locspec
= new_address_location_spec (b
->loc
->address
, NULL
, 0);
7554 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7559 struct lang_and_radix
7565 /* Create a breakpoint for JIT code registration and unregistration. */
7568 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7570 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7573 /* Remove JIT code registration and unregistration breakpoint(s). */
7576 remove_jit_event_breakpoints (void)
7578 for (breakpoint
*b
: all_breakpoints_safe ())
7579 if (b
->type
== bp_jit_event
7580 && b
->loc
->pspace
== current_program_space
)
7581 delete_breakpoint (b
);
7585 remove_solib_event_breakpoints (void)
7587 for (breakpoint
*b
: all_breakpoints_safe ())
7588 if (b
->type
== bp_shlib_event
7589 && b
->loc
->pspace
== current_program_space
)
7590 delete_breakpoint (b
);
7593 /* See breakpoint.h. */
7596 remove_solib_event_breakpoints_at_next_stop (void)
7598 for (breakpoint
*b
: all_breakpoints_safe ())
7599 if (b
->type
== bp_shlib_event
7600 && b
->loc
->pspace
== current_program_space
)
7601 b
->disposition
= disp_del_at_next_stop
;
7604 /* Helper for create_solib_event_breakpoint /
7605 create_and_insert_solib_event_breakpoint. Allows specifying which
7606 INSERT_MODE to pass through to update_global_location_list. */
7608 static struct breakpoint
*
7609 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7610 enum ugll_insert_mode insert_mode
)
7612 struct breakpoint
*b
;
7614 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
7615 update_global_location_list_nothrow (insert_mode
);
7620 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7622 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7625 /* See breakpoint.h. */
7628 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7630 struct breakpoint
*b
;
7632 /* Explicitly tell update_global_location_list to insert
7634 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7635 if (!b
->loc
->inserted
)
7637 delete_breakpoint (b
);
7643 /* Disable any breakpoints that are on code in shared libraries. Only
7644 apply to enabled breakpoints, disabled ones can just stay disabled. */
7647 disable_breakpoints_in_shlibs (void)
7649 for (bp_location
*loc
: all_bp_locations ())
7651 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7652 struct breakpoint
*b
= loc
->owner
;
7654 /* We apply the check to all breakpoints, including disabled for
7655 those with loc->duplicate set. This is so that when breakpoint
7656 becomes enabled, or the duplicate is removed, gdb will try to
7657 insert all breakpoints. If we don't set shlib_disabled here,
7658 we'll try to insert those breakpoints and fail. */
7659 if (((b
->type
== bp_breakpoint
)
7660 || (b
->type
== bp_jit_event
)
7661 || (b
->type
== bp_hardware_breakpoint
)
7662 || (is_tracepoint (b
)))
7663 && loc
->pspace
== current_program_space
7664 && !loc
->shlib_disabled
7665 && solib_name_from_address (loc
->pspace
, loc
->address
)
7668 loc
->shlib_disabled
= 1;
7673 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7674 notification of unloaded_shlib. Only apply to enabled breakpoints,
7675 disabled ones can just stay disabled. */
7678 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7680 int disabled_shlib_breaks
= 0;
7682 for (bp_location
*loc
: all_bp_locations ())
7684 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7685 struct breakpoint
*b
= loc
->owner
;
7687 if (solib
->pspace
== loc
->pspace
7688 && !loc
->shlib_disabled
7689 && (((b
->type
== bp_breakpoint
7690 || b
->type
== bp_jit_event
7691 || b
->type
== bp_hardware_breakpoint
)
7692 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7693 || loc
->loc_type
== bp_loc_software_breakpoint
))
7694 || is_tracepoint (b
))
7695 && solib_contains_address_p (solib
, loc
->address
))
7697 loc
->shlib_disabled
= 1;
7698 /* At this point, we cannot rely on remove_breakpoint
7699 succeeding so we must mark the breakpoint as not inserted
7700 to prevent future errors occurring in remove_breakpoints. */
7703 /* This may cause duplicate notifications for the same breakpoint. */
7704 gdb::observers::breakpoint_modified
.notify (b
);
7706 if (!disabled_shlib_breaks
)
7708 target_terminal::ours_for_output ();
7709 warning (_("Temporarily disabling breakpoints "
7710 "for unloaded shared library \"%s\""),
7713 disabled_shlib_breaks
= 1;
7718 /* Disable any breakpoints and tracepoints in OBJFILE upon
7719 notification of free_objfile. Only apply to enabled breakpoints,
7720 disabled ones can just stay disabled. */
7723 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7725 if (objfile
== NULL
)
7728 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7729 managed by the user with add-symbol-file/remove-symbol-file.
7730 Similarly to how breakpoints in shared libraries are handled in
7731 response to "nosharedlibrary", mark breakpoints in such modules
7732 shlib_disabled so they end up uninserted on the next global
7733 location list update. Shared libraries not loaded by the user
7734 aren't handled here -- they're already handled in
7735 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7736 solib_unloaded observer. We skip objfiles that are not
7737 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7739 if ((objfile
->flags
& OBJF_SHARED
) == 0
7740 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7743 for (breakpoint
*b
: all_breakpoints ())
7745 int bp_modified
= 0;
7747 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7750 for (bp_location
*loc
: b
->locations ())
7752 CORE_ADDR loc_addr
= loc
->address
;
7754 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7755 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7758 if (loc
->shlib_disabled
!= 0)
7761 if (objfile
->pspace
!= loc
->pspace
)
7764 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7765 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7768 if (is_addr_in_objfile (loc_addr
, objfile
))
7770 loc
->shlib_disabled
= 1;
7771 /* At this point, we don't know whether the object was
7772 unmapped from the inferior or not, so leave the
7773 inserted flag alone. We'll handle failure to
7774 uninsert quietly, in case the object was indeed
7777 mark_breakpoint_location_modified (loc
);
7784 gdb::observers::breakpoint_modified
.notify (b
);
7788 /* See breakpoint.h. */
7790 breakpoint::breakpoint (struct gdbarch
*gdbarch_
, enum bptype bptype
,
7791 bool temp
, const char *cond_string_
)
7793 disposition (temp
? disp_del
: disp_donttouch
),
7795 language (current_language
->la_language
),
7796 input_radix (::input_radix
),
7797 cond_string (cond_string_
!= nullptr
7798 ? make_unique_xstrdup (cond_string_
)
7800 related_breakpoint (this)
7804 /* See breakpoint.h. */
7806 catchpoint::catchpoint (struct gdbarch
*gdbarch
, bool temp
,
7807 const char *cond_string
)
7808 : breakpoint (gdbarch
, bp_catchpoint
, temp
, cond_string
)
7810 add_dummy_location (this, current_program_space
);
7812 pspace
= current_program_space
;
7816 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
7818 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
7819 set_breakpoint_number (internal
, b
);
7820 if (is_tracepoint (b
))
7821 set_tracepoint_count (breakpoint_count
);
7824 gdb::observers::breakpoint_created
.notify (b
);
7827 update_global_location_list (UGLL_MAY_INSERT
);
7831 hw_breakpoint_used_count (void)
7835 for (breakpoint
*b
: all_breakpoints ())
7836 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7837 for (bp_location
*bl
: b
->locations ())
7839 /* Special types of hardware breakpoints may use more than
7841 i
+= b
->resources_needed (bl
);
7847 /* Returns the resources B would use if it were a hardware
7851 hw_watchpoint_use_count (struct breakpoint
*b
)
7855 if (!breakpoint_enabled (b
))
7858 for (bp_location
*bl
: b
->locations ())
7860 /* Special types of hardware watchpoints may use more than
7862 i
+= b
->resources_needed (bl
);
7868 /* Returns the sum the used resources of all hardware watchpoints of
7869 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7870 the sum of the used resources of all hardware watchpoints of other
7871 types _not_ TYPE. */
7874 hw_watchpoint_used_count_others (struct breakpoint
*except
,
7875 enum bptype type
, int *other_type_used
)
7879 *other_type_used
= 0;
7880 for (breakpoint
*b
: all_breakpoints ())
7884 if (!breakpoint_enabled (b
))
7887 if (b
->type
== type
)
7888 i
+= hw_watchpoint_use_count (b
);
7889 else if (is_hardware_watchpoint (b
))
7890 *other_type_used
= 1;
7897 disable_watchpoints_before_interactive_call_start (void)
7899 for (breakpoint
*b
: all_breakpoints ())
7900 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7902 b
->enable_state
= bp_call_disabled
;
7903 update_global_location_list (UGLL_DONT_INSERT
);
7908 enable_watchpoints_after_interactive_call_stop (void)
7910 for (breakpoint
*b
: all_breakpoints ())
7911 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7913 b
->enable_state
= bp_enabled
;
7914 update_global_location_list (UGLL_MAY_INSERT
);
7919 disable_breakpoints_before_startup (void)
7921 current_program_space
->executing_startup
= 1;
7922 update_global_location_list (UGLL_DONT_INSERT
);
7926 enable_breakpoints_after_startup (void)
7928 current_program_space
->executing_startup
= 0;
7929 breakpoint_re_set ();
7932 /* Allocate a new momentary breakpoint. */
7934 template<typename
... Arg
>
7935 static momentary_breakpoint
*
7936 new_momentary_breakpoint (struct gdbarch
*gdbarch
, enum bptype type
,
7939 if (type
== bp_longjmp
|| type
== bp_exception
)
7940 return new longjmp_breakpoint (gdbarch
, type
,
7941 std::forward
<Arg
> (args
)...);
7943 return new momentary_breakpoint (gdbarch
, type
,
7944 std::forward
<Arg
> (args
)...);
7947 /* Set a momentary breakpoint of type TYPE at address specified by
7948 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
7952 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7953 struct frame_id frame_id
, enum bptype type
)
7955 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
7957 gdb_assert (!frame_id_artificial_p (frame_id
));
7959 std::unique_ptr
<momentary_breakpoint
> b
7960 (new_momentary_breakpoint (gdbarch
, type
, sal
.pspace
, frame_id
,
7961 inferior_thread ()->global_num
));
7963 b
->add_location (sal
);
7965 breakpoint_up
bp (add_to_breakpoint_chain (std::move (b
)));
7967 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7972 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7973 The new breakpoint will have type TYPE, use OPS as its
7974 breakpoint_ops, and will set enabled to LOC_ENABLED. */
7976 static struct breakpoint
*
7977 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7982 std::unique_ptr
<breakpoint
> copy
7983 (new_momentary_breakpoint (orig
->gdbarch
, type
, orig
->pspace
,
7984 orig
->frame_id
, thread
));
7985 copy
->loc
= copy
->allocate_location ();
7986 set_breakpoint_location_function (copy
->loc
);
7988 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7989 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7990 copy
->loc
->address
= orig
->loc
->address
;
7991 copy
->loc
->section
= orig
->loc
->section
;
7992 copy
->loc
->pspace
= orig
->loc
->pspace
;
7993 copy
->loc
->probe
= orig
->loc
->probe
;
7994 copy
->loc
->line_number
= orig
->loc
->line_number
;
7995 copy
->loc
->symtab
= orig
->loc
->symtab
;
7996 copy
->loc
->enabled
= loc_enabled
;
7998 breakpoint
*b
= add_to_breakpoint_chain (std::move (copy
));
7999 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8003 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8007 clone_momentary_breakpoint (struct breakpoint
*orig
)
8009 /* If there's nothing to clone, then return nothing. */
8013 return momentary_breakpoint_from_master (orig
, orig
->type
, 0,
8018 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8021 struct symtab_and_line sal
;
8023 sal
= find_pc_line (pc
, 0);
8025 sal
.section
= find_pc_overlay (pc
);
8026 sal
.explicit_pc
= 1;
8028 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8032 /* Tell the user we have just set a breakpoint B. */
8035 mention (const breakpoint
*b
)
8037 b
->print_mention ();
8038 current_uiout
->text ("\n");
8042 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8044 /* Handle "set breakpoint auto-hw on".
8046 If the explicitly specified breakpoint type is not hardware
8047 breakpoint, check the memory map to see whether the breakpoint
8048 address is in read-only memory.
8050 - location type is not hardware breakpoint, memory is read-only.
8051 We change the type of the location to hardware breakpoint.
8053 - location type is hardware breakpoint, memory is read-write. This
8054 means we've previously made the location hardware one, but then the
8055 memory map changed, so we undo.
8059 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8061 if (automatic_hardware_breakpoints
8062 && bl
->owner
->type
!= bp_hardware_breakpoint
8063 && (bl
->loc_type
== bp_loc_software_breakpoint
8064 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8066 /* When breakpoints are removed, remove_breakpoints will use
8067 location types we've just set here, the only possible problem
8068 is that memory map has changed during running program, but
8069 it's not going to work anyway with current gdb. */
8070 mem_region
*mr
= lookup_mem_region (bl
->address
);
8074 enum bp_loc_type new_type
;
8076 if (mr
->attrib
.mode
!= MEM_RW
)
8077 new_type
= bp_loc_hardware_breakpoint
;
8079 new_type
= bp_loc_software_breakpoint
;
8081 if (new_type
!= bl
->loc_type
)
8083 static bool said
= false;
8085 bl
->loc_type
= new_type
;
8088 gdb_printf (_("Note: automatically using "
8089 "hardware breakpoints for "
8090 "read-only addresses.\n"));
8099 code_breakpoint::add_location (const symtab_and_line
&sal
)
8101 struct bp_location
*new_loc
, **tmp
;
8102 CORE_ADDR adjusted_address
;
8103 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8105 if (loc_gdbarch
== NULL
)
8106 loc_gdbarch
= gdbarch
;
8108 /* Adjust the breakpoint's address prior to allocating a location.
8109 Once we call allocate_location(), that mostly uninitialized
8110 location will be placed on the location chain. Adjustment of the
8111 breakpoint may cause target_read_memory() to be called and we do
8112 not want its scan of the location chain to find a breakpoint and
8113 location that's only been partially initialized. */
8114 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8118 /* Sort the locations by their ADDRESS. */
8119 new_loc
= allocate_location ();
8120 for (tmp
= &(loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8121 tmp
= &((*tmp
)->next
))
8123 new_loc
->next
= *tmp
;
8126 new_loc
->requested_address
= sal
.pc
;
8127 new_loc
->address
= adjusted_address
;
8128 new_loc
->pspace
= sal
.pspace
;
8129 new_loc
->probe
.prob
= sal
.prob
;
8130 new_loc
->probe
.objfile
= sal
.objfile
;
8131 gdb_assert (new_loc
->pspace
!= NULL
);
8132 new_loc
->section
= sal
.section
;
8133 new_loc
->gdbarch
= loc_gdbarch
;
8134 new_loc
->line_number
= sal
.line
;
8135 new_loc
->symtab
= sal
.symtab
;
8136 new_loc
->symbol
= sal
.symbol
;
8137 new_loc
->msymbol
= sal
.msymbol
;
8138 new_loc
->objfile
= sal
.objfile
;
8140 set_breakpoint_location_function (new_loc
);
8142 /* While by definition, permanent breakpoints are already present in the
8143 code, we don't mark the location as inserted. Normally one would expect
8144 that GDB could rely on that breakpoint instruction to stop the program,
8145 thus removing the need to insert its own breakpoint, except that executing
8146 the breakpoint instruction can kill the target instead of reporting a
8147 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8148 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8149 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8150 breakpoint be inserted normally results in QEMU knowing about the GDB
8151 breakpoint, and thus trap before the breakpoint instruction is executed.
8152 (If GDB later needs to continue execution past the permanent breakpoint,
8153 it manually increments the PC, thus avoiding executing the breakpoint
8155 if (bp_loc_is_permanent (new_loc
))
8156 new_loc
->permanent
= 1;
8162 /* Return true if LOC is pointing to a permanent breakpoint,
8163 return false otherwise. */
8166 bp_loc_is_permanent (struct bp_location
*loc
)
8168 gdb_assert (loc
!= NULL
);
8170 /* If we have a non-breakpoint-backed catchpoint or a software
8171 watchpoint, just return 0. We should not attempt to read from
8172 the addresses the locations of these breakpoint types point to.
8173 gdbarch_program_breakpoint_here_p, below, will attempt to read
8175 if (!bl_address_is_meaningful (loc
))
8178 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8179 switch_to_program_space_and_thread (loc
->pspace
);
8180 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8183 /* Build a command list for the dprintf corresponding to the current
8184 settings of the dprintf style options. */
8187 update_dprintf_command_list (struct breakpoint
*b
)
8189 const char *dprintf_args
= b
->extra_string
.get ();
8190 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8195 dprintf_args
= skip_spaces (dprintf_args
);
8197 /* Allow a comma, as it may have terminated a location, but don't
8199 if (*dprintf_args
== ',')
8201 dprintf_args
= skip_spaces (dprintf_args
);
8203 if (*dprintf_args
!= '"')
8204 error (_("Bad format string, missing '\"'."));
8206 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8207 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8208 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8210 if (dprintf_function
.empty ())
8211 error (_("No function supplied for dprintf call"));
8213 if (!dprintf_channel
.empty ())
8214 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8215 dprintf_function
.c_str (),
8216 dprintf_channel
.c_str (),
8219 printf_line
= xstrprintf ("call (void) %s (%s)",
8220 dprintf_function
.c_str (),
8223 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8225 if (target_can_run_breakpoint_commands ())
8226 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8229 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8230 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8234 internal_error (__FILE__
, __LINE__
,
8235 _("Invalid dprintf style."));
8237 gdb_assert (printf_line
!= NULL
);
8239 /* Manufacture a printf sequence. */
8240 struct command_line
*printf_cmd_line
8241 = new struct command_line (simple_control
, printf_line
.release ());
8242 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8243 command_lines_deleter ()));
8246 /* Update all dprintf commands, making their command lists reflect
8247 current style settings. */
8250 update_dprintf_commands (const char *args
, int from_tty
,
8251 struct cmd_list_element
*c
)
8253 for (breakpoint
*b
: all_breakpoints ())
8254 if (b
->type
== bp_dprintf
)
8255 update_dprintf_command_list (b
);
8258 code_breakpoint::code_breakpoint (struct gdbarch
*gdbarch_
,
8260 gdb::array_view
<const symtab_and_line
> sals
,
8261 location_spec_up
&&locspec_
,
8262 gdb::unique_xmalloc_ptr
<char> filter_
,
8263 gdb::unique_xmalloc_ptr
<char> cond_string_
,
8264 gdb::unique_xmalloc_ptr
<char> extra_string_
,
8265 enum bpdisp disposition_
,
8266 int thread_
, int task_
, int ignore_count_
,
8268 int enabled_
, unsigned flags
,
8269 int display_canonical_
)
8270 : breakpoint (gdbarch_
, type_
)
8274 if (type
== bp_hardware_breakpoint
)
8276 int target_resources_ok
;
8278 i
= hw_breakpoint_used_count ();
8279 target_resources_ok
=
8280 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8282 if (target_resources_ok
== 0)
8283 error (_("No hardware breakpoint support in the target."));
8284 else if (target_resources_ok
< 0)
8285 error (_("Hardware breakpoints used exceeds limit."));
8288 gdb_assert (!sals
.empty ());
8293 cond_string
= std::move (cond_string_
);
8294 extra_string
= std::move (extra_string_
);
8295 ignore_count
= ignore_count_
;
8296 enable_state
= enabled_
? bp_enabled
: bp_disabled
;
8297 disposition
= disposition_
;
8299 if (type
== bp_static_tracepoint
8300 || type
== bp_static_marker_tracepoint
)
8302 auto *t
= static_cast<struct tracepoint
*> (this);
8303 struct static_tracepoint_marker marker
;
8305 if (strace_marker_p (this))
8307 /* We already know the marker exists, otherwise, we wouldn't
8308 see a sal for it. */
8309 const char *p
= &locspec_
->to_string ()[3];
8312 p
= skip_spaces (p
);
8314 endp
= skip_to_space (p
);
8316 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8318 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8319 t
->static_trace_marker_id
.c_str ());
8321 else if (target_static_tracepoint_marker_at (sals
[0].pc
, &marker
))
8323 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8325 gdb_printf (_("Probed static tracepoint marker \"%s\"\n"),
8326 t
->static_trace_marker_id
.c_str ());
8329 warning (_("Couldn't determine the static tracepoint marker to probe"));
8332 for (const auto &sal
: sals
)
8336 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8337 if (loc_gdbarch
== nullptr)
8338 loc_gdbarch
= gdbarch
;
8340 describe_other_breakpoints (loc_gdbarch
,
8341 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8344 bp_location
*new_loc
= add_location (sal
);
8345 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8346 new_loc
->inserted
= 1;
8348 /* Do not set breakpoint locations conditions yet. As locations
8349 are inserted, they get sorted based on their addresses. Let
8350 the list stabilize to have reliable location numbers. */
8352 /* Dynamic printf requires and uses additional arguments on the
8353 command line, otherwise it's an error. */
8354 if (type
== bp_dprintf
)
8356 if (extra_string
!= nullptr)
8357 update_dprintf_command_list (this);
8359 error (_("Format string required"));
8361 else if (extra_string
!= nullptr)
8362 error (_("Garbage '%s' at end of command"), extra_string
.get ());
8365 /* The order of the locations is now stable. Set the location
8366 condition using the location's number. */
8368 for (bp_location
*bl
: locations ())
8370 if (cond_string
!= nullptr)
8371 set_breakpoint_location_condition (cond_string
.get (), bl
,
8377 display_canonical
= display_canonical_
;
8378 if (locspec_
!= nullptr)
8379 locspec
= std::move (locspec_
);
8381 locspec
= new_address_location_spec (this->loc
->address
, NULL
, 0);
8382 filter
= std::move (filter_
);
8386 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8387 gdb::array_view
<const symtab_and_line
> sals
,
8388 location_spec_up
&&locspec
,
8389 gdb::unique_xmalloc_ptr
<char> filter
,
8390 gdb::unique_xmalloc_ptr
<char> cond_string
,
8391 gdb::unique_xmalloc_ptr
<char> extra_string
,
8392 enum bptype type
, enum bpdisp disposition
,
8393 int thread
, int task
, int ignore_count
,
8395 int enabled
, int internal
, unsigned flags
,
8396 int display_canonical
)
8398 std::unique_ptr
<code_breakpoint
> b
8399 = new_breakpoint_from_type (gdbarch
,
8402 std::move (locspec
),
8404 std::move (cond_string
),
8405 std::move (extra_string
),
8407 thread
, task
, ignore_count
,
8412 install_breakpoint (internal
, std::move (b
), 0);
8415 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8416 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8417 value. COND_STRING, if not NULL, specified the condition to be
8418 used for all breakpoints. Essentially the only case where
8419 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8420 function. In that case, it's still not possible to specify
8421 separate conditions for different overloaded functions, so
8422 we take just a single condition string.
8424 NOTE: If the function succeeds, the caller is expected to cleanup
8425 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8426 array contents). If the function fails (error() is called), the
8427 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8428 COND and SALS arrays and each of those arrays contents. */
8431 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8432 struct linespec_result
*canonical
,
8433 gdb::unique_xmalloc_ptr
<char> cond_string
,
8434 gdb::unique_xmalloc_ptr
<char> extra_string
,
8435 enum bptype type
, enum bpdisp disposition
,
8436 int thread
, int task
, int ignore_count
,
8438 int enabled
, int internal
, unsigned flags
)
8440 if (canonical
->pre_expanded
)
8441 gdb_assert (canonical
->lsals
.size () == 1);
8443 for (const auto &lsal
: canonical
->lsals
)
8445 /* Note that 'location' can be NULL in the case of a plain
8446 'break', without arguments. */
8447 location_spec_up locspec
8448 = (canonical
->locspec
!= nullptr
8449 ? canonical
->locspec
->clone ()
8451 gdb::unique_xmalloc_ptr
<char> filter_string
8452 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8454 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8455 std::move (locspec
),
8456 std::move (filter_string
),
8457 std::move (cond_string
),
8458 std::move (extra_string
),
8460 thread
, task
, ignore_count
,
8461 from_tty
, enabled
, internal
, flags
,
8462 canonical
->special_display
);
8466 /* Parse LOCSPEC which is assumed to be a SAL specification possibly
8467 followed by conditionals. On return, SALS contains an array of SAL
8468 addresses found. LOCSPEC points to the end of the SAL (for
8471 The array and the line spec strings are allocated on the heap, it is
8472 the caller's responsibility to free them. */
8475 parse_breakpoint_sals (location_spec
*locspec
,
8476 struct linespec_result
*canonical
)
8478 struct symtab_and_line cursal
;
8480 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8482 const char *spec
= as_linespec_location_spec (locspec
)->spec_string
;
8486 /* The last displayed codepoint, if it's valid, is our default
8487 breakpoint address. */
8488 if (last_displayed_sal_is_valid ())
8490 /* Set sal's pspace, pc, symtab, and line to the values
8491 corresponding to the last call to print_frame_info.
8492 Be sure to reinitialize LINE with NOTCURRENT == 0
8493 as the breakpoint line number is inappropriate otherwise.
8494 find_pc_line would adjust PC, re-set it back. */
8495 symtab_and_line sal
= get_last_displayed_sal ();
8496 CORE_ADDR pc
= sal
.pc
;
8498 sal
= find_pc_line (pc
, 0);
8500 /* "break" without arguments is equivalent to "break *PC"
8501 where PC is the last displayed codepoint's address. So
8502 make sure to set sal.explicit_pc to prevent GDB from
8503 trying to expand the list of sals to include all other
8504 instances with the same symtab and line. */
8506 sal
.explicit_pc
= 1;
8508 struct linespec_sals lsal
;
8510 lsal
.canonical
= NULL
;
8512 canonical
->lsals
.push_back (std::move (lsal
));
8516 error (_("No default breakpoint address now."));
8520 /* Force almost all breakpoints to be in terms of the
8521 current_source_symtab (which is decode_line_1's default).
8522 This should produce the results we want almost all of the
8523 time while leaving default_breakpoint_* alone.
8525 ObjC: However, don't match an Objective-C method name which
8526 may have a '+' or '-' succeeded by a '['. */
8527 cursal
= get_current_source_symtab_and_line ();
8528 if (last_displayed_sal_is_valid ())
8530 const char *spec
= NULL
;
8532 if (locspec
->type () == LINESPEC_LOCATION_SPEC
)
8533 spec
= as_linespec_location_spec (locspec
)->spec_string
;
8537 && strchr ("+-", spec
[0]) != NULL
8540 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8541 get_last_displayed_symtab (),
8542 get_last_displayed_line (),
8543 canonical
, NULL
, NULL
);
8548 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8549 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8553 /* Convert each SAL into a real PC. Verify that the PC can be
8554 inserted as a breakpoint. If it can't throw an error. */
8557 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8559 for (auto &sal
: sals
)
8560 resolve_sal_pc (&sal
);
8563 /* Fast tracepoints may have restrictions on valid locations. For
8564 instance, a fast tracepoint using a jump instead of a trap will
8565 likely have to overwrite more bytes than a trap would, and so can
8566 only be placed where the instruction is longer than the jump, or a
8567 multi-instruction sequence does not have a jump into the middle of
8571 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8572 gdb::array_view
<const symtab_and_line
> sals
)
8574 for (const auto &sal
: sals
)
8576 struct gdbarch
*sarch
;
8578 sarch
= get_sal_arch (sal
);
8579 /* We fall back to GDBARCH if there is no architecture
8580 associated with SAL. */
8584 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8585 error (_("May not have a fast tracepoint at %s%s"),
8586 paddress (sarch
, sal
.pc
), msg
.c_str ());
8590 /* Given TOK, a string specification of condition and thread, as
8591 accepted by the 'break' command, extract the condition
8592 string and thread number and set *COND_STRING and *THREAD.
8593 PC identifies the context at which the condition should be parsed.
8594 If no condition is found, *COND_STRING is set to NULL.
8595 If no thread is found, *THREAD is set to -1. */
8598 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8599 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8600 int *thread
, int *task
,
8601 gdb::unique_xmalloc_ptr
<char> *rest
)
8603 cond_string
->reset ();
8611 const char *end_tok
;
8613 const char *cond_start
= NULL
;
8614 const char *cond_end
= NULL
;
8616 tok
= skip_spaces (tok
);
8618 if ((*tok
== '"' || *tok
== ',') && rest
)
8620 rest
->reset (savestring (tok
, strlen (tok
)));
8624 end_tok
= skip_to_space (tok
);
8626 toklen
= end_tok
- tok
;
8628 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8630 tok
= cond_start
= end_tok
+ 1;
8633 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8635 catch (const gdb_exception_error
&)
8640 tok
= tok
+ strlen (tok
);
8643 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8645 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8650 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8653 struct thread_info
*thr
;
8656 thr
= parse_thread_id (tok
, &tmptok
);
8658 error (_("Junk after thread keyword."));
8659 *thread
= thr
->global_num
;
8662 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8667 *task
= strtol (tok
, &tmptok
, 0);
8669 error (_("Junk after task keyword."));
8670 if (!valid_task_id (*task
))
8671 error (_("Unknown task %d."), *task
);
8676 rest
->reset (savestring (tok
, strlen (tok
)));
8680 error (_("Junk at end of arguments."));
8684 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8685 succeeds. The parsed values are written to COND_STRING, THREAD,
8686 TASK, and REST. See the comment of 'find_condition_and_thread'
8687 for the description of these parameters and INPUT. */
8690 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8692 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8693 int *thread
, int *task
,
8694 gdb::unique_xmalloc_ptr
<char> *rest
)
8696 int num_failures
= 0;
8697 for (auto &sal
: sals
)
8699 gdb::unique_xmalloc_ptr
<char> cond
;
8702 gdb::unique_xmalloc_ptr
<char> remaining
;
8704 /* Here we want to parse 'arg' to separate condition from thread
8705 number. But because parsing happens in a context and the
8706 contexts of sals might be different, try each until there is
8707 success. Finding one successful parse is sufficient for our
8708 goal. When setting the breakpoint we'll re-parse the
8709 condition in the context of each sal. */
8712 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8713 &task_id
, &remaining
);
8714 *cond_string
= std::move (cond
);
8715 *thread
= thread_id
;
8717 *rest
= std::move (remaining
);
8720 catch (const gdb_exception_error
&e
)
8723 /* If no sal remains, do not continue. */
8724 if (num_failures
== sals
.size ())
8730 /* Decode a static tracepoint marker spec. */
8732 static std::vector
<symtab_and_line
>
8733 decode_static_tracepoint_spec (const char **arg_p
)
8735 const char *p
= &(*arg_p
)[3];
8738 p
= skip_spaces (p
);
8740 endp
= skip_to_space (p
);
8742 std::string
marker_str (p
, endp
- p
);
8744 std::vector
<static_tracepoint_marker
> markers
8745 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8746 if (markers
.empty ())
8747 error (_("No known static tracepoint marker named %s"),
8748 marker_str
.c_str ());
8750 std::vector
<symtab_and_line
> sals
;
8751 sals
.reserve (markers
.size ());
8753 for (const static_tracepoint_marker
&marker
: markers
)
8755 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8756 sal
.pc
= marker
.address
;
8757 sals
.push_back (sal
);
8764 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8765 according to IS_TRACEPOINT. */
8767 static const struct breakpoint_ops
*
8768 breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type
,
8773 if (locspec_type
== PROBE_LOCATION_SPEC
)
8774 return &tracepoint_probe_breakpoint_ops
;
8776 return &code_breakpoint_ops
;
8780 if (locspec_type
== PROBE_LOCATION_SPEC
)
8781 return &bkpt_probe_breakpoint_ops
;
8783 return &code_breakpoint_ops
;
8787 /* See breakpoint.h. */
8789 const struct breakpoint_ops
*
8790 breakpoint_ops_for_location_spec (const location_spec
*locspec
,
8793 if (locspec
!= nullptr)
8794 return (breakpoint_ops_for_location_spec_type
8795 (locspec
->type (), is_tracepoint
));
8796 return &code_breakpoint_ops
;
8799 /* See breakpoint.h. */
8802 create_breakpoint (struct gdbarch
*gdbarch
,
8803 location_spec
*locspec
,
8804 const char *cond_string
,
8805 int thread
, const char *extra_string
,
8806 bool force_condition
, int parse_extra
,
8807 int tempflag
, enum bptype type_wanted
,
8809 enum auto_boolean pending_break_support
,
8810 const struct breakpoint_ops
*ops
,
8811 int from_tty
, int enabled
, int internal
,
8814 struct linespec_result canonical
;
8817 int prev_bkpt_count
= breakpoint_count
;
8819 gdb_assert (ops
!= NULL
);
8821 /* If extra_string isn't useful, set it to NULL. */
8822 if (extra_string
!= NULL
&& *extra_string
== '\0')
8823 extra_string
= NULL
;
8827 ops
->create_sals_from_location_spec (locspec
, &canonical
);
8829 catch (const gdb_exception_error
&e
)
8831 /* If caller is interested in rc value from parse, set
8833 if (e
.error
== NOT_FOUND_ERROR
)
8835 /* If pending breakpoint support is turned off, throw
8838 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8841 exception_print (gdb_stderr
, e
);
8843 /* If pending breakpoint support is auto query and the user
8844 selects no, then simply return the error code. */
8845 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8846 && !nquery (_("Make %s pending on future shared library load? "),
8847 bptype_string (type_wanted
)))
8850 /* At this point, either the user was queried about setting
8851 a pending breakpoint and selected yes, or pending
8852 breakpoint behavior is on and thus a pending breakpoint
8853 is defaulted on behalf of the user. */
8860 if (!pending
&& canonical
.lsals
.empty ())
8863 /* Resolve all line numbers to PC's and verify that the addresses
8864 are ok for the target. */
8867 for (auto &lsal
: canonical
.lsals
)
8868 breakpoint_sals_to_pc (lsal
.sals
);
8871 /* Fast tracepoints may have additional restrictions on location. */
8872 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8874 for (const auto &lsal
: canonical
.lsals
)
8875 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
8878 /* Verify that condition can be parsed, before setting any
8879 breakpoints. Allocate a separate condition expression for each
8883 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
8884 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
8888 gdb::unique_xmalloc_ptr
<char> rest
;
8889 gdb::unique_xmalloc_ptr
<char> cond
;
8891 const linespec_sals
&lsal
= canonical
.lsals
[0];
8893 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
8894 &cond
, &thread
, &task
, &rest
);
8895 cond_string_copy
= std::move (cond
);
8896 extra_string_copy
= std::move (rest
);
8900 if (type_wanted
!= bp_dprintf
8901 && extra_string
!= NULL
&& *extra_string
!= '\0')
8902 error (_("Garbage '%s' at end of location"), extra_string
);
8904 /* Check the validity of the condition. We should error out
8905 if the condition is invalid at all of the locations and
8906 if it is not forced. In the PARSE_EXTRA case above, this
8907 check is done when parsing the EXTRA_STRING. */
8908 if (cond_string
!= nullptr && !force_condition
)
8910 int num_failures
= 0;
8911 const linespec_sals
&lsal
= canonical
.lsals
[0];
8912 for (const auto &sal
: lsal
.sals
)
8914 const char *cond
= cond_string
;
8917 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
8918 /* One success is sufficient to keep going. */
8921 catch (const gdb_exception_error
&)
8924 /* If this is the last sal, error out. */
8925 if (num_failures
== lsal
.sals
.size ())
8931 /* Create a private copy of condition string. */
8933 cond_string_copy
.reset (xstrdup (cond_string
));
8934 /* Create a private copy of any extra string. */
8936 extra_string_copy
.reset (xstrdup (extra_string
));
8939 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
8940 std::move (cond_string_copy
),
8941 std::move (extra_string_copy
),
8943 tempflag
? disp_del
: disp_donttouch
,
8944 thread
, task
, ignore_count
,
8945 from_tty
, enabled
, internal
, flags
);
8949 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
,
8951 b
->locspec
= locspec
->clone ();
8954 b
->cond_string
= NULL
;
8957 /* Create a private copy of condition string. */
8958 b
->cond_string
.reset (cond_string
!= NULL
8959 ? xstrdup (cond_string
)
8964 /* Create a private copy of any extra string. */
8965 b
->extra_string
.reset (extra_string
!= NULL
8966 ? xstrdup (extra_string
)
8968 b
->ignore_count
= ignore_count
;
8969 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8970 b
->condition_not_parsed
= 1;
8971 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8972 if ((type_wanted
!= bp_breakpoint
8973 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
8974 b
->pspace
= current_program_space
;
8976 install_breakpoint (internal
, std::move (b
), 0);
8979 if (canonical
.lsals
.size () > 1)
8981 warning (_("Multiple breakpoints were set.\nUse the "
8982 "\"delete\" command to delete unwanted breakpoints."));
8983 prev_breakpoint_count
= prev_bkpt_count
;
8986 update_global_location_list (UGLL_MAY_INSERT
);
8991 /* Set a breakpoint.
8992 ARG is a string describing breakpoint address,
8993 condition, and thread.
8994 FLAG specifies if a breakpoint is hardware on,
8995 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8999 break_command_1 (const char *arg
, int flag
, int from_tty
)
9001 int tempflag
= flag
& BP_TEMPFLAG
;
9002 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9003 ? bp_hardware_breakpoint
9006 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9007 const struct breakpoint_ops
*ops
9008 = breakpoint_ops_for_location_spec (locspec
.get (),
9009 false /* is_tracepoint */);
9011 create_breakpoint (get_current_arch (),
9013 NULL
, 0, arg
, false, 1 /* parse arg */,
9014 tempflag
, type_wanted
,
9015 0 /* Ignore count */,
9016 pending_break_support
,
9024 /* Helper function for break_command_1 and disassemble_command. */
9027 resolve_sal_pc (struct symtab_and_line
*sal
)
9031 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9033 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9034 error (_("No line %d in file \"%s\"."),
9035 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9038 /* If this SAL corresponds to a breakpoint inserted using a line
9039 number, then skip the function prologue if necessary. */
9040 if (sal
->explicit_line
)
9041 skip_prologue_sal (sal
);
9044 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9046 const struct blockvector
*bv
;
9047 const struct block
*b
;
9050 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9051 sal
->symtab
->compunit ());
9054 sym
= block_linkage_function (b
);
9057 fixup_symbol_section (sym
, sal
->symtab
->compunit ()->objfile ());
9059 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9063 /* It really is worthwhile to have the section, so we'll
9064 just have to look harder. This case can be executed
9065 if we have line numbers but no functions (as can
9066 happen in assembly source). */
9068 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9069 switch_to_program_space_and_thread (sal
->pspace
);
9071 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9073 sal
->section
= msym
.obj_section ();
9080 break_command (const char *arg
, int from_tty
)
9082 break_command_1 (arg
, 0, from_tty
);
9086 tbreak_command (const char *arg
, int from_tty
)
9088 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9092 hbreak_command (const char *arg
, int from_tty
)
9094 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9098 thbreak_command (const char *arg
, int from_tty
)
9100 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9103 /* The dynamic printf command is mostly like a regular breakpoint, but
9104 with a prewired command list consisting of a single output command,
9105 built from extra arguments supplied on the dprintf command
9109 dprintf_command (const char *arg
, int from_tty
)
9111 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
9113 /* If non-NULL, ARG should have been advanced past the location;
9114 the next character must be ','. */
9117 if (arg
[0] != ',' || arg
[1] == '\0')
9118 error (_("Format string required"));
9121 /* Skip the comma. */
9126 create_breakpoint (get_current_arch (),
9128 NULL
, 0, arg
, false, 1 /* parse arg */,
9130 0 /* Ignore count */,
9131 pending_break_support
,
9132 &code_breakpoint_ops
,
9140 agent_printf_command (const char *arg
, int from_tty
)
9142 error (_("May only run agent-printf on the target"));
9145 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9148 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9149 const address_space
*aspace
,
9151 const target_waitstatus
&ws
)
9153 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9154 || ws
.sig () != GDB_SIGNAL_TRAP
)
9157 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9158 bl
->length
, aspace
, bp_addr
);
9161 /* Implement the "resources_needed" method for ranged breakpoints. */
9164 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9166 return target_ranged_break_num_registers ();
9169 /* Implement the "print_it" method for ranged breakpoints. */
9171 enum print_stop_action
9172 ranged_breakpoint::print_it (const bpstat
*bs
) const
9174 struct bp_location
*bl
= loc
;
9175 struct ui_out
*uiout
= current_uiout
;
9177 gdb_assert (type
== bp_hardware_breakpoint
);
9179 /* Ranged breakpoints have only one location. */
9180 gdb_assert (bl
&& bl
->next
== NULL
);
9182 annotate_breakpoint (number
);
9184 maybe_print_thread_hit_breakpoint (uiout
);
9186 if (disposition
== disp_del
)
9187 uiout
->text ("Temporary ranged breakpoint ");
9189 uiout
->text ("Ranged breakpoint ");
9190 if (uiout
->is_mi_like_p ())
9192 uiout
->field_string ("reason",
9193 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9194 uiout
->field_string ("disp", bpdisp_text (disposition
));
9196 uiout
->field_signed ("bkptno", number
);
9199 return PRINT_SRC_AND_LOC
;
9202 /* Implement the "print_one" method for ranged breakpoints. */
9205 ranged_breakpoint::print_one (bp_location
**last_loc
) const
9207 struct bp_location
*bl
= loc
;
9208 struct value_print_options opts
;
9209 struct ui_out
*uiout
= current_uiout
;
9211 /* Ranged breakpoints have only one location. */
9212 gdb_assert (bl
&& bl
->next
== NULL
);
9214 get_user_print_options (&opts
);
9216 if (opts
.addressprint
)
9217 /* We don't print the address range here, it will be printed later
9218 by ranged_breakpoint::print_one_detail. */
9219 uiout
->field_skip ("addr");
9221 print_breakpoint_location (this, bl
);
9227 /* Implement the "print_one_detail" method for ranged breakpoints. */
9230 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9232 CORE_ADDR address_start
, address_end
;
9233 struct bp_location
*bl
= loc
;
9238 address_start
= bl
->address
;
9239 address_end
= address_start
+ bl
->length
- 1;
9241 uiout
->text ("\taddress range: ");
9242 stb
.printf ("[%s, %s]",
9243 print_core_address (bl
->gdbarch
, address_start
),
9244 print_core_address (bl
->gdbarch
, address_end
));
9245 uiout
->field_stream ("addr", stb
);
9249 /* Implement the "print_mention" method for ranged breakpoints. */
9252 ranged_breakpoint::print_mention () const
9254 struct bp_location
*bl
= loc
;
9255 struct ui_out
*uiout
= current_uiout
;
9258 gdb_assert (type
== bp_hardware_breakpoint
);
9260 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9261 number
, paddress (bl
->gdbarch
, bl
->address
),
9262 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9265 /* Implement the "print_recreate" method for ranged breakpoints. */
9268 ranged_breakpoint::print_recreate (struct ui_file
*fp
) const
9270 gdb_printf (fp
, "break-range %s, %s",
9271 locspec
->to_string (),
9272 locspec_range_end
->to_string ());
9273 print_recreate_thread (fp
);
9276 /* Find the address where the end of the breakpoint range should be
9277 placed, given the SAL of the end of the range. This is so that if
9278 the user provides a line number, the end of the range is set to the
9279 last instruction of the given line. */
9282 find_breakpoint_range_end (struct symtab_and_line sal
)
9286 /* If the user provided a PC value, use it. Otherwise,
9287 find the address of the end of the given location. */
9288 if (sal
.explicit_pc
)
9295 ret
= find_line_pc_range (sal
, &start
, &end
);
9297 error (_("Could not find location of the end of the range."));
9299 /* find_line_pc_range returns the start of the next line. */
9306 /* Implement the "break-range" CLI command. */
9309 break_range_command (const char *arg
, int from_tty
)
9311 const char *arg_start
;
9312 struct linespec_result canonical_start
, canonical_end
;
9313 int bp_count
, can_use_bp
, length
;
9316 /* We don't support software ranged breakpoints. */
9317 if (target_ranged_break_num_registers () < 0)
9318 error (_("This target does not support hardware ranged breakpoints."));
9320 bp_count
= hw_breakpoint_used_count ();
9321 bp_count
+= target_ranged_break_num_registers ();
9322 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9325 error (_("Hardware breakpoints used exceeds limit."));
9327 arg
= skip_spaces (arg
);
9328 if (arg
== NULL
|| arg
[0] == '\0')
9329 error(_("No address range specified."));
9332 location_spec_up start_locspec
9333 = string_to_location_spec (&arg
, current_language
);
9334 parse_breakpoint_sals (start_locspec
.get (), &canonical_start
);
9337 error (_("Too few arguments."));
9338 else if (canonical_start
.lsals
.empty ())
9339 error (_("Could not find location of the beginning of the range."));
9341 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9343 if (canonical_start
.lsals
.size () > 1
9344 || lsal_start
.sals
.size () != 1)
9345 error (_("Cannot create a ranged breakpoint with multiple locations."));
9347 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9348 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9350 arg
++; /* Skip the comma. */
9351 arg
= skip_spaces (arg
);
9353 /* Parse the end location specification. */
9357 /* We call decode_line_full directly here instead of using
9358 parse_breakpoint_sals because we need to specify the start
9359 location spec's symtab and line as the default symtab and line
9360 for the end of the range. This makes it possible to have ranges
9361 like "foo.c:27, +14", where +14 means 14 lines from the start
9363 location_spec_up end_locspec
9364 = string_to_location_spec (&arg
, current_language
);
9365 decode_line_full (end_locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9366 sal_start
.symtab
, sal_start
.line
,
9367 &canonical_end
, NULL
, NULL
);
9369 if (canonical_end
.lsals
.empty ())
9370 error (_("Could not find location of the end of the range."));
9372 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9373 if (canonical_end
.lsals
.size () > 1
9374 || lsal_end
.sals
.size () != 1)
9375 error (_("Cannot create a ranged breakpoint with multiple locations."));
9377 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9379 end
= find_breakpoint_range_end (sal_end
);
9380 if (sal_start
.pc
> end
)
9381 error (_("Invalid address range, end precedes start."));
9383 length
= end
- sal_start
.pc
+ 1;
9385 /* Length overflowed. */
9386 error (_("Address range too large."));
9387 else if (length
== 1)
9389 /* This range is simple enough to be handled by
9390 the `hbreak' command. */
9391 hbreak_command (&addr_string_start
[0], 1);
9396 /* Now set up the breakpoint and install it. */
9398 std::unique_ptr
<breakpoint
> br
9399 (new ranged_breakpoint (get_current_arch (),
9401 std::move (start_locspec
),
9402 std::move (end_locspec
)));
9404 install_breakpoint (false, std::move (br
), true);
9407 /* Return non-zero if EXP is verified as constant. Returned zero
9408 means EXP is variable. Also the constant detection may fail for
9409 some constant expressions and in such case still falsely return
9413 watchpoint_exp_is_const (const struct expression
*exp
)
9415 return exp
->op
->constant_p ();
9418 /* Implement the "re_set" method for watchpoints. */
9421 watchpoint::re_set ()
9423 /* Watchpoint can be either on expression using entirely global
9424 variables, or it can be on local variables.
9426 Watchpoints of the first kind are never auto-deleted, and even
9427 persist across program restarts. Since they can use variables
9428 from shared libraries, we need to reparse expression as libraries
9429 are loaded and unloaded.
9431 Watchpoints on local variables can also change meaning as result
9432 of solib event. For example, if a watchpoint uses both a local
9433 and a global variables in expression, it's a local watchpoint,
9434 but unloading of a shared library will make the expression
9435 invalid. This is not a very common use case, but we still
9436 re-evaluate expression, to avoid surprises to the user.
9438 Note that for local watchpoints, we re-evaluate it only if
9439 watchpoints frame id is still valid. If it's not, it means the
9440 watchpoint is out of scope and will be deleted soon. In fact,
9441 I'm not sure we'll ever be called in this case.
9443 If a local watchpoint's frame id is still valid, then
9444 exp_valid_block is likewise valid, and we can safely use it.
9446 Don't do anything about disabled watchpoints, since they will be
9447 reevaluated again when enabled. */
9448 update_watchpoint (this, 1 /* reparse */);
9451 /* Implement the "insert" method for hardware watchpoints. */
9454 watchpoint::insert_location (struct bp_location
*bl
)
9456 int length
= exact
? 1 : bl
->length
;
9458 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9462 /* Implement the "remove" method for hardware watchpoints. */
9465 watchpoint::remove_location (struct bp_location
*bl
,
9466 enum remove_bp_reason reason
)
9468 int length
= exact
? 1 : bl
->length
;
9470 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9475 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9476 const address_space
*aspace
, CORE_ADDR bp_addr
,
9477 const target_waitstatus
&ws
)
9479 struct breakpoint
*b
= bl
->owner
;
9481 /* Continuable hardware watchpoints are treated as non-existent if the
9482 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9483 some data address). Otherwise gdb won't stop on a break instruction
9484 in the code (not from a breakpoint) when a hardware watchpoint has
9485 been defined. Also skip watchpoints which we know did not trigger
9486 (did not match the data address). */
9487 if (is_hardware_watchpoint (b
)
9488 && watchpoint_triggered
== watch_triggered_no
)
9495 watchpoint::check_status (bpstat
*bs
)
9497 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9499 bpstat_check_watchpoint (bs
);
9502 /* Implement the "resources_needed" method for hardware
9506 watchpoint::resources_needed (const struct bp_location
*bl
)
9508 int length
= exact
? 1 : bl
->length
;
9510 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9513 /* Implement the "works_in_software_mode" method for hardware
9517 watchpoint::works_in_software_mode () const
9519 /* Read and access watchpoints only work with hardware support. */
9520 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9523 enum print_stop_action
9524 watchpoint::print_it (const bpstat
*bs
) const
9526 struct breakpoint
*b
;
9527 enum print_stop_action result
;
9528 struct ui_out
*uiout
= current_uiout
;
9530 gdb_assert (bs
->bp_location_at
!= NULL
);
9532 b
= bs
->breakpoint_at
;
9534 annotate_watchpoint (b
->number
);
9535 maybe_print_thread_hit_breakpoint (uiout
);
9539 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9543 case bp_hardware_watchpoint
:
9544 if (uiout
->is_mi_like_p ())
9546 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9548 tuple_emitter
.emplace (uiout
, "value");
9549 uiout
->text ("\nOld value = ");
9550 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9551 uiout
->field_stream ("old", stb
);
9552 uiout
->text ("\nNew value = ");
9553 watchpoint_value_print (val
.get (), &stb
);
9554 uiout
->field_stream ("new", stb
);
9556 /* More than one watchpoint may have been triggered. */
9557 result
= PRINT_UNKNOWN
;
9560 case bp_read_watchpoint
:
9561 if (uiout
->is_mi_like_p ())
9563 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9565 tuple_emitter
.emplace (uiout
, "value");
9566 uiout
->text ("\nValue = ");
9567 watchpoint_value_print (val
.get (), &stb
);
9568 uiout
->field_stream ("value", stb
);
9570 result
= PRINT_UNKNOWN
;
9573 case bp_access_watchpoint
:
9574 if (bs
->old_val
!= NULL
)
9576 if (uiout
->is_mi_like_p ())
9579 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9581 tuple_emitter
.emplace (uiout
, "value");
9582 uiout
->text ("\nOld value = ");
9583 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9584 uiout
->field_stream ("old", stb
);
9585 uiout
->text ("\nNew value = ");
9590 if (uiout
->is_mi_like_p ())
9593 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9594 tuple_emitter
.emplace (uiout
, "value");
9595 uiout
->text ("\nValue = ");
9597 watchpoint_value_print (val
.get (), &stb
);
9598 uiout
->field_stream ("new", stb
);
9600 result
= PRINT_UNKNOWN
;
9603 result
= PRINT_UNKNOWN
;
9609 /* Implement the "print_mention" method for hardware watchpoints. */
9612 watchpoint::print_mention () const
9614 struct ui_out
*uiout
= current_uiout
;
9615 const char *tuple_name
;
9620 uiout
->text ("Watchpoint ");
9623 case bp_hardware_watchpoint
:
9624 uiout
->text ("Hardware watchpoint ");
9627 case bp_read_watchpoint
:
9628 uiout
->text ("Hardware read watchpoint ");
9629 tuple_name
= "hw-rwpt";
9631 case bp_access_watchpoint
:
9632 uiout
->text ("Hardware access (read/write) watchpoint ");
9633 tuple_name
= "hw-awpt";
9636 internal_error (__FILE__
, __LINE__
,
9637 _("Invalid hardware watchpoint type."));
9640 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9641 uiout
->field_signed ("number", number
);
9643 uiout
->field_string ("exp", exp_string
.get ());
9646 /* Implement the "print_recreate" method for watchpoints. */
9649 watchpoint::print_recreate (struct ui_file
*fp
) const
9654 case bp_hardware_watchpoint
:
9655 gdb_printf (fp
, "watch");
9657 case bp_read_watchpoint
:
9658 gdb_printf (fp
, "rwatch");
9660 case bp_access_watchpoint
:
9661 gdb_printf (fp
, "awatch");
9664 internal_error (__FILE__
, __LINE__
,
9665 _("Invalid watchpoint type."));
9668 gdb_printf (fp
, " %s", exp_string
.get ());
9669 print_recreate_thread (fp
);
9672 /* Implement the "explains_signal" method for watchpoints. */
9675 watchpoint::explains_signal (enum gdb_signal sig
)
9677 /* A software watchpoint cannot cause a signal other than
9679 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9685 struct masked_watchpoint
: public watchpoint
9687 using watchpoint::watchpoint
;
9689 int insert_location (struct bp_location
*) override
;
9690 int remove_location (struct bp_location
*,
9691 enum remove_bp_reason reason
) override
;
9692 int resources_needed (const struct bp_location
*) override
;
9693 bool works_in_software_mode () const override
;
9694 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
9695 void print_one_detail (struct ui_out
*) const override
;
9696 void print_mention () const override
;
9697 void print_recreate (struct ui_file
*fp
) const override
;
9700 /* Implement the "insert" method for masked hardware watchpoints. */
9703 masked_watchpoint::insert_location (struct bp_location
*bl
)
9705 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9706 bl
->watchpoint_type
);
9709 /* Implement the "remove" method for masked hardware watchpoints. */
9712 masked_watchpoint::remove_location (struct bp_location
*bl
,
9713 enum remove_bp_reason reason
)
9715 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9716 bl
->watchpoint_type
);
9719 /* Implement the "resources_needed" method for masked hardware
9723 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9725 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9728 /* Implement the "works_in_software_mode" method for masked hardware
9732 masked_watchpoint::works_in_software_mode () const
9737 /* Implement the "print_it" method for masked hardware
9740 enum print_stop_action
9741 masked_watchpoint::print_it (const bpstat
*bs
) const
9743 struct breakpoint
*b
= bs
->breakpoint_at
;
9744 struct ui_out
*uiout
= current_uiout
;
9746 /* Masked watchpoints have only one location. */
9747 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9749 annotate_watchpoint (b
->number
);
9750 maybe_print_thread_hit_breakpoint (uiout
);
9754 case bp_hardware_watchpoint
:
9755 if (uiout
->is_mi_like_p ())
9757 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9760 case bp_read_watchpoint
:
9761 if (uiout
->is_mi_like_p ())
9763 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9766 case bp_access_watchpoint
:
9767 if (uiout
->is_mi_like_p ())
9770 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9773 internal_error (__FILE__
, __LINE__
,
9774 _("Invalid hardware watchpoint type."));
9779 Check the underlying instruction at PC for the memory\n\
9780 address and value which triggered this watchpoint.\n"));
9783 /* More than one watchpoint may have been triggered. */
9784 return PRINT_UNKNOWN
;
9787 /* Implement the "print_one_detail" method for masked hardware
9791 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9793 /* Masked watchpoints have only one location. */
9794 gdb_assert (loc
&& loc
->next
== NULL
);
9796 uiout
->text ("\tmask ");
9797 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
9801 /* Implement the "print_mention" method for masked hardware
9805 masked_watchpoint::print_mention () const
9807 struct ui_out
*uiout
= current_uiout
;
9808 const char *tuple_name
;
9812 case bp_hardware_watchpoint
:
9813 uiout
->text ("Masked hardware watchpoint ");
9816 case bp_read_watchpoint
:
9817 uiout
->text ("Masked hardware read watchpoint ");
9818 tuple_name
= "hw-rwpt";
9820 case bp_access_watchpoint
:
9821 uiout
->text ("Masked hardware access (read/write) watchpoint ");
9822 tuple_name
= "hw-awpt";
9825 internal_error (__FILE__
, __LINE__
,
9826 _("Invalid hardware watchpoint type."));
9829 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9830 uiout
->field_signed ("number", number
);
9832 uiout
->field_string ("exp", exp_string
.get ());
9835 /* Implement the "print_recreate" method for masked hardware
9839 masked_watchpoint::print_recreate (struct ui_file
*fp
) const
9843 case bp_hardware_watchpoint
:
9844 gdb_printf (fp
, "watch");
9846 case bp_read_watchpoint
:
9847 gdb_printf (fp
, "rwatch");
9849 case bp_access_watchpoint
:
9850 gdb_printf (fp
, "awatch");
9853 internal_error (__FILE__
, __LINE__
,
9854 _("Invalid hardware watchpoint type."));
9857 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
9858 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
9859 print_recreate_thread (fp
);
9862 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9865 is_masked_watchpoint (const struct breakpoint
*b
)
9867 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
9870 /* accessflag: hw_write: watch write,
9871 hw_read: watch read,
9872 hw_access: watch access (read or write) */
9874 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
9875 bool just_location
, bool internal
)
9877 struct breakpoint
*scope_breakpoint
= NULL
;
9878 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9879 struct value
*result
;
9880 int saved_bitpos
= 0, saved_bitsize
= 0;
9881 const char *exp_start
= NULL
;
9882 const char *exp_end
= NULL
;
9883 const char *tok
, *end_tok
;
9885 const char *cond_start
= NULL
;
9886 const char *cond_end
= NULL
;
9887 enum bptype bp_type
;
9889 /* Flag to indicate whether we are going to use masks for
9890 the hardware watchpoint. */
9891 bool use_mask
= false;
9895 /* Make sure that we actually have parameters to parse. */
9896 if (arg
!= NULL
&& arg
[0] != '\0')
9898 const char *value_start
;
9900 exp_end
= arg
+ strlen (arg
);
9902 /* Look for "parameter value" pairs at the end
9903 of the arguments string. */
9904 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
9906 /* Skip whitespace at the end of the argument list. */
9907 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9910 /* Find the beginning of the last token.
9911 This is the value of the parameter. */
9912 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9914 value_start
= tok
+ 1;
9916 /* Skip whitespace. */
9917 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9922 /* Find the beginning of the second to last token.
9923 This is the parameter itself. */
9924 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9927 toklen
= end_tok
- tok
+ 1;
9929 if (toklen
== 6 && startswith (tok
, "thread"))
9931 struct thread_info
*thr
;
9932 /* At this point we've found a "thread" token, which means
9933 the user is trying to set a watchpoint that triggers
9934 only in a specific thread. */
9938 error(_("You can specify only one thread."));
9940 /* Extract the thread ID from the next token. */
9941 thr
= parse_thread_id (value_start
, &endp
);
9943 /* Check if the user provided a valid thread ID. */
9944 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9945 invalid_thread_id_error (value_start
);
9947 thread
= thr
->global_num
;
9949 else if (toklen
== 4 && startswith (tok
, "task"))
9953 task
= strtol (value_start
, &tmp
, 0);
9954 if (tmp
== value_start
)
9955 error (_("Junk after task keyword."));
9956 if (!valid_task_id (task
))
9957 error (_("Unknown task %d."), task
);
9959 else if (toklen
== 4 && startswith (tok
, "mask"))
9961 /* We've found a "mask" token, which means the user wants to
9962 create a hardware watchpoint that is going to have the mask
9964 struct value
*mask_value
, *mark
;
9967 error(_("You can specify only one mask."));
9969 use_mask
= just_location
= true;
9971 mark
= value_mark ();
9972 mask_value
= parse_to_comma_and_eval (&value_start
);
9973 mask
= value_as_address (mask_value
);
9974 value_free_to_mark (mark
);
9977 /* We didn't recognize what we found. We should stop here. */
9980 /* Truncate the string and get rid of the "parameter value" pair before
9981 the arguments string is parsed by the parse_exp_1 function. */
9988 /* Parse the rest of the arguments. From here on out, everything
9989 is in terms of a newly allocated string instead of the original
9991 std::string
expression (arg
, exp_end
- arg
);
9992 exp_start
= arg
= expression
.c_str ();
9993 innermost_block_tracker tracker
;
9994 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
9996 /* Remove trailing whitespace from the expression before saving it.
9997 This makes the eventual display of the expression string a bit
9999 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10002 /* Checking if the expression is not constant. */
10003 if (watchpoint_exp_is_const (exp
.get ()))
10007 len
= exp_end
- exp_start
;
10008 while (len
> 0 && isspace (exp_start
[len
- 1]))
10010 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10013 exp_valid_block
= tracker
.block ();
10014 struct value
*mark
= value_mark ();
10015 struct value
*val_as_value
= nullptr;
10016 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10019 if (val_as_value
!= NULL
&& just_location
)
10021 saved_bitpos
= value_bitpos (val_as_value
);
10022 saved_bitsize
= value_bitsize (val_as_value
);
10030 exp_valid_block
= NULL
;
10031 val
= release_value (value_addr (result
));
10032 value_free_to_mark (mark
);
10036 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10039 error (_("This target does not support masked watchpoints."));
10040 else if (ret
== -2)
10041 error (_("Invalid mask or memory region."));
10044 else if (val_as_value
!= NULL
)
10045 val
= release_value (val_as_value
);
10047 tok
= skip_spaces (arg
);
10048 end_tok
= skip_to_space (tok
);
10050 toklen
= end_tok
- tok
;
10051 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10053 tok
= cond_start
= end_tok
+ 1;
10054 innermost_block_tracker if_tracker
;
10055 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10057 /* The watchpoint expression may not be local, but the condition
10058 may still be. E.g.: `watch global if local > 0'. */
10059 cond_exp_valid_block
= if_tracker
.block ();
10064 error (_("Junk at end of command."));
10066 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10068 /* Save this because create_internal_breakpoint below invalidates
10070 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10072 /* If the expression is "local", then set up a "watchpoint scope"
10073 breakpoint at the point where we've left the scope of the watchpoint
10074 expression. Create the scope breakpoint before the watchpoint, so
10075 that we will encounter it first in bpstat_stop_status. */
10076 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10078 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10080 if (frame_id_p (caller_frame_id
))
10082 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10083 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10086 = create_internal_breakpoint (caller_arch
, caller_pc
,
10087 bp_watchpoint_scope
);
10089 /* create_internal_breakpoint could invalidate WP_FRAME. */
10092 scope_breakpoint
->enable_state
= bp_enabled
;
10094 /* Automatically delete the breakpoint when it hits. */
10095 scope_breakpoint
->disposition
= disp_del
;
10097 /* Only break in the proper frame (help with recursion). */
10098 scope_breakpoint
->frame_id
= caller_frame_id
;
10100 /* Set the address at which we will stop. */
10101 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10102 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10103 scope_breakpoint
->loc
->address
10104 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10105 scope_breakpoint
->loc
->requested_address
,
10106 scope_breakpoint
->type
,
10107 current_program_space
);
10111 /* Now set up the breakpoint. We create all watchpoints as hardware
10112 watchpoints here even if hardware watchpoints are turned off, a call
10113 to update_watchpoint later in this function will cause the type to
10114 drop back to bp_watchpoint (software watchpoint) if required. */
10116 if (accessflag
== hw_read
)
10117 bp_type
= bp_read_watchpoint
;
10118 else if (accessflag
== hw_access
)
10119 bp_type
= bp_access_watchpoint
;
10121 bp_type
= bp_hardware_watchpoint
;
10123 std::unique_ptr
<watchpoint
> w
;
10125 w
.reset (new masked_watchpoint (nullptr, bp_type
));
10127 w
.reset (new watchpoint (nullptr, bp_type
));
10129 w
->thread
= thread
;
10131 w
->disposition
= disp_donttouch
;
10132 w
->pspace
= current_program_space
;
10133 w
->exp
= std::move (exp
);
10134 w
->exp_valid_block
= exp_valid_block
;
10135 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10138 struct type
*t
= value_type (val
.get ());
10139 CORE_ADDR addr
= value_as_address (val
.get ());
10141 w
->exp_string_reparse
10142 = current_language
->watch_location_expression (t
, addr
);
10144 w
->exp_string
= xstrprintf ("-location %.*s",
10145 (int) (exp_end
- exp_start
), exp_start
);
10148 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10152 w
->hw_wp_mask
= mask
;
10157 w
->val_bitpos
= saved_bitpos
;
10158 w
->val_bitsize
= saved_bitsize
;
10159 w
->val_valid
= true;
10163 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10165 w
->cond_string
= 0;
10167 if (frame_id_p (watchpoint_frame
))
10169 w
->watchpoint_frame
= watchpoint_frame
;
10170 w
->watchpoint_thread
= inferior_ptid
;
10174 w
->watchpoint_frame
= null_frame_id
;
10175 w
->watchpoint_thread
= null_ptid
;
10178 if (scope_breakpoint
!= NULL
)
10180 /* The scope breakpoint is related to the watchpoint. We will
10181 need to act on them together. */
10182 w
->related_breakpoint
= scope_breakpoint
;
10183 scope_breakpoint
->related_breakpoint
= w
.get ();
10186 if (!just_location
)
10187 value_free_to_mark (mark
);
10189 /* Finally update the new watchpoint. This creates the locations
10190 that should be inserted. */
10191 update_watchpoint (w
.get (), 1);
10193 install_breakpoint (internal
, std::move (w
), 1);
10196 /* Return count of debug registers needed to watch the given expression.
10197 If the watchpoint cannot be handled in hardware return zero. */
10200 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10202 int found_memory_cnt
= 0;
10204 /* Did the user specifically forbid us to use hardware watchpoints? */
10205 if (!can_use_hw_watchpoints
)
10208 gdb_assert (!vals
.empty ());
10209 struct value
*head
= vals
[0].get ();
10211 /* Make sure that the value of the expression depends only upon
10212 memory contents, and values computed from them within GDB. If we
10213 find any register references or function calls, we can't use a
10214 hardware watchpoint.
10216 The idea here is that evaluating an expression generates a series
10217 of values, one holding the value of every subexpression. (The
10218 expression a*b+c has five subexpressions: a, b, a*b, c, and
10219 a*b+c.) GDB's values hold almost enough information to establish
10220 the criteria given above --- they identify memory lvalues,
10221 register lvalues, computed values, etcetera. So we can evaluate
10222 the expression, and then scan the chain of values that leaves
10223 behind to decide whether we can detect any possible change to the
10224 expression's final value using only hardware watchpoints.
10226 However, I don't think that the values returned by inferior
10227 function calls are special in any way. So this function may not
10228 notice that an expression involving an inferior function call
10229 can't be watched with hardware watchpoints. FIXME. */
10230 for (const value_ref_ptr
&iter
: vals
)
10232 struct value
*v
= iter
.get ();
10234 if (VALUE_LVAL (v
) == lval_memory
)
10236 if (v
!= head
&& value_lazy (v
))
10237 /* A lazy memory lvalue in the chain is one that GDB never
10238 needed to fetch; we either just used its address (e.g.,
10239 `a' in `a.b') or we never needed it at all (e.g., `a'
10240 in `a,b'). This doesn't apply to HEAD; if that is
10241 lazy then it was not readable, but watch it anyway. */
10245 /* Ahh, memory we actually used! Check if we can cover
10246 it with hardware watchpoints. */
10247 struct type
*vtype
= check_typedef (value_type (v
));
10249 /* We only watch structs and arrays if user asked for it
10250 explicitly, never if they just happen to appear in a
10251 middle of some value chain. */
10253 || (vtype
->code () != TYPE_CODE_STRUCT
10254 && vtype
->code () != TYPE_CODE_ARRAY
))
10256 CORE_ADDR vaddr
= value_address (v
);
10260 len
= (target_exact_watchpoints
10261 && is_scalar_type_recursive (vtype
))?
10262 1 : TYPE_LENGTH (value_type (v
));
10264 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10268 found_memory_cnt
+= num_regs
;
10272 else if (VALUE_LVAL (v
) != not_lval
10273 && deprecated_value_modifiable (v
) == 0)
10274 return 0; /* These are values from the history (e.g., $1). */
10275 else if (VALUE_LVAL (v
) == lval_register
)
10276 return 0; /* Cannot watch a register with a HW watchpoint. */
10279 /* The expression itself looks suitable for using a hardware
10280 watchpoint, but give the target machine a chance to reject it. */
10281 return found_memory_cnt
;
10285 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10287 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10290 /* Options for the watch, awatch, and rwatch commands. */
10292 struct watch_options
10294 /* For -location. */
10295 bool location
= false;
10298 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10300 Historically GDB always accepted both '-location' and '-l' flags for
10301 these commands (both flags being synonyms). When converting to the
10302 newer option scheme only '-location' is added here. That's fine (for
10303 backward compatibility) as any non-ambiguous prefix of a flag will be
10304 accepted, so '-l', '-loc', are now all accepted.
10306 What this means is that, if in the future, we add any new flag here
10307 that starts with '-l' then this will break backward compatibility, so
10308 please, don't do that! */
10310 static const gdb::option::option_def watch_option_defs
[] = {
10311 gdb::option::flag_option_def
<watch_options
> {
10313 [] (watch_options
*opt
) { return &opt
->location
; },
10315 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10316 -l can be used as a short form of -location."),
10320 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10323 static gdb::option::option_def_group
10324 make_watch_options_def_group (watch_options
*opts
)
10326 return {{watch_option_defs
}, opts
};
10329 /* A helper function that looks for the "-location" argument and then
10330 calls watch_command_1. */
10333 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10335 watch_options opts
;
10336 auto grp
= make_watch_options_def_group (&opts
);
10337 gdb::option::process_options
10338 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10339 if (arg
!= nullptr && *arg
== '\0')
10342 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10345 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10347 watch_command_completer (struct cmd_list_element
*ignore
,
10348 completion_tracker
&tracker
,
10349 const char *text
, const char * /*word*/)
10351 const auto group
= make_watch_options_def_group (nullptr);
10352 if (gdb::option::complete_options
10353 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10356 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10357 expression_completer (ignore
, tracker
, text
, word
);
10361 watch_command (const char *arg
, int from_tty
)
10363 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10367 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10369 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10373 rwatch_command (const char *arg
, int from_tty
)
10375 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10379 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10381 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10385 awatch_command (const char *arg
, int from_tty
)
10387 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10391 /* Data for the FSM that manages the until(location)/advance commands
10392 in infcmd.c. Here because it uses the mechanisms of
10395 struct until_break_fsm
: public thread_fsm
10397 /* The thread that was current when the command was executed. */
10400 /* The breakpoint set at the return address in the caller frame,
10401 plus breakpoints at all the destination locations. */
10402 std::vector
<breakpoint_up
> breakpoints
;
10404 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10405 std::vector
<breakpoint_up
> &&breakpoints
)
10406 : thread_fsm (cmd_interp
),
10408 breakpoints (std::move (breakpoints
))
10412 void clean_up (struct thread_info
*thread
) override
;
10413 bool should_stop (struct thread_info
*thread
) override
;
10414 enum async_reply_reason
do_async_reply_reason () override
;
10417 /* Implementation of the 'should_stop' FSM method for the
10418 until(location)/advance commands. */
10421 until_break_fsm::should_stop (struct thread_info
*tp
)
10423 for (const breakpoint_up
&bp
: breakpoints
)
10424 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10425 bp
.get ()) != NULL
)
10434 /* Implementation of the 'clean_up' FSM method for the
10435 until(location)/advance commands. */
10438 until_break_fsm::clean_up (struct thread_info
*)
10440 /* Clean up our temporary breakpoints. */
10441 breakpoints
.clear ();
10442 delete_longjmp_breakpoint (thread
);
10445 /* Implementation of the 'async_reply_reason' FSM method for the
10446 until(location)/advance commands. */
10448 enum async_reply_reason
10449 until_break_fsm::do_async_reply_reason ()
10451 return EXEC_ASYNC_LOCATION_REACHED
;
10455 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10457 struct frame_info
*frame
;
10458 struct gdbarch
*frame_gdbarch
;
10459 struct frame_id stack_frame_id
;
10460 struct frame_id caller_frame_id
;
10462 struct thread_info
*tp
;
10464 clear_proceed_status (0);
10466 /* Set a breakpoint where the user wants it and at return from
10469 location_spec_up locspec
= string_to_location_spec (&arg
, current_language
);
10471 std::vector
<symtab_and_line
> sals
10472 = (last_displayed_sal_is_valid ()
10473 ? decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10474 get_last_displayed_symtab (),
10475 get_last_displayed_line ())
10476 : decode_line_1 (locspec
.get (), DECODE_LINE_FUNFIRSTLINE
,
10480 error (_("Couldn't get information on specified line."));
10483 error (_("Junk at end of arguments."));
10485 tp
= inferior_thread ();
10486 thread
= tp
->global_num
;
10488 /* Note linespec handling above invalidates the frame chain.
10489 Installing a breakpoint also invalidates the frame chain (as it
10490 may need to switch threads), so do any frame handling before
10493 frame
= get_selected_frame (NULL
);
10494 frame_gdbarch
= get_frame_arch (frame
);
10495 stack_frame_id
= get_stack_frame_id (frame
);
10496 caller_frame_id
= frame_unwind_caller_id (frame
);
10498 /* Keep within the current frame, or in frames called by the current
10501 std::vector
<breakpoint_up
> breakpoints
;
10503 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10505 if (frame_id_p (caller_frame_id
))
10507 struct symtab_and_line sal2
;
10508 struct gdbarch
*caller_gdbarch
;
10510 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10511 sal2
.pc
= frame_unwind_caller_pc (frame
);
10512 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10514 breakpoint_up caller_breakpoint
10515 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10516 caller_frame_id
, bp_until
);
10517 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10519 set_longjmp_breakpoint (tp
, stack_frame_id
);
10520 lj_deleter
.emplace (thread
);
10523 /* set_momentary_breakpoint could invalidate FRAME. */
10526 /* If the user told us to continue until a specified location, we
10527 don't specify a frame at which we need to stop. Otherwise,
10528 specify the selected frame, because we want to stop only at the
10529 very same frame. */
10530 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10532 for (symtab_and_line
&sal
: sals
)
10534 resolve_sal_pc (&sal
);
10536 breakpoint_up location_breakpoint
10537 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10538 stop_frame_id
, bp_until
);
10539 breakpoints
.emplace_back (std::move (location_breakpoint
));
10543 (std::unique_ptr
<thread_fsm
>
10544 (new until_break_fsm (command_interp (), tp
->global_num
,
10545 std::move (breakpoints
))));
10548 lj_deleter
->release ();
10550 proceed (-1, GDB_SIGNAL_DEFAULT
);
10555 /* Compare two breakpoints and return a strcmp-like result. */
10558 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10560 uintptr_t ua
= (uintptr_t) a
;
10561 uintptr_t ub
= (uintptr_t) b
;
10563 if (a
->number
< b
->number
)
10565 else if (a
->number
> b
->number
)
10568 /* Now sort by address, in case we see, e..g, two breakpoints with
10572 return ua
> ub
? 1 : 0;
10575 /* Delete breakpoints by address or line. */
10578 clear_command (const char *arg
, int from_tty
)
10582 std::vector
<symtab_and_line
> decoded_sals
;
10583 symtab_and_line last_sal
;
10584 gdb::array_view
<symtab_and_line
> sals
;
10588 = decode_line_with_current_source (arg
,
10589 (DECODE_LINE_FUNFIRSTLINE
10590 | DECODE_LINE_LIST_MODE
));
10592 sals
= decoded_sals
;
10596 /* Set sal's line, symtab, pc, and pspace to the values
10597 corresponding to the last call to print_frame_info. If the
10598 codepoint is not valid, this will set all the fields to 0. */
10599 last_sal
= get_last_displayed_sal ();
10600 if (last_sal
.symtab
== 0)
10601 error (_("No source file specified."));
10607 /* We don't call resolve_sal_pc here. That's not as bad as it
10608 seems, because all existing breakpoints typically have both
10609 file/line and pc set. So, if clear is given file/line, we can
10610 match this to existing breakpoint without obtaining pc at all.
10612 We only support clearing given the address explicitly
10613 present in breakpoint table. Say, we've set breakpoint
10614 at file:line. There were several PC values for that file:line,
10615 due to optimization, all in one block.
10617 We've picked one PC value. If "clear" is issued with another
10618 PC corresponding to the same file:line, the breakpoint won't
10619 be cleared. We probably can still clear the breakpoint, but
10620 since the other PC value is never presented to user, user
10621 can only find it by guessing, and it does not seem important
10622 to support that. */
10624 /* For each line spec given, delete bps which correspond to it. Do
10625 it in two passes, solely to preserve the current behavior that
10626 from_tty is forced true if we delete more than one
10629 std::vector
<struct breakpoint
*> found
;
10630 for (const auto &sal
: sals
)
10632 const char *sal_fullname
;
10634 /* If exact pc given, clear bpts at that pc.
10635 If line given (pc == 0), clear all bpts on specified line.
10636 If defaulting, clear all bpts on default line
10639 defaulting sal.pc != 0 tests to do
10644 1 0 <can't happen> */
10646 sal_fullname
= (sal
.symtab
== NULL
10647 ? NULL
: symtab_to_fullname (sal
.symtab
));
10649 /* Find all matching breakpoints and add them to 'found'. */
10650 for (breakpoint
*b
: all_breakpoints ())
10653 /* Are we going to delete b? */
10654 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10655 && user_breakpoint_p (b
))
10657 for (bp_location
*loc
: b
->locations ())
10659 /* If the user specified file:line, don't allow a PC
10660 match. This matches historical gdb behavior. */
10661 int pc_match
= (!sal
.explicit_line
10663 && (loc
->pspace
== sal
.pspace
)
10664 && (loc
->address
== sal
.pc
)
10665 && (!section_is_overlay (loc
->section
)
10666 || loc
->section
== sal
.section
));
10667 int line_match
= 0;
10669 if ((default_match
|| sal
.explicit_line
)
10670 && loc
->symtab
!= NULL
10671 && sal_fullname
!= NULL
10672 && sal
.pspace
== loc
->pspace
10673 && loc
->line_number
== sal
.line
10674 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10675 sal_fullname
) == 0)
10678 if (pc_match
|| line_match
)
10687 found
.push_back (b
);
10691 /* Now go thru the 'found' chain and delete them. */
10692 if (found
.empty ())
10695 error (_("No breakpoint at %s."), arg
);
10697 error (_("No breakpoint at this line."));
10700 /* Remove duplicates from the vec. */
10701 std::sort (found
.begin (), found
.end (),
10702 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10704 return compare_breakpoints (bp_a
, bp_b
) < 0;
10706 found
.erase (std::unique (found
.begin (), found
.end (),
10707 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10709 return compare_breakpoints (bp_a
, bp_b
) == 0;
10713 if (found
.size () > 1)
10714 from_tty
= 1; /* Always report if deleted more than one. */
10717 if (found
.size () == 1)
10718 gdb_printf (_("Deleted breakpoint "));
10720 gdb_printf (_("Deleted breakpoints "));
10723 for (breakpoint
*iter
: found
)
10726 gdb_printf ("%d ", iter
->number
);
10727 delete_breakpoint (iter
);
10733 /* Delete breakpoint in BS if they are `delete' breakpoints and
10734 all breakpoints that are marked for deletion, whether hit or not.
10735 This is called after any breakpoint is hit, or after errors. */
10738 breakpoint_auto_delete (bpstat
*bs
)
10740 for (; bs
; bs
= bs
->next
)
10741 if (bs
->breakpoint_at
10742 && bs
->breakpoint_at
->disposition
== disp_del
10744 delete_breakpoint (bs
->breakpoint_at
);
10746 for (breakpoint
*b
: all_breakpoints_safe ())
10747 if (b
->disposition
== disp_del_at_next_stop
)
10748 delete_breakpoint (b
);
10751 /* A comparison function for bp_location AP and BP being interfaced to
10752 std::sort. Sort elements primarily by their ADDRESS (no matter what
10753 bl_address_is_meaningful says), secondarily by ordering first
10754 permanent elements and terciarily just ensuring the array is sorted
10755 stable way despite std::sort being an unstable algorithm. */
10758 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10760 if (a
->address
!= b
->address
)
10761 return a
->address
< b
->address
;
10763 /* Sort locations at the same address by their pspace number, keeping
10764 locations of the same inferior (in a multi-inferior environment)
10767 if (a
->pspace
->num
!= b
->pspace
->num
)
10768 return a
->pspace
->num
< b
->pspace
->num
;
10770 /* Sort permanent breakpoints first. */
10771 if (a
->permanent
!= b
->permanent
)
10772 return a
->permanent
> b
->permanent
;
10774 /* Sort by type in order to make duplicate determination easier.
10775 See update_global_location_list. This is kept in sync with
10776 breakpoint_locations_match. */
10777 if (a
->loc_type
< b
->loc_type
)
10780 /* Likewise, for range-breakpoints, sort by length. */
10781 if (a
->loc_type
== bp_loc_hardware_breakpoint
10782 && b
->loc_type
== bp_loc_hardware_breakpoint
10783 && a
->length
< b
->length
)
10786 /* Make the internal GDB representation stable across GDB runs
10787 where A and B memory inside GDB can differ. Breakpoint locations of
10788 the same type at the same address can be sorted in arbitrary order. */
10790 if (a
->owner
->number
!= b
->owner
->number
)
10791 return a
->owner
->number
< b
->owner
->number
;
10796 /* Set bp_locations_placed_address_before_address_max and
10797 bp_locations_shadow_len_after_address_max according to the current
10798 content of the bp_locations array. */
10801 bp_locations_target_extensions_update (void)
10803 bp_locations_placed_address_before_address_max
= 0;
10804 bp_locations_shadow_len_after_address_max
= 0;
10806 for (bp_location
*bl
: all_bp_locations ())
10808 CORE_ADDR start
, end
, addr
;
10810 if (!bp_location_has_shadow (bl
))
10813 start
= bl
->target_info
.placed_address
;
10814 end
= start
+ bl
->target_info
.shadow_len
;
10816 gdb_assert (bl
->address
>= start
);
10817 addr
= bl
->address
- start
;
10818 if (addr
> bp_locations_placed_address_before_address_max
)
10819 bp_locations_placed_address_before_address_max
= addr
;
10821 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10823 gdb_assert (bl
->address
< end
);
10824 addr
= end
- bl
->address
;
10825 if (addr
> bp_locations_shadow_len_after_address_max
)
10826 bp_locations_shadow_len_after_address_max
= addr
;
10830 /* Download tracepoint locations if they haven't been. */
10833 download_tracepoint_locations (void)
10835 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
10837 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
10839 for (breakpoint
*b
: all_tracepoints ())
10841 struct tracepoint
*t
;
10842 int bp_location_downloaded
= 0;
10844 if ((b
->type
== bp_fast_tracepoint
10845 ? !may_insert_fast_tracepoints
10846 : !may_insert_tracepoints
))
10849 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
10851 if (target_can_download_tracepoint ())
10852 can_download_tracepoint
= TRIBOOL_TRUE
;
10854 can_download_tracepoint
= TRIBOOL_FALSE
;
10857 if (can_download_tracepoint
== TRIBOOL_FALSE
)
10860 for (bp_location
*bl
: b
->locations ())
10862 /* In tracepoint, locations are _never_ duplicated, so
10863 should_be_inserted is equivalent to
10864 unduplicated_should_be_inserted. */
10865 if (!should_be_inserted (bl
) || bl
->inserted
)
10868 switch_to_program_space_and_thread (bl
->pspace
);
10870 target_download_tracepoint (bl
);
10873 bp_location_downloaded
= 1;
10875 t
= (struct tracepoint
*) b
;
10876 t
->number_on_target
= b
->number
;
10877 if (bp_location_downloaded
)
10878 gdb::observers::breakpoint_modified
.notify (b
);
10882 /* Swap the insertion/duplication state between two locations. */
10885 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10887 const int left_inserted
= left
->inserted
;
10888 const int left_duplicate
= left
->duplicate
;
10889 const int left_needs_update
= left
->needs_update
;
10890 const struct bp_target_info left_target_info
= left
->target_info
;
10892 /* Locations of tracepoints can never be duplicated. */
10893 if (is_tracepoint (left
->owner
))
10894 gdb_assert (!left
->duplicate
);
10895 if (is_tracepoint (right
->owner
))
10896 gdb_assert (!right
->duplicate
);
10898 left
->inserted
= right
->inserted
;
10899 left
->duplicate
= right
->duplicate
;
10900 left
->needs_update
= right
->needs_update
;
10901 left
->target_info
= right
->target_info
;
10902 right
->inserted
= left_inserted
;
10903 right
->duplicate
= left_duplicate
;
10904 right
->needs_update
= left_needs_update
;
10905 right
->target_info
= left_target_info
;
10908 /* Force the re-insertion of the locations at ADDRESS. This is called
10909 once a new/deleted/modified duplicate location is found and we are evaluating
10910 conditions on the target's side. Such conditions need to be updated on
10914 force_breakpoint_reinsertion (struct bp_location
*bl
)
10916 CORE_ADDR address
= 0;
10919 address
= bl
->address
;
10920 pspace_num
= bl
->pspace
->num
;
10922 /* This is only meaningful if the target is
10923 evaluating conditions and if the user has
10924 opted for condition evaluation on the target's
10926 if (gdb_evaluates_breakpoint_condition_p ()
10927 || !target_supports_evaluation_of_breakpoint_conditions ())
10930 /* Flag all breakpoint locations with this address and
10931 the same program space as the location
10932 as "its condition has changed". We need to
10933 update the conditions on the target's side. */
10934 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
10936 if (!is_breakpoint (loc
->owner
)
10937 || pspace_num
!= loc
->pspace
->num
)
10940 /* Flag the location appropriately. We use a different state to
10941 let everyone know that we already updated the set of locations
10942 with addr bl->address and program space bl->pspace. This is so
10943 we don't have to keep calling these functions just to mark locations
10944 that have already been marked. */
10945 loc
->condition_changed
= condition_updated
;
10947 /* Free the agent expression bytecode as well. We will compute
10949 loc
->cond_bytecode
.reset ();
10953 /* Called whether new breakpoints are created, or existing breakpoints
10954 deleted, to update the global location list and recompute which
10955 locations are duplicate of which.
10957 The INSERT_MODE flag determines whether locations may not, may, or
10958 shall be inserted now. See 'enum ugll_insert_mode' for more
10962 update_global_location_list (enum ugll_insert_mode insert_mode
)
10964 /* Last breakpoint location address that was marked for update. */
10965 CORE_ADDR last_addr
= 0;
10966 /* Last breakpoint location program space that was marked for update. */
10967 int last_pspace_num
= -1;
10969 /* Used in the duplicates detection below. When iterating over all
10970 bp_locations, points to the first bp_location of a given address.
10971 Breakpoints and watchpoints of different types are never
10972 duplicates of each other. Keep one pointer for each type of
10973 breakpoint/watchpoint, so we only need to loop over all locations
10975 struct bp_location
*bp_loc_first
; /* breakpoint */
10976 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10977 struct bp_location
*awp_loc_first
; /* access watchpoint */
10978 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10980 /* Saved former bp_locations array which we compare against the newly
10981 built bp_locations from the current state of ALL_BREAKPOINTS. */
10982 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
10983 bp_locations
.clear ();
10985 for (breakpoint
*b
: all_breakpoints ())
10986 for (bp_location
*loc
: b
->locations ())
10987 bp_locations
.push_back (loc
);
10989 /* See if we need to "upgrade" a software breakpoint to a hardware
10990 breakpoint. Do this before deciding whether locations are
10991 duplicates. Also do this before sorting because sorting order
10992 depends on location type. */
10993 for (bp_location
*loc
: bp_locations
)
10994 if (!loc
->inserted
&& should_be_inserted (loc
))
10995 handle_automatic_hardware_breakpoints (loc
);
10997 std::sort (bp_locations
.begin (), bp_locations
.end (),
10998 bp_location_is_less_than
);
11000 bp_locations_target_extensions_update ();
11002 /* Identify bp_location instances that are no longer present in the
11003 new list, and therefore should be freed. Note that it's not
11004 necessary that those locations should be removed from inferior --
11005 if there's another location at the same address (previously
11006 marked as duplicate), we don't need to remove/insert the
11009 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11010 and former bp_location array state respectively. */
11013 for (bp_location
*old_loc
: old_locations
)
11015 /* Tells if 'old_loc' is found among the new locations. If
11016 not, we have to free it. */
11017 int found_object
= 0;
11018 /* Tells if the location should remain inserted in the target. */
11019 int keep_in_target
= 0;
11022 /* Skip LOCP entries which will definitely never be needed.
11023 Stop either at or being the one matching OLD_LOC. */
11024 while (loc_i
< bp_locations
.size ()
11025 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11028 for (size_t loc2_i
= loc_i
;
11029 (loc2_i
< bp_locations
.size ()
11030 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11033 /* Check if this is a new/duplicated location or a duplicated
11034 location that had its condition modified. If so, we want to send
11035 its condition to the target if evaluation of conditions is taking
11037 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11038 && (last_addr
!= old_loc
->address
11039 || last_pspace_num
!= old_loc
->pspace
->num
))
11041 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11042 last_pspace_num
= old_loc
->pspace
->num
;
11045 if (bp_locations
[loc2_i
] == old_loc
)
11049 /* We have already handled this address, update it so that we don't
11050 have to go through updates again. */
11051 last_addr
= old_loc
->address
;
11053 /* Target-side condition evaluation: Handle deleted locations. */
11055 force_breakpoint_reinsertion (old_loc
);
11057 /* If this location is no longer present, and inserted, look if
11058 there's maybe a new location at the same address. If so,
11059 mark that one inserted, and don't remove this one. This is
11060 needed so that we don't have a time window where a breakpoint
11061 at certain location is not inserted. */
11063 if (old_loc
->inserted
)
11065 /* If the location is inserted now, we might have to remove
11068 if (found_object
&& should_be_inserted (old_loc
))
11070 /* The location is still present in the location list,
11071 and still should be inserted. Don't do anything. */
11072 keep_in_target
= 1;
11076 /* This location still exists, but it won't be kept in the
11077 target since it may have been disabled. We proceed to
11078 remove its target-side condition. */
11080 /* The location is either no longer present, or got
11081 disabled. See if there's another location at the
11082 same address, in which case we don't need to remove
11083 this one from the target. */
11085 /* OLD_LOC comes from existing struct breakpoint. */
11086 if (bl_address_is_meaningful (old_loc
))
11088 for (size_t loc2_i
= loc_i
;
11089 (loc2_i
< bp_locations
.size ()
11090 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11093 bp_location
*loc2
= bp_locations
[loc2_i
];
11095 if (loc2
== old_loc
)
11098 if (breakpoint_locations_match (loc2
, old_loc
))
11100 /* Read watchpoint locations are switched to
11101 access watchpoints, if the former are not
11102 supported, but the latter are. */
11103 if (is_hardware_watchpoint (old_loc
->owner
))
11105 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11106 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11109 /* loc2 is a duplicated location. We need to check
11110 if it should be inserted in case it will be
11112 if (unduplicated_should_be_inserted (loc2
))
11114 swap_insertion (old_loc
, loc2
);
11115 keep_in_target
= 1;
11123 if (!keep_in_target
)
11125 if (remove_breakpoint (old_loc
))
11127 /* This is just about all we can do. We could keep
11128 this location on the global list, and try to
11129 remove it next time, but there's no particular
11130 reason why we will succeed next time.
11132 Note that at this point, old_loc->owner is still
11133 valid, as delete_breakpoint frees the breakpoint
11134 only after calling us. */
11135 gdb_printf (_("warning: Error removing "
11136 "breakpoint %d\n"),
11137 old_loc
->owner
->number
);
11145 if (removed
&& target_is_non_stop_p ()
11146 && need_moribund_for_location_type (old_loc
))
11148 /* This location was removed from the target. In
11149 non-stop mode, a race condition is possible where
11150 we've removed a breakpoint, but stop events for that
11151 breakpoint are already queued and will arrive later.
11152 We apply an heuristic to be able to distinguish such
11153 SIGTRAPs from other random SIGTRAPs: we keep this
11154 breakpoint location for a bit, and will retire it
11155 after we see some number of events. The theory here
11156 is that reporting of events should, "on the average",
11157 be fair, so after a while we'll see events from all
11158 threads that have anything of interest, and no longer
11159 need to keep this breakpoint location around. We
11160 don't hold locations forever so to reduce chances of
11161 mistaking a non-breakpoint SIGTRAP for a breakpoint
11164 The heuristic failing can be disastrous on
11165 decr_pc_after_break targets.
11167 On decr_pc_after_break targets, like e.g., x86-linux,
11168 if we fail to recognize a late breakpoint SIGTRAP,
11169 because events_till_retirement has reached 0 too
11170 soon, we'll fail to do the PC adjustment, and report
11171 a random SIGTRAP to the user. When the user resumes
11172 the inferior, it will most likely immediately crash
11173 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11174 corrupted, because of being resumed e.g., in the
11175 middle of a multi-byte instruction, or skipped a
11176 one-byte instruction. This was actually seen happen
11177 on native x86-linux, and should be less rare on
11178 targets that do not support new thread events, like
11179 remote, due to the heuristic depending on
11182 Mistaking a random SIGTRAP for a breakpoint trap
11183 causes similar symptoms (PC adjustment applied when
11184 it shouldn't), but then again, playing with SIGTRAPs
11185 behind the debugger's back is asking for trouble.
11187 Since hardware watchpoint traps are always
11188 distinguishable from other traps, so we don't need to
11189 apply keep hardware watchpoint moribund locations
11190 around. We simply always ignore hardware watchpoint
11191 traps we can no longer explain. */
11193 process_stratum_target
*proc_target
= nullptr;
11194 for (inferior
*inf
: all_inferiors ())
11195 if (inf
->pspace
== old_loc
->pspace
)
11197 proc_target
= inf
->process_target ();
11200 if (proc_target
!= nullptr)
11201 old_loc
->events_till_retirement
11202 = 3 * (thread_count (proc_target
) + 1);
11204 old_loc
->events_till_retirement
= 1;
11205 old_loc
->owner
= NULL
;
11207 moribund_locations
.push_back (old_loc
);
11211 old_loc
->owner
= NULL
;
11212 decref_bp_location (&old_loc
);
11217 /* Rescan breakpoints at the same address and section, marking the
11218 first one as "first" and any others as "duplicates". This is so
11219 that the bpt instruction is only inserted once. If we have a
11220 permanent breakpoint at the same place as BPT, make that one the
11221 official one, and the rest as duplicates. Permanent breakpoints
11222 are sorted first for the same address.
11224 Do the same for hardware watchpoints, but also considering the
11225 watchpoint's type (regular/access/read) and length. */
11227 bp_loc_first
= NULL
;
11228 wp_loc_first
= NULL
;
11229 awp_loc_first
= NULL
;
11230 rwp_loc_first
= NULL
;
11232 for (bp_location
*loc
: all_bp_locations ())
11234 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11236 struct bp_location
**loc_first_p
;
11237 breakpoint
*b
= loc
->owner
;
11239 if (!unduplicated_should_be_inserted (loc
)
11240 || !bl_address_is_meaningful (loc
)
11241 /* Don't detect duplicate for tracepoint locations because they are
11242 never duplicated. See the comments in field `duplicate' of
11243 `struct bp_location'. */
11244 || is_tracepoint (b
))
11246 /* Clear the condition modification flag. */
11247 loc
->condition_changed
= condition_unchanged
;
11251 if (b
->type
== bp_hardware_watchpoint
)
11252 loc_first_p
= &wp_loc_first
;
11253 else if (b
->type
== bp_read_watchpoint
)
11254 loc_first_p
= &rwp_loc_first
;
11255 else if (b
->type
== bp_access_watchpoint
)
11256 loc_first_p
= &awp_loc_first
;
11258 loc_first_p
= &bp_loc_first
;
11260 if (*loc_first_p
== NULL
11261 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11262 || !breakpoint_locations_match (loc
, *loc_first_p
))
11264 *loc_first_p
= loc
;
11265 loc
->duplicate
= 0;
11267 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11269 loc
->needs_update
= 1;
11270 /* Clear the condition modification flag. */
11271 loc
->condition_changed
= condition_unchanged
;
11277 /* This and the above ensure the invariant that the first location
11278 is not duplicated, and is the inserted one.
11279 All following are marked as duplicated, and are not inserted. */
11281 swap_insertion (loc
, *loc_first_p
);
11282 loc
->duplicate
= 1;
11284 /* Clear the condition modification flag. */
11285 loc
->condition_changed
= condition_unchanged
;
11288 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11290 if (insert_mode
!= UGLL_DONT_INSERT
)
11291 insert_breakpoint_locations ();
11294 /* Even though the caller told us to not insert new
11295 locations, we may still need to update conditions on the
11296 target's side of breakpoints that were already inserted
11297 if the target is evaluating breakpoint conditions. We
11298 only update conditions for locations that are marked
11300 update_inserted_breakpoint_locations ();
11304 if (insert_mode
!= UGLL_DONT_INSERT
)
11305 download_tracepoint_locations ();
11309 breakpoint_retire_moribund (void)
11311 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11313 struct bp_location
*loc
= moribund_locations
[ix
];
11314 if (--(loc
->events_till_retirement
) == 0)
11316 decref_bp_location (&loc
);
11317 unordered_remove (moribund_locations
, ix
);
11324 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11329 update_global_location_list (insert_mode
);
11331 catch (const gdb_exception_error
&e
)
11336 /* Clear BKP from a BPS. */
11339 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11343 for (bs
= bps
; bs
; bs
= bs
->next
)
11344 if (bs
->breakpoint_at
== bpt
)
11346 bs
->breakpoint_at
= NULL
;
11347 bs
->old_val
= NULL
;
11348 /* bs->commands will be freed later. */
11352 /* Callback for iterate_over_threads. */
11354 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11356 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11358 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11362 /* Helper for breakpoint and tracepoint breakpoint->mention
11366 say_where (const breakpoint
*b
)
11368 struct value_print_options opts
;
11370 get_user_print_options (&opts
);
11372 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11374 if (b
->loc
== NULL
)
11376 /* For pending locations, the output differs slightly based
11377 on b->extra_string. If this is non-NULL, it contains either
11378 a condition or dprintf arguments. */
11379 if (b
->extra_string
== NULL
)
11381 gdb_printf (_(" (%s) pending."), b
->locspec
->to_string ());
11383 else if (b
->type
== bp_dprintf
)
11385 gdb_printf (_(" (%s,%s) pending."),
11386 b
->locspec
->to_string (),
11387 b
->extra_string
.get ());
11391 gdb_printf (_(" (%s %s) pending."),
11392 b
->locspec
->to_string (),
11393 b
->extra_string
.get ());
11398 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
11399 gdb_printf (" at %ps",
11400 styled_string (address_style
.style (),
11401 paddress (b
->loc
->gdbarch
,
11402 b
->loc
->address
)));
11403 if (b
->loc
->symtab
!= NULL
)
11405 /* If there is a single location, we can print the location
11407 if (b
->loc
->next
== NULL
)
11409 const char *filename
11410 = symtab_to_filename_for_display (b
->loc
->symtab
);
11411 gdb_printf (": file %ps, line %d.",
11412 styled_string (file_name_style
.style (),
11414 b
->loc
->line_number
);
11417 /* This is not ideal, but each location may have a
11418 different file name, and this at least reflects the
11419 real situation somewhat. */
11420 gdb_printf (": %s.", b
->locspec
->to_string ());
11425 struct bp_location
*loc
= b
->loc
;
11427 for (; loc
; loc
= loc
->next
)
11429 gdb_printf (" (%d locations)", n
);
11434 /* See breakpoint.h. */
11436 bp_location_range
breakpoint::locations () const
11438 return bp_location_range (this->loc
);
11441 struct bp_location
*
11442 breakpoint::allocate_location ()
11444 return new bp_location (this);
11447 #define internal_error_pure_virtual_called() \
11448 gdb_assert_not_reached ("pure virtual function called")
11451 breakpoint::insert_location (struct bp_location
*bl
)
11453 internal_error_pure_virtual_called ();
11457 breakpoint::remove_location (struct bp_location
*bl
,
11458 enum remove_bp_reason reason
)
11460 internal_error_pure_virtual_called ();
11464 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11465 const address_space
*aspace
,
11467 const target_waitstatus
&ws
)
11469 internal_error_pure_virtual_called ();
11473 breakpoint::resources_needed (const struct bp_location
*bl
)
11475 internal_error_pure_virtual_called ();
11478 enum print_stop_action
11479 breakpoint::print_it (const bpstat
*bs
) const
11481 internal_error_pure_virtual_called ();
11485 breakpoint::print_mention () const
11487 internal_error_pure_virtual_called ();
11491 breakpoint::print_recreate (struct ui_file
*fp
) const
11493 internal_error_pure_virtual_called ();
11496 /* Default breakpoint_ops methods. */
11499 code_breakpoint::re_set ()
11501 /* FIXME: is this still reachable? */
11502 if (breakpoint_location_spec_empty_p (this))
11504 /* Anything without a location can't be re-set. */
11505 delete_breakpoint (this);
11513 code_breakpoint::insert_location (struct bp_location
*bl
)
11515 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11517 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11518 bl
->target_info
.placed_address
= addr
;
11521 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11522 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11524 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11526 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11528 /* The insertion was successful, now let's set the probe's semaphore
11530 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11537 code_breakpoint::remove_location (struct bp_location
*bl
,
11538 enum remove_bp_reason reason
)
11540 if (bl
->probe
.prob
!= nullptr)
11542 /* Let's clear the semaphore before removing the location. */
11543 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11546 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11547 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11549 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11553 code_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11554 const address_space
*aspace
,
11556 const target_waitstatus
&ws
)
11558 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11559 || ws
.sig () != GDB_SIGNAL_TRAP
)
11562 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11566 if (overlay_debugging
/* unmapped overlay section */
11567 && section_is_overlay (bl
->section
)
11568 && !section_is_mapped (bl
->section
))
11575 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11576 const address_space
*aspace
,
11578 const target_waitstatus
&ws
)
11580 if (dprintf_style
== dprintf_style_agent
11581 && target_can_run_breakpoint_commands ())
11583 /* An agent-style dprintf never causes a stop. If we see a trap
11584 for this address it must be for a breakpoint that happens to
11585 be set at the same address. */
11589 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11593 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
11595 gdb_assert (type
== bp_hardware_breakpoint
);
11600 enum print_stop_action
11601 ordinary_breakpoint::print_it (const bpstat
*bs
) const
11603 const struct bp_location
*bl
;
11605 struct ui_out
*uiout
= current_uiout
;
11607 bl
= bs
->bp_location_at
.get ();
11609 bp_temp
= disposition
== disp_del
;
11610 if (bl
->address
!= bl
->requested_address
)
11611 breakpoint_adjustment_warning (bl
->requested_address
,
11614 annotate_breakpoint (number
);
11615 maybe_print_thread_hit_breakpoint (uiout
);
11617 if (uiout
->is_mi_like_p ())
11619 uiout
->field_string ("reason",
11620 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11621 uiout
->field_string ("disp", bpdisp_text (disposition
));
11624 uiout
->message ("Temporary breakpoint %pF, ",
11625 signed_field ("bkptno", number
));
11627 uiout
->message ("Breakpoint %pF, ",
11628 signed_field ("bkptno", number
));
11630 return PRINT_SRC_AND_LOC
;
11634 ordinary_breakpoint::print_mention () const
11636 if (current_uiout
->is_mi_like_p ())
11641 case bp_breakpoint
:
11642 case bp_gnu_ifunc_resolver
:
11643 if (disposition
== disp_del
)
11644 gdb_printf (_("Temporary breakpoint"));
11646 gdb_printf (_("Breakpoint"));
11647 gdb_printf (_(" %d"), number
);
11648 if (type
== bp_gnu_ifunc_resolver
)
11649 gdb_printf (_(" at gnu-indirect-function resolver"));
11651 case bp_hardware_breakpoint
:
11652 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
11655 gdb_printf (_("Dprintf %d"), number
);
11663 ordinary_breakpoint::print_recreate (struct ui_file
*fp
) const
11665 if (type
== bp_breakpoint
&& disposition
== disp_del
)
11666 gdb_printf (fp
, "tbreak");
11667 else if (type
== bp_breakpoint
)
11668 gdb_printf (fp
, "break");
11669 else if (type
== bp_hardware_breakpoint
11670 && disposition
== disp_del
)
11671 gdb_printf (fp
, "thbreak");
11672 else if (type
== bp_hardware_breakpoint
)
11673 gdb_printf (fp
, "hbreak");
11675 internal_error (__FILE__
, __LINE__
,
11676 _("unhandled breakpoint type %d"), (int) type
);
11678 gdb_printf (fp
, " %s", locspec
->to_string ());
11680 /* Print out extra_string if this breakpoint is pending. It might
11681 contain, for example, conditions that were set by the user. */
11682 if (loc
== NULL
&& extra_string
!= NULL
)
11683 gdb_printf (fp
, " %s", extra_string
.get ());
11685 print_recreate_thread (fp
);
11688 std::vector
<symtab_and_line
>
11689 code_breakpoint::decode_location_spec (location_spec
*locspec
,
11690 program_space
*search_pspace
)
11692 if (locspec
->type () == PROBE_LOCATION_SPEC
)
11693 return bkpt_probe_decode_location_spec (this, locspec
, search_pspace
);
11695 return decode_location_spec_default (this, locspec
, search_pspace
);
11698 /* Virtual table for internal breakpoints. */
11701 internal_breakpoint::re_set ()
11705 /* Delete overlay event and longjmp master breakpoints; they
11706 will be reset later by breakpoint_re_set. */
11707 case bp_overlay_event
:
11708 case bp_longjmp_master
:
11709 case bp_std_terminate_master
:
11710 case bp_exception_master
:
11711 delete_breakpoint (this);
11714 /* This breakpoint is special, it's set up when the inferior
11715 starts and we really don't want to touch it. */
11716 case bp_shlib_event
:
11718 /* Like bp_shlib_event, this breakpoint type is special. Once
11719 it is set up, we do not want to touch it. */
11720 case bp_thread_event
:
11726 internal_breakpoint::check_status (bpstat
*bs
)
11728 if (type
== bp_shlib_event
)
11730 /* If requested, stop when the dynamic linker notifies GDB of
11731 events. This allows the user to get control and place
11732 breakpoints in initializer routines for dynamically loaded
11733 objects (among other things). */
11734 bs
->stop
= stop_on_solib_events
;
11735 bs
->print
= stop_on_solib_events
;
11741 enum print_stop_action
11742 internal_breakpoint::print_it (const bpstat
*bs
) const
11746 case bp_shlib_event
:
11747 /* Did we stop because the user set the stop_on_solib_events
11748 variable? (If so, we report this as a generic, "Stopped due
11749 to shlib event" message.) */
11750 print_solib_event (false);
11753 case bp_thread_event
:
11754 /* Not sure how we will get here.
11755 GDB should not stop for these breakpoints. */
11756 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
11759 case bp_overlay_event
:
11760 /* By analogy with the thread event, GDB should not stop for these. */
11761 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11764 case bp_longjmp_master
:
11765 /* These should never be enabled. */
11766 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11769 case bp_std_terminate_master
:
11770 /* These should never be enabled. */
11771 gdb_printf (_("std::terminate Master Breakpoint: "
11772 "gdb should not stop!\n"));
11775 case bp_exception_master
:
11776 /* These should never be enabled. */
11777 gdb_printf (_("Exception Master Breakpoint: "
11778 "gdb should not stop!\n"));
11782 return PRINT_NOTHING
;
11786 internal_breakpoint::print_mention () const
11788 /* Nothing to mention. These breakpoints are internal. */
11791 /* Virtual table for momentary breakpoints */
11794 momentary_breakpoint::re_set ()
11796 /* Keep temporary breakpoints, which can be encountered when we step
11797 over a dlopen call and solib_add is resetting the breakpoints.
11798 Otherwise these should have been blown away via the cleanup chain
11799 or by breakpoint_init_inferior when we rerun the executable. */
11803 momentary_breakpoint::check_status (bpstat
*bs
)
11805 /* Nothing. The point of these breakpoints is causing a stop. */
11808 enum print_stop_action
11809 momentary_breakpoint::print_it (const bpstat
*bs
) const
11811 return PRINT_UNKNOWN
;
11815 momentary_breakpoint::print_mention () const
11817 /* Nothing to mention. These breakpoints are internal. */
11820 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
11822 It gets cleared already on the removal of the first one of such placed
11823 breakpoints. This is OK as they get all removed altogether. */
11825 longjmp_breakpoint::~longjmp_breakpoint ()
11827 thread_info
*tp
= find_thread_global_id (this->thread
);
11830 tp
->initiating_frame
= null_frame_id
;
11834 bkpt_probe_create_sals_from_location_spec (location_spec
*locspec
,
11835 struct linespec_result
*canonical
)
11838 struct linespec_sals lsal
;
11840 lsal
.sals
= parse_probes (locspec
, NULL
, canonical
);
11841 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
11842 canonical
->lsals
.push_back (std::move (lsal
));
11845 static std::vector
<symtab_and_line
>
11846 bkpt_probe_decode_location_spec (struct breakpoint
*b
,
11847 location_spec
*locspec
,
11848 program_space
*search_pspace
)
11850 std::vector
<symtab_and_line
> sals
11851 = parse_probes (locspec
, search_pspace
, NULL
);
11853 error (_("probe not found"));
11858 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
11859 const address_space
*aspace
, CORE_ADDR bp_addr
,
11860 const target_waitstatus
&ws
)
11862 /* By definition, the inferior does not report stops at
11868 tracepoint::print_one_detail (struct ui_out
*uiout
) const
11870 if (!static_trace_marker_id
.empty ())
11872 gdb_assert (type
== bp_static_tracepoint
11873 || type
== bp_static_marker_tracepoint
);
11875 uiout
->message ("\tmarker id is %pF\n",
11876 string_field ("static-tracepoint-marker-string-id",
11877 static_trace_marker_id
.c_str ()));
11882 tracepoint::print_mention () const
11884 if (current_uiout
->is_mi_like_p ())
11889 case bp_tracepoint
:
11890 gdb_printf (_("Tracepoint"));
11891 gdb_printf (_(" %d"), number
);
11893 case bp_fast_tracepoint
:
11894 gdb_printf (_("Fast tracepoint"));
11895 gdb_printf (_(" %d"), number
);
11897 case bp_static_tracepoint
:
11898 case bp_static_marker_tracepoint
:
11899 gdb_printf (_("Static tracepoint"));
11900 gdb_printf (_(" %d"), number
);
11903 internal_error (__FILE__
, __LINE__
,
11904 _("unhandled tracepoint type %d"), (int) type
);
11911 tracepoint::print_recreate (struct ui_file
*fp
) const
11913 if (type
== bp_fast_tracepoint
)
11914 gdb_printf (fp
, "ftrace");
11915 else if (type
== bp_static_tracepoint
11916 || type
== bp_static_marker_tracepoint
)
11917 gdb_printf (fp
, "strace");
11918 else if (type
== bp_tracepoint
)
11919 gdb_printf (fp
, "trace");
11921 internal_error (__FILE__
, __LINE__
,
11922 _("unhandled tracepoint type %d"), (int) type
);
11924 gdb_printf (fp
, " %s", locspec
->to_string ());
11925 print_recreate_thread (fp
);
11928 gdb_printf (fp
, " passcount %d\n", pass_count
);
11931 /* Virtual table for tracepoints on static probes. */
11934 tracepoint_probe_create_sals_from_location_spec
11935 (location_spec
*locspec
,
11936 struct linespec_result
*canonical
)
11938 /* We use the same method for breakpoint on probes. */
11939 bkpt_probe_create_sals_from_location_spec (locspec
, canonical
);
11943 dprintf_breakpoint::re_set ()
11947 /* extra_string should never be non-NULL for dprintf. */
11948 gdb_assert (extra_string
!= NULL
);
11950 /* 1 - connect to target 1, that can run breakpoint commands.
11951 2 - create a dprintf, which resolves fine.
11952 3 - disconnect from target 1
11953 4 - connect to target 2, that can NOT run breakpoint commands.
11955 After steps #3/#4, you'll want the dprintf command list to
11956 be updated, because target 1 and 2 may well return different
11957 answers for target_can_run_breakpoint_commands().
11958 Given absence of finer grained resetting, we get to do
11959 it all the time. */
11960 if (extra_string
!= NULL
)
11961 update_dprintf_command_list (this);
11964 /* Implement the "print_recreate" method for dprintf. */
11967 dprintf_breakpoint::print_recreate (struct ui_file
*fp
) const
11969 gdb_printf (fp
, "dprintf %s,%s", locspec
->to_string (), extra_string
.get ());
11970 print_recreate_thread (fp
);
11973 /* Implement the "after_condition_true" method for dprintf.
11975 dprintf's are implemented with regular commands in their command
11976 list, but we run the commands here instead of before presenting the
11977 stop to the user, as dprintf's don't actually cause a stop. This
11978 also makes it so that the commands of multiple dprintfs at the same
11979 address are all handled. */
11982 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
11984 /* dprintf's never cause a stop. This wasn't set in the
11985 check_status hook instead because that would make the dprintf's
11986 condition not be evaluated. */
11989 /* Run the command list here. Take ownership of it instead of
11990 copying. We never want these commands to run later in
11991 bpstat_do_actions, if a breakpoint that causes a stop happens to
11992 be set at same address as this dprintf, or even if running the
11993 commands here throws. */
11994 counted_command_line cmds
= std::move (bs
->commands
);
11995 gdb_assert (cmds
!= nullptr);
11996 execute_control_commands (cmds
.get (), 0);
11999 /* The breakpoint_ops structure to be used on static tracepoints with
12003 strace_marker_create_sals_from_location_spec (location_spec
*locspec
,
12004 struct linespec_result
*canonical
)
12006 struct linespec_sals lsal
;
12007 const char *arg_start
, *arg
;
12009 arg
= arg_start
= as_linespec_location_spec (locspec
)->spec_string
;
12010 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12012 std::string
str (arg_start
, arg
- arg_start
);
12013 const char *ptr
= str
.c_str ();
12015 = new_linespec_location_spec (&ptr
, symbol_name_match_type::FULL
);
12017 lsal
.canonical
= xstrdup (canonical
->locspec
->to_string ());
12018 canonical
->lsals
.push_back (std::move (lsal
));
12022 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12023 struct linespec_result
*canonical
,
12024 gdb::unique_xmalloc_ptr
<char> cond_string
,
12025 gdb::unique_xmalloc_ptr
<char> extra_string
,
12026 enum bptype type_wanted
,
12027 enum bpdisp disposition
,
12029 int task
, int ignore_count
,
12030 int from_tty
, int enabled
,
12031 int internal
, unsigned flags
)
12033 const linespec_sals
&lsal
= canonical
->lsals
[0];
12035 /* If the user is creating a static tracepoint by marker id
12036 (strace -m MARKER_ID), then store the sals index, so that
12037 breakpoint_re_set can try to match up which of the newly
12038 found markers corresponds to this one, and, don't try to
12039 expand multiple locations for each sal, given than SALS
12040 already should contain all sals for MARKER_ID. */
12042 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12044 location_spec_up locspec
= canonical
->locspec
->clone ();
12046 std::unique_ptr
<tracepoint
> tp
12047 (new tracepoint (gdbarch
,
12050 std::move (locspec
),
12052 std::move (cond_string
),
12053 std::move (extra_string
),
12055 thread
, task
, ignore_count
,
12056 from_tty
, enabled
, flags
,
12057 canonical
->special_display
));
12059 /* Given that its possible to have multiple markers with
12060 the same string id, if the user is creating a static
12061 tracepoint by marker id ("strace -m MARKER_ID"), then
12062 store the sals index, so that breakpoint_re_set can
12063 try to match up which of the newly found markers
12064 corresponds to this one */
12065 tp
->static_trace_marker_id_idx
= i
;
12067 install_breakpoint (internal
, std::move (tp
), 0);
12071 std::vector
<symtab_and_line
>
12072 static_marker_tracepoint::decode_location_spec (location_spec
*locspec
,
12073 program_space
*search_pspace
)
12075 const char *s
= as_linespec_location_spec (locspec
)->spec_string
;
12077 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12078 if (sals
.size () > static_trace_marker_id_idx
)
12080 sals
[0] = sals
[static_trace_marker_id_idx
];
12085 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12088 /* Static tracepoints with marker (`-m'). */
12089 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12091 strace_marker_create_sals_from_location_spec
,
12092 strace_marker_create_breakpoints_sal
,
12096 strace_marker_p (struct breakpoint
*b
)
12098 return b
->type
== bp_static_marker_tracepoint
;
12101 /* Delete a breakpoint and clean up all traces of it in the data
12105 delete_breakpoint (struct breakpoint
*bpt
)
12107 gdb_assert (bpt
!= NULL
);
12109 /* Has this bp already been deleted? This can happen because
12110 multiple lists can hold pointers to bp's. bpstat lists are
12113 One example of this happening is a watchpoint's scope bp. When
12114 the scope bp triggers, we notice that the watchpoint is out of
12115 scope, and delete it. We also delete its scope bp. But the
12116 scope bp is marked "auto-deleting", and is already on a bpstat.
12117 That bpstat is then checked for auto-deleting bp's, which are
12120 A real solution to this problem might involve reference counts in
12121 bp's, and/or giving them pointers back to their referencing
12122 bpstat's, and teaching delete_breakpoint to only free a bp's
12123 storage when no more references were extent. A cheaper bandaid
12125 if (bpt
->type
== bp_none
)
12128 /* At least avoid this stale reference until the reference counting
12129 of breakpoints gets resolved. */
12130 if (bpt
->related_breakpoint
!= bpt
)
12132 struct breakpoint
*related
;
12133 struct watchpoint
*w
;
12135 if (bpt
->type
== bp_watchpoint_scope
)
12136 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12137 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12138 w
= (struct watchpoint
*) bpt
;
12142 watchpoint_del_at_next_stop (w
);
12144 /* Unlink bpt from the bpt->related_breakpoint ring. */
12145 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12146 related
= related
->related_breakpoint
);
12147 related
->related_breakpoint
= bpt
->related_breakpoint
;
12148 bpt
->related_breakpoint
= bpt
;
12151 /* watch_command_1 creates a watchpoint but only sets its number if
12152 update_watchpoint succeeds in creating its bp_locations. If there's
12153 a problem in that process, we'll be asked to delete the half-created
12154 watchpoint. In that case, don't announce the deletion. */
12156 gdb::observers::breakpoint_deleted
.notify (bpt
);
12158 if (breakpoint_chain
== bpt
)
12159 breakpoint_chain
= bpt
->next
;
12161 for (breakpoint
*b
: all_breakpoints ())
12162 if (b
->next
== bpt
)
12164 b
->next
= bpt
->next
;
12168 /* Be sure no bpstat's are pointing at the breakpoint after it's
12170 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12171 in all threads for now. Note that we cannot just remove bpstats
12172 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12173 commands are associated with the bpstat; if we remove it here,
12174 then the later call to bpstat_do_actions (&stop_bpstat); in
12175 event-top.c won't do anything, and temporary breakpoints with
12176 commands won't work. */
12178 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12180 /* Now that breakpoint is removed from breakpoint list, update the
12181 global location list. This will remove locations that used to
12182 belong to this breakpoint. Do this before freeing the breakpoint
12183 itself, since remove_breakpoint looks at location's owner. It
12184 might be better design to have location completely
12185 self-contained, but it's not the case now. */
12186 update_global_location_list (UGLL_DONT_INSERT
);
12188 /* On the chance that someone will soon try again to delete this
12189 same bp, we mark it as deleted before freeing its storage. */
12190 bpt
->type
= bp_none
;
12194 /* Iterator function to call a user-provided callback function once
12195 for each of B and its related breakpoints. */
12198 iterate_over_related_breakpoints (struct breakpoint
*b
,
12199 gdb::function_view
<void (breakpoint
*)> function
)
12201 struct breakpoint
*related
;
12206 struct breakpoint
*next
;
12208 /* FUNCTION may delete RELATED. */
12209 next
= related
->related_breakpoint
;
12211 if (next
== related
)
12213 /* RELATED is the last ring entry. */
12214 function (related
);
12216 /* FUNCTION may have deleted it, so we'd never reach back to
12217 B. There's nothing left to do anyway, so just break
12222 function (related
);
12226 while (related
!= b
);
12230 delete_command (const char *arg
, int from_tty
)
12236 int breaks_to_delete
= 0;
12238 /* Delete all breakpoints if no argument. Do not delete
12239 internal breakpoints, these have to be deleted with an
12240 explicit breakpoint number argument. */
12241 for (breakpoint
*b
: all_breakpoints ())
12242 if (user_breakpoint_p (b
))
12244 breaks_to_delete
= 1;
12248 /* Ask user only if there are some breakpoints to delete. */
12250 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12251 for (breakpoint
*b
: all_breakpoints_safe ())
12252 if (user_breakpoint_p (b
))
12253 delete_breakpoint (b
);
12256 map_breakpoint_numbers
12257 (arg
, [&] (breakpoint
*br
)
12259 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12263 /* Return true if all locations of B bound to PSPACE are pending. If
12264 PSPACE is NULL, all locations of all program spaces are
12268 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12270 for (bp_location
*loc
: b
->locations ())
12271 if ((pspace
== NULL
12272 || loc
->pspace
== pspace
)
12273 && !loc
->shlib_disabled
12274 && !loc
->pspace
->executing_startup
)
12279 /* Subroutine of update_breakpoint_locations to simplify it.
12280 Return non-zero if multiple fns in list LOC have the same name.
12281 Null names are ignored. */
12284 ambiguous_names_p (struct bp_location
*loc
)
12286 struct bp_location
*l
;
12287 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12290 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12293 const char *name
= l
->function_name
.get ();
12295 /* Allow for some names to be NULL, ignore them. */
12299 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12301 /* NOTE: We can assume slot != NULL here because xcalloc never
12311 /* When symbols change, it probably means the sources changed as well,
12312 and it might mean the static tracepoint markers are no longer at
12313 the same address or line numbers they used to be at last we
12314 checked. Losing your static tracepoints whenever you rebuild is
12315 undesirable. This function tries to resync/rematch gdb static
12316 tracepoints with the markers on the target, for static tracepoints
12317 that have not been set by marker id. Static tracepoint that have
12318 been set by marker id are reset by marker id in breakpoint_re_set.
12321 1) For a tracepoint set at a specific address, look for a marker at
12322 the old PC. If one is found there, assume to be the same marker.
12323 If the name / string id of the marker found is different from the
12324 previous known name, assume that means the user renamed the marker
12325 in the sources, and output a warning.
12327 2) For a tracepoint set at a given line number, look for a marker
12328 at the new address of the old line number. If one is found there,
12329 assume to be the same marker. If the name / string id of the
12330 marker found is different from the previous known name, assume that
12331 means the user renamed the marker in the sources, and output a
12334 3) If a marker is no longer found at the same address or line, it
12335 may mean the marker no longer exists. But it may also just mean
12336 the code changed a bit. Maybe the user added a few lines of code
12337 that made the marker move up or down (in line number terms). Ask
12338 the target for info about the marker with the string id as we knew
12339 it. If found, update line number and address in the matching
12340 static tracepoint. This will get confused if there's more than one
12341 marker with the same ID (possible in UST, although unadvised
12342 precisely because it confuses tools). */
12344 static struct symtab_and_line
12345 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12347 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12348 struct static_tracepoint_marker marker
;
12353 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12355 if (target_static_tracepoint_marker_at (pc
, &marker
))
12357 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12358 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12359 b
->number
, tp
->static_trace_marker_id
.c_str (),
12360 marker
.str_id
.c_str ());
12362 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12367 /* Old marker wasn't found on target at lineno. Try looking it up
12369 if (!sal
.explicit_pc
12371 && sal
.symtab
!= NULL
12372 && !tp
->static_trace_marker_id
.empty ())
12374 std::vector
<static_tracepoint_marker
> markers
12375 = target_static_tracepoint_markers_by_strid
12376 (tp
->static_trace_marker_id
.c_str ());
12378 if (!markers
.empty ())
12380 struct symbol
*sym
;
12381 struct static_tracepoint_marker
*tpmarker
;
12382 struct ui_out
*uiout
= current_uiout
;
12384 tpmarker
= &markers
[0];
12386 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12388 warning (_("marker for static tracepoint %d (%s) not "
12389 "found at previous line number"),
12390 b
->number
, tp
->static_trace_marker_id
.c_str ());
12392 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12393 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12394 uiout
->text ("Now in ");
12397 uiout
->field_string ("func", sym
->print_name (),
12398 function_name_style
.style ());
12399 uiout
->text (" at ");
12401 uiout
->field_string ("file",
12402 symtab_to_filename_for_display (sal2
.symtab
),
12403 file_name_style
.style ());
12406 if (uiout
->is_mi_like_p ())
12408 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12410 uiout
->field_string ("fullname", fullname
);
12413 uiout
->field_signed ("line", sal2
.line
);
12414 uiout
->text ("\n");
12416 b
->loc
->line_number
= sal2
.line
;
12417 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12419 std::unique_ptr
<explicit_location_spec
> els
12420 (new explicit_location_spec ());
12421 els
->source_filename
12422 = xstrdup (symtab_to_filename_for_display (sal2
.symtab
));
12423 els
->line_offset
.offset
= b
->loc
->line_number
;
12424 els
->line_offset
.sign
= LINE_OFFSET_NONE
;
12426 b
->locspec
= std::move (els
);
12428 /* Might be nice to check if function changed, and warn if
12435 /* Returns 1 iff locations A and B are sufficiently same that
12436 we don't need to report breakpoint as changed. */
12439 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12443 if (a
->address
!= b
->address
)
12446 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12449 if (a
->enabled
!= b
->enabled
)
12452 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12459 if ((a
== NULL
) != (b
== NULL
))
12465 /* Split all locations of B that are bound to PSPACE out of B's
12466 location list to a separate list and return that list's head. If
12467 PSPACE is NULL, hoist out all locations of B. */
12469 static struct bp_location
*
12470 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12472 struct bp_location head
;
12473 struct bp_location
*i
= b
->loc
;
12474 struct bp_location
**i_link
= &b
->loc
;
12475 struct bp_location
*hoisted
= &head
;
12477 if (pspace
== NULL
)
12488 if (i
->pspace
== pspace
)
12503 /* Create new breakpoint locations for B (a hardware or software
12504 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12505 zero, then B is a ranged breakpoint. Only recreates locations for
12506 FILTER_PSPACE. Locations of other program spaces are left
12510 update_breakpoint_locations (code_breakpoint
*b
,
12511 struct program_space
*filter_pspace
,
12512 gdb::array_view
<const symtab_and_line
> sals
,
12513 gdb::array_view
<const symtab_and_line
> sals_end
)
12515 struct bp_location
*existing_locations
;
12517 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12519 /* Ranged breakpoints have only one start location and one end
12521 b
->enable_state
= bp_disabled
;
12522 gdb_printf (gdb_stderr
,
12523 _("Could not reset ranged breakpoint %d: "
12524 "multiple locations found\n"),
12529 /* If there's no new locations, and all existing locations are
12530 pending, don't do anything. This optimizes the common case where
12531 all locations are in the same shared library, that was unloaded.
12532 We'd like to retain the location, so that when the library is
12533 loaded again, we don't loose the enabled/disabled status of the
12534 individual locations. */
12535 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12538 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12540 for (const auto &sal
: sals
)
12542 struct bp_location
*new_loc
;
12544 switch_to_program_space_and_thread (sal
.pspace
);
12546 new_loc
= b
->add_location (sal
);
12548 /* Reparse conditions, they might contain references to the
12550 if (b
->cond_string
!= NULL
)
12554 s
= b
->cond_string
.get ();
12557 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12558 block_for_pc (sal
.pc
),
12561 catch (const gdb_exception_error
&e
)
12563 new_loc
->disabled_by_cond
= true;
12567 if (!sals_end
.empty ())
12569 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12571 new_loc
->length
= end
- sals
[0].pc
+ 1;
12575 /* If possible, carry over 'disable' status from existing
12578 struct bp_location
*e
= existing_locations
;
12579 /* If there are multiple breakpoints with the same function name,
12580 e.g. for inline functions, comparing function names won't work.
12581 Instead compare pc addresses; this is just a heuristic as things
12582 may have moved, but in practice it gives the correct answer
12583 often enough until a better solution is found. */
12584 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12586 for (; e
; e
= e
->next
)
12588 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12590 if (have_ambiguous_names
)
12592 for (bp_location
*l
: b
->locations ())
12594 /* Ignore software vs hardware location type at
12595 this point, because with "set breakpoint
12596 auto-hw", after a re-set, locations that were
12597 hardware can end up as software, or vice versa.
12598 As mentioned above, this is an heuristic and in
12599 practice should give the correct answer often
12601 if (breakpoint_locations_match (e
, l
, true))
12603 l
->enabled
= e
->enabled
;
12604 l
->disabled_by_cond
= e
->disabled_by_cond
;
12611 for (bp_location
*l
: b
->locations ())
12612 if (l
->function_name
12613 && strcmp (e
->function_name
.get (),
12614 l
->function_name
.get ()) == 0)
12616 l
->enabled
= e
->enabled
;
12617 l
->disabled_by_cond
= e
->disabled_by_cond
;
12625 if (!locations_are_equal (existing_locations
, b
->loc
))
12626 gdb::observers::breakpoint_modified
.notify (b
);
12629 /* Find the SaL locations corresponding to the given LOCSPEC.
12630 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12632 std::vector
<symtab_and_line
>
12633 code_breakpoint::location_spec_to_sals (location_spec
*locspec
,
12634 struct program_space
*search_pspace
,
12637 struct gdb_exception exception
;
12639 std::vector
<symtab_and_line
> sals
;
12643 sals
= decode_location_spec (locspec
, search_pspace
);
12645 catch (gdb_exception_error
&e
)
12647 int not_found_and_ok
= 0;
12649 /* For pending breakpoints, it's expected that parsing will
12650 fail until the right shared library is loaded. User has
12651 already told to create pending breakpoints and don't need
12652 extra messages. If breakpoint is in bp_shlib_disabled
12653 state, then user already saw the message about that
12654 breakpoint being disabled, and don't want to see more
12656 if (e
.error
== NOT_FOUND_ERROR
12657 && (condition_not_parsed
12659 && search_pspace
!= NULL
12660 && loc
->pspace
!= search_pspace
)
12661 || (loc
&& loc
->shlib_disabled
)
12662 || (loc
&& loc
->pspace
->executing_startup
)
12663 || enable_state
== bp_disabled
))
12664 not_found_and_ok
= 1;
12666 if (!not_found_and_ok
)
12668 /* We surely don't want to warn about the same breakpoint
12669 10 times. One solution, implemented here, is disable
12670 the breakpoint on error. Another solution would be to
12671 have separate 'warning emitted' flag. Since this
12672 happens only when a binary has changed, I don't know
12673 which approach is better. */
12674 enable_state
= bp_disabled
;
12678 exception
= std::move (e
);
12681 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
12683 for (auto &sal
: sals
)
12684 resolve_sal_pc (&sal
);
12685 if (condition_not_parsed
&& extra_string
!= NULL
)
12687 gdb::unique_xmalloc_ptr
<char> local_cond
, local_extra
;
12688 int local_thread
, local_task
;
12690 find_condition_and_thread_for_sals (sals
, extra_string
.get (),
12691 &local_cond
, &local_thread
,
12692 &local_task
, &local_extra
);
12693 gdb_assert (cond_string
== nullptr);
12694 if (local_cond
!= nullptr)
12695 cond_string
= std::move (local_cond
);
12696 thread
= local_thread
;
12698 if (local_extra
!= nullptr)
12699 extra_string
= std::move (local_extra
);
12700 condition_not_parsed
= 0;
12703 if (type
== bp_static_tracepoint
)
12704 sals
[0] = update_static_tracepoint (this, sals
[0]);
12714 /* The default re_set method, for typical hardware or software
12715 breakpoints. Reevaluate the breakpoint and recreate its
12719 code_breakpoint::re_set_default ()
12721 struct program_space
*filter_pspace
= current_program_space
;
12722 std::vector
<symtab_and_line
> expanded
, expanded_end
;
12725 std::vector
<symtab_and_line
> sals
= location_spec_to_sals (locspec
.get (),
12729 expanded
= std::move (sals
);
12731 if (locspec_range_end
!= nullptr)
12733 std::vector
<symtab_and_line
> sals_end
12734 = location_spec_to_sals (locspec_range_end
.get (),
12735 filter_pspace
, &found
);
12737 expanded_end
= std::move (sals_end
);
12740 update_breakpoint_locations (this, filter_pspace
, expanded
, expanded_end
);
12743 /* Default method for creating SALs from an address string. It basically
12744 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12747 create_sals_from_location_spec_default (location_spec
*locspec
,
12748 struct linespec_result
*canonical
)
12750 parse_breakpoint_sals (locspec
, canonical
);
12753 /* Decode the line represented by S by calling decode_line_full. This is the
12754 default function for the `decode_location' method of breakpoint_ops. */
12756 static std::vector
<symtab_and_line
>
12757 decode_location_spec_default (struct breakpoint
*b
,
12758 location_spec
*locspec
,
12759 program_space
*search_pspace
)
12761 struct linespec_result canonical
;
12763 decode_line_full (locspec
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
12764 NULL
, 0, &canonical
, multiple_symbols_all
,
12767 /* We should get 0 or 1 resulting SALs. */
12768 gdb_assert (canonical
.lsals
.size () < 2);
12770 if (!canonical
.lsals
.empty ())
12772 const linespec_sals
&lsal
= canonical
.lsals
[0];
12773 return std::move (lsal
.sals
);
12778 /* Reset a breakpoint. */
12781 breakpoint_re_set_one (breakpoint
*b
)
12783 input_radix
= b
->input_radix
;
12784 set_language (b
->language
);
12789 /* Re-set breakpoint locations for the current program space.
12790 Locations bound to other program spaces are left untouched. */
12793 breakpoint_re_set (void)
12796 scoped_restore_current_language save_language
;
12797 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
12798 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12800 /* breakpoint_re_set_one sets the current_language to the language
12801 of the breakpoint it is resetting (see prepare_re_set_context)
12802 before re-evaluating the breakpoint's location. This change can
12803 unfortunately get undone by accident if the language_mode is set
12804 to auto, and we either switch frames, or more likely in this context,
12805 we select the current frame.
12807 We prevent this by temporarily turning the language_mode to
12808 language_mode_manual. We restore it once all breakpoints
12809 have been reset. */
12810 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
12811 language_mode
= language_mode_manual
;
12813 /* Note: we must not try to insert locations until after all
12814 breakpoints have been re-set. Otherwise, e.g., when re-setting
12815 breakpoint 1, we'd insert the locations of breakpoint 2, which
12816 hadn't been re-set yet, and thus may have stale locations. */
12818 for (breakpoint
*b
: all_breakpoints_safe ())
12822 breakpoint_re_set_one (b
);
12824 catch (const gdb_exception
&ex
)
12826 exception_fprintf (gdb_stderr
, ex
,
12827 "Error in re-setting breakpoint %d: ",
12832 jit_breakpoint_re_set ();
12835 create_overlay_event_breakpoint ();
12836 create_longjmp_master_breakpoint ();
12837 create_std_terminate_master_breakpoint ();
12838 create_exception_master_breakpoint ();
12840 /* Now we can insert. */
12841 update_global_location_list (UGLL_MAY_INSERT
);
12844 /* Reset the thread number of this breakpoint:
12846 - If the breakpoint is for all threads, leave it as-is.
12847 - Else, reset it to the current thread for inferior_ptid. */
12849 breakpoint_re_set_thread (struct breakpoint
*b
)
12851 if (b
->thread
!= -1)
12853 b
->thread
= inferior_thread ()->global_num
;
12855 /* We're being called after following a fork. The new fork is
12856 selected as current, and unless this was a vfork will have a
12857 different program space from the original thread. Reset that
12859 b
->loc
->pspace
= current_program_space
;
12863 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12864 If from_tty is nonzero, it prints a message to that effect,
12865 which ends with a period (no newline). */
12868 set_ignore_count (int bptnum
, int count
, int from_tty
)
12873 for (breakpoint
*b
: all_breakpoints ())
12874 if (b
->number
== bptnum
)
12876 if (is_tracepoint (b
))
12878 if (from_tty
&& count
!= 0)
12879 gdb_printf (_("Ignore count ignored for tracepoint %d."),
12884 b
->ignore_count
= count
;
12888 gdb_printf (_("Will stop next time "
12889 "breakpoint %d is reached."),
12891 else if (count
== 1)
12892 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
12895 gdb_printf (_("Will ignore next %d "
12896 "crossings of breakpoint %d."),
12899 gdb::observers::breakpoint_modified
.notify (b
);
12903 error (_("No breakpoint number %d."), bptnum
);
12906 /* Command to set ignore-count of breakpoint N to COUNT. */
12909 ignore_command (const char *args
, int from_tty
)
12911 const char *p
= args
;
12915 error_no_arg (_("a breakpoint number"));
12917 num
= get_number (&p
);
12919 error (_("bad breakpoint number: '%s'"), args
);
12921 error (_("Second argument (specified ignore-count) is missing."));
12923 set_ignore_count (num
,
12924 longest_to_int (value_as_long (parse_and_eval (p
))),
12931 /* Call FUNCTION on each of the breakpoints with numbers in the range
12932 defined by BP_NUM_RANGE (an inclusive range). */
12935 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
12936 gdb::function_view
<void (breakpoint
*)> function
)
12938 if (bp_num_range
.first
== 0)
12940 warning (_("bad breakpoint number at or near '%d'"),
12941 bp_num_range
.first
);
12945 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
12947 bool match
= false;
12949 for (breakpoint
*b
: all_breakpoints_safe ())
12950 if (b
->number
== i
)
12957 gdb_printf (_("No breakpoint number %d.\n"), i
);
12962 /* Call FUNCTION on each of the breakpoints whose numbers are given in
12966 map_breakpoint_numbers (const char *args
,
12967 gdb::function_view
<void (breakpoint
*)> function
)
12969 if (args
== NULL
|| *args
== '\0')
12970 error_no_arg (_("one or more breakpoint numbers"));
12972 number_or_range_parser
parser (args
);
12974 while (!parser
.finished ())
12976 int num
= parser
.get_number ();
12977 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
12981 /* Return the breakpoint location structure corresponding to the
12982 BP_NUM and LOC_NUM values. */
12984 static struct bp_location
*
12985 find_location_by_number (int bp_num
, int loc_num
)
12987 breakpoint
*b
= get_breakpoint (bp_num
);
12989 if (!b
|| b
->number
!= bp_num
)
12990 error (_("Bad breakpoint number '%d'"), bp_num
);
12993 error (_("Bad breakpoint location number '%d'"), loc_num
);
12996 for (bp_location
*loc
: b
->locations ())
12997 if (++n
== loc_num
)
13000 error (_("Bad breakpoint location number '%d'"), loc_num
);
13003 /* Modes of operation for extract_bp_num. */
13004 enum class extract_bp_kind
13006 /* Extracting a breakpoint number. */
13009 /* Extracting a location number. */
13013 /* Extract a breakpoint or location number (as determined by KIND)
13014 from the string starting at START. TRAILER is a character which
13015 can be found after the number. If you don't want a trailer, use
13016 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13017 string. This always returns a positive integer. */
13020 extract_bp_num (extract_bp_kind kind
, const char *start
,
13021 int trailer
, const char **end_out
= NULL
)
13023 const char *end
= start
;
13024 int num
= get_number_trailer (&end
, trailer
);
13026 error (kind
== extract_bp_kind::bp
13027 ? _("Negative breakpoint number '%.*s'")
13028 : _("Negative breakpoint location number '%.*s'"),
13029 int (end
- start
), start
);
13031 error (kind
== extract_bp_kind::bp
13032 ? _("Bad breakpoint number '%.*s'")
13033 : _("Bad breakpoint location number '%.*s'"),
13034 int (end
- start
), start
);
13036 if (end_out
!= NULL
)
13041 /* Extract a breakpoint or location range (as determined by KIND) in
13042 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13043 representing the (inclusive) range. The returned pair's elements
13044 are always positive integers. */
13046 static std::pair
<int, int>
13047 extract_bp_or_bp_range (extract_bp_kind kind
,
13048 const std::string
&arg
,
13049 std::string::size_type arg_offset
)
13051 std::pair
<int, int> range
;
13052 const char *bp_loc
= &arg
[arg_offset
];
13053 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13054 if (dash
!= std::string::npos
)
13056 /* bp_loc is a range (x-z). */
13057 if (arg
.length () == dash
+ 1)
13058 error (kind
== extract_bp_kind::bp
13059 ? _("Bad breakpoint number at or near: '%s'")
13060 : _("Bad breakpoint location number at or near: '%s'"),
13064 const char *start_first
= bp_loc
;
13065 const char *start_second
= &arg
[dash
+ 1];
13066 range
.first
= extract_bp_num (kind
, start_first
, '-');
13067 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13069 if (range
.first
> range
.second
)
13070 error (kind
== extract_bp_kind::bp
13071 ? _("Inverted breakpoint range at '%.*s'")
13072 : _("Inverted breakpoint location range at '%.*s'"),
13073 int (end
- start_first
), start_first
);
13077 /* bp_loc is a single value. */
13078 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13079 range
.second
= range
.first
;
13084 /* Extract the breakpoint/location range specified by ARG. Returns
13085 the breakpoint range in BP_NUM_RANGE, and the location range in
13088 ARG may be in any of the following forms:
13090 x where 'x' is a breakpoint number.
13091 x-y where 'x' and 'y' specify a breakpoint numbers range.
13092 x.y where 'x' is a breakpoint number and 'y' a location number.
13093 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13094 location number range.
13098 extract_bp_number_and_location (const std::string
&arg
,
13099 std::pair
<int, int> &bp_num_range
,
13100 std::pair
<int, int> &bp_loc_range
)
13102 std::string::size_type dot
= arg
.find ('.');
13104 if (dot
!= std::string::npos
)
13106 /* Handle 'x.y' and 'x.y-z' cases. */
13108 if (arg
.length () == dot
+ 1 || dot
== 0)
13109 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13112 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13113 bp_num_range
.second
= bp_num_range
.first
;
13115 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13120 /* Handle x and x-y cases. */
13122 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13123 bp_loc_range
.first
= 0;
13124 bp_loc_range
.second
= 0;
13128 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13129 specifies whether to enable or disable. */
13132 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13134 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13137 if (loc
->disabled_by_cond
&& enable
)
13138 error (_("Breakpoint %d's condition is invalid at location %d, "
13139 "cannot enable."), bp_num
, loc_num
);
13141 if (loc
->enabled
!= enable
)
13143 loc
->enabled
= enable
;
13144 mark_breakpoint_location_modified (loc
);
13146 if (target_supports_enable_disable_tracepoint ()
13147 && current_trace_status ()->running
&& loc
->owner
13148 && is_tracepoint (loc
->owner
))
13149 target_disable_tracepoint (loc
);
13151 update_global_location_list (UGLL_DONT_INSERT
);
13153 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13156 /* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
13157 owner. 1-based indexing. -1 signals NOT FOUND. */
13160 find_loc_num_by_location (bp_location
*loc
)
13162 if (loc
!= nullptr && loc
->owner
!= nullptr)
13164 /* Locations use 1-based indexing. */
13166 for (bp_location
*it
: loc
->owner
->locations ())
13176 /* Enable or disable a breakpoint location LOC. ENABLE
13177 specifies whether to enable or disable. */
13180 enable_disable_bp_location (bp_location
*loc
, bool enable
)
13182 if (loc
== nullptr)
13183 error (_("Breakpoint location is invalid."));
13185 if (loc
->owner
== nullptr)
13186 error (_("Breakpoint location does not have an owner breakpoint."));
13188 if (loc
->disabled_by_cond
&& enable
)
13190 int loc_num
= find_loc_num_by_location (loc
);
13192 error (_("Breakpoint location LOC_NUM could not be found."));
13194 error (_("Breakpoint %d's condition is invalid at location %d, "
13195 "cannot enable."), loc
->owner
->number
, loc_num
);
13198 if (loc
->enabled
!= enable
)
13200 loc
->enabled
= enable
;
13201 mark_breakpoint_location_modified (loc
);
13204 if (target_supports_enable_disable_tracepoint ()
13205 && current_trace_status ()->running
&& loc
->owner
13206 && is_tracepoint (loc
->owner
))
13207 target_disable_tracepoint (loc
);
13209 update_global_location_list (UGLL_DONT_INSERT
);
13210 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13213 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13214 number of the breakpoint, and BP_LOC_RANGE specifies the
13215 (inclusive) range of location numbers of that breakpoint to
13216 enable/disable. ENABLE specifies whether to enable or disable the
13220 enable_disable_breakpoint_location_range (int bp_num
,
13221 std::pair
<int, int> &bp_loc_range
,
13224 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13225 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13228 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13229 If from_tty is nonzero, it prints a message to that effect,
13230 which ends with a period (no newline). */
13233 disable_breakpoint (struct breakpoint
*bpt
)
13235 /* Never disable a watchpoint scope breakpoint; we want to
13236 hit them when we leave scope so we can delete both the
13237 watchpoint and its scope breakpoint at that time. */
13238 if (bpt
->type
== bp_watchpoint_scope
)
13241 bpt
->enable_state
= bp_disabled
;
13243 /* Mark breakpoint locations modified. */
13244 mark_breakpoint_modified (bpt
);
13246 if (target_supports_enable_disable_tracepoint ()
13247 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13249 for (bp_location
*location
: bpt
->locations ())
13250 target_disable_tracepoint (location
);
13253 update_global_location_list (UGLL_DONT_INSERT
);
13255 gdb::observers::breakpoint_modified
.notify (bpt
);
13258 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13259 specified in ARGS. ARGS may be in any of the formats handled by
13260 extract_bp_number_and_location. ENABLE specifies whether to enable
13261 or disable the breakpoints/locations. */
13264 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13268 for (breakpoint
*bpt
: all_breakpoints ())
13269 if (user_breakpoint_p (bpt
))
13272 enable_breakpoint (bpt
);
13274 disable_breakpoint (bpt
);
13279 std::string num
= extract_arg (&args
);
13281 while (!num
.empty ())
13283 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13285 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13287 if (bp_loc_range
.first
== bp_loc_range
.second
13288 && bp_loc_range
.first
== 0)
13290 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
13291 map_breakpoint_number_range (bp_num_range
,
13293 ? enable_breakpoint
13294 : disable_breakpoint
);
13298 /* Handle breakpoint ids with formats 'x.y' or
13300 enable_disable_breakpoint_location_range
13301 (bp_num_range
.first
, bp_loc_range
, enable
);
13303 num
= extract_arg (&args
);
13308 /* The disable command disables the specified breakpoints/locations
13309 (or all defined breakpoints) so they're no longer effective in
13310 stopping the inferior. ARGS may be in any of the forms defined in
13311 extract_bp_number_and_location. */
13314 disable_command (const char *args
, int from_tty
)
13316 enable_disable_command (args
, from_tty
, false);
13320 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13323 int target_resources_ok
;
13325 if (bpt
->type
== bp_hardware_breakpoint
)
13328 i
= hw_breakpoint_used_count ();
13329 target_resources_ok
=
13330 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13332 if (target_resources_ok
== 0)
13333 error (_("No hardware breakpoint support in the target."));
13334 else if (target_resources_ok
< 0)
13335 error (_("Hardware breakpoints used exceeds limit."));
13338 if (is_watchpoint (bpt
))
13340 /* Initialize it just to avoid a GCC false warning. */
13341 enum enable_state orig_enable_state
= bp_disabled
;
13345 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13347 orig_enable_state
= bpt
->enable_state
;
13348 bpt
->enable_state
= bp_enabled
;
13349 update_watchpoint (w
, 1 /* reparse */);
13351 catch (const gdb_exception
&e
)
13353 bpt
->enable_state
= orig_enable_state
;
13354 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13360 bpt
->enable_state
= bp_enabled
;
13362 /* Mark breakpoint locations modified. */
13363 mark_breakpoint_modified (bpt
);
13365 if (target_supports_enable_disable_tracepoint ()
13366 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13368 for (bp_location
*location
: bpt
->locations ())
13369 target_enable_tracepoint (location
);
13372 bpt
->disposition
= disposition
;
13373 bpt
->enable_count
= count
;
13374 update_global_location_list (UGLL_MAY_INSERT
);
13376 gdb::observers::breakpoint_modified
.notify (bpt
);
13381 enable_breakpoint (struct breakpoint
*bpt
)
13383 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13386 /* The enable command enables the specified breakpoints/locations (or
13387 all defined breakpoints) so they once again become (or continue to
13388 be) effective in stopping the inferior. ARGS may be in any of the
13389 forms defined in extract_bp_number_and_location. */
13392 enable_command (const char *args
, int from_tty
)
13394 enable_disable_command (args
, from_tty
, true);
13398 enable_once_command (const char *args
, int from_tty
)
13400 map_breakpoint_numbers
13401 (args
, [&] (breakpoint
*b
)
13403 iterate_over_related_breakpoints
13404 (b
, [&] (breakpoint
*bpt
)
13406 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13412 enable_count_command (const char *args
, int from_tty
)
13417 error_no_arg (_("hit count"));
13419 count
= get_number (&args
);
13421 map_breakpoint_numbers
13422 (args
, [&] (breakpoint
*b
)
13424 iterate_over_related_breakpoints
13425 (b
, [&] (breakpoint
*bpt
)
13427 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13433 enable_delete_command (const char *args
, int from_tty
)
13435 map_breakpoint_numbers
13436 (args
, [&] (breakpoint
*b
)
13438 iterate_over_related_breakpoints
13439 (b
, [&] (breakpoint
*bpt
)
13441 enable_breakpoint_disp (bpt
, disp_del
, 1);
13446 /* Invalidate last known value of any hardware watchpoint if
13447 the memory which that value represents has been written to by
13451 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13452 CORE_ADDR addr
, ssize_t len
,
13453 const bfd_byte
*data
)
13455 for (breakpoint
*bp
: all_breakpoints ())
13456 if (bp
->enable_state
== bp_enabled
13457 && bp
->type
== bp_hardware_watchpoint
)
13459 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13461 if (wp
->val_valid
&& wp
->val
!= nullptr)
13463 for (bp_location
*loc
: bp
->locations ())
13464 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13465 && loc
->address
+ loc
->length
> addr
13466 && addr
+ len
> loc
->address
)
13469 wp
->val_valid
= false;
13475 /* Create and insert a breakpoint for software single step. */
13478 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13479 const address_space
*aspace
,
13482 struct thread_info
*tp
= inferior_thread ();
13483 struct symtab_and_line sal
;
13484 CORE_ADDR pc
= next_pc
;
13486 if (tp
->control
.single_step_breakpoints
== NULL
)
13488 std::unique_ptr
<breakpoint
> b
13489 (new momentary_breakpoint (gdbarch
, bp_single_step
,
13490 current_program_space
,
13494 tp
->control
.single_step_breakpoints
13495 = add_to_breakpoint_chain (std::move (b
));
13498 sal
= find_pc_line (pc
, 0);
13500 sal
.section
= find_pc_overlay (pc
);
13501 sal
.explicit_pc
= 1;
13504 = static_cast<momentary_breakpoint
*> (tp
->control
.single_step_breakpoints
);
13505 ss_bp
->add_location (sal
);
13507 update_global_location_list (UGLL_INSERT
);
13510 /* Insert single step breakpoints according to the current state. */
13513 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13515 struct regcache
*regcache
= get_current_regcache ();
13516 std::vector
<CORE_ADDR
> next_pcs
;
13518 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13520 if (!next_pcs
.empty ())
13522 struct frame_info
*frame
= get_current_frame ();
13523 const address_space
*aspace
= get_frame_address_space (frame
);
13525 for (CORE_ADDR pc
: next_pcs
)
13526 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13534 /* See breakpoint.h. */
13537 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13538 const address_space
*aspace
,
13541 for (bp_location
*loc
: bp
->locations ())
13543 && breakpoint_location_address_match (loc
, aspace
, pc
))
13549 /* Check whether a software single-step breakpoint is inserted at
13553 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13556 for (breakpoint
*bpt
: all_breakpoints ())
13558 if (bpt
->type
== bp_single_step
13559 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13565 /* Tracepoint-specific operations. */
13567 /* Set tracepoint count to NUM. */
13569 set_tracepoint_count (int num
)
13571 tracepoint_count
= num
;
13572 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13576 trace_command (const char *arg
, int from_tty
)
13578 location_spec_up locspec
= string_to_location_spec (&arg
,
13580 const struct breakpoint_ops
*ops
= breakpoint_ops_for_location_spec
13581 (locspec
.get (), true /* is_tracepoint */);
13583 create_breakpoint (get_current_arch (),
13585 NULL
, 0, arg
, false, 1 /* parse arg */,
13587 bp_tracepoint
/* type_wanted */,
13588 0 /* Ignore count */,
13589 pending_break_support
,
13593 0 /* internal */, 0);
13597 ftrace_command (const char *arg
, int from_tty
)
13599 location_spec_up locspec
= string_to_location_spec (&arg
,
13601 create_breakpoint (get_current_arch (),
13603 NULL
, 0, arg
, false, 1 /* parse arg */,
13605 bp_fast_tracepoint
/* type_wanted */,
13606 0 /* Ignore count */,
13607 pending_break_support
,
13608 &code_breakpoint_ops
,
13611 0 /* internal */, 0);
13614 /* strace command implementation. Creates a static tracepoint. */
13617 strace_command (const char *arg
, int from_tty
)
13619 const struct breakpoint_ops
*ops
;
13620 location_spec_up locspec
;
13623 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13624 or with a normal static tracepoint. */
13625 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13627 ops
= &strace_marker_breakpoint_ops
;
13628 locspec
= new_linespec_location_spec (&arg
,
13629 symbol_name_match_type::FULL
);
13630 type
= bp_static_marker_tracepoint
;
13634 ops
= &code_breakpoint_ops
;
13635 locspec
= string_to_location_spec (&arg
, current_language
);
13636 type
= bp_static_tracepoint
;
13639 create_breakpoint (get_current_arch (),
13641 NULL
, 0, arg
, false, 1 /* parse arg */,
13643 type
/* type_wanted */,
13644 0 /* Ignore count */,
13645 pending_break_support
,
13649 0 /* internal */, 0);
13652 /* Set up a fake reader function that gets command lines from a linked
13653 list that was acquired during tracepoint uploading. */
13655 static struct uploaded_tp
*this_utp
;
13656 static int next_cmd
;
13659 read_uploaded_action (void)
13661 char *rslt
= nullptr;
13663 if (next_cmd
< this_utp
->cmd_strings
.size ())
13665 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13672 /* Given information about a tracepoint as recorded on a target (which
13673 can be either a live system or a trace file), attempt to create an
13674 equivalent GDB tracepoint. This is not a reliable process, since
13675 the target does not necessarily have all the information used when
13676 the tracepoint was originally defined. */
13678 struct tracepoint
*
13679 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13681 const char *addr_str
;
13682 char small_buf
[100];
13683 struct tracepoint
*tp
;
13685 if (utp
->at_string
)
13686 addr_str
= utp
->at_string
.get ();
13689 /* In the absence of a source location, fall back to raw
13690 address. Since there is no way to confirm that the address
13691 means the same thing as when the trace was started, warn the
13693 warning (_("Uploaded tracepoint %d has no "
13694 "source location, using raw address"),
13696 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13697 addr_str
= small_buf
;
13700 /* There's not much we can do with a sequence of bytecodes. */
13701 if (utp
->cond
&& !utp
->cond_string
)
13702 warning (_("Uploaded tracepoint %d condition "
13703 "has no source form, ignoring it"),
13706 location_spec_up locspec
= string_to_location_spec (&addr_str
,
13708 if (!create_breakpoint (get_current_arch (),
13710 utp
->cond_string
.get (), -1, addr_str
,
13711 false /* force_condition */,
13712 0 /* parse cond/thread */,
13714 utp
->type
/* type_wanted */,
13715 0 /* Ignore count */,
13716 pending_break_support
,
13717 &code_breakpoint_ops
,
13719 utp
->enabled
/* enabled */,
13721 CREATE_BREAKPOINT_FLAGS_INSERTED
))
13724 /* Get the tracepoint we just created. */
13725 tp
= get_tracepoint (tracepoint_count
);
13726 gdb_assert (tp
!= NULL
);
13730 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
13733 trace_pass_command (small_buf
, 0);
13736 /* If we have uploaded versions of the original commands, set up a
13737 special-purpose "reader" function and call the usual command line
13738 reader, then pass the result to the breakpoint command-setting
13740 if (!utp
->cmd_strings
.empty ())
13742 counted_command_line cmd_list
;
13747 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
13749 breakpoint_set_commands (tp
, std::move (cmd_list
));
13751 else if (!utp
->actions
.empty ()
13752 || !utp
->step_actions
.empty ())
13753 warning (_("Uploaded tracepoint %d actions "
13754 "have no source form, ignoring them"),
13757 /* Copy any status information that might be available. */
13758 tp
->hit_count
= utp
->hit_count
;
13759 tp
->traceframe_usage
= utp
->traceframe_usage
;
13764 /* Print information on tracepoint number TPNUM_EXP, or all if
13768 info_tracepoints_command (const char *args
, int from_tty
)
13770 struct ui_out
*uiout
= current_uiout
;
13773 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
13775 if (num_printed
== 0)
13777 if (args
== NULL
|| *args
== '\0')
13778 uiout
->message ("No tracepoints.\n");
13780 uiout
->message ("No tracepoint matching '%s'.\n", args
);
13783 default_collect_info ();
13786 /* The 'enable trace' command enables tracepoints.
13787 Not supported by all targets. */
13789 enable_trace_command (const char *args
, int from_tty
)
13791 enable_command (args
, from_tty
);
13794 /* The 'disable trace' command disables tracepoints.
13795 Not supported by all targets. */
13797 disable_trace_command (const char *args
, int from_tty
)
13799 disable_command (args
, from_tty
);
13802 /* Remove a tracepoint (or all if no argument). */
13804 delete_trace_command (const char *arg
, int from_tty
)
13810 int breaks_to_delete
= 0;
13812 /* Delete all breakpoints if no argument.
13813 Do not delete internal or call-dummy breakpoints, these
13814 have to be deleted with an explicit breakpoint number
13816 for (breakpoint
*tp
: all_tracepoints ())
13817 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
13819 breaks_to_delete
= 1;
13823 /* Ask user only if there are some breakpoints to delete. */
13825 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13827 for (breakpoint
*b
: all_breakpoints_safe ())
13828 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13829 delete_breakpoint (b
);
13833 map_breakpoint_numbers
13834 (arg
, [&] (breakpoint
*br
)
13836 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13840 /* Helper function for trace_pass_command. */
13843 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13845 tp
->pass_count
= count
;
13846 gdb::observers::breakpoint_modified
.notify (tp
);
13848 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
13849 tp
->number
, count
);
13852 /* Set passcount for tracepoint.
13854 First command argument is passcount, second is tracepoint number.
13855 If tracepoint number omitted, apply to most recently defined.
13856 Also accepts special argument "all". */
13859 trace_pass_command (const char *args
, int from_tty
)
13861 struct tracepoint
*t1
;
13864 if (args
== 0 || *args
== 0)
13865 error (_("passcount command requires an "
13866 "argument (count + optional TP num)"));
13868 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
13870 args
= skip_spaces (args
);
13871 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13873 args
+= 3; /* Skip special argument "all". */
13875 error (_("Junk at end of arguments."));
13877 for (breakpoint
*b
: all_tracepoints ())
13879 t1
= (struct tracepoint
*) b
;
13880 trace_pass_set_count (t1
, count
, from_tty
);
13883 else if (*args
== '\0')
13885 t1
= get_tracepoint_by_number (&args
, NULL
);
13887 trace_pass_set_count (t1
, count
, from_tty
);
13891 number_or_range_parser
parser (args
);
13892 while (!parser
.finished ())
13894 t1
= get_tracepoint_by_number (&args
, &parser
);
13896 trace_pass_set_count (t1
, count
, from_tty
);
13901 struct tracepoint
*
13902 get_tracepoint (int num
)
13904 for (breakpoint
*t
: all_tracepoints ())
13905 if (t
->number
== num
)
13906 return (struct tracepoint
*) t
;
13911 /* Find the tracepoint with the given target-side number (which may be
13912 different from the tracepoint number after disconnecting and
13915 struct tracepoint
*
13916 get_tracepoint_by_number_on_target (int num
)
13918 for (breakpoint
*b
: all_tracepoints ())
13920 struct tracepoint
*t
= (struct tracepoint
*) b
;
13922 if (t
->number_on_target
== num
)
13929 /* Utility: parse a tracepoint number and look it up in the list.
13930 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13931 If the argument is missing, the most recent tracepoint
13932 (tracepoint_count) is returned. */
13934 struct tracepoint
*
13935 get_tracepoint_by_number (const char **arg
,
13936 number_or_range_parser
*parser
)
13939 const char *instring
= arg
== NULL
? NULL
: *arg
;
13941 if (parser
!= NULL
)
13943 gdb_assert (!parser
->finished ());
13944 tpnum
= parser
->get_number ();
13946 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13947 tpnum
= tracepoint_count
;
13949 tpnum
= get_number (arg
);
13953 if (instring
&& *instring
)
13954 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
13957 gdb_printf (_("No previous tracepoint\n"));
13961 for (breakpoint
*t
: all_tracepoints ())
13962 if (t
->number
== tpnum
)
13963 return (struct tracepoint
*) t
;
13965 gdb_printf ("No tracepoint number %d.\n", tpnum
);
13970 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
13973 gdb_printf (fp
, " thread %d", thread
);
13976 gdb_printf (fp
, " task %d", task
);
13978 gdb_printf (fp
, "\n");
13981 /* Save information on user settable breakpoints (watchpoints, etc) to
13982 a new script file named FILENAME. If FILTER is non-NULL, call it
13983 on each breakpoint and only include the ones for which it returns
13987 save_breakpoints (const char *filename
, int from_tty
,
13988 bool (*filter
) (const struct breakpoint
*))
13991 int extra_trace_bits
= 0;
13993 if (filename
== 0 || *filename
== 0)
13994 error (_("Argument required (file name in which to save)"));
13996 /* See if we have anything to save. */
13997 for (breakpoint
*tp
: all_breakpoints ())
13999 /* Skip internal and momentary breakpoints. */
14000 if (!user_breakpoint_p (tp
))
14003 /* If we have a filter, only save the breakpoints it accepts. */
14004 if (filter
&& !filter (tp
))
14009 if (is_tracepoint (tp
))
14011 extra_trace_bits
= 1;
14013 /* We can stop searching. */
14020 warning (_("Nothing to save."));
14024 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14028 if (!fp
.open (expanded_filename
.get (), "w"))
14029 error (_("Unable to open file '%s' for saving (%s)"),
14030 expanded_filename
.get (), safe_strerror (errno
));
14032 if (extra_trace_bits
)
14033 save_trace_state_variables (&fp
);
14035 for (breakpoint
*tp
: all_breakpoints ())
14037 /* Skip internal and momentary breakpoints. */
14038 if (!user_breakpoint_p (tp
))
14041 /* If we have a filter, only save the breakpoints it accepts. */
14042 if (filter
&& !filter (tp
))
14045 tp
->print_recreate (&fp
);
14047 /* Note, we can't rely on tp->number for anything, as we can't
14048 assume the recreated breakpoint numbers will match. Use $bpnum
14051 if (tp
->cond_string
)
14052 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14054 if (tp
->ignore_count
)
14055 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14057 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14059 fp
.puts (" commands\n");
14061 ui_out_redirect_pop
redir (current_uiout
, &fp
);
14062 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14064 fp
.puts (" end\n");
14067 if (tp
->enable_state
== bp_disabled
)
14068 fp
.puts ("disable $bpnum\n");
14070 /* If this is a multi-location breakpoint, check if the locations
14071 should be individually disabled. Watchpoint locations are
14072 special, and not user visible. */
14073 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14077 for (bp_location
*loc
: tp
->locations ())
14080 fp
.printf ("disable $bpnum.%d\n", n
);
14087 if (extra_trace_bits
&& !default_collect
.empty ())
14088 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14091 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14094 /* The `save breakpoints' command. */
14097 save_breakpoints_command (const char *args
, int from_tty
)
14099 save_breakpoints (args
, from_tty
, NULL
);
14102 /* The `save tracepoints' command. */
14105 save_tracepoints_command (const char *args
, int from_tty
)
14107 save_breakpoints (args
, from_tty
, is_tracepoint
);
14111 /* This help string is used to consolidate all the help string for specifying
14112 locations used by several commands. */
14114 #define LOCATION_SPEC_HELP_STRING \
14115 "Linespecs are colon-separated lists of location parameters, such as\n\
14116 source filename, function name, label name, and line number.\n\
14117 Example: To specify the start of a label named \"the_top\" in the\n\
14118 function \"fact\" in the file \"factorial.c\", use\n\
14119 \"factorial.c:fact:the_top\".\n\
14121 Address locations begin with \"*\" and specify an exact address in the\n\
14122 program. Example: To specify the fourth byte past the start function\n\
14123 \"main\", use \"*main + 4\".\n\
14125 Explicit locations are similar to linespecs but use an option/argument\n\
14126 syntax to specify location parameters.\n\
14127 Example: To specify the start of the label named \"the_top\" in the\n\
14128 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14129 -function fact -label the_top\".\n\
14131 By default, a specified function is matched against the program's\n\
14132 functions in all scopes. For C++, this means in all namespaces and\n\
14133 classes. For Ada, this means in all packages. E.g., in C++,\n\
14134 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14135 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14136 specified name as a complete fully-qualified name instead."
14138 /* This help string is used for the break, hbreak, tbreak and thbreak
14139 commands. It is defined as a macro to prevent duplication.
14140 COMMAND should be a string constant containing the name of the
14143 #define BREAK_ARGS_HELP(command) \
14144 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14145 \t[-force-condition] [if CONDITION]\n\
14146 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14147 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14148 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14149 `-probe-dtrace' (for a DTrace probe).\n\
14150 LOCATION may be a linespec, address, or explicit location as described\n\
14153 With no LOCATION, uses current execution address of the selected\n\
14154 stack frame. This is useful for breaking on return to a stack frame.\n\
14156 THREADNUM is the number from \"info threads\".\n\
14157 CONDITION is a boolean expression.\n\
14159 With the \"-force-condition\" flag, the condition is defined even when\n\
14160 it is invalid for all current locations.\n\
14161 \n" LOCATION_SPEC_HELP_STRING "\n\n\
14162 Multiple breakpoints at one place are permitted, and useful if their\n\
14163 conditions are different.\n\
14165 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14167 /* List of subcommands for "catch". */
14168 static struct cmd_list_element
*catch_cmdlist
;
14170 /* List of subcommands for "tcatch". */
14171 static struct cmd_list_element
*tcatch_cmdlist
;
14174 add_catch_command (const char *name
, const char *docstring
,
14175 cmd_func_ftype
*func
,
14176 completer_ftype
*completer
,
14177 void *user_data_catch
,
14178 void *user_data_tcatch
)
14180 struct cmd_list_element
*command
;
14182 command
= add_cmd (name
, class_breakpoint
, docstring
,
14184 command
->func
= func
;
14185 command
->set_context (user_data_catch
);
14186 set_cmd_completer (command
, completer
);
14188 command
= add_cmd (name
, class_breakpoint
, docstring
,
14190 command
->func
= func
;
14191 command
->set_context (user_data_tcatch
);
14192 set_cmd_completer (command
, completer
);
14195 /* Zero if any of the breakpoint's locations could be a location where
14196 functions have been inlined, nonzero otherwise. */
14199 is_non_inline_function (struct breakpoint
*b
)
14201 /* The shared library event breakpoint is set on the address of a
14202 non-inline function. */
14203 if (b
->type
== bp_shlib_event
)
14209 /* Nonzero if the specified PC cannot be a location where functions
14210 have been inlined. */
14213 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14214 const target_waitstatus
&ws
)
14216 for (breakpoint
*b
: all_breakpoints ())
14218 if (!is_non_inline_function (b
))
14221 for (bp_location
*bl
: b
->locations ())
14223 if (!bl
->shlib_disabled
14224 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14232 /* Remove any references to OBJFILE which is going to be freed. */
14235 breakpoint_free_objfile (struct objfile
*objfile
)
14237 for (bp_location
*loc
: all_bp_locations ())
14238 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14239 loc
->symtab
= NULL
;
14242 /* Chain containing all defined "enable breakpoint" subcommands. */
14244 static struct cmd_list_element
*enablebreaklist
= NULL
;
14246 /* See breakpoint.h. */
14248 cmd_list_element
*commands_cmd_element
= nullptr;
14250 void _initialize_breakpoint ();
14252 _initialize_breakpoint ()
14254 struct cmd_list_element
*c
;
14256 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14258 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14260 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14263 breakpoint_chain
= 0;
14264 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14265 before a breakpoint is set. */
14266 breakpoint_count
= 0;
14268 tracepoint_count
= 0;
14270 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14271 Set ignore-count of breakpoint number N to COUNT.\n\
14272 Usage is `ignore N COUNT'."));
14274 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14275 commands_command
, _("\
14276 Set commands to be executed when the given breakpoints are hit.\n\
14277 Give a space-separated breakpoint list as argument after \"commands\".\n\
14278 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14280 With no argument, the targeted breakpoint is the last one set.\n\
14281 The commands themselves follow starting on the next line.\n\
14282 Type a line containing \"end\" to indicate the end of them.\n\
14283 Give \"silent\" as the first line to make the breakpoint silent;\n\
14284 then no output is printed when it is hit, except what the commands print."));
14286 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14287 static std::string condition_command_help
14288 = gdb::option::build_help (_("\
14289 Specify breakpoint number N to break only if COND is true.\n\
14290 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14291 is an expression to be evaluated whenever breakpoint N is reached.\n\
14294 %OPTIONS%"), cc_opts
);
14296 c
= add_com ("condition", class_breakpoint
, condition_command
,
14297 condition_command_help
.c_str ());
14298 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14300 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14301 Set a temporary breakpoint.\n\
14302 Like \"break\" except the breakpoint is only temporary,\n\
14303 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14304 by using \"enable delete\" on the breakpoint number.\n\
14306 BREAK_ARGS_HELP ("tbreak")));
14307 set_cmd_completer (c
, location_completer
);
14309 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14310 Set a hardware assisted breakpoint.\n\
14311 Like \"break\" except the breakpoint requires hardware support,\n\
14312 some target hardware may not have this support.\n\
14314 BREAK_ARGS_HELP ("hbreak")));
14315 set_cmd_completer (c
, location_completer
);
14317 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14318 Set a temporary hardware assisted breakpoint.\n\
14319 Like \"hbreak\" except the breakpoint is only temporary,\n\
14320 so it will be deleted when hit.\n\
14322 BREAK_ARGS_HELP ("thbreak")));
14323 set_cmd_completer (c
, location_completer
);
14325 cmd_list_element
*enable_cmd
14326 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14327 Enable all or some breakpoints.\n\
14328 Usage: enable [BREAKPOINTNUM]...\n\
14329 Give breakpoint numbers (separated by spaces) as arguments.\n\
14330 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14331 This is used to cancel the effect of the \"disable\" command.\n\
14332 With a subcommand you can enable temporarily."),
14333 &enablelist
, 1, &cmdlist
);
14335 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14337 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14338 Enable all or some breakpoints.\n\
14339 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14340 Give breakpoint numbers (separated by spaces) as arguments.\n\
14341 This is used to cancel the effect of the \"disable\" command.\n\
14342 May be abbreviated to simply \"enable\"."),
14343 &enablebreaklist
, 1, &enablelist
);
14345 add_cmd ("once", no_class
, enable_once_command
, _("\
14346 Enable some breakpoints for one hit.\n\
14347 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14348 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14351 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14352 Enable some breakpoints and delete when hit.\n\
14353 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14354 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14357 add_cmd ("count", no_class
, enable_count_command
, _("\
14358 Enable some breakpoints for COUNT hits.\n\
14359 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14360 If a breakpoint is hit while enabled in this fashion,\n\
14361 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14364 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14365 Enable some breakpoints and delete when hit.\n\
14366 Usage: enable delete BREAKPOINTNUM...\n\
14367 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14370 add_cmd ("once", no_class
, enable_once_command
, _("\
14371 Enable some breakpoints for one hit.\n\
14372 Usage: enable once BREAKPOINTNUM...\n\
14373 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14376 add_cmd ("count", no_class
, enable_count_command
, _("\
14377 Enable some breakpoints for COUNT hits.\n\
14378 Usage: enable count COUNT BREAKPOINTNUM...\n\
14379 If a breakpoint is hit while enabled in this fashion,\n\
14380 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14383 cmd_list_element
*disable_cmd
14384 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14385 Disable all or some breakpoints.\n\
14386 Usage: disable [BREAKPOINTNUM]...\n\
14387 Arguments are breakpoint numbers with spaces in between.\n\
14388 To disable all breakpoints, give no argument.\n\
14389 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14390 &disablelist
, 1, &cmdlist
);
14391 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14392 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14394 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14395 Disable all or some breakpoints.\n\
14396 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14397 Arguments are breakpoint numbers with spaces in between.\n\
14398 To disable all breakpoints, give no argument.\n\
14399 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14400 This command may be abbreviated \"disable\"."),
14403 cmd_list_element
*delete_cmd
14404 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14405 Delete all or some breakpoints.\n\
14406 Usage: delete [BREAKPOINTNUM]...\n\
14407 Arguments are breakpoint numbers with spaces in between.\n\
14408 To delete all breakpoints, give no argument.\n\
14410 Also a prefix command for deletion of other GDB objects."),
14411 &deletelist
, 1, &cmdlist
);
14412 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14413 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14415 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14416 Delete all or some breakpoints or auto-display expressions.\n\
14417 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14418 Arguments are breakpoint numbers with spaces in between.\n\
14419 To delete all breakpoints, give no argument.\n\
14420 This command may be abbreviated \"delete\"."),
14423 cmd_list_element
*clear_cmd
14424 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14425 Clear breakpoint at specified location.\n\
14426 Argument may be a linespec, explicit, or address location as described below.\n\
14428 With no argument, clears all breakpoints in the line that the selected frame\n\
14429 is executing in.\n"
14430 "\n" LOCATION_SPEC_HELP_STRING
"\n\n\
14431 See also the \"delete\" command which clears breakpoints by number."));
14432 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14434 cmd_list_element
*break_cmd
14435 = add_com ("break", class_breakpoint
, break_command
, _("\
14436 Set breakpoint at specified location.\n"
14437 BREAK_ARGS_HELP ("break")));
14438 set_cmd_completer (break_cmd
, location_completer
);
14440 add_com_alias ("b", break_cmd
, class_run
, 1);
14441 add_com_alias ("br", break_cmd
, class_run
, 1);
14442 add_com_alias ("bre", break_cmd
, class_run
, 1);
14443 add_com_alias ("brea", break_cmd
, class_run
, 1);
14445 cmd_list_element
*info_breakpoints_cmd
14446 = add_info ("breakpoints", info_breakpoints_command
, _("\
14447 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14448 The \"Type\" column indicates one of:\n\
14449 \tbreakpoint - normal breakpoint\n\
14450 \twatchpoint - watchpoint\n\
14451 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14452 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14453 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14454 address and file/line number respectively.\n\
14456 Convenience variable \"$_\" and default examine address for \"x\"\n\
14457 are set to the address of the last breakpoint listed unless the command\n\
14458 is prefixed with \"server \".\n\n\
14459 Convenience variable \"$bpnum\" contains the number of the last\n\
14460 breakpoint set."));
14462 add_info_alias ("b", info_breakpoints_cmd
, 1);
14464 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14465 Status of all breakpoints, or breakpoint number NUMBER.\n\
14466 The \"Type\" column indicates one of:\n\
14467 \tbreakpoint - normal breakpoint\n\
14468 \twatchpoint - watchpoint\n\
14469 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14470 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14471 \tuntil - internal breakpoint used by the \"until\" command\n\
14472 \tfinish - internal breakpoint used by the \"finish\" command\n\
14473 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14474 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14475 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14476 address and file/line number respectively.\n\
14478 Convenience variable \"$_\" and default examine address for \"x\"\n\
14479 are set to the address of the last breakpoint listed unless the command\n\
14480 is prefixed with \"server \".\n\n\
14481 Convenience variable \"$bpnum\" contains the number of the last\n\
14483 &maintenanceinfolist
);
14485 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14486 Set catchpoints to catch events."),
14488 0/*allow-unknown*/, &cmdlist
);
14490 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14491 Set temporary catchpoints to catch events."),
14493 0/*allow-unknown*/, &cmdlist
);
14495 const auto opts
= make_watch_options_def_group (nullptr);
14497 static const std::string watch_help
= gdb::option::build_help (_("\
14498 Set a watchpoint for EXPRESSION.\n\
14499 Usage: watch [-location] EXPRESSION\n\
14504 A watchpoint stops execution of your program whenever the value of\n\
14505 an expression changes."), opts
);
14506 c
= add_com ("watch", class_breakpoint
, watch_command
,
14507 watch_help
.c_str ());
14508 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14510 static const std::string rwatch_help
= gdb::option::build_help (_("\
14511 Set a read watchpoint for EXPRESSION.\n\
14512 Usage: rwatch [-location] EXPRESSION\n\
14517 A read watchpoint stops execution of your program whenever the value of\n\
14518 an expression is read."), opts
);
14519 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14520 rwatch_help
.c_str ());
14521 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14523 static const std::string awatch_help
= gdb::option::build_help (_("\
14524 Set an access watchpoint for EXPRESSION.\n\
14525 Usage: awatch [-location] EXPRESSION\n\
14530 An access watchpoint stops execution of your program whenever the value\n\
14531 of an expression is either read or written."), opts
);
14532 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14533 awatch_help
.c_str ());
14534 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14536 add_info ("watchpoints", info_watchpoints_command
, _("\
14537 Status of specified watchpoints (all watchpoints if no argument)."));
14539 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14540 respond to changes - contrary to the description. */
14541 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14542 &can_use_hw_watchpoints
, _("\
14543 Set debugger's willingness to use watchpoint hardware."), _("\
14544 Show debugger's willingness to use watchpoint hardware."), _("\
14545 If zero, gdb will not use hardware for new watchpoints, even if\n\
14546 such is available. (However, any hardware watchpoints that were\n\
14547 created before setting this to nonzero, will continue to use watchpoint\n\
14550 show_can_use_hw_watchpoints
,
14551 &setlist
, &showlist
);
14553 can_use_hw_watchpoints
= 1;
14555 /* Tracepoint manipulation commands. */
14557 cmd_list_element
*trace_cmd
14558 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14559 Set a tracepoint at specified location.\n\
14561 BREAK_ARGS_HELP ("trace") "\n\
14562 Do \"help tracepoints\" for info on other tracepoint commands."));
14563 set_cmd_completer (trace_cmd
, location_completer
);
14565 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14566 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14567 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14568 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14570 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14571 Set a fast tracepoint at specified location.\n\
14573 BREAK_ARGS_HELP ("ftrace") "\n\
14574 Do \"help tracepoints\" for info on other tracepoint commands."));
14575 set_cmd_completer (c
, location_completer
);
14577 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14578 Set a static tracepoint at location or marker.\n\
14580 strace [LOCATION] [if CONDITION]\n\
14581 LOCATION may be a linespec, explicit, or address location (described below) \n\
14582 or -m MARKER_ID.\n\n\
14583 If a marker id is specified, probe the marker with that name. With\n\
14584 no LOCATION, uses current execution address of the selected stack frame.\n\
14585 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14586 This collects arbitrary user data passed in the probe point call to the\n\
14587 tracing library. You can inspect it when analyzing the trace buffer,\n\
14588 by printing the $_sdata variable like any other convenience variable.\n\
14590 CONDITION is a boolean expression.\n\
14591 \n" LOCATION_SPEC_HELP_STRING
"\n\n\
14592 Multiple tracepoints at one place are permitted, and useful if their\n\
14593 conditions are different.\n\
14595 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14596 Do \"help tracepoints\" for info on other tracepoint commands."));
14597 set_cmd_completer (c
, location_completer
);
14599 cmd_list_element
*info_tracepoints_cmd
14600 = add_info ("tracepoints", info_tracepoints_command
, _("\
14601 Status of specified tracepoints (all tracepoints if no argument).\n\
14602 Convenience variable \"$tpnum\" contains the number of the\n\
14603 last tracepoint set."));
14605 add_info_alias ("tp", info_tracepoints_cmd
, 1);
14607 cmd_list_element
*delete_tracepoints_cmd
14608 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14609 Delete specified tracepoints.\n\
14610 Arguments are tracepoint numbers, separated by spaces.\n\
14611 No argument means delete all tracepoints."),
14613 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
14615 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14616 Disable specified tracepoints.\n\
14617 Arguments are tracepoint numbers, separated by spaces.\n\
14618 No argument means disable all tracepoints."),
14620 deprecate_cmd (c
, "disable");
14622 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14623 Enable specified tracepoints.\n\
14624 Arguments are tracepoint numbers, separated by spaces.\n\
14625 No argument means enable all tracepoints."),
14627 deprecate_cmd (c
, "enable");
14629 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14630 Set the passcount for a tracepoint.\n\
14631 The trace will end when the tracepoint has been passed 'count' times.\n\
14632 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14633 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14635 add_basic_prefix_cmd ("save", class_breakpoint
,
14636 _("Save breakpoint definitions as a script."),
14638 0/*allow-unknown*/, &cmdlist
);
14640 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14641 Save current breakpoint definitions as a script.\n\
14642 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14643 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14644 session to restore them."),
14646 set_cmd_completer (c
, filename_completer
);
14648 cmd_list_element
*save_tracepoints_cmd
14649 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14650 Save current tracepoint definitions as a script.\n\
14651 Use the 'source' command in another debug session to restore them."),
14653 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
14655 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
14656 deprecate_cmd (c
, "save tracepoints");
14658 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
14660 Breakpoint specific settings.\n\
14661 Configure various breakpoint-specific variables such as\n\
14662 pending breakpoint behavior."),
14664 Breakpoint specific settings.\n\
14665 Configure various breakpoint-specific variables such as\n\
14666 pending breakpoint behavior."),
14667 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
14668 &setlist
, &showlist
);
14670 add_setshow_auto_boolean_cmd ("pending", no_class
,
14671 &pending_break_support
, _("\
14672 Set debugger's behavior regarding pending breakpoints."), _("\
14673 Show debugger's behavior regarding pending breakpoints."), _("\
14674 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14675 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14676 an error. If auto, an unrecognized breakpoint location results in a\n\
14677 user-query to see if a pending breakpoint should be created."),
14679 show_pending_break_support
,
14680 &breakpoint_set_cmdlist
,
14681 &breakpoint_show_cmdlist
);
14683 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14685 add_setshow_boolean_cmd ("auto-hw", no_class
,
14686 &automatic_hardware_breakpoints
, _("\
14687 Set automatic usage of hardware breakpoints."), _("\
14688 Show automatic usage of hardware breakpoints."), _("\
14689 If set, the debugger will automatically use hardware breakpoints for\n\
14690 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14691 a warning will be emitted for such breakpoints."),
14693 show_automatic_hardware_breakpoints
,
14694 &breakpoint_set_cmdlist
,
14695 &breakpoint_show_cmdlist
);
14697 add_setshow_boolean_cmd ("always-inserted", class_support
,
14698 &always_inserted_mode
, _("\
14699 Set mode for inserting breakpoints."), _("\
14700 Show mode for inserting breakpoints."), _("\
14701 When this mode is on, breakpoints are inserted immediately as soon as\n\
14702 they're created, kept inserted even when execution stops, and removed\n\
14703 only when the user deletes them. When this mode is off (the default),\n\
14704 breakpoints are inserted only when execution continues, and removed\n\
14705 when execution stops."),
14707 &show_always_inserted_mode
,
14708 &breakpoint_set_cmdlist
,
14709 &breakpoint_show_cmdlist
);
14711 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
14712 condition_evaluation_enums
,
14713 &condition_evaluation_mode_1
, _("\
14714 Set mode of breakpoint condition evaluation."), _("\
14715 Show mode of breakpoint condition evaluation."), _("\
14716 When this is set to \"host\", breakpoint conditions will be\n\
14717 evaluated on the host's side by GDB. When it is set to \"target\",\n\
14718 breakpoint conditions will be downloaded to the target (if the target\n\
14719 supports such feature) and conditions will be evaluated on the target's side.\n\
14720 If this is set to \"auto\" (default), this will be automatically set to\n\
14721 \"target\" if it supports condition evaluation, otherwise it will\n\
14722 be set to \"host\"."),
14723 &set_condition_evaluation_mode
,
14724 &show_condition_evaluation_mode
,
14725 &breakpoint_set_cmdlist
,
14726 &breakpoint_show_cmdlist
);
14728 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14729 Set a breakpoint for an address range.\n\
14730 break-range START-LOCATION, END-LOCATION\n\
14731 where START-LOCATION and END-LOCATION can be one of the following:\n\
14732 LINENUM, for that line in the current file,\n\
14733 FILE:LINENUM, for that line in that file,\n\
14734 +OFFSET, for that number of lines after the current line\n\
14735 or the start of the range\n\
14736 FUNCTION, for the first line in that function,\n\
14737 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14738 *ADDRESS, for the instruction at that address.\n\
14740 The breakpoint will stop execution of the inferior whenever it executes\n\
14741 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14742 range (including START-LOCATION and END-LOCATION)."));
14744 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
14745 Set a dynamic printf at specified location.\n\
14746 dprintf location,format string,arg1,arg2,...\n\
14747 location may be a linespec, explicit, or address location.\n"
14748 "\n" LOCATION_SPEC_HELP_STRING
));
14749 set_cmd_completer (c
, location_completer
);
14751 add_setshow_enum_cmd ("dprintf-style", class_support
,
14752 dprintf_style_enums
, &dprintf_style
, _("\
14753 Set the style of usage for dynamic printf."), _("\
14754 Show the style of usage for dynamic printf."), _("\
14755 This setting chooses how GDB will do a dynamic printf.\n\
14756 If the value is \"gdb\", then the printing is done by GDB to its own\n\
14757 console, as with the \"printf\" command.\n\
14758 If the value is \"call\", the print is done by calling a function in your\n\
14759 program; by default printf(), but you can choose a different function or\n\
14760 output stream by setting dprintf-function and dprintf-channel."),
14761 update_dprintf_commands
, NULL
,
14762 &setlist
, &showlist
);
14764 add_setshow_string_cmd ("dprintf-function", class_support
,
14765 &dprintf_function
, _("\
14766 Set the function to use for dynamic printf."), _("\
14767 Show the function to use for dynamic printf."), NULL
,
14768 update_dprintf_commands
, NULL
,
14769 &setlist
, &showlist
);
14771 add_setshow_string_cmd ("dprintf-channel", class_support
,
14772 &dprintf_channel
, _("\
14773 Set the channel to use for dynamic printf."), _("\
14774 Show the channel to use for dynamic printf."), NULL
,
14775 update_dprintf_commands
, NULL
,
14776 &setlist
, &showlist
);
14778 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
14779 &disconnected_dprintf
, _("\
14780 Set whether dprintf continues after GDB disconnects."), _("\
14781 Show whether dprintf continues after GDB disconnects."), _("\
14782 Use this to let dprintf commands continue to hit and produce output\n\
14783 even if GDB disconnects or detaches from the target."),
14786 &setlist
, &showlist
);
14788 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
14789 Target agent only formatted printing, like the C \"printf\" function.\n\
14790 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
14791 This supports most C printf format specifications, like %s, %d, etc.\n\
14792 This is useful for formatted output in user-defined commands."));
14794 automatic_hardware_breakpoints
= true;
14796 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
14798 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,